From a59317627fe78b4dfe9e0482187ea5b497e3c5bc Mon Sep 17 00:00:00 2001 From: Sirius902 <3645979-Sirius902@users.noreply.gitlab.com> Date: Sun, 3 Apr 2022 16:45:02 -0700 Subject: [PATCH 1/6] Fix Shadow Temple title card --- soh/src/code/z_actor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/soh/src/code/z_actor.c b/soh/src/code/z_actor.c index 92702f866..fee697055 100644 --- a/soh/src/code/z_actor.c +++ b/soh/src/code/z_actor.c @@ -766,9 +766,9 @@ void TitleCard_InitPlaceName(GlobalContext* globalCtx, TitleCardContext* titleCt break; case SCENE_JYASINZOU: texture = gSpiritTempleTitleCardENGTex; - break; + break; case SCENE_HAKADAN: - texture = gSpiritTempleTitleCardENGTex; + texture = gShadowTempleTitleCardENGTex; break; case SCENE_HAKADANCH: texture = gBottomOfTheWellTitleCardENGTex; From c1eb71fa3342ab44f7bf91648afc1e3a126c4485 Mon Sep 17 00:00:00 2001 From: Nicholas Estelami Date: Sun, 3 Apr 2022 15:48:44 -0400 Subject: [PATCH 2/6] Updated python script to use new "extract directory" mode. Additionally fixed oversight with audio files and bug in OTRGui. --- OTRExporter/OTRExporter/Main.cpp | 4 + OTRExporter/extract_assets.py | 99 ++----------------- OTRExporter/extract_assets_old.py | 125 ++++++++++++++++++++++++ OTRGui/src/game/game.cpp | 9 +- OTRGui/src/impl/extractor/extractor.cpp | 1 - ZAPDTR/ZAPD/Main.cpp | 12 --- ZAPDTR/ZAPD/ZFile.cpp | 26 +++++ 7 files changed, 167 insertions(+), 109 deletions(-) create mode 100644 OTRExporter/extract_assets_old.py diff --git a/OTRExporter/OTRExporter/Main.cpp b/OTRExporter/OTRExporter/Main.cpp index e62ed5ef4..a58f94ae3 100644 --- a/OTRExporter/OTRExporter/Main.cpp +++ b/OTRExporter/OTRExporter/Main.cpp @@ -78,6 +78,10 @@ static void ExporterProgramEnd() auto fileData = File::ReadAllBytes(item); otrArchive->AddFile(StringHelper::Split(item, "Extract\\")[1], (uintptr_t)fileData.data(), fileData.size()); } + + otrArchive->AddFile("Audiobank", (uintptr_t)Globals::Instance->GetBaseromFile("Audiobank").data(), Globals::Instance->GetBaseromFile("Audiobank").size()); + otrArchive->AddFile("Audioseq", (uintptr_t)Globals::Instance->GetBaseromFile("Audioseq").data(), Globals::Instance->GetBaseromFile("Audioseq").size()); + otrArchive->AddFile("Audiotable", (uintptr_t)Globals::Instance->GetBaseromFile("Audiotable").data(), Globals::Instance->GetBaseromFile("Audiotable").size()); } } diff --git a/OTRExporter/extract_assets.py b/OTRExporter/extract_assets.py index 2922bbf06..bb9ed177c 100755 --- a/OTRExporter/extract_assets.py +++ b/OTRExporter/extract_assets.py @@ -4,21 +4,11 @@ import argparse, json, os, signal, time, sys, shutil from multiprocessing import Pool, cpu_count, Event, Manager, ProcessError import shutil -def SignalHandler(sig, frame): - print(f'Signal {sig} received. Aborting...') - mainAbort.set() - # Don't exit immediately to update the extracted assets file. - -def BuildOTR(): - shutil.copyfile("baserom/Audiobank", "Extract/Audiobank") - shutil.copyfile("baserom/Audioseq", "Extract/Audioseq") - shutil.copyfile("baserom/Audiotable", "Extract/Audiotable") - +def BuildOTR(xmlPath): shutil.copytree("assets", "Extract/assets") execStr = "x64\\Release\\ZAPD.exe" if sys.platform == "win32" else "../ZAPD/ZAPD.out" - - execStr += " botr -se OTR" + execStr += " ed -i %s -b baserom.z64 -fl CFG\\filelists -o placeholder -osf placeholder -gsf 1 -rconf CFG/Config.xml -se OTR" % (xmlPath) print(execStr) exitValue = os.system(execStr) @@ -28,52 +18,12 @@ def BuildOTR(): print("Aborting...", file=os.sys.stderr) print("\n") -def ExtractFile(xmlPath, outputPath, outputSourcePath): - execStr = "x64\\Release\\ZAPD.exe" if sys.platform == "win32" else "../ZAPD/ZAPD.out" - execStr += " e -eh -i %s -b baserom/ -o %s -osf %s -gsf 1 -rconf CFG/Config.xml -se OTR" % (xmlPath, outputPath, outputSourcePath) - - if "overlays" in xmlPath: - execStr += " --static" - - print(execStr) - exitValue = os.system(execStr) - #exitValue = 0 - if exitValue != 0: - print("\n") - print("Error when extracting from file " + xmlPath, file=os.sys.stderr) - print("Aborting...", file=os.sys.stderr) - print("\n") - -def ExtractFunc(fullPath): - *pathList, xmlName = fullPath.split(os.sep) - objectName = os.path.splitext(xmlName)[0] - - outPath = os.path.join("..\\soh\\assets\\", *pathList[5:], objectName) - os.makedirs(outPath, exist_ok=True) - outSourcePath = outPath - - ExtractFile(fullPath, outPath, outSourcePath) - -def initializeWorker(abort, test): - global globalAbort - globalAbort = abort - - def main(): parser = argparse.ArgumentParser(description="baserom asset extractor") - parser.add_argument("-s", "--single", help="asset path relative to assets/, e.g. objects/gameplay_keep") - parser.add_argument("-f", "--force", help="Force the extraction of every xml instead of checking the touched ones.", action="store_true") - parser.add_argument("-u", "--unaccounted", help="Enables ZAPD unaccounted detector warning system.", action="store_true") parser.add_argument("-v", "--version", help="Sets game version.") args = parser.parse_args() - - global mainAbort - mainAbort = Event() - manager = Manager() - signal.signal(signal.SIGINT, SignalHandler) - - extractedAssetsTracker = manager.dict() - + + # TODO: Read from makerom file to automatically determine game version xmlVer = "GC_NMQ_D" if (args.version == "gc_pal_nmpq"): @@ -81,45 +31,10 @@ def main(): elif (args.version == "dbg_mq"): xmlVer = "GC_MQ_D" - asset_path = args.single - if asset_path is not None: - fullPath = os.path.join("..\\soh\\assets", "xml", asset_path + ".xml") - if not os.path.exists(fullPath): - print(f"Error. File {fullPath} doesn't exists.", file=os.sys.stderr) - exit(1) - - ExtractFunc(fullPath) - else: - extract_text_path = "assets/text/message_data.h" - if os.path.isfile(extract_text_path): - extract_text_path = None - extract_staff_text_path = "assets/text/message_data_staff.h" - if os.path.isfile(extract_staff_text_path): - extract_staff_text_path = None - - xmlFiles = [] - for currentPath, _, files in os.walk(os.path.join("..\\soh\\assets\\xml\\", xmlVer)): - for file in files: - fullPath = os.path.join(currentPath, file) - if file.endswith(".xml"): - xmlFiles.append(fullPath) - - try: - numCores = 2 - print("Extracting assets with " + str(numCores) + " CPU cores.") - with Pool(numCores, initializer=initializeWorker, initargs=(mainAbort, 0)) as p: - p.map(ExtractFunc, xmlFiles) - except Exception as e: - print("Warning: Multiprocessing exception ocurred.", file=os.sys.stderr) - print("Disabling mutliprocessing.", file=os.sys.stderr) - - initializeWorker(mainAbort, 0) - for singlePath in xmlFiles: - ExtractFunc(singlePath) - - - BuildOTR() + if (os.path.exists("Extract")): shutil.rmtree("Extract") + + BuildOTR("..\\soh\\assets\\xml\\" + xmlVer + "\\") if __name__ == "__main__": main() \ No newline at end of file diff --git a/OTRExporter/extract_assets_old.py b/OTRExporter/extract_assets_old.py new file mode 100644 index 000000000..2922bbf06 --- /dev/null +++ b/OTRExporter/extract_assets_old.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python3 + +import argparse, json, os, signal, time, sys, shutil +from multiprocessing import Pool, cpu_count, Event, Manager, ProcessError +import shutil + +def SignalHandler(sig, frame): + print(f'Signal {sig} received. Aborting...') + mainAbort.set() + # Don't exit immediately to update the extracted assets file. + +def BuildOTR(): + shutil.copyfile("baserom/Audiobank", "Extract/Audiobank") + shutil.copyfile("baserom/Audioseq", "Extract/Audioseq") + shutil.copyfile("baserom/Audiotable", "Extract/Audiotable") + + shutil.copytree("assets", "Extract/assets") + + execStr = "x64\\Release\\ZAPD.exe" if sys.platform == "win32" else "../ZAPD/ZAPD.out" + + execStr += " botr -se OTR" + + print(execStr) + exitValue = os.system(execStr) + if exitValue != 0: + print("\n") + print("Error when building the OTR file...", file=os.sys.stderr) + print("Aborting...", file=os.sys.stderr) + print("\n") + +def ExtractFile(xmlPath, outputPath, outputSourcePath): + execStr = "x64\\Release\\ZAPD.exe" if sys.platform == "win32" else "../ZAPD/ZAPD.out" + execStr += " e -eh -i %s -b baserom/ -o %s -osf %s -gsf 1 -rconf CFG/Config.xml -se OTR" % (xmlPath, outputPath, outputSourcePath) + + if "overlays" in xmlPath: + execStr += " --static" + + print(execStr) + exitValue = os.system(execStr) + #exitValue = 0 + if exitValue != 0: + print("\n") + print("Error when extracting from file " + xmlPath, file=os.sys.stderr) + print("Aborting...", file=os.sys.stderr) + print("\n") + +def ExtractFunc(fullPath): + *pathList, xmlName = fullPath.split(os.sep) + objectName = os.path.splitext(xmlName)[0] + + outPath = os.path.join("..\\soh\\assets\\", *pathList[5:], objectName) + os.makedirs(outPath, exist_ok=True) + outSourcePath = outPath + + ExtractFile(fullPath, outPath, outSourcePath) + +def initializeWorker(abort, test): + global globalAbort + globalAbort = abort + + +def main(): + parser = argparse.ArgumentParser(description="baserom asset extractor") + parser.add_argument("-s", "--single", help="asset path relative to assets/, e.g. objects/gameplay_keep") + parser.add_argument("-f", "--force", help="Force the extraction of every xml instead of checking the touched ones.", action="store_true") + parser.add_argument("-u", "--unaccounted", help="Enables ZAPD unaccounted detector warning system.", action="store_true") + parser.add_argument("-v", "--version", help="Sets game version.") + args = parser.parse_args() + + global mainAbort + mainAbort = Event() + manager = Manager() + signal.signal(signal.SIGINT, SignalHandler) + + extractedAssetsTracker = manager.dict() + + xmlVer = "GC_NMQ_D" + + if (args.version == "gc_pal_nmpq"): + xmlVer = "GC_NMQ_PAL_F" + elif (args.version == "dbg_mq"): + xmlVer = "GC_MQ_D" + + asset_path = args.single + if asset_path is not None: + fullPath = os.path.join("..\\soh\\assets", "xml", asset_path + ".xml") + if not os.path.exists(fullPath): + print(f"Error. File {fullPath} doesn't exists.", file=os.sys.stderr) + exit(1) + + ExtractFunc(fullPath) + else: + extract_text_path = "assets/text/message_data.h" + if os.path.isfile(extract_text_path): + extract_text_path = None + extract_staff_text_path = "assets/text/message_data_staff.h" + if os.path.isfile(extract_staff_text_path): + extract_staff_text_path = None + + xmlFiles = [] + for currentPath, _, files in os.walk(os.path.join("..\\soh\\assets\\xml\\", xmlVer)): + for file in files: + fullPath = os.path.join(currentPath, file) + if file.endswith(".xml"): + xmlFiles.append(fullPath) + + try: + numCores = 2 + print("Extracting assets with " + str(numCores) + " CPU cores.") + with Pool(numCores, initializer=initializeWorker, initargs=(mainAbort, 0)) as p: + p.map(ExtractFunc, xmlFiles) + except Exception as e: + print("Warning: Multiprocessing exception ocurred.", file=os.sys.stderr) + print("Disabling mutliprocessing.", file=os.sys.stderr) + + initializeWorker(mainAbort, 0) + for singlePath in xmlFiles: + ExtractFunc(singlePath) + + + BuildOTR() + shutil.rmtree("Extract") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/OTRGui/src/game/game.cpp b/OTRGui/src/game/game.cpp index 2f5512385..88bd7201f 100644 --- a/OTRGui/src/game/game.cpp +++ b/OTRGui/src/game/game.cpp @@ -87,10 +87,11 @@ void ExtractRom() if (MoonUtils::exists("Extract")) MoonUtils::rm("Extract"); MoonUtils::mkdir("Extract"); - MoonUtils::copy("tmp/baserom/Audiobank", "Extract/Audiobank"); - MoonUtils::copy("tmp/baserom/Audioseq", "Extract/Audioseq"); - MoonUtils::copy("tmp/baserom/Audiotable", "Extract/Audiotable"); - MoonUtils::copy("tmp/baserom/version", "Extract/version"); + //MoonUtils::copy("tmp/baserom/Audiobank", "Extract/Audiobank"); + //MoonUtils::copy("tmp/baserom/Audioseq", "Extract/Audioseq"); + //MoonUtils::copy("tmp/baserom/Audiotable", "Extract/Audiotable"); + //MoonUtils::copy("tmp/baserom/version", "Extract/version"); + MoonUtils::write("Extract/version", (char*)&version.crc, sizeof(version.crc)); MoonUtils::copy("assets/game/", "Extract/assets/"); diff --git a/OTRGui/src/impl/extractor/extractor.cpp b/OTRGui/src/impl/extractor/extractor.cpp index e28fa5513..a2eab1bb6 100644 --- a/OTRGui/src/impl/extractor/extractor.cpp +++ b/OTRGui/src/impl/extractor/extractor.cpp @@ -83,7 +83,6 @@ void startWorker(RomVersion version) { Util::write("tmp/baserom/version", (char*)&version.crc, sizeof(version.crc)); - if (oldExtractMode) { std::vector files; diff --git a/ZAPDTR/ZAPD/Main.cpp b/ZAPDTR/ZAPD/Main.cpp index 1a99d346a..dd53b9c67 100644 --- a/ZAPDTR/ZAPD/Main.cpp +++ b/ZAPDTR/ZAPD/Main.cpp @@ -387,18 +387,6 @@ int main(int argc, char* argv[]) { BuildAssetBlob(Globals::Instance->inputPath, Globals::Instance->outputPath); } - /* - else if (fileMode == ZFileMode::BuildOverlay) - { - ZOverlay* overlay = - ZOverlay::FromBuild(Path::GetDirectoryName(Globals::Instance->inputPath), - Path::GetDirectoryName(Globals::Instance->cfgPath)); - - if (overlay != nullptr) - File::WriteAllText(Globals::Instance->outputPath.string(), - overlay->GetSourceOutputCode("")); - } - */ if (exporterSet != nullptr && exporterSet->endProgramFunc != nullptr) exporterSet->endProgramFunc(); diff --git a/ZAPDTR/ZAPD/ZFile.cpp b/ZAPDTR/ZAPD/ZFile.cpp index b706c1914..9ff7a6823 100644 --- a/ZAPDTR/ZAPD/ZFile.cpp +++ b/ZAPDTR/ZAPD/ZFile.cpp @@ -823,6 +823,32 @@ void ZFile::GenerateSourceHeaderFiles() if (Globals::Instance->fileMode != ZFileMode::ExtractDirectory) File::WriteAllText(headerFilename, formatter.GetOutput()); + else if (Globals::Instance->sourceOutputPath != "") + { + std::string xmlPath = xmlFilePath.string(); + xmlPath = StringHelper::Replace(xmlPath, "\\", "/"); + auto pathList = StringHelper::Split(xmlPath, "/"); + std::string outPath = ""; + + for (int i = 0; i < 3; i++) + outPath += pathList[i] + "/"; + + for (int i = 5; i < pathList.size(); i++) + { + if (i == pathList.size() - 1) + { + outPath += Path::GetFileNameWithoutExtension(pathList[i]) + "/"; + outPath += outName.string() + ".h"; + } + else + outPath += pathList[i]; + + if (i < pathList.size() - 1) + outPath += "/"; + } + + File::WriteAllText(outPath, formatter.GetOutput()); + } } std::string ZFile::GetHeaderInclude() const From 64327fafb1a71c897006f4980d5231178641432a Mon Sep 17 00:00:00 2001 From: Sirius902 <10891979+Sirius902@users.noreply.github.com> Date: Wed, 6 Apr 2022 17:42:23 -0700 Subject: [PATCH 3/6] Make ResourceMgr and CVar more const correct, remove unnecessary const_cast (#118) --- libultraship/libultraship/Cvar.cpp | 24 ++++++------ libultraship/libultraship/Cvar.h | 24 ++++++------ libultraship/libultraship/GameSettings.cpp | 44 +++++++++++----------- libultraship/libultraship/SohConsole.cpp | 2 +- libultraship/libultraship/SohImGuiImpl.cpp | 30 +++++++-------- soh/soh/OTRGlobals.cpp | 36 +++++++++--------- soh/soh/OTRGlobals.h | 14 +++---- 7 files changed, 87 insertions(+), 87 deletions(-) diff --git a/libultraship/libultraship/Cvar.cpp b/libultraship/libultraship/Cvar.cpp index 306a18e83..91788fd48 100644 --- a/libultraship/libultraship/Cvar.cpp +++ b/libultraship/libultraship/Cvar.cpp @@ -5,16 +5,16 @@ std::map cvars; -CVar* CVar_GetVar(char* name) { +CVar* CVar_GetVar(const char* name) { std::string key(name); return cvars.contains(key) ? cvars[key] : nullptr; } -extern "C" CVar* CVar_Get(char* name) { +extern "C" CVar* CVar_Get(const char* name) { return CVar_GetVar(name); } -extern "C" s32 CVar_GetS32(char* name, s32 defaultValue) { +extern "C" s32 CVar_GetS32(const char* name, s32 defaultValue) { CVar* cvar = CVar_Get(name); if (cvar != nullptr) { @@ -25,7 +25,7 @@ extern "C" s32 CVar_GetS32(char* name, s32 defaultValue) { return defaultValue; } -extern "C" float CVar_GetFloat(char* name, float defaultValue) { +extern "C" float CVar_GetFloat(const char* name, float defaultValue) { CVar* cvar = CVar_Get(name); if (cvar != nullptr) { @@ -36,7 +36,7 @@ extern "C" float CVar_GetFloat(char* name, float defaultValue) { return defaultValue; } -extern "C" char* CVar_GetString(char* name, char* defaultValue) { +extern "C" char* CVar_GetString(const char* name, char* defaultValue) { CVar* cvar = CVar_Get(name); if (cvar != nullptr) { @@ -47,7 +47,7 @@ extern "C" char* CVar_GetString(char* name, char* defaultValue) { return defaultValue; } -extern "C" void CVar_SetS32(char* name, s32 value) { +extern "C" void CVar_SetS32(const char* name, s32 value) { CVar* cvar = CVar_Get(name); if (!cvar) { cvar = new CVar; @@ -57,7 +57,7 @@ extern "C" void CVar_SetS32(char* name, s32 value) { cvar->value.valueS32 = value; } -void CVar_SetFloat(char* name, float value) { +void CVar_SetFloat(const char* name, float value) { CVar* cvar = CVar_Get(name); if (!cvar) { cvar = new CVar; @@ -67,7 +67,7 @@ void CVar_SetFloat(char* name, float value) { cvar->value.valueFloat = value; } -void CVar_SetString(char* name, char* value) { +void CVar_SetString(const char* name, char* value) { CVar* cvar = CVar_Get(name); if (!cvar) { cvar = new CVar; @@ -78,23 +78,23 @@ void CVar_SetString(char* name, char* value) { } -extern "C" void CVar_RegisterS32(char* name, s32 defaultValue) { +extern "C" void CVar_RegisterS32(const char* name, s32 defaultValue) { CVar* cvar = CVar_Get(name); if (cvar == nullptr) CVar_SetS32(name, defaultValue); } -extern "C" void CVar_RegisterFloat(char* name, float defaultValue) { +extern "C" void CVar_RegisterFloat(const char* name, float defaultValue) { CVar* cvar = CVar_Get(name); if (cvar == nullptr) CVar_SetFloat(name, defaultValue); } -extern "C" void CVar_RegisterString(char* name, char* defaultValue) { +extern "C" void CVar_RegisterString(const char* name, char* defaultValue) { CVar* cvar = CVar_Get(name); if (cvar == nullptr) CVar_SetString(name, defaultValue); -} \ No newline at end of file +} diff --git a/libultraship/libultraship/Cvar.h b/libultraship/libultraship/Cvar.h index 7bac8f20b..a85bb8fd3 100644 --- a/libultraship/libultraship/Cvar.h +++ b/libultraship/libultraship/Cvar.h @@ -23,15 +23,15 @@ extern "C" //#include -CVar* CVar_Get(char* name); -s32 CVar_GetS32(char* name, s32 defaultValue); -float CVar_GetFloat(char* name, float defaultValue); -char* CVar_GetString(char* name, char* defaultValue); -void CVar_SetS32(char* name, s32 value); +CVar* CVar_Get(const char* name); +s32 CVar_GetS32(const char* name, s32 defaultValue); +float CVar_GetFloat(const char* name, float defaultValue); +char* CVar_GetString(const char* name, char* defaultValue); +void CVar_SetS32(const char* name, s32 value); -void CVar_RegisterS32(char* name, s32 defaultValue); -void CVar_RegisterFloat(char* name, float defaultValue); -void CVar_RegisterString(char* name, char* defaultValue); +void CVar_RegisterS32(const char* name, s32 defaultValue); +void CVar_RegisterFloat(const char* name, float defaultValue); +void CVar_RegisterString(const char* name, char* defaultValue); #ifdef __cplusplus }; @@ -42,8 +42,8 @@ void CVar_RegisterString(char* name, char* defaultValue); #include extern std::map cvars; -CVar* CVar_GetVar(char* name); -void CVar_SetFloat(char* name, float value); -void CVar_SetString(char* name, char* value); +CVar* CVar_GetVar(const char* name); +void CVar_SetFloat(const char* name, float value); +void CVar_SetString(const char* name, char* value); +#endif #endif -#endif \ No newline at end of file diff --git a/libultraship/libultraship/GameSettings.cpp b/libultraship/libultraship/GameSettings.cpp index 1186fa27c..f12042bc0 100644 --- a/libultraship/libultraship/GameSettings.cpp +++ b/libultraship/libultraship/GameSettings.cpp @@ -50,73 +50,73 @@ namespace Game { // Enhancements Settings.enhancements.fast_text = stob(Conf[EnhancementSection]["fast_text"]); - CVar_SetS32(const_cast("gFastText"), Settings.enhancements.fast_text); + CVar_SetS32("gFastText", Settings.enhancements.fast_text); Settings.enhancements.disable_lod = stob(Conf[EnhancementSection]["disable_lod"]); - CVar_SetS32(const_cast("gDisableLOD"), Settings.enhancements.disable_lod); + CVar_SetS32("gDisableLOD", Settings.enhancements.disable_lod); Settings.enhancements.animated_pause_menu = stob(Conf[EnhancementSection]["animated_pause_menu"]); - CVar_SetS32(const_cast("gPauseLiveLink"), Settings.enhancements.animated_pause_menu); + CVar_SetS32("gPauseLiveLink", Settings.enhancements.animated_pause_menu); Settings.enhancements.minimal_ui = stob(Conf[EnhancementSection]["minimal_ui"]); CVar_SetS32(const_cast("gMinimalUI"), Settings.enhancements.minimal_ui); // Audio Settings.audio.master = Ship::stof(Conf[AudioSection]["master"]); - CVar_SetFloat(const_cast("gGameMasterVolume"), Settings.audio.master); + CVar_SetFloat("gGameMasterVolume", Settings.audio.master); Settings.audio.music_main = Ship::stof(Conf[AudioSection]["music_main"]); - CVar_SetFloat(const_cast("gMainMusicVolume"), Settings.audio.music_main); + CVar_SetFloat("gMainMusicVolume", Settings.audio.music_main); Settings.audio.music_sub = Ship::stof(Conf[AudioSection]["music_sub"]); - CVar_SetFloat(const_cast("gSubMusicVolume"), Settings.audio.music_sub); + CVar_SetFloat("gSubMusicVolume", Settings.audio.music_sub); Settings.audio.sfx = Ship::stof(Conf[AudioSection]["sfx"]); - CVar_SetFloat(const_cast("gSFXMusicVolume"), Settings.audio.sfx); + CVar_SetFloat("gSFXMusicVolume", Settings.audio.sfx); Settings.audio.fanfare = Ship::stof(Conf[AudioSection]["fanfare"]); - CVar_SetFloat(const_cast("gFanfareVolume"), Settings.audio.fanfare); + CVar_SetFloat("gFanfareVolume", Settings.audio.fanfare); // Controllers Settings.controller.gyro_sensitivity = Ship::stof(Conf[ControllerSection]["gyro_sensitivity"]); - CVar_SetFloat(const_cast("gGyroSensitivity"), Settings.controller.gyro_sensitivity); + CVar_SetFloat("gGyroSensitivity", Settings.controller.gyro_sensitivity); Settings.controller.rumble_strength = Ship::stof(Conf[ControllerSection]["rumble_strength"]); - CVar_SetFloat(const_cast("gRumbleStrength"), Settings.controller.rumble_strength); + CVar_SetFloat("gRumbleStrength", Settings.controller.rumble_strength); Settings.controller.input_scale = Ship::stof(Conf[ControllerSection]["input_scale"]); - CVar_SetFloat(const_cast("gInputScale"), Settings.controller.input_scale); + CVar_SetFloat("gInputScale", Settings.controller.input_scale); Settings.controller.input_enabled = stob(Conf[ControllerSection]["input_enabled"]); - CVar_SetS32(const_cast("gInputEnabled"), Settings.controller.input_enabled); + CVar_SetS32("gInputEnabled", Settings.controller.input_enabled); // Cheats Settings.cheats.debug_mode = stob(Conf[CheatSection]["debug_mode"]); - CVar_SetS32(const_cast("gDebugEnabled"), Settings.cheats.debug_mode); + CVar_SetS32("gDebugEnabled", Settings.cheats.debug_mode); Settings.cheats.infinite_money = stob(Conf[CheatSection]["infinite_money"]); - CVar_SetS32(const_cast("gInfiniteMoney"), Settings.cheats.infinite_money); + CVar_SetS32("gInfiniteMoney", Settings.cheats.infinite_money); Settings.cheats.infinite_health = stob(Conf[CheatSection]["infinite_health"]); - CVar_SetS32(const_cast("gInfiniteHealth"), Settings.cheats.infinite_health); + CVar_SetS32("gInfiniteHealth", Settings.cheats.infinite_health); Settings.cheats.infinite_ammo = stob(Conf[CheatSection]["infinite_ammo"]); - CVar_SetS32(const_cast("gInfiniteAmmo"), Settings.cheats.infinite_ammo); + CVar_SetS32("gInfiniteAmmo", Settings.cheats.infinite_ammo); Settings.cheats.infinite_magic = stob(Conf[CheatSection]["infinite_magic"]); - CVar_SetS32(const_cast("gInfiniteMagic"), Settings.cheats.infinite_magic); + CVar_SetS32("gInfiniteMagic", Settings.cheats.infinite_magic); Settings.cheats.no_clip = stob(Conf[CheatSection]["no_clip"]); - CVar_SetS32(const_cast("gNoClip"), Settings.cheats.no_clip); + CVar_SetS32("gNoClip", Settings.cheats.no_clip); Settings.cheats.climb_everything = stob(Conf[CheatSection]["climb_everything"]); - CVar_SetS32(const_cast("gClimbEverything"), Settings.cheats.climb_everything); + CVar_SetS32("gClimbEverything", Settings.cheats.climb_everything); Settings.cheats.moon_jump_on_l = stob(Conf[CheatSection]["moon_jump_on_l"]); - CVar_SetS32(const_cast("gMoonJumpOnL"), Settings.cheats.moon_jump_on_l); + CVar_SetS32("gMoonJumpOnL", Settings.cheats.moon_jump_on_l); Settings.cheats.super_tunic = stob(Conf[CheatSection]["super_tunic"]); - CVar_SetS32(const_cast("gSuperTunic"), Settings.cheats.super_tunic); + CVar_SetS32("gSuperTunic", Settings.cheats.super_tunic); UpdateAudio(); } @@ -173,4 +173,4 @@ namespace Game { void SetSeqPlayerVolume(SeqPlayers playerId, float volume) { Audio_SetGameVolume(playerId, volume); } -} \ No newline at end of file +} diff --git a/libultraship/libultraship/SohConsole.cpp b/libultraship/libultraship/SohConsole.cpp index 71a067196..618cd1e1d 100644 --- a/libultraship/libultraship/SohConsole.cpp +++ b/libultraship/libultraship/SohConsole.cpp @@ -92,7 +92,7 @@ void Console::Update() { } for (auto [key, var] : BindingToggle) { if (ImGui::IsKeyPressed(key)) { - CVar* cvar = CVar_GetVar(const_cast(var.c_str())); + CVar* cvar = CVar_GetVar(var.c_str()); Dispatch("set " + var + " " + std::to_string(cvar == nullptr ? 0 : !static_cast(cvar->value.valueS32))); } } diff --git a/libultraship/libultraship/SohImGuiImpl.cpp b/libultraship/libultraship/SohImGuiImpl.cpp index d95a27d08..bdf9c267b 100644 --- a/libultraship/libultraship/SohImGuiImpl.cpp +++ b/libultraship/libultraship/SohImGuiImpl.cpp @@ -225,7 +225,7 @@ namespace SohImGui { ImGui::Text(name, static_cast(100 * *(value))); if (ImGui::SliderFloat((std::string("##") + key).c_str(), value, 0.0f, 1.0f, "")) { const float volume = floorf(*(value) * 100) / 100; - CVar_SetFloat(const_cast(key), volume); + CVar_SetFloat(key, volume); needs_save = true; Game::SetSeqPlayerVolume(playerId, volume); } @@ -289,7 +289,7 @@ namespace SohImGui { const float volume = Game::Settings.audio.master; ImGui::Text("Master Volume: %d %%", static_cast(100 * volume)); if (ImGui::SliderFloat("##Master_Vol", &Game::Settings.audio.master, 0.0f, 1.0f, "")) { - CVar_SetFloat(const_cast("gGameMasterVolume"), volume); + CVar_SetFloat("gGameMasterVolume", volume); needs_save = true; } @@ -337,7 +337,7 @@ namespace SohImGui { ImGui::Separator(); if (ImGui::Checkbox("Fast Text", &Game::Settings.enhancements.fast_text)) { - CVar_SetS32(const_cast("gFastText"), Game::Settings.enhancements.fast_text); + CVar_SetS32("gFastText", Game::Settings.enhancements.fast_text); needs_save = true; } @@ -354,12 +354,12 @@ namespace SohImGui { } if (ImGui::Checkbox("Animated Link in Pause Menu", &Game::Settings.enhancements.animated_pause_menu)) { - CVar_SetS32(const_cast("gPauseLiveLink"), Game::Settings.enhancements.animated_pause_menu); + CVar_SetS32("gPauseLiveLink", Game::Settings.enhancements.animated_pause_menu); needs_save = true; } if (ImGui::Checkbox("Disable LOD", &Game::Settings.enhancements.disable_lod)) { - CVar_SetS32(const_cast("gDisableLOD"), Game::Settings.enhancements.disable_lod); + CVar_SetS32("gDisableLOD", Game::Settings.enhancements.disable_lod); needs_save = true; } @@ -374,7 +374,7 @@ namespace SohImGui { ImGui::Separator(); if (ImGui::Checkbox("Debug Mode", &Game::Settings.cheats.debug_mode)) { - CVar_SetS32(const_cast("gDebugEnabled"), Game::Settings.cheats.debug_mode); + CVar_SetS32("gDebugEnabled", Game::Settings.cheats.debug_mode); needs_save = true; } @@ -383,42 +383,42 @@ namespace SohImGui { if (ImGui::BeginMenu("Cheats")) { if (ImGui::Checkbox("Infinite Money", &Game::Settings.cheats.infinite_money)) { - CVar_SetS32(const_cast("gInfiniteMoney"), Game::Settings.cheats.infinite_money); + CVar_SetS32("gInfiniteMoney", Game::Settings.cheats.infinite_money); needs_save = true; } if (ImGui::Checkbox("Infinite Health", &Game::Settings.cheats.infinite_health)) { - CVar_SetS32(const_cast("gInfiniteHealth"), Game::Settings.cheats.infinite_health); + CVar_SetS32("gInfiniteHealth", Game::Settings.cheats.infinite_health); needs_save = true; } if (ImGui::Checkbox("Infinite Ammo", &Game::Settings.cheats.infinite_ammo)) { - CVar_SetS32(const_cast("gInfiniteAmmo"), Game::Settings.cheats.infinite_ammo); + CVar_SetS32("gInfiniteAmmo", Game::Settings.cheats.infinite_ammo); needs_save = true; } if (ImGui::Checkbox("Infinite Magic", &Game::Settings.cheats.infinite_magic)) { - CVar_SetS32(const_cast("gInfiniteMagic"), Game::Settings.cheats.infinite_magic); + CVar_SetS32("gInfiniteMagic", Game::Settings.cheats.infinite_magic); needs_save = true; } if (ImGui::Checkbox("No Clip", &Game::Settings.cheats.no_clip)) { - CVar_SetS32(const_cast("gNoClip"), Game::Settings.cheats.no_clip); + CVar_SetS32("gNoClip", Game::Settings.cheats.no_clip); needs_save = true; } if (ImGui::Checkbox("Climb Everything", &Game::Settings.cheats.climb_everything)) { - CVar_SetS32(const_cast("gClimbEverything"), Game::Settings.cheats.climb_everything); + CVar_SetS32("gClimbEverything", Game::Settings.cheats.climb_everything); needs_save = true; } if (ImGui::Checkbox("Moon Jump on L", &Game::Settings.cheats.moon_jump_on_l)) { - CVar_SetS32(const_cast("gMoonJumpOnL"), Game::Settings.cheats.moon_jump_on_l); + CVar_SetS32("gMoonJumpOnL", Game::Settings.cheats.moon_jump_on_l); needs_save = true; } if (ImGui::Checkbox("Super Tunic", &Game::Settings.cheats.super_tunic)) { - CVar_SetS32(const_cast("gSuperTunic"), Game::Settings.cheats.super_tunic); + CVar_SetS32("gSuperTunic", Game::Settings.cheats.super_tunic); needs_save = true; } @@ -538,4 +538,4 @@ namespace SohImGui { void BindCmd(const std::string& cmd, CommandEntry entry) { console->Commands[cmd] = std::move(entry); } -} \ No newline at end of file +} diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index c000ce8e1..d10600bce 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -183,9 +183,9 @@ extern "C" char* ResourceMgr_LoadJPEG(char* data, int dataSize) return (char*)finalBuffer; } -extern "C" char* ResourceMgr_LoadTexByName(char* texPath); +extern "C" char* ResourceMgr_LoadTexByName(const char* texPath); -extern "C" char* ResourceMgr_LoadTexOrDListByName(char* filePath) { +extern "C" char* ResourceMgr_LoadTexOrDListByName(const char* filePath) { auto res = OTRGlobals::Instance->context->GetResourceManager()->LoadResource(filePath); if (res->resType == Ship::ResourceType::DisplayList) @@ -196,28 +196,28 @@ extern "C" char* ResourceMgr_LoadTexOrDListByName(char* filePath) { return ResourceMgr_LoadTexByName(filePath); } -extern "C" char* ResourceMgr_LoadPlayerAnimByName(char* animPath) { +extern "C" char* ResourceMgr_LoadPlayerAnimByName(const char* animPath) { auto anim = std::static_pointer_cast( OTRGlobals::Instance->context->GetResourceManager()->LoadResource(animPath)); return (char*)&anim->limbRotData[0]; } -extern "C" Gfx* ResourceMgr_LoadGfxByName(char* path) +extern "C" Gfx* ResourceMgr_LoadGfxByName(const char* path) { auto res = std::static_pointer_cast( OTRGlobals::Instance->context->GetResourceManager()->LoadResource(path)); return (Gfx*)&res->instructions[0]; } -extern "C" char* ResourceMgr_LoadArrayByName(char* path) +extern "C" char* ResourceMgr_LoadArrayByName(const char* path) { auto res = std::static_pointer_cast(OTRGlobals::Instance->context->GetResourceManager()->LoadResource(path)); return (char*)res->scalars.data(); } -extern "C" char* ResourceMgr_LoadArrayByNameAsVec3s(char* path) { +extern "C" char* ResourceMgr_LoadArrayByNameAsVec3s(const char* path) { auto res = std::static_pointer_cast(OTRGlobals::Instance->context->GetResourceManager()->LoadResource(path)); @@ -239,7 +239,7 @@ extern "C" char* ResourceMgr_LoadArrayByNameAsVec3s(char* path) { } } -extern "C" CollisionHeader* ResourceMgr_LoadColByName(char* path) +extern "C" CollisionHeader* ResourceMgr_LoadColByName(const char* path) { auto colRes = std::static_pointer_cast(OTRGlobals::Instance->context->GetResourceManager()->LoadResource(path)); @@ -333,7 +333,7 @@ extern "C" CollisionHeader* ResourceMgr_LoadColByName(char* path) return (CollisionHeader*)colHeader; } -extern "C" Vtx * ResourceMgr_LoadVtxByName(char* path) +extern "C" Vtx * ResourceMgr_LoadVtxByName(const char* path) { auto res = std::static_pointer_cast(OTRGlobals::Instance->context->GetResourceManager()->LoadResource(path)); return (Vtx*)res->vertices.data(); @@ -355,7 +355,7 @@ extern "C" int ResourceMgr_OTRSigCheck(char* imgData) return 0; } -extern "C" AnimationHeaderCommon* ResourceMgr_LoadAnimByName(char* path) { +extern "C" AnimationHeaderCommon* ResourceMgr_LoadAnimByName(const char* path) { auto res = std::static_pointer_cast( OTRGlobals::Instance->context->GetResourceManager()->LoadResource(path)); @@ -424,7 +424,7 @@ extern "C" AnimationHeaderCommon* ResourceMgr_LoadAnimByName(char* path) { return anim; } -extern "C" SkeletonHeader* ResourceMgr_LoadSkeletonByName(char* path) { +extern "C" SkeletonHeader* ResourceMgr_LoadSkeletonByName(const char* path) { auto res = std::static_pointer_cast(OTRGlobals::Instance->context->GetResourceManager()->LoadResource(path)); if (res->cachedGameAsset != nullptr) @@ -470,14 +470,14 @@ extern "C" SkeletonHeader* ResourceMgr_LoadSkeletonByName(char* path) { limbC->sibling = limb->siblingIndex; if (limb->dListPtr != "") { - auto dList = ResourceMgr_LoadGfxByName((char*)limb->dListPtr.c_str()); + auto dList = ResourceMgr_LoadGfxByName(limb->dListPtr.c_str()); limbC->dLists[0] = dList; } else { limbC->dLists[0] = nullptr; } if (limb->dList2Ptr != "") { - auto dList = ResourceMgr_LoadGfxByName((char*)limb->dList2Ptr.c_str()); + auto dList = ResourceMgr_LoadGfxByName(limb->dList2Ptr.c_str()); limbC->dLists[1] = dList; } else { limbC->dLists[1] = nullptr; @@ -496,7 +496,7 @@ extern "C" SkeletonHeader* ResourceMgr_LoadSkeletonByName(char* path) { limbC->dList = nullptr; if (!limb->dListPtr.empty()) { - const auto dList = ResourceMgr_LoadGfxByName(const_cast(limb->dListPtr.c_str())); + const auto dList = ResourceMgr_LoadGfxByName(limb->dListPtr.c_str()); limbC->dList = dList; } @@ -512,12 +512,12 @@ extern "C" SkeletonHeader* ResourceMgr_LoadSkeletonByName(char* path) { limbC->dList[1] = nullptr; if (!limb->dListPtr.empty()) { - const auto dList = ResourceMgr_LoadGfxByName(const_cast(limb->dListPtr.c_str())); + const auto dList = ResourceMgr_LoadGfxByName(limb->dListPtr.c_str()); limbC->dList[0] = dList; } if (!limb->dList2Ptr.empty()) { - const auto dList = ResourceMgr_LoadGfxByName(const_cast(limb->dList2Ptr.c_str())); + const auto dList = ResourceMgr_LoadGfxByName(limb->dList2Ptr.c_str()); limbC->dList[1] = dList; } @@ -543,7 +543,7 @@ extern "C" SkeletonHeader* ResourceMgr_LoadSkeletonByName(char* path) { limbC->segmentType = 0; if (limb->skinSegmentType == Ship::ZLimbSkinType::SkinType_DList) - limbC->segment = ResourceMgr_LoadGfxByName(const_cast(limb->skinDList.c_str())); + limbC->segment = ResourceMgr_LoadGfxByName(limb->skinDList.c_str()); else if (limb->skinSegmentType == Ship::ZLimbSkinType::SkinType_4) { const auto animData = new SkinAnimatedLimbData; const int skinDataSize = limb->skinData.size(); @@ -551,7 +551,7 @@ extern "C" SkeletonHeader* ResourceMgr_LoadSkeletonByName(char* path) { animData->totalVtxCount = limb->skinVtxCnt; animData->limbModifCount = skinDataSize; animData->limbModifications = new SkinLimbModif[animData->limbModifCount]; - animData->dlist = ResourceMgr_LoadGfxByName(const_cast(limb->skinDList2.c_str())); + animData->dlist = ResourceMgr_LoadGfxByName(limb->skinDList2.c_str()); for (int i = 0; i < skinDataSize; i++) { @@ -611,7 +611,7 @@ extern "C" SkeletonHeader* ResourceMgr_LoadSkeletonByName(char* path) { return baseHeader; } -extern "C" s32* ResourceMgr_LoadCSByName(char* path) +extern "C" s32* ResourceMgr_LoadCSByName(const char* path) { auto res = std::static_pointer_cast(OTRGlobals::Instance->context->GetResourceManager()->LoadResource(path)); return (s32*)res->commands.data(); diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index 4a439fc6d..4f62f0694 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -31,17 +31,17 @@ uint32_t ResourceMgr_GetGameVersion(); void ResourceMgr_CacheDirectory(const char* resName); void ResourceMgr_LoadFile(const char* resName); char* ResourceMgr_LoadFileFromDisk(const char* filePath); -char* ResourceMgr_LoadTexByName(char* texPath); -char* ResourceMgr_LoadTexOrDListByName(char* filePath); -char* ResourceMgr_LoadPlayerAnimByName(char* animPath); +char* ResourceMgr_LoadTexByName(const char* texPath); +char* ResourceMgr_LoadTexOrDListByName(const char* filePath); +char* ResourceMgr_LoadPlayerAnimByName(const char* animPath); char* ResourceMgr_GetNameByCRC(uint64_t crc, char* alloc); Gfx* ResourceMgr_LoadGfxByCRC(uint64_t crc); -Gfx* ResourceMgr_LoadGfxByName(char* path); +Gfx* ResourceMgr_LoadGfxByName(const char* path); Vtx* ResourceMgr_LoadVtxByCRC(uint64_t crc); -Vtx* ResourceMgr_LoadVtxByName(char* path); -CollisionHeader* ResourceMgr_LoadColByName(char* path); +Vtx* ResourceMgr_LoadVtxByName(const char* path); +CollisionHeader* ResourceMgr_LoadColByName(const char* path); uint64_t GetPerfCounter(); -struct SkeletonHeader* ResourceMgr_LoadSkeletonByName(char* path); +struct SkeletonHeader* ResourceMgr_LoadSkeletonByName(const char* path); int ResourceMgr_OTRSigCheck(char* imgData); uint64_t osGetTime(void); uint32_t osGetCount(void); From f20ab2c2600d9e07b342a226f07fc98721dbc8fc Mon Sep 17 00:00:00 2001 From: MaikelChan Date: Fri, 8 Apr 2022 23:23:24 +0200 Subject: [PATCH 4/6] Fixed transparent texture making framebuffers also transparent in D3D11. (#84) This happened with the Mirror Shield in the inventory screen preview. --- libultraship/libultraship/Lib/Fast3D/gfx_direct3d11.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_direct3d11.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_direct3d11.cpp index c989290c6..3481a4db2 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_direct3d11.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_direct3d11.cpp @@ -531,8 +531,8 @@ static struct ShaderProgram *gfx_d3d11_create_and_load_new_shader(uint64_t shade blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; - blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; - blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; + blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA; + blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; } else { From 3e8c48c1162b004f160e727ea8704885dc0d1dd5 Mon Sep 17 00:00:00 2001 From: rozlette Date: Sun, 3 Apr 2022 14:47:24 -0500 Subject: [PATCH 5/6] Add save editor --- .../Lib/Fast3D/gfx_direct3d11.cpp | 4 +- libultraship/libultraship/SohImGuiImpl.cpp | 67 ++- libultraship/libultraship/SohImGuiImpl.h | 14 +- soh/soh.vcxproj | 4 + soh/soh.vcxproj.filters | 18 + .../Enhancements/debugger/debugSaveEditor.cpp | 527 ++++++++++++++++++ .../Enhancements/debugger/debugSaveEditor.h | 3 + soh/soh/Enhancements/debugger/debugger.cpp | 6 + soh/soh/Enhancements/debugger/debugger.h | 3 + soh/soh/OTRGlobals.cpp | 2 + 10 files changed, 641 insertions(+), 7 deletions(-) create mode 100644 soh/soh/Enhancements/debugger/debugSaveEditor.cpp create mode 100644 soh/soh/Enhancements/debugger/debugSaveEditor.h create mode 100644 soh/soh/Enhancements/debugger/debugger.cpp create mode 100644 soh/soh/Enhancements/debugger/debugger.h diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_direct3d11.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_direct3d11.cpp index 3481a4db2..9c2f46422 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_direct3d11.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_direct3d11.cpp @@ -977,8 +977,8 @@ uint16_t gfx_d3d11_get_pixel_depth_old(float x, float y) { } // namespace -void* SohImGui::GetTextureByID(int id) { - return d3d.textures[id].resource_view.Get(); +ImTextureID SohImGui::GetTextureByID(int id) { + return impl.backend == Backend::DX11 ? d3d.textures[id].resource_view.Get() : reinterpret_cast(id); } struct GfxRenderingAPI gfx_direct3d11_api = { diff --git a/libultraship/libultraship/SohImGuiImpl.cpp b/libultraship/libultraship/SohImGuiImpl.cpp index bdf9c267b..7489d14a2 100644 --- a/libultraship/libultraship/SohImGuiImpl.cpp +++ b/libultraship/libultraship/SohImGuiImpl.cpp @@ -1,6 +1,7 @@ #include "SohImGuiImpl.h" #include +#include #include #include "Archive.h" @@ -14,9 +15,11 @@ #include "TextureMod.h" #include "Window.h" #include "Cvar.h" +#include "Texture.h" #include "../Fast3D/gfx_pc.h" #include "Lib/stb/stb_image.h" #include "Lib/Fast3D/gfx_rendering_api.h" +#include "Lib/spdlog/include/spdlog/common.h" #include "Utils/StringHelper.h" #ifdef ENABLE_OPENGL @@ -51,6 +54,9 @@ namespace SohImGui { bool p_open = false; bool needs_save = false; + std::map> windowCategories; + std::map customWindows; + void ImGuiWMInit() { switch (impl.backend) { case Backend::SDL: @@ -153,7 +159,7 @@ namespace SohImGui { } } - void LoadTexture(std::string name, std::string path) { + void LoadTexture(const std::string& name, const std::string& path) { GfxRenderingAPI* api = gfx_get_current_rendering_api(); const auto res = GlobalCtx2::GetInstance()->GetResourceManager()->LoadFile(normalize(path)); @@ -173,6 +179,25 @@ namespace SohImGui { stbi_image_free(img_data); } + void LoadResource(const std::string& name, const std::string& path) { + GfxRenderingAPI* api = gfx_get_current_rendering_api(); + const auto res = static_cast(GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(normalize(path)).get()); + + if (res->texType != Ship::TextureType::RGBA32bpp) { + // TODO convert other image types + SPDLOG_WARN("SohImGui::LoadResource: Attempting to load unsupporting image type %s", path.c_str()); + return; + } + + const auto asset = new GameAsset{ api->new_texture() }; + + api->select_texture(0, asset->textureId); + api->set_sampler_parameters(0, false, 0, 0); + api->upload_texture(res->imageData, res->width, res->height); + + DefaultAssets[name] = asset; + } + void Init(WindowImpl window_impl) { impl = window_impl; Game::LoadSettings(); @@ -219,7 +244,7 @@ namespace SohImGui { ImGuiProcessEvent(event); } -#define BindButton(btn, status) ImGui::Image(impl.backend == Backend::DX11 ? GetTextureByID(DefaultAssets[btn]->textureId) : (ImTextureID)(DefaultAssets[btn]->textureId), ImVec2(16.0f * scale, 16.0f * scale), ImVec2(0, 0), ImVec2(1.0f, 1.0f), ImVec4(255, 255, 255, (status) ? 255 : 0)); +#define BindButton(btn, status) ImGui::Image(GetTextureByID(DefaultAssets[btn]->textureId), ImVec2(16.0f * scale, 16.0f * scale), ImVec2(0, 0), ImVec2(1.0f, 1.0f), ImVec4(255, 255, 255, (status) ? 255 : 0)); void BindAudioSlider(const char* name, const char* key, float* value, SeqPlayers playerId) { ImGui::Text(name, static_cast(100 * *(value))); @@ -278,7 +303,7 @@ namespace SohImGui { if (ImGui::BeginMenuBar()) { if (DefaultAssets.contains("Game_Icon")) { ImGui::SetCursorPos(ImVec2(5, 2.5f)); - ImGui::Image(impl.backend == Backend::DX11 ? GetTextureByID(DefaultAssets["Game_Icon"]->textureId) : reinterpret_cast(DefaultAssets["Game_Icon"]->textureId), ImVec2(16.0f, 16.0f)); + ImGui::Image(GetTextureByID(DefaultAssets["Game_Icon"]->textureId), ImVec2(16.0f, 16.0f)); ImGui::SameLine(); ImGui::SetCursorPos(ImVec2(25, 0)); } @@ -425,6 +450,15 @@ namespace SohImGui { ImGui::EndMenu(); } + for (const auto& category : windowCategories) { + if (ImGui::BeginMenu(category.first.c_str())) { + for (const std::string& name : category.second) { + HOOK(ImGui::MenuItem(name.c_str(), nullptr, &customWindows[name].enabled)); + } + ImGui::EndMenu(); + } + } + ImGui::EndMenuBar(); } @@ -527,6 +561,13 @@ namespace SohImGui { console->Draw(); + for (auto& windowIter : customWindows) { + CustomWindow& window = windowIter.second; + if (window.drawFunc != nullptr) { + window.drawFunc(window.enabled); + } + } + ImGui::Render(); ImGuiRenderDrawData(ImGui::GetDrawData()); if (UseViewports()) { @@ -538,4 +579,22 @@ namespace SohImGui { void BindCmd(const std::string& cmd, CommandEntry entry) { console->Commands[cmd] = std::move(entry); } -} + + void AddWindow(const std::string& category, const std::string& name, WindowDrawFunc drawFunc) { + if (customWindows.contains(name)) { + SPDLOG_ERROR("SohImGui::AddWindow: Attempting to add duplicate window name %s", name.c_str()); + return; + } + + customWindows[name] = { + .enabled = false, + .drawFunc = drawFunc + }; + + windowCategories[category].emplace_back(name); + } + + ImTextureID GetTextureByName(const std::string& name) { + return GetTextureByID(DefaultAssets[name]->textureId); + } +} \ No newline at end of file diff --git a/libultraship/libultraship/SohImGuiImpl.h b/libultraship/libultraship/SohImGuiImpl.h index b7c946eff..8275e4735 100644 --- a/libultraship/libultraship/SohImGuiImpl.h +++ b/libultraship/libultraship/SohImGuiImpl.h @@ -47,11 +47,23 @@ namespace SohImGui { } sdl; } EventImpl; + extern WindowImpl impl; + + using WindowDrawFunc = void(*)(bool& enabled); + + typedef struct { + bool enabled; + WindowDrawFunc drawFunc; + } CustomWindow; + extern Console* console; void Init(WindowImpl window_impl); void Update(EventImpl event); void Draw(void); void ShowCursor(bool hide, Dialogues w); void BindCmd(const std::string& cmd, CommandEntry entry); - void* GetTextureByID(int id); + void AddWindow(const std::string& category, const std::string& name, WindowDrawFunc drawFunc); + void LoadResource(const std::string& name, const std::string& path); + ImTextureID GetTextureByID(int id); + ImTextureID GetTextureByName(const std::string& name); } diff --git a/soh/soh.vcxproj b/soh/soh.vcxproj index aa6dee304..5560bde76 100644 --- a/soh/soh.vcxproj +++ b/soh/soh.vcxproj @@ -178,6 +178,8 @@ + + @@ -922,6 +924,8 @@ + + diff --git a/soh/soh.vcxproj.filters b/soh/soh.vcxproj.filters index 30ca9d4ed..de9ad6f96 100644 --- a/soh/soh.vcxproj.filters +++ b/soh/soh.vcxproj.filters @@ -76,6 +76,12 @@ {18b9727f-30de-4ab8-a317-916090d4a110} + + {9a4378ec-e30f-47b6-9ad6-5ce738b4cf99} + + + {04fc1c52-49ff-48e2-ae23-2c00867374f8} + @@ -2169,6 +2175,12 @@ Source Files\src\overlays\actors + + Source Files\soh\Enhancements\debugger + + + Source Files\soh\Enhancements\debugger + @@ -3710,6 +3722,12 @@ Header Files + + Header Files\soh\Enhancements\debugger + + + Header Files\soh\Enhancements\debugger + diff --git a/soh/soh/Enhancements/debugger/debugSaveEditor.cpp b/soh/soh/Enhancements/debugger/debugSaveEditor.cpp new file mode 100644 index 000000000..95e2f912c --- /dev/null +++ b/soh/soh/Enhancements/debugger/debugSaveEditor.cpp @@ -0,0 +1,527 @@ +#include "debugSaveEditor.h" +#include "../libultraship/SohImGuiImpl.h" + +#include +#include +#include + +extern "C" { +#include +#include "variables.h" +#include "functions.h" +#include "macros.h" +extern GlobalContext* gGlobalCtx; + +#include "textures/icon_item_static/icon_item_static.h" +} + +typedef struct { + uint32_t id; + std::string name; + std::string texturePath; +} ItemMapEntry; + +#define ITEM_MAP_ENTRY(id) \ + { \ + id, { \ + id, #id, static_cast(gItemIcons[id]) \ + } \ + } + +// Maps items ids to info for use in ImGui +std::map itemMapping = { + ITEM_MAP_ENTRY(ITEM_STICK), + ITEM_MAP_ENTRY(ITEM_NUT), + ITEM_MAP_ENTRY(ITEM_BOMB), + ITEM_MAP_ENTRY(ITEM_BOW), + ITEM_MAP_ENTRY(ITEM_ARROW_FIRE), + ITEM_MAP_ENTRY(ITEM_DINS_FIRE), + ITEM_MAP_ENTRY(ITEM_SLINGSHOT), + ITEM_MAP_ENTRY(ITEM_OCARINA_FAIRY), + ITEM_MAP_ENTRY(ITEM_OCARINA_TIME), + ITEM_MAP_ENTRY(ITEM_BOMBCHU), + ITEM_MAP_ENTRY(ITEM_HOOKSHOT), + ITEM_MAP_ENTRY(ITEM_LONGSHOT), + ITEM_MAP_ENTRY(ITEM_ARROW_ICE), + ITEM_MAP_ENTRY(ITEM_FARORES_WIND), + ITEM_MAP_ENTRY(ITEM_BOOMERANG), + ITEM_MAP_ENTRY(ITEM_LENS), + ITEM_MAP_ENTRY(ITEM_BEAN), + ITEM_MAP_ENTRY(ITEM_HAMMER), + ITEM_MAP_ENTRY(ITEM_ARROW_LIGHT), + ITEM_MAP_ENTRY(ITEM_NAYRUS_LOVE), + ITEM_MAP_ENTRY(ITEM_BOTTLE), + ITEM_MAP_ENTRY(ITEM_POTION_RED), + ITEM_MAP_ENTRY(ITEM_POTION_GREEN), + ITEM_MAP_ENTRY(ITEM_POTION_BLUE), + ITEM_MAP_ENTRY(ITEM_FAIRY), + ITEM_MAP_ENTRY(ITEM_FISH), + ITEM_MAP_ENTRY(ITEM_MILK_BOTTLE), + ITEM_MAP_ENTRY(ITEM_LETTER_RUTO), + ITEM_MAP_ENTRY(ITEM_BLUE_FIRE), + ITEM_MAP_ENTRY(ITEM_BUG), + ITEM_MAP_ENTRY(ITEM_BIG_POE), + ITEM_MAP_ENTRY(ITEM_MILK_HALF), + ITEM_MAP_ENTRY(ITEM_POE), + ITEM_MAP_ENTRY(ITEM_WEIRD_EGG), + ITEM_MAP_ENTRY(ITEM_CHICKEN), + ITEM_MAP_ENTRY(ITEM_LETTER_ZELDA), + ITEM_MAP_ENTRY(ITEM_MASK_KEATON), + ITEM_MAP_ENTRY(ITEM_MASK_SKULL), + ITEM_MAP_ENTRY(ITEM_MASK_SPOOKY), + ITEM_MAP_ENTRY(ITEM_MASK_BUNNY), + ITEM_MAP_ENTRY(ITEM_MASK_GORON), + ITEM_MAP_ENTRY(ITEM_MASK_ZORA), + ITEM_MAP_ENTRY(ITEM_MASK_GERUDO), + ITEM_MAP_ENTRY(ITEM_MASK_TRUTH), + ITEM_MAP_ENTRY(ITEM_SOLD_OUT), + ITEM_MAP_ENTRY(ITEM_POCKET_EGG), + ITEM_MAP_ENTRY(ITEM_POCKET_CUCCO), + ITEM_MAP_ENTRY(ITEM_COJIRO), + ITEM_MAP_ENTRY(ITEM_ODD_MUSHROOM), + ITEM_MAP_ENTRY(ITEM_ODD_POTION), + ITEM_MAP_ENTRY(ITEM_SAW), + ITEM_MAP_ENTRY(ITEM_SWORD_BROKEN), + ITEM_MAP_ENTRY(ITEM_PRESCRIPTION), + ITEM_MAP_ENTRY(ITEM_FROG), + ITEM_MAP_ENTRY(ITEM_EYEDROPS), + ITEM_MAP_ENTRY(ITEM_CLAIM_CHECK), + ITEM_MAP_ENTRY(ITEM_BOW_ARROW_FIRE), + ITEM_MAP_ENTRY(ITEM_BOW_ARROW_ICE), + ITEM_MAP_ENTRY(ITEM_BOW_ARROW_LIGHT), + ITEM_MAP_ENTRY(ITEM_SWORD_KOKIRI), + ITEM_MAP_ENTRY(ITEM_SWORD_MASTER), + ITEM_MAP_ENTRY(ITEM_SWORD_BGS), + ITEM_MAP_ENTRY(ITEM_SHIELD_DEKU), + ITEM_MAP_ENTRY(ITEM_SHIELD_HYLIAN), + ITEM_MAP_ENTRY(ITEM_SHIELD_MIRROR), + ITEM_MAP_ENTRY(ITEM_TUNIC_KOKIRI), + ITEM_MAP_ENTRY(ITEM_TUNIC_GORON), + ITEM_MAP_ENTRY(ITEM_TUNIC_ZORA), + ITEM_MAP_ENTRY(ITEM_BOOTS_KOKIRI), + ITEM_MAP_ENTRY(ITEM_BOOTS_IRON), + ITEM_MAP_ENTRY(ITEM_BOOTS_HOVER), + ITEM_MAP_ENTRY(ITEM_BULLET_BAG_30), + ITEM_MAP_ENTRY(ITEM_BULLET_BAG_40), + ITEM_MAP_ENTRY(ITEM_BULLET_BAG_50), + ITEM_MAP_ENTRY(ITEM_QUIVER_30), + ITEM_MAP_ENTRY(ITEM_QUIVER_40), + ITEM_MAP_ENTRY(ITEM_QUIVER_50), + ITEM_MAP_ENTRY(ITEM_BOMB_BAG_20), + ITEM_MAP_ENTRY(ITEM_BOMB_BAG_30), + ITEM_MAP_ENTRY(ITEM_BOMB_BAG_40), + ITEM_MAP_ENTRY(ITEM_BRACELET), + ITEM_MAP_ENTRY(ITEM_GAUNTLETS_SILVER), + ITEM_MAP_ENTRY(ITEM_GAUNTLETS_GOLD), + ITEM_MAP_ENTRY(ITEM_SCALE_SILVER), + ITEM_MAP_ENTRY(ITEM_SCALE_GOLDEN), + ITEM_MAP_ENTRY(ITEM_SWORD_KNIFE), + ITEM_MAP_ENTRY(ITEM_WALLET_ADULT), + ITEM_MAP_ENTRY(ITEM_WALLET_GIANT), + ITEM_MAP_ENTRY(ITEM_SEEDS), + ITEM_MAP_ENTRY(ITEM_FISHING_POLE), +}; + +// Maps entries in the GS flag array to the area name it represents +std::vector gsMapping = { + "Deku Tree", + "Dodongo's Cavern", + "Inside Jabu-Jabu's Belly", + "Forest Temple", + "Fire Temple", + "Water Temple", + "Spirit Temple", + "Shadow Temple", + "Bottom of the Well", + "Ice Cavern", + "Hyrule Field", + "Lon Lon Ranch", + "Kokiri Forest", + "Lost Woods, Sacred Forest Meadow", + "Castle Town and Ganon's Castle", + "Death Mountain Trail, Goron City", + "Kakariko Village", + "Zora Fountain, River", + "Lake Hylia", + "Gerudo Valley", + "Gerudo Fortress", + "Desert Colossus, Haunted Wasteland", +}; +extern "C" u8 gAreaGsFlags[]; + +extern "C" u8 gAmmoItems[]; + +// Modification of gAmmoItems that replaces ITEM_NONE with the item in inventory slot it represents +u8 gAllAmmoItems[] = { + ITEM_STICK, ITEM_NUT, ITEM_BOMB, ITEM_BOW, ITEM_ARROW_FIRE, ITEM_DINS_FIRE, + ITEM_SLINGSHOT, ITEM_OCARINA_TIME, ITEM_BOMBCHU, ITEM_LONGSHOT, ITEM_ARROW_ICE, ITEM_FARORES_WIND, + ITEM_BOOMERANG, ITEM_LENS, ITEM_BEAN, ITEM_HAMMER, +}; + +// Adds a text tooltip for the previous ImGui item +void SetLastItemHoverText(const std::string& text) { + if (ImGui::IsItemHovered()) { + ImGui::BeginTooltip(); + ImGui::Text(text.c_str()); + ImGui::EndTooltip(); + } +} + +// Adds a "?" next to the previous ImGui item with a custom tooltip +void InsertHelpHoverText(const std::string& text) { + ImGui::SameLine(); + ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "?"); + if (ImGui::IsItemHovered()) { + ImGui::BeginTooltip(); + ImGui::Text(text.c_str()); + ImGui::EndTooltip(); + } +} + +void DrawSaveEditor(bool& open) { + if (!open) { + return; + } + + ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver); + if (!ImGui::Begin("Save Editor", &open)) { + ImGui::End(); + return; + } + + // TODO This is the bare minimum to get the player name showing + // There will need to be more effort to get it robust and editable + std::string name; + for (int i = 0; i < 8; i++) { + char letter = gSaveContext.playerName[i] + 0x3D; + if (letter == '{') { + letter = '\0'; + } + name += letter; + } + name += '\0'; + + if (ImGui::BeginTabBar("SaveContextTabBar", ImGuiTabBarFlags_NoCloseWithMiddleMouseButton)) { + if (ImGui::BeginTabItem("Info")) { + ImGui::PushItemWidth(ImGui::GetFontSize() * 6); + + ImGui::Text("Name: %s", name.c_str()); + InsertHelpHoverText("Player Name"); + + // Use an intermediary to keep the health from updating (and potentially killing the player) + // until it is done being edited + int16_t healthIntermediary = gSaveContext.healthCapacity; + ImGui::InputScalar("Max Health", ImGuiDataType_S16, &healthIntermediary); + if (ImGui::IsItemDeactivated()) { + gSaveContext.healthCapacity = healthIntermediary; + } + InsertHelpHoverText("Maximum health. 16 units per full heart"); + if (gSaveContext.health > gSaveContext.healthCapacity) { + gSaveContext.health = gSaveContext.healthCapacity; // Clamp health to new max + } + + const uint16_t healthMin = 0; + const uint16_t healthMax = gSaveContext.healthCapacity; + ImGui::SetNextItemWidth(ImGui::GetFontSize() * 15); + ImGui::SliderScalar("Health", ImGuiDataType_S16, &gSaveContext.health, &healthMin, &healthMax); + InsertHelpHoverText("Current health. 16 units per full heart"); + + bool doubleDefense = gSaveContext.doubleDefense != 0; + if (ImGui::Checkbox("Double Defense", &doubleDefense)) { + gSaveContext.doubleDefense = doubleDefense; + gSaveContext.inventory.defenseHearts = + gSaveContext.doubleDefense ? 20 : 0; // Set to get the border drawn in the UI + } + InsertHelpHoverText("Is double defense unlocked?"); + + std::string magicName; + if (gSaveContext.magicLevel == 2) { + magicName = "Double"; + } else if (gSaveContext.magicLevel == 1) { + magicName = "Single"; + } else { + magicName = "None"; + } + ImGui::SetNextItemWidth(ImGui::GetFontSize() * 6); + if (ImGui::BeginCombo("Magic Level", magicName.c_str())) { + if (ImGui::Selectable("Double")) { + gSaveContext.magicLevel = 2; + gSaveContext.magicAcquired = true; + gSaveContext.doubleMagic = true; + } + if (ImGui::Selectable("Single")) { + gSaveContext.magicLevel = 1; + gSaveContext.magicAcquired = true; + gSaveContext.doubleMagic = false; + } + if (ImGui::Selectable("None")) { + gSaveContext.magicLevel = 0; + gSaveContext.magicAcquired = false; + gSaveContext.doubleMagic = false; + } + + ImGui::EndCombo(); + } + InsertHelpHoverText("Current magic level"); + gSaveContext.unk_13F4 = gSaveContext.magicLevel * 0x30; // Set to get the bar drawn in the UI + if (gSaveContext.magic > gSaveContext.unk_13F4) { + gSaveContext.magic = gSaveContext.unk_13F4; // Clamp magic to new max + } + + const uint8_t magicMin = 0; + const uint8_t magicMax = gSaveContext.unk_13F4; + ImGui::SetNextItemWidth(ImGui::GetFontSize() * 15); + ImGui::SliderScalar("Magic", ImGuiDataType_S8, &gSaveContext.magic, &magicMin, &magicMax); + InsertHelpHoverText("Current magic. 48 units per magic level"); + + ImGui::InputScalar("Rupees", ImGuiDataType_S16, &gSaveContext.rupees); + InsertHelpHoverText("Current rupees"); + + const uint16_t dayTimeMin = 0; + const uint16_t dayTimeMax = 0xFFFF; + ImGui::SetNextItemWidth(ImGui::GetFontSize() * 15); + ImGui::SliderScalar("Time", ImGuiDataType_U16, &gSaveContext.dayTime, &dayTimeMin, &dayTimeMax); + InsertHelpHoverText("Time of day"); + if (ImGui::Button("Dawn")) { + gSaveContext.dayTime = 0x4000; + } + ImGui::SameLine(); + if (ImGui::Button("Noon")) { + gSaveContext.dayTime = 0x8000; + } + ImGui::SameLine(); + if (ImGui::Button("Sunset")) { + gSaveContext.dayTime = 0xC000; + } + ImGui::SameLine(); + if (ImGui::Button("Midnight")) { + gSaveContext.dayTime = 0; + } + + ImGui::InputScalar("Total Days", ImGuiDataType_S32, &gSaveContext.totalDays); + InsertHelpHoverText("Total number of days elapsed since the start of the game"); + + ImGui::InputScalar("Deaths", ImGuiDataType_U16, &gSaveContext.deaths); + InsertHelpHoverText("Total number of deaths"); + + // TODO Move to quest status screen once the page is created + ImGui::InputScalar("GS Count", ImGuiDataType_S16, &gSaveContext.inventory.gsTokens); + InsertHelpHoverText("Number of gold skulltula tokens aquired"); + + bool bgsFlag = gSaveContext.bgsFlag != 0; + if (ImGui::Checkbox("Has BGS", &bgsFlag)) { + gSaveContext.bgsFlag = bgsFlag; + } + InsertHelpHoverText("Is Biggoron sword unlocked? Replaces Giant's knife"); + + ImGui::InputScalar("Sword Health", ImGuiDataType_U16, &gSaveContext.swordHealth); + InsertHelpHoverText("Giant's knife health. Default is 8. Must be >0 for Biggoron sword to work"); + + ImGui::InputScalar("Bgs Day Count", ImGuiDataType_S32, &gSaveContext.bgsDayCount); + InsertHelpHoverText("Total number of days elapsed since giving Biggoron the claim check"); + + // TODO Changing Link's age is more involved than just setting gSaveContext.linkAge + // It might not fit here and instead should be only changable when changing scenes + /* + if (ImGui::BeginCombo("Link Age", LINK_IS_ADULT ? "Adult" : "Child")) { + if (ImGui::Selectable("Adult")) { + gSaveContext.linkAge = 0; + } + if (ImGui::Selectable("Child")) { + gSaveContext.linkAge = 1; + } + + ImGui::EndCombo(); + } + */ + + ImGui::PopItemWidth(); + ImGui::EndTabItem(); + } + + if (ImGui::BeginTabItem("Inventory")) { + static bool restrictToValid = true; + + ImGui::Checkbox("Restrict to valid items", &restrictToValid); + InsertHelpHoverText("Restricts items and ammo to only what is possible to legally acquire in-game"); + + for (int32_t y = 0; y < 4; y++) { + for (int32_t x = 0; x < 6; x++) { + int32_t index = x + y * 6; + static int32_t selectedIndex = -1; + static const char* itemPopupPicker = "itemPopupPicker"; + + ImGui::PushID(index); + + if (x != 0) { + ImGui::SameLine(); + } + + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1, 1, 1, 0)); + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); + uint8_t item = gSaveContext.inventory.items[index]; + if (item != ITEM_NONE) { + const ItemMapEntry& slotEntry = itemMapping.find(item)->second; + if (ImGui::ImageButton(SohImGui::GetTextureByName(slotEntry.name), ImVec2(32.0f, 32.0f), + ImVec2(0, 0), ImVec2(1, 1), 0)) { + selectedIndex = index; + ImGui::OpenPopup(itemPopupPicker); + } + } else { + if (ImGui::Button("##itemNone", ImVec2(32.0f, 32.0f))) { + selectedIndex = index; + ImGui::OpenPopup(itemPopupPicker); + } + } + ImGui::PopStyleVar(); + ImGui::PopStyleColor(); + + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); + if (ImGui::BeginPopup(itemPopupPicker)) { + if (ImGui::Button("##itemNonePicker", ImVec2(32.0f, 32.0f))) { + gSaveContext.inventory.items[selectedIndex] = ITEM_NONE; + ImGui::CloseCurrentPopup(); + } + SetLastItemHoverText("ITEM_NONE"); + + std::vector possibleItems; + if (restrictToValid) { + // Scan gItemSlots to find legal items for this slot. Bottles are a special case + for (int slotIndex = 0; slotIndex < 56; slotIndex++) { + int testIndex = (selectedIndex == SLOT_BOTTLE_1 || selectedIndex == SLOT_BOTTLE_2 || + selectedIndex == SLOT_BOTTLE_3 || selectedIndex == SLOT_BOTTLE_4) + ? SLOT_BOTTLE_1 + : selectedIndex; + if (gItemSlots[slotIndex] == testIndex) { + possibleItems.push_back(itemMapping[slotIndex]); + } + } + } else { + for (const auto& entry : itemMapping) { + possibleItems.push_back(entry.second); + } + } + + for (int32_t pickerIndex = 0; pickerIndex < possibleItems.size(); pickerIndex++) { + if (((pickerIndex + 1) % 8) != 0) { + ImGui::SameLine(); + } + const ItemMapEntry& slotEntry = possibleItems[pickerIndex]; + if (ImGui::ImageButton(SohImGui::GetTextureByName(slotEntry.name), ImVec2(32.0f, 32.0f), + ImVec2(0, 0), ImVec2(1, 1), 0)) { + gSaveContext.inventory.items[selectedIndex] = slotEntry.id; + ImGui::CloseCurrentPopup(); + } + SetLastItemHoverText(slotEntry.name); + } + + ImGui::EndPopup(); + } + ImGui::PopStyleVar(); + + ImGui::PopID(); + } + } + + ImGui::Text("Ammo"); + for (uint32_t ammoIndex = 0, drawnAmmoItems = 0; ammoIndex < 16; ammoIndex++) { + uint8_t item = (restrictToValid) ? gAmmoItems[ammoIndex] : gAllAmmoItems[ammoIndex]; + if (item != ITEM_NONE) { + // For legal items, display as 1 row of 7. For unrestricted items, display rows of 6 to match + // inventory + if ((restrictToValid && (drawnAmmoItems != 0)) || ((drawnAmmoItems % 6) != 0)) { + ImGui::SameLine(); + } + drawnAmmoItems++; + + ImGui::PushID(ammoIndex); + ImGui::PushItemWidth(32.0f); + ImGui::BeginGroup(); + + ImGui::Image(SohImGui::GetTextureByName(itemMapping[item].name), ImVec2(32.0f, 32.0f)); + ImGui::InputScalar("##ammoInput", ImGuiDataType_S8, &AMMO(item)); + + ImGui::EndGroup(); + ImGui::PopItemWidth(); + ImGui::PopID(); + } + } + + ImGui::EndTabItem(); + } + + if (ImGui::BeginTabItem("Flags")) { + static uint32_t selectedGsMap = 0; + ImGui::Text("Gold Skulltulas"); + ImGui::Text("Map"); + ImGui::SameLine(); + if (ImGui::BeginCombo("##Gold Skulltula Map", gsMapping[selectedGsMap].c_str())) { + for (int32_t gsIndex = 0; gsIndex < gsMapping.size(); gsIndex++) { + if (ImGui::Selectable(gsMapping[gsIndex].c_str())) { + selectedGsMap = gsIndex; + } + } + + ImGui::EndCombo(); + } + + // TODO We should write out descriptions for each one... ugh + ImGui::Text("Flags"); + uint32_t currentFlags = GET_GS_FLAGS(selectedGsMap); + uint32_t allFlags = gAreaGsFlags[selectedGsMap]; + uint32_t setMask = 1; + // Iterate over bitfield and create a checkbox for each skulltula + while (allFlags != 0) { + bool isThisSet = (currentFlags & 0x1) == 0x1; + + ImGui::SameLine(); + ImGui::PushID(allFlags); + if (ImGui::Checkbox("##gs", &isThisSet)) { + if (isThisSet) { + SET_GS_FLAGS(selectedGsMap, setMask); + } else { + // Have to do this roundabout method as the macro does not support clearing flags + uint32_t currentFlagsBase = GET_GS_FLAGS(selectedGsMap); + gSaveContext.gsFlags[selectedGsMap >> 2] &= ~gGsFlagsMasks[selectedGsMap & 3]; + SET_GS_FLAGS(selectedGsMap, currentFlagsBase & ~setMask); + } + } + + ImGui::PopID(); + + allFlags >>= 1; + currentFlags >>= 1; + setMask <<= 1; + } + + static bool keepGsCountUpdated = true; + ImGui::Checkbox("Keep GS Count Updated", &keepGsCountUpdated); + InsertHelpHoverText("Automatically adjust the number of gold skulltula tokens acquired based on set flags"); + int32_t gsCount = 0; + if (keepGsCountUpdated) { + for (int32_t gsFlagIndex = 0; gsFlagIndex < 6; gsFlagIndex++) { + gsCount += std::popcount(static_cast(gSaveContext.gsFlags[gsFlagIndex])); + } + gSaveContext.inventory.gsTokens = gsCount; + } + + // TODO other flag types, like switch, clear, etc. + // These flags interact with the actor context, so it's a bit more complicated + + ImGui::EndTabItem(); + } + + ImGui::EndTabBar(); + } + + ImGui::End(); +} + +void InitSaveEditor() { + SohImGui::AddWindow("Debug", "Save Editor", DrawSaveEditor); + + // Load item icons into ImGui + for (const auto& entry : itemMapping) { + SohImGui::LoadResource(entry.second.name, entry.second.texturePath); + } +} diff --git a/soh/soh/Enhancements/debugger/debugSaveEditor.h b/soh/soh/Enhancements/debugger/debugSaveEditor.h new file mode 100644 index 000000000..084f7cadc --- /dev/null +++ b/soh/soh/Enhancements/debugger/debugSaveEditor.h @@ -0,0 +1,3 @@ +#pragma once + +void InitSaveEditor(); diff --git a/soh/soh/Enhancements/debugger/debugger.cpp b/soh/soh/Enhancements/debugger/debugger.cpp new file mode 100644 index 000000000..e493375cd --- /dev/null +++ b/soh/soh/Enhancements/debugger/debugger.cpp @@ -0,0 +1,6 @@ +#include "debugger.h" +#include "debugSaveEditor.h" + +void Debug_Init(void) { + InitSaveEditor(); +} diff --git a/soh/soh/Enhancements/debugger/debugger.h b/soh/soh/Enhancements/debugger/debugger.h new file mode 100644 index 000000000..4bc0f985b --- /dev/null +++ b/soh/soh/Enhancements/debugger/debugger.h @@ -0,0 +1,3 @@ +#pragma once + +void Debug_Init(void); diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index d10600bce..007afd702 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -22,6 +22,7 @@ #include "Lib/stb/stb_image.h" #include "AudioPlayer.h" #include "../soh/Enhancements/debugconsole.h" +#include "../soh/Enhancements/debugger/debugger.h" #include "Utils/BitConverter.h" OTRGlobals* OTRGlobals::Instance; @@ -54,6 +55,7 @@ extern "C" void InitOTR() { clearMtx = (uintptr_t)&gMtxClear; OTRMessage_Init(); DebugConsole_Init(); + Debug_Init(); } extern "C" uint64_t GetFrequency() { From 06fd7f662af4358e9a6111270ce0cd311a9af9ea Mon Sep 17 00:00:00 2001 From: Josh Bodner <30329717+jbodner09@users.noreply.github.com> Date: Sun, 10 Apr 2022 15:19:26 -0700 Subject: [PATCH 6/6] Added DPad support to file selection and pause screens (#124) * Added DPad support to file selection and pause screens * Wrap changes behind CVar * Fix merge conflict for real * Remove unnecessary const_cast * Fixed transparent texture making framebuffers also transparent in D3D11. (#84) This happened with the Mirror Shield in the inventory screen preview. * Add save editor * Added DPad support to file selection and pause screens * Fixing rebase conflict * Remove unnecessary const_cast Co-authored-by: MaikelChan Co-authored-by: rozlette --- libultraship/libultraship/GameSettings.cpp | 6 +- libultraship/libultraship/GameSettings.h | 1 + libultraship/libultraship/SohImGuiImpl.cpp | 9 +- .../ovl_file_choose/z_file_choose.c | 8 +- .../ovl_file_choose/z_file_copy_erase.c | 21 ++- .../ovl_file_choose/z_file_nameset_PAL.c | 21 ++- .../ovl_kaleido_scope/z_kaleido_collect.c | 163 +++++++++--------- .../ovl_kaleido_scope/z_kaleido_equipment.c | 13 +- .../misc/ovl_kaleido_scope/z_kaleido_item.c | 17 +- .../ovl_kaleido_scope/z_kaleido_map_PAL.c | 30 ++-- .../misc/ovl_kaleido_scope/z_kaleido_prompt.c | 5 +- .../ovl_kaleido_scope/z_kaleido_scope_PAL.c | 5 +- 12 files changed, 163 insertions(+), 136 deletions(-) diff --git a/libultraship/libultraship/GameSettings.cpp b/libultraship/libultraship/GameSettings.cpp index f12042bc0..28f4b23cb 100644 --- a/libultraship/libultraship/GameSettings.cpp +++ b/libultraship/libultraship/GameSettings.cpp @@ -59,7 +59,7 @@ namespace Game { CVar_SetS32("gPauseLiveLink", Settings.enhancements.animated_pause_menu); Settings.enhancements.minimal_ui = stob(Conf[EnhancementSection]["minimal_ui"]); - CVar_SetS32(const_cast("gMinimalUI"), Settings.enhancements.minimal_ui); + CVar_SetS32("gMinimalUI", Settings.enhancements.minimal_ui); // Audio Settings.audio.master = Ship::stof(Conf[AudioSection]["master"]); @@ -89,6 +89,9 @@ namespace Game { Settings.controller.input_enabled = stob(Conf[ControllerSection]["input_enabled"]); CVar_SetS32("gInputEnabled", Settings.controller.input_enabled); + + Settings.controller.dpad_pause_name = stob(Conf[ControllerSection]["dpad_pause_name"]); + CVar_SetS32("gDpadPauseName", Settings.controller.dpad_pause_name); // Cheats Settings.cheats.debug_mode = stob(Conf[CheatSection]["debug_mode"]); @@ -149,6 +152,7 @@ namespace Game { Conf[ControllerSection]["rumble_strength"] = std::to_string(Settings.controller.rumble_strength); Conf[ControllerSection]["input_scale"] = std::to_string(Settings.controller.input_scale); Conf[ControllerSection]["input_enabled"] = std::to_string(Settings.controller.input_enabled); + Conf[ControllerSection]["dpad_pause_name"] = std::to_string(Settings.controller.dpad_pause_name); // Cheats Conf[CheatSection]["debug_mode"] = std::to_string(Settings.cheats.debug_mode); diff --git a/libultraship/libultraship/GameSettings.h b/libultraship/libultraship/GameSettings.h index 4f9bb4c99..15ebdad16 100644 --- a/libultraship/libultraship/GameSettings.h +++ b/libultraship/libultraship/GameSettings.h @@ -34,6 +34,7 @@ struct SoHConfigType { float gyroDriftX = 0.0f; float gyroDriftY = 0.0f; bool input_enabled = false; + bool dpad_pause_name = false; } controller; // Cheats diff --git a/libultraship/libultraship/SohImGuiImpl.cpp b/libultraship/libultraship/SohImGuiImpl.cpp index 7489d14a2..cef156246 100644 --- a/libultraship/libultraship/SohImGuiImpl.cpp +++ b/libultraship/libultraship/SohImGuiImpl.cpp @@ -353,6 +353,13 @@ namespace SohImGui { needs_save = true; } + ImGui::Separator(); + + if (ImGui::Checkbox("Dpad Support on Pause and File Select", &Game::Settings.controller.dpad_pause_name)) { + CVar_SetS32("gDpadPauseName", Game::Settings.controller.dpad_pause_name); + needs_save = true; + } + ImGui::EndMenu(); } @@ -367,7 +374,7 @@ namespace SohImGui { } if (ImGui::Checkbox("Minimal UI", &Game::Settings.enhancements.minimal_ui)) { - CVar_SetS32(const_cast("gMinimalUI"), Game::Settings.enhancements.minimal_ui); + CVar_SetS32("gMinimalUI", Game::Settings.enhancements.minimal_ui); needs_save = true; } diff --git a/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index ca5154567..84543fa26 100644 --- a/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -179,6 +179,7 @@ void FileChoose_UpdateMainMenu(GameState* thisx) { FileChooseContext* this = (FileChooseContext*)thisx; SramContext* sramCtx = &this->sramCtx; Input* input = &this->state.input[0]; + bool dpad = CVar_GetS32("gDpadPauseName", 0); if (CHECK_BTN_ALL(input->press.button, BTN_START) || CHECK_BTN_ALL(input->press.button, BTN_A)) { if (this->buttonIndex <= FS_BTN_MAIN_FILE_3) { @@ -237,10 +238,10 @@ void FileChoose_UpdateMainMenu(GameState* thisx) { } } } else { - if (ABS(this->stickRelY) > 30) { + if ((ABS(this->stickRelY) > 30) || (dpad && CHECK_BTN_ANY(input->press.button, BTN_DDOWN | BTN_DUP))) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); - if (this->stickRelY > 30) { + if ((this->stickRelY > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) { this->buttonIndex--; if (this->buttonIndex < FS_BTN_MAIN_FILE_1) { this->buttonIndex = FS_BTN_MAIN_OPTIONS; @@ -1318,6 +1319,7 @@ void FileChoose_FadeInFileInfo(GameState* thisx) { void FileChoose_ConfirmFile(GameState* thisx) { FileChooseContext* this = (FileChooseContext*)thisx; Input* input = &this->state.input[0]; + bool dpad = CVar_GetS32("gDpadPauseName", 0); if (CHECK_BTN_ALL(input->press.button, BTN_START) || (CHECK_BTN_ALL(input->press.button, BTN_A))) { if (this->confirmButtonIndex == FS_BTN_CONFIRM_YES) { @@ -1332,7 +1334,7 @@ void FileChoose_ConfirmFile(GameState* thisx) { } else if (CHECK_BTN_ALL(input->press.button, BTN_B)) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CLOSE, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); this->selectMode++; - } else if (ABS(this->stickRelY) >= 30) { + } else if ((ABS(this->stickRelY) >= 30) || (dpad && CHECK_BTN_ANY(input->press.button, BTN_DDOWN | BTN_DUP))) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); this->confirmButtonIndex ^= 1; } diff --git a/soh/src/overlays/gamestates/ovl_file_choose/z_file_copy_erase.c b/soh/src/overlays/gamestates/ovl_file_choose/z_file_copy_erase.c index 5d13c408d..1f44abe95 100644 --- a/soh/src/overlays/gamestates/ovl_file_choose/z_file_copy_erase.c +++ b/soh/src/overlays/gamestates/ovl_file_choose/z_file_copy_erase.c @@ -62,6 +62,7 @@ void FileChoose_SelectCopySource(GameState* thisx) { FileChooseContext* this = (FileChooseContext*)thisx; SramContext* sramCtx = &this->sramCtx; Input* input = &this->state.input[0]; + bool dpad = CVar_GetS32("gDpadPauseName", 0); if (((this->buttonIndex == FS_BTN_COPY_QUIT) && CHECK_BTN_ANY(input->press.button, BTN_A | BTN_START)) || CHECK_BTN_ALL(input->press.button, BTN_B)) { @@ -82,10 +83,10 @@ void FileChoose_SelectCopySource(GameState* thisx) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); } } else { - if (ABS(this->stickRelY) >= 30) { + if ((ABS(this->stickRelY) >= 30) || (dpad && CHECK_BTN_ANY(input->press.button, BTN_DDOWN | BTN_DUP))) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); - if (this->stickRelY >= 30) { + if ((this->stickRelY >= 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) { this->buttonIndex--; if (this->buttonIndex < FS_BTN_COPY_FILE_1) { @@ -174,6 +175,7 @@ void FileChoose_SelectCopyDest(GameState* thisx) { FileChooseContext* this = (FileChooseContext*)thisx; SramContext* sramCtx = &this->sramCtx; Input* input = &this->state.input[0]; + bool dpad = CVar_GetS32("gDpadPauseName", 0); if (((this->buttonIndex == FS_BTN_COPY_QUIT) && CHECK_BTN_ANY(input->press.button, BTN_A | BTN_START)) || CHECK_BTN_ALL(input->press.button, BTN_B)) { @@ -194,10 +196,10 @@ void FileChoose_SelectCopyDest(GameState* thisx) { } } else { - if (ABS(this->stickRelY) >= 30) { + if ((ABS(this->stickRelY) >= 30) || (dpad && CHECK_BTN_ANY(input->press.button, BTN_DDOWN | BTN_DUP))) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); - if (this->stickRelY >= 30) { + if ((this->stickRelY >= 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) { this->buttonIndex--; if ((this->buttonIndex == this->selectedFileIndex)) { @@ -360,6 +362,7 @@ void FileChoose_CopyConfirm(GameState* thisx) { SramContext* sramCtx = &this->sramCtx; Input* input = &this->state.input[0]; u16 dayTime; + bool dpad = CVar_GetS32("gDpadPauseName", 0); if (((this->buttonIndex != FS_BTN_CONFIRM_YES) && CHECK_BTN_ANY(input->press.button, BTN_A | BTN_START)) || CHECK_BTN_ALL(input->press.button, BTN_B)) { @@ -377,7 +380,7 @@ void FileChoose_CopyConfirm(GameState* thisx) { this->configMode = CM_COPY_ANIM_1; func_800AA000(300.0f, 0xB4, 0x14, 0x64); Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); - } else if (ABS(this->stickRelY) >= 30) { + } else if ((ABS(this->stickRelY) >= 30) || (dpad && CHECK_BTN_ANY(input->press.button, BTN_DDOWN | BTN_DUP))) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); this->buttonIndex ^= 1; } @@ -680,6 +683,7 @@ void FileChoose_EraseSelect(GameState* thisx) { FileChooseContext* this = (FileChooseContext*)thisx; SramContext* sramCtx = &this->sramCtx; Input* input = &this->state.input[0]; + bool dpad = CVar_GetS32("gDpadPauseName", 0); if (((this->buttonIndex == FS_BTN_COPY_QUIT) && CHECK_BTN_ANY(input->press.button, BTN_A | BTN_START)) || CHECK_BTN_ALL(input->press.button, BTN_B)) { @@ -700,10 +704,10 @@ void FileChoose_EraseSelect(GameState* thisx) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); } } else { - if (ABS(this->stickRelY) >= 30) { + if ((ABS(this->stickRelY) >= 30) || (dpad && CHECK_BTN_ANY(input->press.button, BTN_DDOWN | BTN_DUP))) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); - if (this->stickRelY >= 30) { + if ((this->stickRelY >= 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) { this->buttonIndex--; if (this->buttonIndex < FS_BTN_ERASE_FILE_1) { this->buttonIndex = FS_BTN_ERASE_QUIT; @@ -817,6 +821,7 @@ void FileChoose_SetupEraseConfirm2(GameState* thisx) { void FileChoose_EraseConfirm(GameState* thisx) { FileChooseContext* this = (FileChooseContext*)thisx; Input* input = &this->state.input[0]; + bool dpad = CVar_GetS32("gDpadPauseName", 0); if (((this->buttonIndex != FS_BTN_CONFIRM_YES) && CHECK_BTN_ANY(input->press.button, BTN_A | BTN_START)) || CHECK_BTN_ALL(input->press.button, BTN_B)) { @@ -833,7 +838,7 @@ void FileChoose_EraseConfirm(GameState* thisx) { this->nextTitleLabel = FS_TITLE_ERASE_COMPLETE; func_800AA000(200.0f, 0xFF, 0x14, 0x96); sEraseDelayTimer = 15; - } else if (ABS(this->stickRelY) >= 30) { + } else if ((ABS(this->stickRelY) >= 30) || (dpad && CHECK_BTN_ANY(input->press.button, BTN_DDOWN | BTN_DUP))) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); this->buttonIndex ^= 1; } diff --git a/soh/src/overlays/gamestates/ovl_file_choose/z_file_nameset_PAL.c b/soh/src/overlays/gamestates/ovl_file_choose/z_file_nameset_PAL.c index 73aa5e6d1..501986d2b 100644 --- a/soh/src/overlays/gamestates/ovl_file_choose/z_file_nameset_PAL.c +++ b/soh/src/overlays/gamestates/ovl_file_choose/z_file_nameset_PAL.c @@ -509,12 +509,14 @@ void FileChoose_StartNameEntry(GameState* thisx) { */ void FileChoose_UpdateKeyboardCursor(GameState* thisx) { FileChooseContext* this = (FileChooseContext*)thisx; + Input* input = &this->state.input[0]; s16 prevKbdX; + bool dpad = CVar_GetS32("gDpadPauseName", 0); this->kbdButton = 99; if (this->kbdY != 5) { - if (this->stickRelX < -30) { + if ((this->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); this->charIndex--; this->kbdX--; @@ -522,7 +524,7 @@ void FileChoose_UpdateKeyboardCursor(GameState* thisx) { this->kbdX = 12; this->charIndex = (this->kbdY * 13) + this->kbdX; } - } else if (this->stickRelX > 30) { + } else if ((this->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); this->charIndex++; this->kbdX++; @@ -532,13 +534,13 @@ void FileChoose_UpdateKeyboardCursor(GameState* thisx) { } } } else { - if (this->stickRelX < -30) { + if ((this->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); this->kbdX--; if (this->kbdX < 3) { this->kbdX = 4; } - } else if (this->stickRelX > 30) { + } else if ((this->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); this->kbdX++; if (this->kbdX > 4) { @@ -547,7 +549,7 @@ void FileChoose_UpdateKeyboardCursor(GameState* thisx) { } } - if (this->stickRelY > 30) { + if ((this->stickRelY > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); this->kbdY--; @@ -578,7 +580,7 @@ void FileChoose_UpdateKeyboardCursor(GameState* thisx) { this->charIndex += this->kbdX; } } - } else if (this->stickRelY < -30) { + } else if ((this->stickRelY < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DDOWN))) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); this->kbdY++; @@ -655,6 +657,7 @@ void FileChoose_UpdateOptionsMenu(GameState* thisx) { FileChooseContext* this = (FileChooseContext*)thisx; SramContext* sramCtx = &this->sramCtx; Input* input = &this->state.input[0]; + bool dpad = CVar_GetS32("gDpadPauseName", 0); if (CHECK_BTN_ALL(input->press.button, BTN_B)) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); @@ -675,7 +678,7 @@ void FileChoose_UpdateOptionsMenu(GameState* thisx) { return; } - if (this->stickRelX < -30) { + if ((this->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); if (sSelectedSetting == FS_SETTING_AUDIO) { @@ -688,7 +691,7 @@ void FileChoose_UpdateOptionsMenu(GameState* thisx) { } else { gSaveContext.zTargetSetting ^= 1; } - } else if (this->stickRelX > 30) { + } else if ((this->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); if (sSelectedSetting == FS_SETTING_AUDIO) { @@ -702,7 +705,7 @@ void FileChoose_UpdateOptionsMenu(GameState* thisx) { } } - if ((this->stickRelY < -30) || (this->stickRelY > 30)) { + if ((ABS(this->stickRelY) > 30) || (dpad && CHECK_BTN_ANY(input->press.button, BTN_DDOWN | BTN_DUP))) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); sSelectedSetting ^= 1; } else if (CHECK_BTN_ALL(input->press.button, BTN_A)) { diff --git a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_collect.c b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_collect.c index 46be1154f..80ffe8d4a 100644 --- a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_collect.c +++ b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_collect.c @@ -74,6 +74,7 @@ void KaleidoScope_DrawQuestStatus(GlobalContext* globalCtx, GraphicsContext* gfx s16 pad2; s16 phi_s0_2; s16 sp208[3]; + bool dpad = CVar_GetS32("gDpadPauseName", 0); OPEN_DISPS(gfxCtx, "../z_kaleido_collect.c", 248); @@ -83,96 +84,92 @@ void KaleidoScope_DrawQuestStatus(GlobalContext* globalCtx, GraphicsContext* gfx if (pauseCtx->cursorSpecialPos == 0) { pauseCtx->nameColorSet = 0; + sp216 = pauseCtx->cursorSlot[PAUSE_QUEST]; + phi_s3 = pauseCtx->cursorPoint[PAUSE_QUEST]; - if ((pauseCtx->state != 6) || ((pauseCtx->stickRelX == 0) && (pauseCtx->stickRelY == 0))) { - sp216 = pauseCtx->cursorSlot[PAUSE_QUEST]; - } else { - phi_s3 = pauseCtx->cursorPoint[PAUSE_QUEST]; - - if (pauseCtx->stickRelX < -30) { - phi_s0 = D_8082A1AC[phi_s3][2]; - if (phi_s0 == -3) { - KaleidoScope_MoveCursorToSpecialPos(globalCtx, PAUSE_CURSOR_PAGE_LEFT); - pauseCtx->unk_1E4 = 0; - } else { - while (phi_s0 >= 0) { - if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, phi_s0) != 0) { - break; - } - phi_s0 = D_8082A1AC[phi_s0][2]; - } - } - } else if (pauseCtx->stickRelX > 30) { - phi_s0 = D_8082A1AC[phi_s3][3]; - if (phi_s0 == -2) { - KaleidoScope_MoveCursorToSpecialPos(globalCtx, PAUSE_CURSOR_PAGE_RIGHT); - pauseCtx->unk_1E4 = 0; - } else { - while (phi_s0 >= 0) { - if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, phi_s0) != 0) { - break; - } - phi_s0 = D_8082A1AC[phi_s0][3]; - } - } - } - - if (pauseCtx->stickRelY < -30) { - phi_s0 = D_8082A1AC[phi_s3][1]; - while (phi_s0 >= 0) { - if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, phi_s0) != 0) { - break; - } - phi_s0 = D_8082A1AC[phi_s0][1]; - } - } else if (pauseCtx->stickRelY > 30) { - phi_s0 = D_8082A1AC[phi_s3][0]; - while (phi_s0 >= 0) { - if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, phi_s0) != 0) { - break; - } - phi_s0 = D_8082A1AC[phi_s0][0]; - } - } - - if (phi_s3 != pauseCtx->cursorPoint[PAUSE_QUEST]) { + if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) { + phi_s0 = D_8082A1AC[phi_s3][2]; + if (phi_s0 == -3) { + KaleidoScope_MoveCursorToSpecialPos(globalCtx, PAUSE_CURSOR_PAGE_LEFT); pauseCtx->unk_1E4 = 0; - Audio_PlaySoundGeneral(NA_SE_SY_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); - } - - if (pauseCtx->cursorPoint[PAUSE_QUEST] != 0x18) { - if (CHECK_QUEST_ITEM(pauseCtx->cursorPoint[PAUSE_QUEST])) { - if (pauseCtx->cursorPoint[PAUSE_QUEST] < 6) { - phi_s0_2 = pauseCtx->cursorPoint[PAUSE_QUEST] + 0x66; - osSyncPrintf("000 ccc=%d\n", phi_s0_2); - } else if (pauseCtx->cursorPoint[PAUSE_QUEST] < 0x12) { - phi_s0_2 = pauseCtx->cursorPoint[PAUSE_QUEST] + 0x54; - osSyncPrintf("111 ccc=%d\n", phi_s0_2); - } else { - phi_s0_2 = pauseCtx->cursorPoint[PAUSE_QUEST] + 0x5A; - osSyncPrintf("222 ccc=%d (%d, %d, %d)\n", phi_s0_2, pauseCtx->cursorPoint[PAUSE_QUEST], - 0x12, 0x6C); + } else { + while (phi_s0 >= 0) { + if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, phi_s0) != 0) { + break; } + phi_s0 = D_8082A1AC[phi_s0][2]; + } + } + } else if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) { + phi_s0 = D_8082A1AC[phi_s3][3]; + if (phi_s0 == -2) { + KaleidoScope_MoveCursorToSpecialPos(globalCtx, PAUSE_CURSOR_PAGE_RIGHT); + pauseCtx->unk_1E4 = 0; + } else { + while (phi_s0 >= 0) { + if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, phi_s0) != 0) { + break; + } + phi_s0 = D_8082A1AC[phi_s0][3]; + } + } + } + + if ((pauseCtx->stickRelY < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DDOWN))) { + phi_s0 = D_8082A1AC[phi_s3][1]; + while (phi_s0 >= 0) { + if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, phi_s0) != 0) { + break; + } + phi_s0 = D_8082A1AC[phi_s0][1]; + } + } else if ((pauseCtx->stickRelY > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) { + phi_s0 = D_8082A1AC[phi_s3][0]; + while (phi_s0 >= 0) { + if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, phi_s0) != 0) { + break; + } + phi_s0 = D_8082A1AC[phi_s0][0]; + } + } + + if (phi_s3 != pauseCtx->cursorPoint[PAUSE_QUEST]) { + pauseCtx->unk_1E4 = 0; + Audio_PlaySoundGeneral(NA_SE_SY_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + + if (pauseCtx->cursorPoint[PAUSE_QUEST] != 0x18) { + if (CHECK_QUEST_ITEM(pauseCtx->cursorPoint[PAUSE_QUEST])) { + if (pauseCtx->cursorPoint[PAUSE_QUEST] < 6) { + phi_s0_2 = pauseCtx->cursorPoint[PAUSE_QUEST] + 0x66; + osSyncPrintf("000 ccc=%d\n", phi_s0_2); + } else if (pauseCtx->cursorPoint[PAUSE_QUEST] < 0x12) { + phi_s0_2 = pauseCtx->cursorPoint[PAUSE_QUEST] + 0x54; + osSyncPrintf("111 ccc=%d\n", phi_s0_2); } else { - phi_s0_2 = PAUSE_ITEM_NONE; - osSyncPrintf("999 ccc=%d (%d, %d)\n", PAUSE_ITEM_NONE, pauseCtx->cursorPoint[PAUSE_QUEST], - 0x18); + phi_s0_2 = pauseCtx->cursorPoint[PAUSE_QUEST] + 0x5A; + osSyncPrintf("222 ccc=%d (%d, %d, %d)\n", phi_s0_2, pauseCtx->cursorPoint[PAUSE_QUEST], + 0x12, 0x6C); } } else { - if ((gSaveContext.inventory.questItems & 0xF0000000) != 0) { - phi_s0_2 = 0x72; - } else { - phi_s0_2 = PAUSE_ITEM_NONE; - } - osSyncPrintf("888 ccc=%d (%d, %d, %x)\n", phi_s0_2, pauseCtx->cursorPoint[PAUSE_QUEST], 0x72, - gSaveContext.inventory.questItems & 0xF0000000); + phi_s0_2 = PAUSE_ITEM_NONE; + osSyncPrintf("999 ccc=%d (%d, %d)\n", PAUSE_ITEM_NONE, pauseCtx->cursorPoint[PAUSE_QUEST], + 0x18); } - - sp216 = pauseCtx->cursorPoint[PAUSE_QUEST]; - pauseCtx->cursorItem[pauseCtx->pageIndex] = phi_s0_2; - pauseCtx->cursorSlot[pauseCtx->pageIndex] = sp216; + } else { + if ((gSaveContext.inventory.questItems & 0xF0000000) != 0) { + phi_s0_2 = 0x72; + } else { + phi_s0_2 = PAUSE_ITEM_NONE; + } + osSyncPrintf("888 ccc=%d (%d, %d, %x)\n", phi_s0_2, pauseCtx->cursorPoint[PAUSE_QUEST], 0x72, + gSaveContext.inventory.questItems & 0xF0000000); } + sp216 = pauseCtx->cursorPoint[PAUSE_QUEST]; + pauseCtx->cursorItem[pauseCtx->pageIndex] = phi_s0_2; + pauseCtx->cursorSlot[pauseCtx->pageIndex] = sp216; + KaleidoScope_SetCursorVtx(pauseCtx, sp216 * 4, pauseCtx->questVtx); if ((pauseCtx->state == 6) && (pauseCtx->unk_1E4 == 0) && (pauseCtx->cursorSpecialPos == 0)) { @@ -215,7 +212,7 @@ void KaleidoScope_DrawQuestStatus(GlobalContext* globalCtx, GraphicsContext* gfx } } } else if (pauseCtx->cursorSpecialPos == PAUSE_CURSOR_PAGE_LEFT) { - if (pauseCtx->stickRelX > 30) { + if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) { pauseCtx->cursorPoint[PAUSE_QUEST] = 0x15; pauseCtx->nameDisplayTimer = 0; pauseCtx->cursorSpecialPos = 0; @@ -232,7 +229,7 @@ void KaleidoScope_DrawQuestStatus(GlobalContext* globalCtx, GraphicsContext* gfx pauseCtx->cursorSlot[pauseCtx->pageIndex] = sp216; } } else { - if (pauseCtx->stickRelX < -30) { + if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) { pauseCtx->cursorPoint[PAUSE_QUEST] = 0; pauseCtx->nameDisplayTimer = 0; pauseCtx->cursorSpecialPos = 0; diff --git a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_equipment.c b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_equipment.c index 3c236637b..52019dcb2 100644 --- a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_equipment.c +++ b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_equipment.c @@ -140,6 +140,7 @@ void KaleidoScope_DrawEquipment(GlobalContext* globalCtx) { s16 cursorX; s16 cursorY; volatile s16 oldCursorPoint; + bool dpad = CVar_GetS32("gDpadPauseName", 0); OPEN_DISPS(globalCtx->state.gfxCtx, "../z_kaleido_equipment.c", 219); @@ -174,7 +175,7 @@ void KaleidoScope_DrawEquipment(GlobalContext* globalCtx) { cursorMoveResult = 0; while (cursorMoveResult == 0) { - if (pauseCtx->stickRelX < -30) { + if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) { if (pauseCtx->cursorX[PAUSE_EQUIP] != 0) { pauseCtx->cursorX[PAUSE_EQUIP] -= 1; pauseCtx->cursorPoint[PAUSE_EQUIP] -= 1; @@ -216,7 +217,7 @@ void KaleidoScope_DrawEquipment(GlobalContext* globalCtx) { cursorMoveResult = 3; } } - } else if (pauseCtx->stickRelX > 30) { + } else if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) { if (pauseCtx->cursorX[PAUSE_EQUIP] < 3) { pauseCtx->cursorX[PAUSE_EQUIP] += 1; pauseCtx->cursorPoint[PAUSE_EQUIP] += 1; @@ -264,7 +265,7 @@ void KaleidoScope_DrawEquipment(GlobalContext* globalCtx) { cursorMoveResult = 0; while (cursorMoveResult == 0) { - if (pauseCtx->stickRelY > 30) { + if ((pauseCtx->stickRelY > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) { if (pauseCtx->cursorY[PAUSE_EQUIP] != 0) { pauseCtx->cursorY[PAUSE_EQUIP] -= 1; pauseCtx->cursorPoint[PAUSE_EQUIP] -= 4; @@ -286,7 +287,7 @@ void KaleidoScope_DrawEquipment(GlobalContext* globalCtx) { pauseCtx->cursorPoint[PAUSE_EQUIP] = cursorPoint; cursorMoveResult = 3; } - } else if (pauseCtx->stickRelY < -30) { + } else if ((pauseCtx->stickRelY < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DDOWN))) { if (pauseCtx->cursorY[PAUSE_EQUIP] < 3) { pauseCtx->cursorY[PAUSE_EQUIP] += 1; pauseCtx->cursorPoint[PAUSE_EQUIP] += 4; @@ -309,7 +310,7 @@ void KaleidoScope_DrawEquipment(GlobalContext* globalCtx) { } } } else if (pauseCtx->cursorSpecialPos == PAUSE_CURSOR_PAGE_LEFT) { - if (pauseCtx->stickRelX > 30) { + if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) { pauseCtx->nameDisplayTimer = 0; pauseCtx->cursorSpecialPos = 0; @@ -356,7 +357,7 @@ void KaleidoScope_DrawEquipment(GlobalContext* globalCtx) { } } } else { - if (pauseCtx->stickRelX < -30) { + if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) { pauseCtx->nameDisplayTimer = 0; pauseCtx->cursorSpecialPos = 0; Audio_PlaySoundGeneral(NA_SE_SY_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); diff --git a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_item.c b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_item.c index bb42ff711..d39a90e16 100644 --- a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_item.c +++ b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_item.c @@ -96,6 +96,7 @@ void KaleidoScope_DrawItemSelect(GlobalContext* globalCtx) { s16 cursorY; s16 oldCursorPoint; s16 moveCursorResult; + bool dpad = CVar_GetS32("gDpadPauseName", 0); OPEN_DISPS(globalCtx->state.gfxCtx, "../z_kaleido_item.c", 234); @@ -120,7 +121,7 @@ void KaleidoScope_DrawItemSelect(GlobalContext* globalCtx) { pauseCtx->stickRelX = 40; } - if (ABS(pauseCtx->stickRelX) > 30) { + if ((ABS(pauseCtx->stickRelX) > 30) || (dpad && CHECK_BTN_ANY(input->press.button, BTN_DLEFT | BTN_DRIGHT))) { cursorPoint = pauseCtx->cursorPoint[PAUSE_ITEM]; cursorX = pauseCtx->cursorX[PAUSE_ITEM]; cursorY = pauseCtx->cursorY[PAUSE_ITEM]; @@ -132,7 +133,7 @@ void KaleidoScope_DrawItemSelect(GlobalContext* globalCtx) { if (gSaveContext.inventory.items[pauseCtx->cursorPoint[PAUSE_ITEM]]) {} while (moveCursorResult == 0) { - if (pauseCtx->stickRelX < -30) { + if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) { if (pauseCtx->cursorX[PAUSE_ITEM] != 0) { pauseCtx->cursorX[PAUSE_ITEM] -= 1; pauseCtx->cursorPoint[PAUSE_ITEM] -= 1; @@ -164,7 +165,7 @@ void KaleidoScope_DrawItemSelect(GlobalContext* globalCtx) { moveCursorResult = 2; } } - } else if (pauseCtx->stickRelX > 30) { + } else if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) { if (pauseCtx->cursorX[PAUSE_ITEM] < 5) { pauseCtx->cursorX[PAUSE_ITEM] += 1; pauseCtx->cursorPoint[PAUSE_ITEM] += 1; @@ -208,7 +209,7 @@ void KaleidoScope_DrawItemSelect(GlobalContext* globalCtx) { cursorItem, pauseCtx->cursorSpecialPos); } } else if (pauseCtx->cursorSpecialPos == PAUSE_CURSOR_PAGE_LEFT) { - if (pauseCtx->stickRelX > 30) { + if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) { pauseCtx->nameDisplayTimer = 0; pauseCtx->cursorSpecialPos = 0; @@ -242,7 +243,7 @@ void KaleidoScope_DrawItemSelect(GlobalContext* globalCtx) { } } } else { - if (pauseCtx->stickRelX < -30) { + if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) { pauseCtx->nameDisplayTimer = 0; pauseCtx->cursorSpecialPos = 0; @@ -280,13 +281,13 @@ void KaleidoScope_DrawItemSelect(GlobalContext* globalCtx) { if (pauseCtx->cursorSpecialPos == 0) { if (cursorItem != PAUSE_ITEM_NONE) { - if (ABS(pauseCtx->stickRelY) > 30) { + if ((ABS(pauseCtx->stickRelY) > 30) || (dpad && CHECK_BTN_ANY(input->press.button, BTN_DDOWN | BTN_DUP))) { moveCursorResult = 0; cursorPoint = pauseCtx->cursorPoint[PAUSE_ITEM]; cursorY = pauseCtx->cursorY[PAUSE_ITEM]; while (moveCursorResult == 0) { - if (pauseCtx->stickRelY > 30) { + if ((pauseCtx->stickRelY > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) { if (pauseCtx->cursorY[PAUSE_ITEM] != 0) { pauseCtx->cursorY[PAUSE_ITEM] -= 1; pauseCtx->cursorPoint[PAUSE_ITEM] -= 6; @@ -300,7 +301,7 @@ void KaleidoScope_DrawItemSelect(GlobalContext* globalCtx) { moveCursorResult = 2; } - } else if (pauseCtx->stickRelY < -30) { + } else if ((pauseCtx->stickRelY < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DDOWN))) { if (pauseCtx->cursorY[PAUSE_ITEM] < 3) { pauseCtx->cursorY[PAUSE_ITEM] += 1; pauseCtx->cursorPoint[PAUSE_ITEM] += 6; diff --git a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_map_PAL.c b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_map_PAL.c index af5c2b424..022fdd41d 100644 --- a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_map_PAL.c +++ b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_map_PAL.c @@ -36,6 +36,7 @@ void KaleidoScope_DrawDungeonMap(GlobalContext* globalCtx, GraphicsContext* gfxC static u16 mapBgPulseStage = 0; InterfaceContext* interfaceCtx = &globalCtx->interfaceCtx; PauseContext* pauseCtx = &globalCtx->pauseCtx; + Input* input = &globalCtx->state.input[0]; s16 i; s16 j; s16 oldCursorPoint; @@ -43,6 +44,7 @@ void KaleidoScope_DrawDungeonMap(GlobalContext* globalCtx, GraphicsContext* gfxC s16 stepG; s16 stepB; u16 rgba16; + bool dpad = CVar_GetS32("gDpadPauseName", 0); OPEN_DISPS(gfxCtx, "../z_kaleido_map_PAL.c", 123); @@ -51,7 +53,7 @@ void KaleidoScope_DrawDungeonMap(GlobalContext* globalCtx, GraphicsContext* gfxC oldCursorPoint = pauseCtx->cursorPoint[PAUSE_MAP]; if (pauseCtx->cursorSpecialPos == 0) { - if (pauseCtx->stickRelX > 30) { + if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) { if (pauseCtx->cursorX[PAUSE_MAP] != 0) { KaleidoScope_MoveCursorToSpecialPos(globalCtx, PAUSE_CURSOR_PAGE_RIGHT); } else { @@ -67,7 +69,7 @@ void KaleidoScope_DrawDungeonMap(GlobalContext* globalCtx, GraphicsContext* gfxC } } } - } else if (pauseCtx->stickRelX < -30) { + } else if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) { if (pauseCtx->cursorX[PAUSE_MAP] == 0) { KaleidoScope_MoveCursorToSpecialPos(globalCtx, PAUSE_CURSOR_PAGE_LEFT); } else { @@ -82,7 +84,7 @@ void KaleidoScope_DrawDungeonMap(GlobalContext* globalCtx, GraphicsContext* gfxC } if (pauseCtx->cursorPoint[PAUSE_MAP] < 3) { - if (pauseCtx->stickRelY > 30) { + if ((pauseCtx->stickRelY > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) { if (pauseCtx->cursorPoint[PAUSE_MAP] != 0) { for (i = pauseCtx->cursorPoint[PAUSE_MAP] - 1; i >= 0; i--) { if (CHECK_DUNGEON_ITEM(i, gSaveContext.mapIndex)) { @@ -92,7 +94,7 @@ void KaleidoScope_DrawDungeonMap(GlobalContext* globalCtx, GraphicsContext* gfxC } } } else { - if (pauseCtx->stickRelY < -30) { + if ((pauseCtx->stickRelY < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DDOWN))) { if (pauseCtx->cursorPoint[PAUSE_MAP] != 2) { for (i = pauseCtx->cursorPoint[PAUSE_MAP] + 1; i < 3; i++) { if (CHECK_DUNGEON_ITEM(i, gSaveContext.mapIndex)) { @@ -104,7 +106,7 @@ void KaleidoScope_DrawDungeonMap(GlobalContext* globalCtx, GraphicsContext* gfxC } } } else { - if (pauseCtx->stickRelY > 30) { + if ((pauseCtx->stickRelY > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) { if (pauseCtx->cursorPoint[PAUSE_MAP] >= 4) { for (i = pauseCtx->cursorPoint[PAUSE_MAP] - 3 - 1; i >= 0; i--) { if ((gSaveContext.sceneFlags[gSaveContext.mapIndex].floors & gBitFlags[i]) || @@ -115,7 +117,7 @@ void KaleidoScope_DrawDungeonMap(GlobalContext* globalCtx, GraphicsContext* gfxC } } } - } else if (pauseCtx->stickRelY < -30) { + } else if ((pauseCtx->stickRelY < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DDOWN))) { if (pauseCtx->cursorPoint[PAUSE_MAP] != 10) { for (i = pauseCtx->cursorPoint[PAUSE_MAP] - 3 + 1; i < 11; i++) { if ((gSaveContext.sceneFlags[gSaveContext.mapIndex].floors & gBitFlags[i]) || @@ -138,7 +140,7 @@ void KaleidoScope_DrawDungeonMap(GlobalContext* globalCtx, GraphicsContext* gfxC } } } else if (pauseCtx->cursorSpecialPos == PAUSE_CURSOR_PAGE_LEFT) { - if (pauseCtx->stickRelX > 30) { + if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) { pauseCtx->nameDisplayTimer = 0; pauseCtx->cursorSpecialPos = 0; pauseCtx->cursorSlot[PAUSE_MAP] = pauseCtx->cursorPoint[PAUSE_MAP] = pauseCtx->dungeonMapSlot; @@ -148,7 +150,7 @@ void KaleidoScope_DrawDungeonMap(GlobalContext* globalCtx, GraphicsContext* gfxC Audio_PlaySoundGeneral(NA_SE_SY_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); } } else { - if (pauseCtx->stickRelX < -30) { + if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) { pauseCtx->nameDisplayTimer = 0; pauseCtx->cursorSpecialPos = 0; pauseCtx->cursorX[PAUSE_MAP] = 1; @@ -396,6 +398,7 @@ void KaleidoScope_DrawWorldMap(GlobalContext* globalCtx, GraphicsContext* gfxCtx }; static u16 D_8082A6D4 = 0; PauseContext* pauseCtx = &globalCtx->pauseCtx; + Input* input = &globalCtx->state.input[0]; s16 i; s16 j; s16 t; @@ -404,6 +407,7 @@ void KaleidoScope_DrawWorldMap(GlobalContext* globalCtx, GraphicsContext* gfxCtx s16 stepR; s16 stepG; s16 stepB; + bool dpad = CVar_GetS32("gDpadPauseName", 0); OPEN_DISPS(gfxCtx, "../z_kaleido_map_PAL.c", 556); @@ -412,7 +416,7 @@ void KaleidoScope_DrawWorldMap(GlobalContext* globalCtx, GraphicsContext* gfxCtx oldCursorPoint = pauseCtx->cursorPoint[PAUSE_WORLD_MAP]; if (pauseCtx->cursorSpecialPos == 0) { - if (pauseCtx->stickRelX > 30) { + if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) { D_8082A6D4 = 0; do { @@ -423,7 +427,7 @@ void KaleidoScope_DrawWorldMap(GlobalContext* globalCtx, GraphicsContext* gfxCtx break; } } while (pauseCtx->worldMapPoints[pauseCtx->cursorPoint[PAUSE_WORLD_MAP]] == 0); - } else if (pauseCtx->stickRelX < -30) { + } else if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) { D_8082A6D4 = 0; do { @@ -444,7 +448,7 @@ void KaleidoScope_DrawWorldMap(GlobalContext* globalCtx, GraphicsContext* gfxCtx } else { pauseCtx->cursorItem[PAUSE_MAP] = gSaveContext.worldMapArea + 0x18; if (pauseCtx->cursorSpecialPos == PAUSE_CURSOR_PAGE_LEFT) { - if (pauseCtx->stickRelX > 30) { + if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) { pauseCtx->cursorPoint[PAUSE_WORLD_MAP] = 0; pauseCtx->cursorSpecialPos = 0; @@ -459,7 +463,7 @@ void KaleidoScope_DrawWorldMap(GlobalContext* globalCtx, GraphicsContext* gfxCtx D_8082A6D4 = 0; } } else { - if (pauseCtx->stickRelX < -30) { + if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) { pauseCtx->cursorPoint[PAUSE_WORLD_MAP] = 11; pauseCtx->cursorSpecialPos = 0; @@ -663,7 +667,7 @@ void KaleidoScope_DrawWorldMap(GlobalContext* globalCtx, GraphicsContext* gfxCtx gDPLoadTextureBlock(POLY_KAL_DISP++, gWorldMapDotTex, G_IM_FMT_IA, G_IM_SIZ_8b, 8, 8, 0, G_TX_WRAP | G_TX_NOMIRROR, G_TX_WRAP | G_TX_NOMIRROR, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - for (j = i = 0; i < 12; i++, t++, j += 4) { + for (j = t = i = 0; i < 12; i++, t++, j += 4) { if (pauseCtx->worldMapPoints[i] != 0) { gDPPipeSync(POLY_KAL_DISP++); diff --git a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_prompt.c b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_prompt.c index c16404fb2..bfb4897d8 100644 --- a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_prompt.c +++ b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_prompt.c @@ -7,12 +7,13 @@ void KaleidoScope_UpdatePrompt(GlobalContext* globalCtx) { Input* input = &globalCtx->state.input[0]; s8 relStickX = input->rel.stick_x; s16 step; + bool dpad = CVar_GetS32("gDpadPauseName", 0); if (((pauseCtx->state == 7) && (pauseCtx->unk_1EC == 1)) || (pauseCtx->state == 0xE) || (pauseCtx->state == 0x10)) { - if ((pauseCtx->promptChoice == 0) && (relStickX >= 30)) { + if ((pauseCtx->promptChoice == 0) && ((relStickX >= 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT)))) { Audio_PlaySoundGeneral(NA_SE_SY_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); pauseCtx->promptChoice = 4; - } else if ((pauseCtx->promptChoice != 0) && (relStickX <= -30)) { + } else if ((pauseCtx->promptChoice != 0) && ((relStickX <= -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT)))) { Audio_PlaySoundGeneral(NA_SE_SY_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); pauseCtx->promptChoice = 0; } diff --git a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c index 140aa7734..9db5399a4 100644 --- a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c +++ b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c @@ -936,8 +936,9 @@ void KaleidoScope_HandlePageToggles(PauseContext* pauseCtx, Input* input) { return; } + bool dpad = CVar_GetS32("gDpadPauseName", 0); if (pauseCtx->cursorSpecialPos == PAUSE_CURSOR_PAGE_LEFT) { - if (pauseCtx->stickRelX < -30) { + if ((pauseCtx->stickRelX < -30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DLEFT))) { pauseCtx->pageSwitchTimer++; if ((pauseCtx->pageSwitchTimer >= 10) || (pauseCtx->pageSwitchTimer == 0)) { KaleidoScope_SwitchPage(pauseCtx, 0); @@ -946,7 +947,7 @@ void KaleidoScope_HandlePageToggles(PauseContext* pauseCtx, Input* input) { pauseCtx->pageSwitchTimer = -1; } } else if (pauseCtx->cursorSpecialPos == PAUSE_CURSOR_PAGE_RIGHT) { - if (pauseCtx->stickRelX > 30) { + if ((pauseCtx->stickRelX > 30) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DRIGHT))) { pauseCtx->pageSwitchTimer++; if ((pauseCtx->pageSwitchTimer >= 10) || (pauseCtx->pageSwitchTimer == 0)) { KaleidoScope_SwitchPage(pauseCtx, 2);