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() {
ModInternal::RegisterHook<ModInternal::AudioInit>(UpdateAudio);
ModInternal::RegisterHook<ModInternal::GfxInit>([] {
Ship::RegisterHook<Ship::AudioInit>(UpdateAudio);
Ship::RegisterHook<Ship::GfxInit>([] {
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);

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
#ifdef __cplusplus
#include <functional>
#include "UltraController.h"
#include "Controller.h"
#define DEFINE_HOOK(name, type) struct name { typedef std::function<type> fn; }
namespace ModInternal {
namespace Ship {
class Controller;
template <typename H>
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

View File

@ -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 <SDL_hints.h>
@ -385,7 +385,7 @@ namespace SohImGui {
ImGui::GetStyle().ScaleAllSizes(2);
#endif
ModInternal::RegisterHook<ModInternal::GfxInit>([] {
Ship::RegisterHook<Ship::GfxInit>([] {
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<ModInternal::ControllerRead>([](OSContPad* cont_pad) {
Ship::RegisterHook<Ship::ControllerRead>([](OSContPad* 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);
break;
case WM_DESTROY:
ModInternal::ExecuteHooks<ModInternal::ExitGame>();
Ship::ExecuteHooks<Ship::ExitGame>();
exit(0);
case WM_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]);
}
ModInternal::ExecuteHooks<ModInternal::GfxInit>();
Ship::ExecuteHooks<Ship::GfxInit>();
}
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__
Ship::Switch::Exit();
#endif
ModInternal::ExecuteHooks<ModInternal::ExitGame>();
Ship::ExecuteHooks<Ship::ExitGame>();
}
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<ModInternal::ExitGame>();
Ship::ExecuteHooks<Ship::ExitGame>();
SDL_Quit(); // bandaid fix for linux window closing issue
exit(0);
}

View File

@ -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 <SDL.h>
#else
#include <SDL2/SDL.h>
#endif
#include <map>
#include <string>
#include <chrono>
#include "Hooks.h"
#include "Console.h"
#include "Cvar.h"
@ -80,7 +77,7 @@ extern "C" {
Ship::GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck()->WriteToPad(pad);
}
ModInternal::ExecuteHooks<ModInternal::ControllerRead>(pad);
Ship::ExecuteHooks<Ship::ControllerRead>(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<ModInternal::LoadTexture>(hashStr->c_str(), &res->imageData);
Ship::ExecuteHooks<Ship::LoadTexture>(hashStr->c_str(), &res->imageData);
return reinterpret_cast<char*>(res->imageData);
} else {
@ -153,7 +150,7 @@ extern "C" {
char* ResourceMgr_LoadTexByName(char* 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;
}
@ -280,7 +277,7 @@ namespace Ship {
WmApi->set_fullscreen_changed_callback(OnFullscreenChanged);
WmApi->set_keyboard_callbacks(KeyDown, KeyUp, AllKeysUp);
ModInternal::RegisterHook<ModInternal::ExitGame>([this]() {
Ship::RegisterHook<Ship::ExitGame>([this]() {
ControllerApi->SaveControllerSettings();
});
}

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
#include "global.h"
#include "Hooks.h"
#include <string.h>
#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;

View File

@ -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"