From fd379896d6ae16f91a85ee6039e22f6dc6bc5a33 Mon Sep 17 00:00:00 2001 From: Kenix3 Date: Tue, 2 Aug 2022 23:14:25 -0400 Subject: [PATCH] LUS Cleanup: Clean up hooks system. --- libultraship/libultraship/GameSettings.cpp | 4 ++-- libultraship/libultraship/Hooks.cpp | 10 --------- libultraship/libultraship/Hooks.h | 22 +++---------------- libultraship/libultraship/ImGuiImpl.cpp | 6 ++--- .../libultraship/Lib/Fast3D/gfx_dxgi.cpp | 2 +- .../libultraship/Lib/Fast3D/gfx_pc.cpp | 2 +- .../libultraship/Lib/Fast3D/gfx_sdl2.cpp | 4 ++-- libultraship/libultraship/Window.cpp | 15 +++++-------- .../libultraship/libultraship.vcxproj | 1 - .../libultraship/libultraship.vcxproj.filters | 3 --- soh/soh/OTRGlobals.cpp | 10 ++++----- soh/soh/OTRGlobals.h | 1 + soh/src/code/audioMgr.c | 4 ++-- .../ovl_kaleido_scope/z_kaleido_scope_PAL.c | 1 - 14 files changed, 26 insertions(+), 59 deletions(-) delete mode 100644 libultraship/libultraship/Hooks.cpp diff --git a/libultraship/libultraship/GameSettings.cpp b/libultraship/libultraship/GameSettings.cpp index e3f95ad76a3..d6af5139935 100644 --- a/libultraship/libultraship/GameSettings.cpp +++ b/libultraship/libultraship/GameSettings.cpp @@ -41,8 +41,8 @@ namespace Game { } void InitSettings() { - ModInternal::RegisterHook(UpdateAudio); - ModInternal::RegisterHook([] { + Ship::RegisterHook(UpdateAudio); + Ship::RegisterHook([] { gfx_get_current_rendering_api()->set_texture_filter((FilteringMode) CVar_GetS32("gTextureFilter", FILTER_THREE_POINT)); SohImGui::console->opened = CVar_GetS32("gConsoleEnabled", 0); SohImGui::controller->Opened = CVar_GetS32("gControllerConfigurationEnabled", 0); diff --git a/libultraship/libultraship/Hooks.cpp b/libultraship/libultraship/Hooks.cpp deleted file mode 100644 index 2b66ed318ee..00000000000 --- a/libultraship/libultraship/Hooks.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "Hooks.h" -#include -#include -#include -#include -#include - -void ModInternal_ExecuteAudioInitHooks() { - ModInternal::ExecuteHooks(); -} diff --git a/libultraship/libultraship/Hooks.h b/libultraship/libultraship/Hooks.h index 411cffe42ef..5f29a831cd7 100644 --- a/libultraship/libultraship/Hooks.h +++ b/libultraship/libultraship/Hooks.h @@ -1,15 +1,12 @@ #pragma once -#ifdef __cplusplus - #include - #include "UltraController.h" -#include "Controller.h" #define DEFINE_HOOK(name, type) struct name { typedef std::function fn; } -namespace ModInternal { +namespace Ship { + class Controller; template struct RegisteredHooks { @@ -29,22 +26,9 @@ namespace ModInternal { } DEFINE_HOOK(ControllerRead, void(OSContPad* cont_pad)); - DEFINE_HOOK(ControllerRawInput, void(Ship::Controller* backend, uint32_t raw)); + DEFINE_HOOK(ControllerRawInput, void(Controller* backend, uint32_t raw)); DEFINE_HOOK(AudioInit, void()); DEFINE_HOOK(LoadTexture, void(const char* path, uint8_t** texture)); DEFINE_HOOK(GfxInit, void()); DEFINE_HOOK(ExitGame, void()); - -} - -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -void ModInternal_ExecuteAudioInitHooks(); - -#ifdef __cplusplus } -#endif diff --git a/libultraship/libultraship/ImGuiImpl.cpp b/libultraship/libultraship/ImGuiImpl.cpp index e6f7a31c68f..1a0a79bf91f 100644 --- a/libultraship/libultraship/ImGuiImpl.cpp +++ b/libultraship/libultraship/ImGuiImpl.cpp @@ -24,7 +24,7 @@ #include "Lib/stb/stb_image.h" #include "Lib/Fast3D/gfx_rendering_api.h" #include "Lib/spdlog/include/spdlog/common.h" -#include "Utils/StringHelper.h" +#include "UltraController.h" #if __APPLE__ #include @@ -385,7 +385,7 @@ namespace SohImGui { ImGui::GetStyle().ScaleAllSizes(2); #endif - ModInternal::RegisterHook([] { + Ship::RegisterHook([] { if (GlobalCtx2::GetInstance()->GetWindow()->IsFullscreen()) ShowCursor(CVar_GetS32("gOpenMenuBar", 0), Dialogues::dLoadSettings); @@ -402,7 +402,7 @@ namespace SohImGui { LoadTexture("C-Down", "assets/ship_of_harkinian/buttons/CDown.png"); }); - ModInternal::RegisterHook([](OSContPad* cont_pad) { + Ship::RegisterHook([](OSContPad* cont_pad) { pads = cont_pad; }); diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp index aabeb0acf80..1bf67891b20 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp @@ -240,7 +240,7 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par dxgi.current_height = (uint32_t)(l_param >> 16); break; case WM_DESTROY: - ModInternal::ExecuteHooks(); + Ship::ExecuteHooks(); exit(0); case WM_PAINT: if (dxgi.in_paint) { diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp index 25030afbee8..8aebec9e22c 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp @@ -2699,7 +2699,7 @@ void gfx_init(struct GfxWindowManagerAPI *wapi, struct GfxRenderingAPI *rapi, co //gfx_lookup_or_create_shader_program(precomp_shaders[i]); } - ModInternal::ExecuteHooks(); + Ship::ExecuteHooks(); } struct GfxRenderingAPI *gfx_get_current_rendering_api(void) { diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp index 2576bc17b19..06d88b78c4c 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp @@ -239,7 +239,7 @@ static void gfx_sdl_main_loop(void (*run_one_game_iter)(void)) { #ifdef __SWITCH__ Ship::Switch::Exit(); #endif - ModInternal::ExecuteHooks(); + Ship::ExecuteHooks(); } static void gfx_sdl_get_dimensions(uint32_t *width, uint32_t *height) { @@ -309,7 +309,7 @@ static void gfx_sdl_handle_events(void) { Game::SaveSettings(); break; case SDL_QUIT: - ModInternal::ExecuteHooks(); + Ship::ExecuteHooks(); SDL_Quit(); // bandaid fix for linux window closing issue exit(0); } diff --git a/libultraship/libultraship/Window.cpp b/libultraship/libultraship/Window.cpp index 9c11f2d6d5c..d3bdee369b7 100644 --- a/libultraship/libultraship/Window.cpp +++ b/libultraship/libultraship/Window.cpp @@ -1,7 +1,6 @@ #include "Window.h" #include "spdlog/spdlog.h" #include "KeyboardController.h" -#include "SDLController.h" #include "GlobalCtx2.h" #include "DisplayList.h" #include "Vertex.h" @@ -11,22 +10,20 @@ #include "Blob.h" #include "Matrix.h" #include "AudioPlayer.h" +#include "Hooks.h" +#include "UltraController.h" #include "WasapiAudioPlayer.h" #include "PulseAudioPlayer.h" -#include "SDLAudioPlayer.h" #include "Lib/Fast3D/gfx_pc.h" #include "Lib/Fast3D/gfx_sdl.h" #include "Lib/Fast3D/gfx_opengl.h" -#include "stox.h" #if __APPLE__ #include #else #include #endif -#include #include #include -#include "Hooks.h" #include "Console.h" #include "Cvar.h" @@ -80,7 +77,7 @@ extern "C" { Ship::GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck()->WriteToPad(pad); } - ModInternal::ExecuteHooks(pad); + Ship::ExecuteHooks(pad); } const char* ResourceMgr_GetNameByCRC(uint64_t crc) { @@ -126,7 +123,7 @@ extern "C" { if (hashStr != nullptr) { const auto res = LOAD_TEX(hashStr->c_str()); - ModInternal::ExecuteHooks(hashStr->c_str(), &res->imageData); + Ship::ExecuteHooks(hashStr->c_str(), &res->imageData); return reinterpret_cast(res->imageData); } else { @@ -153,7 +150,7 @@ extern "C" { char* ResourceMgr_LoadTexByName(char* texPath) { const auto res = LOAD_TEX(texPath); - ModInternal::ExecuteHooks(texPath, &res->imageData); + Ship::ExecuteHooks(texPath, &res->imageData); return (char*)res->imageData; } @@ -280,7 +277,7 @@ namespace Ship { WmApi->set_fullscreen_changed_callback(OnFullscreenChanged); WmApi->set_keyboard_callbacks(KeyDown, KeyUp, AllKeysUp); - ModInternal::RegisterHook([this]() { + Ship::RegisterHook([this]() { ControllerApi->SaveControllerSettings(); }); } diff --git a/libultraship/libultraship/libultraship.vcxproj b/libultraship/libultraship/libultraship.vcxproj index 52df7d3959d..95250d4b1a9 100644 --- a/libultraship/libultraship/libultraship.vcxproj +++ b/libultraship/libultraship/libultraship.vcxproj @@ -282,7 +282,6 @@ - diff --git a/libultraship/libultraship/libultraship.vcxproj.filters b/libultraship/libultraship/libultraship.vcxproj.filters index d807349a294..bf519368244 100644 --- a/libultraship/libultraship/libultraship.vcxproj.filters +++ b/libultraship/libultraship/libultraship.vcxproj.filters @@ -327,9 +327,6 @@ Source Files\ModManager - - Source Files\CustomImpl\Hooks - Source Files\Logging diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 2bdf80e682a..41347264ecd 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -4,9 +4,7 @@ #include #include #include -#include #include "GlobalCtx2.h" -#include "GameSettings.h" #include "ResourceMgr.h" #include "DisplayList.h" #include "PlayerAnimation.h" @@ -22,11 +20,9 @@ #else #include #endif -#include #include #include #include -#include #include "Lib/stb/stb_image.h" #define DRMP3_IMPLEMENTATION #include "Lib/dr_libs/mp3.h" @@ -40,10 +36,10 @@ #include #include "Enhancements/n64_weird_frame_data.inc" #include "soh/frame_interpolation.h" -#include "Utils/BitConverter.h" #include "variables.h" #include "macros.h" #include +#include "Hooks.h" #ifdef __APPLE__ #include @@ -1376,6 +1372,10 @@ extern "C" int Controller_ShouldRumble(size_t i) { return 0; } +extern "C" void Hooks_ExecuteAudioInit() { + Ship::ExecuteHooks(); +} + extern "C" void* getN64WeirdFrame(s32 i) { char* weirdFrameBytes = reinterpret_cast(n64WeirdFrames); return &weirdFrameBytes[i + sizeof(n64WeirdFrames)]; diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index d838b94dfd1..018c3c94146 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -85,6 +85,7 @@ int AudioPlayer_GetDesiredBuffered(void); void AudioPlayer_Play(const uint8_t* buf, uint32_t len); void AudioMgr_CreateNextAudioBuffer(s16* samples, u32 num_samples); int Controller_ShouldRumble(size_t i); +void Hooks_ExecuteAudioInit(); void* getN64WeirdFrame(s32 i); Sprite* GetSeedTexture(uint8_t index); void Randomizer_LoadSettings(const char* spoilerFileName); diff --git a/soh/src/code/audioMgr.c b/soh/src/code/audioMgr.c index dc826aa5c03..35c21ab950c 100644 --- a/soh/src/code/audioMgr.c +++ b/soh/src/code/audioMgr.c @@ -1,6 +1,6 @@ #include "global.h" -#include "Hooks.h" #include +#include "soh/OTRGlobals.h" void func_800C3C80(AudioMgr* audioMgr) { AudioTask* task; @@ -108,7 +108,7 @@ void AudioMgr_Init(AudioMgr* audioMgr, void* stack, OSPri pri, OSId id, SchedCon AudioLoad_SetDmaHandler(DmaMgr_DmaHandler); Audio_InitSound(); osSendMesgPtr(&audioMgr->unk_C8, NULL, OS_MESG_BLOCK); - ModInternal_ExecuteAudioInitHooks(); + Hooks_ExecuteAudioInit(); // Removed due to crash //IrqMgr_AddClient(audioMgr->irqMgr, &irqClient, &audioMgr->unk_74); hasInitialized = true; diff --git a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c index 2735ed9b426..66967e9a456 100644 --- a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c +++ b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c @@ -12,7 +12,6 @@ #include "textures/map_name_static/map_name_static.h" #include "textures/map_48x85_static/map_48x85_static.h" #include "vt.h" -#include "Hooks.h" #include "soh/frame_interpolation.h"