Typed this for ~780 more methods whose ECX reads fit their class's confirmed fields; Sprite/Color = ANM2/ColorMod

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:01 -04:00
1 parent 76ef4d7834
commit cbb2f465ec
5 files changed
+62 -6

No files matched your search

+20 -2
View File
@@ -1,6 +1,6 @@
// Builds structs from zhl_fields.tsv (class, offset|base, type name), turns those namespaces into classes so
// `this` gets typed, merges Lua-named namespaces (EntityPlayer -> Entity_Player), types NpcAI::* param 1 as Entity_NPC*.
// Arg: zhl_fields.tsv
// Args: merged fields.tsv [this_types.tsv: methods whose ECX use fits their class]
import ghidra.app.script.GhidraScript;
import ghidra.program.model.data.*;
import ghidra.program.model.listing.*;
@@ -100,6 +100,24 @@ public class ApplyTypes extends GhidraScript {
typed++;
}
}
// Lua aliases: the Lua Sprite and Color classes are ANM2 and ColorMod, so their methods' `this` gets that layout
for (String[] al : new String[][] {{"Sprite", "ANM2"}, {"Color", "ColorMod"}}) {
DataType t = dtm.getDataType(new CategoryPath("/"), al[1]);
if (!(t instanceof Structure)) continue;
Structure copy = (Structure) t.copy(dtm);
copy.setName(al[0]);
dtm.addDataType(copy, DataTypeConflictHandler.REPLACE_HANDLER);
}
// methods whose ECX offsets fit their class (scripts/this_types.py) become __thiscall, typing `this`
int fitted = 0;
if (getScriptArgs().length > 1) for (String l : Files.readAllLines(Paths.get(getScriptArgs()[1]))) {
Function f = getFunctionAt(toAddr(l.split("\t")[0]));
if (f == null || "__thiscall".equals(f.getCallingConventionName())) continue;
Namespace ns = f.getParentNamespace();
if (!(ns instanceof GhidraClass)) try { st.convertNamespaceToClass(ns); } catch (Exception e) { continue; }
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);
@@ -112,6 +130,6 @@ public class ApplyTypes extends GhidraScript {
new ParameterImpl("npc", npcPtr, currentProgram));
ain++;
}
println("ApplyTypes: " + classes.size() + " structs, " + typed + " thiscall methods, " + ain + " NpcAI params");
println("ApplyTypes: " + classes.size() + " structs, " + typed + " thiscall methods, " + fitted + " fitted by ECX use, " + ain + " NpcAI params");
}
}