From 95bd71a23eec4d1499e976223a2b82a2ded273ad Mon Sep 17 00:00:00 2001 From: Hyper <34012267+hyperbx@users.noreply.github.com> Date: Fri, 17 Jan 2025 19:51:56 +0000 Subject: [PATCH] Implemented hidden config values, removed DLL exports (#112) --- UnleashedRecomp/exports.cpp | 11 +++---- UnleashedRecomp/exports.h | 6 ++-- UnleashedRecomp/framework.h | 15 --------- UnleashedRecomp/kernel/heap.cpp | 4 +-- UnleashedRecomp/kernel/io/file_system.cpp | 2 +- UnleashedRecomp/kernel/xam.cpp | 24 +++++++------- UnleashedRecomp/kernel/xam.h | 30 +++++++++--------- UnleashedRecomp/patches/misc_patches.cpp | 15 +++++++++ UnleashedRecomp/user/config.cpp | 7 +++-- UnleashedRecomp/user/config.h | 38 ++++++++++++++++------- UnleashedRecompLib/config/SWA.toml | 5 +++ 11 files changed, 89 insertions(+), 68 deletions(-) diff --git a/UnleashedRecomp/exports.cpp b/UnleashedRecomp/exports.cpp index 65b231a..15980ae 100644 --- a/UnleashedRecomp/exports.cpp +++ b/UnleashedRecomp/exports.cpp @@ -1,13 +1,12 @@ +#include #include +#include #include #include #include -#include -#include #include -#include -SWA_API void Game_PlaySound(const char* pName) +void Game_PlaySound(const char* pName) { if (EmbeddedPlayer::s_isActive) { @@ -29,12 +28,12 @@ SWA_API void Game_PlaySound(const char* pName) } } -SWA_API void Window_SetDisplay(int displayIndex) +void Window_SetDisplay(int displayIndex) { GameWindow::SetDisplay(displayIndex); } -SWA_API void Window_SetFullscreen(bool isEnabled) +void Window_SetFullscreen(bool isEnabled) { GameWindow::SetFullscreen(isEnabled); } diff --git a/UnleashedRecomp/exports.h b/UnleashedRecomp/exports.h index 71eec06..37a73b5 100644 --- a/UnleashedRecomp/exports.h +++ b/UnleashedRecomp/exports.h @@ -1,5 +1,5 @@ #pragma once -SWA_API void Game_PlaySound(const char* pName); -SWA_API void Window_SetDisplay(int displayIndex); -SWA_API void Window_SetFullscreen(bool isEnabled); +void Game_PlaySound(const char* pName); +void Window_SetDisplay(int displayIndex); +void Window_SetFullscreen(bool isEnabled); diff --git a/UnleashedRecomp/framework.h b/UnleashedRecomp/framework.h index 68ad36f..9bdf1cf 100644 --- a/UnleashedRecomp/framework.h +++ b/UnleashedRecomp/framework.h @@ -1,20 +1,5 @@ #pragma once -#ifdef _MSVC - #define SWA_DLLEXPORT __declspec(dllexport) - #define SWA_DLLIMPORT __declspec(dllimport) -#else - // TODO - #define SWA_DLLEXPORT - #define SWA_DLLIMPORT -#endif - -#ifdef SWA_IMPL -#define SWA_API extern "C" SWA_DLLEXPORT -#else -#define SWA_API extern "C" SWA_DLLIMPORT -#endif - #define PROC_ADDRESS(libraryName, procName) \ GetProcAddress(LoadLibrary(TEXT(libraryName)), procName) diff --git a/UnleashedRecomp/kernel/heap.cpp b/UnleashedRecomp/kernel/heap.cpp index 2f83f47..11753c2 100644 --- a/UnleashedRecomp/kernel/heap.cpp +++ b/UnleashedRecomp/kernel/heap.cpp @@ -100,7 +100,7 @@ uint32_t RtlSizeHeap(uint32_t heapHandle, uint32_t flags, uint32_t memoryPointer return 0; } -SWA_API uint32_t XAllocMem(uint32_t size, uint32_t flags) +uint32_t XAllocMem(uint32_t size, uint32_t flags) { void* ptr = (flags & 0x80000000) != 0 ? g_userHeap.AllocPhysical(size, (1ull << ((flags >> 24) & 0xF))) : @@ -113,7 +113,7 @@ SWA_API uint32_t XAllocMem(uint32_t size, uint32_t flags) return g_memory.MapVirtual(ptr); } -SWA_API void XFreeMem(uint32_t baseAddress, uint32_t flags) +void XFreeMem(uint32_t baseAddress, uint32_t flags) { if (baseAddress != NULL) g_userHeap.Free(g_memory.Translate(baseAddress)); diff --git a/UnleashedRecomp/kernel/io/file_system.cpp b/UnleashedRecomp/kernel/io/file_system.cpp index 0c669e6..c7e7ebc 100644 --- a/UnleashedRecomp/kernel/io/file_system.cpp +++ b/UnleashedRecomp/kernel/io/file_system.cpp @@ -78,7 +78,7 @@ struct FindHandle : KernelObject } }; -SWA_API FileHandle* XCreateFileA +FileHandle* XCreateFileA ( const char* lpFileName, uint32_t dwDesiredAccess, diff --git a/UnleashedRecomp/kernel/xam.cpp b/UnleashedRecomp/kernel/xam.cpp index 446c5ad..26aeecd 100644 --- a/UnleashedRecomp/kernel/xam.cpp +++ b/UnleashedRecomp/kernel/xam.cpp @@ -144,7 +144,7 @@ void XamRegisterContent(uint32_t type, const std::string_view name, const std::s XamRegisterContent(data, root); } -SWA_API uint32_t XamNotifyCreateListener(uint64_t qwAreas) +uint32_t XamNotifyCreateListener(uint64_t qwAreas) { auto* listener = CreateKernelObject(); @@ -153,7 +153,7 @@ SWA_API uint32_t XamNotifyCreateListener(uint64_t qwAreas) return GetKernelHandle(listener); } -SWA_API void XamNotifyEnqueueEvent(uint32_t dwId, uint32_t dwParam) +void XamNotifyEnqueueEvent(uint32_t dwId, uint32_t dwParam) { for (const auto& listener : gListeners) { @@ -164,7 +164,7 @@ SWA_API void XamNotifyEnqueueEvent(uint32_t dwId, uint32_t dwParam) } } -SWA_API bool XNotifyGetNext(uint32_t hNotification, uint32_t dwMsgFilter, be* pdwId, be* pParam) +bool XNotifyGetNext(uint32_t hNotification, uint32_t dwMsgFilter, be* pdwId, be* pParam) { auto& listener = *GetKernelObject(hNotification); @@ -205,7 +205,7 @@ SWA_API bool XNotifyGetNext(uint32_t hNotification, uint32_t dwMsgFilter, be* wszTitle, be* wszText, uint32_t cButtons, +uint32_t XamShowMessageBoxUI(uint32_t dwUserIndex, be* wszTitle, be* wszText, uint32_t cButtons, xpointer>* pwszButtons, uint32_t dwFocusButton, uint32_t dwFlags, be* pResult, XXOVERLAPPED* pOverlapped) { int button{}; @@ -255,7 +255,7 @@ SWA_API uint32_t XamShowMessageBoxUI(uint32_t dwUserIndex, be* wszTitl return 0; } -SWA_API uint32_t XamContentCreateEnumerator(uint32_t dwUserIndex, uint32_t DeviceID, uint32_t dwContentType, +uint32_t XamContentCreateEnumerator(uint32_t dwUserIndex, uint32_t DeviceID, uint32_t dwContentType, uint32_t dwContentFlags, uint32_t cItem, be* pcbBuffer, be* phEnum) { if (dwUserIndex != 0) @@ -276,7 +276,7 @@ SWA_API uint32_t XamContentCreateEnumerator(uint32_t dwUserIndex, uint32_t Devic return 0; } -SWA_API uint32_t XamEnumerate(uint32_t hEnum, uint32_t dwFlags, void* pvBuffer, uint32_t cbBuffer, be* pcItemsReturned, XXOVERLAPPED* pOverlapped) +uint32_t XamEnumerate(uint32_t hEnum, uint32_t dwFlags, void* pvBuffer, uint32_t cbBuffer, be* pcItemsReturned, XXOVERLAPPED* pOverlapped) { auto* enumerator = GetKernelObject(hEnum); const auto count = enumerator->Next(pvBuffer); @@ -290,7 +290,7 @@ SWA_API uint32_t XamEnumerate(uint32_t hEnum, uint32_t dwFlags, void* pvBuffer, return ERROR_SUCCESS; } -SWA_API uint32_t XamContentCreateEx(uint32_t dwUserIndex, const char* szRootName, const XCONTENT_DATA* pContentData, +uint32_t XamContentCreateEx(uint32_t dwUserIndex, const char* szRootName, const XCONTENT_DATA* pContentData, uint32_t dwContentFlags, be* pdwDisposition, be* pdwLicenseMask, uint32_t dwFileCacheSize, uint64_t uliContentSize, PXXOVERLAPPED pOverlapped) { @@ -359,13 +359,13 @@ SWA_API uint32_t XamContentCreateEx(uint32_t dwUserIndex, const char* szRootName return ERROR_PATH_NOT_FOUND; } -SWA_API uint32_t XamContentClose(const char* szRootName, XXOVERLAPPED* pOverlapped) +uint32_t XamContentClose(const char* szRootName, XXOVERLAPPED* pOverlapped) { gRootMap.erase(StringHash(szRootName)); return 0; } -SWA_API uint32_t XamContentGetDeviceData(uint32_t DeviceID, XDEVICE_DATA* pDeviceData) +uint32_t XamContentGetDeviceData(uint32_t DeviceID, XDEVICE_DATA* pDeviceData) { pDeviceData->DeviceID = DeviceID; pDeviceData->DeviceType = XCONTENTDEVICETYPE_HDD; @@ -381,7 +381,7 @@ SWA_API uint32_t XamContentGetDeviceData(uint32_t DeviceID, XDEVICE_DATA* pDevic return 0; } -SWA_API uint32_t XamInputGetCapabilities(uint32_t unk, uint32_t userIndex, uint32_t flags, XAMINPUT_CAPABILITIES* caps) +uint32_t XamInputGetCapabilities(uint32_t unk, uint32_t userIndex, uint32_t flags, XAMINPUT_CAPABILITIES* caps) { uint32_t result = hid::GetCapabilities(userIndex, caps); @@ -400,7 +400,7 @@ SWA_API uint32_t XamInputGetCapabilities(uint32_t unk, uint32_t userIndex, uint3 return result; } -SWA_API uint32_t XamInputGetState(uint32_t userIndex, uint32_t flags, XAMINPUT_STATE* state) +uint32_t XamInputGetState(uint32_t userIndex, uint32_t flags, XAMINPUT_STATE* state) { memset(state, 0, sizeof(*state)); @@ -464,7 +464,7 @@ SWA_API uint32_t XamInputGetState(uint32_t userIndex, uint32_t flags, XAMINPUT_S return ERROR_SUCCESS; } -SWA_API uint32_t XamInputSetState(uint32_t userIndex, uint32_t flags, XAMINPUT_VIBRATION* vibration) +uint32_t XamInputSetState(uint32_t userIndex, uint32_t flags, XAMINPUT_VIBRATION* vibration) { if (!hid::detail::IsInputDeviceController() || !Config::Vibration) return ERROR_SUCCESS; diff --git a/UnleashedRecomp/kernel/xam.h b/UnleashedRecomp/kernel/xam.h index 6d1f257..c593562 100644 --- a/UnleashedRecomp/kernel/xam.h +++ b/UnleashedRecomp/kernel/xam.h @@ -1,9 +1,9 @@ #pragma once #include -#define MSGID(Area, Number) (uint32_t)((uint16_t)(Area) << 16 | (uint16_t)(Number)) -#define MSG_AREA(msgid) (((msgid) >> 16) & 0xFFFF) -#define MSG_NUMBER(msgid) ((msgid) & 0xFFFF) +#define MSGID(Area, Number) (uint32_t)((uint16_t)(Area) << 16 | (uint16_t)(Number)) +#define MSG_AREA(msgid) (((msgid) >> 16) & 0xFFFF) +#define MSG_NUMBER(msgid) ((msgid) & 0xFFFF) XCONTENT_DATA XamMakeContent(uint32_t type, const std::string_view& name); void XamRegisterContent(const XCONTENT_DATA& data, const std::string_view& root); @@ -11,23 +11,23 @@ void XamRegisterContent(const XCONTENT_DATA& data, const std::string_view& root) std::string_view XamGetRootPath(const std::string_view& root); void XamRootCreate(const std::string_view& root, const std::string_view& path); -SWA_API uint32_t XamNotifyCreateListener(uint64_t qwAreas); -SWA_API void XamNotifyEnqueueEvent(uint32_t dwId, uint32_t dwParam); // i made it the fuck up -SWA_API bool XNotifyGetNext(uint32_t hNotification, uint32_t dwMsgFilter, be* pdwId, be* pParam); +uint32_t XamNotifyCreateListener(uint64_t qwAreas); +void XamNotifyEnqueueEvent(uint32_t dwId, uint32_t dwParam); // i made it the fuck up +bool XNotifyGetNext(uint32_t hNotification, uint32_t dwMsgFilter, be* pdwId, be* pParam); -SWA_API uint32_t XamShowMessageBoxUI(uint32_t dwUserIndex, be* wszTitle, be* wszText, uint32_t cButtons, +uint32_t XamShowMessageBoxUI(uint32_t dwUserIndex, be* wszTitle, be* wszText, uint32_t cButtons, xpointer>* pwszButtons, uint32_t dwFocusButton, uint32_t dwFlags, be* pResult, XXOVERLAPPED* pOverlapped); -SWA_API uint32_t XamContentCreateEnumerator(uint32_t dwUserIndex, uint32_t DeviceID, uint32_t dwContentType, +uint32_t XamContentCreateEnumerator(uint32_t dwUserIndex, uint32_t DeviceID, uint32_t dwContentType, uint32_t dwContentFlags, uint32_t cItem, be* pcbBuffer, be* phEnum); -SWA_API uint32_t XamEnumerate(uint32_t hEnum, uint32_t dwFlags, void* pvBuffer, uint32_t cbBuffer, be* pcItemsReturned, XXOVERLAPPED* pOverlapped); +uint32_t XamEnumerate(uint32_t hEnum, uint32_t dwFlags, void* pvBuffer, uint32_t cbBuffer, be* pcItemsReturned, XXOVERLAPPED* pOverlapped); -SWA_API uint32_t XamContentCreateEx(uint32_t dwUserIndex, const char* szRootName, const XCONTENT_DATA* pContentData, +uint32_t XamContentCreateEx(uint32_t dwUserIndex, const char* szRootName, const XCONTENT_DATA* pContentData, uint32_t dwContentFlags, be* pdwDisposition, be* pdwLicenseMask, uint32_t dwFileCacheSize, uint64_t uliContentSize, PXXOVERLAPPED pOverlapped); -SWA_API uint32_t XamContentGetDeviceData(uint32_t DeviceID, XDEVICE_DATA* pDeviceData); -SWA_API uint32_t XamContentClose(const char* szRootName, XXOVERLAPPED* pOverlapped); +uint32_t XamContentGetDeviceData(uint32_t DeviceID, XDEVICE_DATA* pDeviceData); +uint32_t XamContentClose(const char* szRootName, XXOVERLAPPED* pOverlapped); -SWA_API uint32_t XamInputGetCapabilities(uint32_t unk, uint32_t userIndex, uint32_t flags, XAMINPUT_CAPABILITIES* caps); -SWA_API uint32_t XamInputGetState(uint32_t userIndex, uint32_t flags, XAMINPUT_STATE* state); -SWA_API uint32_t XamInputSetState(uint32_t userIndex, uint32_t flags, XAMINPUT_VIBRATION* vibration); +uint32_t XamInputGetCapabilities(uint32_t unk, uint32_t userIndex, uint32_t flags, XAMINPUT_CAPABILITIES* caps); +uint32_t XamInputGetState(uint32_t userIndex, uint32_t flags, XAMINPUT_STATE* state); +uint32_t XamInputSetState(uint32_t userIndex, uint32_t flags, XAMINPUT_VIBRATION* vibration); diff --git a/UnleashedRecomp/patches/misc_patches.cpp b/UnleashedRecomp/patches/misc_patches.cpp index 33ac846..d6bb7d6 100644 --- a/UnleashedRecomp/patches/misc_patches.cpp +++ b/UnleashedRecomp/patches/misc_patches.cpp @@ -27,6 +27,11 @@ bool DisableEvilControlTutorialMidAsmHook(PPCRegister& r4, PPCRegister& r5) return r4.u32 == 1 && r5.u32 == 1; } +bool DisableDLCIconMidAsmHook() +{ + return Config::DisableDLCIcon; +} + void ToggleSubtitlesMidAsmHook(PPCRegister& r27) { auto pApplicationDocument = (SWA::CApplicationDocument*)g_memory.Translate(r27.u32); @@ -91,3 +96,13 @@ PPC_FUNC(sub_8305D5B8) __imp__sub_8305D5B8(ctx, base); } + +// Disable auto save warning. +PPC_FUNC_IMPL(__imp__sub_82586698); +PPC_FUNC(sub_82586698) +{ + if (Config::DisableAutoSaveWarning) + *(bool*)g_memory.Translate(0x83367BC2) = true; + + __imp__sub_82586698(ctx, base); +} diff --git a/UnleashedRecomp/user/config.cpp b/UnleashedRecomp/user/config.cpp index 7cad141..7d0b235 100644 --- a/UnleashedRecomp/user/config.cpp +++ b/UnleashedRecomp/user/config.cpp @@ -15,14 +15,14 @@ void Config::Load() { toml::parse_result toml; std::ifstream tomlStream(configPath); + if (tomlStream.is_open()) - { toml = toml::parse(tomlStream); - } for (auto def : g_configDefinitions) { def->ReadValue(toml); + #if _DEBUG LOGFN_UTILITY("{} (0x{:X})", def->GetDefinition().c_str(), (intptr_t)def->GetValue()); #endif @@ -46,6 +46,9 @@ void Config::Save() for (auto def : g_configDefinitions) { + if (def->IsHidden()) + continue; + auto isFirstSection = section.empty(); auto isDefWithSection = section != def->GetSection(); auto tomlDef = def->GetDefinition(isDefWithSection); diff --git a/UnleashedRecomp/user/config.h b/UnleashedRecomp/user/config.h index 157f3f0..852ef2b 100644 --- a/UnleashedRecomp/user/config.h +++ b/UnleashedRecomp/user/config.h @@ -8,6 +8,7 @@ class IConfigDef { public: virtual ~IConfigDef() = default; + virtual bool IsHidden() = 0; virtual void ReadValue(toml::v3::ex::parse_result& toml) = 0; virtual void MakeDefault() = 0; virtual std::string_view GetSection() const = 0; @@ -29,6 +30,9 @@ public: #define CONFIG_DEFINE(section, type, name, defaultValue) \ static inline ConfigDef name{section, #name, defaultValue}; +#define CONFIG_DEFINE_HIDDEN(section, type, name, defaultValue) \ + static inline ConfigDef name{section, #name, defaultValue}; + #define CONFIG_DEFINE_LOCALISED(section, type, name, defaultValue) \ static CONFIG_LOCALE g_##name##_locale; \ static inline ConfigDef name{section, #name, &g_##name##_locale, defaultValue}; @@ -267,7 +271,7 @@ CONFIG_DEFINE_ENUM_TEMPLATE(EUIScaleMode) { "Center", EUIScaleMode::Centre } }; -template +template class ConfigDef final : public IConfigDef { public: @@ -279,9 +283,10 @@ public: std::unordered_map* EnumTemplate; std::map EnumTemplateReverse{}; CONFIG_ENUM_LOCALE(T)* EnumLocale{}; - std::function*)> Callback; - std::function*)> LockCallback; - std::function*)> ApplyCallback; + std::function*)> Callback; + std::function*)> LockCallback; + std::function*)> ApplyCallback; + bool IsLoadedFromConfig{}; // CONFIG_DEFINE ConfigDef(std::string section, std::string name, T defaultValue) : Section(section), Name(name), DefaultValue(defaultValue) @@ -314,11 +319,16 @@ public: } // CONFIG_DEFINE_CALLBACK - ConfigDef(std::string section, std::string name, T defaultValue, std::function*)> callback) : Section(section), Name(name), DefaultValue(defaultValue), Callback(callback) + ConfigDef(std::string section, std::string name, T defaultValue, std::function*)> callback) : Section(section), Name(name), DefaultValue(defaultValue), Callback(callback) { g_configDefinitions.emplace_back(this); } + bool IsHidden() override + { + return isHidden; + } + void ReadValue(toml::v3::ex::parse_result& toml) override { if (auto pSection = toml[Section].as_table()) @@ -331,8 +341,9 @@ public: } else if constexpr (std::is_enum_v) { - std::string value = section[Name].value_or(std::string()); + auto value = section[Name].value_or(std::string()); auto it = EnumTemplate->find(value); + if (it != EnumTemplate->end()) { Value = it->second; @@ -349,6 +360,8 @@ public: if (Callback) Callback(this); + + IsLoadedFromConfig = true; } } @@ -650,12 +663,13 @@ public: CONFIG_DEFINE_LOCALISED("Video", bool, XboxColorCorrection, false); CONFIG_DEFINE_ENUM_LOCALISED("Video", EUIScaleMode, UIScaleMode, EUIScaleMode::Edge); - // TODO: remove these once the exports are implemented. - CONFIG_DEFINE("Exports", bool, AllowCancellingUnleash, false); - CONFIG_DEFINE("Exports", bool, FixUnleashOutOfControlDrain, false); - CONFIG_DEFINE("Exports", bool, HomingAttackOnBoost, true); - CONFIG_DEFINE("Exports", bool, SaveScoreAtCheckpoints, false); - CONFIG_DEFINE("Exports", bool, SkipIntroLogos, false); + CONFIG_DEFINE_HIDDEN("Exports", bool, AllowCancellingUnleash, false); + CONFIG_DEFINE_HIDDEN("Exports", bool, DisableAutoSaveWarning, false); + CONFIG_DEFINE_HIDDEN("Exports", bool, DisableDLCIcon, false); + CONFIG_DEFINE_HIDDEN("Exports", bool, FixUnleashOutOfControlDrain, false); + CONFIG_DEFINE_HIDDEN("Exports", bool, HomingAttackOnBoost, true); + CONFIG_DEFINE_HIDDEN("Exports", bool, SaveScoreAtCheckpoints, false); + CONFIG_DEFINE_HIDDEN("Exports", bool, SkipIntroLogos, false); static std::filesystem::path GetConfigPath() { diff --git a/UnleashedRecompLib/config/SWA.toml b/UnleashedRecompLib/config/SWA.toml index 10b9c2c..6161629 100644 --- a/UnleashedRecompLib/config/SWA.toml +++ b/UnleashedRecompLib/config/SWA.toml @@ -585,3 +585,8 @@ jump_address_on_false = 0x82536140 name = "RemoveMoviePlayerLetterboxMidAsmHook" address = 0x82B723A8 jump_address = 0x82B723BC + +[[midasm_hook]] +name = "DisableDLCIconMidAsmHook" +address = 0x825756B0 +jump_address_on_true = 0x825756E0