From 6eb5bee09af1bb9f162e664c5b230beee7eee462 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Fri, 17 Nov 2023 10:26:21 +0100 Subject: [PATCH] port Overlay_FlashCounter --- docs/progress.svg | 16 ++++++++-------- docs/progress.txt | 4 +++- meson.build | 1 + src/game/overlay.c | 18 ++++++++++++++++++ src/game/overlay.h | 5 +++++ src/global/funcs.h | 1 - src/inject_exec.c | 10 ++++++++++ 7 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 src/game/overlay.c create mode 100644 src/game/overlay.h diff --git a/docs/progress.svg b/docs/progress.svg index 2412d38..c169bd1 100644 --- a/docs/progress.svg +++ b/docs/progress.svg @@ -69,10 +69,10 @@ Tomb2.exe progress according to the physical function order: -29.06% (354) · 68.47% (834) · 0.66% (8) · 1.81% (22) +29.15% (355) · 68.39% (833) · 0.66% (8) · 1.81% (22) - - + + @@ -391,7 +391,7 @@ void __cdecl InitialiseHair(void); void __cdecl HairControl(int32_t in_cutscene); void __cdecl DrawHair(void); -int32_t __cdecl Overlay_FlashCounter(void); +int32_t __cdecl Overlay_FlashCounter(void); void __cdecl Overlay_DrawAssaultTimer(void); void __cdecl Overlay_DrawGameInfo(int32_t timed); void __cdecl Overlay_DrawHealthBar(int32_t flash_state); @@ -1299,10 +1299,10 @@ Tomb2.exe progress according to the function sizes: -27.77% · 71.90% · 0.02% · 0.31% +27.78% · 71.89% · 0.02% · 0.31% - - + + @@ -2305,7 +2305,7 @@ void __cdecl S_Audio_Sample_CloseAllTracks(void); void __cdecl S_DrawScreenFBox(int32_t sx, int32_t sy, int32_t z, int32_t width, int32_t height, BYTE color_idx, const struct GOURAUD_FILL *gour, uint16_t flags); void __cdecl Demo_GetInput(void); -int32_t __cdecl Overlay_FlashCounter(void); +int32_t __cdecl Overlay_FlashCounter(void); void __cdecl WinInStart(void); void __cdecl ChandelierFX(struct ITEM_INFO *item); void __cdecl Overlay_DrawModeInfo(void); diff --git a/docs/progress.txt b/docs/progress.txt index 7ce4d85..c0e8cae 100644 --- a/docs/progress.txt +++ b/docs/progress.txt @@ -1969,7 +1969,7 @@ typedef enum GAME_OBJECT_ID { 00421920 00000076 -R void __cdecl DrawHair(void); # game/health.c -004219A0 0000002D - int32_t __cdecl Overlay_FlashCounter(void); +004219A0 0000002D + int32_t __cdecl Overlay_FlashCounter(void); 004219D0 00000145 - void __cdecl Overlay_DrawAssaultTimer(void); 00421B20 00000045 - void __cdecl Overlay_DrawGameInfo(int32_t timed); 00421B70 000000AB - void __cdecl Overlay_DrawHealthBar(int32_t flash_state); @@ -3046,6 +3046,8 @@ typedef enum GAME_OBJECT_ID { 004D77A0 - int32_t g_LOSNumRooms = 0; 004D77AC - int32_t g_IsDemoLevelType; 004D780C - int8_t g_GF_StartGame; +004D7920 + BOOL g_FlashState; +004D7924 + int32_t g_FlashCounter; 004D7978 - uint16_t g_IsInventoryActive; 004D7C38 - int32_t g_LevelItemCount; 004D7C80 - int32_t g_SoundTrackIds[128]; diff --git a/meson.build b/meson.build index c51f81e..75471c1 100644 --- a/meson.build +++ b/meson.build @@ -91,6 +91,7 @@ dll_sources = [ 'src/game/matrix.c', 'src/game/music.c', 'src/game/output.c', + 'src/game/overlay.c', 'src/game/random.c', 'src/game/shell.c', 'src/game/sound.c', diff --git a/src/game/overlay.c b/src/game/overlay.c new file mode 100644 index 0000000..28c5d0d --- /dev/null +++ b/src/game/overlay.c @@ -0,0 +1,18 @@ +#include "game/overlay.h" + +#define FLASH_FRAMES 5 + +static bool m_FlashState = false; +static int32_t m_FlashCounter = 0; + +bool __cdecl Overlay_FlashCounter(void) +{ + if (m_FlashCounter > 0) { + m_FlashCounter--; + return m_FlashState; + } else { + m_FlashCounter = FLASH_FRAMES; + m_FlashState = !m_FlashState; + } + return m_FlashState; +} diff --git a/src/game/overlay.h b/src/game/overlay.h new file mode 100644 index 0000000..1b1e55c --- /dev/null +++ b/src/game/overlay.h @@ -0,0 +1,5 @@ +#pragma once + +#include "global/types.h" + +bool __cdecl Overlay_FlashCounter(void); diff --git a/src/global/funcs.h b/src/global/funcs.h index 4631b3f..11cd7c6 100644 --- a/src/global/funcs.h +++ b/src/global/funcs.h @@ -203,7 +203,6 @@ #define InitialiseHair ((void __cdecl (*)(void))0x00420EA0) #define HairControl ((void __cdecl (*)(int32_t in_cutscene))0x00420F20) #define DrawHair ((void __cdecl (*)(void))0x00421920) -#define Overlay_FlashCounter ((int32_t __cdecl (*)(void))0x004219A0) #define Overlay_DrawAssaultTimer ((void __cdecl (*)(void))0x004219D0) #define Overlay_DrawGameInfo ((void __cdecl (*)(int32_t timed))0x00421B20) #define Overlay_DrawHealthBar ((void __cdecl (*)(int32_t flash_state))0x00421B70) diff --git a/src/inject_exec.c b/src/inject_exec.c index b1d7a48..996b23f 100644 --- a/src/inject_exec.c +++ b/src/inject_exec.c @@ -15,6 +15,7 @@ #include "game/matrix.h" #include "game/music.h" #include "game/output.h" +#include "game/overlay.h" #include "game/random.h" #include "game/shell.h" #include "game/sound.h" @@ -34,6 +35,8 @@ static void Inject_Output(void); static void Inject_Music(void); static void Inject_Sound(void); +static void Inject_Overlay(void); +static void Inject_Random(void); static void Inject_Items(void); static void Inject_Effects(void); static void Inject_LOS(void); @@ -229,6 +232,11 @@ static void Inject_Sound(void) INJECT(1, 0x00455380, Sound_SetMasterVolume); } +static void Inject_Overlay(void) +{ + INJECT(1, 0x004219A0, Overlay_FlashCounter); +} + static void Inject_Random(void) { INJECT(1, 0x0044C970, Random_GetControl); @@ -489,6 +497,8 @@ void Inject_Exec(void) Inject_Music(); Inject_Sound(); + Inject_Overlay(); + Inject_Random(); Inject_Items(); Inject_Effects(); Inject_LOS();