Tidy the repo root: build.sh's derived tables into analysis/, build.sh, decompile.sh and find.sh into scripts/, stale by-products removed, .gitignore regrouped, README describes the src/ layout and the test harness

This commit is contained in:
shweet committed 2026-11-23 20:24:03 -05:00
1 parent aefd3e2098
commit 7d407d5c19
17 files changed
+140 -86

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
#!/bin/bash
# Usage: find.sh MODE ARG
# name REGEX functions whose qualified name matches (addr name size)
# str REGEX strings matching, with the functions using them (addr "string" users)
# strs X strings a function uses (anm2 animations/events, sounds, paths)
# code REGEX functions whose decompiled C contains REGEX (addr name hits)
# callers X who calls X (address or exact name)
# 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 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)
# val ADDR constant at DAT_ADDR as int/float/double/string (decompiler leaves floats as DAT_)
# field REGEX known struct field offsets (REPENTOGON zhl struct defs)
# 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,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
}
name_of() { awk -F'\t' 'NR==FNR {n[$1]=$2; next} {print $0 "\t" n[$1]}' "$T/functions.tsv" -; }
case "$MODE" in
name) grep -E -- "$ARG" <(cut -f1-3 "$T/functions.tsv") ;;
str) awk -F'\t' -v r="$ARG" '$2 ~ r' "$T/strings.tsv" ;;
code) awk -v r="$ARG" '/^\/\/@@ / {h=$2" "$3; next} $0 ~ r {c[h]++} END {for (k in c) print k, c[k]}' "$T/all.c" | sort ;;
strs) for a in $(addr_of "$ARG"); do awk -F'\t' -v a="$a:" 'index($3, a) {print $2}' "$T/strings.tsv"; "$D/scripts/decompile.sh" "$a" | grep -o '"[^"]*"' | tr -d '"'; done | sort -u ;;
callers) for a in $(addr_of "$ARG"); do awk -F'\t' -v a="$a" '$2 == a "" {print $1}' "$T/calls.tsv"; done | sort -u | name_of ;;
callees) for a in $(addr_of "$ARG"); do awk -F'\t' -v a="$a" '$1 == a "" {print $2}' "$T/calls.tsv"; done | sort -u | name_of ;;
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|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/analysis/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/scripts/decompile.sh" "^Entity_Player::$F\$" | awk -v r="$LABEL" -v a="$ANCHOR" -v n="${3:-60}" \
-v t="LAB_$TARGET:" 'a == "-" || index($0, a) {on = 1} (on && !c && $0 ~ r && ++c) || index($0, t) == 1 {w = n; print "---- line " NR} w > 0 {print; w--}' ;; # also the case code under its LAB_ label (a case that is only a goto)
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/^ *//' ;;
lua) grep -P -- "$ARG" "$T/lua_bindings.tsv" ;;
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/analysis/zhl_vtables.tsv" "$ARG" "${3:-60}" ;;
*) sed -n '2,19p' "$0"; exit 1 ;;
esac