From 1bf399658c979933a914d86feffd87e2a8af68c1 Mon Sep 17 00:00:00 2001 From: aMannus Date: Mon, 19 May 2025 09:55:01 +0200 Subject: [PATCH] Replace archi SPD instances with built in console --- soh/soh/Enhancements/randomizer/context.cpp | 7 +++---- soh/soh/Enhancements/randomizer/hook_handlers.cpp | 7 +++---- soh/soh/Enhancements/randomizer/randomizerTypes.h | 1 - soh/soh/Enhancements/randomizer/settings.cpp | 7 ++++--- soh/soh/Network/Archipelago/Archipelago.cpp | 13 ++++++++----- .../Archipelago/ArchipelagoConsoleWindow.cpp | 4 ++-- .../Network/Archipelago/ArchipelagoConsoleWindow.h | 2 +- .../Archipelago/ArchipelagoSettingsWindow.cpp | 2 +- 8 files changed, 22 insertions(+), 21 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/context.cpp b/soh/soh/Enhancements/randomizer/context.cpp index 72271c394..7271d084b 100644 --- a/soh/soh/Enhancements/randomizer/context.cpp +++ b/soh/soh/Enhancements/randomizer/context.cpp @@ -348,13 +348,12 @@ void Context::SetSpoilerLoaded(const bool spoilerLoaded) { void Context::AddRecievedArchipelagoItem(const std::string& ap_item_id) { mAPrecieveQueue.emplace(ap_item_id); - SPDLOG_TRACE("Item Pushed {}", ap_item_id); - AddToArchipelagoConsole("Item Pushed"); + std::string logMessage = "[LOG] Item Pushed: " + ap_item_id; + ArchipelagoConsole_SendMessage(logMessage.c_str()); } GetItemEntry Context::GetArchipelagoGIEntry() { - SPDLOG_TRACE("Trying to get Item Entry"); - AddToArchipelagoConsole("Trying to get Item Entry"); + ArchipelagoConsole_SendMessage("[LOG] Trying to get Item Entry"); if(mAPrecieveQueue.empty()) { // something must have gone wrong here, just give a rupee return ItemTableManager::Instance->RetrieveItemEntry(MOD_NONE, GI_HEART); diff --git a/soh/soh/Enhancements/randomizer/hook_handlers.cpp b/soh/soh/Enhancements/randomizer/hook_handlers.cpp index 39776d6e5..1915857c2 100644 --- a/soh/soh/Enhancements/randomizer/hook_handlers.cpp +++ b/soh/soh/Enhancements/randomizer/hook_handlers.cpp @@ -17,6 +17,7 @@ #include "soh/SaveManager.h" #include "soh/Enhancements/randomizer/ShuffleFairies.h" #include "soh/Network/Archipelago/Archipelago.h" +#include "soh/Network/Archipelago/ArchipelagoConsoleWindow.h" extern "C" { #include "macros.h" @@ -223,7 +224,8 @@ static RandomizerCheck randomizerQueuedCheck = RC_UNKNOWN_CHECK; static GetItemEntry randomizerQueuedItemEntry = GET_ITEM_NONE; void ArchipelagoOnRecieveItem(const std::string& ap_item_name) { - SPDLOG_TRACE("Recieve item handler called! {}", ap_item_name); + std::string logMessage = "[LOG] Receive item handler called: " + ap_item_name; + ArchipelagoConsole_SendMessage(logMessage.c_str()); randomizerQueuedChecks.push(RC_ARCHIPELAGO_RECIEVED_ITEM); Rando::Context::GetInstance()->AddRecievedArchipelagoItem(ap_item_name); } @@ -314,7 +316,6 @@ void RandomizerOnPlayerUpdateForRCQueueHandler() { GetItemID vanillaItem = (GetItemID)Rando::StaticData::RetrieveItem(vanillaRandomizerGet).GetItemID(); getItemEntry = Rando::Context::GetInstance()->GetFinalGIEntry(rc, true, (GetItemID)vanillaRandomizerGet); } - SPDLOG_TRACE("RC found!"); if (loc->HasObtained()) { SPDLOG_INFO("RC {} already obtained, skipping", static_cast(rc)); @@ -373,8 +374,6 @@ void RandomizerOnItemReceiveHandler(GetItemEntry receivedItemEntry) { if (randomizerQueuedCheck == RC_UNKNOWN_CHECK) return; - SPDLOG_TRACE("Dropped into recieve handler!"); - auto loc = Rando::Context::GetInstance()->GetItemLocation(randomizerQueuedCheck); if (randomizerQueuedItemEntry.modIndex == receivedItemEntry.modIndex && randomizerQueuedItemEntry.itemId == receivedItemEntry.itemId) { diff --git a/soh/soh/Enhancements/randomizer/randomizerTypes.h b/soh/soh/Enhancements/randomizer/randomizerTypes.h index 46866bb8a..5b16ea8b8 100644 --- a/soh/soh/Enhancements/randomizer/randomizerTypes.h +++ b/soh/soh/Enhancements/randomizer/randomizerTypes.h @@ -14,7 +14,6 @@ typedef enum { MOD_NONE, MOD_RANDOMIZER, - MOD_ARCHIPELAGO // no actually used yet i think } ModIndex; typedef enum { TABLE_VANILLA = MOD_NONE, diff --git a/soh/soh/Enhancements/randomizer/settings.cpp b/soh/soh/Enhancements/randomizer/settings.cpp index dab246f8c..e3433e5e2 100644 --- a/soh/soh/Enhancements/randomizer/settings.cpp +++ b/soh/soh/Enhancements/randomizer/settings.cpp @@ -4,12 +4,12 @@ #include "soh/OTRGlobals.h" -#include - #include #include "consolevariablebridge.h" +#include "soh/Network/Archipelago/ArchipelagoConsoleWindow.h" + namespace Rando { std::shared_ptr Settings::mInstance; @@ -2968,7 +2968,8 @@ void Settings::ParseArchipelago(const std::map& slot_data) { const std::string& setting_name = std::string(StaticData::APsettingToHoSsetting[APname]); const RandomizerSettingKey index = StaticData::optionNameToEnum[setting_name]; mContext->GetOption(index).Set(value); - SPDLOG_INFO("Parsed Setting {}: ({}, {})", APname, (int)index, value); + std::string logMessage = "[LOG] Parsed Setting " + APname + ": (" + std::to_string((int)index) + ", " + std::to_string(value) + ")"; + ArchipelagoConsole_SendMessage(logMessage.c_str()); } // maybe we have to set a couple of settings manually, if ap doesn't set them diff --git a/soh/soh/Network/Archipelago/Archipelago.cpp b/soh/soh/Network/Archipelago/Archipelago.cpp index 66119ebcc..85da9b46b 100644 --- a/soh/soh/Network/Archipelago/Archipelago.cpp +++ b/soh/soh/Network/Archipelago/Archipelago.cpp @@ -5,9 +5,9 @@ #include #include -#include #include +#include "soh/Network/Archipelago/ArchipelagoConsoleWindow.h" #include "soh/Enhancements/randomizer/randomizerTypes.h" #include "soh/Enhancements/randomizer/static_data.h" #include "soh/Enhancements/game-interactor/GameInteractor.h" @@ -67,7 +67,8 @@ bool ArchipelagoClient::start_client() { const std::string itemName = apItem.itemName; const std::string playerName = apItem.playerName; const std::string locationName = apItem.locationName; - SPDLOG_TRACE("Location scouted: {} for {} in location {}", itemName, playerName, locationName); + std::string logMessage = "[LOG] Location scouted: " + itemName + " for " + playerName + " in location " + locationName; + ArchipelagoConsole_SendMessage(logMessage.c_str()); } }); // todo maybe move these functions to a lambda, since they don't have to be static anymore @@ -108,7 +109,8 @@ void ArchipelagoClient::check_location(RandomizerCheck SoH_check_id) { return; } int64_t ap_item_id = apclient->get_location_id(std::string(ap_name)); - SPDLOG_TRACE("Checked: {}({}), sending to AP server", ap_name, ap_item_id); + std::string logMessage = "[LOG] Checked: " + ap_name + "(" + std::to_string(ap_item_id) + "), sending to AP server"; + ArchipelagoConsole_SendMessage(logMessage.c_str()); // currently not sending, because i only get so many real chances if(!isConnected()) { @@ -127,7 +129,7 @@ void ArchipelagoClient::removeItemRecievedCallback(std::functionget_item_name(recieved_item_id, AP_Client_consts::AP_GAME_NAME); ArchipelagoClient& ap_client = ArchipelagoClient::getInstance(); if(ap_client.ItemRecievedCallback) { - SPDLOG_TRACE("item recieved: {}, notify: {}", item_name, notify_player); + std::string logMessage = "[LOG] Item recieved: " + item_name + ". Notify: " + std::to_string(notify_player); + ArchipelagoConsole_SendMessage(logMessage.c_str()); ap_client.ItemRecievedCallback.operator()(item_name); // somehow passing it through the itemname breaks it???? } } diff --git a/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.cpp b/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.cpp index 1e99e603c..6861cd780 100644 --- a/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.cpp +++ b/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.cpp @@ -7,7 +7,7 @@ ImVector Items; bool autoScroll = true; bool scrollToBottom = false; -void AddToArchipelagoConsole(const char* fmt, ...) IM_FMTARGS(2) { +void ArchipelagoConsole_SendMessage(const char* fmt, ...) IM_FMTARGS(2) { char buf[1024]; va_list args; va_start(args, fmt); @@ -22,7 +22,7 @@ void ArchipelagoConsoleWindow::DrawElement() { const float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing(); if (ImGui::Button("Add line to log")) { - AddToArchipelagoConsole("Hello world"); + ArchipelagoConsole_SendMessage("Hello World"); } if (ImGui::BeginChild("ScrollingRegion", ImVec2(0, 400), false, diff --git a/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.h b/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.h index c75a8bf3c..602dee2db 100644 --- a/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.h +++ b/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.h @@ -15,6 +15,6 @@ class ArchipelagoConsoleWindow final : public Ship::GuiWindow { void UpdateElement() override {}; }; -void AddToArchipelagoConsole(const char* fmt, ...); +void ArchipelagoConsole_SendMessage(const char* fmt, ...); #endif // ARCHIPELAGO_CONSOLE_WINDOW_H \ No newline at end of file diff --git a/soh/soh/Network/Archipelago/ArchipelagoSettingsWindow.cpp b/soh/soh/Network/Archipelago/ArchipelagoSettingsWindow.cpp index e1f8d4819..df9c7cd5d 100644 --- a/soh/soh/Network/Archipelago/ArchipelagoSettingsWindow.cpp +++ b/soh/soh/Network/Archipelago/ArchipelagoSettingsWindow.cpp @@ -15,7 +15,7 @@ void ArchipelagoSettingsWindow::DrawElement() { if (ImGui::Button("Connect")) { bool success = AP_client.start_client(); - AddToArchipelagoConsole("Trying to connect..."); + ArchipelagoConsole_SendMessage("[LOG] Trying to connect..."); } ImGui::SameLine();