ApplyTypes: FamiliarAI routines typed __fastcall(Entity_Familiar *familiar) like NpcAI (ECX reads all fit)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-25 16:08:58 -04:00
1 parent cbb2f465ec
commit 5dbb3e398d
1 file changed
+10 -7
+10 -7
View File
@@ -118,18 +118,21 @@ public class ApplyTypes extends GhidraScript {
f.setCallingConvention("__thiscall"); f.setCallingConvention("__thiscall");
fitted++; fitted++;
} }
// NpcAI routines are __fastcall(npc in ECX) // per-type AI routines take the entity in ECX: NpcAI (dispatcher) and FamiliarAI (Entity_Familiar::Update cases,
DataType npcPtr = new PointerDataType(dtm.getDataType(new CategoryPath("/"), "Entity_NPC")); // their ECX reads all land in Entity_Familiar fields); FamiliarAI ones with stack arguments are left alone
Namespace ai = st.getNamespace("NpcAI", global);
int ain = 0; 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()); Function f = getFunctionAt(sym.getAddress());
if (f == null) continue; if (f == null || (ai[0].equals("FamiliarAI") && f.getStackPurgeSize() != 0)) continue;
f.setCallingConvention("__fastcall"); f.setCallingConvention("__fastcall");
f.replaceParameters(Function.FunctionUpdateType.DYNAMIC_STORAGE_FORMAL_PARAMS, true, SourceType.USER_DEFINED, f.replaceParameters(Function.FunctionUpdateType.DYNAMIC_STORAGE_FORMAL_PARAMS, true, SourceType.USER_DEFINED,
new ParameterImpl("npc", npcPtr, currentProgram)); new ParameterImpl(ai[2], npcPtr, currentProgram));
ain++; 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");
} }
} }