From e4f369dddfd700da320ec50f57021424460d80de Mon Sep 17 00:00:00 2001 From: bdot89 <50345309+bdot89@users.noreply.github.com> Date: Sun, 11 Oct 2026 14:12:04 +0100 Subject: [PATCH] DMorph 2.6.0: race morphs keep your own race rules, size shows and is shared - DmorphHelper v3 hooks the game's model builder: during a race morph your model is built as the morph's race, but the game keeps your own race the rest of the time, so you understand your own languages (no garbled chat), and see your own flight paths and spells. - Size now changes the model you see, not only the camera: the game draws the model at its own copy of the size, which DmorphHelper now sets too (found in WoW.exe at 0x614640). - Sizes are shared with other DMorph users (a size token in the look and a small size message); older versions ignore it. - The Setup check asks players with DmorphHelper v2 to run the installer. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 1 + DmorphOcto.lua | 61 ++++++++++++++++++++++-- DmorphOcto.toc | 2 +- README.md | 6 +-- Share.lua | 94 ++++++++++++++++++++++++++++++++---- helper/DmorphHelper.c | 103 +++++++++++++++++++++++++++++++++++++--- helper/DmorphHelper.dll | Bin 32256 -> 33280 bytes tests/run_tests.lua | 85 +++++++++++++++++++++++++++++---- 8 files changed, 320 insertions(+), 32 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index f83a009..3b584eb 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -109,3 +109,4 @@ The live copy is the game's `Interface\AddOns\DmorphOcto` folder, a git checkout - 2.4.0, user report: Ashes of Al'ar mount "gone" (it was display 18179, Creature\Phoenix\Phoenix.mdx, named "Phoenix Hatchling" by Turtle, not mount-tagged). build_models.ps1 now has $MOUNT_MODEL (later-expansion rideable models by path: phoenix, winged/celestial horses, Northrend drakes, victorious steed, armoured raptor, lava/fel horses, Antonidas horse, nether rays, taxi wyverns/hippogryphs, ghost gryphon, riding turtle: 66 displays) and $MOUNT_NAMES (Phoenix -> "Ashes of Al'ar (Phoenix)"). Race morphs: VanillaHelpers rewrites BYTES_0 race, so TaxiNodeGetType hides the other faction's nodes and the spellbook re-sorts. M.HoldRace(reason) clears the display override (native race) while TaxiFrame (TAXIMAP_OPENED, redrawn via TaxiFrame_OnEvent) or SpellBookFrame (OnShow/OnHide wrapped at PLAYER_LOGIN) is open, pauses the DmorphHelper look watcher and shows the real look; ApplyBody waits while held. Untested in game: whether TaxiNodeGetType/spellbook re-read the race live. Scale slider asked: no installed DLL can set OBJECT_FIELD_SCALE_X; needs DmorphHelper_SetScale (C) and a rebuild (no compiler on this PC). - 2.5.0 size: DmorphHelper v2 (HELPER_VERSION 2 in C and Lua) adds DmorphHelper_GetScale/SetScale(unit, 0.1-10) writing OBJECT_FIELD_SCALE_X (field 4, a float) + the display flip. Built on this PC with winlibs gcc 16.2 i686 msvcrt, unzipped to C:\Users\bdot1\tools\winlibs\mingw32 (downloaded with the user's OK): `PATH=/c/Users/bdot1/tools/winlibs/mingw32/bin:$PATH sh helper/build.sh` from Git Bash. Core: db.scale/scaleReal/scaleWritten, WatchScale inside WatchHelper, M.SetScale/GetScale, .scale, Reset everything clears it. UI: DmorphOctoSize slider (0.25-3, step 0.05, applied 0.3 s after it stops, right-click resets) on the name plate. Not shared with other DMorph users yet. Untested in game: whether the client draws a changed OBJECT_FIELD_SCALE_X on your own model after the flip, and how mounts and the camera react. - 2.5.1, user report: "Gnome still can't speak that language, Goblin speaks Orcish". GetLanguageByIndex/GetDefaultLanguage follow the race VanillaHelpers writes (a Gnome morph lists Common, Gnomish), so 2.2.1's check passed Common. CaptureNative (run by EnsureSession right after clearing the display override, i.e. with the native race) now stores db.languages/db.defaultLanguage and SpeakableLanguage uses those. Goblin -> Orcish is correct for a Horde character. Also: flight-path birds got the mount skin (taxi = mount field > 0, no new buff -> the "any buff" fallback), and after landing the override held the bird ("can't cast spells"). WatchMount now skips UnitOnTaxi, uses the any-buff fallback only without an on-foot snapshot (login/reload mounted), and PLAYER_CONTROL_LOST/GAINED take the skin off (re-applied next tick if still riding). +- 2.6.0, user reports: (1) race morph still "speaks Orcish" = the client garbles chat (own and faction's) by the race in UNIT_FIELD_BYTES_0 (0x24, low byte), which VanillaHelpers sets to the morph race. DmorphHelper v3 hooks CGUnit_C::UpdateDisplayInfo (0x60ABE0, thiscall(unit), prologue push esi/push edi/mov esi,ecx/call rel32): for the active player, while DmorphHelper_SetRaces(build, own) is on, it writes the build race before the original and the own race after, so the model is built as the morph race but the byte holds your own race (languages, taxi nodes, spellbook). Lua KeepRace (core) switches it on for race morphs of another race, rechecks every 0.1 s (VanillaHelpers rewrites the override on server writes) and DmorphHelper_Rebuild on UNIT_INVENTORY_CHANGED(player); HoldRace is skipped while raceKept ~= 0. (2) Size moved only the camera: the camera reads OBJECT_FIELD_SCALE_X but the model is drawn at unit+0x90, which the per-frame code at 0x614a90 only eases towards the field (start time unit+0xA0, from +0xA4, 2 s) when the server changes it; 0x614640 is the game's instant path (+0x90 = field, +0xA0 = 0). SetScale now writes the field, +0x90 and clears +0xA0. Found by disassembling WoW.exe.original with winlibs objdump (8 places read field 4). Sizes are shared: "s" token after the guid in L and H messages (none = 100; old clients ignore it), "S " when only the size changes; receivers put it on with DmorphHelper_SetScale and restore the size they read first. All of this is untested in game. diff --git a/DmorphOcto.lua b/DmorphOcto.lua index 3e6b4b9..b610aa9 100644 --- a/DmorphOcto.lua +++ b/DmorphOcto.lua @@ -11,7 +11,7 @@ -- The client runs Lua 5.0: no #, no %, no string.match, no select(), and -- table.getn() counts element by element, so long lists keep their own count. -local VERSION = "2.5.1" +local VERSION = "2.6.0" local PREFIX = "|cff33ff99DMorph|r: " -- VANILLAHELPERS_VERSION is major * 10000 + minor * 100 + patch; morphing -- came in v1.1.0. Older versions load and set it, but can't morph. @@ -1265,18 +1265,54 @@ local function DisplayRace(display) end end +-- With DmorphHelper v3 your own race stays in the game's race byte during a +-- race morph, and the morph's race is only used while the game builds your +-- model (DmorphHelper_SetRaces). Then languages, flight paths and spells all +-- follow your own race, and nothing needs holding. raceKept: the race your +-- model is built as (0: off); raceKeepWorks: whether DmorphHelper took it. +local raceKept, raceKeepWorks = 0, false + +local function KeepRace() + if type(DmorphHelper_SetRaces) ~= "function" then + return + end + local morph = DisplayRace(BodyDisplayID() or 0) + local want = 0 + if sessionReady and morph and nativeRace and morph ~= nativeRace and not next(raceHeld) then + want = morph + end + if want ~= raceKept then + local own = want ~= 0 and nativeRace or 0 + raceKeepWorks = pcall(DmorphHelper_SetRaces, want, own) and true or false + raceKept = raceKeepWorks and want or 0 + elseif want ~= 0 and type(DmorphHelper_GetRace) == "function" then + -- VanillaHelpers puts the morph's race back when the server resends + -- the field: your own race goes back in. + local ok, race = pcall(DmorphHelper_GetRace, "player") + if ok and race ~= nativeRace then + pcall(DmorphHelper_SetRaces, want, nativeRace) + end + end +end + local function ApplyBody() helperHold, helperWait = 0.5, 0.5 if next(raceHeld) then return true -- it goes on when the flight map or spellbook closes end - return Morph(SetUnitDisplayID, "player", BodyDisplayID()) + KeepRace() -- first, so the new model is built as the morph's race + local ok, err = Morph(SetUnitDisplayID, "player", BodyDisplayID()) + KeepRace() + return ok, err end -- Holds (on) or releases your own race for a reason. Returns whether the -- race was changed back just now, so the window can redraw. function M.HoldRace(reason, on) if on then + if raceKept ~= 0 then + return false -- DmorphHelper already keeps your own race (KeepRace) + end local held = next(raceHeld) ~= nil if held then raceHeld[reason] = true @@ -1504,7 +1540,7 @@ local MISSING_HELPER = "DmorphHelper.dll isn't loaded, so weapon glows, your siz M.MISSING_HELPER = MISSING_HELPER -- The DmorphHelper_Version() the DLL in helper\ reports. An older one in the -- game folder (DMorph was updated, the DLL wasn't copied again) is flagged. -local HELPER_VERSION = 2 +local HELPER_VERSION = 3 -- Rows 1-5 of the Races tab, in DmorphHelper_GetLook's order. local OWN_LOOK_NPC = { "npcSkin", "npcFace", "npcHairStyle", "npcHairColour" } @@ -2820,14 +2856,33 @@ mountFrame:SetScript("OnUpdate", function() if this.wait <= 0 then this.wait = 0.1 WatchMount() + KeepRace() + end + -- Gear the server changed is drawn by the game without a full rebuild, + -- so a helmet would follow your own race: rebuild as the morph's race. + if this.rebuild then + this.rebuild = this.rebuild - arg1 + if this.rebuild <= 0 then + this.rebuild = nil + if raceKept ~= 0 then + pcall(DmorphHelper_Rebuild, "player") + end + end end end) +mountFrame:RegisterEvent("UNIT_INVENTORY_CHANGED") -- Losing and getting back control (a flight path starts and lands, a fear, -- a stun) takes the skin off: if you're still on your mount, the watcher -- sees its buff and puts the skin on again a tenth of a second later. mountFrame:RegisterEvent("PLAYER_CONTROL_LOST") mountFrame:RegisterEvent("PLAYER_CONTROL_GAINED") mountFrame:SetScript("OnEvent", function() + if event == "UNIT_INVENTORY_CHANGED" then + if arg1 == "player" and raceKept ~= 0 then + this.rebuild = 0.3 + end + return + end if watch.active then StopSkin() watch.real = nil diff --git a/DmorphOcto.toc b/DmorphOcto.toc index 0103aa2..3f21ae8 100644 --- a/DmorphOcto.toc +++ b/DmorphOcto.toc @@ -2,7 +2,7 @@ ## Title: DMorph |cff33ff99(OctoWoW)|r ## Notes: Morph window for OctoWoW: every creature model in the client (16,000+, with 3D previews, bosses and mounts), every race with NPC looks, 12,000+ items and 352 item sets. Skins for your mount, favourites, and DMorph users see each other's morphs. Weapon glows and real skin, face and hair with the bundled DmorphHelper.dll. Type /dmorph. Needs VanillaHelpers v1.1.0+ (OctoLauncher's vanillaHelpers mod); previews need ClassicAPI. ## Author: bdot89 -## Version: 2.5.1 +## Version: 2.6.0 ## X-Website: https://github.com/bdot89/DmorphOcto ## SavedVariables: DmorphOctoAccount ## SavedVariablesPerCharacter: DmorphOctoDB diff --git a/README.md b/README.md index e541931..32177f5 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ **Become any creature, ride any mount, wear any item** · WoW 1.12 · OctoWoW -![Version](https://img.shields.io/badge/version-2.5.1-33ff99?style=flat-square) +![Version](https://img.shields.io/badge/version-2.6.0-33ff99?style=flat-square) ![WoW 1.12.1](https://img.shields.io/badge/WoW-1.12.1-c79c6e?style=flat-square) ![Models](https://img.shields.io/badge/models-16%2C000%2B-b46bff?style=flat-square) ![Items](https://img.shields.io/badge/items-12%2C000%2B-a335ee?style=flat-square) @@ -175,10 +175,10 @@ Slots: `1` head, `3` shoulder, `4` shirt, `5` chest, `6` waist, `7` legs, `8` fe ## 💡 Good to know -- **Who sees what:** you and other DMorph users see your model, items and mount skin (friendly players only). Glows, looks and size are only on your own screen for now. +- **Who sees what:** you and other DMorph users see your model, items, mount skin and size (friendly players only; seeing someone's size needs DmorphHelper). Glows and picked faces are only on your own screen for now. - **Seeing other DMorph users:** their morph shows when you target or mouse over them, when you're grouped, or straight away with SuperWoW. DMorph only talks to players near you, through hidden messages that no chat window shows. - **Mount skins** go on when you mount and come off when you dismount. Flight master birds keep their own look. -- **Race morphs:** while the flight map or spellbook is open, your own race comes back for a moment, so you see all your flight paths and your spells stay in order. Your chat is always sent in a language your character knows. +- **Race morphs keep your own character's rules:** with DmorphHelper, the game still knows you as your own race, so you understand your own languages (no garbled chat), speak them, and see all your flight paths and spells as usual; only the model is the other race. Without DmorphHelper, your own race comes back for a moment while the flight map or spellbook is open, and chat is sent in a language you know, but other players' chat may look garbled. - **Fast clicking is safe:** a click right after another waits its turn, so two looks never mix. - **Shapeshifting** shows your morph instead of the form; reset your model first if you want the form. - **Later expansions aren't in this game:** models, glows and races from The Burning Crusade onwards (Draenei, Mongoose glow, Outland mounts...) aren't in the 1.12 files, so no addon can show them. Everything OctoWoW and Turtle WoW added is included. diff --git a/Share.lua b/Share.lua index 54656c8..af3450e 100644 --- a/Share.lua +++ b/Share.lua @@ -68,7 +68,7 @@ local audience = {} -- name -> when they last showed they see us local inGroup, inGuild = {}, {} -- names local replies = {} -- way -> "L" (full look) or "H" (fingerprint) local timers = {} -- clock times: join, ready, send, first, mount, reply, replied, query, scan, guild, next -local sent = { d = "0", m = "0", it = "-" } -- what the others were last told +local sent = { d = "0", m = "0", it = "-", s = "" } -- what the others were last told local cache -- DmorphOctoAccount.peerCache for this realm local guidWorks -- whether VanillaHelpers took a GUID as a unit token (nil: not tried) local counts = { channel = 0, hidden = 0 } @@ -481,8 +481,20 @@ local function ApplyTo(name, token) done.mount = mount end end + -- Their size, through DmorphHelper (which every DMorph user may not have): + -- their own size is read first, to put back when they go back to it. + local scale = want.scale + if (scale ~= done.scale or (force and scale)) and type(DmorphHelper_SetScale) == "function" then + if scale and not done.scale then + local ok, real = pcall(DmorphHelper_GetScale, token) + done.scaleReal = ok and type(real) == "number" and real or 1 + end + if Call(DmorphHelper_SetScale, token, scale or done.scaleReal or 1) then + done.scale = scale + end + end done.version, done.scan, done.away = want.version, scanID, nil - if want == NONE and not done.display and not done.mount and not next(done.items) then + if want == NONE and not done.display and not done.mount and not next(done.items) and not done.scale then applied[name] = nil else applied[name] = done @@ -520,6 +532,7 @@ local function SetPeer(name, look, guid, confirmed) peerCount = peerCount + 1 end look.guid = guid or (peer and peer.guid) + look.scale = peer and peer.scale -- a full look message sets it again after look.version = (peer and peer.version or 0) + 1 look.heard = confirmed and clock or -1000 look.confirmed = confirmed @@ -654,12 +667,32 @@ end -- Messages from other clients --------------------------------------------------- +-- A player's size from a message's "s" token (none: normal size). +-- Clients before 2.6 send no token and ignore it. +local function SizeOf(token) + local _, _, pct = strfind(token or "", "^s(%d+)$") + pct = tonumber(pct) + if pct and pct >= 10 and pct <= 1000 and pct ~= 100 then + return pct / 100 + end +end + +local function SetPeerSize(name, scale) + local peer = peers[name] + if peer and peer.scale ~= scale then + peer.scale = scale + peer.version = peer.version + 1 + Scan() + end +end + local function ReadLook(sender, rest) - local _, _, d, m, it, guid = strfind(rest, "^(%S+) (%S+) (%S+) ?(%S*)") + local _, _, d, m, it, guid, size = strfind(rest, "^(%S+) (%S+) (%S+) ?(%S*) ?(%S*)") local look = MakeLook(d, m, it) if not look then return end + local scale = SizeOf(size) if not strfind(guid or "", "^0x%x+$") then guid = nil end @@ -673,9 +706,11 @@ local function ReadLook(sender, rest) peer.confirmed = true Cache()[sender] = { look = peer.look, guid = peer.guid, seen = time() } end + SetPeerSize(sender, scale) return end if SetPeer(sender, look, guid, true) then + look.scale = scale Scan() end end @@ -694,13 +729,14 @@ local function ReadMount(sender, m) end -- "Nothing changed": confirms what we remember, else we ask for it all. -local function ReadPrint(sender, print, guid) +local function ReadPrint(sender, print, guid, size) Unask(sender) Answered(sender) asked[sender] = clock local peer = peers[sender] if peer and peer.print == print then peer.heard = clock + SetPeerSize(sender, SizeOf(size)) if strfind(guid or "", "^0x%x+$") then peer.guid = guid end @@ -753,9 +789,15 @@ local function Receive(sender, text, way) elseif kind == "M" then ReadMount(sender, rest) elseif kind == "H" then - local _, _, print, guid = strfind(rest, "^(%S+) ?(%S*)") + local _, _, print, guid, size = strfind(rest, "^(%S+) ?(%S*) ?(%S*)") if print then - ReadPrint(sender, print, guid) + ReadPrint(sender, print, guid, size) + end + elseif kind == "S" then + -- Only the size changed. + local peer = peers[sender] + if peer and peer.confirmed then + SetPeerSize(sender, SizeOf("s" .. rest)) end elseif kind == "Q" then ReadQuestion(sender, rest, way) @@ -764,6 +806,16 @@ end -- Your own changes ------------------------------------------------------------ +-- Your size as a message token: "s150", or "" at normal size. +local function OwnSize() + local scale = Sharing() and M.GetScale and M.GetScale() + local pct = scale and math.floor(scale * 100 + 0.5) or 100 + if pct == 100 then + return "" + end + return "s" .. pct +end + local function OnChange() local d, m, it = OwnParts() -- Mounting and dismounting go out at once; other changes wait until @@ -771,6 +823,9 @@ local function OnChange() if m ~= sent.m then timers.mount = timers.mount or clock end + if OwnSize() ~= sent.s then + timers.size = timers.size or clock + SETTLE + end if d ~= sent.d or it ~= sent.it then timers.first = timers.first or clock timers.send = math.min(clock + SETTLE, timers.first + MAX_WAIT) @@ -779,14 +834,23 @@ local function OnChange() end end +local function WithSize(text) + local size = OwnSize() + if size ~= "" then + return text .. " " .. size + end + return text +end + local function LookText() - return "L " .. OwnLook() .. " " .. (GUIDOf("player") or "-") + return WithSize("L " .. OwnLook() .. " " .. (GUIDOf("player") or "-")) end -- Tells everyone who needs it; that answers any waiting question too. local function SendLook(ways) sent.d, sent.m, sent.it = OwnParts() - timers.send, timers.first, timers.mount = nil, nil, nil + sent.s = OwnSize() + timers.send, timers.first, timers.mount, timers.size = nil, nil, nil, nil local text = LookText() for way in pairs(ways) do Send(text, way) @@ -813,6 +877,15 @@ local function SendNext() end elseif timers.send and clock >= timers.send then SendLook(ChangeWays()) + elseif timers.size and clock >= timers.size then + timers.size = nil + local size = OwnSize() + if size ~= sent.s then + sent.s = size + for way in pairs(ChangeWays()) do + Send("S " .. (size == "" and "100" or strsub(size, 2)), way) + end + end elseif timers.reply and clock >= timers.reply then timers.reply, timers.replied = nil, clock local look = OwnLook() @@ -821,7 +894,7 @@ local function SendNext() if kind == "L" then Send(LookText(), way) else - Send("H " .. Fingerprint(look) .. " " .. (GUIDOf("player") or "-"), way) + Send(WithSize("H " .. Fingerprint(look) .. " " .. (GUIDOf("player") or "-")), way) end end elseif table.getn(queue) > 0 and clock >= (timers.query or 0) then @@ -873,7 +946,8 @@ local function Tick() -- What we look like now is what everyone will learn by asking. timers.introduced = true sent.d, sent.m, sent.it = OwnParts() - timers.send, timers.first, timers.mount = nil, nil, nil + sent.s = OwnSize() + timers.send, timers.first, timers.mount, timers.size = nil, nil, nil, nil timers.group = clock end if timers.group and clock >= timers.group and not (timers.next and clock < timers.next) then diff --git a/helper/DmorphHelper.c b/helper/DmorphHelper.c index 889bf91..c3c8ce0 100644 --- a/helper/DmorphHelper.c +++ b/helper/DmorphHelper.c @@ -6,6 +6,11 @@ // - a player's skin colour, face, hair style, hair colour and facial hair // (PLAYER_BYTES and PLAYER_BYTES_2) // - a player's size (OBJECT_FIELD_SCALE_X, a float: what Enlarge spells change) +// - a player's race byte (UNIT_FIELD_BYTES_0): a race morph needs the morph's +// race while the model is built, but the game also reads it to know which +// languages you understand, which flight paths and spells you have; so +// the addon builds the model as the morph's race and keeps your own +// race there the rest of the time // // Lua functions (registered when the game loads its own): // DmorphHelper_Version() -> version @@ -15,6 +20,9 @@ // DmorphHelper_SetLook(unit, skin, face, hairStyle, hairColour, facialHair) // DmorphHelper_GetScale(unit) -> scale (1 = normal size) // DmorphHelper_SetScale(unit, scale) (0.1 to 10) +// DmorphHelper_GetRace(unit) -> race +// DmorphHelper_SetRaces(buildRace, ownRace) (0, 0 = off; see Race morphs) +// DmorphHelper_Rebuild(unit) // unit is a unit token for a player you could help ("player", "target", ...); // slot is an inventory slot, 1-19. The functions only write the values: the // addon keeps what it wants and puts it back after the server resends them. @@ -35,7 +43,7 @@ #define GAME_FASTCALL __attribute__((fastcall)) #define GAME_THISCALL __attribute__((thiscall)) -#define HELPER_VERSION 2 +#define HELPER_VERSION 3 // Game functions, build 5875 (from VanillaHelpers' Offsets.h). #define FUN_INVALID_FUNCTION_PTR_CHECK 0x42A320 @@ -56,6 +64,13 @@ // Descriptor fields, as indexes into a unit's uint32 field array. #define OBJECT_FIELD_SCALE_X 0x4 // a float +#define UNIT_FIELD_BYTES_0 0x24 // race, class, gender, power type (one byte each) + +// In the unit object itself (build 5875, from 0x614640 and the per-frame +// size animation at 0x614a90): the size the model is drawn at, and when a +// size animation started (0 = none; it eases from +0xA4 to the field over 2 s). +#define UNIT_SHOWN_SCALE 0x90 +#define UNIT_SCALE_ANIM_START 0xA0 #define UNIT_FIELD_DISPLAYID 0x83 #define PLAYER_BYTES 0xC1 #define PLAYER_BYTES_2 0xC2 @@ -230,13 +245,80 @@ static int GAME_FASTCALL Script_SetScale(void *L) { LuaError(L, SET_SCALE_USAGE); return 0; } - float scale = (float)v, current; + float scale = (float)v; uint32_t *f = Fields(unit); - memcpy(¤t, f + OBJECT_FIELD_SCALE_X, sizeof current); - if (current != scale) { - memcpy(f + OBJECT_FIELD_SCALE_X, &scale, sizeof scale); - Reload(unit); + memcpy(f + OBJECT_FIELD_SCALE_X, &scale, sizeof scale); + // The field is what the camera reads; the model is drawn at the unit's + // own copy, which the game only animates towards the field when the + // server changes it. So set that copy too, and stop any such animation, + // as the game's own "size at once" code at 0x614640 does. + memcpy((char *)unit + UNIT_SHOWN_SCALE, &scale, sizeof scale); + *(uint32_t *)((char *)unit + UNIT_SCALE_ANIM_START) = 0; + return 0; +} + +// Race morphs. VanillaHelpers writes the morph's race into your race byte, +// because the game builds a character model from it (skin, hair, helmets). +// But the game also reads that byte to know which languages you understand +// (it garbles your own and your faction's chat otherwise), which flight paths +// and spells you have. So, once the addon says so (DmorphHelper_SetRaces), +// your own race stays in the byte and the morph's race is only put in while +// the game builds your model (the UpdateDisplayInfo hook below). +static uint32_t g_buildRace = 0, g_ownRace = 0; +static UpdateDisplayInfo_t UpdateDisplayInfo_o = NULL; + +static void *Me(void) { + uint64_t guid = GetActivePlayer(); + return guid ? ObjectPtr(TYPEMASK_PLAYER, NULL, guid, 0) : NULL; +} + +static void WriteRace(void *unit, uint32_t race) { + uint32_t *f = Fields(unit); + f[UNIT_FIELD_BYTES_0] = (f[UNIT_FIELD_BYTES_0] & 0xFFFFFF00u) | race; +} + +static void GAME_FASTCALL UpdateDisplayInfo_h(void *unit, void *edx) { + (void)edx; + if (g_buildRace && g_ownRace && unit && unit == Me()) { + WriteRace(unit, g_buildRace); + UpdateDisplayInfo_o(unit); + WriteRace(unit, g_ownRace); + return; } + UpdateDisplayInfo_o(unit); +} + +static const char *RACE_USAGE = "Usage: DmorphHelper_GetRace(unit)"; +static const char *SET_RACES_USAGE = "Usage: DmorphHelper_SetRaces(buildRace 0-20, ownRace 0-20)"; +static const char *REBUILD_USAGE = "Usage: DmorphHelper_Rebuild(unit)"; + +static int GAME_FASTCALL Script_GetRace(void *L) { + void *unit = PlayerArg(L, 1, RACE_USAGE); + LuaPushNumber(L, Fields(unit)[UNIT_FIELD_BYTES_0] & 0xFF); + return 1; +} + +// DmorphHelper_SetRaces(buildRace, ownRace): build your model as buildRace +// and keep ownRace in your race byte (written at once). 0, 0 turns it off. +static int GAME_FASTCALL Script_SetRaces(void *L) { + uint32_t build = NumberArg(L, 1, 0, 20, SET_RACES_USAGE); + uint32_t own = NumberArg(L, 2, 0, 20, SET_RACES_USAGE); + if (!UpdateDisplayInfo_o) { + LuaError(L, "DmorphHelper couldn't hook the model builder."); + return 0; + } + g_buildRace = build && own ? build : 0; + g_ownRace = build && own ? own : 0; + void *me = Me(); + if (me && g_ownRace) { + WriteRace(me, g_ownRace); + } + return 0; +} + +// Rebuilds a model (for a change the game made without rebuilding it). +static int GAME_FASTCALL Script_Rebuild(void *L) { + Reload(PlayerArg(L, 1, REBUILD_USAGE)); return 0; } @@ -249,6 +331,9 @@ static void GAME_FASTCALL LoadScriptFunctions_h(void) { RegisterFunction("DmorphHelper_SetLook", (uintptr_t)&Script_SetLook); RegisterFunction("DmorphHelper_GetScale", (uintptr_t)&Script_GetScale); RegisterFunction("DmorphHelper_SetScale", (uintptr_t)&Script_SetScale); + RegisterFunction("DmorphHelper_GetRace", (uintptr_t)&Script_GetRace); + RegisterFunction("DmorphHelper_SetRaces", (uintptr_t)&Script_SetRaces); + RegisterFunction("DmorphHelper_Rebuild", (uintptr_t)&Script_Rebuild); } // The game's own image must reach every address used here (a 1.12.1 exe). @@ -281,6 +366,12 @@ static void InstallHook(void) { (LPVOID *)&LoadScriptFunctions_o) == MH_OK) { MH_EnableHook((LPVOID)FUN_LOAD_SCRIPT_FUNCTIONS); } + // Without it the race functions say so; everything else still works. + if (MH_CreateHook((LPVOID)FUN_CGUNIT_C_UPDATE_DISPLAY_INFO, (LPVOID)&UpdateDisplayInfo_h, + (LPVOID *)&UpdateDisplayInfo_o) != MH_OK || + MH_EnableHook((LPVOID)FUN_CGUNIT_C_UPDATE_DISPLAY_INFO) != MH_OK) { + UpdateDisplayInfo_o = NULL; + } } static BOOL Ready(void) { diff --git a/helper/DmorphHelper.dll b/helper/DmorphHelper.dll index b1aa5c83e1af04a2172afcb1e148f95a1340624a..f34c91e66a27db088ba43030216351919eb3102d 100755 GIT binary patch delta 8238 zcmc&(3sh5Ax;{B35+Q^r0TBVC28u75gd`Bi3nYjYEmc5AsiFoS6%`SDv}%|MsA)=z z?$)uETJSN`htt~PI7po~2o=Om>r`IOpX*O${8l&z~oSoq?utlz#5lORy%Cal`J zm6FcTTit=l;l#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}~9$CftU_1C&RUIjXs;#j1B<`^T!&s`IM< zR3)i3YO6X&Jxg7nE>TyiUFx0c2K5c~Ep>n^b_+LgK=bte5L{qW=|$<@gRxTD-BTod;>cbU7!earn9(sYL#Hqs+Hh^OR-uj8CTf*ht=6VZ*Jf&Sv<2EkL#`pufak{H F{{gdF8U_FW diff --git a/tests/run_tests.lua b/tests/run_tests.lua index 290712f..429e5fe 100644 --- a/tests/run_tests.lua +++ b/tests/run_tests.lua @@ -1483,6 +1483,41 @@ quiet() say(".item head 0") wait(3) check(channelSays("DMO2 L 3HR 0 eA"), "once they come into range, your changes reach them") + +-- Sizes are shared too (put on with DmorphHelper). +local sized = {} +function DmorphHelper_SetScale(unit, scale) + local u = Mock.Unit(unit) + if not u then + error("Unit not found.") + end + sized[u.guid] = scale +end +function DmorphHelper_GetScale(unit) + return 1 +end +hear("Ally", "L 3HR 0 - " .. ally .. " s150") +check(sized[ally] == 1.5 and morphOf(ally).display == 4527, "a DMorph user's size shows on them") +hear("Ally", "S 50") +check(sized[ally] == 0.5, "a size message changes only the size") +hear("Ally", "S 100") +check(sized[ally] == 1, "and their own size goes back when they reset it") +hear("Ally", "L 3HR 0 - " .. ally) +check(sized[ally] == 1, "a look without a size (or from DMorph before 2.6) means normal size") +quiet() +DmorphOctoDB.scale = 2 +say(".item head 0") -- any change tells the sharing code +wait(3) +check(channelSays("DMO2 S 200"), "your size goes out to DMorph users around you") +quiet() +hear("Someone", "Q Tester") +wait(4) +check(channelSays(" s200"), "and with your look when someone asks") +DmorphOctoDB.scale = nil +say(".item head 0") +wait(3) +hear("Ally", "L 3HR 3HR - " .. ally) -- Ally's look as the tests below remember it +DmorphHelper_SetScale, DmorphHelper_GetScale = nil, nil Mock.units.target = nil -- Looks are remembered: after a /reload a known player shows at once, and is @@ -1749,12 +1784,30 @@ local OPTIONS = { local game local function installHelper(look) game = { look = look, real = look, enchants = { [16] = { 803, 0 }, [17] = { 0, 0 }, [18] = { 0, 0 } }, lookWrites = 0, - scale = 1 } + scale = 1, race = 1, build = 0, own = 0, rebuilds = 0 } local function whole(v, max) return type(v) == "number" and v >= 0 and v <= max and v == math.floor(v) end function DmorphHelper_Version() - return 2 + return 3 + end + -- The race byte: VanillaHelpers writes the morph's race there (tests set + -- game.race), DmorphHelper_SetRaces keeps your own one in it. + function DmorphHelper_GetRace(unit) + return game.race + end + function DmorphHelper_SetRaces(build, own) + if not (whole(build, 20) and whole(own, 20)) then + error("Usage: DmorphHelper_SetRaces(buildRace 0-20, ownRace 0-20)") + end + local on = build ~= 0 and own ~= 0 + game.build, game.own = on and build or 0, on and own or 0 + if on then + game.race = own + end + end + function DmorphHelper_Rebuild(unit) + game.rebuilds = game.rebuilds + 1 end function DmorphHelper_GetScale(unit) return game.scale @@ -1797,6 +1850,7 @@ local function removeHelper() DmorphHelper_Version, DmorphHelper_GetItemEnchants, DmorphHelper_SetItemEnchants = nil, nil, nil DmorphHelper_GetLook, DmorphHelper_SetLook = nil, nil DmorphHelper_GetScale, DmorphHelper_SetScale = nil, nil + DmorphHelper_GetRace, DmorphHelper_SetRaces, DmorphHelper_Rebuild = nil, nil, nil end local function sameLook(a, b) @@ -1859,13 +1913,13 @@ DmorphOctoDB, DmorphOctoAccount = nil, nil loadWithHelper() Mock.Tick(1.1) slash("dmorph status") -check(contains(allChat(), "DmorphHelper v2 is loaded"), "status shows the helper's version") +check(contains(allChat(), "DmorphHelper v3 is loaded"), "status shows the helper's version") slash("dmorph check") check(contains(allChat(), "DmorphHelper: |cff33ff99OK"), "the check says the helper runs") local currentVersion = DmorphHelper_Version -DmorphHelper_Version = function() return 1 end +DmorphHelper_Version = function() return 2 end slash("dmorph check") -check(contains(allChat(), "An older DmorphHelper (v1)") and contains(allChat(), "Install DmorphHelper.bat"), +check(contains(allChat(), "An older DmorphHelper (v2)") and contains(allChat(), "Install DmorphHelper.bat"), "an older DLL in the game folder is flagged, with how to update it") DmorphHelper_Version = currentVersion @@ -1993,14 +2047,27 @@ check(sameLook(game.look, orc), "and gets it back") SpellBookFrame = CreateFrame("Frame", "SpellBookFrame") SpellBookFrame:Hide() Mock.Fire("PLAYER_LOGIN") +-- DmorphHelper v3 keeps your own race in the game's race byte during a race +-- morph (the model is built as the Orc): languages, flight paths and spells +-- follow your own race, so nothing has to be held. +check(game.build == 2 and game.own == 1 and game.race == 1, + "an Orc race morph is built as an Orc while your own race (Human) stays in the race byte") +game.race = 2 -- VanillaHelpers writes the morph's race again +Mock.Tick(0.2) +check(game.race == 1, "your own race goes straight back in") SpellBookFrame:Show() Mock.Tick(1.1) -check(vh.display == 49 and sameLook(game.look, REAL), - "while the spellbook holds your own race, your real look shows (not the Orc one)") +check(vh.display == 51 and sameLook(game.look, orc), "the spellbook no longer needs your own model shown") SpellBookFrame:Hide() -Mock.Tick(1.1) -check(vh.display == 51 and sameLook(game.look, orc), "and the Orc morph and look come back when it closes") SpellBookFrame = nil +local rebuilds = game.rebuilds +Mock.Fire("UNIT_INVENTORY_CHANGED", "player") +Mock.Tick(0.2) +Mock.Tick(0.2) +check(game.rebuilds == rebuilds + 1, "gear the server changes is rebuilt as the morph's race") +Mock.Fire("UNIT_INVENTORY_CHANGED", "target") +Mock.Tick(0.5) +check(game.rebuilds == rebuilds + 1, "but not someone else's") press(DmorphOctoCreatorRandom) check(wearable(game.look, "2:0") and vh.display == 51, "the dice picks a look the race can wear, on your model") -- From an NPC look: the rows take you back to your own model with its face.