Skip to content

Commit

Permalink
LUS Cleanup: Clean up hooks system.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenix3 committed Aug 4, 2022
1 parent 8431cdd commit fd37989
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 59 deletions.
4 changes: 2 additions & 2 deletions libultraship/libultraship/GameSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 0 additions & 10 deletions libultraship/libultraship/Hooks.cpp

This file was deleted.

22 changes: 3 additions & 19 deletions libultraship/libultraship/Hooks.h
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
6 changes: 3 additions & 3 deletions libultraship/libultraship/ImGuiImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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);

Expand All @@ -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;
});

Expand Down
2 changes: 1 addition & 1 deletion libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
15 changes: 6 additions & 9 deletions libultraship/libultraship/Window.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}

Expand Down Expand Up @@ -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();
});
}
Expand Down
1 change: 0 additions & 1 deletion libultraship/libultraship/libultraship.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
3 changes: 0 additions & 3 deletions libultraship/libultraship/libultraship.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
10 changes: 5 additions & 5 deletions soh/soh/OTRGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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>
Expand Down Expand Up @@ -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)];
Expand Down
1 change: 1 addition & 0 deletions soh/soh/OTRGlobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions soh/src/code/audioMgr.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "global.h"
#include "Hooks.h"
#include <string.h>
#include "soh/OTRGlobals.h"

void func_800C3C80(AudioMgr* audioMgr) {
AudioTask* task;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit fd37989

Please sign in to comment.