From 929e16bd40e9e28474deabc90eeafd884c20100c Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Mon, 27 Oct 2025 01:20:05 -0700 Subject: [PATCH] debugging features (lookup, metrics, stronger checks on rollloot) --- .../SlashCommands/DEVGMCommands.cpp | 90 ++++++++++++------- dNet/ChatPackets.cpp | 4 + dNet/ChatPackets.h | 1 + 3 files changed, 62 insertions(+), 33 deletions(-) diff --git a/dGame/dUtilities/SlashCommands/DEVGMCommands.cpp b/dGame/dUtilities/SlashCommands/DEVGMCommands.cpp index 83d5d12a..5b231d97 100644 --- a/dGame/dUtilities/SlashCommands/DEVGMCommands.cpp +++ b/dGame/dUtilities/SlashCommands/DEVGMCommands.cpp @@ -26,6 +26,8 @@ #include "Database.h" #include "CDObjectsTable.h" #include "CDRewardCodesTable.h" +#include "CDLootMatrixTable.h" +#include "CDLootTableTable.h" // Components #include "BuffComponent.h" @@ -743,11 +745,30 @@ namespace DEVGMCommands { auto tables = query.execQuery(); + std::map lotToName{}; + std::map nameToLot{}; while (!tables.eof()) { - std::string message = std::to_string(tables.getIntField("id")) + " - " + tables.getStringField("name"); - ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::UTF8ToUTF16(message, message.size())); + const auto lot = tables.getIntField("id"); + const auto name = tables.getStringField("name"); + lotToName[lot] = name; + nameToLot[name] = lot; tables.nextRow(); } + + AMFArrayValue response; + response.Insert("visible", true); + response.Insert("objectID", "Search Results"); + response.Insert("serverInfo", true); + auto* const info = response.InsertArray("data"); + auto& lotSort = info->PushDebug("Sorted by LOT"); + for (const auto& [lot, name] : lotToName) { + auto& entry = lotSort.PushDebug(std::to_string(lot)) = name; + } + auto& nameSort = info->PushDebug("Sorted by Name"); + for (const auto& [name, lot] : nameToLot) { + auto& entry = nameSort.PushDebug(name) = std::to_string(lot); + } + GameMessages::SendUIMessageServerToSingleClient("ToggleObjectDebugger", response, sysAddr); } void Spawn(Entity* entity, const SystemAddress& sysAddr, const std::string args) { @@ -1247,38 +1268,30 @@ namespace DEVGMCommands { } void Metrics(Entity* entity, const SystemAddress& sysAddr, const std::string args) { + AMFArrayValue response; + response.Insert("visible", true); + response.Insert("objectID", "Metrics"); + response.Insert("serverInfo", true); + auto* info = response.InsertArray("data"); for (const auto variable : Metrics::GetAllMetrics()) { + auto& metricData = info->PushDebug(StringifiedEnum::ToString(variable)); + auto* metric = Metrics::GetMetric(variable); if (metric == nullptr) { continue; } - ChatPackets::SendSystemMessage( - sysAddr, - GeneralUtils::ASCIIToUTF16(Metrics::MetricVariableToString(variable)) + - u": " + - GeneralUtils::to_u16string(Metrics::ToMiliseconds(metric->average)) + - u"ms" - ); + metricData.PushDebug("Maximum") = std::to_string(Metrics::ToMiliseconds(metric->max)) + "ms"; + metricData.PushDebug("Mininum") = std::to_string(Metrics::ToMiliseconds(metric->min)) + "ms"; + metricData.PushDebug("Average") = std::to_string(Metrics::ToMiliseconds(metric->average)) + "ms"; + metricData.PushDebug("Measurements Count") = std::to_string(metric->measurementSize); } - - ChatPackets::SendSystemMessage( - sysAddr, - u"Peak RSS: " + GeneralUtils::to_u16string(static_cast(static_cast(Metrics::GetPeakRSS()) / 1.024e6)) + - u"MB" - ); - - ChatPackets::SendSystemMessage( - sysAddr, - u"Current RSS: " + GeneralUtils::to_u16string(static_cast(static_cast(Metrics::GetCurrentRSS()) / 1.024e6)) + - u"MB" - ); - - ChatPackets::SendSystemMessage( - sysAddr, - u"Process ID: " + GeneralUtils::to_u16string(Metrics::GetProcessID()) - ); + auto& processInfo = info->PushDebug("Process Info"); + processInfo.PushDebug("Peak RSS") = std::to_string(static_cast(Metrics::GetPeakRSS()) / 1.024e6) + "MB"; + processInfo.PushDebug("Current RSS") = std::to_string(static_cast(Metrics::GetCurrentRSS()) / 1.024e6) + "MB"; + processInfo.PushDebug("Process ID") = Metrics::GetProcessID(); + GameMessages::SendUIMessageServerToSingleClient("ToggleObjectDebugger", response, sysAddr); } void ReloadConfig(Entity* entity, const SystemAddress& sysAddr, const std::string args) { @@ -1310,19 +1323,30 @@ namespace DEVGMCommands { const auto loops = GeneralUtils::TryParse(splitArgs[2]); if (!loops) return; + auto* const lootMatrixTable = CDClientManager::GetTable(); + auto* const lootTableTable = CDClientManager::GetTable(); + bool found = false; + for (const auto& entry : lootMatrixTable->GetMatrix(lootMatrixIndex.value())) { + for (const auto& loot : lootTableTable->GetTable(entry.LootTableIndex)) { + found = targetLot.value() == loot.itemid; + if (found) break; + } + } + + if (!found) { + std::stringstream ss; + ss << "Target LOT " << targetLot.value() << " not found in loot matrix " << lootMatrixIndex.value() << "."; + ChatPackets::SendSystemMessage(sysAddr, ss.str()); + return; + } + uint64_t totalRuns = 0; for (uint32_t i = 0; i < loops; i++) { while (true) { const auto lootRoll = Loot::RollLootMatrix(nullptr, lootMatrixIndex.value()); totalRuns += 1; - bool doBreak = false; - for (const auto& kv : lootRoll) { - if (static_cast(kv.first) == targetLot) { - doBreak = true; - } - } - if (doBreak) break; + if (lootRoll.contains(targetLot.value())) break; } } diff --git a/dNet/ChatPackets.cpp b/dNet/ChatPackets.cpp index 86622ad1..0c54e214 100644 --- a/dNet/ChatPackets.cpp +++ b/dNet/ChatPackets.cpp @@ -58,6 +58,10 @@ void ChatPackets::SendChatMessage(const SystemAddress& sysAddr, char chatChannel SEND_PACKET_BROADCAST; } +void ChatPackets::SendSystemMessage(const SystemAddress& sysAddr, const std::string& message, const bool broadcast) { + ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(message), broadcast); +} + void ChatPackets::SendSystemMessage(const SystemAddress& sysAddr, const std::u16string& message, const bool broadcast) { CBITSTREAM; BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::GENERAL_CHAT_MESSAGE); diff --git a/dNet/ChatPackets.h b/dNet/ChatPackets.h index 53d0eced..8139fb03 100644 --- a/dNet/ChatPackets.h +++ b/dNet/ChatPackets.h @@ -58,6 +58,7 @@ namespace ChatPackets { }; void SendChatMessage(const SystemAddress& sysAddr, char chatChannel, const std::string& senderName, LWOOBJID playerObjectID, bool senderMythran, const std::u16string& message); + void SendSystemMessage(const SystemAddress& sysAddr, const std::string& message, bool broadcast = false); void SendSystemMessage(const SystemAddress& sysAddr, const std::u16string& message, bool broadcast = false); void SendMessageFail(const SystemAddress& sysAddr); void SendRoutedMsg(const LUBitStream& msg, const LWOOBJID targetID, const SystemAddress& sysAddr);