Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
DubbleClick committed Jan 20, 2025
1 parent f8ad9e5 commit ee2ceb7
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 66 deletions.
135 changes: 81 additions & 54 deletions GWToolboxdll/Modules/ChatCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ namespace {
: title(in)
{
const auto title_info = GW::PlayerMgr::GetTitleData(title);
if(title_info)
if (title_info)
name.reset(title_info->name_id);
};
GW::Constants::TitleID title;
Expand Down Expand Up @@ -266,14 +266,14 @@ namespace {

void CHAT_CMD_FUNC(CmdDuncan)
{
std::wstring out_message = std::format(L"{}\x2\x108\x107 Status: \x1",GW::EncStrings::Quest::TheLastHeirophant);
std::wstring out_message = std::format(L"{}\x2\x108\x107 Status: \x1", GW::EncStrings::Quest::TheLastHeirophant);
if (!GW::QuestMgr::GetQuest(GW::Constants::QuestID::The_Last_Hierophant)) {
out_message += L"\x108\x107I don't have the quest!\x1";
}
else {
const auto objectives = QuestModule::ParseQuestObjectives(GW::Constants::QuestID::The_Last_Hierophant);
const wchar_t* objective_names[] = {
L"Thommis",L"Rand",L"Selvetarm",L"Forgewight",L"Duncan"
L"Thommis", L"Rand", L"Selvetarm", L"Forgewight", L"Duncan"
};
for (size_t i = 0; i < _countof(objective_names); i++) {
const wchar_t completed_mark = i < objectives.size() && objectives[i].is_completed ? L'\x2705' : ' ';
Expand Down Expand Up @@ -345,7 +345,7 @@ namespace {
GW::GameThread::Enqueue([packet] {
GW::StoC::EmulatePacket(packet);
delete packet;
});
});
}

HallOfMonumentsAchievements hom_achievements;
Expand Down Expand Up @@ -464,16 +464,19 @@ namespace {
PrefLabel(const uint32_t _enc_string) : EncString(_enc_string, false) {};
protected:
static void OnPrefLabelDecoded(void* param, const wchar_t* decoded);
void decode() override {

void decode() override
{
language(GW::Constants::Language::English);
if (!decoded && !decoding && !encoded_ws.empty()) {
decoding = true;
GW::GameThread::Enqueue([&] {
GW::UI::AsyncDecodeStr(encoded_ws.c_str(), OnPrefLabelDecoded, this, language_id);
});
});
}
}
};

void PrefLabel::OnPrefLabelDecoded(void* param, const wchar_t* decoded)
{
GuiUtils::EncString::OnStringDecoded(param, decoded);
Expand Down Expand Up @@ -524,7 +527,7 @@ namespace {
pref_map = {
{GW::UI::EnumPreference::AntiAliasing, GW::EncStrings::AntiAliasing},
{GW::UI::EnumPreference::ShaderQuality, GW::EncStrings::ShaderQuality},
{GW::UI::EnumPreference::TerrainQuality, GW::EncStrings::TerrainQuality },
{GW::UI::EnumPreference::TerrainQuality, GW::EncStrings::TerrainQuality},
{GW::UI::EnumPreference::Reflections, GW::EncStrings::Reflections},
{GW::UI::EnumPreference::ShadowQuality, GW::EncStrings::ShadowQuality},
{GW::UI::EnumPreference::InterfaceSize, GW::EncStrings::InterfaceSize},
Expand All @@ -538,7 +541,7 @@ namespace {
{GW::UI::FlagPreference::DisableMouseWalking, GW::EncStrings::DisableMouseWalking},
{GW::UI::FlagPreference::AlwaysShowFoeNames, L"\x108\x107Show Foe Names\x1"},
{GW::UI::FlagPreference::AlwaysShowAllyNames, L"\x108\x107Show Ally Names\x1"},
{ GW::UI::FlagPreference::EnableGamepad, L"\x108\x107" "Enable Gamepad\x1" },
{GW::UI::FlagPreference::EnableGamepad, L"\x108\x107" "Enable Gamepad\x1"},
};
for (auto& it : pref_map) {
it.label->wstring();
Expand Down Expand Up @@ -569,7 +572,7 @@ namespace {
// Find preference by name
const auto found = std::ranges::find_if(options, [argv](const PrefMapCommand& cmd) {
return cmd.label->wstring() == argv[1];
});
});
if (found == options.end()) {
return Log::Error(pref_syntax);
}
Expand Down Expand Up @@ -598,7 +601,8 @@ namespace {

std::vector<CmdAlias*> cmd_aliases;

void sort_cmd_aliases() {
void sort_cmd_aliases()
{
std::ranges::stable_sort(cmd_aliases, [](const auto* a, const auto* b) {
if (a->alias_cstr[0] == '\0' && b->alias_cstr[0] != '\0') {
return false;
Expand Down Expand Up @@ -641,18 +645,24 @@ namespace {
}
}

void CHAT_CMD_FUNC(CmdTick) {
void CHAT_CMD_FUNC(CmdTick)
{
GW::PartyMgr::Tick(!GW::PartyMgr::GetIsPlayerTicked());
}
void CHAT_CMD_FUNC(CmdCallTarget) {

void CHAT_CMD_FUNC(CmdCallTarget)
{
const auto* target = GW::Agents::GetTarget();
if (!target)
return;
auto call_packet = GW::UI::UIPacket::kSendCallTarget{ GW::CallTargetType::AttackingOrTargetting, target->agent_id };
auto call_packet = GW::UI::UIPacket::kSendCallTarget{
.call_type = GW::CallTargetType::AttackingOrTargetting,
.agent_id = target->agent_id
};
GW::UI::SendUIMessage(GW::UI::UIMessage::kSendCallTarget, &call_packet);
}

std::vector<std::pair< const wchar_t*, GW::Chat::ChatCommandCallback>> chat_commands;
std::vector<std::pair<const wchar_t*, GW::Chat::ChatCommandCallback>> chat_commands;

const wchar_t* settings_via_chat_commands_cmd = L"tb_setting";

Expand All @@ -665,48 +675,56 @@ namespace {
Uint,
Int
} setting_type;

void* setting_ptr;
const wchar_t* setting_name;
const wchar_t* description;
std::wstring ChatCommandSyntax() {

std::wstring ChatCommandSyntax()
{
switch (setting_type) {
case SettingType::Bool:
if(description)
return std::format(L"'/{} {} [on|off|toggle]' {}", settings_via_chat_commands_cmd, setting_name, description);
return std::format(L"'/{} {} [on|off|toggle]'", settings_via_chat_commands_cmd, setting_name);
case SettingType::Bool:
if (description)
return std::format(L"'/{} {} [on|off|toggle]' {}", settings_via_chat_commands_cmd, setting_name, description);
return std::format(L"'/{} {} [on|off|toggle]'", settings_via_chat_commands_cmd, setting_name);
}
return std::format(L"Failed to get ChatCommandSyntax for SettingType {} ({})", (uint32_t)setting_type, setting_name);
}
void ChatCommandCallback(GW::HookStatus*, const wchar_t*, int argc, const LPWSTR* argv) {

void ChatCommandCallback(GW::HookStatus*, const wchar_t*, int argc, const LPWSTR* argv)
{
switch (setting_type) {
case SettingType::Bool:
if (argc < 2)
return Log::WarningW(L"Invalid syntax for %s\n%s", setting_name, ChatCommandSyntax().c_str());
auto current_val = (bool*)setting_ptr;
bool new_val = !*current_val;
if (wcscmp(argv[1], L"on") == 0 || wcscmp(argv[1], L"1") == 0)
new_val = true;
if (wcscmp(argv[1], L"off") == 0 || wcscmp(argv[1], L"0") == 0)
new_val = false;
if (*current_val == new_val)
return;
*current_val = new_val;
case SettingType::Bool:
if (argc < 2)
return Log::WarningW(L"Invalid syntax for %s\n%s", setting_name, ChatCommandSyntax().c_str());
auto current_val = (bool*)setting_ptr;
bool new_val = !*current_val;
if (wcscmp(argv[1], L"on") == 0 || wcscmp(argv[1], L"1") == 0)
new_val = true;
if (wcscmp(argv[1], L"off") == 0 || wcscmp(argv[1], L"0") == 0)
new_val = false;
if (*current_val == new_val)
return;
*current_val = new_val;
// TODO: Maybe OnChanged callback?
return;
return;
}
Log::WarningW(L"Failed to process ToolboxChatCommandSetting %s", setting_name);
}
public:
ToolboxChatCommandSetting(const wchar_t* setting_name, const bool* bool_setting_ptr, const wchar_t* description = nullptr) :
setting_name(setting_name), setting_ptr((void*)bool_setting_ptr), description(description) {

ToolboxChatCommandSetting(const wchar_t* setting_name, const bool* bool_setting_ptr, const wchar_t* description = nullptr)
: setting_name(setting_name),
setting_ptr((void*)bool_setting_ptr),
description(description)
{
setting_type = SettingType::Bool;
}
};

std::map<std::wstring, ToolboxChatCommandSetting*> settings_via_chat_commands;

void CHAT_CMD_FUNC(CmdSettingViaChatCommand) {
void CHAT_CMD_FUNC(CmdSettingViaChatCommand)
{
const auto found = argc > 1 ? settings_via_chat_commands.find(argv[1]) : settings_via_chat_commands.end();

if (found == settings_via_chat_commands.end()) {
Expand All @@ -716,7 +734,8 @@ namespace {
found->second->ChatCommandCallback(status, message, argc, argv);
}

void DrawChatCommandsHelp() {
void DrawChatCommandsHelp()
{
if (!ImGui::TreeNodeEx("Chat Commands", ImGuiTreeNodeFlags_FramePadding | ImGuiTreeNodeFlags_SpanAvailWidth)) {
return;
}
Expand Down Expand Up @@ -869,7 +888,8 @@ namespace {
ImGui::TreePop();
}

void DrawToolboxSettingChatCommandsHelp() {
void DrawToolboxSettingChatCommandsHelp()
{
if (settings_via_chat_commands.empty() || !ImGui::TreeNodeEx("Chat Commands for Toolbox Settings", ImGuiTreeNodeFlags_FramePadding | ImGuiTreeNodeFlags_SpanAvailWidth)) {
return;
}
Expand All @@ -880,10 +900,10 @@ namespace {
}
ImGui::TreePop();
}

} // namespace

void ChatCommands::CreateAlias(const wchar_t* alias, const wchar_t* message) {
void ChatCommands::CreateAlias(const wchar_t* alias, const wchar_t* message)
{
if (alias && *alias == L'/')
alias++;
if (!(alias && *alias && message && *message))
Expand All @@ -907,17 +927,21 @@ void ChatCommands::CreateAlias(const wchar_t* alias, const wchar_t* message) {
strcpy(alias_obj->command_cstr, message_cstr.c_str());
wcscpy(alias_obj->command_wstr, message);
}

void ChatCommands::RegisterSettingChatCommand(const wchar_t* setting_name, const bool* static_setting_ptr, const wchar_t* description)
{
settings_via_chat_commands[setting_name] = new ToolboxChatCommandSetting( setting_name,static_setting_ptr,description );
settings_via_chat_commands[setting_name] = new ToolboxChatCommandSetting(setting_name, static_setting_ptr, description);
}
void ChatCommands::RemoveSettingChatCommand(const wchar_t* setting_name) {

void ChatCommands::RemoveSettingChatCommand(const wchar_t* setting_name)
{
const auto found = settings_via_chat_commands.find(setting_name);
if (found != settings_via_chat_commands.end()) {
delete found->second;
settings_via_chat_commands.erase(found);
}
}

void ChatCommands::TransmoAgent(DWORD agent_id, PendingTransmo& transmo)
{
if (!transmo.npc_id || !agent_id) {
Expand Down Expand Up @@ -1078,7 +1102,7 @@ void ChatCommands::DrawSettingsInternal()
if (!result)
return;
auto alias = (CmdAlias*)wparam;
const auto found = std::ranges::find(cmd_aliases,alias);
const auto found = std::ranges::find(cmd_aliases, alias);
if (found != cmd_aliases.end()) {
cmd_aliases.erase(found);
delete alias;
Expand All @@ -1101,7 +1125,7 @@ void ChatCommands::DrawSettingsInternal()
const auto text_height = ImGui::GetTextLineHeightWithSpacing();
const auto num_newlines = 1 + std::count((*it)->command_cstr, (*it)->command_cstr + _countof(CmdAlias::command_cstr), '\n');
if (ImGui::InputTextMultiline("##cmd_command", (*it)->command_cstr,
_countof(CmdAlias::command_cstr), ImVec2(avail_w * .6f, text_height + num_newlines * ImGui::GetTextLineHeight()))) {
_countof(CmdAlias::command_cstr), ImVec2(avail_w * .6f, text_height + num_newlines * ImGui::GetTextLineHeight()))) {
swprintf((*it)->command_wstr, _countof(CmdAlias::command_wstr), L"%S", (*it)->command_cstr);
}
if (ImGui::IsItemHovered()) {
Expand Down Expand Up @@ -1280,23 +1304,23 @@ void ChatCommands::Initialize()
#if _DEBUG
// Experimental chat commands
uintptr_t address = 0;
chat_commands.push_back({ L"skillimage", CmdSkillImage });
chat_commands.push_back({L"skillimage", CmdSkillImage});
address = GW::Scanner::Find("\x83\xc4\x04\xc7\x45\x08\x00\x00\x00\x00", "xxxxxxxxxx", -5);
if (address) {
SetMuted_Func = (SetMuted_pt)GW::Scanner::FunctionFromNearCall(address);
PostMuted_Func = (PostMute_pt)GW::Scanner::FunctionFromNearCall(address + 0x10);
is_muted = *(bool**)((uintptr_t)SetMuted_Func + 0x6);
}
chat_commands.push_back({ L"mute", CmdMute }); // Doesn't unmute!
chat_commands.push_back({ L"effect", CmdPlayEffect });
chat_commands.push_back({L"mute", CmdMute}); // Doesn't unmute!
chat_commands.push_back({L"effect", CmdPlayEffect});

#endif

GW::WaitForFrame(L"Chat", [](GW::UI::Frame* frame) {
OnChatInteraction_Callback_Func = frame->frame_callbacks[0];
GW::Hook::CreateHook((void**)&OnChatInteraction_Callback_Func, OnChatUI_Callback, (void**)&OnChatInteraction_Callback_Ret);
GW::Hook::EnableHooks(OnChatInteraction_Callback_Func);
});
});

#ifdef _DEBUG
ASSERT(SetMuted_Func);
Expand All @@ -1305,7 +1329,7 @@ void ChatCommands::Initialize()
#endif

for (auto& it : chat_commands) {
GW::Chat::CreateCommand(&ChatCmd_HookEntry,it.first, it.second);
GW::Chat::CreateCommand(&ChatCmd_HookEntry, it.first, it.second);
}
getPrefCommandOptions();
}
Expand Down Expand Up @@ -1724,7 +1748,10 @@ void CHAT_CMD_FUNC(ChatCommands::CmdMorale)
GW::Chat::SendChat('#', L"I have no Morale Boost or Death Penalty!");
}
else {
auto packet = GW::UI::UIPacket::kSendCallTarget { GW::CallTargetType::Morale, GW::Agents::GetControlledCharacterId() };
auto packet = GW::UI::UIPacket::kSendCallTarget{
.call_type = GW::CallTargetType::Morale,
.agent_id= GW::Agents::GetControlledCharacterId()
};
GW::UI::SendUIMessage(GW::UI::UIMessage::kSendCallTarget, &packet);
}
}
Expand Down Expand Up @@ -2160,7 +2187,7 @@ const wchar_t* ChatCommands::GetRemainingArgsWstr(const wchar_t* message, const
}
}

if(!out) {
if (!out) {
return L"";
}
return out;
Expand Down Expand Up @@ -2422,7 +2449,7 @@ void CHAT_CMD_FUNC(ChatCommands::CmdPingBuild)
continue;
}

GW::Chat::SendChat('#', std::format(L"[{};{}]",arg,TextUtils::StringToWString(content)).c_str());
GW::Chat::SendChat('#', std::format(L"[{};{}]", arg, TextUtils::StringToWString(content)).c_str());
}
}

Expand Down
12 changes: 0 additions & 12 deletions GWToolboxdll/Modules/SalvageInfoModule.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#include "stdafx.h"

#include <Defines.h>
#include <Logger.h>
#include <base64.h>
#include <ctime>
#include <regex>

#include <GWCA/GameEntities/Item.h>
#include <GWCA/GameEntities/Agent.h>
Expand All @@ -14,25 +10,17 @@
#include <GWCA/Managers/UIMgr.h>
#include <GWCA/Managers/AgentMgr.h>

#include <GWCA/Context/GameContext.h>
#include <GWCA/Context/TextParser.h>

#include <GWCA/Constants/Constants.h>
#include <GWCA/Constants/ItemIDs.h>

#include <GWCA/Utilities/Hook.h>
#include <GWCA/Utilities/Hooker.h>
#include <GWCA/Utilities/Scanner.h>

#include <Modules/ItemDescriptionHandler.h>
#include <Modules/InventoryManager.h>
#include <Modules/Resources.h>
#include <Modules/GameSettings.h>
#include <Modules/SalvageInfoModule.h>
#include <Windows/DailyQuestsWindow.h>

#include <Utils/GuiUtils.h>
#include <Timer.h>
#include <Constants/EncStrings.h>

using nlohmann::json;
Expand Down

0 comments on commit ee2ceb7

Please sign in to comment.