From 45f78c92f051db15d7212a41db0037fdaebb3010 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Thu, 16 Nov 2023 20:14:19 +0100 Subject: [PATCH] port Random_GetControl --- docs/progress.svg | 16 ++++++++-------- docs/progress.txt | 4 ++-- src/game/camera.c | 1 + src/game/random.c | 10 +++++++++- src/game/random.h | 1 + src/global/funcs.h | 1 - src/global/vars.h | 1 - src/inject_exec.c | 1 + 8 files changed, 22 insertions(+), 13 deletions(-) diff --git a/docs/progress.svg b/docs/progress.svg index 4f6dda44..c13dad89 100644 --- a/docs/progress.svg +++ b/docs/progress.svg @@ -69,10 +69,10 @@ Tomb2.exe progress according to the physical function order: -28.90% (352) · 68.64% (836) · 0.66% (8) · 1.81% (22) +28.98% (353) · 68.56% (835) · 0.66% (8) · 1.81% (22) - - + + @@ -1074,7 +1074,7 @@ int32_t __cdecl LevelCompleteSequence(void); int32_t __cdecl LevelStats(int32_t levelID); int32_t __cdecl GameStats(int32_t levelID); -int32_t __cdecl Random_GetControl(void); +int32_t __cdecl Random_GetControl(void); void __cdecl Random_SeedControl(int32_t seed); int32_t __cdecl Random_GetDraw(void); void __cdecl Random_SeedDraw(int32_t seed); @@ -1299,10 +1299,10 @@ Tomb2.exe progress according to the function sizes: -27.75% · 71.92% · 0.02% · 0.31% +27.76% · 71.91% · 0.02% · 0.31% - - + + @@ -2393,7 +2393,7 @@ void __cdecl Text_CentreV(struct TEXTSTRING *string, int16_t enable); void __cdecl Text_AlignRight(struct TEXTSTRING *string, int16_t enable); void __cdecl Text_AlignBottom(struct TEXTSTRING *string, int16_t enable); -int32_t __cdecl Random_GetControl(void); +int32_t __cdecl Random_GetControl(void); int32_t __cdecl Random_GetDraw(void); LONG __cdecl SetRegistryDwordValue(LPCTSTR lpValueName, DWORD value); void __cdecl Matrix_Push(void); diff --git a/docs/progress.txt b/docs/progress.txt index ce43acce..9d518172 100644 --- a/docs/progress.txt +++ b/docs/progress.txt @@ -2708,7 +2708,7 @@ typedef enum GAME_OBJECT_ID { 0044C670 00000006 *R int32_t __cdecl LevelCompleteSequence(void); 0044C680 000001C2 -R int32_t __cdecl LevelStats(int32_t levelID); 0044C850 00000113 -R int32_t __cdecl GameStats(int32_t levelID); -0044C970 0000001E * int32_t __cdecl Random_GetControl(void); +0044C970 0000001E + int32_t __cdecl Random_GetControl(void); 0044C990 0000000A + void __cdecl Random_SeedControl(int32_t seed); 0044C9A0 0000001E - int32_t __cdecl Random_GetDraw(void); 0044C9C0 0000000A + void __cdecl Random_SeedDraw(int32_t seed); @@ -2952,7 +2952,7 @@ typedef enum GAME_OBJECT_ID { 004662E0 - int8_t g_TextASCIIMap[]; 00466480 - double g_GameSizer = 1.0; 00466488 - double g_GameSizerCopy = 1.0; -00466BB0 - int32_t g_RandControl; +00466BB0 + int32_t g_RandControl; 00466BB4 - int32_t g_RandDraw; 00466F70 - struct CONTROL_LAYOUT g_Layout[2]; 00467DD0 + const int32_t g_AtanBaseTable[8]; diff --git a/src/game/camera.c b/src/game/camera.c index 6e614117..fd7cf9bf 100644 --- a/src/game/camera.c +++ b/src/game/camera.c @@ -5,6 +5,7 @@ #include "game/matrix.h" #include "game/music.h" #include "game/output.h" +#include "game/random.h" #include "global/const.h" #include "global/funcs.h" #include "global/vars.h" diff --git a/src/game/random.c b/src/game/random.c index baf44643..f5f475d7 100644 --- a/src/game/random.c +++ b/src/game/random.c @@ -5,9 +5,11 @@ #include +static int32_t m_RandControl = 0xD371F947; + void __cdecl Random_SeedControl(const int32_t seed) { - g_RandControl = seed; + m_RandControl = seed; } void __cdecl Random_SeedDraw(const int32_t seed) @@ -15,6 +17,12 @@ void __cdecl Random_SeedDraw(const int32_t seed) g_RandDraw = seed; } +int32_t __cdecl Random_GetControl(void) +{ + m_RandControl = 0x41C64E6D * m_RandControl + 12345; + return (m_RandControl >> 10) & 0x7FFF; +} + void __cdecl Random_Seed(void) { time_t lt = time(0); diff --git a/src/game/random.h b/src/game/random.h index 26e313b2..2dc9c6f1 100644 --- a/src/game/random.h +++ b/src/game/random.h @@ -4,4 +4,5 @@ void __cdecl Random_SeedControl(int32_t seed); void __cdecl Random_SeedDraw(int32_t seed); +int32_t __cdecl Random_GetControl(void); void __cdecl Random_Seed(void); diff --git a/src/global/funcs.h b/src/global/funcs.h index 1326dcd2..22f72a51 100644 --- a/src/global/funcs.h +++ b/src/global/funcs.h @@ -662,7 +662,6 @@ #define LevelCompleteSequence ((int32_t __cdecl (*)(void))0x0044C670) #define LevelStats ((int32_t __cdecl (*)(int32_t levelID))0x0044C680) #define GameStats ((int32_t __cdecl (*)(int32_t levelID))0x0044C850) -#define Random_GetControl ((int32_t __cdecl (*)(void))0x0044C970) #define Random_GetDraw ((int32_t __cdecl (*)(void))0x0044C9A0) #define GetValidLevelsList ((void __cdecl (*)(REQUEST_INFO *req))0x0044C9D0) #define GetSavedGamesList ((void __cdecl (*)(REQUEST_INFO *req))0x0044CA20) diff --git a/src/global/vars.h b/src/global/vars.h index e299f6b8..3f9e69a8 100644 --- a/src/global/vars.h +++ b/src/global/vars.h @@ -22,7 +22,6 @@ #define g_TextASCIIMap (*(int8_t(*)[])0x004662E0) #define g_GameSizer (*(double*)0x00466480) // = 1.0 #define g_GameSizerCopy (*(double*)0x00466488) // = 1.0 -#define g_RandControl (*(int32_t*)0x00466BB0) #define g_RandDraw (*(int32_t*)0x00466BB4) #define g_Layout (*(struct CONTROL_LAYOUT(*)[2])0x00466F70) #define g_MidSort (*(int32_t*)0x0046C300) // = 0 diff --git a/src/inject_exec.c b/src/inject_exec.c index d26758c9..14afbdc6 100644 --- a/src/inject_exec.c +++ b/src/inject_exec.c @@ -231,6 +231,7 @@ static void Inject_Sound(void) static void Inject_Random(void) { + INJECT(1, 0x0044C970, Random_GetControl); INJECT(1, 0x0044C990, Random_SeedControl); INJECT(1, 0x0044C9C0, Random_SeedDraw); INJECT(1, 0x0044D870, Random_Seed);