From 540cc49d34880d09bd820aeeed84b92d934e2c26 Mon Sep 17 00:00:00 2001 From: shweet Date: Sat, 24 Oct 2026 22:46:55 -0400 Subject: [PATCH] ApplyTypes: place fields in offset order and keep an embedded struct over views into it Entity._sprite (ANM2, now its full 0x114) was being overwritten by _spriteOffset/_spriteScale/_isFlipX, which are sprite members; every sprite access had fallen back to field_0x48/0x78/0x7c/0x8c. Co-Authored-By: Claude Opus 5.5 --- scripts/ApplyTypes.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/ApplyTypes.java b/scripts/ApplyTypes.java index a8ec3d4..4c6fc7e 100644 --- a/scripts/ApplyTypes.java +++ b/scripts/ApplyTypes.java @@ -34,7 +34,9 @@ public class ApplyTypes extends GhidraScript { void addFields(StructureDataType s, String cls, int depth) { if (depth > 8) return; if (base.containsKey(cls)) addFields(s, base.get(cls), depth + 1); - for (String[] f : fields.getOrDefault(cls, List.of())) { + List own = new ArrayList<>(fields.getOrDefault(cls, List.of())); + own.sort(Comparator.comparingInt(f -> Integer.decode(f[1]))); // in offset order, so an embedded struct beats views into it + for (String[] f : own) { java.util.regex.Matcher arr = java.util.regex.Pattern.compile("\\[(\\w+)\\]\\s*$").matcher(f[2]); // "int _trinketsID[2]" String decl = arr.find() ? f[2].substring(0, arr.start()) : f[2]; DataType dt = prim(decl); @@ -43,6 +45,8 @@ public class ApplyTypes extends GhidraScript { int off = Integer.decode(f[1]); String nm = decl.trim().replaceAll(".*\\s", "").replaceAll("[^\\w]", ""); try { + DataTypeComponent in = off < s.getLength() ? s.getComponentContaining(off) : null; + if (in != null && in.getOffset() != off && in.getDataType() != DataType.DEFAULT) continue; // inside a placed member (Entity 0xdc is _sprite._offset): keep the member if (off + dt.getLength() > s.getLength()) s.growStructure(off + dt.getLength() - s.getLength()); s.replaceAtOffset(off, dt, dt.getLength(), nm, null); } catch (Exception e) { /* overlapping/odd field: skip */ }