use_dispatch: id -> case table for UseActiveItem/UseCard/UsePill from the jump tables; find.sh active/card/pill

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-24 21:14:38 -04:00
1 parent f4eb24590e
commit 17fa5aa8e2
6 files changed
+452 -12

No files matched your search

+13 -5
View File
@@ -8,7 +8,9 @@
# callees X what X calls
# npc TYPE NPC AI function(s) for an entities2.xml type id (see README)
# item ID code lines testing collectible/trinket ID (HasCollectible(0x34,..), HasTrinket, ...)
# active ID [N] the case(s) for active item ID in Entity_Player::UseActiveItem (N lines each, default 60)
# active ID [N] the case for active item ID in Entity_Player::UseActiveItem (N lines, default 60; table: use_dispatch.tsv)
# card ID [N] the case for card/rune/soul ID in Entity_Player::UseCard
# pill ID [N] the case for pill effect ID in Entity_Player::UsePill
# player ID code comparing the player type to ID (heuristic: compare within 4 lines of a player-type read)
# enum REGEX game enums (entity types, collectibles, trinkets, cards, players...) from REPENTOGON
# lua REGEX Lua API bindings (class, member, target function or field+offset)
@@ -17,7 +19,7 @@
# vtable CLASS vtable slots of an RTTI class, read from the exe (e.g. Weapon_Knife, Entity_Player)
D="$(cd "$(dirname "$0")" && pwd)"; T="$D/dump"
MODE="$1"; ARG="$2"
[ -z "$ARG" ] && { sed -n '2,17p' "$0"; exit 1; }
[ -z "$ARG" ] && { sed -n '2,19p' "$0"; exit 1; }
addr_of() { # address or name -> 8-digit address
if [[ "$1" =~ ^(0x)?[0-9a-fA-F]{6,8}$ ]]; then printf '%08x\n' $((16#${1#0x}))
else awk -F'\t' -v n="$1" '$2 == n "" {print $1}' "$T/functions.tsv"; fi
@@ -33,8 +35,14 @@ case "$MODE" in
npc) grep -P "^$ARG\t" "$T/npc_ai.tsv" ;;
item) H=$(printf '0x%x' "$ARG")
awk -v r="(Collectible|Trinket)[A-Za-z]*[(]([^,()]*,)?($H|$ARG)[,)]" '/^\/\/@@ / {h=$2" "$3; next} $0 ~ r {gsub(/^ +/, ""); print h "\t" $0}' "$T/all.c" ;;
active) H=$(printf '%x' "$ARG")
"$D/decompile.sh" Entity_Player::UseActiveItem | awk -v r="case ([(][^)]*[)])?(0x$H|$ARG):|caseD_$H:" -v n="${3:-60}" '$0 ~ r {w=n; print "---- line " NR} w-- > 0' ;;
active|card|pill) # id -> case address and label from the exe's jump tables (scripts/use_dispatch.py)
F=UseActiveItem; [ "$MODE" = card ] && F=UseCard; [ "$MODE" = pill ] && F=UsePill
ROW=$(awk -F'\t' -v k="$MODE" -v i="$ARG" '$1 == k && $2 == i' "$D/use_dispatch.tsv")
[ -z "$ROW" ] && { echo "$MODE $ARG has no case in $F (an active then only adds its TemporaryEffect: try find.sh item $ARG)"; exit; }
IFS=$'\t' read -r _ _ ENUM TARGET LABEL ANCHOR SHARES <<< "$ROW"
echo "---- $ENUM: case at 0x$TARGET, shared with: $SHARES"
"$D/decompile.sh" "^Entity_Player::$F\$" | awk -v r="$LABEL" -v a="$ANCHOR" -v n="${3:-60}" \
'a == "-" || index($0, a) {on = 1} on && !w && $0 ~ r {w = n; print "---- line " NR} w > 0 {print; if (!--w) exit}' ;;
player) H=$(printf '0x%x' "$ARG") # player-type read, then a compare/case with ID within 4 lines
awk -v r="([!=]= |case )($H|$ARG)([^0-9a-fx]|$)" '/^\/\/@@ / {h=$2" "$3; next} /_playerType|0x13c0|GetPlayerType/ {w=5} w-- > 0 && $0 ~ r {gsub(/^ +/, ""); print h "\t" $0}' "$T/all.c" ;;
enum) grep -P -- "$ARG" "$D/repentogon/libzhl/functions/Global.zhl" | sed 's/^ *//' ;;
@@ -42,5 +50,5 @@ case "$MODE" in
val) python3 -I "$D/scripts/read_value.py" "$D/bin/isaac-ng.exe" "${ARG#DAT_}" ;;
field) grep -P -- "$ARG" "$T/zhl_fields.tsv" ;;
vtable) python3 -I "$D/scripts/vtable.py" "$D/bin/isaac-ng.exe" "$T/functions.tsv" "$D/zhl_vtables.tsv" "$ARG" "${3:-60}" ;;
*) sed -n '2,17p' "$0"; exit 1 ;;
*) sed -n '2,19p' "$0"; exit 1 ;;
esac