mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
Retail's motion focus is a list (probed on 5.5.4): the walk takes the top mouse-enabled frame under the cursor and keeps going while the last frame taken propagates motion; the next frame is the next one under the cursor, not the parent. Every listed frame is focus, a frame that stays listed across a change gets neither leave nor enter, and the ones that drop out leave before the ones that join enter, each top-first. The three blocks that write the UI context's focus (+0x7C) - the focus pass's commit, the mouselook focus setter and the input removal - now call Frame::MotionFocus, which keeps the list and keeps +0x7C as its first frame. A propagating pick resumes the engine's walk through the same per-frame probe. A removed frame leaves wherever it is in the list and asks for a re-pick; hiding a frame removes it before its children, which gives retail's outer-first leave order. - frame:SetPropagateMouseMotion / CanPropagateMouseMotion / IsMouseMotionFocus, and propagateMouseInput="Motion"|"Both" in XML. - GetMouseFoci returns the list (one frame unless frames propagate), as retail does, instead of every frame under the cursor. - EnterLeaveMotion offers motion to the frame MotionFocus is notifying. - Common::ReplaceWithCall takes up to 64 bytes; it refused anything over 16 without a word.
90 lines
2.9 KiB
C++
90 lines
2.9 KiB
C++
// This file is part of ClassicAPI.
|
|
//
|
|
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
|
// of the GNU General Public License as published by the Free Software Foundation, either
|
|
// version 3 of the License, or (at your option) any later version.
|
|
//
|
|
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
// PURPOSE. See the GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License along with
|
|
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
#include "Common.h"
|
|
|
|
#include <cstring>
|
|
#include <string>
|
|
#include <windows.h>
|
|
|
|
namespace Common {
|
|
|
|
bool PatchBytes(void *dst, const void *src, size_t len) {
|
|
DWORD oldProt = 0;
|
|
if (!VirtualProtect(dst, len, PAGE_EXECUTE_READWRITE, &oldProt))
|
|
return false;
|
|
|
|
std::memcpy(dst, src, len);
|
|
FlushInstructionCache(GetCurrentProcess(), dst, len);
|
|
|
|
DWORD dummy = 0;
|
|
VirtualProtect(dst, len, oldProt, &dummy);
|
|
return true;
|
|
}
|
|
|
|
bool RedirectCall(uintptr_t site, uintptr_t expected, const void *target) {
|
|
const auto *code = reinterpret_cast<const uint8_t *>(site);
|
|
if (code[0] != 0xE8)
|
|
return false;
|
|
const auto callee = [site](int32_t rel) { return site + 5 + static_cast<uintptr_t>(rel); };
|
|
int32_t rel = 0;
|
|
std::memcpy(&rel, code + 1, sizeof rel);
|
|
const uintptr_t to = reinterpret_cast<uintptr_t>(target);
|
|
if (callee(rel) == to)
|
|
return true;
|
|
if (callee(rel) != expected)
|
|
return false;
|
|
rel = static_cast<int32_t>(to - (site + 5));
|
|
return PatchBytes(reinterpret_cast<uint8_t *>(site) + 1, &rel, sizeof rel);
|
|
}
|
|
|
|
bool ReplaceWithCall(uintptr_t site, const uint8_t *original, size_t len, const void *target) {
|
|
uint8_t code[64];
|
|
if (len < 5 || len > sizeof code)
|
|
return false;
|
|
code[0] = 0xE8;
|
|
const int32_t rel = static_cast<int32_t>(reinterpret_cast<uintptr_t>(target) - (site + 5));
|
|
std::memcpy(code + 1, &rel, sizeof rel);
|
|
std::memset(code + 5, 0x90, len - 5);
|
|
const void *at = reinterpret_cast<const void *>(site);
|
|
if (std::memcmp(at, code, len) == 0)
|
|
return true;
|
|
if (std::memcmp(at, original, len) != 0)
|
|
return false;
|
|
return PatchBytes(reinterpret_cast<void *>(site), code, len);
|
|
}
|
|
|
|
void BoundedCopy(char *dst, const char *src, size_t n) {
|
|
if (dst == nullptr || n == 0)
|
|
return;
|
|
size_t i = 0;
|
|
for (; src != nullptr && src[i] != '\0' && i + 1 < n; ++i)
|
|
dst[i] = src[i];
|
|
dst[i] = '\0';
|
|
}
|
|
|
|
void EnsureParentDirs(const char *relPath) {
|
|
std::string accum;
|
|
for (const char *p = relPath; *p != '\0'; ++p) {
|
|
if (*p == '\\' || *p == '/') {
|
|
if (!accum.empty())
|
|
CreateDirectoryA(accum.c_str(), nullptr);
|
|
accum.push_back('\\');
|
|
} else {
|
|
accum.push_back(*p);
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace Common
|