diff --git a/Source/UI/UIMacroBlackListCheckWnd.cpp b/Source/UI/UIMacroBlackListCheckWnd.cpp index a32c75f8..82e01c72 100644 --- a/Source/UI/UIMacroBlackListCheckWnd.cpp +++ b/Source/UI/UIMacroBlackListCheckWnd.cpp @@ -1,11 +1,23 @@ #include "UI/UIMacroBlackListCheckWnd.h" #include "UI/Buttons/UIBitmapButton.h" +#include "Network/Connection/Connection.h" +#include "Network/Packets/PacketLengths.h" #include +#include +#include #include #include +namespace { + struct MacroBlackListCheckPacket { + /* 0000 */ std::int16_t id; + /* 0002 */ char text[16]; + }; + static_assert(sizeof(MacroBlackListCheckPacket) == 18); +} + // OFFSET: 0x007EB230 // FUNCTION: fn_09794 void UIMacroBlackListCheckWnd::Slot15(int width, int height) { @@ -66,3 +78,95 @@ void UIMacroBlackListCheckWnd::Slot15(int width, int height) { this->geometry.targetAlpha = 176; } + +// OFFSET: 0x007EC770 +// FUNCTION: fn_09796 +void UIMacroBlackListCheckWnd::Slot25(int, int) { +} + +// OFFSET: 0x007EC780 +// FUNCTION: fn_09797 +void UIMacroBlackListCheckWnd::Slot31(int, int) { +} + +// OFFSET: 0x007EC790 +// FUNCTION: fn_09798 +void UIMacroBlackListCheckWnd::Slot27(int, int) { +} + +// OFFSET: 0x007EC7A0 +// FUNCTION: fn_09799 +void UIMacroBlackListCheckWnd::Slot19() { + this->Invalidate(); +} + +// OFFSET: 0x007EC7B0 +// FUNCTION: fn_09800 +void UIMacroBlackListCheckWnd::ShuffleDigitButtons() { + unsigned char order[10]; + for (int i = 0; i < 10; ++i) { + order[i] = static_cast(i); + } + + std::mt19937 engine(std::random_device{}()); + std::shuffle(order, order + 10, engine); + + const int positions[11][2] = { + {303, 75}, {363, 75}, {423, 75}, {303, 135}, {363, 135}, {423, 135}, {303, 195}, {363, 195}, {423, 195}, {303, 255}, {363, 255}, + }; + + for (int i = 0; i < 10; ++i) { + this->digitButtons[i]->Move(positions[order[i]][0], positions[order[i]][1]); + } + + this->Invalidate(); +} + +// OFFSET: 0x007EC910 +// FUNCTION: fn_09801 +int UIMacroBlackListCheckWnd::SendMsg( + UIWindow* sender, int message, std::intptr_t argument1, std::intptr_t argument2, std::intptr_t argument3, std::intptr_t argument4 +) { + if (message != 6) { + return UIFrameWnd::SendMsg(sender, message, argument1, argument2, argument3, argument4); + } + + switch (argument1) { + case 184: + if (static_cast(this->inputLength - 4) <= 4) { + MacroBlackListCheckPacket packet; + packet.id = 0x0BDC; + strncpy_s(packet.text, sizeof(packet.text), this->input, _TRUNCATE); + CRagConnection& connection = GetRagConnection(); + connection.Send(g_packetLengths.FixedLength(packet.id), &packet); + this->inputLength = 0; + std::memset(this->input, 0, sizeof(this->input)); + return 0; + } + break; + case 293: + case 294: + case 295: + case 296: + case 297: + case 298: + case 299: + case 300: + case 301: + case 302: + this->ShuffleDigitButtons(); + if (this->inputLength < 8) { + this->input[this->inputLength] = static_cast('0' + (argument1 - 293)); + ++this->inputLength; + return 0; + } + break; + case 303: + this->inputLength = 0; + std::memset(this->input, 0, sizeof(this->input)); + this->ShuffleDigitButtons(); + break; + } + + return 0; +} diff --git a/Source/UI/UIMacroBlackListCheckWnd.h b/Source/UI/UIMacroBlackListCheckWnd.h index 193dd49d..fbe6d729 100644 --- a/Source/UI/UIMacroBlackListCheckWnd.h +++ b/Source/UI/UIMacroBlackListCheckWnd.h @@ -9,12 +9,20 @@ struct UIButtonContext; class UIMacroBlackListCheckWnd : public UIFrameWnd { public: void Slot15(int width, int height) override; + void Slot19() override; + void Slot25(int x, int y) override; + void Slot27(int x, int y) override; + void Slot31(int x, int y) override; + int SendMsg(UIWindow* sender, int message, std::intptr_t argument1, std::intptr_t argument2, std::intptr_t argument3, std::intptr_t argument4) override; + void ShuffleDigitButtons(); /* 00B4 */ UIBitmapButton* digitButtons[10]; /* 00DC */ UIBitmapButton* resetButton; /* 00E0 */ UIBitmapButton* okButton; /* 00E4 */ unsigned char unknown_00E4; /* 00E5 */ char digits[10]; + /* 00F0 */ int inputLength; + /* 00F4 */ char input[9]; protected: UIButtonContext* m_controls;