Skip to content

Commit 23d82ba

Browse files
committed
Changed behaviour of skipping character name entry when donating faction to bring in line with UI functions
Tidied up ui message handling in game settings
1 parent e0ba94c commit 23d82ba

File tree

2 files changed

+84
-134
lines changed

2 files changed

+84
-134
lines changed

GWToolboxdll/Modules/GameSettings.cpp

+84-123
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <GWCA/Managers/UIMgr.h>
4444
#include <GWCA/Managers/RenderMgr.h>
4545
#include <GWCA/Managers/QuestMgr.h>
46+
#include <GWCA/Managers/MerchantMgr.h>
4647

4748
#include <GWCA/Utilities/Hooker.h>
4849

@@ -215,6 +216,16 @@ namespace {
215216
bool prevent_weapon_spell_animation_on_player = false;
216217
bool block_vanquish_complete_popup = false;
217218

219+
bool was_leading = true;
220+
bool hide_dungeon_chest_popup = false;
221+
bool skip_entering_name_for_faction_donate = false;
222+
bool stop_screen_shake = false;
223+
bool disable_camera_smoothing = false;
224+
225+
bool check_message_on_party_change = true;
226+
227+
bool is_prompting_hard_mode_mission = false;
228+
218229
GW::HookEntry SkillList_UICallback_HookEntry;
219230
GW::UI::UIInteractionCallback SkillList_UICallback_Func = 0, SkillList_UICallback_Ret = 0;
220231

@@ -1049,43 +1060,31 @@ namespace {
10491060

10501061
GW::HookEntry OnQuestUIMessage_HookEntry;
10511062

1052-
void OnPostQuestUIMessage(const GW::HookStatus* status, const GW::UI::UIMessage message_id, void*, void*)
1053-
{
1054-
switch (message_id) {
1055-
case GW::UI::UIMessage::kSendSetActiveQuest:
1056-
if (status->blocked) {
1057-
break;
1058-
}
1059-
player_requested_active_quest_id = GW::QuestMgr::GetActiveQuestId();
1060-
break;
1061-
case GW::UI::UIMessage::kQuestAdded:
1062-
if (status->blocked) {
1063-
break;
1064-
}
1065-
if (GW::QuestMgr::GetActiveQuestId() == player_requested_active_quest_id) {
1066-
break;
1067-
}
1068-
if (keep_current_quest_when_new_quest_added) {
1069-
// Re-request a quest change
1070-
const auto quest = GW::QuestMgr::GetQuest(player_requested_active_quest_id);
1071-
if (!quest) {
1072-
break;
1073-
}
1074-
GW::Packet::StoC::QuestAdd packet;
1075-
packet.quest_id = quest->quest_id;
1076-
packet.marker = quest->marker;
1077-
packet.map_to = quest->map_to;
1078-
packet.log_state = quest->log_state;
1079-
packet.map_from = quest->map_from;
1080-
wcscpy(packet.location, quest->location);
1081-
wcscpy(packet.name, quest->name);
1082-
wcscpy(packet.npc, quest->npc);
1083-
GW::StoC::EmulatePacket(&packet); // Why? Can we not send more ui messages if thats the need?
1084-
GW::QuestMgr::SetActiveQuestId(quest->quest_id);
1085-
}
1086-
1087-
break;
1063+
void OnQuestAdded(uint32_t) {
1064+
if (GW::QuestMgr::GetActiveQuestId() == player_requested_active_quest_id) {
1065+
return;
10881066
}
1067+
if (keep_current_quest_when_new_quest_added) {
1068+
// Re-request a quest change
1069+
const auto quest = GW::QuestMgr::GetQuest(player_requested_active_quest_id);
1070+
if (!quest) {
1071+
return;
1072+
}
1073+
// Emulate the StoC packet because the packet handler itself sorts memory out, and then calls affected modules via UI messages with the new (current) data...
1074+
GW::Packet::StoC::QuestAdd packet;
1075+
packet.quest_id = quest->quest_id;
1076+
packet.marker = quest->marker;
1077+
packet.map_to = quest->map_to;
1078+
packet.log_state = quest->log_state;
1079+
packet.map_from = quest->map_from;
1080+
wcscpy(packet.location, quest->location);
1081+
wcscpy(packet.name, quest->name);
1082+
wcscpy(packet.npc, quest->npc);
1083+
// ...We do this because sending UI messages doesn't actually update the quest data, it only notifies te ui that stuff has changed
1084+
GW::StoC::EmulatePacket(&packet);
1085+
GW::QuestMgr::SetActiveQuestId(quest->quest_id);
1086+
}
1087+
10891088
}
10901089

10911090
void CHAT_CMD_FUNC(CmdReinvite)
@@ -1236,6 +1235,34 @@ namespace {
12361235
}
12371236
}
12381237

1238+
void OnVendorWindow(GW::UI::UIPacket::kVendorWindow* packet) {
1239+
// Pre-fill character name when donating faction
1240+
if (!(skip_entering_name_for_faction_donate && packet && packet->transaction_type == GW::Merchant::TransactionType::DonateFaction))
1241+
return;
1242+
auto frame = GW::UI::GetChildFrame(GW::UI::GetFrameByLabel(L"NPCInteract"), 0, 0);
1243+
const auto sign_btn = GW::UI::GetChildFrame(frame, 2);
1244+
if (!(sign_btn && sign_btn->IsVisible()))
1245+
return; // If sign button isn't visible, the player doesn't have enough faction
1246+
const auto name_input = GW::UI::GetChildFrame(frame, 4, 2);
1247+
const auto agent_enc_name = GW::PlayerMgr::GetPlayerName();
1248+
// Prefill and hide the name input
1249+
GW::UI::SendFrameUIMessage(name_input, (GW::UI::UIMessage)0x4e, (void*)agent_enc_name);
1250+
GW::UI::SetFrameVisible(name_input, 0);
1251+
// Show and enable the "Sign" button
1252+
GW::UI::SetFrameDisabled(sign_btn, 0);
1253+
}
1254+
1255+
void OnDialogButton(GW::UI::DialogButtonInfo* packet) {
1256+
if (auto_open_locked_chest_with_key && wcscmp(packet->message, L"\x8101\x7F88\x10A\x8101\x13BE\x1") == 0) {
1257+
// Auto use key
1258+
DialogModule::SendDialog(packet->dialog_id);
1259+
}
1260+
if (auto_open_locked_chest && wcscmp(packet->message, L"\x8101\x7f88\x010a\x8101\x730e\x1") == 0) {
1261+
// Auto use lockpick
1262+
DialogModule::SendDialog(packet->dialog_id);
1263+
}
1264+
}
1265+
12391266
GW::HookEntry OnPostUIMessage_HookEntry;
12401267
void OnPostUIMessage(GW::HookStatus* status, GW::UI::UIMessage message_id, void* wParam, void*) {
12411268
if (status->blocked)
@@ -1248,6 +1275,12 @@ namespace {
12481275
GW::UI::ButtonClick(GW::UI::GetChildFrame(GW::UI::GetFrameByLabel(L"Party"), 1, 10, 6));
12491276
}
12501277
} break;
1278+
case GW::UI::UIMessage::kSendSetActiveQuest:
1279+
player_requested_active_quest_id = GW::QuestMgr::GetActiveQuestId();
1280+
break;
1281+
case GW::UI::UIMessage::kQuestAdded:
1282+
OnQuestAdded(*(uint32_t*)wParam);
1283+
break;
12511284
case GW::UI::UIMessage::kTradeSessionStart: {
12521285
if (flash_window_on_trade) {
12531286
FlashWindow();
@@ -1256,6 +1289,9 @@ namespace {
12561289
FocusWindow();
12571290
}
12581291
} break;
1292+
case GW::UI::UIMessage::kVendorWindow: {
1293+
OnVendorWindow((GW::UI::UIPacket::kVendorWindow*)wParam);
1294+
} break;
12591295
case GW::UI::UIMessage::kPartySearchInviteSent: {
12601296
// Automatically send a party window invite when a party search invite is sent
12611297
const auto packet = (GW::UI::UIPacket::kPartySearchInvite*)wParam;
@@ -1268,16 +1304,16 @@ namespace {
12681304
CheckRemoveWindowBorder();
12691305
} break;
12701306
case GW::UI::UIMessage::kPartyDefeated: {
1271-
if (auto_return_on_defeat && GW::PartyMgr::GetIsLeader() && !GW::PartyMgr::ReturnToOutpost())
1272-
Log::Warning("Failed to return to outpost");
1307+
if (auto_return_on_defeat && GW::PartyMgr::GetIsLeader())
1308+
GW::PartyMgr::ReturnToOutpost() || (Log::Warning("Failed to return to outpost"), true);
12731309
} break;
12741310
case GW::UI::UIMessage::kMapLoaded: {
12751311
last_online_status = static_cast<uint32_t>(GW::FriendListMgr::GetMyStatus());
12761312
} break;
12771313
case GW::UI::UIMessage::kShowCancelEnterMissionBtn: {
12781314
CheckPromptBeforeEnterMission(status);
1279-
if (status->blocked && !GW::Map::CancelEnterChallenge())
1280-
Log::Warning("Failed to cancel mission entry");
1315+
if (status->blocked)
1316+
GW::Map::CancelEnterChallenge() || (Log::Warning("Failed to cancel mission entry"), true);
12811317
break;
12821318
} break;
12831319
case GW::UI::UIMessage::kVanquishComplete: {
@@ -1286,6 +1322,9 @@ namespace {
12861322
if (block_vanquish_complete_popup)
12871323
GW::UI::SetFrameVisible(GW::UI::GetChildFrame(GW::UI::GetFrameByLabel(L"Game"), 6, 8), false) || (Log::Warning("Failed to hide vanquish popup"), true);
12881324
} break;
1325+
case GW::UI::UIMessage::kDialogButton: {
1326+
OnDialogButton((GW::UI::DialogButtonInfo*)wParam);
1327+
} break;
12891328
}
12901329
}
12911330

@@ -1585,7 +1624,6 @@ void GameSettings::Initialize()
15851624
GW::Hook::EnableHooks(CharacterStatIncreased_Func);
15861625
}
15871626

1588-
RegisterUIMessageCallback(&OnDialog_Entry, GW::UI::UIMessage::kSendDialog, bind_member(this, &GameSettings::OnFactionDonate));
15891627
RegisterUIMessageCallback(&OnDialog_Entry, GW::UI::UIMessage::kSendLoadSkillTemplate, &OnPreLoadSkillBar);
15901628
GW::StoC::RegisterPacketCallback(&OnDialog_Entry, GAME_SMSG_SKILL_UPDATE_SKILL_COUNT_1, OnUpdateSkillCount, -0x3000);
15911629
GW::StoC::RegisterPacketCallback(&OnDialog_Entry, GAME_SMSG_SKILL_UPDATE_SKILL_COUNT_2, OnUpdateSkillCount, -0x3000);
@@ -1645,20 +1683,6 @@ void GameSettings::Initialize()
16451683
GW::FriendListMgr::RegisterFriendStatusCallback(&FriendStatusCallback_Entry, FriendStatusCallback);
16461684
RegisterUIMessageCallback(&OnPreSendDialog_Entry, GW::UI::UIMessage::kSendPingWeaponSet, OnPingWeaponSet);
16471685

1648-
constexpr GW::UI::UIMessage dialog_ui_messages[] = {
1649-
GW::UI::UIMessage::kSendDialog,
1650-
GW::UI::UIMessage::kDialogBody,
1651-
GW::UI::UIMessage::kDialogButton
1652-
};
1653-
for (const auto message_id : dialog_ui_messages) {
1654-
RegisterUIMessageCallback(
1655-
&OnPostSendDialog_Entry,
1656-
message_id,
1657-
OnDialogUIMessage,
1658-
0x8000
1659-
);
1660-
}
1661-
16621686
constexpr GW::UI::UIMessage party_target_ui_messages[] = {
16631687
GW::UI::UIMessage::kTargetPlayerPartyMember,
16641688
GW::UI::UIMessage::kTargetNPCPartyMember,
@@ -1686,7 +1710,11 @@ void GameSettings::Initialize()
16861710
GW::UI::UIMessage::kShowCancelEnterMissionBtn,
16871711
GW::UI::UIMessage::kPartyDefeated,
16881712
GW::UI::UIMessage::kVanquishComplete,
1689-
GW::UI::UIMessage::kPartyShowConfirmDialog
1713+
GW::UI::UIMessage::kPartyShowConfirmDialog,
1714+
GW::UI::UIMessage::kVendorWindow,
1715+
GW::UI::UIMessage::kDialogButton,
1716+
GW::UI::UIMessage::kQuestAdded,
1717+
GW::UI::UIMessage::kSendSetActiveQuest
16901718
};
16911719
for (const auto message_id : post_ui_messages) {
16921720
RegisterUIMessageCallback(&OnPostUIMessage_HookEntry, message_id, OnPostUIMessage, 0x8000);
@@ -1699,13 +1727,6 @@ void GameSettings::Initialize()
16991727

17001728
set_window_title_delay = TIMER_INIT();
17011729

1702-
GW::UI::UIMessage ui_message_ids[] = {
1703-
GW::UI::UIMessage::kQuestAdded,
1704-
GW::UI::UIMessage::kSendSetActiveQuest
1705-
};
1706-
for (const auto message_id : ui_message_ids) {
1707-
RegisterUIMessageCallback(&OnQuestUIMessage_HookEntry, message_id, OnPostQuestUIMessage, 0x8000);
1708-
}
17091730
player_requested_active_quest_id = GW::QuestMgr::GetActiveQuestId();
17101731

17111732
last_online_status = static_cast<uint32_t>(GW::FriendListMgr::GetMyStatus());
@@ -1719,24 +1740,6 @@ void GameSettings::Initialize()
17191740
#endif
17201741
}
17211742

1722-
void GameSettings::OnDialogUIMessage(GW::HookStatus*, const GW::UI::UIMessage message_id, void* wparam, void*)
1723-
{
1724-
switch (message_id) {
1725-
case GW::UI::UIMessage::kDialogButton: {
1726-
const auto info = static_cast<GW::UI::DialogButtonInfo*>(wparam);
1727-
if (auto_open_locked_chest_with_key && wcscmp(info->message, L"\x8101\x7F88\x10A\x8101\x13BE\x1") == 0) {
1728-
// Auto use key
1729-
DialogModule::SendDialog(info->dialog_id);
1730-
}
1731-
if (auto_open_locked_chest && wcscmp(info->message, L"\x8101\x7f88\x010a\x8101\x730e\x1") == 0) {
1732-
// Auto use lockpick
1733-
DialogModule::SendDialog(info->dialog_id);
1734-
}
1735-
}
1736-
break;
1737-
}
1738-
}
1739-
17401743

17411744
void GameSettings::MessageOnPartyChange()
17421745
{
@@ -2584,48 +2587,6 @@ void GameSettings::OnAgentLoopingAnimation(GW::HookStatus*, const GW::Packet::St
25842587
GW::StoC::EmulatePacket(&pak2);
25852588
}
25862589

2587-
// Skip char name entry dialog when donating faction
2588-
void GameSettings::OnFactionDonate(GW::HookStatus* status, GW::UI::UIMessage, void* wparam, void*) const
2589-
{
2590-
const auto dialog_id = (uint32_t)wparam;
2591-
if (!(dialog_id == 0x87 && skip_entering_name_for_faction_donate)) {
2592-
return;
2593-
}
2594-
uint32_t allegiance = 2;
2595-
const auto raising_luxon_faction_cap = L"\x8102\x4A32\xAF32\xBDB5\x21AE";
2596-
const auto raising_kurzick_faction_cap = L"\x8102\x4A26\x814C\x89CC\x5B0";
2597-
// Look for "Raising Luxon/Kurzick faction cap" dialog option to check allegiance
2598-
for (const auto dialog : DialogModule::Instance().GetDialogButtons()) {
2599-
if (wcscmp(dialog->message, raising_luxon_faction_cap) == 0) {
2600-
allegiance = 1; // Luxon
2601-
}
2602-
if (wcscmp(dialog->message, raising_kurzick_faction_cap) == 0) {
2603-
allegiance = 0; // Kurzick
2604-
}
2605-
}
2606-
const uint32_t* current_faction = nullptr;
2607-
switch (allegiance) {
2608-
case 0: // Kurzick
2609-
current_faction = &GW::GetWorldContext()->current_kurzick;
2610-
break;
2611-
case 1: // Luxon
2612-
current_faction = &GW::GetWorldContext()->current_luxon;
2613-
break;
2614-
default: // Didn't find an allegiance, not the relevent dialog
2615-
return;
2616-
}
2617-
GW::GuildContext* c = GW::GetGuildContext();
2618-
if (!c || !c->player_guild_index || c->guilds[c->player_guild_index]->faction != allegiance) {
2619-
return; // Alliance isn't the right faction. Return here and the NPC will reply.
2620-
}
2621-
if (*current_faction < 5000) {
2622-
return; // Not enough to donate. Return here and the NPC will reply.
2623-
}
2624-
status->blocked = true;
2625-
GW::PlayerMgr::DepositFaction(allegiance);
2626-
GW::Agents::InteractAgent(GW::Agents::GetAgentByID(DialogModule::GetDialogAgent()));
2627-
}
2628-
26292590
// Show a message when player leaves the outpost
26302591
void GameSettings::OnPlayerLeaveInstance(GW::HookStatus*, const GW::Packet::StoC::PlayerLeaveInstance* pak)
26312592
{

GWToolboxdll/Modules/GameSettings.h

-11
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ class GameSettings : public ToolboxModule {
6868
static void OnAgentLoopingAnimation(GW::HookStatus*, const GW::Packet::StoC::GenericValue*);
6969
static void OnAgentMarker(GW::HookStatus* status, GW::Packet::StoC::GenericValue* pak);
7070
static void OnAgentEffect(GW::HookStatus*, const GW::Packet::StoC::GenericValue*);
71-
void OnFactionDonate(GW::HookStatus*, GW::UI::UIMessage, void*, void*) const;
7271
static void OnPartyDefeated(const GW::HookStatus*, GW::Packet::StoC::PartyDefeated*);
7372
void OnDungeonReward(GW::HookStatus*, GW::Packet::StoC::DungeonReward*) const;
7473
static void OnMapLoaded(GW::HookStatus*, GW::Packet::StoC::MapLoaded*);
@@ -83,12 +82,10 @@ class GameSettings : public ToolboxModule {
8382
static void OnWriteChat(GW::HookStatus* status, GW::UI::UIMessage msgid, void* wParam, void*);
8483
static void OnAgentStartCast(GW::HookStatus* status, GW::UI::UIMessage, void*, void*);
8584
static void OnOpenWiki(GW::HookStatus*, GW::UI::UIMessage, void*, void*);
86-
static void OnCast(GW::HookStatus*, uint32_t agent_id, uint32_t slot, uint32_t target_id, uint32_t call_target);
8785
static void OnAgentAdd(GW::HookStatus* status, const GW::Packet::StoC::AgentAdd* packet);
8886
static void OnUpdateAgentState(GW::HookStatus* status, GW::Packet::StoC::AgentState* packet);
8987
static void OnUpdateSkillCount(GW::HookStatus*, void* packet);
9088
static void OnAgentNameTag(GW::HookStatus* status, GW::UI::UIMessage msgid, void* wParam, void*);
91-
static void OnDialogUIMessage(GW::HookStatus*, GW::UI::UIMessage, void*, void*);
9289
private:
9390
void FactionEarnedCheckAndWarn();
9491
bool faction_checked = false;
@@ -100,15 +97,7 @@ class GameSettings : public ToolboxModule {
10097

10198
std::vector<uint32_t> available_dialog_ids{};
10299

103-
bool was_leading = true;
104-
bool hide_dungeon_chest_popup = false;
105-
bool skip_entering_name_for_faction_donate = false;
106-
bool stop_screen_shake = false;
107-
bool disable_camera_smoothing = false;
108100

109-
bool check_message_on_party_change = true;
110-
111-
bool is_prompting_hard_mode_mission = false;
112101

113102
GW::HookEntry VanquishComplete_Entry;
114103
GW::HookEntry ItemClickCallback_Entry;

0 commit comments

Comments
 (0)