Skip to content

Commit

Permalink
GWCA Debug Module (#733)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMacocian authored May 14, 2024
1 parent 795f2b4 commit 9721a7e
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Daybreak.GWCA/header/DebugModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
#include "httplib.h"
#include <DaybreakModule.h>
#include <payloads/DebugPayload.h>

namespace Daybreak::Modules {
class DebugModule : public DaybreakModule<DebugPayload, uint32_t> {
public:
std::string ApiUri() override;
protected:
std::optional<uint32_t> GetContext(const httplib::Request& req, httplib::Response& res) override;
std::optional<DebugPayload> GetPayload(uint32_t context) override;
};
}
20 changes: 20 additions & 0 deletions Daybreak.GWCA/header/payloads/DebugPayload.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include <cstdint>
#include <GWCA/GameEntities/Map.h>
#include <json.hpp>
#include <payloads/MainPlayer.h>
#include <payloads/MapIcon.h>

using json = nlohmann::json;

namespace Daybreak {
struct DebugPayload {
std::string GameContextAddress;
std::string WorldContextAddress;
std::string AgentContextAddress;
std::string MapContextAddress;
std::string CharContextAddress;
};

void to_json(json& j, const DebugPayload& p);
}
36 changes: 36 additions & 0 deletions Daybreak.GWCA/source/DebugModule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "pch.h"
#include "DebugModule.h"
#include "payloads/DebugPayload.h"
#include <GWCA/GWCA.h>
#include <GWCA/Context/GameContext.h>

namespace Daybreak::Modules {
std::string DebugModule::ApiUri()
{
return "/debug";
}

std::optional<uint32_t> DebugModule::GetContext(const httplib::Request& req, httplib::Response& res)
{
return 0;
}

std::optional<DebugPayload> DebugModule::GetPayload(const uint32_t)
{
char buffer[20];
DebugPayload debugPayload;
const auto gameContext = GW::GetGameContext();
std::sprintf(buffer, "%p", static_cast<void*>(gameContext));
debugPayload.GameContextAddress = std::string(buffer);
std::sprintf(buffer, "%p", static_cast<void*>(gameContext->agent));
debugPayload.AgentContextAddress = std::string(buffer);
std::sprintf(buffer, "%p", static_cast<void*>(gameContext->character));
debugPayload.CharContextAddress = std::string(buffer);
std::sprintf(buffer, "%p", static_cast<void*>(gameContext->world));
debugPayload.WorldContextAddress = std::string(buffer);
std::sprintf(buffer, "%p", static_cast<void*>(gameContext->map));
debugPayload.MapContextAddress = std::string(buffer);

return debugPayload;
}
}
3 changes: 3 additions & 0 deletions Daybreak.GWCA/source/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "ItemNameModule.h"
#include "TitleInfoModule.h"
#include "WhisperModule.h"
#include "DebugModule.h"
#include <mutex>

volatile bool initialized;
Expand Down Expand Up @@ -73,6 +74,7 @@ static DWORD WINAPI StartHttpServer(LPVOID)
const auto sessionModule = new Daybreak::Modules::SessionModule();
const auto userModule = new Daybreak::Modules::UserModule();
const auto whisperModule = new Daybreak::Modules::WhisperModule();
const auto debugModule = new Daybreak::Modules::DebugModule();

http::server::SetLogger(http::ConsoleLogger);
http::server::Get("/alive", http::modules::HandleAlive);
Expand All @@ -92,6 +94,7 @@ static DWORD WINAPI StartHttpServer(LPVOID)
http::server::Get(itemNameModule->ApiUri(), [&itemNameModule](const httplib::Request& req, httplib::Response& res) { itemNameModule->HandleApiCall(req, res); });
http::server::Get(titleInfoModule->ApiUri(), [&titleInfoModule](const httplib::Request& req, httplib::Response& res) { titleInfoModule->HandleApiCall(req, res); });
http::server::Post(whisperModule->ApiUri(), [&whisperModule](const httplib::Request& req, httplib::Response& res) { whisperModule->HandleApiCall(req, res); });
http::server::Get(debugModule->ApiUri(), [&debugModule](const httplib::Request& req, httplib::Response& res) { debugModule->HandleApiCall(req, res); });
http::server::StartServer();
return 0;
}
Expand Down
18 changes: 18 additions & 0 deletions Daybreak.GWCA/source/payloads/DebugPayload.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <cstdint>
#include <json.hpp>
#include <payloads/DebugPayload.h>

using json = nlohmann::json;

namespace Daybreak {
void to_json(json& j, const DebugPayload& p) {
j = json
{
{"GameContextAddress", p.GameContextAddress},
{"WorldContextAddress", p.WorldContextAddress},
{"MapContextAddress", p.MapContextAddress},
{"AgentContextAddress", p.AgentContextAddress},
{"CharContextAddress", p.CharContextAddress},
};
}
}

0 comments on commit 9721a7e

Please sign in to comment.