Reconstruct readable C++ and organize cohesive source subsystems
Administrative source import: native x86 compilation passed for 423 authored units. Source placement and submission states are migrated separately; this commit does not imply peer acceptance.
Previous head: 35d2a8cb36
Payload SHA256: 592f016d2730c5593bb653aa054c1e5f76a6df72c8f5a09e66f74876e2e33dee
This commit is contained in:
parent
35d2a8cb36
commit
a47d20f8be
890 changed files with 11796 additions and 16664 deletions
116
Source/Client/Input/ImeInput.cpp
Normal file
116
Source/Client/Input/ImeInput.cpp
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
#include "Client/Input/ImeInput.h"
|
||||
#include "Client/Input/TraditionalKeyInput.h"
|
||||
#include "Utility/Text/LanguageCharset.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <intrin.h>
|
||||
|
||||
// OFFSET: 0x00ACEF00
|
||||
// FUNCTION: fn_17793
|
||||
LRESULT ImeInput::Message(HWND, UINT message, WPARAM value, LPARAM flags, std::uint8_t& handled) {
|
||||
const auto options = static_cast<std::uint16_t>(flags);
|
||||
|
||||
switch (message) {
|
||||
case WM_INPUTLANGCHANGE:
|
||||
this->language = options;
|
||||
this->codePage = this->languageCodePage ? LanguageCodePage(options) : this->fallbackCodePage;
|
||||
break;
|
||||
case WM_IME_STARTCOMPOSITION:
|
||||
this->input.DeleteSelection();
|
||||
break;
|
||||
case WM_IME_ENDCOMPOSITION:
|
||||
if (this->traditional) {
|
||||
this->traditional->ClearKeys();
|
||||
}
|
||||
this->input.candidate.clear();
|
||||
break;
|
||||
case WM_IME_COMPOSITION:
|
||||
if (options & GCS_COMPSTR) {
|
||||
this->input.RefreshComposition(this->codePage);
|
||||
if (this->traditional) {
|
||||
this->traditional->FilterCandidate(this->input.candidate);
|
||||
this->traditional->RetainSingleKey();
|
||||
}
|
||||
}
|
||||
|
||||
if (options & GCS_CURSORPOS) {
|
||||
HIMC context = ImmGetContext(this->input.window);
|
||||
if (context) {
|
||||
ImmGetCompositionStringA(context, GCS_CURSORPOS, &this->compositionCursor, sizeof(this->compositionCursor));
|
||||
ImmReleaseContext(this->input.window, context);
|
||||
} else {
|
||||
this->input.candidate.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (options & GCS_RESULTSTR) {
|
||||
HIMC context = ImmGetContext(this->input.window);
|
||||
if (context) {
|
||||
WCHAR wide[256];
|
||||
char converted[256];
|
||||
const auto bytes = static_cast<std::uint32_t>(ImmGetCompositionStringW(context, GCS_RESULTSTR, wide, sizeof(wide)));
|
||||
const unsigned size = WideCharToMultiByte(this->codePage, 0, wide, bytes >> 1, converted, sizeof(converted), nullptr, nullptr);
|
||||
|
||||
if (size >= sizeof(converted)) {
|
||||
__fastfail(FAST_FAIL_RANGE_CHECK_FAILURE);
|
||||
}
|
||||
|
||||
converted[size] = 0;
|
||||
ImmReleaseContext(this->input.window, context);
|
||||
this->input.Insert(converted);
|
||||
} else {
|
||||
this->input.candidate.clear();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WM_IME_NOTIFY:
|
||||
if (value == IMN_OPENCANDIDATE || value == IMN_CHANGECANDIDATE) {
|
||||
HIMC context = ImmGetContext(this->input.window);
|
||||
if (context) {
|
||||
const auto bytes = ImmGetCandidateListW(context, 0, nullptr, 0);
|
||||
if (static_cast<std::int32_t>(bytes) > 0) {
|
||||
this->candidateStorage.resize(bytes);
|
||||
this->candidateList = reinterpret_cast<CANDIDATELIST*>(this->candidateStorage.data());
|
||||
ImmGetCandidateListW(context, 0, this->candidateList, bytes);
|
||||
this->input.compositionState = this->candidateList->dwCount;
|
||||
this->selection = this->candidateList->dwSelection;
|
||||
this->pageSize = std::min<unsigned>(this->candidateList->dwPageSize, 9);
|
||||
} else {
|
||||
this->input.compositionState = 0;
|
||||
}
|
||||
|
||||
ImmReleaseContext(this->input.window, context);
|
||||
} else {
|
||||
this->input.compositionState = 0;
|
||||
}
|
||||
} else if (value == IMN_CLOSECANDIDATE) {
|
||||
this->input.compositionState = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
handled = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
handled = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACD840
|
||||
// FUNCTION: fn_17770
|
||||
const char* ImeInput::Candidate(int index) const {
|
||||
// STATIC: 0x016D3978
|
||||
// GLOBAL: gl_24374
|
||||
static char output[256];
|
||||
if (index >= this->input.compositionState) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const unsigned char* bytes = this->candidateStorage.data();
|
||||
const WCHAR* text = reinterpret_cast<const WCHAR*>(bytes + this->candidateList->dwOffset[index]);
|
||||
const unsigned size = WideCharToMultiByte(this->codePage, 0, text, -1, output, sizeof(output), nullptr, nullptr);
|
||||
output[std::min<unsigned>(size, 255)] = 0;
|
||||
|
||||
return output;
|
||||
}
|
||||
30
Source/Client/Input/ImeInput.h
Normal file
30
Source/Client/Input/ImeInput.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef RAGNAROK_SOURCE_CLIENT_INPUT_IMEINPUT_H
|
||||
#define RAGNAROK_SOURCE_CLIENT_INPUT_IMEINPUT_H
|
||||
|
||||
#include "Client/Input/TextInputBuffer.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <imm.h>
|
||||
#include <vector>
|
||||
|
||||
struct TraditionalKeyInput;
|
||||
|
||||
struct ImeInput {
|
||||
TextInputBuffer& input;
|
||||
std::uint16_t& language;
|
||||
unsigned& codePage;
|
||||
const bool& languageCodePage;
|
||||
const unsigned& fallbackCodePage;
|
||||
std::vector<unsigned char>& candidateStorage;
|
||||
CANDIDATELIST*& candidateList;
|
||||
unsigned& selection;
|
||||
unsigned& pageSize;
|
||||
int& compositionCursor;
|
||||
TraditionalKeyInput* traditional;
|
||||
|
||||
LRESULT Message(HWND unused, UINT message, WPARAM value, LPARAM flags, std::uint8_t& handled);
|
||||
|
||||
const char* Candidate(int index) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
24
Source/Client/Input/InputCharset.cpp
Normal file
24
Source/Client/Input/InputCharset.cpp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#include "Client/Input/InputCharset.h"
|
||||
#include "Utility/Text/LanguageCharset.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
// OFFSET: 0x00ACE360
|
||||
// FUNCTION: fn_17781
|
||||
const char* InputCharset::Prefix(bool alternate) const {
|
||||
// STATIC: 0x016D3964
|
||||
// GLOBAL: gl_24373
|
||||
static char prefix[8];
|
||||
|
||||
if (this->enabled) {
|
||||
std::sprintf(prefix, "|%02x", LanguageCharset(alternate ? this->alternateLanguage : this->language));
|
||||
} else {
|
||||
prefix[0] = '\0';
|
||||
}
|
||||
|
||||
return prefix;
|
||||
}
|
||||
|
||||
unsigned InputCharset::CodePage(unsigned fallback) const {
|
||||
return this->enabled ? LanguageCodePage(this->language) : fallback;
|
||||
}
|
||||
16
Source/Client/Input/InputCharset.h
Normal file
16
Source/Client/Input/InputCharset.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef RAGNAROK_SOURCE_CLIENT_INPUT_INPUTCHARSET_H
|
||||
#define RAGNAROK_SOURCE_CLIENT_INPUT_INPUTCHARSET_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
struct InputCharset {
|
||||
const bool& enabled;
|
||||
const std::uint16_t& language;
|
||||
const std::uint16_t& alternateLanguage;
|
||||
|
||||
const char* Prefix(bool alternate) const;
|
||||
|
||||
unsigned CodePage(unsigned fallback) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
125
Source/Client/Input/Mouse.cpp
Normal file
125
Source/Client/Input/Mouse.cpp
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
#include "Client/Input/Mouse.h"
|
||||
#include "Render/DeviceContext/DCSurface.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <timeapi.h>
|
||||
|
||||
// OFFSET: 0x006370C0
|
||||
// FUNCTION: fn_04724
|
||||
// OFFSET: 0x006370D0
|
||||
// FUNCTION: fn_04725
|
||||
CMouse::~CMouse() = default;
|
||||
|
||||
// OFFSET: 0x00637100
|
||||
// FUNCTION: fn_04726
|
||||
void CMouse::Update() {
|
||||
if (!this->active) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->deltaX = this->pendingX - this->x;
|
||||
this->deltaY = this->pendingY - this->y;
|
||||
this->x = this->pendingX;
|
||||
this->y = this->pendingY;
|
||||
const std::uint32_t now = timeGetTime();
|
||||
|
||||
for (unsigned index = 0; index < 2; ++index) {
|
||||
if (this->deltaX != 0 || this->deltaY != 0) {
|
||||
this->pressTicks[index] = now - this->doubleClickTime;
|
||||
}
|
||||
|
||||
if (this->pendingButtons[index]) {
|
||||
if (this->previousButtons[index]) {
|
||||
this->buttons[index] = 2;
|
||||
} else if (now >= this->pressTicks[index] + this->doubleClickTime) {
|
||||
this->pressTicks[index] = now;
|
||||
this->buttons[index] = 1;
|
||||
} else {
|
||||
this->buttons[index] = 4;
|
||||
this->pressTicks[index] = now - this->doubleClickTime;
|
||||
}
|
||||
} else {
|
||||
this->buttons[index] = this->previousButtons[index] ? 3 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
this->wheel = this->pendingWheel;
|
||||
this->pendingWheel = 0;
|
||||
this->previousButtons[0] = this->pendingButtons[0];
|
||||
this->previousButtons[1] = this->pendingButtons[1];
|
||||
}
|
||||
|
||||
// OFFSET: 0x006371E0
|
||||
// FUNCTION: fn_04727
|
||||
void CMouse::Reset() {
|
||||
this->buttons[1] = 0;
|
||||
this->buttons[0] = 0;
|
||||
this->previousButtons[0] = 0;
|
||||
this->previousButtons[1] = 0;
|
||||
this->pendingButtons[0] = 0;
|
||||
this->pendingButtons[1] = 0;
|
||||
}
|
||||
|
||||
// OFFSET: 0x00637200
|
||||
// FUNCTION: fn_04728
|
||||
int CMouse::Center() {
|
||||
const int halfWidth = static_cast<int>(GetRenderSystemHolder()->Width()) / 2;
|
||||
this->pendingX = halfWidth;
|
||||
this->x = halfWidth;
|
||||
const int halfHeight = static_cast<int>(GetRenderSystemHolder()->Height()) / 2;
|
||||
this->pendingY = halfHeight;
|
||||
this->y = halfHeight;
|
||||
|
||||
return halfHeight;
|
||||
}
|
||||
|
||||
// OFFSET: 0x00637240
|
||||
// FUNCTION: fn_04729
|
||||
void CMouse::SetX(int value) {
|
||||
this->pendingX = value;
|
||||
this->x = value;
|
||||
}
|
||||
|
||||
// OFFSET: 0x00637250
|
||||
// FUNCTION: fn_04730
|
||||
void CMouse::SetY(int value) {
|
||||
this->pendingY = value;
|
||||
this->y = value;
|
||||
}
|
||||
|
||||
// OFFSET: 0x00637260
|
||||
// FUNCTION: fn_04731
|
||||
void CMouse::Message(CMouse& global, HWND mainWindow, HWND source, UINT message, WPARAM keys, LPARAM) {
|
||||
if (global.active != 1) {
|
||||
global.Reset();
|
||||
global.active = 1;
|
||||
}
|
||||
|
||||
switch (message) {
|
||||
case WM_MOUSEMOVE: {
|
||||
POINT point;
|
||||
GetCursorPos(&point);
|
||||
ScreenToClient(mainWindow, &point);
|
||||
this->pendingX = point.x;
|
||||
this->pendingY = point.y;
|
||||
break;
|
||||
}
|
||||
case WM_LBUTTONDOWN:
|
||||
this->pendingButtons[0] = 1;
|
||||
SetCapture(source);
|
||||
break;
|
||||
case WM_LBUTTONUP:
|
||||
this->pendingButtons[0] = 0;
|
||||
ReleaseCapture();
|
||||
break;
|
||||
case WM_RBUTTONDOWN:
|
||||
this->pendingButtons[1] = 1;
|
||||
break;
|
||||
case WM_RBUTTONUP:
|
||||
this->pendingButtons[1] = 0;
|
||||
break;
|
||||
case WM_MOUSEWHEEL:
|
||||
this->pendingWheel = GET_WHEEL_DELTA_WPARAM(keys);
|
||||
break;
|
||||
}
|
||||
}
|
||||
39
Source/Client/Input/Mouse.h
Normal file
39
Source/Client/Input/Mouse.h
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#ifndef RAGNAROK_SOURCE_CLIENT_INPUT_MOUSE_H
|
||||
#define RAGNAROK_SOURCE_CLIENT_INPUT_MOUSE_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <windows.h>
|
||||
|
||||
class CMouse {
|
||||
public:
|
||||
virtual ~CMouse();
|
||||
void Update();
|
||||
void Reset();
|
||||
int Center();
|
||||
void SetX(int value);
|
||||
void SetY(int value);
|
||||
|
||||
void Message(CMouse& global, HWND mainWindow, HWND source, UINT message, WPARAM keys, LPARAM unused);
|
||||
|
||||
/* 0004 */ int x = 0;
|
||||
/* 0008 */ int y = 0;
|
||||
/* 000C */ int deltaX = 0;
|
||||
/* 0010 */ int deltaY = 0;
|
||||
/* 0014 */ int buttons[2] = {};
|
||||
/* 001C */ int wheel = 0;
|
||||
/* 0020 */ int pendingX = 0;
|
||||
/* 0024 */ int pendingY = 0;
|
||||
/* 0028 */ int pendingWheel = 0;
|
||||
/* 002C */ std::uint8_t previousButtons[2] = {};
|
||||
/* 002E */ std::uint8_t pendingButtons[2] = {};
|
||||
/* 0030 */ std::uint32_t pressTicks[2] = {};
|
||||
/* 0038 */ std::uint32_t doubleClickTime = 500;
|
||||
/* 003C */ std::uint8_t active = 1;
|
||||
std::uint8_t unknown_003D[3] = {};
|
||||
};
|
||||
|
||||
#if defined(_WIN32) && !defined(_WIN64)
|
||||
static_assert(sizeof(CMouse) == 64);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
309
Source/Client/Input/TextInputBuffer.cpp
Normal file
309
Source/Client/Input/TextInputBuffer.cpp
Normal file
|
|
@ -0,0 +1,309 @@
|
|||
#include "Client/Input/TextInputBuffer.h"
|
||||
#include "UI/Window/UIWindow.h"
|
||||
#include "UI/Window/WindowManagerWindows.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <imm.h>
|
||||
|
||||
// OFFSET: 0x00ACF2A0
|
||||
// FUNCTION: fn_17794
|
||||
void TextInputBuffer::CancelComposition() {
|
||||
HIMC context = ImmGetContext(this->window);
|
||||
|
||||
if (context) {
|
||||
ImmNotifyIME(context, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
|
||||
ImmReleaseContext(this->window, context);
|
||||
}
|
||||
|
||||
this->text.clear();
|
||||
this->cursor = 0;
|
||||
this->anchor = 0;
|
||||
this->composition.clear();
|
||||
this->candidate.clear();
|
||||
this->compositionState = 0;
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACD700
|
||||
// FUNCTION: fn_17767
|
||||
void TextInputBuffer::DeleteSelection() {
|
||||
if (this->cursor == this->anchor) {
|
||||
return;
|
||||
}
|
||||
|
||||
const int begin = std::min(this->cursor, this->anchor);
|
||||
const int length = std::max(this->cursor, this->anchor) - begin;
|
||||
this->text.erase(static_cast<std::size_t>(begin), length);
|
||||
this->cursor = begin;
|
||||
this->anchor = begin;
|
||||
|
||||
if (this->suggestionsEnabled && this->chatOpen && this->chatInput && this->focused == this->chatInput) {
|
||||
this->suggestions.Update(this->text.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACD360
|
||||
// FUNCTION: fn_17760
|
||||
void TextInputBuffer::Insert(const char* value) {
|
||||
this->DeleteSelection();
|
||||
this->text.insert(static_cast<std::size_t>(this->cursor), value, std::strlen(value));
|
||||
this->anchor = this->cursor + static_cast<int>(std::strlen(value));
|
||||
this->cursor = this->anchor;
|
||||
|
||||
if (this->suggestionsEnabled && this->chatOpen && this->chatInput && this->focused == this->chatInput) {
|
||||
this->suggestions.Update(this->text.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACF590
|
||||
// FUNCTION: fn_17797
|
||||
void TextInputBuffer::Select(int anchor, int cursor) {
|
||||
this->anchor = anchor;
|
||||
this->cursor = cursor;
|
||||
this->anchor = std::clamp(this->anchor, 0, static_cast<int>(this->text.size()));
|
||||
this->cursor = std::clamp(this->cursor, 0, static_cast<int>(this->text.size()));
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACE3C0
|
||||
// FUNCTION: fn_17782
|
||||
void TextInputBuffer::CopyDisplayText(std::string& output) const {
|
||||
if (&output != &this->text) {
|
||||
output = this->text;
|
||||
}
|
||||
|
||||
if (!this->candidate.empty()) {
|
||||
output.insert(static_cast<std::size_t>(this->cursor), this->candidate.c_str(), std::strlen(this->candidate.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACE420
|
||||
// FUNCTION: fn_17783
|
||||
void TextInputBuffer::Selection(int& anchor, int& cursor) const {
|
||||
anchor = this->anchor;
|
||||
cursor = this->cursor;
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACDD20
|
||||
// FUNCTION: fn_17775
|
||||
void TextInputBuffer::RefreshComposition(unsigned codePage) {
|
||||
HIMC context = ImmGetContext(this->window);
|
||||
if (!context) {
|
||||
this->candidate.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
WCHAR wide[256];
|
||||
char converted[256];
|
||||
const auto bytes = static_cast<std::uint32_t>(ImmGetCompositionStringW(context, GCS_COMPSTR, wide, sizeof(wide)));
|
||||
const unsigned size = WideCharToMultiByte(codePage, 0, wide, bytes >> 1, converted, sizeof(converted), nullptr, nullptr);
|
||||
ImmReleaseContext(this->window, context);
|
||||
this->candidate.assign(converted, size);
|
||||
|
||||
char combined[256];
|
||||
const std::size_t committed = std::min<std::size_t>(this->text.size(), 255);
|
||||
std::memcpy(combined, this->text.data(), committed);
|
||||
const std::size_t pending = std::min<std::size_t>(this->candidate.size(), 255 - committed);
|
||||
std::memcpy(combined + committed, this->candidate.data(), pending);
|
||||
combined[committed + pending] = 0;
|
||||
|
||||
if (this->suggestionsEnabled && this->chatOpen && this->chatInput && this->focused == this->chatInput) {
|
||||
this->suggestions.Update(combined);
|
||||
}
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACD5C0
|
||||
// FUNCTION: fn_17765
|
||||
void TextInputBuffer::CopySelection(bool password) {
|
||||
const int length = std::max(this->cursor, this->anchor) - std::min(this->cursor, this->anchor);
|
||||
if (!length || !OpenClipboard(this->window)) {
|
||||
return;
|
||||
}
|
||||
|
||||
HGLOBAL memory = GlobalAlloc(GMEM_DDESHARE, static_cast<std::uint32_t>(length + 1));
|
||||
if (memory) {
|
||||
auto* data = static_cast<char*>(GlobalLock(memory));
|
||||
if (data) {
|
||||
const int begin = std::min(this->cursor, this->anchor);
|
||||
if (password) {
|
||||
std::memset(data, '*', static_cast<std::uint32_t>(this->text.size()) - static_cast<std::uint32_t>(begin));
|
||||
} else {
|
||||
std::memcpy(data, this->text.data() + begin, length);
|
||||
}
|
||||
|
||||
data[length] = 0;
|
||||
GlobalUnWire(memory);
|
||||
EmptyClipboard();
|
||||
SetClipboardData(CF_TEXT, memory);
|
||||
}
|
||||
}
|
||||
|
||||
CloseClipboard();
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACD540
|
||||
// FUNCTION: fn_17764
|
||||
void TextInputBuffer::Paste(UIWindow* blockedFocus, WindowManagerWindows& windows) {
|
||||
if (this->focused == blockedFocus || windows.LookupWindow(278) || windows.LookupWindow(128)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!OpenClipboard(this->window)) {
|
||||
return;
|
||||
}
|
||||
|
||||
HANDLE memory = GetClipboardData(CF_TEXT);
|
||||
if (memory) {
|
||||
const char* data = static_cast<const char*>(GlobalLock(memory));
|
||||
if (data) {
|
||||
this->Insert(data);
|
||||
GlobalUnWire(memory);
|
||||
}
|
||||
}
|
||||
|
||||
CloseClipboard();
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACD6B0
|
||||
// FUNCTION: fn_17766
|
||||
void TextInputBuffer::MoveBack(unsigned codePage) {
|
||||
if (this->cursor < 0) {
|
||||
this->cursor = 0;
|
||||
} else if (this->cursor != 0) {
|
||||
const char* begin = this->text.c_str();
|
||||
this->cursor = static_cast<int>(CharPrevExA(static_cast<WORD>(codePage), begin, begin + this->cursor, 0) - begin);
|
||||
}
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACE440
|
||||
// FUNCTION: fn_45441
|
||||
void TextInputBuffer::SelectionRange(int& begin, int& end) const {
|
||||
if (this->anchor < this->cursor) {
|
||||
begin = this->anchor;
|
||||
end = this->cursor;
|
||||
} else {
|
||||
begin = this->cursor;
|
||||
end = this->anchor;
|
||||
}
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACE4C0
|
||||
// FUNCTION: fn_17787
|
||||
void TextInputBuffer::MoveForward(unsigned codePage) {
|
||||
const auto length = static_cast<std::uint32_t>(this->text.size());
|
||||
const auto position = static_cast<std::uint32_t>(this->cursor);
|
||||
if (position > length) {
|
||||
this->cursor = static_cast<int>(length);
|
||||
} else if (position < length) {
|
||||
const char* begin = this->text.c_str();
|
||||
this->cursor = static_cast<int>(CharNextExA(static_cast<WORD>(codePage), begin + position, 0) - begin);
|
||||
}
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACE660
|
||||
// FUNCTION: fn_17791
|
||||
void TextInputBuffer::Character(unsigned value, LPARAM, unsigned codePage) {
|
||||
if (value == 8) {
|
||||
if (this->cursor == this->anchor) {
|
||||
this->MoveBack(codePage);
|
||||
}
|
||||
|
||||
this->DeleteSelection();
|
||||
return;
|
||||
}
|
||||
|
||||
if (value <= 31) {
|
||||
return;
|
||||
}
|
||||
|
||||
char bytes[sizeof(value)];
|
||||
std::memcpy(bytes, &value, sizeof(value));
|
||||
this->Insert(bytes);
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACE880
|
||||
// FUNCTION: fn_17792
|
||||
void TextInputBuffer::KeyDown(
|
||||
unsigned key, LPARAM, unsigned codePage, bool password, UIWindow* blockedPasteFocus, WindowManagerWindows& windows, UIWindow* const& chatArrows
|
||||
) {
|
||||
const auto cut = [&]() {
|
||||
this->CopySelection(password);
|
||||
this->DeleteSelection();
|
||||
};
|
||||
|
||||
if ((static_cast<unsigned short>(GetKeyState(VK_SHIFT)) >> 8) != 0) {
|
||||
switch (key) {
|
||||
case VK_LEFT:
|
||||
this->MoveBack(codePage);
|
||||
break;
|
||||
case VK_RIGHT:
|
||||
this->MoveForward(codePage);
|
||||
break;
|
||||
case VK_HOME:
|
||||
this->cursor = 0;
|
||||
break;
|
||||
case VK_END:
|
||||
this->cursor = static_cast<int>(this->text.size());
|
||||
break;
|
||||
case VK_INSERT:
|
||||
this->Paste(blockedPasteFocus, windows);
|
||||
break;
|
||||
case VK_DELETE:
|
||||
cut();
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ((static_cast<unsigned short>(GetKeyState(VK_CONTROL)) >> 8) != 0) {
|
||||
switch (key) {
|
||||
case 'X':
|
||||
cut();
|
||||
break;
|
||||
case 'C':
|
||||
this->CopySelection(password);
|
||||
break;
|
||||
case 'V':
|
||||
this->Paste(blockedPasteFocus, windows);
|
||||
break;
|
||||
case 'A':
|
||||
this->anchor = 0;
|
||||
this->cursor = std::max(static_cast<int>(this->text.size()), 0);
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch (key) {
|
||||
case VK_DELETE:
|
||||
if (this->cursor == this->anchor) {
|
||||
this->MoveForward(codePage);
|
||||
}
|
||||
this->DeleteSelection();
|
||||
break;
|
||||
case VK_LEFT:
|
||||
case VK_RIGHT:
|
||||
if (chatArrows && chatArrows->geometry.visible != 0) {
|
||||
chatArrows->SendMsg(nullptr, 176, key, 0, 0, 0);
|
||||
} else {
|
||||
if (key == VK_LEFT) {
|
||||
this->MoveBack(codePage);
|
||||
} else {
|
||||
this->MoveForward(codePage);
|
||||
}
|
||||
|
||||
this->anchor = this->cursor;
|
||||
}
|
||||
break;
|
||||
case VK_HOME:
|
||||
this->cursor = 0;
|
||||
this->anchor = 0;
|
||||
break;
|
||||
case VK_END:
|
||||
this->cursor = static_cast<int>(this->text.size());
|
||||
this->anchor = this->cursor;
|
||||
break;
|
||||
}
|
||||
}
|
||||
57
Source/Client/Input/TextInputBuffer.h
Normal file
57
Source/Client/Input/TextInputBuffer.h
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#ifndef RAGNAROK_SOURCE_CLIENT_INPUT_TEXTINPUTBUFFER_H
|
||||
#define RAGNAROK_SOURCE_CLIENT_INPUT_TEXTINPUTBUFFER_H
|
||||
|
||||
#include <string>
|
||||
#include <windows.h>
|
||||
|
||||
class UIWindow;
|
||||
class WindowManagerWindows;
|
||||
|
||||
class TextInputSuggestions {
|
||||
public:
|
||||
virtual void Update(const char* text) = 0;
|
||||
|
||||
protected:
|
||||
~TextInputSuggestions() = default;
|
||||
};
|
||||
|
||||
struct TextInputBuffer {
|
||||
std::string& text;
|
||||
int& cursor;
|
||||
int& anchor;
|
||||
std::string& composition;
|
||||
std::string& candidate;
|
||||
int& compositionState;
|
||||
HWND& window;
|
||||
const bool& suggestionsEnabled;
|
||||
UIWindow* const& focused;
|
||||
UIWindow* const& chatInput;
|
||||
const bool& chatOpen;
|
||||
TextInputSuggestions& suggestions;
|
||||
|
||||
void CancelComposition();
|
||||
void DeleteSelection();
|
||||
void Insert(const char* value);
|
||||
void Select(int anchor, int cursor);
|
||||
void CopyDisplayText(std::string& output) const;
|
||||
void Selection(int& anchor, int& cursor) const;
|
||||
|
||||
void SelectionRange(int& begin, int& end) const;
|
||||
|
||||
void RefreshComposition(unsigned codePage);
|
||||
|
||||
void CopySelection(bool password);
|
||||
void Paste(UIWindow* blockedFocus, WindowManagerWindows& windows);
|
||||
|
||||
void MoveBack(unsigned codePage);
|
||||
|
||||
void MoveForward(unsigned codePage);
|
||||
|
||||
void Character(unsigned value, LPARAM unused, unsigned codePage);
|
||||
|
||||
void KeyDown(
|
||||
unsigned key, LPARAM unused, unsigned codePage, bool password, UIWindow* blockedPasteFocus, WindowManagerWindows& windows, UIWindow* const& chatArrows
|
||||
);
|
||||
};
|
||||
|
||||
#endif
|
||||
151
Source/Client/Input/TraditionalKeyInput.cpp
Normal file
151
Source/Client/Input/TraditionalKeyInput.cpp
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
#include "Client/Input/TraditionalKeyInput.h"
|
||||
#include "Network/TextEncoding.h"
|
||||
#include <windows.h>
|
||||
|
||||
// OFFSET: 0x00ACCD30
|
||||
// FUNCTION: fn_17752
|
||||
void TraditionalKeyInput::InitializeMappings() {
|
||||
// STATIC: 0x011594E0
|
||||
// GLOBAL: gl_13427
|
||||
static constexpr std::uint8_t bytes[] = {0xA3, 0x74, 0xA3, 0x78, 0xA3, 0xBE, 0xA3, 0xBF, 0xA3, 0xA4, 0xA3, 0xBD, 0xA3, 0xBB, 0xA3, 0xAB, 0xA3,
|
||||
0xAF, 0xA3, 0xB3, 0xA3, 0x76, 0xA3, 0xA7, 0xA3, 0x74, 0xA3, 0x74, 0xA3, 0x74, 0xA3, 0xA2, 0xA3, 0xA6,
|
||||
0xA3, 0xA9, 0xA3, 0xAC, 0xA3, 0xB9, 0xA3, 0xAD, 0xA3, 0xB1, 0xA3, 0xAA, 0xA3, 0xBA, 0xA3, 0xB0, 0xA3,
|
||||
0xB4, 0xA3, 0x75, 0xA3, 0xA1, 0xA3, 0x7A, 0xA3, 0xA5, 0xA3, 0x74, 0xA3, 0xA3, 0xA3, 0x79, 0xA3, 0x74,
|
||||
0xA3, 0xA8, 0xA3, 0x77, 0xA3, 0xB7, 0xA3, 0xB5, 0xA3, 0xAE, 0xA3, 0xB2, 0xA3, 0xB6};
|
||||
static constexpr char categories[] = "11441443331111111132331233111121111133333";
|
||||
static constexpr unsigned char keys[] = "1234567890ABCDEFGHIJKLNMOPQRSTUVWXYZ\xBD\xBA\xBC\xBE\xBF";
|
||||
|
||||
this->unknown04C1 = 0;
|
||||
|
||||
for (auto& mapping : this->mappings) {
|
||||
mapping.category = 4;
|
||||
}
|
||||
|
||||
for (unsigned index = 0; index < 41; ++index) {
|
||||
auto& mapping = this->mappings[keys[index]];
|
||||
mapping.bytes[0] = bytes[2 * index];
|
||||
mapping.bytes[1] = bytes[2 * index + 1];
|
||||
mapping.bytes[2] = 0;
|
||||
mapping.category = static_cast<std::uint8_t>(categories[index] - '1');
|
||||
}
|
||||
|
||||
this->mappings['C'].bytes[1] = 0x7E;
|
||||
this->mappings['D'].bytes[1] = 0x7D;
|
||||
this->mappings['E'].bytes[1] = 0x7C;
|
||||
this->mappings['U'].bytes[1] = 0xB8;
|
||||
this->mappings['X'].bytes[1] = 0x7B;
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACF330
|
||||
// FUNCTION: fn_17795
|
||||
void TraditionalKeyInput::DefaultKey(int) {
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACF340
|
||||
// FUNCTION: fn_17796
|
||||
void TraditionalKeyInput::Key(int virtualKey) {
|
||||
const auto key = static_cast<std::uint8_t>(virtualKey);
|
||||
if (key == 8) {
|
||||
if (!this->keys.empty()) {
|
||||
this->keys.pop_back();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto entry = this->keys.begin(); entry != this->keys.end(); ++entry) {
|
||||
if (this->mappings[*entry].category == this->mappings[key].category) {
|
||||
this->keys.erase(entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this->keys.push_back(key);
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACE270
|
||||
// FUNCTION: fn_17777
|
||||
const char* TraditionalKeyInput::DisplayText() const {
|
||||
return this->display.c_str();
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACE280
|
||||
// FUNCTION: fn_17778
|
||||
const char* TraditionalKeyInput::Display() {
|
||||
char bytes[8] = {};
|
||||
|
||||
for (std::uint8_t key : this->keys) {
|
||||
const auto& mapping = this->mappings[key];
|
||||
if (mapping.category < 4) {
|
||||
bytes[2 * mapping.category] = static_cast<char>(mapping.bytes[0]);
|
||||
bytes[2 * mapping.category + 1] = static_cast<char>(mapping.bytes[1]);
|
||||
}
|
||||
}
|
||||
|
||||
this->display.assign(bytes, sizeof(bytes));
|
||||
return this->display.c_str();
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACE320
|
||||
// FUNCTION: fn_17779
|
||||
int TraditionalKeyInput::DisplayLength() const {
|
||||
return static_cast<int>(this->display.size());
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACE330
|
||||
// FUNCTION: fn_17780
|
||||
int TraditionalKeyInput::Count() const {
|
||||
if (this->keys.size() == 1 && this->mappings[this->keys.back()].category == 4) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return static_cast<int>(this->keys.size());
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACE470
|
||||
// FUNCTION: fn_17784
|
||||
const char* TraditionalKeyInput::NextChar(const char* current, int) {
|
||||
return CharNextExA(static_cast<WORD>(g_textCodePage), current, 0);
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACE490
|
||||
// FUNCTION: fn_17785
|
||||
const char* TraditionalKeyInput::NextCharArabic(const char* current, int) {
|
||||
return CharNextExA(static_cast<WORD>(g_textCodePage), current, 0);
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACD7E0
|
||||
// FUNCTION: fn_17769
|
||||
void TraditionalKeyInput::ClearKeys() {
|
||||
this->keys.clear();
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACD4A0
|
||||
// FUNCTION: fn_17761
|
||||
void TraditionalKeyInput::ResetState() {
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACD4E0
|
||||
// FUNCTION: fn_17762
|
||||
void TraditionalKeyInput::ResetCandidate() {
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACD4F0
|
||||
// FUNCTION: fn_17763
|
||||
void TraditionalKeyInput::RetainSingleKey() {
|
||||
if (!this->keys.empty()) {
|
||||
const auto key = this->keys.back();
|
||||
this->keys.clear();
|
||||
if (this->mappings[key].category < 4) {
|
||||
this->keys.push_back(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// OFFSET: 0x00ACE000
|
||||
// FUNCTION: fn_17776
|
||||
void TraditionalKeyInput::FilterCandidate(std::string& candidate) {
|
||||
if (candidate.size() > 2 && std::strcmp(candidate.c_str() + candidate.size() - 2, "?") == 0) {
|
||||
candidate.resize(candidate.size() - 2);
|
||||
}
|
||||
}
|
||||
38
Source/Client/Input/TraditionalKeyInput.h
Normal file
38
Source/Client/Input/TraditionalKeyInput.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#ifndef RAGNAROK_SOURCE_CLIENT_INPUT_TRADITIONALKEYINPUT_H
|
||||
#define RAGNAROK_SOURCE_CLIENT_INPUT_TRADITIONALKEYINPUT_H
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
struct TraditionalKeyMapping {
|
||||
std::uint8_t category;
|
||||
std::uint8_t bytes[3];
|
||||
};
|
||||
|
||||
struct TraditionalKeyInput {
|
||||
std::list<std::uint8_t>& keys;
|
||||
std::array<TraditionalKeyMapping, 256>& mappings;
|
||||
std::string& display;
|
||||
std::uint8_t& unknown04C1;
|
||||
|
||||
void InitializeMappings();
|
||||
void Key(int virtualKey);
|
||||
void DefaultKey(int virtualKey);
|
||||
const char* Display();
|
||||
const char* DisplayText() const;
|
||||
int DisplayLength() const;
|
||||
const char* NextChar(const char* current, int unused);
|
||||
const char* NextCharArabic(const char* current, int unused);
|
||||
int Count() const;
|
||||
void ClearKeys();
|
||||
void ResetState();
|
||||
void ResetCandidate();
|
||||
void RetainSingleKey();
|
||||
void FilterCandidate(std::string& candidate);
|
||||
};
|
||||
|
||||
static_assert(sizeof(TraditionalKeyMapping) == 4);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue