From 60a106aa43a63260a40ac3bc3eb72b9679ba6550 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Thu, 5 Sep 2024 14:17:17 +0200 Subject: [PATCH] port AddAssaultTime --- docs/progress.svg | 16 ++++++++-------- docs/progress.txt | 2 +- src/decomp/stats.c | 26 ++++++++++++++++++++++++++ src/decomp/stats.h | 1 + src/global/const.h | 1 + src/global/funcs.h | 1 - src/inject_exec.c | 1 + 7 files changed, 38 insertions(+), 10 deletions(-) diff --git a/docs/progress.svg b/docs/progress.svg index 317b838a..a1f9ac52 100644 --- a/docs/progress.svg +++ b/docs/progress.svg @@ -69,10 +69,10 @@ Tomb2.exe progress according to the physical function order: -58.95% (718) · 38.59% (470) · 0% (0) · 2.46% (30) +59.03% (719) · 38.51% (469) · 0% (0) · 2.46% (30) - - + + @@ -448,7 +448,7 @@ void __cdecl Requester_ChangeItem(REQUEST_INFO *req, int32_t item, const char *text1, uint32_t flags1, const char *text2, uint32_t flags2); void __cdecl Requester_AddItem(REQUEST_INFO *req, const char *text1, uint32_t flags1, const char *text2, uint32_t flags2); void __cdecl Requester_SetSize(REQUEST_INFO *req, int32_t maxlines, int32_t ypos); -int32_t __cdecl AddAssaultTime(uint32_t time); +int32_t __cdecl AddAssaultTime(uint32_t time); void __cdecl ShowGymStatsText(char *time_str, int32_t type); void __cdecl ShowStatsText(char *time_str, int32_t type); void __cdecl ShowEndStatsText(void); @@ -1298,10 +1298,10 @@ Tomb2.exe progress according to the function sizes: -63.72% · 35.95% · 0% · 0.33% +63.76% · 35.91% · 0% · 0.33% - - + + @@ -1927,7 +1927,7 @@ void __cdecl HWR_EnableZBuffer(bool z_write_enable, bool z_enable); int32_t __cdecl Inv_AnimateInventoryItem(INVENTORY_ITEM *inv_item); void __cdecl RingIsNotOpen(RING_INFO *ring); -int32_t __cdecl AddAssaultTime(uint32_t time); +int32_t __cdecl AddAssaultTime(uint32_t time); void __cdecl Lara_Col_Stop(ITEM_INFO *item, COLL_INFO *coll); void __cdecl Lara_Col_Roll(ITEM_INFO *item, COLL_INFO *coll); void __cdecl SkidmanCollision(int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll); diff --git a/docs/progress.txt b/docs/progress.txt index d793224f..411455d3 100644 --- a/docs/progress.txt +++ b/docs/progress.txt @@ -3248,7 +3248,7 @@ typedef enum { 0x00426100 0x00C0 + void __cdecl Requester_ChangeItem(REQUEST_INFO *req, int32_t item, const char *text1, uint32_t flags1, const char *text2, uint32_t flags2); 0x004261C0 0x00AC + void __cdecl Requester_AddItem(REQUEST_INFO *req, const char *text1, uint32_t flags1, const char *text2, uint32_t flags2); 0x00426270 0x0039 + void __cdecl Requester_SetSize(REQUEST_INFO *req, int32_t maxlines, int32_t ypos); -0x004262B0 0x0081 -R int32_t __cdecl AddAssaultTime(uint32_t time); +0x004262B0 0x0081 +R int32_t __cdecl AddAssaultTime(uint32_t time); 0x00426340 0x01D6 +R void __cdecl ShowGymStatsText(char *time_str, int32_t type); 0x00426520 0x0397 +R void __cdecl ShowStatsText(char *time_str, int32_t type); 0x004268C0 0x0425 +R void __cdecl ShowEndStatsText(void); diff --git a/src/decomp/stats.c b/src/decomp/stats.c index 29e102d0..b1f407e0 100644 --- a/src/decomp/stats.c +++ b/src/decomp/stats.c @@ -394,3 +394,29 @@ int32_t __cdecl GameStats(const int32_t level_num) S_DontDisplayPicture(); return 0; } + +int32_t __cdecl AddAssaultTime(uint32_t time) +{ + ASSAULT_STATS *const stats = &g_Assault; + + int32_t insert_idx = -1; + for (int32_t i = 0; i < MAX_ASSAULT_TIMES; i++) { + if (stats->best_time[i] == 0 || time < stats->best_time[i]) { + insert_idx = i; + break; + } + } + if (insert_idx == -1) { + return false; + } + + for (int32_t i = MAX_ASSAULT_TIMES - 1; i > insert_idx; i--) { + stats->best_finish[i] = stats->best_finish[i - 1]; + stats->best_time[i] = stats->best_time[i - 1]; + } + + stats->finish_count++; + stats->best_time[insert_idx] = time; + stats->best_finish[insert_idx] = stats->finish_count; + return true; +} diff --git a/src/decomp/stats.h b/src/decomp/stats.h index b0c28be9..a1fd6447 100644 --- a/src/decomp/stats.h +++ b/src/decomp/stats.h @@ -8,3 +8,4 @@ void __cdecl ShowEndStatsText(void); int32_t __cdecl LevelStats(int32_t level_num); int32_t __cdecl GameStats(int32_t level_num); +int32_t __cdecl AddAssaultTime(uint32_t time); diff --git a/src/global/const.h b/src/global/const.h index 2069c2df..140332ba 100644 --- a/src/global/const.h +++ b/src/global/const.h @@ -55,6 +55,7 @@ #define MAX_DEMO_SIZE 9000 #define MAX_REQUESTER_ITEMS 24 #define MAX_SAVE_SLOTS 16 +#define MAX_ASSAULT_TIMES 10 #define TEXTURE_PAGE_WIDTH 256 #define TEXTURE_PAGE_HEIGHT 256 diff --git a/src/global/funcs.h b/src/global/funcs.h index e1ebe07e..45ab77a2 100644 --- a/src/global/funcs.h +++ b/src/global/funcs.h @@ -120,7 +120,6 @@ #define Inv_Ring_MotionCameraPitch ((void __cdecl (*)(RING_INFO *ring, int16_t target))0x004254B0) #define Inv_Ring_MotionItemSelect ((void __cdecl (*)(RING_INFO *ring, INVENTORY_ITEM *inv_item))0x004254D0) #define Inv_Ring_MotionItemDeselect ((void __cdecl (*)(RING_INFO *ring, INVENTORY_ITEM *inv_item))0x00425530) -#define AddAssaultTime ((int32_t __cdecl (*)(uint32_t time))0x004262B0) #define HarpoonBolt_Control ((void __cdecl (*)(int16_t item_num))0x0042C0F0) #define Rocket_Control ((void __cdecl (*)(int16_t item_num))0x0042C530) #define Flare_DoLight ((int32_t __cdecl (*)(XYZ_32 *pos, int32_t flare_age))0x0042F7A0) diff --git a/src/inject_exec.c b/src/inject_exec.c index dabe007f..131d6648 100644 --- a/src/inject_exec.c +++ b/src/inject_exec.c @@ -210,6 +210,7 @@ static void Inject_Decomp_General(const bool enable) static void Inject_Decomp_Stats(const bool enable) { + INJECT(enable, 0x004262B0, AddAssaultTime); INJECT(enable, 0x00426340, ShowGymStatsText); INJECT(enable, 0x00426520, ShowStatsText); INJECT(enable, 0x004268C0, ShowEndStatsText);