From 974119e2eebe7eeb4af4e4ec4c4c5f8d038ea24c Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Fri, 26 Jul 2024 22:37:49 +0200 Subject: [PATCH] port Item_GetFrames --- docs/progress.svg | 16 ++++++++-------- docs/progress.txt | 2 +- src/game/items.c | 28 ++++++++++++++++++++++++++++ src/game/items.h | 2 ++ src/global/funcs.h | 1 - src/inject_exec.c | 1 + 6 files changed, 40 insertions(+), 10 deletions(-) diff --git a/docs/progress.svg b/docs/progress.svg index 3dfb1ea..2b7e89a 100644 --- a/docs/progress.svg +++ b/docs/progress.svg @@ -69,10 +69,10 @@ Tomb2.exe progress according to the physical function order: -48.44% (590) · 49.10% (598) · 0% (0) · 2.46% (30) +48.52% (591) · 49.01% (597) · 0% (0) · 2.46% (30) - - + + @@ -311,7 +311,7 @@ void __cdecl Matrix_InterpolateArm(void); void __cdecl Gun_DrawFlash(int32_t weapon_type, int32_t clip); void __cdecl Output_CalculateObjectLighting(ITEM_INFO *item, int16_t *frame); -int32_t __cdecl Item_GetFrames(const ITEM_INFO *item, int16_t *frmptr[], int32_t *rate); +int32_t __cdecl Item_GetFrames(const ITEM_INFO *item, int16_t *frmptr[], int32_t *rate); int16_t *__cdecl Item_GetBoundsAccurate(const ITEM_INFO *item); int16_t *__cdecl Item_GetBestFrame(const ITEM_INFO *item); void __cdecl AddDynamicLight(int32_t x, int32_t y, int32_t z, int32_t intensity, int32_t falloff); @@ -1298,10 +1298,10 @@ Tomb2.exe progress according to the function sizes: -46.56% · 53.11% · 0% · 0.33% +46.60% · 53.07% · 0% · 0.33% - - + + @@ -1875,7 +1875,7 @@ void __cdecl Misc_InitCinematicRooms(void); void __cdecl Effect_NewRoom(int16_t fx_num, int16_t room_num); void __cdecl SE_AdvancedDlgUpdate(HWND hwndDlg); -int32_t __cdecl Item_GetFrames(const ITEM_INFO *item, int16_t *frmptr[], int32_t *rate); +int32_t __cdecl Item_GetFrames(const ITEM_INFO *item, int16_t *frmptr[], int32_t *rate); void __cdecl Music_SetVolume(int32_t volume); const int16_t *__cdecl Output_InsertObjectGT4_ZBuffered(const int16_t *obj_ptr, int32_t num, SORT_TYPE sort_type); void __cdecl Lara_State_Extra_SharkKill(ITEM_INFO *item, COLL_INFO *coll); diff --git a/docs/progress.txt b/docs/progress.txt index 3165d48..902fe7d 100644 --- a/docs/progress.txt +++ b/docs/progress.txt @@ -2915,7 +2915,7 @@ typedef enum { 0x0041BC30 0x00FC + void __cdecl Matrix_InterpolateArm(void); 0x0041BD30 0x014B - void __cdecl Gun_DrawFlash(int32_t weapon_type, int32_t clip); 0x0041BEA0 0x00E8 - void __cdecl Output_CalculateObjectLighting(ITEM_INFO *item, int16_t *frame); -0x0041BF90 0x0092 * int32_t __cdecl Item_GetFrames(const ITEM_INFO *item, int16_t *frmptr[], int32_t *rate); +0x0041BF90 0x0092 + int32_t __cdecl Item_GetFrames(const ITEM_INFO *item, int16_t *frmptr[], int32_t *rate); 0x0041C030 0x007C * int16_t *__cdecl Item_GetBoundsAccurate(const ITEM_INFO *item); 0x0041C0B0 0x0035 - int16_t *__cdecl Item_GetBestFrame(const ITEM_INFO *item); 0x0041C0F0 0x0048 -R void __cdecl AddDynamicLight(int32_t x, int32_t y, int32_t z, int32_t intensity, int32_t falloff); diff --git a/src/game/items.c b/src/game/items.c index dab7d71..56451c0 100644 --- a/src/game/items.c +++ b/src/game/items.c @@ -660,3 +660,31 @@ int32_t __cdecl Item_IsTriggerActive(ITEM_INFO *const item) return ok; } + +int32_t __cdecl Item_GetFrames( + const ITEM_INFO *item, int16_t *frmptr[], int32_t *rate) +{ + const ANIM_STRUCT *const anim = &g_Anims[item->anim_num]; + const int32_t key_frame_span = anim->interpolation & 0xFF; + const int32_t size = anim->interpolation >> 8; + const int32_t cur_frame_num = item->frame_num - anim->frame_base; + const int32_t first_key_frame_num = cur_frame_num / key_frame_span * size; + const int32_t second_key_frame_num = first_key_frame_num + size; + frmptr[0] = anim->frame_ptr + first_key_frame_num; + frmptr[1] = anim->frame_ptr + second_key_frame_num; + const int32_t key_frame_shift = cur_frame_num % key_frame_span; + if (!key_frame_shift) { + return 0; + } + // TODO: ?? + const int32_t second_key_frame_num2 = + key_frame_span * (cur_frame_num / key_frame_span + 1); + const int32_t numerator = key_frame_shift; + int32_t denominator = key_frame_span; + if (second_key_frame_num2 > anim->frame_end) { + denominator += anim->frame_end - second_key_frame_num2; + } + + *rate = denominator; + return numerator; +} diff --git a/src/game/items.h b/src/game/items.h index 6ef994a..f9ce629 100644 --- a/src/game/items.h +++ b/src/game/items.h @@ -27,5 +27,7 @@ void __cdecl Item_Animate(ITEM_INFO *item); int32_t __cdecl Item_GetAnimChange(ITEM_INFO *item, const ANIM_STRUCT *anim); void __cdecl Item_Translate(ITEM_INFO *item, int32_t x, int32_t y, int32_t z); int32_t __cdecl Item_IsTriggerActive(ITEM_INFO *item); +int32_t __cdecl Item_GetFrames( + const ITEM_INFO *item, int16_t *frmptr[], int32_t *rate); bool Item_IsSmashable(const ITEM_INFO *item); diff --git a/src/global/funcs.h b/src/global/funcs.h index 2fb2d64..1b195f9 100644 --- a/src/global/funcs.h +++ b/src/global/funcs.h @@ -35,7 +35,6 @@ #define Lara_Draw_I ((void __cdecl (*)(ITEM_INFO *item, int16_t *frame1, int16_t *frame2, int32_t frac, int32_t rate))0x0041AB20) #define Gun_DrawFlash ((void __cdecl (*)(int32_t weapon_type, int32_t clip))0x0041BD30) #define Output_CalculateObjectLighting ((void __cdecl (*)(ITEM_INFO *item, int16_t *frame))0x0041BEA0) -#define Item_GetFrames ((int32_t __cdecl (*)(const ITEM_INFO *item, int16_t *frmptr[], int32_t *rate))0x0041BF90) #define Item_GetBoundsAccurate ((int16_t *__cdecl (*)(const ITEM_INFO *item))0x0041C030) #define Item_GetBestFrame ((int16_t *__cdecl (*)(const ITEM_INFO *item))0x0041C0B0) #define AddDynamicLight ((void __cdecl (*)(int32_t x, int32_t y, int32_t z, int32_t intensity, int32_t falloff))0x0041C0F0) diff --git a/src/inject_exec.c b/src/inject_exec.c index 106b286..8e3a4e2 100644 --- a/src/inject_exec.c +++ b/src/inject_exec.c @@ -484,6 +484,7 @@ static void Inject_Items(const bool enable) INJECT(enable, 0x00414A60, Item_GetAnimChange); INJECT(enable, 0x00414B10, Item_Translate); INJECT(enable, 0x004158D0, Item_IsTriggerActive); + INJECT(enable, 0x0041BF90, Item_GetFrames); } static void Inject_Effects(const bool enable)