Skip to content

Commit

Permalink
decomp3: support for virtual states inheriting from their own type's …
Browse files Browse the repository at this point in the history
…virtual states, `gun-yellow-shot`, `gun-red-shot`, `gun-dark-shot` (#3438)
  • Loading branch information
Hat-Kid authored Mar 31, 2024
1 parent afea4f7 commit c96e44a
Show file tree
Hide file tree
Showing 52 changed files with 28,550 additions and 367 deletions.
37 changes: 31 additions & 6 deletions decompiler/analysis/find_defstates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,21 @@ FormElement* rewrite_virtual_defstate(
inherit_info = {{mot_mr.maps.strings.at(0), mot_mr.maps.strings.at(1)}};
}

// jak 3: some virtual states set their parent here and inherit from their own type's states...
std::string maybe_parent_state;
std::string maybe_state_type;
auto maybe_parent = elt->body()->at(body_idx);
auto maybe_parent_matcher =
Matcher::set(Matcher::deref(Matcher::any_reg(), false, {DerefTokenMatcher::string("parent")}),
Matcher::op(GenericOpMatcher::fixed(FixedOperatorKind::METHOD_OF_TYPE),
{Matcher::any_symbol(0), Matcher::any_constant_token(1)}));
auto maybe_parent_mr = match(maybe_parent_matcher, maybe_parent);
if (maybe_parent_mr.matched) {
maybe_state_type = maybe_parent_mr.maps.strings.at(0);
maybe_parent_state = maybe_parent_mr.maps.strings.at(1);
body_idx++;
}

// checks to check: method type is a state
// if inherit matches expected.

Expand Down Expand Up @@ -411,7 +426,14 @@ FormElement* rewrite_virtual_defstate(
// expected_state_name, type_name);
}
} else {
if (inherit_info) {
// if we set our parent state, check that that state's type and this type are the same
if (inherit_info && maybe_parent_mr.matched && maybe_state_type == type_name) {
env.func->warnings.warning(
"Virtual defstate {} is inheriting from state {} which is one of its own type's "
"states.",
expected_state_name, maybe_parent_state);
}
if (inherit_info && !maybe_parent_mr.matched) {
env.func->warnings.error_and_throw(
"Virtual defstate for state {} in type {}: the state wasn't defined in the "
"parent but was inherited.",
Expand All @@ -421,7 +443,7 @@ FormElement* rewrite_virtual_defstate(
}

// checks: parent_type_name is the parent
if (inherit_info) {
if (inherit_info && !maybe_parent_mr.matched) {
auto child_type_info = env.dts->ts.lookup_type(type_name);
if (child_type_info->get_parent() != inherit_info->parent_type_name) {
env.func->warnings.error_and_throw(
Expand Down Expand Up @@ -451,8 +473,13 @@ FormElement* rewrite_virtual_defstate(
elt->body(), body_idx + 1, env, expected_state_name, elt->entries().at(0).dest,
method_info.type.substitute_for_method_call(type_name), pool, type_name, skip_states);

return pool.alloc_element<DefstateElement>(type_name, expected_state_name, "", entries, true,
state_override);
std::string parent_str;
if (!maybe_parent_state.empty()) {
parent_str = fmt::format("({} {})", type_name, maybe_parent_state);
}

return pool.alloc_element<DefstateElement>(type_name, expected_state_name, parent_str, entries,
true, state_override);
}

FormElement* rewrite_virtual_defstate_with_nonvirtual_inherit(
Expand Down Expand Up @@ -481,8 +508,6 @@ FormElement* rewrite_virtual_defstate_with_nonvirtual_inherit(
// (set! (-> gp-6 exit) (the-as (function object) L251))
// (set! (-> gp-6 trans) (the-as (function object) L253))
// )

// ASSERT(elt->body()->size() > 1);
env.func->warnings.warning("Encountered virtual defstate {} with non-virtual inherit.",
expected_state_name);
// variable at the top of let, contains the static state with name exptected_state_name
Expand Down
509 changes: 241 additions & 268 deletions decompiler/config/jak3/all-types.gc

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion decompiler/config/jak3/ntsc_v1/anonymous_function_types.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,15 @@
[8, "(function string object :behavior process)"],
[12, "(function object :behavior target)"]
],
"gun-yellow-shot": [[59, "(function handle object :behavior process)"]]
"gun-yellow-shot": [[59, "(function handle object :behavior process)"]],
"gun-dark-shot": [
[25, "(function collide-shape-prim none :behavior gravity-spinner)"],
[34, "(function handle float object :behavior process)"]
],
"entity": [
[11, "(function process object)"],
[16, "(function process object)"],
[57, "(function process object)"],
[61, "(function process object)"]
]
}
3 changes: 2 additions & 1 deletion decompiler/config/jak3/ntsc_v1/art_info.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"wings": "jakb-ag",
"lightjak-shield": "jakb-ag",
"freeze-screen": "collectables-ag",
"red-3-sphere": "gun-ag"
"red-3-sphere": "gun-ag",
"gun-dark-3-sphere": "gun-ag"
},

// remap names for types in an entire file (higher priority)
Expand Down
5 changes: 3 additions & 2 deletions decompiler/config/jak3/ntsc_v1/hacks.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
"(method 33 rub-tower)",
"(method 261 crimson-guard)",
"(anon-function 25 volcanox-obs)",
"find-nearest-entity",
"foreground-draw-hud"
],

Expand Down Expand Up @@ -354,7 +353,9 @@
"(method 11 rigid-body-queue)": [0, 6, 7, 9],
"(method 10 rigid-body-queue)": [10, 34, 37],
"(method 9 los-control)": [0, 43],
"load-game-text-info": [19, 20, 21]
"load-game-text-info": [19, 20, 21],
"draw-actor-marks": [8],
"find-nearest-entity": [7, 9]
},

// Sometimes the game might use format strings that are fetched dynamically,
Expand Down
35 changes: 34 additions & 1 deletion decompiler/config/jak3/ntsc_v1/label_types.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -457,5 +457,38 @@
["L443", "uint64", true],
["L405", "attack-info"],
["L450", "uint64", true]
]
],
"gun-dark-shot": [
["L824", "uint64", true],
["L827", "uint64", true],
["L823", "uint64", true],
["L826", "uint64", true],
["L828", "uint64", true],
["L829", "uint64", true],
["L825", "uint64", true],
["L830", "uint64", true],
["L707", "uint64", true],
["L704", "uint64", true],
["L702", "uint64", true],
["L701", "uint64", true],
["L700", "uint64", true],
["L710", "uint64", true],
["L648", "attack-info"],
["L647", "attack-info"],
["L638", "attack-info"],
["L637", "attack-info"],
["L639", "attack-info"],
["L708", "uint64", true],
["L643", "attack-info"],
["L644", "attack-info"],
["L712", "uint64", true],
["L711", "uint64", true],
["L709", "uint64", true],
["L664", "attack-info"],
["L703", "uint64", true],
["L699", "uint64", true],
["L705", "uint64", true],
["L706", "uint64", true]
],
"gun-part": [["L537", "(pointer rgba)", 36]]
}
52 changes: 50 additions & 2 deletions decompiler/config/jak3/ntsc_v1/stack_structures.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,12 @@
[16, "vector"],
[1584, "collide-query"]
],
"(method 19 gun-red-2-shockwave)": [[16, "collide-query"]],
"(method 19 gun-red-2-shockwave)": [
[16, "collide-query"],
[576, "vector"],
[624, "vector"],
[592, "vector"]
],
"(method 23 gun-red-2-shockwave)": [[32, "vector"]],
"(method 24 gun-red-2-shockwave)": [[16, "vector"]],
"gun-fire-red-2": [[16, "gun-red-2-shockwave-init-params"]],
Expand All @@ -497,5 +502,48 @@
[128, "vector"],
[1696, "vector"]
],
"(method 26 gun-red-shot)": [[16, "bounding-box"]]
"(method 26 gun-red-shot)": [[16, "bounding-box"]],
"gun-dark-reaction": [[112, "vector"]],
"gun-fire-red-1": [
[16, "vector"],
[32, "event-message-block"],
[112, "vector"]
],
"(trans expand gun-gravity)": [
[16, "vector"],
[32, "vector"],
[48, "vector"],
[80, "collide-query"],
[624, "matrix"]
],
"gun-fire-dark-3": [[16, "projectile-init-by-other-params"]],
"(trans moving gun-dark-shot)": [[16, "vector"]],
"(enter impact gun-dark-shot)": [
[192, ["array", "collide-shape", 384]],
[96, "vector"]
],
"gravity-spinner-init-by-other": [[32, "vector"]],
"(code zero-g gravity-spinner)": [[112, "vector"]],
"(method 25 gun-dark-3-nuke)": [[16, "matrix"]],
"(code impact-dud gun-dark-3-nuke)": [[16, "explosion-init-params"]],
"(method 54 gun-dark-3-nuke)": [
[32, ["array", "collide-shape", 384]],
[16, "vector"]
],
"(trans impact gun-dark-3-nuke)": [
[96, "gun-dark-3-sphere-init-params"],
[128, "gun-dark-3-sphere-init-params"]
],
"(method 19 gravity-spinner)": [
[176, ["array", "collide-shape", 384]],
[128, "vector"],
[112, "vector"],
[1712, "vector"],
[2288, "vector"]
],
"(method 16 gravity-spinner)": [[32, "vector"]],
"(method 22 gun-gravity)": [
[112, ["array", "collide-shape", 384]],
[16, "vector"]
]
}
Loading

0 comments on commit c96e44a

Please sign in to comment.