[decomp] fisher and FIN.DGO (finalboss) level (#899)

* decomp `fisher`, `robotboss`, `light-eco`, `green-eco-lurker`, `sage-finalboss`, `robotboss-weapon`, `robotboss-misc`

* fixes

* add files

* add `:states` list to `deftype` and fix files

* test state forward decl's on a few more types

* also the refs

* add light-eco

* whatever
This commit is contained in:
ManDude
2021-10-16 19:06:33 +01:00
committed by GitHub
parent 9225d28444
commit caac740aff
185 changed files with 30529 additions and 4422 deletions
+39 -30
View File
@@ -327,16 +327,12 @@ goos::Object decomp_ref_to_inline_array_guess_size(
int my_seg,
int field_location,
const TypeSystem& ts,
const Field& data_field,
const std::vector<std::vector<LinkedWord>>& all_words,
const LinkedObjectFile* file,
const TypeSpec& array_elt_type,
int stride) {
// fmt::print("Decomp decomp_ref_to_inline_array_guess_size {}\n", array_elt_type.print());
// verify that the field is the right type.
assert(data_field.type() == TypeSpec("inline-array", {array_elt_type}));
// verify the stride matches the type system
auto elt_type_info = ts.lookup_type(array_elt_type);
assert(stride == align(elt_type_info->get_size_in_memory(),
@@ -425,12 +421,10 @@ goos::Object ocean_near_indices_decompile(const std::vector<LinkedWord>& words,
int my_seg,
int field_location,
const TypeSystem& ts,
const Field& data_field,
const std::vector<std::vector<LinkedWord>>& all_words,
const LinkedObjectFile* file) {
return decomp_ref_to_inline_array_guess_size(words, labels, my_seg, field_location, ts,
data_field, all_words, file,
TypeSpec("ocean-near-index"), 32);
return decomp_ref_to_inline_array_guess_size(words, labels, my_seg, field_location, ts, all_words,
file, TypeSpec("ocean-near-index"), 32);
}
goos::Object ocean_mid_masks_decompile(const std::vector<LinkedWord>& words,
@@ -438,12 +432,10 @@ goos::Object ocean_mid_masks_decompile(const std::vector<LinkedWord>& words,
int my_seg,
int field_location,
const TypeSystem& ts,
const Field& data_field,
const std::vector<std::vector<LinkedWord>>& all_words,
const LinkedObjectFile* file) {
return decomp_ref_to_inline_array_guess_size(words, labels, my_seg, field_location, ts,
data_field, all_words, file,
TypeSpec("ocean-mid-mask"), 8);
return decomp_ref_to_inline_array_guess_size(words, labels, my_seg, field_location, ts, all_words,
file, TypeSpec("ocean-mid-mask"), 8);
}
goos::Object sp_field_init_spec_decompile(const std::vector<LinkedWord>& words,
@@ -451,12 +443,10 @@ goos::Object sp_field_init_spec_decompile(const std::vector<LinkedWord>& words,
int my_seg,
int field_location,
const TypeSystem& ts,
const Field& data_field,
const std::vector<std::vector<LinkedWord>>& all_words,
const LinkedObjectFile* file) {
return decomp_ref_to_inline_array_guess_size(words, labels, my_seg, field_location, ts,
data_field, all_words, file,
TypeSpec("sp-field-init-spec"), 16);
return decomp_ref_to_inline_array_guess_size(words, labels, my_seg, field_location, ts, all_words,
file, TypeSpec("sp-field-init-spec"), 16);
}
goos::Object sp_launch_grp_launcher_decompile(const std::vector<LinkedWord>& words,
@@ -464,12 +454,10 @@ goos::Object sp_launch_grp_launcher_decompile(const std::vector<LinkedWord>& wor
int my_seg,
int field_location,
const TypeSystem& ts,
const Field& data_field,
const std::vector<std::vector<LinkedWord>>& all_words,
const LinkedObjectFile* file) {
return decomp_ref_to_inline_array_guess_size(words, labels, my_seg, field_location, ts,
data_field, all_words, file,
TypeSpec("sparticle-group-item"), 32);
return decomp_ref_to_inline_array_guess_size(words, labels, my_seg, field_location, ts, all_words,
file, TypeSpec("sparticle-group-item"), 32);
}
} // namespace
@@ -658,19 +646,19 @@ goos::Object decompile_structure(const TypeSpec& type,
// first, get the label:
field_defs_out.emplace_back(
field.name(), ocean_near_indices_decompile(obj_words, labels, label.target_segment,
field_start, ts, field, words, file));
field_start, ts, words, file));
} else if (field.name() == "data" && type.print() == "ocean-mid-masks") {
field_defs_out.emplace_back(
field.name(), ocean_mid_masks_decompile(obj_words, labels, label.target_segment,
field_start, ts, field, words, file));
field_start, ts, words, file));
} else if (field.name() == "init-specs" && type.print() == "sparticle-launcher") {
field_defs_out.emplace_back(
field.name(), sp_field_init_spec_decompile(obj_words, labels, label.target_segment,
field_start, ts, field, words, file));
field_start, ts, words, file));
} else if (field.name() == "launcher" && type.print() == "sparticle-launch-group") {
field_defs_out.emplace_back(field.name(), sp_launch_grp_launcher_decompile(
obj_words, labels, label.target_segment,
field_start, ts, field, words, file));
field_start, ts, words, file));
} else {
if (field.type().base_type() == "pointer") {
if (obj_words.at(field_start / 4).kind != LinkedWord::SYM_PTR) {
@@ -950,15 +938,18 @@ goos::Object decompile_value(const TypeSpec& type,
}
} else if (type == TypeSpec("seconds")) {
assert(bytes.size() == 8);
u64 value;
s64 value;
memcpy(&value, bytes.data(), 8);
// only rewrite if exact.
u64 seconds = value / TICKS_PER_SECOND;
if (seconds * TICKS_PER_SECOND == value) {
return pretty_print::to_symbol(fmt::format("(seconds {})", seconds));
s64 seconds_int = value / TICKS_PER_SECOND;
if (seconds_int * TICKS_PER_SECOND == value) {
return pretty_print::to_symbol(fmt::format("(seconds {})", seconds_int));
}
double seconds = (double)value / TICKS_PER_SECOND;
if (seconds * TICKS_PER_SECOND == value) {
return pretty_print::build_list("seconds", pretty_print::float_representation(seconds));
}
return pretty_print::to_symbol(fmt::format("#x{:x}", value));
} else if (ts.tc(TypeSpec("uint64"), type)) {
assert(bytes.size() == 8);
@@ -1070,6 +1061,23 @@ goos::Object decompile_boxed_array(const DecompilerLabel& label,
}
}
return pretty_print::build_list(result);
} else if (content_type.base_type() == "inline-array") {
std::vector<goos::Object> result = {
pretty_print::to_symbol("new"), pretty_print::to_symbol("'static"),
pretty_print::to_symbol("'boxed-array"),
pretty_print::to_symbol(fmt::format(":type {} :length {} :allocated-length {}",
content_type.print(), array_length,
array_allocated_length))};
for (int elt = 0; elt < array_length; elt++) {
auto& word = words.at(label.target_segment).at(first_elt_word_idx + elt);
auto segment = labels.at(word.label_id).target_segment;
result.push_back(decomp_ref_to_inline_array_guess_size(
words.at(segment), labels, segment, (first_elt_word_idx + elt) * 4, ts, words, file,
content_type.get_single_arg(), ts.get_deref_info(content_type).stride));
}
return pretty_print::build_list(result);
} else {
// value array
@@ -1088,7 +1096,8 @@ goos::Object decompile_boxed_array(const DecompilerLabel& label,
for (int j = start; j < end; j++) {
auto& word = words.at(label.target_segment).at(j / 4);
if (word.kind != LinkedWord::PLAIN_DATA) {
throw std::runtime_error("Got bad word in kind in array of values");
throw std::runtime_error(
fmt::format("Got bad word of kind {} in boxed array of values", word.kind));
}
elt_bytes.push_back(word.get_byte(j % 4));
}