Port the model outline hook system (CM2SceneRenderDraw, ManageRenderListNode, DrawBatchProjected) from the C++ idris DLL to pure Zig. Includes D3D9 vtable hooks for stencil-based outline rendering with per-category colors and thickness. Fix GetObjectByGUID calling convention: was using fastcall (ECX/EDX) but Ghidra confirms it's __stdcall with stack params and RET 8. Fix lua_pushcclosure address from 0x6F3B80 (mid-body of another function) to 0x6F3920. Guard resolveModelOwner in DrawBatchProj with hasTargets() check and cache unit model status during ManageRenderListNode to avoid raw pointer chasing at render time. Add IsBadReadPtr validation in resolveModelOwner to match C++ IsValidReadPtr pattern for page-level memory safety.
3.9 KiB
3.9 KiB
Task: Pure Zig Unit Outline Reimplementation for weirdutils
Mission
Reimplement the WoW unit outlining system in pure Zig inside zig/weirdutils, with cleanly separated source files and no runtime dependency on the Idris C/C++ outline implementation.
Explicit Tooling Permission
You are explicitly authorized to use Code Executor MCP freely, including controlling Ghidra for reverse engineering support (function signatures, prologues, calling conventions, offsets, call sites).
Use this freedom proactively to verify:
- Function prologues and patch-safe lengths
- rel32 fixup needs for call/jmp in overwritten prologues
- Calling convention correctness (__thiscall/__fastcall/__stdcall)
- Data structure offsets relevant to model tracking/render hooks
Repos / Paths
- Target implementation:
/media/storage/projects/zig/weirdutils - Reference implementation:
/media/storage/projects/idris/dlls - Existing Zig hook library reference:
/media/storage/projects/zig/hook
Hard Constraints
- Pure Zig runtime path for outlines (C/C++ outline files from Idris are reference-only).
- Keep existing weirdutils features working (screenshot/interact/addon load).
- Split code into focused modules; avoid giant monolith file growth.
- Maintain x86 WoW 1.12.1 calling-convention correctness.
- Preserve hook-chain safety (do not break existing detours).
Desired Source Layout (implement this or a clearly better equivalent)
Create these Zig modules under src/outline/:
offsets.zig– constants for addresses/offsetstypes.zig– enums/structs (object types, vectors, draw categories)wow.zig– game memory access wrapperstracker.zig– per-frame model/category tracking statemodel_hook.zig– WoW render pipeline hooks for model classificationd3d9_hook.zig– D3D9 DIP/EndScene hook logic for outline renderingshader.zig– optional shader helpers/constants (if used)api.zig– public init/reset/config functions exposed to main
Also update:
src/main.zig(initialize/cleanup outline subsystem)build.zig(if needed for new modules)src/addon/WeirdUtils.lua(outline command UX/status)
Behavior Requirements
Implement category-based outlines:
- Dead friendly players/corpses: through-wall style visibility
- Raid-marked units: clear colored outlines
- Current target (enemy NPC): emphasized outline
Implement robust per-frame reset + repopulation logic to avoid stale tracking.
Implementation Phases
Phase 1 – Mapping + verification
- Use Ghidra + references to verify prologues and hook patch sizes.
- Produce a concise mapping note in
docs/outline-port-notes.md.
Phase 2 – Core Zig architecture
- Create modular outline subsystem under
src/outline/. - Port tracking/state logic and category assignment.
Phase 3 – Hook integration
- Implement render hooks with safe trampoline usage using existing Zig hook patterns.
- Integrate into weirdutils startup/shutdown flow.
Phase 4 – User controls + defaults
- Add
/wu outlinecommand family:/wu outline on/wu outline off/wu outline status
Phase 5 – Validation
- Ensure weirdutils still builds for x86 windows msvc.
- Smoke-check no regressions in interact/screenshot command registration paths.
- Add a brief test checklist in
docs/outline-validation.md.
Deliverables
- Pure Zig outline subsystem in separated files.
- Updated integration in main/addon.
docs/outline-port-notes.mdwith verified hook/prologue decisions.docs/outline-validation.mdwith run/test checklist.- Final summary with changed files and known limitations.
Guardrails
- Do not run destructive git operations.
- Do not remove existing features.
- If a prologue/callconv is uncertain, verify in Ghidra before patching.
Completion Signal
When fully done, run:
openclaw system event --text "Done: pure Zig outline port implemented in weirdutils" --mode now
Then print a short completion summary.