diff options
| author | louist103 <35883445+louist103@users.noreply.github.com> | 2025-08-28 15:06:43 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-28 15:06:43 -0400 |
| commit | 78b824b99bb6d82609e1ec171b593b26ff02b3aa (patch) | |
| tree | c5118bf5754d4f2c47117cb9be1555d6ee9f329b | |
| parent | 9e3d6e9c3f7fd598ef5f84d2972740a9a82db7b4 (diff) | |
Use registration system instead of polling for dropped files (#1182)
* Support file registration
* Format
* Format
* Update LUS
* Update BenPort.cpp
| m--------- | libultraship | 0 | ||||
| -rw-r--r-- | mm/2s2h/BenPort.cpp | 39 | ||||
| -rw-r--r-- | mm/2s2h/GameInteractor/GameInteractor_HookTable.h | 2 | ||||
| -rw-r--r-- | mm/2s2h/PresetManager/PresetManager.cpp | 4 | ||||
| -rw-r--r-- | mm/2s2h/Rando/Rando.cpp | 4 | ||||
| -rw-r--r-- | mm/2s2h/Rando/Spoiler/HandleFileDropped.cpp | 2 | ||||
| -rw-r--r-- | mm/2s2h/Rando/Spoiler/Spoiler.h | 2 | ||||
| -rw-r--r-- | mm/2s2h/SaveManager/BinarySaveConverter.cpp | 2 | ||||
| -rw-r--r-- | mm/2s2h/SaveManager/SaveManager.cpp | 2 | ||||
| -rw-r--r-- | mm/2s2h/SaveManager/SaveManager.h | 4 |
10 files changed, 15 insertions, 46 deletions
diff --git a/libultraship b/libultraship -Subproject 7f737f8be9580980f5a1fe7784d6e1045f0309d +Subproject 09dfab5fb2a9a047a6e268dc9db2daad9b2ce5f diff --git a/mm/2s2h/BenPort.cpp b/mm/2s2h/BenPort.cpp index 2b34605a4..e543b1230 100644 --- a/mm/2s2h/BenPort.cpp +++ b/mm/2s2h/BenPort.cpp @@ -471,33 +471,6 @@ extern "C" void OTRExtScanner() { } } -void Ben_ProcessDroppedFiles(const std::string& filePath) { - SPDLOG_INFO("Processing dropped file: {}", filePath); - - bool handled = false; - - if (!handled) { - handled = SaveManager_HandleFileDropped(filePath); - } - - if (!handled) { - handled = BinarySaveConverter_HandleFileDropped(filePath); - } - - if (!handled) { - handled = Rando::Spoiler::HandleFileDropped(filePath); - } - - if (!handled) { - handled = PresetManager_HandleFileDropped(filePath); - } - - if (!handled) { - auto gui = Ship::Context::GetInstance()->GetWindow()->GetGui(); - gui->GetGameOverlay()->TextDrawNotification(30.0f, true, "Unsupported file dropped, ignoring"); - } -} - typedef struct { uint16_t major; uint16_t minor; @@ -743,8 +716,6 @@ extern "C" void InitOTR() { // usually set once(?) in currently stubbed out areas of code. gIrqMgrRetraceTime = Ship_Random(700000, 850000); - GameInteractor::Instance->RegisterGameHook<GameInteractor::OnFileDropped>(Ben_ProcessDroppedFiles); - time_t now = time(NULL); tm* tm_now = localtime(&now); if (tm_now->tm_mon == 11 && tm_now->tm_mday >= 24 && tm_now->tm_mday <= 25) { @@ -765,6 +736,8 @@ extern "C" void InitOTR() { #endif std::shared_ptr<Ship::Config> conf = OTRGlobals::Instance->context->GetConfig(); + Ship::Context::GetInstance()->GetFileDropMgr()->RegisterDropHandler(BinarySaveConverter_HandleFileDropped); + Ship::Context::GetInstance()->GetFileDropMgr()->RegisterDropHandler(SaveManager_HandleFileDropped); } extern "C" void SaveManager_ThreadPoolWait() { @@ -916,14 +889,6 @@ extern "C" void Graph_StartFrame() { } } #endif - auto dropMgr = Ship::Context::GetInstance()->GetFileDropMgr(); - if (dropMgr->FileDropped()) { - std::string filePath = dropMgr->GetDroppedFile(); - if (!filePath.empty()) { - GameInteractor::Instance->ExecuteHooks<GameInteractor::OnFileDropped>(filePath); - } - dropMgr->ClearDroppedFile(); - } } void RunCommands(Gfx* Commands, const std::vector<std::unordered_map<Mtx*, MtxF>>& mtx_replacements) { diff --git a/mm/2s2h/GameInteractor/GameInteractor_HookTable.h b/mm/2s2h/GameInteractor/GameInteractor_HookTable.h index 7e786757e..745fc08d0 100644 --- a/mm/2s2h/GameInteractor/GameInteractor_HookTable.h +++ b/mm/2s2h/GameInteractor/GameInteractor_HookTable.h @@ -1,5 +1,3 @@ -DEFINE_HOOK(OnFileDropped, (const std::string& path)) - DEFINE_HOOK(OnGameStateMainStart, ()) DEFINE_HOOK(OnGameStateMainFinish, ()) DEFINE_HOOK(OnGameStateDrawFinish, ()) diff --git a/mm/2s2h/PresetManager/PresetManager.cpp b/mm/2s2h/PresetManager/PresetManager.cpp index cf8ea54aa..270eedd66 100644 --- a/mm/2s2h/PresetManager/PresetManager.cpp +++ b/mm/2s2h/PresetManager/PresetManager.cpp @@ -6,6 +6,7 @@ #include "2s2h/BenPort.h" #include "2s2h/BenGui/UIWidgets.hpp" #include "2s2h/BenGui/Notification.h" +#include "FileDropMgr.h" std::unordered_map<std::string, std::string> tagMap = { { "gEventLog", "Developer Tools" }, @@ -385,7 +386,7 @@ void PresetManager_CreatePreset(std::string presetName) { } catch (...) { Notification::Emit({ .suffix = "Failed to create preset" }); } } -bool PresetManager_HandleFileDropped(const std::string& filePath) { +bool PresetManager_HandleFileDropped(char* filePath) { try { std::ifstream fileStream(filePath); @@ -525,6 +526,7 @@ void PresetManager_Draw() { } void PresetManager_RegisterHooks() { + Ship::Context::GetInstance()->GetFileDropMgr()->RegisterDropHandler(PresetManager_HandleFileDropped); PresetManager_RefreshPresets(); } diff --git a/mm/2s2h/Rando/Rando.cpp b/mm/2s2h/Rando/Rando.cpp index 296dff207..723ee0d4f 100644 --- a/mm/2s2h/Rando/Rando.cpp +++ b/mm/2s2h/Rando/Rando.cpp @@ -5,6 +5,8 @@ #include "Rando/Spoiler/Spoiler.h" #include "Rando/CheckTracker/CheckTracker.h" #include "2s2h/ShipInit.hpp" +#include "FileDropMgr.h" +#include "Context.h" // When a save is loaded, we want to unregister all hooks and re-register them if it's a rando save void OnSaveLoadHandler(s16 fileNum) { @@ -22,6 +24,8 @@ void Rando::Init() { Rando::MiscBehavior::Init(); Rando::ActorBehavior::Init(); Rando::CheckTracker::Init(); + Ship::Context::GetInstance()->GetFileDropMgr()->RegisterDropHandler(Rando::Spoiler::HandleFileDropped); + GameInteractor::Instance->RegisterGameHook<GameInteractor::OnSaveLoad>(OnSaveLoadHandler); } diff --git a/mm/2s2h/Rando/Spoiler/HandleFileDropped.cpp b/mm/2s2h/Rando/Spoiler/HandleFileDropped.cpp index b59826760..9cdc163d7 100644 --- a/mm/2s2h/Rando/Spoiler/HandleFileDropped.cpp +++ b/mm/2s2h/Rando/Spoiler/HandleFileDropped.cpp @@ -11,7 +11,7 @@ extern "C" { #include "sfx.h" } -bool Rando::Spoiler::HandleFileDropped(const std::string& filePath) { +bool Rando::Spoiler::HandleFileDropped(char* filePath) { try { std::ifstream fileStream(filePath); diff --git a/mm/2s2h/Rando/Spoiler/Spoiler.h b/mm/2s2h/Rando/Spoiler/Spoiler.h index 08b0c4272..4cb145796 100644 --- a/mm/2s2h/Rando/Spoiler/Spoiler.h +++ b/mm/2s2h/Rando/Spoiler/Spoiler.h @@ -15,7 +15,7 @@ nlohmann::json GenerateFromSaveContext(); void SaveToFile(const std::string& fileName, nlohmann::json spoiler); nlohmann::json LoadFromFile(const std::string& filePath); void ApplyToSaveContext(nlohmann::json spoiler); -bool HandleFileDropped(const std::string& path); +bool HandleFileDropped(char* path); } // namespace Spoiler diff --git a/mm/2s2h/SaveManager/BinarySaveConverter.cpp b/mm/2s2h/SaveManager/BinarySaveConverter.cpp index 9b6056759..cb926d6df 100644 --- a/mm/2s2h/SaveManager/BinarySaveConverter.cpp +++ b/mm/2s2h/SaveManager/BinarySaveConverter.cpp @@ -640,7 +640,7 @@ void BinarySaveConverter_ReadBufferToSave(Legacy_SaveContext* saveContext, std:: saveContext->save.saveInfo.checksum = 1; } -bool BinarySaveConverter_HandleFileDropped(const std::string& filePath) { +bool BinarySaveConverter_HandleFileDropped(char* filePath) { try { std::ifstream fileStream(filePath, std::ios::binary | std::ios::ate); diff --git a/mm/2s2h/SaveManager/SaveManager.cpp b/mm/2s2h/SaveManager/SaveManager.cpp index 15b35e88a..012a72bf0 100644 --- a/mm/2s2h/SaveManager/SaveManager.cpp +++ b/mm/2s2h/SaveManager/SaveManager.cpp @@ -242,7 +242,7 @@ std::string SaveManager_GetFileNameFromFlashSave(FlashSave flashSave) { return "file" + std::to_string(fileNum) + (isBackup ? "backup" : "") + ".json"; } -bool SaveManager_HandleFileDropped(const std::string& filePath) { +bool SaveManager_HandleFileDropped(char* filePath) { try { std::ifstream fileStream(filePath); diff --git a/mm/2s2h/SaveManager/SaveManager.h b/mm/2s2h/SaveManager/SaveManager.h index f9560ed0a..2c82ca4b9 100644 --- a/mm/2s2h/SaveManager/SaveManager.h +++ b/mm/2s2h/SaveManager/SaveManager.h @@ -7,8 +7,8 @@ #include <filesystem> #include <nlohmann/json.hpp> std::string SaveManager_GetFileName(int fileNum, bool isBackup = false); -bool SaveManager_HandleFileDropped(const std::string& filePath); -bool BinarySaveConverter_HandleFileDropped(const std::string& filePath); +bool SaveManager_HandleFileDropped(char* filePath); +bool BinarySaveConverter_HandleFileDropped(char* filePath); int SaveManager_GetOpenFileSlot(); void SaveManager_WriteSaveFile(const std::filesystem::path& fileName, nlohmann::json j); #else |
