diff --git a/Source/Client/ReplayPacketRecorder.cpp b/Source/Client/ReplayPacketRecorder.cpp index f9bc250c..d7daa73c 100644 --- a/Source/Client/ReplayPacketRecorder.cpp +++ b/Source/Client/ReplayPacketRecorder.cpp @@ -5,6 +5,7 @@ #include "Network/Packets/PacketLengths.h" #include "Network/Packets/PacketId.h" #include "UI/Window/UIWindow.h" +#include "UI/Window/UIWindowMgr.h" #include "UI/Window/WindowPolicy.h" #include @@ -271,12 +272,12 @@ namespace { // OFFSET: 0x00A82F80 // FUNCTION: fn_17000 -void WindowReplayRecorder::RecordDrop(int x, int y, const ModeDragState& drag, int target) { +void UIWindow::RecordDrop(int x, int y, const ModeDragState& drag, int target) { if (Replay::Instance().state != 2) { return; } - if (WindowPolicy(this->policy, this->restricted, 5, this->windowId) == 0) { + if (WindowPolicy(g_windowMgr.policy[0].actions, g_replayAnimationScaling != 0, 5, this->geometry.id) == 0) { return; } @@ -284,7 +285,7 @@ void WindowReplayRecorder::RecordDrop(int x, int y, const ModeDragState& drag, i std::memset(&packet, 0, sizeof(packet)); packet.marker = 0x038508AEu; packet.bytes = sizeof(packet); - packet.windowId = target == -1 ? this->windowId : target; + packet.windowId = target == -1 ? this->geometry.id : target; packet.x = x; packet.y = y; packet.source = drag.source; @@ -305,12 +306,12 @@ void WindowReplayRecorder::RecordDrop(int x, int y, const ModeDragState& drag, i packet.optionCount = drag.optionCount; std::memcpy(packet.options, drag.options, sizeof(packet.options)); - this->packets.Record(packet.bytes, &packet, 42, 0); + reinterpret_cast(&Replay::Instance())->Record(packet.bytes, &packet, 42, 0); } // OFFSET: 0x00A83180 // FUNCTION: fn_17001 -int WindowReplayRecorder::RecordData(std::uint16_t type, std::vector data) { +int UIWindow::RecordData(std::uint16_t type, std::vector data) { if (Replay::Instance().state != 2 || data.empty()) { return 0; } @@ -329,7 +330,7 @@ int WindowReplayRecorder::RecordData(std::uint16_t type, std::vectorwindowId; + packet.windowId = this->geometry.id; packet.value = value; packet.arguments[0] = argument1; packet.arguments[1] = argument2; packet.arguments[2] = argument3; packet.arguments[3] = argument4; - this->packets.Record(packet.bytes, &packet, 42, 0); + reinterpret_cast(&Replay::Instance())->Record(packet.bytes, &packet, 42, 0); } // OFFSET: 0x00A83440 // FUNCTION: fn_17003 -void WindowReplayRecorder::RecordText(int event, const char* text) { +void UIWindow::RecordText(int event, const char* text) { if (Replay::Instance().state != 2) { return; } @@ -357,8 +358,8 @@ void WindowReplayRecorder::RecordText(int event, const char* text) { std::memset(packet.text, 0, sizeof(packet.text)); packet.marker = 0x038B08AEu; packet.bytes = sizeof(packet); - packet.windowId = this->windowId; + packet.windowId = this->geometry.id; packet.event = event; std::memcpy(packet.text, text, std::min(static_cast(std::strlen(text)), 100)); - this->packets.Record(packet.bytes, &packet, 42, 0); + reinterpret_cast(&Replay::Instance())->Record(packet.bytes, &packet, 42, 0); } diff --git a/Source/Client/ReplayPacketRecorder.h b/Source/Client/ReplayPacketRecorder.h index 197c014f..92cfc64c 100644 --- a/Source/Client/ReplayPacketRecorder.h +++ b/Source/Client/ReplayPacketRecorder.h @@ -27,17 +27,5 @@ struct ReplayPacketRecorder { bool Record(std::uint16_t bytes, const void* packet, int event, std::uint32_t delay); }; -struct WindowReplayRecorder { - const int& windowId; - const int* policy; - const bool& restricted; - ReplayPacketRecorder& packets; - - void RecordDrop(int x, int y, const ModeDragState& drag, int target); - int RecordData(std::uint16_t type, std::vector data); - void RecordValues(int value, int argument1, int argument2, int argument3, int argument4); - void RecordWindowFlag(bool value); - void RecordText(int event, const char* text); -}; #endif diff --git a/Source/UI/Buttons/UIButton.cpp b/Source/UI/Buttons/UIButton.cpp index 25ff430e..c0c5a16c 100644 --- a/Source/UI/Buttons/UIButton.cpp +++ b/Source/UI/Buttons/UIButton.cpp @@ -174,7 +174,7 @@ void UIButton::Slot31(int x, int y) { } } else { if (id == 184 || id == 321) { - RecordEditTextsNoArg(parent); + parent->RecordEditTexts(); id = this->geometry.id; parent = this->parent; } diff --git a/Source/UI/Buttons/UITextureButton.cpp b/Source/UI/Buttons/UITextureButton.cpp index 9cdc196a..44733205 100644 --- a/Source/UI/Buttons/UITextureButton.cpp +++ b/Source/UI/Buttons/UITextureButton.cpp @@ -43,7 +43,7 @@ void UITextureButton::Slot31(int x, int y) { } } else { if (id == 184 || id == 321) { - RecordEditTextsNoArg(parent); + parent->RecordEditTexts(); id = this->geometry.id; } diff --git a/Source/UI/Edit/UIEditCtrl.cpp b/Source/UI/Edit/UIEditCtrl.cpp index 53a7d434..deb70c89 100644 --- a/Source/UI/Edit/UIEditCtrl.cpp +++ b/Source/UI/Edit/UIEditCtrl.cpp @@ -1717,7 +1717,7 @@ void UIItemSellWnd2::Slot26(int x, int y) { if (target) { this->Slot25(x, y); CGameMode* mode = static_cast(g_modeMgr.GetGameMode()); - this->m_recorder->RecordDrop(x, y, mode->drag, 160); + this->RecordDrop(x, y, mode->drag, 160); target->Slot10(x, y, reinterpret_cast(&mode->drag)); } } @@ -1734,7 +1734,7 @@ void UIItemSellWnd::Slot26(int x, int y) { if (target) { this->Slot25(x, y); CGameMode* mode = static_cast(g_modeMgr.GetGameMode()); - this->m_recorder->RecordDrop(x, y, mode->drag, 22); + this->RecordDrop(x, y, mode->drag, 22); target->Slot10(x, y, reinterpret_cast(&mode->drag)); } } @@ -4204,7 +4204,7 @@ void UIItemShopWnd2::Slot26(int x, int y) { if (target) { this->Slot25(x, y); CGameMode* mode = static_cast(g_modeMgr.GetGameMode()); - this->m_recorder->RecordDrop(x, y, mode->drag, 161); + this->RecordDrop(x, y, mode->drag, 161); target->Slot10(x, y, reinterpret_cast(&mode->drag)); } } @@ -4221,7 +4221,7 @@ void UIItemShopWnd::Slot26(int x, int y) { if (target) { this->Slot25(x, y); CGameMode* mode = static_cast(g_modeMgr.GetGameMode()); - this->m_recorder->RecordDrop(x, y, mode->drag, 24); + this->RecordDrop(x, y, mode->drag, 24); target->Slot10(x, y, reinterpret_cast(&mode->drag)); } } diff --git a/Source/UI/Item/UIItemSellWnd.h b/Source/UI/Item/UIItemSellWnd.h index 611cb8a0..f9b69218 100644 --- a/Source/UI/Item/UIItemSellWnd.h +++ b/Source/UI/Item/UIItemSellWnd.h @@ -6,7 +6,6 @@ #include -struct WindowReplayRecorder; class UIStaticText; class UIItemSellWnd : public UIItemBaseWnd { @@ -23,10 +22,7 @@ public: int SendMsg(UIWindow* sender, int message, std::intptr_t a, std::intptr_t b, std::intptr_t c, std::intptr_t d) override; protected: - union { - WindowReplayRecorder* m_recorder; - /* 00F0 */ UIStaticText* total; - }; + /* 00F0 */ UIStaticText* total; public: /* 00F4 */ ItemSellWndInfo* saved; diff --git a/Source/UI/Item/UIItemSellWnd2.h b/Source/UI/Item/UIItemSellWnd2.h index 9bd5d111..bc1958fe 100644 --- a/Source/UI/Item/UIItemSellWnd2.h +++ b/Source/UI/Item/UIItemSellWnd2.h @@ -7,7 +7,6 @@ #include #include -struct WindowReplayRecorder; class UIStaticText; class UIItemSellWnd2 : public UIItemBaseWnd { @@ -25,10 +24,7 @@ public: void Slot15(int width, int height) override; protected: - union { - WindowReplayRecorder* m_recorder; - /* 00F0 */ UIStaticText* total; - }; + /* 00F0 */ UIStaticText* total; public: /* 00F4 */ ItemSellWndInfo* saved; diff --git a/Source/UI/Item/UIItemShopWnd.h b/Source/UI/Item/UIItemShopWnd.h index 904f7cb6..0b81c0da 100644 --- a/Source/UI/Item/UIItemShopWnd.h +++ b/Source/UI/Item/UIItemShopWnd.h @@ -8,7 +8,6 @@ #include #include -struct WindowReplayRecorder; class UICheckBox; class UIStaticText; @@ -27,10 +26,7 @@ public: int SendMsg(UIWindow* sender, int message, std::intptr_t a, std::intptr_t b, std::intptr_t c, std::intptr_t d) override; protected: - union { - WindowReplayRecorder* m_recorder; - /* 00F0 */ UIStaticText* title; - }; + /* 00F0 */ UIStaticText* title; public: /* 00F4 */ UICheckBox* checkBox; diff --git a/Source/UI/Item/UIItemShopWnd2.h b/Source/UI/Item/UIItemShopWnd2.h index a260ffda..a095d68b 100644 --- a/Source/UI/Item/UIItemShopWnd2.h +++ b/Source/UI/Item/UIItemShopWnd2.h @@ -7,7 +7,6 @@ #include #include -struct WindowReplayRecorder; class UICheckBox; class UIStaticText; @@ -25,10 +24,7 @@ public: int SendMsg(UIWindow* sender, int message, std::intptr_t argument1, std::intptr_t argument2, std::intptr_t argument3, std::intptr_t argument4) override; protected: - union { - WindowReplayRecorder* m_recorder; - /* 00F0 */ UIStaticText* title; - }; + /* 00F0 */ UIStaticText* title; public: /* 00F4 */ UICheckBox* checkBox; diff --git a/Source/UI/Quest/UIRenewQuestUI.cpp b/Source/UI/Quest/UIRenewQuestUI.cpp index edd0d367..819fc87e 100644 --- a/Source/UI/Quest/UIRenewQuestUI.cpp +++ b/Source/UI/Quest/UIRenewQuestUI.cpp @@ -954,7 +954,7 @@ template void CUIListBoxEx::ClearData // OFFSET: 0x00A661F0 // FUNCTION: fn_16612 -void WindowReplayRecorder::RecordWindowFlag(bool value) { +void UIWindow::RecordWindowFlag(bool value) { this->RecordValues(6, 0xd5, value, 0, 0); if (UIWindow* window = g_windowMgr.LookupWindow(0xcc)) { window->Show(value); @@ -1101,7 +1101,7 @@ int CUIRenewQuestUI::SendMsg(UIWindow* sender, int message, std::intptr_t a, std const bool checked = b != 0; this->checkBox->checked = checked; this->checkBox->Invalidate(); - reinterpret_cast(this)->RecordValues(6, 0xD5, checked, 0, 0); + this->RecordValues(6, 0xD5, checked, 0, 0); if (UIWindow* window = g_windowMgr.LookupWindow(0xCC)) { window->Show(checked); } @@ -1593,7 +1593,7 @@ void CUIRenewQuestUI::Slot15(int width, int height) { processButton->SetSize(30, 100); processButton->Move(0, 0); processButton->SetOnClick([this]() { - reinterpret_cast(this)->RecordValues(0x16, 1, 0, 0, 0); + this->RecordValues(0x16, 1, 0, 0, 0); for (RenewQuestUI::CUIQuestList* list : this->questLists) { if (list->type == 1) { if (list->list) { @@ -1648,7 +1648,7 @@ void CUIRenewQuestUI::Slot15(int width, int height) { recommendedButton->SetSize(30, 100); recommendedButton->Move(0, 101); recommendedButton->SetOnClick([this]() { - reinterpret_cast(this)->RecordValues(0x16, 2, 0, 0, 0); + this->RecordValues(0x16, 2, 0, 0, 0); for (RenewQuestUI::CUIQuestList* list : this->questLists) { if (list->type == 2) { if (list->list) { @@ -1711,7 +1711,7 @@ void CUIRenewQuestUI::Slot15(int width, int height) { holdButton->SetSize(30, 100); holdButton->Move(0, 202); holdButton->SetOnClick([this]() { - reinterpret_cast(this)->RecordValues(0x16, 4, 0, 0, 0); + this->RecordValues(0x16, 4, 0, 0, 0); for (RenewQuestUI::CUIQuestList* list : this->questLists) { if (list->type == 4) { if (list->list) { @@ -1763,7 +1763,7 @@ void CUIRenewQuestUI::Slot15(int width, int height) { waitButton->SetSize(30, 100); waitButton->Move(0, 303); waitButton->SetOnClick([this]() { - reinterpret_cast(this)->RecordValues(0x16, 8, 0, 0, 0); + this->RecordValues(0x16, 8, 0, 0, 0); for (RenewQuestUI::CUIQuestList* list : this->questLists) { if (list->type == 8) { if (list->list) { @@ -1814,7 +1814,7 @@ void CUIRenewQuestUI::Slot15(int width, int height) { this->checkBox = new CUICheckBox(); this->checkBox->SetSize(10, 10); this->checkBox->Move(38, 448); - this->checkBox->SetOnCheck([this](bool checked) { reinterpret_cast(this)->RecordWindowFlag(checked); }); + this->checkBox->SetOnCheck([this](bool checked) { this->RecordWindowFlag(checked); }); this->checkBox->disabled = 0; this->checkBox->Invalidate(); const std::uint8_t checkInactive[] = { diff --git a/Source/UI/Quest/UIRenewQuestWnd.cpp b/Source/UI/Quest/UIRenewQuestWnd.cpp index 009936a3..4cb749ca 100644 --- a/Source/UI/Quest/UIRenewQuestWnd.cpp +++ b/Source/UI/Quest/UIRenewQuestWnd.cpp @@ -1065,7 +1065,7 @@ static void SetRecommendedQuestSummary(CRenewQuestMgr* mgr, unsigned int id, std int UIRenewQuestWnd::SendMsg(UIWindow* sender, int message, std::intptr_t argument1, std::intptr_t argument2, std::intptr_t argument3, std::intptr_t argument4) { if (message == 22 || argument1 == 0xD5) { - reinterpret_cast(this)->RecordValues(message, argument1, argument2, argument3, argument4); + this->RecordValues(message, argument1, argument2, argument3, argument4); } switch (message) { diff --git a/Source/UI/Shortcuts/UIShortCutWnd.cpp b/Source/UI/Shortcuts/UIShortCutWnd.cpp index d0725b45..50712211 100644 --- a/Source/UI/Shortcuts/UIShortCutWnd.cpp +++ b/Source/UI/Shortcuts/UIShortCutWnd.cpp @@ -1079,7 +1079,7 @@ bool UINavigationWnd::LoadRoute(int index) { fclose(file); if (g_navigationManager.StateCount() > 0) { - reinterpret_cast(this)->RecordData(0x38F, g_navigationManager.WriteStates()); + this->RecordData(0x38F, g_navigationManager.WriteStates()); } this->FillRouteList(); diff --git a/Source/UI/StylingShop/UIStylingShopWnd.cpp b/Source/UI/StylingShop/UIStylingShopWnd.cpp index 2f550c2c..250a26c6 100644 --- a/Source/UI/StylingShop/UIStylingShopWnd.cpp +++ b/Source/UI/StylingShop/UIStylingShopWnd.cpp @@ -174,7 +174,7 @@ void UIStylingShopButton::Slot31(int, int) { } } else { if (id == 184 || id == 321) { - RecordEditTextsNoArg(parent); + parent->RecordEditTexts(); id = this->geometry.id; parent = this->parent; } diff --git a/Source/UI/Window/UIWindow.cpp b/Source/UI/Window/UIWindow.cpp index 313f5101..abe4091d 100644 --- a/Source/UI/Window/UIWindow.cpp +++ b/Source/UI/Window/UIWindow.cpp @@ -2215,8 +2215,8 @@ static_assert(sizeof(EditTextsRecord) == 0x1000); // OFFSET: 0x00A834E0 // FUNCTION: fn_17004 -int UIWindow::RecordEditTexts(WindowReplayRecorder& recorder) { - if (Replay::Instance().state != 2 || !WindowPolicy(recorder.policy, recorder.restricted, 6, this->geometry.id)) { +int UIWindow::RecordEditTexts() { + if (Replay::Instance().state != 2 || !WindowPolicy(g_windowMgr.policy[0].actions, g_replayAnimationScaling != 0, 6, this->geometry.id)) { return 0; } @@ -2254,7 +2254,7 @@ int UIWindow::RecordEditTexts(WindowReplayRecorder& recorder) { record.bytes = static_cast(offset); record.marker = 0x038608AEu; record.windowId = this->geometry.id; - recorder.packets.Record(record.bytes, &record, 41, 0); + reinterpret_cast(&Replay::Instance())->Record(record.bytes, &record, 41, 0); return offset; } @@ -3314,7 +3314,7 @@ bool UINavigationV4Wnd::LoadRoute(int index) { g_navigationManager.BuildSingleNodePaths(); if (g_navigationManager.StateCount() > 0) { - reinterpret_cast(this)->RecordData(0x38F, g_navigationManager.WriteStates()); + this->RecordData(0x38F, g_navigationManager.WriteStates()); } this->FillRouteGroups(); diff --git a/Source/UI/Window/UIWindow.h b/Source/UI/Window/UIWindow.h index eeb2858d..b96461b1 100644 --- a/Source/UI/Window/UIWindow.h +++ b/Source/UI/Window/UIWindow.h @@ -26,7 +26,7 @@ class CBitmapRes; class CActRes; class TextureCache; class UITextViewer; -struct WindowReplayRecorder; +struct ModeDragState; struct ITEM_INFO; class UIItemTagButton; @@ -177,7 +177,12 @@ public: const char* TruncateText(const char* text, int maxBytes); const char* ClipTextToWidth(const char* text, int maxWidth, int family, int height, unsigned char bold); void RecordResponse(int response, std::intptr_t b, std::intptr_t c, std::intptr_t d); - int RecordEditTexts(WindowReplayRecorder& recorder); + int RecordEditTexts(); + void RecordDrop(int x, int y, const ModeDragState& drag, int target); + int RecordData(std::uint16_t type, std::vector data); + void RecordValues(int value, int argument1, int argument2, int argument3, int argument4); + void RecordWindowFlag(bool value); + void RecordText(int event, const char* text); int RestoreEditTexts(const unsigned char* data); void DrawActionSprite( const CSprRes* sprite, const CActRes* action, int x, int y, int width, int height, int interval, bool scaled, const CBitmapRes* background @@ -233,16 +238,6 @@ private: UIWindow& operator=(const UIWindow&) = delete; }; -// INLINED -__forceinline void RecordEditTextsNoArg(UIWindow* window) { - union { - int (UIWindow::*method)(WindowReplayRecorder&); - void (__thiscall* call)(UIWindow*); - } convert; - convert.method = &UIWindow::RecordEditTexts; - convert.call(window); -} - extern std::uint32_t g_windowUid; #if defined(_WIN32) && !defined(_WIN64) diff --git a/Source/UI/Window/UIWindowMgr.cpp b/Source/UI/Window/UIWindowMgr.cpp index b6a1949b..578e5271 100644 --- a/Source/UI/Window/UIWindowMgr.cpp +++ b/Source/UI/Window/UIWindowMgr.cpp @@ -1975,7 +1975,7 @@ bool UIWindowMgr::sub_A8CA20() { window = this->unknown_0314; if (window != nullptr) { if (Replay::Instance().state == 2) { - RecordEditTextsNoArg(window); + window->RecordEditTexts(); } window->SendMsg(nullptr, 0, 0, 0, 0, 0); return true; @@ -1983,7 +1983,7 @@ bool UIWindowMgr::sub_A8CA20() { window = this->unknown_0318; if (window != nullptr) { if (Replay::Instance().state == 2) { - RecordEditTextsNoArg(window); + window->RecordEditTexts(); } window->SendMsg(nullptr, 0, 0, 0, 0, 0); return true; @@ -2027,7 +2027,7 @@ bool UIWindowMgr::sub_A8CA20() { handled = false; } if (Replay::Instance().state == 2 && handled) { - RecordEditTextsNoArg(this->hoverWindow->Root()); + this->hoverWindow->Root()->RecordEditTexts(); } if (g_windowCloseByte == 0) { handled = true; @@ -2041,7 +2041,7 @@ bool UIWindowMgr::sub_A8CA20() { if (window == nullptr) { if (this->window_01C8 != nullptr && g_inputSuggestionsEnabled == 1) { handled = false; - RecordEditTextsNoArg(this->window_01C8); + this->window_01C8->RecordEditTexts(); window = this->window_01C8; } else { for (UIWindow* item : this->rendered) { @@ -2049,7 +2049,7 @@ bool UIWindowMgr::sub_A8CA20() { continue; } if (g_replayAnimationScaling == 0) { - RecordEditTextsNoArg(item->Root()); + item->Root()->RecordEditTexts(); } item->SendMsg(nullptr, 0, 0, 0, 0, 0); } diff --git a/Source/UI/Window/WindowMgrState.cpp b/Source/UI/Window/WindowMgrState.cpp index 64ac12ca..8c9098cc 100644 --- a/Source/UI/Window/WindowMgrState.cpp +++ b/Source/UI/Window/WindowMgrState.cpp @@ -1095,7 +1095,7 @@ bool UIWindowMgr::DropAt(int x, int y, ModeDragState* drag) { const int localX = x - offsetX; const int localY = y - offsetY; - reinterpret_cast(window)->RecordDrop(localX, localY, *drag, -1); + window->RecordDrop(localX, localY, *drag, -1); drag->unknown_038C = reinterpret_cast(window); if (this->window_01EC != window->Root()) { window->Slot10(localX, localY, reinterpret_cast(drag));