Skip to content

Commit

Permalink
tr2: port SE_ReadAppSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Dec 2, 2024
1 parent 181c3a0 commit 65ce5fd
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 10 deletions.
16 changes: 8 additions & 8 deletions docs/tr2/progress.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/tr2/progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4082,7 +4082,7 @@ typedef enum {
0x004523C0 0x004E -R bool __cdecl OpenGameRegistryKey(LPCTSTR key);
0x00452410 0x0005 -R LONG __cdecl CloseGameRegistryKey(void);
0x00452420 0x0262 -R bool __cdecl SE_WriteAppSettings(APP_SETTINGS *settings);
0x00452690 0x0348 -R int32_t __cdecl SE_ReadAppSettings(APP_SETTINGS *settings);
0x00452690 0x0348 +R int32_t __cdecl SE_ReadAppSettings(APP_SETTINGS *settings);
0x004529E0 0x00D7 -R bool __cdecl SE_GraphicsTestStart(void);
0x00452AB0 0x0014 -R void __cdecl SE_GraphicsTestFinish(void);
0x00452AD0 0x0003 -R int32_t __cdecl SE_GraphicsTestExecute(void);
Expand Down
1 change: 1 addition & 0 deletions src/tr2/decomp/decomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,4 @@ BOOL __cdecl S_LoadLevelFile(
const char *file_name, int32_t level_num, GAMEFLOW_LEVEL_TYPE level_type);
void __cdecl S_UnloadLevelFile(void);
BOOL __cdecl S_ReloadLevelGraphics(bool reload_palettes, bool reload_tex_pages);
int32_t __cdecl SE_ReadAppSettings(APP_SETTINGS *settings);
89 changes: 89 additions & 0 deletions src/tr2/decomp/decomp2.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "global/funcs.h"
#include "global/vars.h"

#include <libtrx/utils.h>
#include <libtrx/virtual_file.h>

int32_t __cdecl CreateTexturePage(
Expand Down Expand Up @@ -601,3 +602,91 @@ BOOL __cdecl S_ReloadLevelGraphics(

return true;
}

int32_t __cdecl SE_ReadAppSettings(APP_SETTINGS *const settings)
{
if (!OpenGameRegistryKey("System")) {
return 0;
}

bool rc;
GUID value;
rc = GetRegistryGuidValue("PreferredDisplayAdapterGUID", &value, 0);
settings->preferred_display_adapter =
WinVidGetDisplayAdapter(rc ? &value : 0);

settings->preferred_sound_adapter = NULL;
settings->preferred_joystick = NULL;

DISPLAY_MODE dm;
GetRegistryDwordValue(
"RenderMode", (DWORD *)&settings->render_mode, RM_HARDWARE);
GetRegistryBoolValue("Dither", &settings->dither, false);
GetRegistryBoolValue("ZBuffer", &settings->zbuffer, true);
GetRegistryBoolValue(
"BilinearFiltering", &settings->bilinear_filtering, true);
GetRegistryBoolValue("TripleBuffering", &settings->triple_buffering, false);
GetRegistryBoolValue("FullScreen", &settings->fullscreen, true);
GetRegistryDwordValue(
"WindowWidth", (DWORD *)&settings->window_width, 1280);
GetRegistryDwordValue(
"WindowHeight", (DWORD *)&settings->window_height, 720);
GetRegistryDwordValue(
"AspectMode", (DWORD *)&settings->aspect_mode, AM_4_3);
GetRegistryDwordValue("FullScreenWidth", (DWORD *)&dm.width, 1280);
GetRegistryDwordValue("FullScreenHeight", (DWORD *)&dm.height, 720);
GetRegistryDwordValue("FullScreenBPP", (DWORD *)&dm.bpp, 16);
GetRegistryBoolValue("SoundEnabled", &settings->sound_enabled, true);
GetRegistryBoolValue("LaraMic", &settings->lara_mic, false);
GetRegistryBoolValue("JoystickEnabled", &settings->joystick_enabled, true);
GetRegistryBoolValue(
"Disable16BitTextures", &settings->disable_16bit_textures, false);
GetRegistryBoolValue(
"DontSortPrimitives", &settings->dont_sort_primitives, false);
GetRegistryDwordValue(
"TexelAdjustMode", (DWORD *)&settings->texel_adjust_mode, TAM_ALWAYS);
GetRegistryDwordValue(
"NearestAdjustment", (DWORD *)&settings->nearest_adjustment, 16);
GetRegistryDwordValue(
"LinearAdjustment", (DWORD *)&settings->linear_adjustment, 128);
GetRegistryBoolValue("FlipBroken", &settings->flip_broken, false);

if (settings->render_mode != RM_HARDWARE
&& settings->render_mode != RM_SOFTWARE) {
settings->render_mode = RM_SOFTWARE;
}
if (settings->aspect_mode != AM_ANY && settings->aspect_mode != AM_16_9) {
settings->aspect_mode = AM_4_3;
}
if (settings->texel_adjust_mode != TAM_DISABLED
&& settings->texel_adjust_mode != TAM_BILINEAR_ONLY) {
settings->texel_adjust_mode = TAM_ALWAYS;
}
CLAMP(settings->nearest_adjustment, 0, 256);
CLAMP(settings->linear_adjustment, 0, 256);

GetRegistryBoolValue(
"PerspectiveCorrect", &settings->perspective_correct,
settings->render_mode != RM_SOFTWARE);

DISPLAY_MODE_LIST *disp_mode_list =
&settings->preferred_display_adapter->body.hw_disp_mode_list;
if (settings->render_mode == RM_SOFTWARE) {
dm.bpp = 8;
disp_mode_list =
&settings->preferred_display_adapter->body.sw_disp_mode_list;
}
dm.vga = VGA_NO_VGA;

const DISPLAY_MODE_NODE *head = disp_mode_list->head;
while (head != NULL) {
if (!CompareVideoModes(&head->body, &dm)) {
break;
}
head = head->next;
}
settings->video_mode = head;

CloseGameRegistryKey();
return IsNewRegistryKeyCreated() ? 2 : 1;
}
1 change: 0 additions & 1 deletion src/tr2/global/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@
#define OpenGameRegistryKey ((bool __cdecl (*)(LPCTSTR key))0x004523C0)
#define CloseGameRegistryKey ((LONG __cdecl (*)(void))0x00452410)
#define SE_WriteAppSettings ((bool __cdecl (*)(APP_SETTINGS *settings))0x00452420)
#define SE_ReadAppSettings ((int32_t __cdecl (*)(APP_SETTINGS *settings))0x00452690)
#define SE_GraphicsTestStart ((bool __cdecl (*)(void))0x004529E0)
#define SE_GraphicsTestFinish ((void __cdecl (*)(void))0x00452AB0)
#define SE_GraphicsTestExecute ((int32_t __cdecl (*)(void))0x00452AD0)
Expand Down
1 change: 1 addition & 0 deletions src/tr2/inject_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ static void M_DecompGeneral(const bool enable)
INJECT(enable, 0x00456430, EnumerateTextureFormats);
INJECT(enable, 0x00456460, CleanupTextures);
INJECT(enable, 0x00456470, InitTextures);
INJECT(enable, 0x00452690, SE_ReadAppSettings);
}

static void M_DecompFMV(const bool enable)
Expand Down

0 comments on commit 65ce5fd

Please sign in to comment.