![]() |
V-Gears 0
Free Final Fantasy VII engine.
|
A disassebler for field maps. More...
#include <FieldDisassembler.h>
Classes | |
struct | InstructionRecord |
Information about an instruction. More... | |
struct | ScriptHeader |
A script header. More... | |
struct | ScriptInfo |
Info about a script. More... | |
Public Member Functions | |
FieldDisassembler (FieldScriptFormatter &formatter, FieldEngine *engine, InstVec &insts) | |
Constructor. More... | |
FieldDisassembler (FieldScriptFormatter &formatter, FieldEngine *engine, InstVec &insts, const std::vector< unsigned char > &raw_script_data) | |
Constructor. More... | |
~FieldDisassembler () | |
Destructor. More... | |
float | GetScaleFactor () const |
Retrieves the scale factor for the field. More... | |
virtual void | DoDisassemble () override |
Disassembles the instructions. More... | |
![]() | |
Disassembler (InstVec &insts) | |
Constructor for Disassembler. More... | |
virtual | ~Disassembler ()=default |
Destructor. More... | |
virtual void | Open (const char *filename) |
Open a file for disassembly. More... | |
void | Disassemble () |
Request disassembled instructions. More... | |
void | DumpDisassembly (std::ostream &output) |
Outputs the disassembled code. More... | |
Static Public Member Functions | |
static std::map< std::string, const InstructionRecord * > | FieldInstructions () |
Generates a map of control flow instructions. More... | |
static int | FindId (uint32 start_addr, uint32 end_addr, const InstVec &insts) |
Finds the ID of the character a function refers to. More... | |
Static Public Attributes | |
static InstructionRecord | FLOW_OPCODES [] |
A list of flow control opcodes needed by the disassembler. More... | |
Private Types | |
enum | SECTIONS { SCRIPT = 0 , WALKMESH = 1 , TILE_MAP = 2 , CAMERA_MATRIX = 3 , TRIGGERS = 4 , ENCOUNTERS = 5 , MODELS = 6 } |
The sections of a field. More... | |
Private Member Functions | |
virtual void | Open (const char *filename) override |
Open a file for disassembly. More... | |
void | DisassembleIndivdualScript (std::string entity_name, size_t entity_index, size_t script_index, size_t script_entry_point, uint32 next_script_entry_point, bool is_start, bool is_end) |
Disassembles a script (function). More... | |
void | AddFunc (std::string entity_name, size_t entity_index, size_t script_index, uint32 next_script_entry_point, const bool is_start, const bool is_end, bool to_return_only, std::string func_name) |
Adds a function to the engine. More... | |
bool | ReadOpCodesToPositionOrReturn (size_t end_pos, std::vector< float > &point_a, std::vector< float > &point_b) |
Reads opcodes from a script, and detects lines. More... | |
std::unique_ptr< Function > | StartFunction (size_t script_index) |
Initializes a function for an entity. More... | |
void | ReadHeader () |
Reads the header. More... | |
void | ReadHeader (BinaryReader &reader) |
Reads the header. More... | |
uint32 | GetEndOfScriptOffset (uint16 cur_entry_point, size_t entity_index, size_t script_index) |
Retrieves the offset of the end of a script. More... | |
template<typename T > | |
void | ParseOpcode (int opcode, std::string name, T instruction, int stack_change, const char *argument_format) |
Parses an opcode. More... | |
Private Attributes | |
FieldEngine * | engine_ |
The engine. More... | |
uint32 | header_end_position_ = 0 |
Last address of the header. More... | |
std::array< uint32, 7 > | sections_ |
The list of sections. More... | |
int16 | section_pointers_size_ |
Size of the pointers to sections. More... | |
ScriptHeader | header_ |
The field header. More... | |
bool | loaded_from_raw_data_ = false |
Indicates if the field has been loaded from raw data. More... | |
FieldScriptFormatter & | formatter_ |
The formatter. More... | |
float | scale_factor_ = 1.0f |
The scale factor of the field. More... | |
Static Private Attributes | |
static const int | MAGIC |
Field file identification magic number. More... | |
static const int | NUM_SECTIONS |
The number of sections in a field. More... | |
Additional Inherited Members | |
![]() | |
virtual void | DoDisassemble ()=0 |
Performs disassembly. More... | |
virtual void | DoDumpDisassembly (std::ostream &output) |
Outputs the disassembled code. More... | |
void | ReadParams (InstPtr inst, const char *types) |
Read parameters and associate them with an instruction. More... | |
void | ReadParams (InstPtr inst, const char *types, const std::vector< std::string > ¶ms) |
Read parameters but it doesn't associate them with an instruction. More... | |
virtual ValuePtr | ReadParameter (InstPtr inst, std::string type) |
Reads data for a single parameter. More... | |
![]() | |
std::unique_ptr< BinaryReader > | stream_ |
Used to perform file I/O. More... | |
InstVec & | insts_ |
List of disassembled instructions. More... | |
uint32 | address_base_ |
Base address where the script starts. More... | |
uint32 | address_ |
The current address. More... | |
A disassebler for field maps.
|
private |
FieldDisassembler::FieldDisassembler | ( | FieldScriptFormatter & | formatter, |
FieldEngine * | engine, | ||
InstVec & | insts | ||
) |
Constructor.
[in] | formatter | The code formatter. |
[in] | engine | The engine to use to disassemble. |
[in] | insts | The list of instructions. |
FieldDisassembler::FieldDisassembler | ( | FieldScriptFormatter & | formatter, |
FieldEngine * | engine, | ||
InstVec & | insts, | ||
const std::vector< unsigned char > & | raw_script_data | ||
) |
Constructor.
[in] | formatter | The code formatter. |
[in] | engine | The engine to use to disassemble. |
[in] | insts | The list of instructions. |
[in] | raw_script_data |
FieldDisassembler::~FieldDisassembler | ( | ) |
Destructor.
|
private |
Adds a function to the engine.
[in] | entity_name | Name of the entity that owns the function. |
[in] | entity_index | Index of the entity that owns the function. |
[in] | script_index | Index of the script within the entity. |
[in] | next_script_entry_point | Start position of the next script (or the ending position of this one, plus one). |
[in] | is_start |
[in] | is_end |
[in] | to_return_only | True to read the script only until the first return. |
[in] | func_name | Name of the function. If the entity is a line, the provided name will be overridden and set to the standard line entity script names. |
|
private |
Disassembles a script (function).
[in] | entity_name | Name of the entity the script belongs to. |
[in] | entity_index | Index of the entity the script belongs to. |
[in] | script_index | Index of the script, relative to the entity scripts. |
[in] | script_entry_point | Address of the first instruction of the script to disassemble. |
[in] | next_script_entry_point | Address of the first instruction of the script next to the one to disassemble (i.e. the last address of the script to disassemble, plus one). |
[in] | is_start | Indicates if the script is the first one for it's entity. |
[in] | is_end | Indicates if the script is the last one for it's entity. |
DecompilerException | for malformed scripts. |
|
overridevirtual |
Disassembles the instructions.
Implements Disassembler.
|
static |
Generates a map of control flow instructions.
Finds the ID of the character a function refers to.
[in] | start_addr | The starting address of the function. |
[in] | end_addr | The ending address of the instruction. |
[in] | insts | The list of instructions to search. |
|
private |
Retrieves the offset of the end of a script.
[in] | cur_entry_point |
[in] | entity_index | Index of the entity the script belongs to. |
[in] | script_index | The script index. |
float FieldDisassembler::GetScaleFactor | ( | ) | const |
Retrieves the scale factor for the field.
|
overrideprivatevirtual |
Open a file for disassembly.
[in] | filename | The file to disassemble. |
Reimplemented from Disassembler.
|
inlineprivate |
Parses an opcode.
Adds properties to an instruction, and adds the instruction to the list.
[in] | opcode | The opcode code. |
[in] | name | the opcode name. |
[in] | instruction | A newly created instruction of the type the opcode belongs to. |
[in] | stack_change | Indicates how much the instruction changes the stack pointer by. |
[in] | argument_format | The opcode argument format. |
|
private |
Reads the header.
|
private |
Reads the header.
[in] | reader | Reader to use to read. |
|
private |
Reads opcodes from a script, and detects lines.
It stops when it reaches the ending position or a RET opcode, whatever comes first. It also detects if one of the read opcodes LINE, which means that the entity is a line
[in] | end_pos | The last position to read. Opcodes will be read until this, or until a RET is found. |
[out] | point_a | If a LINE opcode is found, the first point will be saved here. |
[out] | point_b | If a LINE opcode is found, the second point will be saved here. |
|
private |
Initializes a function for an entity.
[in] | script_index | Index of the script. |
|
private |
The engine.
|
static |
A list of flow control opcodes needed by the disassembler.
|
private |
The formatter.
|
private |
The field header.
|
private |
Last address of the header.
|
private |
Indicates if the field has been loaded from raw data.
|
staticprivate |
Field file identification magic number.
|
staticprivate |
The number of sections in a field.
|
private |
The scale factor of the field.
|
private |
Size of the pointers to sections.
|
private |
The list of sections.