Browse Source

Function and Engine partially refactored.

Iñigo Valentin 3 years ago
parent
commit
15c6713c04
37 changed files with 493 additions and 365 deletions
  1. 6 3
      V-Gears-Installer/CMakeLists.txt
  2. 1 1
      V-Gears-Installer/include/decompiler/ControlFlow.h
  3. 96 0
      V-Gears-Installer/include/decompiler/Disassembler.h
  4. 113 0
      V-Gears-Installer/include/decompiler/Engine.h
  5. 85 0
      V-Gears-Installer/include/decompiler/Function.h
  6. 0 86
      V-Gears-Installer/include/decompiler/decompiler_disassembler.h
  7. 0 144
      V-Gears-Installer/include/decompiler/decompiler_engine.h
  8. 2 1
      V-Gears-Installer/include/decompiler/field/FieldEngine.h
  9. 1 1
      V-Gears-Installer/include/decompiler/simple_disassembler.h
  10. 1 1
      V-Gears-Installer/include/decompiler/test/cfg_test.cpp
  11. 1 1
      V-Gears-Installer/include/decompiler/test/codegen.cpp
  12. 2 1
      V-Gears-Installer/include/decompiler/world/WorldEngine.h
  13. 8 5
      V-Gears-Installer/src/decompiler/CodeGenerator.cpp
  14. 25 9
      V-Gears-Installer/src/decompiler/ControlFlow.cpp
  15. 39 0
      V-Gears-Installer/src/decompiler/Disassembler.cpp
  16. 15 0
      V-Gears-Installer/src/decompiler/Engine.cpp
  17. 32 0
      V-Gears-Installer/src/decompiler/Function.cpp
  18. 2 2
      V-Gears-Installer/src/decompiler/decompiler.cpp
  19. 0 49
      V-Gears-Installer/src/decompiler/decompiler_disassembler.cpp
  20. 11 11
      V-Gears-Installer/src/decompiler/field/FieldCodeGenerator.cpp
  21. 21 19
      V-Gears-Installer/src/decompiler/field/FieldDisassembler.cpp
  22. 10 10
      V-Gears-Installer/src/decompiler/field/FieldEngine.cpp
  23. 1 1
      V-Gears-Installer/src/decompiler/field/instruction/FieldBackgroundInstruction.cpp
  24. 1 1
      V-Gears-Installer/src/decompiler/field/instruction/FieldCameraInstruction.cpp
  25. 2 2
      V-Gears-Installer/src/decompiler/field/instruction/FieldControlFlowInstruction.cpp
  26. 1 1
      V-Gears-Installer/src/decompiler/field/instruction/FieldMathInstruction.cpp
  27. 1 1
      V-Gears-Installer/src/decompiler/field/instruction/FieldMediaInstruction.cpp
  28. 1 1
      V-Gears-Installer/src/decompiler/field/instruction/FieldModelInstruction.cpp
  29. 4 4
      V-Gears-Installer/src/decompiler/field/instruction/FieldModuleInstruction.cpp
  30. 1 1
      V-Gears-Installer/src/decompiler/field/instruction/FieldPartyInstruction.cpp
  31. 1 1
      V-Gears-Installer/src/decompiler/field/instruction/FieldUncategorizedInstruction.cpp
  32. 1 1
      V-Gears-Installer/src/decompiler/field/instruction/FieldWalkmeshInstruction.cpp
  33. 1 1
      V-Gears-Installer/src/decompiler/field/instruction/FieldWindowInstruction.cpp
  34. 4 3
      V-Gears-Installer/src/decompiler/graph.cpp
  35. 1 1
      V-Gears-Installer/src/decompiler/instruction.cpp
  36. 1 1
      V-Gears-Installer/src/decompiler/sudm.cpp
  37. 1 1
      V-Gears-Installer/src/decompiler/world/WorldCodeGenerator.cpp

+ 6 - 3
V-Gears-Installer/CMakeLists.txt

@@ -25,8 +25,9 @@ set(HEADER_FILES
     include/decompiler/LuaLanguage.h
     include/decompiler/CodeGenerator.h
     include/decompiler/ControlFlow.h
-    include/decompiler/decompiler_disassembler.h
-    include/decompiler/decompiler_engine.h
+    include/decompiler/Disassembler.h
+    include/decompiler/Engine.h
+    include/decompiler/Function.h
     include/decompiler/graph.h
     include/decompiler/instruction.h
     include/decompiler/objectFactory.h
@@ -87,7 +88,9 @@ set(SOURCE_FILES
     src/decompiler/LuaLanguage.cpp
     src/decompiler/CodeGenerator.cpp
     src/decompiler/ControlFlow.cpp
-    src/decompiler/decompiler_disassembler.cpp
+    src/decompiler/Disassembler.cpp
+    src/decompiler/Engine.cpp
+    src/decompiler/Function.cpp
     src/decompiler/graph.cpp
     src/decompiler/instruction.cpp
     src/decompiler/simple_disassembler.cpp

+ 1 - 1
V-Gears-Installer/include/decompiler/ControlFlow.h

@@ -15,8 +15,8 @@
 
 #pragma once
 
+#include "Engine.h"
 #include "graph.h"
-#include "decompiler_engine.h"
 
 /**
  * Class for doing code flow analysis.

+ 96 - 0
V-Gears-Installer/include/decompiler/Disassembler.h

@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
+
+#include <iostream>
+#include <vector>
+#include "common/BinaryReader.h"
+#include "instruction.h"
+#include "unknown_opcode_exception.h"
+#include "objectFactory.h"
+
+/**
+ * Base class for disassemblers.
+ */
+class Disassembler{
+
+    public:
+
+        /**
+         * Constructor for Disassembler.
+         *
+         * @param insts[in] Where disassembled instructions will be placed.
+         */
+        Disassembler(InstVec &insts);
+
+        /**
+         * Destructor.
+         */
+        virtual ~Disassembler() = default;
+
+        /**
+         * Open a file for disassembly.
+         *
+         * @param filename[in] The file to Disassemble.
+         */
+        virtual void Open(const char *filename);
+
+        /**
+         * Request disassembled instructions.
+         */
+        void Disassemble();
+
+        /**
+         * Outputs the disassembled code.
+         *
+         * Disassembles code if this has not already been done.
+         *
+         * @param output[out] The output stream.
+         */
+        void DumpDisassembly(std::ostream &output);
+
+    protected:
+
+        /**
+         * Performs disassembly.
+         *
+         * @throws UnknownOpcodeException on unknown opcode.
+         * @throws std::exception on other failures.
+         */
+        virtual void DoDisassemble() = 0;
+
+        /**
+         * Outputs the disassembled code.
+         *
+         * @param output[out] The output stream.
+         */
+        virtual void DoDumpDisassembly(std::ostream &output);
+
+        /**
+         * Used to perform file I/O.
+         */
+        std::unique_ptr<BinaryReader> stream_;
+
+        /**
+         * List of disassembled instructions.
+         */
+        InstVec &insts_;
+
+        /**
+         * Base address where the script starts.
+         */
+        uint32 address_base_;
+};

+ 113 - 0
V-Gears-Installer/include/decompiler/Engine.h

@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
+
+#include <set>
+#include <string>
+#include <vector>
+#include "CodeGenerator.h"
+#include "Disassembler.h"
+#include "Function.h"
+
+/**
+ * Type representing a map of functions, indexed by starting address.
+ */
+typedef std::map<uint32, Function> FuncMap;
+
+/**
+ * Base class for engines.
+ */
+class Engine {
+    public:
+
+        virtual ~Engine() = default;
+
+        virtual std::unique_ptr<Disassembler> GetDisassembler(InstVec &, const std::vector<unsigned char>& )
+        {
+            throw NotImplementedException();
+        }
+
+        /**
+         * Retrieve the disassembler for the engine.
+         *
+         * @param insts Reference to the std::vector to place the Instructions in.
+         * @return Pointer to a Disassembler for the engine.
+         */
+        virtual std::unique_ptr<Disassembler> GetDisassembler(InstVec &insts) = 0;
+
+        /**
+         * Retrieve the code generator for the engine.
+         *
+         * @param output The std::ostream to output the code to.
+         * @return Pointer to a CodeGenerator for the engine.
+         */
+        virtual std::unique_ptr<CodeGenerator> GetCodeGenerator(const InstVec& insts, std::ostream &output) = 0;
+
+        /**
+         * Post-processing step after CFG analysis.
+         * @param insts Reference to the std::vector to place the Instructions in.
+         * @param g Graph generated from the CFG analysis.
+         */
+        virtual void PostCFG(InstVec&, Graph) { }
+
+        /**
+         * Whether or not code flow analysis is supported for this engine.
+         *
+         * @return True if supported, false if not. If false is returned, code flow analysis should not take place, and -D should be implied.
+         */
+        virtual bool SupportsCodeFlow() const { return true; }
+
+        /**
+         * Whether or not code generation is supported for this engine.
+         *
+         * @return True if supported, false if not. If false is returned, code generation should not take place, and -G should be implied.
+         */
+        virtual bool SupportsCodeGen() const { return true; }
+
+
+
+        /**
+         * Fill a vector with the names of all variants supported for this engine.
+         * If variants are not used by this engine, leave the vector empty (default implementation).
+         *
+         * @param variants Vector to add the supported variants to.
+         */
+        virtual void GetVariants(std::vector<std::string>&) const { };
+
+
+        /**
+         * Whether or not to use "pure" grouping during code flow analysis.
+         * With pure grouping, code flow analysis only looks at branches when merging.
+         * This method may be more appropriate for non-stack-based engines.
+         *
+         * @return True if pure grouping should be used, false if not.
+         */
+        virtual bool UsePureGrouping() const { return false; }
+
+        virtual FuncMap GetFunctions() const{return _functions;}
+
+        virtual void SetFunction(uint32 index, Function function){
+            _functions[index] = function;
+        }
+
+        FuncMap _functions;
+
+    protected:
+
+        //FuncMap _functions; ///< Map to functions in the current script, indexed by starting address.
+        std::string _variant; ///< Engine variant to use for the script.
+
+};

+ 85 - 0
V-Gears-Installer/include/decompiler/Function.h

@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
+
+#include <set>
+#include "CodeGenerator.h"
+#include "Disassembler.h"
+
+/**
+ * Structure representing a function.
+ */
+class Function {
+    public:
+
+        /**
+         * Constructor.
+         *
+         * Required for use with STL, should not be called manually.
+         */
+        Function();
+
+        /**
+         * Constructor.
+         *
+         * @param start_addr[in] Address of the first instruction in the function.
+         * @param end_addr[in] Address of the last instruction in the function
+         */
+        Function(uint32 start_addr, uint32 end_addr);
+
+        /**
+         * The function starting address.
+         */
+        uint32 start_addr = 0;
+
+        /**
+         * The function ending address.
+         */
+        uint32 end_addr = 0;
+
+        /**
+         * Number of instructions in the function.
+         */
+        uint32 num_instructions = 0;
+
+        /**
+         * The name of the function.
+         */
+        std::string name;
+
+        /**
+         * The function vertex.
+         */
+        GraphVertex vertex;
+
+        /**
+         * Number of arguments in the function.
+         */
+        uint32 num_args;
+
+        /**
+         * Return value of the function.
+         */
+        bool ret_val;
+
+        /**
+         * Metadata for code generation.
+         */
+        std::string metadata;
+
+
+
+};

+ 0 - 86
V-Gears-Installer/include/decompiler/decompiler_disassembler.h

@@ -1,86 +0,0 @@
-/* ScummVM Tools
- *
- * ScummVM Tools is the legal property of its developers, whose
- * names are too numerous to list here. Please refer to the
- * COPYRIGHT file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifndef DEC_DISASSEMBLER_H
-#define DEC_DISASSEMBLER_H
-
-#include <iostream>
-#include <vector>
-
-#include "../common/BinaryReader.h"
-#include "instruction.h"
-#include "unknown_opcode_exception.h"
-#include "objectFactory.h"
-
-/**
- * Base class for disassemblers.
- */
-class Disassembler {
-protected:
-	std::unique_ptr<BinaryReader> stream_;                         ///< Used to perform file I/O.
-	InstVec &insts_;                              ///< Container for disassembled instructions.
-	uint32 address_base_;                          ///< Base address where the script starts.
-
-	/**
-	 * Performs disassembly.
-	 *
-	 * @throws UnknownOpcodeException on unknown opcode. May throw std::exception on other failures.
-	 */
-	virtual void DoDisassemble() = 0;
-
-	/**
-	 * Outputs the disassembled code.
-	 *
-	 * @param output The std::ostream to output to.
-	 */
-	virtual void doDumpDisassembly(std::ostream &output);
-
-public:
-	/**
-	 * Constructor for Disassembler.
-	 *
-	 * @param insts Reference to the vector in which disassembled instructions should be placed.
-	 */
-	Disassembler(InstVec &insts);
-    virtual ~Disassembler() = default;
-
-	/**
-	 * Open a file for disassembly.
-	 *
-	 * @param filename The file to disassemble.
-	 */
-	virtual void Open(const char *filename);
-
-	/**
-	 * Request disassembled instructions.
-	 *
-	 * @return An std::vector containing the disassembled instructions.
-	 */
-	void disassemble();
-
-	/**
-	 * Outputs the disassembled code. Disassembles code if this has not already been done.
-	 *
-	 * @param output The std::ostream to output to.
-	 */
-	void dumpDisassembly(std::ostream &output);
-};
-#endif

+ 0 - 144
V-Gears-Installer/include/decompiler/decompiler_engine.h

@@ -1,144 +0,0 @@
-/* ScummVM Tools
- *
- * ScummVM Tools is the legal property of its developers, whose
- * names are too numerous to list here. Please refer to the
- * COPYRIGHT file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifndef ENGINE_H
-#define ENGINE_H
-
-#include "decompiler_disassembler.h"
-#include <set>
-#include <string>
-#include <vector>
-#include "CodeGenerator.h"
-
-/**
- * Structure representing a function.
- */
-class Function 
-{
-public:
-    uint32 mStartAddr = 0;
-    uint32 mEndAddr = 0;
-    uint32 mNumInstructions = 0;
-	//InstIterator _startIt; ///< Iterator to of the first instruction in the function, if available.
-	//InstIterator _endIt;   ///< Iterator to the instruction immediately after the function, similar to end() on STL containers. If _endIt == _startIt, the function endpoint is assumed to be unknown.
-	std::string _name;          ///< Function name.
-	GraphVertex _v;             ///< Graph vertex for the entry point to the function.
-	uint32 _args;               ///< Number of arguments to the function.
-	bool _retVal;               ///< Whether or not the function returns a value.
-	std::string _metadata;      ///< Metadata for code generation.
-
-	/**
-	 * Parameterless constructor for Function. Required for use with STL, should not be called manually.
-	 */
-	Function() {
-	}
-
-	/**
-	 * Constructor for Function.
-	 *
-	 * @param startIt Index of the first instruction in the function.
-	 * @param endIt Index of the instruction immediately after the function, similar to end() on STL containers.
-	 */
-//	Function(InstIterator startIt, InstIterator endIt) : _startIt(startIt), _endIt(endIt) {}
-    Function(uint32 startAddr, uint32 endAddr) : mStartAddr(startAddr), mEndAddr(endAddr){
-    }
-};
-
-/**
- * Type representing a map of functions, indexed by starting address.
- */
-typedef std::map<uint32, Function> FuncMap;
-
-/**
- * Base class for engines.
- */
-class Engine 
-{
-public:
-
-    virtual ~Engine() = default;
-
-    virtual std::unique_ptr<Disassembler> GetDisassembler(InstVec &, const std::vector<unsigned char>& )
-    {
-        throw NotImplementedException();
-    }
-
-	/**
-	 * Retrieve the disassembler for the engine.
-	 *
-	 * @param insts Reference to the std::vector to place the Instructions in.
-	 * @return Pointer to a Disassembler for the engine.
-	 */
-	virtual std::unique_ptr<Disassembler> GetDisassembler(InstVec &insts) = 0;
-
-	/**
-	 * Retrieve the code generator for the engine.
-	 *
-	 * @param output The std::ostream to output the code to.
-	 * @return Pointer to a CodeGenerator for the engine.
-	 */
-    virtual std::unique_ptr<CodeGenerator> GetCodeGenerator(const InstVec& insts, std::ostream &output) = 0;
-
-	/**
-	 * Post-processing step after CFG analysis.
-	 * @param insts Reference to the std::vector to place the Instructions in.
-	 * @param g Graph generated from the CFG analysis.
-	 */
-	virtual void PostCFG(InstVec&, Graph) { }
-
-	/**
-	 * Whether or not code flow analysis is supported for this engine.
-	 *
-	 * @return True if supported, false if not. If false is returned, code flow analysis should not take place, and -D should be implied.
-	 */
-	virtual bool supportsCodeFlow() const { return true; }
-
-	/**
-	 * Whether or not code generation is supported for this engine.
-	 *
-	 * @return True if supported, false if not. If false is returned, code generation should not take place, and -G should be implied.
-	 */
-	virtual bool supportsCodeGen() const { return true; }
-
-	FuncMap _functions; ///< Map to functions in the current script, indexed by starting address.
-
-	/**
-	 * Fill a vector with the names of all variants supported for this engine.
-	 * If variants are not used by this engine, leave the vector empty (default implementation).
-	 *
-	 * @param variants Vector to add the supported variants to.
-	 */
-	virtual void GetVariants(std::vector<std::string>&) const { };
-
-	std::string _variant; ///< Engine variant to use for the script.
-
-	/**
-	 * Whether or not to use "pure" grouping during code flow analysis.
-	 * With pure grouping, code flow analysis only looks at branches when merging.
-	 * This method may be more appropriate for non-stack-based engines.
-	 *
-	 * @return True if pure grouping should be used, false if not.
-	 */
-	virtual bool UsePureGrouping() const { return false; }
-
-};
-
-#endif

+ 2 - 1
V-Gears-Installer/include/decompiler/field/FieldEngine.h

@@ -18,9 +18,10 @@
 
 #pragma once
 
-#include "decompiler/decompiler_engine.h"
 #include <string>
 #include <vector>
+
+#include "../Engine.h"
 #include "decompiler/sudm.h"
 
 namespace FF7{

+ 1 - 1
V-Gears-Installer/include/decompiler/simple_disassembler.h

@@ -22,7 +22,7 @@
 #ifndef DEC_SIMPLE_DISASSEMBLER_H
 #define DEC_SIMPLE_DISASSEMBLER_H
 
-#include "decompiler_disassembler.h"
+#include "Disassembler.h"
 
 /**
  * Simple disassembler acting as a base for instruction sets only consisting of simple instructions (opcode params...).

+ 1 - 1
V-Gears-Installer/include/decompiler/test/cfg_test.cpp

@@ -19,12 +19,12 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#include "decompiler/decompiler_disassembler.h"
 #include "decompiler/graph.h"
 #include "decompiler/scummv6/engine.h"
 #include <gmock/gmock.h>
 #include <vector>
 #include "../ControlFlow.h"
+#include "../Disassembler.h"
 
 #define GET(vertex) (boost::get(boost::vertex_name, g, vertex))
 

+ 1 - 1
V-Gears-Installer/include/decompiler/test/codegen.cpp

@@ -20,7 +20,6 @@
  */
 
 
-#include "decompiler/decompiler_disassembler.h"
 #include "decompiler/graph.h"
 #include "decompiler/scummv6/engine.h"
 
@@ -28,6 +27,7 @@
 
 #include "../CodeGenerator.h"
 #include "../ControlFlow.h"
+#include "../Disassembler.h"
 #define GET(vertex) (boost::get(boost::vertex_name, g, vertex))
 
 #include <streambuf>

+ 2 - 1
V-Gears-Installer/include/decompiler/world/WorldEngine.h

@@ -20,7 +20,8 @@
 
 #include <string>
 #include <vector>
-#include "decompiler/decompiler_engine.h"
+
+#include "../Engine.h"
 
 namespace FF7{
 

+ 8 - 5
V-Gears-Installer/src/decompiler/CodeGenerator.cpp

@@ -13,12 +13,13 @@
  * GNU General Public License for more details.
  */
 
-#include "decompiler/decompiler_engine.h"
 #include <algorithm>
 #include <iostream>
 #include <set>
 #include <boost/format.hpp>
 #include "decompiler/CodeGenerator.h"
+
+#include "../../include/decompiler/Engine.h"
 #include "decompiler/LuaLanguage.h"
 
 #define GET(vertex)    (boost::get(boost::vertex_name, graph_, vertex))
@@ -162,7 +163,7 @@ void CodeGenerator::ProcessUncondJumpInst(Function& function, InstVec& insts, co
                             // and its an uncond jump.
                             if (
                               cur_group_->_type == kDoWhileCondGroupType
-                              && inst->_address == function.mEndAddr
+                              && inst->_address == function.end_addr
                               && inst->IsUncondJump()
                             ){
                                 print_jump = false;
@@ -256,16 +257,18 @@ typedef std::pair<GraphVertex, ValueStack> DFSEntry;
 void CodeGenerator::GeneratePass(InstVec& insts, const Graph& graph){
     graph_ = graph;
     for (
-      FuncMap::iterator fn = engine_->_functions.begin(); fn != engine_->_functions.end(); ++ fn
+      FuncMap::iterator fn = engine_->GetFunctions().begin();
+      fn != engine_->GetFunctions().end();
+      ++ fn
     ){
         while (!stack_.empty()) stack_.pop();
-        GraphVertex entry_point = fn->second._v;
+        GraphVertex entry_point = fn->second.vertex;
         std::string func_signature = ConstructFuncSignature(fn->second);
         // Write the function start.
         bool print_func_signature = !func_signature.empty();
         if (print_func_signature){
             cur_group_ = GET(entry_point);
-            if (!(fn == engine_->_functions.begin())) AddOutputLine("");
+            if (!(fn == engine_->GetFunctions().begin())) AddOutputLine("");
             OnBeforeStartFunction(fn->second);
             AddOutputLine(func_signature, false, true);
             OnStartFunction(fn->second);

+ 25 - 9
V-Gears-Installer/src/decompiler/ControlFlow.cpp

@@ -65,7 +65,11 @@ ControlFlow::ControlFlow(InstVec& insts, Engine& engine): insts_(insts),engine_(
     // Automatically add a function if we're not supposed to look for more functions
     // and no functions are defined.
     // This avoids a special case for when no real functions exist in the script.
-    if (engine_._functions.empty()){
+    if (engine_.GetFunctions().empty()){
+        /*engine_.SetFunction(
+          (*insts.begin())->_address,
+          Function((*insts.begin())->_address, (insts.back())->_address)
+        );*/
         engine_._functions[(*insts.begin())->_address]= Function(
           (*insts.begin())->_address, (insts.back())->_address
         );
@@ -80,8 +84,11 @@ ControlFlow::ControlFlow(InstVec& insts, Engine& engine): insts_(insts),engine_(
         PUT_ID(cur, id);
         id ++;
         // Add reference to vertex if function starts here.
-        if (engine_._functions.find((*it)->_address) != engine_._functions.end())
-            engine_._functions[(*it)->_address]._v = cur;
+        /*if (engine_.GetFunctions().find((*it)->_address) != engine_.GetFunctions().end())
+            engine_.GetFunctions()[(*it)->_address].vertex = cur;*/
+        if (engine_._functions.find((*it)->_address) != engine_._functions.end()){
+            engine_._functions[(*it)->_address].vertex = cur;
+        }
         prev = GET(cur);
     }
     // Add regular edges.
@@ -90,7 +97,8 @@ ControlFlow::ControlFlow(InstVec& insts, Engine& engine): insts_(insts),engine_(
     bool add_edge = false;
     prev = NULL;
     for (InstIterator it = insts.begin(); it != insts.end(); ++it){
-        if (engine_._functions.find((*it)->_address) != engine_._functions.end()) add_edge = false;
+        if (engine_.GetFunctions().find((*it)->_address) != engine_.GetFunctions().end())
+            add_edge = false;
         GraphVertex cur = Find(it);
         if (add_edge){
             GraphEdge e = boost::add_edge(last, cur, graph_).first;
@@ -184,16 +192,24 @@ void ControlFlow::SetStackLevel(GraphVertex graph, int level){
 
 void ControlFlow::CreateGroups(){
     if (
-      !engine_._functions.empty() && GET(engine_._functions.begin()->second._v)->_stackLevel != -1
+      !engine_.GetFunctions().empty()
+      //&& GET(engine_.GetFunctions().begin()->second.GetVertex())->_stackLevel != -1
+      //&& GET(engine_.GetFunctions().begin()->second.vertex_)->_stackLevel != -1
+      && GET(engine_._functions.begin()->second.vertex)->_stackLevel != -1
     ){
         return;
     }
 
-    for (FuncMap::iterator fn = engine_._functions.begin(); fn != engine_._functions.end(); ++ fn)
-        SetStackLevel(fn->second._v, 0);
+    for (
+      FuncMap::iterator fn = engine_._functions.begin();
+      fn != engine_._functions.end();
+      ++ fn
+    ){
+        SetStackLevel(fn->second.vertex, 0);
+    }
     ConstInstIterator cur_inst, next_inst;
     next_inst = insts_.begin();
-    next_inst++;
+    next_inst ++;
     int stack_level = 0;
     int expected_stack_level = 0;
     for (cur_inst = insts_.begin(); next_inst != insts_.end(); ++ cur_inst, ++ next_inst){
@@ -317,7 +333,7 @@ void ControlFlow::DetectWhile(){
         if (out_degree(*v, graph_) == 2 && gr->_type == kNormalGroupType){
             InEdgeRange ier = boost::in_edges(*v, graph_);
             bool is_while = false;
-            for (InEdgeIterator e = ier.first; e != ier.second; ++e){
+            for (InEdgeIterator e = ier.first; e != ier.second; ++ e){
                 GroupPtr source_gr = GET(boost::source(*e, graph_));
                 // Block has ingoing edge from block later in the
                 // code that isn't a do-while condition.

+ 39 - 0
V-Gears-Installer/src/decompiler/Disassembler.cpp

@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include "decompiler/Disassembler.h"
+
+Disassembler::Disassembler(InstVec &insts) : insts_(insts), address_base_(0){}
+
+void Disassembler::Open(const char *filename){
+    stream_ = std::make_unique<BinaryReader>(BinaryReader::ReadAll(filename));
+}
+
+void Disassembler::DoDumpDisassembly(std::ostream &output){
+    InstIterator inst;
+    for (inst = insts_.begin(); inst != insts_.end(); ++ inst) output << *inst << "\n";
+}
+
+void Disassembler::Disassemble() {
+    if (insts_.empty()) {
+        stream_->Seek(0);
+        DoDisassemble();
+    }
+}
+
+void Disassembler::DumpDisassembly(std::ostream &output){
+    Disassemble();
+    DoDumpDisassembly(output);
+}

+ 15 - 0
V-Gears-Installer/src/decompiler/Engine.cpp

@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+

+ 32 - 0
V-Gears-Installer/src/decompiler/Function.cpp

@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include "decompiler/Function.h"
+
+/**
+ * Constructor.
+ *
+ * Required for use with STL, should not be called manually.
+ */
+Function::Function(): start_addr(0), end_addr(0), num_instructions(0){}
+
+/**
+ * Constructor.
+ *
+ * @param start_addr[in] Address of the first instruction in the function.
+ * @param end_addr[in] Address of the last instruction in the function
+ */
+Function::Function(uint32 start_addr, uint32 end_addr)
+  : start_addr(start_addr), end_addr(end_addr), num_instructions(0){}

+ 2 - 2
V-Gears-Installer/src/decompiler/decompiler.cpp

@@ -21,8 +21,6 @@
 
 #include "objectFactory.h"
 
-#include "decompiler_disassembler.h"
-#include "decompiler_engine.h"
 #include "instruction.h"
 
 #include <fstream>
@@ -31,6 +29,8 @@
 #include <string>
 #include <vector>
 #include "../../include/decompiler/ControlFlow.h"
+#include "../../include/decompiler/Disassembler.h"
+#include "../../include/decompiler/Engine.h"
 
 #ifdef _MSC_VER
 #pragma warning (push)

+ 0 - 49
V-Gears-Installer/src/decompiler/decompiler_disassembler.cpp

@@ -1,49 +0,0 @@
-/* ScummVM Tools
- *
- * ScummVM Tools is the legal property of its developers, whose
- * names are too numerous to list here. Please refer to the
- * COPYRIGHT file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#include "decompiler/decompiler_disassembler.h"
-
-Disassembler::Disassembler(InstVec &insts) : insts_(insts) {
-	address_base_ = 0;
-}
-
-void Disassembler::Open(const char *filename) {
-    stream_ = std::make_unique<BinaryReader>(BinaryReader::ReadAll(filename));
-}
-
-void Disassembler::doDumpDisassembly(std::ostream &output) {
-	InstIterator inst;
-	for (inst = insts_.begin(); inst != insts_.end(); ++inst) {
-		output << *inst << "\n";
-	}
-}
-
-void Disassembler::disassemble() {
-	if (insts_.empty()) {
-        stream_->Seek(0);
-		DoDisassemble();
-	}
-}
-
-void Disassembler::dumpDisassembly(std::ostream &output) {
-	disassemble();
-	doDumpDisassembly(output);
-}

+ 11 - 11
V-Gears-Installer/src/decompiler/field/FieldCodeGenerator.cpp

@@ -93,7 +93,7 @@ void FF7::FieldCodeGenerator::Generate(InstVec& insts, const Graph& graph){
       ++ function
     ){
         InstVec body;
-        for (size_t i = 0; i < function->second.mNumInstructions; ++ i, ++ instruction)
+        for (size_t i = 0; i < function->second.num_instructions; ++ i, ++ instruction)
             body.push_back(*instruction);
         functions_with_bodies.push_back(std::pair<Function&, InstVec> {function->second, body});
     }
@@ -163,18 +163,18 @@ void FF7::FieldCodeGenerator::Generate(InstVec& insts, const Graph& graph){
             }
             else if ((*instruction)->IsUncondJump()){
                 // If destination address is outside the functions, turn goto into a return.
-                if ((*instruction)->GetDestAddress() > function->first.mEndAddr){
+                if ((*instruction)->GetDestAddress() > function->first.end_addr){
                     AddOutputLine(
                       "-- Overflowed jump to "
                       + (boost::format("0x%1$X") % (*instruction)->GetDestAddress()).str()
                       + " (last address in function is "
-                      + (boost::format("0x%1$X)") % function->first.mEndAddr).str()
+                      + (boost::format("0x%1$X)") % function->first.end_addr).str()
                     );
                     AddOutputLine("do return 0 end");
                 }
                 // Prevent backward jumps in the on_start script.
                 else if (
-                  "on_start" == function->first._name
+                  "on_start" == function->first.name
                   && (*instruction)->GetDestAddress() <= (*instruction)->_address
                 ){
                     AddOutputLine("-- No infinite loops in the on_start script.");
@@ -217,20 +217,20 @@ float FF7::FieldCodeGenerator::GetScaleFactor() const
 {return static_cast<FieldEngine*>(engine_)->GetScaleFactor();}
 
 void FF7::FieldCodeGenerator::OnBeforeStartFunction(const Function& function){
-    FunctionMetaData meta_data(function._metadata);
+    FunctionMetaData meta_data(function.metadata);
     if (meta_data.IsStart()){
         AddOutputLine("EntityContainer[\"" + meta_data.GetEntityName() + "\"] = {", false, true);
         if (meta_data.GetCharacterId() != -1)
             AddOutputLine(meta_data.GetEntityName() + " = nil,\n");
     }
-    const auto comment = formatter_.FunctionComment(meta_data.GetEntityName(), function._name);
+    const auto comment = formatter_.FunctionComment(meta_data.GetEntityName(), function.name);
     if (!comment.empty()) AddOutputLine("-- " + comment);
 }
 
 void FF7::FieldCodeGenerator::OnStartFunction(const Function& func){
     AddOutputLine("--[[");
     for (const auto& inst : insts_){
-        if (inst->_address >= func.mStartAddr && inst->_address <= func.mEndAddr){
+        if (inst->_address >= func.start_addr && inst->_address <= func.end_addr){
             std::stringstream output;
             output << inst;
             AddOutputLine(output.str());
@@ -238,7 +238,7 @@ void FF7::FieldCodeGenerator::OnStartFunction(const Function& func){
     }
     AddOutputLine("]]\n");
     // TODO: If this hack is needed, maybe it can just be added to the "Direcor" entity.
-    if (func._name == "on_start" || func._name == "init"){
+    if (func.name == "on_start" || func.name == "init"){
         AddOutputLine("-- HACK ensure camera follows cloud, fix in engine properly later");
         AddOutputLine("background2d:autoscroll_to_entity(entity_manager:get_entity(\"Cloud\"))");
     }
@@ -248,15 +248,15 @@ void FF7::FieldCodeGenerator::OnEndFunction(const Function& function){
     // End function.
     AddOutputLine("end,", true, false);
     // End class?
-    FunctionMetaData meta_data(function._metadata);
+    FunctionMetaData meta_data(function.metadata);
     if (meta_data.IsEnd()) AddOutputLine("}\n\n\n", true, false);
     else AddOutputLine("\n");
 }
 
 std::string FF7::FieldCodeGenerator::ConstructFuncSignature(const Function &function){
     // Generate name
-    FunctionMetaData meta_data(function._metadata);
-    return formatter_.FunctionName(meta_data.GetEntityName(), function._name) + " = function(self)";
+    FunctionMetaData meta_data(function.metadata);
+    return formatter_.FunctionName(meta_data.GetEntityName(), function.name) + " = function(self)";
 }
 
 bool FF7::FieldCodeGenerator::OutputOnlyRequiredLabels() const{return true;}

+ 21 - 19
V-Gears-Installer/src/decompiler/field/FieldDisassembler.cpp

@@ -17,9 +17,10 @@
 #include <boost/format.hpp>
 #include <boost/algorithm/string/split.hpp>
 #include <boost/algorithm/string.hpp>
-#include "decompiler/decompiler_engine.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldDisassembler.h"
+
+#include "../../../include/decompiler/Engine.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/instruction/FieldBackgroundInstruction.h"
 #include "decompiler/field/instruction/FieldCameraInstruction.h"
@@ -110,10 +111,10 @@ uint32 FF7::FieldDisassembler::GetEndOfScriptOffset(
 
 std::unique_ptr<Function> FF7::FieldDisassembler::StartFunction(size_t script_index){
     auto func = std::make_unique<Function>();
-    func->_retVal = false;
-    func->_args = 0;
-    func->_name = "script_" + std::to_string(script_index);
-    func->mStartAddr = address_;
+    func->ret_val = false;
+    func->num_args = 0;
+    func->name = "script_" + std::to_string(script_index);
+    func->start_addr = address_;
     return func;
 }
 
@@ -207,9 +208,9 @@ void FF7::FieldDisassembler::AddFunc(
     else if (is_end) meta_data = "end_";
 
     const size_t new_num_instructions = insts_.size();
-    func->mNumInstructions = new_num_instructions - old_num_instructions;
-    func->mEndAddr = insts_.back()->_address;
-    if (!func_name.empty()) func->_name = func_name;
+    func->num_instructions = new_num_instructions - old_num_instructions;
+    func->end_addr = insts_.back()->_address;
+    if (!func_name.empty()) func->name = func_name;
     if (engine_->EntityIsLine(entity_index)){
         switch (script_index){
             // main   - on_update
@@ -217,23 +218,23 @@ void FF7::FieldDisassembler::AddFunc(
             // [OK]   - on_interact
             case 1: break;
             // Move - on_enter_line
-            case 2: func->_name = "on_enter_line"; break;
+            case 2: func->name = "on_enter_line"; break;
             // Move - on_move_to_line
-            case 3: func->_name = "on_move_to_line"; break;
+            case 3: func->name = "on_move_to_line"; break;
             // Go - on_cross_line
-            case 4: func->_name = "on_cross_line"; break;
+            case 4: func->name = "on_cross_line"; break;
             // Go1x - on_cross_line
-            case 5: func->_name = "on_cross_line_once"; break;
+            case 5: func->name = "on_cross_line_once"; break;
             // GoAway - on_leave_line
-            case 6: func->_name = "on_leave_line"; break;
+            case 6: func->name = "on_leave_line"; break;
         }
     }
-    int id = FindId(func->mStartAddr, func->mEndAddr, insts_);
+    int id = FindId(func->start_addr, func->end_addr, insts_);
     // If there is no ID check if there was an ID for this entity in any of
     // its other functions and use that instead.
     if (id == -1){
-        for (auto& func : engine_->_functions){
-            FunctionMetaData func_meta_data(func.second._metadata);
+        for (auto& func : engine_->GetFunctions()){
+            FunctionMetaData func_meta_data(func.second.metadata);
             if (func_meta_data.GetEntityName() == entity_name && func_meta_data.GetCharacterId() != -1){
                 id = func_meta_data.GetCharacterId();
                 break;
@@ -241,9 +242,10 @@ void FF7::FieldDisassembler::AddFunc(
         }
     }
     meta_data += std::to_string(id) + "_" + entity_name;
-    func->_metadata = meta_data;
-    engine_->_functions[SCRIPT_ENTRY_POINT] = *func;
-    engine_->AddEntityFunction(entity_name, entity_index, func->_name, script_index);
+    func->metadata = meta_data;
+    //engine_->_functions[SCRIPT_ENTRY_POINT] = *func;
+    engine_->SetFunction(SCRIPT_ENTRY_POINT, *func);
+    engine_->AddEntityFunction(entity_name, entity_index, func->name, script_index);
     // If the entity is a line, mark it as so.
     if (is_line) engine_->MarkEntityAsLine(entity_index, true, point_a, point_b);
 }

+ 10 - 10
V-Gears-Installer/src/decompiler/field/FieldEngine.cpp

@@ -148,7 +148,7 @@ std::map<std::string, int> FF7::FieldEngine::GetEntities() const{
     std::map<std::string, int> r;
     for (auto& f : _functions){
         const Function& func = f.second;
-        FF7::FunctionMetaData meta(func._metadata);
+        FF7::FunctionMetaData meta(func.metadata);
         auto it = r.find(meta.GetEntityName());
         if (it != std::end(r)){
             // Try to find a function in this entity has that has a char id.
@@ -174,7 +174,7 @@ std::vector<SUDM::FF7::Field::FieldEntity> FF7::FieldEngine::GetEntityList() con
             std::map<std::string, int> r;
             for (auto& f : _functions){
                 const Function& func = f.second;
-                FF7::FunctionMetaData meta(func._metadata);
+                FF7::FunctionMetaData meta(func.metadata);
                 if (meta.GetEntityName() == ent.name){
                     ent.char_id = meta.GetCharacterId();
                     break;
@@ -243,11 +243,11 @@ void FF7::FieldEngine::RemoveExtraneousReturnStatements(InstVec& insts, Graph gr
         Function& func = f.second;
         for (auto it = insts.begin(); it != insts.end(); it ++){
             // Is it the last instruction in the function, and is it a return statement?
-            if ((*it)->_address == func.mEndAddr){
+            if ((*it)->_address == func.end_addr){
                 if ((*it)->_opcode == OPCODES::RET){
                     // Set new end address to be before the NOP.
-                    func.mEndAddr = (*(it - 1))->_address;
-                    func.mNumInstructions --;
+                    func.end_addr =(*(it - 1))->_address;
+                    func.num_instructions --;
                     Instruction* nop = new FieldNoOperationInstruction();
                     nop->_opcode = OPCODES::NOP;
                     nop->_address = (*it)->_address;
@@ -264,11 +264,11 @@ void FF7::FieldEngine::RemoveTrailingInfiniteLoops(InstVec& insts, Graph graph){
         Function& func = f.second;
         for (auto it = insts.begin(); it != insts.end(); it ++){
             // Is it the last instruction in the function, a jump, and a jumping to itself?
-            if ((*it)->_address == func.mEndAddr){
+            if ((*it)->_address == func.end_addr){
                 if ((*it)->isJump() && (*it)->GetDestAddress() == (*it)->_address){
                     // Set new end address to be before the NOP
-                    func.mEndAddr = (*(it - 1))->_address;
-                    func.mNumInstructions--;
+                    func.end_addr =(*(it - 1))->_address;
+                    func.num_instructions --;
                     Instruction* nop = new FieldNoOperationInstruction();
                     nop->_opcode = OPCODES::NOP;
                     nop->_address = (*it)->_address;
@@ -284,7 +284,7 @@ void FF7::FieldEngine::MarkInfiniteLoopGroups(InstVec& insts, Graph graph){
     for (auto& f : _functions){
         Function& func = f.second;
         for (auto it = insts.begin(); it != insts.end(); it ++){
-            if ((*it)->_address == func.mEndAddr){
+            if ((*it)->_address == func.end_addr){
                 // Note: This is a "best effort heuristic", so quite a few loops will
                 // still end up as goto's. This could potentially generate invalid code too.
                 if ((*it)->IsUncondJump()){
@@ -293,7 +293,7 @@ void FF7::FieldEngine::MarkInfiniteLoopGroups(InstVec& insts, Graph graph){
                     VertexRange vr = boost::vertices(graph);
                     for (VertexIterator v = vr.first; v != vr.second; ++ v){
                         GroupPtr gr = GET(*v);
-                        if ((*gr->start_)->_address == func.mEndAddr){
+                        if ((*gr->start_)->_address == func.end_addr){
                             // Then assume its an infinite do { } while(true) loop
                             // that wraps part of the script.
                             gr->_type = kDoWhileCondGroupType;

+ 1 - 1
V-Gears-Installer/src/decompiler/field/instruction/FieldBackgroundInstruction.cpp

@@ -27,7 +27,7 @@
 void FF7::FieldBackgroundInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
-    FunctionMetaData md(func._metadata);
+    FunctionMetaData md(func.metadata);
     switch (_opcode){
         case OPCODES::BGPDH: code_gen->WriteTodo(md.GetEntityName(), "BGPDH");break;
         case OPCODES::BGSCR: code_gen->WriteTodo(md.GetEntityName(), "BGSCR"); break;

+ 1 - 1
V-Gears-Installer/src/decompiler/field/instruction/FieldCameraInstruction.cpp

@@ -27,7 +27,7 @@
 void FF7::FieldCameraInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
-    FunctionMetaData md(func._metadata);
+    FunctionMetaData md(func.metadata);
     switch (_opcode){
     case OPCODES::NFADE: ProcessNFADE(code_gen); break;
     case OPCODES::SHAKE: code_gen->WriteTodo(md.GetEntityName(), "SHAKE"); break;

+ 2 - 2
V-Gears-Installer/src/decompiler/field/instruction/FieldControlFlowInstruction.cpp

@@ -28,7 +28,7 @@ void FF7::FF7ControlFlowInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
     FF7::FieldEngine& eng = static_cast<FF7::FieldEngine&>(*engine);
-    FunctionMetaData md(func._metadata);
+    FunctionMetaData md(func.metadata);
     switch (_opcode){
         case OPCODES::RET:
             // A few notes in RET.
@@ -39,7 +39,7 @@ void FF7::FF7ControlFlowInstruction::ProcessInst(
             //     'main' return is kept, the code of 'main' is never executed.
             //     There are safeguards forfunctions without a return in the end,
             //     so it's OK not to include it here.
-            if (func._name != "on_start") code_gen->AddOutputLine("do return 0 end");
+            if (func.name != "on_start") code_gen->AddOutputLine("do return 0 end");
             break;
         case OPCODES::REQ: ProcessREQ(code_gen, eng); break;
         case OPCODES::REQSW: ProcessREQSW(code_gen, eng); break;

+ 1 - 1
V-Gears-Installer/src/decompiler/field/instruction/FieldMathInstruction.cpp

@@ -28,7 +28,7 @@ void FF7::FieldMathInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
-    FunctionMetaData md(func._metadata);
+    FunctionMetaData md(func.metadata);
     switch (_opcode){
         case OPCODES::PLUS_: ProcessSaturatedPLUS(code_gen); break;
         case OPCODES::PLUS2_: ProcessSaturatedPLUS2(code_gen); break;

+ 1 - 1
V-Gears-Installer/src/decompiler/field/instruction/FieldMediaInstruction.cpp

@@ -27,7 +27,7 @@
 void FF7::FieldMediaInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
-    FunctionMetaData md(func._metadata);
+    FunctionMetaData md(func.metadata);
     switch (_opcode){
         case OPCODES::BGMOVIE: code_gen->WriteTodo(md.GetEntityName(), "BGMOVIE"); break;
         case OPCODES::AKAO2: ProcessAKAO2(code_gen); break;

+ 1 - 1
V-Gears-Installer/src/decompiler/field/instruction/FieldModelInstruction.cpp

@@ -28,7 +28,7 @@ void FF7::FieldModelInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
     FF7::FieldEngine& eng = static_cast<FF7::FieldEngine&>(*engine);
-    FunctionMetaData md(func._metadata);
+    FunctionMetaData md(func.metadata);
     switch (_opcode){
         case OPCODES::JOIN: ProcessJOIN(code_gen); break;
         case OPCODES::SPLIT: ProcessSPLIT(code_gen); break;

+ 4 - 4
V-Gears-Installer/src/decompiler/field/instruction/FieldModuleInstruction.cpp

@@ -27,7 +27,7 @@
 void FF7::FieldModuleInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
-    FunctionMetaData md(func._metadata);
+    FunctionMetaData md(func.metadata);
     switch (_opcode){
         case OPCODES::DSKCG: code_gen->WriteTodo(md.GetEntityName(), "DSKCG"); break;
         case (OPCODES::SPECIAL << 8) | OPCODES_SPECIAL::ARROW:
@@ -119,12 +119,12 @@ void FF7::FieldModuleInstruction::ProcessBTLON(CodeGenerator* code_gen){
 void FF7::FieldModuleInstruction::ProcessMAPJUMP(CodeGenerator* code_gen, Function& func){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     const auto target_map_id = _params[0]->getUnsigned();
-    FunctionMetaData md(func._metadata);
+    FunctionMetaData md(func.metadata);
     const std::string source_spawn_point_name = cg->GetFormatter().SpawnPointName(
-      target_map_id, md.GetEntityName(), func._name, _address
+      target_map_id, md.GetEntityName(), func.name, _address
     );
     cg->GetFormatter().AddSpawnPoint(
-      target_map_id, md.GetEntityName(), func._name, _address,
+      target_map_id, md.GetEntityName(), func.name, _address,
       _params[1]->getSigned(), // X
       _params[2]->getSigned(), // Y
       _params[3]->getSigned(), // Walk mesh triangle ID

+ 1 - 1
V-Gears-Installer/src/decompiler/field/instruction/FieldPartyInstruction.cpp

@@ -27,7 +27,7 @@
 void FF7::FieldPartyInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
-    FunctionMetaData md(func._metadata);
+    FunctionMetaData md(func.metadata);
     switch (_opcode){
         case OPCODES::SPTYE: code_gen->WriteTodo(md.GetEntityName(), "SPTYE"); break;
         case OPCODES::GTPYE: code_gen->WriteTodo(md.GetEntityName(), "GTPYE"); break;

+ 1 - 1
V-Gears-Installer/src/decompiler/field/instruction/FieldUncategorizedInstruction.cpp

@@ -27,7 +27,7 @@
 void FF7::FieldUncategorizedInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
-    FunctionMetaData md(func._metadata);
+    FunctionMetaData md(func.metadata);
     switch (_opcode){
         case OPCODES::MPDSP: code_gen->WriteTodo(md.GetEntityName(), "MPDSP"); break;
         case OPCODES::SETX: code_gen->WriteTodo(md.GetEntityName(), "SETX"); break;

+ 1 - 1
V-Gears-Installer/src/decompiler/field/instruction/FieldWalkmeshInstruction.cpp

@@ -27,7 +27,7 @@
 void FF7::FieldWalkmeshInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
-    FunctionMetaData md(func._metadata);
+    FunctionMetaData md(func.metadata);
     switch (_opcode){
         case OPCODES::SLIP: code_gen->WriteTodo(md.GetEntityName(), "SLIP"); break;
         case OPCODES::UC: ProcessUC(code_gen); break;

+ 1 - 1
V-Gears-Installer/src/decompiler/field/instruction/FieldWindowInstruction.cpp

@@ -28,7 +28,7 @@ void FF7::FieldWindowInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
     FF7::FieldEngine& eng = static_cast<FF7::FieldEngine&>(*engine);
-    FunctionMetaData md(func._metadata);
+    FunctionMetaData md(func.metadata);
     switch (_opcode){
         case OPCODES::TUTOR: code_gen->WriteTodo(md.GetEntityName(), "TUTOR"); break;
         case OPCODES::WCLS: code_gen->WriteTodo(md.GetEntityName(), "WCLS"); break;

+ 4 - 3
V-Gears-Installer/src/decompiler/graph.cpp

@@ -20,12 +20,13 @@
  */
 
 #include "decompiler/graph.h"
-#include "decompiler/decompiler_engine.h"
+
+#include "../../include/decompiler/Engine.h"
 
 void GraphProperties::operator()(std::ostream& out) const {
 	out << "node [shape=record]" << std::endl;
-	for (FuncMap::iterator fn = _engine->_functions.begin(); fn != _engine->_functions.end(); ++fn) {
-		int index = (boost::get(boost::vertex_index, *_g, fn->second._v));
+	for (FuncMap::iterator fn = _engine->GetFunctions().begin(); fn != _engine->GetFunctions().end(); ++fn) {
+		int index = (boost::get(boost::vertex_index, *_g, fn->second.vertex));
 		out << "XXX" << index << " [shape=none, label=\"\", height=0]" << std::endl;
 		out << "XXX" << index << " -> " << index << std::endl;
 	}

+ 1 - 1
V-Gears-Installer/src/decompiler/instruction.cpp

@@ -22,7 +22,7 @@
 #include "decompiler/instruction.h"
 
 #include "../../include/decompiler/CodeGenerator.h"
-#include "decompiler/decompiler_engine.h"
+#include "../../include/decompiler/Engine.h"
 
 bool outputStackEffect = true;
 

+ 1 - 1
V-Gears-Installer/src/decompiler/sudm.cpp

@@ -47,7 +47,7 @@ namespace SUDM{
                 ::FF7::FieldEngine engine(formatter, script_name);
                 InstVec insts;
                 auto disassembler = engine.GetDisassembler(insts, script_bytes);
-                disassembler->disassemble();
+                disassembler->Disassemble();
                 // Create control flow group.
                 auto control_flow = std::make_unique<ControlFlow>(insts, engine);
                 control_flow->CreateGroups();

+ 1 - 1
V-Gears-Installer/src/decompiler/world/WorldCodeGenerator.cpp

@@ -22,7 +22,7 @@ FF7::WorldCodeGenerator::WorldCodeGenerator(Engine *engine, std::ostream &output
 
 std::string FF7::WorldCodeGenerator::ConstructFuncSignature(const Function& function){
     // TODO: Implement.
-    return function._name + " = function(self)";
+    return function.name + " = function(self)";
 }
 
 const InstPtr FF7::WorldCodeGenerator::FindFirstCall(){