mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2025-04-28 13:27:58 +03:00
Moved callbacks to config.cpp, fixed Subtitles option not applying to stages (#400)
This commit is contained in:
parent
431a6d9841
commit
414ccb3637
9 changed files with 62 additions and 86 deletions
|
@ -28,7 +28,7 @@ void App::Exit()
|
|||
std::_Exit(0);
|
||||
}
|
||||
|
||||
// SWA::CApplication
|
||||
// SWA::CApplication::CApplication
|
||||
PPC_FUNC_IMPL(__imp__sub_824EB490);
|
||||
PPC_FUNC(sub_824EB490)
|
||||
{
|
||||
|
@ -75,6 +75,10 @@ PPC_FUNC(sub_822C1130)
|
|||
AudioPatches::Update(App::s_deltaTime);
|
||||
InspirePatches::Update();
|
||||
|
||||
// Apply subtitles option.
|
||||
if (auto pApplicationDocument = SWA::CApplicationDocument::GetInstance())
|
||||
pApplicationDocument->m_InspireSubtitles = Config::Subtitles;
|
||||
|
||||
__imp__sub_822C1130(ctx, base);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,13 +31,3 @@ void Game_PlaySound(const char* pName)
|
|||
g_userHeap.Free(strAllocation);
|
||||
}
|
||||
}
|
||||
|
||||
void Window_SetDisplay(int displayIndex)
|
||||
{
|
||||
GameWindow::SetDisplay(displayIndex);
|
||||
}
|
||||
|
||||
void Window_SetFullscreen(bool isEnabled)
|
||||
{
|
||||
GameWindow::SetFullscreen(isEnabled);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
void Game_PlaySound(const char* pName);
|
||||
void Window_SetDisplay(int displayIndex);
|
||||
void Window_SetFullscreen(bool isEnabled);
|
||||
|
|
|
@ -43,13 +43,6 @@ bool DisableDLCIconMidAsmHook()
|
|||
return Config::DisableDLCIcon;
|
||||
}
|
||||
|
||||
void ToggleSubtitlesMidAsmHook(PPCRegister& r27)
|
||||
{
|
||||
auto pApplicationDocument = (SWA::CApplicationDocument*)g_memory.Translate(r27.u32);
|
||||
|
||||
pApplicationDocument->m_InspireSubtitles = Config::Subtitles;
|
||||
}
|
||||
|
||||
void WerehogBattleMusicMidAsmHook(PPCRegister& r11)
|
||||
{
|
||||
if (Config::BattleTheme)
|
||||
|
|
|
@ -173,27 +173,6 @@ void GameWindow::Init(const char* sdlVideoDriver)
|
|||
SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
|
||||
#endif
|
||||
|
||||
Config::WindowSize.LockCallback = [](ConfigDef<int32_t>* def)
|
||||
{
|
||||
// Try matching the current window size with a known configuration.
|
||||
if (def->Value < 0)
|
||||
def->Value = FindNearestDisplayMode();
|
||||
};
|
||||
|
||||
Config::WindowSize.ApplyCallback = [](ConfigDef<int32_t>* def)
|
||||
{
|
||||
auto displayModes = GetDisplayModes();
|
||||
|
||||
// Use largest supported resolution if overflowed.
|
||||
if (def->Value >= displayModes.size())
|
||||
def->Value = displayModes.size() - 1;
|
||||
|
||||
auto& mode = displayModes[def->Value];
|
||||
auto centre = SDL_WINDOWPOS_CENTERED_DISPLAY(GetDisplay());
|
||||
|
||||
SetDimensions(mode.w, mode.h, centre, centre);
|
||||
};
|
||||
|
||||
s_x = Config::WindowX;
|
||||
s_y = Config::WindowY;
|
||||
s_width = Config::WindowWidth;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "config.h"
|
||||
#include <os/logger.h>
|
||||
#include <ui/game_window.h>
|
||||
#include <user/paths.h>
|
||||
#include <exports.h>
|
||||
|
||||
std::vector<IConfigDef*> g_configDefinitions;
|
||||
|
||||
|
@ -407,11 +407,6 @@ CONFIG_DEFINE_ENUM_TEMPLATE(EUIAlignmentMode)
|
|||
extern CONFIG_ENUM_LOCALE(type) g_##type##_locale; \
|
||||
ConfigDef<type> Config::name{section, #name, &g_##name##_locale, defaultValue, &g_##type##_template, &g_##type##_locale};
|
||||
|
||||
#undef CONFIG_DEFINE_CALLBACK
|
||||
#define CONFIG_DEFINE_CALLBACK(section, type, name, defaultValue, readCallback) \
|
||||
extern CONFIG_LOCALE g_##name##_locale; \
|
||||
ConfigDef<type> Config::name{section, #name, defaultValue, [](ConfigDef<type>* def) readCallback};
|
||||
|
||||
#include "config_def.h"
|
||||
|
||||
// CONFIG_DEFINE
|
||||
|
@ -448,13 +443,6 @@ ConfigDef<T, isHidden>::ConfigDef(std::string section, std::string name, CONFIG_
|
|||
g_configDefinitions.emplace_back(this);
|
||||
}
|
||||
|
||||
// CONFIG_DEFINE_CALLBACK
|
||||
template<typename T, bool isHidden>
|
||||
ConfigDef<T, isHidden>::ConfigDef(std::string section, std::string name, T defaultValue, std::function<void(ConfigDef<T, isHidden>*)> callback) : Section(section), Name(name), DefaultValue(defaultValue), Callback(callback)
|
||||
{
|
||||
g_configDefinitions.emplace_back(this);
|
||||
}
|
||||
|
||||
template<typename T, bool isHidden>
|
||||
ConfigDef<T, isHidden>::~ConfigDef() = default;
|
||||
|
||||
|
@ -723,8 +711,54 @@ std::filesystem::path Config::GetConfigPath()
|
|||
return GetUserPath() / "config.toml";
|
||||
}
|
||||
|
||||
void Config::CreateCallbacks()
|
||||
{
|
||||
Config::WindowSize.LockCallback = [](ConfigDef<int32_t>* def)
|
||||
{
|
||||
// Try matching the current window size with a known configuration.
|
||||
if (def->Value < 0)
|
||||
def->Value = GameWindow::FindNearestDisplayMode();
|
||||
};
|
||||
|
||||
Config::WindowSize.ApplyCallback = [](ConfigDef<int32_t>* def)
|
||||
{
|
||||
auto displayModes = GameWindow::GetDisplayModes();
|
||||
|
||||
// Use largest supported resolution if overflowed.
|
||||
if (def->Value >= displayModes.size())
|
||||
def->Value = displayModes.size() - 1;
|
||||
|
||||
auto& mode = displayModes[def->Value];
|
||||
auto centre = SDL_WINDOWPOS_CENTERED_DISPLAY(GameWindow::GetDisplay());
|
||||
|
||||
GameWindow::SetDimensions(mode.w, mode.h, centre, centre);
|
||||
};
|
||||
|
||||
Config::Monitor.Callback = [](ConfigDef<int32_t>* def)
|
||||
{
|
||||
GameWindow::SetDisplay(def->Value);
|
||||
};
|
||||
|
||||
Config::Fullscreen.Callback = [](ConfigDef<bool>* def)
|
||||
{
|
||||
GameWindow::SetFullscreen(def->Value);
|
||||
GameWindow::SetDisplay(Config::Monitor);
|
||||
};
|
||||
|
||||
Config::ResolutionScale.Callback = [](ConfigDef<float>* def)
|
||||
{
|
||||
def->Value = std::clamp(def->Value, 0.25f, 2.0f);
|
||||
};
|
||||
}
|
||||
|
||||
void Config::Load()
|
||||
{
|
||||
if (!s_isCallbacksCreated)
|
||||
{
|
||||
CreateCallbacks();
|
||||
s_isCallbacksCreated = true;
|
||||
}
|
||||
|
||||
auto configPath = GetConfigPath();
|
||||
|
||||
if (!std::filesystem::exists(configPath))
|
||||
|
|
|
@ -25,6 +25,10 @@ public:
|
|||
#define CONFIG_LOCALE std::unordered_map<ELanguage, std::tuple<std::string, std::string>>
|
||||
#define CONFIG_ENUM_LOCALE(type) std::unordered_map<ELanguage, std::unordered_map<type, std::tuple<std::string, std::string>>>
|
||||
|
||||
#define CONFIG_CALLBACK(name) if (name.Callback) name.Callback(&name)
|
||||
#define CONFIG_LOCK_CALLBACK(name) if (name.LockCallback) name.LockCallback(&name)
|
||||
#define CONFIG_APPLY_CALLBACK(name) if (name.ApplyCallback) name.ApplyCallback(&name)
|
||||
|
||||
#define WINDOWPOS_CENTRED 0x2FFF0000
|
||||
|
||||
extern std::vector<IConfigDef*> g_configDefinitions;
|
||||
|
@ -174,9 +178,6 @@ public:
|
|||
// CONFIG_DEFINE_ENUM_LOCALISED
|
||||
ConfigDef(std::string section, std::string name, CONFIG_LOCALE* nameLocale, T defaultValue, std::unordered_map<std::string, T>* enumTemplate, CONFIG_ENUM_LOCALE(T)* enumLocale);
|
||||
|
||||
// CONFIG_DEFINE_CALLBACK
|
||||
ConfigDef(std::string section, std::string name, T defaultValue, std::function<void(ConfigDef<T, isHidden>*)> callback);
|
||||
|
||||
ConfigDef(const ConfigDef&) = delete;
|
||||
ConfigDef(ConfigDef&&) = delete;
|
||||
~ConfigDef();
|
||||
|
@ -221,15 +222,17 @@ public:
|
|||
#define CONFIG_DEFINE_LOCALISED(section, type, name, defaultValue) CONFIG_DECLARE(type, name)
|
||||
#define CONFIG_DEFINE_ENUM(section, type, name, defaultValue) CONFIG_DECLARE(type, name)
|
||||
#define CONFIG_DEFINE_ENUM_LOCALISED(section, type, name, defaultValue) CONFIG_DECLARE(type, name)
|
||||
#define CONFIG_DEFINE_CALLBACK(section, type, name, defaultValue, readCallback) CONFIG_DECLARE(type, name)
|
||||
|
||||
class Config
|
||||
{
|
||||
public:
|
||||
#include "config_def.h"
|
||||
|
||||
static inline bool s_isCallbacksCreated;
|
||||
|
||||
static std::filesystem::path GetConfigPath();
|
||||
|
||||
static void CreateCallbacks();
|
||||
static void Load();
|
||||
static void Save();
|
||||
};
|
||||
|
|
|
@ -54,30 +54,10 @@ CONFIG_DEFINE_LOCALISED("Video", int32_t, WindowSize, -1);
|
|||
CONFIG_DEFINE("Video", int32_t, WindowWidth, 1280);
|
||||
CONFIG_DEFINE("Video", int32_t, WindowHeight, 720);
|
||||
CONFIG_DEFINE_ENUM("Video", EWindowState, WindowState, EWindowState::Normal);
|
||||
|
||||
CONFIG_DEFINE_CALLBACK("Video", int32_t, Monitor, 0,
|
||||
{
|
||||
def->Locale = &g_Monitor_locale;
|
||||
|
||||
Window_SetDisplay(def->Value);
|
||||
});
|
||||
|
||||
CONFIG_DEFINE_LOCALISED("Video", int32_t, Monitor, 0);
|
||||
CONFIG_DEFINE_ENUM_LOCALISED("Video", EAspectRatio, AspectRatio, EAspectRatio::Auto);
|
||||
|
||||
CONFIG_DEFINE_CALLBACK("Video", float, ResolutionScale, 1.0f,
|
||||
{
|
||||
def->Locale = &g_ResolutionScale_locale;
|
||||
def->Value = std::clamp(def->Value, 0.25f, 2.0f);
|
||||
});
|
||||
|
||||
CONFIG_DEFINE_CALLBACK("Video", bool, Fullscreen, true,
|
||||
{
|
||||
def->Locale = &g_Fullscreen_locale;
|
||||
|
||||
Window_SetFullscreen(def->Value);
|
||||
Window_SetDisplay(Monitor);
|
||||
});
|
||||
|
||||
CONFIG_DEFINE_LOCALISED("Video", float, ResolutionScale, 1.0f);
|
||||
CONFIG_DEFINE_LOCALISED("Video", bool, Fullscreen, true);
|
||||
CONFIG_DEFINE_LOCALISED("Video", bool, VSync, true);
|
||||
CONFIG_DEFINE_ENUM("Video", ETripleBuffering, TripleBuffering, ETripleBuffering::Auto);
|
||||
CONFIG_DEFINE_LOCALISED("Video", int32_t, FPS, 60);
|
||||
|
|
|
@ -587,11 +587,6 @@ address = 0x824B08C0
|
|||
registers = ["r3"]
|
||||
return_on_true = true
|
||||
|
||||
[[midasm_hook]]
|
||||
name = "ToggleSubtitlesMidAsmHook"
|
||||
address = 0x82B9BB74
|
||||
registers = ["r27"]
|
||||
|
||||
[[midasm_hook]]
|
||||
name = "AchievementManagerUnlockMidAsmHook"
|
||||
address = 0x82BCFF28
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue