2020-09-13 21:32:55 -04:00
|
|
|
#pragma once
|
|
|
|
|
2022-06-22 23:37:46 -04:00
|
|
|
#include <optional>
|
2020-08-22 23:30:17 -04:00
|
|
|
#include <string>
|
2020-12-17 15:48:07 -05:00
|
|
|
#include <unordered_map>
|
2022-06-22 23:37:46 -04:00
|
|
|
#include <unordered_set>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "common/common_types.h"
|
2022-07-29 20:10:11 -04:00
|
|
|
#include "common/util/FileUtil.h"
|
2023-04-22 14:13:57 -04:00
|
|
|
#include "common/versions/versions.h"
|
2022-06-22 23:37:46 -04:00
|
|
|
|
2020-12-17 15:48:07 -05:00
|
|
|
#include "decompiler/Disasm/Register.h"
|
2021-12-26 11:43:16 -05:00
|
|
|
#include "decompiler/data/game_text.h"
|
2020-12-17 15:48:07 -05:00
|
|
|
|
2021-01-06 20:04:15 -05:00
|
|
|
namespace decompiler {
|
2021-06-04 13:43:19 -04:00
|
|
|
struct RegisterTypeCast {
|
2021-03-13 16:10:39 -05:00
|
|
|
int atomic_op_idx = -1;
|
2020-12-17 15:48:07 -05:00
|
|
|
Register reg;
|
|
|
|
std::string type_name;
|
|
|
|
};
|
2020-08-22 23:30:17 -04:00
|
|
|
|
2021-06-04 13:43:19 -04:00
|
|
|
struct StackTypeCast {
|
|
|
|
int stack_offset = -1;
|
|
|
|
std::string type_name;
|
|
|
|
};
|
|
|
|
|
2021-08-29 11:13:06 -04:00
|
|
|
struct LabelConfigInfo {
|
|
|
|
// if the label is a "value" type, it will be loaded directly into a register.
|
|
|
|
// in all cases, this is a constant, either a 64-bit integer or a float.
|
|
|
|
// For example:
|
|
|
|
// ld v1, L346(fp)
|
|
|
|
// lwc1 f0, L345(fp)
|
|
|
|
// lw a0, L41(fp)
|
|
|
|
|
|
|
|
// if the label is not a value type, it's a reference type, and the GOAL variable is a pointer.
|
|
|
|
bool is_value = false;
|
|
|
|
|
|
|
|
// the type of the resulting GOAL variable.
|
2021-02-20 11:42:46 -05:00
|
|
|
std::string type_name;
|
2021-08-29 11:13:06 -04:00
|
|
|
|
|
|
|
// if the type is a (pointer x) or (inline-array x), the size must be specified here.
|
|
|
|
// For a boxed array (array x), the size will be figured out automatically
|
2021-02-27 14:40:18 -05:00
|
|
|
std::optional<int> array_size;
|
2021-02-20 11:42:46 -05:00
|
|
|
};
|
|
|
|
|
2021-03-13 16:10:39 -05:00
|
|
|
struct LocalVarOverride {
|
|
|
|
std::string name;
|
|
|
|
// this may be left out, indicating that the variable should use the type determined
|
|
|
|
// by the type analysis pass.
|
|
|
|
std::optional<std::string> type;
|
|
|
|
};
|
|
|
|
|
2021-03-27 15:18:59 -04:00
|
|
|
/*!
|
2021-06-04 13:43:19 -04:00
|
|
|
* Information about a structure on the stack.
|
2021-03-27 15:18:59 -04:00
|
|
|
*/
|
2021-06-04 13:43:19 -04:00
|
|
|
struct StackStructureHint {
|
2021-03-27 15:18:59 -04:00
|
|
|
std::string element_type; // type of the thing stored
|
|
|
|
// todo - is boxed array on the stack supported?
|
|
|
|
enum class ContainerType {
|
|
|
|
NONE, // just store the plain thing.
|
|
|
|
ARRAY, // for refs, array of refs. For values, array of values.
|
|
|
|
INLINE_ARRAY // for refs, array of values, for values, invalid
|
|
|
|
} container_type = ContainerType::NONE;
|
|
|
|
int container_size = -1; // if container other than NONE, the number of elements.
|
|
|
|
int stack_offset = 0; // where it's located on the stack (relative to sp after prologue)
|
|
|
|
};
|
|
|
|
|
2021-05-24 19:52:19 -04:00
|
|
|
struct CondWithElseLengthHack {
|
|
|
|
std::unordered_map<std::string, int> max_length_by_start_block;
|
|
|
|
};
|
|
|
|
|
2021-05-11 20:49:54 -04:00
|
|
|
struct DecompileHacks {
|
|
|
|
std::unordered_set<std::string> types_with_bad_inspect_methods;
|
|
|
|
std::unordered_set<std::string> no_type_analysis_functions_by_name;
|
|
|
|
std::unordered_set<std::string> hint_inline_assembly_functions;
|
|
|
|
std::unordered_set<std::string> asm_functions_by_name;
|
|
|
|
std::unordered_set<std::string> pair_functions_by_name;
|
2021-05-24 19:52:19 -04:00
|
|
|
std::unordered_map<std::string, CondWithElseLengthHack> cond_with_else_len_by_func_name;
|
2021-05-30 19:57:11 -04:00
|
|
|
std::unordered_set<std::string> reject_cond_to_value;
|
2021-07-05 16:07:07 -04:00
|
|
|
std::unordered_map<std::string, std::unordered_set<int>> blocks_ending_in_asm_branch_by_func_name;
|
2021-09-06 20:35:03 -04:00
|
|
|
std::unordered_map<std::string, std::vector<std::vector<int>>>
|
|
|
|
format_ops_with_dynamic_string_by_func_name;
|
2021-09-11 20:52:35 -04:00
|
|
|
std::unordered_set<std::string> mips2c_functions_by_name;
|
2022-01-28 21:32:03 -05:00
|
|
|
std::unordered_map<std::string, std::vector<int>> mips2c_jump_table_functions;
|
2021-12-04 12:33:18 -05:00
|
|
|
std::unordered_map<std::string, std::vector<std::pair<int, int>>> missing_textures_by_level;
|
2021-05-11 20:49:54 -04:00
|
|
|
};
|
|
|
|
|
2022-06-22 00:16:34 -04:00
|
|
|
struct ObjectPatchInfo {
|
|
|
|
u32 crc;
|
|
|
|
std::string target_file;
|
|
|
|
std::string patch_file;
|
|
|
|
};
|
|
|
|
|
2020-08-22 23:30:17 -04:00
|
|
|
struct Config {
|
2022-06-06 17:58:49 -04:00
|
|
|
GameVersion game_version = GameVersion::Jak1;
|
2020-08-22 23:30:17 -04:00
|
|
|
std::vector<std::string> dgo_names;
|
2020-11-19 21:22:16 -05:00
|
|
|
std::vector<std::string> object_file_names;
|
2020-11-21 15:58:51 -05:00
|
|
|
std::vector<std::string> str_file_names;
|
2023-07-23 12:35:59 -04:00
|
|
|
std::vector<std::string> str_texture_file_names;
|
2021-05-11 20:49:54 -04:00
|
|
|
|
2021-07-18 19:28:56 -04:00
|
|
|
std::string audio_dir_file_name;
|
|
|
|
std::vector<std::string> streamed_audio_file_names;
|
|
|
|
|
2020-10-24 14:27:50 -04:00
|
|
|
std::string obj_file_name_map_file;
|
2022-06-06 17:58:49 -04:00
|
|
|
std::string all_types_file;
|
2021-05-11 19:19:23 -04:00
|
|
|
|
|
|
|
bool disassemble_code = false;
|
|
|
|
bool decompile_code = false;
|
2020-08-22 23:30:17 -04:00
|
|
|
bool write_scripts = false;
|
2021-05-11 19:19:23 -04:00
|
|
|
bool disassemble_data = false;
|
2020-11-16 19:57:45 -05:00
|
|
|
bool process_tpages = false;
|
2020-11-19 21:22:16 -05:00
|
|
|
bool process_game_text = false;
|
2020-11-24 20:48:38 -05:00
|
|
|
bool process_game_count = false;
|
2022-05-19 21:30:14 -04:00
|
|
|
bool process_art_groups = false;
|
2023-03-22 17:31:13 -04:00
|
|
|
bool process_subtitle_text = false;
|
|
|
|
bool process_subtitle_images = false;
|
2023-01-04 18:26:59 -05:00
|
|
|
bool dump_art_group_info = false;
|
2023-10-06 10:42:16 -04:00
|
|
|
bool dump_joint_geo_info = false;
|
2021-12-30 18:48:37 -05:00
|
|
|
bool rip_levels = false;
|
2022-04-25 21:53:23 -04:00
|
|
|
bool extract_collision = false;
|
2022-06-08 18:34:52 -04:00
|
|
|
bool find_functions = false;
|
2023-03-22 17:31:13 -04:00
|
|
|
bool read_spools = false;
|
2024-01-25 21:28:47 -05:00
|
|
|
bool ignore_var_name_casts = false;
|
2021-05-11 19:19:23 -04:00
|
|
|
|
|
|
|
bool write_hex_near_instructions = false;
|
|
|
|
bool hexdump_code = false;
|
|
|
|
bool hexdump_data = false;
|
2020-11-24 20:48:38 -05:00
|
|
|
bool dump_objs = false;
|
2021-05-24 19:52:19 -04:00
|
|
|
bool print_cfgs = false;
|
2021-05-11 19:19:23 -04:00
|
|
|
|
2021-05-31 10:43:25 -04:00
|
|
|
bool generate_symbol_definition_map = false;
|
|
|
|
|
2022-06-25 21:26:15 -04:00
|
|
|
bool generate_all_types = false;
|
|
|
|
std::optional<std::string> old_all_types_file;
|
|
|
|
|
2021-10-15 18:17:51 -04:00
|
|
|
bool is_pal = false;
|
2022-06-22 00:16:34 -04:00
|
|
|
|
|
|
|
bool write_patches = false;
|
|
|
|
bool apply_patches = false;
|
|
|
|
|
2022-02-04 18:37:48 -05:00
|
|
|
std::string game_name;
|
2022-02-12 17:48:50 -05:00
|
|
|
std::string expected_elf_name;
|
2021-12-26 11:43:16 -05:00
|
|
|
GameTextVersion text_version = GameTextVersion::JAK1_V1;
|
|
|
|
|
2021-02-01 20:41:37 -05:00
|
|
|
std::unordered_set<std::string> allowed_objects;
|
2021-09-21 18:40:38 -04:00
|
|
|
std::unordered_set<std::string> banned_objects;
|
2022-01-04 20:32:34 -05:00
|
|
|
std::unordered_set<std::string> merged_objects;
|
2021-06-04 13:43:19 -04:00
|
|
|
std::unordered_map<std::string, std::unordered_map<int, std::vector<RegisterTypeCast>>>
|
|
|
|
register_type_casts_by_function_by_atomic_op_idx;
|
|
|
|
std::unordered_map<std::string, std::unordered_map<int, StackTypeCast>>
|
|
|
|
stack_type_casts_by_function_by_stack_offset;
|
2020-12-26 11:09:59 -05:00
|
|
|
std::unordered_map<std::string, std::unordered_map<int, std::string>>
|
|
|
|
anon_function_types_by_obj_by_id;
|
2021-02-09 20:59:14 -05:00
|
|
|
std::unordered_map<std::string, std::vector<std::string>> function_arg_names;
|
2021-03-13 16:10:39 -05:00
|
|
|
std::unordered_map<std::string, std::unordered_map<std::string, LocalVarOverride>>
|
|
|
|
function_var_overrides;
|
2021-08-29 11:13:06 -04:00
|
|
|
std::unordered_map<std::string, std::unordered_map<std::string, LabelConfigInfo>> label_types;
|
2021-06-04 13:43:19 -04:00
|
|
|
std::unordered_map<std::string, std::vector<StackStructureHint>>
|
|
|
|
stack_structure_hints_by_function;
|
2022-06-22 00:16:34 -04:00
|
|
|
std::unordered_map<std::string, ObjectPatchInfo> object_patches;
|
2021-04-26 21:40:08 -04:00
|
|
|
|
2021-07-01 21:38:19 -04:00
|
|
|
std::unordered_map<std::string, int> bad_format_strings;
|
|
|
|
|
2023-07-14 18:17:54 -04:00
|
|
|
std::unordered_set<std::string> animated_textures;
|
2023-07-23 12:35:59 -04:00
|
|
|
std::unordered_set<int> common_tpages;
|
2023-07-14 18:17:54 -04:00
|
|
|
|
2021-12-04 12:33:18 -05:00
|
|
|
std::vector<std::string> levels_to_extract;
|
2022-02-04 18:37:48 -05:00
|
|
|
bool levels_extract;
|
2023-08-13 16:06:59 -04:00
|
|
|
bool save_texture_pngs = false;
|
2021-12-04 12:33:18 -05:00
|
|
|
|
2021-05-11 20:49:54 -04:00
|
|
|
DecompileHacks hacks;
|
2022-05-19 21:30:14 -04:00
|
|
|
|
2023-10-06 10:42:16 -04:00
|
|
|
std::unordered_map<std::string, std::string> art_group_type_remap;
|
2023-11-04 14:25:13 -04:00
|
|
|
std::unordered_map<std::string, std::unordered_map<std::string, std::string>>
|
|
|
|
art_group_file_override;
|
2023-01-15 11:33:39 -05:00
|
|
|
std::unordered_map<std::string, std::unordered_map<int, std::string>> art_group_info_dump;
|
2023-10-06 10:42:16 -04:00
|
|
|
std::unordered_map<std::string, std::unordered_map<int, std::string>> jg_info_dump;
|
|
|
|
std::unordered_map<std::string, std::string> joint_node_hacks;
|
2022-05-23 18:53:02 -04:00
|
|
|
|
|
|
|
std::unordered_map<std::string, std::vector<std::string>> import_deps_by_file;
|
2024-01-29 16:15:42 -05:00
|
|
|
|
|
|
|
bool rip_collision = false;
|
2020-08-22 23:30:17 -04:00
|
|
|
};
|
|
|
|
|
2022-07-31 19:25:18 -04:00
|
|
|
Config read_config_file(const fs::path& path_to_config_file,
|
2023-03-08 20:07:26 -05:00
|
|
|
const std::string& config_game_version,
|
2022-07-31 19:25:18 -04:00
|
|
|
const std::string& override_json = "{}");
|
2021-03-27 15:18:59 -04:00
|
|
|
|
2021-01-06 20:04:15 -05:00
|
|
|
} // namespace decompiler
|