diff --git a/Source/UI/Edit/UIEditCtrl.h b/Source/UI/Edit/UIEditCtrl.h index 2e928a8b..3421d97f 100644 --- a/Source/UI/Edit/UIEditCtrl.h +++ b/Source/UI/Edit/UIEditCtrl.h @@ -37,6 +37,8 @@ struct UIEditContext { }; class UIEditCtrl : public UIWindow { + friend class UIMacroDetectorWnd; + public: UIEditCtrl(); UIEditCtrl(UIWindowContext& windows, UIEditContext& edit); diff --git a/Source/UI/UICaptchaPreviewWnd.h b/Source/UI/UICaptchaPreviewWnd.h index d013a148..03014302 100644 --- a/Source/UI/UICaptchaPreviewWnd.h +++ b/Source/UI/UICaptchaPreviewWnd.h @@ -8,6 +8,7 @@ class UICaptchaImage; class UICaptchaPreviewWnd : public UIFrameWnd { public: void Paint() override; + int SendMsg(UIWindow* sender, int message, std::intptr_t a, std::intptr_t b, std::intptr_t c, std::intptr_t d) override; void AddImageData(const void* data, int size); void ClearImageData(); diff --git a/Source/UI/UIMacroDetectorWnd.cpp b/Source/UI/UIMacroDetectorWnd.cpp index 895605c6..87bd171c 100644 --- a/Source/UI/UIMacroDetectorWnd.cpp +++ b/Source/UI/UIMacroDetectorWnd.cpp @@ -1,5 +1,11 @@ #include "UI/UIMacroDetectorWnd.h" +#include "Client/Input/Language.h" #include "Contents/MessageTable.h" +#include "Network/Connection/Connection.h" +#include "Network/Packets/PacketLengths.h" +#include "UI/Edit/UIEditCtrl.h" +#include "UI/UICaptchaPreviewWnd.h" +#include "UI/Window/WindowManagerWindows.h" #include "Utility/Text/FormatString.h" #include @@ -7,6 +13,14 @@ #include #include +namespace { +struct CaptchaAnswerPacket { + /* 0000 */ std::int16_t id; + /* 0002 */ char text[16]; +}; +static_assert(sizeof(CaptchaAnswerPacket) == 18); +} + // OFFSET: 0x007EDC00 // FUNCTION: fn_09814 void UIMacroDetectorWnd::Slot25(int, int) { @@ -74,3 +88,33 @@ void UIMacroDetectorWnd::InitImageData(unsigned short size) { this->m_imageData = static_cast(std::malloc(size)); std::memset(this->m_imageData, 0, size); } + +// OFFSET: 0x007EDCF0 +// FUNCTION: fn_09820 +int UICaptchaPreviewWnd::SendMsg(UIWindow* sender, int message, std::intptr_t a, std::intptr_t b, std::intptr_t c, std::intptr_t d) { + if (message == 6 && a == 201) { + this->m_frameContext->windows.CloseWindow(288); + } + return UIWindow::SendMsg(sender, message, a, b, c, d); +} + +// OFFSET: 0x007EDD40 +// FUNCTION: fn_09821 +int UIMacroDetectorWnd::SendMsg(UIWindow* sender, int message, std::intptr_t a, std::intptr_t b, std::intptr_t c, std::intptr_t d) { + if (message == 0) { + this->SendMsg(this, 6, 345, 0, 0, 0); + } else if (message == 6) { + if (a == 201) { + this->m_frameContext->windows.CloseWindow(284); + } else if (a == 345 && this->m_editCtrl->Length() != 0 && this->m_lastAnswer != this->m_editCtrl->Text()) { + CaptchaAnswerPacket packet; + packet.id = 0xA5C; + memcpy_s(packet.text, sizeof(packet.text), this->m_editCtrl->Text(), sizeof(packet.text)); + CRagConnection& connection = GetRagConnection(); + connection.Send(g_packetLengths.FixedLength(packet.id), &packet); + this->m_lastAnswer = this->m_editCtrl->Text(); + this->m_editCtrl->m_edit->input.ResetInput(); + } + } + return UIWindow::SendMsg(sender, message, a, b, c, d); +} diff --git a/Source/UI/UIMacroDetectorWnd.h b/Source/UI/UIMacroDetectorWnd.h index a21e759c..0d73c31a 100644 --- a/Source/UI/UIMacroDetectorWnd.h +++ b/Source/UI/UIMacroDetectorWnd.h @@ -6,6 +6,8 @@ #include #include +class UIEditCtrl; + class UIMacroDetectorWnd : public UIFrameWnd { public: void Slot19() override; @@ -13,6 +15,7 @@ public: 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 a, std::intptr_t b, std::intptr_t c, std::intptr_t d) override; void sub_8D2CE0(bool closeButton, const char* title, int width); void sub_A84360(int x, int y, const char* text, int bytes, int family, int height, std::uint32_t color, unsigned char bold, unsigned char italic); @@ -31,10 +34,20 @@ public: /* 00D4 */ std::uint32_t totalDuration; /* 00D8 */ std::uint32_t startTick; /* 00DC */ std::uint32_t messageDuration; - /* 00E0 */ unsigned char unknown_00E0[0x18]; + /* 00E0 */ std::string m_lastAnswer; /* 00F8 */ std::string message; /* 0110 */ std::uint32_t unknown_0110; /* 0114 */ std::uint32_t messageTick; + + /* 00B8 */ UIEditCtrl* m_editCtrl; }; +#if defined(_WIN32) && !defined(_WIN64) +static_assert(offsetof(UIMacroDetectorWnd, m_captchaKey) == 0xC0); +static_assert(offsetof(UIMacroDetectorWnd, m_imageData) == 0xC4); +static_assert(offsetof(UIMacroDetectorWnd, m_lastAnswer) == 0xE0); +static_assert(offsetof(UIMacroDetectorWnd, message) == 0xF8); +static_assert(offsetof(UIMacroDetectorWnd, messageTick) == 0x114); +#endif + #endif