LUS Cleanup: Clean up hooks system.

This commit is contained in:
Kenix3 2022-08-02 23:14:25 -04:00
parent 8431cddb14
commit fd379896d6
14 changed files with 26 additions and 59 deletions

View File

@ -41,8 +41,8 @@ namespace Game {
} }
void InitSettings() { void InitSettings() {
ModInternal::RegisterHook<ModInternal::AudioInit>(UpdateAudio); Ship::RegisterHook<Ship::AudioInit>(UpdateAudio);
ModInternal::RegisterHook<ModInternal::GfxInit>([] { Ship::RegisterHook<Ship::GfxInit>([] {
gfx_get_current_rendering_api()->set_texture_filter((FilteringMode) CVar_GetS32("gTextureFilter", FILTER_THREE_POINT)); gfx_get_current_rendering_api()->set_texture_filter((FilteringMode) CVar_GetS32("gTextureFilter", FILTER_THREE_POINT));
SohImGui::console->opened = CVar_GetS32("gConsoleEnabled", 0); SohImGui::console->opened = CVar_GetS32("gConsoleEnabled", 0);
SohImGui::controller->Opened = CVar_GetS32("gControllerConfigurationEnabled", 0); SohImGui::controller->Opened = CVar_GetS32("gControllerConfigurationEnabled", 0);

View File

@ -1,10 +0,0 @@
#include "Hooks.h"
#include <map>
#include <string>
#include <vector>
#include <stdarg.h>
#include <iostream>
void ModInternal_ExecuteAudioInitHooks() {
ModInternal::ExecuteHooks<ModInternal::AudioInit>();
}

View File

@ -1,15 +1,12 @@
#pragma once #pragma once
#ifdef __cplusplus
#include <functional> #include <functional>
#include "UltraController.h" #include "UltraController.h"
#include "Controller.h"
#define DEFINE_HOOK(name, type) struct name { typedef std::function<type> fn; } #define DEFINE_HOOK(name, type) struct name { typedef std::function<type> fn; }
namespace ModInternal { namespace Ship {
class Controller;
template <typename H> template <typename H>
struct RegisteredHooks { struct RegisteredHooks {
@ -29,22 +26,9 @@ namespace ModInternal {
} }
DEFINE_HOOK(ControllerRead, void(OSContPad* cont_pad)); 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(AudioInit, void());
DEFINE_HOOK(LoadTexture, void(const char* path, uint8_t** texture)); DEFINE_HOOK(LoadTexture, void(const char* path, uint8_t** texture));
DEFINE_HOOK(GfxInit, void()); DEFINE_HOOK(GfxInit, void());
DEFINE_HOOK(ExitGame, void()); DEFINE_HOOK(ExitGame, void());
} }
#endif
#ifdef __cplusplus
extern "C" {
#endif
void ModInternal_ExecuteAudioInitHooks();
#ifdef __cplusplus
}
#endif

View File

@ -24,7 +24,7 @@
#include "Lib/stb/stb_image.h" #include "Lib/stb/stb_image.h"
#include "Lib/Fast3D/gfx_rendering_api.h" #include "Lib/Fast3D/gfx_rendering_api.h"
#include "Lib/spdlog/include/spdlog/common.h" #include "Lib/spdlog/include/spdlog/common.h"
#include "Utils/StringHelper.h" #include "UltraController.h"
#if __APPLE__ #if __APPLE__
#include <SDL_hints.h> #include <SDL_hints.h>
@ -385,7 +385,7 @@ namespace SohImGui {
ImGui::GetStyle().ScaleAllSizes(2); ImGui::GetStyle().ScaleAllSizes(2);
#endif #endif
ModInternal::RegisterHook<ModInternal::GfxInit>([] { Ship::RegisterHook<Ship::GfxInit>([] {
if (GlobalCtx2::GetInstance()->GetWindow()->IsFullscreen()) if (GlobalCtx2::GetInstance()->GetWindow()->IsFullscreen())
ShowCursor(CVar_GetS32("gOpenMenuBar", 0), Dialogues::dLoadSettings); ShowCursor(CVar_GetS32("gOpenMenuBar", 0), Dialogues::dLoadSettings);
@ -402,7 +402,7 @@ namespace SohImGui {
LoadTexture("C-Down", "assets/ship_of_harkinian/buttons/CDown.png"); LoadTexture("C-Down", "assets/ship_of_harkinian/buttons/CDown.png");
}); });
ModInternal::RegisterHook<ModInternal::ControllerRead>([](OSContPad* cont_pad) { Ship::RegisterHook<Ship::ControllerRead>([](OSContPad* cont_pad) {
pads = cont_pad; pads = cont_pad;
}); });

View File

@ -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); dxgi.current_height = (uint32_t)(l_param >> 16);
break; break;
case WM_DESTROY: case WM_DESTROY:
ModInternal::ExecuteHooks<ModInternal::ExitGame>(); Ship::ExecuteHooks<Ship::ExitGame>();
exit(0); exit(0);
case WM_PAINT: case WM_PAINT:
if (dxgi.in_paint) { if (dxgi.in_paint) {

View File

@ -2699,7 +2699,7 @@ void gfx_init(struct GfxWindowManagerAPI *wapi, struct GfxRenderingAPI *rapi, co
//gfx_lookup_or_create_shader_program(precomp_shaders[i]); //gfx_lookup_or_create_shader_program(precomp_shaders[i]);
} }
ModInternal::ExecuteHooks<ModInternal::GfxInit>(); Ship::ExecuteHooks<Ship::GfxInit>();
} }
struct GfxRenderingAPI *gfx_get_current_rendering_api(void) { struct GfxRenderingAPI *gfx_get_current_rendering_api(void) {

View File

@ -239,7 +239,7 @@ static void gfx_sdl_main_loop(void (*run_one_game_iter)(void)) {
#ifdef __SWITCH__ #ifdef __SWITCH__
Ship::Switch::Exit(); Ship::Switch::Exit();
#endif #endif
ModInternal::ExecuteHooks<ModInternal::ExitGame>(); Ship::ExecuteHooks<Ship::ExitGame>();
} }
static void gfx_sdl_get_dimensions(uint32_t *width, uint32_t *height) { 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(); Game::SaveSettings();
break; break;
case SDL_QUIT: case SDL_QUIT:
ModInternal::ExecuteHooks<ModInternal::ExitGame>(); Ship::ExecuteHooks<Ship::ExitGame>();
SDL_Quit(); // bandaid fix for linux window closing issue SDL_Quit(); // bandaid fix for linux window closing issue
exit(0); exit(0);
} }

View File

@ -1,7 +1,6 @@
#include "Window.h" #include "Window.h"
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#include "KeyboardController.h" #include "KeyboardController.h"
#include "SDLController.h"
#include "GlobalCtx2.h" #include "GlobalCtx2.h"
#include "DisplayList.h" #include "DisplayList.h"
#include "Vertex.h" #include "Vertex.h"
@ -11,22 +10,20 @@
#include "Blob.h" #include "Blob.h"
#include "Matrix.h" #include "Matrix.h"
#include "AudioPlayer.h" #include "AudioPlayer.h"
#include "Hooks.h"
#include "UltraController.h"
#include "WasapiAudioPlayer.h" #include "WasapiAudioPlayer.h"
#include "PulseAudioPlayer.h" #include "PulseAudioPlayer.h"
#include "SDLAudioPlayer.h"
#include "Lib/Fast3D/gfx_pc.h" #include "Lib/Fast3D/gfx_pc.h"
#include "Lib/Fast3D/gfx_sdl.h" #include "Lib/Fast3D/gfx_sdl.h"
#include "Lib/Fast3D/gfx_opengl.h" #include "Lib/Fast3D/gfx_opengl.h"
#include "stox.h"
#if __APPLE__ #if __APPLE__
#include <SDL.h> #include <SDL.h>
#else #else
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#endif #endif
#include <map>
#include <string> #include <string>
#include <chrono> #include <chrono>
#include "Hooks.h"
#include "Console.h" #include "Console.h"
#include "Cvar.h" #include "Cvar.h"
@ -80,7 +77,7 @@ extern "C" {
Ship::GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck()->WriteToPad(pad); Ship::GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck()->WriteToPad(pad);
} }
ModInternal::ExecuteHooks<ModInternal::ControllerRead>(pad); Ship::ExecuteHooks<Ship::ControllerRead>(pad);
} }
const char* ResourceMgr_GetNameByCRC(uint64_t crc) { const char* ResourceMgr_GetNameByCRC(uint64_t crc) {
@ -126,7 +123,7 @@ extern "C" {
if (hashStr != nullptr) { if (hashStr != nullptr) {
const auto res = LOAD_TEX(hashStr->c_str()); const auto res = LOAD_TEX(hashStr->c_str());
ModInternal::ExecuteHooks<ModInternal::LoadTexture>(hashStr->c_str(), &res->imageData); Ship::ExecuteHooks<Ship::LoadTexture>(hashStr->c_str(), &res->imageData);
return reinterpret_cast<char*>(res->imageData); return reinterpret_cast<char*>(res->imageData);
} else { } else {
@ -153,7 +150,7 @@ extern "C" {
char* ResourceMgr_LoadTexByName(char* texPath) { char* ResourceMgr_LoadTexByName(char* texPath) {
const auto res = LOAD_TEX(texPath); const auto res = LOAD_TEX(texPath);
ModInternal::ExecuteHooks<ModInternal::LoadTexture>(texPath, &res->imageData); Ship::ExecuteHooks<Ship::LoadTexture>(texPath, &res->imageData);
return (char*)res->imageData; return (char*)res->imageData;
} }
@ -280,7 +277,7 @@ namespace Ship {
WmApi->set_fullscreen_changed_callback(OnFullscreenChanged); WmApi->set_fullscreen_changed_callback(OnFullscreenChanged);
WmApi->set_keyboard_callbacks(KeyDown, KeyUp, AllKeysUp); WmApi->set_keyboard_callbacks(KeyDown, KeyUp, AllKeysUp);
ModInternal::RegisterHook<ModInternal::ExitGame>([this]() { Ship::RegisterHook<Ship::ExitGame>([this]() {
ControllerApi->SaveControllerSettings(); ControllerApi->SaveControllerSettings();
}); });
} }

View File

@ -282,7 +282,6 @@
<ClCompile Include="Factories\VtxFactory.cpp" /> <ClCompile Include="Factories\VtxFactory.cpp" />
<ClCompile Include="Array.cpp" /> <ClCompile Include="Array.cpp" />
<ClCompile Include="Controller.cpp" /> <ClCompile Include="Controller.cpp" />
<ClCompile Include="Hooks.cpp" />
<ClCompile Include="ImGuiImpl.cpp" /> <ClCompile Include="ImGuiImpl.cpp" />
<ClCompile Include="KeyboardController.cpp" /> <ClCompile Include="KeyboardController.cpp" />
<ClCompile Include="Factories\CollisionHeaderFactory.cpp" /> <ClCompile Include="Factories\CollisionHeaderFactory.cpp" />

View File

@ -327,9 +327,6 @@
<ClCompile Include="ModManager.cpp"> <ClCompile Include="ModManager.cpp">
<Filter>Source Files\ModManager</Filter> <Filter>Source Files\ModManager</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Hooks.cpp">
<Filter>Source Files\CustomImpl\Hooks</Filter>
</ClCompile>
<ClCompile Include="luslog.cpp"> <ClCompile Include="luslog.cpp">
<Filter>Source Files\Logging</Filter> <Filter>Source Files\Logging</Filter>
</ClCompile> </ClCompile>

View File

@ -4,9 +4,7 @@
#include <algorithm> #include <algorithm>
#include <filesystem> #include <filesystem>
#include <locale> #include <locale>
#include <codecvt>
#include "GlobalCtx2.h" #include "GlobalCtx2.h"
#include "GameSettings.h"
#include "ResourceMgr.h" #include "ResourceMgr.h"
#include "DisplayList.h" #include "DisplayList.h"
#include "PlayerAnimation.h" #include "PlayerAnimation.h"
@ -22,11 +20,9 @@
#else #else
#include <time.h> #include <time.h>
#endif #endif
#include <Vertex.h>
#include <CollisionHeader.h> #include <CollisionHeader.h>
#include <Array.h> #include <Array.h>
#include <Cutscene.h> #include <Cutscene.h>
#include <Texture.h>
#include "Lib/stb/stb_image.h" #include "Lib/stb/stb_image.h"
#define DRMP3_IMPLEMENTATION #define DRMP3_IMPLEMENTATION
#include "Lib/dr_libs/mp3.h" #include "Lib/dr_libs/mp3.h"
@ -40,10 +36,10 @@
#include <soh/Enhancements/randomizer/randomizer_item_tracker.h> #include <soh/Enhancements/randomizer/randomizer_item_tracker.h>
#include "Enhancements/n64_weird_frame_data.inc" #include "Enhancements/n64_weird_frame_data.inc"
#include "soh/frame_interpolation.h" #include "soh/frame_interpolation.h"
#include "Utils/BitConverter.h"
#include "variables.h" #include "variables.h"
#include "macros.h" #include "macros.h"
#include <Utils/StringHelper.h> #include <Utils/StringHelper.h>
#include "Hooks.h"
#ifdef __APPLE__ #ifdef __APPLE__
#include <SDL_scancode.h> #include <SDL_scancode.h>
@ -1376,6 +1372,10 @@ extern "C" int Controller_ShouldRumble(size_t i) {
return 0; return 0;
} }
extern "C" void Hooks_ExecuteAudioInit() {
Ship::ExecuteHooks<Ship::AudioInit>();
}
extern "C" void* getN64WeirdFrame(s32 i) { extern "C" void* getN64WeirdFrame(s32 i) {
char* weirdFrameBytes = reinterpret_cast<char*>(n64WeirdFrames); char* weirdFrameBytes = reinterpret_cast<char*>(n64WeirdFrames);
return &weirdFrameBytes[i + sizeof(n64WeirdFrames)]; return &weirdFrameBytes[i + sizeof(n64WeirdFrames)];

View File

@ -85,6 +85,7 @@ int AudioPlayer_GetDesiredBuffered(void);
void AudioPlayer_Play(const uint8_t* buf, uint32_t len); void AudioPlayer_Play(const uint8_t* buf, uint32_t len);
void AudioMgr_CreateNextAudioBuffer(s16* samples, u32 num_samples); void AudioMgr_CreateNextAudioBuffer(s16* samples, u32 num_samples);
int Controller_ShouldRumble(size_t i); int Controller_ShouldRumble(size_t i);
void Hooks_ExecuteAudioInit();
void* getN64WeirdFrame(s32 i); void* getN64WeirdFrame(s32 i);
Sprite* GetSeedTexture(uint8_t index); Sprite* GetSeedTexture(uint8_t index);
void Randomizer_LoadSettings(const char* spoilerFileName); void Randomizer_LoadSettings(const char* spoilerFileName);

View File

@ -1,6 +1,6 @@
#include "global.h" #include "global.h"
#include "Hooks.h"
#include <string.h> #include <string.h>
#include "soh/OTRGlobals.h"
void func_800C3C80(AudioMgr* audioMgr) { void func_800C3C80(AudioMgr* audioMgr) {
AudioTask* task; AudioTask* task;
@ -108,7 +108,7 @@ void AudioMgr_Init(AudioMgr* audioMgr, void* stack, OSPri pri, OSId id, SchedCon
AudioLoad_SetDmaHandler(DmaMgr_DmaHandler); AudioLoad_SetDmaHandler(DmaMgr_DmaHandler);
Audio_InitSound(); Audio_InitSound();
osSendMesgPtr(&audioMgr->unk_C8, NULL, OS_MESG_BLOCK); osSendMesgPtr(&audioMgr->unk_C8, NULL, OS_MESG_BLOCK);
ModInternal_ExecuteAudioInitHooks(); Hooks_ExecuteAudioInit();
// Removed due to crash // Removed due to crash
//IrqMgr_AddClient(audioMgr->irqMgr, &irqClient, &audioMgr->unk_74); //IrqMgr_AddClient(audioMgr->irqMgr, &irqClient, &audioMgr->unk_74);
hasInitialized = true; hasInitialized = true;

View File

@ -12,7 +12,6 @@
#include "textures/map_name_static/map_name_static.h" #include "textures/map_name_static/map_name_static.h"
#include "textures/map_48x85_static/map_48x85_static.h" #include "textures/map_48x85_static/map_48x85_static.h"
#include "vt.h" #include "vt.h"
#include "Hooks.h"
#include "soh/frame_interpolation.h" #include "soh/frame_interpolation.h"