From 5dbb3e398d2d69fea0e27433d69581caada12330 Mon Sep 17 00:00:00 2001 From: shweet Date: Sun, 25 Oct 2026 16:08:58 -0400 Subject: [PATCH] ApplyTypes: FamiliarAI routines typed __fastcall(Entity_Familiar *familiar) like NpcAI (ECX reads all fit) Co-Authored-By: Claude Opus 5.5 --- scripts/ApplyTypes.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/scripts/ApplyTypes.java b/scripts/ApplyTypes.java index 017022b..a0d68bc 100644 --- a/scripts/ApplyTypes.java +++ b/scripts/ApplyTypes.java @@ -118,18 +118,21 @@ public class ApplyTypes extends GhidraScript { f.setCallingConvention("__thiscall"); fitted++; } - // NpcAI routines are __fastcall(npc in ECX) - DataType npcPtr = new PointerDataType(dtm.getDataType(new CategoryPath("/"), "Entity_NPC")); - Namespace ai = st.getNamespace("NpcAI", global); + // per-type AI routines take the entity in ECX: NpcAI (dispatcher) and FamiliarAI (Entity_Familiar::Update cases, + // their ECX reads all land in Entity_Familiar fields); FamiliarAI ones with stack arguments are left alone int ain = 0; - if (ai != null) for (Symbol sym : st.getSymbols(ai)) { + for (String[] ai : new String[][] {{"NpcAI", "Entity_NPC", "npc"}, {"FamiliarAI", "Entity_Familiar", "familiar"}}) { + DataType npcPtr = new PointerDataType(dtm.getDataType(new CategoryPath("/"), ai[1])); + Namespace aiNs = st.getNamespace(ai[0], global); + if (aiNs != null) for (Symbol sym : st.getSymbols(aiNs)) { Function f = getFunctionAt(sym.getAddress()); - if (f == null) continue; + if (f == null || (ai[0].equals("FamiliarAI") && f.getStackPurgeSize() != 0)) continue; f.setCallingConvention("__fastcall"); f.replaceParameters(Function.FunctionUpdateType.DYNAMIC_STORAGE_FORMAL_PARAMS, true, SourceType.USER_DEFINED, - new ParameterImpl("npc", npcPtr, currentProgram)); + new ParameterImpl(ai[2], npcPtr, currentProgram)); ain++; } - println("ApplyTypes: " + classes.size() + " structs, " + typed + " thiscall methods, " + fitted + " fitted by ECX use, " + ain + " NpcAI params"); + } + println("ApplyTypes: " + classes.size() + " structs, " + typed + " thiscall methods, " + fitted + " fitted by ECX use, " + ain + " NpcAI/FamiliarAI params"); } }