Skip to content

Commit

Permalink
Added c_rasterizer::shell_initialize WIP impl
Browse files Browse the repository at this point in the history
The implementation works but is still missing logic so commented out for now, future note update this to use D3D9On12?
  • Loading branch information
twist84 committed Oct 7, 2024
1 parent 2b7267d commit 497c5ae
Show file tree
Hide file tree
Showing 10 changed files with 271 additions and 15 deletions.
20 changes: 10 additions & 10 deletions game/source/main/global_preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ bool __cdecl global_preferences_get_antialiasing()
return global_preferences_get()->preferences0.data.video_settings.antialiasing;
}

long __cdecl global_preferences_get_unknown41BD0()
long __cdecl global_preferences_get_aspect_ratio()
{
//return INVOKE(0x0050A8B0, global_preferences_get_unknown41BD0);
//return INVOKE(0x0050A8B0, global_preferences_get_aspect_ratio);

if (!global_preferences_available())
return 0;

c_global_preferences_scope_lock scope_lock;
return global_preferences_get()->preferences0.data.__unknown41BD0;
return global_preferences_get()->preferences0.data.aspect_ratio;
}

real __cdecl global_preferences_get_betrayal_count()
Expand Down Expand Up @@ -755,8 +755,8 @@ void __cdecl global_preferences_make_safe(s_global_preferences* preferences)
if (!VALID_INDEX(preferences->data.subtitle_setting, k_number_of_subtitle_settings))
preferences->data.subtitle_setting = _subtitle_setting_automatic;

if (!VALID_INDEX(preferences->data.__unknown41BD0, 3))
preferences->data.__unknown41BD0 = 0;
if (!VALID_INDEX(preferences->data.aspect_ratio, 3))
preferences->data.aspect_ratio = 0;

if (!VALID_INDEX(preferences->data.brightness, 100))
preferences->data.brightness = 50;
Expand Down Expand Up @@ -784,15 +784,15 @@ void __cdecl global_preferences_set_antialiasing(bool antialiasing)
global_preferences_dirty(true);
}

void __cdecl global_preferences_set_unknown41BD0(bool unknown41BD0)
void __cdecl global_preferences_set_aspect_ratio(bool aspect_ratio)
{
//INVOKE(0x0050CD70, global_preferences_set_unknown41BD0, unknown41BD0);
//INVOKE(0x0050CD70, global_preferences_set_aspect_ratio, aspect_ratio);

if (!global_preferences_available())
return;

c_global_preferences_scope_lock scope_lock;
global_preferences_get()->preferences0.data.__unknown41BD0 = unknown41BD0;
global_preferences_get()->preferences0.data.aspect_ratio = aspect_ratio;
global_preferences_dirty(true);
}

Expand Down Expand Up @@ -1451,7 +1451,7 @@ void __stdcall sound_system_set_sfx_volume(long volume, bool update_preference)
char const* const k_global_preference_names[k_global_preference_count]
{
"antialiasing",
//"unknown41BD0",
//"aspect_ratio",
//"betrayal_count",
//"build_number",
"camera_fov",
Expand Down Expand Up @@ -1506,7 +1506,7 @@ char const* const k_global_preference_names[k_global_preference_count]
s_global_preference const* k_global_preferences[k_global_preference_count]
{
DECLARE_GLOBAL_PREFERENCE(antialiasing, "<bool>", 1, _global_preference_type_bool),
//DECLARE_GLOBAL_PREFERENCE(unknown41BD0, "<bool>", 1, _global_preference_type_bool),
//DECLARE_GLOBAL_PREFERENCE(aspect_ratio, "<long>", 1, _global_preference_type_long),
//DECLARE_GLOBAL_PREFERENCE(betrayal_count, "<real>", 1, _global_preference_type_real),
//DECLARE_GLOBAL_PREFERENCE(build_number, "<long>", 1, _global_preference_type_long),
DECLARE_GLOBAL_PREFERENCE(camera_fov, "<real>", 1, _global_preference_type_real),
Expand Down
8 changes: 4 additions & 4 deletions game/source/main/global_preferences.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ struct s_global_preferences_data
long checksum;
long adapter;
bool fullscreen;
long __unknown41BD0;
long aspect_ratio;
long brightness;
long contrast;
s_video_settings video_settings;
Expand Down Expand Up @@ -356,7 +356,7 @@ extern void __cdecl global_preferences_create_default();
extern void __cdecl global_preferences_dispose();
extern void __cdecl global_preferences_flush();
extern bool __cdecl global_preferences_get_antialiasing();
extern long __cdecl global_preferences_get_unknown41BD0();
extern long __cdecl global_preferences_get_aspect_ratio();
extern real __cdecl global_preferences_get_betrayal_count();
extern long __cdecl global_preferences_get_build_number();
extern real __cdecl global_preferences_get_camera_fov();
Expand Down Expand Up @@ -415,7 +415,7 @@ extern void __cdecl global_preferences_initialize();
extern void __cdecl global_preferences_invalidate_maps();
extern void __cdecl global_preferences_make_safe(s_global_preferences* preferences);
extern void __cdecl global_preferences_set_antialiasing(bool antialiasing);
extern void __cdecl global_preferences_set_unknown41BD0(bool unknown41BD0);
extern void __cdecl global_preferences_set_aspect_ratio(bool aspect_ratio);
extern void __cdecl global_preferences_set_betrayal_count(real betrayal_count);
extern void __cdecl global_preferences_set_build_number(long build_number);
extern void __cdecl global_preferences_set_camera_fov(real camera_fov);
Expand Down Expand Up @@ -471,7 +471,7 @@ extern void __cdecl global_preferences_write();
enum e_global_preference
{
_global_preference_antialiasing = 0,
//_global_preference_unknown41BD0,
//_global_preference_aspect_ratio,
//_global_preference_betrayal_count,
//_global_preference_build_number,
_global_preference_camera_fov,
Expand Down
233 changes: 233 additions & 0 deletions game/source/rasterizer/rasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include "main/main.hpp"
#include "memory/module.hpp"
#include "memory/thread_local.hpp"
#include "rasterizer/rasterizer_d3d_allocations.hpp"
#include "rasterizer/rasterizer_dynamic_render_targets.hpp"
#include "rasterizer/rasterizer_globals.hpp"
#include "rasterizer/rasterizer_main.hpp"
#include "rasterizer/rasterizer_memory.hpp"
#include "rasterizer/rasterizer_resource_definitions.hpp"
Expand All @@ -29,6 +31,7 @@ REFERENCE_DECLARE_ARRAY(0x01692A0C, D3DRENDERSTATETYPE, c_rasterizer::x_last_ren
REFERENCE_DECLARE(0x019104FC, dword, c_rasterizer::g_render_thread);
REFERENCE_DECLARE(0x019106C0, s_rasterizer_render_globals, c_rasterizer::render_globals);
REFERENCE_DECLARE(0x0194FEA8, dword, c_rasterizer::g_render_thread_begin_scene);
REFERENCE_DECLARE(0x050DADD8, IDirect3D9Ex*, c_rasterizer::g_direct3d);
REFERENCE_DECLARE(0x050DADDC, IDirect3DDevice9Ex*, c_rasterizer::g_device);
REFERENCE_DECLARE_ARRAY(0x050DADE0, bool, c_rasterizer::byte_50DADE0, 3);
REFERENCE_DECLARE_ARRAY(0x050DADE4, IDirect3DQuery9*, c_rasterizer::dword_50DADE4, 3);
Expand All @@ -54,6 +57,7 @@ REFERENCE_DECLARE(0x050DD998, short_rectangle2d, c_rasterizer::g_last_viewport);
REFERENCE_DECLARE(0x050DD9A0, short_rectangle2d, c_rasterizer::g_last_scissor_rect);
REFERENCE_DECLARE(0x050DD9BC, dword, c_rasterizer::g_max_vs_gprs);
REFERENCE_DECLARE(0x050DD9C0, dword, c_rasterizer::g_max_ps_gprs);
REFERENCE_DECLARE(0x050DD9C4, long, c_rasterizer::g_adapter);

long render_debug_toggle_default_lightmaps_texaccum = 0;
REFERENCE_DECLARE(0x0191C920, bool, render_debug_toggle_default_static_lighting);
Expand Down Expand Up @@ -311,6 +315,8 @@ void __cdecl c_rasterizer::shell_initialize(bool window_exists, bool windowed)

if (!c_rasterizer::initialized)
{
//set_render_resolution(1920, 1080, true);

if (c_rasterizer::initialize_device(window_exists, windowed))
{
if (c_rasterizer::g_device)
Expand Down Expand Up @@ -566,24 +572,249 @@ void __cdecl c_rasterizer::end_high_quality_blend()
INVOKE(0x00A21880, end_high_quality_blend);
}

decltype(Direct3DCreate9)* __cdecl GetDirect3DCreate9()
{
return INVOKE(0x00A218E0, GetDirect3DCreate9);
}

decltype(Direct3DCreate9Ex)* __cdecl GetDirect3DCreate9Ex()
{
return INVOKE(0x00A21950, GetDirect3DCreate9Ex);
}

c_rasterizer::e_platform __cdecl c_rasterizer::get_runtime_platform()
{
return INVOKE(0x00A21A80, get_runtime_platform);

//return _platform_dx9;
}

bool __cdecl c_rasterizer::initialize_device(bool window_exists, bool windowed)
{
return INVOKE(0x00A21B40, initialize_device, window_exists, windowed);

//if (LoadLibraryA("d3dx9_43.dll"))
//{
// bool v3 = shell_application_type() == _shell_application_type_client;
//
// bool d3d9ex = v3;
// if (char const* command_line = shell_get_command_line())
// {
// if (strstr(command_line, "-d3d9ex") != 0)
// d3d9ex = true;
//
// if (strstr(command_line, "-nod3d9ex") != 0)
// d3d9ex = false;
// }
//
// if (d3d9ex)
// {
// IDirect3D9Ex* direct3d = NULL;
// decltype(Direct3DCreate9Ex)* Direct3DCreateEx = GetDirect3DCreate9Ex();
// if (SUCCEEDED(Direct3DCreateEx(D3D_SDK_VERSION, &direct3d)))
// g_direct3d = direct3d;
// else
// d3d9ex = false;
// }
//
// render_globals.is_d3d9ex = d3d9ex;
// if (!g_direct3d)
// {
// decltype(Direct3DCreate9)* Direct3DCreate = GetDirect3DCreate9();
// g_direct3d = (IDirect3D9Ex*)Direct3DCreate(D3D_SDK_VERSION);
// if (!g_direct3d)
// return false;
// }
//
// g_adapter = 0;
// if (!windowed)
// {
// if (v3)
// {
// long adapter = global_preferences_get_adapter();
// if (char const* command_line = shell_get_command_line())
// {
// if (char const* adapter_arg = strstr(command_line, "-adapter "))
// adapter = atol(adapter_arg + 9);
// }
//
// if (adapter == NONE)
// adapter = 0;
//
// g_adapter = adapter;
// }
// }
//
// if (v3)
// global_preferences_set_adapter(g_adapter);
//
// g_direct3d->GetDeviceCaps(g_adapter, windowed ? D3DDEVTYPE_NULLREF : D3DDEVTYPE_HAL, get_global_device_caps());
//
// bool vsync = global_preferences_get_vsync();
// if (strstr(shell_get_command_line(), "-no_vsync") != 0)
// vsync = false;
//
// //windowed_check(windowed);
// {
// bool window = true;
// if (shell_application_type() == _shell_application_type_client)
// {
// window = false;
// if (!windowed)
// window = !global_preferences_get_fullscreen();
// }
//
// if (shell_get_command_line())
// {
// if (strstr(shell_get_command_line(), "-fullscreen") != 0)
// window = false;
//
// if (strstr(shell_get_command_line(), "-window") != 0)
// window = true;
// }
//
// global_preferences_set_fullscreen(!window);
// }
//
// long width = 1152;
// long height = 640;
// long aspect_ratio = 0;
//
// if (v3)
// {
// //if (sub_A22920())
// if (DECLFUNC(0x00A22920, bool, __cdecl)())
// {
// global_preferences_get_screen_resolution(&width, &height);
// aspect_ratio = global_preferences_get_aspect_ratio();
// }
// }
//
// if (char const* command_line = shell_get_command_line())
// {
// char const* width_arg = strstr(command_line, "-width ");
// char const* height_arg = strstr(command_line, "-height ");
// if (width_arg && height_arg)
// {
// width = atol(width_arg + 7);
// height = atol(height_arg + 8);
// }
// }
//
// D3DDISPLAYMODE* global_display_mode = get_global_display_mode();
// g_direct3d->GetAdapterDisplayMode(g_adapter, global_display_mode);
//
// real real_aspect_ratio = 0.0f;
// if (global_display_mode->Height)
// real_aspect_ratio = (real)global_display_mode->Width / (real)global_display_mode->Height;
//
// if (!aspect_ratio)
// {
// if (v3)
// aspect_ratio = (real_aspect_ratio > 1.5) + 1;
// else
// aspect_ratio = 2;
// }
//
// if (width <= 0 || height <= 0)
// {
// switch (aspect_ratio)
// {
// case 1:
// {
// width = render_globals.resolution_width34;
// height = render_globals.resolution_height38;
// }
// break;
// case 2:
// {
// width = render_globals.width2C;
// height = render_globals.height30;
// }
// break;
// }
// }
//
// D3DPRESENT_PARAMETERS* presentation_parameters = get_presentation_parameters();
// csmemset(presentation_parameters, 0, sizeof(D3DPRESENT_PARAMETERS));
//
// presentation_parameters->Windowed = TRUE;
// presentation_parameters->SwapEffect = D3DSWAPEFFECT_DISCARD;
// presentation_parameters->EnableAutoDepthStencil = TRUE;
// presentation_parameters->AutoDepthStencilFormat = D3DFMT_D24S8;
// presentation_parameters->BackBufferCount = 2;
// presentation_parameters->BackBufferFormat = D3DFMT_A8R8G8B8;
// presentation_parameters->PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
//
// if (vsync)
// presentation_parameters->PresentationInterval = D3DPRESENT_INTERVAL_ONE;
//
// rasterizer_set_presentation_interval(vsync ? 1 : 5);
//
// if (window_exists)
// {
// g_windows_params.game_window_handle = GetDesktopWindow();
// }
// else
// {
// render_globals.back_buffer_width = width;
// render_globals.back_buffer_height = height;
// initialize_window();
// }
//
// set_render_resolution(width, height, global_preferences_get_fullscreen());
// presentation_parameters->BackBufferWidth = render_globals.back_buffer_width;
// presentation_parameters->BackBufferHeight = render_globals.back_buffer_height;
//
// if (v3)
// {
// global_preferences_set_screen_resolution(width, height);
// global_preferences_set_aspect_ratio(aspect_ratio);
// }
//
// if (SUCCEEDED(g_direct3d->CreateDevice(
// g_adapter,
// windowed ? D3DDEVTYPE_NULLREF : D3DDEVTYPE_HAL,
// g_windows_params.game_window_handle,
// D3DCREATE_PUREDEVICE | D3DCREATE_HARDWARE_VERTEXPROCESSING,
// get_presentation_parameters(),
// (IDirect3DDevice9**)&g_device)))
// {
// g_thread_owning_device = get_current_thread_index();
// g_render_thread = get_current_thread_index();
//
// g_device->GetDeviceCaps(get_global_device_caps());
//
// if (!windowed)
// {
// //sub_A1FCE0(true);
// DECLFUNC(0x00A1FCE0, void*, __cdecl, bool)(true);
// }
//
// c_d3d_resource_allocator::set_d3d_device(c_rasterizer::g_device);
// return true;
// }
//}
//else
//{
// MessageBoxA(NULL, "d3dx9_43.dll not found.", "Error", MB_OK);
//}
//
//return false;
}

void __cdecl c_rasterizer::rasterizer_device_acquire_thread()
{
INVOKE(0x00A222D0, rasterizer_device_acquire_thread);

//g_thread_owning_device = get_current_thread_index();
}

void __cdecl c_rasterizer::rasterizer_device_release_thread()
{
INVOKE(0x00A222F0, rasterizer_device_release_thread);

//g_thread_owning_device = NONE;
}

// get cursor image
Expand All @@ -604,6 +835,8 @@ HCURSOR __cdecl sub_A22340()
bool __cdecl c_rasterizer::rasterizer_thread_owns_device()
{
return INVOKE(0x00A22390, rasterizer_thread_owns_device);

//return g_thread_owning_device == get_current_thread_index();
}

void __cdecl c_rasterizer::initialize_window()
Expand Down
Loading

0 comments on commit 497c5ae

Please sign in to comment.