mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-15 23:50:38 +00:00
The ModelScene mover and contact sweep carried their own copies of engine code and data. They now use the client's. Constants: every float the transcribed mover reads from 1.12.1's .rdata (and the two fall-speed caps in .data, the 2pi the static initializer fills at 0x00CF5D00) is an Offsets.h entry read where it is used, through Game::Live<T>. Each value was checked against WoW.exe's bytes. The pooled floats other modules already named for one use (0x00801360, 0x008026BC, 0x008029D4, 0x00803568, 0x008022CC, 0x00801620, 0x0080306C, 0x00801628) are renamed by value, since the mover reads them too. Leaf math: the pure geometry helpers the mover calls are now called, not copied: DotVector3 0x00602630, PlaneFromTriangle 0x00637480, PlaneDistanceAlongRay 0x006329E0, ClipPolygonByPlane(s/Except) 0x006318C0 / 0x00631870 / 0x00632980, IntersectThreePlanes 0x00634FC0 and PointToLineDistanceSquared 0x00634F40. Each is __fastcall with callee cleanup and reads only its arguments and .rdata (Ghidra). Two stay transcribed: FindNearestTriangleEdge 0x00634DA0 reads the client's facet list at 0x00C4E534, and SelectBevelContactNormal 0x00636610 reads an unwritten stack slot as an index when three bevels have no odd one out. Wrappers: engine calls that several files cast themselves get one typed home: M2.h (key-bone animation state, sequence info, base transform, scene draw, model lights, the IsXAnimation tests, whose death test is __stdcall and the rest __fastcall), gx/Matrix.h (the 0x007BxXXX matrix helpers), gx/Device.h (render-state journal, state setters, transform stacks, clear), Frame::Layout (DDC/NDC conversion), Texture::DeviceTexture, Xml::ReadColor and Frame::Subclass's slot types.
98 lines
3.3 KiB
C++
98 lines
3.3 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/>.
|
|
|
|
// `GetCursorDelta()` -> deltaX, deltaY
|
|
//
|
|
// Retail's: how far the cursor moved since the last frame, zero when it did
|
|
// not, in GetCursorPosition's units (independent of the UI scale; InputUtil.
|
|
// GetCursorDelta divides by a frame's effective scale). The orbit camera of
|
|
// a ModelScene drags with it.
|
|
//
|
|
// The cursor is sampled once a frame, at the head of the UI render callback,
|
|
// before any OnUpdate runs, the way the in-game GetCursorPosition (0x0048B820)
|
|
// reads it: the top's NDC position (OFF_UI_CONTEXT_MOUSE_POSITION) through
|
|
// NDCToDDC, then the engine's script push (Game::InternalToPixel). The delta is
|
|
// this frame's sample less the last frame's, so every OnUpdate of a frame sees
|
|
// the same value.
|
|
|
|
#include "Game.h"
|
|
#include "Offsets.h"
|
|
#include "frame/Layout.h"
|
|
#include "tick/FrameTick.h"
|
|
|
|
namespace Input::CursorDelta {
|
|
|
|
namespace {
|
|
|
|
struct Position {
|
|
double x = 0.0;
|
|
double y = 0.0;
|
|
};
|
|
|
|
Position g_previous;
|
|
Position g_current;
|
|
bool g_sampled = false;
|
|
|
|
// What GetCursorPosition pushes now, or false before the UI top exists.
|
|
bool ReadCursor(Position &out) {
|
|
const void *top = Game::Read<const void *>(Offsets::VAR_UI_CONTEXT_PTR);
|
|
if (top == nullptr)
|
|
return false;
|
|
const float ndcX = Game::Read<float>(top, Offsets::OFF_UI_CONTEXT_MOUSE_POSITION);
|
|
const float ndcY = Game::Read<float>(top, Offsets::OFF_UI_CONTEXT_MOUSE_POSITION + 4);
|
|
float ddcX = 0.0f;
|
|
float ddcY = 0.0f;
|
|
Frame::Layout::NdcToDdc(&ddcX, &ddcY, ndcX, ndcY);
|
|
out = {Game::InternalToPixel(ddcX), Game::InternalToPixel(ddcY)};
|
|
return true;
|
|
}
|
|
|
|
void Sample() {
|
|
Position now;
|
|
if (!ReadCursor(now))
|
|
return;
|
|
g_previous = g_sampled ? g_current : now;
|
|
g_current = now;
|
|
g_sampled = true;
|
|
}
|
|
|
|
const Tick::FrameTick::AutoSubscribeBefore _tick{&Sample};
|
|
|
|
int __fastcall Script_GetCursorDelta(void *L) {
|
|
Game::Lua::PushNumber(L, g_current.x - g_previous.x);
|
|
Game::Lua::PushNumber(L, g_current.y - g_previous.y);
|
|
return 2;
|
|
}
|
|
|
|
const Game::Doc::Field kRets[] = {
|
|
Game::Doc::Req("deltaX", "number"),
|
|
Game::Doc::Req("deltaY", "number"),
|
|
};
|
|
const Game::Doc::Function kDoc{"Returns how far the cursor moved since the last frame.", {},
|
|
kRets, "Input"};
|
|
|
|
void RegisterInGame() {
|
|
Game::Lua::RegisterGlobalFunction("GetCursorDelta", &Script_GetCursorDelta, &kDoc);
|
|
}
|
|
|
|
void RegisterGlue() {
|
|
Game::Lua::RegisterGlueFunction("GetCursorDelta", &Script_GetCursorDelta, &kDoc);
|
|
}
|
|
|
|
const Game::ModuleAutoRegister _autoreg{&RegisterInGame};
|
|
const Game::GlueModuleAutoRegister _autoregGlue{&RegisterGlue};
|
|
|
|
} // namespace
|
|
|
|
} // namespace Input::CursorDelta
|