Skip to content

Commit

Permalink
removed stoc hooks from faction leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
3vcloud committed May 17, 2024
1 parent 20e22f7 commit 3d251fe
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 99 deletions.
7 changes: 7 additions & 0 deletions GWToolboxdll/Utils/GuiUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,13 @@ namespace GuiUtils {
return out;
}

std::wstring UrlEncode(const std::wstring& s, const char space_token) {
const auto str = WStringToString(s);
const auto enc = UrlEncode(str, space_token);
return StringToWString(enc);
}


std::string UrlEncode(const std::string& s, const char space_token)
{
if (s.empty()) {
Expand Down
1 change: 1 addition & 0 deletions GWToolboxdll/Utils/GuiUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace GuiUtils {
std::wstring ToSlug(std::wstring s);
std::string ToLower(std::string s);
std::wstring ToLower(std::wstring s);
std::wstring UrlEncode(const std::wstring& s, char space_token = '_');
std::string UrlEncode(const std::string& s, char space_token = '_');
std::string HtmlEncode(const std::string& s);
std::wstring RemovePunctuation(std::wstring s);
Expand Down
120 changes: 24 additions & 96 deletions GWToolboxdll/Windows/FactionLeaderboardWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,84 +5,18 @@
#include <GWCA/Packets/StoC.h>

#include <GWCA/GameEntities/Map.h>
#include <GWCA/Context/GuildContext.h>

#include <GWCA/Managers/UIMgr.h>
#include <GWCA/Managers/MapMgr.h>
#include <GWCA/Managers/StoCMgr.h>

#include <Modules/Resources.h>

#include <Utils/GuiUtils.h>

#include <Windows/FactionLeaderboardWindow.h>

namespace {


struct LeaderboardEntry {
LeaderboardEntry() = default;

LeaderboardEntry(const uint32_t m, const uint32_t r, const uint32_t a, const uint32_t f, const wchar_t* n, const wchar_t* t)
: map_id(m), rank(r), allegiance(a), faction(f)
{
wcscpy(guild_wstr, n); // Copy the string to avoid read errors later.
wcscpy(tag_wstr, t); // Copy the string to avoid read errors later.
map_name[0] = 0;
strcpy(guild_str, GuiUtils::WStringToString(guild_wstr).c_str());
strcpy(tag_str, GuiUtils::WStringToString(tag_wstr).c_str());
guild_wiki_url = guild_wstr;
std::ranges::transform(guild_wiki_url, guild_wiki_url.begin(),
[](const wchar_t ch) -> wchar_t {
return ch == ' ' ? L'_' : ch;
});
guild_wiki_url = L"https://wiki.guildwars.com/wiki/Guild:" + guild_wiki_url;
initialised = true;
}

uint32_t map_id = 0;
uint32_t rank = 0;
uint32_t allegiance = 0;
uint32_t faction = 0;
wchar_t guild_wstr[32]{};
wchar_t tag_wstr[5]{};
char guild_str[128]{}; // unicode char can be up to 4 bytes
char tag_str[20]{}; // unicode char can be up to 4 bytes
wchar_t map_name_enc[16]{};
char map_name[256]{};
std::wstring guild_wiki_url;
bool initialised = false;
};

std::vector<LeaderboardEntry> leaderboard{};
std::vector<LeaderboardEntry>::iterator lit{};

GW::HookEntry TownAlliance_Entry;

void OnStoC_TownAllianceObject(const GW::HookStatus*, GW::Packet::StoC::TownAllianceObject* pak) {
const LeaderboardEntry leaderboardEntry = {
pak->map_id,
pak->rank,
pak->allegiance,
pak->faction,
pak->name,
pak->tag
};
if (leaderboard.size() <= leaderboardEntry.rank) {
leaderboard.resize(leaderboardEntry.rank + 1);
}
leaderboard.at(leaderboardEntry.rank) = leaderboardEntry;
}
}


void FactionLeaderboardWindow::Initialize()
{
ToolboxWindow::Initialize();
leaderboard.resize(15);
GW::StoC::RegisterPacketCallback<GW::Packet::StoC::TownAllianceObject>(&TownAlliance_Entry, OnStoC_TownAllianceObject);
}
void FactionLeaderboardWindow::Terminate() {
GW::StoC::RemoveCallbacks(&TownAlliance_Entry);
}

void FactionLeaderboardWindow::Draw(IDirect3DDevice9*)
{
if (!visible) {
Expand All @@ -109,35 +43,29 @@ void FactionLeaderboardWindow::Draw(IDirect3DDevice9*)
ImGui::Text("Guild");
ImGui::Separator();
bool has_entries = false;
for (size_t i = 0; i < leaderboard.size(); i++) {
LeaderboardEntry* e = &leaderboard[i];
if (!e->initialised) {
continue;
}
has_entries = true;
offset = 0.0f;
if (e->map_name[0] == 0) {
// Try to load map name in.
const GW::AreaInfo* info = GW::Map::GetMapInfo(static_cast<GW::Constants::MapID>(e->map_id));
if (info && GW::UI::UInt32ToEncStr(info->name_id, e->map_name_enc, 256)) {
GW::UI::AsyncDecodeStr(e->map_name_enc, e->map_name, 256);

const auto g = GW::GetGuildContext();
if (g) {
const auto& leaderboard = g->factions_outpost_guilds;
for (const auto& e : leaderboard) {
has_entries = true;
offset = 0.0f;
ImGui::Text("%d", e.rank);
ImGui::SameLine(offset += tiny_text_width);
ImGui::Text(e.allegiance == 1 ? "Luxon" : "Kurzick");
ImGui::SameLine(offset += short_text_width);
ImGui::Text("%d", e.faction);
ImGui::SameLine(offset += short_text_width);
ImGui::Text(Resources::GetMapName(e.map_id)->string().c_str());
ImGui::SameLine(offset += long_text_width);
ImGui::Text("%s [%s]", GuiUtils::WStringToString(e.name).c_str(), GuiUtils::WStringToString(e.tag).c_str());
ImGui::PushID(&e);
ImGui::SameLine(offset = avail_width - tiny_text_width);
if (ImGui::Button("Wiki", ImVec2(tiny_text_width, 0))) {
GuiUtils::OpenWiki(std::format(L"Guild:{}", e.name));
}
ImGui::PopID();
}
ImGui::Text("%d", e->rank);
ImGui::SameLine(offset += tiny_text_width);
ImGui::Text(e->allegiance == 1 ? "Luxon" : "Kurzick");
ImGui::SameLine(offset += short_text_width);
ImGui::Text("%d", e->faction);
ImGui::SameLine(offset += short_text_width);
ImGui::Text(e->map_name);
ImGui::SameLine(offset += long_text_width);
ImGui::Text("%s [%s]", e->guild_str, e->tag_str);
ImGui::PushID(static_cast<int>(e->map_id));
ImGui::SameLine(offset = avail_width - tiny_text_width);
if (ImGui::Button("Wiki", ImVec2(tiny_text_width, 0))) {
ShellExecuteW(nullptr, L"open", e->guild_wiki_url.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
}
ImGui::PopID();
}
if (!has_entries) {
const ImVec2 w = ImGui::CalcTextSize("Enter a Canthan outpost to see data");
Expand Down
3 changes: 0 additions & 3 deletions GWToolboxdll/Windows/FactionLeaderboardWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class FactionLeaderboardWindow : public ToolboxWindow {
[[nodiscard]] const char* Name() const override { return "Faction Leaderboard"; }
[[nodiscard]] const char* Icon() const override { return ICON_FA_GLOBE; }

void Initialize() override;
void Terminate() override;

// Draw user interface. Will be called every frame if the element is visible
void Draw(IDirect3DDevice9* pDevice) override;

Expand Down

0 comments on commit 3d251fe

Please sign in to comment.