diff --git a/libultraship/libultraship/Cvar.cpp b/libultraship/libultraship/Cvar.cpp index 891ee73af..55fc70793 100644 --- a/libultraship/libultraship/Cvar.cpp +++ b/libultraship/libultraship/Cvar.cpp @@ -64,7 +64,7 @@ void CVar_SetFloat(const char* name, float value) { cvar->value.valueFloat = value; } -void CVar_SetString(const char* name, const char* value) { +extern "C" void CVar_SetString(const char* name, const char* value) { auto& cvar = cvars[name]; if (!cvar) { cvar = std::make_unique(); diff --git a/libultraship/libultraship/Cvar.h b/libultraship/libultraship/Cvar.h index e16f4469f..f9583ef0c 100644 --- a/libultraship/libultraship/Cvar.h +++ b/libultraship/libultraship/Cvar.h @@ -27,6 +27,7 @@ s32 CVar_GetS32(const char* name, s32 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_SetString(const char* name, const char* value); void CVar_RegisterS32(const char* name, s32 defaultValue); void CVar_RegisterFloat(const char* name, float defaultValue); @@ -44,6 +45,5 @@ void CVar_RegisterString(const char* name, const char* defaultValue); extern std::map, std::less<>> cvars; void CVar_SetFloat(const char* name, float value); -void CVar_SetString(const char* name, const char* value); #endif #endif diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp index 922646a1d..c99ee21be 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_dxgi.cpp @@ -27,6 +27,7 @@ #include "gfx_screen_config.h" #include "gfx_pc.h" #include "../../SohImGuiImpl.h" +#include "../../Cvar.h" #define DECLARE_GFX_DXGI_FUNCTIONS #include "gfx_dxgi.h" @@ -271,7 +272,8 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par case WM_DROPFILES: char fileName[256]; DragQueryFileA((HDROP)w_param, 0, fileName, 256); - LoadItemLocations(fileName); + CVar_SetString("gDroppedFile", fileName); + CVar_SetS32("gDroppedNewSpoilerFile", 1); break; case WM_SYSKEYDOWN: if ((w_param == VK_RETURN) && ((l_param & 1 << 30) == 0)) { diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp index 49300911f..637c1937c 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp @@ -20,6 +20,7 @@ #endif #include "../../SohImGuiImpl.h" +#include "../../Cvar.h" #include "gfx_window_manager_api.h" #include "gfx_screen_config.h" @@ -228,8 +229,6 @@ static void gfx_sdl_onkeyup(int scancode) { } } -extern "C" void LoadItemLocations(const char* spoilerFileName); - static void gfx_sdl_handle_events(void) { SDL_Event event; while (SDL_PollEvent(&event)) { @@ -253,9 +252,8 @@ static void gfx_sdl_handle_events(void) { } break; case SDL_DROPFILE: - #ifndef __linux__ - LoadItemLocations(event.drop.file); - #endif + CVar_SetString("gDroppedFile", event.drop.file); + CVar_SetS32("gDroppedNewSpoilerFile", 1); break; case SDL_QUIT: SDL_Quit(); // bandaid fix for linux window closing issue diff --git a/soh/soh/Enhancements/randomizer.cpp b/soh/soh/Enhancements/randomizer.cpp index 15711a629..c6f414811 100644 --- a/soh/soh/Enhancements/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer.cpp @@ -8,6 +8,7 @@ #include #include #include +#include using json = nlohmann::json; @@ -779,6 +780,8 @@ void Randomizer::ParseItemLocations(const char* spoilerFileName) { if (success) { CVar_SetS32("gRandomizer", 1); + CVar_SetS32("gDroppedNewSpoilerFile", 0); + Game::SaveSettings(); } } diff --git a/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index 1825945f0..c0317a118 100644 --- a/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -66,7 +66,13 @@ void FileChoose_InitModeUpdate(GameState* thisx) { this->configMode = CM_FADE_IN_START; this->nextTitleLabel = FS_TITLE_OPEN_FILE; osSyncPrintf("Sram Start─Load 》》》》》 "); - CVar_SetS32("gRandomizer", 0); + + if (strcmp(CVar_GetString("gDroppedFile", ""), "") != 0 && CVar_GetS32("gRandomizer", 0) != 0) { + LoadItemLocations(CVar_GetString("gDroppedFile", "")); + } else { + CVar_SetS32("gRandomizer", 0); + } + Sram_VerifyAndLoadAllSaves(this, &this->sramCtx); osSyncPrintf("終了!!!\n"); } @@ -233,6 +239,9 @@ void FileChoose_UpdateMainMenu(GameState* thisx) { SramContext* sramCtx = &this->sramCtx; Input* input = &this->state.input[0]; bool dpad = CVar_GetS32("gDpadPauseName", 0); + if (strcmp(CVar_GetString("gDroppedFile", ""), "") != 0 && CVar_GetS32("gDroppedNewSpoilerFile", 0) != 0) { + LoadItemLocations(CVar_GetString("gDroppedFile", "")); + } if (CHECK_BTN_ALL(input->press.button, BTN_START) || CHECK_BTN_ALL(input->press.button, BTN_A)) { if (this->buttonIndex <= FS_BTN_MAIN_FILE_3) {