diff --git a/soh/soh/Enhancements/randomizer/context.cpp b/soh/soh/Enhancements/randomizer/context.cpp index 67502ff5e..c9cc8e746 100644 --- a/soh/soh/Enhancements/randomizer/context.cpp +++ b/soh/soh/Enhancements/randomizer/context.cpp @@ -349,11 +349,11 @@ void Context::SetSpoilerLoaded(const bool spoilerLoaded) { void Context::AddRecievedArchipelagoItem(const RandomizerGet item) { mAPrecieveQueue.emplace(item); std::string logMessage = "[LOG] Item Pushed: " + item; - ArchipelagoConsole_SendMessage(logMessage.c_str()); + ArchipelagoConsole_SendMessage(logMessage.c_str(), true); } GetItemEntry Context::GetArchipelagoGIEntry() { - ArchipelagoConsole_SendMessage("[LOG] Trying to get Item Entry"); + ArchipelagoConsole_SendMessage("[LOG] Trying to get Item Entry", true); 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/Network/Archipelago/Archipelago.cpp b/soh/soh/Network/Archipelago/Archipelago.cpp index e4c80b7a9..775944fe3 100644 --- a/soh/soh/Network/Archipelago/Archipelago.cpp +++ b/soh/soh/Network/Archipelago/Archipelago.cpp @@ -25,18 +25,14 @@ extern PlayState* gPlayState; } ArchipelagoClient::ArchipelagoClient() { - std::string uuid = ap_get_uuid("uuid"); + uuid = ap_get_uuid("uuid"); gameWon = false; - - namespace apc = AP_Client_consts; - CVarSetInteger(CVAR_REMOTE_ARCHIPELAGO("Connected"), 0); - bool itemQueued = false; + itemQueued = false; // call poll every frame COND_HOOK(GameInteractor::OnGameFrameUpdate, true, [](){ArchipelagoClient::GetInstance().Poll();}); COND_HOOK(GameInteractor::OnLoadGame, true, [](int32_t file_id){ArchipelagoClient::GetInstance().GameLoaded();}); - } ArchipelagoClient& ArchipelagoClient::GetInstance() { @@ -62,7 +58,7 @@ bool ArchipelagoClient::StartClient() { }); apClient->set_slot_connected_handler([&](const nlohmann::json data) { - ArchipelagoConsole_SendMessage("[LOG] Connected.", false); + ArchipelagoConsole_SendMessage("[LOG] Connected.", true); ArchipelagoClient::StartLocationScouts(); slotData = data; @@ -105,10 +101,10 @@ bool ArchipelagoClient::StartClient() { const std::string playerName = apItem.playerName; const std::string locationName = apItem.locationName; std::string logMessage = "[LOG] Location scouted: " + itemName + " for " + playerName + " in location " + locationName; - ArchipelagoConsole_SendMessage(logMessage.c_str()); + ArchipelagoConsole_SendMessage(logMessage.c_str(), true); } - ArchipelagoConsole_SendMessage("[LOG] Scouting finished."); + ArchipelagoConsole_SendMessage("[LOG] Scouting finished.", true); }); // todo maybe move these functions to a lambda, since they don't have to be static anymore apClient->set_location_checked_handler([&](const std::list locations) { @@ -117,6 +113,11 @@ bool ArchipelagoClient::StartClient() { } }); + apClient->set_print_json_handler([&](const std::list& nodes) { + std::string text = apClient->render_json(nodes, APClient::RenderFormat::TEXT); + ArchipelagoConsole_SendMessage(text.c_str(), false); + }); + return true; } @@ -131,7 +132,7 @@ void ArchipelagoClient::GameLoaded() { return; } - ArchipelagoConsole_SendMessage("[LOG] Synching Items and Locations."); + ArchipelagoConsole_SendMessage("[LOG] Synching Items and Locations.", true); SynchItems(); SynchSentLocations(); @@ -153,7 +154,7 @@ void ArchipelagoClient::StartLocationScouts() { void ArchipelagoClient::SynchItems() { // Send a Synch request to get any items we may have missed - ArchipelagoConsole_SendMessage("[LOG] Sending synch request"); + ArchipelagoConsole_SendMessage("[LOG] Sending synch request", true); apClient->Sync(); } @@ -168,7 +169,7 @@ void ArchipelagoClient::SynchSentLocations() { } } std::string locationLog = "[LOG] Synching " + std::to_string(checkedLocations.size())+ " checks already found in game"; - ArchipelagoConsole_SendMessage(locationLog.c_str()); + ArchipelagoConsole_SendMessage(locationLog.c_str(), true); apClient->LocationChecks(checkedLocations); } @@ -198,7 +199,7 @@ void ArchipelagoClient::CheckLocation(RandomizerCheck sohCheckId) { int64_t apItemId = apClient->get_location_id(std::string(apName)); std::string logMessage = "[LOG] Checked: " + apName + "(" + std::to_string(apItemId) + "), sending to AP server"; - ArchipelagoConsole_SendMessage(logMessage.c_str()); + ArchipelagoConsole_SendMessage(logMessage.c_str(), true); if(!IsConnected()) { return; @@ -214,7 +215,7 @@ void ArchipelagoClient::OnItemReceived(const ApItem apItem) { } std::string logMessage = "[Log] Recieved " + apItem.itemName; - ArchipelagoConsole_SendMessage(logMessage.c_str()); + ArchipelagoConsole_SendMessage(logMessage.c_str(), true); // add item to the queue recieveQueue.push(apItem); @@ -224,12 +225,12 @@ void ArchipelagoClient::QueueItem(const ApItem item) { if(item.index < gSaveContext.ship.quest.data.archipelago.lastReceivedItemIndex) { // Skip queueing any items we already have std::string logMessage = "[Log] Skipping giving " + item.itemName + ". We recieved this previously."; - ArchipelagoConsole_SendMessage(logMessage.c_str()); + ArchipelagoConsole_SendMessage(logMessage.c_str(), true); return; } std::string logMessage = "[Log] Giving " + item.itemName; - ArchipelagoConsole_SendMessage(logMessage.c_str()); + ArchipelagoConsole_SendMessage(logMessage.c_str(), true); const RandomizerGet RG = Rando::StaticData::itemNameToEnum[item.itemName]; if(RG == RG_NONE) { return; @@ -390,6 +391,8 @@ void InitArchipelagoData(bool isDebug) { } void RegisterArchipelago() { + CVarSetInteger(CVAR_REMOTE_ARCHIPELAGO("Connected"), 0); + COND_HOOK(GameInteractor::OnRandomizerItemGivenHooks, IS_ARCHIPELAGO, [](uint32_t rc, GetItemEntry gi, uint8_t isGiSkipped) { if (rc == RC_ARCHIPELAGO_RECIEVED_ITEM) { diff --git a/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.cpp b/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.cpp index 75e359839..af5bf1ce8 100644 --- a/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.cpp +++ b/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.cpp @@ -10,15 +10,16 @@ bool autoScroll = true; using namespace UIWidgets; void ArchipelagoConsole_SendMessage(const char* fmt, bool debugMessage, ...) { - if (!debugMessage || CVarGetInteger(CVAR_REMOTE_ARCHIPELAGO("DebugEnabled"), 0)) { - char buf[1024]; - va_list args; - va_start(args, fmt); - vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args); - buf[IM_ARRAYSIZE(buf) - 1] = 0; - va_end(args); - Items.push_back(strdup(buf)); + if (debugMessage && CVarGetInteger(CVAR_REMOTE_ARCHIPELAGO("DebugEnabled"), 0) == 0) { + return; } + char buf[1024]; + va_list args; + va_start(args, fmt); + vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args); + buf[IM_ARRAYSIZE(buf) - 1] = 0; + va_end(args); + Items.push_back(strdup(buf)); } void ArchipelagoConsoleWindow::DrawElement() { diff --git a/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.h b/soh/soh/Network/Archipelago/ArchipelagoConsoleWindow.h index 9856969df..46cc3332e 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 ArchipelagoConsole_SendMessage(const char* fmt, bool debugMessage = true, ...); +void ArchipelagoConsole_SendMessage(const char* fmt, bool debugMessage = false, ...); #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 7f0d92a71..162045a98 100644 --- a/soh/soh/Network/Archipelago/ArchipelagoSettingsWindow.cpp +++ b/soh/soh/Network/Archipelago/ArchipelagoSettingsWindow.cpp @@ -39,7 +39,7 @@ void ArchipelagoSettingsWindow::DrawElement() { if (UIWidgets::Button("Connect", UIWidgets::ButtonOptions().Color(THEME_COLOR).Size(ImVec2(0.0, 0.0)))) { bool success = AP_client.StartClient(); - ArchipelagoConsole_SendMessage("[LOG] Trying to connect...", false); + ArchipelagoConsole_SendMessage("[LOG] Trying to connect...", true); } ImGui::SameLine();