mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
refactor(model): call the engine's math and read its constants live
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.
This commit is contained in:
+12
@@ -58,6 +58,18 @@ inline T &Ref(uintptr_t address) {
|
||||
return *reinterpret_cast<T *>(address);
|
||||
}
|
||||
|
||||
// An engine constant at a fixed VA, read each time it is used, so the value is
|
||||
// the one the engine's own code reads: a runtime patch shows, and so does a
|
||||
// global the engine's static initializers fill after this DLL loads. Converts
|
||||
// to T, so it stands in a float expression as a float would.
|
||||
//
|
||||
// const Game::Live<float> kSkin{Offsets::VAR_MOVER_SKIN};
|
||||
template <typename T>
|
||||
struct Live {
|
||||
uintptr_t address;
|
||||
operator T() const { return Read<T>(address); }
|
||||
};
|
||||
|
||||
// Calls `fn(object)` for each object of one of a frame's intrusive lists,
|
||||
// OFF_FRAME_REGION_LIST or OFF_FRAME_CHILD_LIST: node+4 next, node+8 object,
|
||||
// a NULL or low-bit-1 link ends it - the walk the engine's own frame code
|
||||
|
||||
+105
-11
@@ -811,8 +811,8 @@ enum Offsets {
|
||||
// double-duties as the MINIMUM font size numerator in the node ctor
|
||||
// (FUN_005cd6d0 / FUN_005ccb80: fontSize floored at [0x801628]/rasterY =
|
||||
// 2 pen px).
|
||||
FLOAT_OUTLINE_EXTRA_THICK = 0x0080306C,
|
||||
FLOAT_OUTLINE_EXTRA_THIN = 0x00801628,
|
||||
VAR_FOUR = 0x0080306C, // float 4.0
|
||||
VAR_TWO = 0x00801628, // float 2.0
|
||||
// The node's BUILT line count — incremented once per emitted wrapped line
|
||||
// by the draw builder (FUN_005CDC20, including the \n break case) and the
|
||||
// builder's own early-out gate (`if (node+0x9C != 0) return`); zeroed by
|
||||
@@ -2083,7 +2083,7 @@ enum Offsets {
|
||||
// Front-cone half angle of the tab-target collector (0x494200): pi times
|
||||
// 1/6, both read from these floats (stored into 0xB4D8F4 on first use).
|
||||
VAR_TARGETING_PI = 0x00804488,
|
||||
VAR_TARGETING_ONE_SIXTH = 0x00803568,
|
||||
VAR_ONE_SIXTH = 0x00803568, // float 1/6
|
||||
// HeadingBetweenPoints — `float __fastcall(const float *from, const
|
||||
// float *to)`: atan2 of the y and x differences (the tab collector's
|
||||
// heading).
|
||||
@@ -3561,7 +3561,7 @@ enum Offsets {
|
||||
// counts as ranged (`fcomp` then `test ah,5; jp` at `0x4E5885`
|
||||
// passes unordered). Verified by a direct float dump of the image:
|
||||
// exactly 2^-22 (0x34800000) at this address. Read live, not hardcoded.
|
||||
VAR_HAS_RANGE_EPSILON = 0x008029D4,
|
||||
VAR_TWO_POW_MINUS_22 = 0x008029D4, // float 2^-22
|
||||
|
||||
// The two floats `FUN_006e3480`'s COMBAT-RANGE branch folds into its
|
||||
// max-range output: `casterReach + targetReach + LEEWAY`, floored at
|
||||
@@ -13601,7 +13601,7 @@ enum Offsets {
|
||||
// lighting/shadows). A world entity with flag 0x400 draws it when its
|
||||
// model is ready and shadowLOD is 1 (0x006D78F0). The box is the bounds
|
||||
// of sequence (0, 0), skipped when the x or y extent is under
|
||||
// VAR_HAS_RANGE_EPSILON, clamped to +-5 and multiplied by the length of
|
||||
// VAR_TWO_POW_MINUS_22, clamped to +-5 and multiplied by the length of
|
||||
// the base transform's row 0 (times 1.0, 0x00811698); its four corners
|
||||
// turn by the base rotation (rows over that length) and move by the base
|
||||
// translation. The decal box is those corners' bounds, z from the base
|
||||
@@ -14145,8 +14145,8 @@ enum Offsets {
|
||||
// A group light's end gains 0.1 when it is within 0.001 of its start
|
||||
// (0x00695CB1 / 0x00695CC1); AddMapLight 0x006A7AC0 measures from the
|
||||
// doodad's position raised by 1.1666666.
|
||||
VAR_MAP_LIGHT_RANGE_EPSILON = 0x00801360, // float 0.001
|
||||
VAR_MAP_LIGHT_RANGE_PAD = 0x00801620, // float 0.1
|
||||
VAR_ONE_THOUSANDTH = 0x00801360, // float 0.001
|
||||
VAR_ONE_TENTH = 0x00801620, // float 0.1
|
||||
VAR_MAP_LIGHT_LIFT = 0x00810A70, // float 1.1666666
|
||||
VAR_ONE = 0x007FF9D8, // float 1.0
|
||||
VAR_ONE_OVER_255 = 0x008026C8, // float 1/255
|
||||
@@ -14233,7 +14233,7 @@ enum Offsets {
|
||||
// floor 0xA8, ambient cap DOODAD_AMBIENT_CAP); a day face blends both
|
||||
// toward the sun's by the colour's alpha. The unit is placed again when
|
||||
// its translation moved by a squared distance of
|
||||
// VAR_MAP_LIGHT_RANGE_EPSILON or more (SyncLightNode, the same 0.001).
|
||||
// VAR_ONE_THOUSANDTH or more (SyncLightNode, the same 0.001).
|
||||
// TransformBox `__fastcall(const float m[16], const float box[6], float
|
||||
// out[6])` ret 4; CMapObj::BoxOverlaps `__thiscall(obj, box)` ret 4.
|
||||
FUN_TRANSFORM_BOX = 0x006DC540,
|
||||
@@ -14256,7 +14256,7 @@ enum Offsets {
|
||||
FUN_CMAPOBJDEF_GET_FACE_TERRAIN_TYPE = 0x006A26C0,
|
||||
FUN_CMAPOBJ_SAMPLE_GROUP_COLOR = 0x006A4DC0,
|
||||
FUN_M2MODEL_GET_COLLISION_BOX = 0x00713700, // `__thiscall(model, float out[6])`; waits for an unloaded file
|
||||
VAR_ENTITY_PROBE_LENGTH = 0x008022CC, // 1000.0
|
||||
VAR_ONE_THOUSAND = 0x008022CC, // 1000.0
|
||||
MAPOBJ_GROUP_EXTERIOR = 0x08,
|
||||
MAPOBJ_GROUP_EXTERIOR_LIT = 0x40,
|
||||
ENTITY_DIRECTIONAL_FLOOR = 0xA8,
|
||||
@@ -15184,7 +15184,7 @@ enum Offsets {
|
||||
DRAW_BUILDER_FRAME_LINE_X = 0x48,
|
||||
// The fit-to-height count's line test (0x005C21C0, after its stepper
|
||||
// call): `fld [ebp+10h]` (the block height), then this `fadd dword ptr
|
||||
// [VAR_TEXT_FIT_HEIGHT_EPSILON]` (D8 05 BC 26 80 00), then FCOMPP against
|
||||
// [VAR_TWO_POW_MINUS_20]` (D8 05 BC 26 80 00), then FCOMPP against
|
||||
// the running height + font height; it stops at the first line that
|
||||
// fails. [ebp-8] is the bytes fitted so far, 0 until a line fits. EAX is
|
||||
// dead here (FNSTSW AX, then both paths reload it from [ebp-8]).
|
||||
@@ -15193,7 +15193,7 @@ enum Offsets {
|
||||
TEXT_FIT_HEIGHT_FRAME_FITTED_BYTES = 0x8,
|
||||
// Exactly 2^-20 (0x35800000, .rdata): the fit's line margin above. A
|
||||
// shared float, also read by collision, movement and matrix code.
|
||||
VAR_TEXT_FIT_HEIGHT_EPSILON = 0x008026BC,
|
||||
VAR_TWO_POW_MINUS_20 = 0x008026BC, // float 2^-20
|
||||
// The draw builder's right / centre x: `FUN_TEXT_SCREEN_TO_PIXEL_WIDTH(raw,
|
||||
// -width)` (or -width / 2), `float __fastcall(int raw, float)`, `ret 4`,
|
||||
// result in ST0, stored to the line x at 0x005CDE28.
|
||||
@@ -15747,4 +15747,98 @@ enum Offsets {
|
||||
// (FUN_REGION_LAYOUT_DIRTY(layout)) FUN_007680e0(layout, 1)`, 4.3.4's
|
||||
// `if (IsResizePending()) Resize(1)`).
|
||||
FUN_LAYOUT_RESIZE = 0x007680E0,
|
||||
|
||||
// ---- The client mover's floats (Model::Scene::Mover / Contact, the
|
||||
// scene actor's body facing and locomotion) ---------------------------
|
||||
// Each is the float (or double) the transcribed client function reads at
|
||||
// that address; every value was checked against the image's bytes. The
|
||||
// pooled ones are named by value, the mover's own by their role. All
|
||||
// are .rdata except the three noted.
|
||||
VAR_HALF = 0x007FFA24, // float 0.5
|
||||
VAR_THREE_QUARTERS = 0x008012CC, // float 0.75; a swimmer's height share, the aim height
|
||||
VAR_ONE_HUNDREDTH = 0x008029D0, // float 0.01
|
||||
VAR_ONE_THIRTY_SIXTH = 0x007FF9D0, // float 1/36
|
||||
VAR_MINUS_ONE_THIRTY_SIXTH = 0x007FF9C8, // float -1/36
|
||||
VAR_HALF_PI = 0x00808ACC, // float pi/2
|
||||
VAR_MINUS_HALF_PI = 0x0080C5E4, // float -pi/2
|
||||
VAR_QUARTER_PI = 0x0080C4E4, // float pi/4
|
||||
// WrapAngleToPi (0x006084F0): pi as a float, 2pi as a double.
|
||||
VAR_WRAP_PI = 0x008030B0,
|
||||
VAR_WRAP_TWO_PI = 0x00803090, // double
|
||||
// 2pi in .bss, filled by a static initializer: read it only at use.
|
||||
VAR_MOVER_TWO_PI = 0x00CF5D00,
|
||||
VAR_MOVER_FACING_EPSILON = 0x0080C5C8, // float 1e-5, the turn and facing test
|
||||
VAR_MOVER_MINUS_FACING_EPSILON = 0x0080C5C4, // float -1e-5
|
||||
// The contact sweep's band and bounds (0x00631440 through 0x00632F80).
|
||||
VAR_MOVER_SKIN = 0x0080DFEC, // float 1/720
|
||||
VAR_MOVER_MINUS_SKIN = 0x0080DFF0, // float -1/720
|
||||
VAR_MOVER_ALL_BEHIND = 0x0080DFF4, // float -2^-20
|
||||
// The volume's bevels: sin, cos and tan of 61.6 degrees, the bevel
|
||||
// normal's z and the two-bevel normalizer.
|
||||
VAR_MOVER_BEVEL_OUT = 0x0080DFE4,
|
||||
VAR_MOVER_BEVEL_DOWN = 0x0080DFE0,
|
||||
VAR_MOVER_WAIST = 0x0080C740,
|
||||
VAR_MOVER_BEVEL_Z = 0x0080E014,
|
||||
VAR_MOVER_BISECT = 0x0080E024,
|
||||
// The walk and fall resolvers.
|
||||
VAR_MOVER_NINTH = 0x0080DFF8, // float 1/9
|
||||
VAR_MOVER_STALL = 0x0080C698, // float 0.0005
|
||||
VAR_MOVER_STALL_REACH = 0x0080E018, // float 1.1866661
|
||||
VAR_MOVER_COS_10 = 0x0080E01C,
|
||||
VAR_MOVER_FLOOR_COS = 0x0080DFFC, // float cos 50 degrees, the walkable limit
|
||||
VAR_MOVER_FLOOR_TAN = 0x0080E008, // float tan 50 degrees
|
||||
VAR_MOVER_MINUS_FLOOR_TAN = 0x0080E010,
|
||||
VAR_MOVER_SQRT_2 = 0x0080E00C,
|
||||
// Gravity g (19.29110527) and the forms the fall arc reads.
|
||||
VAR_MOVER_GRAVITY = 0x0081DA58,
|
||||
VAR_MOVER_HALF_GRAVITY = 0x0081DA60,
|
||||
VAR_MOVER_TWO_GRAVITY = 0x0081DA64,
|
||||
VAR_MOVER_INV_GRAVITY = 0x0080E020,
|
||||
VAR_MOVER_MINUS_INV_GRAVITY = 0x0081DA5C,
|
||||
VAR_MOVER_TWO_OVER_GRAVITY = 0x0081DA68,
|
||||
// The fall's speed cap and the cap under flag 0x20000000, in .data.
|
||||
VAR_MOVER_TERMINAL_SPEED = 0x0087D894,
|
||||
VAR_MOVER_TERMINAL_SPEED_SLOW = 0x0087D898,
|
||||
// The spline mover (OnMonsterMove 0x006018F0, SnapIfFar 0x00616D60, the
|
||||
// warp gate 0x00616AF0, the position check 0x00616BF0).
|
||||
VAR_MOVER_SNAP_DISTANCE_SQ = 0x0080C5BC, // float 9.0, 3 yards squared
|
||||
VAR_MOVER_WARP_SPEED_SQ = 0x0080C734, // float 3600.0, 60 yards a second squared
|
||||
VAR_MOVER_PATH_POINT_SQ = 0x0080C450, // float (1/36)^2
|
||||
VAR_MOVER_CELL_SPAN = 0x0080C738, // float 34131.332
|
||||
// The unit's sprint threshold (the move animation pick 0x005FD100).
|
||||
VAR_MOVER_SPRINT_SPEED = 0x0080C484, // float 11.0
|
||||
// The mover's pure geometry helpers: each reads only its arguments and
|
||||
// .rdata constants (Ghidra), so a scene body calls them as the client's
|
||||
// mover does. A plane is {n xyz, d}, 16 bytes; a clip polygon is 0xF4
|
||||
// bytes: 15 vertices, the tag of each (+0xB4), the count (+0xF0). All are
|
||||
// __fastcall with the callee popping its stack arguments.
|
||||
// DotVector3 `double(const float a[3], const float b[3])`, plain ret;
|
||||
// the result unrounded in st0.
|
||||
FUN_DOT_VECTOR3 = 0x00602630,
|
||||
// PlaneFromTriangle `void(Plane *out, int /*edx unused*/, const float
|
||||
// p0[3], const float p1[3], const float p2[3])`, ret 0xC: the unit
|
||||
// normal (p1 - p0) x (p2 - p0) and d = -n·p0.
|
||||
FUN_PLANE_FROM_TRIANGLE = 0x00637480,
|
||||
// PlaneDistanceAlongRay `double(const float p[3], const Plane *, const
|
||||
// float dir[3])`, ret 4: (n·p + d) / (n·dir), undivided when |n·dir| <
|
||||
// 2^-22.
|
||||
FUN_PLANE_DISTANCE_ALONG_RAY = 0x006329E0,
|
||||
// ClipPolygonByPlane `void(const Plane *, Polygon *, int tag)`, ret 4:
|
||||
// keeps the inside with a 1/720 band, tagging the vertices it adds;
|
||||
// fewer than three left empties it.
|
||||
FUN_CLIP_POLYGON_BY_PLANE = 0x006318C0,
|
||||
// ClipPolygonByPlanes `int(const Plane *, uint32 count, Polygon *)`,
|
||||
// ret 4, and ClipPolygonByPlanesExcept `int(const Plane *, uint32
|
||||
// count, uint32 skip, Polygon *)`, ret 8: by each plane in turn (the
|
||||
// tag its index), 0 once empty.
|
||||
FUN_CLIP_POLYGON_BY_PLANES = 0x00631870,
|
||||
FUN_CLIP_POLYGON_BY_PLANES_EXCEPT = 0x00632980,
|
||||
// IntersectThreePlanes `float *(float out[3], const Plane *a, const
|
||||
// Plane *b, const Plane *c)`, ret 8: through Matrix3Determinant and
|
||||
// InvertMatrix3 (0x007BE0E0, 0x007BE2A0).
|
||||
FUN_INTERSECT_THREE_PLANES = 0x00634FC0,
|
||||
// PointToLineDistanceSquared `double(const float p[3], const float
|
||||
// q[3], const float dir[3])`, ret 4: from p to the line through q
|
||||
// along the unit dir.
|
||||
FUN_POINT_TO_LINE_DISTANCE_SQ = 0x00634F40,
|
||||
};
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "frame/Layout.h"
|
||||
#include "frame/Alpha.h"
|
||||
#include "frame/Destruction.h"
|
||||
#include "texture/Transform.h"
|
||||
@@ -115,7 +116,6 @@ using SetColor_t = void(__fastcall *)(void *region, void *edx, const uint32_t *b
|
||||
using StoreCorners_t = void(__fastcall *)(void *region, void *edx, float *rect);
|
||||
using Crop_t = void(__fastcall *)(void *region, void *edx, float *rect);
|
||||
using SetStringPos_t = void(__fastcall *)(void *block, const float *position);
|
||||
using NdcToDdc_t = void(__fastcall *)(float *outX, float *outY, float x, float y);
|
||||
using SizeChanged_t = void(__fastcall *)(void *layout, void *edx, const float *oldRect);
|
||||
using InvalidateNode_t = void(__fastcall *)(void *node);
|
||||
|
||||
@@ -216,7 +216,7 @@ bool GetStringPos(void *block, float out[3]) {
|
||||
if (node == nullptr)
|
||||
return false;
|
||||
const float *position = Game::Ptr<const float>(node, Offsets::OFF_TEXT_NODE_POSITION);
|
||||
reinterpret_cast<NdcToDdc_t>(Offsets::FUN_COORD_NDC_TO_DDC)(&out[0], &out[1], position[0], position[1]);
|
||||
Frame::Layout::NdcToDdc(&out[0], &out[1], position[0], position[1]);
|
||||
out[2] = position[2];
|
||||
return true;
|
||||
}
|
||||
|
||||
+12
-22
@@ -67,13 +67,6 @@ namespace {
|
||||
|
||||
using SetProjection_t = void(__fastcall *)(const float *m);
|
||||
using SetViewport_t = void(__stdcall *)(float minX, float maxX, float minY, float maxY, float minZ, float maxZ);
|
||||
using Convert_t = void(__fastcall *)(float *outX, float *outY, float x, float y);
|
||||
using GetRenderable_t = void *(__fastcall *)(void *hTex, int force, void *);
|
||||
using RsSet_t = void(__fastcall *)(int selector, int value);
|
||||
using RsSetPtr_t = void(__fastcall *)(int selector, const void *value);
|
||||
using StateOp_t = void(__fastcall *)();
|
||||
using TexMtxLoad_t = void(__fastcall *)(int unit, const float *m);
|
||||
using TexMtxOp_t = void(__fastcall *)(int unit);
|
||||
using SetFrameFlag_t = void(__fastcall *)(void *frame, void *edx, uint32_t mask, int on);
|
||||
|
||||
// A rect: {bottom, left, top, right}.
|
||||
@@ -133,7 +126,7 @@ void *RampTexture() {
|
||||
if (g_ramp == nullptr)
|
||||
g_ramp = Texture::CreateFromPixels("ClassicAPI\\AlphaGradient", 2, 2, kRampTexels, Texture::DefaultFlags());
|
||||
return g_ramp != nullptr
|
||||
? reinterpret_cast<GetRenderable_t>(Offsets::FUN_TEXTURE_GET_RENDERABLE)(g_ramp, 1, nullptr)
|
||||
? Texture::DeviceTexture(g_ramp)
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
@@ -167,7 +160,7 @@ void Load(const Stage &s) {
|
||||
m[r * 4 + 2] = row[3];
|
||||
m[r * 4 + 3] = 0.0f;
|
||||
}
|
||||
reinterpret_cast<TexMtxLoad_t>(Offsets::FUN_GX_TEXMTX_LOAD)(s.unit, m);
|
||||
Gx::SetTransform(s.unit, m);
|
||||
}
|
||||
|
||||
// Appends the stages of `frame`'s gradient at g_stages[g_count + n]. Returns
|
||||
@@ -180,7 +173,6 @@ int AddStages(const void *frame, int n, int lastUnit) {
|
||||
if (!Frame::Layout::GetRect(frame, rect))
|
||||
return n;
|
||||
const float scale = Game::Read<float>(frame, Offsets::OFF_REGION_EFFECTIVE_SCALE);
|
||||
const auto toNdc = reinterpret_cast<Convert_t>(Offsets::FUN_COORD_DDC_TO_NDC);
|
||||
for (int index = 0; index < 2; ++index) {
|
||||
const float lx = it->second.x[index], ly = it->second.y[index];
|
||||
if (!(lx > 0.0f) && !(ly > 0.0f))
|
||||
@@ -194,8 +186,8 @@ int AddStages(const void *frame, int n, int lastUnit) {
|
||||
const float dy = Game::PixelToInternal(ly * scale) * (index == 0 ? -1.0f : 1.0f);
|
||||
Stage &s = g_stages[g_count + n];
|
||||
s.unit = 1 + g_count + n;
|
||||
toNdc(&s.p0[0], &s.p0[1], ex, ey);
|
||||
toNdc(&s.p1[0], &s.p1[1], ex + dx, ey + dy);
|
||||
Frame::Layout::DdcToNdc(&s.p0[0], &s.p0[1], ex, ey);
|
||||
Frame::Layout::DdcToNdc(&s.p1[0], &s.p1[1], ex + dx, ey + dy);
|
||||
s.on[0] = lx > 0.0f && s.p1[0] != s.p0[0];
|
||||
s.on[1] = ly > 0.0f && s.p1[1] != s.p0[1];
|
||||
if (s.on[0] || s.on[1])
|
||||
@@ -351,16 +343,14 @@ int Begin(const void *frame, bool ancestors) {
|
||||
void *ramp = RampTexture();
|
||||
if (ramp == nullptr)
|
||||
return 0;
|
||||
const auto rs = reinterpret_cast<RsSet_t>(Offsets::FUN_GX_RS_SET);
|
||||
const auto rsPtr = reinterpret_cast<RsSetPtr_t>(Offsets::FUN_GX_RS_SET_PTR);
|
||||
reinterpret_cast<StateOp_t>(Offsets::FUN_GX_STATE_PUSH)();
|
||||
Gx::PushStates();
|
||||
for (int i = g_count; i < g_count + n; ++i) {
|
||||
const int unit = g_stages[i].unit;
|
||||
rsPtr(Offsets::GXRS_TEXTURE0 + unit, ramp);
|
||||
rs(Offsets::GXRS_COMBINER0 + unit, Offsets::GXRS_COMBINE_MODULATE);
|
||||
rs(Offsets::GXRS_TEXGEN0 + unit, Offsets::GXRS_TEXGEN_CAMERA_POS);
|
||||
rs(Offsets::GXRS_TEXXFORM0 + unit, Offsets::GXRS_TEXXFORM_PROJECTED);
|
||||
reinterpret_cast<TexMtxOp_t>(Offsets::FUN_GX_TEXMTX_PUSH)(unit);
|
||||
Gx::SetState(Offsets::GXRS_TEXTURE0 + unit, ramp);
|
||||
Gx::SetState(Offsets::GXRS_COMBINER0 + unit, Offsets::GXRS_COMBINE_MODULATE);
|
||||
Gx::SetState(Offsets::GXRS_TEXGEN0 + unit, Offsets::GXRS_TEXGEN_CAMERA_POS);
|
||||
Gx::SetState(Offsets::GXRS_TEXXFORM0 + unit, Offsets::GXRS_TEXXFORM_PROJECTED);
|
||||
Gx::PushTransform(unit);
|
||||
Load(g_stages[i]);
|
||||
}
|
||||
g_count += n;
|
||||
@@ -371,9 +361,9 @@ void End(int stages) {
|
||||
if (stages == 0)
|
||||
return;
|
||||
for (int i = g_count - 1; i >= g_count - stages; --i)
|
||||
reinterpret_cast<TexMtxOp_t>(Offsets::FUN_GX_TEXMTX_POP)(g_stages[i].unit);
|
||||
Gx::PopTransform(g_stages[i].unit);
|
||||
g_count -= stages;
|
||||
reinterpret_cast<StateOp_t>(Offsets::FUN_GX_STATE_POP)();
|
||||
Gx::PopStates();
|
||||
}
|
||||
|
||||
int StagesInUse() { return g_count; }
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
#include "Common.h"
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "frame/Layout.h"
|
||||
#include "frame/AlphaGradient.h"
|
||||
#include "frame/ClipChildren.h"
|
||||
#include "frame/Destruction.h"
|
||||
@@ -89,7 +90,6 @@ using AddCallback_t = void(__fastcall *)(void *batch, void *edx, Callback_t fn,
|
||||
using SetFrameFlag_t = void(__fastcall *)(void *frame, void *edx, uint32_t mask, int on);
|
||||
using HitTest_t = int(__fastcall *)(void *frame, void *edx, const float *point);
|
||||
using SetupOrtho_t = void(__fastcall *)(const float *rect, const float *point, int unused);
|
||||
using Convert_t = void(__fastcall *)(float *outX, float *outY, float x, float y);
|
||||
|
||||
// A hit rect: {bottom, left, top, right}.
|
||||
enum { BOTTOM, LEFT, TOP, RIGHT };
|
||||
@@ -217,11 +217,9 @@ bool ClipRect(const void *root, float rect[4]) {
|
||||
void DrawInside(float rect[4], Callback_t draw, void *arg) {
|
||||
const Gx::SavedTransforms saved;
|
||||
const Gx::Viewport &vp = saved.SavedViewport();
|
||||
|
||||
const auto toDdc = reinterpret_cast<Convert_t>(Offsets::FUN_COORD_NDC_TO_DDC);
|
||||
float minX = 0, minY = 0, maxX = 0, maxY = 0;
|
||||
toDdc(&minX, &minY, vp.minX, vp.minY);
|
||||
toDdc(&maxX, &maxY, vp.maxX, vp.maxY);
|
||||
Frame::Layout::NdcToDdc(&minX, &minY, vp.minX, vp.minY);
|
||||
Frame::Layout::NdcToDdc(&maxX, &maxY, vp.maxX, vp.maxY);
|
||||
if (minX > rect[LEFT])
|
||||
rect[LEFT] = minX;
|
||||
if (maxX < rect[RIGHT])
|
||||
@@ -233,9 +231,8 @@ void DrawInside(float rect[4], Callback_t draw, void *arg) {
|
||||
|
||||
const float point[2] = {0, 0};
|
||||
reinterpret_cast<SetupOrtho_t>(Offsets::FUN_SETUP_ORTHO_TRANSFORMS)(rect, point, 0);
|
||||
const auto toNdc = reinterpret_cast<Convert_t>(Offsets::FUN_COORD_DDC_TO_NDC);
|
||||
toNdc(&rect[LEFT], &rect[BOTTOM], rect[LEFT], rect[BOTTOM]);
|
||||
toNdc(&rect[RIGHT], &rect[TOP], rect[RIGHT], rect[TOP]);
|
||||
Frame::Layout::DdcToNdc(&rect[LEFT], &rect[BOTTOM], rect[LEFT], rect[BOTTOM]);
|
||||
Frame::Layout::DdcToNdc(&rect[RIGHT], &rect[TOP], rect[RIGHT], rect[TOP]);
|
||||
if (rect[LEFT] < 0.0f) {
|
||||
rect[RIGHT] -= rect[LEFT];
|
||||
rect[LEFT] = 0.0f;
|
||||
|
||||
@@ -632,12 +632,11 @@ void UpdateCountdown(void *frame) {
|
||||
|
||||
// ---- the overrides ------------------------------------------------------------
|
||||
|
||||
using SetFrameAlpha_t = void(__fastcall *)(void *self, void *edx, uint8_t alpha);
|
||||
using OnFrameUpdate_t = void(__fastcall *)(void *self, void *edx, float elapsedSec);
|
||||
using EmitLayer_t = void(__fastcall *)(void *self, void *edx, void *batch, int layer);
|
||||
using Frame::Subclass::EmitLayer_t;
|
||||
using Frame::Subclass::LoadXML_t;
|
||||
using Frame::Subclass::OnFrameUpdate_t;
|
||||
using Frame::Subclass::SetFrameAlpha_t;
|
||||
using OnFrameSizeChanged_t = void(__fastcall *)(void *layout, void *edx, const float *oldRect);
|
||||
using LoadXML_t = uintptr_t(__fastcall *)(void *layout, void *edx, const void *node,
|
||||
void *status);
|
||||
const Frame::ExtraScripts::Script g_onCooldownDone{"oncooldowndone", g_class.TypeIdVar()};
|
||||
|
||||
// From the update walk, where the engine runs OnUpdate.
|
||||
@@ -756,10 +755,9 @@ void LoadModernTemplate(void *layout) {
|
||||
// A texture element's <Color> child into `color`, read as CSimpleTexture::
|
||||
// LoadXML reads one (it passes its load status too); false when it has none.
|
||||
bool XmlTextureColor(const void *node, void *status, uint32_t &color) {
|
||||
using ReadColor_t = int(__fastcall *)(const void *node, uint32_t *bgra, void *status);
|
||||
for (const void *c = Xml::FirstChild(node); c != nullptr; c = Xml::NextSibling(c)) {
|
||||
if (Xml::TagIs(c, "Color")) {
|
||||
reinterpret_cast<ReadColor_t>(Offsets::FUN_XML_READ_COLOR)(c, &color, status);
|
||||
Xml::ReadColor(c, color, status);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,18 @@ inline void *Of(const void *object) {
|
||||
return const_cast<uint8_t *>(static_cast<const uint8_t *>(object) + Offsets::OFF_REGION_ANCHOR);
|
||||
}
|
||||
|
||||
// Layout units (DDC, the space rects are stored in) to the device's 0..1
|
||||
// (NDC) and back: each axis scaled by the screen's (VAR_COORD_DDC_*_SCALE).
|
||||
// Either out pointer may be null, and may alias its input.
|
||||
inline void DdcToNdc(float *outX, float *outY, float x, float y) {
|
||||
using Fn = void(__fastcall *)(float *, float *, float, float);
|
||||
reinterpret_cast<Fn>(Offsets::FUN_COORD_DDC_TO_NDC)(outX, outY, x, y);
|
||||
}
|
||||
inline void NdcToDdc(float *outX, float *outY, float x, float y) {
|
||||
using Fn = void(__fastcall *)(float *, float *, float, float);
|
||||
reinterpret_cast<Fn>(Offsets::FUN_COORD_NDC_TO_DDC)(outX, outY, x, y);
|
||||
}
|
||||
|
||||
// The region or frame a layout sub-object belongs to, for the layout
|
||||
// vtable's overrides and hooks.
|
||||
inline void *OwnerOf(void *layout) {
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include "Common.h"
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "frame/Layout.h"
|
||||
#include "baselib/Ascii.h"
|
||||
#include "frame/Destruction.h"
|
||||
#include "frame/MotionFocus.h"
|
||||
@@ -63,7 +64,6 @@ using EnableEvent_t = void(__thiscall *)(void *frame, int kind, int priority);
|
||||
using DisableEvent_t = void(__thiscall *)(void *frame, int kind);
|
||||
using Button_t = void(__thiscall *)(void *frame, const void *event);
|
||||
using HitTest_t = int(__thiscall *)(void *frame, const float *point);
|
||||
using NDCToDDC_t = void(__fastcall *)(float *outX, float *outY, float x, float y);
|
||||
|
||||
// Frames with their mouse bit on and that half off.
|
||||
std::unordered_set<void *> g_clickOff;
|
||||
@@ -119,7 +119,7 @@ void ClickTargets(uint8_t *ctx, std::vector<void *> &out) {
|
||||
void *const primary = Game::Read<void *>(ctx, Offsets::OFF_UI_CONTEXT_MOUSE_FOCUS);
|
||||
const float *mouse = Game::Ptr<float>(ctx, Offsets::OFF_UI_CONTEXT_MOUSE_POSITION);
|
||||
float point[2] = {0.0f, 0.0f};
|
||||
reinterpret_cast<NDCToDDC_t>(Offsets::FUN_COORD_NDC_TO_DDC)(&point[0], &point[1], mouse[0], mouse[1]);
|
||||
Frame::Layout::NdcToDdc(&point[0], &point[1], mouse[0], mouse[1]);
|
||||
const auto hitTest = reinterpret_cast<HitTest_t>(Offsets::FUN_FRAME_HIT_TEST);
|
||||
|
||||
bool pastPrimary = primary == nullptr;
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "texture/Load.h"
|
||||
|
||||
namespace Frame::RenderBatch {
|
||||
|
||||
namespace {
|
||||
|
||||
using GetRenderable_t = void *(__fastcall *)(void *texture, int load, void *callback);
|
||||
using ReserveQuads_t = void(__thiscall *)(void *array, uint32_t extra, int round);
|
||||
|
||||
struct QuadRecord {
|
||||
@@ -40,8 +40,7 @@ void QueueStrip(void *batch, void *texture, Blend blend, const C3Vector *positio
|
||||
const C2Vector *texCoords, const uint32_t *color) {
|
||||
// Loading on demand, as the texture emit does: a texture still streaming
|
||||
// is finished here, so the first rebuild already draws it.
|
||||
void *device = reinterpret_cast<GetRenderable_t>(Offsets::FUN_TEXTURE_GET_RENDERABLE)(
|
||||
texture, 1, nullptr);
|
||||
void *device = Texture::DeviceTexture(texture);
|
||||
if (device == nullptr)
|
||||
return;
|
||||
reinterpret_cast<ReserveQuads_t>(Offsets::FUN_RENDERBATCH_RESERVE_QUADS)(
|
||||
|
||||
@@ -118,6 +118,13 @@ using GetScriptMethod_t = int(__fastcall *)(void *self, void *edx, void *L, cons
|
||||
using IsA_t = bool(__fastcall *)(void *self, void *edx, int typeId);
|
||||
using IsObjectType_t = bool(__fastcall *)(void *self, void *edx, const char *name);
|
||||
|
||||
// The slots a class overrides for itself, for their base calls.
|
||||
using SetFrameAlpha_t = void(__fastcall *)(void *self, void *edx, uint8_t alpha);
|
||||
using OnFrameUpdate_t = void(__fastcall *)(void *self, void *edx, float elapsedSec);
|
||||
using EmitLayer_t = void(__fastcall *)(void *self, void *edx, void *batch, int layer);
|
||||
// The layout vtable's node loader (Offsets::VTBL_XML_NODE_LOADER).
|
||||
using LoadXML_t = uintptr_t(__fastcall *)(void *layout, void *edx, const void *node, void *status);
|
||||
|
||||
// Our part released, then the engine class's deleting destructor.
|
||||
template <auto &C>
|
||||
void *__fastcall DeletingDestructor(void *self, void *, uint32_t flags) {
|
||||
|
||||
+69
-2
@@ -20,11 +20,12 @@
|
||||
// after; SavedTransforms does that for a scope.
|
||||
|
||||
#include "Offsets.h"
|
||||
#include "gx/Matrix.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Gx {
|
||||
|
||||
using Matrix = float[16];
|
||||
|
||||
inline void GetProjection(Matrix &m) {
|
||||
reinterpret_cast<void(__fastcall *)(float *)>(Offsets::FUN_GX_GET_PROJECTION)(m);
|
||||
}
|
||||
@@ -56,6 +57,72 @@ inline void SetViewport(const Viewport &v) {
|
||||
v.maxZ);
|
||||
}
|
||||
|
||||
// ---- render states (GXRS_*) -----------------------------------------------------
|
||||
// The device journals each state written after a push; the pop puts every one
|
||||
// back. The engine brackets each region-layer draw in a pair.
|
||||
|
||||
inline void PushStates() { reinterpret_cast<void(__fastcall *)()>(Offsets::FUN_GX_STATE_PUSH)(); }
|
||||
inline void PopStates() { reinterpret_cast<void(__fastcall *)()>(Offsets::FUN_GX_STATE_POP)(); }
|
||||
|
||||
// The render states written in a scope, put back when it ends.
|
||||
class SavedStates {
|
||||
public:
|
||||
SavedStates() { PushStates(); }
|
||||
~SavedStates() { PopStates(); }
|
||||
SavedStates(const SavedStates &) = delete;
|
||||
SavedStates &operator=(const SavedStates &) = delete;
|
||||
};
|
||||
|
||||
inline void SetState(int state, int value) {
|
||||
reinterpret_cast<void(__fastcall *)(int, int)>(Offsets::FUN_GX_RS_SET)(state, value);
|
||||
}
|
||||
// A pointer state: a texture bind.
|
||||
inline void SetState(int state, const void *value) {
|
||||
reinterpret_cast<void(__fastcall *)(int, const void *)>(Offsets::FUN_GX_RS_SET_PTR)(state, value);
|
||||
}
|
||||
// A colour state (fog colour, material).
|
||||
inline void SetStateWord(int state, uint32_t value) {
|
||||
reinterpret_cast<void(__fastcall *)(int, int, uint32_t)>(Offsets::FUN_GX_RS_SET_WORD)(state, 0, value);
|
||||
}
|
||||
inline void SetStateFloat(int state, float value) {
|
||||
reinterpret_cast<void(__fastcall *)(int, int, float)>(Offsets::FUN_GX_RS_SET_FLOAT)(state, 0, value);
|
||||
}
|
||||
inline int GetState(int state) {
|
||||
int value = 0;
|
||||
reinterpret_cast<void(__fastcall *)(int, int *)>(Offsets::FUN_GX_RS_GET_INT)(state, &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
// ---- transform stacks -----------------------------------------------------------
|
||||
// Each texture unit has a matrix stack, and stack 8 is the world transform.
|
||||
|
||||
inline void PushTransform(int unit) {
|
||||
reinterpret_cast<void(__fastcall *)(int)>(Offsets::FUN_GX_TEXMTX_PUSH)(unit);
|
||||
}
|
||||
inline void PushTransform(int unit, const float *m) {
|
||||
reinterpret_cast<void(__fastcall *)(int, const float *)>(Offsets::FUN_GX_TEXMTX_PUSH_LOAD)(unit, m);
|
||||
}
|
||||
inline void PopTransform(int unit) {
|
||||
reinterpret_cast<void(__fastcall *)(int)>(Offsets::FUN_GX_TEXMTX_POP)(unit);
|
||||
}
|
||||
// Over the top of the unit's stack.
|
||||
inline void SetTransform(int unit, const float *m) {
|
||||
reinterpret_cast<void(__fastcall *)(int, const float *)>(Offsets::FUN_GX_TEXMTX_LOAD)(unit, m);
|
||||
}
|
||||
|
||||
// ---- clear ----------------------------------------------------------------------
|
||||
|
||||
inline uint32_t GetClearColor() {
|
||||
uint32_t argb = 0;
|
||||
reinterpret_cast<uint32_t *(__fastcall *)(uint32_t *)>(Offsets::FUN_GX_GET_CLEAR_COLOR)(&argb);
|
||||
return argb;
|
||||
}
|
||||
inline void SetClearColor(uint32_t argb) {
|
||||
reinterpret_cast<void(__stdcall *)(uint32_t)>(Offsets::FUN_GX_SET_CLEAR_COLOR)(argb);
|
||||
}
|
||||
// `mask` 1 the colour, 2 the depth.
|
||||
inline void Clear(uint32_t mask) { reinterpret_cast<void(__fastcall *)(uint32_t)>(Offsets::FUN_GX_CLEAR)(mask); }
|
||||
|
||||
// The projection, view and viewport, put back when the scope ends.
|
||||
class SavedTransforms {
|
||||
public:
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
// 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/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
// The engine's 4x4 matrix helpers (Offsets.h FUN_MATRIX_*, FUN_TRANSFORM_*).
|
||||
// Matrices are row-vector: a point is a row times the matrix, rows 0..2 are
|
||||
// the scaled axes and row 3 the translation. Each transform below
|
||||
// pre-multiplies, so the one called last applies to a point first.
|
||||
|
||||
#include "Offsets.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace Gx {
|
||||
|
||||
using Matrix = float[16];
|
||||
|
||||
inline void Identity(float *m) {
|
||||
std::memset(m, 0, sizeof(Matrix));
|
||||
m[0] = m[5] = m[10] = m[15] = 1.0f;
|
||||
}
|
||||
|
||||
// TranslateMatrix: row 3 += t · rows 0..2.
|
||||
inline void Translate(float *m, const float (&t)[3]) {
|
||||
reinterpret_cast<void(__thiscall *)(float *, const float *)>(Offsets::FUN_MATRIX_TRANSLATE)(m, t);
|
||||
}
|
||||
|
||||
// RotateMatrix: by `angle` radians about the unit `axis`.
|
||||
inline void Rotate(float *m, float angle, const float (&axis)[3]) {
|
||||
reinterpret_cast<void(__thiscall *)(float *, float, const float *, int)>(Offsets::FUN_MATRIX_ROTATE)(
|
||||
m, angle, axis, 1);
|
||||
}
|
||||
|
||||
// By the quaternion {x, y, z, w}.
|
||||
inline void RotateQuaternion(float *m, const float *q) {
|
||||
reinterpret_cast<void(__thiscall *)(float *, const float *)>(Offsets::FUN_MATRIX_ROTATE_QUATERNION)(m, q);
|
||||
}
|
||||
|
||||
inline void Scale(float *m, float s) {
|
||||
reinterpret_cast<void(__thiscall *)(float *, float)>(Offsets::FUN_MATRIX_SCALE)(m, s);
|
||||
}
|
||||
|
||||
// MultiplyMatrix4: out = a × b.
|
||||
inline void Multiply(float *out, const float *a, const float *b) {
|
||||
reinterpret_cast<float *(__fastcall *)(float *, const float *, const float *)>(Offsets::FUN_MATRIX_MULTIPLY)(
|
||||
out, a, b);
|
||||
}
|
||||
|
||||
// m = m × b.
|
||||
inline void MultiplyInPlace(float *m, const float *b) {
|
||||
reinterpret_cast<float *(__thiscall *)(float *, const float *)>(Offsets::FUN_MATRIX_MULTIPLY_IN_PLACE)(m, b);
|
||||
}
|
||||
|
||||
// InvertAffineMatrix: the inverse of a rotation, uniform `scale` and
|
||||
// translation.
|
||||
inline void InvertAffine(const float *m, float *out, float scale) {
|
||||
reinterpret_cast<void(__thiscall *)(const float *, float *, float)>(Offsets::FUN_MATRIX_INVERT_AFFINE)(
|
||||
m, out, scale);
|
||||
}
|
||||
|
||||
// The point through the matrix (`in` and `out` may be the same).
|
||||
inline void TransformPoint(const float (&in)[3], const float *m, float (&out)[3]) {
|
||||
float v[3] = {in[0], in[1], in[2]};
|
||||
reinterpret_cast<float *(__fastcall *)(float *, float *, const float *)>(Offsets::FUN_TRANSFORM_POINT_IN_PLACE)(
|
||||
out, v, m);
|
||||
}
|
||||
|
||||
// The box {min xyz, max xyz} through the matrix, as the box around its
|
||||
// transformed corners.
|
||||
inline void TransformBox(const float *m, const float (&box)[6], float (&out)[6]) {
|
||||
reinterpret_cast<void(__fastcall *)(const float *, const float *, float *)>(Offsets::FUN_TRANSFORM_BOX)(m, box,
|
||||
out);
|
||||
}
|
||||
|
||||
} // namespace Gx
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "frame/Layout.h"
|
||||
#include "tick/FrameTick.h"
|
||||
|
||||
namespace Input::CursorDelta {
|
||||
@@ -44,7 +45,6 @@ bool g_sampled = false;
|
||||
|
||||
// What GetCursorPosition pushes now, or false before the UI top exists.
|
||||
bool ReadCursor(Position &out) {
|
||||
using NdcToDdc_t = void(__fastcall *)(float *outX, float *outY, float x, float y);
|
||||
const void *top = Game::Read<const void *>(Offsets::VAR_UI_CONTEXT_PTR);
|
||||
if (top == nullptr)
|
||||
return false;
|
||||
@@ -52,7 +52,7 @@ bool ReadCursor(Position &out) {
|
||||
const float ndcY = Game::Read<float>(top, Offsets::OFF_UI_CONTEXT_MOUSE_POSITION + 4);
|
||||
float ddcX = 0.0f;
|
||||
float ddcY = 0.0f;
|
||||
reinterpret_cast<NdcToDdc_t>(Offsets::FUN_COORD_NDC_TO_DDC)(&ddcX, &ddcY, ndcX, ndcY);
|
||||
Frame::Layout::NdcToDdc(&ddcX, &ddcY, ndcX, ndcY);
|
||||
out = {Game::InternalToPixel(ddcX), Game::InternalToPixel(ddcY)};
|
||||
return true;
|
||||
}
|
||||
|
||||
+114
-9
@@ -19,6 +19,7 @@
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace Model::M2 {
|
||||
@@ -70,13 +71,37 @@ inline void PlayAnimation(void *model, int keyBone, uint32_t id, int variation,
|
||||
offset, speed, blend, primary);
|
||||
}
|
||||
|
||||
// The key bone's sequence as it plays (FUN_M2MODEL_GET_KEY_BONE_ANIM_STATE).
|
||||
struct AnimState {
|
||||
uint32_t id;
|
||||
uint32_t variation;
|
||||
uint32_t position; // ms into the sequence
|
||||
float speed;
|
||||
uint32_t lo;
|
||||
uint32_t hi;
|
||||
uint32_t latch;
|
||||
};
|
||||
static_assert(sizeof(AnimState) == Offsets::M2_KEY_BONE_ANIM_STATE_SIZE);
|
||||
static_assert(offsetof(AnimState, id) == Offsets::OFF_M2_KEY_BONE_ANIM_STATE_ID);
|
||||
static_assert(offsetof(AnimState, variation) == Offsets::OFF_M2_KEY_BONE_ANIM_STATE_VARIATION);
|
||||
static_assert(offsetof(AnimState, position) == Offsets::OFF_M2_KEY_BONE_ANIM_STATE_POSITION);
|
||||
static_assert(offsetof(AnimState, speed) == Offsets::OFF_M2_KEY_BONE_ANIM_STATE_SPEED);
|
||||
static_assert(offsetof(AnimState, lo) == Offsets::OFF_M2_KEY_BONE_ANIM_STATE_LO);
|
||||
static_assert(offsetof(AnimState, hi) == Offsets::OFF_M2_KEY_BONE_ANIM_STATE_HI);
|
||||
static_assert(offsetof(AnimState, latch) == Offsets::OFF_M2_KEY_BONE_ANIM_STATE_LATCH);
|
||||
|
||||
// Waits for an unloaded instance.
|
||||
inline AnimState GetAnimState(void *model, int keyBone) {
|
||||
using Fn = void(__thiscall *)(void *, int, AnimState *);
|
||||
AnimState state;
|
||||
reinterpret_cast<Fn>(Offsets::FUN_M2MODEL_GET_KEY_BONE_ANIM_STATE)(model, keyBone, &state);
|
||||
return state;
|
||||
}
|
||||
|
||||
// Where the key bone's animation stands, in ms into its sequence. Waits for
|
||||
// an unloaded instance.
|
||||
inline int GetAnimPosition(void *model, int keyBone) {
|
||||
using Fn = void(__thiscall *)(void *, int, void *);
|
||||
uint32_t state[Offsets::M2_KEY_BONE_ANIM_STATE_SIZE / 4];
|
||||
reinterpret_cast<Fn>(Offsets::FUN_M2MODEL_GET_KEY_BONE_ANIM_STATE)(model, keyBone, state);
|
||||
return static_cast<int>(state[Offsets::OFF_M2_KEY_BONE_ANIM_STATE_POSITION / 4]);
|
||||
return static_cast<int>(GetAnimState(model, keyBone).position);
|
||||
}
|
||||
|
||||
// Moves the key bone's animation to `ms` into its sequence, keeping its speed.
|
||||
@@ -200,16 +225,35 @@ inline void GetBoundingSphere(void *model, float (&sphere)[4]) {
|
||||
reinterpret_cast<Fn>(Offsets::FUN_M2MODEL_GET_BOUNDING_SPHERE)(model, sphere);
|
||||
}
|
||||
|
||||
// An animation's sequence record (FUN_M2MODEL_GET_SEQUENCE_INFO), all zero
|
||||
// when the model has no sequence for it.
|
||||
struct SequenceInfo {
|
||||
uint32_t flags;
|
||||
uint32_t length; // ms
|
||||
float speed; // the move speed times the model's scale
|
||||
float bounds[6]; // {min xyz, max xyz}
|
||||
uint8_t rest[Offsets::M2_SEQUENCE_INFO_SIZE - 0x24];
|
||||
};
|
||||
static_assert(sizeof(SequenceInfo) == Offsets::M2_SEQUENCE_INFO_SIZE);
|
||||
static_assert(offsetof(SequenceInfo, length) == Offsets::OFF_M2_SEQUENCE_INFO_LENGTH);
|
||||
static_assert(offsetof(SequenceInfo, speed) == Offsets::OFF_M2_SEQUENCE_INFO_SPEED);
|
||||
static_assert(offsetof(SequenceInfo, bounds) == Offsets::OFF_M2_SEQUENCE_INFO_BOUNDS);
|
||||
|
||||
// Waits for an unloaded file.
|
||||
inline SequenceInfo GetSequenceInfo(void *model, uint32_t animation, uint32_t variation) {
|
||||
using Fn = void(__thiscall *)(void *, uint32_t, uint32_t, SequenceInfo *);
|
||||
SequenceInfo info{};
|
||||
reinterpret_cast<Fn>(Offsets::FUN_M2MODEL_GET_SEQUENCE_INFO)(model, animation, variation, &info);
|
||||
return info;
|
||||
}
|
||||
|
||||
// The bounds of the animation's sequence, all zero when the model has none.
|
||||
// Waits for an unloaded file.
|
||||
inline void GetSequenceBounds(void *model, uint32_t animation, uint32_t variation,
|
||||
float (&box)[6]) {
|
||||
using Fn = void(__thiscall *)(void *, uint32_t, uint32_t, void *);
|
||||
uint8_t record[Offsets::M2_SEQUENCE_INFO_SIZE];
|
||||
reinterpret_cast<Fn>(Offsets::FUN_M2MODEL_GET_SEQUENCE_INFO)(model, animation, variation,
|
||||
record);
|
||||
const SequenceInfo info = GetSequenceInfo(model, animation, variation);
|
||||
for (int i = 0; i < 6; ++i)
|
||||
box[i] = Game::Read<float>(record, Offsets::OFF_M2_SEQUENCE_INFO_BOUNDS + i * 4);
|
||||
box[i] = info.bounds[i];
|
||||
}
|
||||
|
||||
// The world pick's steps (Offsets::FUN_M2SCENE_RAY_HIT): ray hits on, the
|
||||
@@ -242,6 +286,23 @@ inline void GetBaseTransform(void *model, float (&m)[16]) {
|
||||
reinterpret_cast<Fn>(Offsets::FUN_M2MODEL_GET_BASE_TRANSFORM)(model, m);
|
||||
}
|
||||
|
||||
// CM2Model::SetBaseTransform: the base matrix as given.
|
||||
inline void SetBaseTransform(void *model, const float (&m)[16]) {
|
||||
using Fn = void(__thiscall *)(void *, const float *);
|
||||
reinterpret_cast<Fn>(Offsets::FUN_M2MODEL_SET_BASE_TRANSFORM)(model, m);
|
||||
}
|
||||
|
||||
// CM2Model::SetBaseTransformTRS: identity, translated to `position`, rotated
|
||||
// by `angle` about `axis`, then each row scaled.
|
||||
inline void SetBaseTRS(void *model, const float (&position)[3], float angle, const float (&axis)[3],
|
||||
const float (&scale)[3]) {
|
||||
using Fn = void(__thiscall *)(void *, const float *, float, const float *, const float *);
|
||||
reinterpret_cast<Fn>(Offsets::FUN_M2MODEL_SET_BASE_TRS)(model, position, angle, axis, scale);
|
||||
}
|
||||
|
||||
// The base matrix in place, for the engine's matrix calls after SetBaseTRS.
|
||||
inline float *BaseMatrix(void *model) { return Game::Ptr<float>(model, Offsets::OFF_M2MODEL_BASE_MATRIX); }
|
||||
|
||||
inline float GetAlpha(void *model) {
|
||||
using Fn = float(__thiscall *)(void *);
|
||||
return reinterpret_cast<Fn>(Offsets::FUN_M2MODEL_GET_ALPHA)(model);
|
||||
@@ -264,6 +325,12 @@ inline void AnimateScene(void *scene, const float *cameraPos) {
|
||||
reinterpret_cast<Fn>(Offsets::FUN_M2SCENE_ANIMATE)(scene, cameraPos);
|
||||
}
|
||||
|
||||
// M2SceneDraw: pass 0 the opaque models, 1 the translucent ones.
|
||||
inline void DrawScene(void *scene, uint32_t pass) {
|
||||
using Fn = void(__thiscall *)(void *, uint32_t);
|
||||
reinterpret_cast<Fn>(Offsets::FUN_M2SCENE_DRAW)(scene, pass);
|
||||
}
|
||||
|
||||
inline void AttachItemVisuals(void *model, uint32_t visualID) {
|
||||
using Fn = void(__fastcall *)(void *, uint32_t);
|
||||
reinterpret_cast<Fn>(Offsets::FUN_ATTACH_ITEM_VISUALS)(model, visualID);
|
||||
@@ -294,6 +361,44 @@ inline uint16_t LookupIndex(void *model, uintptr_t tableOffset, uint32_t id) {
|
||||
return reinterpret_cast<Fn>(Offsets::FUN_M2_LOOKUP_INDEX)(id, Data(model) + tableOffset);
|
||||
}
|
||||
|
||||
// ---- a model light (M2LIGHT_SIZE bytes) -----------------------------------------
|
||||
|
||||
inline void InitLight(void *light) {
|
||||
reinterpret_cast<void(__fastcall *)(void *)>(Offsets::FUN_M2LIGHT_INITIALIZE)(light);
|
||||
}
|
||||
// 0 directional, 1 point.
|
||||
inline void SetLightType(void *light, int type) {
|
||||
reinterpret_cast<void(__thiscall *)(void *, int)>(Offsets::FUN_M2LIGHT_SET_TYPE)(light, type);
|
||||
}
|
||||
inline void SetLightEnabled(void *light, bool enabled) {
|
||||
reinterpret_cast<void(__thiscall *)(void *, int)>(Offsets::FUN_M2LIGHT_SET_ENABLED)(light, enabled ? 1 : 0);
|
||||
}
|
||||
inline void SetLightDirection(void *light, const float *v) {
|
||||
reinterpret_cast<void(__thiscall *)(void *, const float *)>(Offsets::FUN_M2LIGHT_SET_DIRECTION)(light, v);
|
||||
}
|
||||
inline void SetLightPosition(void *light, const float *v) {
|
||||
reinterpret_cast<void(__thiscall *)(void *, const float *)>(Offsets::FUN_M2LIGHT_SET_POSITION)(light, v);
|
||||
}
|
||||
|
||||
// ---- animation classes (Offsets::FUN_IS_*_ANIMATION) -----------------------------
|
||||
// The unit's tests of an AnimationData ID. The death test is __stdcall, the
|
||||
// others __fastcall.
|
||||
|
||||
inline bool IsDeathAnimation(int anim) {
|
||||
return reinterpret_cast<int(__stdcall *)(int)>(Offsets::FUN_IS_DEATH_ANIMATION)(anim) != 0;
|
||||
}
|
||||
|
||||
namespace Detail {
|
||||
inline bool AnimTest(uintptr_t fn, int anim) { return reinterpret_cast<int(__fastcall *)(int)>(fn)(anim) != 0; }
|
||||
} // namespace Detail
|
||||
|
||||
inline bool IsBowAnimation(int anim) { return Detail::AnimTest(Offsets::FUN_IS_BOW_ANIMATION, anim); }
|
||||
inline bool IsRifleAnimation(int anim) { return Detail::AnimTest(Offsets::FUN_IS_RIFLE_ANIMATION, anim); }
|
||||
inline bool IsThrownAnimation(int anim) { return Detail::AnimTest(Offsets::FUN_IS_THROWN_ANIMATION, anim); }
|
||||
inline bool IsEmoteAnimation(int anim) { return Detail::AnimTest(Offsets::FUN_IS_EMOTE_ANIMATION, anim); }
|
||||
inline bool IsSpellCastAnimation(int anim) { return Detail::AnimTest(Offsets::FUN_IS_SPELL_CAST_ANIMATION, anim); }
|
||||
inline bool IsMoveAnimation(int anim) { return Detail::AnimTest(Offsets::FUN_IS_MOVE_ANIMATION, anim); }
|
||||
|
||||
} // namespace Model::M2
|
||||
|
||||
namespace Model::Pane {
|
||||
|
||||
+9
-17
@@ -51,6 +51,7 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "frame/Layout.h"
|
||||
#include "gx/Device.h"
|
||||
#include "model/Camera.h"
|
||||
#include "model/DisplayInfo.h"
|
||||
@@ -72,16 +73,11 @@ constexpr uint32_t kTexels = kSize * kSize;
|
||||
|
||||
using CreateScene_t = void *(__cdecl *)();
|
||||
using ReleaseScene_t = void(__thiscall *)(void *scene);
|
||||
using DrawScene_t = void(__thiscall *)(void *scene, uint32_t pass);
|
||||
using ScreenSize_t = void(__fastcall *)(float *rect);
|
||||
using DdcToNdc_t = void(__fastcall *)(float *x, float *y, float inX, float inY);
|
||||
using DeviceGate_t = int(__cdecl *)();
|
||||
using MasterGet_t = bool(__fastcall *)(uint32_t cap);
|
||||
using MasterSet_t = void(__fastcall *)(uint32_t cap, uint32_t on);
|
||||
using SetClearColor_t = void(__stdcall *)(uint32_t argb);
|
||||
using Clear_t = void(__fastcall *)(uint32_t mask);
|
||||
using AlphaMask_t = const uint8_t *(__fastcall *)(uint32_t size);
|
||||
using GetDeviceTexture_t = void *(__fastcall *)(void *texture, uint32_t wait, void *callback);
|
||||
using MarkDirty_t = void(__fastcall *)(void *gxTex, const int32_t *rect, uint32_t immediate);
|
||||
using SetImage_t = void(__thiscall *)(void *region, void *texture);
|
||||
|
||||
@@ -159,9 +155,8 @@ bool Bake(Portrait &p) {
|
||||
const Gx::SavedTransforms saved;
|
||||
const float aspect = static_cast<float>((static_cast<double>(x1) - x0) /
|
||||
(static_cast<double>(y1) - y0));
|
||||
auto toNdc = reinterpret_cast<DdcToNdc_t>(Offsets::FUN_COORD_DDC_TO_NDC);
|
||||
toNdc(&x0, &y0, x0, y0);
|
||||
toNdc(&x1, &y1, x1, y1);
|
||||
Frame::Layout::DdcToNdc(&x0, &y0, x0, y0);
|
||||
Frame::Layout::DdcToNdc(&x1, &y1, x1, y1);
|
||||
|
||||
// First collection: evaluate the portrait camera.
|
||||
M2::IsLoaded(copy, 1, 1);
|
||||
@@ -173,9 +168,8 @@ bool Bake(Portrait &p) {
|
||||
const float rect[4] = {0.0f, 0.0f, 1.0f, aspect};
|
||||
Model::Camera::SetDeviceTransforms(camera, rect);
|
||||
Gx::SetViewport({x0, x1, y0, y1, 0.0f, 1.0f});
|
||||
reinterpret_cast<SetClearColor_t>(Offsets::FUN_GX_SET_CLEAR_COLOR)(0);
|
||||
auto clear = reinterpret_cast<Clear_t>(Offsets::FUN_GX_CLEAR);
|
||||
clear(3);
|
||||
Gx::SetClearColor(0);
|
||||
Gx::Clear(3);
|
||||
|
||||
// Second collection from the portrait eye, then both passes.
|
||||
M2::IsReady(copy, 1, 1);
|
||||
@@ -184,22 +178,20 @@ bool Bake(Portrait &p) {
|
||||
M2::SetRenderCallback(copy, reinterpret_cast<const void *>(Offsets::FUN_PORTRAIT_LIGHTING),
|
||||
nullptr);
|
||||
M2::AnimateScene(scene, &eye.x);
|
||||
auto draw = reinterpret_cast<DrawScene_t>(Offsets::FUN_M2SCENE_DRAW);
|
||||
draw(scene, 0);
|
||||
draw(scene, 1);
|
||||
M2::DrawScene(scene, 0);
|
||||
M2::DrawScene(scene, 1);
|
||||
|
||||
const int32_t box[4] = {0, 0, static_cast<int32_t>(kSize), static_cast<int32_t>(kSize)};
|
||||
TexelArray out{kTexels, kTexels, p.texels.data(), kTexels};
|
||||
reinterpret_cast<void(__fastcall *)(const int32_t *, TexelArray *)>(
|
||||
Offsets::FUN_GX_READ_PIXELS)(box, &out);
|
||||
clear(3);
|
||||
Gx::Clear(3);
|
||||
const auto *mask = reinterpret_cast<const AlphaMask *>(
|
||||
reinterpret_cast<AlphaMask_t>(Offsets::FUN_PORTRAIT_ALPHA_MASK)(kSize));
|
||||
if (out.data == p.texels.data()) {
|
||||
for (uint32_t i = 0; i < kTexels; ++i)
|
||||
p.texels[i] = (p.texels[i] & 0x00FFFFFFu) | static_cast<uint32_t>(mask->alpha[i]) << 24;
|
||||
void *gxTex = reinterpret_cast<GetDeviceTexture_t>(Offsets::FUN_TEXTURE_GET_RENDERABLE)(
|
||||
p.texture, 1, nullptr);
|
||||
void *gxTex = Texture::DeviceTexture(p.texture);
|
||||
reinterpret_cast<MarkDirty_t>(Offsets::FUN_GX_TEX_MARK_RECT_DIRTY)(gxTex, box, 1);
|
||||
}
|
||||
}
|
||||
|
||||
+32
-49
@@ -107,6 +107,7 @@
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "texture/Load.h"
|
||||
#include "api/Documentation.h"
|
||||
#include "frame/ExtraScripts.h"
|
||||
#include "frame/LayerChange.h"
|
||||
@@ -221,8 +222,6 @@ void InstallCamera(void *frame) {
|
||||
|
||||
// ---- the light and fog ---------------------------------------------------------------
|
||||
|
||||
using LightInt_t = void(__thiscall *)(void *light, int value);
|
||||
using LightVector_t = void(__thiscall *)(void *light, const float *v);
|
||||
|
||||
void *LightOf(void *frame) { return Game::Ptr<uint8_t>(frame, Offsets::OFF_SIMPLEMODEL_LIGHT); }
|
||||
float *AmbientOf(void *frame) { return Game::Ptr<float>(LightOf(frame), Offsets::OFF_M2LIGHT_AMBIENT); }
|
||||
@@ -230,22 +229,22 @@ float *DiffuseOf(void *frame) { return Game::Ptr<float>(LightOf(frame), Offsets:
|
||||
|
||||
void SetLightType(void *frame, uint32_t type) {
|
||||
F(frame).lightType = type;
|
||||
reinterpret_cast<LightInt_t>(Offsets::FUN_M2LIGHT_SET_TYPE)(LightOf(frame), static_cast<int>(type));
|
||||
M2::SetLightType(LightOf(frame), static_cast<int>(type));
|
||||
}
|
||||
|
||||
void SetLightVisible(void *frame, bool visible) {
|
||||
F(frame).lightVisible = visible ? 1 : 0;
|
||||
reinterpret_cast<LightInt_t>(Offsets::FUN_M2LIGHT_SET_ENABLED)(LightOf(frame), visible ? 1 : 0);
|
||||
M2::SetLightEnabled(LightOf(frame), visible);
|
||||
}
|
||||
|
||||
void SetLightDirection(void *frame, const Vec3 &v) {
|
||||
F(frame).lightDirection = v;
|
||||
reinterpret_cast<LightVector_t>(Offsets::FUN_M2LIGHT_SET_DIRECTION)(LightOf(frame), &v.x);
|
||||
M2::SetLightDirection(LightOf(frame), &v.x);
|
||||
}
|
||||
|
||||
void SetLightPosition(void *frame, const Vec3 &v) {
|
||||
F(frame).lightPosition = v;
|
||||
reinterpret_cast<LightVector_t>(Offsets::FUN_M2LIGHT_SET_POSITION)(LightOf(frame), &v.x);
|
||||
M2::SetLightPosition(LightOf(frame), &v.x);
|
||||
}
|
||||
|
||||
void SetColor(float *color, const Vec3 &v) {
|
||||
@@ -377,11 +376,6 @@ void CameraTransforms(void *frame, void *camera, const float (&rect)[4]) {
|
||||
// without depth writes: each model then draws over the shadows, its own
|
||||
// included.
|
||||
|
||||
using GxRsSet_t = void(__fastcall *)(int selector, int value);
|
||||
using GxRsSetPtr_t = void(__fastcall *)(int selector, const void *value);
|
||||
using GxRsSetWord_t = void(__fastcall *)(int selector, int, uint32_t value);
|
||||
using GxState_t = void(__fastcall *)();
|
||||
using GetRenderable_t = void *(__fastcall *)(void *texture, int force, void *);
|
||||
using PrimStreams_t = void(__fastcall *)(int count, const void *pos, int posStride, const void *normal,
|
||||
int normalStride, const void *colors, int colorStride,
|
||||
int unused8, int unused9, const void *uv0, int uv0Stride,
|
||||
@@ -401,7 +395,7 @@ struct Blob {
|
||||
bool MakeBlob(void *model, Blob &blob) {
|
||||
float *b = blob.bounds;
|
||||
M2::GetSequenceBounds(model, 0, 0, blob.bounds);
|
||||
const float epsilon = Game::Read<float>(Offsets::VAR_HAS_RANGE_EPSILON);
|
||||
const float epsilon = Game::Read<float>(Offsets::VAR_TWO_POW_MINUS_22);
|
||||
if (std::fabs(b[4] - b[1]) < epsilon || std::fabs(b[3] - b[0]) < epsilon)
|
||||
return false;
|
||||
constexpr float kClamp = static_cast<float>(Offsets::SHADOW_BOUNDS_CLAMP);
|
||||
@@ -507,31 +501,26 @@ void DrawShadows(void *frame, const float (&eye)[3]) {
|
||||
if (!any)
|
||||
return;
|
||||
World::Backdrop *world = CameraOf(frame) != nullptr ? F(frame).world : nullptr;
|
||||
auto rs = reinterpret_cast<GxRsSet_t>(Offsets::FUN_GX_RS_SET);
|
||||
reinterpret_cast<GxState_t>(Offsets::FUN_GX_STATE_PUSH)();
|
||||
rs(Offsets::GXRS_BLEND, Offsets::GXRS_BLEND_MODULATE);
|
||||
rs(Offsets::GXRS_LIGHTING, 0);
|
||||
rs(Offsets::GXRS_FOG, 0);
|
||||
rs(Offsets::GXRS_DEPTH_WRITE, 0);
|
||||
reinterpret_cast<GxRsSetPtr_t>(Offsets::FUN_GX_RS_SET_PTR)(
|
||||
Offsets::GXRS_TEXTURE0,
|
||||
reinterpret_cast<GetRenderable_t>(Offsets::FUN_TEXTURE_GET_RENDERABLE)(texture, 1, nullptr));
|
||||
reinterpret_cast<GxRsSetWord_t>(Offsets::FUN_GX_RS_SET_WORD)(Offsets::GXRS_FOG_COLOR, 0, 0xFFFFFFFFu);
|
||||
rs(Offsets::GXRS_COMBINER0, Offsets::GXRS_COMBINE_BLEND_DIFFUSE_ALPHA);
|
||||
Gx::PushStates();
|
||||
Gx::SetState(Offsets::GXRS_BLEND, Offsets::GXRS_BLEND_MODULATE);
|
||||
Gx::SetState(Offsets::GXRS_LIGHTING, 0);
|
||||
Gx::SetState(Offsets::GXRS_FOG, 0);
|
||||
Gx::SetState(Offsets::GXRS_DEPTH_WRITE, 0);
|
||||
Gx::SetState(Offsets::GXRS_TEXTURE0, Texture::DeviceTexture(texture));
|
||||
Gx::SetStateWord(Offsets::GXRS_FOG_COLOR, 0xFFFFFFFFu);
|
||||
Gx::SetState(Offsets::GXRS_COMBINER0, Offsets::GXRS_COMBINE_BLEND_DIFFUSE_ALPHA);
|
||||
if (world == nullptr)
|
||||
rs(Offsets::GXRS_CULL, 0);
|
||||
Gx::SetState(Offsets::GXRS_CULL, 0);
|
||||
else if (Game::Read<float>(Offsets::VAR_SHADOW_BIAS) == 0.0f)
|
||||
rs(Offsets::GXRS_DEPTH_FUNC, Offsets::GXRS_DEPTH_FUNC_DECAL);
|
||||
Gx::SetState(Offsets::GXRS_DEPTH_FUNC, Offsets::GXRS_DEPTH_FUNC_DECAL);
|
||||
for (Actor *actor : actors)
|
||||
DrawShadow(*actor, world, eye);
|
||||
reinterpret_cast<GxState_t>(Offsets::FUN_GX_STATE_POP)();
|
||||
Gx::PopStates();
|
||||
}
|
||||
|
||||
void __fastcall Paint(void *frame) {
|
||||
using SetupOrtho_t = void(__fastcall *)(const float *rect, const float *point, int unused);
|
||||
using DdcToNdc_t = void(__fastcall *)(float *x, float *y, float inX, float inY);
|
||||
using Clear_t = void(__fastcall *)(uint32_t mask);
|
||||
using Draw_t = void(__thiscall *)(void *scene, uint32_t pass);
|
||||
|
||||
// {bottom, left, top, right}
|
||||
float rect[4] = {};
|
||||
@@ -550,12 +539,11 @@ void __fastcall Paint(void *frame) {
|
||||
const float point[2] = {rect[1], rect[0]};
|
||||
reinterpret_cast<SetupOrtho_t>(Offsets::FUN_SETUP_ORTHO_TRANSFORMS)(rect, point, 0);
|
||||
}
|
||||
auto toNdc = reinterpret_cast<DdcToNdc_t>(Offsets::FUN_COORD_DDC_TO_NDC);
|
||||
toNdc(&rect[1], &rect[0], rect[1], rect[0]);
|
||||
toNdc(&rect[3], &rect[2], rect[3], rect[2]);
|
||||
Frame::Layout::DdcToNdc(&rect[1], &rect[0], rect[1], rect[0]);
|
||||
Frame::Layout::DdcToNdc(&rect[3], &rect[2], rect[3], rect[2]);
|
||||
for (float &edge : rect)
|
||||
edge = ClampUnit(edge);
|
||||
const float epsilon = Game::Read<float>(Offsets::VAR_HAS_RANGE_EPSILON); // 2^-22
|
||||
const float epsilon = Game::Read<float>(Offsets::VAR_TWO_POW_MINUS_22); // 2^-22
|
||||
if (!(std::fabs(rect[1] - rect[3]) < epsilon) && !(std::fabs(rect[0] - rect[2]) < epsilon)) {
|
||||
Gx::SetViewport({rect[1] * vp.maxX, rect[3] * vp.maxX, rect[0] * vp.maxY, rect[2] * vp.maxY,
|
||||
0.0f, 1.0f});
|
||||
@@ -563,25 +551,24 @@ void __fastcall Paint(void *frame) {
|
||||
if (world != nullptr)
|
||||
World::ClearAndDrawSky(*world, frame, eye);
|
||||
else
|
||||
reinterpret_cast<Clear_t>(Offsets::FUN_GX_CLEAR)(2);
|
||||
Gx::Clear(2);
|
||||
PlaceActors(frame);
|
||||
void *scene = Model::Pane::Scene(frame);
|
||||
M2::AnimateScene(scene, eye);
|
||||
if (world != nullptr)
|
||||
World::Draw(*world, frame, eye);
|
||||
DrawShadows(frame, eye);
|
||||
auto draw = reinterpret_cast<Draw_t>(Offsets::FUN_M2SCENE_DRAW);
|
||||
draw(scene, 0);
|
||||
M2::DrawScene(scene, 0);
|
||||
// The world's frame draws its liquids before the translucent models
|
||||
// over the water and, with the camera in liquid, after them
|
||||
// (0x004836D6).
|
||||
const bool wet = world != nullptr && World::CameraWet(*world);
|
||||
if (wet)
|
||||
draw(scene, 1);
|
||||
M2::DrawScene(scene, 1);
|
||||
if (world != nullptr)
|
||||
World::DrawLiquids(*world, frame, eye);
|
||||
if (!wet)
|
||||
draw(scene, 1);
|
||||
M2::DrawScene(scene, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -698,18 +685,16 @@ bool Unproject(const Gx::Matrix &m, float x, float y, float depth, float (&out)[
|
||||
// {bottom, left, top, right} in NDC clamped to the screen; false when the
|
||||
// cursor is outside it or the paint draws nothing.
|
||||
bool CursorClip(const float (&rect)[4], float &x, float &y) {
|
||||
using DdcToNdc_t = void(__fastcall *)(float *x, float *y, float inX, float inY);
|
||||
const uint8_t *ctx = Game::Read<const uint8_t *>(Offsets::VAR_UI_CONTEXT_PTR);
|
||||
if (ctx == nullptr)
|
||||
return false;
|
||||
const float *mouse = Game::Ptr<float>(ctx, Offsets::OFF_UI_CONTEXT_MOUSE_POSITION);
|
||||
float vp[4] = {rect[0], rect[1], rect[2], rect[3]};
|
||||
auto toNdc = reinterpret_cast<DdcToNdc_t>(Offsets::FUN_COORD_DDC_TO_NDC);
|
||||
toNdc(&vp[1], &vp[0], vp[1], vp[0]);
|
||||
toNdc(&vp[3], &vp[2], vp[3], vp[2]);
|
||||
Frame::Layout::DdcToNdc(&vp[1], &vp[0], vp[1], vp[0]);
|
||||
Frame::Layout::DdcToNdc(&vp[3], &vp[2], vp[3], vp[2]);
|
||||
for (float &edge : vp)
|
||||
edge = ClampUnit(edge);
|
||||
const float epsilon = Game::Read<float>(Offsets::VAR_HAS_RANGE_EPSILON);
|
||||
const float epsilon = Game::Read<float>(Offsets::VAR_TWO_POW_MINUS_22);
|
||||
if (std::fabs(vp[1] - vp[3]) < epsilon || std::fabs(vp[0] - vp[2]) < epsilon)
|
||||
return false;
|
||||
if (!(mouse[0] >= vp[1] && mouse[0] <= vp[3] && mouse[1] >= vp[0] && mouse[1] <= vp[2]))
|
||||
@@ -762,9 +747,6 @@ Actor *ActorAtCursor(void *frame) {
|
||||
|
||||
// ---- the overrides -----------------------------------------------------------------
|
||||
|
||||
using SetFrameAlpha_t = void(__fastcall *)(void *self, void *edx, uint8_t alpha);
|
||||
using OnFrameUpdate_t = void(__fastcall *)(void *self, void *edx, float elapsedSec);
|
||||
using EmitLayer_t = void(__fastcall *)(void *self, void *edx, void *batch, int layer);
|
||||
using Hide_t = int(__fastcall *)(void *self, void *edx);
|
||||
using Callback_t = void(__fastcall *)(void *arg);
|
||||
using AddCallback_t = void(__fastcall *)(void *batch, void *edx, Callback_t fn, void *arg);
|
||||
@@ -790,6 +772,10 @@ Frame::Subclass::Class<Offsets::VTBL_SIMPLEMODEL_SLOTS, Offsets::VTBL_SIMPLEMODE
|
||||
&Destroy};
|
||||
|
||||
using Frame::Subclass::FrameBase;
|
||||
using Frame::Subclass::EmitLayer_t;
|
||||
using Frame::Subclass::LoadXML_t;
|
||||
using Frame::Subclass::OnFrameUpdate_t;
|
||||
using Frame::Subclass::SetFrameAlpha_t;
|
||||
|
||||
// OnActorEnter / OnActorLeave (self, actor): the actor under the cursor
|
||||
// changed while the scene is the mouse focus, from the update walk.
|
||||
@@ -881,12 +867,10 @@ int __fastcall Hide(void *self, void *) {
|
||||
return g_class.Base<Hide_t>(Offsets::VTBL_FRAME_HIDE)(self, nullptr);
|
||||
}
|
||||
|
||||
using LoadXML_t = uintptr_t(__fastcall *)(void *layout, void *edx, const void *node, void *status);
|
||||
|
||||
// The frame's own loader, then ModelSceneType's attributes and <FogColor>.
|
||||
uintptr_t __fastcall LoadXML(void *layout, void *, const void *node, void *status) {
|
||||
using LayerFromName_t = int(__fastcall *)(const char *name, int *layer);
|
||||
using ReadColor_t = int(__fastcall *)(const void *node, uint32_t *bgra, void *status);
|
||||
const uintptr_t result = Frame::Subclass::Slot<LoadXML_t>(
|
||||
Offsets::VTBL_SIMPLEFRAME_LAYOUT, Offsets::VTBL_XML_NODE_LOADER)(layout, nullptr, node, status);
|
||||
if (node == nullptr)
|
||||
@@ -901,8 +885,7 @@ uintptr_t __fastcall LoadXML(void *layout, void *, const void *node, void *statu
|
||||
Game::Ref<float>(frame, Offsets::OFF_SIMPLEMODEL_FOG_FAR) = value < 0.0f ? 0.0f : value;
|
||||
for (const void *c = Xml::FirstChild(node); c != nullptr; c = Xml::NextSibling(c)) {
|
||||
if (Xml::TagIs(c, "FogColor")) {
|
||||
reinterpret_cast<ReadColor_t>(Offsets::FUN_XML_READ_COLOR)(
|
||||
c, Game::Ptr<uint32_t>(frame, Offsets::OFF_SIMPLEMODEL_FOG_COLOR), status);
|
||||
Xml::ReadColor(c, Game::Ref<uint32_t>(frame, Offsets::OFF_SIMPLEMODEL_FOG_COLOR), status);
|
||||
FogFlags(frame) |= Offsets::SIMPLEMODEL_FOG_ARMED;
|
||||
} else if (Xml::TagIs(c, "ViewInsets")) {
|
||||
float *in = F(frame).viewInsets;
|
||||
|
||||
+13
-26
@@ -166,6 +166,7 @@
|
||||
#include "api/Documentation.h"
|
||||
#include "dbc/Lookup.h"
|
||||
#include "guid/Guid.h"
|
||||
#include "gx/Matrix.h"
|
||||
#include "item/Data.h"
|
||||
#include "item/Record.h"
|
||||
#include "model/DisplayInfo.h"
|
||||
@@ -622,14 +623,6 @@ void Actor::ClearModel() {
|
||||
RunScript(S_ONMODELCLEARED, 0);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
bool IsDeathAnimation(int anim) {
|
||||
return reinterpret_cast<int(__stdcall *)(int)>(Offsets::FUN_IS_DEATH_ANIMATION)(anim) != 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// An actor whose own animation is a death animation is dead to its spells, as
|
||||
// a unit without health is to its PlayAnimation (0x005FE2F0): a kit's
|
||||
// animation (a cast, an impact, a wound) does not play over the death, and a
|
||||
@@ -637,7 +630,7 @@ bool IsDeathAnimation(int anim) {
|
||||
void Actor::PlayAnimation() {
|
||||
if (model == nullptr)
|
||||
return;
|
||||
if (kitAnimation >= 0 && IsDeathAnimation(static_cast<int>(animation)) && !IsDeathAnimation(kitAnimation)) {
|
||||
if (kitAnimation >= 0 && M2::IsDeathAnimation(static_cast<int>(animation)) && !M2::IsDeathAnimation(kitAnimation)) {
|
||||
kitAnimation = -1;
|
||||
kitAnimationLoops = false;
|
||||
kitLoopAnimation = -1;
|
||||
@@ -737,12 +730,12 @@ void Advance(Actor &actor) {
|
||||
// units' update, so the body pass reads the one the last frame set. The
|
||||
// pass's shuffle (11, 12) is Locomotion::OnBodyTurn's, given the turn it made.
|
||||
|
||||
constexpr float kPi = 3.14159274f; // 0x008030B0
|
||||
constexpr double kTwoPi = 6.2831854820251465; // 0x00803090, a double
|
||||
constexpr float kHalfPi = 1.57079637f; // 0x00808ACC
|
||||
constexpr float kQuarterPi = 0.785398185f; // 0x0080C4E4
|
||||
constexpr float kFacingEpsilon = 1e-5f; // 0x0080C5C8
|
||||
constexpr float kMsToSec = 0.001f; // 0x00801360
|
||||
const Game::Live<float> kPi{Offsets::VAR_WRAP_PI};
|
||||
const Game::Live<double> kTwoPi{Offsets::VAR_WRAP_TWO_PI};
|
||||
const Game::Live<float> kHalfPi{Offsets::VAR_HALF_PI};
|
||||
const Game::Live<float> kQuarterPi{Offsets::VAR_QUARTER_PI};
|
||||
const Game::Live<float> kFacingEpsilon{Offsets::VAR_MOVER_FACING_EPSILON};
|
||||
const Game::Live<float> kMsToSec{Offsets::VAR_ONE_THOUSANDTH};
|
||||
constexpr uint32_t kTurning = 0x1, kTwistLow = 0x80, kTwistHigh = 0x100;
|
||||
|
||||
// WrapAngleToPi (0x006084F0).
|
||||
@@ -1023,22 +1016,16 @@ void Actor::Place() {
|
||||
Casts::Place(*this);
|
||||
if (model == nullptr)
|
||||
return;
|
||||
using SetTRS_t = void(__thiscall *)(void *model, const float *pos, float angle,
|
||||
const float *axis, const float *scale);
|
||||
using Rotate_t = void(__thiscall *)(float *m, float angle, const float *axis, int);
|
||||
using Translate_t = void(__thiscall *)(float *m, const float *t);
|
||||
const float axisX[3] = {1.0f, 0.0f, 0.0f};
|
||||
const float axisY[3] = {0.0f, 1.0f, 0.0f};
|
||||
const float axisZ[3] = {0.0f, 0.0f, 1.0f};
|
||||
const float scales[3] = {scale, scale, scale};
|
||||
reinterpret_cast<SetTRS_t>(Offsets::FUN_M2MODEL_SET_BASE_TRS)(model, position, ShownYaw(), axisZ,
|
||||
scales);
|
||||
float *matrix = Game::Ptr<float>(model, Offsets::OFF_M2MODEL_BASE_MATRIX);
|
||||
auto rotate = reinterpret_cast<Rotate_t>(Offsets::FUN_MATRIX_ROTATE);
|
||||
M2::SetBaseTRS(model, position, ShownYaw(), axisZ, scales);
|
||||
float *matrix = M2::BaseMatrix(model);
|
||||
if (pitch != 0.0f)
|
||||
rotate(matrix, pitch, axisY, 1);
|
||||
Gx::Rotate(matrix, pitch, axisY);
|
||||
if (roll != 0.0f)
|
||||
rotate(matrix, roll, axisX, 1);
|
||||
Gx::Rotate(matrix, roll, axisX);
|
||||
if (!loaded || !(useCenterForOrigin[0] || useCenterForOrigin[1] || useCenterForOrigin[2]))
|
||||
return;
|
||||
float box[6];
|
||||
@@ -1047,7 +1034,7 @@ void Actor::Place() {
|
||||
float offset[3];
|
||||
for (int i = 0; i < 3; ++i)
|
||||
offset[i] = useCenterForOrigin[i] ? -(box[i] + box[i + 3]) * 0.5f : 0.0f;
|
||||
reinterpret_cast<Translate_t>(Offsets::FUN_MATRIX_TRANSLATE)(matrix, offset);
|
||||
Gx::Translate(matrix, offset);
|
||||
}
|
||||
|
||||
// ---- the methods ---------------------------------------------------------------
|
||||
|
||||
+44
-114
@@ -27,7 +27,13 @@
|
||||
|
||||
#include "model/SceneContact.h"
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "model/ScenePrecision.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cfloat>
|
||||
#include <cstddef>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <xmmintrin.h>
|
||||
@@ -36,29 +42,23 @@ namespace Model::Scene::Contact {
|
||||
|
||||
namespace {
|
||||
|
||||
float Bits(uint32_t bits) {
|
||||
float f;
|
||||
std::memcpy(&f, &bits, sizeof f);
|
||||
return f;
|
||||
}
|
||||
using Game::Live;
|
||||
using Precision::Bits;
|
||||
using Precision::D;
|
||||
|
||||
double D(float x) { return x; }
|
||||
|
||||
const float kSkin = Bits(0x3AB60B61); // 1/720 (0x0080DFEC)
|
||||
const float kNegSkin = Bits(0xBAB60B61); // -1/720 (0x0080DFF0)
|
||||
const float kAllBehind = Bits(0xB5800000); // -2^-20 (0x0080DFF4)
|
||||
const float kDegenerate = Bits(0x35800000); // 2^-20 (0x008026BC)
|
||||
const float kParallel = Bits(0x34800000); // 2^-22 (0x008029D4)
|
||||
const float kThirtySixth = Bits(0x3CE38E39); // 1/36 (0x007FF9D0)
|
||||
const float kNegThirtySixth = Bits(0xBCE38E39); // -1/36 (0x007FF9C8)
|
||||
const float kFacing = Bits(0xB727C5AC); // -1e-5 (0x0080C5C4)
|
||||
const float kGrowth = Bits(0x3E2AAAAB); // 1/6, the gather's growth
|
||||
const float kBevelOut = Bits(0x3F613036); // sin 61.6° (0x0080DFE4)
|
||||
const float kBevelDown = Bits(0x3EF386A4); // cos 61.6° (0x0080DFE0)
|
||||
const float kWaist = Bits(0x3FECB91B); // tan 61.6° (0x0080C740)
|
||||
const float kFltMax = Bits(0x7F7FFFFF);
|
||||
const float kTwelfth = Bits(0x3DAAAAAB); // 1/12, the point-over-facet margin
|
||||
const float kThreeQuarters = Bits(0x3F400000); // 0.75 (0x008012CC), the swimmer's height
|
||||
const Live<float> kSkin{Offsets::VAR_MOVER_SKIN}; // 1/720
|
||||
const Live<float> kAllBehind{Offsets::VAR_MOVER_ALL_BEHIND}; // -2^-20
|
||||
const Live<float> kDegenerate{Offsets::VAR_TWO_POW_MINUS_20};
|
||||
const Live<float> kThirtySixth{Offsets::VAR_ONE_THIRTY_SIXTH};
|
||||
const Live<float> kNegThirtySixth{Offsets::VAR_MINUS_ONE_THIRTY_SIXTH};
|
||||
const Live<float> kFacing{Offsets::VAR_MOVER_MINUS_FACING_EPSILON}; // -1e-5
|
||||
const float kGrowth = Bits(0x3E2AAAAB); // 1/6, the gather's growth
|
||||
const Live<float> kBevelOut{Offsets::VAR_MOVER_BEVEL_OUT}; // sin 61.6°
|
||||
const Live<float> kBevelDown{Offsets::VAR_MOVER_BEVEL_DOWN}; // cos 61.6°
|
||||
const Live<float> kWaist{Offsets::VAR_MOVER_WAIST}; // tan 61.6°
|
||||
constexpr float kFltMax = FLT_MAX;
|
||||
const float kTwelfth = Bits(0x3DAAAAAB); // 1/12, the point-over-facet margin
|
||||
const Live<float> kThreeQuarters{Offsets::VAR_THREE_QUARTERS}; // the swimmer's height
|
||||
|
||||
// The volume's faces as vertex indices (0x00631BE0's store block): the five
|
||||
// box faces as quads, in plane order, then the four bevels as triangles.
|
||||
@@ -72,110 +72,41 @@ struct Polygon {
|
||||
int32_t tag[15];
|
||||
uint32_t count;
|
||||
};
|
||||
static_assert(sizeof(Polygon) == 0xF4 && offsetof(Polygon, tag) == 0xB4 && offsetof(Polygon, count) == 0xF0,
|
||||
"the client's clip polygon");
|
||||
static_assert(sizeof(Plane) == 0x10, "the client's plane");
|
||||
|
||||
struct Volume {
|
||||
Plane planes[9];
|
||||
float v[9][3];
|
||||
};
|
||||
|
||||
// ClipPolygonByPlane (0x006318C0): keeps the inside of a plane, with a
|
||||
// 1/720 band, tagging the vertices it adds.
|
||||
// ClipPolygonByPlane: keeps the inside of a plane, with a 1/720 band,
|
||||
// tagging the vertices it adds.
|
||||
void ClipByPlane(Polygon &poly, const Plane &pl, int32_t tag) {
|
||||
const uint32_t n = poly.count;
|
||||
if (n == 0)
|
||||
return;
|
||||
float s[15];
|
||||
float most = -kFltMax, least = kFltMax;
|
||||
for (uint32_t i = 0; i < n; ++i) {
|
||||
const float *v = poly.v[i];
|
||||
s[i] = static_cast<float>(-(((D(v[0]) * pl.n[0] + D(v[2]) * pl.n[2]) + D(v[1]) * pl.n[1]) + pl.d));
|
||||
if (s[i] > most)
|
||||
most = s[i];
|
||||
if (s[i] < least)
|
||||
least = s[i];
|
||||
}
|
||||
if (least > kNegSkin)
|
||||
return;
|
||||
if (most < kSkin) {
|
||||
poly.count = 0;
|
||||
return;
|
||||
}
|
||||
const Polygon old = poly;
|
||||
uint32_t out = 0;
|
||||
const auto keep = [&](uint32_t i) {
|
||||
std::memcpy(poly.v[out], old.v[i], sizeof poly.v[out]);
|
||||
poly.tag[out++] = old.tag[i];
|
||||
};
|
||||
uint32_t prev = n - 1;
|
||||
for (uint32_t cur = 0; cur < n && out + 2 <= 15; prev = cur++) {
|
||||
const float sp = s[prev], sc = s[cur];
|
||||
const bool prevIn = !(sp < 0.0f), curIn = !(sc < 0.0f);
|
||||
const float *p = old.v[prev], *c = old.v[cur];
|
||||
if (!prevIn && curIn) {
|
||||
if (sc > kSkin) {
|
||||
// Out to in (0x00631A36): z's difference rounds first, y's
|
||||
// product stays unrounded.
|
||||
const float t = static_cast<float>(D(sp) / (D(sc) - sp));
|
||||
const float ex = static_cast<float>((D(c[0]) - p[0]) * t);
|
||||
const double ey = (D(c[1]) - p[1]) * t;
|
||||
const float dz = static_cast<float>(D(c[2]) - p[2]);
|
||||
const double ez = D(dz) * t;
|
||||
poly.v[out][0] = static_cast<float>(D(p[0]) - ex);
|
||||
poly.v[out][1] = static_cast<float>(D(p[1]) - ey);
|
||||
poly.v[out][2] = static_cast<float>(D(p[2]) - ez);
|
||||
poly.tag[out++] = tag;
|
||||
}
|
||||
keep(cur);
|
||||
} else if (prevIn && curIn) {
|
||||
keep(cur);
|
||||
} else if (prevIn && !curIn && sp > kSkin) {
|
||||
// In to out (0x00631B6B): each product rounds.
|
||||
const float t = static_cast<float>(D(sp) / (D(sc) - sp));
|
||||
for (int k = 0; k < 3; ++k)
|
||||
poly.v[out][k] = static_cast<float>(D(p[k]) - static_cast<float>((D(c[k]) - p[k]) * t));
|
||||
poly.tag[out++] = tag;
|
||||
}
|
||||
}
|
||||
poly.count = out < 3 ? 0 : out;
|
||||
using Fn = void(__fastcall *)(const Plane *, Polygon *, int32_t);
|
||||
reinterpret_cast<Fn>(Offsets::FUN_CLIP_POLYGON_BY_PLANE)(&pl, &poly, tag);
|
||||
}
|
||||
|
||||
// ClipPolygonByPlanes (0x00631870): by each plane in turn, false once empty.
|
||||
// ClipPolygonByPlanes: by each plane in turn, false once empty.
|
||||
bool ClipByPlanes(Polygon &poly, const Plane *planes, int count) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
ClipByPlane(poly, planes[i], i);
|
||||
if (poly.count == 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
using Fn = int(__fastcall *)(const Plane *, uint32_t, Polygon *);
|
||||
return reinterpret_cast<Fn>(Offsets::FUN_CLIP_POLYGON_BY_PLANES)(planes, static_cast<uint32_t>(count), &poly) != 0;
|
||||
}
|
||||
|
||||
// ClipPolygonByPlanesExcept (0x00632980): by every volume plane but one.
|
||||
// ClipPolygonByPlanesExcept: by every volume plane but one.
|
||||
bool ClipByPlanesExcept(Polygon &poly, const Plane (&planes)[9], int skip) {
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
if (i == skip)
|
||||
continue;
|
||||
ClipByPlane(poly, planes[i], i);
|
||||
if (poly.count == 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
using Fn = int(__fastcall *)(const Plane *, uint32_t, uint32_t, Polygon *);
|
||||
return reinterpret_cast<Fn>(Offsets::FUN_CLIP_POLYGON_BY_PLANES_EXCEPT)(planes, 9, static_cast<uint32_t>(skip),
|
||||
&poly) != 0;
|
||||
}
|
||||
|
||||
// PlaneFromTriangle (0x00637480): the normalized plane through three points,
|
||||
// normal (p1 - p0) × (p2 - p0).
|
||||
// PlaneFromTriangle: the normalized plane through three points, normal
|
||||
// (p1 - p0) × (p2 - p0).
|
||||
Plane PlaneFromPoints(const float (&p0)[3], const float (&p1)[3], const float (&p2)[3]) {
|
||||
const double a[3] = {D(p2[0]) - p0[0], D(p2[1]) - p0[1], D(p2[2]) - p0[2]};
|
||||
const float bx = static_cast<float>(D(p1[0]) - p0[0]);
|
||||
const float by = static_cast<float>(D(p1[1]) - p0[1]);
|
||||
const double bz = D(p1[2]) - p0[2];
|
||||
const float n[3] = {static_cast<float>(D(by) * a[2] - bz * a[1]), static_cast<float>(bz * a[0] - a[2] * bx),
|
||||
static_cast<float>(a[1] * bx - D(by) * a[0])};
|
||||
const double inverse = 1.0 / std::sqrt((D(n[0]) * n[0] + D(n[1]) * n[1]) + D(n[2]) * n[2]);
|
||||
const double f[3] = {D(n[0]) * inverse, D(n[1]) * inverse, D(n[2]) * inverse};
|
||||
using Fn = void(__fastcall *)(Plane *, int, const float *, const float *, const float *);
|
||||
Plane pl;
|
||||
for (int k = 0; k < 3; ++k)
|
||||
pl.n[k] = static_cast<float>(f[k]);
|
||||
pl.d = static_cast<float>(-((f[2] * p0[2] + f[1] * p0[1]) + f[0] * p0[0]));
|
||||
reinterpret_cast<Fn>(Offsets::FUN_PLANE_FROM_TRIANGLE)(&pl, 0, p0, p1, p2);
|
||||
return pl;
|
||||
}
|
||||
|
||||
@@ -264,12 +195,11 @@ Volume BuildVolume(const float (&p)[3], float radius, float height) {
|
||||
return v;
|
||||
}
|
||||
|
||||
// PlaneDistanceAlongRay (0x006329E0): how far a plane moves along `dir`
|
||||
// before it reaches q; n·q + d undivided when it runs parallel.
|
||||
// PlaneDistanceAlongRay: how far a plane moves along `dir` before it
|
||||
// reaches q; n·q + d undivided when it runs parallel.
|
||||
double DistanceAlongRay(const float (&q)[3], const Plane &pl, const float (&dir)[3]) {
|
||||
const double num = ((D(q[2]) * pl.n[2] + D(q[1]) * pl.n[1]) + D(q[0]) * pl.n[0]) + pl.d;
|
||||
const double den = (D(pl.n[2]) * dir[2] + D(pl.n[1]) * dir[1]) + D(pl.n[0]) * dir[0];
|
||||
return std::fabs(den) < kParallel ? num : num / den;
|
||||
using Fn = double(__fastcall *)(const float *, const Plane *, const float *);
|
||||
return reinterpret_cast<Fn>(Offsets::FUN_PLANE_DISTANCE_ALONG_RAY)(q, &pl, dir);
|
||||
}
|
||||
|
||||
// PolygonContactDistance (0x00632830): the travel until volume face k
|
||||
|
||||
@@ -18,9 +18,11 @@
|
||||
// and the first contact of the moving volume with them (0x00631440 through
|
||||
// 0x00632F80). Each function is one client function, with its arithmetic in
|
||||
// the client's order and precision (53-bit sums, float stores), so a body
|
||||
// meets a face where the client's mover would. Nothing here calls the engine:
|
||||
// the facets come in through Facets::query, and the client's own mover state
|
||||
// (CMovement, the lists at 0x00C4E52C) is never touched.
|
||||
// meets a face where the client's mover would. The client's pure geometry
|
||||
// helpers (the polygon clips, the plane builder, the ray distance) are called,
|
||||
// not copied; the functions that read the client's mover state (CMovement,
|
||||
// the lists at 0x00C4E52C) are transcribed over the body's own, which come in
|
||||
// through Facets::query.
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "model/Camera.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// The UiModelScene rows behind C_ModelInfo. Retail keeps them in four DB2s
|
||||
@@ -28,9 +30,7 @@
|
||||
// modelSceneType.
|
||||
namespace Model::SceneData {
|
||||
|
||||
struct Vec3 {
|
||||
float x, y, z;
|
||||
};
|
||||
using Model::Camera::Vec3;
|
||||
|
||||
struct SceneRow {
|
||||
uint32_t id;
|
||||
|
||||
@@ -234,12 +234,11 @@ void PlaySound(Actor &actor, uint32_t tag, uint32_t data) {
|
||||
// $BWR's point (0x00600159): a bow animation releases from the body's
|
||||
// attachment 35, a rifle animation from 36, any other from the event's point.
|
||||
void BowReleasePoint(const Actor &actor, float (&point)[3]) {
|
||||
using IsAnim_t = int(__fastcall *)(int anim);
|
||||
const int anim = actor.CurrentAnimation();
|
||||
uint32_t attachment = 0;
|
||||
if (reinterpret_cast<IsAnim_t>(Offsets::FUN_IS_BOW_ANIMATION)(anim) != 0)
|
||||
if (M2::IsBowAnimation(anim))
|
||||
attachment = Offsets::ATTACH_BOW_RELEASE;
|
||||
else if (reinterpret_cast<IsAnim_t>(Offsets::FUN_IS_RIFLE_ANIMATION)(anim) != 0)
|
||||
else if (M2::IsRifleAnimation(anim))
|
||||
attachment = Offsets::ATTACH_RIFLE_RELEASE;
|
||||
if (attachment != 0 && actor.model != nullptr && M2::HasAttachment(actor.model, attachment))
|
||||
M2::GetAttachmentPosition(actor.model, attachment, point);
|
||||
|
||||
@@ -51,23 +51,16 @@ namespace Model::Scene::Locomotion {
|
||||
|
||||
namespace {
|
||||
|
||||
using AnimTest_t = int(__fastcall *)(int anim);
|
||||
|
||||
constexpr uint32_t kNone = 208; // AnimationData's row count: no animation
|
||||
constexpr float kSprintSpeed = 11.0f; // 0x0080C484
|
||||
constexpr float kTurnEpsilon = 1e-5f; // 0x0080C5C8
|
||||
constexpr float kTurnEpsilonNegative = -1e-5f; // 0x0080C5C4
|
||||
|
||||
bool Test(uintptr_t fn, uint32_t anim) { return reinterpret_cast<AnimTest_t>(fn)(static_cast<int>(anim)) != 0; }
|
||||
|
||||
bool IsDeath(uint32_t anim) {
|
||||
return reinterpret_cast<int(__stdcall *)(int)>(Offsets::FUN_IS_DEATH_ANIMATION)(static_cast<int>(anim)) != 0;
|
||||
}
|
||||
const Game::Live<float> kSprintSpeed{Offsets::VAR_MOVER_SPRINT_SPEED};
|
||||
const Game::Live<float> kTurnEpsilon{Offsets::VAR_MOVER_FACING_EPSILON};
|
||||
const Game::Live<float> kTurnEpsilonNegative{Offsets::VAR_MOVER_MINUS_FACING_EPSILON};
|
||||
|
||||
// The chain runs for an actor with the mover and a loaded model that is not
|
||||
// dead.
|
||||
bool Active(const Actor &actor) {
|
||||
return actor.mover != nullptr && actor.model != nullptr && actor.loaded && !IsDeath(actor.animation);
|
||||
return actor.mover != nullptr && actor.model != nullptr && actor.loaded &&
|
||||
!M2::IsDeathAnimation(static_cast<int>(actor.animation));
|
||||
}
|
||||
|
||||
// A fall the pick holds through (0x005FD8EE to 0x005FD919): falling far, or
|
||||
@@ -106,10 +99,9 @@ bool CanShuffle(const Actor &actor, bool jumpEndLock) {
|
||||
return false;
|
||||
if (b.flags & 0x40200800)
|
||||
return false;
|
||||
const auto anim = static_cast<uint32_t>(actor.CurrentAnimation());
|
||||
if (Test(Offsets::FUN_IS_EMOTE_ANIMATION, anim) || Test(Offsets::FUN_IS_SPELL_CAST_ANIMATION, anim) ||
|
||||
Test(Offsets::FUN_IS_THROWN_ANIMATION, anim) || Test(Offsets::FUN_IS_BOW_ANIMATION, anim) ||
|
||||
Test(Offsets::FUN_IS_RIFLE_ANIMATION, anim))
|
||||
const int anim = actor.CurrentAnimation();
|
||||
if (M2::IsEmoteAnimation(anim) || M2::IsSpellCastAnimation(anim) || M2::IsThrownAnimation(anim) ||
|
||||
M2::IsBowAnimation(anim) || M2::IsRifleAnimation(anim))
|
||||
return false;
|
||||
return !jumpEndLock;
|
||||
}
|
||||
@@ -132,21 +124,6 @@ uint32_t Select(const Actor &actor, bool jumpEndLock) {
|
||||
|
||||
bool JumpEndLock(const Actor &actor) { return actor.animation == Offsets::ANIM_JUMP_END; }
|
||||
|
||||
struct SequenceInfo {
|
||||
uint32_t flags;
|
||||
uint32_t length;
|
||||
float speed;
|
||||
uint8_t rest[Offsets::M2_SEQUENCE_INFO_SIZE - 12];
|
||||
};
|
||||
static_assert(sizeof(SequenceInfo) == Offsets::M2_SEQUENCE_INFO_SIZE);
|
||||
|
||||
SequenceInfo Info(void *model, uint32_t anim, uint32_t variation) {
|
||||
using Fn = void(__thiscall *)(void *model, uint32_t anim, uint32_t variation, void *out);
|
||||
SequenceInfo info;
|
||||
reinterpret_cast<Fn>(Offsets::FUN_M2MODEL_GET_SEQUENCE_INFO)(model, anim, variation, &info);
|
||||
return info;
|
||||
}
|
||||
|
||||
// CGUnit_C::PlayAnimation (0x005FE2F0) of `anim` on the body's track, as a
|
||||
// body with no mount, swing, weapon or effect plays it: a move animation at
|
||||
// the mover's speed over the sequence's (0x005FE50A to 0x005FE54D), starting
|
||||
@@ -157,20 +134,16 @@ void Play(Actor &actor, uint32_t anim, bool ended) {
|
||||
return;
|
||||
float rate = 1.0f;
|
||||
uint32_t offsetMs = 0;
|
||||
const SequenceInfo info = Info(actor.model, anim, 0);
|
||||
if (0.0f < info.speed && Test(Offsets::FUN_IS_MOVE_ANIMATION, anim)) {
|
||||
const M2::SequenceInfo info = M2::GetSequenceInfo(actor.model, anim, 0);
|
||||
if (0.0f < info.speed && M2::IsMoveAnimation(static_cast<int>(anim))) {
|
||||
rate = Mover::CurrentSpeed(*actor.mover) / info.speed;
|
||||
if (info.length != 0) {
|
||||
using State_t = void(__thiscall *)(void *model, int keyBone, uint32_t *out);
|
||||
uint32_t state[Offsets::M2_KEY_BONE_ANIM_STATE_SIZE / 4];
|
||||
reinterpret_cast<State_t>(Offsets::FUN_M2MODEL_GET_KEY_BONE_ANIM_STATE)(actor.model, -1, state);
|
||||
const SequenceInfo was = Info(actor.model, state[Offsets::OFF_M2_KEY_BONE_ANIM_STATE_ID / 4],
|
||||
state[Offsets::OFF_M2_KEY_BONE_ANIM_STATE_VARIATION / 4]);
|
||||
const M2::AnimState state = M2::GetAnimState(actor.model, -1);
|
||||
const M2::SequenceInfo was = M2::GetSequenceInfo(actor.model, state.id, state.variation);
|
||||
// 32-bit, as the client's imul and two divs (0x005FE606): the
|
||||
// product wraps.
|
||||
if (0.0f < was.speed && was.length != 0)
|
||||
offsetMs = state[Offsets::OFF_M2_KEY_BONE_ANIM_STATE_POSITION / 4] * info.length / was.length %
|
||||
info.length;
|
||||
offsetMs = state.position * info.length / was.length % info.length;
|
||||
}
|
||||
}
|
||||
actor.animation = anim;
|
||||
|
||||
+67
-94
@@ -31,6 +31,11 @@
|
||||
|
||||
#include "model/SceneMover.h"
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "model/ScenePrecision.h"
|
||||
|
||||
#include <cfloat>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
|
||||
@@ -38,59 +43,55 @@ namespace Model::Scene::Mover {
|
||||
|
||||
namespace {
|
||||
|
||||
float Bits(uint32_t bits) {
|
||||
float f;
|
||||
std::memcpy(&f, &bits, sizeof f);
|
||||
return f;
|
||||
}
|
||||
using Game::Live;
|
||||
using Precision::Bits;
|
||||
using Precision::D;
|
||||
|
||||
double D(float x) { return x; }
|
||||
|
||||
const float kMsToSec = Bits(0x3A83126F); // 0.001 (0x00801360), also the 0.001 nudge
|
||||
const float kThousand = Bits(0x447A0000); // 1000.0 (0x008022CC)
|
||||
const float kHalf = Bits(0x3F000000); // 0.5 (0x007FFA24)
|
||||
const float kOne = Bits(0x3F800000); // 1.0 (0x007FF9D8)
|
||||
const float kTiny = Bits(0x35800000); // 2^-20 (0x008026BC)
|
||||
const float kParallel = Bits(0x34800000); // 2^-22 (0x008029D4)
|
||||
const float kSkin = Bits(0x3AB60B61); // 1/720 (0x0080DFEC)
|
||||
const float kThirtySixth = Bits(0x3CE38E39); // 1/36 (0x007FF9D0)
|
||||
const float kNinth = Bits(0x3DE38E39); // 1/9 (0x0080DFF8)
|
||||
const float kDownBias = Bits(0x3C23D70A); // 0.01 (0x008029D0)
|
||||
const float kStall = Bits(0x3A03126F); // 0.0005 (0x0080C698)
|
||||
const float kStallReach = Bits(0x3F97E4AD); // 1.1866661 (0x0080E018)
|
||||
const float kTenth = Bits(0x3DCCCCCD); // 0.1 (0x00801620)
|
||||
const float kCos10 = Bits(0x3F7C1C5C); // cos 10° (0x0080E01C)
|
||||
const float kCos50 = Bits(0x3F248DBB); // cos 50° (0x0080DFFC), the floor limit
|
||||
const float kTan50 = Bits(0x3F988B62); // tan 50° (0x0080E008)
|
||||
const float kNegTan50 = Bits(0xBF988B62); // -tan 50° (0x0080E010)
|
||||
const float kSqrt2 = Bits(0x3FB504F3); // √2 (0x0080E00C)
|
||||
const float kRootHalf = Bits(0x3F3504F3); // √½, the diagonal
|
||||
const float kWaist = Bits(0x3FECB91B); // tan 61.6° (0x0080C740)
|
||||
const float kBevelZ = Bits(0xBEF386A4); // the bevels' normal z (0x0080E014)
|
||||
const float kBisect = Bits(0x3F237868); // the two-bevel normalizer (0x0080E024)
|
||||
const float kG = Bits(0x419A542F); // g (0x0081DA58)
|
||||
const float kHalfG = Bits(0x411A542F); // g/2 (0x0081DA60)
|
||||
const float kTwoG = Bits(0x421A542F); // 2g (0x0081DA64)
|
||||
const float kInvG = Bits(0x3D54536A); // 1/g (0x0080E020)
|
||||
const float kNegInvG = Bits(0xBD54536A); // -1/g (0x0081DA5C)
|
||||
const float kTwoOverG = Bits(0x3DD4536A); // 2/g (0x0081DA68)
|
||||
const float kTerminal = Bits(0x4270978E); // the fall's cap (0x0087D894)
|
||||
const float kTerminalSlow = Bits(0x40E00000); // the cap under 0x20000000 (0x0087D898)
|
||||
const float kJumpSpeed = Bits(0xC0FE93D8); // the jump's launch (0x007C626F)
|
||||
const Live<float> kMsToSec{Offsets::VAR_ONE_THOUSANDTH}; // also the 0.001 nudge
|
||||
const Live<float> kThousand{Offsets::VAR_ONE_THOUSAND};
|
||||
const Live<float> kHalf{Offsets::VAR_HALF};
|
||||
const Live<float> kOne{Offsets::VAR_ONE};
|
||||
const Live<float> kTiny{Offsets::VAR_TWO_POW_MINUS_20};
|
||||
const Live<float> kParallel{Offsets::VAR_TWO_POW_MINUS_22};
|
||||
const Live<float> kSkin{Offsets::VAR_MOVER_SKIN}; // 1/720
|
||||
const Live<float> kThirtySixth{Offsets::VAR_ONE_THIRTY_SIXTH};
|
||||
const Live<float> kNinth{Offsets::VAR_MOVER_NINTH};
|
||||
const Live<float> kDownBias{Offsets::VAR_ONE_HUNDREDTH};
|
||||
const Live<float> kStall{Offsets::VAR_MOVER_STALL};
|
||||
const Live<float> kStallReach{Offsets::VAR_MOVER_STALL_REACH};
|
||||
const Live<float> kTenth{Offsets::VAR_ONE_TENTH};
|
||||
const Live<float> kCos10{Offsets::VAR_MOVER_COS_10};
|
||||
const Live<float> kCos50{Offsets::VAR_MOVER_FLOOR_COS}; // the floor limit
|
||||
const Live<float> kTan50{Offsets::VAR_MOVER_FLOOR_TAN};
|
||||
const Live<float> kNegTan50{Offsets::VAR_MOVER_MINUS_FLOOR_TAN};
|
||||
const Live<float> kSqrt2{Offsets::VAR_MOVER_SQRT_2};
|
||||
const float kRootHalf = Bits(0x3F3504F3); // √½, the diagonal
|
||||
const Live<float> kWaist{Offsets::VAR_MOVER_WAIST}; // tan 61.6°
|
||||
const Live<float> kBevelZ{Offsets::VAR_MOVER_BEVEL_Z}; // the bevels' normal z
|
||||
const Live<float> kBisect{Offsets::VAR_MOVER_BISECT}; // the two-bevel normalizer
|
||||
const Live<float> kG{Offsets::VAR_MOVER_GRAVITY};
|
||||
const Live<float> kHalfG{Offsets::VAR_MOVER_HALF_GRAVITY};
|
||||
const Live<float> kTwoG{Offsets::VAR_MOVER_TWO_GRAVITY};
|
||||
const Live<float> kInvG{Offsets::VAR_MOVER_INV_GRAVITY};
|
||||
const Live<float> kNegInvG{Offsets::VAR_MOVER_MINUS_INV_GRAVITY};
|
||||
const Live<float> kTwoOverG{Offsets::VAR_MOVER_TWO_OVER_GRAVITY};
|
||||
const Live<float> kTerminal{Offsets::VAR_MOVER_TERMINAL_SPEED}; // the fall's cap
|
||||
const Live<float> kTerminalSlow{Offsets::VAR_MOVER_TERMINAL_SPEED_SLOW}; // the cap under 0x20000000
|
||||
const float kJumpSpeed = Bits(0xC0FE93D8); // the jump's launch, an immediate (0x007C626F)
|
||||
const float kSwimJumpSpeed = Bits(0xC1118C48);
|
||||
const float kTwoPi = Bits(0x40C90FDB); // 0x00CF5D00
|
||||
const float kHalfPi = Bits(0x3FC90FDB); // pi/2 (0x00808ACC), the pitch clamp
|
||||
const float kNegHalfPi = Bits(0xBFC90FDB); // -pi/2 (0x0080C5E4)
|
||||
const float kThreeQuarters = Bits(0x3F400000); // 0.75 (0x008012CC)
|
||||
const float kFltMax = Bits(0x7F7FFFFF);
|
||||
const float kNegFltMax = Bits(0xFF7FFFFF);
|
||||
const float kSnapSq = Bits(0x41100000); // 9.0, 3 yards squared (0x0080C5BC)
|
||||
const float kWarpSpeedSq = Bits(0x45610000); // 3600.0, 60 yards a second squared (0x0080C734)
|
||||
const float kReachedSq = Bits(0x3A4A4588); // (1/36)^2, one path point (0x0080C450)
|
||||
const float kSixth = Bits(0x3E2AAAAB); // 1/6, the shortest path (0x00803568)
|
||||
const float kFour = Bits(0x40800000); // the path speed's cap over the run speed (0x0080306C)
|
||||
const float kCellCentre = Bits(0x46855555); // 17066.666 (0x00616BF0)
|
||||
const float kCellSpan = Bits(0x47055355); // 34131.332 (0x0080C738)
|
||||
const Live<float> kTwoPi{Offsets::VAR_MOVER_TWO_PI};
|
||||
const Live<float> kHalfPi{Offsets::VAR_HALF_PI}; // the pitch clamp
|
||||
const Live<float> kNegHalfPi{Offsets::VAR_MINUS_HALF_PI};
|
||||
const Live<float> kThreeQuarters{Offsets::VAR_THREE_QUARTERS};
|
||||
constexpr float kFltMax = FLT_MAX;
|
||||
constexpr float kNegFltMax = -FLT_MAX;
|
||||
const Live<float> kSnapSq{Offsets::VAR_MOVER_SNAP_DISTANCE_SQ}; // 3 yards squared
|
||||
const Live<float> kWarpSpeedSq{Offsets::VAR_MOVER_WARP_SPEED_SQ}; // 60 yards a second squared
|
||||
const Live<float> kReachedSq{Offsets::VAR_MOVER_PATH_POINT_SQ}; // one path point
|
||||
const Live<float> kSixth{Offsets::VAR_ONE_SIXTH}; // the shortest path
|
||||
const Live<float> kFour{Offsets::VAR_FOUR}; // the path speed's cap over the run speed
|
||||
const float kCellCentre = Bits(0x46855555); // 17066.666, an immediate (0x00616BF0)
|
||||
const Live<float> kCellSpan{Offsets::VAR_MOVER_CELL_SPAN};
|
||||
const float kDefaultRadius = Bits(0x3EAAAAAB);
|
||||
const float kDefaultHeight = Bits(0x4001C71C);
|
||||
|
||||
@@ -119,9 +120,10 @@ int32_t Round(double x) {
|
||||
return static_cast<int32_t>(static_cast<int64_t>(biased));
|
||||
}
|
||||
|
||||
// DotVector3 (0x00602630).
|
||||
// DotVector3, unrounded.
|
||||
double Dot(const float (&a)[3], const float (&b)[3]) {
|
||||
return (D(a[2]) * b[2] + D(a[1]) * b[1]) + D(a[0]) * b[0];
|
||||
using Fn = double(__fastcall *)(const float *, const float *);
|
||||
return reinterpret_cast<Fn>(Offsets::FUN_DOT_VECTOR3)(a, b);
|
||||
}
|
||||
|
||||
using Contact::Facet;
|
||||
@@ -639,7 +641,9 @@ bool LandsOn(const Body &b, const Facet &f, const float (&move)[3]) {
|
||||
|
||||
// ---- walking helpers (0x00635C00 to 0x00636610) ------------------------------------
|
||||
|
||||
// SelectBevelContactNormal (0x00636610).
|
||||
// SelectBevelContactNormal (0x00636610), transcribed rather than called: with
|
||||
// three bevels and no odd one out the client reads an index from a stack slot
|
||||
// it never wrote.
|
||||
bool BevelDirection(const Plane *faces, uint32_t count, float (&out)[3]) {
|
||||
if (count == 0 || count > 4)
|
||||
return false;
|
||||
@@ -756,52 +760,21 @@ bool PlaneNearFoot(const Body &b, const Plane &pl) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Matrix3Determinant (0x007BE0E0), Matrix3Adjugate (0x007BE1E0),
|
||||
// InvertMatrix3 (0x007BE2A0).
|
||||
float Determinant(const float (&m)[9]) {
|
||||
return static_cast<float>(D(m[6]) * m[1] * m[5] + D(m[2]) * m[3] * m[7] + D(m[8]) * m[0] * m[4] -
|
||||
D(m[6]) * m[2] * m[4] - D(m[8]) * m[1] * m[3] - D(m[0]) * m[7] * m[5]);
|
||||
}
|
||||
|
||||
void Invert(const float (&m)[9], float det, float (&out)[9]) {
|
||||
const float adj[9] = {
|
||||
static_cast<float>(D(m[8]) * m[4] - D(m[5]) * m[7]), static_cast<float>(-(D(m[1]) * m[8] - D(m[2]) * m[7])),
|
||||
static_cast<float>(D(m[5]) * m[1] - D(m[2]) * m[4]), static_cast<float>(-(D(m[3]) * m[8] - D(m[5]) * m[6])),
|
||||
static_cast<float>(D(m[8]) * m[0] - D(m[2]) * m[6]), static_cast<float>(-(D(m[5]) * m[0] - D(m[2]) * m[3])),
|
||||
static_cast<float>(D(m[7]) * m[3] - D(m[6]) * m[4]), static_cast<float>(-(D(m[7]) * m[0] - D(m[1]) * m[6])),
|
||||
static_cast<float>(D(m[0]) * m[4] - D(m[1]) * m[3])};
|
||||
const float inverse = static_cast<float>(1.0 / det);
|
||||
for (int i = 0; i < 9; ++i)
|
||||
out[i] = static_cast<float>(D(inverse) * adj[i]);
|
||||
}
|
||||
|
||||
// IntersectThreePlanes (0x00634FC0).
|
||||
// IntersectThreePlanes: the point the three planes share.
|
||||
void ThreePlanes(const Plane &a, const Plane &b, const Plane &c, float (&out)[3]) {
|
||||
const float m[9] = {a.n[0], a.n[1], a.n[2], b.n[0], b.n[1], b.n[2], c.n[0], c.n[1], c.n[2]};
|
||||
const float v[3] = {-a.d, -b.d, -c.d};
|
||||
float inv[9];
|
||||
Invert(m, Determinant(m), inv);
|
||||
for (int r = 0; r < 3; ++r)
|
||||
out[r] = static_cast<float>((D(inv[r * 3 + 2]) * v[2] + D(inv[r * 3 + 1]) * v[1]) + D(inv[r * 3]) * v[0]);
|
||||
using Fn = float *(__fastcall *)(float *, const Plane *, const Plane *, const Plane *);
|
||||
reinterpret_cast<Fn>(Offsets::FUN_INTERSECT_THREE_PLANES)(out, &a, &b, &c);
|
||||
}
|
||||
|
||||
// PointToLineDistanceSquared (0x00634F40).
|
||||
// PointToLineDistanceSquared: from p to the line through q along the unit
|
||||
// `dir`.
|
||||
double LineDistance2(const float (&p)[3], const float (&q)[3], const float (&dir)[3]) {
|
||||
const double v[3] = {D(p[0]) - q[0], D(p[1]) - q[1], D(p[2]) - q[2]};
|
||||
const double proj = (v[2] * dir[2] + v[1] * dir[1]) + v[0] * dir[0];
|
||||
const double px = proj * dir[0];
|
||||
const float py = static_cast<float>(proj * dir[1]);
|
||||
const float pz = static_cast<float>(proj * dir[2]);
|
||||
const double cx = px + q[0];
|
||||
const double cy = D(py) + q[1];
|
||||
const float cz = static_cast<float>(D(pz) + q[2]);
|
||||
const float ex = static_cast<float>(D(p[0]) - cx);
|
||||
const double ey = D(p[1]) - cy;
|
||||
const double ez = D(p[2]) - cz;
|
||||
return (ez * ez + ey * ey) + D(ex) * ex;
|
||||
using Fn = double(__fastcall *)(const float *, const float *, const float *);
|
||||
return reinterpret_cast<Fn>(Offsets::FUN_POINT_TO_LINE_DISTANCE_SQ)(p, q, dir);
|
||||
}
|
||||
|
||||
// FindNearestTriangleEdge (0x00634DA0).
|
||||
// FindNearestTriangleEdge (0x00634DA0), which the client runs on its own
|
||||
// facet list (0x00C4E534): transcribed for the body's list.
|
||||
void NearestEdge(const Facet &f, const float (&point)[3], const float (&crease)[3], float (&out)[3]) {
|
||||
float best = kFltMax;
|
||||
out[0] = out[1] = out[2] = 0.0f;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
// 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/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
// The two helpers the transcribed client mover (SceneContact.cpp,
|
||||
// SceneMover.cpp) writes its arithmetic with. The client runs it on the x87
|
||||
// at 53 bits and stores floats, so a sum is taken in doubles (D) and each
|
||||
// store is a float cast. A constant the client reads from memory is a
|
||||
// Game::Live over its Offsets.h address; Bits is for the few that are code
|
||||
// immediates or have no address.
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
namespace Model::Scene::Precision {
|
||||
|
||||
// The float with these bits.
|
||||
inline float Bits(uint32_t bits) {
|
||||
float f;
|
||||
std::memcpy(&f, &bits, sizeof f);
|
||||
return f;
|
||||
}
|
||||
|
||||
// A float widened to the 53-bit sum the x87 keeps.
|
||||
inline double D(float x) { return x; }
|
||||
|
||||
} // namespace Model::Scene::Precision
|
||||
+31
-55
@@ -61,6 +61,7 @@
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "dbc/Lookup.h"
|
||||
#include "gx/Matrix.h"
|
||||
#include "model/DisplayInfo.h"
|
||||
#include "model/M2.h"
|
||||
#include "model/VisualKit.h"
|
||||
@@ -125,7 +126,7 @@ constexpr int kAnimInFlight = 144;
|
||||
constexpr float kReleaseTimeoutSec = 2.0f; // 0x0060A814
|
||||
constexpr float kMaxSpeed = 100.0f; // 0x0080C854
|
||||
constexpr float kSoundFadeSec = 0.15f; // the missile's free, 0x0061CD70
|
||||
constexpr float kAimHeight = 0.75f; // 0x008012CC
|
||||
const Game::Live<float> kAimHeight{Offsets::VAR_THREE_QUARTERS};
|
||||
constexpr uint32_t kFallbackAttachments[] = {15, 19};
|
||||
constexpr char kErrorCube[] = "Spells\\ErrorCube.mdx";
|
||||
|
||||
@@ -264,10 +265,17 @@ void Nock(Actor &actor) {
|
||||
Model::DisplayInfo::LightChildren(actor.SceneFrame(), actor.model);
|
||||
}
|
||||
|
||||
// CreateLooseItemModel: an item display's model for `body`, of `kind`
|
||||
// (LOOSE_ITEM_*), that the caller owns one reference on, or null.
|
||||
void *LooseItemModel(void *body, uint32_t display, uint32_t kind) {
|
||||
using LooseItem_t = void *(__fastcall *)(void *model, const void *record, uint32_t kind);
|
||||
return reinterpret_cast<LooseItem_t>(Offsets::FUN_CREATE_LOOSE_ITEM_MODEL)(
|
||||
body, DBC::Record(Offsets::VAR_ITEMDISPLAYINFO_RECORDS, Offsets::VAR_ITEMDISPLAYINFO_COUNT, display), kind);
|
||||
}
|
||||
|
||||
// SetAmmoDisplay (0x0060BA30): the ammo in hand for `display`, made again
|
||||
// when it changes; nocked at once while the bow is drawn.
|
||||
void HoldAmmo(Actor &actor, uint32_t display) {
|
||||
using LooseItem_t = void *(__fastcall *)(void *model, const void *record, uint32_t kind);
|
||||
if (actor.heldAmmoDisplay == display && actor.heldAmmo != nullptr)
|
||||
return;
|
||||
if (actor.heldAmmo != nullptr) {
|
||||
@@ -281,20 +289,11 @@ void HoldAmmo(Actor &actor, uint32_t display) {
|
||||
return;
|
||||
const uint32_t kind = actor.ranged.inventoryType == Offsets::INVTYPE_THROWN ? Offsets::LOOSE_ITEM_WEAPON
|
||||
: Offsets::LOOSE_ITEM_AMMO;
|
||||
actor.heldAmmo = reinterpret_cast<LooseItem_t>(Offsets::FUN_CREATE_LOOSE_ITEM_MODEL)(
|
||||
actor.model,
|
||||
DBC::Record(Offsets::VAR_ITEMDISPLAYINFO_RECORDS, Offsets::VAR_ITEMDISPLAYINFO_COUNT, display), kind);
|
||||
actor.heldAmmo = LooseItemModel(actor.model, display, kind);
|
||||
if (actor.heldAmmo != nullptr && !KeepsAmmoOff(actor) && actor.bowDrawn && kind == Offsets::LOOSE_ITEM_AMMO)
|
||||
Nock(actor);
|
||||
}
|
||||
|
||||
int KeyBoneAnimId(void *model) {
|
||||
using Fn = void(__thiscall *)(void *, int, void *);
|
||||
uint32_t state[Offsets::M2_KEY_BONE_ANIM_STATE_SIZE / 4];
|
||||
reinterpret_cast<Fn>(Offsets::FUN_M2MODEL_GET_KEY_BONE_ANIM_STATE)(model, -1, state);
|
||||
return static_cast<int>(state[Offsets::OFF_M2_KEY_BONE_ANIM_STATE_ID / 4]);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void EndRangedPose(Actor &actor) {
|
||||
@@ -302,7 +301,7 @@ void EndRangedPose(Actor &actor) {
|
||||
if (actor.heldAmmo != nullptr && M2::Parent(actor.heldAmmo) != nullptr)
|
||||
M2::Detach(actor.heldAmmo);
|
||||
if (void *ranged = RangedModel(actor)) {
|
||||
if (KeyBoneAnimId(ranged) != Offsets::ANIM_BOW_RELEASE)
|
||||
if (M2::GetAnimState(ranged, -1).id != Offsets::ANIM_BOW_RELEASE)
|
||||
M2::PlayAnimation(ranged, -1, Offsets::ANIM_STAND, -1, 0, 1.0f, 1, 1);
|
||||
}
|
||||
}
|
||||
@@ -314,29 +313,20 @@ namespace {
|
||||
// has no such state and asks the whole model.
|
||||
void PlayBowPull(Actor &actor) {
|
||||
using HasAnim_t = bool(__thiscall *)(void *model, uint32_t anim);
|
||||
using State_t = void(__thiscall *)(void *model, int keyBone, void *state);
|
||||
using Info_t = void(__thiscall *)(void *model, uint32_t anim, uint32_t variation, void *info);
|
||||
void *ranged = RangedModel(actor);
|
||||
if (ranged == nullptr || !M2::IsLoaded(ranged, 0, 0) ||
|
||||
!reinterpret_cast<HasAnim_t>(Offsets::FUN_M2MODEL_HAS_ANIMATION)(ranged, Offsets::ANIM_BOW_PULL) ||
|
||||
actor.model == nullptr || !M2::IsLoaded(actor.model, 0, 0))
|
||||
return;
|
||||
uint8_t state[Offsets::M2_KEY_BONE_ANIM_STATE_SIZE];
|
||||
reinterpret_cast<State_t>(Offsets::FUN_M2MODEL_GET_KEY_BONE_ANIM_STATE)(actor.model, -1, state);
|
||||
if (Game::Read<uint32_t>(state, Offsets::OFF_M2_KEY_BONE_ANIM_STATE_LATCH) != 0)
|
||||
const M2::AnimState state = M2::GetAnimState(actor.model, -1);
|
||||
if (state.latch != 0)
|
||||
return;
|
||||
const auto position =
|
||||
static_cast<double>(Game::Read<uint32_t>(state, Offsets::OFF_M2_KEY_BONE_ANIM_STATE_POSITION));
|
||||
const auto played =
|
||||
static_cast<int>(position / Game::Read<float>(state, Offsets::OFF_M2_KEY_BONE_ANIM_STATE_SPEED));
|
||||
const int left = Game::Read<int32_t>(state, Offsets::OFF_M2_KEY_BONE_ANIM_STATE_HI) - played -
|
||||
Game::Read<int32_t>(state, Offsets::OFF_M2_KEY_BONE_ANIM_STATE_LO);
|
||||
const auto played = static_cast<int>(static_cast<double>(state.position) / state.speed);
|
||||
const int left = static_cast<int32_t>(state.hi) - played - static_cast<int32_t>(state.lo);
|
||||
if (left <= 0)
|
||||
return;
|
||||
uint8_t info[Offsets::M2_SEQUENCE_INFO_SIZE] = {};
|
||||
reinterpret_cast<Info_t>(Offsets::FUN_M2MODEL_GET_SEQUENCE_INFO)(ranged, Offsets::ANIM_BOW_PULL, 0, info);
|
||||
const float speed = static_cast<float>(Game::Read<uint32_t>(info, Offsets::OFF_M2_SEQUENCE_INFO_LENGTH)) /
|
||||
static_cast<float>(left);
|
||||
const M2::SequenceInfo info = M2::GetSequenceInfo(ranged, Offsets::ANIM_BOW_PULL, 0);
|
||||
const float speed = static_cast<float>(info.length) / static_cast<float>(left);
|
||||
M2::PlayAnimation(ranged, -1, Offsets::ANIM_BOW_PULL, 0, 0, speed, 1, 1);
|
||||
}
|
||||
|
||||
@@ -467,15 +457,12 @@ void Impact(Actor &caster, SpellCast &cast, bool missileHit) {
|
||||
// the destination first (Arrive 0x0061E1D0), keeping the turn of its flight.
|
||||
bool Stick(SpellCast &cast) {
|
||||
using Matrix_t = void(__thiscall *)(void *model, float *out, uint32_t id);
|
||||
using Invert_t = void(__thiscall *)(const float *m, float *out, float scale);
|
||||
using Multiply_t = float *(__fastcall *)(float *out, const float *a, const float *b);
|
||||
using SetBase_t = void(__thiscall *)(void *model, const float *m);
|
||||
Actor *target = cast.target;
|
||||
if (!cast.sticks || cast.attachment < 0 || cast.missile == nullptr || target == nullptr ||
|
||||
target->model == nullptr || !M2::HasAttachment(target->model, static_cast<uint32_t>(cast.attachment)))
|
||||
return false;
|
||||
void *missile = cast.missile;
|
||||
float *base = Game::Ptr<float>(missile, Offsets::OFF_M2MODEL_BASE_MATRIX);
|
||||
float *base = M2::BaseMatrix(missile);
|
||||
for (int i = 0; i < 3; ++i)
|
||||
base[12 + i] = cast.destination[i];
|
||||
M2::SetAnimDoneCallback(missile, nullptr, 0, 0);
|
||||
@@ -484,10 +471,10 @@ bool Stick(SpellCast &cast) {
|
||||
float attachment[16], inverse[16], world[16], local[16];
|
||||
reinterpret_cast<Matrix_t>(Offsets::FUN_M2MODEL_GET_ATTACHMENT_MATRIX)(target->model, attachment,
|
||||
static_cast<uint32_t>(cast.attachment));
|
||||
reinterpret_cast<Invert_t>(Offsets::FUN_MATRIX_INVERT_AFFINE)(attachment, inverse, target->scale);
|
||||
Gx::InvertAffine(attachment, inverse, target->scale);
|
||||
M2::GetBaseTransform(missile, world);
|
||||
reinterpret_cast<Multiply_t>(Offsets::FUN_MATRIX_MULTIPLY)(local, world, inverse);
|
||||
reinterpret_cast<SetBase_t>(Offsets::FUN_M2MODEL_SET_BASE_TRANSFORM)(missile, local);
|
||||
Gx::Multiply(local, world, inverse);
|
||||
M2::SetBaseTransform(missile, local);
|
||||
// The world object goes (0x0061E859); the missile is lit as the target's
|
||||
// child.
|
||||
Model::DisplayInfo::LightChildren(target->SceneFrame(), target->model);
|
||||
@@ -508,9 +495,7 @@ void LeaveImpactModel(Actor &caster, const SpellCast &cast) {
|
||||
LightAsEntity(model, light, caster.SceneFrame());
|
||||
const float axisZ[3] = {0.0f, 0.0f, 1.0f};
|
||||
const float scales[3] = {1.0f, 1.0f, 1.0f};
|
||||
using SetTRS_t = void(__thiscall *)(void *, const float *, float, const float *, const float *);
|
||||
reinterpret_cast<SetTRS_t>(Offsets::FUN_M2MODEL_SET_BASE_TRS)(model, cast.destination, 0.0f,
|
||||
axisZ, scales);
|
||||
M2::SetBaseTRS(model, cast.destination, 0.0f, axisZ, scales);
|
||||
caster.impactModels.push_back({model, 0, std::move(light)});
|
||||
}
|
||||
|
||||
@@ -558,24 +543,20 @@ bool Launch(Actor &caster, SpellCast &cast, const float (&from)[3]) {
|
||||
// ammo's, else the error cube. A shot made during a rifle animation is drawn
|
||||
// at alpha 0 (the bullet is not seen).
|
||||
void *MakeMissile(Actor &caster, const SpellCast &cast) {
|
||||
using LooseItem_t = void *(__fastcall *)(void *model, const void *record, uint32_t kind);
|
||||
void *scene = Model::Pane::Scene(caster.SceneFrame());
|
||||
void *model = nullptr;
|
||||
const auto effect = Game::Read<int32_t>(cast.visual, Offsets::OFF_SPELLVISUAL_MISSILE_MODEL);
|
||||
if (effect < 1) {
|
||||
if (cast.ammoDisplay != 0)
|
||||
model = reinterpret_cast<LooseItem_t>(Offsets::FUN_CREATE_LOOSE_ITEM_MODEL)(
|
||||
caster.model,
|
||||
DBC::Record(Offsets::VAR_ITEMDISPLAYINFO_RECORDS, Offsets::VAR_ITEMDISPLAYINFO_COUNT,
|
||||
cast.ammoDisplay),
|
||||
cast.ammoType == Offsets::INVTYPE_THROWN ? Offsets::LOOSE_ITEM_WEAPON : Offsets::LOOSE_ITEM_AMMO);
|
||||
model = LooseItemModel(caster.model, cast.ammoDisplay,
|
||||
cast.ammoType == Offsets::INVTYPE_THROWN ? Offsets::LOOSE_ITEM_WEAPON
|
||||
: Offsets::LOOSE_ITEM_AMMO);
|
||||
} else if (const char *file = EffectFile(static_cast<uint32_t>(effect))) {
|
||||
model = M2::CreateModel(scene, file);
|
||||
}
|
||||
if (model == nullptr)
|
||||
model = M2::CreateModel(scene, kErrorCube);
|
||||
if (model != nullptr && reinterpret_cast<int(__fastcall *)(int)>(Offsets::FUN_IS_RIFLE_ANIMATION)(
|
||||
caster.CurrentAnimation()) != 0)
|
||||
if (model != nullptr && M2::IsRifleAnimation(caster.CurrentAnimation()))
|
||||
M2::SetAlpha(model, 0.0f);
|
||||
return model;
|
||||
}
|
||||
@@ -701,16 +682,15 @@ void BowPull(Actor &caster) {
|
||||
// bow animation plays the weapon's stand and a rifle animation its release;
|
||||
// the ammo leaves the string.
|
||||
void BowRelease(Actor &caster) {
|
||||
using IsAnim_t = int(__fastcall *)(int anim);
|
||||
caster.bowDrawn = false;
|
||||
if (MissileQueued(caster) && caster.model != nullptr) {
|
||||
const int anim = caster.CurrentAnimation();
|
||||
void *ranged = RangedModel(caster);
|
||||
if (reinterpret_cast<IsAnim_t>(Offsets::FUN_IS_BOW_ANIMATION)(anim) != 0 &&
|
||||
if (M2::IsBowAnimation(anim) &&
|
||||
M2::HasAttachment(caster.model, Offsets::ATTACH_BOW_RELEASE)) {
|
||||
if (ranged != nullptr)
|
||||
M2::PlayAnimation(ranged, -1, Offsets::ANIM_STAND, -1, 0, 1.0f, 1, 1);
|
||||
} else if (reinterpret_cast<IsAnim_t>(Offsets::FUN_IS_RIFLE_ANIMATION)(anim) != 0 &&
|
||||
} else if (M2::IsRifleAnimation(anim) &&
|
||||
M2::HasAttachment(caster.model, Offsets::ATTACH_RIFLE_RELEASE)) {
|
||||
if (ranged != nullptr)
|
||||
M2::PlayAnimation(ranged, -1, Offsets::ANIM_BOW_RELEASE, -1, 0, 1.0f, 1, 1);
|
||||
@@ -853,8 +833,6 @@ void Link(Actor &caster) {
|
||||
// The missile faces its travel: yaw about the up axis, then pitch, as an
|
||||
// actor's placement turns.
|
||||
void Place(Actor &caster) {
|
||||
using SetTRS_t = void(__thiscall *)(void *, const float *, float, const float *, const float *);
|
||||
using Rotate_t = void(__thiscall *)(float *m, float angle, const float *axis, int);
|
||||
const float axisY[3] = {0.0f, 1.0f, 0.0f};
|
||||
const float axisZ[3] = {0.0f, 0.0f, 1.0f};
|
||||
const float scales[3] = {1.0f, 1.0f, 1.0f};
|
||||
@@ -866,10 +844,8 @@ void Place(Actor &caster) {
|
||||
const float dz = cast.destination[2] - cast.position[2];
|
||||
const float yaw = std::atan2(dy, dx);
|
||||
const float pitch = -std::atan2(dz, std::sqrt(dx * dx + dy * dy));
|
||||
reinterpret_cast<SetTRS_t>(Offsets::FUN_M2MODEL_SET_BASE_TRS)(cast.missile, cast.position,
|
||||
yaw, axisZ, scales);
|
||||
reinterpret_cast<Rotate_t>(Offsets::FUN_MATRIX_ROTATE)(
|
||||
Game::Ptr<float>(cast.missile, Offsets::OFF_M2MODEL_BASE_MATRIX), pitch, axisY, 1);
|
||||
M2::SetBaseTRS(cast.missile, cast.position, yaw, axisZ, scales);
|
||||
Gx::Rotate(M2::BaseMatrix(cast.missile), pitch, axisY);
|
||||
Sounds::Move(caster.SceneFrame(), cast.missileSound, cast.position);
|
||||
}
|
||||
}
|
||||
|
||||
+62
-121
@@ -122,6 +122,7 @@
|
||||
#include "Offsets.h"
|
||||
#include "dbc/Lookup.h"
|
||||
#include "gx/Device.h"
|
||||
#include "gx/Matrix.h"
|
||||
#include "model/M2.h"
|
||||
#include "model/SceneContact.h"
|
||||
|
||||
@@ -249,7 +250,13 @@ struct Ambience {
|
||||
|
||||
namespace {
|
||||
|
||||
using Matrix = float[16];
|
||||
using Gx::Identity;
|
||||
using Gx::Matrix;
|
||||
using Gx::Multiply;
|
||||
using Gx::Rotate;
|
||||
using Gx::TransformBox;
|
||||
using Gx::TransformPoint;
|
||||
using Gx::Translate;
|
||||
|
||||
constexpr uint32_t Tag(const char (&name)[5]) {
|
||||
return (static_cast<uint32_t>(static_cast<uint8_t>(name[0])) << 24) |
|
||||
@@ -359,27 +366,6 @@ int CheckedGroupCount(const char *path) {
|
||||
return groups;
|
||||
}
|
||||
|
||||
// ---- matrices --------------------------------------------------------------------
|
||||
|
||||
void Identity(Matrix &m) {
|
||||
std::memset(m, 0, sizeof m);
|
||||
m[0] = m[5] = m[10] = m[15] = 1.0f;
|
||||
}
|
||||
|
||||
void Translate(Matrix &m, const float (&t)[3]) {
|
||||
reinterpret_cast<void(__thiscall *)(float *, const float *)>(Offsets::FUN_MATRIX_TRANSLATE)(m, t);
|
||||
}
|
||||
|
||||
void Rotate(Matrix &m, float angle, const float (&axis)[3]) {
|
||||
reinterpret_cast<void(__thiscall *)(float *, float, const float *, int)>(Offsets::FUN_MATRIX_ROTATE)(
|
||||
m, angle, axis, 1);
|
||||
}
|
||||
|
||||
void Multiply(Matrix &out, const Matrix &a, const Matrix &b) {
|
||||
reinterpret_cast<float *(__fastcall *)(float *, const float *, const float *)>(
|
||||
Offsets::FUN_MATRIX_MULTIPLY)(out, a, b);
|
||||
}
|
||||
|
||||
// ---- the draw ---------------------------------------------------------------------
|
||||
|
||||
void *Group(void *object, uint32_t index) {
|
||||
@@ -525,10 +511,8 @@ void CommitLighting(const Backdrop &b, void *frame, const float (&eye)[3]) {
|
||||
// render-state scope ends it.
|
||||
if (!WmoFogShown(b) &&
|
||||
(Game::Read<uint32_t>(frame, Offsets::OFF_SIMPLEMODEL_FOG_FLAGS) & Offsets::SIMPLEMODEL_FOG_ARMED) == 0) {
|
||||
using SetFloat_t = void(__fastcall *)(int id, int, float value);
|
||||
const auto setFloat = reinterpret_cast<SetFloat_t>(Offsets::FUN_GX_RS_SET_FLOAT);
|
||||
setFloat(Offsets::GXRS_FOG_START, 0, b.farClip);
|
||||
setFloat(Offsets::GXRS_FOG_END, 0, Game::Read<float>(Offsets::VAR_NO_LIGHT_FOG_END));
|
||||
Gx::SetStateFloat(Offsets::GXRS_FOG_START, b.farClip);
|
||||
Gx::SetStateFloat(Offsets::GXRS_FOG_END, Game::Read<float>(Offsets::VAR_NO_LIGHT_FOG_END));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -563,17 +547,6 @@ void DrawGroups(Backdrop &b, void *frame) {
|
||||
|
||||
float EngineFloat(uintptr_t address) { return Game::Read<float>(address); }
|
||||
|
||||
void TransformPoint(const float (&in)[3], const Matrix &m, float (&out)[3]) {
|
||||
float v[3] = {in[0], in[1], in[2]};
|
||||
reinterpret_cast<float *(__fastcall *)(float *, float *, const float *)>(Offsets::FUN_TRANSFORM_POINT_IN_PLACE)(
|
||||
out, v, m);
|
||||
}
|
||||
|
||||
void TransformBox(const float *m, const float (&box)[6], float (&out)[6]) {
|
||||
reinterpret_cast<void(__fastcall *)(const float *, const float *, float *)>(Offsets::FUN_TRANSFORM_BOX)(m, box,
|
||||
out);
|
||||
}
|
||||
|
||||
void ReadVector(const uint8_t *at, float (&out)[3]) { std::memcpy(out, at, sizeof out); }
|
||||
|
||||
// BGRA bytes as the rgb the record adds (byte / 255).
|
||||
@@ -584,24 +557,22 @@ void ColorOf(uint32_t bgra, float (&rgb)[3]) {
|
||||
rgb[2] = static_cast<float>(bgra & 0xFF) * k;
|
||||
}
|
||||
|
||||
using LightInt_t = void(__thiscall *)(void *light, int value);
|
||||
using LightVector_t = void(__thiscall *)(void *light, const float *v);
|
||||
|
||||
MapLight MakeMapLight(const Backdrop &b, const uint8_t *record) {
|
||||
MapLight m{};
|
||||
void *light = m.light.bytes;
|
||||
reinterpret_cast<void(__fastcall *)(void *)>(Offsets::FUN_M2LIGHT_INITIALIZE)(light);
|
||||
M2::InitLight(light);
|
||||
float position[3];
|
||||
ReadVector(record + Offsets::OFF_MOLT_POSITION, position);
|
||||
TransformPoint(position, b.placement, position);
|
||||
m.start = Game::Read<float>(record, Offsets::OFF_MOLT_START);
|
||||
m.end = Game::Read<float>(record, Offsets::OFF_MOLT_END);
|
||||
if (std::fabs(m.start - m.end) < EngineFloat(Offsets::VAR_MAP_LIGHT_RANGE_EPSILON))
|
||||
m.end += EngineFloat(Offsets::VAR_MAP_LIGHT_RANGE_PAD);
|
||||
if (std::fabs(m.start - m.end) < EngineFloat(Offsets::VAR_ONE_THOUSANDTH))
|
||||
m.end += EngineFloat(Offsets::VAR_ONE_TENTH);
|
||||
m.falloff = EngineFloat(Offsets::VAR_ONE) / (m.end - m.start);
|
||||
reinterpret_cast<LightInt_t>(Offsets::FUN_M2LIGHT_SET_ENABLED)(light, 1);
|
||||
reinterpret_cast<LightInt_t>(Offsets::FUN_M2LIGHT_SET_TYPE)(light, 1);
|
||||
reinterpret_cast<LightVector_t>(Offsets::FUN_M2LIGHT_SET_POSITION)(light, position);
|
||||
M2::SetLightEnabled(light, true);
|
||||
M2::SetLightType(light, 1);
|
||||
M2::SetLightPosition(light, position);
|
||||
const float intensity = Game::Read<float>(record, Offsets::OFF_MOLT_INTENSITY);
|
||||
float rgb[3];
|
||||
ColorOf(Game::Read<uint32_t>(record, Offsets::OFF_MOLT_COLOR), rgb);
|
||||
@@ -636,12 +607,12 @@ void AddMapLight(const float (&position)[3], const MapLight &m, std::vector<Ligh
|
||||
void *light = added.bytes;
|
||||
const float k = EngineFloat(Offsets::VAR_ONE) / distance;
|
||||
const float direction[3] = {k * offset[0], k * offset[1], k * offset[2]};
|
||||
reinterpret_cast<LightVector_t>(Offsets::FUN_M2LIGHT_SET_DIRECTION)(light, direction);
|
||||
M2::SetLightDirection(light, direction);
|
||||
float *diffuse = reinterpret_cast<float *>(added.bytes + Offsets::OFF_M2LIGHT_DIFFUSE);
|
||||
for (int i = 0; i < 3; ++i)
|
||||
diffuse[i] *= intensity;
|
||||
reinterpret_cast<LightInt_t>(Offsets::FUN_M2LIGHT_SET_ENABLED)(light, 1);
|
||||
reinterpret_cast<LightInt_t>(Offsets::FUN_M2LIGHT_SET_TYPE)(light, 0);
|
||||
M2::SetLightEnabled(light, true);
|
||||
M2::SetLightType(light, 0);
|
||||
const float attenuation[3] = {1.0f, 0.0f, 0.0f};
|
||||
std::memcpy(added.bytes + Offsets::OFF_M2LIGHT_ATTENUATION, attenuation, sizeof attenuation);
|
||||
lights.push_back(added);
|
||||
@@ -759,12 +730,9 @@ Doodad *MakeDoodad(Backdrop &b, void *frame, uint32_t index) {
|
||||
Matrix m;
|
||||
Identity(m);
|
||||
Translate(m, position);
|
||||
reinterpret_cast<void(__thiscall *)(float *, const float *)>(Offsets::FUN_MATRIX_ROTATE_QUATERNION)(
|
||||
m, Game::Ptr<float>(record, Offsets::OFF_MODD_ROTATION));
|
||||
reinterpret_cast<void(__thiscall *)(float *, float)>(Offsets::FUN_MATRIX_SCALE)(
|
||||
m, Game::Read<float>(record, Offsets::OFF_MODD_SCALE));
|
||||
reinterpret_cast<float *(__thiscall *)(float *, const float *)>(Offsets::FUN_MATRIX_MULTIPLY_IN_PLACE)(
|
||||
m, b.placement);
|
||||
Gx::RotateQuaternion(m, Game::Ptr<float>(record, Offsets::OFF_MODD_ROTATION));
|
||||
Gx::Scale(m, Game::Read<float>(record, Offsets::OFF_MODD_SCALE));
|
||||
Gx::MultiplyInPlace(m, b.placement);
|
||||
std::memcpy(d.matrix, m, sizeof d.matrix);
|
||||
d.scale = Game::Read<float>(record, Offsets::OFF_MODD_SCALE);
|
||||
using Split_t = void(__stdcall *)(const uint32_t *src, uint32_t *first, uint8_t floor, uint32_t *second,
|
||||
@@ -774,8 +742,7 @@ Doodad *MakeDoodad(Backdrop &b, void *frame, uint32_t index) {
|
||||
&d.ambient, Offsets::DOODAD_AMBIENT_CAP);
|
||||
d.model = M2::CreateModel(Model::Pane::Scene(frame), path);
|
||||
if (d.model != nullptr) {
|
||||
reinterpret_cast<void(__thiscall *)(void *, const float *)>(Offsets::FUN_M2MODEL_SET_BASE_TRANSFORM)(d.model,
|
||||
m);
|
||||
M2::SetBaseTransform(d.model, m);
|
||||
const auto user = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(&d));
|
||||
M2::SetAnimDoneCallback(d.model, reinterpret_cast<const void *>(Offsets::FUN_DOODAD_MODEL_DONE), 0, 0);
|
||||
M2::SetEventCallback(d.model, reinterpret_cast<const void *>(&OnDoodadEvent), user, 0);
|
||||
@@ -883,8 +850,7 @@ Backdrop *Load(const char *path, const float (&placement)[16], uint32_t doodadSe
|
||||
auto *b = new Backdrop{object, {}, {}, doodadSet, mapID};
|
||||
b->serial = ++serials;
|
||||
std::memcpy(b->placement, placement, sizeof b->placement);
|
||||
reinterpret_cast<void(__thiscall *)(const float *, float *, float)>(Offsets::FUN_MATRIX_INVERT_AFFINE)(
|
||||
b->placement, b->inverse, 1.0f);
|
||||
Gx::InvertAffine(b->placement, b->inverse, 1.0f);
|
||||
std::memcpy(b->def + Offsets::OFF_MAPOBJDEF_PLACEMENT, b->placement, sizeof b->placement);
|
||||
std::memcpy(b->def + Offsets::OFF_MAPOBJDEF_INVERSE, b->inverse, sizeof b->inverse);
|
||||
std::memcpy(b->def + Offsets::OFF_MAPOBJDEF_OBJECT, &object, sizeof object);
|
||||
@@ -1235,18 +1201,7 @@ void UpdateCameraFog(Backdrop &b, void *frame, const float (&eye)[3], float farC
|
||||
|
||||
using Fn_t = void(__cdecl *)();
|
||||
|
||||
// The render states a pass of the WMO sets (CommitLighting's fog range) last
|
||||
// until it ends.
|
||||
class RenderStateScope {
|
||||
public:
|
||||
RenderStateScope() { reinterpret_cast<Fn_t>(Offsets::FUN_GX_STATE_PUSH)(); }
|
||||
~RenderStateScope() { reinterpret_cast<Fn_t>(Offsets::FUN_GX_STATE_POP)(); }
|
||||
RenderStateScope(const RenderStateScope &) = delete;
|
||||
RenderStateScope &operator=(const RenderStateScope &) = delete;
|
||||
};
|
||||
|
||||
using Unit_t = void(__fastcall *)(int unit);
|
||||
using Load_t = void(__fastcall *)(int unit, const float *m);
|
||||
constexpr int kWorldStack = 8;
|
||||
|
||||
// The render states pushed and world stack 8 = placement x Translate(-eye),
|
||||
@@ -1256,14 +1211,14 @@ void PushObjectSpace(const Backdrop &b, const float (&eye)[3]) {
|
||||
Identity(toEye);
|
||||
Translate(toEye, {-eye[0], -eye[1], -eye[2]});
|
||||
Multiply(world, b.placement, toEye);
|
||||
reinterpret_cast<Fn_t>(Offsets::FUN_GX_STATE_PUSH)();
|
||||
reinterpret_cast<Unit_t>(Offsets::FUN_GX_TEXMTX_PUSH)(kWorldStack);
|
||||
reinterpret_cast<Load_t>(Offsets::FUN_GX_TEXMTX_LOAD)(kWorldStack, world);
|
||||
Gx::PushStates();
|
||||
Gx::PushTransform(kWorldStack);
|
||||
Gx::SetTransform(kWorldStack, world);
|
||||
}
|
||||
|
||||
void PopObjectSpace() {
|
||||
reinterpret_cast<Unit_t>(Offsets::FUN_GX_TEXMTX_POP)(kWorldStack);
|
||||
reinterpret_cast<Fn_t>(Offsets::FUN_GX_STATE_POP)();
|
||||
Gx::PopTransform(kWorldStack);
|
||||
Gx::PopStates();
|
||||
}
|
||||
|
||||
// AnimateMapEntityLight (0x0069E770): the ambient bytes and the intensity
|
||||
@@ -1349,7 +1304,7 @@ void Place(const Backdrop &b, Ambience &a, void *frame, void *model, const float
|
||||
float start[3];
|
||||
TransformPoint(point, *reinterpret_cast<const Matrix *>(base), start);
|
||||
|
||||
const float length = EngineFloat(Offsets::VAR_ENTITY_PROBE_LENGTH);
|
||||
const float length = EngineFloat(Offsets::VAR_ONE_THOUSAND);
|
||||
float end[3] = {start[0], start[1], start[2] - length};
|
||||
float t = 1.0f;
|
||||
uint32_t group = 0;
|
||||
@@ -1418,7 +1373,7 @@ void Settle(const Backdrop &b, Ambience &a, void *frame, void *model, float elap
|
||||
if (placed && a.generation == b.generation) {
|
||||
const float dx = position[0] - a.position[0], dy = position[1] - a.position[1],
|
||||
dz = position[2] - a.position[2];
|
||||
moved = !(std::fabs(dx * dx + dy * dy + dz * dz) < EngineFloat(Offsets::VAR_MAP_LIGHT_RANGE_EPSILON));
|
||||
moved = !(std::fabs(dx * dx + dy * dy + dz * dz) < EngineFloat(Offsets::VAR_ONE_THOUSANDTH));
|
||||
}
|
||||
if (!placed) {
|
||||
// A new node (0x00670DB0): intensity 1.0, the day ambient.
|
||||
@@ -1473,7 +1428,7 @@ bool LiquidAt(const Backdrop &b, const float (&point)[3], uint32_t &type, float
|
||||
return false;
|
||||
// The group, as a unit's is found (AttachEntityToGround 0x006A8A20): the
|
||||
// nearest face down from the point.
|
||||
const float end[3] = {point[0], point[1], point[2] - EngineFloat(Offsets::VAR_ENTITY_PROBE_LENGTH)};
|
||||
const float end[3] = {point[0], point[1], point[2] - EngineFloat(Offsets::VAR_ONE_THOUSAND)};
|
||||
float t = 1.0f;
|
||||
uint32_t group = 0;
|
||||
uint16_t face = 0;
|
||||
@@ -1821,11 +1776,6 @@ void FromEye(Matrix &m, const float (&eye)[3]) {
|
||||
// DrawDecalBatches (0x006D7480) over the WMO's facets, the eye for the
|
||||
// world camera.
|
||||
void DrawBatches(const Backdrop &b, const float (&box)[6], uint32_t argb, uint32_t mask, const float (&eye)[3]) {
|
||||
using GetInt_t = void(__fastcall *)(int id, int *out);
|
||||
using Set_t = void(__fastcall *)(int id, int value);
|
||||
using SetPtr_t = void(__fastcall *)(int id, const void *value);
|
||||
using SetWord_t = void(__fastcall *)(int id, int, uint32_t value);
|
||||
using SetFloat_t = void(__fastcall *)(int id, int, float value);
|
||||
using Caps_t = const uint8_t *(__fastcall *)();
|
||||
using WriteColored_t = void(__fastcall *)(const void *batch);
|
||||
using Write_t = void(__thiscall *)(const void *batch, uint32_t color);
|
||||
@@ -1839,31 +1789,25 @@ void DrawBatches(const Backdrop &b, const float (&box)[6], uint32_t argb, uint32
|
||||
ResetFacets();
|
||||
if (!CollectBox(b, box, mask))
|
||||
return;
|
||||
const auto getInt = reinterpret_cast<GetInt_t>(Offsets::FUN_GX_RS_GET_INT);
|
||||
const auto set = reinterpret_cast<Set_t>(Offsets::FUN_GX_RS_SET);
|
||||
const auto setPtr = reinterpret_cast<SetPtr_t>(Offsets::FUN_GX_RS_SET_PTR);
|
||||
reinterpret_cast<Fn_t>(Offsets::FUN_GX_STATE_PUSH)();
|
||||
int blend = 0;
|
||||
getInt(Offsets::GXRS_BLEND, &blend);
|
||||
Gx::PushStates();
|
||||
const int blend = Gx::GetState(Offsets::GXRS_BLEND);
|
||||
if (blend == Offsets::GXRS_BLEND_MODULATE) {
|
||||
setPtr(Offsets::GXRS_TEXTURE0 + 1, Game::Read<void *>(Offsets::VAR_SHADOW_GREY_RAMP));
|
||||
set(Offsets::GXRS_COMBINER0 + 1, Offsets::GXRS_COMBINE_ADD);
|
||||
Gx::SetState(Offsets::GXRS_TEXTURE0 + 1, Game::Read<void *>(Offsets::VAR_SHADOW_GREY_RAMP));
|
||||
Gx::SetState(Offsets::GXRS_COMBINER0 + 1, Offsets::GXRS_COMBINE_ADD);
|
||||
} else {
|
||||
setPtr(Offsets::GXRS_TEXTURE0 + 1, Game::Read<void *>(Offsets::VAR_SHADOW_RAMP));
|
||||
Gx::SetState(Offsets::GXRS_TEXTURE0 + 1, Game::Read<void *>(Offsets::VAR_SHADOW_RAMP));
|
||||
}
|
||||
const float bias = Game::Read<float>(Offsets::VAR_SHADOW_BIAS);
|
||||
if (bias != 0.0f)
|
||||
reinterpret_cast<SetFloat_t>(Offsets::FUN_GX_RS_SET_FLOAT)(
|
||||
Offsets::GXRS_DEPTH_BIAS, 0, (bias + bias) * Game::Read<float>(Offsets::VAR_SHADOW_BIAS_SCALE));
|
||||
Gx::SetStateFloat(Offsets::GXRS_DEPTH_BIAS, (bias + bias) * Game::Read<float>(Offsets::VAR_SHADOW_BIAS_SCALE));
|
||||
for (int unit = 0; unit < 2; ++unit) {
|
||||
set(Offsets::GXRS_TEXGEN0 + unit, Offsets::GXRS_TEXGEN_WORLD_POS);
|
||||
set(Offsets::GXRS_TEXXFORM0 + unit, Offsets::GXRS_TEXXFORM_MATRIX);
|
||||
Gx::SetState(Offsets::GXRS_TEXGEN0 + unit, Offsets::GXRS_TEXGEN_WORLD_POS);
|
||||
Gx::SetState(Offsets::GXRS_TEXXFORM0 + unit, Offsets::GXRS_TEXXFORM_MATRIX);
|
||||
}
|
||||
uint32_t color = argb;
|
||||
int lighting = 0;
|
||||
getInt(Offsets::GXRS_LIGHTING, &lighting);
|
||||
const int lighting = Gx::GetState(Offsets::GXRS_LIGHTING);
|
||||
if (lighting == 1) {
|
||||
reinterpret_cast<SetWord_t>(Offsets::FUN_GX_RS_SET_WORD)(Offsets::GXRS_MATERIAL, 0, argb);
|
||||
Gx::SetStateWord(Offsets::GXRS_MATERIAL, argb);
|
||||
} else if (Game::Read<int>(reinterpret_cast<Caps_t>(Offsets::FUN_GX_DEVICE_CAPS)(),
|
||||
Offsets::OFF_GXCAPS_COLOR_SWAP) == 1) {
|
||||
color = (argb & 0xFF00FF00u) | (argb & 0xFFu) << 16 | (argb >> 16 & 0xFFu);
|
||||
@@ -1871,7 +1815,7 @@ void DrawBatches(const Backdrop &b, const float (&box)[6], uint32_t argb, uint32
|
||||
Matrix toEye;
|
||||
Identity(toEye);
|
||||
Translate(toEye, {-eye[0], -eye[1], -eye[2]});
|
||||
reinterpret_cast<Unit_t>(Offsets::FUN_GX_TEXMTX_PUSH)(kWorldStack);
|
||||
Gx::PushTransform(kWorldStack);
|
||||
const uint32_t count = Game::Read<uint32_t>(Offsets::VAR_FACET_BATCH_COUNT);
|
||||
for (uint32_t i = 0; i < count; ++i) {
|
||||
const uint8_t *batch = FacetBatch(i);
|
||||
@@ -1883,7 +1827,7 @@ void DrawBatches(const Backdrop &b, const float (&box)[6], uint32_t argb, uint32
|
||||
continue;
|
||||
Matrix world;
|
||||
Multiply(world, *reinterpret_cast<const Matrix *>(matrix), toEye);
|
||||
reinterpret_cast<Load_t>(Offsets::FUN_GX_TEXMTX_LOAD)(kWorldStack, world);
|
||||
Gx::SetTransform(kWorldStack, world);
|
||||
if (lighting == 1)
|
||||
reinterpret_cast<WriteColored_t>(Offsets::FUN_WRITE_DECAL_VERTICES_COLOURED)(batch);
|
||||
else
|
||||
@@ -1892,8 +1836,8 @@ void DrawBatches(const Backdrop &b, const float (&box)[6], uint32_t argb, uint32
|
||||
const Prim prim{Offsets::GX_PRIM_TRIANGLES, 0, indices, 0, static_cast<uint16_t>(indices - 1), 0};
|
||||
reinterpret_cast<Render_t>(Offsets::FUN_GX_PRIM_RENDER_ONE)(&prim, 1);
|
||||
}
|
||||
reinterpret_cast<Unit_t>(Offsets::FUN_GX_TEXMTX_POP)(kWorldStack);
|
||||
reinterpret_cast<Fn_t>(Offsets::FUN_GX_STATE_POP)();
|
||||
Gx::PopTransform(kWorldStack);
|
||||
Gx::PopStates();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -1912,11 +1856,11 @@ void DrawDecal(const Backdrop &b, const float (&box)[6], uint32_t argb, const fl
|
||||
reinterpret_cast<Build_t>(Offsets::FUN_BUILD_DECAL_TRANSFORMS)(tex0, tex1, box, m, fade, 1);
|
||||
FromEye(tex0, eye);
|
||||
FromEye(tex1, eye);
|
||||
reinterpret_cast<Load_t>(Offsets::FUN_GX_TEXMTX_PUSH_LOAD)(0, tex0);
|
||||
reinterpret_cast<Load_t>(Offsets::FUN_GX_TEXMTX_PUSH_LOAD)(1, tex1);
|
||||
Gx::PushTransform(0, tex0);
|
||||
Gx::PushTransform(1, tex1);
|
||||
DrawBatches(b, box, argb, mask, eye);
|
||||
reinterpret_cast<Unit_t>(Offsets::FUN_GX_TEXMTX_POP)(0);
|
||||
reinterpret_cast<Unit_t>(Offsets::FUN_GX_TEXMTX_POP)(1);
|
||||
Gx::PopTransform(0);
|
||||
Gx::PopTransform(1);
|
||||
}
|
||||
|
||||
void Update(Backdrop &b, void *frame, bool sounds, float elapsed) {
|
||||
@@ -1988,7 +1932,9 @@ void Draw(Backdrop &b, void *frame, const float (&eye)[3]) {
|
||||
if (!(corners[i * 3 + 2] > lowest))
|
||||
lowest = corners[i * 3 + 2];
|
||||
b.probeDrop = eye[2] - lowest;
|
||||
const RenderStateScope states;
|
||||
// The render states a pass of the WMO sets (CommitLighting's fog range)
|
||||
// last until it ends.
|
||||
const Gx::SavedStates states;
|
||||
PushObjectSpace(b, eye);
|
||||
reinterpret_cast<Fn_t>(Offsets::FUN_FRUSTUM_PUSH)();
|
||||
reinterpret_cast<void(__thiscall *)(void *)>(Offsets::FUN_FRUSTUM_STORE)(volume);
|
||||
@@ -2142,7 +2088,7 @@ void DrawLiquids(Backdrop &b, void *frame, const float (&eye)[3]) {
|
||||
return;
|
||||
// Outdoor water takes the light of the backdrop's map at the camera.
|
||||
const MapWaterLight mapLight(b, eye);
|
||||
const RenderStateScope states;
|
||||
const Gx::SavedStates states;
|
||||
reinterpret_cast<Fn_t>(Offsets::FUN_MAPOBJ_BUILD_LIQUID_DEPTH_RAMP)();
|
||||
uint32_t &fogFlag = Game::Ref<uint32_t>(Offsets::VAR_MAPOBJ_GROUP_FOG_FLAG);
|
||||
const uint32_t savedFogFlag = fogFlag;
|
||||
@@ -2308,7 +2254,6 @@ PortalSky WalkFromCamera(const Backdrop &b, const float (&eye)[3]) {
|
||||
using Culled_t = uint32_t(__fastcall *)(const float *box, const float *basis, const float *position);
|
||||
using GetMatrix_t = void(__fastcall *)(float *out);
|
||||
using GetXform_t = void(__fastcall *)(int unit, float *out);
|
||||
using Multiply_t = float *(__fastcall *)(float *out, const float *a, const float *b);
|
||||
using Volume_t = void(__fastcall *)(const float *corners, const float *rect);
|
||||
void *object = b.object;
|
||||
const bool inside = b.cameraGroupCount != 0;
|
||||
@@ -2338,7 +2283,7 @@ PortalSky WalkFromCamera(const Backdrop &b, const float (&eye)[3]) {
|
||||
Matrix device, slot, toClip;
|
||||
reinterpret_cast<GetMatrix_t>(Offsets::FUN_GX_GET_VIEW_PROJECTION)(device);
|
||||
reinterpret_cast<GetXform_t>(Offsets::FUN_GX_XFORM_GET)(kWorldStack, slot);
|
||||
reinterpret_cast<Multiply_t>(Offsets::FUN_MATRIX_MULTIPLY)(toClip, slot, device);
|
||||
Multiply(toClip, slot, device);
|
||||
std::memcpy(reinterpret_cast<void *>(static_cast<uintptr_t>(Offsets::VAR_PORTAL_OBJECT_TO_CLIP)), toClip,
|
||||
sizeof toClip);
|
||||
float camera[3];
|
||||
@@ -2434,28 +2379,24 @@ void DrawSkyPass(const Backdrop &b, const float (&eye)[3], const float (&forward
|
||||
}
|
||||
Game::Ref<float>(state, Offsets::OFF_LIGHT_STATE_HEADING) = Heading(forward);
|
||||
reinterpret_cast<void(__fastcall *)(void *)>(Offsets::FUN_COLOUR_SKY_DOME)(SkyObjects::Dome());
|
||||
const RenderStateScope states;
|
||||
const Gx::SavedStates states;
|
||||
Matrix identity;
|
||||
Identity(identity);
|
||||
reinterpret_cast<Load_t>(Offsets::FUN_GX_TEXMTX_PUSH_LOAD)(kWorldStack, identity);
|
||||
Gx::PushTransform(kWorldStack, identity);
|
||||
reinterpret_cast<Fn_t>(Offsets::FUN_DRAW_SKY)();
|
||||
reinterpret_cast<Unit_t>(Offsets::FUN_GX_TEXMTX_POP)(kWorldStack);
|
||||
Gx::PopTransform(kWorldStack);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void ClearAndDrawSky(const Backdrop &b, void *frame, const float (&eye)[3]) {
|
||||
using GetClear_t = uint32_t *(__fastcall *)(uint32_t *out);
|
||||
using SetClear_t = void(__stdcall *)(uint32_t argb);
|
||||
using Clear_t = void(__fastcall *)(uint32_t mask);
|
||||
const PortalSky walked = WalkFromCamera(b, eye);
|
||||
const bool dry = b.cameraLiquid == Offsets::LIQUID_DRY;
|
||||
const uint32_t colour = !walked.weather ? DrawnFog(b, frame).color : dry ? 0u : ZoneFog(b, frame).color;
|
||||
uint32_t saved = 0;
|
||||
reinterpret_cast<GetClear_t>(Offsets::FUN_GX_GET_CLEAR_COLOR)(&saved);
|
||||
reinterpret_cast<SetClear_t>(Offsets::FUN_GX_SET_CLEAR_COLOR)(colour);
|
||||
reinterpret_cast<Clear_t>(Offsets::FUN_GX_CLEAR)(3);
|
||||
reinterpret_cast<SetClear_t>(Offsets::FUN_GX_SET_CLEAR_COLOR)(saved);
|
||||
const uint32_t saved = Gx::GetClearColor();
|
||||
Gx::SetClearColor(colour);
|
||||
Gx::Clear(3);
|
||||
Gx::SetClearColor(saved);
|
||||
if (walked.weather && dry)
|
||||
DrawSkyPass(b, eye, CameraView(frame).forward, walked.skybox);
|
||||
}
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ bool EngineHasRange(void *caster, int spellID) {
|
||||
float maxRange;
|
||||
EngineMinMax(caster, spellID, nullptr, minRange, maxRange);
|
||||
const float epsilon = Game::Read<float>(
|
||||
static_cast<uintptr_t>(Offsets::VAR_HAS_RANGE_EPSILON));
|
||||
static_cast<uintptr_t>(Offsets::VAR_TWO_POW_MINUS_22));
|
||||
return !(std::fabs(minRange) < epsilon) ||
|
||||
!(std::fabs(maxRange) < epsilon);
|
||||
}
|
||||
|
||||
@@ -252,7 +252,7 @@ bool Begin(Area &area, CVar::Factory::Handle arc, CVar::Factory::Handle range,
|
||||
return false;
|
||||
area.arc = CVar::Factory::GetInt(arc);
|
||||
area.coneHalf = Game::Read<float>(Offsets::VAR_TARGETING_PI) *
|
||||
Game::Read<float>(Offsets::VAR_TARGETING_ONE_SIXTH);
|
||||
Game::Read<float>(Offsets::VAR_ONE_SIXTH);
|
||||
float r = CVar::Factory::GetFloat(range, defaultRange);
|
||||
if (CVar::Factory::Handle tabRange =
|
||||
Game::Read<void *>(Offsets::VAR_CVAR_TARGET_NEAREST_DISTANCE)) {
|
||||
|
||||
@@ -47,10 +47,10 @@ namespace {
|
||||
// 4.3.4's numLines: the line the fit is trying.
|
||||
int g_line = 0;
|
||||
|
||||
constexpr uintptr_t addrEpsilon = Offsets::VAR_TEXT_FIT_HEIGHT_EPSILON;
|
||||
constexpr uintptr_t addrEpsilon = Offsets::VAR_TWO_POW_MINUS_20;
|
||||
static_assert(Offsets::TEXT_FIT_HEIGHT_FRAME_FITTED_BYTES == 8, "LineMarginThunk reads [ebp - 8]");
|
||||
|
||||
// Stands in for `fadd dword ptr [VAR_TEXT_FIT_HEIGHT_EPSILON]`, with the
|
||||
// Stands in for `fadd dword ptr [VAR_TWO_POW_MINUS_20]`, with the
|
||||
// block height in ST0. The bytes fitted so far ([ebp - 8]) are 0 only while
|
||||
// the first line is tried.
|
||||
__declspec(naked) void LineMarginThunk() {
|
||||
|
||||
@@ -690,9 +690,9 @@ float OutlinePadPen(const void *fontFace, float fontPx) {
|
||||
const uint32_t flags = Game::Read<uint32_t>(fontFace, Offsets::OFF_FONTFACE_FLAGS);
|
||||
float ink = 0.0f;
|
||||
if ((flags & 8u) != 0)
|
||||
ink = Game::Read<float>(Offsets::FLOAT_OUTLINE_EXTRA_THICK);
|
||||
ink = Game::Read<float>(Offsets::VAR_FOUR);
|
||||
else if ((flags & 1u) != 0)
|
||||
ink = Game::Read<float>(Offsets::FLOAT_OUTLINE_EXTRA_THIN);
|
||||
ink = Game::Read<float>(Offsets::VAR_TWO);
|
||||
if (ink == 0.0f)
|
||||
return 0.0f;
|
||||
using FontNativeHeight_t = int(__fastcall *)(const void *font);
|
||||
@@ -959,7 +959,7 @@ bool ResolveFsPenFont(void *fs, FsPenFont &out) {
|
||||
// fontHInt/fontHPen bridge inflated fixed-size/ink width terms (the
|
||||
// money-tooltip right-anchor gap).
|
||||
float sizeNorm = out.fontHInt * scale / anchorH;
|
||||
const float minNorm = Game::Read<float>(Offsets::FLOAT_OUTLINE_EXTRA_THIN) /
|
||||
const float minNorm = Game::Read<float>(Offsets::VAR_TWO) /
|
||||
static_cast<float>(rasterY);
|
||||
if (sizeNorm < minNorm)
|
||||
sizeNorm = minNorm;
|
||||
|
||||
@@ -71,6 +71,11 @@ void ReleaseHandle(void *handle) {
|
||||
reinterpret_cast<HandleRelease_t>(Offsets::FUN_HANDLE_RELEASE)(handle);
|
||||
}
|
||||
|
||||
void *DeviceTexture(void *handle) {
|
||||
using Fn = void *(__fastcall *)(void *handle, int load, void *callback);
|
||||
return reinterpret_cast<Fn>(Offsets::FUN_TEXTURE_GET_RENDERABLE)(handle, 1, nullptr);
|
||||
}
|
||||
|
||||
// Same failure test and cleanup as SetTexture: a status level of 2 or more
|
||||
// closes the green fallback and passes the status to the (silent)
|
||||
// system-message printer; the status is destroyed either way.
|
||||
|
||||
@@ -34,6 +34,11 @@ void *LoadByPath(const char *path, uint32_t flags = DefaultFlags());
|
||||
// Drops one reference on a handle (FUN_HANDLE_RELEASE). Null is a no-op.
|
||||
void ReleaseHandle(void *handle);
|
||||
|
||||
// The handle's device texture (FUN_TEXTURE_GET_RENDERABLE), what a render
|
||||
// state binds. The texture is finished loading first, so null means it has
|
||||
// none.
|
||||
void *DeviceTexture(void *handle);
|
||||
|
||||
// A one-mip `width` x `height` texture of ARGB8888 `texels`, through the
|
||||
// engine's own procedural path (FUN_TEXTURE_CREATE_WITH_CALLBACK) with the
|
||||
// texture flags word a loader was handed (TextureMakeFlags is idempotent on
|
||||
|
||||
+11
-19
@@ -58,6 +58,7 @@
|
||||
#include "Offsets.h"
|
||||
#include "frame/AlphaGradient.h"
|
||||
#include "frame/Layout.h"
|
||||
#include "gx/Device.h"
|
||||
#include "texture/Construct.h"
|
||||
#include "texture/Load.h"
|
||||
#include "texture/Mask.h"
|
||||
@@ -104,7 +105,6 @@ std::unordered_map<void *, std::vector<void *>> g_baseMasks;
|
||||
// Regions minted by CreateMaskTexture — a mask-source allow-list.
|
||||
std::unordered_set<void *> g_maskRegions;
|
||||
|
||||
using GetRenderable_t = void *(__fastcall *)(void *hTex, int force, void *);
|
||||
|
||||
using Texture::LoadByPath;
|
||||
using Texture::ReleaseHandle;
|
||||
@@ -158,9 +158,6 @@ namespace {
|
||||
|
||||
// --- stream-primitive co-hook: apply the mask on unit 1 ----------------------
|
||||
|
||||
using GxRsSet_t = void(__fastcall *)(int selector, int value);
|
||||
using GxRsSetPtr_t = void(__fastcall *)(int selector, const void *value);
|
||||
using GxTexMtxOp_t = void(__fastcall *)(int unit);
|
||||
using PrimStreams_t = void(__fastcall *)(int count, const void *pos, int posStride, const void *s3,
|
||||
int s3Stride, const void *colors, int colorStride,
|
||||
int drop8, int drop9, const void *uv0, int uv0Stride,
|
||||
@@ -227,7 +224,6 @@ bool BuildMaskMatrix(const float mr[4], float midY, bool rotated, float angle, f
|
||||
return true;
|
||||
}
|
||||
|
||||
using GxTexMtxPushLoad_t = void(__fastcall *)(int unit, const float *m16);
|
||||
using PrimIndexed_t = void(__fastcall *)(int primType, int indexCount, const void *indices);
|
||||
using Crop_t = void(__fastcall *)(void *region, void *edx, float *rect);
|
||||
|
||||
@@ -248,9 +244,9 @@ void RestoreAfterDraw() {
|
||||
g_pendingRestore = 0;
|
||||
for (int u = 1; u <= 7; ++u)
|
||||
if ((bits & (1u << u)) != 0)
|
||||
reinterpret_cast<GxTexMtxOp_t>(Offsets::FUN_GX_TEXMTX_POP)(u);
|
||||
Gx::PopTransform(u);
|
||||
if ((bits & 1u) != 0)
|
||||
reinterpret_cast<void(__fastcall *)()>(Offsets::FUN_GX_STATE_POP)();
|
||||
Gx::PopStates();
|
||||
}
|
||||
|
||||
void __fastcall PrimIndexed_h(int primType, int indexCount, const void *indices) {
|
||||
@@ -299,8 +295,7 @@ bool MaskedRegionDrawImpl(void *base, void *pathMaskH, void *const *masks, int m
|
||||
// rotation — the exact matrix a mask region covering the base would get.
|
||||
// Per-frame residency reference (force=1), exactly like the minimap's mask.
|
||||
if (pathMaskH != nullptr) {
|
||||
cgx[units] = reinterpret_cast<GetRenderable_t>(Offsets::FUN_TEXTURE_GET_RENDERABLE)(
|
||||
pathMaskH, 1, nullptr);
|
||||
cgx[units] = Texture::DeviceTexture(pathMaskH);
|
||||
if (cgx[units] == nullptr)
|
||||
return false;
|
||||
float angle = 0.0f, cxN = 0.5f, cyN = 0.5f;
|
||||
@@ -318,8 +313,7 @@ bool MaskedRegionDrawImpl(void *base, void *pathMaskH, void *const *masks, int m
|
||||
void *hTex = Game::Read<void *>(masks[i], Offsets::OFF_SIMPLETEXTURE_HTEXTURE);
|
||||
if (hTex == nullptr)
|
||||
return false;
|
||||
cgx[units] = reinterpret_cast<GetRenderable_t>(Offsets::FUN_TEXTURE_GET_RENDERABLE)(
|
||||
hTex, 1, nullptr);
|
||||
cgx[units] = Texture::DeviceTexture(hTex);
|
||||
if (cgx[units] == nullptr)
|
||||
return false;
|
||||
float mr[4];
|
||||
@@ -337,17 +331,15 @@ bool MaskedRegionDrawImpl(void *base, void *pathMaskH, void *const *masks, int m
|
||||
// never pops something that wasn't pushed.
|
||||
if (g_pendingRestore != 0)
|
||||
RestoreAfterDraw(); // stale leftover (shouldn't happen) — clear first
|
||||
auto rs = reinterpret_cast<GxRsSet_t>(Offsets::FUN_GX_RS_SET);
|
||||
auto rsPtr = reinterpret_cast<GxRsSetPtr_t>(Offsets::FUN_GX_RS_SET_PTR);
|
||||
reinterpret_cast<void(__fastcall *)()>(Offsets::FUN_GX_STATE_PUSH)();
|
||||
Gx::PushStates();
|
||||
g_pendingRestore = 1u;
|
||||
for (int i = 0; i < units; ++i) {
|
||||
const int unit = first + i;
|
||||
rsPtr(Offsets::GXRS_TEXTURE0 + unit, cgx[i]);
|
||||
rs(Offsets::GXRS_COMBINER0 + unit, Offsets::GXRS_COMBINE_MODULATE);
|
||||
rs(Offsets::GXRS_TEXGEN0 + unit, Offsets::GXRS_TEXGEN_OBJECT_POS);
|
||||
rs(Offsets::GXRS_TEXXFORM0 + unit, Offsets::GXRS_TEXXFORM_MATRIX);
|
||||
reinterpret_cast<GxTexMtxPushLoad_t>(Offsets::FUN_GX_TEXMTX_PUSH_LOAD)(unit, mtx[i]);
|
||||
Gx::SetState(Offsets::GXRS_TEXTURE0 + unit, cgx[i]);
|
||||
Gx::SetState(Offsets::GXRS_COMBINER0 + unit, Offsets::GXRS_COMBINE_MODULATE);
|
||||
Gx::SetState(Offsets::GXRS_TEXGEN0 + unit, Offsets::GXRS_TEXGEN_OBJECT_POS);
|
||||
Gx::SetState(Offsets::GXRS_TEXXFORM0 + unit, Offsets::GXRS_TEXXFORM_MATRIX);
|
||||
Gx::PushTransform(unit, mtx[i]);
|
||||
g_pendingRestore |= 1u << unit;
|
||||
}
|
||||
g_primStreamsOriginal(count, pos, posStride, s3, s3Stride, colors, colorStride, drop8, drop9,
|
||||
|
||||
@@ -82,7 +82,6 @@ namespace Tooltip::FrameStack {
|
||||
namespace {
|
||||
|
||||
using GetName_t = const char *(__thiscall *)(void *object);
|
||||
using NDCToDDC_t = void(__fastcall *)(float *outX, float *outY, float x, float y);
|
||||
using StrataToString_t = const char *(__fastcall *)(int strata);
|
||||
using PointToString_t = const char *(__fastcall *)(int point);
|
||||
using GetRelative_t = void *(__thiscall *)(void *node);
|
||||
@@ -243,7 +242,7 @@ int __fastcall Script_GameTooltipSetFrameStack(void *L) {
|
||||
const float *mouse = Game::Ptr<float>(ctx, Offsets::OFF_UI_CONTEXT_MOUSE_POSITION);
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
reinterpret_cast<NDCToDDC_t>(Offsets::FUN_COORD_NDC_TO_DDC)(&x, &y, mouse[0], mouse[1]);
|
||||
Frame::Layout::NdcToDdc(&x, &y, mouse[0], mouse[1]);
|
||||
|
||||
void *frame = Game::Read<void *>(ctx, Offsets::OFF_UI_CONTEXT_FRAME_LIST_HEAD);
|
||||
if (frame == nullptr || (reinterpret_cast<uintptr_t>(frame) & 1) != 0)
|
||||
|
||||
@@ -101,6 +101,11 @@ bool FloatAttr(const void *node, const char *name, float &out) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void ReadColor(const void *node, uint32_t &bgra, void *status) {
|
||||
using ReadColor_t = int(__fastcall *)(const void *node, uint32_t *bgra, void *status);
|
||||
reinterpret_cast<ReadColor_t>(Offsets::FUN_XML_READ_COLOR)(node, &bgra, status);
|
||||
}
|
||||
|
||||
void Warn(void *status, const char *fmt, const char *a, const char *b, const char *c) {
|
||||
Report(status, Offsets::XML_STATUS_WARNING, fmt, a, b, c);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// Shared observer for the engine's frame XML loader FUN_XML_FRAME_LOAD
|
||||
// (0x00769820) — `__thiscall(loader, node, status)`, where loader is the
|
||||
// object's layout sub-object (object + OFF_XML_LOADER_SUBOBJECT). Every
|
||||
@@ -42,6 +44,9 @@ const char *Attr(const void *node, const char *name);
|
||||
// A number attribute through the engine's SStrToFloat (the frame loader's
|
||||
// `alpha` conversion); false, `out` untouched, when absent or empty.
|
||||
bool FloatAttr(const void *node, const char *name, float &out);
|
||||
// A colour element's r / g / b / a attributes as BGRA (FUN_XML_READ_COLOR),
|
||||
// the read CSimpleTexture::LoadXML gives <Color>, with the loader's status.
|
||||
void ReadColor(const void *node, uint32_t &bgra, void *status);
|
||||
// The template definition node `inherits=` resolves `name` to
|
||||
// (FUN_XML_TEMPLATE_LOOKUP); nullptr when no template has that name.
|
||||
const void *Template(const char *name);
|
||||
|
||||
Reference in New Issue
Block a user