diff --git a/decompiler/IR2/Env.cpp b/decompiler/IR2/Env.cpp index ce60f6fe35..c053b4d1e7 100644 --- a/decompiler/IR2/Env.cpp +++ b/decompiler/IR2/Env.cpp @@ -579,7 +579,7 @@ FunctionVariableDefinitions Env::local_var_type_list(const Form* top_level_form, lookup_name = remapped->second; } - if (m_vars_defined_in_let.find(lookup_name) != m_vars_defined_in_let.end()) { + if (m_vars_defined_in_let.find(x.reg_id) != m_vars_defined_in_let.end()) { continue; } @@ -599,7 +599,7 @@ FunctionVariableDefinitions Env::local_var_type_list(const Form* top_level_form, std::sort(spills.begin(), spills.end(), [](const StackSpillEntry& a, const StackSpillEntry& b) { return a.offset < b.offset; }); for (auto& x : spills) { - if (m_vars_defined_in_let.find(x.name()) != m_vars_defined_in_let.end()) { + if (m_stack_slots_defined_in_let.find(x.offset) != m_stack_slots_defined_in_let.end()) { continue; } elts.push_back(pretty_print::build_list(x.name(), x.typespec.print())); diff --git a/decompiler/IR2/Env.h b/decompiler/IR2/Env.h index d8a6230fab..43000b82d0 100644 --- a/decompiler/IR2/Env.h +++ b/decompiler/IR2/Env.h @@ -229,7 +229,13 @@ class Env { void disable_def(const RegisterAccess& access, DecompWarnings& warnings); - void set_defined_in_let(const std::string& var) { m_vars_defined_in_let.insert(var); } + void set_defined_in_let(const RegisterAccess& var) { + if (is_stack_slot_access(var)) { + m_stack_slots_defined_in_let.insert(get_stack_slot_offset_from_access(var)); + } else { + m_vars_defined_in_let.insert(get_program_var_id(var)); + } + } void set_retype_map(const std::unordered_map& map) { m_var_retype = map; } @@ -286,7 +292,8 @@ class Env { std::unordered_map m_var_remap; std::unordered_map m_var_retype; - std::unordered_set m_vars_defined_in_let; + std::unordered_set m_vars_defined_in_let; + std::unordered_set m_stack_slots_defined_in_let; std::optional m_type_analysis_return_type; StackSpillMap m_stack_spill_map; diff --git a/decompiler/analysis/insert_lets.cpp b/decompiler/analysis/insert_lets.cpp index db32dcbf20..d2db02c819 100644 --- a/decompiler/analysis/insert_lets.cpp +++ b/decompiler/analysis/insert_lets.cpp @@ -3968,15 +3968,15 @@ LetStats insert_lets(const Function& func, // Stored per variable. struct PerVarInfo { - std::string var_name; // name used to uniquely identify - RegisterAccess access; + std::string var_name; + RegId var_id; std::unordered_set elts_using_var; // all FormElements using var Form* lca_form = nullptr; // the lowest common form that contains all the above elts int start_idx = -1; // in the above form, first FormElement using var's index int end_idx = -1; // in the above form, 1 + last FormElement using var's index }; - std::unordered_map var_info; + std::unordered_map var_info; // Part 1, figure out which forms reference each var top_level_form->apply([&](FormElement* elt) { @@ -4001,10 +4001,11 @@ LetStats insert_lets(const Function& func, // and add it. for (auto& access : reg_accesses) { if (register_can_hold_var(access.reg())) { + auto var_id = env.get_program_var_id(access); auto name = env.get_variable_name(access); - var_info[name].elts_using_var.insert(elt); - var_info[name].var_name = name; - var_info[name].access = access; + var_info[var_id].elts_using_var.insert(elt); + var_info[var_id].var_name = name; + var_info[var_id].var_id = var_id; } } }); @@ -4036,7 +4037,7 @@ LetStats insert_lets(const Function& func, bool uses = false; for (auto& ra : ras) { if ((ra.reg().get_kind() == Reg::FPR || ra.reg().get_kind() == Reg::GPR) && - env.get_variable_name(ra) == kv.second.var_name) { + env.get_program_var_id(ra) == kv.second.var_id) { uses = true; } } @@ -4073,7 +4074,6 @@ LetStats insert_lets(const Function& func, int start_elt = -1; // this is the set! SetVarElement* set_form = nullptr; int end_elt = -1; - std::string name; }; // stored per containing form. @@ -4082,18 +4082,17 @@ LetStats insert_lets(const Function& func, auto first_form = info.lca_form->at(info.start_idx); auto first_form_as_set = dynamic_cast(first_form); if (first_form_as_set && register_can_hold_var(first_form_as_set->dst().reg()) && - env.get_variable_name(first_form_as_set->dst()) == env.get_variable_name(info.access) && + env.get_program_var_id(first_form_as_set->dst()) == info.var_id && !first_form_as_set->info().is_eliminated_coloring_move) { bool allowed = true; + auto dst_var_id = env.get_program_var_id(first_form_as_set->dst()); RegAccessSet ras; first_form_as_set->src()->collect_vars(ras, true); for (auto ra : ras) { - if (ra.reg() == first_form_as_set->dst().reg()) { - if (env.get_variable_name(ra) == env.get_variable_name(first_form_as_set->dst())) { - allowed = false; - break; - } + if (env.get_program_var_id(ra) == dst_var_id) { + allowed = false; + break; } } // success! @@ -4105,7 +4104,6 @@ LetStats insert_lets(const Function& func, li.start_elt = info.start_idx; li.end_elt = info.end_idx; li.set_form = first_form_as_set; - li.name = info.var_name; possible_insertions[li.form].push_back(li); stats.vars_in_lets++; } @@ -4180,7 +4178,7 @@ LetStats insert_lets(const Function& func, auto casted_src = insert_cast_for_let(let_desc.set_form->dst(), let_desc.set_form->src_type(), let_desc.set_form->src(), pool, env); new_let->add_def(let_desc.set_form->dst(), casted_src); - env.set_defined_in_let(let_desc.name); + env.set_defined_in_let(let_desc.set_form->dst()); lets.at(let_idx) = new_let; } @@ -4252,12 +4250,12 @@ LetStats insert_lets(const Function& func, if (!as_let->is_star()) { RegAccessSet used; e.src->collect_vars(used, true); - std::unordered_set used_by_name; + std::unordered_set used_vars; for (auto used_var : used) { - used_by_name.insert(env.get_variable_name(used_var)); + used_vars.insert(env.get_program_var_id(used_var)); } for (auto& old_entry : as_let->entries()) { - if (used_by_name.find(env.get_variable_name(old_entry.dest)) != used_by_name.end()) { + if (used_vars.find(env.get_program_var_id(old_entry.dest)) != used_vars.end()) { as_let->make_let_star(); break; } diff --git a/decompiler/config/jak1/all-types.gc b/decompiler/config/jak1/all-types.gc index 9c1cb9b25d..c9f5e3467e 100644 --- a/decompiler/config/jak1/all-types.gc +++ b/decompiler/config/jak1/all-types.gc @@ -23681,7 +23681,7 @@ (navenmf5 5) (navenmf6 6) (navenmf7 7) - (navenmf8 8) + (just-attacked 8) (standing-jump 9) (drop-jump 10) (navenmf11 11) @@ -23708,7 +23708,7 @@ ) (deftype nav-enemy (process-drawable) - ((collide-info collide-shape-moving :score 100 :offset 112) + ((root collide-shape-moving :override) (enemy-info fact-info-enemy :score 100 :offset 144) (hit-from-dir vector :inline :offset-assert 176) (event-param-point vector :inline :offset-assert 192) diff --git a/decompiler/config/jak1/ntsc_v1/var_names.jsonc b/decompiler/config/jak1/ntsc_v1/var_names.jsonc index 1ad68a2c1a..f569574ee1 100644 --- a/decompiler/config/jak1/ntsc_v1/var_names.jsonc +++ b/decompiler/config/jak1/ntsc_v1/var_names.jsonc @@ -75,6 +75,18 @@ ] } }, + "(code idle assistant-bluehut)": {}, + "(code idle assistant-firecanyon)": {}, + "(code idle assistant-lavatube-end)": {}, + "(code idle assistant-lavatube-start)": {}, + "(code idle assistant-levitator)": {}, + "(code idle assistant-villagec)": {}, + "(code just-particles assistant-levitator)": {}, + "(code level-hint-ambient-sound level-hint)": {}, + "(code level-hint-error level-hint)": {}, + "(code level-hint-exit level-hint)": {}, + "(code level-hint-normal level-hint)": {}, + "(code level-hint-sidekick level-hint)": {}, "(code manipy-idle)": { "vars": { "v1-29": [ @@ -83,6 +95,28 @@ ] } }, + "(code nav-enemy-chase aphid)": { + "vars": { + "f30-0": "speed", + "f30-1": "speed", + "gp-0": "time-adjust", + "s4-1": "invuln-duration", + "s4-3": "run-duration", + "s5-1": "invuln-start-time", + "s5-3": "run-start" + } + }, + "(code nav-enemy-give-up aphid)": { + "vars": { + "s4-0": "root", + "s5-0": "tgt-pos" + } + }, + "(code nav-enemy-stare aphid)": { + "vars": { + "f30-0": "speed" + } + }, "(code ogreboss-stage1)": { "vars": { "s5-0": [ @@ -271,6 +305,7 @@ ] } }, + "(enter idle assistant-lavatube-end)": {}, "(event be-clone process-taskable)": { "vars": { "v0-0": [ @@ -311,6 +346,8 @@ ] } }, + "(event level-hint-normal level-hint)": {}, + "(event level-hint-sidekick level-hint)": {}, "(event pickup eco-collectable)": { "vars": { "v0-1": [ @@ -343,6 +380,12 @@ ] } }, + "(exit idle assistant-levitator)": {}, + "(exit level-hint-ambient-sound level-hint)": {}, + "(exit level-hint-normal level-hint)": {}, + "(exit level-hint-sidekick level-hint)": {}, + "(exit play-anim assistant-bluehut)": {}, + "(exit play-anim assistant-levitator)": {}, "(exit play-anim sequenceA-village1)": { "vars": { "v1-10": [ @@ -389,6 +432,9 @@ "v1-2": "bc" } }, + "(method 0 anim-test-obj)": {}, + "(method 0 anim-test-seq-item)": {}, + "(method 0 anim-test-sequence)": {}, "(method 0 array)": { "args": [ "allocation", @@ -410,6 +456,7 @@ "v0-0": "this" } }, + "(method 0 catch-frame)": {}, "(method 0 collide-shape)": { "args": [ "allocation", @@ -491,6 +538,14 @@ } }, "(method 0 cpu-thread)": { + "args": [ + "allocation", + "type-to-make", + "parent-process", + "name", + "stack-size", + "stack-addr" + ], "vars": { "v0-0": [ "this", @@ -512,6 +567,7 @@ "v1-3": "lookup-entity" } }, + "(method 0 dead-pool)": {}, "(method 0 dead-pool-heap)": { "vars": { "v0-0": [ @@ -725,6 +781,9 @@ "v1-9": "data" } }, + "(method 0 process)": {}, + "(method 0 process-tree)": {}, + "(method 0 protect-frame)": {}, "(method 0 res-lump)": { "args": [ "allocation", @@ -803,6 +862,19 @@ "v0-0": "this" } }, + "(method 0 string)": { + "args": [ + "allocation", + "type-to-make", + "min-len", + "copy-from" + ], + "vars": { + "a0-4": "obj", + "s2-1": "len", + "v0-2": "obj" + } + }, "(method 0 touching-list)": { "vars": { "v0-0": [ @@ -816,6 +888,7 @@ "gp-0": "this" } }, + "(method 1 thread)": {}, "(method 10 __assert-info-private-struct)": {}, "(method 10 actor-link-info)": { "vars": { @@ -894,6 +967,7 @@ "s5-1": "cur" } }, + "(method 10 cpu-thread)": {}, "(method 10 cylinder)": { "args": [ "this", @@ -1015,6 +1089,8 @@ "f0-2": "vel" } }, + "(method 10 process)": {}, + "(method 10 process-tree)": {}, "(method 10 res-lump)": { "args": [ "this", @@ -1224,6 +1300,7 @@ "f1-6": "abs-vel" } }, + "(method 11 cpu-thread)": {}, "(method 11 eco)": { "vars": { "v1-2": [ @@ -1555,6 +1632,7 @@ "v1-3": "num-cverts" } }, + "(method 12 process)": {}, "(method 12 profile-bar)": { "args": [ "this", @@ -1944,6 +2022,8 @@ "s4-0": "next-point" } }, + "(method 14 dead-pool)": {}, + "(method 14 dead-pool-heap)": {}, "(method 14 effect-control)": { "args": [ "this", @@ -2140,6 +2220,8 @@ } }, "(method 15 actor-link-info)": {}, + "(method 15 dead-pool)": {}, + "(method 15 dead-pool-heap)": {}, "(method 15 engine)": { "args": [ "this", @@ -2328,6 +2410,7 @@ "s3-0": "ent" } }, + "(method 16 dead-pool-heap)": {}, "(method 16 font-context)": { "args": [ "this", @@ -2490,6 +2573,7 @@ "s3-0": "ent" } }, + "(method 17 dead-pool-heap)": {}, "(method 17 drawable-ambient)": { "args": [ "this", @@ -2589,6 +2673,7 @@ "v1-25": "actor-to-birth" } }, + "(method 18 dead-pool-heap)": {}, "(method 18 drawable-ambient)": { "args": [ "this", @@ -2645,6 +2730,7 @@ "msg" ] }, + "(method 19 dead-pool-heap)": {}, "(method 19 engine)": { "args": [ "this", @@ -2724,9 +2810,26 @@ }, "(method 2 array)": { "vars": { + "s5-0": "i", + "s5-1": "i", + "s5-10": "i", + "s5-11": "i", + "s5-2": "i", + "s5-3": "i", + "s5-4": "i", + "s5-5": "i", + "s5-6": "i", + "s5-7": "i", + "s5-8": "i", + "s5-9": "i", "v1-1": "content-type-sym" } }, + "(method 2 bfloat)": {}, + "(method 2 handle)": {}, + "(method 2 process)": {}, + "(method 2 thread)": {}, + "(method 2 vec4s)": {}, "(method 20 actor-link-info)": { "args": [ "this", @@ -2824,6 +2927,7 @@ "t2-0": "probe-result" } }, + "(method 20 dead-pool-heap)": {}, "(method 20 driller-lurker)": { "args": [ "this", @@ -3240,6 +3344,7 @@ "s5-0": "all-destroyed?" } }, + "(method 21 dead-pool-heap)": {}, "(method 21 drop-plat)": { "args": [ "this" @@ -3507,6 +3612,7 @@ "gp-0": "ripple-ctrl" } }, + "(method 22 dead-pool-heap)": {}, "(method 22 entity-actor)": { "vars": { "s4-0": "entity-process", @@ -4154,6 +4260,7 @@ "s5-0": "cshape" } }, + "(method 24 dead-pool-heap)": {}, "(method 24 driller-lurker)": { "args": [ "this" @@ -4437,6 +4544,7 @@ "s5-0": "actor" } }, + "(method 25 dead-pool-heap)": {}, "(method 25 driller-lurker)": { "args": [ "this" @@ -4610,6 +4718,7 @@ "f0-0": "scale" } }, + "(method 26 dead-pool-heap)": {}, "(method 26 driller-lurker)": { "args": [ "this" @@ -5241,6 +5350,9 @@ "(method 3 actor-link-info)": {}, "(method 3 air-box)": {}, "(method 3 align-control)": {}, + "(method 3 anim-test-obj)": {}, + "(method 3 anim-test-seq-item)": {}, + "(method 3 anim-test-sequence)": {}, "(method 3 anim-tester)": { "vars": { "s3-0": [ @@ -5257,9 +5369,22 @@ ] } }, + "(method 3 anim-tester-bank)": {}, "(method 3 aphid)": {}, "(method 3 array)": { "vars": { + "s5-0": "i", + "s5-1": "i", + "s5-10": "i", + "s5-11": "i", + "s5-2": "i", + "s5-3": "i", + "s5-4": "i", + "s5-5": "i", + "s5-6": "i", + "s5-7": "i", + "s5-8": "i", + "s5-9": "o", "v1-1": "content-type-sym" } }, @@ -5276,27 +5401,43 @@ "(method 3 baby-spider)": {}, "(method 3 baby-spider-spawn-params)": {}, "(method 3 background-work)": {}, + "(method 3 baseplat)": {}, + "(method 3 bfloat)": {}, + "(method 3 catch-frame)": {}, "(method 3 connectable)": {}, + "(method 3 cpu-thread)": {}, + "(method 3 dead-pool)": {}, + "(method 3 dead-pool-heap)": {}, + "(method 3 dead-pool-heap-rec)": {}, "(method 3 display-env)": {}, "(method 3 double-lurker-top)": {}, "(method 3 draw-control)": {}, + "(method 3 handle)": {}, + "(method 3 inline-array-class)": {}, "(method 3 joint-anim)": {}, "(method 3 joint-anim-compressed-control)": {}, "(method 3 joint-anim-compressed-fixed)": {}, "(method 3 joint-anim-compressed-frame)": {}, "(method 3 joint-anim-compressed-hdr)": {}, + "(method 3 junglesnake-twist-joint)": {}, + "(method 3 kernel-context)": {}, "(method 3 lavatube-part)": {}, "(method 3 list-control)": {}, "(method 3 list-field)": {}, "(method 3 lod-group)": {}, "(method 3 lod-set)": {}, + "(method 3 process)": {}, + "(method 3 process-tree)": {}, + "(method 3 protect-frame)": {}, "(method 3 res-lump)": { "vars": { "s5-0": "i" } }, "(method 3 skeleton-group)": {}, + "(method 3 thread)": {}, "(method 3 tippy)": {}, + "(method 3 vec4s)": {}, "(method 3 vif-disasm-element)": {}, "(method 3 wobbler)": {}, "(method 3 yeti-slave)": {}, @@ -5780,12 +5921,19 @@ "(method 39 assistant-villagec)": {}, "(method 39 babak-with-cannon)": {}, "(method 39 baby-spider)": {}, + "(method 4 array)": {}, + "(method 4 inline-array-class)": {}, "(method 4 pair)": { "vars": { "v0-0": "result", "v1-1": "iter" } }, + "(method 4 string)": { + "vars": { + "v1-0": "ptr" + } + }, "(method 40 process-taskable)": { "args": [ "this", @@ -6126,6 +6274,14 @@ "v1-23": "jmod" } }, + "(method 5 array)": {}, + "(method 5 cpu-thread)": {}, + "(method 5 dead-pool-heap)": {}, + "(method 5 inline-array-class)": {}, + "(method 5 pair)": {}, + "(method 5 process)": {}, + "(method 5 string)": {}, + "(method 5 type)": {}, "(method 50 nav-enemy)": { "args": [ "this", @@ -6632,6 +6788,7 @@ "v1-0": "i" } }, + "(method 7 object)": {}, "(method 76 snow-bunny)": { "args": [ "this", @@ -6957,6 +7114,7 @@ "damping" ] }, + "(method 9 process)": {}, "(method 9 res-lump)": { "args": [ "this", @@ -7059,6 +7217,11 @@ "v1-0": "mem-start" } }, + "(method 9 thread)": { + "vars": { + "a2-0": "proc" + } + }, "(method 9 tippy)": { "args": [ "this", @@ -7176,6 +7339,14 @@ ] } }, + "(trans hidden assistant-firecanyon)": {}, + "(trans hidden assistant-lavatube-end)": {}, + "(trans hidden assistant-lavatube-start)": {}, + "(trans hidden assistant-levitator)": {}, + "(trans idle assistant-bluehut)": {}, + "(trans idle assistant-levitator)": {}, + "(trans play-anim assistant-bluehut)": {}, + "(trans play-anim assistant-levitator)": {}, "*": { "args": [ "x", @@ -7578,6 +7749,10 @@ "v1-0": "max-magnitude" } }, + "anim-test-anim-list-handler": {}, + "anim-test-edit-seq-insert-item": {}, + "anim-test-edit-sequence-list-handler": {}, + "anim-test-obj-init": {}, "anim-test-obj-item-valid?": { "vars": { "s5-0": [ @@ -7586,6 +7761,7 @@ ] } }, + "anim-test-obj-list-handler": {}, "anim-test-obj-remove-invalid": { "vars": { "s2-0": [ @@ -7602,7 +7778,15 @@ ] } }, + "anim-test-seq-item-copy!": {}, + "anim-test-seq-mark-as-edited": {}, + "anim-test-sequence-init": {}, + "anim-test-sequence-list-handler": {}, + "anim-tester-add-newobj": {}, + "anim-tester-add-object": {}, "anim-tester-add-sequence": {}, + "anim-tester-adjust-frame": {}, + "anim-tester-disp-frame-num": {}, "anim-tester-get-playing-item": { "vars": { "v0-0": [ @@ -7611,7 +7795,12 @@ ] } }, + "anim-tester-interface": {}, + "anim-tester-load-object-seqs": {}, + "anim-tester-num-print": {}, + "anim-tester-pick-item-setup": {}, "anim-tester-post": {}, + "anim-tester-real-post": {}, "anim-tester-reset": { "vars": { "v1-1": [ @@ -7620,6 +7809,7 @@ ] } }, + "anim-tester-save-all-objects": {}, "anim-tester-save-object-seqs": { "vars": { "s4-2": [ @@ -7628,6 +7818,12 @@ ] } }, + "anim-tester-set-name": {}, + "anim-tester-standard-event-handler": {}, + "anim-tester-start": {}, + "anim-tester-stop": {}, + "anim-tester-string-get-frame!!": {}, + "anim-tester-update-anim-info": {}, "aphid-init-by-other": { "args": [ "parent-boss", @@ -7823,6 +8019,7 @@ "pt" ] }, + "breakpoint-range-set!": {}, "bsp-camera-asm": { "args": [ "bsp-hdr", @@ -7946,6 +8143,28 @@ "v1-0": "a-ptr" } }, + "change-brother": { + "args": [ + "new-brother", + "old-brother" + ], + "vars": { + "a2-1": "parent", + "a3-1": "new-bro-pred", + "t0-0": "it", + "v1-4": "old-bro-pred" + } + }, + "change-parent": {}, + "change-to-last-brother": { + "args": [ + "proc" + ], + "vars": { + "a1-0": "parent", + "v1-4": "it" + } + }, "charp-basename": { "args": [ "charp" @@ -7999,6 +8218,11 @@ ] } }, + "clear": { + "args": [ + "s" + ] + }, "cloud-track": { "vars": { "s1-1": [ @@ -8033,6 +8257,16 @@ "src" ] }, + "copy-string<-string": { + "args": [ + "dst", + "src" + ], + "vars": { + "a1-1": "s-ptr", + "v1-0": "d-ptr" + } + }, "copyn-string<-charp": { "args": [ "str", @@ -8807,11 +9041,13 @@ "v1-1": "data" } }, + "execute-process-tree": {}, "fact": { "args": [ "x" ] }, + "false-func": {}, "file-info-correct-version?": { "args": [ "info", @@ -9028,6 +9264,7 @@ "ent" ] }, + "initialize-anim-tester": {}, "initialize-collision": { "args": [ "this", @@ -9050,6 +9287,11 @@ "a3-0": "updated-list" } }, + "inspect": { + "args": [ + "obj" + ] + }, "inspect-process-heap": { "vars": { "s5-0": [ @@ -9058,6 +9300,7 @@ ] } }, + "inspect-process-tree": {}, "internal-draw-debug-line": { "vars": { "a0-31": [ @@ -9098,6 +9341,7 @@ ] } }, + "iterate-process-tree": {}, "ja-play-spooled-anim": { "vars": { "sv-16": "spool-part", @@ -9125,6 +9369,9 @@ "mat" ] }, + "kernel-dispatcher": {}, + "kill-by-name": {}, + "kill-by-type": {}, "kill-current-level-hint": { "args": [ "allowed-modes", @@ -9135,6 +9382,8 @@ "s4-0": "proc" } }, + "kill-not-name": {}, + "kill-not-type": {}, "last": { "args": [ "lst" @@ -9312,6 +9561,12 @@ "sv-40": "heap-free" } }, + "load-package": { + "args": [ + "package", + "allocation" + ] + }, "logand": { "args": [ "x", @@ -9794,6 +10049,12 @@ "s4-0": "local-trans" } }, + "name=": { + "args": [ + "a", + "b" + ] + }, "nassoc": { "args": [ "item-name", @@ -9945,6 +10206,11 @@ "v1-2": "child" } }, + "print": { + "args": [ + "obj" + ] + }, "print-game-text": { "args": [ "str", @@ -9978,6 +10244,14 @@ "s4-0": "i" } }, + "printl": { + "args": [ + "obj" + ] + }, + "process-by-name": {}, + "process-count": {}, + "process-not-name": {}, "process-status-bits": { "vars": { "s3-0": [ @@ -10012,6 +10286,7 @@ "v1-1": "qwc" } }, + "quad-copy!": {}, "quaternion-axis-angle!": { "args": [ "quat", @@ -10118,6 +10393,7 @@ "y" ] }, + "remove-exit": {}, "render-ocean-far": { "vars": { "s5-0": [ @@ -10126,6 +10402,7 @@ ] } }, + "reset-and-call": {}, "reset-display-gs-state": { "args": [ "disp", @@ -10150,6 +10427,9 @@ "v1-0": "hoff" } }, + "return-from-thread": {}, + "return-from-thread-dead": {}, + "run-function-in-process": {}, "scale-matrix!": { "args": [ "dst", @@ -10157,6 +10437,7 @@ "src" ] }, + "search-process-tree": {}, "seek": { "args": [ "x", @@ -10310,6 +10591,8 @@ "v1-3": "mode" } }, + "set-to-run": {}, + "set-to-run-bootstrap": {}, "show-mc-info": { "args": [ "dma-buf" @@ -10873,6 +11156,8 @@ "s5-0": "cmd" } }, + "stream<-process-mask": {}, + "string->float": {}, "string->int": { "args": [ "str" @@ -10937,6 +11222,29 @@ "second-flag" ] }, + "string-get-float!!": { + "args": [ + "ret", + "str" + ] + }, + "string-get-int32!!": {}, + "string-skip-to-char": { + "args": [ + "str", + "char" + ] + }, + "string-skip-whitespace": { + "args": [ + "str" + ] + }, + "string-strip-leading-whitespace!": { + "args": [ + "str" + ] + }, "string-strip-trailing-whitespace!": { "args": [ "str" @@ -10945,6 +11253,7 @@ "v1-6": "ptr" } }, + "string-strip-whitespace!": {}, "string-suck-up!": { "args": [ "str", @@ -11217,6 +11526,8 @@ "v1-0": "mip-level" } }, + "throw": {}, + "throw-dispatch": {}, "transform-matrix-calc!": { "args": [ "tf", @@ -11236,6 +11547,7 @@ "dst-mat" ] }, + "true-func": {}, "type-type?": { "args": [ "child-type", @@ -11258,6 +11570,14 @@ "s4-0": "spr-to-bank" } }, + "unload-package": { + "args": [ + "package" + ], + "vars": { + "v1-0": "pack" + } + }, "unpack-comp-rle": { "args": [ "out", diff --git a/docs/jak1_cleanup_inputs/method_names.jsonc b/docs/jak1_cleanup_inputs/method_names.jsonc index 23029a5766..9ab7cf3587 100644 --- a/docs/jak1_cleanup_inputs/method_names.jsonc +++ b/docs/jak1_cleanup_inputs/method_names.jsonc @@ -11,6 +11,10 @@ "new", "Allocate `joint-anim-frame` with enough room for `matrix-count`, including the two built-in align, prejoint matrices." ], + "(method 0 string)": [ + "new", + "Create a new string which can hold `len` characters, not including null terminator.\nCopies from `copy-from` if provided, picking the maximum size between `len` and `copy-from`." + ], "(method 10 actor-link-info)": [ "actor-count-before", "Return the index of this actor" @@ -1087,6 +1091,10 @@ "common-post", "Load spooled animations for the babak." ], + "(method 4 string)": [ + "length", + "Get the length of a string, like `strlen`." + ], "(method 40 nav-enemy)": [ "update-nav-target!", "Point nav-control at our current nav target-pos so it recomputes the travel vector." @@ -1172,6 +1180,10 @@ "setup-enemy!", "Per-subclass post-init hook called from init-from-entity! after collision/entity setup: initialize the skeleton, nav-enemy-info defaults, particle/joint controls and enemy-specific state. Empty stub on the nav-enemy base." ], + "(method 5 string)": [ + "asize-of", + "Get the size in bytes of this object." + ], "(method 50 nav-enemy)": [ "jump-dest-blocked?", "Test whether a jump destination lies inside any nav-mesh sphere relative to our origin, i.e. the jump is blocked." @@ -1490,6 +1502,10 @@ "aphid-vulnerable", "remove invulnerability" ], + "append-character-to-string": [ + "append-character-to-string", + "Append a single character to string." + ], "assistant-levitator-blue-glow": [ "assistant-levitator-blue-glow", "Spawn particles" @@ -1514,6 +1530,34 @@ "can-grab-display?", "Can this process draw its hint text or similar to the screen?\nOnce it returns #t, it will become the exclusive process to draw to the screen for 0.1 seconds." ], + "cat-string<-string": [ + "cat-string<-string", + "Append b to a, no length checks." + ], + "cat-string<-string_to_charp": [ + "cat-string<-string_to_charp", + "Append b to a, using chars of b up to and including `end-ptr`, or the end of b, whichever is first." + ], + "catn-string<-charp": [ + "catn-string<-charp", + "Append `len` chars of `b` to `a`" + ], + "change-brother": [ + "change-brother", + "Unused and wrong.\nSeems like this assumes a process stores a `process-tree` reference directly, not `(poitner process-tree)`" + ], + "change-to-last-brother": [ + "change-to-last-brother", + "Move this process to the last spot in its list of brothers" + ], + "charp-basename": [ + "charp-basename", + "Like basename in C" + ], + "charp<-string": [ + "charp<-string", + "Copy a GOAL string into a C string." + ], "check-drop-level-assistant": [ "check-drop-level-assistant", "Check if the particle hits the surface height stored in `user-float`: if so, chance to play drip sound,\nthen spawn a splash particle." @@ -1522,6 +1566,22 @@ "check-drop-level-assistant-bluehut", "Check if particle has dropped past the threshold stored in `user-float`. If so, chance to play splash,\nand draw a splash particle." ], + "clear": [ + "clear", + "Make string empty" + ], + "copy-charp<-charp": [ + "copy-charp<-charp", + "C string copy." + ], + "copy-string<-string": [ + "copy-string<-string", + "Copy data from `src` to `dst`, no length checks." + ], + "copyn-string<-charp": [ + "copyn-string<-charp", + "Copy `len` characters from a C-string to a GOAL string, inserting a null character." + ], "entity-actor-count": [ "entity-actor-count", "Get the number of actors stored in `lump[name]`" @@ -1562,6 +1622,10 @@ "level-hint-task-process", "If this entity's hint can be played, run its command array. This can mutate game state and check conditions.\nIf all conditions pass, return the text-id. Otherwise, return -1." ], + "name=": [ + "name=", + "Are `a` and `b` the same name? This works for strings and symbols." + ], "point-in-air-box-area?": [ "point-in-air-box-area?", "Check if point `x, z` (relative to air-box origin) is within the projected area of the air-box. Effectively doesn't check height." @@ -1577,5 +1641,77 @@ "points-in-air?": [ "points-in-air?", "Are both `p1` and `p2` inside any of the boxes?" + ], + "string->int": [ + "string->int", + "String to int. Supports binary, hex, and decimal, and negatives." + ], + "string-charp=": [ + "string-charp=", + "Is the GOAL string `str` equal to the C-string `charp`?" + ], + "string-get-arg!!": [ + "string-get-arg!!", + "Get the first argument from a whitespace separated list of arguments.\nThe arguments can optionally be in quotes.\nSucks up the argument and whitespace, leaving the rest." + ], + "string-get-flag!!": [ + "string-get-flag!!", + "If argument is `first-flag`, result is `#t`. If argument is `second-flag`, result is `#f`. Otherwise,\nleave `result` unset and return #f." + ], + "string-get-float!!": [ + "string-get-float!!", + "Get a float from a list of arguments." + ], + "string-get-int32!!": [ + "string-get-int32!!", + "Get an int32 from a list of arguments." + ], + "string-skip-to-char": [ + "string-skip-to-char", + "Return pointer to first instance of char in C string, or to the null terminator if it doesn't occur." + ], + "string-skip-whitespace": [ + "string-skip-whitespace", + "Skip over spaces, tabs, newline, and carriage return." + ], + "string-strip-leading-whitespace!": [ + "string-strip-leading-whitespace!", + "Remove whitespace at the start of a string." + ], + "string-strip-trailing-whitespace!": [ + "string-strip-trailing-whitespace!", + "Remove whitespace at the end of a string." + ], + "string-strip-whitespace!": [ + "string-strip-whitespace!", + "Remove whitespace at the beginning and end of a string." + ], + "string-suck-up!": [ + "string-suck-up!", + "Remove characters between the start of string and location. The original char at location is the first." + ], + "string<-charp": [ + "string<-charp", + "Copy all chars from a C string to GOAL string." + ], + "string<=?": [ + "string<=?", + "In dictionary order, is a <= b?" + ], + "string=?": [ + "string>=?", + "In dictionary order, is a >= b?" + ], + "string>?": [ + "string>?", + "In dictionary order, is a > b?" ] } diff --git a/goal_src/jak1/kernel/gcommon.gc b/goal_src/jak1/kernel/gcommon.gc index 5a3d3eeba1..1e260c9549 100644 --- a/goal_src/jak1/kernel/gcommon.gc +++ b/goal_src/jak1/kernel/gcommon.gc @@ -542,52 +542,32 @@ this) (defmethod print ((this array)) - "Print array." (format #t "#(") (cond ((type-type? (-> this content-type) integer) (case (-> this content-type symbol) - (('int32) - (dotimes (s5-0 (-> this length)) - (format #t (if (zero? s5-0) "~D" " ~D") (-> (the-as (array int32) this) s5-0)))) - (('uint32) - (dotimes (s5-1 (-> this length)) - (format #t (if (zero? s5-1) "~D" " ~D") (-> (the-as (array uint32) this) s5-1)))) - (('int64) - (dotimes (s5-2 (-> this length)) - (format #t (if (zero? s5-2) "~D" " ~D") (-> (the-as (array int64) this) s5-2)))) - (('uint64) - (dotimes (s5-3 (-> this length)) - (format #t (if (zero? s5-3) "#x~X" " #x~X") (-> (the-as (array uint64) this) s5-3)))) - (('int8) (dotimes (s5-4 (-> this length)) (format #t (if (zero? s5-4) "~D" " ~D") (-> (the-as (array int8) this) s5-4)))) - (('uint8) - (dotimes (s5-5 (-> this length)) - (format #t (if (zero? s5-5) "~D" " ~D") (-> (the-as (array uint8) this) s5-5)))) - (('int16) - (dotimes (s5-6 (-> this length)) - (format #t (if (zero? s5-6) "~D" " ~D") (-> (the-as (array int16) this) s5-6)))) - (('uint16) - (dotimes (s5-7 (-> this length)) - (format #t (if (zero? s5-7) "~D" " ~D") (-> (the-as (array uint16) this) s5-7)))) + (('int32) (dotimes (i (-> this length)) (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array int32) this) i)))) + (('uint32) (dotimes (i (-> this length)) (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array uint32) this) i)))) + (('int64) (dotimes (i (-> this length)) (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array int64) this) i)))) + (('uint64) (dotimes (i (-> this length)) (format #t (if (zero? i) "#x~X" " #x~X") (-> (the-as (array uint64) this) i)))) + (('int8) (dotimes (i (-> this length)) (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array int8) this) i)))) + (('uint8) (dotimes (i (-> this length)) (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array uint8) this) i)))) + (('int16) (dotimes (i (-> this length)) (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array int16) this) i)))) + (('uint16) (dotimes (i (-> this length)) (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array uint16) this) i)))) (('uint128 'int128) - (dotimes (s5-8 (-> this length)) - (format #t (if (zero? s5-8) "#x~X" " #x~X") (-> (the-as (array uint128) this) s5-8)))) - (else (dotimes (s5-9 (-> this length)) (format #t (if (zero? s5-9) "~D" " ~D") (-> (the-as (array int32) this) s5-9)))))) + (dotimes (i (-> this length)) + (format #t (if (zero? i) "#x~X" " #x~X") (-> (the-as (array uint128) this) i)))) + (else (dotimes (i (-> this length)) (format #t (if (zero? i) "~D" " ~D") (-> (the-as (array int32) this) i)))))) ((= (-> this content-type) float) - (dotimes (s5-10 (-> this length)) - (if (zero? s5-10) - (format #t "~f" (-> (the-as (array float) this) s5-10)) - (format #t " ~f" (-> (the-as (array float) this) s5-10))))) + (dotimes (i (-> this length)) + (if (zero? i) (format #t "~f" (-> (the-as (array float) this) i)) (format #t " ~f" (-> (the-as (array float) this) i))))) (else - (dotimes (s5-11 (-> this length)) - (if (zero? s5-11) - (format #t "~A" (-> (the-as (array basic) this) s5-11)) - (format #t " ~A" (-> (the-as (array basic) this) s5-11)))))) + (dotimes (i (-> this length)) + (if (zero? i) (format #t "~A" (-> (the-as (array basic) this) i)) (format #t " ~A" (-> (the-as (array basic) this) i)))))) (format #t ")") this) (defmethod inspect ((this array)) - "Inspect an array" (format #t "[~8x] ~A~%" this (-> this type)) (format #t "~Tallocated-length: ~D~%" (-> this allocated-length)) (format #t "~Tlength: ~D~%" (-> this length)) @@ -596,22 +576,20 @@ (cond ((type-type? (-> this content-type) integer) (case (-> this content-type symbol) - (('int32) (dotimes (s5-0 (-> this length)) (format #t "~T [~D] ~D~%" s5-0 (-> (the-as (array int32) this) s5-0)))) - (('uint32) (dotimes (s5-1 (-> this length)) (format #t "~T [~D] ~D~%" s5-1 (-> (the-as (array uint32) this) s5-1)))) - (('int64) (dotimes (s5-2 (-> this length)) (format #t "~T [~D] ~D~%" s5-2 (-> (the-as (array int64) this) s5-2)))) - (('uint64) (dotimes (s5-3 (-> this length)) (format #t "~T [~D] #x~X~%" s5-3 (-> (the-as (array uint64) this) s5-3)))) - (('int8) (dotimes (s5-4 (-> this length)) (format #t "~T [~D] ~D~%" s5-4 (-> (the-as (array int8) this) s5-4)))) - (('uint8) (dotimes (s5-5 (-> this length)) (format #t "~T [~D] ~D~%" s5-5 (-> (the-as (array int8) this) s5-5)))) - (('int16) (dotimes (s5-6 (-> this length)) (format #t "~T [~D] ~D~%" s5-6 (-> (the-as (array int16) this) s5-6)))) - (('uint16) (dotimes (s5-7 (-> this length)) (format #t "~T [~D] ~D~%" s5-7 (-> (the-as (array uint16) this) s5-7)))) - (('int128 'uint128) - (dotimes (s5-8 (-> this length)) - (format #t "~T [~D] #x~X~%" s5-8 (-> (the-as (array uint128) this) s5-8)))) - (else (dotimes (s5-9 (-> this length)) (format #t "~T [~D] ~D~%" s5-9 (-> (the-as (array int32) this) s5-9)))))) + (('int32) (dotimes (i (-> this length)) (format #t "~T [~D] ~D~%" i (-> (the-as (array int32) this) i)))) + (('uint32) (dotimes (i (-> this length)) (format #t "~T [~D] ~D~%" i (-> (the-as (array uint32) this) i)))) + (('int64) (dotimes (i (-> this length)) (format #t "~T [~D] ~D~%" i (-> (the-as (array int64) this) i)))) + (('uint64) (dotimes (i (-> this length)) (format #t "~T [~D] #x~X~%" i (-> (the-as (array uint64) this) i)))) + (('int8) (dotimes (i (-> this length)) (format #t "~T [~D] ~D~%" i (-> (the-as (array int8) this) i)))) + (('uint8) (dotimes (i (-> this length)) (format #t "~T [~D] ~D~%" i (-> (the-as (array int8) this) i)))) + (('int16) (dotimes (i (-> this length)) (format #t "~T [~D] ~D~%" i (-> (the-as (array int16) this) i)))) + (('uint16) (dotimes (i (-> this length)) (format #t "~T [~D] ~D~%" i (-> (the-as (array uint16) this) i)))) + (('int128 'uint128) (dotimes (i (-> this length)) (format #t "~T [~D] #x~X~%" i (-> (the-as (array uint128) this) i)))) + (else (dotimes (o (-> this length)) (format #t "~T [~D] ~D~%" o (-> (the-as (array int32) this) o)))))) ((= (-> this content-type) float) - (dotimes (s5-10 (-> this length)) - (format #t "~T [~D] ~f~%" s5-10 (-> (the-as (array float) this) s5-10)))) - (else (dotimes (s5-11 (-> this length)) (format #t "~T [~D] ~A~%" s5-11 (-> (the-as (array basic) this) s5-11))))) + (dotimes (i (-> this length)) + (format #t "~T [~D] ~f~%" i (-> (the-as (array float) this) i)))) + (else (dotimes (i (-> this length)) (format #t "~T [~D] ~A~%" i (-> (the-as (array basic) this) i))))) this) (defmethod length ((this array)) diff --git a/goal_src/jak1/kernel/gkernel.gc b/goal_src/jak1/kernel/gkernel.gc index 73a056e45a..ecaa386e89 100644 --- a/goal_src/jak1/kernel/gkernel.gc +++ b/goal_src/jak1/kernel/gkernel.gc @@ -1657,87 +1657,59 @@ (set! (-> new-parent child) (-> this ppointer)) this)) -(defun change-brother ((arg0 process-tree) (arg1 process-tree)) - "Unused, and wrong. - It seems like this was written when processes store process-trees, not (pointer process-tree)." - (local-vars - (v1-4 (pointer process-tree)) - (a1-1 symbol) - (a2-1 (pointer process-tree)) - (a3-1 (pointer process-tree)) - (t0-0 (pointer process-tree)) - (t1-0 (pointer process-tree)) - (t1-3 (pointer process-tree)) - (t1-4 (pointer process-tree)) - (t1-7 (pointer process-tree)) - (t1-8 (pointer process-tree)) - (t1-12 (pointer process-tree)) - (t1-13 (pointer process-tree)) - (t1-17 (pointer process-tree))) - (when (and arg0 (!= (-> arg0 brother) arg1) (!= arg0 arg1)) - (set! a2-1 (-> arg0 parent)) - (when a2-1 - (set! t0-0 (-> a2-1 0 child)) - (set! a3-1 '#f) - (set! v1-4 '#f) - (set! t1-0 t0-0) - (when (= (if t1-0 (-> t1-0 0 self)) arg0) - (set! a3-1 a2-1) - (set! t1-3 a3-1)) - (set! t1-4 t0-0) - (when (= (if t1-4 (-> t1-4 0 self)) arg1) - (set! v1-4 a2-1) - (set! t1-7 v1-4)) - (while (and (-> t0-0 0 brother) (or (not a3-1) (not v1-4))) - (set! t1-8 t0-0) - (when (= (-> (if t1-8 (-> t1-8 0 self)) brother) arg1) - (set! v1-4 t0-0) - (set! t1-12 v1-4)) - (set! t1-13 t0-0) - (when (= (-> (if t1-13 (-> t1-13 0 self)) brother) arg0) - (set! a3-1 t0-0) - (set! t1-17 a3-1)) - (set! t0-0 (-> t0-0 0 brother))) - (if (or (not a3-1) (not v1-4)) - (return 0) - (if (= a3-1 a2-1) - (set! (-> a3-1 4) (the process-tree (-> arg0 brother))) ;; wrong - (set! (-> a3-1 3) (the process-tree (-> arg0 brother))) ;; wrong - )) - (cond - ((= v1-4 a2-1) - (set! (-> arg0 brother) (the (pointer process-tree) (-> v1-4 4))) ;; wrong - (set! (-> v1-4 4) (the process-tree (-> arg0 ppointer))) ;; wrong - ) - (else - (set! (-> arg0 brother) (the (pointer process-tree) (-> v1-4 3))) - (set! (-> v1-4 3) (the process-tree (-> arg0 ppointer))))))) - (the-as process-tree arg0)) +(defun change-brother ((new-brother process-tree) (old-brother process-tree)) + "Unused and wrong. + Seems like this assumes a process stores a `process-tree` reference directly, not `(poitner process-tree)`" + (when (and new-brother (!= (-> new-brother brother) old-brother) (!= new-brother old-brother)) + (let ((parent (-> new-brother parent))) + (when parent + (let ((it (-> parent 0 child)) + (new-bro-pred (the-as (pointer process-tree) #f)) + (old-bro-pred (the-as (pointer process-tree) #f))) + (if (= (ppointer->process it) new-brother) (set! new-bro-pred parent)) + (if (= (ppointer->process it) old-brother) (set! old-bro-pred parent)) + (while (and (-> it 0 brother) (or (not new-bro-pred) (not old-bro-pred))) + (if (= (-> (ppointer->process it) brother) old-brother) (set! old-bro-pred it)) + (if (= (-> (ppointer->process it) brother) new-brother) (set! new-bro-pred it)) + (set! it (-> it 0 brother))) + (cond + ((or (not new-bro-pred) (not old-bro-pred)) (return 0)) + ((= new-bro-pred parent) (set! (-> new-bro-pred 4) (the-as process-tree (-> new-brother brother)))) + (else (set! (-> new-bro-pred 3) (the-as process-tree (-> new-brother brother))))) + (cond + ((= old-bro-pred parent) + (set! (-> new-brother brother) (the-as (pointer process-tree) (-> old-bro-pred 4))) + (set! (-> old-bro-pred 4) (the-as process-tree (-> new-brother ppointer)))) + (else + (set! (-> new-brother brother) (the-as (pointer process-tree) (-> old-bro-pred 3))) + (set! (-> old-bro-pred 3) (the-as process-tree (-> new-brother ppointer))))))))) + new-brother) -(defun change-to-last-brother ((arg0 process-tree)) - (local-vars (v1-4 (pointer process-tree)) (v1-8 symbol) (a1-0 (pointer process-tree)) (a1-5 symbol) (a1-9 symbol)) - (when (and (-> arg0 brother) (-> arg0 parent)) - (set! a1-0 (-> arg0 parent)) - (set! v1-4 (-> a1-0 0 child)) - (cond - ((= (-> v1-4 0) arg0) (set! (-> a1-0 0 child) (-> arg0 brother))) - (else - (while (!= (-> v1-4 0 brother 0) arg0) - (nop!) - (nop!) - (nop!) - (nop!) - (set! v1-4 (-> v1-4 0 brother))) - (set! (-> v1-4 0 brother) (-> arg0 brother)))) - (while (-> v1-4 0 brother) - (nop!) - (nop!) - (nop!) - (nop!) - (set! v1-4 (-> v1-4 0 brother))) - (set! (-> v1-4 0 brother) (-> arg0 ppointer)) - (set! (-> arg0 brother) '#f)) - arg0) + +(defun change-to-last-brother ((proc process-tree)) + "Move this process to the last spot in its list of brothers" + (when (and (-> proc brother) (-> proc parent)) + (let* ((parent (-> proc parent)) + (it (-> parent 0 child))) + (cond + ((= (-> it 0) proc) (set! (-> parent 0 child) (-> proc brother))) + (else + (while (!= (-> it 0 brother 0) proc) + (nop!) + (nop!) + (nop!) + (nop!) + (set! it (-> it 0 brother))) + (set! (-> it 0 brother) (-> proc brother)))) + (while (-> it 0 brother) + (nop!) + (nop!) + (nop!) + (nop!) + (set! it (-> it 0 brother))) + (set! (-> it 0 brother) (-> proc ppointer))) + (set! (-> proc brother) (the-as (pointer process-tree) #f))) + proc) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Process Control