mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
8ff1549b83c0f383afbf9c99abaea6d149b22708
15
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
8ff1549b83 |
feat(model): ModelScene WMO light eases and lights spell models
An actor's light in the scene's WMO now changes the way a 1.12.1 unit's entity light does. AnimateMapEntityLight (0x0069E770) moves each byte of the ambient toward its target by max(1, trunc(2.0 x dt x 255)) per tick. It moves the intensity, which scales the directional light in ApplyMapLighting (0x006A7300), by 3.3333 x dt. The bake (BakeMapEntityGroupLight 0x0069E4C0) writes the ambient target, not the ambient. The target intensity is 1.0 indoors and 2.5 (0x00810A68) on an exterior group. A new node starts at 1.0 with the day ambient (0x00670DB0). Outside, with no channel moving, the ambient follows the day's. World::Settle now takes the frame's elapsed time and eases each tick, and places the node again only when the model moved. A missile in flight gets its own entity light node, as the world gives one (CreateLightObjectB 0x00671010 from 0x0061E655, placed by AttachEntityToGround). Impact models left behind get one too. Each model releases its callback back to the frame's before the light goes. LightChildren now copies the parent model's own lighting callback pair (+0x3BC / +0x3C0), so a nocked arrow and a stuck missile are lit like the actor that holds them, not with the frame's flat light. |
||
|
|
be93a6f969 |
feat(model): show a unit on a ModelScene actor
ModelSceneActor:SetModelByUnit copies the unit's model the way 1.12.1's character panes do in AttachUnitModel (0x005059A0): the unit's own character component is pumped forced (UpdateCharacterComponent 0x00477860), its model (+0xD8) is copied into the scene's M2 scene with CreateModelFromModel (0x00707400, which carries the helm, shoulders and held items), the effect and spell attachments come off (DetachAllItemModels 0x0047A230), and the hand grips close (CloseHand 0x00479660). What DressUpModel's SetModelInstance (0x00504350) adds comes next: a clone of the unit's component (CloneCharacterComponent 0x00476CB0, on a pool component with the model AddRef'd) and the two held-item lanes from unit vtable +0x98. The actor pumps the clone on every update, as the DressUpModel paint (0x00504470) pumps its own, so outfit changes show at once; OnModelLoaded waits for its first composite. On top: retail's Dress, Undress(includeWeapons), UndressSlot, SetSheathed / GetSheathed, SetAutoDress / GetAutoDress, IsGeoReady and GetModelUnitGUID. Undress mirrors ClearModel (0x00504490); sheathing is the unit's AttachHandItem step (AttachItemModel 0x0047A0C0 with the sheathed flag). The lane, weapon and undress steps move out of Model::DressUp into Model::Outfit, which the DressUpModel pane and the actor share. One change on the pane: UndressSlot on a held slot no longer needs the component. PumpDresser takes the engine's force argument, which the old typedef called an unused pointer. |
||
|
|
be21ff50f6 |
feat(model): add the ModelScene frame type and C_ModelInfo
ModelScene is a 3D stage of model actors with its own camera. 1.12.1's Model frame is already one: every Model frame owns an M2 scene and a clock, and its paint (SimpleModelDraw 0x0076D240) animates and draws the whole scene, each unattached model with its own placement matrix. The stock frame only ever places one model. So a ModelScene is a CSimpleModel: the Model factory's allocation plus our fields, CSimpleModel's constructor (0x0076C8E0), then copies of its two vtables with the Model half hidden from Lua. Lookup goes to our method hash and then CSimpleFrame's, the type answers ModelScene, Frame and Region but not Model, and Model's script names and XML loader give way to the Frame ones. The layer emit queues our paint on ARTWORK. The paint repeats SimpleModelDraw call for call: save the device transforms, project through the frame's camera over its rect, clamp the viewport, clear depth, place each actor where slot 0x98 would place the one model, animate the scene from the camera eye, draw passes 0 and 1, and restore. The camera is a CCamera made and installed the way the PlayerModel pane makes its fallback camera (CameraCreate 0x007AC930, SimpleModelInstallCamera 0x0076CE80). Eye and target come from the position and forward axis. The yaw and roll properties are solved so that the view's up vector equals the requested one. The default light is set the way PlayerModel's constructor sets its own. An actor is a script object holding one model in the frame's scene. It is lit through the frame's light callback, placed with CM2Model::SetBaseTransformTRS (0x00710650), and polled for load and dressing from the frame's update, never from the paint. A display with an Extra record is dressed through the engine compositor. The bounding boxes come from GetSequenceInfo (0x00711A20) and GetBoundingBox (0x00713640). C_ModelInfo's getters read the rows of scenes 4, 44 and 596, embedded from the retail 12.1.7 exports. The four active-scene functions do nothing, as retail's own documentation says, and live in Compat.lua. The same calls on Turtle and on retail draw the same picture (scene 4's camera on the Brown Horse, centred on Z, scaled by retail's normalization). Frame::Subclass now holds the vtable copy and the per-class method hash, which Cooldown uses too. Model::DisplayInfo::CreateDisplayModel builds a display's model for both portraits and actors. |
||
|
|
b49c107778 |
refactor(lua): take frame-method tables as arrays, not pointer and count
Every RegisterFrameMethods call passed its method table and doc table with a count beside each: sizeof(t) / sizeof(t[0]), std::size, or a literal. The literals had to be kept in step with the tables by hand. Game::ArrayRef<T> is a view over a file-scope array that takes the count from the array's type, the way Doc::FieldList already did for a function's arguments and returns. FieldList is now ArrayRef<Field>, Doc::MethodList is ArrayRef<Method>, and RegisterFrameMethods takes (context, methods, docs). The table and count still go to the engine's frame-method iterator (FUN_REGISTER_FRAME_METHODS) unchanged, and to the documentation recorder. All 84 call sites pass only the arrays. The 16 literal counts were checked against their tables first: each was the full length, so every registry gets the same methods as before. |
||
|
|
53b7f79440 |
fix(model): release dress builders and stopped effects with their frame
/reload crashed with an access violation in the model release (0x007103A3, inside FUN_MODEL_INSTANCE_RELEASE 0x007103A0) when SetDisplayInfo had dressed a few panes. 1.12.1 reloads in two steps. CGGameUI::Shutdown (0x00490BD0) deletes the CSimpleTop, which destroys every frame. A Model frame's teardown, DestroyModelFrame (0x0076CA50, from the CSimpleModel and CGCharacterModelBase destructors), releases the frame's M2 scene at +0x314, and the scene frees every model in it, even one that something else still holds a reference on. Only then does CGGameUI::Initialize (0x0048FBF0) reset the Lua state, which runs FrameScript_Initialize and our reload cleanups. DisplayInfo's cleanup destroyed each kept compositor there (FUN_CHARCOMP_DESTROY 0x00476000), and the compositor released its reference to a model that was already freed. VisualKit's cleanup detached and released stopped one-shot effects that live in the same freed scene. Model::Teardown hooks DestroyModelFrame and runs its subscribers before the original, while the frame's scene and models are intact, which is where the engine frees what its own frames hold. DisplayInfo drops the frame's dress job there, and VisualKit records each stopped effect's pane (in the done callback's user data) and discards that pane's effects there. Their reload cleanups keep only the pointer-keyed state. The ReloadAutoRegister doc now says that the cleanups run after the frames are gone, so they may forget pointers but never release an engine object tied to a frame. |
||
|
|
7b21453469 |
refactor(model): share the engine model calls across the model modules
The model modules each declared their own pointers to the same 1.12.1 engine functions: the instance gates FUN_MODEL_INSTANCE_LOADED (0x007103D0) and FUN_MODEL_INSTANCE_READY, AddRef / Release (0x00710390 / 0x007103A0), FUN_M2SCENE_CREATE_MODEL, FUN_M2MODEL_PLAY_ANIMATION, the done callback, the item visuals, the render callback, the M2 data lookup FUN_M2_LOOKUP_INDEX (0x00710310), and the pane's model, scene, SetModelInstance virtual (vtable +0x90) and SetDisplay. model/M2.h now holds one typed wrapper for each, and every module calls through it. - Game::Lua::ResolvePlayerModel / ResolveDressUpModel join the per-type resolvers, replacing four ResolvePane copies and five inline ResolveTypedObject calls. Game::Lua::TYPE_NONE replaces the local kTypeNone in Rotation and frame/CreateFrame. - Offsets.h has the full INVTYPE list, 0..28, named by the engine's own key table at 0x0083DDB0. It replaces the four scattered INVTYPE_* entries and the local copies in DressUp and ItemDisplay, and the try-on result switch reads by name. - DisplayInfo keeps its dress jobs in a map by frame, like the other modules, in place of the fixed 8-slot pool and its eviction. - DressUp names the held lane's bytes (item class, inventory type, sheathe type) and detaches a lane in one place. - ItemDisplay::OwnVisual is the one test for a display's own ItemVisuals row (GetItemDescVisual 0x0062EC70), used by SetItem and by TryOn's enchant glow. Both own-record panes share Pane::DisplayRecord, and the SetDisplayInfo records are cleared on /reload as the SetItem records are. |
||
|
|
8f4f574174 |
feat(model): add PlayerModel:SetItem
PlayerModel:SetItem(itemID [, appearanceModID, itemVisualID]) shows one item's own model in the pane: a weapon, shield, helm, shoulder, quiver or ammo, with its skin texture and its glow. A 1.12.1 pane shows whatever its display record names (+0x3F0). SetDisplay (0x00505CB0) stores the record and builds it when the pane is visible, the show path (0x00505D49) builds it again, and the SetUnit helper (0x00505B50) clears it. SetItem gives the pane a record of its own and passes it to SetDisplay. The AttachDisplayModel (0x00505A70) co-hook in Model::DisplayInfo then builds the item instead of a creature. So hide, show, SetUnit, SetDisplayInfo and SetKeepModelOnHide handle an item with no new hooks. The model is built from 1.12.1's own steps: - the item folder by inventory type, from the engine's own Item\ObjectComponents\ path strings (0x00838CD8 on); - model name 0, else name 1, with the texture of the same index; - for a head item, the helm builder's (0x004799A0) path, with the player's race prefix (ChrRaces +0x18) and sex letter (0x00838AB4); - AttachItemModelFile's (0x004798C0) steps: create the model in the pane's scene, load the skin with the item-model status (0x00B424F0) and filter 3, bind it as texture type 2 (0x00710EC0), and attach the item visuals (0x00479700); - AttachDisplayModel's install: SetModelInstance (vtable +0x90), the pane's done callback (0x005062A0 through 0x00711BB0), Stand, and the release of the creation reference. The display's own ItemVisuals row wins over itemVisualID, the rule GetItemDescVisual (0x0062EC70) applies to enchants. The visual's child models get the frame's light and fog callback, now a shared LightChildren helper, so they are not drawn black. An uncached item is queued through Item::Data::WarmCache, and each visible pane that still shows it is built again when the item loads. |
||
|
|
0caddb8fe6 |
feat(model): add PlayerModel animation, keep-on-hide and unit methods
Adds SetAnimation, SetDoBlend/GetDoBlend, HasAnimation, SetKeepModelOnHide/GetKeepModelOnHide, CanSetUnit and GetDisplayInfo to PlayerModel (and so to DressUpModel and TabardModel). SetUnit now returns whether the unit exists, and SetCreature takes an optional display ID. Animation. A 1.12.1 pane rests on Stand: its per-paint UpdateModel (0x00505C50) arms Stand (PlayAnimation 0x007121A0 with id 0) whenever key bone -1 plays anything else and no turn is pending. A deadline of 0 counts as passed, so any other animation lasted one frame. SetAnimation gives the pane a resting animation and variation of its own. With one set, UpdateModel is hooked to arm that animation in Stand's place, using the pane's blend setting. Every other pane runs the stock function. The pane's done callback (0x005062A0) arms Stand when the animation ends, so the next paint starts it again and it loops. CSimpleModelFFX's SetModelInstance (0x0076CD30), which every pane model build and hide goes through, clears it, so a new model rests on Stand again. SetRotation turns without the shuffle while a resting animation other than Stand is set. HasAnimation is PlayAnimation's own test on the raw id: the lookup at shared data +0x24 must give an index below the sequence count at +0x1C. It is false until the model has loaded. Keep on hide. The pane's Hide (0x00505CE0) drops its model through slot 36, and its Show (0x00505D00) builds a new one from the unit or display record. With keep on, Hide runs only the base hide (0x0076AD50) and Show runs only the base show (0x0076AE10) while the pane still holds its model. The model then comes back with its try-ons and animation. The SetUnit helper (0x00505B50, behind SetUnit, RefreshUnit and Dress) and SetDisplay (0x00505CB0) only store the new subject while the pane is hidden, so they drop a kept model first. The next Show then builds the new one. Off is the default and matches the stock client. Units and displays. SetUnit runs the engine's method (0x00505D70, which Turtle patches) unchanged. It then reports whether the GUID it stored resolves to a unit (type mask 8), the same test the helper uses before it builds. CanSetUnit is that resolve without the set. GetDisplayInfo reads the display record's ID, or the unit's UNIT_FIELD_DISPLAYID (+0x1F4, field 0x7D). SetCreature with a display ID shows that display through the SetDisplayInfo record. |
||
|
|
6f3a8ffc1d |
feat(texture): add static creature portraits by display ID (#123)
* feat(texture): add static creature portraits by display ID * docs(api): document static creature portrait functions * Update API.md * refactor(model): bake display-ID portraits on the engine's own path SetPortraitTextureFromCreatureDisplayID now replays 1.12.1's unit portrait bake, BakePortrait (0x00524F60), call for call on a display model of its own, instead of driving a hidden PlayerModel through Lua. The display model is built the way AttachDisplayModel (0x00505A70) builds one, without a frame: M2CreateScene (0x00706E10), then CreateModelFromPath (0x00707350) on the CreatureModelData path, then ApplyCreatureDisplay (0x004797B0). A character display is dressed through the engine compositor with the same code that dresses PlayerModel:SetDisplayInfo, now shared as Model::DisplayInfo:: CreateDresser / PumpDresser / DestroyDresser. The bake's own gate, IsReady(model, 0, 1) (0x00710450), only passes for a model that something has drawn: a BLP texture gets its device texture only when GetTextureDeviceObject (0x0044ACF0) is asked with wait set. The shared M2 still loads on its own, so the gate here is IsLoaded(model, 0, 1) (0x007103D0) plus the dress, and the bake's IsReady(copy, 1, 1) makes the device textures, as it does for the copy of a unit's model. The bake itself is the engine's sequence: copy into a fresh scene, DetachAllItemModels, camera 0, PlayAnimation, save projection, view, viewport and fog (GxMasterEnable 0x0058A210 / 0x0058A1E0), the 64x64 DDC box in the bake's own float order, CameraSetDeviceTransforms, clear colour 0, ClearDevice(3), PortraitLighting, both scene passes, read back through 0x00589CF0, clear, cut the alpha mask in (0x005258A0), restore. It runs at the head of the UI render callback, the same point as an OnUpdate script that calls SetPortraitTexture, behind the bake's device gate (0x0058A260 window active, 0x0058A280 device alive). Each display ID owns one callback texture (TextureCreateWithCallback, which makes its device texture at creation). It is bound with SetImage (0x00770300) at call time and filled in place with GxTexMarkRectDirty (0x0058ACD0), the bake's own path for re-baking a cached portrait. A region the caller re-points before the bake finishes keeps what it was given, so no region is tracked: the request map, the region-destruction subscription and ClassicAPI_CancelPortraitTextureRequest are gone. The function returns nothing, as retail's does. Portraits are kept until logout, the lifetime of the engine's display-ID portrait cache (cleared in ShutdownGame). A display with no portrait camera is done once and stays transparent. Offsets.h: the portrait block is renamed to engine names with calling conventions and sources; the duplicates of FUN_M2SCENE_ANIMATE, FUN_M2MODEL_SET_ANIMATED and GetCameraById are removed, as are the made-up draw-flag and scene-count fields and the raw device-vtable slots. Model::Camera::CameraById is exposed instead of being copied. --------- Co-authored-by: z1xel <ramirezthiago@71gmail.com> Co-authored-by: Brues <5278969+brues-code@users.noreply.github.com> |
||
|
|
bbd78b437f |
feat(model): backport 4.3.4's PlayerModel and DressUpModel methods
SetDisplayInfo and SetCreature move from Model to PlayerModel, where 4.3.4 registers them, and now ride vanilla's own pane path: SetDisplay (0x505CB0) stores the record and AttachDisplayModel (0x505A70) builds the model with the engine's skins (ApplyCreatureDisplay), Stand, the pane camera and light, and rebuilds it on every show. A co-hook on AttachDisplayModel adds 4.3.4's SetUpModel step: a display with an Extra record is dressed through the character compositor. SetCreature passes the creature-cache record itself; SetDisplayInfo passes a per-pane record holding the display ID, the only field the pane reads. The hand-built ApplySkins is removed. SetPortraitZoom, SetCamDistanceScale and RefreshCamera apply 4.3.4's ConfigureCamera steps after vanilla's (0x505890); the defaults leave the camera untouched. The portrait camera id is bounds-checked, since GetCameraById indexes unchecked. DressUpModel gains UndressSlot (one step of vanilla's Undress) and a TryOn that takes item links, recipe links and carried item names in front of vanilla's worker. PlayerModel:SetRotation takes 4.3.4's animate flag, and Model:SetGlow exists as the no-op it is on a 4.3.4 Model. |
||
|
|
61db68dd7f |
fix(lua): gate frame-method self with the engine's own type check
Every engine frame method validates its `self` in three steps before
touching it: lua_type == table, resolve to the CFrameScriptObject, then
the IsA(typeId) vmethod at vtable+0x10. We did the first two and skipped
the third, so ResolveObject handed back a pointer for ANY frame and the
method cast it to whatever type it expected.
That was reachable from plain Lua, not just through a mirror or a hook.
The per-type method dispatcher is an __index handler that rawgeti's the
method closure out of the Lua registry, so frame methods are ordinary
first-class values, and
GameTooltip.SetSpellByID(ShapeshiftButton1, 133)
reached the tooltip builder with a Button, writing tooltip fields through
Button memory. The engine refuses that same call with "Wrong object type
for member function".
Game::Lua::ResolveTypedObject runs the engine's prologue and raises the
engine's own three error strings, read from .data rather than reinvented.
FrameScriptTypeId mirrors the lazy id assignment, so a check is valid
before any stock method of the type has run. Seven per-type wrappers stop
a call site pairing a method with the wrong class's id, and
ResolveTypedObjectAny covers a method that more than one type reaches.
45 call sites across 19 files now gate self. model/DisplayInfo.cpp had
already worked this out for Model alone and loses its private copy.
Type ids are per CLASS, one shared by all of that class's methods. Each
was read from the prologue of a method that can only belong to its class:
a base-class method registered into several tables carries the BASE id, so
sampling GetObjectType or GetDrawLayer would have produced a gate that
accepts unrelated types. Frame comes from Script_RegisterEvent and Texture
from Script_SetDesaturated, both cross-checked against the first entry of
their table.
Deliberately left ungated: the binding `owner` in bindings/Api.cpp and the
three co-hook sites in texture/Atlas.cpp. Each only uses the pointer as an
identity key and never casts it, so a gate would tighten the contract for
no safety gain -- and raising inside a co-hook would fire before the
original ran.
Verified in-game: the Button-as-tooltip call now raises the engine's
error; a Button still reaches a Frame-registry method
(button:SetAttribute round-trips), so IsA does accept derived types; and
fontstring:GetRotation() still answers -- that reader is registered on
both the Texture and FontString registries and needs the id pair rather
than the Texture id alone.
|
||
|
|
0c8468cf2f |
refactor(reload): auto-register per-/reload cleanup; fix Time::Timer stale refs
Modules that keep reload-fragile file-static state (Lua registry refs, frame/object-pointer-keyed maps, cached event-slot indices) each expose a PrepareForReload() that DllMain called from the FrameScript_Initialize hook. That list was hand-maintained, so a new module could silently forget to wire itself in -- the failure mode behind the Frame::Attributes stale-ref bug and Tooltip::SetEvents issue #33. Add Game::ReloadAutoRegister + Game::RunReloadCleanups(), mirroring the existing ModuleAutoRegister / HookAutoRegister / WorldTick::AutoSubscribe patterns. Each module self-registers with one file-scope line after its PrepareForReload: static const Game::ReloadAutoRegister _reloadReg{&PrepareForReload}; DllMain's 11-call manual list collapses to a single RunReloadCleanups(); a new module can no longer be forgotten. Player::NameCache::Flush stays an explicit call -- it's a save-before-teardown, not a stale-state clear, and also runs on the glue-return path. A sweep of all file-static state found one uncovered module: Time::Timer pins C_Timer.After/NewTimer/NewTicker callbacks in the Lua registry but never released them on /reload -- a surviving/stale ref could fire a dead closure. Add Time::Timer::PrepareForReload (release each pending timer's registry callback, clear the queue) and self-register it. - Game.{h,cpp}: ReloadAutoRegister + RunReloadCleanups. - DllMain.cpp: collapse the manual list to RunReloadCleanups(); drop 6 now-dead includes. - 11 existing reload modules + Time::Timer: add the self-register line. Behavior-preserving (same cleanups, before the Lua teardown); auto-register order is unspecified across TUs but every callback only clears its own state. |
||
|
|
c54556f6a1 |
refactor: centralize engine field/global access via Game::Read/Ref/Ptr
Replace the raw `*reinterpret_cast<const T *>(base + Offsets::OFF_X)` idiom (and its double-cast variant when base wasn't already a byte pointer) with three typed accessors in Game.h: Game::Read<T>(base, offset) field value read Game::Ref<T>(base, offset) writable field lvalue Game::Ptr<T>(base, offset) pointer to a field (arrays / out-params) Game::Read<T>(address) / Ref<T>(address) fixed-VA globals Pure mechanical refactor, zero behavior change: ~330 cast sites across 84 files collapse to 651 helper calls. Offsets stay in Offsets.h per the single-source-of-truth rule — the helpers only remove the cast noise and fold away the inner `reinterpret_cast<uint8_t*>(obj)` base casts. Left as raw casts by design: FUN_* function-pointer casts, void*/char* VA handles passed as arguments (caches, method registries), subobject- anchor pointers fed to __thiscall helpers, `void *volatile` player-ptr readiness gates (converting would strip volatile), and VA-as-array-base captures that are subscripted later. |
||
|
|
67172c95f7 |
feat(model): add Model:SetCreature; dress character displays natively
SetCreature(creatureID) resolves through the client creature cache to a display ID, then loads like SetDisplayInfo (uncached entry = no-op, documented with a RequestLoadCreatureByID recipe). Character-based displays (extendedDisplayInfoID != 0) are now dressed by the engine's own CharComponent compositor, mirroring CGUnit_C::UpdateCharacterCustomization's NPC branch field for field: baked body texture, hair/facial-hair geosets (CharHairGeosets, CharacterFacialHairStyles), equipment geosets (sleeves, robe->trousers, tabard), and helm/shoulder attachment models with HelmetGeosetVisData hiding. Dress jobs run on WorldTick behind the engine's own model-loaded gate, one compositor per Model frame, kept until the frame loads another display or the reload teardown (PrepareForReload). Attached helm/shoulder children additionally get the frame's light/fog pre-render callback: the frame only registers it on its own instance, so the children rendered pure black (verified in-game -- a light tint colored the body but not the equipment). Weapons cannot show: NPC weapons are server-pushed per spawned unit, not in any client table. The manual baked-skin/hair-texture appliers are superseded by the compositor and removed, along with the geoset debug probes (_classicapi_ModelInstance/Peek/Poke). Creature::Info gains a public DisplayID(creatureID) for the cache resolve. |
||
|
|
54782df95e |
feat(model): add Model:SetDisplayInfo(creatureDisplayID)
Backport the retail Model widget method (present since 5.4.8, string verified in the 5.4.8 and 1.15.8 binaries) that points a Model frame at a creature by its display ID rather than a raw .mdx path. Resolve creatureDisplayID -> CreatureDisplayInfo[+0x04] ModelID -> CreatureModelData[+0x08] ModelPath, load it through SetModel's own worker (vtable+0x94), then apply the display's TextureVariation columns as replaceable-texture skins (MONSTER_1/2/3 = slots 11/12/13). The DBC column offsets are verified two ways: parsing the extracted 1.12 DBCs and the engine's own unit-display resolver FUN_0060afb0. Verified in-game: displays 13/330 (human NPCs) load correctly textured and lit; missing assets fall back to the engine's error cube. Only the single-model form is implemented; the optional mountDisplayID (rider-on-mount) second arg is a separate follow-up. |