V-Gears 0
Free Final Fantasy VII engine.
FieldEngine Class Reference

Represents the FF7 Field engine. More...

#include <FieldEngine.h>

Inheritance diagram for FieldEngine:
Collaboration diagram for FieldEngine:

Classes

class  Entity
 Represents an entity. More...
 

Public Member Functions

 FieldEngine (FieldScriptFormatter &formatter, std::string script_name)
 Constructor. More...
 
 FieldEngine (const FieldEngine &engine)=delete
 Copy constructor, disabled. More...
 
FieldEngineoperator= (const FieldEngine &engine)=delete
 Copy constructor, disabled. More...
 
virtual std::unique_ptr< DisassemblerGetDisassembler (InstVec &insts, const std::vector< unsigned char > &raw_script_data) override
 Retrieves the disasembler. More...
 
virtual std::unique_ptr< DisassemblerGetDisassembler (InstVec &insts) override
 Retrieves the dissasembler. More...
 
virtual std::unique_ptr< CodeGeneratorGetCodeGenerator (const InstVec &insts, std::ostream &output) override
 Retrieves the code generator. More...
 
virtual void PostCFG (InstVec &insts, Graph graph) override
 Post-processing actions to apply to the scripts. More...
 
virtual bool UsePureGrouping () const override
 Indicates if instructions are purely grouped. More...
 
std::map< std::string, int > GetEntities () const
 Retrieves all entities in the map. More...
 
std::vector< FieldDecompiler::FieldEntityGetEntityList () const
 Retrieves all non-line entities in the map. More...
 
std::vector< FieldDecompiler::LineGetLineList () const
 Retrieves all line entities in the map. More...
 
std::map< size_t, EntityGetEntityIndexMap () const
 Retrieves all entities in the map. More...
 
void AddEntityFunction (const std::string &entity_name, size_t entity_index, const std::string &func_name, size_t func_index)
 Adds a function to an entity. More...
 
void MarkEntityAsLine (size_t entity_index, bool line, std::vector< float > point_a, std::vector< float > point_b)
 Marks an entity as a line. More...
 
bool EntityIsLine (size_t entity_index)
 Checks if an entity has been marked as a line. More...
 
const EntityEntityByIndex (size_t index) const
 Retrieves an entity. More...
 
float GetScaleFactor () const
 Retrieves the scale factor for the map. More...
 
const std::string & GetScriptName () const
 Retrieves the script name. More...
 
- Public Member Functions inherited from Engine
virtual ~Engine ()=default
 
virtual std::unique_ptr< DisassemblerGetDisassembler (InstVec &insts, const std::vector< unsigned char > &c)
 
virtual std::unique_ptr< DisassemblerGetDisassembler (InstVec &insts)=0
 Retrieve the disassembler for the engine. More...
 
virtual std::unique_ptr< CodeGeneratorGetCodeGenerator (const InstVec &insts, std::ostream &output)=0
 Retrieve the code generator for the engine. More...
 
virtual void PostCFG (InstVec &insts, Graph graph)
 Post-processing step after CFG analysis. More...
 
virtual bool SupportsCodeFlow () const
 Whether or not code flow analysis is supported for this engine. More...
 
virtual bool SupportsCodeGen () const
 Whether or not code generation is supported for this engine. More...
 
virtual void GetVariants (std::vector< std::string > &variants) const
 Retrieves the names of all variants supported for this engine. More...
 
virtual bool UsePureGrouping () const
 Whether or not to use "pure" grouping during code flow analysis. More...
 

Private Member Functions

void RemoveExtraneousReturnStatements (InstVec &insts, Graph graph)
 Removes extraneous return statements. More...
 
void RemoveTrailingInfiniteLoops (InstVec &insts, Graph graph)
 Removes trailing infinite loops. More...
 
FieldScriptFormatterformatter_
 The script formatter. More...
 
std::map< size_t, Entityentity_index_map_
 The entity index map for the field. More...
 
float scale_factor_
 The map scale factor. More...
 
std::string script_name_
 The script name. More...
 
void MarkInfiniteLoopGroups (InstVec &insts, Graph graph)
 Tries to detect scripts with trailing infinite loops. More...
 

Additional Inherited Members

- Public Attributes inherited from Engine
FuncMap functions
 Map to functions in the current script, indexed by start address. More...
 
- Protected Attributes inherited from Engine
std::string variant_
 Engine variant to use for the script. More...
 

Detailed Description

Represents the FF7 Field engine.

Constructor & Destructor Documentation

◆ FieldEngine() [1/2]

FieldEngine::FieldEngine ( FieldScriptFormatter formatter,
std::string  script_name 
)

Constructor.

Parameters
[in]formatterThe formatter to be used by the engine.
[in]script_nameThe script name.

◆ FieldEngine() [2/2]

FieldEngine::FieldEngine ( const FieldEngine engine)
delete

Copy constructor, disabled.

Parameters
[in]engineThe engine to copy.

Member Function Documentation

◆ AddEntityFunction()

void FieldEngine::AddEntityFunction ( const std::string &  entity_name,
size_t  entity_index,
const std::string &  func_name,
size_t  func_index 
)

Adds a function to an entity.

Parameters
[in]entity_nameName of the entity.
[in]entity_indexIndex of the entity.
[in]func_nameName of the function.
[in]func_indexIndex of the function.

◆ EntityByIndex()

const FieldEngine::Entity & FieldEngine::EntityByIndex ( size_t  index) const

Retrieves an entity.

Parameters
[in]indexIndex of the entity to retrieve.
Exceptions
DecompilerExceptionif there is no entity at the specified index.

◆ EntityIsLine()

bool FieldEngine::EntityIsLine ( size_t  entity_index)

Checks if an entity has been marked as a line.

Parameters
[in]entity_indexIndex of the entity to check.
Returns
True if the entity is a line. False if it isn't, or if there is no such entity.

◆ GetCodeGenerator()

std::unique_ptr< CodeGenerator > FieldEngine::GetCodeGenerator ( const InstVec insts,
std::ostream &  output 
)
overridevirtual

Retrieves the code generator.

Parameters
[in]instsList of instructions.
[in]outputPointer to the output (file, stream...).
Returns
Pointer to the generator.

Implements Engine.

◆ GetDisassembler() [1/2]

std::unique_ptr< Disassembler > FieldEngine::GetDisassembler ( InstVec insts)
overridevirtual

Retrieves the dissasembler.

Parameters
[in]instsList of instructions.
Returns
Pointer to the dissasembler.

Implements Engine.

◆ GetDisassembler() [2/2]

std::unique_ptr< Disassembler > FieldEngine::GetDisassembler ( InstVec insts,
const std::vector< unsigned char > &  raw_script_data 
)
overridevirtual

Retrieves the disasembler.

Parameters
[in]instsList of instructions.
[in]raw_script_dataScript data, raw format.
Returns
Pointer to the disasembler.

Reimplemented from Engine.

◆ GetEntities()

std::map< std::string, int > FieldEngine::GetEntities ( ) const

Retrieves all entities in the map.

Returns
A map of entities, with the name and index.

◆ GetEntityIndexMap()

std::map< size_t, Entity > FieldEngine::GetEntityIndexMap ( ) const
inline

Retrieves all entities in the map.

Returns
A map of entities, with the name and index.

◆ GetEntityList()

std::vector< FieldDecompiler::FieldEntity > FieldEngine::GetEntityList ( ) const

Retrieves all non-line entities in the map.

Returns
A list of non-line entities.

◆ GetLineList()

std::vector< FieldDecompiler::Line > FieldEngine::GetLineList ( ) const

Retrieves all line entities in the map.

Returns
A list of line entities.

◆ GetScaleFactor()

float FieldEngine::GetScaleFactor ( ) const

Retrieves the scale factor for the map.

Returns
Map scale factor.

◆ GetScriptName()

const std::string & FieldEngine::GetScriptName ( ) const

Retrieves the script name.

Returns
The script name.

◆ MarkEntityAsLine()

void FieldEngine::MarkEntityAsLine ( size_t  entity_index,
bool  line,
std::vector< float >  point_a,
std::vector< float >  point_b 
)

Marks an entity as a line.

Parameters
[in]entity_indexIndex of the entity.
[in]lineTrue to mark the entity as a line, false to unmark it.
[in]point_aFirst point of the line. Can be null if line is false.
[in]point_bSecond point of the line. Can be null if line is false.

◆ MarkInfiniteLoopGroups()

void FieldEngine::MarkInfiniteLoopGroups ( InstVec insts,
Graph  graph 
)
private

Tries to detect scripts with trailing infinite loops.

In FF7 some scripts ends with an infinite loop to keep it alive. In VGears this isn't required, and can cause infinite loops, so they can be removed. This function marks them, so they can be deleted withsee FieldEngine::RemoveTrailingInfiniteLoops}.

◆ operator=()

FieldEngine & FieldEngine::operator= ( const FieldEngine engine)
delete

Copy constructor, disabled.

Parameters
[in]engineThe engine to copy.

◆ PostCFG()

void FieldEngine::PostCFG ( InstVec insts,
Graph  graph 
)
overridevirtual

Post-processing actions to apply to the scripts.

It actually does nothing. CFG stands for control flow group.

Parameters
[in]instsInstruction list.
[in]graphCode graph.

Reimplemented from Engine.

◆ RemoveExtraneousReturnStatements()

void FieldEngine::RemoveExtraneousReturnStatements ( InstVec insts,
Graph  graph 
)
private

Removes extraneous return statements.

Useful for scripts that only contain one one return statement.

Parameters
[in,out]instsList of instructions to process. Extraneous return statements will be deleted from the instructions.
[in]graphCode graph. Unused.

◆ RemoveTrailingInfiniteLoops()

void FieldEngine::RemoveTrailingInfiniteLoops ( InstVec insts,
Graph  graph 
)
private

Removes trailing infinite loops.

In FF7 some scripts ends with an infinite loop to keep it alive. In VGears this isn't required, and can cause infinite loops, so they can be removed.

Parameters
[in,out]instsList of instructions to proccess. Trailing infinite loops will be deleted from the instructions.
[in]graphCode graph.

◆ UsePureGrouping()

bool FieldEngine::UsePureGrouping ( ) const
overridevirtual

Indicates if instructions are purely grouped.

Returns
True if instructions are purely grouped. Always false.

Reimplemented from Engine.

Member Data Documentation

◆ entity_index_map_

std::map<size_t, Entity> FieldEngine::entity_index_map_
private

The entity index map for the field.

◆ formatter_

FieldScriptFormatter& FieldEngine::formatter_
private

The script formatter.

◆ scale_factor_

float FieldEngine::scale_factor_
private

The map scale factor.

◆ script_name_

std::string FieldEngine::script_name_
private

The script name.


The documentation for this class was generated from the following files: