diff --git a/.gitignore b/.gitignore index 2940b34a7ac..1d41d50aefe 100644 --- a/.gitignore +++ b/.gitignore @@ -401,10 +401,17 @@ ZAPD/BuildInfo.h DebugObj/* ReleaseObj/* +.tags +tags +oot.otr +*.sav +shipofharkinian.ini +shipofharkinian.json -// Switch Stuff +# Switch Stuff *.nro *.nacp ZAPDTR/ZAPDUtils/lib/* -!/soh/icon.jpg \ No newline at end of file +!/soh/icon.jpg + diff --git a/libultraship/Makefile.switch b/libultraship/Makefile.switch index b1e6e9e18b1..d8c93ad043d 100644 --- a/libultraship/Makefile.switch +++ b/libultraship/Makefile.switch @@ -77,8 +77,6 @@ SOURCEFILES_CPP := \ libultraship/Factories/VtxFactory.cpp \ libultraship/Array.cpp \ libultraship/Audio.cpp \ - libultraship/ConfigFile.cpp \ - libultraship/Controller.cpp \ libultraship/Hooks.cpp \ libultraship/Factories/CollisionHeaderFactory.cpp \ libultraship/Factories/DisplayListFactory.cpp \ diff --git a/libultraship/libultraship/Cvar.h b/libultraship/libultraship/Cvar.h index f9583ef0c95..717e21a1355 100644 --- a/libultraship/libultraship/Cvar.h +++ b/libultraship/libultraship/Cvar.h @@ -1,8 +1,6 @@ #ifndef _CVAR_H #define _CVAR_H -#include - typedef enum CVarType { CVAR_TYPE_S32, CVAR_TYPE_FLOAT, CVAR_TYPE_STRING } CVarType; typedef struct CVar { @@ -10,7 +8,7 @@ typedef struct CVar { CVarType type; union { - s32 valueS32; + int valueS32; float valueFloat; const char* valueStr; } value; @@ -23,13 +21,13 @@ extern "C" //#include CVar* CVar_Get(const char* name); -s32 CVar_GetS32(const char* name, s32 defaultValue); +int CVar_GetS32(const char* name, int defaultValue); float CVar_GetFloat(const char* name, float defaultValue); const char* CVar_GetString(const char* name, const char* defaultValue); -void CVar_SetS32(const char* name, s32 value); +void CVar_SetS32(const char* name, int value); void CVar_SetString(const char* name, const char* value); -void CVar_RegisterS32(const char* name, s32 defaultValue); +void CVar_RegisterS32(const char* name, int defaultValue); void CVar_RegisterFloat(const char* name, float defaultValue); void CVar_RegisterString(const char* name, const char* defaultValue); diff --git a/libultraship/libultraship/GlobalCtx2.cpp b/libultraship/libultraship/GlobalCtx2.cpp index fb6219cb654..e44f0de8e20 100644 --- a/libultraship/libultraship/GlobalCtx2.cpp +++ b/libultraship/libultraship/GlobalCtx2.cpp @@ -8,6 +8,9 @@ #include "spdlog/sinks/stdout_color_sinks.h" #include "spdlog/sinks/sohconsole_sink.h" #include "ModManager.h" +#ifdef __APPLE__ +#include "OSXFolderManager.h" +#endif namespace Ship { std::weak_ptr GlobalCtx2::Context; @@ -29,7 +32,23 @@ namespace Ship { return GetInstance(); } - GlobalCtx2::GlobalCtx2(const std::string& Name) : Name(Name), MainPath(""), PatchesPath("") { + std::string GlobalCtx2::GetAppDirectoryPath() { + #ifdef __APPLE__ + FolderManager folderManager; + std::string fpath = std::string(folderManager.pathForDirectory(NSApplicationSupportDirectory, NSUserDomainMask)); + fpath.append("/com.shipofharkinian.soh"); + return fpath; + #endif + + return "."; + + } + + std::string GlobalCtx2::GetPathRelativeToAppDirectory(const char* path) { + return GlobalCtx2::GetAppDirectoryPath() + "/" + path; + } + + GlobalCtx2::GlobalCtx2(std::string Name) : Name(std::move(Name)) { } @@ -40,22 +59,19 @@ namespace Ship { void GlobalCtx2::InitWindow() { InitLogging(); - Config = std::make_shared(GlobalCtx2::GetInstance(), "shipofharkinian.ini"); - MainPath = (*Config)["ARCHIVE"]["Main Archive"]; - if (MainPath.empty()) { - MainPath = "oot.otr"; - } - PatchesPath = (*Config)["ARCHIVE"]["Patches Directory"]; - if (PatchesPath.empty()) { - PatchesPath = "./mods"; - } - ResMan = std::make_shared(GlobalCtx2::GetInstance(), MainPath, PatchesPath); - Win = std::make_shared(GlobalCtx2::GetInstance()); + Config = std::make_shared(GetPathRelativeToAppDirectory("shipofharkinian.json")); + Config->reload(); + + MainPath = Config->getString("Game.Main Archive", GetPathRelativeToAppDirectory("oot.otr")); + PatchesPath = Config->getString("Game.Patches Archive", GetAppDirectoryPath() + "/mods"); + + ResMan = std::make_shared(GetInstance(), MainPath, PatchesPath); + Win = std::make_shared(GetInstance()); if (!ResMan->DidLoadSuccessfully()) { #ifdef _WIN32 - MessageBox(NULL, L"Main OTR file not found!", L"Uh oh", MB_OK); + MessageBox(nullptr, L"Main OTR file not found!", L"Uh oh", MB_OK); #elif defined(__SWITCH__) printf("Main OTR file not found!\n"); #else @@ -69,11 +85,13 @@ namespace Ship { void GlobalCtx2::InitLogging() { try { + auto logPath = GetPathRelativeToAppDirectory(("logs/" + GetName() + ".log").c_str()); + // Setup Logging spdlog::init_thread_pool(8192, 1); auto SohConsoleSink = std::make_shared(); auto ConsoleSink = std::make_shared(); - auto FileSink = std::make_shared("logs/" + GetName() + ".log", 1024 * 1024 * 10, 10); + auto FileSink = std::make_shared(logPath, 1024 * 1024 * 10, 10); SohConsoleSink->set_level(spdlog::level::trace); ConsoleSink->set_level(spdlog::level::trace); FileSink->set_level(spdlog::level::trace); @@ -88,4 +106,25 @@ namespace Ship { std::cout << "Log initialization failed: " << ex.what() << std::endl; } } -} \ No newline at end of file + + void GlobalCtx2::WriteSaveFile(const std::filesystem::path& savePath, const uintptr_t addr, void* dramAddr, const size_t size) { + std::ofstream saveFile = std::ofstream(savePath, std::fstream::in | std::fstream::out | std::fstream::binary); + saveFile.seekp(addr); + saveFile.write((char*)dramAddr, size); + saveFile.close(); + } + + void GlobalCtx2::ReadSaveFile(std::filesystem::path savePath, uintptr_t addr, void* dramAddr, size_t size) { + std::ifstream saveFile = std::ifstream(savePath, std::fstream::in | std::fstream::out | std::fstream::binary); + + // If the file doesn't exist, initialize DRAM + if (saveFile.good()) { + saveFile.seekg(addr); + saveFile.read((char*)dramAddr, size); + } else { + memset(dramAddr, 0, size); + } + + saveFile.close(); + } +} diff --git a/libultraship/libultraship/ImGuiImpl.cpp b/libultraship/libultraship/ImGuiImpl.cpp index 153a193e8d3..4d892b27846 100644 --- a/libultraship/libultraship/ImGuiImpl.cpp +++ b/libultraship/libultraship/ImGuiImpl.cpp @@ -26,6 +26,7 @@ #include "Lib/Fast3D/gfx_rendering_api.h" #include "Lib/spdlog/include/spdlog/common.h" #include "Utils/StringHelper.h" +#include "SwitchImpl.h" #ifdef ENABLE_OPENGL #include "Lib/ImGui/backends/imgui_impl_opengl3.h" @@ -47,11 +48,10 @@ bool oldCursorState = true; #define EXPERIMENTAL() \ ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(255, 50, 50, 255)); \ - ImGui::Text("Experimental"); \ - ImGui::PopStyleColor(); \ - ImGui::Separator(); + ImGui::Text("Experimental"); \ + ImGui::PopStyleColor(); \ + ImGui::Separator(); #define TOGGLE_BTN ImGuiKey_F1 -#define TOGGLE_PAD_BTN ImGuiKey_GamepadBack #define HOOK(b) if(b) needs_save = true; OSContPad* pads; @@ -68,6 +68,26 @@ namespace SohImGui { static ImVector s_GroupPanelLabelStack; bool p_open = false; bool needs_save = false; +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp +======== + std::vector CustomTexts; + int SelectedLanguage = CVar_GetS32("gLanguages", 0); //Default Language to 0=English 1=German 2=French + float kokiri_col[3] = { 0.118f, 0.41f, 0.106f }; + float goron_col[3] = { 0.392f, 0.078f, 0.0f }; + float zora_col[3] = { 0.0f, 0.235f, 0.392f }; + + float navi_idle_i_col[3] = { 0.0f, 0.0f, 0.0f }; + float navi_idle_o_col[3] = { 0.0f, 0.0f, 0.0f }; + + float navi_npc_i_col[3] = { 0.0f, 0.0f, 0.0f }; + float navi_npc_o_col[3] = { 0.0f, 0.0f, 0.0f }; + + float navi_enemy_i_col[3] = { 0.0f, 0.0f, 0.0f }; + float navi_enemy_o_col[3] = { 0.0f, 0.0f, 0.0f }; + + float navi_prop_i_col[3] = { 0.0f, 0.0f, 0.0f }; + float navi_prop_o_col[3] = { 0.0f, 0.0f, 0.0f }; +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp const char* filters[3] = { "Three-Point", @@ -91,15 +111,6 @@ namespace SohImGui { std::map> windowCategories; std::map customWindows; - int ClampFloatToInt(float value, int min, int max) { - return fmin(fmax(value, min), max); - } - - void Tooltip(const char* text) { - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("%s", text); - } - void ImGuiWMInit() { switch (impl.backend) { case Backend::SDL: @@ -114,6 +125,50 @@ namespace SohImGui { break; } + // OTRTODO: This gameplay specific stuff should not be in libultraship. This needs to be moved to soh and use sTunicColors + kokiri_col[0] = 30 / 255.0f; + kokiri_col[1] = 105 / 255.0f; + kokiri_col[2] = 27 / 255.0f; + + goron_col[0] = 100 / 255.0f; + goron_col[1] = 20 / 255.0f; + goron_col[2] = 0; + + zora_col[0] = 0; + zora_col[1] = 60 / 255.0f; + zora_col[2] = 100 / 255.0f; + + navi_idle_i_col[0] = 0; + navi_idle_i_col[1] = 0; + navi_idle_i_col[2] = 0; + + navi_idle_o_col[0] = 0; + navi_idle_o_col[1] = 0; + navi_idle_o_col[2] = 0; + + navi_npc_i_col[0] = 0; + navi_npc_i_col[1] = 0; + navi_npc_i_col[2] = 0; + + navi_npc_o_col[0] = 0; + navi_npc_o_col[1] = 0; + navi_npc_o_col[2] = 0; + + navi_enemy_i_col[0] = 0; + navi_enemy_i_col[1] = 0; + navi_enemy_i_col[2] = 0; + + navi_enemy_o_col[0] = 0; + navi_enemy_o_col[1] = 0; + navi_enemy_o_col[2] = 0; + + navi_prop_i_col[0] = 0; + navi_prop_i_col[1] = 0; + navi_prop_i_col[2] = 0; + + navi_prop_o_col[0] = 0; + navi_prop_o_col[1] = 0; + navi_prop_o_col[2] = 0; } void ImGuiBackendInit() { @@ -245,6 +300,7 @@ namespace SohImGui { stbi_image_free(img_data); } +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp void LoadPickersColors(ImVec4& ColorArray, const char* cvarname, const ImVec4& default_colors, bool has_alpha) { std::string Cvar_Red = cvarname; Cvar_Red += "R"; @@ -263,6 +319,8 @@ namespace SohImGui { } } +======== +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp void LoadResource(const std::string& name, const std::string& path, const ImVec4& tint) { GfxRenderingAPI* api = gfx_get_current_rendering_api(); const auto res = static_cast(GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(path).get()); @@ -315,9 +373,6 @@ namespace SohImGui { io = &ImGui::GetIO(); io->ConfigFlags |= ImGuiConfigFlags_DockingEnable; io->Fonts->AddFontDefault(); - if (CVar_GetS32("gOpenMenuBar", 0) != 1) { - SohImGui::overlay->TextDrawNotification(30.0f, true, "Press F1 to access enhancements menu"); - } auto imguiIniPath = Ship::GlobalCtx2::GetPathRelativeToAppDirectory("imgui.ini"); auto imguiLogPath = Ship::GlobalCtx2::GetPathRelativeToAppDirectory("imgui_log.txt"); @@ -332,8 +387,12 @@ namespace SohImGui { controller->Init(); ImGuiWMInit(); ImGuiBackendInit(); + #ifdef __SWITCH__ + ImGui::GetStyle().ScaleAllSizes(Ship::Switch::GetDPI() / 96.0f); + #endif + + ModInternal::registerHookListener({ GFX_INIT, [](const HookEvent ev) { - ModInternal::RegisterHook([] { if (GlobalCtx2::GetInstance()->GetWindow()->IsFullscreen()) ShowCursor(CVar_GetS32("gOpenMenuBar", 0), Dialogues::dLoadSettings); @@ -348,12 +407,27 @@ namespace SohImGui { LoadTexture("C-Right", "assets/ship_of_harkinian/buttons/CRight.png"); LoadTexture("C-Up", "assets/ship_of_harkinian/buttons/CUp.png"); LoadTexture("C-Down", "assets/ship_of_harkinian/buttons/CDown.png"); +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp }); ModInternal::RegisterHook([](OSContPad* cont_pad) { pads = cont_pad; }); +======== + } }); + + for (const auto& [i, controllers] : Ship::Window::Controllers) + { + CVar_SetFloat(StringHelper::Sprintf("gCont%i_GyroDriftX", i).c_str(), 0); + CVar_SetFloat(StringHelper::Sprintf("gCont%i_GyroDriftY", i).c_str(), 0); + needs_save = true; + } + + ModInternal::registerHookListener({ CONTROLLER_READ, [](const HookEvent ev) { + pads = static_cast(ev->baseArgs["cont_pad"]); + }}); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp Game::InitSettings(); CVar_SetS32("gRandoGenerating", 0); @@ -364,6 +438,11 @@ namespace SohImGui { } void Update(EventImpl event) { + #ifdef __SWITCH__ + int xPos, yPos; + Switch::GetTouchPosition(&xPos, &yPos); + io->MousePos = ImVec2(xPos, yPos); + #endif if (needs_save) { Game::SaveSettings(); needs_save = false; @@ -386,29 +465,7 @@ namespace SohImGui { } } - - void EnhancementCombobox(const char* name, const char* ComboArray[], size_t arraySize, uint8_t FirstTimeValue = 0) { - if (FirstTimeValue <= 0) { - FirstTimeValue = 0; - } - uint8_t selected = CVar_GetS32(name, FirstTimeValue); - uint8_t DefaultValue = selected; - std::string comboName = std::string("##") + std::string(name); - if (ImGui::BeginCombo(comboName.c_str(), ComboArray[DefaultValue])) { - for (uint8_t i = 0; i < arraySize; i++) { - if (strlen(ComboArray[i]) > 1) { - if (ImGui::Selectable(ComboArray[i], i == selected)) { - CVar_SetS32(name, i); - selected = i; - needs_save = true; - } - } - } - ImGui::EndCombo(); - } - } - - void EnhancementRadioButton(const char* text, const char* cvarName, int id) { + void EnhancementRadioButton(std::string text, std::string cvarName, int id) { /*Usage : EnhancementRadioButton("My Visible Name","gMyCVarName", MyID); First arg is the visible name of the Radio button @@ -419,147 +476,105 @@ namespace SohImGui { EnhancementRadioButton("German", "gLanguages", 1); EnhancementRadioButton("French", "gLanguages", 2); */ - std::string make_invisible = "##"; - make_invisible += text; - make_invisible += cvarName; - - int val = CVar_GetS32(cvarName, 0); - if (ImGui::RadioButton(make_invisible.c_str(), id == val)) { - CVar_SetS32(cvarName, id); + int val = CVar_GetS32(cvarName.c_str(), 0); + if (ImGui::RadioButton(text.c_str(), id==val)) { + CVar_SetS32(cvarName.c_str(), (int)id); needs_save = true; } - ImGui::SameLine(); - ImGui::Text("%s", text); } - void EnhancementCheckbox(const char* text, const char* cvarName) + void EnhancementCheckbox(std::string text, std::string cvarName) { - bool val = (bool)CVar_GetS32(cvarName, 0); - if (ImGui::Checkbox(text, &val)) { - CVar_SetS32(cvarName, val); + bool val = (bool)CVar_GetS32(cvarName.c_str(), 0); + if (ImGui::Checkbox(text.c_str(), &val)) { + CVar_SetS32(cvarName.c_str(), val); needs_save = true; } } - void EnhancementButton(const char* text, const char* cvarName) + void EnhancementButton(std::string text, std::string cvarName) { - bool val = (bool)CVar_GetS32(cvarName, 0); - if (ImGui::Button(text)) { - CVar_SetS32(cvarName, !val); - CVar_SetS32(cvarName, !val); + bool val = (bool)CVar_GetS32(cvarName.c_str(), 0); + if (ImGui::Button(text.c_str())) { + CVar_SetS32(cvarName.c_str(), !val); needs_save = true; } } +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp void EnhancementSliderInt(const char* text, const char* id, const char* cvarName, int min, int max, const char* format, int defaultValue) { int val = CVar_GetS32(cvarName, defaultValue); +======== + void EnhancementSliderInt(std::string text, std::string id, std::string cvarName, int min, int max, std::string format) + { + int val = CVar_GetS32(cvarName.c_str(), 0); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp - ImGui::Text(text, val); + ImGui::Text(text.c_str(), val); - if (ImGui::SliderInt(id, &val, min, max, format)) + if (ImGui::SliderInt(id.c_str(), &val, min, max, format.c_str())) { - CVar_SetS32(cvarName, val); + CVar_SetS32(cvarName.c_str(), val); needs_save = true; } if (val < min) { val = min; - CVar_SetS32(cvarName, val); + CVar_SetS32(cvarName.c_str(), val); needs_save = true; } if (val > max) { val = max; - CVar_SetS32(cvarName, val); + CVar_SetS32(cvarName.c_str(), val); needs_save = true; } } - void EnhancementSliderFloat(const char* text, const char* id, const char* cvarName, float min, float max, const char* format, float defaultValue, bool isPercentage) + void EnhancementSliderFloat(std::string text, std::string id, std::string cvarName, float min, float max, std::string format, float defaultValue, bool isPercentage) { - float val = CVar_GetFloat(cvarName, defaultValue); + float val = CVar_GetFloat(cvarName.c_str(), defaultValue); if (!isPercentage) - ImGui::Text(text, val); + ImGui::Text(text.c_str(), val); else - ImGui::Text(text, static_cast(100 * val)); + ImGui::Text(text.c_str(), static_cast(100 * val)); - if (ImGui::SliderFloat(id, &val, min, max, format)) + if (ImGui::SliderFloat(id.c_str(), &val, min, max, format.c_str())) { - CVar_SetFloat(cvarName, val); + CVar_SetFloat(cvarName.c_str(), val); needs_save = true; } if (val < min) { val = min; - CVar_SetFloat(cvarName, val); + CVar_SetFloat(cvarName.c_str(), val); needs_save = true; } if (val > max) { val = max; - CVar_SetFloat(cvarName, val); - needs_save = true; - } - } - - void EnhancementCombo(const std::string& name, const char* cvarName, const std::vector& items, int defaultValue) { - - if (ImGui::BeginCombo(name.c_str(), items[static_cast(CVar_GetS32(cvarName, defaultValue))].c_str())) { - for (int settingIndex = 0; settingIndex < (int) items.size(); settingIndex++) { - if (ImGui::Selectable(items[settingIndex].c_str())) { - CVar_SetS32(cvarName, settingIndex); - needs_save = true; - - } - } - ImGui::EndCombo(); - } - } - - void RandomizeColor(const char* cvarName, ImVec4* colors) { - std::string Cvar_Red = cvarName; - Cvar_Red += "R"; - std::string Cvar_Green = cvarName; - Cvar_Green += "G"; - std::string Cvar_Blue = cvarName; - Cvar_Blue += "B"; - std::string Cvar_RBM = cvarName; - Cvar_RBM += "RBM"; - std::string MakeInvisible = "##"; - MakeInvisible += cvarName; - MakeInvisible += "Random"; - std::string FullName = "Random"; - FullName += MakeInvisible; - if (ImGui::Button(FullName.c_str())) { - s16 RND_R = rand() % (255 - 0); - s16 RND_G = rand() % (255 - 0); - s16 RND_B = rand() % (255 - 0); - colors->x = (float)RND_R / 255; - colors->y = (float)RND_G / 255; - colors->z = (float)RND_B / 255; - CVar_SetS32(Cvar_Red.c_str(), ClampFloatToInt(colors->x * 255, 0, 255)); - CVar_SetS32(Cvar_Green.c_str(), ClampFloatToInt(colors->y * 255, 0, 255)); - CVar_SetS32(Cvar_Blue.c_str(), ClampFloatToInt(colors->z * 255, 0, 255)); - CVar_SetS32(Cvar_RBM.c_str(), 0); //On click disable rainbow mode. + CVar_SetFloat(cvarName.c_str(), val); needs_save = true; } +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp Tooltip("Chooses a random color\nOverwrites previously chosen color"); +======== +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp } - void RainbowColor(const char* cvarName, ImVec4* colors) { - std::string Cvar_RBM = cvarName; - Cvar_RBM += "RBM"; - std::string MakeInvisible = "Rainbow"; - MakeInvisible += "##"; - MakeInvisible += cvarName; - MakeInvisible += "Rainbow"; + void EnhancementColor3(std::string text, std::string cvarName, float defaultColors[3]) + { + int r = CVar_GetS32((cvarName + "_Red").c_str(), (defaultColors[0] * 255.0f)); + int g = CVar_GetS32((cvarName + "_Green").c_str(), (defaultColors[1] * 255.0f)); + int b = CVar_GetS32((cvarName + "_Blue").c_str(), (defaultColors[2] * 255.0f)); +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp EnhancementCheckbox(MakeInvisible.c_str(), Cvar_RBM.c_str()); Tooltip("Cycles through colors on a timer\nOverwrites previously chosen color"); } @@ -644,9 +659,30 @@ namespace SohImGui { } ImGui::NewLine(); ImGui::PopItemWidth(); +======== + float colors[3]; + colors[0] = r / 255.0f; + colors[1] = g / 255.0f; + colors[2] = b / 255.0f; + + { + if (ImGui::ColorEdit3(text.c_str(), colors)) + { + CVar_SetS32((cvarName + "_Red").c_str(), (int)(colors[0] * 255)); + CVar_SetS32((cvarName + "_Green").c_str(), (int)(colors[1] * 255)); + CVar_SetS32((cvarName + "_Blue").c_str(), (int)(colors[2] * 255)); + needs_save = true; + } + } + } + + void Tooltip(std::string text){ + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("%s", text.c_str()); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp } - void DrawMainMenuAndCalculateGameSize(void) { + void DrawMainMenuAndCalculateGameSize() { console->Update(); ImGuiBackendNewFrame(); ImGuiWMNewFrame(); @@ -660,7 +696,7 @@ namespace SohImGui { const ImGuiViewport* viewport = ImGui::GetMainViewport(); ImGui::SetNextWindowPos(viewport->WorkPos); - ImGui::SetNextWindowSize(ImVec2(wnd->GetCurrentWidth(), wnd->GetCurrentHeight())); + ImGui::SetNextWindowSize(ImVec2((int) wnd->GetCurrentWidth(), (int) wnd->GetCurrentHeight())); ImGui::SetNextWindowViewport(viewport->ID); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); @@ -755,6 +791,7 @@ namespace SohImGui { if (ImGui::BeginMenu("Controller")) { +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp EnhancementCheckbox("Use Controller Navigation", "gControlNav"); Tooltip("Allows controller navigation of the menu bar\nD-pad to move between items, A to select, and X to grab focus on the menu bar"); @@ -777,6 +814,49 @@ namespace SohImGui { EnhancementSliderFloat("Input Scale: %.1f", "##Input", "gInputScale", 1.0f, 3.0f, "", 1.0f, false); Tooltip("Sets the on screen size of the displayed inputs from the Show Inputs setting"); +======== + for (const auto& [i, controllers] : Ship::Window::Controllers) + { + bool hasPad = std::find_if(controllers.begin(), controllers.end(), [](const auto& c) { + return c->HasPadConf() && c->Connected(); + }) != controllers.end(); + + if (!hasPad) continue; + + auto menuLabel = "Controller " + std::to_string(i + 1); + if (ImGui::BeginMenu(menuLabel.c_str())) + { + EnhancementSliderFloat("Gyro Sensitivity: %d %%", "##GYROSCOPE", StringHelper::Sprintf("gCont%i_GyroSensitivity", i), 0.0f, 1.0f, "", 1.0f, true); + + if (ImGui::Button("Recalibrate Gyro")) + { + CVar_SetFloat(StringHelper::Sprintf("gCont%i_GyroDriftX", i).c_str(), 0); + CVar_SetFloat(StringHelper::Sprintf("gCont%i_GyroDriftY", i).c_str(), 0); + needs_save = true; + } + + ImGui::Separator(); + + EnhancementSliderFloat("Rumble Strength: %d %%", "##RUMBLE", StringHelper::Sprintf("gCont%i_RumbleStrength", i), 0.0f, 1.0f, "", 1.0f, true); + + ImGui::EndMenu(); + } + ImGui::Separator(); + } +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp + + EnhancementCheckbox("Show Inputs", "gInputEnabled"); + Tooltip("Shows currently pressed inputs on the bottom right of the screen"); + EnhancementCheckbox("Rumble Enabled", "gRumbleEnabled"); + + EnhancementSliderFloat("Input Scale: %.1f", "##Input", "gInputScale", 1.0f, 3.0f, "", 1.0f, false); + Tooltip("Sets the on screen size of the displayed inputs from Show Inputs"); + + ImGui::Separator(); + + EnhancementCheckbox("D-pad Support on Pause and File Select", "gDpadPauseName"); + EnhancementCheckbox("D-pad Support in Ocarina and Text Choice", "gDpadOcarinaText"); + EnhancementCheckbox("D-pad Support for Browsing Shop Items", "gDpadShop"); ImGui::EndMenu(); } @@ -785,6 +865,7 @@ namespace SohImGui { if (ImGui::BeginMenu("Graphics")) { +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp EnhancementSliderFloat("Internal Resolution: %d %%", "##IMul", "gInternalResolution", 0.5f, 2.0f, "", 1.0f, true); Tooltip("Multiplies your output resolution by the value inputted,\nas a more intensive but effective form of anti-aliasing"); gfx_current_dimensions.internal_mul = CVar_GetFloat("gInternalResolution", 1); @@ -822,11 +903,31 @@ namespace SohImGui { "to do CPU + GPU work in time."); } +======== + EnhancementSliderInt("Internal Resolution: %dx", "##IMul", "gInternalResolution", 1, 8, ""); + Tooltip("Increases the render resolution of the game, up to 8x your output resolution,\nas a more intensive but effective form of anti-aliasing"); + gfx_current_dimensions.internal_mul = CVar_GetS32("gInternalResolution", 1); + EnhancementSliderInt("MSAA: %d", "##IMSAA", "gMSAAValue", 1, 8, ""); + Tooltip("Activates anti-aliasing when above 1, up to 8x for 8 samples for every pixel"); + gfx_msaa_level = CVar_GetS32("gMSAAValue", 1); + +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp EXPERIMENTAL(); ImGui::Text("Texture Filter (Needs reload)"); - EnhancementCombobox("gTextureFilter", filters, 3, 0); GfxRenderingAPI* gapi = gfx_get_current_rendering_api(); - gapi->set_texture_filter((FilteringMode)CVar_GetS32("gTextureFilter", 0)); + if (ImGui::BeginCombo("##filters", filters[gapi->get_texture_filter()])) { + for (int fId = 0; fId <= FilteringMode::NONE; fId++) { + if (ImGui::Selectable(filters[fId], fId == gapi->get_texture_filter())) { + INFO("New Filter: %s", filters[fId]); + gapi->set_texture_filter((FilteringMode)fId); + + CVar_SetS32("gTextureFilter", (int) fId); + needs_save = true; + } + + } + ImGui::EndCombo(); + } overlay->DrawSettings(); ImGui::EndMenu(); } @@ -844,6 +945,7 @@ namespace SohImGui { if (ImGui::BeginMenu("Enhancements")) { +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp if (ImGui::BeginMenu("Gameplay")) { if (ImGui::BeginMenu("Time Savers")) @@ -1013,47 +1115,15 @@ namespace SohImGui { Tooltip("Allows graves to be pulled when child during the day"); ImGui::EndMenu(); } +======== + ImGui::Text("Gameplay"); + ImGui::Separator(); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp - if (ImGui::BeginMenu("Graphics")) - { - if (ImGui::BeginMenu("Animated Link in Pause Menu")) { - ImGui::Text("Rotation"); - EnhancementRadioButton("Disabled", "gPauseLiveLinkRotation", 0); - EnhancementRadioButton("Rotate Link with D-pad", "gPauseLiveLinkRotation", 1); - Tooltip("Allow you to rotate Link on the Equipment menu with the DPAD\nUse DPAD-Up or DPAD-Down to reset Link's rotation"); - EnhancementRadioButton("Rotate Link with C-buttons", "gPauseLiveLinkRotation", 2); - Tooltip("Allow you to rotate Link on the Equipment menu with the C-buttons\nUse C-Up or C-Down to reset Link's rotation"); - - if (CVar_GetS32("gPauseLiveLinkRotation", 0) != 0) { - EnhancementSliderInt("Rotation Speed: %d", "##MinRotationSpeed", "gPauseLiveLinkRotationSpeed", 1, 20, ""); - } - ImGui::Separator(); - ImGui::Text("Static loop"); - EnhancementRadioButton("Disabled", "gPauseLiveLink", 0); - EnhancementRadioButton("Idle (standing)", "gPauseLiveLink", 1); - EnhancementRadioButton("Idle (look around)", "gPauseLiveLink", 2); - EnhancementRadioButton("Idle (belt)", "gPauseLiveLink", 3); - EnhancementRadioButton("Idle (shield)", "gPauseLiveLink", 4); - EnhancementRadioButton("Idle (test sword)", "gPauseLiveLink", 5); - EnhancementRadioButton("Idle (yawn)", "gPauseLiveLink", 6); - EnhancementRadioButton("Battle Stance", "gPauseLiveLink", 7); - EnhancementRadioButton("Walking (no shield)", "gPauseLiveLink", 8); - EnhancementRadioButton("Walking (holding shield)", "gPauseLiveLink", 9); - EnhancementRadioButton("Running (no shield)", "gPauseLiveLink", 10); - EnhancementRadioButton("Running (holding shield)", "gPauseLiveLink", 11); - EnhancementRadioButton("Hand on hip", "gPauseLiveLink", 12); - EnhancementRadioButton("Spin attack charge", "gPauseLiveLink", 13); - EnhancementRadioButton("Look at hand", "gPauseLiveLink", 14); - ImGui::Separator(); - ImGui::Text("Randomize"); - EnhancementRadioButton("Random", "gPauseLiveLink", 15); - Tooltip("Randomize the animation played each time you open the menu"); - EnhancementRadioButton("Random cycle", "gPauseLiveLink", 16); - Tooltip("Randomize the animation played on the menu after a certain time"); - if (CVar_GetS32("gPauseLiveLink", 0) >= 16) { - EnhancementSliderInt("Frame to wait: %d", "##MinFrameCount", "gMinFrameCount", 1, 1000, ""); - } + EnhancementSliderInt("Text Speed: %dx", "##TEXTSPEED", "gTextSpeed", 1, 5, ""); + EnhancementSliderInt("King Zora Speed: %dx", "##WEEPSPEED", "gMweepSpeed", 1, 5, ""); +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp ImGui::EndMenu(); } EnhancementCheckbox("N64 Mode", "gN64Mode"); @@ -1066,10 +1136,21 @@ namespace SohImGui { Tooltip("Changes the rupee in the wallet icon to match the wallet size you currently have"); EnhancementCheckbox("Always show dungeon entrances", "gAlwaysShowDungeonMinimapIcon"); Tooltip("Always shows dungeon entrance icons on the minimap"); +======== + EnhancementCheckbox("Skip Text", "gSkipText"); + Tooltip("Holding down B skips text"); + EnhancementCheckbox("Minimal UI", "gMinimalUI"); + Tooltip("Hides most of the UI when not needed"); + EnhancementCheckbox("MM Bunny Hood", "gMMBunnyHood"); + Tooltip("Wearing the Bunny Hood grants a speed increase like in Majora's Mask"); + EnhancementCheckbox("Visual Stone of Agony", "gVisualAgony"); + Tooltip("Displays an icon and plays a sound when Stone of Agony should be activated, for those without rumble"); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp + + ImGui::Text("Graphics"); + ImGui::Separator(); - ImGui::EndMenu(); - } - +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp if (ImGui::BeginMenu("Fixes")) { EnhancementCheckbox("Fix L&R Pause menu", "gUniformLR"); @@ -1088,10 +1169,20 @@ namespace SohImGui { Tooltip("Correctly centers the Navi text prompt on the HUD's C-Up button"); EnhancementCheckbox("Fix Anubis fireballs", "gAnubisFix"); Tooltip("Make Anubis fireballs do fire damage when reflected\nback at them with the Mirror Shield"); - - ImGui::EndMenu(); - } - +======== + EnhancementCheckbox("N64 Mode", "gN64Mode"); + Tooltip("Sets aspect ratio to 4:3 and lowers resolution to 240p, the N64's native resolution"); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp + + EnhancementCheckbox("Animated Link in Pause Menu", "gPauseLiveLink"); + EnhancementCheckbox("Enable 3D Dropped items", "gNewDrops"); + EnhancementCheckbox("Faster Block Push", "gFasterBlockPush"); + EnhancementCheckbox("Dynamic Wallet Icon", "gDynamicWalletIcon"); + Tooltip("Changes the rupee in the wallet icon to match the wallet size you currently have"); + EnhancementCheckbox("Always show dungeon entrances", "gAlwaysShowDungeonMinimapIcon"); + Tooltip("Always shows dungeon entrance icons on the minimap"); + +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp if (ImGui::BeginMenu("Restoration")) { EnhancementCheckbox("Red Ganon blood", "gRedGanonBlood"); @@ -1163,10 +1254,68 @@ namespace SohImGui { EnhancementCheckbox("Free Camera", "gFreeCamera"); + #ifdef __SWITCH__ + int slot = CVar_GetS32("gSwitchPerfMode", (int)SwitchProfiles::STOCK); + ImGui::Text("Switch performance mode"); + if (ImGui::BeginCombo("##perf", SWITCH_CPU_PROFILES[slot])) { + for (int sId = 0; sId <= SwitchProfiles::POWERSAVINGM3; sId++) { + if (ImGui::Selectable(SWITCH_CPU_PROFILES[sId], sId == slot)) { + INFO("Profile:: %s", SWITCH_CPU_PROFILES[sId]); + CVar_SetS32("gSwitchPerfMode", sId); + needs_save = true; + } + + } + ImGui::EndCombo(); + } + #endif +======== + ImGui::Text("Fixes"); + ImGui::Separator(); + EnhancementCheckbox("Fix L&R Pause menu", "gUniformLR"); + Tooltip("Makes the L and R buttons in the pause menu the same color"); + EnhancementCheckbox("Fix Dungeon entrances", "gFixDungeonMinimapIcon"); + Tooltip("Show dungeon entrances icon only when it should be"); + EnhancementCheckbox("Fix Two Handed idle animations", "gTwoHandedIdle"); + Tooltip("Makes two handed idle animation play, a seemingly finished animation that was disabled on accident in the original game"); + + EXPERIMENTAL(); + + EnhancementCheckbox("60 fps interpolation", "g60FPS"); + EnhancementCheckbox("Disable LOD", "gDisableLOD"); + Tooltip("Turns off the level of detail setting, making models always use their higher poly variants"); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp + ImGui::EndMenu(); } +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp ImGui::SetCursorPosY(0.0f); +======== + if (ImGui::BeginMenu("Cosmetics")) + { + ImGui::Text("Tunics"); + ImGui::Separator(); + + EnhancementColor3("Kokiri Tunic", "gTunic_Kokiri", kokiri_col); + EnhancementColor3("Goron Tunic", "gTunic_Goron", goron_col); + EnhancementColor3("Zora Tunic", "gTunic_Zora", zora_col); + + ImGui::Text("Navi"); + ImGui::Separator(); + + EnhancementColor3("Navi Idle Inner", "gNavi_Idle_Inner", navi_idle_i_col); + EnhancementColor3("Navi Idle Outer", "gNavi_Idle_Outer", navi_idle_o_col); + EnhancementColor3("Navi NPC Inner", "gNavi_NPC_Inner", navi_npc_i_col); + EnhancementColor3("Navi NPC Outer", "gNavi_NPC_Outer", navi_npc_o_col); + EnhancementColor3("Navi Enemy Inner", "gNavi_Enemy_Inner", navi_enemy_i_col); + EnhancementColor3("Navi Enemy Outer", "gNavi_Enemy_Outer", navi_enemy_o_col); + EnhancementColor3("Navi Prop Inner", "gNavi_Prop_Inner", navi_prop_i_col); + EnhancementColor3("Navi Prop Outer", "gNavi_Prop_Outer", navi_prop_o_col); + + ImGui::EndMenu(); + } +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp if (ImGui::BeginMenu("Cheats")) { @@ -1182,18 +1331,23 @@ namespace SohImGui { } EnhancementCheckbox("No Clip", "gNoClip"); - Tooltip("Allows you to walk through walls"); + Tooltip("Allows you to walk through walls"); EnhancementCheckbox("Climb Everything", "gClimbEverything"); - Tooltip("Makes every surface in the game climbable"); + Tooltip("Makes every surface in the game climbable"); EnhancementCheckbox("Moon Jump on L", "gMoonJumpOnL"); - Tooltip("Holding L makes you float into the air"); + Tooltip("Holding L makes you float into the air"); EnhancementCheckbox("Super Tunic", "gSuperTunic"); - Tooltip("Makes every tunic have the effects of every other tunic"); + Tooltip("Makes every tunic have the effects of every other tunic"); EnhancementCheckbox("Easy ISG", "gEzISG"); +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp Tooltip("Passive Infinite Sword Glitch\nIt makes your sword's swing effect and hitbox stay active indefinitely"); +======== + Tooltip("Automatically activates the Infinite Sword glitch, making you constantly swing your sword"); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp EnhancementCheckbox("Unrestricted Items", "gNoRestrictItems"); - Tooltip("Allows you to use any item at any location"); + Tooltip("Allows you to use all items at any age"); EnhancementCheckbox("Freeze Time", "gFreezeTime"); +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp Tooltip("Freezes the time of day"); EnhancementCheckbox("Drops Don't Despawn", "gDropsDontDie"); Tooltip("Drops from enemies, grass, etc. don't disappear after a set amount of time"); @@ -1201,6 +1355,9 @@ namespace SohImGui { Tooltip("Prevents the Deku Shield from burning on contact with fire"); EnhancementCheckbox("Shield with Two-Handed Weapons", "gShieldTwoHanded"); Tooltip("This allows you to put up your shield with any two-handed weapon in hand\nexcept for Deku Sticks"); +======== + Tooltip("Freezes the time of day"); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp ImGui::EndMenu(); } @@ -1210,6 +1367,7 @@ namespace SohImGui { if (ImGui::BeginMenu("Developer Tools")) { EnhancementCheckbox("OoT Debug Mode", "gDebugEnabled"); +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp Tooltip("Enables Debug Mode, allowing you to select maps with L + R + Z, noclip with L + D-pad Right,\nand open the debug menu with L on the pause screen"); EnhancementCheckbox("Fast File Select", "gSkipLogoTitle"); Tooltip("Load the game to the selected slot below upon launch\nUse slot number 4 to load directly into the game's internal Map Select\n(Does not require the Debug Menu, but you will be unable to save there\nYou can also load the Map Select with OoT Debug Mode + slot 0)\nWith slot 0 you can directly go to the File Select menu\nAttention: loading an empty save file will result in a crash"); @@ -1221,6 +1379,14 @@ namespace SohImGui { Tooltip("Shows the stats window, with your FPS and frametimes,\nand the OS you're playing on"); EnhancementCheckbox("Console", "gConsoleEnabled"); Tooltip("Enables the console window, allowing you to input commands,\ntype help for some examples"); +======== + Tooltip("Enables Debug Mode, allowing you to select maps with L + R + Z, noclip with L + D-pad Right,\nand open the debug menu with L on the pause screen"); + ImGui::Separator(); + EnhancementCheckbox("Stats", "gStatsEnabled"); + Tooltip("Shows the stats window, with your FPS and frametimes, and the OS you're playing on"); + EnhancementCheckbox("Console", "gConsoleEnabled"); + Tooltip("Enables the console window, allowing you to input commands, type help for some examples"); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp console->opened = CVar_GetS32("gConsoleEnabled", 0); ImGui::EndMenu(); @@ -1231,10 +1397,14 @@ namespace SohImGui { if (ImGui::BeginMenu(category.first.c_str())) { for (const std::string& name : category.second) { std::string varName(name); +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp varName.erase(std::remove_if(varName.begin(), varName.end(), [](unsigned char x) { return std::isspace(x); }), varName.end()); +======== + varName.erase(std::ranges::remove_if(varName, isspace).begin(), varName.end()); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp std::string toggleName = "g" + varName + "Enabled"; - EnhancementCheckbox(name.c_str(), toggleName.c_str()); + EnhancementCheckbox(name, toggleName); customWindows[name].enabled = CVar_GetS32(toggleName.c_str(), 0); } ImGui::EndMenu(); @@ -1265,6 +1435,8 @@ namespace SohImGui { ImGui::Text("Platform: Windows"); #elif __APPLE__ ImGui::Text("Platform: macOS"); +#elif defined(__SWITCH__) + ImGui::Text("Platform: Nintendo Switch"); #else ImGui::Text("Platform: Linux"); #endif @@ -1297,19 +1469,19 @@ namespace SohImGui { main_pos.y -= top_left_pos.y; ImVec2 size = ImGui::GetContentRegionAvail(); ImVec2 pos = ImVec2(0, 0); - gfx_current_dimensions.width = (uint32_t)(size.x * gfx_current_dimensions.internal_mul); - gfx_current_dimensions.height = (uint32_t)(size.y * gfx_current_dimensions.internal_mul); - gfx_current_game_window_viewport.x = (int16_t)main_pos.x; - gfx_current_game_window_viewport.y = (int16_t)main_pos.y; - gfx_current_game_window_viewport.width = (int16_t)size.x; - gfx_current_game_window_viewport.height = (int16_t)size.y; + gfx_current_dimensions.width = size.x * gfx_current_dimensions.internal_mul; + gfx_current_dimensions.height = size.y * gfx_current_dimensions.internal_mul; + gfx_current_game_window_viewport.x = main_pos.x; + gfx_current_game_window_viewport.y = main_pos.y; + gfx_current_game_window_viewport.width = size.x; + gfx_current_game_window_viewport.height = size.y; if (CVar_GetS32("gN64Mode", 0)) { gfx_current_dimensions.width = 320; gfx_current_dimensions.height = 240; const int sw = size.y * 320 / 240; - gfx_current_game_window_viewport.x += ((int)size.x - sw) / 2; + gfx_current_game_window_viewport.x += (size.x - sw) / 2; gfx_current_game_window_viewport.width = sw; pos = ImVec2(size.x / 2 - sw / 2, 0); size = ImVec2(sw, size.y); @@ -1318,12 +1490,12 @@ namespace SohImGui { overlay->Draw(); } - void DrawFramebufferAndGameInput(void) { - const ImVec2 main_pos = ImGui::GetWindowPos(); + void DrawFramebufferAndGameInput() { + ImVec2 main_pos = ImGui::GetWindowPos(); ImVec2 size = ImGui::GetContentRegionAvail(); ImVec2 pos = ImVec2(0, 0); if (CVar_GetS32("gN64Mode", 0)) { - const float sw = size.y * 320.0f / 240.0f; + const int sw = size.y * 320 / 240; pos = ImVec2(size.x / 2 - sw / 2, 0); size = ImVec2(sw, size.y); } diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_opengl.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_opengl.cpp index 04a775c5349..1c5e9aa2892 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_opengl.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_opengl.cpp @@ -6,6 +6,7 @@ #include #include +#include #ifndef _LANGUAGE_C #define _LANGUAGE_C @@ -27,6 +28,9 @@ #include "SDL.h" #define GL_GLEXT_PROTOTYPES 1 #include "SDL_opengl.h" +#elif __APPLE__ +#include +#include #elif __SWITCH__ #include #include "glad/glad.h" @@ -41,7 +45,7 @@ #include "gfx_cc.h" #include "gfx_rendering_api.h" -#include "../../SohImGuiImpl.h" +#include "../../ImGuiImpl.h" #include "../../Environment.h" #include "../../GlobalCtx2.h" #include "gfx_pc.h" @@ -72,6 +76,9 @@ struct Framebuffer { static map, struct ShaderProgram> shader_program_pool; static GLuint opengl_vbo; +#ifdef __APPLE__ +static GLuint opengl_vao; +#endif static bool current_depth_mask; static uint32_t frame_count; @@ -79,7 +86,7 @@ static uint32_t frame_count; static vector framebuffers; static size_t current_framebuffer; static float current_noise_scale; -static FilteringMode current_filter_mode = THREE_POINT; +static FilteringMode current_filter_mode = FILTER_THREE_POINT; GLuint pixel_depth_rb, pixel_depth_fb; size_t pixel_depth_rb_size; @@ -225,37 +232,67 @@ static struct ShaderProgram* gfx_opengl_create_and_load_new_shader(uint64_t shad size_t num_floats = 4; // Vertex shader +#ifdef __APPLE__ + append_line(vs_buf, &vs_len, "#version 410 core"); + append_line(vs_buf, &vs_len, "in vec4 aVtxPos;"); +#else append_line(vs_buf, &vs_len, "#version 110"); append_line(vs_buf, &vs_len, "attribute vec4 aVtxPos;"); +#endif for (int i = 0; i < 2; i++) { if (cc_features.used_textures[i]) { + #ifdef __APPLE__ + vs_len += sprintf(vs_buf + vs_len, "in vec2 aTexCoord%d;\n", i); + vs_len += sprintf(vs_buf + vs_len, "out vec2 vTexCoord%d;\n", i); + #else vs_len += sprintf(vs_buf + vs_len, "attribute vec2 aTexCoord%d;\n", i); vs_len += sprintf(vs_buf + vs_len, "varying vec2 vTexCoord%d;\n", i); + #endif num_floats += 2; for (int j = 0; j < 2; j++) { if (cc_features.clamp[i][j]) { + #ifdef __APPLE__ + vs_len += sprintf(vs_buf + vs_len, "in float aTexClamp%s%d;\n", j == 0 ? "S" : "T", i); + vs_len += sprintf(vs_buf + vs_len, "out float vTexClamp%s%d;\n", j == 0 ? "S" : "T", i); + #else vs_len += sprintf(vs_buf + vs_len, "attribute float aTexClamp%s%d;\n", j == 0 ? "S" : "T", i); vs_len += sprintf(vs_buf + vs_len, "varying float vTexClamp%s%d;\n", j == 0 ? "S" : "T", i); + #endif num_floats += 1; } } } } if (cc_features.opt_fog) { + #ifdef __APPLE__ + append_line(vs_buf, &vs_len, "in vec4 aFog;"); + append_line(vs_buf, &vs_len, "out vec4 vFog;"); + #else append_line(vs_buf, &vs_len, "attribute vec4 aFog;"); append_line(vs_buf, &vs_len, "varying vec4 vFog;"); + #endif num_floats += 4; } if (cc_features.opt_grayscale) { + #ifdef __APPLE__ + append_line(vs_buf, &vs_len, "in vec4 aGrayscaleColor;"); + append_line(vs_buf, &vs_len, "out vec4 vGrayscaleColor;"); + #else append_line(vs_buf, &vs_len, "attribute vec4 aGrayscaleColor;"); append_line(vs_buf, &vs_len, "varying vec4 vGrayscaleColor;"); + #endif num_floats += 4; } for (int i = 0; i < cc_features.num_inputs; i++) { + #ifdef __APPLE__ + vs_len += sprintf(vs_buf + vs_len, "in vec%d aInput%d;\n", cc_features.opt_alpha ? 4 : 3, i + 1); + vs_len += sprintf(vs_buf + vs_len, "out vec%d vInput%d;\n", cc_features.opt_alpha ? 4 : 3, i + 1); + #else vs_len += sprintf(vs_buf + vs_len, "attribute vec%d aInput%d;\n", cc_features.opt_alpha ? 4 : 3, i + 1); vs_len += sprintf(vs_buf + vs_len, "varying vec%d vInput%d;\n", cc_features.opt_alpha ? 4 : 3, i + 1); + #endif num_floats += cc_features.opt_alpha ? 4 : 3; } append_line(vs_buf, &vs_len, "void main() {"); @@ -282,26 +319,50 @@ static struct ShaderProgram* gfx_opengl_create_and_load_new_shader(uint64_t shad append_line(vs_buf, &vs_len, "}"); // Fragment shader +#ifdef __APPLE__ + append_line(fs_buf, &fs_len, "#version 410 core"); +#else append_line(fs_buf, &fs_len, "#version 130"); +#endif //append_line(fs_buf, &fs_len, "precision mediump float;"); for (int i = 0; i < 2; i++) { if (cc_features.used_textures[i]) { + #ifdef __APPLE__ + fs_len += sprintf(fs_buf + fs_len, "in vec2 vTexCoord%d;\n", i); + #else fs_len += sprintf(fs_buf + fs_len, "varying vec2 vTexCoord%d;\n", i); + #endif for (int j = 0; j < 2; j++) { if (cc_features.clamp[i][j]) { + #ifdef __APPLE__ + fs_len += sprintf(fs_buf + fs_len, "in float vTexClamp%s%d;\n", j == 0 ? "S" : "T", i); + #else fs_len += sprintf(fs_buf + fs_len, "varying float vTexClamp%s%d;\n", j == 0 ? "S" : "T", i); + #endif } } } } if (cc_features.opt_fog) { + #ifdef __APPLE__ + append_line(fs_buf, &fs_len, "in vec4 vFog;"); + #else append_line(fs_buf, &fs_len, "varying vec4 vFog;"); + #endif } if (cc_features.opt_grayscale) { + #ifdef __APPLE__ + append_line(fs_buf, &fs_len, "in vec4 vGrayscaleColor;"); + #else append_line(fs_buf, &fs_len, "varying vec4 vGrayscaleColor;"); + #endif } for (int i = 0; i < cc_features.num_inputs; i++) { + #ifdef __APPLE__ + fs_len += sprintf(fs_buf + fs_len, "in vec%d vInput%d;\n", cc_features.opt_alpha ? 4 : 3, i + 1); + #else fs_len += sprintf(fs_buf + fs_len, "varying vec%d vInput%d;\n", cc_features.opt_alpha ? 4 : 3, i + 1); + #endif } if (cc_features.used_textures[0]) { append_line(fs_buf, &fs_len, "uniform sampler2D uTex0;"); @@ -320,8 +381,12 @@ static struct ShaderProgram* gfx_opengl_create_and_load_new_shader(uint64_t shad append_line(fs_buf, &fs_len, "}"); } - if (current_filter_mode == THREE_POINT) { + if (current_filter_mode == FILTER_THREE_POINT) { + #if __APPLE__ + append_line(fs_buf, &fs_len, "#define TEX_OFFSET(off) texture(tex, texCoord - (off)/texSize)"); + #else append_line(fs_buf, &fs_len, "#define TEX_OFFSET(off) texture2D(tex, texCoord - (off)/texSize)"); + #endif append_line(fs_buf, &fs_len, "vec4 filter3point(in sampler2D tex, in vec2 texCoord, in vec2 texSize) {"); append_line(fs_buf, &fs_len, " vec2 offset = fract(texCoord*texSize - vec2(0.5));"); append_line(fs_buf, &fs_len, " offset -= step(1.0, offset.x + offset.y);"); @@ -335,10 +400,18 @@ static struct ShaderProgram* gfx_opengl_create_and_load_new_shader(uint64_t shad append_line(fs_buf, &fs_len, "}"); } else { append_line(fs_buf, &fs_len, "vec4 hookTexture2D(in sampler2D tex, in vec2 uv, in vec2 texSize) {"); + #if __APPLE__ + append_line(fs_buf, &fs_len, " return texture(tex, uv);"); + #else append_line(fs_buf, &fs_len, " return texture2D(tex, uv);"); + #endif append_line(fs_buf, &fs_len, "}"); } +#if __APPLE__ + append_line(fs_buf, &fs_len, "out vec4 outColor;"); +#endif + append_line(fs_buf, &fs_len, "void main() {"); for (int i = 0; i < 2; i++) { @@ -410,9 +483,17 @@ static struct ShaderProgram* gfx_opengl_create_and_load_new_shader(uint64_t shad if (cc_features.opt_invisible) { append_line(fs_buf, &fs_len, "texel.a = 0.0;"); } + #if __APPLE__ + append_line(fs_buf, &fs_len, "outColor = texel;"); + #else append_line(fs_buf, &fs_len, "gl_FragColor = texel;"); + #endif } else { + #if __APPLE__ + append_line(fs_buf, &fs_len, "outColor = vec4(texel, 1.0);"); + #else append_line(fs_buf, &fs_len, "gl_FragColor = vec4(texel, 1.0);"); + #endif } append_line(fs_buf, &fs_len, "}"); @@ -586,7 +667,7 @@ static uint32_t gfx_cm_to_opengl(uint32_t val) { } static void gfx_opengl_set_sampler_parameters(int tile, bool linear_filter, uint32_t cms, uint32_t cmt) { - const GLint filter = linear_filter && current_filter_mode == LINEAR ? GL_LINEAR : GL_NEAREST; + const GLint filter = linear_filter && current_filter_mode == FILTER_LINEAR ? GL_LINEAR : GL_NEAREST; glActiveTexture(GL_TEXTURE0 + tile); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); @@ -645,6 +726,11 @@ static void gfx_opengl_init(void) { glGenBuffers(1, &opengl_vbo); glBindBuffer(GL_ARRAY_BUFFER, opengl_vbo); +#ifdef __APPLE__ + glGenVertexArrays(1, &opengl_vao); + glBindVertexArray(opengl_vao); +#endif + glEnable(GL_DEPTH_CLAMP); glDepthFunc(GL_LEQUAL); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -797,8 +883,8 @@ void gfx_opengl_select_texture_fb(int fb_id) { glBindTexture(GL_TEXTURE_2D, framebuffers[fb_id].clrbuf); } -static std::map, uint16_t> gfx_opengl_get_pixel_depth(int fb_id, const std::set>& coordinates) { - std::map, uint16_t> res; +static std::unordered_map, uint16_t, hash_pair_ff> gfx_opengl_get_pixel_depth(int fb_id, const std::set>& coordinates) { + std::unordered_map, uint16_t, hash_pair_ff> res; Framebuffer& fb = framebuffers[fb_id]; diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_pc.h b/libultraship/libultraship/Lib/Fast3D/gfx_pc.h index 9085cbdf7c9..4e620ef2d3b 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_pc.h +++ b/libultraship/libultraship/Lib/Fast3D/gfx_pc.h @@ -2,12 +2,17 @@ #define GFX_PC_H #include +#include #include #include #include -#include "U64/PR/ultra64/types.h" #include +#include "U64/PR/ultra64/types.h" + +// TODO figure out why changing these to 640x480 makes the game only render in a quarter of the window +#define SCREEN_WIDTH 320 +#define SCREEN_HEIGHT 240 struct GfxRenderingAPI; struct GfxWindowManagerAPI; @@ -18,7 +23,7 @@ struct XYWidthHeight { }; struct GfxDimensions { - uint32_t internal_mul; + float internal_mul; uint32_t width, height; float aspect_ratio; }; @@ -47,12 +52,11 @@ struct TextureCacheValue { uint8_t cms, cmt; bool linear_filter; - // Old versions of libstdc++ fail to compile this -#ifdef _MSC_VER - std::list::iterator lru_location; -#else - std::list::iterator lru_location; -#endif + std::list::iterator lru_location; +}; + +struct TextureCacheMapIter { + TextureCacheMap::iterator it; }; extern "C" { @@ -64,12 +68,14 @@ extern uint32_t gfx_msaa_level; } -void gfx_init(struct GfxWindowManagerAPI* wapi, struct GfxRenderingAPI* rapi, const char* game_name, bool start_in_fullscreen); +void gfx_init(struct GfxWindowManagerAPI* wapi, struct GfxRenderingAPI* rapi, const char* game_name, bool start_in_fullscreen, uint32_t width = SCREEN_WIDTH, uint32_t height = SCREEN_HEIGHT); struct GfxRenderingAPI* gfx_get_current_rendering_api(void); void gfx_start_frame(void); void gfx_run(Gfx* commands, const std::unordered_map& mtx_replacements); void gfx_end_frame(void); -void gfx_set_framedivisor(int); +void gfx_set_target_fps(int); +void gfx_set_maximum_frame_latency(int latency); +float gfx_get_detected_hz(void); void gfx_texture_cache_clear(); extern "C" int gfx_create_framebuffer(uint32_t width, uint32_t height); void gfx_get_pixel_depth_prepare(float x, float y); diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp index f9e0b292cec..74cdcf85f85 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp @@ -13,24 +13,30 @@ #include "SDL.h" #define GL_GLEXT_PROTOTYPES 1 #include "SDL_opengl.h" -#elif !defined(__SWITCH__) -#include -#define GL_GLEXT_PROTOTYPES 1 -#include -#else +#elif __APPLE__ +#include +#elif __SWITCH__ #include #include #include "glad/glad.h" +#else +#include +#define GL_GLEXT_PROTOTYPES 1 +#include #endif -#include "../../SohImGuiImpl.h" +#include "../../ImGuiImpl.h" #include "../../SwitchImpl.h" +#include "../../Cvar.h" +#include "../../Hooks.h" + #include "gfx_window_manager_api.h" #include "gfx_screen_config.h" #ifdef _WIN32 #include #endif #include +#include "../../GameSettings.h" #define GFX_API_NAME "SDL2 - OpenGL" @@ -38,8 +44,8 @@ static SDL_Window *wnd; static SDL_GLContext ctx; static int inverted_scancode_table[512]; static int vsync_enabled = 0; -static unsigned int window_width = DESIRED_SCREEN_WIDTH; -static unsigned int window_height = DESIRED_SCREEN_HEIGHT; +static int window_width = DESIRED_SCREEN_WIDTH; +static int window_height = DESIRED_SCREEN_HEIGHT; static bool fullscreen_state; static bool is_running = true; static void (*on_fullscreen_changed_callback)(bool is_now_fullscreen); @@ -128,18 +134,26 @@ static uint64_t previous_time; static HANDLE timer; #endif -static int frameDivisor = 1; +static int target_fps = 60; -#define FRAME_INTERVAL_US_NUMERATOR_ 50000 -#define FRAME_INTERVAL_US_DENOMINATOR 3 -#define FRAME_INTERVAL_US_NUMERATOR (FRAME_INTERVAL_US_NUMERATOR_ * frameDivisor) +#define FRAME_INTERVAL_US_NUMERATOR 1000000 +#define FRAME_INTERVAL_US_DENOMINATOR (target_fps) -static void gfx_sdl_init(const char *game_name, bool start_in_fullscreen) { +static void gfx_sdl_init(const char *game_name, bool start_in_fullscreen, uint32_t width, uint32_t height) { SDL_Init(SDL_INIT_VIDEO); + SDL_EventState(SDL_DROPFILE, SDL_ENABLE); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); +#if defined(__APPLE__) + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); // Always required on Mac + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); +#endif + #ifdef _WIN32 timer = CreateWaitableTimer(nullptr, false, nullptr); #endif @@ -154,8 +168,12 @@ static void gfx_sdl_init(const char *game_name, bool start_in_fullscreen) { char title[512]; int len = sprintf(title, "%s (%s)", game_name, GFX_API_NAME); + window_width = width; + window_height = height; + wnd = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - window_width, window_height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); + window_width, window_height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); + SDL_GL_GetDrawableSize(wnd, &window_width, &window_height); #ifndef __SWITCH__ if (start_in_fullscreen) { @@ -240,6 +258,15 @@ static int translate_scancode(int scancode) { } } +static int untranslate_scancode(int translatedScancode) { + for (int i = 0; i < 512; i++) { + if (inverted_scancode_table[i] == translatedScancode) { + return i; + } + } + return 0; +} + static void gfx_sdl_onkeydown(int scancode) { int key = translate_scancode(scancode); if (on_key_down_callback != NULL) { @@ -275,12 +302,18 @@ static void gfx_sdl_handle_events(void) { #endif case SDL_WINDOWEVENT: if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { - window_width = event.window.data1; - window_height = event.window.data2; + SDL_GL_GetDrawableSize(wnd, &window_width, &window_height); } break; + case SDL_DROPFILE: + CVar_SetString("gDroppedFile", event.drop.file); + CVar_SetS32("gNewFileDropped", 1); + Game::SaveSettings(); + break; case SDL_QUIT: - is_running = false; + ModInternal::ExecuteHooks(); + SDL_Quit(); // bandaid fix for linux window closing issue + exit(0); } } } @@ -296,15 +329,16 @@ static uint64_t qpc_to_100ns(uint64_t qpc) { static inline void sync_framerate_with_timer(void) { uint64_t t; - t = SDL_GetPerformanceCounter(); + t = qpc_to_100ns(SDL_GetPerformanceCounter()); - const int64_t next = qpc_to_100ns(previous_time) + 10 * FRAME_INTERVAL_US_NUMERATOR / FRAME_INTERVAL_US_DENOMINATOR; - const int64_t left = next - qpc_to_100ns(t); + const int64_t next = previous_time + 10 * FRAME_INTERVAL_US_NUMERATOR / FRAME_INTERVAL_US_DENOMINATOR; + const int64_t left = next - t; if (left > 0) { #ifndef _WIN32 const timespec spec = { 0, left * 100 }; nanosleep(&spec, nullptr); #else + // The accuracy of this timer seems to usually be within +- 1.0 ms LARGE_INTEGER li; li.QuadPart = -left; SetWaitableTimer(timer, &li, 0, nullptr, nullptr, false); @@ -312,7 +346,13 @@ static inline void sync_framerate_with_timer(void) { #endif } - t = SDL_GetPerformanceCounter(); + t = qpc_to_100ns(SDL_GetPerformanceCounter()); + if (left > 0 && t - next < 10000) { + // In case it takes some time for the application to wake up after sleep, + // or inaccurate timer, + // don't let that slow down the framerate. + t = next; + } previous_time = t; } @@ -329,9 +369,20 @@ static double gfx_sdl_get_time(void) { return 0.0; } -static void gfx_sdl_set_framedivisor(int divisor) -{ - frameDivisor = divisor; +static void gfx_sdl_set_target_fps(int fps) { + target_fps = fps; +} + +static void gfx_sdl_set_maximum_frame_latency(int latency) { + // Not supported by SDL :( +} + +static float gfx_sdl_get_detected_hz(void) { + return 0; +} + +static const char* gfx_sdl_get_key_name(int scancode) { + return SDL_GetScancodeName((SDL_Scancode) untranslate_scancode(scancode)); } struct GfxWindowManagerAPI gfx_sdl = { @@ -347,7 +398,10 @@ struct GfxWindowManagerAPI gfx_sdl = { gfx_sdl_swap_buffers_begin, gfx_sdl_swap_buffers_end, gfx_sdl_get_time, - gfx_sdl_set_framedivisor + gfx_sdl_set_target_fps, + gfx_sdl_set_maximum_frame_latency, + gfx_sdl_get_detected_hz, + gfx_sdl_get_key_name }; #endif diff --git a/libultraship/libultraship/Lib/ImGui/backends/imgui_impl_opengl3.cpp b/libultraship/libultraship/Lib/ImGui/backends/imgui_impl_opengl3.cpp index ac2d7928db8..d55eb7204e9 100644 --- a/libultraship/libultraship/Lib/ImGui/backends/imgui_impl_opengl3.cpp +++ b/libultraship/libultraship/Lib/ImGui/backends/imgui_impl_opengl3.cpp @@ -357,6 +357,7 @@ void ImGui_ImplOpenGL3_NewFrame() static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_width, int fb_height, GLuint vertex_array_object) { ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData(); + // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, polygon fill glEnable(GL_BLEND); glBlendEquation(GL_FUNC_ADD); diff --git a/libultraship/libultraship/SohImGuiImpl.cpp b/libultraship/libultraship/SohImGuiImpl.cpp deleted file mode 100644 index e5edaa91285..00000000000 --- a/libultraship/libultraship/SohImGuiImpl.cpp +++ /dev/null @@ -1,987 +0,0 @@ -#include "SohImGuiImpl.h" - -#include -#include -#include -#include -#include -#include - -#include "Archive.h" -#include "Environment.h" -#include "GameSettings.h" -#include "SohConsole.h" -#include "SohHooks.h" -#include "Lib/ImGui/imgui_internal.h" -#include "GlobalCtx2.h" -#include "ResourceMgr.h" -#include "TextureMod.h" -#include "Window.h" -#include "Cvar.h" -#include "GameOverlay.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" -#include "SwitchImpl.h" - -#ifdef ENABLE_OPENGL -#include "Lib/ImGui/backends/imgui_impl_opengl3.h" -#include "Lib/ImGui/backends/imgui_impl_sdl.h" - -#endif - -#if defined(ENABLE_DX11) || defined(ENABLE_DX12) -#include "Lib/ImGui/backends/imgui_impl_dx11.h" -#include "Lib/ImGui/backends/imgui_impl_win32.h" -#include - -IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); - -#endif - -using namespace Ship; -bool oldCursorState = true; - -#define EXPERIMENTAL() \ - ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(255, 50, 50, 255)); \ - ImGui::Text("Experimental"); \ - ImGui::PopStyleColor(); \ - ImGui::Separator(); -#define TOGGLE_BTN ImGuiKey_F1 -#define HOOK(b) if(b) needs_save = true; -OSContPad* pads; - -std::map DefaultAssets; - -namespace SohImGui { - - WindowImpl impl; - ImGuiIO* io; - Console* console = new Console; - GameOverlay* overlay = new GameOverlay; - bool p_open = false; - bool needs_save = false; - std::vector CustomTexts; - int SelectedLanguage = CVar_GetS32("gLanguages", 0); //Default Language to 0=English 1=German 2=French - float kokiri_col[3] = { 0.118f, 0.41f, 0.106f }; - float goron_col[3] = { 0.392f, 0.078f, 0.0f }; - float zora_col[3] = { 0.0f, 0.235f, 0.392f }; - - float navi_idle_i_col[3] = { 0.0f, 0.0f, 0.0f }; - float navi_idle_o_col[3] = { 0.0f, 0.0f, 0.0f }; - - float navi_npc_i_col[3] = { 0.0f, 0.0f, 0.0f }; - float navi_npc_o_col[3] = { 0.0f, 0.0f, 0.0f }; - - float navi_enemy_i_col[3] = { 0.0f, 0.0f, 0.0f }; - float navi_enemy_o_col[3] = { 0.0f, 0.0f, 0.0f }; - - float navi_prop_i_col[3] = { 0.0f, 0.0f, 0.0f }; - float navi_prop_o_col[3] = { 0.0f, 0.0f, 0.0f }; - - const char* filters[3] = { - "Three-Point", - "Linear", - "None" - }; - - std::map> windowCategories; - std::map customWindows; - - void ImGuiWMInit() { - switch (impl.backend) { - case Backend::SDL: - ImGui_ImplSDL2_InitForOpenGL(static_cast(impl.sdl.window), impl.sdl.context); - break; -#if defined(ENABLE_DX11) || defined(ENABLE_DX12) - case Backend::DX11: - ImGui_ImplWin32_Init(impl.dx11.window); - break; -#endif - default: - break; - } - - // OTRTODO: This gameplay specific stuff should not be in libultraship. This needs to be moved to soh and use sTunicColors - kokiri_col[0] = 30 / 255.0f; - kokiri_col[1] = 105 / 255.0f; - kokiri_col[2] = 27 / 255.0f; - - goron_col[0] = 100 / 255.0f; - goron_col[1] = 20 / 255.0f; - goron_col[2] = 0; - - zora_col[0] = 0; - zora_col[1] = 60 / 255.0f; - zora_col[2] = 100 / 255.0f; - - navi_idle_i_col[0] = 0; - navi_idle_i_col[1] = 0; - navi_idle_i_col[2] = 0; - - navi_idle_o_col[0] = 0; - navi_idle_o_col[1] = 0; - navi_idle_o_col[2] = 0; - - navi_npc_i_col[0] = 0; - navi_npc_i_col[1] = 0; - navi_npc_i_col[2] = 0; - - navi_npc_o_col[0] = 0; - navi_npc_o_col[1] = 0; - navi_npc_o_col[2] = 0; - - navi_enemy_i_col[0] = 0; - navi_enemy_i_col[1] = 0; - navi_enemy_i_col[2] = 0; - - navi_enemy_o_col[0] = 0; - navi_enemy_o_col[1] = 0; - navi_enemy_o_col[2] = 0; - - navi_prop_i_col[0] = 0; - navi_prop_i_col[1] = 0; - navi_prop_i_col[2] = 0; - - navi_prop_o_col[0] = 0; - navi_prop_o_col[1] = 0; - navi_prop_o_col[2] = 0; - } - - void ImGuiBackendInit() { - switch (impl.backend) { - case Backend::SDL: - ImGui_ImplOpenGL3_Init("#version 120"); - break; - -#if defined(ENABLE_DX11) || defined(ENABLE_DX12) - case Backend::DX11: - ImGui_ImplDX11_Init(static_cast(impl.dx11.device), static_cast(impl.dx11.device_context)); - break; -#endif - default: - break; - } - } - - void ImGuiProcessEvent(EventImpl event) { - switch (impl.backend) { - case Backend::SDL: - ImGui_ImplSDL2_ProcessEvent(static_cast(event.sdl.event)); - break; -#if defined(ENABLE_DX11) || defined(ENABLE_DX12) - case Backend::DX11: - ImGui_ImplWin32_WndProcHandler(static_cast(event.win32.handle), event.win32.msg, event.win32.wparam, event.win32.lparam); - break; -#endif - default: - break; - } - } - - void ImGuiWMNewFrame() { - switch (impl.backend) { - case Backend::SDL: - ImGui_ImplSDL2_NewFrame(static_cast(impl.sdl.window)); - break; -#if defined(ENABLE_DX11) || defined(ENABLE_DX12) - case Backend::DX11: - ImGui_ImplWin32_NewFrame(); - break; -#endif - default: - break; - } - } - - void ImGuiBackendNewFrame() { - switch (impl.backend) { - case Backend::SDL: - ImGui_ImplOpenGL3_NewFrame(); - break; -#if defined(ENABLE_DX11) || defined(ENABLE_DX12) - case Backend::DX11: - ImGui_ImplDX11_NewFrame(); - break; -#endif - default: - break; - } - } - - void ImGuiRenderDrawData(ImDrawData* data) { - switch (impl.backend) { - case Backend::SDL: - ImGui_ImplOpenGL3_RenderDrawData(data); - break; -#if defined(ENABLE_DX11) || defined(ENABLE_DX12) - case Backend::DX11: - ImGui_ImplDX11_RenderDrawData(data); - break; -#endif - default: - break; - } - } - - bool UseViewports() { - switch (impl.backend) { - case Backend::DX11: - return true; - default: - return false; - } - } - - void ShowCursor(bool hide, Dialogues d) { - if (d == Dialogues::dLoadSettings) { - GlobalCtx2::GetInstance()->GetWindow()->ShowCursor(hide); - return; - } - - if (d == Dialogues::dConsole && CVar_GetS32("gOpenMenuBar", 0)) { - return; - } - if (!GlobalCtx2::GetInstance()->GetWindow()->IsFullscreen()) { - oldCursorState = false; - return; - } - - if (oldCursorState != hide) { - oldCursorState = hide; - GlobalCtx2::GetInstance()->GetWindow()->ShowCursor(hide); - } - } - - void LoadTexture(const std::string& name, const std::string& path) { - GfxRenderingAPI* api = gfx_get_current_rendering_api(); - const auto res = GlobalCtx2::GetInstance()->GetResourceManager()->LoadFile(path); - - const auto asset = new GameAsset{ api->new_texture() }; - uint8_t* img_data = stbi_load_from_memory(reinterpret_cast(res->buffer.get()), res->dwBufferSize, &asset->width, &asset->height, nullptr, 4); - - if (img_data == nullptr) { - std::cout << "Found error: " << stbi_failure_reason() << std::endl; - return; - } - - api->select_texture(0, asset->textureId); - api->set_sampler_parameters(0, false, 0, 0); - api->upload_texture(img_data, asset->width, asset->height); - - DefaultAssets[name] = asset; - stbi_image_free(img_data); - } - - void LoadResource(const std::string& name, const std::string& path, const ImVec4& tint) { - GfxRenderingAPI* api = gfx_get_current_rendering_api(); - const auto res = static_cast(GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(path).get()); - - std::vector texBuffer; - texBuffer.reserve(res->width * res->height * 4); - - switch (res->texType) { - case Ship::TextureType::RGBA32bpp: - texBuffer.assign(res->imageData, res->imageData + (res->width * res->height * 4)); - break; - case Ship::TextureType::GrayscaleAlpha8bpp: - for (int32_t i = 0; i < res->width * res->height; i++) { - uint8_t ia = res->imageData[i]; - uint8_t color = ((ia >> 4) & 0xF) * 255 / 15; - uint8_t alpha = (ia & 0xF) * 255 / 15; - texBuffer.push_back(color); - texBuffer.push_back(color); - texBuffer.push_back(color); - texBuffer.push_back(alpha); - } - break; - default: - // TODO convert other image types - SPDLOG_WARN("SohImGui::LoadResource: Attempting to load unsupporting image type %s", path.c_str()); - return; - } - - for (size_t pixel = 0; pixel < texBuffer.size() / 4; pixel++) { - texBuffer[pixel * 4 + 0] *= tint.x; - texBuffer[pixel * 4 + 1] *= tint.y; - texBuffer[pixel * 4 + 2] *= tint.z; - texBuffer[pixel * 4 + 3] *= tint.w; - } - - 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(texBuffer.data(), res->width, res->height); - - DefaultAssets[name] = asset; - } - - void Init(WindowImpl window_impl) { - Game::LoadSettings(); - impl = window_impl; - ImGuiContext* ctx = ImGui::CreateContext(); - ImGui::SetCurrentContext(ctx); - io = &ImGui::GetIO(); - io->ConfigFlags |= ImGuiConfigFlags_DockingEnable; - io->Fonts->AddFontDefault(); - - if (UseViewports()) { - io->ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; - } - console->Init(); - overlay->Init(); - ImGuiWMInit(); - ImGuiBackendInit(); - #ifdef __SWITCH__ - ImGui::GetStyle().ScaleAllSizes(Ship::Switch::GetDPI() / 96.0f); - #endif - - ModInternal::registerHookListener({ GFX_INIT, [](const HookEvent ev) { - - if (GlobalCtx2::GetInstance()->GetWindow()->IsFullscreen()) - ShowCursor(CVar_GetS32("gOpenMenuBar", 0), Dialogues::dLoadSettings); - - LoadTexture("Game_Icon", "assets/ship_of_harkinian/icons/gSohIcon.png"); - LoadTexture("A-Btn", "assets/ship_of_harkinian/buttons/ABtn.png"); - LoadTexture("B-Btn", "assets/ship_of_harkinian/buttons/BBtn.png"); - LoadTexture("L-Btn", "assets/ship_of_harkinian/buttons/LBtn.png"); - LoadTexture("R-Btn", "assets/ship_of_harkinian/buttons/RBtn.png"); - LoadTexture("Z-Btn", "assets/ship_of_harkinian/buttons/ZBtn.png"); - LoadTexture("Start-Btn", "assets/ship_of_harkinian/buttons/StartBtn.png"); - LoadTexture("C-Left", "assets/ship_of_harkinian/buttons/CLeft.png"); - LoadTexture("C-Right", "assets/ship_of_harkinian/buttons/CRight.png"); - LoadTexture("C-Up", "assets/ship_of_harkinian/buttons/CUp.png"); - LoadTexture("C-Down", "assets/ship_of_harkinian/buttons/CDown.png"); - } }); - - for (const auto& [i, controllers] : Ship::Window::Controllers) - { - CVar_SetFloat(StringHelper::Sprintf("gCont%i_GyroDriftX", i).c_str(), 0); - CVar_SetFloat(StringHelper::Sprintf("gCont%i_GyroDriftY", i).c_str(), 0); - needs_save = true; - } - - ModInternal::registerHookListener({ CONTROLLER_READ, [](const HookEvent ev) { - pads = static_cast(ev->baseArgs["cont_pad"]); - }}); - Game::InitSettings(); - } - - void Update(EventImpl event) { - #ifdef __SWITCH__ - int xPos, yPos; - Switch::GetTouchPosition(&xPos, &yPos); - io->MousePos = ImVec2(xPos, yPos); - #endif - if (needs_save) { - Game::SaveSettings(); - needs_save = false; - } - ImGuiProcessEvent(event); - } - -#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 defaultValue, SeqPlayers playerId) - { - float value = CVar_GetFloat(key, defaultValue); - - 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(key, volume); - needs_save = true; - Game::SetSeqPlayerVolume(playerId, volume); - } - } - - void EnhancementRadioButton(std::string text, std::string cvarName, int id) { - /*Usage : - EnhancementRadioButton("My Visible Name","gMyCVarName", MyID); - First arg is the visible name of the Radio button - Second is the cvar name where MyID will be saved. - Note: the CVar name should be the same to each Buddies. - Example : - EnhancementRadioButton("English", "gLanguages", 0); - EnhancementRadioButton("German", "gLanguages", 1); - EnhancementRadioButton("French", "gLanguages", 2); - */ - int val = CVar_GetS32(cvarName.c_str(), 0); - if (ImGui::RadioButton(text.c_str(), id==val)) { - CVar_SetS32(cvarName.c_str(), (int)id); - needs_save = true; - } - } - - void EnhancementCheckbox(std::string text, std::string cvarName) - { - bool val = (bool)CVar_GetS32(cvarName.c_str(), 0); - if (ImGui::Checkbox(text.c_str(), &val)) { - CVar_SetS32(cvarName.c_str(), val); - needs_save = true; - } - } - - void EnhancementButton(std::string text, std::string cvarName) - { - bool val = (bool)CVar_GetS32(cvarName.c_str(), 0); - if (ImGui::Button(text.c_str())) { - CVar_SetS32(cvarName.c_str(), !val); - needs_save = true; - } - } - - void EnhancementSliderInt(std::string text, std::string id, std::string cvarName, int min, int max, std::string format) - { - int val = CVar_GetS32(cvarName.c_str(), 0); - - ImGui::Text(text.c_str(), val); - - if (ImGui::SliderInt(id.c_str(), &val, min, max, format.c_str())) - { - CVar_SetS32(cvarName.c_str(), val); - needs_save = true; - } - - if (val < min) - { - val = min; - CVar_SetS32(cvarName.c_str(), val); - needs_save = true; - } - - if (val > max) - { - val = max; - CVar_SetS32(cvarName.c_str(), val); - needs_save = true; - } - } - - void EnhancementSliderFloat(std::string text, std::string id, std::string cvarName, float min, float max, std::string format, float defaultValue, bool isPercentage) - { - float val = CVar_GetFloat(cvarName.c_str(), defaultValue); - - if (!isPercentage) - ImGui::Text(text.c_str(), val); - else - ImGui::Text(text.c_str(), static_cast(100 * val)); - - if (ImGui::SliderFloat(id.c_str(), &val, min, max, format.c_str())) - { - CVar_SetFloat(cvarName.c_str(), val); - needs_save = true; - } - - if (val < min) - { - val = min; - CVar_SetFloat(cvarName.c_str(), val); - needs_save = true; - } - - if (val > max) - { - val = max; - CVar_SetFloat(cvarName.c_str(), val); - needs_save = true; - } - } - - void EnhancementColor3(std::string text, std::string cvarName, float defaultColors[3]) - { - int r = CVar_GetS32((cvarName + "_Red").c_str(), (defaultColors[0] * 255.0f)); - int g = CVar_GetS32((cvarName + "_Green").c_str(), (defaultColors[1] * 255.0f)); - int b = CVar_GetS32((cvarName + "_Blue").c_str(), (defaultColors[2] * 255.0f)); - - float colors[3]; - colors[0] = r / 255.0f; - colors[1] = g / 255.0f; - colors[2] = b / 255.0f; - - { - if (ImGui::ColorEdit3(text.c_str(), colors)) - { - CVar_SetS32((cvarName + "_Red").c_str(), (int)(colors[0] * 255)); - CVar_SetS32((cvarName + "_Green").c_str(), (int)(colors[1] * 255)); - CVar_SetS32((cvarName + "_Blue").c_str(), (int)(colors[2] * 255)); - needs_save = true; - } - } - } - - void Tooltip(std::string text){ - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("%s", text.c_str()); - } - - void DrawMainMenuAndCalculateGameSize() { - console->Update(); - ImGuiBackendNewFrame(); - ImGuiWMNewFrame(); - ImGui::NewFrame(); - - const std::shared_ptr wnd = GlobalCtx2::GetInstance()->GetWindow(); - ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoBackground | - ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | - ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoResize; - if (CVar_GetS32("gOpenMenuBar", 0)) window_flags |= ImGuiWindowFlags_MenuBar; - - const ImGuiViewport* viewport = ImGui::GetMainViewport(); - ImGui::SetNextWindowPos(viewport->WorkPos); - ImGui::SetNextWindowSize(ImVec2((int) wnd->GetCurrentWidth(), (int) wnd->GetCurrentHeight())); - ImGui::SetNextWindowViewport(viewport->ID); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0.0f); - ImGui::Begin("Main - Deck", nullptr, window_flags); - ImGui::PopStyleVar(3); - - ImVec2 top_left_pos = ImGui::GetWindowPos(); - - const ImGuiID dockId = ImGui::GetID("main_dock"); - - if (!ImGui::DockBuilderGetNode(dockId)) { - ImGui::DockBuilderRemoveNode(dockId); - ImGui::DockBuilderAddNode(dockId, ImGuiDockNodeFlags_NoTabBar); - - ImGui::DockBuilderDockWindow("OoT Master Quest", dockId); - - ImGui::DockBuilderFinish(dockId); - } - - ImGui::DockSpace(dockId, ImVec2(0.0f, 0.0f), ImGuiDockNodeFlags_None); - - if (ImGui::IsKeyPressed(TOGGLE_BTN)) { - bool menu_bar = CVar_GetS32("gOpenMenuBar", 0); - CVar_SetS32("gOpenMenuBar", !menu_bar); - needs_save = true; - GlobalCtx2::GetInstance()->GetWindow()->dwMenubar = menu_bar; - ShowCursor(menu_bar, Dialogues::dMenubar); - } - - if (ImGui::BeginMenuBar()) { - if (DefaultAssets.contains("Game_Icon")) { - ImGui::SetCursorPos(ImVec2(5, 2.5f)); - ImGui::Image(GetTextureByID(DefaultAssets["Game_Icon"]->textureId), ImVec2(16.0f, 16.0f)); - ImGui::SameLine(); - ImGui::SetCursorPos(ImVec2(25, 0)); - } - ImGui::Text("Shipwright"); - ImGui::Separator(); - - if (ImGui::BeginMenu("Audio")) { - EnhancementSliderFloat("Master Volume: %d %%", "##Master_Vol", "gGameMasterVolume", 0.0f, 1.0f, "", 1.0f, true); - - BindAudioSlider("Main Music Volume: %d %%", "gMainMusicVolume", 1.0f, SEQ_BGM_MAIN); - BindAudioSlider("Sub Music Volume: %d %%", "gSubMusicVolume", 1.0f, SEQ_BGM_SUB); - BindAudioSlider("Sound Effects Volume: %d %%", "gSFXMusicVolume", 1.0f, SEQ_SFX); - BindAudioSlider("Fanfare Volume: %d %%", "gFanfareVolume", 1.0f, SEQ_FANFARE); - - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("Controller")) - { - for (const auto& [i, controllers] : Ship::Window::Controllers) - { - bool hasPad = std::find_if(controllers.begin(), controllers.end(), [](const auto& c) { - return c->HasPadConf() && c->Connected(); - }) != controllers.end(); - - if (!hasPad) continue; - - auto menuLabel = "Controller " + std::to_string(i + 1); - if (ImGui::BeginMenu(menuLabel.c_str())) - { - EnhancementSliderFloat("Gyro Sensitivity: %d %%", "##GYROSCOPE", StringHelper::Sprintf("gCont%i_GyroSensitivity", i), 0.0f, 1.0f, "", 1.0f, true); - - if (ImGui::Button("Recalibrate Gyro")) - { - CVar_SetFloat(StringHelper::Sprintf("gCont%i_GyroDriftX", i).c_str(), 0); - CVar_SetFloat(StringHelper::Sprintf("gCont%i_GyroDriftY", i).c_str(), 0); - needs_save = true; - } - - ImGui::Separator(); - - EnhancementSliderFloat("Rumble Strength: %d %%", "##RUMBLE", StringHelper::Sprintf("gCont%i_RumbleStrength", i), 0.0f, 1.0f, "", 1.0f, true); - - ImGui::EndMenu(); - } - ImGui::Separator(); - } - - EnhancementCheckbox("Show Inputs", "gInputEnabled"); - Tooltip("Shows currently pressed inputs on the bottom right of the screen"); - EnhancementCheckbox("Rumble Enabled", "gRumbleEnabled"); - - EnhancementSliderFloat("Input Scale: %.1f", "##Input", "gInputScale", 1.0f, 3.0f, "", 1.0f, false); - Tooltip("Sets the on screen size of the displayed inputs from Show Inputs"); - - ImGui::Separator(); - - EnhancementCheckbox("D-pad Support on Pause and File Select", "gDpadPauseName"); - EnhancementCheckbox("D-pad Support in Ocarina and Text Choice", "gDpadOcarinaText"); - EnhancementCheckbox("D-pad Support for Browsing Shop Items", "gDpadShop"); - - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("Graphics")) - { - EnhancementSliderInt("Internal Resolution: %dx", "##IMul", "gInternalResolution", 1, 8, ""); - Tooltip("Increases the render resolution of the game, up to 8x your output resolution,\nas a more intensive but effective form of anti-aliasing"); - gfx_current_dimensions.internal_mul = CVar_GetS32("gInternalResolution", 1); - EnhancementSliderInt("MSAA: %d", "##IMSAA", "gMSAAValue", 1, 8, ""); - Tooltip("Activates anti-aliasing when above 1, up to 8x for 8 samples for every pixel"); - gfx_msaa_level = CVar_GetS32("gMSAAValue", 1); - - EXPERIMENTAL(); - ImGui::Text("Texture Filter (Needs reload)"); - GfxRenderingAPI* gapi = gfx_get_current_rendering_api(); - if (ImGui::BeginCombo("##filters", filters[gapi->get_texture_filter()])) { - for (int fId = 0; fId <= FilteringMode::NONE; fId++) { - if (ImGui::Selectable(filters[fId], fId == gapi->get_texture_filter())) { - INFO("New Filter: %s", filters[fId]); - gapi->set_texture_filter((FilteringMode)fId); - - CVar_SetS32("gTextureFilter", (int) fId); - needs_save = true; - } - - } - ImGui::EndCombo(); - } - overlay->DrawSettings(); - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("Languages")) { - EnhancementRadioButton("English", "gLanguages", 0); - EnhancementRadioButton("German", "gLanguages", 1); - EnhancementRadioButton("French", "gLanguages", 2); - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("Enhancements")) - { - ImGui::Text("Gameplay"); - ImGui::Separator(); - - EnhancementSliderInt("Text Speed: %dx", "##TEXTSPEED", "gTextSpeed", 1, 5, ""); - EnhancementSliderInt("King Zora Speed: %dx", "##WEEPSPEED", "gMweepSpeed", 1, 5, ""); - - EnhancementCheckbox("Skip Text", "gSkipText"); - Tooltip("Holding down B skips text"); - EnhancementCheckbox("Minimal UI", "gMinimalUI"); - Tooltip("Hides most of the UI when not needed"); - EnhancementCheckbox("MM Bunny Hood", "gMMBunnyHood"); - Tooltip("Wearing the Bunny Hood grants a speed increase like in Majora's Mask"); - EnhancementCheckbox("Visual Stone of Agony", "gVisualAgony"); - Tooltip("Displays an icon and plays a sound when Stone of Agony should be activated, for those without rumble"); - - ImGui::Text("Graphics"); - ImGui::Separator(); - - EnhancementCheckbox("N64 Mode", "gN64Mode"); - Tooltip("Sets aspect ratio to 4:3 and lowers resolution to 240p, the N64's native resolution"); - - EnhancementCheckbox("Animated Link in Pause Menu", "gPauseLiveLink"); - EnhancementCheckbox("Enable 3D Dropped items", "gNewDrops"); - EnhancementCheckbox("Faster Block Push", "gFasterBlockPush"); - EnhancementCheckbox("Dynamic Wallet Icon", "gDynamicWalletIcon"); - Tooltip("Changes the rupee in the wallet icon to match the wallet size you currently have"); - EnhancementCheckbox("Always show dungeon entrances", "gAlwaysShowDungeonMinimapIcon"); - Tooltip("Always shows dungeon entrance icons on the minimap"); - - ImGui::Text("Fixes"); - ImGui::Separator(); - EnhancementCheckbox("Fix L&R Pause menu", "gUniformLR"); - Tooltip("Makes the L and R buttons in the pause menu the same color"); - EnhancementCheckbox("Fix Dungeon entrances", "gFixDungeonMinimapIcon"); - Tooltip("Show dungeon entrances icon only when it should be"); - EnhancementCheckbox("Fix Two Handed idle animations", "gTwoHandedIdle"); - Tooltip("Makes two handed idle animation play, a seemingly finished animation that was disabled on accident in the original game"); - - EXPERIMENTAL(); - - EnhancementCheckbox("60 fps interpolation", "g60FPS"); - EnhancementCheckbox("Disable LOD", "gDisableLOD"); - Tooltip("Turns off the level of detail setting, making models always use their higher poly variants"); - - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("Cosmetics")) - { - ImGui::Text("Tunics"); - ImGui::Separator(); - - EnhancementColor3("Kokiri Tunic", "gTunic_Kokiri", kokiri_col); - EnhancementColor3("Goron Tunic", "gTunic_Goron", goron_col); - EnhancementColor3("Zora Tunic", "gTunic_Zora", zora_col); - - ImGui::Text("Navi"); - ImGui::Separator(); - - EnhancementColor3("Navi Idle Inner", "gNavi_Idle_Inner", navi_idle_i_col); - EnhancementColor3("Navi Idle Outer", "gNavi_Idle_Outer", navi_idle_o_col); - EnhancementColor3("Navi NPC Inner", "gNavi_NPC_Inner", navi_npc_i_col); - EnhancementColor3("Navi NPC Outer", "gNavi_NPC_Outer", navi_npc_o_col); - EnhancementColor3("Navi Enemy Inner", "gNavi_Enemy_Inner", navi_enemy_i_col); - EnhancementColor3("Navi Enemy Outer", "gNavi_Enemy_Outer", navi_enemy_o_col); - EnhancementColor3("Navi Prop Inner", "gNavi_Prop_Inner", navi_prop_i_col); - EnhancementColor3("Navi Prop Outer", "gNavi_Prop_Outer", navi_prop_o_col); - - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("Cheats")) - { - if (ImGui::BeginMenu("Infinite...")) { - EnhancementCheckbox("Money", "gInfiniteMoney"); - EnhancementCheckbox("Health", "gInfiniteHealth"); - EnhancementCheckbox("Ammo", "gInfiniteAmmo"); - EnhancementCheckbox("Magic", "gInfiniteMagic"); - EnhancementCheckbox("Nayru's Love", "gInfiniteNayru"); - - ImGui::EndMenu(); - } - - EnhancementCheckbox("No Clip", "gNoClip"); - Tooltip("Allows you to walk through walls"); - EnhancementCheckbox("Climb Everything", "gClimbEverything"); - Tooltip("Makes every surface in the game climbable"); - EnhancementCheckbox("Moon Jump on L", "gMoonJumpOnL"); - Tooltip("Holding L makes you float into the air"); - EnhancementCheckbox("Super Tunic", "gSuperTunic"); - Tooltip("Makes every tunic have the effects of every other tunic"); - EnhancementCheckbox("Easy ISG", "gEzISG"); - Tooltip("Automatically activates the Infinite Sword glitch, making you constantly swing your sword"); - EnhancementCheckbox("Unrestricted Items", "gNoRestrictItems"); - Tooltip("Allows you to use all items at any age"); - EnhancementCheckbox("Freeze Time", "gFreezeTime"); - Tooltip("Freezes the time of day"); - - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("Developer Tools")) - { - EnhancementCheckbox("OoT Debug Mode", "gDebugEnabled"); - Tooltip("Enables Debug Mode, allowing you to select maps with L + R + Z, noclip with L + D-pad Right,\nand open the debug menu with L on the pause screen"); - ImGui::Separator(); - EnhancementCheckbox("Stats", "gStatsEnabled"); - Tooltip("Shows the stats window, with your FPS and frametimes, and the OS you're playing on"); - EnhancementCheckbox("Console", "gConsoleEnabled"); - Tooltip("Enables the console window, allowing you to input commands, type help for some examples"); - console->opened = CVar_GetS32("gConsoleEnabled", 0); - - ImGui::EndMenu(); - } - - for (const auto& category : windowCategories) { - if (ImGui::BeginMenu(category.first.c_str())) { - for (const std::string& name : category.second) { - std::string varName(name); - varName.erase(std::ranges::remove_if(varName, isspace).begin(), varName.end()); - std::string toggleName = "g" + varName + "Enabled"; - - EnhancementCheckbox(name, toggleName); - customWindows[name].enabled = CVar_GetS32(toggleName.c_str(), 0); - } - ImGui::EndMenu(); - } - - } - - ImGui::EndMenuBar(); - } - - ImGui::End(); - - if (CVar_GetS32("gStatsEnabled", 0)) { - const float framerate = ImGui::GetIO().Framerate; - ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0)); - ImGui::Begin("Debug Stats", nullptr, ImGuiWindowFlags_NoFocusOnAppearing); - -#ifdef _WIN32 - ImGui::Text("Platform: Windows"); -#elif defined(__SWITCH__) - ImGui::Text("Platform: Nintendo Switch"); -#else - ImGui::Text("Platform: Linux"); -#endif - ImGui::Text("Status: %.3f ms/frame (%.1f FPS)", 1000.0f / framerate, framerate); - ImGui::End(); - ImGui::PopStyleColor(); - } - - console->Draw(); - - for (auto& windowIter : customWindows) { - CustomWindow& window = windowIter.second; - if (window.drawFunc != nullptr) { - window.drawFunc(window.enabled); - } - } - - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); - ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0.0f); - ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.0f, 0.0f, 0.0f, 0.0f)); - ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBackground; - ImGui::Begin("OoT Master Quest", nullptr, flags); - ImGui::PopStyleVar(3); - ImGui::PopStyleColor(); - - ImVec2 main_pos = ImGui::GetWindowPos(); - main_pos.x -= top_left_pos.x; - main_pos.y -= top_left_pos.y; - ImVec2 size = ImGui::GetContentRegionAvail(); - ImVec2 pos = ImVec2(0, 0); - gfx_current_dimensions.width = size.x * gfx_current_dimensions.internal_mul; - gfx_current_dimensions.height = size.y * gfx_current_dimensions.internal_mul; - gfx_current_game_window_viewport.x = main_pos.x; - gfx_current_game_window_viewport.y = main_pos.y; - gfx_current_game_window_viewport.width = size.x; - gfx_current_game_window_viewport.height = size.y; - - if (CVar_GetS32("gN64Mode", 0)) - { - gfx_current_dimensions.width = 320; - gfx_current_dimensions.height = 240; - const int sw = size.y * 320 / 240; - gfx_current_game_window_viewport.x += (size.x - sw) / 2; - gfx_current_game_window_viewport.width = sw; - pos = ImVec2(size.x / 2 - sw / 2, 0); - size = ImVec2(sw, size.y); - } - - overlay->Draw(); - } - - void DrawFramebufferAndGameInput() { - ImVec2 main_pos = ImGui::GetWindowPos(); - ImVec2 size = ImGui::GetContentRegionAvail(); - ImVec2 pos = ImVec2(0, 0); - if (CVar_GetS32("gN64Mode", 0)) { - const int sw = size.y * 320 / 240; - pos = ImVec2(size.x / 2 - sw / 2, 0); - size = ImVec2(sw, size.y); - } - std::string fb_str = SohUtils::getEnvironmentVar("framebuffer"); - if (!fb_str.empty()) { - uintptr_t fbuf = (uintptr_t)std::stoull(fb_str); - //ImGui::ImageSimple(reinterpret_cast(fbuf), pos, size); - ImGui::SetCursorPos(pos); - ImGui::Image(reinterpret_cast(fbuf), size); - } - - ImGui::End(); - - const float scale = CVar_GetFloat("gInputScale", 1.0f); - ImVec2 BtnPos = ImVec2(160 * scale, 85 * scale); - - if (CVar_GetS32("gInputEnabled", 0)) { - ImGui::SetNextWindowSize(BtnPos); - ImGui::SetNextWindowPos(ImVec2(main_pos.x + size.x - BtnPos.x - 20, main_pos.y + size.y - BtnPos.y - 20)); - - if (pads != nullptr && ImGui::Begin("Game Buttons", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoBackground)) { - ImGui::SetCursorPosY(32 * scale); - - ImGui::BeginGroup(); - const ImVec2 cPos = ImGui::GetCursorPos(); - ImGui::SetCursorPos(ImVec2(cPos.x + 10 * scale, cPos.y - 20 * scale)); - BindButton("L-Btn", pads[0].button & BTN_L); - ImGui::SetCursorPos(ImVec2(cPos.x + 16 * scale, cPos.y)); - BindButton("C-Up", pads[0].button & BTN_CUP); - ImGui::SetCursorPos(ImVec2(cPos.x, cPos.y + 16 * scale)); - BindButton("C-Left", pads[0].button & BTN_CLEFT); - ImGui::SetCursorPos(ImVec2(cPos.x + 32 * scale, cPos.y + 16 * scale)); - BindButton("C-Right", pads[0].button & BTN_CRIGHT); - ImGui::SetCursorPos(ImVec2(cPos.x + 16 * scale, cPos.y + 32 * scale)); - BindButton("C-Down", pads[0].button & BTN_CDOWN); - ImGui::EndGroup(); - - ImGui::SameLine(); - - ImGui::BeginGroup(); - const ImVec2 sPos = ImGui::GetCursorPos(); - ImGui::SetCursorPos(ImVec2(sPos.x + 21, sPos.y - 20 * scale)); - BindButton("Z-Btn", pads[0].button & BTN_Z); - ImGui::SetCursorPos(ImVec2(sPos.x + 22, sPos.y + 16 * scale)); - BindButton("Start-Btn", pads[0].button & BTN_START); - ImGui::EndGroup(); - - ImGui::SameLine(); - - ImGui::BeginGroup(); - const ImVec2 bPos = ImGui::GetCursorPos(); - ImGui::SetCursorPos(ImVec2(bPos.x + 20 * scale, bPos.y - 20 * scale)); - BindButton("R-Btn", pads[0].button & BTN_R); - ImGui::SetCursorPos(ImVec2(bPos.x + 12 * scale, bPos.y + 8 * scale)); - BindButton("B-Btn", pads[0].button & BTN_B); - ImGui::SetCursorPos(ImVec2(bPos.x + 28 * scale, bPos.y + 24 * scale)); - BindButton("A-Btn", pads[0].button & BTN_A); - ImGui::EndGroup(); - - ImGui::End(); - } - } - } - - void Render() { - ImGui::Render(); - ImGuiRenderDrawData(ImGui::GetDrawData()); - if (UseViewports()) { - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindowsDefault(); - } - } - - void CancelFrame() { - ImGui::EndFrame(); - if (UseViewports()) { - ImGui::UpdatePlatformWindows(); - } - } - - 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); - } - - ImTextureID GetTextureByID(int id) { -#ifdef ENABLE_DX11 - if (impl.backend == Backend::DX11) - { - ImTextureID gfx_d3d11_get_texture_by_id(int id); - return gfx_d3d11_get_texture_by_id(id); - } -#endif - return reinterpret_cast(id); - } -} diff --git a/libultraship/libultraship/Window.cpp b/libultraship/libultraship/Window.cpp index 3a22973af48..8760ae1942f 100644 --- a/libultraship/libultraship/Window.cpp +++ b/libultraship/libultraship/Window.cpp @@ -18,12 +18,16 @@ #include "Lib/Fast3D/gfx_sdl.h" #include "Lib/Fast3D/gfx_opengl.h" #include "stox.h" +#if __APPLE__ +#include +#else #include +#endif #include #include #include -#include "SohHooks.h" -#include "SohConsole.h" +#include "Hooks.h" +#include "Console.h" #include @@ -34,8 +38,7 @@ extern "C" { uint8_t __enableGameInput = 1; int32_t osContInit(OSMesgQueue* mq, uint8_t* controllerBits, OSContStatus* status) { - std::shared_ptr pConf = Ship::GlobalCtx2::GetInstance()->GetConfig(); - Ship::ConfigFile& Conf = *pConf.get(); + *controllerBits = 0; if (SDL_Init(SDL_INIT_GAMECONTROLLER) != 0) { SPDLOG_ERROR("Failed to initialize SDL game controllers ({})", SDL_GetError()); @@ -51,43 +54,8 @@ extern "C" { SPDLOG_ERROR("Failed add SDL game controller mappings from \"{}\" ({})", controllerDb, SDL_GetError()); } #endif - // TODO: This for loop is debug. Burn it with fire. - for (int i = 0; i < SDL_NumJoysticks(); i++) { - if (SDL_IsGameController(i)) { - // Get the GUID from SDL - char buf[33]; - SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(i), buf, sizeof(buf)); - auto guid = std::string(buf); - auto name = std::string(SDL_GameControllerNameForIndex(i)); - - SPDLOG_INFO("Found Controller \"{}\" with ID \"{}\"", name, guid); - } - } - for (int32_t i = 0; i < __osMaxControllers; i++) { - std::string ControllerType = Conf["CONTROLLERS"]["CONTROLLER " + std::to_string(i+1)]; - mINI::INIStringUtil::toLower(ControllerType); - - if (ControllerType == "auto") { - Ship::Window::Controllers[i].push_back(std::make_shared(i)); - Ship::Window::Controllers[i].push_back(std::make_shared(i)); - } else if (ControllerType == "keyboard") { - Ship::Window::Controllers[i].push_back(std::make_shared(i)); - } else if (ControllerType == "usb") { - Ship::Window::Controllers[i].push_back(std::make_shared(i)); - } else if (ControllerType == "unplugged") { - // Do nothing for unplugged controllers - } else { - SPDLOG_ERROR("Invalid Controller Type: {}", ControllerType); - } - } - - *controllerBits = 0; - for (size_t i = 0; i < __osMaxControllers; i++) { - if (Ship::Window::Controllers[i].size() > 0) { - *controllerBits |= 1 << i; - } - } + Ship::Window::ControllerApi->Init(controllerBits); return 0; } @@ -100,64 +68,51 @@ extern "C" { pad->button = 0; pad->stick_x = 0; pad->stick_y = 0; + pad->cam_x = 0; + pad->cam_y = 0; pad->err_no = 0; pad->gyro_x = 0; pad->gyro_y = 0; - if (__enableGameInput) - { - for (size_t i = 0; i < __osMaxControllers; i++) { - for (size_t j = 0; j < Ship::Window::Controllers[i].size(); j++) { - Ship::Window::Controllers[i][j]->Read(&pad[i]); - } - } + if (__enableGameInput) { + Ship::Window::ControllerApi->WriteToPad(pad); } - ModInternal::bindHook(CONTROLLER_READ); - ModInternal::initBindHook(1, - HookParameter({ .name = "cont_pad", .parameter = (void*)pad }) - ); - ModInternal::callBindHook(0); + ModInternal::ExecuteHooks(pad); } - char* ResourceMgr_GetNameByCRC(uint64_t crc, char* alloc) { - std::string hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(crc); - strcpy(alloc, hashStr.c_str()); - return (char*)hashStr.c_str(); + const char* ResourceMgr_GetNameByCRC(uint64_t crc) { + const std::string* hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(crc); + return hashStr != nullptr ? hashStr->c_str() : nullptr; } Vtx* ResourceMgr_LoadVtxByCRC(uint64_t crc) { - std::string hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(crc); - - if (hashStr != "") { - auto res = std::static_pointer_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(hashStr)); + const std::string* hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(crc); - //if (res != nullptr) - return (Vtx*)res->vertices.data(); - //else - //return (Vtx*)Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadFile(hashStr)->buffer.get(); - } - else { - return nullptr; + if (hashStr != nullptr) { + auto res = std::static_pointer_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(hashStr->c_str())); + return (Vtx*)res->vertices.data(); } + + return nullptr; } int32_t* ResourceMgr_LoadMtxByCRC(uint64_t crc) { - std::string hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(crc); + const std::string* hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(crc); - if (hashStr != "") { - auto res = std::static_pointer_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(hashStr)); + if (hashStr != nullptr) { + auto res = std::static_pointer_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(hashStr->c_str())); return (int32_t*)res->mtx.data(); - } else { - return nullptr; } + + return nullptr; } Gfx* ResourceMgr_LoadGfxByCRC(uint64_t crc) { - std::string hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(crc); + const std::string* hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(crc); - if (hashStr != "") { - auto res = std::static_pointer_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(hashStr)); + if (hashStr != nullptr) { + auto res = std::static_pointer_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(hashStr->c_str())); return (Gfx*)&res->instructions[0]; } else { return nullptr; @@ -165,17 +120,12 @@ extern "C" { } char* ResourceMgr_LoadTexByCRC(uint64_t crc) { - const std::string hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(crc); + const std::string* hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(crc); - if (!hashStr.empty()) { - const auto res = static_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(hashStr).get()); + if (hashStr != nullptr) { + const auto res = static_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(hashStr->c_str()).get()); - ModInternal::bindHook(LOAD_TEXTURE); - ModInternal::initBindHook(2, - HookParameter({.name = "path", .parameter = (void*)hashStr.c_str() }), - HookParameter({.name = "texture", .parameter = static_cast(&res->imageData) }) - ); - ModInternal::callBindHook(0); + ModInternal::ExecuteHooks(hashStr->c_str(), &res->imageData); return reinterpret_cast(res->imageData); } else { @@ -185,11 +135,11 @@ extern "C" { void ResourceMgr_RegisterResourcePatch(uint64_t hash, uint32_t instrIndex, uintptr_t origData) { - std::string hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(hash); + const std::string* hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(hash); - if (hashStr != "") + if (hashStr != nullptr) { - auto res = (Ship::Texture*)Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(hashStr).get(); + auto res = (Ship::Texture*)Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(hashStr->c_str()).get(); Ship::Patch patch; patch.crc = hash; @@ -202,12 +152,7 @@ extern "C" { char* ResourceMgr_LoadTexByName(char* texPath) { const auto res = static_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(texPath).get()); - ModInternal::bindHook(LOAD_TEXTURE); - ModInternal::initBindHook(2, - HookParameter({ .name = "path", .parameter = (void*)texPath }), - HookParameter({ .name = "texture", .parameter = static_cast(&res->imageData) }) - ); - ModInternal::callBindHook(0); + ModInternal::ExecuteHooks(texPath, &res->imageData); return (char*)res->imageData; } @@ -245,7 +190,7 @@ extern GfxWindowManagerAPI gfx_sdl; void SetWindowManager(GfxWindowManagerAPI** WmApi, GfxRenderingAPI** RenderingApi, const std::string& gfx_backend); namespace Ship { - std::map>> Window::Controllers; + int32_t Window::lastScancode; Window::Window(std::shared_ptr Context) : Context(Context), APlayer(nullptr) { @@ -260,23 +205,49 @@ namespace Ship { SPDLOG_INFO("destruct window"); } + void Window::CreateDefaults() { + const std::shared_ptr pConf = GlobalCtx2::GetInstance()->GetConfig(); + if (pConf->isNewInstance) { + pConf->setInt("Window.Width", 640); + pConf->setInt("Window.Height", 480); + pConf->setBool("Window.Options", false); + pConf->setString("Window.GfxBackend", ""); + + pConf->setBool("Window.Fullscreen.Enabled", false); + pConf->setInt("Window.Fullscreen.Width", 640); + pConf->setInt("Window.Fullscreen.Height", 480); + + pConf->setString("Game.SaveName", ""); + pConf->setString("Game.Main Archive", ""); + pConf->setString("Game.Patches Archive", ""); + + pConf->setInt("Shortcuts.Fullscreen", 0x044); + pConf->setInt("Shortcuts.Console", 0x029); + pConf->save(); + } + } + void Window::Init() { - std::shared_ptr pConf = GlobalCtx2::GetInstance()->GetConfig(); - ConfigFile& Conf = *pConf.get(); + std::shared_ptr pConf = GlobalCtx2::GetInstance()->GetConfig(); + + CreateDefaults(); SetAudioPlayer(); - bIsFullscreen = Ship::stob(Conf["WINDOW"]["FULLSCREEN"]); - dwWidth = Ship::stoi(Conf["WINDOW"]["WINDOW WIDTH"], 320); - dwHeight = Ship::stoi(Conf["WINDOW"]["WINDOW HEIGHT"], 240); - dwWidth = Ship::stoi(Conf["WINDOW"]["FULLSCREEN WIDTH"], 1920); - dwHeight = Ship::stoi(Conf["WINDOW"]["FULLSCREEN HEIGHT"], 1080); - dwMenubar = Ship::stoi(Conf["WINDOW"]["menubar"], 0); - const std::string& gfx_backend = Conf["WINDOW"]["GFX BACKEND"]; + bIsFullscreen = pConf->getBool("Window.Fullscreen.Enabled", false); + + dwWidth = pConf->getInt("Window.Fullscreen.Width", bIsFullscreen ? 1920 : 640); + dwHeight = pConf->getInt("Window.Fullscreen.Height", bIsFullscreen ? 1080 : 480); + dwMenubar = pConf->getBool("Window.Options", false); + const std::string& gfx_backend = pConf->getString("Window.GfxBackend"); SetWindowManager(&WmApi, &RenderingApi, gfx_backend); - gfx_init(WmApi, RenderingApi, GetContext()->GetName().c_str(), bIsFullscreen); - WmApi->set_fullscreen_changed_callback(Window::OnFullscreenChanged); - WmApi->set_keyboard_callbacks(Window::KeyDown, Window::KeyUp, Window::AllKeysUp); + gfx_init(WmApi, RenderingApi, GetContext()->GetName().c_str(), bIsFullscreen, dwWidth, dwHeight); + WmApi->set_fullscreen_changed_callback(OnFullscreenChanged); + WmApi->set_keyboard_callbacks(KeyDown, KeyUp, AllKeysUp); + + ModInternal::RegisterHook([]() { + ControllerApi->SaveControllerSettings(); + }); } void Window::StartFrame() { @@ -288,13 +259,14 @@ namespace Ship { gfx_run(Commands, m); gfx_end_frame(); } - gfx_run(Commands, {}); - gfx_end_frame(); } - void Window::SetFrameDivisor(int divisor) { - gfx_set_framedivisor(divisor); - //gfx_set_framedivisor(0); + void Window::SetTargetFps(int fps) { + gfx_set_target_fps(fps); + } + + void Window::SetMaximumFrameLatency(int latency) { + gfx_set_maximum_frame_latency(latency); } void Window::GetPixelDepthPrepare(float x, float y) { @@ -327,10 +299,9 @@ namespace Ship { WmApi->main_loop(MainFunction); } bool Window::KeyUp(int32_t dwScancode) { - std::shared_ptr pConf = GlobalCtx2::GetInstance()->GetConfig(); - ConfigFile& Conf = *pConf.get(); + std::shared_ptr pConf = GlobalCtx2::GetInstance()->GetConfig(); - if (dwScancode == Ship::stoi(Conf["KEYBOARD SHORTCUTS"]["KEY_FULLSCREEN"])) { + if (dwScancode == pConf->getInt("Shortcuts.Fullscreen", 0x044)) { GlobalCtx2::GetInstance()->GetWindow()->ToggleFullscreen(); } @@ -338,16 +309,14 @@ namespace Ship { //if (dwScancode == Ship::stoi(Conf["KEYBOARD SHORTCUTS"]["KEY_CONSOLE"])) { // ToggleConsole(); //} + + lastScancode = -1; bool bIsProcessed = false; - for (size_t i = 0; i < __osMaxControllers; i++) { - for (size_t j = 0; j < Controllers[i].size(); j++) { - KeyboardController* pad = dynamic_cast(Ship::Window::Controllers[i][j].get()); - if (pad != nullptr) { - if (pad->ReleaseButton(dwScancode)) { - bIsProcessed = true; - } - } + const auto pad = dynamic_cast(ControllerApi->physicalDevices[ControllerApi->physicalDevices.size() - 2].get()); + if (pad != nullptr) { + if (pad->ReleaseButton(dwScancode)) { + bIsProcessed = true; } } @@ -356,14 +325,11 @@ namespace Ship { bool Window::KeyDown(int32_t dwScancode) { bool bIsProcessed = false; - for (size_t i = 0; i < __osMaxControllers; i++) { - for (size_t j = 0; j < Controllers[i].size(); j++) { - KeyboardController* pad = dynamic_cast(Ship::Window::Controllers[i][j].get()); - if (pad != nullptr) { - if (pad->PressButton(dwScancode)) { - bIsProcessed = true; - } - } + + const auto pad = dynamic_cast(ControllerApi->physicalDevices[ControllerApi->physicalDevices.size() - 2].get()); + if (pad != nullptr) { + if (pad->PressButton(dwScancode)) { + bIsProcessed = true; } } @@ -374,21 +340,17 @@ namespace Ship { void Window::AllKeysUp(void) { - for (size_t i = 0; i < __osMaxControllers; i++) { - for (size_t j = 0; j < Controllers[i].size(); j++) { - KeyboardController* pad = dynamic_cast(Ship::Window::Controllers[i][j].get()); - if (pad != nullptr) { - pad->ReleaseAllButtons(); - } - } + const auto pad = dynamic_cast(ControllerApi->physicalDevices[ControllerApi->physicalDevices.size() - 2].get()); + if (pad != nullptr) { + pad->ReleaseAllButtons(); } } void Window::OnFullscreenChanged(bool bIsFullscreen) { - std::shared_ptr pConf = GlobalCtx2::GetInstance()->GetConfig(); - ConfigFile& Conf = *pConf.get(); + std::shared_ptr pConf = GlobalCtx2::GetInstance()->GetConfig(); + GlobalCtx2::GetInstance()->GetWindow()->bIsFullscreen = bIsFullscreen; - Conf["WINDOW"]["FULLSCREEN"] = std::to_string(bIsFullscreen); + pConf->setBool("Window.Fullscreen.Enabled", bIsFullscreen); GlobalCtx2::GetInstance()->GetWindow()->ShowCursor(!bIsFullscreen); } diff --git a/soh/include/functions.h b/soh/include/functions.h index c0d21049777..c0600929d38 100644 --- a/soh/include/functions.h +++ b/soh/include/functions.h @@ -60,7 +60,7 @@ void Locale_ResetRegion(void); u32 func_80001F48(void); u32 func_80001F8C(void); u32 Locale_IsRegionNative(void); -#ifndef __SWITCH__ +#if !defined(__APPLE__) && !defined(__SWITCH__) void __assert(const char* exp, const char* file, s32 line); #endif void isPrintfInit(void); @@ -448,6 +448,7 @@ u32 Actor_TextboxIsClosing(Actor* actor, GlobalContext* globalCtx); s8 func_8002F368(GlobalContext* globalCtx); void Actor_GetScreenPos(GlobalContext* globalCtx, Actor* actor, s16* x, s16* y); u32 Actor_HasParent(Actor* actor, GlobalContext* globalCtx); +s32 GiveItemWithoutActor(GlobalContext* globalCtx, s32 getItemId); s32 func_8002F434(Actor* actor, GlobalContext* globalCtx, s32 getItemId, f32 xzRange, f32 yRange); void func_8002F554(Actor* actor, GlobalContext* globalCtx, s32 getItemId); void func_8002F580(Actor* actor, GlobalContext* globalCtx); @@ -558,6 +559,7 @@ void ActorOverlayTable_Cleanup(void); u16 DynaSSNodeList_GetNextNodeIdx(DynaSSNodeList*); void func_80038A28(CollisionPoly* poly, f32 tx, f32 ty, f32 tz, MtxF* dest); f32 CollisionPoly_GetPointDistanceFromPlane(CollisionPoly* poly, Vec3f* point); +CollisionHeader* BgCheck_GetCollisionHeader(CollisionContext* colCtx, s32 bgId); void CollisionPoly_GetVerticesByBgId(CollisionPoly* poly, s32 bgId, CollisionContext* colCtx, Vec3f* dest); s32 BgCheck_CheckStaticCeiling(StaticLookup* lookup, u16 xpFlags, CollisionContext* colCtx, f32* outY, Vec3f* pos, f32 checkHeight, CollisionPoly** outPoly); @@ -2406,6 +2408,8 @@ char* SetQuote(); void Heaps_Alloc(void); void Heaps_Free(void); +CollisionHeader* BgCheck_GetCollisionHeader(CollisionContext* colCtx, s32 bgId); + #ifdef __cplusplus #undef this }; diff --git a/soh/soh/Enhancements/bootcommands.c b/soh/soh/Enhancements/bootcommands.c index c43135a215c..e64748d0046 100644 --- a/soh/soh/Enhancements/bootcommands.c +++ b/soh/soh/Enhancements/bootcommands.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -19,22 +20,30 @@ extern BootCommandFunc BootCommands_Command_LoadFileSelect(char** argv, s32 argc static BootCommand sCommands[] = { { "--skiplogo", BootCommands_Command_SkipLogo }, { "--loadfileselect", BootCommands_Command_LoadFileSelect } }; -void BootCommands_Init() +void BootCommands_Init() { CVar_RegisterS32("gDisableLOD", 0); CVar_RegisterS32("gDebugEnabled", 0); CVar_RegisterS32("gPauseLiveLink", 0); CVar_RegisterS32("gMinimalUI", 0); - CVar_RegisterS32("gRumbleEnabled", 0); - CVar_RegisterS32("gUniformLR", 1); + CVar_RegisterS32("gRedGanonBlood", 0); + CVar_RegisterS32("gHoverFishing", 0); + CVar_RegisterS32("gN64WeirdFrames", 0); + CVar_RegisterS32("gBombchusOOB", 0); + CVar_RegisterS32("gUniformLR", 0); CVar_RegisterS32("gTwoHandedIdle", 0); - CVar_RegisterS32("gDekuNutUpgradeFix", 1); + CVar_RegisterS32("gDekuNutUpgradeFix", 0); + CVar_RegisterS32("gNaviTextFix", 0); CVar_RegisterS32("gNewDrops", 0); CVar_RegisterS32("gVisualAgony", 0); CVar_RegisterS32("gLanguages", 0); //0 = English / 1 = German / 2 = French + CVar_RegisterS32("gForgeTime", 3); + CVar_RegisterS32("gGravediggingTourFix", 1); CVar_RegisterS32("gHudColors", 1); //0 = N64 / 1 = NGC / 2 = Custom CVar_RegisterS32("gUseNaviCol", 0); CVar_RegisterS32("gUseTunicsCol", 0); + CVar_RegisterS32("gGuardVision", 0); + CVar_RegisterS32("gTimeFlowFileSelect", 0); } //void BootCommands_ParseBootArgs(char* str) @@ -55,10 +64,10 @@ void BootCommands_ParseBootArgs(s32 argc, char** argv) } } - // for (i = 0; i < argc; i++) - // DebugArena_Free(argv[i]); + //for (i = 0; i < argc; i++) + //DebugArena_Free(argv[i]); - // DebugArena_Free(argv); + //DebugArena_Free(argv); } /* diff --git a/soh/src/code/audio_load.c b/soh/src/code/audio_load.c index 74b1a4bff43..eff3e5f8730 100644 --- a/soh/src/code/audio_load.c +++ b/soh/src/code/audio_load.c @@ -4,6 +4,7 @@ #include "ultra64.h" #include "global.h" +#include "soh/OTRGlobals.h" #define MK_ASYNC_MSG(retData, tableType, id, status) (((retData) << 24) | ((tableType) << 16) | ((id) << 8) | (status)) #define ASYNC_TBLTYPE(v) ((u8)(v >> 16)) @@ -37,11 +38,11 @@ void AudioLoad_ProcessAsyncLoads(s32 resetStatus); void AudioLoad_ProcessAsyncLoadUnkMedium(AudioAsyncLoad* asyncLoad, s32 resetStatus); void AudioLoad_ProcessAsyncLoad(AudioAsyncLoad* asyncLoad, s32 resetStatus); void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo, s32 temporary); -void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* mem, RelocInfo* relocInfo); +void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* mem, RelocInfo* relocInfo, int fontId); void AudioLoad_DiscardFont(s32 fontId); uintptr_t AudioLoad_TrySyncLoadSampleBank(u32 sampleBankId, u32* outMedium, s32 noLoad); uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 tableId, s32* didAllocate); -uintptr_t AudioLoad_GetRealTableIndex(s32 tableType, u32 tableId); +u32 AudioLoad_GetRealTableIndex(s32 tableType, u32 tableId); void* AudioLoad_SearchCaches(s32 tableType, s32 id); AudioTable* AudioLoad_GetLoadTable(s32 tableType); void AudioLoad_SyncDma(uintptr_t devAddr, u8* addr, size_t size, s32 medium); @@ -75,6 +76,12 @@ void* sUnusedHandler = NULL; s32 gAudioContextInitalized = false; +char* sequenceMap[256]; +char* fontMap[256]; + +uintptr_t fontStart; +uint32_t fontOffsets[8192]; + void AudioLoad_DecreaseSampleDmaTtls(void) { u32 i; @@ -279,8 +286,10 @@ void AudioLoad_InitSampleDmaBuffers(s32 arg0) { } s32 AudioLoad_IsFontLoadComplete(s32 fontId) { + return true; if (fontId == 0xFF) { return true; + } else if (gAudioContext.fontLoadStatus[fontId] >= 2) { return true; } else if (gAudioContext.fontLoadStatus[AudioLoad_GetRealTableIndex(FONT_TABLE, fontId)] >= 2) { @@ -353,6 +362,9 @@ void AudioLoad_InitTable(AudioTable* table, uintptr_t romAddr, u16 unkMediumPara for (i = 0; i < table->numEntries; i++) { if ((table->entries[i].size != 0) && (table->entries[i].medium == MEDIUM_CART)) { + if (romAddr == fontStart) + fontOffsets[i] = table->entries[i].romAddr; + table->entries[i].romAddr += romAddr; } } @@ -361,7 +373,7 @@ void AudioLoad_InitTable(AudioTable* table, uintptr_t romAddr, u16 unkMediumPara SoundFontData* AudioLoad_SyncLoadSeqFonts(s32 seqId, u32* outDefaultFontId) { char pad[0x8]; s32 index; - SoundFontData* font; + SoundFontData* font = NULL; s32 numFonts; s32 fontId; s32 i; @@ -376,6 +388,7 @@ SoundFontData* AudioLoad_SyncLoadSeqFonts(s32 seqId, u32* outDefaultFontId) { while (numFonts > 0) { fontId = gAudioContext.sequenceFontTable[index++]; + font = AudioLoad_SyncLoadFont(fontId); numFonts--; } @@ -401,7 +414,8 @@ void AudioLoad_SyncLoadSeqParts(s32 seqId, s32 arg1) { s32 AudioLoad_SyncLoadSample(SoundFontSample* sample, s32 fontId) { void* sampleAddr; - if (sample->unk_bit25 == 1) { + if (sample->unk_bit25 == 1) + { if (sample->medium != MEDIUM_RAM) { sampleAddr = AudioHeap_AllocSampleCache(sample->size, fontId, (void*)sample->sampleAddr, sample->medium, CACHE_PERSISTENT); @@ -448,7 +462,7 @@ s32 AudioLoad_SyncLoadInstrument(s32 fontId, s32 instId, s32 drumId) { void AudioLoad_AsyncLoad(s32 tableType, s32 id, s32 nChunks, s32 retData, OSMesgQueue* retQueue) { if (AudioLoad_AsyncLoadInner(tableType, id, nChunks, retData, retQueue) == NULL) { - osSendMesg(retQueue, 0xFFFFFFFF, OS_MESG_NOBLOCK); + osSendMesg32(retQueue, 0xFFFFFFFF, OS_MESG_NOBLOCK); } } @@ -467,13 +481,15 @@ void AudioLoad_AsyncLoadFont(s32 fontId, s32 arg1, s32 retData, OSMesgQueue* ret u8* AudioLoad_GetFontsForSequence(s32 seqId, u32* outNumFonts) { s32 index; - index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; + if (seqId == 255) + return NULL; + + SequenceData sDat = ResourceMgr_LoadSeqByName(sequenceMap[seqId]); - *outNumFonts = gAudioContext.sequenceFontTable[index++]; - if (*outNumFonts == 0) { + if (sDat.numFonts == 0) return NULL; - } - return &gAudioContext.sequenceFontTable[index]; + + return sDat.fonts; } void AudioLoad_DiscardSeqFonts(s32 seqId) { @@ -549,30 +565,31 @@ s32 AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2) { s32 numFonts; s32 fontId; - if (seqId >= gAudioContext.numSequences) { - return 0; - } - AudioSeq_SequencePlayerDisable(seqPlayer); fontId = 0xFF; - index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; - numFonts = gAudioContext.sequenceFontTable[index++]; + //index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; + //numFonts = gAudioContext.sequenceFontTable[index++]; - while (numFonts > 0) { - fontId = gAudioContext.sequenceFontTable[index++]; - AudioLoad_SyncLoadFont(fontId); - numFonts--; + SequenceData seqData2 = ResourceMgr_LoadSeqByName(sequenceMap[seqId]); + + for (int i = 0; i < seqData2.numFonts; i++) + { + fontId = seqData2.fonts[i]; + AudioLoad_SyncLoadFont(fontId); // NOTE: If this is commented out, then enemies will play child link sounds... + //numFonts--; } seqData = AudioLoad_SyncLoadSeq(seqId); + if (seqData == NULL) { return 0; } AudioSeq_ResetSequencePlayer(seqPlayer); seqPlayer->seqId = seqId; - seqPlayer->defaultFont = AudioLoad_GetRealTableIndex(FONT_TABLE, fontId); + seqPlayer->defaultFont = fontId; + seqPlayer->seqData = seqData; seqPlayer->enabled = 1; seqPlayer->scriptState.pc = seqData; @@ -615,8 +632,8 @@ uintptr_t AudioLoad_TrySyncLoadSampleBank(u32 sampleBankId, u32* outMedium, s32 return ret; } - cachePolicy = sampleBankTable->entries[sampleBankId].cachePolicy; - if (cachePolicy == 4 || noLoad == true) { + //cachePolicy = sampleBankTable->entries[sampleBankId].cachePolicy; + if (/* cachePolicy == 4 || */ noLoad == true) { *outMedium = sampleBankTable->entries[sampleBankId].medium; return sampleBankTable->entries[realTableId].romAddr; } @@ -642,22 +659,25 @@ SoundFontData* AudioLoad_SyncLoadFont(u32 fontId) { if (gAudioContext.fontLoadStatus[realFontId] == 1) { return NULL; } - sampleBankId1 = gAudioContext.soundFonts[realFontId].sampleBankId1; - sampleBankId2 = gAudioContext.soundFonts[realFontId].sampleBankId2; + + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); + + sampleBankId1 = sf->sampleBankId1; + sampleBankId2 = sf->sampleBankId2; relocInfo.sampleBankId1 = sampleBankId1; relocInfo.sampleBankId2 = sampleBankId2; - if (sampleBankId1 != 0xFF) { - relocInfo.baseAddr1 = AudioLoad_TrySyncLoadSampleBank(sampleBankId1, &relocInfo.medium1, false); - } else { + //if (sampleBankId1 != 0xFF) { + //relocInfo.baseAddr1 = AudioLoad_TrySyncLoadSampleBank(sampleBankId1, &relocInfo.medium1, false); + //} else { relocInfo.baseAddr1 = 0; - } + //} - if (sampleBankId2 != 0xFF) { - relocInfo.baseAddr2 = AudioLoad_TrySyncLoadSampleBank(sampleBankId2, &relocInfo.medium2, false); - } else { + //if (sampleBankId2 != 0xFF) { + //relocInfo.baseAddr2 = AudioLoad_TrySyncLoadSampleBank(sampleBankId2, &relocInfo.medium2, false); + //} else { relocInfo.baseAddr2 = 0; - } + //} ret = AudioLoad_SyncLoad(FONT_TABLE, fontId, &didAllocate); if (ret == NULL) { @@ -687,12 +707,36 @@ uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) { *didAllocate = false; status = 2; } else { - table = AudioLoad_GetLoadTable(tableType); - size = table->entries[realId].size; - size = ALIGN16(size); - medium = table->entries[id].medium; - cachePolicy = table->entries[id].cachePolicy; - romAddr = table->entries[realId].romAddr; + char* seqData = 0; + SoundFont* fnt; + + if (tableType == SEQUENCE_TABLE) + { + SequenceData sData = ResourceMgr_LoadSeqByName(sequenceMap[id]); + seqData = sData.seqData; + size = sData.seqDataSize; + medium = sData.medium; + cachePolicy = sData.cachePolicy; + romAddr = 0; + } + else if (tableType == FONT_TABLE) + { + fnt = ResourceMgr_LoadAudioSoundFont(fontMap[id]); + size = sizeof(SoundFont); + medium = 2; + cachePolicy = 0; + romAddr = 0; + } + else + { + //table = AudioLoad_GetLoadTable(tableType); + //size = table->entries[realId].size; + //size = ALIGN16(size); + //medium = table->entries[id].medium; + //cachePolicy = table->entries[id].cachePolicy; + //romAddr = table->entries[realId].romAddr; + } + switch (cachePolicy) { case 0: ret = AudioHeap_AllocPermanent(tableType, realId, size); @@ -725,7 +769,14 @@ uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) { if (medium == MEDIUM_UNK) { AudioLoad_SyncDmaUnkMedium(romAddr, ret, size, (s16)table->unkMediumParam); } else { - AudioLoad_SyncDma(romAddr, ret, size, medium); + if (tableType == SEQUENCE_TABLE && seqData != NULL) { + AudioLoad_SyncDma(seqData, ret, size, medium); + } else if (tableType == FONT_TABLE) { + AudioLoad_SyncDma(fnt, ret, size, medium); + } + else { + //AudioLoad_SyncDma(romAddr, ret, size, medium); + } } status = cachePolicy == 0 ? 5 : 2; @@ -748,13 +799,20 @@ uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) { return ret; } -uintptr_t AudioLoad_GetRealTableIndex(s32 tableType, u32 id) { - AudioTable* table = AudioLoad_GetLoadTable(tableType); - - if (table->entries[id].size == 0) { - id = table->entries[id].romAddr; +u32 AudioLoad_GetRealTableIndex(s32 tableType, u32 id) +{ + if ((tableType == SEQUENCE_TABLE || tableType == FONT_TABLE)) { + return id; } + //AudioTable* table = AudioLoad_GetLoadTable(tableType); + + // If the size is 0, then this entry actually redirects to another entry. + // The rom address is actually an index into the same table where the "real" data is. + //if (table->entries[id].size == 0) { + //id = table->entries[id].romAddr; + //} + return id; } @@ -801,46 +859,42 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo Drum* drum; SoundFontSound* sfx; s32 i; - s32 numDrums = gAudioContext.soundFonts[fontId].numDrums; - s32 numInstruments = gAudioContext.soundFonts[fontId].numInstruments; - s32 numSfx = gAudioContext.soundFonts[fontId].numSfx; + SoundFont* sf = NULL; + s32 numDrums = 0; + s32 numInstruments = 0; + s32 numSfx = 0; + + sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); + numDrums = sf->numDrums; + numInstruments = sf->numInstruments; + numSfx = sf->numSfx; + void** ptrs = (void**)mem; -#define BASE_OFFSET(x) (uintptr_t)((uintptr_t)(x) + (uintptr_t)(mem)) +#define BASE_OFFSET(x) (void*)((u32)(x) + (u32)(mem)) reloc2 = ptrs[0]; - if (1) {} - if ((reloc2 != 0) && (numDrums != 0)) { + if ((numDrums != 0)) + { ptrs[0] = BASE_OFFSET(reloc2); - for (i = 0; i < numDrums; i++) { - reloc = ((Drum**)ptrs[0])[i]; - - if (reloc != 0) { - reloc = BASE_OFFSET(reloc); - - ((Drum**)ptrs[0])[i] = drum = reloc; - if (!drum->loaded) { - AudioLoad_RelocateSample(&drum->sound, mem, relocInfo); - reloc = drum->envelope; - drum->envelope = BASE_OFFSET(reloc); - drum->loaded = 1; - } + for (i = 0; i < numDrums; i++) + { + drum = sf->drums[i]; + + if (!drum->loaded) + { + AudioLoad_RelocateSample(&sf->drums[i]->sound, mem, relocInfo, fontOffsets[fontId]); + drum->loaded = 1; } } } reloc2 = ptrs[1]; - if (1) {} - if ((reloc2 != 0) && (numSfx != 0)) { + if (numSfx != 0) { ptrs[1] = BASE_OFFSET(reloc2); for (i = 0; i < numSfx; i++) { reloc = (SoundFontSound*)ptrs[1] + i; - if (reloc != 0) { - sfx = reloc; - if (sfx->sample != NULL) { - AudioLoad_RelocateSample(sfx, mem, relocInfo); - } - } + AudioLoad_RelocateSample(&sf->soundEffects[i].sample, mem, relocInfo, fontOffsets[fontId]); } } @@ -848,38 +902,34 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo numInstruments = 0x7E; } - for (i = 2; i <= 2 + numInstruments - 1; i++) { - if (ptrs[i] != NULL) { - ptrs[i] = BASE_OFFSET(ptrs[i]); + int startI = 0; + int startEC = numInstruments - 1; + for (i = startI; i <= startEC; i++) { + ptrs[i] = BASE_OFFSET(ptrs[i]); + inst = sf->instruments[i]; - inst = ptrs[i]; - if (!inst->loaded) { - if (inst->normalRangeLo != 0) { - AudioLoad_RelocateSample(&inst->lowNotesSound, mem, relocInfo); - } - AudioLoad_RelocateSample(&inst->normalNotesSound, mem, relocInfo); - if (inst->normalRangeHi != 0x7F) { - AudioLoad_RelocateSample(&inst->highNotesSound, mem, relocInfo); - } - - reloc = inst->envelope; - inst->envelope = BASE_OFFSET(reloc); - inst->loaded = 1; + if (inst != NULL && !inst->loaded) { + if (inst->normalRangeLo != 0) + { + AudioLoad_RelocateSample(&inst->lowNotesSound, mem, relocInfo, fontOffsets[fontId]); + } + AudioLoad_RelocateSample(&inst->normalNotesSound, mem, relocInfo, fontOffsets[fontId]); + if (inst->normalRangeHi != 0x7F) { + AudioLoad_RelocateSample(&inst->highNotesSound, mem, relocInfo, fontOffsets[fontId]); } + + reloc = inst->envelope; + inst->loaded = 1; } } #undef BASE_OFFSET - - gAudioContext.soundFonts[fontId].drums = ptrs[0]; - gAudioContext.soundFonts[fontId].soundEffects = ptrs[1]; - gAudioContext.soundFonts[fontId].instruments = (Instrument**)(ptrs + 2); } void AudioLoad_SyncDma(uintptr_t devAddr, u8* addr, size_t size, s32 medium) { OSMesgQueue* msgQueue = &gAudioContext.syncDmaQueue; OSIoMesg* ioMesg = &gAudioContext.syncDmaIoMesg; - size = ALIGN16(size); + //size = ALIGN16(size); Audio_InvalDCache(addr, size); @@ -956,7 +1006,7 @@ void* AudioLoad_AsyncLoadInner(s32 tableType, s32 id, s32 nChunks, s32 retData, ret = AudioLoad_SearchCaches(tableType, realId); if (ret != NULL) { status = 2; - osSendMesg(retQueue, MK_ASYNC_MSG(retData, 0, 0, 0), OS_MESG_NOBLOCK); + osSendMesg32(retQueue, MK_ASYNC_MSG(retData, 0, 0, 0), OS_MESG_NOBLOCK); } else { sp50 = AudioLoad_GetLoadTable(tableType); size = sp50->entries[realId].size; @@ -1059,25 +1109,6 @@ s32 AudioLoad_AssertValidAddr(uintptr_t ramAddr, uintptr_t startAddr, size_t siz #define BASE_ROM_OFFSET(x) (uintptr_t)((uintptr_t)(x) + (uintptr_t)(romAddr)) void AudioLoad_InitSwapFontSampleHeaders(SoundFontSample* sample, uintptr_t romAddr) { - // OTRTODO: This will be removed when we actually extract the data. - size_t maxSoundFontSize = 0x3AA0; // soundFont 0 is the largest size at 0x3AA0 - AdpcmLoop* loop; - AdpcmBook* book; - - if (((uintptr_t)sample->loop > maxSoundFontSize) || ((uintptr_t)sample->book > maxSoundFontSize) ) { - bswapSoundFontSample(sample); - - loop = (AdpcmLoop*)BASE_ROM_OFFSET(sample->loop); - if ((uint32_t)loop->end > (uint32_t)0xFFFF) { - bswapAdpcmLoop(loop); - } - - book = (AdpcmBook*)BASE_ROM_OFFSET(sample->book); - if (book->order > 0xFFFF) { - bswapAdpcmBook(book); - } - } - return; } void AudioLoad_InitSwapFont(void) { @@ -1124,7 +1155,6 @@ void AudioLoad_InitSwapFont(void) { if (drumList[i] != NULL) { drum = (Drum*)BASE_ROM_OFFSET(drumList[i]); - bswapDrum(drum); sample = (SoundFontSample*)BASE_ROM_OFFSET(drum->sound.sample); AudioLoad_InitSwapFontSampleHeaders(sample, romAddr); @@ -1140,7 +1170,6 @@ void AudioLoad_InitSwapFont(void) { for (i = 0; i < numSfxs; i++) { sfx = &sfxList[i]; - bswapSoundFontSound(sfx); if (sfx->sample != NULL) { SoundFontSample* sample = (SoundFontSample*)BASE_ROM_OFFSET(sfx->sample); @@ -1160,7 +1189,6 @@ void AudioLoad_InitSwapFont(void) { if (instList[i] != NULL) { inst = BASE_ROM_OFFSET(instList[i]); - bswapInstrument(inst); if (inst->normalRangeLo != 0) { sample = (SoundFontSample*)BASE_ROM_OFFSET(inst->lowNotesSound.sample); @@ -1189,19 +1217,12 @@ void AudioLoad_Init(void* heap, size_t heapSize) { void* temp_v0_3; s32 i; u64* heapP; - u8* ctxP; s16* u2974p; D_801755D0 = NULL; gAudioContext.resetTimer = 0; - { - s32 i; - u8* ctxP = (u8*)&gAudioContext; - for (i = sizeof(gAudioContext); i >= 0; i--) { - *ctxP++ = 0; - } - } + memset(&gAudioContext, 0, sizeof(gAudioContext)); switch (osTvType) { case OS_TV_PAL: @@ -1260,41 +1281,59 @@ void AudioLoad_Init(void* heap, size_t heapSize) { gAudioContext.aiBuffers[i] = AudioHeap_AllocZeroed(&gAudioContext.audioInitPool, AIBUF_LEN * sizeof(s16)); } - gAudioContext.sequenceTable = (AudioTable*)gSequenceTable; - gAudioContext.soundFontTable = (AudioTable*)gSoundFontTable; - gAudioContext.sampleBankTable = (AudioTable*)gSampleBankTable; - gAudioContext.sequenceFontTable = gSequenceFontTable; - gAudioContext.numSequences = gAudioContext.sequenceTable->numEntries; + //gAudioContext.sequenceTable = (AudioTable*)gSequenceTable; + //gAudioContext.soundFontTable = (AudioTable*)gSoundFontTable; + //gAudioContext.sampleBankTable = (AudioTable*)gSampleBankTable; + //gAudioContext.sequenceFontTable = gSequenceFontTable; + //gAudioContext.numSequences = gAudioContext.sequenceTable->numEntries; gAudioContext.audioResetSpecIdToLoad = 0; gAudioContext.resetStatus = 1; AudioHeap_ResetStep(); - uintptr_t seqStart = ResourceMgr_LoadFileRaw(_AudioseqSegmentRomStart); - uintptr_t bankStart = ResourceMgr_LoadFileRaw(_AudiobankSegmentRomStart); - uintptr_t tableStart = ResourceMgr_LoadFileRaw(_AudiotableSegmentRomStart); + int seqListSize = 0; + char** seqList = ResourceMgr_ListFiles("audio/sequences*", &seqListSize); - AudioLoad_InitTable(gAudioContext.sequenceTable, seqStart, 0); - AudioLoad_InitTable(gAudioContext.soundFontTable, bankStart, 0); - AudioLoad_InitTable(gAudioContext.sampleBankTable, tableStart, 0); - numFonts = gAudioContext.soundFontTable->numEntries; - gAudioContext.soundFonts = AudioHeap_Alloc(&gAudioContext.audioInitPool, numFonts * sizeof(SoundFont)); + for (size_t i = 0; i < seqListSize; i++) + { + SequenceData sDat = ResourceMgr_LoadSeqByName(seqList[i]); + + char* str = malloc(strlen(seqList[i]) + 1); + strcpy(str, seqList[i]); + + sequenceMap[sDat.seqNumber] = str; + } + + free(seqList); + + int fntListSize = 0; + char** fntList = ResourceMgr_ListFiles("audio/fonts*", &fntListSize); - for (i = 0; i < numFonts; i++) { - AudioLoad_InitSoundFontMeta(i); + for (int i = 0; i < fntListSize; i++) + { + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fntList[i]); + + char* str = malloc(strlen(fntList[i]) + 1); + strcpy(str, fntList[i]); + + fontMap[sf->fntIndex] = str; } - AudioLoad_InitSwapFont(); + numFonts = fntListSize; + + free(fntList); + gAudioContext.soundFonts = AudioHeap_Alloc(&gAudioContext.audioInitPool, numFonts * sizeof(SoundFont)); + if (temp_v0_3 = AudioHeap_Alloc(&gAudioContext.audioInitPool, D_8014A6C4.permanentPoolSize), temp_v0_3 == NULL) { // cast away const from D_8014A6C4 - *((size_t*)&D_8014A6C4.permanentPoolSize) = 0; + // *((u32*)&D_8014A6C4.permanentPoolSize) = 0; } AudioHeap_AllocPoolInit(&gAudioContext.permanentPool, temp_v0_3, D_8014A6C4.permanentPoolSize); gAudioContextInitalized = true; - osSendMesg(gAudioContext.taskStartQueueP, (void*)gAudioContext.totalTaskCnt, OS_MESG_NOBLOCK); + osSendMesg32(gAudioContext.taskStartQueueP, gAudioContext.totalTaskCnt, OS_MESG_NOBLOCK); } void AudioLoad_InitSlowLoads(void) { @@ -1459,11 +1498,6 @@ s32 AudioLoad_SlowLoadSeq(s32 seqId, u8* ramAddr, s8* isDone) { AudioTable* seqTable; size_t size; - if (seqId >= gAudioContext.numSequences) { - *isDone = 0; - return -1; - } - seqId = AudioLoad_GetRealTableIndex(SEQUENCE_TABLE, seqId); seqTable = AudioLoad_GetLoadTable(SEQUENCE_TABLE); slowLoad = &gAudioContext.slowLoads[gAudioContext.slowLoadPos]; @@ -1473,14 +1507,17 @@ s32 AudioLoad_SlowLoadSeq(s32 seqId, u8* ramAddr, s8* isDone) { slowLoad->sample.sampleAddr = NULL; slowLoad->isDone = isDone; - size = seqTable->entries[seqId].size; - size = ALIGN16(size); + + SequenceData sData = ResourceMgr_LoadSeqByName(sequenceMap[seqId]); + char* seqData = sData.seqData; + size = sData.seqDataSize; + slowLoad->curDevAddr = seqData; + slowLoad->medium = sData.medium; + slowLoad->curRamAddr = ramAddr; slowLoad->status = LOAD_STATUS_START; slowLoad->bytesRemaining = size; slowLoad->ramAddr = ramAddr; - slowLoad->curDevAddr = seqTable->entries[seqId].romAddr; - slowLoad->medium = seqTable->entries[seqId].medium; slowLoad->seqOrFontId = seqId; if (slowLoad->medium == MEDIUM_UNK) { @@ -1499,8 +1536,8 @@ void AudioLoad_InitAsyncLoads(void) { } } -AudioAsyncLoad* AudioLoad_StartAsyncLoadUnkMedium(s32 unkMediumParam, uintptr_t devAddr, uintptr_t ramAddr, - size_t size, s32 medium, +AudioAsyncLoad* AudioLoad_StartAsyncLoadUnkMedium(s32 unkMediumParam, uintptr_t devAddr, uintptr_t ramAddr, size_t size, + s32 medium, s32 nChunks, OSMesgQueue* retQueue, s32 retMsg) { AudioAsyncLoad* asyncLoad; @@ -1510,7 +1547,7 @@ AudioAsyncLoad* AudioLoad_StartAsyncLoadUnkMedium(s32 unkMediumParam, uintptr_t return NULL; } - osSendMesg(&gAudioContext.asyncLoadUnkMediumQueue, asyncLoad, OS_MESG_NOBLOCK); + osSendMesgPtr(&gAudioContext.asyncLoadUnkMediumQueue, asyncLoad, OS_MESG_NOBLOCK); asyncLoad->unkMediumParam = unkMediumParam; return asyncLoad; } @@ -1603,7 +1640,6 @@ void AudioLoad_FinishAsyncLoad(AudioAsyncLoad* asyncLoad) { u32 sampleBankId2; RelocInfo relocInfo; - if (1) {} switch (ASYNC_TBLTYPE(retMsg)) { case SEQUENCE_TABLE: AudioLoad_SetSeqLoadStatus(ASYNC_ID(retMsg), ASYNC_STATUS(retMsg)); @@ -1626,8 +1662,7 @@ void AudioLoad_FinishAsyncLoad(AudioAsyncLoad* asyncLoad) { break; } - doneMsg = asyncLoad->retMsg; - if (1) {} + doneMsg.data32 = asyncLoad->retMsg; asyncLoad->status = LOAD_STATUS_WAITING; osSendMesg(asyncLoad->retQueue, doneMsg, OS_MESG_NOBLOCK); } @@ -1691,53 +1726,10 @@ void AudioLoad_AsyncDma(AudioAsyncLoad* asyncLoad, size_t size) { void AudioLoad_AsyncDmaUnkMedium(uintptr_t devAddr, uintptr_t ramAddr, size_t size, s16 arg3) { } -#define RELOC(v, base) (reloc = (uintptr_t)((uintptr_t)(v) + (uintptr_t)(base))) - -void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* mem, RelocInfo* relocInfo) { - // OTRTODO: This is hack to detect whether or not the sample has been relocated. - size_t maxSoundBankSize = 0x3EB2A0; // sample bank 0 is largest size at 0x3EB2A0 - if ((uintptr_t)mem <= maxSoundBankSize) { - // OTRTODO: This can be removed once we have properly byteswapped files on the disk. - assert("mem for sound font bank is too low."); - } - - SoundFontSample* sample; - void* reloc; - - // OTRTODO: Seems precarious to assume the RAM is never <= 0x3EB2A0, but it largely works. - if ((uintptr_t)sound->sample < maxSoundBankSize) { - sample = sound->sample = RELOC(sound->sample, mem); - if (sample->size != 0 && sample->unk_bit25 != 1) { - sample->loop = RELOC(sample->loop, mem); - sample->book = RELOC(sample->book, mem); - - // Resolve the sample medium 2-bit bitfield into a real value based on relocInfo. - switch (sample->medium) { - case 0: - sample->sampleAddr = RELOC(sample->sampleAddr, relocInfo->baseAddr1); - sample->medium = relocInfo->medium1; - break; - case 1: - sample->sampleAddr = RELOC(sample->sampleAddr, relocInfo->baseAddr2); - sample->medium = relocInfo->medium2; - break; - case 2: - case 3: - // Invalid? This leaves sample->medium as MEDIUM_CART and MEDIUM_DISK_DRIVE - // respectively, and the sampleAddr unrelocated. - break; - } - - sample->unk_bit25 = 1; - if (sample->unk_bit26 && (sample->medium != MEDIUM_RAM)) { - gAudioContext.usedSamples[gAudioContext.numUsedSamples++] = sample; - } - } - } +void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* mem, RelocInfo* relocInfo, int fontId) +{ } -#undef RELOC - void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo, s32 async) { AudioPreloadReq* preload; AudioPreloadReq* topPreload; @@ -1864,7 +1856,7 @@ s32 AudioLoad_ProcessSamplePreloads(s32 resetStatus) { if (preload->isFree == false) { sample = preload->sample; - key = sample->sampleAddr + sample->size + sample->medium; + key = (u32)sample->sampleAddr + sample->size + sample->medium; if (key == preload->endAndMediumKey) { // Change storage for sample to the preloaded version. sample->sampleAddr = preload->ramAddr; @@ -1887,12 +1879,12 @@ s32 AudioLoad_ProcessSamplePreloads(s32 resetStatus) { sample = preload->sample; nChunks = (sample->size >> 12) + 1; - key = sample->sampleAddr + sample->size + sample->medium; + key = (u32)sample->sampleAddr + sample->size + sample->medium; if (key != preload->endAndMediumKey) { preload->isFree = true; gAudioContext.preloadSampleStackTop--; } else { - AudioLoad_StartAsyncLoad(sample->sampleAddr, preload->ramAddr, sample->size, sample->medium, + AudioLoad_StartAsyncLoad((u32)sample->sampleAddr, preload->ramAddr, sample->size, sample->medium, nChunks, &gAudioContext.preloadSampleQueue, preload->encodedInfo); break; } @@ -1929,7 +1921,6 @@ s32 AudioLoad_GetSamplesForFont(s32 fontId, SoundFontSample** sampleSet) { for (i = 0; i < numDrums; i++) { Drum* drum = Audio_GetDrum(fontId, i); - if (1) {} if (drum != NULL) { numSamples = AudioLoad_AddToSampleSet(drum->sound.sample, numSamples, sampleSet); } @@ -1955,8 +1946,10 @@ s32 AudioLoad_GetSamplesForFont(s32 fontId, SoundFontSample** sampleSet) { void AudioLoad_AddUsedSample(SoundFontSound* sound) { SoundFontSample* sample = sound->sample; - if ((sample->size != 0) && (sample->unk_bit26) && (sample->medium != MEDIUM_RAM)) { - gAudioContext.usedSamples[gAudioContext.numUsedSamples++] = sample; + if (sample != NULL) { + if ((sample->size != 0) && (sample->unk_bit26) && (sample->medium != MEDIUM_RAM)) { + gAudioContext.usedSamples[gAudioContext.numUsedSamples++] = sample; + } } } @@ -1983,9 +1976,11 @@ void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, RelocInfo* relocInfo gAudioContext.numUsedSamples = 0; - numDrums = gAudioContext.soundFonts[fontId].numDrums; - numInstruments = gAudioContext.soundFonts[fontId].numInstruments; - numSfx = gAudioContext.soundFonts[fontId].numSfx; + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); + + numDrums = sf->numDrums; + numInstruments = sf->numInstruments; + numSfx = sf->numSfx; for (i = 0; i < numInstruments; i++) { instrument = Audio_GetInstrumentInner(fontId, i); @@ -2106,11 +2101,16 @@ void AudioLoad_LoadPermanentSamples(void) { for (i = 0; i < gAudioContext.permanentPool.count; i++) { RelocInfo relocInfo; - if (gAudioContext.permanentCache[i].tableType == FONT_TABLE) { + if (gAudioContext.permanentCache[i].tableType == FONT_TABLE) + { fontId = AudioLoad_GetRealTableIndex(FONT_TABLE, gAudioContext.permanentCache[i].id); - relocInfo.sampleBankId1 = gAudioContext.soundFonts[fontId].sampleBankId1; - relocInfo.sampleBankId2 = gAudioContext.soundFonts[fontId].sampleBankId2; + //fontId = gAudioContext.permanentCache[i].id; + + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); + relocInfo.sampleBankId1 = sf->sampleBankId1; + relocInfo.sampleBankId2 = sf->sampleBankId2; + /* if (relocInfo.sampleBankId1 != 0xFF) { relocInfo.sampleBankId1 = AudioLoad_GetRealTableIndex(SAMPLE_TABLE, relocInfo.sampleBankId1); relocInfo.medium1 = sampleBankTable->entries[relocInfo.sampleBankId1].medium; @@ -2120,6 +2120,8 @@ void AudioLoad_LoadPermanentSamples(void) { relocInfo.sampleBankId2 = AudioLoad_GetRealTableIndex(SAMPLE_TABLE, relocInfo.sampleBankId2); relocInfo.medium2 = sampleBankTable->entries[relocInfo.sampleBankId2].medium; } + */ + AudioLoad_PreloadSamplesForFont(fontId, false, &relocInfo); } }