From 7d8d4ced6403532d19cc438084b787fa9337f869 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Thu, 5 Sep 2024 01:35:20 +0200 Subject: [PATCH] port Option_Sound --- docs/progress.svg | 16 ++--- docs/progress.txt | 2 +- src/game/option/option.h | 1 + src/game/option/option_sound.c | 127 ++++++++++++++++++++++++++++++++- src/global/funcs.h | 1 - src/inject_exec.c | 1 + 6 files changed, 137 insertions(+), 11 deletions(-) diff --git a/docs/progress.svg b/docs/progress.svg index 82f5dba..0929786 100644 --- a/docs/progress.svg +++ b/docs/progress.svg @@ -69,10 +69,10 @@ Tomb2.exe progress according to the physical function order: -58.13% (708) · 39.41% (480) · 0% (0) · 2.46% (30) +58.21% (709) · 39.33% (479) · 0% (0) · 2.46% (30) - - + + @@ -1124,7 +1124,7 @@ void __cdecl Option_DoInventory(INVENTORY_ITEM *item); void __cdecl Option_Passport(INVENTORY_ITEM *item); void __cdecl Option_Detail(INVENTORY_ITEM *item); -void __cdecl Option_Sound(INVENTORY_ITEM *item); +void __cdecl Option_Sound(INVENTORY_ITEM *item); void __cdecl Option_Compass(INVENTORY_ITEM *item); void __cdecl Option_Controls_FlashConflicts(void); void __cdecl Option_Controls_DefaultConflict(void); @@ -1298,10 +1298,10 @@ Tomb2.exe progress according to the function sizes: -62.51% · 37.16% · 0% · 0.33% +62.86% · 36.82% · 0% · 0.33% - - + + @@ -1350,7 +1350,7 @@ void __cdecl MonkControl(int16_t item_num); LRESULT __stdcall WinVidGameWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); int32_t __cdecl SkidooDynamics(ITEM_INFO *skidoo); -void __cdecl Option_Sound(INVENTORY_ITEM *item); +void __cdecl Option_Sound(INVENTORY_ITEM *item); void __cdecl Sound_Effect(int32_t sample_id, const XYZ_32 *pos, uint32_t flags); void __cdecl PickUpCollision(int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll); int32_t __cdecl GF_InterpretSequence(int16_t *ptr, GF_LEVEL_TYPE type, int32_t seq_type); diff --git a/docs/progress.txt b/docs/progress.txt index 11ad2ca..201826f 100644 --- a/docs/progress.txt +++ b/docs/progress.txt @@ -3979,7 +3979,7 @@ typedef enum { 0x0044EDC0 0x007F + void __cdecl Option_DoInventory(INVENTORY_ITEM *item); 0x0044EED0 0x0648 + void __cdecl Option_Passport(INVENTORY_ITEM *item); 0x0044F520 0x02DA + void __cdecl Option_Detail(INVENTORY_ITEM *item); -0x0044F800 0x049D - void __cdecl Option_Sound(INVENTORY_ITEM *item); +0x0044F800 0x049D + void __cdecl Option_Sound(INVENTORY_ITEM *item); 0x0044FCA0 0x00C0 + void __cdecl Option_Compass(INVENTORY_ITEM *item); 0x0044FD60 0x007E + void __cdecl Option_Controls_FlashConflicts(void); 0x0044FDE0 0x0040 + void __cdecl Option_Controls_DefaultConflict(void); diff --git a/src/game/option/option.h b/src/game/option/option.h index de8f403..7990880 100644 --- a/src/game/option/option.h +++ b/src/game/option/option.h @@ -11,6 +11,7 @@ void __cdecl Option_Passport_Shutdown(void); void __cdecl Option_Detail(INVENTORY_ITEM *item); void __cdecl Option_Detail_Shutdown(void); +void __cdecl Option_Sound(INVENTORY_ITEM *item); void __cdecl Option_Sound_Shutdown(void); void __cdecl Option_Controls_FlashConflicts(void); diff --git a/src/game/option/option_sound.c b/src/game/option/option_sound.c index aec16ee..6cb73c0 100644 --- a/src/game/option/option_sound.c +++ b/src/game/option/option_sound.c @@ -1,12 +1,137 @@ +#include "game/music.h" #include "game/option/option.h" +#include "game/sound.h" #include "game/text.h" #include "global/funcs.h" #include "global/vars.h" -void Option_Sound_Shutdown(void) +#include + +#include + +static void Option_Sound_InitText(void); +static void Option_Sound_ShutdownText(void); + +static void Option_Sound_InitText(void) +{ + CLAMPG(g_OptionMusicVolume, 10); + CLAMPG(g_OptionSoundVolume, 10); + + char text[8]; + sprintf(text, "| %2d", g_OptionMusicVolume); + g_SoundText[0] = Text_Create(0, 0, 0, text); + Text_AddBackground(g_SoundText[0], 128, 0, 0, 0, 8, 0, 0, 0); + Text_AddOutline(g_SoundText[0], 1, 4, 0, 0); + + sprintf(text, "} %2d", g_OptionSoundVolume); + g_SoundText[1] = Text_Create(0, 25, 0, text); + + g_SoundText[2] = Text_Create(0, -32, 0, " "); + Text_AddBackground(g_SoundText[2], 140, 85, 0, 0, 48, 0, 0, 0); + Text_AddOutline(g_SoundText[2], 1, 15, 0, 0); + + g_SoundText[3] = + Text_Create(0, -30, 0, g_GF_PCStrings[GF_S_PC_SET_VOLUMES]); + Text_AddBackground(g_SoundText[3], 136, 0, 0, 0, 8, 0, 0, 0); + Text_AddOutline(g_SoundText[3], 1, 15, 0, 0); + + for (int32_t i = 0; i < 4; i++) { + Text_CentreH(g_SoundText[i], true); + Text_CentreV(g_SoundText[i], true); + } +} + +static void Option_Sound_ShutdownText(void) { for (int32_t i = 0; i < 4; i++) { Text_Remove(g_SoundText[i]); g_SoundText[i] = NULL; } } + +void Option_Sound_Shutdown(void) +{ + Option_Sound_ShutdownText(); +} + +void __cdecl Option_Sound(INVENTORY_ITEM *const item) +{ + char text[8]; + + if (g_SoundText[0] == NULL) { + Option_Sound_InitText(); + } + + if ((g_InputDB & IN_FORWARD) && g_SoundOptionLine > 0) { + Text_RemoveOutline(g_SoundText[g_SoundOptionLine]); + Text_RemoveBackground(g_SoundText[g_SoundOptionLine]); + g_SoundOptionLine--; + Text_AddBackground( + g_SoundText[g_SoundOptionLine], 128, 0, 0, 0, 8, 0, 0, 0); + Text_AddOutline(g_SoundText[g_SoundOptionLine], 1, 4, 0, 0); + } + + if ((g_InputDB & IN_BACK) && g_SoundOptionLine < 1) { + Text_RemoveOutline(g_SoundText[g_SoundOptionLine]); + Text_RemoveBackground(g_SoundText[g_SoundOptionLine]); + g_SoundOptionLine++; + Text_AddBackground( + g_SoundText[g_SoundOptionLine], 128, 0, 0, 0, 8, 0, 0, 0); + Text_AddOutline(g_SoundText[g_SoundOptionLine], 1, 4, 0, 0); + } + + if (g_SoundOptionLine) { + bool changed = false; + if ((g_Input & IN_LEFT) && g_OptionSoundVolume > 0) { + g_Inv_IsOptionsDelay = 1; + g_Inv_OptionsDelayCounter = 10; + g_OptionSoundVolume--; + changed = true; + } else if ((g_Input & IN_RIGHT) && g_OptionSoundVolume < 10) { + g_Inv_IsOptionsDelay = 1; + g_Inv_OptionsDelayCounter = 10; + g_OptionSoundVolume++; + changed = true; + } + + if (changed) { + sprintf(text, "} %2d", g_OptionSoundVolume); + Text_ChangeText(g_SoundText[1], text); + if (g_OptionSoundVolume) { + Sound_SetMasterVolume(6 * g_OptionSoundVolume + 4); + } else { + Sound_SetMasterVolume(0); + } + + Sound_Effect(SFX_MENU_PASSPORT, NULL, SPM_ALWAYS); + } + } else { + bool changed = false; + if ((g_Input & IN_LEFT) && g_OptionMusicVolume > 0) { + g_OptionMusicVolume--; + changed = true; + } else if ((g_Input & IN_RIGHT) && g_OptionMusicVolume < 10) { + g_OptionMusicVolume++; + changed = true; + } + + if (changed) { + g_Inv_IsOptionsDelay = 1; + g_Inv_OptionsDelayCounter = 10; + sprintf(text, "| %2d", g_OptionMusicVolume); + Text_ChangeText(g_SoundText[0], text); + + if (g_OptionMusicVolume) { + Music_SetVolume(25 * g_OptionMusicVolume + 5); + } else { + Music_SetVolume(0); + } + + Sound_Effect(SFX_MENU_PASSPORT, NULL, SPM_ALWAYS); + } + } + + if (g_InputDB & (IN_SELECT | IN_DESELECT)) { + Option_Sound_Shutdown(); + } +} diff --git a/src/global/funcs.h b/src/global/funcs.h index ce026b3..1d07737 100644 --- a/src/global/funcs.h +++ b/src/global/funcs.h @@ -356,7 +356,6 @@ #define game_malloc ((void *__cdecl (*)(size_t alloc_size, GAME_BUFFER buf_index))0x0044D6C0) #define game_free ((void __cdecl (*)(size_t free_size))0x0044D740) #define CalculateWibbleTable ((void __cdecl (*)(void))0x0044D780) -#define Option_Sound ((void __cdecl (*)(INVENTORY_ITEM *item))0x0044F800) #define GetRenderHeight ((int32_t __cdecl (*)(void))0x00450AE0) #define GetRenderWidth ((int32_t __cdecl (*)(void))0x00450AF0) #define S_InitialisePolyList ((void __cdecl (*)(BOOL clear_back_buffer))0x00450B00) diff --git a/src/inject_exec.c b/src/inject_exec.c index 6095a21..fe6f953 100644 --- a/src/inject_exec.c +++ b/src/inject_exec.c @@ -368,6 +368,7 @@ static void Inject_Option(const bool enable) INJECT(enable, 0x0044EDC0, Option_DoInventory); INJECT(enable, 0x0044EED0, Option_Passport); INJECT(enable, 0x0044F520, Option_Detail); + INJECT(enable, 0x0044F800, Option_Sound); INJECT(enable, 0x0044FCA0, Option_Compass); INJECT(enable, 0x0044FD60, Option_Controls_FlashConflicts); INJECT(enable, 0x0044FDE0, Option_Controls_DefaultConflict);