Selaa lähdekoodia

Installer: Code refactoring. Field and world instructions separated to their own files. More old SUDM code removed.

Iñigo Valentin 3 vuotta sitten
vanhempi
sitoutus
65efc0f2e2
100 muutettua tiedostoa jossa 6981 lisäystä ja 5222 poistoa
  1. 4 3
      CMakeLists.txt
  2. 26 0
      V-Gears-Installer/CMakeLists.txt
  3. 1 1
      V-Gears-Installer/include/common/BinaryReader.h
  4. 5 6
      V-Gears-Installer/include/common/OgreBase.h
  5. 4 5
      V-Gears-Installer/include/common/OgreGenUtilites.h
  6. 1 3
      V-Gears-Installer/include/common/Surface.h
  7. 1 3
      V-Gears-Installer/include/common/Vram.h
  8. 233 221
      V-Gears-Installer/include/common/scummsys.h
  9. 15 4
      V-Gears-Installer/include/decompiler/decompiler_codegen.h
  10. 5 5
      V-Gears-Installer/include/decompiler/decompiler_disassembler.h
  11. 3 1
      V-Gears-Installer/include/decompiler/decompiler_engine.h
  12. 394 391
      V-Gears-Installer/include/decompiler/field/FieldCodeGenerator.h
  13. 678 626
      V-Gears-Installer/include/decompiler/field/FieldDisassembler.h
  14. 379 376
      V-Gears-Installer/include/decompiler/field/FieldEngine.h
  15. 38 34
      V-Gears-Installer/include/decompiler/field/instruction/FieldBackgroundInstruction.h
  16. 32 28
      V-Gears-Installer/include/decompiler/field/instruction/FieldCameraInstruction.h
  17. 42 40
      V-Gears-Installer/include/decompiler/field/instruction/FieldCondJumpInstruction.h
  18. 160 155
      V-Gears-Installer/include/decompiler/field/instruction/FieldControlFlowInstruction.h
  19. 89 83
      V-Gears-Installer/include/decompiler/field/instruction/FieldMathInstruction.h
  20. 36 32
      V-Gears-Installer/include/decompiler/field/instruction/FieldMediaInstruction.h
  21. 360 343
      V-Gears-Installer/include/decompiler/field/instruction/FieldModelInstruction.h
  22. 98 90
      V-Gears-Installer/include/decompiler/field/instruction/FieldModuleInstruction.h
  23. 34 30
      V-Gears-Installer/include/decompiler/field/instruction/FieldNoOperationInstruction.h
  24. 30 26
      V-Gears-Installer/include/decompiler/field/instruction/FieldPartyInstruction.h
  25. 23 19
      V-Gears-Installer/include/decompiler/field/instruction/FieldUncategorizedInstruction.h
  26. 57 54
      V-Gears-Installer/include/decompiler/field/instruction/FieldUncondJumpInstruction.h
  27. 62 57
      V-Gears-Installer/include/decompiler/field/instruction/FieldWalkmeshInstruction.h
  28. 33 29
      V-Gears-Installer/include/decompiler/field/instruction/FieldWindowInstruction.h
  29. 7 7
      V-Gears-Installer/include/decompiler/graph.h
  30. 0 10
      V-Gears-Installer/include/decompiler/instruction.h
  31. 3 3
      V-Gears-Installer/include/decompiler/simple_disassembler.h
  32. 77 76
      V-Gears-Installer/include/decompiler/sudm.h
  33. 2 2
      V-Gears-Installer/include/decompiler/test/disassembler/pasc.cpp
  34. 1 1
      V-Gears-Installer/include/decompiler/test/disassembler/pasc.h
  35. 1 1
      V-Gears-Installer/include/decompiler/test/disassembler/subopcode.cpp
  36. 1 1
      V-Gears-Installer/include/decompiler/test/disassembler/subopcode.h
  37. 71 71
      V-Gears-Installer/include/decompiler/test/ff7_field_all_opcodes_disassembler_test.cpp
  38. 17 17
      V-Gears-Installer/include/decompiler/test/ff7_field_control_flow_test.cpp
  39. 144 144
      V-Gears-Installer/include/decompiler/test/ff7_field_disasm_all_opcodes_by_category_test.cpp
  40. 15 15
      V-Gears-Installer/include/decompiler/test/main.cpp
  41. 76 0
      V-Gears-Installer/include/decompiler/world/WorldCodeGenerator.h
  42. 83 0
      V-Gears-Installer/include/decompiler/world/WorldDisassembler.h
  43. 115 0
      V-Gears-Installer/include/decompiler/world/WorldEngine.h
  44. 0 21
      V-Gears-Installer/include/decompiler/world/ff7_world_codegen.h
  45. 0 18
      V-Gears-Installer/include/decompiler/world/ff7_world_disassembler.h
  46. 0 108
      V-Gears-Installer/include/decompiler/world/ff7_world_engine.h
  47. 45 0
      V-Gears-Installer/include/decompiler/world/instruction/WorldBinaryEqualStackInstruction.h
  48. 60 0
      V-Gears-Installer/include/decompiler/world/instruction/WorldCondJumpInstruction.h
  49. 45 0
      V-Gears-Installer/include/decompiler/world/instruction/WorldKernelCallInstruction.h
  50. 46 0
      V-Gears-Installer/include/decompiler/world/instruction/WorldLoadBankInstruction.h
  51. 46 0
      V-Gears-Installer/include/decompiler/world/instruction/WorldLoadInstruction.h
  52. 46 0
      V-Gears-Installer/include/decompiler/world/instruction/WorldNoOutputInstruction.h
  53. 46 0
      V-Gears-Installer/include/decompiler/world/instruction/WorldStackInstruction.h
  54. 46 0
      V-Gears-Installer/include/decompiler/world/instruction/WorldStoreInstruction.h
  55. 45 0
      V-Gears-Installer/include/decompiler/world/instruction/WorldSubStackInstruction.h
  56. 90 0
      V-Gears-Installer/include/decompiler/world/instruction/WorldUncondJumpInstruction.h
  57. 3 9
      V-Gears-Installer/src/common/OgreBase.cpp
  58. 12 44
      V-Gears-Installer/src/common/OgreGenUtilites.cpp
  59. 5 12
      V-Gears-Installer/src/common/Surface.cpp
  60. 14 30
      V-Gears-Installer/src/common/TimToVram.cpp
  61. 10 20
      V-Gears-Installer/src/common/Vram.cpp
  62. 31 31
      V-Gears-Installer/src/decompiler/control_flow.cpp
  63. 1 4
      V-Gears-Installer/src/decompiler/decompiler.cpp
  64. 27 27
      V-Gears-Installer/src/decompiler/decompiler_codegen.cpp
  65. 8 8
      V-Gears-Installer/src/decompiler/decompiler_disassembler.cpp
  66. 27 29
      V-Gears-Installer/src/decompiler/field/FieldCodeGenerator.cpp
  67. 951 438
      V-Gears-Installer/src/decompiler/field/FieldDisassembler.cpp
  68. 76 77
      V-Gears-Installer/src/decompiler/field/FieldEngine.cpp
  69. 55 52
      V-Gears-Installer/src/decompiler/field/instruction/FieldBackgroundInstruction.cpp
  70. 37 34
      V-Gears-Installer/src/decompiler/field/instruction/FieldCameraInstruction.cpp
  71. 30 27
      V-Gears-Installer/src/decompiler/field/instruction/FieldCondJumpInstruction.cpp
  72. 20 18
      V-Gears-Installer/src/decompiler/field/instruction/FieldControlFlowInstruction.cpp
  73. 80 77
      V-Gears-Installer/src/decompiler/field/instruction/FieldMathInstruction.cpp
  74. 43 40
      V-Gears-Installer/src/decompiler/field/instruction/FieldMediaInstruction.cpp
  75. 177 166
      V-Gears-Installer/src/decompiler/field/instruction/FieldModelInstruction.cpp
  76. 45 43
      V-Gears-Installer/src/decompiler/field/instruction/FieldModuleInstruction.cpp
  77. 4 1
      V-Gears-Installer/src/decompiler/field/instruction/FieldNoOperationInstruction.cpp
  78. 35 32
      V-Gears-Installer/src/decompiler/field/instruction/FieldPartyInstruction.cpp
  79. 9 6
      V-Gears-Installer/src/decompiler/field/instruction/FieldUncategorizedInstruction.cpp
  80. 22 18
      V-Gears-Installer/src/decompiler/field/instruction/FieldUncondJumpInstruction.cpp
  81. 15 12
      V-Gears-Installer/src/decompiler/field/instruction/FieldWalkmeshInstruction.cpp
  82. 35 31
      V-Gears-Installer/src/decompiler/field/instruction/FieldWindowInstruction.cpp
  83. 1 5
      V-Gears-Installer/src/decompiler/instruction.cpp
  84. 40 38
      V-Gears-Installer/src/decompiler/sudm.cpp
  85. 44 0
      V-Gears-Installer/src/decompiler/world/WorldCodeGenerator.cpp
  86. 573 0
      V-Gears-Installer/src/decompiler/world/WorldDisassembler.cpp
  87. 61 0
      V-Gears-Installer/src/decompiler/world/WorldEngine.cpp
  88. 0 35
      V-Gears-Installer/src/decompiler/world/ff7_world_codegen.cpp
  89. 0 229
      V-Gears-Installer/src/decompiler/world/ff7_world_disassembler.cpp
  90. 0 469
      V-Gears-Installer/src/decompiler/world/ff7_world_engine.cpp
  91. 33 0
      V-Gears-Installer/src/decompiler/world/instruction/WorldBinaryEqualStackInstruction.cpp
  92. 39 0
      V-Gears-Installer/src/decompiler/world/instruction/WorldCondJumpInstruction.cpp
  93. 182 0
      V-Gears-Installer/src/decompiler/world/instruction/WorldKernelCallInstruction.cpp
  94. 31 0
      V-Gears-Installer/src/decompiler/world/instruction/WorldLoadBankInstruction.cpp
  95. 31 0
      V-Gears-Installer/src/decompiler/world/instruction/WorldLoadInstruction.cpp
  96. 32 0
      V-Gears-Installer/src/decompiler/world/instruction/WorldNoOutputInstruction.cpp
  97. 32 0
      V-Gears-Installer/src/decompiler/world/instruction/WorldStackInstruction.cpp
  98. 36 0
      V-Gears-Installer/src/decompiler/world/instruction/WorldStoreInstruction.cpp
  99. 53 0
      V-Gears-Installer/src/decompiler/world/instruction/WorldSubStackInstruction.cpp
  100. 50 0
      V-Gears-Installer/src/decompiler/world/instruction/WorldUncondJumpInstruction.cpp

+ 4 - 3
CMakeLists.txt

@@ -208,8 +208,9 @@ set(VGears_INCLUDE_DIRS
     ${CMAKE_CURRENT_SOURCE_DIR}/lib/tinyxml
     ${CMAKE_CURRENT_SOURCE_DIR}/lib/tinyxml
 )
 )
 
 
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20 -fPIC")
-
+# C++20
+# TODO: Try to remove PIC
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -fPIC")
 if (MSVC)
 if (MSVC)
     # Build cpp files on all cores, up virtual mem for PCH's as cotire really makes the compiler scream
     # Build cpp files on all cores, up virtual mem for PCH's as cotire really makes the compiler scream
     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /Zm193")
     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /Zm193")
@@ -217,7 +218,7 @@ if (MSVC)
     add_definitions( -D_CRT_SECURE_NO_WARNINGS )
     add_definitions( -D_CRT_SECURE_NO_WARNINGS )
 else()
 else()
     # Enable C++11, you may need to use -std=c++0x if using an older gcc compiler
     # Enable C++11, you may need to use -std=c++0x if using an older gcc compiler
-    #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -fPIC")
+    #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC")
 endif()
 endif()
 
 
 if (UNIX AND $ENV{COVERAGE}==1)
 if (UNIX AND $ENV{COVERAGE}==1)

+ 26 - 0
V-Gears-Installer/CMakeLists.txt

@@ -52,6 +52,19 @@ set(HEADER_FILES
     include/decompiler/field/FieldDisassembler.h
     include/decompiler/field/FieldDisassembler.h
     include/decompiler/field/FieldEngine.h
     include/decompiler/field/FieldEngine.h
     include/decompiler/field/FieldCodeGenerator.h
     include/decompiler/field/FieldCodeGenerator.h
+    include/decompiler/world/instruction/WorldBinaryEqualStackInstruction.h
+    include/decompiler/world/instruction/WorldCondJumpInstruction.h
+    include/decompiler/world/instruction/WorldKernelCallInstruction.h
+    include/decompiler/world/instruction/WorldLoadBankInstruction.h
+    include/decompiler/world/instruction/WorldLoadInstruction.h
+    include/decompiler/world/instruction/WorldNoOutputInstruction.h
+    include/decompiler/world/instruction/WorldStackInstruction.h
+    include/decompiler/world/instruction/WorldStoreInstruction.h
+    include/decompiler/world/instruction/WorldSubStackInstruction.h
+    include/decompiler/world/instruction/WorldUncondJumpInstruction.h
+    include/decompiler/world/WorldCodeGenerator.h
+    include/decompiler/world/WorldDisassembler.h
+    include/decompiler/world/WorldEngine.h
     include/common/scummsys.h
     include/common/scummsys.h
     include/common/BinaryReader.h
     include/common/BinaryReader.h
     include/common/Lzs.h
     include/common/Lzs.h
@@ -95,6 +108,19 @@ set(SOURCE_FILES
     src/decompiler/field/FieldDisassembler.cpp
     src/decompiler/field/FieldDisassembler.cpp
     src/decompiler/field/FieldEngine.cpp
     src/decompiler/field/FieldEngine.cpp
     src/decompiler/field/FieldCodeGenerator.cpp
     src/decompiler/field/FieldCodeGenerator.cpp
+    src/decompiler/world/instruction/WorldBinaryEqualStackInstruction.cpp
+    src/decompiler/world/instruction/WorldCondJumpInstruction.cpp
+    src/decompiler/world/instruction/WorldKernelCallInstruction.cpp
+    src/decompiler/world/instruction/WorldLoadBankInstruction.cpp
+    src/decompiler/world/instruction/WorldLoadInstruction.cpp
+    src/decompiler/world/instruction/WorldNoOutputInstruction.cpp
+    src/decompiler/world/instruction/WorldStackInstruction.cpp
+    src/decompiler/world/instruction/WorldStoreInstruction.cpp
+    src/decompiler/world/instruction/WorldSubStackInstruction.cpp
+    src/decompiler/world/instruction/WorldUncondJumpInstruction.cpp
+    src/decompiler/world/WorldCodeGenerator.cpp
+    src/decompiler/world/WorldDisassembler.cpp
+    src/decompiler/world/WorldEngine.cpp
 )
 )
 
 
 # For SUDM. TODO: Add elses.
 # For SUDM. TODO: Add elses.

+ 1 - 1
V-Gears-Installer/include/common/BinaryReader.h

@@ -21,7 +21,7 @@
 #include "decompiler/unknown_opcode_exception.h"
 #include "decompiler/unknown_opcode_exception.h"
 
 
 /**
 /**
- * REader for binary files.
+ * Reader for binary files.
  */
  */
 class BinaryReader{
 class BinaryReader{
 
 

+ 5 - 6
V-Gears-Installer/include/common/OgreBase.h

@@ -63,6 +63,7 @@ class DisplayFrameListener :
 {
 {
 
 
     public:
     public:
+        // Constructor takes a RenderWindow because it uses that to determine input context
 
 
         /**
         /**
          * Constructor.
          * Constructor.
@@ -81,15 +82,13 @@ class DisplayFrameListener :
             std::ostringstream window_hnd_str;
             std::ostringstream window_hnd_str;
             win->getCustomAttribute("WINDOW", &window_hnd);
             win->getCustomAttribute("WINDOW", &window_hnd);
             window_hnd_str << window_hnd;
             window_hnd_str << window_hnd;
-            pl.insert(
-              std::make_pair(std::string("WINDOW"), window_hnd_str.str())
-            );
+            pl.insert(std::make_pair(std::string("WINDOW"), window_hnd_str.str()));
             input_manager_ = InputManager::createInputSystem(pl);
             input_manager_ = InputManager::createInputSystem(pl);
-            keyboard_ = static_cast<Keyboard*> (
+            keyboard_ = static_cast<Keyboard*>(
               input_manager_->createInputObject(OIS::OISKeyboard, true)
               input_manager_->createInputObject(OIS::OISKeyboard, true)
             );
             );
             keyboard_->setEventCallback(this);
             keyboard_->setEventCallback(this);
-            mouse_ = static_cast<OIS::Mouse*> (
+            mouse_ = static_cast<OIS::Mouse*>(
               input_manager_->createInputObject(OIS::OISMouse, true)
               input_manager_->createInputObject(OIS::OISMouse, true)
             );
             );
             mouse_->setEventCallback(this);
             mouse_->setEventCallback(this);
@@ -226,7 +225,7 @@ class DisplayFrameListener :
                 case OIS::KC_UP:
                 case OIS::KC_UP:
                     {
                     {
                         bool change = false;
                         bool change = false;
-                        for (unsigned int i = 0; i < entities.size(); ++i){
+                        for (unsigned int i = 0; i < entities.size(); ++ i){
                             if (entities[i]->isVisible() == true){
                             if (entities[i]->isVisible() == true){
                                 Ogre::AnimationStateIterator animations
                                 Ogre::AnimationStateIterator animations
                                   = entities[i]->getAllAnimationStates()
                                   = entities[i]->getAllAnimationStates()

+ 4 - 5
V-Gears-Installer/include/common/OgreGenUtilites.h

@@ -164,7 +164,7 @@ void CreateMaterial(
  * @param texture_y[in] Y coordinate for the texture.
  * @param texture_y[in] Y coordinate for the texture.
  * @param bpp[in] BPP mode for the texture colour.
  * @param bpp[in] BPP mode for the texture colour.
  * @param transparency[in] Indicates if the texture has transparencies.
  * @param transparency[in] Indicates if the texture has transparencies.
- * @todo Whats the difference betwwen start_x/start_y and texture_x/texture_y?
+ * @todo What's the difference between start_x/start_y and texture_x/texture_y?
  */
  */
 void CreateTextureFromVram(
 void CreateTextureFromVram(
   const Ogre::PixelBox& pixel_box, Vram* vram, const int start_x, const int start_y,
   const Ogre::PixelBox& pixel_box, Vram* vram, const int start_x, const int start_y,
@@ -176,14 +176,13 @@ void CreateTextureFromVram(
  * Adds a texture to the list.
  * Adds a texture to the list.
  *
  *
  * @param texture[in] Texture information/
  * @param texture[in] Texture information/
- * @param data[in] Mehs information.
+ * @param data[in] Mesh information.
  * @param textures[in|out] The texture will be added to this list.
  * @param textures[in|out] The texture will be added to this list.
- * @param logger[in] Custom logger to print info abou the process. It can be
+ * @param logger[in] Custom logger to print info about the process. It can be
  * NULL, but then nothing will be printed.
  * NULL, but then nothing will be printed.
  */
  */
 void AddTexture(
 void AddTexture(
-  TexForGen& texture, const MeshData& data, VectorTexForGen& textures,
-  Logger* logger
+  TexForGen& texture, const MeshData& data, VectorTexForGen& textures, Logger* logger
 );
 );
 
 
 /**
 /**

+ 1 - 3
V-Gears-Installer/include/common/Surface.h

@@ -113,6 +113,4 @@ Surface* CreateSubSurface(
  * enough pixels to cover the entire surface, the rest of pixels will be NULL.
  * enough pixels to cover the entire surface, the rest of pixels will be NULL.
  * @return The new surface.
  * @return The new surface.
  */
  */
-Surface* CreateSurfaceFrom(
-  const int width, const int height, unsigned char* pixels
-);
+Surface* CreateSurfaceFrom(const int width, const int height, unsigned char* pixels);

+ 1 - 3
V-Gears-Installer/include/common/Vram.h

@@ -33,9 +33,7 @@ class Vram{
          *
          *
          * @return The VRAM block.
          * @return The VRAM block.
          */
          */
-        static std::unique_ptr<Vram> MakeInstance(){
-            return std::unique_ptr<Vram>(new Vram());
-        }
+        static std::unique_ptr<Vram> MakeInstance(){return std::unique_ptr<Vram>(new Vram());}
 
 
         /**
         /**
          * Destructor.
          * Destructor.

+ 233 - 221
V-Gears-Installer/include/common/scummsys.h

@@ -1,89 +1,101 @@
-/*
- * Copyright (C) 2022 The V-Gears Team
+/* ScummVM Tools
  *
  *
- * This file is part of V-Gears
+ * 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.
  *
  *
- * 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.
+ * Additionally this file is based on the ScummVM source code.
+ * Copyright information for the ScummVM source code is
+ * available in the COPYRIGHT file of the ScummVM source
+ * distribution.
  *
  *
- * V-Gears is distributed in the hope that it will be useful,
+ * 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
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  * 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 COMMON_SCUMMSYS_H
 #ifndef COMMON_SCUMMSYS_H
 #define COMMON_SCUMMSYS_H
 #define COMMON_SCUMMSYS_H
 
 
 
 
 #if defined(_WIN32_WCE) && _WIN32_WCE < 300
 #if defined(_WIN32_WCE) && _WIN32_WCE < 300
-    #define NONSTANDARD_PORT
+	#define NONSTANDARD_PORT
 #endif
 #endif
 
 
 #if defined(NONSTANDARD_PORT)
 #if defined(NONSTANDARD_PORT)
 
 
-    // Ports which need to perform #includes and #defines visible in
-    // virtually all the source of ScummVM should do so by providing a
-    // "portdefs.h" header file (and not by directly modifying this
-    // header file).
-    #include <portdefs.h>
+	// Ports which need to perform #includes and #defines visible in
+	// virtually all the source of ScummVM should do so by providing a
+	// "portdefs.h" header file (and not by directly modifying this
+	// header file).
+	#include <portdefs.h>
 #else // defined(NONSTANDARD_PORT)
 #else // defined(NONSTANDARD_PORT)
 
 
-    #if defined(WIN32)
-
-        #ifdef _MSC_VER
-        // vsnprintf is already defined in Visual Studio 2008
-        #if (_MSC_VER < 1500)
-            #define vsnprintf _vsnprintf
-        #endif
-        #endif
-
-        #if !defined(_WIN32_WCE)
-
-        #define WIN32_LEAN_AND_MEAN        // Exclude rarely-used stuff from Windows headers
-        #define NOGDICAPMASKS
-        #define OEMRESOURCE
-        #define NONLS
-        #define NOICONS
-        #define NOMCX
-        #define NOPROFILER
-        #define NOKANJI
-        #define NOSERVICE
-        #define NOMETAFILE
-        #define NOCOMM
-        #define NOCRYPT
-        #define NOIME
-        #define NOATOM
-        #define NOCTLMGR
-        #define NOCLIPBOARD
-        #define NOMEMMGR
-        #define NOSYSMETRICS
-        #define NOMENUS
-        #define NOOPENFILE
-        #define NOWH
-        #define NOSOUND
-        #define NODRAWTEXT
-
-        #endif
-
-        #if defined(ARRAYSIZE)
-        // VS2005beta2 introduces new stuff in winnt.h
-        #undef ARRAYSIZE
-        #endif
-
-    #endif
-
-    #if defined(__QNXNTO__)
-    #include <strings.h>    /* For strcasecmp */
-    #endif
-
-    #include <stdio.h>
-    #include <stdlib.h>
-    #include <string.h>
-    #include <stdarg.h>
-    #include <assert.h>
-    #include <ctype.h>
-    #include <math.h>
+	#if defined(WIN32)
+
+		#ifdef _MSC_VER
+		// vsnprintf is already defined in Visual Studio 2008
+		#if (_MSC_VER < 1500)
+			#define vsnprintf _vsnprintf
+		#endif
+		#endif
+
+		#if !defined(_WIN32_WCE)
+
+		#define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
+		#define NOGDICAPMASKS
+		#define OEMRESOURCE
+		#define NONLS
+		#define NOICONS
+		#define NOMCX
+		#define NOPROFILER
+		#define NOKANJI
+		#define NOSERVICE
+		#define NOMETAFILE
+		#define NOCOMM
+		#define NOCRYPT
+		#define NOIME
+		#define NOATOM
+		#define NOCTLMGR
+		#define NOCLIPBOARD
+		#define NOMEMMGR
+		#define NOSYSMETRICS
+		#define NOMENUS
+		#define NOOPENFILE
+		#define NOWH
+		#define NOSOUND
+		#define NODRAWTEXT
+
+		#endif
+
+		#if defined(ARRAYSIZE)
+		// VS2005beta2 introduces new stuff in winnt.h
+		#undef ARRAYSIZE
+		#endif
+
+	#endif
+
+	#if defined(__QNXNTO__)
+	#include <strings.h>	/* For strcasecmp */
+	#endif
+
+	#include <stdio.h>
+	#include <stdlib.h>
+	#include <string.h>
+	#include <stdarg.h>
+	#include <assert.h>
+	#include <ctype.h>
+	#include <math.h>
 
 
 #endif
 #endif
 
 
@@ -141,223 +153,223 @@
 
 
 #if defined(__SYMBIAN32__)
 #if defined(__SYMBIAN32__)
 
 
-    #define scumm_stricmp strcasecmp
-    #define scumm_strnicmp strncasecmp
+	#define scumm_stricmp strcasecmp
+	#define scumm_strnicmp strncasecmp
 
 
-    #define SCUMM_LITTLE_ENDIAN
-    #define SCUMM_NEED_ALIGNMENT
+	#define SCUMM_LITTLE_ENDIAN
+	#define SCUMM_NEED_ALIGNMENT
 
 
-    #define SMALL_SCREEN_DEVICE
+	#define SMALL_SCREEN_DEVICE
 
 
-    // Enable Symbians own datatypes
-    // This is done for two reasons
-    // a) uint is already defined by Symbians libc component
-    // b) Symbian is using its "own" datatyping, and the Scummvm port
-    //    should follow this to ensure the best compability possible.
-    #define SCUMMVM_DONT_DEFINE_TYPES
-    typedef unsigned char byte;
+	// Enable Symbians own datatypes
+	// This is done for two reasons
+	// a) uint is already defined by Symbians libc component
+	// b) Symbian is using its "own" datatyping, and the Scummvm port
+	//    should follow this to ensure the best compability possible.
+	#define SCUMMVM_DONT_DEFINE_TYPES
+	typedef unsigned char byte;
 
 
-    typedef unsigned char uint8;
-    typedef signed char int8;
+	typedef unsigned char uint8;
+	typedef signed char int8;
 
 
-    typedef unsigned short int uint16;
-    typedef signed short int int16;
+	typedef unsigned short int uint16;
+	typedef signed short int int16;
 
 
-    typedef unsigned long int uint32;
-    typedef signed long int int32;
+	typedef unsigned long int uint32;
+	typedef signed long int int32;
 
 
 #elif defined(_WIN32_WCE)
 #elif defined(_WIN32_WCE)
 
 
-    #define scumm_stricmp stricmp
-    #define scumm_strnicmp _strnicmp
-    #define snprintf _snprintf
+	#define scumm_stricmp stricmp
+	#define scumm_strnicmp _strnicmp
+	#define snprintf _snprintf
 
 
-    #define SCUMM_LITTLE_ENDIAN
+	#define SCUMM_LITTLE_ENDIAN
 
 
-    #ifndef __GNUC__
-        #define FORCEINLINE __forceinline
-        #define NORETURN_PRE __declspec(noreturn)
-    #endif
-    #define PLUGIN_EXPORT __declspec(dllexport)
+	#ifndef __GNUC__
+		#define FORCEINLINE __forceinline
+		#define NORETURN_PRE __declspec(noreturn)
+	#endif
+	#define PLUGIN_EXPORT __declspec(dllexport)
 
 
-    #if _WIN32_WCE < 300
-    #define SMALL_SCREEN_DEVICE
-    #endif
+	#if _WIN32_WCE < 300
+	#define SMALL_SCREEN_DEVICE
+	#endif
 
 
 #elif defined(_MSC_VER)
 #elif defined(_MSC_VER)
 
 
-    #define scumm_stricmp _stricmp
-    #define scumm_strnicmp _strnicmp
-    #define snprintf _snprintf
+	#define scumm_stricmp _stricmp
+	#define scumm_strnicmp _strnicmp
+	#define snprintf _snprintf
 
 
-    #define SCUMM_LITTLE_ENDIAN
+	#define SCUMM_LITTLE_ENDIAN
 
 
-    #define FORCEINLINE __forceinline
-    #define NORETURN_PRE __declspec(noreturn)
-    #define PLUGIN_EXPORT __declspec(dllexport)
+	#define FORCEINLINE __forceinline
+	#define NORETURN_PRE __declspec(noreturn)
+	#define PLUGIN_EXPORT __declspec(dllexport)
 
 
 
 
 #elif defined(__MINGW32__)
 #elif defined(__MINGW32__)
 
 
-    #define scumm_stricmp stricmp
-    #define scumm_strnicmp strnicmp
+	#define scumm_stricmp stricmp
+	#define scumm_strnicmp strnicmp
 
 
-    #define SCUMM_LITTLE_ENDIAN
+	#define SCUMM_LITTLE_ENDIAN
 
 
-    #define PLUGIN_EXPORT __declspec(dllexport)
+	#define PLUGIN_EXPORT __declspec(dllexport)
 
 
 #elif defined(POSIX)
 #elif defined(POSIX)
 
 
-    #define scumm_stricmp strcasecmp
-    #define scumm_strnicmp strncasecmp
+	#define scumm_stricmp strcasecmp
+	#define scumm_strnicmp strncasecmp
 
 
-    #ifndef CONFIG_H
-        /* need this for the SDL_BYTEORDER define */
-        //#include <SDL_byteorder.h>
+	#ifndef CONFIG_H
+		/* need this for the SDL_BYTEORDER define */
+		//#include <SDL_byteorder.h>
 
 
 #define SDL_BYTEORDER SDL_LIL_ENDIAN
 #define SDL_BYTEORDER SDL_LIL_ENDIAN
 
 
-        #if SDL_BYTEORDER == SDL_LIL_ENDIAN
-        #define SCUMM_LITTLE_ENDIAN
-        #elif SDL_BYTEORDER == SDL_BIG_ENDIAN
-        #define SCUMM_BIG_ENDIAN
-        #else
-        #error Neither SDL_BIG_ENDIAN nor SDL_LIL_ENDIAN is set.
-        #endif
-    #endif
+		#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+		#define SCUMM_LITTLE_ENDIAN
+		#elif SDL_BYTEORDER == SDL_BIG_ENDIAN
+		#define SCUMM_BIG_ENDIAN
+		#else
+		#error Neither SDL_BIG_ENDIAN nor SDL_LIL_ENDIAN is set.
+		#endif
+	#endif
 
 
-    // You need to set this manually if necessary
-//    #define SCUMM_NEED_ALIGNMENT
+	// You need to set this manually if necessary
+//	#define SCUMM_NEED_ALIGNMENT
 
 
-    #if defined(__DECCXX) // Assume alpha architecture
-    #define INVERSE_MKID
-    #define SCUMM_NEED_ALIGNMENT
-    #endif
+	#if defined(__DECCXX) // Assume alpha architecture
+	#define INVERSE_MKID
+	#define SCUMM_NEED_ALIGNMENT
+	#endif
 
 
-#elif defined(__PALMOS_TRAPS__)    || defined (__PALMOS_ARMLET__)
+#elif defined(__PALMOS_TRAPS__)	|| defined (__PALMOS_ARMLET__)
 
 
 #ifdef __PALMOS_ARMLET__
 #ifdef __PALMOS_ARMLET__
-    #include <extras_string.h>
+	#include <extras_string.h>
 #endif
 #endif
-    #define SCUMM_LITTLE_ENDIAN
+	#define SCUMM_LITTLE_ENDIAN
 
 
-    #define scumm_stricmp stricmp
-    #define scumm_strnicmp strnicmp
+	#define scumm_stricmp stricmp
+	#define scumm_strnicmp strnicmp
 
 
-    #define SCUMM_NEED_ALIGNMENT
-    #define STRINGBUFLEN 256
+	#define SCUMM_NEED_ALIGNMENT
+	#define STRINGBUFLEN 256
 
 
-    extern const char *SCUMMVM_SAVEPATH;
+	extern const char *SCUMMVM_SAVEPATH;
 
 
-    #if !defined(COMPILE_ZODIAC) && !defined(COMPILE_OS5)
-    #    define NEWGUI_256
-    #else
-    #    undef UNUSED
-    #endif
+	#if !defined(COMPILE_ZODIAC) && !defined(COMPILE_OS5)
+	#	define NEWGUI_256
+	#else
+	#	undef UNUSED
+	#endif
 
 
 #elif defined(__DC__)
 #elif defined(__DC__)
 
 
-    #define scumm_stricmp strcasecmp
-    #define scumm_strnicmp strncasecmp
+	#define scumm_stricmp strcasecmp
+	#define scumm_strnicmp strncasecmp
 
 
-    #define SCUMM_LITTLE_ENDIAN
-    #define SCUMM_NEED_ALIGNMENT
+	#define SCUMM_LITTLE_ENDIAN
+	#define SCUMM_NEED_ALIGNMENT
 
 
 #elif defined(__GP32__)
 #elif defined(__GP32__)
 
 
-    #define scumm_stricmp stricmp
-    #define scumm_strnicmp strnicmp
+	#define scumm_stricmp stricmp
+	#define scumm_strnicmp strnicmp
 
 
-    #define SCUMM_LITTLE_ENDIAN
-    #define SCUMM_NEED_ALIGNMENT
+	#define SCUMM_LITTLE_ENDIAN
+	#define SCUMM_NEED_ALIGNMENT
 
 
-    // Override typenames. uint is already defined by system header files.
-    #define SCUMMVM_DONT_DEFINE_TYPES
-    typedef unsigned char byte;
+	// Override typenames. uint is already defined by system header files.
+	#define SCUMMVM_DONT_DEFINE_TYPES
+	typedef unsigned char byte;
 
 
-    typedef unsigned char uint8;
-    typedef signed char int8;
+	typedef unsigned char uint8;
+	typedef signed char int8;
 
 
-    typedef unsigned short int uint16;
-    typedef signed short int int16;
+	typedef unsigned short int uint16;
+	typedef signed short int int16;
 
 
-    typedef unsigned long int uint32;
-    typedef signed long int int32;
+	typedef unsigned long int uint32;
+	typedef signed long int int32;
 
 
 #elif defined(__PLAYSTATION2__)
 #elif defined(__PLAYSTATION2__)
 
 
-    #define scumm_stricmp strcasecmp
-    #define scumm_strnicmp strncasecmp
+	#define scumm_stricmp strcasecmp
+	#define scumm_strnicmp strncasecmp
 
 
-    #define SCUMM_LITTLE_ENDIAN
-    #define SCUMM_NEED_ALIGNMENT
+	#define SCUMM_LITTLE_ENDIAN
+	#define SCUMM_NEED_ALIGNMENT
 
 
 #elif defined(__N64__)
 #elif defined(__N64__)
 
 
-    #define scumm_stricmp strcasecmp
-    #define scumm_strnicmp strncasecmp
+	#define scumm_stricmp strcasecmp
+	#define scumm_strnicmp strncasecmp
 
 
-    #define SCUMM_BIG_ENDIAN
-    #define SCUMM_NEED_ALIGNMENT
+	#define SCUMM_BIG_ENDIAN
+	#define SCUMM_NEED_ALIGNMENT
 
 
-    #define STRINGBUFLEN 256
+	#define STRINGBUFLEN 256
 
 
-    #define SCUMMVM_DONT_DEFINE_TYPES
-    typedef unsigned char byte;
+	#define SCUMMVM_DONT_DEFINE_TYPES
+	typedef unsigned char byte;
 
 
-    typedef unsigned char uint8;
-    typedef signed char int8;
+	typedef unsigned char uint8;
+	typedef signed char int8;
 
 
-    typedef unsigned short int uint16;
-    typedef signed short int int16;
+	typedef unsigned short int uint16;
+	typedef signed short int int16;
 
 
-    typedef unsigned int uint32;
-    typedef signed int int32;
+	typedef unsigned int uint32;
+	typedef signed int int32;
 
 
-    typedef unsigned long long uint64;
-    typedef signed long long int64;
+	typedef unsigned long long uint64;
+	typedef signed long long int64;
 
 
 #elif defined(__PSP__)
 #elif defined(__PSP__)
 
 
-    #include <malloc.h>
+	#include <malloc.h>
 
 
-    #define scumm_stricmp strcasecmp
-    #define scumm_strnicmp strncasecmp
+	#define scumm_stricmp strcasecmp
+	#define scumm_strnicmp strncasecmp
 
 
-    #define    SCUMM_LITTLE_ENDIAN
-    #define    SCUMM_NEED_ALIGNMENT
+	#define	SCUMM_LITTLE_ENDIAN
+	#define	SCUMM_NEED_ALIGNMENT
 
 
 #elif defined(__amigaos4__)
 #elif defined(__amigaos4__)
 
 
-    #define    scumm_stricmp strcasecmp
-    #define    scumm_strnicmp strncasecmp
+	#define	scumm_stricmp strcasecmp
+	#define	scumm_strnicmp strncasecmp
 
 
-    #define    SCUMM_BIG_ENDIAN
-    #define    SCUMM_NEED_ALIGNMENT
+	#define	SCUMM_BIG_ENDIAN
+	#define	SCUMM_NEED_ALIGNMENT
 
 
 #elif defined (__DS__)
 #elif defined (__DS__)
 
 
-    #define scumm_stricmp stricmp
-    #define scumm_strnicmp strnicmp
+	#define scumm_stricmp stricmp
+	#define scumm_strnicmp strnicmp
 
 
-    #define SCUMM_NEED_ALIGNMENT
-    #define SCUMM_LITTLE_ENDIAN
+	#define SCUMM_NEED_ALIGNMENT
+	#define SCUMM_LITTLE_ENDIAN
 
 
-    #define SCUMMVM_DONT_DEFINE_TYPES
+	#define SCUMMVM_DONT_DEFINE_TYPES
 
 
-    #define STRINGBUFLEN 256
-//    #define printf(fmt, ...)                    consolePrintf(fmt, ##__VA_ARGS__)
+	#define STRINGBUFLEN 256
+//	#define printf(fmt, ...)					consolePrintf(fmt, ##__VA_ARGS__)
 
 
 #elif defined(__WII__)
 #elif defined(__WII__)
 
 
-    #define scumm_stricmp strcasecmp
-    #define scumm_strnicmp strncasecmp
+	#define scumm_stricmp strcasecmp
+	#define scumm_strnicmp strncasecmp
 
 
-    #define    SCUMM_BIG_ENDIAN
-    #define    SCUMM_NEED_ALIGNMENT
+	#define	SCUMM_BIG_ENDIAN
+	#define	SCUMM_NEED_ALIGNMENT
 
 
 #else
 #else
-    #error No system type defined
+	#error No system type defined
 
 
 #endif
 #endif
 
 
@@ -366,16 +378,16 @@
 // GCC specific stuff
 // GCC specific stuff
 //
 //
 #if defined(__GNUC__)
 #if defined(__GNUC__)
-    #define NORETURN_POST __attribute__((__noreturn__))
-    #define PACKED_STRUCT __attribute__((__packed__))
-    #define GCC_PRINTF(x,y) __attribute__((__format__(printf, x, y)))
+	#define NORETURN_POST __attribute__((__noreturn__))
+	#define PACKED_STRUCT __attribute__((__packed__))
+	#define GCC_PRINTF(x,y) __attribute__((__format__(printf, x, y)))
 
 
-    #if !defined(FORCEINLINE) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
-        #define FORCEINLINE inline __attribute__((__always_inline__))
-    #endif
+	#if !defined(FORCEINLINE) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
+		#define FORCEINLINE inline __attribute__((__always_inline__))
+	#endif
 #else
 #else
-    #define PACKED_STRUCT
-    #define GCC_PRINTF(x,y)
+	#define PACKED_STRUCT
+	#define GCC_PRINTF(x,y)
 #endif
 #endif
 
 
 
 
@@ -391,11 +403,11 @@
 #endif
 #endif
 
 
 #ifndef NORETURN_PRE
 #ifndef NORETURN_PRE
-#define    NORETURN_PRE
+#define	NORETURN_PRE
 #endif
 #endif
 
 
 #ifndef NORETURN_POST
 #ifndef NORETURN_POST
-#define    NORETURN_POST
+#define	NORETURN_POST
 #endif
 #endif
 
 
 #ifndef STRINGBUFLEN
 #ifndef STRINGBUFLEN
@@ -415,14 +427,14 @@
 // Typedef our system types unless SCUMMVM_DONT_DEFINE_TYPES is set.
 // Typedef our system types unless SCUMMVM_DONT_DEFINE_TYPES is set.
 //
 //
 #ifndef SCUMMVM_DONT_DEFINE_TYPES
 #ifndef SCUMMVM_DONT_DEFINE_TYPES
-    typedef unsigned char byte;
-    typedef unsigned char uint8;
-    typedef signed char int8;
-    typedef unsigned short uint16;
-    typedef signed short int16;
-    typedef unsigned int uint32;
-    typedef signed int int32;
-    typedef unsigned int uint;
+	typedef unsigned char byte;
+	typedef unsigned char uint8;
+	typedef signed char int8;
+	typedef unsigned short uint16;
+	typedef signed short int16;
+	typedef unsigned int uint32;
+	typedef signed int int32;
+	typedef unsigned int uint;
 #endif
 #endif
 
 
 
 
@@ -431,11 +443,11 @@
 // Overlay color type (FIXME: shouldn't be declared here)
 // Overlay color type (FIXME: shouldn't be declared here)
 //
 //
 #if defined(NEWGUI_256)
 #if defined(NEWGUI_256)
-    // 256 color only on PalmOS
-    typedef byte OverlayColor;
+	// 256 color only on PalmOS
+	typedef byte OverlayColor;
 #else
 #else
-    // 15/16 bit color mode everywhere else...
-    typedef uint16 OverlayColor;
+	// 15/16 bit color mode everywhere else...
+	typedef uint16 OverlayColor;
 #endif
 #endif
 
 
 
 

+ 15 - 4
V-Gears-Installer/include/decompiler/decompiler_codegen.h

@@ -306,8 +306,8 @@ protected:
      * @param inst The instruction to process.
      * @param inst The instruction to process.
      */
      */
     void ProcessInst(Function& func, InstVec& insts, const InstPtr inst);
     void ProcessInst(Function& func, InstVec& insts, const InstPtr inst);
-    void processUncondJumpInst(Function& func, InstVec& insts, const InstPtr inst);
-    void processCondJumpInst(const InstPtr inst);
+    void ProcessUncondJumpInst(Function& func, InstVec& insts, const InstPtr inst);
+    void ProcessCondJumpInst(const InstPtr inst);
 
 
     /**
     /**
      * Indents a string according to the current indentation level.
      * Indents a string according to the current indentation level.
@@ -343,7 +343,7 @@ public:
     const ArgOrder _binOrder;  ///< Order of operands for binary operations.
     const ArgOrder _binOrder;  ///< Order of operands for binary operations.
     const ArgOrder _callOrder; ///< Order of operands for call arguments.
     const ArgOrder _callOrder; ///< Order of operands for call arguments.
     ValueList _argList;        ///< Storage for lists of arguments to be built when processing function calls.
     ValueList _argList;        ///< Storage for lists of arguments to be built when processing function calls.
-    GroupPtr mCurGroup;     ///< Pointer to the group currently being processed.
+    GroupPtr cur_group_;     ///< Pointer to the group currently being processed.
 
 
     virtual ~CodeGenerator() { }
     virtual ~CodeGenerator() { }
 
 
@@ -373,6 +373,17 @@ public:
      */
      */
     virtual void AddOutputLine(std::string s, bool unindentBefore = false, bool indentAfter = false);
     virtual void AddOutputLine(std::string s, bool unindentBefore = false, bool indentAfter = false);
 
 
+    /**
+     * Writes a comment line indicating an unimplemented opcode.
+     *
+     * @param code_gen[in|out] The code generator.
+     * @param class_name[in] The class where the instruction is. Unused.
+     * @param instruction[in] The unimplemented instruction.
+     */
+    void WriteTodo(std::string class_name, std::string instruction){
+        AddOutputLine("-- UNIMPLMENTED INSTRUCTION: \"" + instruction + "\")");
+    }
+
     /**
     /**
      * Generate an assignment statement.
      * Generate an assignment statement.
      *
      *
@@ -395,5 +406,5 @@ public:
      * @param c The character signifying the action to be taken.
      * @param c The character signifying the action to be taken.
      * @param pos The position at which c occurred in the metadata.
      * @param pos The position at which c occurred in the metadata.
      */
      */
-    virtual void processSpecialMetadata(const InstPtr inst, char c, int pos);
+    virtual void ProcessSpecialMetadata(const InstPtr inst, char c, int pos);
 };
 };

+ 5 - 5
V-Gears-Installer/include/decompiler/decompiler_disassembler.h

@@ -25,8 +25,8 @@
 #include <iostream>
 #include <iostream>
 #include <vector>
 #include <vector>
 
 
+#include "../common/BinaryReader.h"
 #include "instruction.h"
 #include "instruction.h"
-#include "common/BinaryReader.h"
 #include "unknown_opcode_exception.h"
 #include "unknown_opcode_exception.h"
 #include "objectFactory.h"
 #include "objectFactory.h"
 
 
@@ -36,7 +36,7 @@
 class Disassembler {
 class Disassembler {
 protected:
 protected:
 	std::unique_ptr<BinaryReader> stream_;                         ///< Used to perform file I/O.
 	std::unique_ptr<BinaryReader> stream_;                         ///< Used to perform file I/O.
-	InstVec &_insts;                              ///< Container for disassembled instructions.
+	InstVec &insts_;                              ///< Container for disassembled instructions.
 	uint32 address_base_;                          ///< Base address where the script starts.
 	uint32 address_base_;                          ///< Base address where the script starts.
 
 
 	/**
 	/**
@@ -51,7 +51,7 @@ protected:
 	 *
 	 *
 	 * @param output The std::ostream to output to.
 	 * @param output The std::ostream to output to.
 	 */
 	 */
-	virtual void DoDumpDisassembly(std::ostream &output);
+	virtual void doDumpDisassembly(std::ostream &output);
 
 
 public:
 public:
 	/**
 	/**
@@ -74,13 +74,13 @@ public:
 	 *
 	 *
 	 * @return An std::vector containing the disassembled instructions.
 	 * @return An std::vector containing the disassembled instructions.
 	 */
 	 */
-	void Disassemble();
+	void disassemble();
 
 
 	/**
 	/**
 	 * Outputs the disassembled code. Disassembles code if this has not already been done.
 	 * Outputs the disassembled code. Disassembles code if this has not already been done.
 	 *
 	 *
 	 * @param output The std::ostream to output to.
 	 * @param output The std::ostream to output to.
 	 */
 	 */
-	void DumpDisassembly(std::ostream &output);
+	void dumpDisassembly(std::ostream &output);
 };
 };
 #endif
 #endif

+ 3 - 1
V-Gears-Installer/include/decompiler/decompiler_engine.h

@@ -74,6 +74,7 @@ typedef std::map<uint32, Function> FuncMap;
 class Engine 
 class Engine 
 {
 {
 public:
 public:
+
     virtual ~Engine() = default;
     virtual ~Engine() = default;
 
 
     virtual std::unique_ptr<Disassembler> GetDisassembler(InstVec &, const std::vector<unsigned char>& )
     virtual std::unique_ptr<Disassembler> GetDisassembler(InstVec &, const std::vector<unsigned char>& )
@@ -126,7 +127,7 @@ public:
 	 *
 	 *
 	 * @param variants Vector to add the supported variants to.
 	 * @param variants Vector to add the supported variants to.
 	 */
 	 */
-	virtual void getVariants(std::vector<std::string>&) const { };
+	virtual void GetVariants(std::vector<std::string>&) const { };
 
 
 	std::string _variant; ///< Engine variant to use for the script.
 	std::string _variant; ///< Engine variant to use for the script.
 
 
@@ -138,6 +139,7 @@ public:
 	 * @return True if pure grouping should be used, false if not.
 	 * @return True if pure grouping should be used, false if not.
 	 */
 	 */
 	virtual bool UsePureGrouping() const { return false; }
 	virtual bool UsePureGrouping() const { return false; }
+
 };
 };
 
 
 #endif
 #endif

+ 394 - 391
V-Gears-Installer/include/decompiler/field/FieldCodeGenerator.h

@@ -15,400 +15,403 @@
 
 
 #pragma once
 #pragma once
 
 
-#include "decompiler/decompiler_codegen.h"
 #include <boost/algorithm/string.hpp>
 #include <boost/algorithm/string.hpp>
 #include <deque>
 #include <deque>
 #include <unordered_map>
 #include <unordered_map>
+#include "decompiler/decompiler_codegen.h"
 #include "decompiler/sudm.h"
 #include "decompiler/sudm.h"
 
 
-/**
- * Parses an stores function metadata.
- *
- * Function metadata can indicate the entity and character of a function, and
- * if the function is the first or last in a class.
- */
-class FunctionMetaData{
-
-    public:
-
-        /**
-         * Constructor. Parses function metadata.
-         *
-         * Meta data format can be:
-         * - start_end_entityname
-         * - start_entityname
-         * - end_entity_name
-         *
-         * @param meta_data[in] Metadata to parse.
-         */
-        FunctionMetaData(std::string meta_data);
-
-        /**
-         * Checks if the function is the first of a class.
-         *
-         * @return True if the metadata is the first of a class, false
-         * otherwise.
-         */
-        bool IsStart() const;
-
-        /**
-         * Checks if the function is the last of a class.
-         *
-         * @return True if the metadata is the last of a class, false
-         * otherwise.
-         */
-        bool IsEnd() const;
-
-        /**
-         * Retrieves the entity name.
-         *
-         * @return The entity name.
-         */
-        std::string GetEntityName();
-
-        /**
-         * Retrieves the character ID.
-         *
-         * @return The chaacter ID.
-         */
-        int GetCharacterId();
-
-    private:
-
-        /**
-         * Delimiter for metadata tokens.
-         */
-        static const std::string DELIMITER;
-
-        /**
-         * Start tag for metadata.
-         */
-        static const std::string START;
-
-        /**
-         * End tag for metadata.
-         */
-        static const std::string END;
-
-        /**
-         * Parses metadata.
-         *
-         * @param meta_data[in] Metadata to parse.
-         */
-        void Parse(std::string meta_data);
-
-        /**
-         * Parses a metadata item, looking for a start mark.
-         *
-         * If it finds it, marks the metadata as the first function of a
-         * class. It also * calls {@see ParseEnd} with the next token.
-         *
-         * @param item[in] The item to check for a start mark.
-         * @param item[in] All the metadata tokens.
-         */
-        void ParseStart(const std::string& item, std::deque<std::string>& strs);
-
-        /**
-         * Parses a metadata item, looking for an end mark.
-         *
-         * If it finds it, marks the metadata as the last function of a class.
-         * It also calls {@see ParseCharId}.
-         *
-         * @param item[in] The item to check for a start mark.
-         * @param item[in] Metadata tokens, first removed.
-         */
-        void ParseEnd(const std::string& item, std::deque<std::string>& strs);
-
-        /**
-         * Parses a metadata item, looking for a character ID.
-         *
-         * If it finds it, sets the character ID. It also calls
-         * {@see ParseEntity}.
-         *
-         * @param item[in] The item to check for a start mark.
-         * @param item[in] Metadata tokens, first two removed.
-         */
-        void ParseCharId(const std::string& item, std::deque<std::string>& strs);
-
-        /**
-         * Parses a metadata item, looking for an entity name.
-         *
-         * It sets the entity name.
-         *
-         * @param item[in] The item to check for a start mark.
-         * @param item[in] Metadata tokens, first three removed.
-         */
-        void ParseEntity(const std::string& item, std::deque<std::string>& strs);
-
-        /**
-         * Indicates if the function is the last of a class.
-         */
-        bool end_ = false;
-
-        /**
-         * Indicates if the function is the first of a class.
-         */
-        bool start_ = false;
-
-        /**
-         * The entity name.
-         */
-        std::string entity_name_;
-
-        /**
-         * The character ID.
-         */
-        int character_id_ = -1;
-};
-
-/**
- * The code generator.
- *
- * Generates code for a field map function.
- */
-class FieldCodeGenerator : public CodeGenerator{
-
-    public:
-
-        /**
-         * Type of data.
-         */
-        enum struct ValueType : int{
-
-            /**
-             * Integer.
-             */
-            Integer = 0,
-
-            /**
-             * Float.
-             */
-            Float = 1
-        };
-
-        /**
-         * Generates code for an unimplemented instruction.
-         *
-         * The code will actually be a comment, indicating where the function
-         * call must have been.
-         *
-         * @param entity[in] The entity name.
-         * @param address[in] The address of the instruction.
-         * @param opcode[in] The opcode not implemented.
-         */
-        static const std::string FormatInstructionNotImplemented(
-          const std::string& entity, uint32 address, uint32 opcode
-        );
-
-        /**
-         * Generates code for an unimplemented instruction.
-         *
-         * The code will actually be a comment, indicating where the function
-         * call must have been.
-         *
-         * @param entity[in] The entity name.
-         * @param address[in] The address of the instruction.
-         * @param opcode[in] The unimplemented instruction.
-         */
-        static const std::string FormatInstructionNotImplemented(
-          const std::string& entity, uint32 address, const Instruction& instruction
-        );
-
-        /**
-         * Formats a value as a boolean.
-         *
-         * @param value[in] The value to format.
-         * @return "false" if the value is 0, "true" otherwise.
-         */
-        static const std::string FormatBool(uint32 value);
-
-        /**
-         * Formats a value as a boolean.
-         *
-         * @param value[in] The value to format.
-         * @return "true" if the value is 0, "false" otherwise.
-         */
-        static const std::string FormatInvertedBool(uint32 value);
-
-        /**
-         * Formats a data access for a map script.
-         *
-         * If possible, it will look for friendly names for variables.
-         *
-         * @param formatter[in] Formatter to look up variable friendly names.
-         * @param bank[in] The memory bank to use.
-         * @param value_or_address[in] The value or memory address to use.
-         * When bank is 0, it will be considered as a value. When bank is non
-         * 0, it will be considered an address of the bank.
-         * @param value_type[in] Data type to use. Used only when getting a
-         * value, not a bank address.
-         * @param scale[in] Scale to scale values to. Used only when using
-         * float values, unused when type is integer or when using a bank
-         * address.
-         * @return String with the friendly variable name, value, or bank
-         * address.
-         */
-        template<typename TValue>static const std::string FormatValueOrVariable(
-          SUDM::IScriptFormatter& formatter, uint32 bank, TValue value_or_address,
-          ValueType type = ValueType::Integer, float scale = 1.0f
-        ){
-            switch (bank){
-                case 0:
-                    switch (type){
-                        // TODO: check for zero
-                        case ValueType::Float: return std::to_string(value_or_address / scale);
-                        case ValueType::Integer: return std::to_string(value_or_address);
-                        default: return std::to_string(value_or_address);
-                    }
-                case 1:
-                case 2:
-                case 3:
-                case 13:
-                case 15:
-                    {
-                        const auto address = static_cast<uint32>(value_or_address) & 0xFF;
-                        const auto friendly_name = formatter.VarName(bank, value_or_address);
-                        if (friendly_name.empty())
-                            return (boost::format("FFVII.Banks[%1%][%2%]") % bank % address).str();
-                        return (boost::format("FFVII.Data.%1%") % friendly_name).str();
-                    }
-                case 5:
-                case 6:
-                    {
-                        const auto address = static_cast<uint32>(value_or_address)& 0xFF;
-                        const  auto friendly_name = formatter.VarName(bank, address);
-                        if (friendly_name.empty())
-                            return (boost::format("FFVII.Banks[%1%][%2%]") % bank % address).str();
-                        return "FFVII.Data." + friendly_name;
-                    }
-                default:
-                    return (
-                      boost::format(
-                        "FFVII.Banks[%1%][%2%]"
-                      ) % bank % (static_cast<uint32>(value_or_address) & 0xFF)
-                    ).str();
+namespace FF7{
+
+    /**
+     * Parses an stores function metadata.
+     *
+     * Function metadata can indicate the entity and character of a function, and
+     * if the function is the first or last in a class.
+     */
+    class FunctionMetaData{
+
+        public:
+
+            /**
+             * Constructor. Parses function metadata.
+             *
+             * Meta data format can be:
+             * - start_end_entityname
+             * - start_entityname
+             * - end_entity_name
+             *
+             * @param meta_data[in] Metadata to parse.
+             */
+            FunctionMetaData(std::string meta_data);
+
+            /**
+             * Checks if the function is the first of a class.
+             *
+             * @return True if the metadata is the first of a class, false
+             * otherwise.
+             */
+            bool IsStart() const;
+
+            /**
+             * Checks if the function is the last of a class.
+             *
+             * @return True if the metadata is the last of a class, false
+             * otherwise.
+             */
+            bool IsEnd() const;
+
+            /**
+             * Retrieves the entity name.
+             *
+             * @return The entity name.
+             */
+            std::string GetEntityName();
+
+            /**
+             * Retrieves the character ID.
+             *
+             * @return The chaacter ID.
+             */
+            int GetCharacterId();
+
+        private:
+
+            /**
+             * Delimiter for metadata tokens.
+             */
+            static const std::string DELIMITER;
+
+            /**
+             * Start tag for metadata.
+             */
+            static const std::string START;
+
+            /**
+             * End tag for metadata.
+             */
+            static const std::string END;
+
+            /**
+             * Parses metadata.
+             *
+             * @param meta_data[in] Metadata to parse.
+             */
+            void Parse(std::string meta_data);
+
+            /**
+             * Parses a metadata item, looking for a start mark.
+             *
+             * If it finds it, marks the metadata as the first function of a
+             * class. It also * calls {@see ParseEnd} with the next token.
+             *
+             * @param item[in] The item to check for a start mark.
+             * @param item[in] All the metadata tokens.
+             */
+            void ParseStart(const std::string& item, std::deque<std::string>& strs);
+
+            /**
+             * Parses a metadata item, looking for an end mark.
+             *
+             * If it finds it, marks the metadata as the last function of a class.
+             * It also calls {@see ParseCharId}.
+             *
+             * @param item[in] The item to check for a start mark.
+             * @param item[in] Metadata tokens, first removed.
+             */
+            void ParseEnd(const std::string& item, std::deque<std::string>& strs);
+
+            /**
+             * Parses a metadata item, looking for a character ID.
+             *
+             * If it finds it, sets the character ID. It also calls
+             * {@see ParseEntity}.
+             *
+             * @param item[in] The item to check for a start mark.
+             * @param item[in] Metadata tokens, first two removed.
+             */
+            void ParseCharId(const std::string& item, std::deque<std::string>& strs);
+
+            /**
+             * Parses a metadata item, looking for an entity name.
+             *
+             * It sets the entity name.
+             *
+             * @param item[in] The item to check for a start mark.
+             * @param item[in] Metadata tokens, first three removed.
+             */
+            void ParseEntity(const std::string& item, std::deque<std::string>& strs);
+
+            /**
+             * Indicates if the function is the last of a class.
+             */
+            bool end_ = false;
+
+            /**
+             * Indicates if the function is the first of a class.
+             */
+            bool start_ = false;
+
+            /**
+             * The entity name.
+             */
+            std::string entity_name_;
+
+            /**
+             * The character ID.
+             */
+            int character_id_ = -1;
+    };
+
+    /**
+     * The code generator.
+     *
+     * Generates code for a field map function.
+     */
+    class FieldCodeGenerator : public CodeGenerator{
+
+        public:
+
+            /**
+             * Type of data.
+             */
+            enum struct ValueType : int{
+
+                /**
+                 * Integer.
+                 */
+                Integer = 0,
+
+                /**
+                 * Float.
+                 */
+                Float = 1
+            };
+
+            /**
+             * Generates code for an unimplemented instruction.
+             *
+             * The code will actually be a comment, indicating where the function
+             * call must have been.
+             *
+             * @param entity[in] The entity name.
+             * @param address[in] The address of the instruction.
+             * @param opcode[in] The opcode not implemented.
+             */
+            static const std::string FormatInstructionNotImplemented(
+              const std::string& entity, uint32 address, uint32 opcode
+            );
+
+            /**
+             * Generates code for an unimplemented instruction.
+             *
+             * The code will actually be a comment, indicating where the function
+             * call must have been.
+             *
+             * @param entity[in] The entity name.
+             * @param address[in] The address of the instruction.
+             * @param opcode[in] The unimplemented instruction.
+             */
+            static const std::string FormatInstructionNotImplemented(
+              const std::string& entity, uint32 address, const Instruction& instruction
+            );
+
+            /**
+             * Formats a value as a boolean.
+             *
+             * @param value[in] The value to format.
+             * @return "false" if the value is 0, "true" otherwise.
+             */
+            static const std::string FormatBool(uint32 value);
+
+            /**
+             * Formats a value as a boolean.
+             *
+             * @param value[in] The value to format.
+             * @return "true" if the value is 0, "false" otherwise.
+             */
+            static const std::string FormatInvertedBool(uint32 value);
+
+            /**
+             * Formats a data access for a map script.
+             *
+             * If possible, it will look for friendly names for variables.
+             *
+             * @param formatter[in] Formatter to look up variable friendly names.
+             * @param bank[in] The memory bank to use.
+             * @param value_or_address[in] The value or memory address to use.
+             * When bank is 0, it will be considered as a value. When bank is non
+             * 0, it will be considered an address of the bank.
+             * @param value_type[in] Data type to use. Used only when getting a
+             * value, not a bank address.
+             * @param scale[in] Scale to scale values to. Used only when using
+             * float values, unused when type is integer or when using a bank
+             * address.
+             * @return String with the friendly variable name, value, or bank
+             * address.
+             */
+            template<typename TValue>static const std::string FormatValueOrVariable(
+              SUDM::IScriptFormatter& formatter, uint32 bank, TValue value_or_address,
+              ValueType type = ValueType::Integer, float scale = 1.0f
+            ){
+                switch (bank){
+                    case 0:
+                        switch (type){
+                            // TODO: check for zero
+                            case ValueType::Float: return std::to_string(value_or_address / scale);
+                            case ValueType::Integer: return std::to_string(value_or_address);
+                            default: return std::to_string(value_or_address);
+                        }
+                    case 1:
+                    case 2:
+                    case 3:
+                    case 13:
+                    case 15:
+                        {
+                            const auto address = static_cast<uint32>(value_or_address) & 0xFF;
+                            const auto friendly_name = formatter.VarName(bank, value_or_address);
+                            if (friendly_name.empty())
+                                return (boost::format("FFVII.Banks[%1%][%2%]") % bank % address).str();
+                            return (boost::format("FFVII.Data.%1%") % friendly_name).str();
+                        }
+                    case 5:
+                    case 6:
+                        {
+                            const auto address = static_cast<uint32>(value_or_address)& 0xFF;
+                            const  auto friendly_name = formatter.VarName(bank, address);
+                            if (friendly_name.empty())
+                                return (boost::format("FFVII.Banks[%1%][%2%]") % bank % address).str();
+                            return "FFVII.Data." + friendly_name;
+                        }
+                    default:
+                        return (
+                          boost::format(
+                            "FFVII.Banks[%1%][%2%]"
+                          ) % bank % (static_cast<uint32>(value_or_address) & 0xFF)
+                        ).str();
+                }
             }
             }
-        }
-
-        /**
-         * Constructor.
-         *
-         * @param engine[in] The engine.
-         * @param insts[in] The list of instructions to parse.
-         * @param output[out] The generated script.
-         * @param formatter[in] The code formatter.
-         */
-        FieldCodeGenerator(
-          Engine *engine, const InstVec& insts, std::ostream &output,
-          SUDM::IScriptFormatter& formatter
-        ) :
-          CodeGenerator(engine, output, FIFO_ARGUMENT_ORDER, LIFO_ARGUMENT_ORDER),
-          insts_(insts), formatter_(formatter)
-        {target_lang_ = std::make_unique<LuaTargetLanguage>();}
-
-        /**
-         * Generates the script from the instructions.
-         *
-         * @param insts[in] The list of instructions.
-         * @param graph[in] Code graph, unused.
-         */
-        virtual void Generate(InstVec& insts, const Graph &g) override;
-
-        /**
-         * Adds a line to the script.
-         *
-         * @param line[in] The line to add.
-         * @param unindent_before[in] If true, the current script indentation
-         * will be moved back one position before the line.
-         * @param indent_after[in] If true, the current script indentation
-         * will be moved forward one position after the line.
-         */
-        virtual void AddOutputLine(
-          std::string line, bool unindent_before = false, bool indent_after = false
-        ) override;
-
-        /**
-         * Retrieves the engine scale factor.
-         *
-         * @return The scale factor
-         */
-        float GetScaleFactor() const;
-
-        /**
-         * Retrieves the formatter.
-         */
-        SUDM::IScriptFormatter& GetFormatter();
-
-
-
-    protected:
-
-        /**
-         * Constructs the function signature.
-         *
-         * The function signature is the LUA function declaration, and it
-         * looks like this:
-         *
-         * <function_name> = function(self)
-         *
-         * @param function[in] The function to construct the signature for.
-         * @return The function signature.
-         */
-        virtual std::string ConstructFuncSignature(const Function &function) override;
-
-        /**
-         * Finalizes a function.
-         *
-         * It appends an "end" to finalize the function. If the function is
-         * the last of a class, it also closes the class braces.
-         *
-         * @param function[in] The function to end.
-         */
-        virtual void OnEndFunction(const Function& function) override;
-
-        /**
-         * Adds lines to the script before a function.
-         *
-         * If the function is the first in a class, it initializes the class
-         * and, if the function belongs to a character, creates the class
-         * variable for the character. If the function has a comment
-         * associated, it will also be added before the function.
-         *
-         * @param function[in] The function about to start.
-         */
-        virtual void OnBeforeStartFunction(const Function& function) override;
-
-        /**
-         * Initializes a function.
-         *
-         * It adds a comment with the function opcodes.
-         *
-         * @param function[in] The function to start.
-         */
-        virtual void OnStartFunction(const Function& function) override;
-
-        /**
-         * Checks if only required labels are to be written.
-         *
-         * @return Always true.
-         */
-        virtual bool OutputOnlyRequiredLabels() const override;
-
-    private:
-
-        /**
-         * The list of instructions in the function to generate.
-         */
-        const InstVec& insts_;
-
-        /**
-         * Generated lines.
-         */
-        std::vector<CodeLine> lines_;
-
-        /**
-         * The formatter.
-         */
-        SUDM::IScriptFormatter& formatter_;
-
-};
+
+            /**
+             * Constructor.
+             *
+             * @param engine[in] The engine.
+             * @param insts[in] The list of instructions to parse.
+             * @param output[out] The generated script.
+             * @param formatter[in] The code formatter.
+             */
+            FieldCodeGenerator(
+              Engine *engine, const InstVec& insts, std::ostream &output,
+              SUDM::IScriptFormatter& formatter
+            ) :
+              CodeGenerator(engine, output, FIFO_ARGUMENT_ORDER, LIFO_ARGUMENT_ORDER),
+              insts_(insts), formatter_(formatter)
+            {target_lang_ = std::make_unique<LuaTargetLanguage>();}
+
+            /**
+             * Generates the script from the instructions.
+             *
+             * @param insts[in] The list of instructions.
+             * @param graph[in] Code graph, unused.
+             */
+            virtual void Generate(InstVec& insts, const Graph &graph) override;
+
+            /**
+             * Adds a line to the script.
+             *
+             * @param line[in] The line to add.
+             * @param unindent_before[in] If true, the current script indentation
+             * will be moved back one position before the line.
+             * @param indent_after[in] If true, the current script indentation
+             * will be moved forward one position after the line.
+             */
+            virtual void AddOutputLine(
+              std::string line, bool unindent_before = false, bool indent_after = false
+            ) override;
+
+            /**
+             * Retrieves the engine scale factor.
+             *
+             * @return The scale factor
+             */
+            float GetScaleFactor() const;
+
+            /**
+             * Retrieves the formatter.
+             */
+            SUDM::IScriptFormatter& GetFormatter();
+
+
+
+        protected:
+
+            /**
+             * Constructs the function signature.
+             *
+             * The function signature is the LUA function declaration, and it
+             * looks like this:
+             *
+             * <function_name> = function(self)
+             *
+             * @param function[in] The function to construct the signature for.
+             * @return The function signature.
+             */
+            virtual std::string ConstructFuncSignature(const Function &function) override;
+
+            /**
+             * Finalizes a function.
+             *
+             * It appends an "end" to finalize the function. If the function is
+             * the last of a class, it also closes the class braces.
+             *
+             * @param function[in] The function to end.
+             */
+            virtual void OnEndFunction(const Function& function) override;
+
+            /**
+             * Adds lines to the script before a function.
+             *
+             * If the function is the first in a class, it initializes the class
+             * and, if the function belongs to a character, creates the class
+             * variable for the character. If the function has a comment
+             * associated, it will also be added before the function.
+             *
+             * @param function[in] The function about to start.
+             */
+            virtual void OnBeforeStartFunction(const Function& function) override;
+
+            /**
+             * Initializes a function.
+             *
+             * It adds a comment with the function opcodes.
+             *
+             * @param function[in] The function to start.
+             */
+            virtual void OnStartFunction(const Function& function) override;
+
+            /**
+             * Checks if only required labels are to be written.
+             *
+             * @return Always true.
+             */
+            virtual bool OutputOnlyRequiredLabels() const override;
+
+        private:
+
+            /**
+             * The list of instructions in the function to generate.
+             */
+            const InstVec& insts_;
+
+            /**
+             * Generated lines.
+             */
+            std::vector<CodeLine> lines_;
+
+            /**
+             * The formatter.
+             */
+            SUDM::IScriptFormatter& formatter_;
+
+    };
+}

+ 678 - 626
V-Gears-Installer/include/decompiler/field/FieldDisassembler.h

@@ -15,723 +15,775 @@
 
 
 #pragma once
 #pragma once
 
 
-#include <array>
 #include "decompiler/simple_disassembler.h"
 #include "decompiler/simple_disassembler.h"
 #include "decompiler/sudm.h"
 #include "decompiler/sudm.h"
-
+#include <array>
 
 
 class BinaryReader;
 class BinaryReader;
 class Function;
 class Function;
 
 
-/**
- * Field opcodes.
- */
-enum OPCODE{
-    RET = 0x0,
-    REQ = 0x01,
-    REQSW = 0x02,
-    REQEW = 0x03,
-    PREQ = 0x04,
-    PRQSW = 0x05,
-    PRQEW = 0x06,
-    RETTO = 0x07,
-    JOIN = 0x08,
-    SPLIT = 0x09,
-    SPTYE = 0x0A,
-    GTPYE = 0x0B,
-    DSKCG = 0x0E,
-    SPECIAL = 0x0F,
-    JMPF = 0x10,
-    JMPFL = 0x11,
-    JMPB = 0x12,
-    JMPBL = 0x13,
-    IFUB = 0x14,
-    IFUBL = 0x15,
-    IFSW = 0x16,
-    IFSWL = 0x17,
-    IFUW = 0x18,
-    IFUWL = 0x19,
-    MINIGAME = 0x20,
-    TUTOR = 0x21,
-    BTMD2 = 0x22,
-    BTRLD = 0x23,
-    WAIT = 0x24,
-    NFADE = 0x25,
-    BLINK = 0x26,
-    BGMOVIE = 0x27,
-    KAWAI = 0x28,
-    KAWIW = 0x29,
-    PMOVA = 0x2A,
-    SLIP = 0x2B,
-    BGPDH = 0x2C,
-    BGSCR = 0x2D,
-    WCLS = 0x2E,
-    WSIZW = 0x2F,
-    IFKEY = 0x30,
-    IFKEYON = 0x31,
-    IFKEYOFF = 0x32,
-    UC = 0x33,
-    PDIRA = 0x34,
-    PTURA = 0x35,
-    WSPCL = 0x36,
-    WNUMB = 0x37,
-    STTIM = 0x38,
-    GOLDU = 0x39,
-    GOLDD = 0x3A,
-    CHGLD = 0x3B,
-    HMPMAX1 = 0x3C,
-    HMPMAX2 = 0x3D,
-    MHMMX = 0x3E,
-    HMPMAX3 = 0x3F,
-    MESSAGE = 0x40,
-    MPARA = 0x41,
-    MPRA2 = 0x42,
-    MPNAM = 0x43,
-    MPU = 0x45,
-    MPD = 0x47,
-    ASK = 0x48,
-    MENU = 0x49,
-    MENU2 = 0x4A,
-    BTLTB = 0x4B,
-    HPU = 0x4D,
-    HPD = 0x4F,
-    WINDOW = 0x50,
-    WMOVE = 0x51,
-    WMODE = 0x52,
-    WREST = 0x53,
-    WCLSE = 0x54,
-    WROW = 0x55,
-    GWCOL = 0x56,
-    SWCOL = 0x57,
-    STITM = 0x58,
-    DLITM = 0x59,
-    CKITM = 0x5A,
-    SMTRA = 0x5B,
-    DMTRA = 0x5C,
-    CMTRA = 0x5D,
-    SHAKE = 0x5E,
-    NOP = 0x5F,
-    MAPJUMP = 0x60,
-    SCRLO = 0x61,
-    SCRLC = 0x62,
-    SCRLA = 0x63,
-    SCR2D = 0x64,
-    SCRCC = 0x65,
-    SCR2DC = 0x66,
-    SCRLW = 0x67,
-    SCR2DL = 0x68,
-    MPDSP = 0x69,
-    VWOFT = 0x6A,
-    FADE = 0x6B,
-    FADEW = 0x6C,
-    IDLCK = 0x6D,
-    LSTMP = 0x6E,
-    SCRLP = 0x6F,
-    BATTLE = 0x70,
-    BTLON = 0x71,
-    BTLMD = 0x72,
-    PGTDR = 0x73,
-    GETPC = 0x74,
-    PXYZI = 0x75,
-    PLUS_ = 0x76, // PLUS!
-    PLUS2_ = 0x77, // PLUS2!
-    MINUS_ = 0x78, // MINUS!
-    MINUS2_ = 0x79, // MINUS2!
-    INC_ = 0x7A, //  INC!
-    INC2_ = 0x7B, // INC2!
-    DEC_ = 0x7C, // DEC!
-    DEC2_ = 0x7D, // DEC2!
-    TLKON = 0x7E,
-    RDMSD = 0x7F,
-    SETBYTE = 0x80,
-    SETWORD = 0x81,
-    BITON = 0x82,
-    BITOFF = 0x83,
-    BITXOR = 0x84,
-    PLUS = 0x85,
-    PLUS2 = 0x86,
-    MINUS = 0x87,
-    MINUS2 = 0x88,
-    MUL = 0x89,
-    MUL2 = 0x8A,
-    DIV = 0x8B,
-    DIV2 = 0x8C,
-    MOD = 0x8D,
-    MOD2 = 0x8E,
-    AND = 0x8F,
-    AND2 = 0x90,
-    OR = 0x91,
-    OR2 = 0x92,
-    XOR = 0x93,
-    XOR2 = 0x94,
-    INC = 0x95,
-    INC2 = 0x96,
-    DEC = 0x97,
-    DEC2 = 0x98,
-    RANDOM = 0x99,
-    LBYTE = 0x9A,
-    HBYTE = 0x9B,
-    TWOBYTE = 0x9C,
-    SETX = 0x9D,
-    GETX = 0x9E,
-    SEARCHX = 0x9F,
-    PC = 0xA0,
-    opCodeCHAR = 0xA1,
-    DFANM = 0xA2,
-    ANIME1 = 0xA3,
-    VISI = 0xA4,
-    XYZI = 0xA5,
-    XYI = 0xA6,
-    XYZ = 0xA7,
-    MOVE = 0xA8,
-    CMOVE = 0xA9,
-    MOVA = 0xAA,
-    TURA = 0xAB,
-    ANIMW = 0xAC,
-    FMOVE = 0xAD,
-    ANIME2 = 0xAE,
-    ANIM_1 = 0xAF, // ANIM!1
-    CANIM1 = 0xB0,
-    CANM_1 = 0xB1, // CANM!1
-    MSPED = 0xB2,
-    DIR = 0xB3,
-    TURNGEN = 0xB4,
-    TURN = 0xB5,
-    DIRA = 0xB6,
-    GETDIR = 0xB7,
-    GETAXY = 0xB8,
-    GETAI = 0xB9,
-    ANIM_2 = 0xBA, // ANIM!2
-    CANIM2 = 0xBB,
-    CANM_2 = 0xBC, // CANM!2
-    ASPED = 0xBD,
-    CC = 0xBF,
-    JUMP = 0xC0,
-    AXYZI = 0xC1,
-    LADER = 0xC2,
-    OFST = 0xC3,
-    OFSTW = 0xC4,
-    TALKR = 0xC5,
-    SLIDR = 0xC6,
-    SOLID = 0xC7,
-    PRTYP = 0xC8,
-    PRTYM = 0xC9,
-    PRTYE = 0xCA,
-    IFPRTYQ = 0xCB,
-    IFMEMBQ = 0xCC,
-    MMBUD = 0xCD,
-    MMBLK = 0xCE,
-    MMBUK = 0xCF,
-    LINE = 0xD0,
-    LINON = 0xD1,
-    MPJPO = 0xD2,
-    SLINE = 0xD3,
-    SIN = 0xD4,
-    COS = 0xD5,
-    TLKR2 = 0xD6,
-    SLDR2 = 0xD7,
-    PMJMP = 0xD8,
-    PMJMP2 = 0xD9,
-    AKAO2 = 0xDA,
-    FCFIX = 0xDB,
-    CCANM = 0xDC,
-    ANIMB = 0xDD,
-    TURNW = 0xDE,
-    MPPAL = 0xDF,
-    BGON = 0xE0,
-    BGOFF = 0xE1,
-    BGROL = 0xE2,
-    BGROL2 = 0xE3,
-    BGCLR = 0xE4,
-    STPAL = 0xE5,
-    LDPAL = 0xE6,
-    CPPAL = 0xE7,
-    RTPAL = 0xE8,
-    ADPAL = 0xE9,
-    MPPAL2 = 0xEA,
-    STPLS = 0xEB,
-    LDPLS = 0xEC,
-    CPPAL2 = 0xED,
-    RTPAL2 = 0xEE,
-    ADPAL2 = 0xEF,
-    MUSIC = 0xF0,
-    SOUND = 0xF1,
-    AKAO = 0xF2,
-    MUSVT = 0xF3,
-    MUSVM = 0xF4,
-    MULCK = 0xF5,
-    BMUSC = 0xF6,
-    CHMPH = 0xF7,
-    PMVIE = 0xF8,
-    MOVIE = 0xF9,
-    MVIEF = 0xFA,
-    MVCAM = 0xFB,
-    FMUSC = 0xFC,
-    CMUSC = 0xFD,
-    CHMST = 0xFE,
-    GAMEOVER = 0xFF
-};
-
-/**
- * SPECIAL opcodes.
- *
- * SPECIAL opcode is a special one. It's a multi-purpose opcode, used to
- * perform game-specific tasks. It has a sub-opcode, in the next address, that
- * determines the operation to perform. This is a list of those sub-opcodes.
- */
-enum OPCODE_SPECIAL{
-    ARROW = 0xF5,
-    PNAME = 0xF6,
-    GMSPD = 0xF7,
-    SMSPD = 0xF8,
-    FLMAT = 0xF9,
-    FLITM = 0xFA,
-    BTLCK = 0xFB,
-    MVLCK = 0xFC,
-    SPCNM = 0xFD,
-    RSGLB = 0xFE,
-    CLITM = 0xFF
-};
-
-/**
- * KAWAI opcodes.
- *
- * KAWAI opcode is a special one. It's a multi-purpose opcode, used to perform
- * graphics related tasks. It has a sub-opcode, in the next address, that
- * determines the operation to perform. This is a list of those sub-opcodes.
- */
-enum OPCODE_KAWAI{
-    EYETX = 0x00,
-    TRNSP = 0x01,
-    AMBNT = 0x02,
-    Unknown03 = 0x03, // Makou Reactor can write these unknowns.
-    Unknown04 = 0x04,
-    Unknown05 = 0x05,
-    LIGHT = 0x06,
-    Unknown07 = 0x07,
-    Unknown08 = 0x08,
-    Unknown09 = 0x09,
-    SBOBJ = 0x0A,
-    Unknown0B = 0x0B,
-    Unknown0C = 0x0C,
-    SHINE = 0x0D,
-    RESET = 0xFF
-};
-
-/**
- * Information about an instruction.
- */
-struct InstructionRecord{
+namespace FF7{
 
 
     /**
     /**
-     * The size, in bytes, of the opcode.
+     * Field opcodes.
      */
      */
-    unsigned char opcode_size;
+    enum OPCODES{
+        RET = 0x0,
+        REQ = 0x01,
+        REQSW = 0x02,
+        REQEW = 0x03,
+        PREQ = 0x04,
+        PRQSW = 0x05,
+        PRQEW = 0x06,
+        RETTO = 0x07,
+        JOIN = 0x08,
+        SPLIT = 0x09,
+        SPTYE = 0x0A,
+        GTPYE = 0x0B,
+        DSKCG = 0x0E,
+        SPECIAL = 0x0F,
+        JMPF = 0x10,
+        JMPFL = 0x11,
+        JMPB = 0x12,
+        JMPBL = 0x13,
+        IFUB = 0x14,
+        IFUBL = 0x15,
+        IFSW = 0x16,
+        IFSWL = 0x17,
+        IFUW = 0x18,
+        IFUWL = 0x19,
+        MINIGAME = 0x20,
+        TUTOR = 0x21,
+        BTMD2 = 0x22,
+        BTRLD = 0x23,
+        WAIT = 0x24,
+        NFADE = 0x25,
+        BLINK = 0x26,
+        BGMOVIE = 0x27,
+        KAWAI = 0x28,
+        KAWIW = 0x29,
+        PMOVA = 0x2A,
+        SLIP = 0x2B,
+        BGPDH = 0x2C,
+        BGSCR = 0x2D,
+        WCLS = 0x2E,
+        WSIZW = 0x2F,
+        IFKEY = 0x30,
+        IFKEYON = 0x31,
+        IFKEYOFF = 0x32,
+        UC = 0x33,
+        PDIRA = 0x34,
+        PTURA = 0x35,
+        WSPCL = 0x36,
+        WNUMB = 0x37,
+        STTIM = 0x38,
+        GOLDU = 0x39,
+        GOLDD = 0x3A,
+        CHGLD = 0x3B,
+        HMPMAX1 = 0x3C,
+        HMPMAX2 = 0x3D,
+        MHMMX = 0x3E,
+        HMPMAX3 = 0x3F,
+        MESSAGE = 0x40,
+        MPARA = 0x41,
+        MPRA2 = 0x42,
+        MPNAM = 0x43,
+        MPU = 0x45,
+        MPD = 0x47,
+        ASK = 0x48,
+        MENU = 0x49,
+        MENU2 = 0x4A,
+        BTLTB = 0x4B,
+        HPU = 0x4D,
+        HPD = 0x4F,
+        WINDOW = 0x50,
+        WMOVE = 0x51,
+        WMODE = 0x52,
+        WREST = 0x53,
+        WCLSE = 0x54,
+        WROW = 0x55,
+        GWCOL = 0x56,
+        SWCOL = 0x57,
+        STITM = 0x58,
+        DLITM = 0x59,
+        CKITM = 0x5A,
+        SMTRA = 0x5B,
+        DMTRA = 0x5C,
+        CMTRA = 0x5D,
+        SHAKE = 0x5E,
+        NOP = 0x5F,
+        MAPJUMP = 0x60,
+        SCRLO = 0x61,
+        SCRLC = 0x62,
+        SCRLA = 0x63,
+        SCR2D = 0x64,
+        SCRCC = 0x65,
+        SCR2DC = 0x66,
+        SCRLW = 0x67,
+        SCR2DL = 0x68,
+        MPDSP = 0x69,
+        VWOFT = 0x6A,
+        FADE = 0x6B,
+        FADEW = 0x6C,
+        IDLCK = 0x6D,
+        LSTMP = 0x6E,
+        SCRLP = 0x6F,
+        BATTLE = 0x70,
+        BTLON = 0x71,
+        BTLMD = 0x72,
+        PGTDR = 0x73,
+        GETPC = 0x74,
+        PXYZI = 0x75,
+        PLUS_ = 0x76, // PLUS!
+        PLUS2_ = 0x77, // PLUS2!
+        MINUS_ = 0x78, // MINUS!
+        MINUS2_ = 0x79, // MINUS2!
+        INC_ = 0x7A, //  INC!
+        INC2_ = 0x7B, // INC2!
+        DEC_ = 0x7C, // DEC!
+        DEC2_ = 0x7D, // DEC2!
+        TLKON = 0x7E,
+        RDMSD = 0x7F,
+        SETBYTE = 0x80,
+        SETWORD = 0x81,
+        BITON = 0x82,
+        BITOFF = 0x83,
+        BITXOR = 0x84,
+        PLUS = 0x85,
+        PLUS2 = 0x86,
+        MINUS = 0x87,
+        MINUS2 = 0x88,
+        MUL = 0x89,
+        MUL2 = 0x8A,
+        DIV = 0x8B,
+        DIV2 = 0x8C,
+        MOD = 0x8D,
+        MOD2 = 0x8E,
+        AND = 0x8F,
+        AND2 = 0x90,
+        OR = 0x91,
+        OR2 = 0x92,
+        XOR = 0x93,
+        XOR2 = 0x94,
+        INC = 0x95,
+        INC2 = 0x96,
+        DEC = 0x97,
+        DEC2 = 0x98,
+        RANDOM = 0x99,
+        LBYTE = 0x9A,
+        HBYTE = 0x9B,
+        TWOBYTE = 0x9C,
+        SETX = 0x9D,
+        GETX = 0x9E,
+        SEARCHX = 0x9F,
+        PC = 0xA0,
+        opCodeCHAR = 0xA1,
+        DFANM = 0xA2,
+        ANIME1 = 0xA3,
+        VISI = 0xA4,
+        XYZI = 0xA5,
+        XYI = 0xA6,
+        XYZ = 0xA7,
+        MOVE = 0xA8,
+        CMOVE = 0xA9,
+        MOVA = 0xAA,
+        TURA = 0xAB,
+        ANIMW = 0xAC,
+        FMOVE = 0xAD,
+        ANIME2 = 0xAE,
+        ANIM_1 = 0xAF, // ANIM!1
+        CANIM1 = 0xB0,
+        CANM_1 = 0xB1, // CANM!1 
+        MSPED = 0xB2,
+        DIR = 0xB3,
+        TURNGEN = 0xB4,
+        TURN = 0xB5,
+        DIRA = 0xB6,
+        GETDIR = 0xB7,
+        GETAXY = 0xB8,
+        GETAI = 0xB9,
+        ANIM_2 = 0xBA, // ANIM!2
+        CANIM2 = 0xBB,
+        CANM_2 = 0xBC, // CANM!2
+        ASPED = 0xBD,
+        CC = 0xBF,
+        JUMP = 0xC0,
+        AXYZI = 0xC1,
+        LADER = 0xC2,
+        OFST = 0xC3,
+        OFSTW = 0xC4,
+        TALKR = 0xC5,
+        SLIDR = 0xC6,
+        SOLID = 0xC7,
+        PRTYP = 0xC8,
+        PRTYM = 0xC9,
+        PRTYE = 0xCA,
+        IFPRTYQ = 0xCB,
+        IFMEMBQ = 0xCC,
+        MMBUD = 0xCD,
+        MMBLK = 0xCE,
+        MMBUK = 0xCF,
+        LINE = 0xD0,
+        LINON = 0xD1,
+        MPJPO = 0xD2,
+        SLINE = 0xD3,
+        SIN = 0xD4,
+        COS = 0xD5,
+        TLKR2 = 0xD6,
+        SLDR2 = 0xD7,
+        PMJMP = 0xD8,
+        PMJMP2 = 0xD9,
+        AKAO2 = 0xDA,
+        FCFIX = 0xDB,
+        CCANM = 0xDC,
+        ANIMB = 0xDD,
+        TURNW = 0xDE,
+        MPPAL = 0xDF,
+        BGON = 0xE0,
+        BGOFF = 0xE1,
+        BGROL = 0xE2,
+        BGROL2 = 0xE3,
+        BGCLR = 0xE4,
+        STPAL = 0xE5,
+        LDPAL = 0xE6,
+        CPPAL = 0xE7,
+        RTPAL = 0xE8,
+        ADPAL = 0xE9,
+        MPPAL2 = 0xEA,
+        STPLS = 0xEB,
+        LDPLS = 0xEC,
+        CPPAL2 = 0xED,
+        RTPAL2 = 0xEE,
+        ADPAL2 = 0xEF,
+        MUSIC = 0xF0,
+        SOUND = 0xF1,
+        AKAO = 0xF2,
+        MUSVT = 0xF3,
+        MUSVM = 0xF4,
+        MULCK = 0xF5,
+        BMUSC = 0xF6,
+        CHMPH = 0xF7,
+        PMVIE = 0xF8,
+        MOVIE = 0xF9,
+        MVIEF = 0xFA,
+        MVCAM = 0xFB,
+        FMUSC = 0xFC,
+        CMUSC = 0xFD,
+        CHMST = 0xFE,
+        GAMEOVER = 0xFF
+    };
 
 
     /**
     /**
-     * The opcode code.
+     * SPECIAL opcodes.
+     *
+     * SPECIAL opcode is a special one. It's a multi-purpose opcode, used to
+     * perform game-specific tasks. It has a sub-opcode, in the next address,
+     * that determines the operation to perform. This is a list of those
+     * sub-opcodes.
      */
      */
-    unsigned int opcode;
+    enum OPCODES_SPECIAL{
+        ARROW = 0xF5,
+        PNAME = 0xF6,
+        GMSPD = 0xF7,
+        SMSPD = 0xF8,
+        FLMAT = 0xF9,
+        FLITM = 0xFA,
+        BTLCK = 0xFB,
+        MVLCK = 0xFC,
+        SPCNM = 0xFD,
+        RSGLB = 0xFE,
+        CLITM = 0xFF
+    };
 
 
     /**
     /**
-     * The opcode short name (mnemonic).
+     * KAWAI opcodes.
+     *
+     * KAWAI opcode is a special one. It's a multi-purpose opcode, used to
+     * perform graphics related tasks. It has a sub-opcode, in the next
+     * address, that determines the operation to perform. This is a list of
+     * those sub-opcodes.
      */
      */
-    const char* opcode_name;
+    enum OPCODES_KAWAI{
+        EYETX = 0x00,
+        TRNSP = 0x01,
+        AMBNT = 0x02,
+        Unknown03 = 0x03, // Makou Reactor can write these unknowns.
+        Unknown04 = 0x04,
+        Unknown05 = 0x05,
+        LIGHT = 0x06,
+        Unknown07 = 0x07,
+        Unknown08 = 0x08,
+        Unknown09 = 0x09,
+        SBOBJ = 0x0A,
+        Unknown0B = 0x0B,
+        Unknown0C = 0x0C,
+        SHINE = 0x0D,
+        RESET = 0xFF
+    };
+
+    class FieldEngine;
 
 
     /**
     /**
-     * Format of the opcode arguments.
+     * A disassebler for field maps.
      */
      */
-    const char* argument_format;
+    class FieldDisassembler : public SimpleDisassembler{
 
 
-    /**
-     * @todo Document.
-     */
-    std::function<InstPtr()> factory_function;
-};
-
-std::map<std::string, const InstructionRecord*> FieldInstructions();
-
-class FieldEngine;
-
-class FieldDisassembler : public SimpleDisassembler{
-
-    public:
-
-        /**
-         * Constructor.
-         *
-         * @param formatter[in] The code formatter.
-         * @param engine[in] The engine to use to disassemble.
-         * @param insts[in] The list of instructions.
-         */
-        FieldDisassembler(SUDM::IScriptFormatter& formatter, FieldEngine* engine, InstVec& insts);
-
-        /**
-         * Constructor.
-         *
-         * @param formatter[in] The code formatter.
-         * @param engine[in] The engine to use to disassemble.
-         * @param insts[in] The list of instructions.
-         * @param raw_script_data[in] @todo Understand and document.
-         */
-        FieldDisassembler(
-          SUDM::IScriptFormatter& formatter, FieldEngine* engine,
-          InstVec& insts, const std::vector<unsigned char>& raw_script_data
-        );
-
-        /**
-         * Destructor.
-         */
-        ~FieldDisassembler();
-
-        /**
-         * Disassembles the instructions.
-         */
-        virtual void DoDisassemble() override;
-
-        /**
-         * Retrieves the scale factor for the field.
-         */
-        float GetScaleFactor() const;
-
-    private:
-
-        /**
-         * Finds the ID of the character a function refers to.
-         *
-         * @param start_addr[in] The starting address of the function.
-         * @param start_addr[in] The starting address of the function.
-         * @param end_addr[in] The ending address of the instruction.
-         * @param insts[in] The lsit of instructions to search.
-         * @return The ID of the character the function refers to, or -1 if
-         * the function doesn't belong to acharacter.
-         */
-        static int FindId(uint32 start_addr, uint32 end_addr, const InstVec& insts);
-
-        /**
-         * Open a file for disassembly.
-         *
-         * @param filename[in] The file to disassemble.
-         * @deprecated Do not use. Load the instructions from the constructor.
-         */
-        virtual void Open(const char *filename) override;
-
-        /**
-         * Disassembles a script (function).
-         *
-         * @param entity_name[in] Name of the entity the script belongs to.
-         * @param entity_index[in] Index of the entity the script belongs to.
-         * @param script_entry_point[in] Address of the first instruction of
-         * the script to disassemble.
-         * @param script index[in] Index of the script, relative to the entity
-         * scripts.
-         * @param next_script_entry_point[in] 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).
-         * @param is_start[in] Indicates if the script is the first one for
-         * it's entity.
-         * @param is_end[in] Indicates if the script is the last one for it's
-         * entity.
-         * @throws InternalDecompilerError for malformed scripts.
-         */
-        void DisassembleIndivdualScript(
-          std::string entity_name, size_t entity_index, size_t script_entry_point,
-          size_t script_index, uint32 next_script_entry_point, bool is_start, bool is_end
-        );
-
-        /**
-         * Adds a function to the engine.
-         *
-         * @param entity_name[in] Name of the entity that owns the function.
-         * @param entity_index[in] Index of the entity that owns the function.
-         * @param script_index[in] Index of the script within the entity.
-         * @param next_script_entry_point[in] Start position of the next
-         * script (or the ending position of this one, plus one).
-         * @param is_start[in] Indicates if the function is the first in a class.
-         * @param is_end[in] Indicates if the function is the last in a class.
-         * @param to_return_only[in] True to read the script only until the
-         * first return.
-         * @param func_name[in] 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.
-         */
-        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
-        );
-
-        /**
-         * 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
-         *
-         * @param end_pos[in] The last position to read. Opcodes will be read
-         * until this, or until a RET is found.
-         * @param point_a[out] If a LINE opcode is found, the first point will
-         * be saved here.
-         * @param point_b[out] If a LINE opcode is found, the second point
-         * will be saved here.
-         * @return True if LINE opcode found, false if not.
-         */
-        bool ReadOpCodesToPositionOrReturn(
-          size_t end_pos, std::vector<float>& point_a, std::vector<float>& point_b
-        );
-
-        /**
-         * Initializes a function for an entity.
-         *
-         * @param script_index[in] Index of the script.
-         */
-        std::unique_ptr<Function> StartFunction(size_t script_index);
-
-        /**
-         * The engine.
-         */
-        FieldEngine* engine_;
-
-        /**
-         * Last address of the header.
-         */
-        uint32 header_end_position_ = 0;
-
-        /**
-         * Reads the header.
-         */
-        void ReadHeader();
-
-        /**
-         * Reads the header.
-         *
-         * @param reader[in] Reader to use to read.
-         */
-        void ReadHeader(BinaryReader& reader);
-
-        /**
-         * Field file identification magic number.
-         */
-        static const int MAGIC;
-
-        /**
-         * The number of sections in a field.
-         */
-        static const int NUM_SECTIONS;
-
-        /**
-         * Size of the pointers to sections.
-         *
-         * @todo Understand and document.
-         */
-        int16 section_pointers_size_; // = sizeof(uint32) * NUM_SECTIONS;
-
-        /**
-         * The sections of a field.
-         */
-        enum SECTIONS{
+        public:
 
 
             /**
             /**
-             * The scripts section.
+             * Information about an instruction.
              */
              */
-            SCRIPT = 0,
+            struct InstructionRecord{
+
+                /**
+                 * The size, in bytes, of the opcode.
+                 */
+                unsigned char opcode_size;
+
+                /**
+                 * The opcode code.
+                 */
+                unsigned int opcode;
+
+                /**
+                 * The opcode short name (mnemonic).
+                 */
+                const char* opcode_name;
+
+                /**
+                 * Format of the opcode arguments.
+                 */
+                const char* argument_format;
+
+                /**
+                 * @todo Document.
+                 */
+                std::function<InstPtr()> factory_function;
+            };
 
 
             /**
             /**
-             * The walkmesh section.
+             * A list of flow control opcodes needed by the disassembler.
              */
              */
-            WALKMESH = 1,
+            static InstructionRecord FLOW_OPCODES[];
 
 
             /**
             /**
-             * The tiles section.
+             * Generates a map of control flow instructions.
+             *
+             * @return A map of control flow instructions, by opcode name.
              */
              */
-            TILE_MAP = 2,
+            static std::map<std::string, const InstructionRecord*> FieldInstructions();
 
 
             /**
             /**
-             * The camera section.
+             * Finds the ID of the character a function refers to.
+             *
+             * @param start_addr[in] The starting address of the function.
+             * @param start_addr[in] The starting address of the function.
+             * @param end_addr[in] The ending address of the instruction.
+             * @param insts[in] The lsit of instructions to search.
+             * @return The ID of the character the function refers to, or -1
+             * if the function doesn't belong to a character.
              */
              */
-            CAMERA_MATRIX = 3,
+            static int FindId(uint32 start_addr, uint32 end_addr, const InstVec& insts);
 
 
             /**
             /**
-             * The triggers section.
+             * Constructor.
+             *
+             * @param formatter[in] The code formatter.
+             * @param engine[in] The engine to use to disassemble.
+             * @param insts[in] The list of instructions.
              */
              */
-            TRIGGERS = 4,
+            FieldDisassembler(
+              SUDM::IScriptFormatter& formatter, FieldEngine* engine, InstVec& insts
+            );
 
 
             /**
             /**
-             * Encounter data section.
+             * Constructor.
+             *
+             * @param formatter[in] The code formatter.
+             * @param engine[in] The engine to use to disassemble.
+             * @param insts[in] The list of instructions.
+             * @param raw_script_data[in] @todo Understand and document.
              */
              */
-            ENCOUNTERS = 5,
+            FieldDisassembler(
+              SUDM::IScriptFormatter& formatter, FieldEngine* engine,
+              InstVec& insts, const std::vector<unsigned char>& raw_script_data
+            );
 
 
             /**
             /**
-             * Field models section.
+             * Destructor.
              */
              */
-            MODELS = 6
-        };
-
-        /**
-         * The list of sections.
-         */
-        std::array<uint32, 7> sections_;
-
-        /**
-         * Retrieves the offset of the end of a script.
-         *
-         * @param cur_entry_point[in] @todo Understand and document.
-         * @param entity_index[in] Index of the entity the script belongs to.
-         * @param script_index[in] The script index.
-         * @return The address of the end of the script.
-         */
-        uint32 GetEndOfScriptOffset(
-          uint16 cur_entry_point, size_t entity_index, size_t script_index
-        );
-
-        /**
-         * Info about a script.
-         */
-        struct ScriptInfo{
+            ~FieldDisassembler();
 
 
             /**
             /**
-             * Address of the script entry point.
+             * Retrieves the scale factor for the field.
              */
              */
-            uint16 entry_point;
+            float GetScaleFactor() const;
 
 
-            /**
-             * Address of the next script entry point.
-             *
-             * I.e. The last address of the script, plus one.
-             */
-            uint32 next_entry_point;
 
 
             /**
             /**
-             * Script index.
+             * Disassembles the instructions.
              */
              */
-            size_t index;
-        };
+            virtual void DoDisassemble() override;
 
 
-        /**
-         * A script header.
-         */
-        struct ScriptHeader{
+        private:
 
 
             /**
             /**
              * Field file identification magic number.
              * Field file identification magic number.
              */
              */
-            uint16 magic;
+            static const int MAGIC;
 
 
             /**
             /**
-             * The number of entities in the field.
+             * The number of sections in a field.
              */
              */
-            uint8 number_of_entities;
+            static const int NUM_SECTIONS;
 
 
             /**
             /**
-             * The number of models in the field.
+             * The sections of a field.
              */
              */
-            uint8 number_of_models;
+            enum SECTIONS{
+
+                /**
+                 * The scripts section.
+                 */
+                SCRIPT = 0,
+
+                /**
+                 * The walkmesh section.
+                 */
+                WALKMESH = 1,
+
+                /**
+                 * The tiles section.
+                 */
+                TILE_MAP = 2,
+
+                /**
+                 * The camera section.
+                 */
+                CAMERA_MATRIX = 3,
+
+                /**
+                 * The triggers section.
+                 */
+                TRIGGERS = 4,
+
+                /**
+                 * Encounter data section.
+                 */
+                ENCOUNTERS = 5,
+
+                /**
+                 * Field models section.
+                 */
+                MODELS = 6
+            };
 
 
             /**
             /**
-             * Offset at which the field text strings begin.
+             * Info about a script.
              */
              */
-            uint16 offset_to_strings;
+            struct ScriptInfo{
+
+                /**
+                 * Address of the script entry point.
+                 */
+                uint16 entry_point;
+
+                /**
+                 * Address of the next script entry point.
+                 *
+                 * I.e. The last address of the script, plus one.
+                 */
+                uint32 next_entry_point;
+
+                /**
+                 * Script index.
+                 */
+                size_t index;
+            };
 
 
             /**
             /**
-             * The number of Akao/tuto blocks/offsets.
+             * A script header.
              */
              */
-            uint16 number_of_akao_offsets;
+            struct ScriptHeader{
+
+                /**
+                 * Field file identification magic number.
+                 */
+                uint16 magic;
+
+                /**
+                 * The number of entities in the field.
+                 */
+                uint8 number_of_entities;
+
+                /**
+                 * The number of models in the field.
+                 */
+                uint8 number_of_models;
+
+                /**
+                 * Offset at which the field text strings begin.
+                 */
+                uint16 offset_to_strings;
+
+                /**
+                 * The number of Akao/tuto blocks/offsets.
+                 */
+                uint16 number_of_akao_offsets;
+
+                /**
+                 * Scale of field.
+                 *
+                 * For move and talk calculation (9bit fixed point).
+                 */
+                uint16 scale;
+
+                /**
+                 * Blank data, unused.
+                 */
+                std::array<uint16, 3> blank;
+
+                /**
+                 * Field creator name.
+                 */
+                std::array<char, 8> creator;
+
+                /**
+                 * The field name.
+                 */
+                std::array<char, 8> name;
+
+                /**
+                 * The list of entity names.
+                 *
+                 * There will be {@see number_of_entities} entities.
+                 */
+                std::vector<std::array<char, 8>> field_entity_names;
+
+                /**
+                 * Akao/Tuto block offsets.
+                 *
+                 * There will be {@see number_of_akao_offsets} offsets.
+                 */
+                std::vector<uint32> akao_offsets;
+
+                /**
+                 * Entity script entry points.
+                 *
+                 * More explicitly, subroutine offsets. There will be
+                 * {@see number_of_entities} entity scripts.
+                 */
+                std::vector<std::array<uint16, 32>> entity_scripts;
+
+                /**
+                 * Reads the header.
+                 *
+                 * @param reader[in] The reader used to read the header.
+                 * @throws FF7ScriptHeaderInvalidException If the magic number for
+                 * the field is wrong.
+                 */
+                void Read(BinaryReader& reader){
+                    magic = reader.ReadU16();
+                    if (magic != MAGIC) throw FF7ScriptHeaderInvalidException();
+                    number_of_entities = reader.ReadU8();
+                    number_of_models = reader.ReadU8();
+                    offset_to_strings = reader.ReadU16();
+                    number_of_akao_offsets = reader.ReadU16();
+                    scale = reader.ReadU16();
+                    for (int i = 0; i < 3; i ++) blank[i] = reader.ReadU16();
+                    for (int i = 0; i < 8; i ++) creator[i] = reader.ReadU8();
+                    for (int i = 0; i < 8; i ++) name[i] = reader.ReadU8();
+                    for (int i = 0; i < number_of_entities; i ++){
+                        std::array<char, 8> name;
+                        for (int j = 0; j < 8; j ++) name[j] = reader.ReadU8();
+                        field_entity_names.emplace_back(name);
+                    }
+                    for (int i = 0; i < number_of_akao_offsets; i ++)
+                        akao_offsets.emplace_back(reader.ReadU32());
+                    entity_scripts.reserve(number_of_entities);
+                    for (int i = 0; i < number_of_entities; i ++){
+                        std::array<uint16, 32> scripts;
+                        for (int j = 0; j < 32; j ++) scripts[j] = reader.ReadU16();
+                        entity_scripts.push_back(scripts);
+                    }
+                }
+            };
 
 
             /**
             /**
-             * Scale of field.
+             * Open a file for disassembly.
              *
              *
-             * For move and talk calculation (9bit fixed point).
+             * @param filename[in] The file to disassemble.
+             * @deprecated Do not use. Load the instructions from the
+             * constructor.
              */
              */
-            uint16 scale;
+            virtual void Open(const char *filename) override;
 
 
             /**
             /**
-             * Blank data, unused.
+             * Disassembles a script (function).
+             *
+             * @param entity_name[in] Name of the entity the script belongs
+             * to.
+             * @param entity_index[in] Index of the entity the script belongs
+             * to.
+             * @param script_entry_point[in] Address of the first instruction
+             * of the script to disassemble.
+             * @param script index[in] Index of the script, relative to the
+             * entity scripts.
+             * @param next_script_entry_point[in] 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).
+             * @param is_start[in] Indicates if the script is the first one
+             * for it's entity.
+             * @param is_end[in] Indicates if the script is the last one for
+             * it's entity.
+             * @throws InternalDecompilerError for malformed scripts.
              */
              */
-            std::array<uint16, 3> blank;
+            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
+            );
 
 
             /**
             /**
-             * Field creator name.
+             * Adds a function to the engine.
+             *
+             * @param entity_name[in] Name of the entity that owns the function.
+             * @param entity_index[in] Index of the entity that owns the function.
+             * @param script_index[in] Index of the script within the entity.
+             * @param next_script_entry_point[in] Start position of the next
+             * script (or the ending position of this one, plus one).
+             * @param is_start[in] @todo Understand and document.
+             * @param is_end[in] @todo Understand and document.
+             * @param to_return_only[in] True to read the script only until the
+             * first return.
+             * @param func_name[in] 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.
              */
              */
-            std::array<char, 8> creator;
+            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
+            );
 
 
             /**
             /**
-             * The field name.
+             * 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
+             *
+             * @param end_pos[in] The last position to read. Opcodes will be read
+             * until this, or until a RET is found.
+             * @param point_a[out] If a LINE opcode is found, the first point will
+             * be saved here.
+             * @param point_b[out] If a LINE opcode is found, the second point
+             * will be saved here.
+             * @return True if LINE opcode found, false if not.
              */
              */
-            std::array<char, 8> name;
+            bool ReadOpCodesToPositionOrReturn(
+              size_t end_pos, std::vector<float>& point_a, std::vector<float>& point_b
+            );
 
 
             /**
             /**
-             * The list of entity names.
+             * Initializes a function for an entity.
              *
              *
-             * There will be {@see number_of_entities} entities.
+             * @param script_index[in] Index of the script.
              */
              */
-            std::vector<std::array<char, 8>> field_entity_names;
+            std::unique_ptr<Function> StartFunction(size_t scriptIndex);
 
 
             /**
             /**
-             * Akao/Tuto block offsets.
+             * Reads the header.
+             */
+            void ReadHeader();
+
+            /**
+             * Reads the header.
              *
              *
-             * There will be {@see number_of_akao_offsets} offsets.
+             * @param reader[in] Reader to use to read.
              */
              */
-            std::vector<uint32> akao_offsets;
+            void ReadHeader(BinaryReader& reader);
 
 
             /**
             /**
-             * Entity script entry points.
+             * Retrieves the offset of the end of a script.
              *
              *
-             * More explicitly, subroutine offsets. There will be
-             * {@see number_of_entities} entity scripts.
+             * @param cur_entry_point[in] @todo Understand and document.
+             * @param entity_index[in] Index of the entity the script belongs to.
+             * @param script_index[in] The script index.
+             * @return The address of the end of the script.
              */
              */
-            std::vector<std::array<uint16, 32>> entity_scripts;
+            uint32 GetEndOfScriptOffset(
+              uint16 cur_entry_point, size_t entity_index, size_t script_index
+            );
 
 
             /**
             /**
-             * Reads the header.
+             * Parses an opcode.
              *
              *
-             * @param reader[in] The reader used to read the header.
-             * @throws FF7ScriptHeaderInvalidException If the magic number for
-             * the field is wrong.
+             * Adds properties to an instruction, and adds the instruction to
+             * the list.
+             *
+             * @param opcode[in] The opcode code.
+             * @param name[in] the opcode name.
+             * @param instruction[in][out] A newly created instruction of the
+             * type the opcode belongs to.
+             * @param stack_change[in] Indicates how much the instruction
+             * changes the stack pointer by.
+             * @param argument_format[in] The opcode argument format.
              */
              */
-            void Read(BinaryReader& reader){
-                magic = reader.ReadU16();
-                if (magic != MAGIC) throw FF7ScriptHeaderInvalidException();
-                number_of_entities = reader.ReadU8();
-                number_of_models = reader.ReadU8();
-                offset_to_strings = reader.ReadU16();
-                number_of_akao_offsets = reader.ReadU16();
-                scale = reader.ReadU16();
-                for (int i = 0; i < 3; i ++) blank[i] = reader.ReadU16();
-                for (int i = 0; i < 8; i ++) creator[i] = reader.ReadU8();
-                for (int i = 0; i < 8; i ++) name[i] = reader.ReadU8();
-                for (int i = 0; i < number_of_entities; i ++){
-                    std::array<char, 8> name;
-                    for (int j = 0; j < 8; j ++) name[j] = reader.ReadU8();
-                    field_entity_names.emplace_back(name);
-                }
-                for (int i = 0; i < number_of_akao_offsets; i ++)
-                    akao_offsets.emplace_back(reader.ReadU32());
-                entity_scripts.reserve(number_of_entities);
-                for (int i = 0; i < number_of_entities; i ++){
-                    std::array<uint16, 32> scripts;
-                    for (int j = 0; j < 32; j ++) scripts[j] = reader.ReadU16();
-                    entity_scripts.push_back(scripts);
-                }
+            template<typename T> void ParseOpcode(
+              int opcode, std::string name, T instruction,
+              int stack_change, const char* argument_format
+            ){
+                uint32 full_opcode = (full_opcode << 8) + opcode;
+                this->insts_.push_back(instruction);
+                this->insts_.back()->_opcode = full_opcode;
+                this->insts_.back()->_address = this->address_;
+                this->insts_.back()->_stackChange = 0;
+                this->insts_.back()->_name = std::string(name);
+                this->insts_.back()->_codeGenData = "";
+                this->readParams(this->insts_.back(), argument_format);
             }
             }
-        };
-
-        /**
-         * The field header.
-         */
-        ScriptHeader header_;
-
-        /**
-         * Indicates if the field has been loaded from raw data.
-         */
-        bool loaded_from_raw_ = false;
-
-        /**
-         * The formatter.
-         */
-        SUDM::IScriptFormatter& formatter_;
-
-        /**
-         * The scale factor of the field.
-         */
-        float scale_factor_ = 1.0f;
-};
+
+            /**
+             * The engine.
+             */
+            FieldEngine* engine_;
+
+            /**
+             * Last address of the header.
+             */
+            uint32 header_end_position_ = 0;
+
+            /**
+             * The list of sections.
+             */
+            std::array<uint32, 7> sections_;
+
+            /**
+             * Size of the pointers to sections.
+             *
+             * @todo Understand and document.
+             */
+            int16 section_pointers_size_;
+
+            /**
+             * The field header.
+             */
+            ScriptHeader header_;
+
+            /**
+             * Indicates if the field has been loaded from raw data.
+             */
+            bool loaded_from_raw_data_ = false;
+
+            /**
+             * The formatter.
+             */
+            SUDM::IScriptFormatter& formatter_;
+
+            /**
+             * The scale factor of the field.
+             */
+            float scale_factor_ = 1.0f;
+    };
+
+}

+ 379 - 376
V-Gears-Installer/include/decompiler/field/FieldEngine.h

@@ -18,383 +18,386 @@
 
 
 #pragma once
 #pragma once
 
 
+#include "decompiler/decompiler_engine.h"
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 #include "decompiler/sudm.h"
 #include "decompiler/sudm.h"
-#include "decompiler/decompiler_engine.h"
 
 
-/**
- * Represents the FF7 Field engine.
- */
-class FieldEngine : public Engine{
-
-    public:
-
-        /**
-         * FieldEngine constructor.
-         *
-         * Generates a FieldEngine.
-         *
-         * @param formatter[in] The formatter to be used by the engine.
-         * @param script_name The script name.
-         */
-        FieldEngine(SUDM::IScriptFormatter& formatter, std::string script_name);
-
-        /**
-         * Copy constructor, deleted.
-         *
-         * @param engine[in] The engine to copy.
-         */
-        FieldEngine(const FieldEngine& engine) = delete;
-
-        /**
-         * Copy constructor, deleted.
-         *
-         * @param engine[in] The engine to copy.
-         */
-        FieldEngine& operator = (const FieldEngine& engine) = delete;
-
-        /**
-         * Represents an entity.
-         *
-         * An entity can be almost anything in a field map: the playable
-         * character, an NPC, an item, a line...
-         */
-        class Entity{
-
-            public:
-
-                /**
-                 * Entity constructor.
-                 *
-                 * It doesn't initialize any of the fields.
-                 */
-                Entity() = default;
-
-                /**
-                 * Entity constructor.
-                 *
-                 * Instantiates an entity with a name.
-                 *
-                 * @param name[in] Entity name.
-                 */
-                Entity(const std::string& name, size_t index);
-
-                /**
-                 * Retrieves the entity name.
-                 *
-                 * @return The entity name.
-                 */
-                std::string GetName() const;
-
-                /**
-                 * Retrieves the entity index.
-                 *
-                 * The index is the one at which appears in the original game
-                 * script.
-                 *
-                 * @return The entity index.
-                 */
-                size_t GetIndex() const;
-
-                /**
-                 * Retrieves a function.
-                 *
-                 * Retrieves the name of a function from it's index.
-                 *
-                 * @param index[in] Function index.
-                 * @return Function name.
-                 * @throws InternalDecompilerError if there is no function
-                 * with the specified index.
-                 */
-                std::string FunctionByIndex(size_t index) const;
-
-                /**
-                 * Adds a function to the engine.
-                 *
-                 * Must be added by name and index.
-                 *
-                 * @param name[in] Function name. If the entity is a line, the
-                 * name will be overridden.
-                 * @param index[in] Function index.
-                 * @todo What is a function here? An Opcode?
-                 */
-                void AddFunction(const std::string& name, size_t index);
-
-                /**
-                 * Marks the entity as a line.
-                 *
-                 * @param line[in] True to mark the entity as a line,
-                 * false to unmark it.
-                 * @param point_a[in] First point of the line. Can be null if
-                 * line is false.
-                 * @param point_b[in] Second point of the line. Can be null if
-                 * line is false.
-                 */
-                void MarkAsLine(bool line, std::vector<float> point_a, std::vector<float> point_b);
-
-                /**
-                 * Checks if the entity is a line.
-                 *
-                 * Note that an entity is not considered to be a line until a
-                 * function has been found containing the opcode LINE and
-                 * {@see MarkAsLine} has been called.
-                 *
-                 * @return true if the entity is a line.
-                 */
-                bool IsLine();
-
-                /**
-                 * Retrieves the first point of the line entity.
-                 *
-                 * If the entity is not a line, the behavior is undefined.
-                 *
-                 * @return The first point of the line entity.
-                 */
-                std::vector<float> GetLinePointA();
-
-                /**
-                 * Retrieves the second point of the line entity.
-                 *
-                 * If the entity is not a line, the behavior is undefined.
-                 *
-                 * @return The second point of the line entity.
-                 */
-                std::vector<float> GetLinePointB();
-
-
-
-            private:
-
-                /**
-                 * Entity name.
-                 */
-                std::string name_;
-
-                /**
-                 * Entity index.
-                 */
-                size_t index_;
-
-                /**
-                 * Function list.
-                 */
-                std::map<size_t, std::string> functions_;
-
-                /**
-                 * Indicates if the entity is a line.
-                 */
-                bool is_line_;
-
-                /**
-                 * The first point of a line entity.
-                 *
-                 * If the entity is not a line, it may not be initializer.
-                 */
-                std::vector<float> point_a_;
-
-                /**
-                 * The second point of a line entity.
-                 *
-                 * If the entity is not a line, it may not be initializer.
-                 */
-                std::vector<float> point_b_;
-        };
-
-        /**
-         * Retrieves the disassembler.
-         *
-         * @param insts[in] List of instructions.
-         * @param raw_script_data[in] Script data, raw format.
-         * @return Pointer to the disassembler.
-         */
-        virtual std::unique_ptr<Disassembler> GetDisassembler(
-          InstVec &insts, const std::vector<unsigned char>& raw_script_data
-        ) override;
-
-        /**
-         * Retrieves the dissasembler.
-         *
-         * @param insts[in] List of instructions.
-         * @return Pointer to the dissasembler.
-         * @todo Understand and document properly.
-         */
-        virtual std::unique_ptr<Disassembler> GetDisassembler(InstVec &insts) override;
-
-        /**
-         * Retrieves the code generator.
-         *
-         * @param insts[in] List of instructions.
-         * @param output[in] Pointer to the output (file, stream...).
-         * @return Pointer to the generator.
-         */
-        virtual std::unique_ptr<CodeGenerator> GetCodeGenerator(
-          const InstVec& insts, std::ostream &output
-        ) override;
-
-        /**
-         * Post-processing actions to apply to the scripts.
-         *
-         * It actually does nothing. CFG stands for control flow group
-         *
-         * @param insts[in] Instruction list.
-         * @param grapho[in] Code graph.
-         */
-        virtual void PostCFG(InstVec &insts, Graph g) override;
-
-        /**
-         * Indicates if instructions are purely grouped.
-         *
-         * @return True if instructions are purely grouped.
-         * @todo What is pure grouping?
-         */
-        virtual bool UsePureGrouping() const override;
-
-        /**
-         * Retrieves all entities in the map.
-         *
-         * @return A map of entities, with the name and index.
-         */
-        std::map<std::string, int> GetEntities() const;
-
-        /**
-         * Retrieves all non-line entities in the map.
-         *
-         * @return A list of non-line entities.
-         */
-        std::vector<SUDM::Field::FieldEntity> GetEntityList() const;
-
-        /**
-         * Retrieves all line entities in the map.
-         *
-         * @param A list of line entities.
-         */
-        std::vector<SUDM::Field::Line> GetLineList() const;
-
-        /**
-         * Retrieves all entities in the map.
-         *
-         * @return A map of entities, with the name and index.
-         */
-        std::map<size_t, Entity> GetEntityIndexMap() const{return entity_index_map_;}
-
-        /**
-         * Adds a function to an entity.
-         *
-         * @param entity_name Name of the entity.
-         * @param entity_index Index of the entity.
-         * @param func_name Name of the function.
-         * @param func_index Index of the function.
-         */
-        void AddEntityFunction(
-          const std::string& entity_name, size_t entity_index,
-          const std::string& func_name, size_t func_index
-        );
-
-        /**
-         * Marks an entity as a line.
-         *
-         * @param entity_index Index of the entity.
-         * @param line[in] True to mark the entity as a line, false to unmark
-         * it.
-         * @param point_a[in] First point of the line. Can be null if line is
-         * false.
-         * @param point_b[in] Second point of the line. Can be null if line is
-         * false.
-         */
-        void MarkEntityAsLine(
-            size_t entity_index, bool line, std::vector<float> point_a, std::vector<float> point_b
-        );
-
-        /**
-         * Checks if an entity has been marked as a line.
-         *
-         * @param entity_index[in] Index of the entity to check.
-         * @return True if the entity is a line. False if it isn't, or if
-         * there is no such entity.
-         */
-        bool EntityIsLine(size_t entity_index);
-
-        /**
-         * Retrieves an entity.
-         *
-         * @param index[in] Index of the entity to retrieve.
-         * @throws InternalDecompilerError if there is no entity at the
-         * specified index.
-         */
-        const Entity& EntityByIndex(size_t index) const;
-
-        /**
-         * Retrieves the scale factor for the map.
-         *
-         * @return Map scale factor.
-         */
-        float GetScaleFactor() const;
-
-        /**
-         * Retrieves the script name.
-         *
-         * @return The script name.
-         */
-        const std::string& ScriptName() const;
-
-    private:
-
-        /**
-         * Removes extraneous return statements.
-         *
-         * Usefull for scripts that only contain one one return
-         * statement.
-         *
-         * @param insts[in|out] List of instructions to proccess.
-         * Extraneous return statements will be deleted from the
-         * instructions.
-         * @param g[in] Code graph. Unused.
-         */
-        void RemoveExtraneousReturnStatements(InstVec& insts, Graph g);
-
-        /**
-         * 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.
-         *
-         * @param insts[in|out] List of instructions to proccess. Trailing
-         * infinite loops will be deleted from the instructions.
-         * @param g[in] Code graph.
-         * @todo What is the graph used to?
-         */
-        void RemoveTrailingInfiniteLoops(InstVec& insts, Graph g);
-
-        /**
-         * 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 with
-         * @{see FieldEngine::RemoveTrailingInfiniteLoops}.
-         */
-        void MarkInfiniteLoopGroups(InstVec& insts, Graph g);
-
-        /**
-         * The script formatter.
-         */
-        SUDM::IScriptFormatter& mFormatter;
-
-        /**
-         * The entity index map for the field.
-         */
-        std::map<size_t, Entity> entity_index_map_;
-
-        /**
-         * The map scale factor.
-         */
-        float scale_factor_ = 1.0f;
-
-        /**
-         * The script name.
-         */
-        std::string script_name_;
-};
+namespace FF7{
+
+    /**
+     * Represents the FF7 Field engine.
+     */
+    class FieldEngine : public Engine{
+
+        public:
+
+            /**
+             * Represents an entity.
+             *
+             * An entity can be almost anything in a field map: the playable
+             * character, an NPC, an item, a line...
+             */
+            class Entity{
+                public:
+
+                    /**
+                     * Entity constructor.
+                     *
+                     * It doesn't initialize any of the fields.
+                     */
+                    Entity() = default;
+
+                    /**
+                     * Entity constructor.
+                     *
+                     * Instantiates an entity with a name.
+                     *
+                     * @param name[in] Entity name.
+                     */
+                    Entity(const std::string& name, size_t index);
+
+                    /**
+                     * Retrieves the entity name.
+                     *
+                     * @return The entity name.
+                     */
+                    std::string GetName() const;
+
+                    /**
+                     * Retrieves the entity index.
+                     *
+                     * The index is the one at which appears in the original
+                     * game script.
+                     *
+                     * @return The entity index.
+                     */
+                    size_t GetIndex() const;
+
+                    /**
+                     * Retrieves a function.
+                     *
+                     * Retrieves the name of a function from it's index.
+                     *
+                     * @param index[in] Function index.
+                     * @return Function name.
+                     * @throws InternalDecompilerError if there is no function
+                     * with the specified index.
+                     * @todo What is a function here? An Opcode?
+                     */
+                    std::string FunctionByIndex(size_t index) const;
+
+                    /**
+                     * Adds a function to the engine.
+                     *
+                     * Must be added by name and index.
+                     *
+                     * @param name[in] Function name. If the entity is a line,
+                     * the name will be overridden.
+                     * @param index[in] Function index.
+                     * @todo What is a function here? An Opcode?
+                     */
+                    void AddFunction(const std::string& name, size_t index);
+
+                    /**
+                     * Marks the entity as a line.
+                     *
+                     * @param line[in] True to mark the entity as a line,
+                     * false to unmark it.
+                     * @param point_a[in] First point of the line. Can be null
+                     * if line is false.
+                     * @param point_b[in] Second point of the line. Can be
+                     * null if line is false.
+                     */
+                    void MarkAsLine(
+                      bool line, std::vector<float> point_a, std::vector<float> point_b
+                    );
+
+                    /**
+                     * Checks if the entity is a line.
+                     *
+                     * Note that an entity is not considered to be a line
+                     * until a function has been found containing the opcode
+                     * LINE and {@see MarkAsLine} has been called.
+                     *
+                     * @return true if the entity is a line.
+                     */
+                    bool IsLine();
+
+                    /**
+                     * Retrieves the first point of the line entity.
+                     *
+                     * If the entity is not a line, the behavior is undefined.
+                     *
+                     * @return The first point of the line entity.
+                     */
+                    std::vector<float> GetLinePointA();
+
+                    /**
+                     * Retrieves the second point of the line entity.
+                     *
+                     * If the entity is not a line, the behavior is undefined.
+                     *
+                     * @return The second point of the line entity.
+                     */
+                    std::vector<float> GetLinePointB();
+
+
+
+                private:
+
+                    /**
+                     * Entity name.
+                     */
+                    std::string name_;
+
+                    /**
+                     * Entity index.
+                     */
+                    size_t index_;
+
+                    /**
+                     * Entity function (script) list.
+                     */
+                    std::map< size_t, std::string > functions_;
+
+                    /**
+                     * Indicates if the entity is a line.
+                     */
+                    bool is_line_;
+
+                    /**
+                     * The first point of a line entity.
+                     *
+                     * If the entity is not a line, it may not be initializer.
+                     */
+                    std::vector<float> point_a_;
+
+                    /**
+                     * The second point of a line entity.
+                     *
+                     * If the entity is not a line, it may not be initializer.
+                     */
+                    std::vector<float> point_b_;
+            };
+
+            /**
+             * Constructor.
+             *
+             * @param formatter[in] The formatter to be used by the engine.
+             * @param script_name[in] The script name.
+             */
+            FieldEngine(SUDM::IScriptFormatter& formatter, std::string script_name);
+
+            /**
+             * Copy constructor, disabled.
+             *
+             * @param engine[in] The engine to copy.
+             */
+            FieldEngine(const FieldEngine& engine) = delete;
+
+            /**
+             * Copy constructor, disabled.
+             *
+             * @param engine[in] The engine to copy.
+             */
+            FieldEngine& operator = (const FieldEngine& engine) = delete;
+
+            /**
+             * Retrieves the disasembler.
+             *
+             * @param insts[in] List of instructions.
+             * @param raw_script_data[in] Script data, raw format.
+             * @return Pointer to the disasembler.
+             */
+            virtual std::unique_ptr<Disassembler> GetDisassembler(
+              InstVec &insts, const std::vector<unsigned char>& raw_script_data
+            ) override;
+
+            /**
+             * Retrieves the dissasembler.
+             *
+             * @param insts[in] List of instructions.
+             * @return Pointer to the dissasembler.
+             */
+            virtual std::unique_ptr<Disassembler> GetDisassembler(InstVec &insts) override;
+
+            /**
+             * Retrieves the code generator.
+             *
+             * @param insts[in] List of instructions.
+             * @param output[in] Pointer to the output (file, stream...).
+             * @return Pointer to the generator.
+             */
+            virtual std::unique_ptr<CodeGenerator> GetCodeGenerator(
+              const InstVec& insts, std::ostream &output
+            ) override;
+
+            /**
+             * Post-processing actions to apply to the scripts.
+             *
+             * It actually does nothing. CFG stands for control flow group.
+             *
+             * @param insts[in] Instruction list.
+             * @param graph[in] Code graph.
+             */
+            virtual void PostCFG(InstVec &insts, Graph graph) override;
+
+            /**
+             * Indicates if instructions are purely grouped.
+             *
+             * @return True if instructions are purely grouped. Always false.
+             * @todo What is pure grouping?
+             */
+            virtual bool UsePureGrouping() const override;
+
+            /**
+             * Retrieves all entities in the map.
+             *
+             * @return A map of entities, with the name and index.
+             */
+            std::map<std::string, int> GetEntities() const;
+
+            /**
+             * Retrieves all non-line entities in the map.
+             *
+             * @return A list of non-line entities.
+             */
+            std::vector<SUDM::FF7::Field::FieldEntity> GetEntityList() const;
+
+            /**
+             * Retrieves all line entities in the map.
+             *
+             * @param A list of line entities.
+             */
+            std::vector<SUDM::FF7::Field::Line> GetLineList() const;
+
+            /**
+             * Retrieves all entities in the map.
+             *
+             * @return A map of entities, with the name and index.
+             */
+            std::map<size_t, Entity> GetEntityIndexMap() const{return entity_index_map_;}
+
+            /**
+             * Adds a function to an entity.
+             *
+             * @param entity_name Name of the entity.
+             * @param entity_index Index of the entity.
+             * @param func_name Name of the function.
+             * @param func_index Index of the function.
+             */
+            void AddEntityFunction(
+              const std::string& entity_name, size_t entity_index,
+              const std::string& func_name, size_t func_index
+            );
+
+            /**
+             * Marks an entity as a line.
+             *
+             * @param entity_index Index of the entity.
+             * @param line[in] True to mark the entity as a line, false to
+             * unmark it.
+             * @param point_a[in] First point of the line. Can be null if line
+             * is false.
+             * @param point_b[in] Second point of the line. Can be null if
+             * line is false.
+             */
+            void MarkEntityAsLine(
+                size_t entity_index, bool line,
+                std::vector<float> point_a, std::vector<float> point_b
+            );
+
+            /**
+             * Checks if an entity has been marked as a line.
+             *
+             * @param entity_index[in] Index of the entity to check.
+             * @return True if the entity is a line. False if it isn't, or if
+             * there is no such entity.
+             */
+            bool EntityIsLine(size_t entity_index);
+
+            /**
+             * Retrieves an entity.
+             *
+             * @param index[in] Index of the entity to retrieve.
+             * @throws InternalDecompilerError if there is no entity at the
+             * specified index.
+             */
+            const Entity& EntityByIndex(size_t index) const;
+
+            /**
+             * Retrieves the scale factor for the map.
+             *
+             * @return Map scale factor.
+             */
+            float GetScaleFactor() const;
+
+            /**
+             * Retrieves the script name.
+             *
+             * @return The script name.
+             */
+            const std::string& GetScriptName() const;
+
+        private:
+
+            /**
+             * Removes extraneous return statements.
+             *
+             * Useful for scripts that only contain one one return statement.
+             *
+             * @param insts[in|out] List of instructions to process.
+             * Extraneous return statements will be deleted from the
+             * instructions.
+             * @param graph[in] Code graph. Unused.
+             */
+            void RemoveExtraneousReturnStatements(InstVec& insts, Graph graph);
+
+            /**
+             * 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.
+             *
+             * @param insts[in|out] List of instructions to proccess. Trailing
+             * infinite loops will be deleted from the instructions.
+             * @param g[in] Code graph.
+             * @todo What is the graph used to?
+             */
+            void RemoveTrailingInfiniteLoops(InstVec& insts, Graph graph);
+
+            /**
+             * 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 with
+             * @{see FieldEngine::RemoveTrailingInfiniteLoops}.
+             */
+            void MarkInfiniteLoopGroups(InstVec& insts, Graph graph);
+
+            /**
+             * The script formatter.
+             */
+            SUDM::IScriptFormatter& formatter_;
+
+            /**
+             * The entity index map for the field.
+             */
+            std::map<size_t, Entity> entity_index_map_;
+
+            /**
+             * The map scale factor.
+             */
+            float scale_factor_;
+
+            /**
+             * The script name.
+             */
+            std::string script_name_;
+    };
+
+}

+ 38 - 34
V-Gears-Installer/include/decompiler/field/instruction/FieldBackgroundInstruction.h

@@ -1,5 +1,4 @@
 /*
 /*
- * V-Gears
  * Copyright (C) 2022 V-Gears Team
  * Copyright (C) 2022 V-Gears Team
  *
  *
  * This program is free software: you can redistribute it and/or modify
  * This program is free software: you can redistribute it and/or modify
@@ -18,37 +17,42 @@
 
 
 #pragma once
 #pragma once
 
 
-#include "decompiler/decompiler_engine.h"
+#include "decompiler/instruction.h"
+#include "decompiler/field/FieldEngine.h"
 
 
-/**
- * A background instruction.
- */
-class FieldBackgroundInstruction : public KernelCallInstruction{
-
-    public:
-
-        /**
-         * Processes the instruction.
-         *
-         * @param func[in] Function to process.
-         * @param stack[out] Function stack.
-         * @param engine[in] Engine. Unused
-         * @param code_gen[in|out] Code generator.
-         */
-        virtual void ProcessInst(
-          Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
-        ) override;
-
-    private:
-
-        void ProcessBGON(CodeGenerator* code_gen);
-        void ProcessBGOFF(CodeGenerator* code_gen);
-        void ProcessBGCLR(CodeGenerator* code_gen);
-        void ProcessSTPAL(CodeGenerator* code_gen);
-        void ProcessLDPAL(CodeGenerator* code_gen);
-        void ProcessCPPAL(CodeGenerator* code_gen);
-        void ProcessADPAL(CodeGenerator* code_gen);
-        void ProcessMPPAL2(CodeGenerator* code_gen);
-        void ProcessSTPLS(CodeGenerator* code_gen);
-        void ProcessLDPLS(CodeGenerator* code_gen);
-};
+namespace FF7{
+
+    /**
+     * A background instruction.
+     */
+    class FieldBackgroundInstruction : public KernelCallInstruction{
+
+        public:
+
+            /**
+             * Processes the instruction.
+             *
+             * @param func[in] Function to process.
+             * @param stack[out] Function stack.
+             * @param engine[in] Engine. Unused
+             * @param codegen[in|out] Code generator to append lines.
+             */
+            virtual void ProcessInst(
+              Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
+
+        private:
+
+            void ProcessBGON(CodeGenerator* code_gen);
+            void ProcessBGOFF(CodeGenerator* code_gen);
+            void ProcessBGCLR(CodeGenerator* code_gen);
+            void ProcessSTPAL(CodeGenerator* code_gen);
+            void ProcessLDPAL(CodeGenerator* code_gen);
+            void ProcessCPPAL(CodeGenerator* code_gen);
+            void ProcessADPAL(CodeGenerator* code_gen);
+            void ProcessMPPAL2(CodeGenerator* code_gen);
+            void ProcessSTPLS(CodeGenerator* code_gen);
+            void ProcessLDPLS(CodeGenerator* code_gen);
+    };
+
+}

+ 32 - 28
V-Gears-Installer/include/decompiler/field/instruction/FieldCameraInstruction.h

@@ -1,5 +1,4 @@
 /*
 /*
- * V-Gears
  * Copyright (C) 2022 V-Gears Team
  * Copyright (C) 2022 V-Gears Team
  *
  *
  * This program is free software: you can redistribute it and/or modify
  * This program is free software: you can redistribute it and/or modify
@@ -18,31 +17,36 @@
 
 
 #pragma once
 #pragma once
 
 
-#include "decompiler/decompiler_engine.h"
+#include "decompiler/instruction.h"
+#include "decompiler/field/FieldEngine.h"
 
 
-/**
- * A camera instruction.
- */
-class FieldCameraInstruction : public KernelCallInstruction{
-
-    public:
-
-        /**
-         * Processes the instruction.
-         *
-         * @param func[in] Function to process.
-         * @param stack[out] Function stack.
-         * @param engine[in] Engine. Unused
-         * @param code_gen[in|out] Code generator.
-         */
-        virtual void ProcessInst(
-          Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
-        ) override;
-
-    private:
-
-        void ProcessNFADE(CodeGenerator* code_gen);
-        void ProcessSCR2D(CodeGenerator* code_gen);
-        void ProcessSCR2DC(CodeGenerator* code_gen);
-        void ProcessFADE(CodeGenerator* code_gen);
-};
+namespace FF7{
+
+    /**
+     * A camera instruction.
+     */
+    class FieldCameraInstruction : public KernelCallInstruction{
+
+        public:
+
+            /**
+             * Processes the instruction.
+             *
+             * @param func[in] Function to process.
+             * @param stack[out] Function stack.
+             * @param engine[in] Engine. Unused
+             * @param codegen[in|out] Code generator to append lines.
+             */
+            virtual void ProcessInst(
+              Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
+
+        private:
+
+            void ProcessNFADE(CodeGenerator* code_gen);
+            void ProcessSCR2D(CodeGenerator* code_gen);
+            void ProcessSCR2DC(CodeGenerator* code_gen);
+            void ProcessFADE(CodeGenerator* code_gen);
+    };
+
+}

+ 42 - 40
V-Gears-Installer/include/decompiler/field/instruction/FieldCondJumpInstruction.h

@@ -18,44 +18,46 @@
 
 
 #pragma once
 #pragma once
 
 
-#include "decompiler/decompiler_engine.h"
+#include "decompiler/instruction.h"
 
 
-/**
- * A conditional map jump instruction.
- */
-class FieldCondJumpInstruction : public CondJumpInstruction{
-
-    public:
-
-        /**
-         * Processes a conditional jump instruction.
-         *
-         * Checks if the condition is a function or a comparison, and
-         * adds the function to the stack.
-         *
-         * @param function[in] Function to process. Unused.
-         * @param stack[out] Function stack. The instruction will be added
-         * here.
-         * @param engine[in] Engine. Unused.
-         * @param code_gen[in|out] Code generator.
-         */
-        virtual void ProcessInst(
-          Function& function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
-        ) override;
-
-        /**
-         * Retrieves the destination address of the jump.
-         *
-         * @return The offset (number of bytes) to jump from the beginning
-         * of the instruction.
-         */
-        virtual uint32 GetDestAddress() const override;
-
-        /**
-         * Prints the instruction
-         *
-         * @param output The stram to print the instruction to.
-         * @todo Understand and document properly.
-         */
-        virtual std::ostream& Print(std::ostream &output) const override;
-};
+namespace FF7{
+
+    /**
+     * A conditional map jump instruction.
+     */
+    class FieldCondJumpInstruction : public CondJumpInstruction{
+
+        public:
+
+            /**
+             * Processes a conditional jump instruction.
+             *
+             * Checks if the condition is a function or a comparison, and
+             * adds the function to the stack.
+             *
+             * @param function[in] Function to process. Unused.
+             * @param stack[out] Function stack. The instruction will be added
+             * here.
+             * @param engine[in] Engine. Unused.
+             * @param codegen[in|out] Code generator to append lines.
+             */
+            virtual void ProcessInst(
+              Function& function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
+
+            /**
+             * Retrieves the destination address of the jump.
+             *
+             * @return The offset (number of bytes) to jump from the beginning
+             * of the instruction.
+             */
+            virtual uint32 GetDestAddress() const override;
+
+            /**
+             * Prints the instruction
+             *
+             * @param output The stream to print the instruction to.
+             */
+            virtual std::ostream& Print(std::ostream &output) const override;
+    };
+}

+ 160 - 155
V-Gears-Installer/include/decompiler/field/instruction/FieldControlFlowInstruction.h

@@ -18,169 +18,174 @@
 
 
 #pragma once
 #pragma once
 
 
-#include "decompiler/decompiler_engine.h"
+#include "decompiler/instruction.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldEngine.h"
 
 
-/**
- * A script flow control instruction.
- */
-class FieldControlFlowInstruction : public KernelCallInstruction{
+namespace FF7{
+
+    /**
+     * A script flow control instruction.
+     */
+    class FF7ControlFlowInstruction : public KernelCallInstruction{
+
+        public:
 
 
-    public:
+            /**
+             * Create a FF7ControlFlowInstruction.
+             *
+             * @return Pointer to the newly created instruction.
+             */
+            static InstPtr Create(){return new FF7ControlFlowInstruction();}
 
 
-        /**
-         * Create a FieldControlFlowInstruction.
-         *
-         * @return Pointer to the newly created instruction.
-         */
-        static InstPtr Create(){return new FieldControlFlowInstruction();}
+            /**
+             * Processes the instruction.
+             *
+             * @param func[in] Function to process.
+             * @param stack[out] Function stack.
+             * @param engine[in] Engine.
+             * @param code_gen[in] Code generator.
+             */
+            virtual void ProcessInst(
+              Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
 
 
-        /**
-         * Processes the instruction.
-         *
-         * @param func[in] Function to process.
-         * @param stack[out] Function stack.
-         * @param engine[in] Engine.
-         * @param code_gen[in|out] Code generator.
-         */
-        virtual void ProcessInst(
-          Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
-        ) override;
+        private:
 
 
-    private:
+            /**
+             * Processes a REQ command.
+             *
+             * Opcode: 0x01
+             * Short name: REQ
+             * Long name: Request remote execution (asynchronous,
+             *            non-guaranteed)
+             *
+             * Memory layout (3 bytes)
+             * |0x01|E|P/F|
+             *
+             * Arguments
+             * - const UByte E: The ID of the target entity.
+             * - const Bit[3] P: The priority at which we want to execute the
+             * remote script (high 3 bits of byte).
+             * - const Bit[5] F: The ID of the specific member function of E
+             * to be executed (low 5 bits of byte).
+             *
+             * Requests that a remote entity executes one of its member
+             * functions at a specified priority. The request is asynchronous
+             * and returns immediately without waiting for the remote
+             * execution to start or finish. If the specified priority is
+             * already busy executing, the request will fail silently.
+             *
+             * @param codegen[in|out] Code generator to append lines.
+             * @param engine[in] The engine.
+             */
+            void ProcessREQ(CodeGenerator* code_gen, const FieldEngine& engine);
 
 
-        /**
-         * Processes a REQ command.
-         *
-         * Opcode: 0x01
-         * Short name: REQ
-         * Long name: Request remote execution (asynchronous, non-guaranteed)
-         *
-         * Memory layout (3 bytes)
-         * |0x01|E|P/F|
-         *
-         * Arguments
-         * - const UByte E: The ID of the target entity.
-         * - const Bit[3] P: The priority at which we want to execute the
-         * remote script (high 3 bits of byte).
-         * - const Bit[5] F: The ID of the specific member function of E to be
-         * executed (low 5 bits of byte).
-         *
-         * Requests that a remote entity executes one of its member functions
-         * at a specified priority. The request is asynchronous and returns
-         * immediately without waiting for the remote execution to start or
-         * finish. If the specified priority is already busy executing, the
-         * request will fail silently.
-         *
-         * @param codegen[in|out] Code generator. Output lines are appended.
-         * @param engine[in] The engine.
-         */
-        void ProcessREQ(CodeGenerator* code_gen, const FieldEngine& engine);
+            /**
+             * Processes a REQSW command.
+             *
+             * Opcode: 0x02
+             * Short name: REQSW
+             * Long name: Request remote execution (asynchronous execution,
+             * guaranteed)
+             *
+             * Memory layout (3 bytes)
+             * |0x02|E|P/F|
+             *
+             * Arguments
+             * - const UByte E: The ID of the target entity.
+             * - const Bit[3] P: The priority at which we want to execute the
+             * remote script (high 3 bits of byte).
+             * - const Bit[5] F: The ID of the specific member function of E
+             * tobe executed (low 5 bits of byte).
+             *
+             * Requests that a remote entity executes one of its member
+             * functions at a specified priority. If the specified priority is
+             * already busy executing, the request will block until it becomes
+             * available and only then return. The remote execution is still
+             * carried out asynchronously, with no notification of completion.
+             *
+             * @param codegen[in|out] Code generator to append lines.
+             * @param engine[in] The engine.
+             */
+            void ProcessREQSW(CodeGenerator* code_gen, const FieldEngine& engine);
 
 
-        /**
-         * Processes a REQSW command.
-         *
-         * Opcode: 0x02
-         * Short name: REQSW
-         * Long name: Request remote execution (asynchronous execution,
-         * guaranteed)
-         *
-         * Memory layout (3 bytes)
-         * |0x02|E|P/F|
-         *
-         * Arguments
-         * - const UByte E: The ID of the target entity.
-         * - const Bit[3] P: The priority at which we want to execute the
-         * remote script (high 3 bits of byte).
-         * - const Bit[5] F: The ID of the specific member function of E to be
-         * executed (low 5 bits of byte).
-         *
-         * Requests that a remote entity executes one of its member functions
-         * at a specified priority. If the specified priority is already busy
-         * executing, the request will block until it becomes available and
-         * only then return. The remote execution is still carried out
-         * asynchronously, with no notification of completion.
-         *
-         * @param codegen[in|out] Code generator. Output lines are appended.
-         * @param engine[in] The engine.
-         */
-        void ProcessREQSW(CodeGenerator* code_gen, const FieldEngine& engine);
+            /**
+             * Processes a REQEW command.
+             *
+             * Opcode: 0x03
+             * Short name: REQEW
+             * Long name: Request remote execution (synchronous, guaranteed)
+             *
+             * Memory layout (3 bytes)
+             * |0x03|E|P/F|
+             *
+             * Arguments
+             * - const UByte E: The ID of the target entity.
+             * - const Bit[3] P: The priority at which we want to execute the
+             * remote script (high 3 bits of byte).
+             * - const Bit[5] F: The ID of the specific member function of E
+             * to be executed (low 5 bits of byte).
+             *
+             * Requests that a remote entity executes one of its member
+             * functions at a specified priority. The request will block until
+             * remote execution has finished before returning.
+             *
+             * @param codegen[in|out] Code generator to append lines.
+             * @param engine[in] The engine.
+             */
+            void ProcessREQEW(CodeGenerator* code_gen, const FieldEngine& engine);
 
 
-        /**
-         * Processes a REQEW command.
-         *
-         * Opcode: 0x03
-         * Short name: REQEW
-         * Long name: Request remote execution (synchronous, guaranteed)
-         *
-         * Memory layout (3 bytes)
-         * |0x03|E|P/F|
-         *
-         * Arguments
-         * - const UByte E: The ID of the target entity.
-         * - const Bit[3] P: The priority at which we want to execute the
-         * remote script (high 3 bits of byte).
-         * - const Bit[5] F: The ID of the specific member function of E to be
-         * be executed (low 5 bits of byte).
-         *
-         * Requests that a remote entity executes one of its member functions
-         * at a specified priority. The request will block until remote
-         * execution has finished before returning.
-         *
-         * @param codegen[in|out] Code generator. Output lines are appended.
-         * @param engine[in] The engine.
-         */
-        void ProcessREQEW(CodeGenerator* code_gen, const FieldEngine& engine);
+            /**
+             * Processes a RETTO command.
+             *
+             * Opcode: 0x07
+             * Short name: RETTO
+             * Long name: Return To
+             *
+             * Memory layout (2 bytes)
+             * |0x07|P/F|
+             *
+             * Arguments
+             * - const Bit[3] P: The priority at which we want to execute the
+             * remote script (high 3 bits of byte).
+             * - const Bit[5] F: The ID of the specific member function of the
+             * current entity to be executed to (low 5 bits of byte).
+             *
+             * Stops the active script loop for this entity and also any
+             * script loops (except the main) that are queuing to be executed
+             * after the current script. This is essentially the same as
+             * adding a RET onto each of the active / queued scripts next
+             * execution position and returning the current op index to index
+             * for each script. Then the script control is passed to the
+             * script F within the current entity with the priority P.
+             *
+             * @param codegen[in|out] Code generator to append lines.
+             */
+            void ProcessRETTO(CodeGenerator* code_gen);
 
 
-        /**
-         * Processes a RETTO command.
-         *
-         * Opcode: 0x07
-         * Short name: RETTO
-         * Long name: Return To
-         *
-         * Memory layout (2 bytes)
-         * |0x07|P/F|
-         *
-         * Arguments
-         * - const Bit[3] P: The priority at which we want to execute the
-         * remote script (high 3 bits of byte).
-         * - const Bit[5] F: The ID of the specific member function of the
-         * current entity to be executed to (low 5 bits of byte).
-         *
-         * Stops the active script loop for this entity and also any script
-         * loops (except the main) that are queuing to be executed after the
-         * current script. This is essentially the same as adding a RET onto
-         * each of the active / queued scripts next execution position and
-         * returning the current op index to index for each script. Then the
-         * script control is passed to the script F within the current entity
-         * with the priority P.
-         *
-         * @param codegen[in|out] Code generator. Output lines are appended.
-         */
-        void ProcessRETTO(CodeGenerator* code_gen);
+            /**
+             * Processes a WAIT command.
+             *
+             * Opcode: 0x24
+             * Short name: WAIT
+             * Long name: Wait
+             *
+             * Memory layout (2 bytes)
+             * |0x24|A|
+             *
+             * Arguments
+             * - const UShort A: Amount (number of frames) to wait.
+             *
+             * Pauses current script execution for a specific amount of time.
+             * Rather than a specific time value in milliseconds/seconds,
+             * the amount specifies the number of frames that must be drawn
+             * before execution resumes. Since the game runs at 30fps,
+             * WAIT(0x1E) (or WAIT(30) in decimal) will pause script execution
+             * for 1 second, WAIT(0x96) will pause for 5 seconds, and so on.
+             *
+             * @param codegen[in|out] Code generator to append lines.
+             */
+            void ProcessWAIT(CodeGenerator* code_gen);
+    };
 
 
-        /**
-         * Processes a WAIT command.
-         *
-         * Opcode: 0x24
-         * Short name: WAIT
-         * Long name: Wait
-         *
-         * Memory layout (2 bytes)
-         * |0x24|A|
-         *
-         * Arguments
-         * - const UShort A: Amount (number of frames) to wait.
-         *
-         * Pauses current script execution for a specific amount of time.
-         * Rather than a specific time value in milliseconds/seconds, the
-         * amount specifies the number of frames that must be drawn before
-         * execution resumes. Since the game runs at 30fps, WAIT(0x1E) (or
-         * WAIT(30) in decimal) will pause script execution for 1 second,
-         * WAIT(0x96) will pause for 5 seconds, and so on.
-         *
-         * @param codegen[in|out] Code generator. Output lines are appended.
-         */
-        void ProcessWAIT(CodeGenerator* code_gen);
-};
+}

+ 89 - 83
V-Gears-Installer/include/decompiler/field/instruction/FieldMathInstruction.h

@@ -1,5 +1,4 @@
 /*
 /*
- * V-Gears
  * Copyright (C) 2022 V-Gears Team
  * Copyright (C) 2022 V-Gears Team
  *
  *
  * This program is free software: you can redistribute it and/or modify
  * This program is free software: you can redistribute it and/or modify
@@ -18,92 +17,99 @@
 
 
 #pragma once
 #pragma once
 
 
-#include "decompiler/decompiler_engine.h"
+#include "decompiler/instruction.h"
+#include "decompiler/field/FieldEngine.h"
 
 
-/**
- * A math instruction.
- */
-class FieldMathInstruction : public StoreInstruction{
+namespace FF7{
+
+    /**
+     * A math instruction.
+     */
+    class FieldMathInstruction : public StoreInstruction{
+
+        public:
 
 
-    public:
+            /**
+             * Processes the instruction.
+             *
+             * @param func[in] Function to process.
+             * @param stack[out] Function stack.
+             * @param engine[in] Engine. Unused.
+             * @param code_gen[in] Code generator.
+             */
+            virtual void ProcessInst(
+              Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
 
 
-        /**
-         * Processes the instruction.
-         *
-         * @param func[in] Function to process.
-         * @param stack[out] Function stack.
-         * @param engine[in] Engine. Unused.
-         * @param code_gen[in|out] Code generator.
-         */
-        virtual void ProcessInst(
-          Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
-        ) override;
+        private:
 
 
-    private:
+            void ProcessSaturatedPLUS(CodeGenerator* code_gen);
+            void ProcessSaturatedPLUS2(CodeGenerator* code_gen);
+            void ProcessSaturatedMINUS(CodeGenerator* code_gen);
+            void ProcessSaturatedMINUS2(CodeGenerator* code_gen);
+            void ProcessSaturatedINC(CodeGenerator* code_gen);
+            void ProcessSaturatedINC2(CodeGenerator* code_gen);
+            void ProcessSaturatedDEC(CodeGenerator* code_gen);
+            void ProcessSaturatedDEC2(CodeGenerator* code_gen);
+            void ProcessRDMSD(CodeGenerator* code_gen);
+            void ProcessSETBYTE_SETWORD(CodeGenerator* code_gen);
 
 
-        void ProcessSaturatedPLUS(CodeGenerator* code_gen);
-        void ProcessSaturatedPLUS2(CodeGenerator* code_gen);
-        void ProcessSaturatedMINUS(CodeGenerator* code_gen);
-        void ProcessSaturatedMINUS2(CodeGenerator* code_gen);
-        void ProcessSaturatedINC(CodeGenerator* code_gen);
-        void ProcessSaturatedINC2(CodeGenerator* code_gen);
-        void ProcessSaturatedDEC(CodeGenerator* code_gen);
-        void ProcessSaturatedDEC2(CodeGenerator* code_gen);
-        void ProcessRDMSD(CodeGenerator* code_gen);
-        void ProcessSETBYTE_SETWORD(CodeGenerator* code_gen);
+            /**
+             * Processes a BITON opcode.
+             *
+             * Opcode: 0x82
+             * Short name: BITON
+             * Long name: Set Bit
+             *
+             * Memory layout (4 bytes)
+             * |0x82|D/S|A|B|
+             *
+             * Arguments
+             * - const Bit[4] D: Destination bank.
+             * - const Bit[4] S: Source bank.
+             * - const UByte A: Destination address.
+             * - const UByte Bit: The number of the bit to turn on.
+             *
+             * Sets the nth bit in the "A" location, where n is a number
+             * between 0-7 supplied in B. A value of zero in B will set the
+             * least significant bit. If the Source Bank is 0 then the bit to
+             * be set is taken from "Bit". If the Source Bank is an 8 bit
+             * bank, then the bit is the address in that bank where the
+             * operand is.
+             *
+             * @param codegen[in|out] Code generator to append lines.
+             */
+            void ProcessBITON(CodeGenerator* code_gen);
 
 
-        /**
-         * Processes a BITON opcode.
-         *
-         * Opcode: 0x82
-         * Short name: BITON
-         * Long name: Set Bit
-         *
-         * Memory layout (4 bytes)
-         * |0x82|D/S|A|B|
-         *
-         * Arguments
-         * - const Bit[4] D: Destination bank.
-         * - const Bit[4] S: Source bank.
-         * - const UByte A: Destination address.
-         * - const UByte Bit: The number of the bit to turn on.
-         *
-         * Sets the nth bit in the "A" location, where n is a number between
-         * 0-7 supplied in B. A value of zero in B will set the least
-         * significant bit. If the Source Bank is 0 then the bit to be set is
-         * taken from "Bit". If the Source Bank is an 8 bit bank, then the bit
-         * is the address in that bank where the operand is.
-         *
-         * @param codegen[in|out] Code generator. Output lines are appended.
-         */
-        void ProcessBITON(CodeGenerator* code_gen);
+            /**
+             * Processes a BITON opcode.
+             *
+             * Opcode: 0x83
+             * Short name: BITOFF
+             * Long name: Reset Bit
+             *
+             * Memory layout (4 bytes)
+             * |0x83|D/S|A|B|
+             *
+             * Arguments
+             * - const Bit[4] D: Destination bank.
+             * - const Bit[4] S: Source bank.
+             * - const UByte A: Destination address.
+             * - const UByte Bit: The number of the bit to turn off.
+             *
+             * Sets the nth bit in the "A" location, where n is a number
+             * between 0-7 supplied in B. A value of zero in B will reset the
+             * least significant bit. If the Source Bank is 0 then the bit to
+             * be set is taken from "Bit". If the Source Bank is an 8 bit
+             * bank, then the bit is the address in that bank where the
+             * operand is.
+             *
+             * @param codegen[in|out] Code generator to append lines.
+             */
+            void ProcessBITOFF(CodeGenerator* code_gen);
+            void ProcessPLUSx_MINUSx(CodeGenerator* code_gen, const std::string& op);
+            void ProcessINCx_DECx(CodeGenerator* code_gen, const std::string& op);
+            void ProcessRANDOM(CodeGenerator* code_gen);
+    };
 
 
-        /**
-         * Processes a BITON opcode.
-         *
-         * Opcode: 0x83
-         * Short name: BITOFF
-         * Long name: Reset Bit
-         *
-         * Memory layout (4 bytes)
-         * |0x83|D/S|A|B|
-         *
-         * Arguments
-         * - const Bit[4] D: Destination bank.
-         * - const Bit[4] S: Source bank.
-         * - const UByte A: Destination address.
-         * - const UByte Bit: The number of the bit to turn off.
-         *
-         * Sets the nth bit in the "A" location, where n is a number between
-         * 0-7 supplied in B. A value of zero in B will reset the least
-         * significant bit. If the Source Bank is 0 then the bit to be set is
-         * taken from "Bit". If the Source Bank is an 8 bit bank, then the bit
-         * is the address in that bank where the operand is.
-         *
-         * @param codegen[in|out] Code generator. Output lines are appended.
-         */
-        void ProcessBITOFF(CodeGenerator* code_gen);
-        void ProcessPLUSx_MINUSx(CodeGenerator* code_gen, const std::string& op);
-        void ProcessINCx_DECx(CodeGenerator* code_gen, const std::string& op);
-        void ProcessRANDOM(CodeGenerator* code_gen);
-};
+}

+ 36 - 32
V-Gears-Installer/include/decompiler/field/instruction/FieldMediaInstruction.h

@@ -1,5 +1,4 @@
 /*
 /*
- * V-Gears
  * Copyright (C) 2022 V-Gears Team
  * Copyright (C) 2022 V-Gears Team
  *
  *
  * This program is free software: you can redistribute it and/or modify
  * This program is free software: you can redistribute it and/or modify
@@ -18,35 +17,40 @@
 
 
 #pragma once
 #pragma once
 
 
-#include "decompiler/decompiler_engine.h"
+#include "decompiler/instruction.h"
+#include "decompiler/field/FieldEngine.h"
 
 
-/**
- * An audio or video (or both) instruction.
- */
-class FieldMediaInstruction : public KernelCallInstruction{
-
-    public:
-
-        /**
-         * Processes the instruction.
-         *
-         * @param func[in] Function to process.
-         * @param stack[out] Function stack.
-         * @param engine[in] Engine. Unused
-         * @param code_gen[in|out] Code generator.
-         */
-        virtual void ProcessInst(
-          Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
-        ) override;
-
-    private:
-
-        void ProcessAKAO2(CodeGenerator* code_gen);
-        void ProcessMUSIC(CodeGenerator* code_gen);
-        void ProcessSOUND(CodeGenerator* code_gen);
-        void ProcessAKAO(CodeGenerator* code_gen);
-        void ProcessMULCK(CodeGenerator* code_gen);
-        void ProcessPMVIE(CodeGenerator* code_gen);
-        void ProcessMOVIE(CodeGenerator* code_gen);
-        void ProcessMVIEF(CodeGenerator* code_gen);
-};
+namespace FF7{
+
+    /**
+     * An audio or video (or both) instruction.
+     */
+    class FieldMediaInstruction : public KernelCallInstruction{
+
+        public:
+
+            /**
+             * Processes the instruction.
+             *
+             * @param func[in] Function to process.
+             * @param stack[out] Function stack.
+             * @param engine[in] Engine. Unused
+             * @param codegen[in|out] Code generator to append lines.
+             */
+            virtual void ProcessInst(
+              Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
+
+        private:
+
+            void ProcessAKAO2(CodeGenerator* code_gen);
+            void ProcessMUSIC(CodeGenerator* code_gen);
+            void ProcessSOUND(CodeGenerator* code_gen);
+            void ProcessAKAO(CodeGenerator* code_gen);
+            void ProcessMULCK(CodeGenerator* code_gen);
+            void ProcessPMVIE(CodeGenerator* code_gen);
+            void ProcessMOVIE(CodeGenerator* code_gen);
+            void ProcessMVIEF(CodeGenerator* code_gen);
+    };
+
+}

+ 360 - 343
V-Gears-Installer/include/decompiler/field/instruction/FieldModelInstruction.h

@@ -1,5 +1,4 @@
 /*
 /*
- * V-Gears
  * Copyright (C) 2022 V-Gears Team
  * Copyright (C) 2022 V-Gears Team
  *
  *
  * This program is free software: you can redistribute it and/or modify
  * This program is free software: you can redistribute it and/or modify
@@ -18,357 +17,375 @@
 
 
 #pragma once
 #pragma once
 
 
-#include "decompiler/decompiler_engine.h"
+#include "decompiler/instruction.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldEngine.h"
 
 
-/**
- * A model instruction.
- */
-class FieldModelInstruction : public KernelCallInstruction{
+namespace FF7{
+
+    /**
+     * A model instruction.
+     */
+    class FieldModelInstruction : public KernelCallInstruction{
+
+        public:
 
 
-    public:
+            /**
+             * Processes the instruction.
+             *
+             * @param func[in] Function to process.
+             * @param stack[out] Function stack.
+             * @param engine[in] Engine.
+             * @param code_gen[in] Code generator.
+             */
+            virtual void ProcessInst(
+              Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
 
 
-        /**
-         * Processes the instruction.
-         *
-         * @param func[in] Function to process.
-         * @param stack[out] Function stack.
-         * @param engine[in] Engine.
-         * @param code_gen[in|out] Code generator.
-         */
-        virtual void ProcessInst(
-          Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
-        ) override;
+        private:
 
 
-    private:
+            /**
+             * Processes a JOIN opcode.
+             *
+             * Opcode: 0x08
+             * Short name: JOIN
+             * Long name: Party Field Join
+             * Memory layout (2 bytes)
+             * |0x08|S|
+             *
+             * Arguments
+             * - const UByte S: Speed that the characters join back together.
+             *
+             * Causes seperated party characters that have previously been
+             * SPLIT onto the field, to be joined back together again; that
+             * is, only the party leader becomes visible on the field. This
+             * should be called if a previous SPLIT has completed (the party
+             * members have finished speaking, or performing their actions,
+             * for example). As with SPLIT, the speed of the join is
+             * specified, from a scale of 1 (almost instant) to FF (very slow
+             * walk), and must be non-zero. In contrast to most MOVE related
+             * op codes, the speed is this setting is actually the total
+             * number of frames required. Depending on the distance from the
+             * player character and the number of frames required, the entity
+             * plays a run or walk animation. Also, all characters take the
+             * same time irrespective of distance. Calling JOIN without having
+             * previously SPLIT the characters will cause the party members to
+             * appear at the walkmesh origin and attempt to JOIN from there.
+             * This is not normally the required behaviour and should be
+             * avoided.
+             *
+             * @param codegen[in|out] Code generator to append lines.
+             */
+            void ProcessJOIN(CodeGenerator* code_gen);
 
 
-        /**
-         * Processes a JOIN opcode.
-         *
-         * Opcode: 0x08
-         * Short name: JOIN
-         * Long name: Party Field Join
-         * Memory layout (2 bytes)
-         * |0x08|S|
-         *
-         * Arguments
-         * - const UByte S: Speed that the characters join back together.
-         *
-         * Causes seperated party characters that have previously been SPLIT
-         * onto the field, to be joined back together again; that is, only the
-         * party leader becomes visible on the field. This should be called if
-         * a previous SPLIT has completed (the party members have finished
-         * speaking, or performing their actions, for example). As with SPLIT,
-         * the speed of the join is specified, from a scale of 1 (almost
-         * instant) to FF (very slow walk), and must be non-zero. In contrast
-         * to most MOVE related opcodes, the speed is this setting is actually
-         * the total number of frames required. Depending on the distance from
-         * the player character and the number of frames required, the entity
-         * plays a run or walk animation. Also, all characters take the same
-         * time irrespective of distance. Calling JOIN without having
-         * previously SPLIT the characters will cause the party members to
-         * appear at the walkmesh origin and attempt to JOIN from there. This
-         * is not normally the required behaviour and should be avoided.
-         *
-         * @param codegen[in|out] Code generator. Output lines are appended.
-         */
-        void ProcessJOIN(CodeGenerator* code_gen);
+            /**
+             * Processes a SPLIT opcode.
+             *
+             * Opcode: 0x09
+             * Short name: SPLIT
+             * Long name: Party Field Split
+             *
+             * Memory layout (15 bytes)
+             * |0x20|B1/B2|B3/B4|B5/B6|XA|XA|YA|YA|DA|XB|XB|YB|YB|DB|S|
+             *
+             * Arguments
+             * - const Bit[4] B1: Bank for XA, or zero if XA is specified as a
+             * literal value.
+             * - const Bit[4] B2: Bank for YA, or zero if YA is specified as a
+             * literal value.
+             * - const Bit[4] B3: Bank for DA, or zero if DA is specified as a
+             * literal value.
+             * - const Bit[4] B4: Bank for XB, or zero if XB is specified as a
+             * literal value.
+             * - const Bit[4] B5: Bank for YB, or zero if YB is specified as a
+             * literal value.
+             * - const Bit[4] B6: Bank for DB, or zero if DB is specified as a
+             * literal value.
+             * - const Short XA: X-coordinate of the second character in the
+             * party after the split, or address for the value if B1 is
+             * non-zero.
+             * - const Short YA: Y-coordinate of the second character in the
+             * party after the split, or address for the value if B2 is
+             * non-zero.
+             * - const UByte DA: Direction the second character faces after the
+             * split, or address for the value if B3 is non-zero.
+             * - const Short XB: X-coordinate of the third character in the
+             * party after the split, or address for the value if B4 is
+             * non-zero.
+             * - const Short YB: Y-coordinate of the third character in the
+             * party after the split, or address for the value if B5 is
+             * non-zero.
+             * - const UByte DB: Direction the third character faces after the
+             * split, or address for the value if B6 is non-zero.
+             * - const UByte S: Speed that the characters split.
+             *
+             * Causes the common 'split effect' whereby the second and third
+             * characters in the current party 'come out' from the party
+             * leader. That is, they become visible in the field, starting
+             * from the center of the party leader, and move out to the
+             * coordinates specified in the argument list. This is commonly
+             * used when the other characters in the current party have an
+             * action or dialog to perform and must be individually visible in
+             * the field. As well as specifying final coordinates for the two
+             * other party characters, the directions each character faces
+             * after the split are specified as a byte, using the common
+             * direction values found throughout the game. Speed is also given
+             * and is used to specify the rate at which the characters leave
+             * the party leader, using a scale from 1 (almost instant) to FF
+             * (extremely slow walk); this must be non-zero. In contrast to
+             * most MOVE related op codes, the speed is this setting is
+             * actually the total number of frames required. Depending on the
+             * distance from the player character and the number of frames
+             * required, the entity plays a run or walk animation. Also, all
+             * characters take the same time irrespective of distance.
+             *
+             * @param codegen[in|out] Code generator to append lines.
+             */
+            void ProcessSPLIT(CodeGenerator* code_gen);
+            void ProcessTLKON(CodeGenerator* code_gen, const std::string& entity);
+            void ProcessPC(CodeGenerator* code_gen, const std::string& entity);
+            void ProcessCHAR(CodeGenerator* code_gen, const std::string& entity);
+            void ProcessDFANM(CodeGenerator* code_gen, const std::string& entity, int char_id);
+            void ProcessANIME1(CodeGenerator* code_gen, const std::string& entity, int char_id);
+            void ProcessVISI(CodeGenerator* code_gen, const std::string& entity);
+            void ProcessXYZI(CodeGenerator* code_gen, const std::string& entity);
+            void ProcessMOVE(CodeGenerator* code_gen, const std::string& entity);
+            void ProcessMSPED(CodeGenerator* code_gen, const std::string& entity);
+            void ProcessDIR(CodeGenerator* code_gen, const std::string& entity);
+            void ProcessTURNGEN(CodeGenerator* code_gen, const std::string& entity);
+            void ProcessGETAI(CodeGenerator* code_gen, const FieldEngine& engine);
+            void ProcessANIM_2(CodeGenerator* code_gen, const std::string& entity, int char_id);
+            void ProcessCANIM2(CodeGenerator* code_gen, const std::string& entity, int char_id);
+            void ProcessCANM_2(CodeGenerator* code_gen, const std::string& entity, int char_id);
+            void ProcessCC(CodeGenerator* code_gen, const FieldEngine& engine);
 
 
-        /**
-         * Processes a SPLIT opcode.
-         *
-         * Opcode: 0x09
-         * Short name: SPLIT
-         * Long name: Party Field Split
-         *
-         * Memory layout (15 bytes)
-         * |0x20|B1/B2|B3/B4|B5/B6|XA|XA|YA|YA|DA|XB|XB|YB|YB|DB|S|
-         *
-         * Arguments
-         * - const Bit[4] B1: Bank for XA, or zero if XA is specified as a
-         * literal value.
-         * - const Bit[4] B2: Bank for YA, or zero if YA is specified as a
-         * literal value.
-         * - const Bit[4] B3: Bank for DA, or zero if DA is specified as a
-         * literal value.
-         * - const Bit[4] B4: Bank for XB, or zero if XB is specified as a
-         * literal value.
-         * - const Bit[4] B5: Bank for YB, or zero if YB is specified as a
-         * literal value.
-         * - const Bit[4] B6: Bank for DB, or zero if DB is specified as a
-         * literal value.
-         * - const Short XA: X-coordinate of the second character in the party
-         * after the split, or address for the value if B1 is non-zero.
-         * - const Short YA: Y-coordinate of the second character in the party
-         * after the split, or address for the value if B2 is non-zero.
-         * - const UByte DA: Direction the second character faces after the
-         * split, or address for the value if B3 is non-zero.
-         * - const Short XB: X-coordinate of the third character in the party
-         * after the split, or address for the value if B4 is non-zero.
-         * - const Short YB: Y-coordinate of the third character in the party
-         * after the split, or address for the value if B5 is non-zero.
-         * - const UByte DB: Direction the third character faces after the
-         * split, or address for the value if B6 is non-zero.
-         * - const UByte S: Speed that the characters split.
-         *
-         * Causes the common 'split effect' whereby the second and third
-         * characters in the current party 'come out' from the party leader.
-         * That is, they become visible in the field, starting from the center
-         * of the party leader, and move out to the coordinates specified in
-         * the argument list. This is commonly used when the other characters
-         * in the current party have an action or dialog to perform and must
-         * be individually visible in the field. As well as specifying final
-         * coordinates for the two other party characters, the directions each
-         * character faces after the split are specified as a byte, using the
-         * common direction values found throughout the game. Speed is also
-         * given and is used to specify the rate at which the characters leave
-         * the party leader, using a scale from 1 (almost instant) to FF
-         * (extremely slow walk); this must be non-zero. In contrast to most
-         * MOVE related op codes, the speed is this setting is actually the
-         * total number of frames required. Depending on the distance from the
-         * player character and the number of frames required, the entity
-         * plays a run or walk animation. Also, all * characters take the same
-         * time irrespective of distance.
-         *
-         * @param codegen[in|out] Code generator. Output lines are appended.
-         */
-        void ProcessSPLIT(CodeGenerator* code_gen);
-        void ProcessTLKON(CodeGenerator* code_gen, const std::string& entity);
-        void ProcessPC(CodeGenerator* code_gen, const std::string& entity);
-        void ProcessCHAR(CodeGenerator* code_gen, const std::string& entity);
-        void ProcessDFANM(CodeGenerator* code_gen, const std::string& entity, int char_id);
-        void ProcessANIME1(CodeGenerator* code_gen, const std::string& entity, int char_id);
-        void ProcessVISI(CodeGenerator* code_gen, const std::string& entity);
-        void ProcessXYZI(CodeGenerator* code_gen, const std::string& entity);
-        void ProcessMOVE(CodeGenerator* code_gen, const std::string& entity);
-        void ProcessMSPED(CodeGenerator* code_gen, const std::string& entity);
-        void ProcessDIR(CodeGenerator* code_gen, const std::string& entity);
-        void ProcessTURNGEN(CodeGenerator* code_gen, const std::string& entity);
-        void ProcessGETAI(CodeGenerator* code_gen, const FieldEngine& engine);
-        void ProcessANIM_2(CodeGenerator* code_gen, const std::string& entity, int char_id);
-        void ProcessCANIM2(CodeGenerator* code_gen, const std::string& entity, int char_id);
-        void ProcessCANM_2(CodeGenerator* code_gen, const std::string& entity, int char_id);
-        void ProcessCC(CodeGenerator* code_gen, const FieldEngine& engine);
+            /**
+             * Processes a JUMP opcode.
+             *
+             * Opcode: 0xC0
+             * Short name: JUMP
+             * Long name: Jump
+             *
+             * Memory layout (7 bytes)
+             * |0xC2|B1/B2|B3/B4|X|Y|I|Steps|
+             *
+             * Arguments
+             * - const Bit[4] B1: Bank to retrieve X-coordinate, or zero if
+             * specifying X as a literal value.
+             * - const Bit[4] B2: Bank to retrieve Y-coordinate, or zero if
+             * specifying Y as a literal value.
+             * - const Bit[4] B3: Bank to retrieve triangle ID, or zero if
+             * specifying Z as a literal value.
+             * - const Bit[4] B4: Bank to retrieve jump height, or zero if
+             * specifying H as a literal value.
+             * - const Short X: X-coordinate of the target to jump to, or
+             * lower byte specifying address if B1 is non-zero.
+             * - const Short Y: Y-coordinate of the target to jump to, or
+             * lower byte specifying address if B2 is non-zero.
+             * - const Short I: Triangle ID of the target to jump to, or
+             * lower byte specifying address if B3 is non-zero.
+             * - const UShort Steps: Steps in jump. Must be non-zero if a
+             * literal value. Alternatively, lower byte specifies address if
+             * B4 is non-zero.
+             *
+             * Causes the character to jump to the specified point and
+             * triangle ID, with the jump curve peaking at a height which is
+             * increased by using a larger value for the H argument. In
+             * addition, the larger the number, the longer the jump will take
+             * to complete. A "normal" value is around 0x15, 0x01 is fast and
+             * instantaneous; the argument must not be zero or the game will
+             * crash. Whilst this is an unsigned two-byte number, a large
+             * value (beyond around 0x60) will not only cause a vast jump
+             * height, but also cause the screen to scroll erratically (the
+             * larger the number, the more erratic).
+             * Main update function go through all entity with JUMP state and
+             * if stage is 0 it calculates final Z point according to triangle
+             * id. It sets current coords as start coords. The main thing this
+             * function does is set B coefficient for later calculation. It
+             * defines as follows:
+             *   B = (Z_final - Z_start) / steps - steps * 1.45;
+             * Then it set current step to 0 and stage to 1. On next update
+             * other part of function works. It's calculate real position.
+             * First it increment current step number. Then it calculate X and
+             * Y. They change linear so nothing interesting here. The Z
+             * calculation is as follows:
+             *   Z_current = - step^2 * 1.45 + step * B + Z_start;
+             * If current substep equal number of steps then we set current
+             * triangle to final triangle and set stage to 2. Which finalizes
+             * the routine on next opcode call. Neither animation nor sound is
+             * specified in this opcode. An animation is played by using an
+             * animation opcode such as DFANM, and a SOUND played, before the
+             * jump.
+             *
+             * @param codegen[in|out] Code generator to append lines.
+             * @param entity[in] The name of the entity.
+             */
+            void ProcessJUMP(CodeGenerator* code_gen, const std::string& entity);
 
 
-        /**
-         * Processes a JUMP opcode.
-         *
-         * Opcode: 0xC0
-         * Short name: JUMP
-         * Long name: Jump
-         *
-         * Memory layout (7 bytes)
-         * |0xC2|B1/B2|B3/B4|X|Y|I|Steps|
-         *
-         * Arguments
-         * - const Bit[4] B1: Bank to retrieve X-coordinate, or zero if
-         * specifying X as a literal value.
-         * - const Bit[4] B2: Bank to retrieve Y-coordinate, or zero if
-         * specifying Y as a literal value.
-         * - const Bit[4] B3: Bank to retrieve triangle ID, or zero if
-         * specifying Z as a literal value.
-         * - const Bit[4] B4: Bank to retrieve jump height, or zero if
-         * specifying H as a literal value.
-         * - const Short X: X-coordinate of the target to jump to, or lower
-         * byte specifying address if B1 is non-zero.
-         * - const Short Y: Y-coordinate of the target to jump to, or lower
-         * byte specifying address if B2 is non-zero.
-         * - const Short I: Triangle ID of the target to jump to, or lower
-         * byte specifying address if B3 is non-zero.
-         * - const UShort Steps: Steps in jump. Must be non-zero if a literal
-         * value. Alternatively, lower byte specifies address if B4 is
-         * non-zero.
-         *
-         * Causes the character to jump to the specified point and triangle
-         * ID, with the jump curve peaking at a height which is increased by
-         * using a larger value for the H argument. In addition, the larger
-         * the number, the longer the jump will take to complete. A "normal"
-         * value is around 0x15, 0x01 is fast and instantaneous; the argument
-         * must not be zero or the game will crash. Whilst this is an unsigned
-         * two-byte number, a large value (beyond around 0x60) will not only
-         * cause a vast jump height, but also cause the screen to scroll
-         * erratically (the larger the number, the more erratic). Main update
-         * function go through all entity with JUMP state and if stage is 0 it
-         * calculates final Z point according to triangle id. It sets current
-         * coords as start coords. The main thing this function does is set B
-         * coefficient for later calculation. It defines as follows:
-         *   B = (Z_final - Z_start) / steps - steps * 1.45;
-         * Then it set current step to 0 and stage to 1. On next update other
-         * part of function works. It's calculate real position. First it
-         * increment current step number. Then it calculate X and Y. They
-         * change linear so nothing interesting here. The Z calculation is as
-         * follows:
-         *   Z_current = - step^2 * 1.45 + step * B + Z_start;
-         * If current substep equal number of steps then we set current
-         * triangle to final triangle and set stage to 2. Which finalizes the
-         * routine on next opcode call. Neither animation nor sound is
-         * specified in this opcode. An animation is played by using an
-         * animation opcode such as DFANM, and a SOUND played, before the
-         * jump.
-         *
-         * @param codegen[in|out] Code generator. Output lines are appended.
-         * @param entity[in] The name of the entity.
-         */
-        void ProcessJUMP(CodeGenerator* code_gen, const std::string& entity);
+            /**
+             * Processes a AXYZI opcode
+             *
+             * Opcode: 0xC1
+             * Short name: AXYZI
+             * Long name: Entity Get Position
+             *
+             * Memory layout (8 bytes)
+             * |0xC1|B1/B2|B3/B4|A|X|Y|Z|I|
+             *
+             * Arguments
+             * - const Bit[4] B1: Bank to store X.
+             * - const Bit[4] B2: Bank to store Y.
+             * - const Bit[4] B3: Bank to store Z.
+             * - const Bit[4] B4: Bank to store I.
+             * - const UByte A: Entity ID whose field object will have its
+             * position retrieved from.
+             * - const UByte X: Address to store the X-coordinate.
+             * - const UByte Y: Address to store the Y-coordinate.
+             * - const UByte Z: Address to store the Z-coordinate.
+             * - const UByte I: Address to store the ID of the walkmesh
+             * triangle the object is standing on.
+             *
+             * Retrieves the coordinates of the field object that the entity,
+             * whose ID specified in A, is associated with. This opcode uses
+             * an entity ID, not a field object offset; as such, if an entity
+             * ID is given that does not have a field object, this opcode will
+             * store zero in each of the four address specified.
+             *
+             * @param codegen[in|out] Code generator to append lines.
+             */
+            void ProcessAXYZI(CodeGenerator* code_gen);
 
 
-        /**
-         * Processes a AXYZI opcode
-         *
-         * Opcode: 0xC1
-         * Short name: AXYZI
-         * Long name: Entity Get Position
-         *
-         * Memory layout (8 bytes)
-         * |0xC1|B1/B2|B3/B4|A|X|Y|Z|I|
-         *
-         * Arguments
-         * - const Bit[4] B1: Bank to store X.
-         * - const Bit[4] B2: Bank to store Y.
-         * - const Bit[4] B3: Bank to store Z.
-         * - const Bit[4] B4: Bank to store I.
-         * - const UByte A: Entity ID whose field object will have its
-         * position retrieved from.
-         * - const UByte X: Address to store the X-coordinate.
-         * - const UByte Y: Address to store the Y-coordinate.
-         * - const UByte Z: Address to store the Z-coordinate.
-         * - const UByte I: Address to store the ID of the walkmesh triangle
-         * the object is standing on.
-         *
-         * Retrieves the coordinates of the field object that the entity,
-         * whose ID specified in A, is associated with. This opcode uses an
-         * entity ID, not a field object offset; as such, if an entity ID is
-         * given that does not have a field object, this opcode will store
-         * zero in each of the four address specified.
-         *
-         * @param codegen[in|out] Code generator. Output lines are appended.
-         */
-        void ProcessAXYZI(CodeGenerator* code_gen);
+            /**
+             * Processes a LADER opcode.
+             *
+             * Opcode: 0xC2
+             * Short name: LADER
+             * Long name: Ladder
+             *
+             * Memory layout (15 bytes)
+             * |0xC2|B1/B2|B3/B4|X|X|Y|Y|Z|Z|I|I|K|A|D|S|
+             *
+             * Arguments
+             * - const Bit[4] B1: Bank to retrieve X-coordinate, or zero if X
+             * is specified as a literal value.
+             * - const Bit[4] B2: Bank to retrieve Y-coordinate, or zero if Y
+             * is specified as a literal value.
+             * - const Bit[4] B3: Bank to retrieve Z-coordinate, or zero if Z
+             * is specified as a literal value.
+             * - const Bit[4] B4: Bank to retrieve ID, or zero if I is
+             * specified as a literal value.
+             * - const Short X: X-coordinate of the end of the ladder, or
+             * address to find X-coordinate if B1 is non-zero.
+             * - const Short Y: Y-coordinate of the end of the ladder, or
+             * address to find Y-coordinate if B2 is non-zero.
+             * - const Short Z: Z-coordinate of the end of the ladder, or
+             * address to find Z-coordinate if B3 is non-zero.
+             * - const UShort I: ID of the walkmesh triangle found at the end
+             * of the ladder, or address to find ID if B4 is non-zero.
+             * - const UByte K: The keys used to move the character on the
+             * ladder.
+             * - const UByte A: Animation ID for the field object's movement
+             * animation.
+             * - const UByte D: Direction the character faces when climbing
+             * the ladder.
+             * - const UByte S: Speed of the animation whilst climbing the
+             * ladder.
+             *
+             * Causes the character to climb a ladder; that is, switching from
+             * standard walkmesh movement, to climbing along a line connecting
+             * two points on the walkmesh. If B1, B2, B3 or B4 is non-zero,
+             * then the value for that particular component is taken from
+             * memory using the corresponding bank and address specified,
+             * rather than as a literal value. Both retrieved values and
+             * literals can be used for different components. If using X, Y, Z
+             * or I as addresses, the lower byte should hold the address
+             * whilst the higher byte should be zero. The coordinates specify
+             * the end-point of the ladder; the current position of the
+             * character is used as the start point. The ID of the walkmesh
+             * triangle must be specified; this is the triangle the character
+             * will step onto after reaching the end point of the ladder. The
+             * K value specifies the keys used to move the character across
+             * the ladder; keys outside the range found in the table will
+             * cause unpredictable behaviour. The animation ID specifies an
+             * offset into the field object's animation list; this animation
+             * is played at the speed specified by S whilst the character
+             * climbs. Finally, the D argument is a direction value in the
+             * game's standard direction format, which orients the character
+             * on the ladder. This opcode is used as part of the character's
+             * entity, rather than in a seperate entity, as with a LINE. A
+             * LINE is used to set the start point of the ladder on the
+             * walkmesh. When this LINE is crossed by the player, a script in
+             * the LINE then uses a PREQ (or one of its variants), calling the
+             * script in the party leader that defines the LADER, causing the
+             * character to switch to 'climbing mode'. To set up a two-way
+             * ladder, two LINEs are used at either end, with different values
+             * for the LADER arguments, such as differing end points. If this
+             * opcode is used as part of a non-playable character entity, the
+             * NPC object will automatically climb from the start to the end
+             * point without need for player interaction.
+             *
+             * @param codegen[in|out] Code generator to append lines.
+             * @param entity[in] The name of the entity.
+             */
+            void ProcessLADER(CodeGenerator* code_gen, const std::string& entity);
 
 
-        /**
-         * Processes a LADER opcode.
-         *
-         * Opcode: 0xC2
-         * Short name: LADER
-         * Long name: Ladder
-         *
-         * Memory layout (15 bytes)
-         * |0xC2|B1/B2|B3/B4|X|X|Y|Y|Z|Z|I|I|K|A|D|S|
-         *
-         * Arguments
-         * - const Bit[4] B1: Bank to retrieve X-coordinate, or zero if X is
-         * specified as a literal value.
-         * - const Bit[4] B2: Bank to retrieve Y-coordinate, or zero if Y is
-         * specified as a literal value.
-         * - const Bit[4] B3: Bank to retrieve Z-coordinate, or zero if Z is
-         * specified as a literal value.
-         * - const Bit[4] B4: Bank to retrieve ID, or zero if I is specified
-         * as a literal value.
-         * - const Short X: X-coordinate of the end of the ladder, or address
-         * to find X-coordinate if B1 is non-zero.
-         * - const Short Y: Y-coordinate of the end of the ladder, or address
-         * to find Y-coordinate if B2 is non-zero.
-         * - const Short Z: Z-coordinate of the end of the ladder, or address
-         * to find Z-coordinate if B3 is non-zero.
-         * - const UShort I: ID of the walkmesh triangle found at the end of
-         * the ladder, or address to find ID if B4 is non-zero.
-         * - const UByte K: The keys used to move the character on the ladder.
-         * - const UByte A: Animation ID for the field object's movement
-         * animation.
-         * - const UByte D: Direction the character faces when climbing the
-         * ladder.
-         * - const UByte S: Speed of the animation whilst climbing the ladder.
-         *
-         * Causes the character to climb a ladder; that is, switching from
-         * standard walkmesh movement, to climbing along a line connecting two
-         * points on the walkmesh. If B1, B2, B3 or B4 is non-zero, then the
-         * value for that particular component is taken from memory using the
-         * corresponding bank and address specified, rather than as a literal
-         * value. Both retrieved values and literals can be used for different
-         * components. If using X, Y, Z or I as addresses, the lower byte
-         * should hold the address whilst the higher byte should be zero. The
-         * coordinates specify the end-point of the ladder; the current
-         * position of the character is used as the start point. The ID of the
-         * walkmesh triangle must be specified; this is the triangle the
-         * character will step onto after reaching the end point of the
-         * ladder. The K value specifies the keys used to move the character
-         * across the ladder; keys outside the range found in the table will
-         * cause unpredictable behavior. The animation ID specifies an offset
-         * into the field object's animation list; this animation is played at
-         * the speed specified by S whilst the character climbs. Finally, the
-         * D argument is a direction value in the game's standard direction
-         * format, which orients the character on the ladder. This opcode is
-         * used as part of the character's entity, rather than in a separate
-         * entity, as with a LINE. A LINE is used to set the start point of
-         * the ladder on the walkmesh. When this LINE is crossed by the
-         * player, a script in the LINE then uses a PREQ (or one of its
-         * variants), calling the script in the party leader that defines the
-         * LADER, causing the character to switch to 'climbing mode'. To set
-         * up a two-way ladder, two LINEs are used at either end, with
-         * different values for the LADER arguments, such as differing end
-         * points. If this opcode is used as part of a non-playable character
-         * entity, the NPC object will automatically climb from the start to
-         * the end point without need for player interaction.
-         *
-         * @param codegen[in|out] Code generator. Output lines are appended.
-         * @param entity[in] The name of the entity.
-         */
-        void ProcessLADER(CodeGenerator* code_gen, const std::string& entity);
+            void ProcessSOLID(CodeGenerator* code_gen, const std::string& entity);
 
 
-        void ProcessSOLID(CodeGenerator* code_gen, const std::string& entity);
+            /**
+             * Processes an OFST opcode.
+             *
+             * Opcode: 0xC3
+             * Short name: OFST
+             * Long name: Offset Object
+             *
+             * Memory layout (8 bytes)
+             * |0xC3|B1/B2|B3/B4|T|X|Y|Z|S|
+             *
+             * Arguments:
+             * - const Bit[4] B1: Bank to retrieve X offset, or zero if X is
+             * specified as a literal.
+             * - const Bit[4] B2: Bank to retrieve Y offset, or zero if Y is
+             * specified as a literal.
+             * - const Bit[4] B3: Bank to retrieve Z offset, or zero if Z is
+             * specified as a literal.
+             * - const Bit[4] B4: Bank to retrieve speed, or zero if S is
+             * specified as a literal.
+             * - const UByte T: Type of movement.
+             * - const Short X: X offset amount, relative to current position,
+             * or address to find X offset, if B1 is non-zero.
+             * - const Short Y: Y offset amount, relative to current position,
+             * or address to find Y offset, if B2 is non-zero.
+             * - const Short Z: Z offset amount, relative to current position,
+             * or address to find Z offset, if B3 is non-zero.
+             * - const UShort S: Speed of the offset movement, if type is
+             * non-zero, or address to find speed, if B4 is non-zero.
+             *
+             * Offsets the field object, belonging to the entity whose script
+             * this opcode resides in, by a certain amount. After being
+             * offset, the character continues to be constrained in movement
+             * as defined by the walkmesh's shape, but at a certain distance
+             * away from the normal walkmesh position. Other field objects are
+             * unaffected, and their position or movements are maintained on
+             * the walkmesh's original position. If B1, B2, B3 or B4 is
+             * non-zero, then the value for that particular component is taken
+             * from memory using the corresponding bank and address specified,
+             * rather than as a literal value. Both retrieved values and
+             * literals can be used for different components. If using T, X, Y
+             * or S as addresses, the lower byte should hold the address
+             * whilst the higher byte should be zero. The amount to offset is
+             * specified relative to the current position. If Type is
+             * specified, the object moves gradually from its current point to
+             * the offset position; this can be used to simulate movements
+             * such as elevators. Any type outside the range in the table will
+             * cause the offset not to occur. If the object is set to move
+             * gradually, then the speed of offset can be set; the greater the
+             * number, the slower the object moves to its target offset.
+             * Script execution may also be halted until the gradual offset
+             * has been completed. For this, see OFSTW.
+             *
+             * @param codegen[in|out] Code generator to append lines.
+             * @param entity[in] The entity name.
+             */
+            void ProcessOFST(CodeGenerator* codegen, const std::string& entity);
+    };
 
 
-        /**
-         * Processes an OFST opcode.
-         *
-         * Opcode: 0xC3
-         * Short name: OFST
-         * Long name: Offset Object
-         *
-         * Memory layout (8 bytes)
-         * |0xC3|B1/B2|B3/B4|T|X|Y|Z|S|
-         *
-         * Arguments:
-         * - const Bit[4] B1: Bank to retrieve X offset, or zero if X is
-         * specified as a literal.
-         * - const Bit[4] B2: Bank to retrieve Y offset, or zero if Y is
-         * specified as a literal.
-         * - const Bit[4] B3: Bank to retrieve Z offset, or zero if Z is
-         * specified as a literal.
-         * - const Bit[4] B4: Bank to retrieve speed, or zero if S is
-         * specified as a literal.
-         * - const UByte T: Type of movement.
-         * - const Short X: X offset amount, relative to current position, or
-         * address to find X offset, if B1 is non-zero.
-         * - const Short Y: Y offset amount, relative to current position, or
-         * address to find Y offset, if B2 is non-zero.
-         * - const Short Z: Z offset amount, relative to current position, or
-         * address to find Z offset, if B3 is non-zero.
-         * - const UShort S: Speed of the offset movement, if type is
-         * non-zero, or address to find speed, if B4 is non-zero.
-         *
-         * Offsets the field object, belonging to the entity whose script this
-         * opcode resides in, by a certain amount. After being offset, the
-         * character continues to be constrained in movement as defined by the
-         * walkmesh's shape, but at a certain distance away from the normal
-         * walkmesh position. Other field objects are unaffected, and their
-         * position or movements are maintained on the walkmesh's original
-         * position. If B1, B2, B3 or B4 is non-zero, then the value for that
-         * particular component is taken from memory using the corresponding
-         * bank and address specified, rather than as a literal value. Both
-         * retrieved values and literals can be used for different components.
-         * If using T, X, Y or S as addresses, the lower byte should hold the
-         * address whilst the higher byte should be zero. The amount to offset
-         * is specified relative to the current position. If Type is
-         * specified, the object moves gradually from its current point to the
-         * offset position; this can be used to simulate movements such as
-         * elevators. Any type outside the range in the table will cause the
-         * offset not to occur. If the object is set to move gradually, then
-         * the speed of offset can be set; the greater the number, the slower
-         * the object moves to its target offset. Script execution may also be
-         * halted until the gradual offset has been completed. For this, see
-         * OFSTW.
-         *
-         * @param codegen[in|out] Code generator. Output lines are appended.
-         * @param entity[in] The entity name.
-         */
-        void ProcessOFST(CodeGenerator* codegen, const std::string& entity);
-};
+}

+ 98 - 90
V-Gears-Installer/include/decompiler/field/instruction/FieldModuleInstruction.h

@@ -18,100 +18,108 @@
 
 
 #pragma once
 #pragma once
 
 
-#include "decompiler/decompiler_engine.h"
+#include "decompiler/instruction.h"
+#include "decompiler/field/FieldEngine.h"
 
 
-/**
- * A module instruction.
- */
-class FieldModuleInstruction : public KernelCallInstruction{
+namespace FF7{
+
+    /**
+     * A module instruction.
+     */
+    class FieldModuleInstruction : public KernelCallInstruction{
+
+        public:
 
 
-    public:
+            /**
+             * Processes the instruction.
+             *
+             * @param func[in] Function to process.
+             * @param stack[out] Function stack.
+             * @param engine[in] Engine. Unused.
+             * @param code_gen[in] Code generator.
+             */
+            virtual void ProcessInst(
+              Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
 
 
-        /**
-         * Processes the instruction.
-         *
-         * @param func[in] Function to process.
-         * @param stack[out] Function stack.
-         * @param engine[in] Engine. Unused.
-         * @param code_gen[in|out] Code generator.
-         */
-        virtual void ProcessInst(
-          Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
-        ) override;
+        private:
 
 
-    private:
+            /**
+             * Processes a BATTLE opcode.
+             *
+             * Opcode: 0x70
+             * Short name: BATTLE
+             * Long name: Start battle
+             *
+             * Memory layout (4 bytes)
+             * |0x70|B|N|N|
+             *
+             * Arguments
+             * - const UByte B: Bank (16-bit) to retrieve the address of the
+             * battle ID, or zero if it is given as a literal value.
+             * - const UWord N: Battle ID, or address to find ID if B is
+             * non-zero.
+             *
+             * This launches the battle module with whatever battle number is
+             * used in the argument, or the value retrieved from memory
+             * location N if B is non-zero. Battle 1, 2, and 999 (0x03E7) are
+             * debug battles.
+             *
+             * @param codegen[in|out] Code generator to append lines.
+             */
+            void ProcessBATTLE(CodeGenerator* code_gen);
 
 
-        /**
-         * Processes a BATTLE opcode.
-         *
-         * Opcode: 0x70
-         * Short name: BATTLE
-         * Long name: Start battle
-         *
-         * Memory layout (4 bytes)
-         * |0x70|B|N|N|
-         *
-         * Arguments
-         * - const UByte B: Bank (16-bit) to retrieve the address of the
-         * battle ID, or zero if it is given as a literal value.
-         * - const UWord N: Battle ID, or address to find ID if B is non-zero.
-         *
-         * This launches the battle module with whatever battle number is used
-         * in the argument, or the value retrieved from memory location N if B
-         * is non-zero. Battle 1, 2, and 999 (0x03E7) are debug battles.
-         *
-         * @param codegen[in|out] Code generator. Output lines are appended.
-         */
-        void ProcessBATTLE(CodeGenerator* code_gen);
+            /**
+             * Processes a BTLON opcode.
+             *
+             * Opcode: 0x71
+             * Short name: BTLON
+             * Long name: Battle switch
+             *
+             * Memory layout (2 bytes)
+             * |0x71|S|
+             *
+             * Arguments
+             * - const UByte S: Switch battles on/off (0/1, respectively).
+             *
+             * Turns random encounters on or off for this field. Note that if
+             * a field does not have any Encounter Data set in its field file,
+             * battles will not occur regardless of the argument passed with
+             * this opcode.
+             *
+             * @param codegen[in|out] Code generator to append lines.
+             */
+            void ProcessBTLON(CodeGenerator* code_gen);
 
 
-        /**
-         * Processes a BTLON opcode.
-         *
-         * Opcode: 0x71
-         * Short name: BTLON
-         * Long name: Battle switch
-         *
-         * Memory layout (2 bytes)
-         * |0x71|S|
-         *
-         * Arguments
-         * - const UByte S: Switch battles on/off (0/1, respectively).
-         *
-         * Turns random encounters on or off for this field. Note that if a
-         * field does not have any Encounter Data set in its field file,
-         * battles will not occur regardless of the argument passed with this
-         * opcode.
-         *
-         * @param codegen[in|out] Code generator. Output lines are appended.
-         */
-        void ProcessBTLON(CodeGenerator* code_gen);
+            /**
+             * Processes a MAPJUMP opcode.
+             *
+             * Opcode: 0x60
+             * Short name: BTLON
+             * Long name: Change Field
+             *
+             * Memory layout
+             * |0x60|I|I|X|X|Y|Y|Z|Z|D|
+             *
+             * Arguments
+             * - const UShort I: Field ID of the map to jump to.
+             * - const Short X: X-coordinate of the player on the next field.
+             * - const Short Y: Y-coordinate of the player on the next field.
+             * - const Short Z: Z-coordinate of the player on the next field.
+             * - const UByte D: Direction the character will be facing on the
+             * next field, in the standard game format.
+             *
+             * Switches fields to the one indicated by I, and places the
+             * character at the coordinates and direction specified. This is
+             * an alternative to using a gateway, and can complement their
+             * usage as it allows for more than 12 gateways by simulating
+             * their behavior through a LINE which, when crossed, executes a
+             * MAPJUMP.
+             *
+             * @param codegen[in|out] Code generator to append lines.
+             * @param func[in] Function to get the spawn point from.
+             */
+            void ProcessMAPJUMP(CodeGenerator* code_gen, Function& func);
+    };
 
 
-        /**
-         * Processes a MAPJUMP opcode.
-         *
-         * Opcode: 0x60
-         * Short name: BTLON
-         * Long name: Change Field
-         *
-         * Memory layout (10 bytes)
-         * |0x60|I|I|X|X|Y|Y|Z|Z|D|
-         *
-         * Arguments
-         * - const UShort I: Field ID of the map to jump to.
-         * - const Short X: X-coordinate of the player on the next field.
-         * - const Short Y: Y-coordinate of the player on the next field.
-         * - const Short Z: Z-coordinate of the player on the next field.
-         * - const UByte D: Direction the character will be facing on the next
-         * field, in the standard game format.
-         *
-         * Switches fields to the one indicated by I, and places the character
-         * at the coordinates and direction specified. This is an alternative
-         * to using a gateway, and can complement their usage as it allows for
-         * more than 12 gateways by simulating their behavior through a LINE
-         * which, when crossed, executes a MAPJUMP.
-         *
-         * @param codegen[in|out] Code generator. Output lines are appended.
-         * @param func[in] Function. @todo What for?
-         */
-        void ProcessMAPJUMP(CodeGenerator* code_gen, Function& func);
-};
+}

+ 34 - 30
V-Gears-Installer/include/decompiler/field/instruction/FieldNoOperationInstruction.h

@@ -1,5 +1,4 @@
 /*
 /*
- * V-Gears
  * Copyright (C) 2022 V-Gears Team
  * Copyright (C) 2022 V-Gears Team
  *
  *
  * This program is free software: you can redistribute it and/or modify
  * This program is free software: you can redistribute it and/or modify
@@ -18,33 +17,38 @@
 
 
 #pragma once
 #pragma once
 
 
-#include "decompiler/decompiler_engine.h"
+#include "decompiler/instruction.h"
+#include "decompiler/field/FieldEngine.h"
 
 
-/**
- * An instruction that does nothing.
- */
-class FieldNoOperationInstruction : public Instruction{
-
-    public:
-
-        /**
-         * Generates a instruction that does nothing.
-         *
-         * @return The generated instruction.
-         */
-        static InstPtr Create(){return new FieldNoOperationInstruction();}
-
-        /**
-         * Processes the instruction.
-         *
-         * It doesn't do anything.
-         *
-         * @param func[in] Function to process. Unused.
-         * @param stack[out] Function stack. Unused.
-         * @param engine[in] Engine. Unused.
-         * @param code_gen[in|out] Code generator. Unused.
-         */
-        virtual void ProcessInst(
-          Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
-        ) override;
-};
+namespace FF7{
+
+    /**
+     * An instruction that does nothing.
+     */
+    class FieldNoOperationInstruction : public Instruction{
+
+        public:
+
+            /**
+             * Generates a instruction that does nothing.
+             *
+             * @return The generated instruction.
+             */
+            static InstPtr Create(){return new FieldNoOperationInstruction();}
+
+            /**
+             * Processes the instruction.
+             *
+             * It doesn't do anything.
+             *
+             * @param func[in] Function to process. Unused.
+             * @param stack[out] Function stack. Unused.
+             * @param engine[in] Engine. Unused.
+             * @param codegen[in|out] Code generator to append lines.
+             */
+            virtual void ProcessInst(
+              Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
+    };
+
+}

+ 30 - 26
V-Gears-Installer/include/decompiler/field/instruction/FieldPartyInstruction.h

@@ -1,5 +1,4 @@
 /*
 /*
- * V-Gears
  * Copyright (C) 2022 V-Gears Team
  * Copyright (C) 2022 V-Gears Team
  *
  *
  * This program is free software: you can redistribute it and/or modify
  * This program is free software: you can redistribute it and/or modify
@@ -18,29 +17,34 @@
 
 
 #pragma once
 #pragma once
 
 
-#include "decompiler/decompiler_engine.h"
+#include "decompiler/instruction.h"
+#include "decompiler/field/FieldEngine.h"
 
 
-/**
- * A party instruction.
- */
-class FieldPartyInstruction : public KernelCallInstruction{
-
-    public:
-
-        /**
-         * Processes the instruction.
-         *
-         * @param func[in] Function to process.
-         * @param stack[out] Function stack.
-         * @param engine[in] Engine. Unused
-         * @param code_gen[in|out] Code generator.
-         */
-        virtual void ProcessInst(
-          Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
-        ) override;
-
-    private:
-
-        void ProcessSTITM(CodeGenerator* code_gen);
-        void ProcessPRTYE(CodeGenerator* code_gen);
-};
+namespace FF7{
+
+    /**
+     * A party instruction
+     */
+    class FieldPartyInstruction : public KernelCallInstruction{
+
+        public:
+
+            /**
+             * Processes the instruction.
+             *
+             * @param func[in] Function to process.
+             * @param stack[out] Function stack.
+             * @param engine[in] The engine. Unused
+             * @param codegen[in|out] Code generator to append lines.
+             */
+            virtual void ProcessInst(
+              Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
+
+        private:
+
+            void ProcessSTITM(CodeGenerator* code_gen);
+            void ProcessPRTYE(CodeGenerator* code_gen);
+    };
+
+}

+ 23 - 19
V-Gears-Installer/include/decompiler/field/instruction/FieldUncategorizedInstruction.h

@@ -1,5 +1,4 @@
 /*
 /*
- * V-Gears
  * Copyright (C) 2022 V-Gears Team
  * Copyright (C) 2022 V-Gears Team
  *
  *
  * This program is free software: you can redistribute it and/or modify
  * This program is free software: you can redistribute it and/or modify
@@ -18,24 +17,29 @@
 
 
 #pragma once
 #pragma once
 
 
-#include "decompiler/decompiler_engine.h"
+#include "decompiler/instruction.h"
+#include "decompiler/field/FieldEngine.h"
 
 
-/**
- * An instructions that doesn't fall in any other category.
- */
-class FieldUncategorizedInstruction : public KernelCallInstruction{
+namespace FF7{
+
+    /**
+     * An instructions that doesn't fall in any other category.
+     */
+    class FieldUncategorizedInstruction : public KernelCallInstruction{
+
+        public:
 
 
-    public:
+            /**
+             * Processes the instruction.
+             *
+             * @param func[in] Function to process.
+             * @param stack[out] Function stack.
+             * @param engine[in] Engine. Unused.
+             * @param codegen[in|out] Code generator to append lines.
+             */
+            virtual void ProcessInst(
+              Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
+    };
 
 
-        /**
-         * Processes the instruction.
-         *
-         * @param func[in] Function to process.
-         * @param stack[out] Function stack.
-         * @param engine[in] Engine.
-         * @param code_gen[in|out] Code generator.
-         */
-        virtual void ProcessInst(
-          Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
-        ) override;
-};
+}

+ 57 - 54
V-Gears-Installer/include/decompiler/field/instruction/FieldUncondJumpInstruction.h

@@ -18,67 +18,70 @@
 
 
 #pragma once
 #pragma once
 
 
-#include "decompiler/decompiler_engine.h"
+#include "decompiler/instruction.h"
 
 
-/**
- * An unconditional map jump instruction.
- */
-class FieldUncondJumpInstruction : public UncondJumpInstruction{
+namespace FF7{
+
+    /**
+     * An unconditional map jump instruction.
+     */
+    class FieldUncondJumpInstruction : public UncondJumpInstruction{
 
 
-    public:
+        public:
 
 
-        /**
-         * Constructor.
-         */
-        FieldUncondJumpInstruction();
+            /**
+             * Constructor.
+             */
+            FieldUncondJumpInstruction();
 
 
-        /**
-         * Indicates if the instruction is a function call.
-         *
-         * @return true if the instruction is a function call, false if not.
-         */
-        virtual bool IsFuncCall() const;
+            /**
+             * Indicates if the instruction is a function call.
+             *
+             * @return true if the instruction is a function call, false if not.
+             */
+            virtual bool IsFuncCall() const;
 
 
-        /**
-         * Indicates if the instruction is an unconditional jump.
-         *
-         * @return true if the instruction is an unconditional jump, false if
-         * it's not.
-         */
-        virtual bool IsUncondJump() const;
+            /**
+             * Indicates if the instruction is an unconditional jump.
+             *
+             * @return true if the instruction is an unconditional jump, false
+             * if it's not.
+             */
+            virtual bool IsUncondJump() const;
 
 
-        /**
-         * Retrieves the destination address of the jump.
-         *
-         * @return The offset (number of bytes) to jump from the beginning of
-         * the instruction.
-         */
-        virtual uint32 GetDestAddress() const;
+            /**
+             * Retrieves the destination address of the jump.
+             *
+             * @return The offset (number of bytes) to jump from the beginning
+             * of the instruction.
+             */
+            virtual uint32 GetDestAddress() const;
 
 
-        /**
-         * Processes the instruction.
-         *
-         * @param func[in] Function to process. Unused.
-         * @param stack[out] Function stack.
-         * @param engine[in] Engine. Unused.
-         * @param code_gen[in|out] Code generator.
-         */
-        virtual void ProcessInst(
-          Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
-        ) override;
+            /**
+             * Processes the instruction.
+             *
+             * @param func[in] Function to process.
+             * @param stack[out] Function stack. Unused.
+             * @param engine[in] The engine. Unused
+             * @param codegen[in|out] Code generator to append lines.
+             */
+            virtual void ProcessInst(
+              Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
 
 
-        /**
-         * Prints the instruction
-         *
-         * @param output The stream to print the instruction to.
-         * @todo Understand and document properly.
-         */
-        virtual std::ostream& Print(std::ostream &output) const override;
+            /**
+             * Prints the instruction
+             *
+             * @param[in] output The stream to print the instruction to.
+             * @return The same output.
+             */
+            virtual std::ostream& Print(std::ostream &output) const override;
 
 
-    private:
+        private:
 
 
-        /**
-         * Whether or not this is really a call to a script function.
-         */
-        bool call_;
-};
+            /**
+             * Whether or not this is really a call to a script function.
+             */
+            bool is_func_call_;
+    };
+}

+ 62 - 57
V-Gears-Installer/include/decompiler/field/instruction/FieldWalkmeshInstruction.h

@@ -1,5 +1,4 @@
 /*
 /*
- * V-Gears
  * Copyright (C) 2022 V-Gears Team
  * Copyright (C) 2022 V-Gears Team
  *
  *
  * This program is free software: you can redistribute it and/or modify
  * This program is free software: you can redistribute it and/or modify
@@ -18,65 +17,71 @@
 
 
 #pragma once
 #pragma once
 
 
-#include "decompiler/decompiler_engine.h"
+#include "decompiler/instruction.h"
+#include "decompiler/field/FieldEngine.h"
 
 
-/**
- * A walkmesh instruction.
- */
-class FieldWalkmeshInstruction : public KernelCallInstruction{
+namespace FF7{
+
+    /**
+     * A walkmesh instruction.
+     */
+    class FieldWalkmeshInstruction : public KernelCallInstruction{
+
+        public:
 
 
-    public:
+            /**
+             * Processes the instruction.
+             *
+             * @param func[in] Function to process.
+             * @param stack[out] Function stack.
+             * @param engine[in] Engine. Unused.
+             * @param codegen[in|out] Code generator to append lines.
+             */
+            virtual void ProcessInst(
+              Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
 
 
-        /**
-         * Processes the instruction.
-         *
-         * @param func[in] Function to process.
-         * @param stack[out] Function stack.
-         * @param engine[in] Engine. Unused.
-         * @param code_gen[in|out] Code generator.
-         */
-        virtual void ProcessInst(
-          Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
-        ) override;
+        private:
 
 
-    private:
+            void ProcessUC(CodeGenerator* code_gen);
 
 
-        void ProcessUC(CodeGenerator* code_gen);
+            /**
+             * Processes a LINE opcode.
+             *
+             * Opcode: 0xD0
+             * Short name: LINE
+             * Long name: Line definition
+             *
+             * Memory layout (7 bytes)
+             * |0xD0|XA|YA|ZA|XB|YB|ZB|
+             *
+             * Arguments:
+             * - const Short XA: X-coordinate of the first point of the line.
+             * - const Short YA: Y-coordinate of the first point of the line.
+             * - const Short ZA: Z-coordinate of the first point of the line.
+             * - const Short XB: X-coordinate of the second point of the line.
+             * - const Short YB: Y-coordinate of the second point of the line.
+             * - const Short ZB: Z-coordinate of the second point of the line.
+             *
+             * Defines a line on the walkmesh that, when crossed by a playable
+             * character, causes one of the entity's scripts to be executed.
+             * These are similar to the triggers in Section 8. All the lines
+             * in the current field can be turned on or off by using the LINON
+             * opcode.
+             *
+             * There are generally 6 scripts (other than the init and main) if
+             * the entity is a LINE.
+             * - script index 2 -> S1 - [OK].
+             * - script index 3 -> S2 - Move.
+             * - script index 4 -> S3 - Move.
+             * - script index 5 -> S4 - Go.
+             * - script index 6 -> S5 - Go 1x.
+             * - script index 7 -> S6 - Go away.
+             *
+             * @param codegen[in|out] Code generator to append lines.
+             * @param entity[in] The entity name.
+             */
+            void ProcessLINE(CodeGenerator* code_gen, const std::string& entity);
+    };
 
 
-        /**
-         * Processes a LINE opcode.
-         *
-         * Opcode: 0xD0
-         * Short name: LINE
-         * Long name: Line definition
-         *
-         * Memory layout (7 bytes)
-         * |0xD0|XA|YA|ZA|XB|YB|ZB|
-         *
-         * Arguments:
-         * - const Short XA: X-coordinate of the first point of the line.
-         * - const Short YA: Y-coordinate of the first point of the line.
-         * - const Short ZA: Z-coordinate of the first point of the line.
-         * - const Short XB: X-coordinate of the second point of the line.
-         * - const Short YB: Y-coordinate of the second point of the line.
-         * - const Short ZB: Z-coordinate of the second point of the line.
-         *
-         * Defines a line on the walkmesh that, when crossed by a playable
-         * character, causes one of the entity's scripts to be executed. These
-         * are similar to the triggers in Section 8. All the lines in the
-         * current field can be turned on or off by using the LINON opcode.
-         *
-         * There are generally 6 scripts (other than the init and main) if the
-         * entity is a LINE.
-         * - script index 2 -> S1 - [OK].
-         * - script index 3 -> S2 - Move.
-         * - script index 4 -> S3 - Move.
-         * - script index 5 -> S4 - Go.
-         * - script index 6 -> S5 - Go 1x.
-         * - script index 7 -> S6 - Go away.
-         *
-         * @param codegen[in|out] Code generator. Output lines are appended.
-         * @param entity[in] The entity name.
-         */
-        void ProcessLINE(CodeGenerator* code_gen, const std::string& entity);
-};
+}

+ 33 - 29
V-Gears-Installer/include/decompiler/field/instruction/FieldWindowInstruction.h

@@ -1,5 +1,4 @@
 /*
 /*
- * V-Gears
  * Copyright (C) 2022 V-Gears Team
  * Copyright (C) 2022 V-Gears Team
  *
  *
  * This program is free software: you can redistribute it and/or modify
  * This program is free software: you can redistribute it and/or modify
@@ -18,32 +17,37 @@
 
 
 #pragma once
 #pragma once
 
 
-#include "decompiler/decompiler_engine.h"
+#include "decompiler/instruction.h"
+#include "decompiler/field/FieldEngine.h"
 
 
-/**
- * A window instruction.
- */
-class FieldWindowInstruction : public KernelCallInstruction{
-
-    public:
-
-        /**
-         * Processes the instruction.
-         *
-         * @param func[in] Function to process.
-         * @param stack[out] Function stack.
-         * @param engine[in] Engine.
-         * @param code_gen[in|out] Code generator.
-         */
-        virtual void ProcessInst(
-          Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
-        ) override;
-
-    private:
-
-        void ProcessMESSAGE(CodeGenerator* code_gen, const std::string& script_name);
-        void ProcessMPNAM(CodeGenerator* code_gen);
-        void ProcessMENU2(CodeGenerator* code_gen);
-        void ProcessWINDOW(CodeGenerator* code_gen);
-        void ProcessWCLSE(CodeGenerator* code_gen);
-};
+namespace FF7{
+
+    /**
+     * A window instruction.
+     */
+    class FieldWindowInstruction : public KernelCallInstruction{
+
+        public:
+
+            /**
+             * Processes the instruction.
+             *
+             * @param func[in] Function to process.
+             * @param stack[out] Function stack. Unused.
+             * @param engine[in] Engine.
+             * @param codegen[in|out] Code generator to append lines.
+             */
+            virtual void ProcessInst(
+              Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
+
+        private:
+
+            void ProcessMESSAGE(CodeGenerator* code_gen, const std::string& script_name);
+            void ProcessMPNAM(CodeGenerator* code_gen);
+            void ProcessMENU2(CodeGenerator* code_gen);
+            void ProcessWINDOW(CodeGenerator* code_gen);
+            void ProcessWCLSE(CodeGenerator* code_gen);
+    };
+
+}

+ 7 - 7
V-Gears-Installer/include/decompiler/graph.h

@@ -238,8 +238,8 @@ typedef ElseEnds::iterator ElseEndIterator;
 struct Group : public RefCounted {
 struct Group : public RefCounted {
 public:
 public:
 	GraphVertex _vertex;         ///< Vertex the group belongs to.
 	GraphVertex _vertex;         ///< Vertex the group belongs to.
-	InstIterator _start;    ///< First instruction in the group.
-	InstIterator _end;      ///< Last instruction in the group.
+	InstIterator start_;    ///< First instruction in the group.
+	InstIterator end_;      ///< Last instruction in the group.
 	int _stackLevel;             ///< Level of the stack upon entry.
 	int _stackLevel;             ///< Level of the stack upon entry.
 	GroupType _type;             ///< Type of the group.
 	GroupType _type;             ///< Type of the group.
 	bool _startElse;             ///< Group is start of an else block.
 	bool _startElse;             ///< Group is start of an else block.
@@ -264,8 +264,8 @@ public:
 	 */
 	 */
 	Group(GraphVertex v,InstIterator start, InstIterator end, GroupPtr prev) {
 	Group(GraphVertex v,InstIterator start, InstIterator end, GroupPtr prev) {
 		_vertex = v;
 		_vertex = v;
-		_start = start;
-		_end = end;
+		start_ = start;
+		end_ = end;
 		_stackLevel = -1;
 		_stackLevel = -1;
 		_type = kNormalGroupType;
 		_type = kNormalGroupType;
 		_prev = prev.get();
 		_prev = prev.get();
@@ -310,10 +310,10 @@ public:
 		if (group->_startElse)
 		if (group->_startElse)
 			output << "Start of else\\n";
 			output << "Start of else\\n";
 		for (ElseEndIterator it = group->_endElse.begin(); it != group->_endElse.end(); ++it) {
 		for (ElseEndIterator it = group->_endElse.begin(); it != group->_endElse.end(); ++it) {
-			output << boost::format("End of else at %08x\\n") % (*(*it)->_start)->_address;
+			output << boost::format("End of else at %08x\\n") % (*(*it)->start_)->_address;
 		}
 		}
 		output << "|";
 		output << "|";
-		ConstInstIterator inst = group->_start;
+		ConstInstIterator inst = group->start_;
 		do {
 		do {
 			std::stringstream stream;
 			std::stringstream stream;
 			stream << *inst;
 			stream << *inst;
@@ -334,7 +334,7 @@ public:
 						output << *it;
 						output << *it;
 #endif
 #endif
 			output << "\\n";
 			output << "\\n";
-		} while (inst++ != group->_end);
+		} while (inst++ != group->end_);
 		output << "}";
 		output << "}";
 		return output;
 		return output;
 	}
 	}

+ 0 - 10
V-Gears-Installer/include/decompiler/instruction.h

@@ -81,15 +81,6 @@ public:
 	std::string _codeGenData;       ///< String containing metadata for code generation. See the extended documentation for details.
 	std::string _codeGenData;       ///< String containing metadata for code generation. See the extended documentation for details.
     bool mLabelRequired = false;
     bool mLabelRequired = false;
 
 
-    /**
-     * Writes a comment to the script indicating an unimplemented opcode.
-     *
-     * @param code_gen[in|out] Code generator. The line will be added to it
-     * @param owner[in] The name of the class. Unused.
-     * @param instructions[in] The name of the instruction.
-     */
-    static void WriteTodo(CodeGenerator *code_gen, std::string owner, std::string opcode);
-
 	/**
 	/**
 	 * Operator overload to output an Instruction to a std::ostream.
 	 * Operator overload to output an Instruction to a std::ostream.
 	 *
 	 *
@@ -188,7 +179,6 @@ public:
 	 * @param codeGen Pointer to the CodeGenerator used for code generation.
 	 * @param codeGen Pointer to the CodeGenerator used for code generation.
 	 */
 	 */
 	virtual void ProcessInst(Function& func, ValueStack &stack, Engine *engine, CodeGenerator *codeGen) = 0;
 	virtual void ProcessInst(Function& func, ValueStack &stack, Engine *engine, CodeGenerator *codeGen) = 0;
-
 };
 };
 
 
 /**
 /**

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

@@ -59,8 +59,8 @@ public:
 };
 };
 
 
 #define INC_ADDR this->address_++;
 #define INC_ADDR this->address_++;
-#define ADD_INST(category) this->_insts.push_back(new category());
-#define LAST_INST (this->_insts.back())
+#define ADD_INST(category) this->insts_.push_back(new category());
+#define LAST_INST (this->insts_.back())
 
 
 #define START_OPCODES \
 #define START_OPCODES \
 	this->address_ = this->address_base_; \
 	this->address_ = this->address_base_; \
@@ -97,7 +97,7 @@ public:
 		OPCODE_BODY(name, category, stackChange, params, codeGenData)\
 		OPCODE_BODY(name, category, stackChange, params, codeGenData)\
 		OPCODE_END;
 		OPCODE_END;
 
 
-#define CASE_OPCODE(val, name, category, stackChange, params) \
+#define OPCODE(val, name, category, stackChange, params) \
 	OPCODE_MD(val, name, category, stackChange, params, "")
 	OPCODE_MD(val, name, category, stackChange, params, "")
 
 
 #define START_SUBOPCODE_WITH_PREFIX(val,prefix) \
 #define START_SUBOPCODE_WITH_PREFIX(val,prefix) \

+ 77 - 76
V-Gears-Installer/include/decompiler/sudm.h

@@ -140,103 +140,104 @@ namespace SUDM{
             ){return "";}
             ){return "";}
         };
         };
 
 
+    namespace FF7{
 
 
-
-    namespace Field{
-
-        /**
-         * A line.
-         */
-        struct Line{
+        namespace Field{
 
 
             /**
             /**
-             * Name of the line entity.
+             * A line.
              */
              */
-            std::string name;
+            struct Line{
 
 
-            /**
-             * First point of the line.
-             */
-            std::vector<float> point_a;
+                /**
+                 * Name of the line entity.
+                 */
+                std::string name;
 
 
-            /**
-             * Second point of the line.
-             */
-            std::vector<float> point_b;
-        };
+                /**
+                 * First point of the line.
+                 */
+                std::vector<float> point_a;
 
 
-        /**
-         * An entity.
-         */
-        struct FieldEntity{
+                /**
+                 * Second point of the line.
+                 */
+                std::vector<float> point_b;
+            };
 
 
             /**
             /**
-             * Character identifier of the entity.
+             * An entity.
              */
              */
-            uint char_id;
+            struct FieldEntity{
 
 
-            /**
-             * Index of the entity in the field.
-             */
-            uint index;
+                /**
+                 * Character identifier of the entity.
+                 */
+                uint char_id;
 
 
-            /**
-             * Name of the entity.
-             */
-            std::string name;
-        };
+                /**
+                 * Index of the entity in the field.
+                 */
+                uint index;
 
 
-        /**
-         * The field decompiled script.
-         */
-        struct DecompiledScript{
+                /**
+                 * Name of the entity.
+                 */
+                std::string name;
+            };
 
 
             /**
             /**
-             * The LUA script for the field.
+             * The field decompiled script.
              */
              */
-            std::string luaScript;
+            struct DecompiledScript{
+
+                /**
+                 * The LUA script for the field.
+                 */
+                std::string luaScript;
+
+                /**
+                 * The field entities.
+                 *
+                 * Lines are not included.
+                 */
+                std::vector<FieldEntity> entities;
+
+                /**
+                 * Lines in the field.
+                 */
+                std::vector<Line> lines;
+            };
 
 
             /**
             /**
-             * The field entities.
+             * Retrieves the scale factor of a field.
              *
              *
-             * Lines are not included.
+             * @param script_bytes[in] Vector of raw byte data that makes up
+             * the script.
+             * @return The scale fctor.
              */
              */
-            std::vector<FieldEntity> entities;
+            float ScaleFactor(const std::vector<unsigned char>& script_bytes);
 
 
             /**
             /**
-             * Lines in the field.
-             */
-            std::vector<Line> lines;
-        };
-
-        /**
-         * Retrieves the scale factor of a field.
-         *
-         * @param script_bytes[in] Vector of raw byte data that makes up
-         * the script.
-         * @return The scale fctor.
-         */
-        float ScaleFactor(const std::vector<unsigned char>& script_bytes);
-
-        /**
-         * Decompiles a field script.
-         *
-         * @param script_name[in] Name of the script to be converted,
-         * should match file name.
-         * @param script_bytes[in] Vector of raw byte data that makes up
-         * the script.
-         * @param formatter[in] Formatter used to rename variables, drop
-         * functions...
-         * @param text_after[in] Raw text that is added at to the end of
-         * the decompiled output.
-         * @param text_before[in] Raw text that is added at to the start of
-         * the decompiled output.
-         * @return A string with the decompiled script.
-         * @throws InternalDecompilerError on failure.
-         */
-        DecompiledScript Decompile(
-          std::string script_name, const std::vector<unsigned char>& script_bytes,
-          IScriptFormatter& formatter, std::string text_after = "", std::string text_before = ""
-        );
+             * Decompiles a field script.
+             *
+             * @param script_name[in] Name of the script to be converted,
+             * should match file name.
+             * @param script_bytes[in] Vector of raw byte data that makes up
+             * the script.
+             * @param formatter[in] Formatter used to rename variables, drop
+             * functions...
+             * @param text_after[in] Raw text that is added at to the end of
+             * the decompiled output.
+             * @param text_before[in] Raw text that is added at to the start of
+             * the decompiled output.
+             * @return A string with the decompiled script.
+             * @throws InternalDecompilerError on failure.
+             */
+            DecompiledScript Decompile(
+              std::string script_name, const std::vector<unsigned char>& script_bytes,
+              IScriptFormatter& formatter, std::string text_after = "", std::string text_before = ""
+            );
+        }
     }
     }
 }
 }

+ 2 - 2
V-Gears-Installer/include/decompiler/test/disassembler/pasc.cpp

@@ -24,7 +24,7 @@
 PasCDisassembler::PasCDisassembler(InstVec &insts) : ::SimpleDisassembler(insts) {
 PasCDisassembler::PasCDisassembler(InstVec &insts) : ::SimpleDisassembler(insts) {
 }
 }
 
 
-void PasCDisassembler::DoDisassemble(){
+void PasCDisassembler::doDisassemble(){
 	START_OPCODES;
 	START_OPCODES;
 		//Basic machine operations
 		//Basic machine operations
 		OPCODE(0x00, "PUSH", PasCFakeInstruction, 0, "i");
 		OPCODE(0x00, "PUSH", PasCFakeInstruction, 0, "i");
@@ -136,7 +136,7 @@ ValuePtr PasCDisassembler::readParameter(InstPtr inst, std::string type)
     if (type == "a")
     if (type == "a")
     {
     {
         retval = new AddressValue(stream_->ReadU32());
         retval = new AddressValue(stream_->ReadU32());
-        _address += 4;
+        address_ += 4;
     }
     }
     else
     else
     {
     {

+ 1 - 1
V-Gears-Installer/include/decompiler/test/disassembler/pasc.h

@@ -27,7 +27,7 @@
 class PasCDisassembler : public SimpleDisassembler {
 class PasCDisassembler : public SimpleDisassembler {
 public:
 public:
 	PasCDisassembler(InstVec &insts);
 	PasCDisassembler(InstVec &insts);
-	virtual void DoDisassemble() override;
+	virtual void doDisassemble() override;
     virtual ValuePtr readParameter(InstPtr inst, std::string type) override;
     virtual ValuePtr readParameter(InstPtr inst, std::string type) override;
 };
 };
 
 

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

@@ -24,7 +24,7 @@
 SubOpcodeDisassembler::SubOpcodeDisassembler(InstVec &insts) : ::SimpleDisassembler(insts) {
 SubOpcodeDisassembler::SubOpcodeDisassembler(InstVec &insts) : ::SimpleDisassembler(insts) {
 }
 }
 
 
-void SubOpcodeDisassembler::DoDisassemble() {
+void SubOpcodeDisassembler::doDisassemble() {
 	START_OPCODES;
 	START_OPCODES;
 		START_SUBOPCODE(0xFF)
 		START_SUBOPCODE(0xFF)
 			OPCODE(0xFF, "FOO", SubOpcodeFakeInstruction, 0, "");
 			OPCODE(0xFF, "FOO", SubOpcodeFakeInstruction, 0, "");

+ 1 - 1
V-Gears-Installer/include/decompiler/test/disassembler/subopcode.h

@@ -27,7 +27,7 @@
 class SubOpcodeDisassembler : public SimpleDisassembler {
 class SubOpcodeDisassembler : public SimpleDisassembler {
 public:
 public:
 	SubOpcodeDisassembler(InstVec &insts);
 	SubOpcodeDisassembler(InstVec &insts);
-	void DoDisassemble() override;
+	void doDisassemble() override;
 };
 };
 
 
 class SubOpcodeFakeInstruction : public Instruction {
 class SubOpcodeFakeInstruction : public Instruction {

+ 71 - 71
V-Gears-Installer/include/decompiler/test/ff7_field_all_opcodes_disassembler_test.cpp

@@ -12,7 +12,7 @@ TEST(FF7Field, AllOpcodesDisassembler)
 {
 {
     InstVec insts;
     InstVec insts;
     DummyFormatter formatter;
     DummyFormatter formatter;
-    FieldEngine engine(formatter);
+    FF7::FieldEngine engine(formatter);
 
 
     auto d = engine.GetDisassembler(insts);
     auto d = engine.GetDisassembler(insts);
     d->open("decompiler/test/ff7_all_opcodes.dat");
     d->open("decompiler/test/ff7_all_opcodes.dat");
@@ -21,50 +21,50 @@ TEST(FF7Field, AllOpcodesDisassembler)
     std::cout << std::endl;
     std::cout << std::endl;
 
 
 
 
-    ASSERT_EQ(insts[0]->_opcode, OPCODE::RET);
+    ASSERT_EQ(insts[0]->_opcode, FF7::eOpcodes::RET);
     ASSERT_EQ(insts[0]->_params.size(), 0);
     ASSERT_EQ(insts[0]->_params.size(), 0);
 
 
-	ASSERT_EQ(insts[1]->_opcode, OPCODE::REQ);
+	ASSERT_EQ(insts[1]->_opcode, FF7::eOpcodes::REQ);
 	ASSERT_EQ(insts[1]->_params.size(), 3);
 	ASSERT_EQ(insts[1]->_params.size(), 3);
 	ASSERT_EQ(insts[1]->_params[0]->getSigned(), 0);
 	ASSERT_EQ(insts[1]->_params[0]->getSigned(), 0);
 	ASSERT_EQ(insts[1]->_params[1]->getSigned(), 2);
 	ASSERT_EQ(insts[1]->_params[1]->getSigned(), 2);
 	ASSERT_EQ(insts[1]->_params[2]->getSigned(), 1);
 	ASSERT_EQ(insts[1]->_params[2]->getSigned(), 1);
 
 
-	ASSERT_EQ(insts[2]->_opcode, OPCODE::REQSW);
+	ASSERT_EQ(insts[2]->_opcode, FF7::eOpcodes::REQSW);
 	ASSERT_EQ(insts[2]->_params.size(), 3);
 	ASSERT_EQ(insts[2]->_params.size(), 3);
 	ASSERT_EQ(insts[2]->_params[0]->getSigned(), 0);
 	ASSERT_EQ(insts[2]->_params[0]->getSigned(), 0);
 	ASSERT_EQ(insts[2]->_params[1]->getSigned(), 2);
 	ASSERT_EQ(insts[2]->_params[1]->getSigned(), 2);
 	ASSERT_EQ(insts[2]->_params[2]->getSigned(), 1);
 	ASSERT_EQ(insts[2]->_params[2]->getSigned(), 1);
 
 
-	ASSERT_EQ(insts[3]->_opcode, OPCODE::REQEW);
+	ASSERT_EQ(insts[3]->_opcode, FF7::eOpcodes::REQEW);
 	ASSERT_EQ(insts[3]->_params.size(), 3);
 	ASSERT_EQ(insts[3]->_params.size(), 3);
 	ASSERT_EQ(insts[3]->_params[0]->getSigned(), 0);
 	ASSERT_EQ(insts[3]->_params[0]->getSigned(), 0);
 	ASSERT_EQ(insts[3]->_params[1]->getSigned(), 2);
 	ASSERT_EQ(insts[3]->_params[1]->getSigned(), 2);
 	ASSERT_EQ(insts[3]->_params[2]->getSigned(), 1);
 	ASSERT_EQ(insts[3]->_params[2]->getSigned(), 1);
 
 
-	ASSERT_EQ(insts[4]->_opcode, OPCODE::PREQ);
+	ASSERT_EQ(insts[4]->_opcode, FF7::eOpcodes::PREQ);
 	ASSERT_EQ(insts[4]->_params.size(), 3);
 	ASSERT_EQ(insts[4]->_params.size(), 3);
 	ASSERT_EQ(insts[4]->_params[0]->getSigned(), 0);
 	ASSERT_EQ(insts[4]->_params[0]->getSigned(), 0);
 	ASSERT_EQ(insts[4]->_params[1]->getSigned(), 2);
 	ASSERT_EQ(insts[4]->_params[1]->getSigned(), 2);
 	ASSERT_EQ(insts[4]->_params[2]->getSigned(), 1);
 	ASSERT_EQ(insts[4]->_params[2]->getSigned(), 1);
 
 
-	ASSERT_EQ(insts[5]->_opcode, OPCODE::PREQSW);
+	ASSERT_EQ(insts[5]->_opcode, FF7::eOpcodes::PREQSW);
 	ASSERT_EQ(insts[5]->_params.size(), 3);
 	ASSERT_EQ(insts[5]->_params.size(), 3);
 	ASSERT_EQ(insts[5]->_params[0]->getSigned(), 0);
 	ASSERT_EQ(insts[5]->_params[0]->getSigned(), 0);
 	ASSERT_EQ(insts[5]->_params[1]->getSigned(), 2);
 	ASSERT_EQ(insts[5]->_params[1]->getSigned(), 2);
 	ASSERT_EQ(insts[5]->_params[2]->getSigned(), 1);
 	ASSERT_EQ(insts[5]->_params[2]->getSigned(), 1);
 
 
-	ASSERT_EQ(insts[6]->_opcode, OPCODE::PREQEW);
+	ASSERT_EQ(insts[6]->_opcode, FF7::eOpcodes::PREQEW);
 	ASSERT_EQ(insts[6]->_params.size(), 3);
 	ASSERT_EQ(insts[6]->_params.size(), 3);
 	ASSERT_EQ(insts[6]->_params[0]->getSigned(), 0);
 	ASSERT_EQ(insts[6]->_params[0]->getSigned(), 0);
 	ASSERT_EQ(insts[6]->_params[1]->getSigned(), 2);
 	ASSERT_EQ(insts[6]->_params[1]->getSigned(), 2);
 	ASSERT_EQ(insts[6]->_params[2]->getSigned(), 1);
 	ASSERT_EQ(insts[6]->_params[2]->getSigned(), 1);
 
 
-	ASSERT_EQ(insts[7]->_opcode, OPCODE::JOIN);
+	ASSERT_EQ(insts[7]->_opcode, FF7::eOpcodes::JOIN);
 	ASSERT_EQ(insts[7]->_params.size(), 1);
 	ASSERT_EQ(insts[7]->_params.size(), 1);
 	ASSERT_EQ(insts[7]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[7]->_params[0]->getSigned(), 1);
 
 
-	ASSERT_EQ(insts[8]->_opcode, OPCODE::SPLIT);
+	ASSERT_EQ(insts[8]->_opcode, FF7::eOpcodes::SPLIT);
 	ASSERT_EQ(insts[8]->_params.size(), 13);
 	ASSERT_EQ(insts[8]->_params.size(), 13);
 	ASSERT_EQ(insts[8]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[8]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[8]->_params[1]->getSigned(), 2);
 	ASSERT_EQ(insts[8]->_params[1]->getSigned(), 2);
@@ -80,7 +80,7 @@ TEST(FF7Field, AllOpcodesDisassembler)
 	ASSERT_EQ(insts[8]->_params[11]->getSigned(), 12);
 	ASSERT_EQ(insts[8]->_params[11]->getSigned(), 12);
 	ASSERT_EQ(insts[8]->_params[12]->getSigned(), 13);
 	ASSERT_EQ(insts[8]->_params[12]->getSigned(), 13);
 
 
-	ASSERT_EQ(insts[9]->_opcode, OPCODE::SPTYE);
+	ASSERT_EQ(insts[9]->_opcode, FF7::eOpcodes::SPTYE);
 	ASSERT_EQ(insts[9]->_params.size(), 7);
 	ASSERT_EQ(insts[9]->_params.size(), 7);
 	ASSERT_EQ(insts[9]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[9]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[9]->_params[1]->getSigned(), 2);
 	ASSERT_EQ(insts[9]->_params[1]->getSigned(), 2);
@@ -90,7 +90,7 @@ TEST(FF7Field, AllOpcodesDisassembler)
 	ASSERT_EQ(insts[9]->_params[5]->getSigned(), 6);
 	ASSERT_EQ(insts[9]->_params[5]->getSigned(), 6);
 	ASSERT_EQ(insts[9]->_params[6]->getSigned(), 7);
 	ASSERT_EQ(insts[9]->_params[6]->getSigned(), 7);
 
 
-	ASSERT_EQ(insts[10]->_opcode, OPCODE::GTPYE);
+	ASSERT_EQ(insts[10]->_opcode, FF7::eOpcodes::GTPYE);
 	ASSERT_EQ(insts[10]->_params.size(), 7);
 	ASSERT_EQ(insts[10]->_params.size(), 7);
 	ASSERT_EQ(insts[10]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[10]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[10]->_params[1]->getSigned(), 2);
 	ASSERT_EQ(insts[10]->_params[1]->getSigned(), 2);
@@ -100,66 +100,66 @@ TEST(FF7Field, AllOpcodesDisassembler)
 	ASSERT_EQ(insts[10]->_params[5]->getSigned(), 6);
 	ASSERT_EQ(insts[10]->_params[5]->getSigned(), 6);
 	ASSERT_EQ(insts[10]->_params[6]->getSigned(), 7);
 	ASSERT_EQ(insts[10]->_params[6]->getSigned(), 7);
 
 
-	ASSERT_EQ(insts[11]->_opcode, OPCODE::DSKCG);
+	ASSERT_EQ(insts[11]->_opcode, FF7::eOpcodes::DSKCG);
 	ASSERT_EQ(insts[11]->_params.size(), 1);
 	ASSERT_EQ(insts[11]->_params.size(), 1);
 	ASSERT_EQ(insts[11]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[11]->_params[0]->getSigned(), 1);
 
 
 	
 	
-	ASSERT_EQ(insts[12]->_opcode, MAKE_SUBOPCODE(OPCODE::SPECIAL, OPCODE_SPECIAL::ARROW));
+	ASSERT_EQ(insts[12]->_opcode, MAKE_SUBOPCODE(FF7::eOpcodes::SPECIAL, FF7::eSpecialOpcodes::ARROW));
 	ASSERT_EQ(insts[12]->_params.size(), 1);
 	ASSERT_EQ(insts[12]->_params.size(), 1);
 	ASSERT_EQ(insts[12]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[12]->_params[0]->getSigned(), 1);
 
 
-	ASSERT_EQ(insts[13]->_opcode, MAKE_SUBOPCODE(OPCODE::SPECIAL, OPCODE_SPECIAL::PNAME));
+	ASSERT_EQ(insts[13]->_opcode, MAKE_SUBOPCODE(FF7::eOpcodes::SPECIAL, FF7::eSpecialOpcodes::PNAME));
 	ASSERT_EQ(insts[13]->_params.size(), 1);
 	ASSERT_EQ(insts[13]->_params.size(), 1);
 	ASSERT_EQ(insts[13]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[13]->_params[0]->getSigned(), 1);
 
 
-	ASSERT_EQ(insts[14]->_opcode, MAKE_SUBOPCODE(OPCODE::SPECIAL, OPCODE_SPECIAL::GMSPD));
+	ASSERT_EQ(insts[14]->_opcode, MAKE_SUBOPCODE(FF7::eOpcodes::SPECIAL, FF7::eSpecialOpcodes::GMSPD));
 	ASSERT_EQ(insts[14]->_params.size(), 1);
 	ASSERT_EQ(insts[14]->_params.size(), 1);
 	ASSERT_EQ(insts[14]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[14]->_params[0]->getSigned(), 1);
 
 
-	ASSERT_EQ(insts[15]->_opcode, MAKE_SUBOPCODE(OPCODE::SPECIAL, OPCODE_SPECIAL::SMSPD));
+	ASSERT_EQ(insts[15]->_opcode, MAKE_SUBOPCODE(FF7::eOpcodes::SPECIAL, FF7::eSpecialOpcodes::SMSPD));
 	ASSERT_EQ(insts[15]->_params.size(), 2);
 	ASSERT_EQ(insts[15]->_params.size(), 2);
 	ASSERT_EQ(insts[15]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[15]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[15]->_params[1]->getSigned(), 2);
 	ASSERT_EQ(insts[15]->_params[1]->getSigned(), 2);
 
 
-	ASSERT_EQ(insts[16]->_opcode, MAKE_SUBOPCODE(OPCODE::SPECIAL, OPCODE_SPECIAL::FLMAT));
+	ASSERT_EQ(insts[16]->_opcode, MAKE_SUBOPCODE(FF7::eOpcodes::SPECIAL, FF7::eSpecialOpcodes::FLMAT));
 	ASSERT_EQ(insts[16]->_params.size(), 0);
 	ASSERT_EQ(insts[16]->_params.size(), 0);
 
 
-	ASSERT_EQ(insts[17]->_opcode, MAKE_SUBOPCODE(OPCODE::SPECIAL, OPCODE_SPECIAL::FLITM));
+	ASSERT_EQ(insts[17]->_opcode, MAKE_SUBOPCODE(FF7::eOpcodes::SPECIAL, FF7::eSpecialOpcodes::FLITM));
 	ASSERT_EQ(insts[17]->_params.size(), 0);
 	ASSERT_EQ(insts[17]->_params.size(), 0);
 
 
-	ASSERT_EQ(insts[18]->_opcode, MAKE_SUBOPCODE(OPCODE::SPECIAL, OPCODE_SPECIAL::BTLCK));
+	ASSERT_EQ(insts[18]->_opcode, MAKE_SUBOPCODE(FF7::eOpcodes::SPECIAL, FF7::eSpecialOpcodes::BTLCK));
 	ASSERT_EQ(insts[18]->_params.size(), 1);
 	ASSERT_EQ(insts[18]->_params.size(), 1);
 	ASSERT_EQ(insts[18]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[18]->_params[0]->getSigned(), 1);
 
 
-	ASSERT_EQ(insts[19]->_opcode, MAKE_SUBOPCODE(OPCODE::SPECIAL, OPCODE_SPECIAL::MVLCK));
+	ASSERT_EQ(insts[19]->_opcode, MAKE_SUBOPCODE(FF7::eOpcodes::SPECIAL, FF7::eSpecialOpcodes::MVLCK));
 	ASSERT_EQ(insts[19]->_params.size(), 1);
 	ASSERT_EQ(insts[19]->_params.size(), 1);
 	ASSERT_EQ(insts[19]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[19]->_params[0]->getSigned(), 1);
 
 
-	ASSERT_EQ(insts[20]->_opcode, MAKE_SUBOPCODE(OPCODE::SPECIAL, OPCODE_SPECIAL::SPCNM));
+	ASSERT_EQ(insts[20]->_opcode, MAKE_SUBOPCODE(FF7::eOpcodes::SPECIAL, FF7::eSpecialOpcodes::SPCNM));
 	ASSERT_EQ(insts[20]->_params.size(), 2);
 	ASSERT_EQ(insts[20]->_params.size(), 2);
 	ASSERT_EQ(insts[20]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[20]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[20]->_params[1]->getSigned(), 2);
 	ASSERT_EQ(insts[20]->_params[1]->getSigned(), 2);
 
 
-	ASSERT_EQ(insts[21]->_opcode, MAKE_SUBOPCODE(OPCODE::SPECIAL, OPCODE_SPECIAL::RSGLB));
+	ASSERT_EQ(insts[21]->_opcode, MAKE_SUBOPCODE(FF7::eOpcodes::SPECIAL, FF7::eSpecialOpcodes::RSGLB));
 	ASSERT_EQ(insts[21]->_params.size(), 0);
 	ASSERT_EQ(insts[21]->_params.size(), 0);
 
 
-	ASSERT_EQ(insts[22]->_opcode, MAKE_SUBOPCODE(OPCODE::SPECIAL, OPCODE_SPECIAL::CLITM));
+	ASSERT_EQ(insts[22]->_opcode, MAKE_SUBOPCODE(FF7::eOpcodes::SPECIAL, FF7::eSpecialOpcodes::CLITM));
 	ASSERT_EQ(insts[22]->_params.size(), 0);
 	ASSERT_EQ(insts[22]->_params.size(), 0);
 
 
-	ASSERT_EQ(insts[23]->_opcode, OPCODE::JMPF);
+	ASSERT_EQ(insts[23]->_opcode, FF7::eOpcodes::JMPF);
 	ASSERT_EQ(insts[23]->_params.size(), 1);
 	ASSERT_EQ(insts[23]->_params.size(), 1);
 
 
-	ASSERT_EQ(insts[24]->_opcode, OPCODE::JMPFL);
+	ASSERT_EQ(insts[24]->_opcode, FF7::eOpcodes::JMPFL);
 	ASSERT_EQ(insts[24]->_params.size(), 1);
 	ASSERT_EQ(insts[24]->_params.size(), 1);
 
 
-	ASSERT_EQ(insts[25]->_opcode, OPCODE::JMPB);
+	ASSERT_EQ(insts[25]->_opcode, FF7::eOpcodes::JMPB);
 	ASSERT_EQ(insts[25]->_params.size(), 1);
 	ASSERT_EQ(insts[25]->_params.size(), 1);
 
 
-	ASSERT_EQ(insts[26]->_opcode, OPCODE::JMPBL);
+	ASSERT_EQ(insts[26]->_opcode, FF7::eOpcodes::JMPBL);
 	ASSERT_EQ(insts[26]->_params.size(), 1);
 	ASSERT_EQ(insts[26]->_params.size(), 1);
 
 
-	ASSERT_EQ(insts[27]->_opcode, OPCODE::IFUB);
+	ASSERT_EQ(insts[27]->_opcode, FF7::eOpcodes::IFUB);
 	ASSERT_EQ(insts[27]->_params.size(), 6);
 	ASSERT_EQ(insts[27]->_params.size(), 6);
 	ASSERT_EQ(insts[27]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[27]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[27]->_params[1]->getSigned(), 3);
 	ASSERT_EQ(insts[27]->_params[1]->getSigned(), 3);
@@ -168,7 +168,7 @@ TEST(FF7Field, AllOpcodesDisassembler)
 	ASSERT_EQ(insts[27]->_params[4]->getSigned(), 5);
 	ASSERT_EQ(insts[27]->_params[4]->getSigned(), 5);
 	ASSERT_EQ(insts[27]->_params[5]->getSigned(), 1);
 	ASSERT_EQ(insts[27]->_params[5]->getSigned(), 1);
 
 
-	ASSERT_EQ(insts[28]->_opcode, OPCODE::IFUBL);
+	ASSERT_EQ(insts[28]->_opcode, FF7::eOpcodes::IFUBL);
 	ASSERT_EQ(insts[28]->_params.size(), 6);
 	ASSERT_EQ(insts[28]->_params.size(), 6);
 	ASSERT_EQ(insts[28]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[28]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[28]->_params[1]->getSigned(), 3);
 	ASSERT_EQ(insts[28]->_params[1]->getSigned(), 3);
@@ -177,7 +177,7 @@ TEST(FF7Field, AllOpcodesDisassembler)
 	ASSERT_EQ(insts[28]->_params[4]->getSigned(), 5);
 	ASSERT_EQ(insts[28]->_params[4]->getSigned(), 5);
 	ASSERT_EQ(insts[28]->_params[5]->getSigned(), 2); // For some reason this one has to be 2
 	ASSERT_EQ(insts[28]->_params[5]->getSigned(), 2); // For some reason this one has to be 2
 
 
-	ASSERT_EQ(insts[29]->_opcode, OPCODE::IFSW);
+	ASSERT_EQ(insts[29]->_opcode, FF7::eOpcodes::IFSW);
 	ASSERT_EQ(insts[29]->_params.size(), 6);
 	ASSERT_EQ(insts[29]->_params.size(), 6);
 	ASSERT_EQ(insts[29]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[29]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[29]->_params[1]->getSigned(), 3);
 	ASSERT_EQ(insts[29]->_params[1]->getSigned(), 3);
@@ -186,7 +186,7 @@ TEST(FF7Field, AllOpcodesDisassembler)
 	ASSERT_EQ(insts[29]->_params[4]->getSigned(), 5);
 	ASSERT_EQ(insts[29]->_params[4]->getSigned(), 5);
 	ASSERT_EQ(insts[29]->_params[5]->getSigned(), 1);
 	ASSERT_EQ(insts[29]->_params[5]->getSigned(), 1);
 
 
-	ASSERT_EQ(insts[30]->_opcode, OPCODE::IFSWL);
+	ASSERT_EQ(insts[30]->_opcode, FF7::eOpcodes::IFSWL);
 	ASSERT_EQ(insts[30]->_params.size(), 6);
 	ASSERT_EQ(insts[30]->_params.size(), 6);
 	ASSERT_EQ(insts[30]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[30]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[30]->_params[1]->getSigned(), 3);
 	ASSERT_EQ(insts[30]->_params[1]->getSigned(), 3);
@@ -195,7 +195,7 @@ TEST(FF7Field, AllOpcodesDisassembler)
 	ASSERT_EQ(insts[30]->_params[4]->getSigned(), 5);
 	ASSERT_EQ(insts[30]->_params[4]->getSigned(), 5);
 	ASSERT_EQ(insts[30]->_params[5]->getSigned(), 2); // For some reason this one has to be 2
 	ASSERT_EQ(insts[30]->_params[5]->getSigned(), 2); // For some reason this one has to be 2
 
 
-	ASSERT_EQ(insts[31]->_opcode, OPCODE::IFUW);
+	ASSERT_EQ(insts[31]->_opcode, FF7::eOpcodes::IFUW);
 	ASSERT_EQ(insts[31]->_params.size(), 6);
 	ASSERT_EQ(insts[31]->_params.size(), 6);
 	ASSERT_EQ(insts[31]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[31]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[31]->_params[1]->getSigned(), 3);
 	ASSERT_EQ(insts[31]->_params[1]->getSigned(), 3);
@@ -204,7 +204,7 @@ TEST(FF7Field, AllOpcodesDisassembler)
 	ASSERT_EQ(insts[31]->_params[4]->getSigned(), 5);
 	ASSERT_EQ(insts[31]->_params[4]->getSigned(), 5);
 	ASSERT_EQ(insts[31]->_params[5]->getSigned(), 1);
 	ASSERT_EQ(insts[31]->_params[5]->getSigned(), 1);
 
 
-	ASSERT_EQ(insts[32]->_opcode, OPCODE::IFUWL);
+	ASSERT_EQ(insts[32]->_opcode, FF7::eOpcodes::IFUWL);
 	ASSERT_EQ(insts[32]->_params.size(), 6);
 	ASSERT_EQ(insts[32]->_params.size(), 6);
 	ASSERT_EQ(insts[32]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[32]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[32]->_params[1]->getSigned(), 3);
 	ASSERT_EQ(insts[32]->_params[1]->getSigned(), 3);
@@ -213,7 +213,7 @@ TEST(FF7Field, AllOpcodesDisassembler)
 	ASSERT_EQ(insts[32]->_params[4]->getSigned(), 5);
 	ASSERT_EQ(insts[32]->_params[4]->getSigned(), 5);
 	ASSERT_EQ(insts[32]->_params[5]->getSigned(), 2); // For some reason this one has to be 2
 	ASSERT_EQ(insts[32]->_params[5]->getSigned(), 2); // For some reason this one has to be 2
 
 
-	ASSERT_EQ(insts[33]->_opcode, OPCODE::MINIGAME);
+	ASSERT_EQ(insts[33]->_opcode, FF7::eOpcodes::MINIGAME);
 	ASSERT_EQ(insts[33]->_params.size(), 6);
 	ASSERT_EQ(insts[33]->_params.size(), 6);
 	ASSERT_EQ(insts[33]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[33]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[33]->_params[1]->getSigned(), 2);
 	ASSERT_EQ(insts[33]->_params[1]->getSigned(), 2);
@@ -222,54 +222,54 @@ TEST(FF7Field, AllOpcodesDisassembler)
 	ASSERT_EQ(insts[33]->_params[4]->getSigned(), 5);
 	ASSERT_EQ(insts[33]->_params[4]->getSigned(), 5);
 	ASSERT_EQ(insts[33]->_params[5]->getSigned(), 6);
 	ASSERT_EQ(insts[33]->_params[5]->getSigned(), 6);
 
 
-	ASSERT_EQ(insts[34]->_opcode, OPCODE::TUTOR);
+	ASSERT_EQ(insts[34]->_opcode, FF7::eOpcodes::TUTOR);
 	ASSERT_EQ(insts[34]->_params.size(), 1);
 	ASSERT_EQ(insts[34]->_params.size(), 1);
 	ASSERT_EQ(insts[34]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[34]->_params[0]->getSigned(), 1);
 
 
 	// BATTLE MODE STATES START
 	// BATTLE MODE STATES START
 
 
-	ASSERT_EQ(insts[35]->_opcode, OPCODE::BTMD2);
+	ASSERT_EQ(insts[35]->_opcode, FF7::eOpcodes::BTMD2);
 	ASSERT_EQ(insts[35]->_params.size(), 4);
 	ASSERT_EQ(insts[35]->_params.size(), 4);
 	ASSERT_EQ(insts[35]->_params[0]->getSigned(), 0x80);
 	ASSERT_EQ(insts[35]->_params[0]->getSigned(), 0x80);
 
 
-	ASSERT_EQ(insts[36]->_opcode, OPCODE::BTMD2);
+	ASSERT_EQ(insts[36]->_opcode, FF7::eOpcodes::BTMD2);
 	ASSERT_EQ(insts[36]->_params.size(), 4);
 	ASSERT_EQ(insts[36]->_params.size(), 4);
 	ASSERT_EQ(insts[36]->_params[0]->getSigned(), 0x40);
 	ASSERT_EQ(insts[36]->_params[0]->getSigned(), 0x40);
 
 
-	ASSERT_EQ(insts[37]->_opcode, OPCODE::BTMD2);
+	ASSERT_EQ(insts[37]->_opcode, FF7::eOpcodes::BTMD2);
 	ASSERT_EQ(insts[37]->_params.size(), 4);
 	ASSERT_EQ(insts[37]->_params.size(), 4);
 	ASSERT_EQ(insts[37]->_params[0]->getSigned(), 0x20);
 	ASSERT_EQ(insts[37]->_params[0]->getSigned(), 0x20);
 
 
-	ASSERT_EQ(insts[38]->_opcode, OPCODE::BTMD2);
+	ASSERT_EQ(insts[38]->_opcode, FF7::eOpcodes::BTMD2);
 	ASSERT_EQ(insts[38]->_params.size(), 4);
 	ASSERT_EQ(insts[38]->_params.size(), 4);
 	ASSERT_EQ(insts[38]->_params[0]->getSigned(), 0x10);
 	ASSERT_EQ(insts[38]->_params[0]->getSigned(), 0x10);
 
 
-	ASSERT_EQ(insts[39]->_opcode, OPCODE::BTMD2);
+	ASSERT_EQ(insts[39]->_opcode, FF7::eOpcodes::BTMD2);
 	ASSERT_EQ(insts[39]->_params.size(), 4);
 	ASSERT_EQ(insts[39]->_params.size(), 4);
 	ASSERT_EQ(insts[39]->_params[0]->getSigned(), 0x08);
 	ASSERT_EQ(insts[39]->_params[0]->getSigned(), 0x08);
 
 
-	ASSERT_EQ(insts[40]->_opcode, OPCODE::BTMD2);
+	ASSERT_EQ(insts[40]->_opcode, FF7::eOpcodes::BTMD2);
 	ASSERT_EQ(insts[40]->_params.size(), 4);
 	ASSERT_EQ(insts[40]->_params.size(), 4);
 	ASSERT_EQ(insts[40]->_params[0]->getSigned(), 0x04);
 	ASSERT_EQ(insts[40]->_params[0]->getSigned(), 0x04);
 
 
-	ASSERT_EQ(insts[41]->_opcode, OPCODE::BTMD2);
+	ASSERT_EQ(insts[41]->_opcode, FF7::eOpcodes::BTMD2);
 	ASSERT_EQ(insts[41]->_params.size(), 4);
 	ASSERT_EQ(insts[41]->_params.size(), 4);
 	ASSERT_EQ(insts[41]->_params[0]->getSigned(), 0x02);
 	ASSERT_EQ(insts[41]->_params[0]->getSigned(), 0x02);
 
 
-	//ASSERT_EQ(insts[42]->_opcode, OPCODE::BTMD2);
+	//ASSERT_EQ(insts[42]->_opcode, FF7::eOpcodes::BTMD2);
 	//ASSERT_EQ(insts[42]->_params.size(), 4);
 	//ASSERT_EQ(insts[42]->_params.size(), 4);
 	//ASSERT_EQ(insts[42]->_params[1]->getSigned(), 0x80);
 	//ASSERT_EQ(insts[42]->_params[1]->getSigned(), 0x80);
 
 
-	ASSERT_EQ(insts[67]->_opcode, OPCODE::BTRLD);
+	ASSERT_EQ(insts[67]->_opcode, FF7::eOpcodes::BTRLD);
 	ASSERT_EQ(insts[67]->_params.size(), 2);
 	ASSERT_EQ(insts[67]->_params.size(), 2);
 	ASSERT_EQ(insts[67]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[67]->_params[0]->getSigned(), 1);
 	//ASSERT_EQ(insts[67]->_params[0]->getSigned(), 1);
 	//ASSERT_EQ(insts[67]->_params[0]->getSigned(), 1);
 
 
-	ASSERT_EQ(insts[68]->_opcode, OPCODE::WAIT);
+	ASSERT_EQ(insts[68]->_opcode, FF7::eOpcodes::WAIT);
 	ASSERT_EQ(insts[68]->_params.size(), 1);
 	ASSERT_EQ(insts[68]->_params.size(), 1);
 	ASSERT_EQ(insts[68]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[68]->_params[0]->getSigned(), 1);
 
 
-	ASSERT_EQ(insts[69]->_opcode, OPCODE::NFADE);
+	ASSERT_EQ(insts[69]->_opcode, FF7::eOpcodes::NFADE);
 	ASSERT_EQ(insts[69]->_params.size(), 8);
 	ASSERT_EQ(insts[69]->_params.size(), 8);
 	//ASSERT_EQ(insts[69]->_params[0]->getSigned(), 1); // TODO:These values are what they are set to in Makou Reactor however SUDM reads them as something else Reads:(18)
 	//ASSERT_EQ(insts[69]->_params[0]->getSigned(), 1); // TODO:These values are what they are set to in Makou Reactor however SUDM reads them as something else Reads:(18)
 	//ASSERT_EQ(insts[69]->_params[1]->getSigned(), 2); // TODO:These values are what they are set to in Makou Reactor however SUDM reads them as something else Reads:(52)
 	//ASSERT_EQ(insts[69]->_params[1]->getSigned(), 2); // TODO:These values are what they are set to in Makou Reactor however SUDM reads them as something else Reads:(52)
@@ -280,35 +280,35 @@ TEST(FF7Field, AllOpcodesDisassembler)
 	ASSERT_EQ(insts[69]->_params[6]->getSigned(), 7);
 	ASSERT_EQ(insts[69]->_params[6]->getSigned(), 7);
 	ASSERT_EQ(insts[69]->_params[7]->getSigned(), 8);
 	ASSERT_EQ(insts[69]->_params[7]->getSigned(), 8);
 
 
-	ASSERT_EQ(insts[70]->_opcode, OPCODE::BLINK);
+	ASSERT_EQ(insts[70]->_opcode, FF7::eOpcodes::BLINK);
 	ASSERT_EQ(insts[70]->_params.size(), 1);
 	ASSERT_EQ(insts[70]->_params.size(), 1);
 	ASSERT_EQ(insts[70]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[70]->_params[0]->getSigned(), 1);
 
 
-	ASSERT_EQ(insts[71]->_opcode, OPCODE::BGMOVIE);
+	ASSERT_EQ(insts[71]->_opcode, FF7::eOpcodes::BGMOVIE);
 	ASSERT_EQ(insts[71]->_params.size(), 1);
 	ASSERT_EQ(insts[71]->_params.size(), 1);
 	ASSERT_EQ(insts[71]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[71]->_params[0]->getSigned(), 1);
 
 
 	//KAWAI is normally here
 	//KAWAI is normally here
 
 
-	ASSERT_EQ(insts[72]->_opcode, OPCODE::KAWIW);
+	ASSERT_EQ(insts[72]->_opcode, FF7::eOpcodes::KAWIW);
 	ASSERT_EQ(insts[72]->_params.size(), 0);
 	ASSERT_EQ(insts[72]->_params.size(), 0);
 
 
-	ASSERT_EQ(insts[73]->_opcode, OPCODE::PMOVA);
+	ASSERT_EQ(insts[73]->_opcode, FF7::eOpcodes::PMOVA);
 	ASSERT_EQ(insts[73]->_params.size(), 1);
 	ASSERT_EQ(insts[73]->_params.size(), 1);
 	ASSERT_EQ(insts[73]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[73]->_params[0]->getSigned(), 1);
 
 
-	ASSERT_EQ(insts[74]->_opcode, OPCODE::SLIP);
+	ASSERT_EQ(insts[74]->_opcode, FF7::eOpcodes::SLIP);
 	ASSERT_EQ(insts[74]->_params.size(), 1);
 	ASSERT_EQ(insts[74]->_params.size(), 1);
 	ASSERT_EQ(insts[74]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[74]->_params[0]->getSigned(), 1);
 
 
-	ASSERT_EQ(insts[75]->_opcode, OPCODE::BGPDH);
+	ASSERT_EQ(insts[75]->_opcode, FF7::eOpcodes::BGPDH);
 	ASSERT_EQ(insts[75]->_params.size(), 4);
 	ASSERT_EQ(insts[75]->_params.size(), 4);
 	ASSERT_EQ(insts[75]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[75]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[75]->_params[1]->getSigned(), 2);
 	ASSERT_EQ(insts[75]->_params[1]->getSigned(), 2);
 	ASSERT_EQ(insts[75]->_params[2]->getSigned(), 3);
 	ASSERT_EQ(insts[75]->_params[2]->getSigned(), 3);
 	ASSERT_EQ(insts[75]->_params[3]->getSigned(), 4);
 	ASSERT_EQ(insts[75]->_params[3]->getSigned(), 4);
 
 
-	//ASSERT_EQ(insts[76]->_opcode, OPCODE::BGSCR);
+	//ASSERT_EQ(insts[76]->_opcode, FF7::eOpcodes::BGSCR);
 	//ASSERT_EQ(insts[76]->_params.size(), 5);
 	//ASSERT_EQ(insts[76]->_params.size(), 5);
 	//ASSERT_EQ(insts[76]->_params[0]->getSigned(), 1);
 	//ASSERT_EQ(insts[76]->_params[0]->getSigned(), 1);
 	//ASSERT_EQ(insts[76]->_params[1]->getSigned(), 2);
 	//ASSERT_EQ(insts[76]->_params[1]->getSigned(), 2);
@@ -316,7 +316,7 @@ TEST(FF7Field, AllOpcodesDisassembler)
 	//ASSERT_EQ(insts[76]->_params[3]->getSigned(), 4);
 	//ASSERT_EQ(insts[76]->_params[3]->getSigned(), 4);
 	//ASSERT_EQ(insts[76]->_params[4]->getSigned(), 5);
 	//ASSERT_EQ(insts[76]->_params[4]->getSigned(), 5);
 
 
-	ASSERT_EQ(insts[78]->_opcode, OPCODE::WSIZW);
+	ASSERT_EQ(insts[78]->_opcode, FF7::eOpcodes::WSIZW);
 	ASSERT_EQ(insts[78]->_params.size(), 5);
 	ASSERT_EQ(insts[78]->_params.size(), 5);
 	ASSERT_EQ(insts[78]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[78]->_params[0]->getSigned(), 1);
 	ASSERT_EQ(insts[78]->_params[1]->getSigned(), 2);
 	ASSERT_EQ(insts[78]->_params[1]->getSigned(), 2);
@@ -324,52 +324,52 @@ TEST(FF7Field, AllOpcodesDisassembler)
 	ASSERT_EQ(insts[78]->_params[3]->getSigned(), 4);
 	ASSERT_EQ(insts[78]->_params[3]->getSigned(), 4);
 	ASSERT_EQ(insts[78]->_params[4]->getSigned(), 5);
 	ASSERT_EQ(insts[78]->_params[4]->getSigned(), 5);
 
 
-	//ASSERT_EQ(insts[79]->_opcode, OPCODE::IFKEY); // TODO
+	//ASSERT_EQ(insts[79]->_opcode, FF7::eOpcodes::IFKEY); // TODO
 	//ASSERT_EQ(insts[79]->_params.size(), 2);
 	//ASSERT_EQ(insts[79]->_params.size(), 2);
 	//ASSERT_EQ(0x0001, insts[79]->_params[0]->getSigned());
 	//ASSERT_EQ(0x0001, insts[79]->_params[0]->getSigned());
 
 
-	//ASSERT_EQ(insts[80]->_opcode, OPCODE::IFKEY); // TODO
+	//ASSERT_EQ(insts[80]->_opcode, FF7::eOpcodes::IFKEY); // TODO
 	//ASSERT_EQ(insts[80]->_params.size(), 2);
 	//ASSERT_EQ(insts[80]->_params.size(), 2);
 	//ASSERT_EQ(0x8000, insts[78]->_params[0]->getSigned());
 	//ASSERT_EQ(0x8000, insts[78]->_params[0]->getSigned());
 
 
-	//ASSERT_EQ(insts[81]->_opcode, OPCODE::IFKEYON); // TODO
+	//ASSERT_EQ(insts[81]->_opcode, FF7::eOpcodes::IFKEYON); // TODO
 	//ASSERT_EQ(insts[81]->_params.size(), 2);
 	//ASSERT_EQ(insts[81]->_params.size(), 2);
 	//ASSERT_EQ(0x0001, insts[81]->_params[0]->getSigned());
 	//ASSERT_EQ(0x0001, insts[81]->_params[0]->getSigned());
 
 
-	//ASSERT_EQ(insts[82]->_opcode, OPCODE::IFKEYON); // TODO
+	//ASSERT_EQ(insts[82]->_opcode, FF7::eOpcodes::IFKEYON); // TODO
 	//ASSERT_EQ(insts[82]->_params.size(), 2);
 	//ASSERT_EQ(insts[82]->_params.size(), 2);
 	//ASSERT_EQ(0x8000, insts[82]->_params[0]->getSigned());
 	//ASSERT_EQ(0x8000, insts[82]->_params[0]->getSigned());
 
 
-	//ASSERT_EQ(insts[83]->_opcode, OPCODE::IFKEYOFF); // TODO
+	//ASSERT_EQ(insts[83]->_opcode, FF7::eOpcodes::IFKEYOFF); // TODO
 	//ASSERT_EQ(insts[83]->_params.size(), 2);
 	//ASSERT_EQ(insts[83]->_params.size(), 2);
 	//ASSERT_EQ(0x0001, insts[83]->_params[0]->getSigned());
 	//ASSERT_EQ(0x0001, insts[83]->_params[0]->getSigned());
 
 
-	//ASSERT_EQ(insts[84]->_opcode, OPCODE::IFKEYOFF); // TODO
+	//ASSERT_EQ(insts[84]->_opcode, FF7::eOpcodes::IFKEYOFF); // TODO
 	//ASSERT_EQ(insts[84]->_params.size(), 2);
 	//ASSERT_EQ(insts[84]->_params.size(), 2);
 	//ASSERT_EQ(0x8000, insts[84]->_params[0]->getSigned());
 	//ASSERT_EQ(0x8000, insts[84]->_params[0]->getSigned());
 
 
-	ASSERT_EQ(insts[85]->_opcode, OPCODE::UC);
+	ASSERT_EQ(insts[85]->_opcode, FF7::eOpcodes::UC);
 	ASSERT_EQ(1, insts[85]->_params.size());
 	ASSERT_EQ(1, insts[85]->_params.size());
 	ASSERT_EQ(1, insts[85]->_params[0]->getSigned());
 	ASSERT_EQ(1, insts[85]->_params[0]->getSigned());
 
 
-	ASSERT_EQ(insts[86]->_opcode, OPCODE::PDIRA);
+	ASSERT_EQ(insts[86]->_opcode, FF7::eOpcodes::PDIRA);
 	ASSERT_EQ(1, insts[86]->_params.size());
 	ASSERT_EQ(1, insts[86]->_params.size());
 	ASSERT_EQ(1, insts[86]->_params[0]->getSigned());
 	ASSERT_EQ(1, insts[86]->_params[0]->getSigned());
 
 
-	ASSERT_EQ(insts[87]->_opcode, OPCODE::PTURA);
+	ASSERT_EQ(insts[87]->_opcode, FF7::eOpcodes::PTURA);
 	ASSERT_EQ(3, insts[87]->_params.size());
 	ASSERT_EQ(3, insts[87]->_params.size());
 	ASSERT_EQ(1, insts[87]->_params[0]->getSigned());
 	ASSERT_EQ(1, insts[87]->_params[0]->getSigned());
 	ASSERT_EQ(2, insts[87]->_params[1]->getSigned());
 	ASSERT_EQ(2, insts[87]->_params[1]->getSigned());
 	ASSERT_EQ(3, insts[87]->_params[2]->getSigned());
 	ASSERT_EQ(3, insts[87]->_params[2]->getSigned());
 
 
-	ASSERT_EQ(insts[88]->_opcode, OPCODE::WSPCL);
+	ASSERT_EQ(insts[88]->_opcode, FF7::eOpcodes::WSPCL);
 	ASSERT_EQ(4, insts[88]->_params.size());
 	ASSERT_EQ(4, insts[88]->_params.size());
 	ASSERT_EQ(1, insts[88]->_params[0]->getSigned());
 	ASSERT_EQ(1, insts[88]->_params[0]->getSigned());
 	ASSERT_EQ(2, insts[88]->_params[1]->getSigned());
 	ASSERT_EQ(2, insts[88]->_params[1]->getSigned());
 	ASSERT_EQ(3, insts[88]->_params[2]->getSigned());
 	ASSERT_EQ(3, insts[88]->_params[2]->getSigned());
 	ASSERT_EQ(4, insts[88]->_params[3]->getSigned());
 	ASSERT_EQ(4, insts[88]->_params[3]->getSigned());
 
 
-	ASSERT_EQ(insts[89]->_opcode, OPCODE::STTIM);
+	ASSERT_EQ(insts[89]->_opcode, FF7::eOpcodes::STTIM);
 	ASSERT_EQ(7, insts[89]->_params.size());
 	ASSERT_EQ(7, insts[89]->_params.size());
 	ASSERT_EQ(1, insts[89]->_params[0]->getSigned());
 	ASSERT_EQ(1, insts[89]->_params[0]->getSigned());
 	ASSERT_EQ(2, insts[89]->_params[1]->getSigned());
 	ASSERT_EQ(2, insts[89]->_params[1]->getSigned());
@@ -379,31 +379,31 @@ TEST(FF7Field, AllOpcodesDisassembler)
 	ASSERT_EQ(6, insts[89]->_params[5]->getSigned());
 	ASSERT_EQ(6, insts[89]->_params[5]->getSigned());
 	ASSERT_EQ(7, insts[89]->_params[6]->getSigned());
 	ASSERT_EQ(7, insts[89]->_params[6]->getSigned());
 
 
-    ASSERT_EQ(insts[90]->_opcode, OPCODE::GOLDU);
+    ASSERT_EQ(insts[90]->_opcode, FF7::eOpcodes::GOLDU);
     ASSERT_EQ(3, insts[90]->_params.size());
     ASSERT_EQ(3, insts[90]->_params.size());
     ASSERT_EQ(0, insts[90]->_params[0]->getSigned());
     ASSERT_EQ(0, insts[90]->_params[0]->getSigned());
     ASSERT_EQ(0, insts[90]->_params[1]->getSigned());
     ASSERT_EQ(0, insts[90]->_params[1]->getSigned());
     ASSERT_EQ(1, insts[90]->_params[2]->getSigned());
     ASSERT_EQ(1, insts[90]->_params[2]->getSigned());
 
 
-    ASSERT_EQ(insts[91]->_opcode, OPCODE::GOLDU);
+    ASSERT_EQ(insts[91]->_opcode, FF7::eOpcodes::GOLDU);
     ASSERT_EQ(3, insts[91]->_params.size());
     ASSERT_EQ(3, insts[91]->_params.size());
     ASSERT_EQ(1, insts[91]->_params[0]->getSigned());
     ASSERT_EQ(1, insts[91]->_params[0]->getSigned());
     ASSERT_EQ(2, insts[91]->_params[1]->getSigned());
     ASSERT_EQ(2, insts[91]->_params[1]->getSigned());
     ASSERT_EQ(0, insts[91]->_params[2]->getSigned());
     ASSERT_EQ(0, insts[91]->_params[2]->getSigned());
 
 
-    ASSERT_EQ(insts[92]->_opcode, OPCODE::GOLDD);
+    ASSERT_EQ(insts[92]->_opcode, FF7::eOpcodes::GOLDD);
     ASSERT_EQ(3, insts[92]->_params.size());
     ASSERT_EQ(3, insts[92]->_params.size());
     ASSERT_EQ(0, insts[92]->_params[0]->getSigned());
     ASSERT_EQ(0, insts[92]->_params[0]->getSigned());
     ASSERT_EQ(0, insts[92]->_params[1]->getSigned());
     ASSERT_EQ(0, insts[92]->_params[1]->getSigned());
     ASSERT_EQ(1, insts[92]->_params[2]->getSigned());
     ASSERT_EQ(1, insts[92]->_params[2]->getSigned());
 
 
-    ASSERT_EQ(insts[93]->_opcode, OPCODE::GOLDD);
+    ASSERT_EQ(insts[93]->_opcode, FF7::eOpcodes::GOLDD);
     ASSERT_EQ(3, insts[93]->_params.size());
     ASSERT_EQ(3, insts[93]->_params.size());
     ASSERT_EQ(1, insts[93]->_params[0]->getSigned());
     ASSERT_EQ(1, insts[93]->_params[0]->getSigned());
     ASSERT_EQ(2, insts[93]->_params[1]->getSigned());
     ASSERT_EQ(2, insts[93]->_params[1]->getSigned());
     ASSERT_EQ(0, insts[93]->_params[2]->getSigned());
     ASSERT_EQ(0, insts[93]->_params[2]->getSigned());
 
 
-    ASSERT_EQ(insts[94]->_opcode, OPCODE::CHGLD);
+    ASSERT_EQ(insts[94]->_opcode, FF7::eOpcodes::CHGLD);
     ASSERT_EQ(4, insts[94]->_params.size());
     ASSERT_EQ(4, insts[94]->_params.size());
     ASSERT_EQ(1, insts[94]->_params[0]->getSigned());
     ASSERT_EQ(1, insts[94]->_params[0]->getSigned());
     ASSERT_EQ(2, insts[94]->_params[1]->getSigned());
     ASSERT_EQ(2, insts[94]->_params[1]->getSigned());

+ 17 - 17
V-Gears-Installer/include/decompiler/test/ff7_field_control_flow_test.cpp

@@ -12,7 +12,7 @@ static uint32 Is3Nops(InstVec& insts, uint32& pos)
     for (int i = 0; i < 3; i++)
     for (int i = 0; i < 3; i++)
     {
     {
         pos++;
         pos++;
-        EXPECT_EQ(insts[pos]->_opcode, OPCODE::NOP);
+        EXPECT_EQ(insts[pos]->_opcode, FF7::eOpcodes::NOP);
         EXPECT_EQ(insts[pos]->_params.size(), 0);
         EXPECT_EQ(insts[pos]->_params.size(), 0);
     }
     }
     return insts[pos]->_address;
     return insts[pos]->_address;
@@ -21,7 +21,7 @@ static uint32 Is3Nops(InstVec& insts, uint32& pos)
 // Each forward jump type has its own script that starts with the
 // Each forward jump type has its own script that starts with the
 // jump opcode followed by 2 NOP's, the 3rd NOP is the end of the script
 // jump opcode followed by 2 NOP's, the 3rd NOP is the end of the script
 // and should be the target address of the jump.
 // and should be the target address of the jump.
-static void CheckForwardJump(OPCODE opCode, size_t paramsSize, InstVec& insts, uint32& pos)
+static void CheckForwardJump(FF7::eOpcodes opCode, size_t paramsSize, InstVec& insts, uint32& pos)
 {
 {
     pos++;
     pos++;
     const InstPtr& jumpInst = insts[pos];
     const InstPtr& jumpInst = insts[pos];
@@ -36,7 +36,7 @@ static void CheckForwardJump(OPCODE opCode, size_t paramsSize, InstVec& insts, u
 static uint32 IsNop(InstVec& insts, uint32& pos)
 static uint32 IsNop(InstVec& insts, uint32& pos)
 {
 {
     pos++;
     pos++;
-    EXPECT_EQ(insts[pos]->_opcode, OPCODE::NOP);
+    EXPECT_EQ(insts[pos]->_opcode, FF7::eOpcodes::NOP);
     EXPECT_EQ(insts[pos]->_params.size(), 0);
     EXPECT_EQ(insts[pos]->_params.size(), 0);
     return insts[pos]->_address;
     return insts[pos]->_address;
 }
 }
@@ -44,7 +44,7 @@ static uint32 IsNop(InstVec& insts, uint32& pos)
 
 
 // For a backwards jump we start with 3 NOPS and the last instruction is the jump itself which
 // For a backwards jump we start with 3 NOPS and the last instruction is the jump itself which
 // should be targeting the second/middle NOP
 // should be targeting the second/middle NOP
-static void CheckBackwardJump(OPCODE opCode, size_t paramsSize, InstVec& insts, uint32& pos)
+static void CheckBackwardJump(FF7::eOpcodes opCode, size_t paramsSize, InstVec& insts, uint32& pos)
 {
 {
     IsNop(insts, pos);
     IsNop(insts, pos);
 
 
@@ -68,7 +68,7 @@ TEST(FF7Field, ControlFlow)
 {
 {
     InstVec insts;
     InstVec insts;
     DummyFormatter formatter;
     DummyFormatter formatter;
-    FieldEngine engine(formatter, "test");
+    FF7::FieldEngine engine(formatter, "test");
 
 
     auto d = engine.GetDisassembler(insts);
     auto d = engine.GetDisassembler(insts);
     d->open("decompiler/test/ff7_control_flow_test.dat");
     d->open("decompiler/test/ff7_control_flow_test.dat");
@@ -77,18 +77,18 @@ TEST(FF7Field, ControlFlow)
     std::cout << std::endl;
     std::cout << std::endl;
 
 
     uint32 pos = 0;
     uint32 pos = 0;
-    ASSERT_EQ(insts[pos]->_opcode, OPCODE::RET);
+    ASSERT_EQ(insts[pos]->_opcode, FF7::eOpcodes::RET);
     ASSERT_EQ(insts[pos]->_params.size(), 0);
     ASSERT_EQ(insts[pos]->_params.size(), 0);
 
 
-    CheckForwardJump(OPCODE::IFUB, 6, insts, pos);
-    CheckForwardJump(OPCODE::IFSWL, 6, insts, pos);
-    CheckForwardJump(OPCODE::JMPF, 1, insts, pos);
-    CheckForwardJump(OPCODE::JMPFL, 1, insts, pos);
-    CheckForwardJump(OPCODE::IFKEY, 2, insts, pos);
-    CheckForwardJump(OPCODE::IFKEYON, 2, insts, pos);
-    CheckForwardJump(OPCODE::IFKEYOFF, 2, insts, pos);
-    CheckForwardJump(OPCODE::IFPRTYQ, 2, insts, pos);
-    CheckForwardJump(OPCODE::IFMEMBQ, 2, insts, pos);
-    CheckBackwardJump(OPCODE::JMPB, 1, insts, pos);
-    CheckBackwardJump(OPCODE::JMPBL, 1, insts, pos);
+    CheckForwardJump(FF7::eOpcodes::IFUB, 6, insts, pos);
+    CheckForwardJump(FF7::eOpcodes::IFSWL, 6, insts, pos);
+    CheckForwardJump(FF7::eOpcodes::JMPF, 1, insts, pos);
+    CheckForwardJump(FF7::eOpcodes::JMPFL, 1, insts, pos);
+    CheckForwardJump(FF7::eOpcodes::IFKEY, 2, insts, pos);
+    CheckForwardJump(FF7::eOpcodes::IFKEYON, 2, insts, pos);
+    CheckForwardJump(FF7::eOpcodes::IFKEYOFF, 2, insts, pos);
+    CheckForwardJump(FF7::eOpcodes::IFPRTYQ, 2, insts, pos);
+    CheckForwardJump(FF7::eOpcodes::IFMEMBQ, 2, insts, pos);
+    CheckBackwardJump(FF7::eOpcodes::JMPB, 1, insts, pos);
+    CheckBackwardJump(FF7::eOpcodes::JMPBL, 1, insts, pos);
 }
 }

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 144 - 144
V-Gears-Installer/include/decompiler/test/ff7_field_disasm_all_opcodes_by_category_test.cpp


+ 15 - 15
V-Gears-Installer/include/decompiler/test/main.cpp

@@ -23,7 +23,7 @@ public:
     TestReadParameterDisassembler(std::vector<unsigned char>&& data, InstVec& insts)
     TestReadParameterDisassembler(std::vector<unsigned char>&& data, InstVec& insts)
         : SimpleDisassembler(insts)
         : SimpleDisassembler(insts)
     {
     {
-        stream_ = std::make_unique<BinaryReader>(std::move(data));
+        mStream = std::make_unique<BinaryReader>(std::move(data));
     }
     }
 
 
     void readParams(InstPtr inst, const char *typeString)
     void readParams(InstPtr inst, const char *typeString)
@@ -32,7 +32,7 @@ public:
     }
     }
 
 
 
 
-    virtual void DoDisassemble() override final
+    virtual void doDisassemble() override final
     {
     {
         // NOP
         // NOP
     }
     }
@@ -124,7 +124,7 @@ TEST(SimpleDisassembler, readParameter_d)
 
 
 TEST(FF7Field, FunctionMetaData_Parse_Empty)
 TEST(FF7Field, FunctionMetaData_Parse_Empty)
 {
 {
-    FunctionMetaData meta("");
+    FF7::FunctionMetaData meta("");
     ASSERT_EQ("", meta.EntityName());
     ASSERT_EQ("", meta.EntityName());
     ASSERT_EQ(false, meta.IsEnd());
     ASSERT_EQ(false, meta.IsEnd());
     ASSERT_EQ(false, meta.IsStart());
     ASSERT_EQ(false, meta.IsStart());
@@ -132,7 +132,7 @@ TEST(FF7Field, FunctionMetaData_Parse_Empty)
 
 
 TEST(FF7Field, FunctionMetaData_Parse_Empties)
 TEST(FF7Field, FunctionMetaData_Parse_Empties)
 {
 {
-    FunctionMetaData meta("__________________");
+    FF7::FunctionMetaData meta("__________________");
     ASSERT_EQ("", meta.EntityName());
     ASSERT_EQ("", meta.EntityName());
     ASSERT_EQ(false, meta.IsEnd());
     ASSERT_EQ(false, meta.IsEnd());
     ASSERT_EQ(false, meta.IsStart());
     ASSERT_EQ(false, meta.IsStart());
@@ -140,7 +140,7 @@ TEST(FF7Field, FunctionMetaData_Parse_Empties)
 
 
 TEST(FF7Field, FunctionMetaData_Parse_Start)
 TEST(FF7Field, FunctionMetaData_Parse_Start)
 {
 {
-    FunctionMetaData meta("start_-1_entity");
+    FF7::FunctionMetaData meta("start_-1_entity");
     ASSERT_EQ("entity", meta.EntityName());
     ASSERT_EQ("entity", meta.EntityName());
     ASSERT_EQ(false, meta.IsEnd());
     ASSERT_EQ(false, meta.IsEnd());
     ASSERT_EQ(true, meta.IsStart());
     ASSERT_EQ(true, meta.IsStart());
@@ -148,7 +148,7 @@ TEST(FF7Field, FunctionMetaData_Parse_Start)
 
 
 TEST(FF7Field, FunctionMetaData_Parse_End)
 TEST(FF7Field, FunctionMetaData_Parse_End)
 {
 {
-    FunctionMetaData meta("end_-1_entity");
+    FF7::FunctionMetaData meta("end_-1_entity");
     ASSERT_EQ("entity", meta.EntityName());
     ASSERT_EQ("entity", meta.EntityName());
     ASSERT_EQ(true, meta.IsEnd());
     ASSERT_EQ(true, meta.IsEnd());
     ASSERT_EQ(false, meta.IsStart());
     ASSERT_EQ(false, meta.IsStart());
@@ -156,7 +156,7 @@ TEST(FF7Field, FunctionMetaData_Parse_End)
 
 
 TEST(FF7Field, FunctionMetaData_Parse_EntityName)
 TEST(FF7Field, FunctionMetaData_Parse_EntityName)
 {
 {
-    FunctionMetaData meta("end_-1_TheName");
+    FF7::FunctionMetaData meta("end_-1_TheName");
     ASSERT_EQ("TheName", meta.EntityName());
     ASSERT_EQ("TheName", meta.EntityName());
     ASSERT_EQ(true, meta.IsEnd());
     ASSERT_EQ(true, meta.IsEnd());
     ASSERT_EQ(false, meta.IsStart());
     ASSERT_EQ(false, meta.IsStart());
@@ -166,7 +166,7 @@ TEST(FF7Field, FunctionMetaData_Parse_EntityName)
 
 
 TEST(FF7Field, FunctionMetaData_Parse_EntityNameAndId)
 TEST(FF7Field, FunctionMetaData_Parse_EntityNameAndId)
 {
 {
-    FunctionMetaData meta("end_99_The_Name");
+    FF7::FunctionMetaData meta("end_99_The_Name");
     ASSERT_EQ("The_Name", meta.EntityName());
     ASSERT_EQ("The_Name", meta.EntityName());
     ASSERT_EQ(99, meta.CharacterId());
     ASSERT_EQ(99, meta.CharacterId());
 
 
@@ -177,7 +177,7 @@ TEST(FF7Field, FunctionMetaData_Parse_EntityNameAndId)
 
 
 TEST(FF7Field, FunctionMetaData_Parse_StartEnd)
 TEST(FF7Field, FunctionMetaData_Parse_StartEnd)
 {
 {
-    FunctionMetaData meta("start_end_-1_entity");
+    FF7::FunctionMetaData meta("start_end_-1_entity");
     ASSERT_EQ("entity", meta.EntityName());
     ASSERT_EQ("entity", meta.EntityName());
     ASSERT_EQ(true, meta.IsEnd());
     ASSERT_EQ(true, meta.IsEnd());
     ASSERT_EQ(true, meta.IsStart());
     ASSERT_EQ(true, meta.IsStart());
@@ -188,7 +188,7 @@ TEST(FF7World, DisAsm)
 {
 {
     for (int i = 0; i < 256; i++)
     for (int i = 0; i < 256; i++)
     {
     {
-        FF7::FF7WorldEngine engine(i);
+        FF7::WorldEngine engine(i);
 
 
 
 
         InstVec insts;
         InstVec insts;
@@ -1159,10 +1159,10 @@ private:
         }
         }
 
 
         // TODO: Handle arguments correctly, validate labels
         // TODO: Handle arguments correctly, validate labels
-        const FF7::InstructionRecord* rec = it->second;
-        const char* fmt = rec->argument_format;
+        const FF7::TInstructRecord* rec = it->second;
+        const char* fmt = rec->mArgumentFormat;
 
 
-        // method.AddInstruction(rec->opcode, rec->opcode_size);
+        // method.AddInstruction(rec->mOpCode, rec->mOpCodeSize);
         // TODO: Flow control needs special handling
         // TODO: Flow control needs special handling
 
 
         while (*fmt)
         while (*fmt)
@@ -1507,10 +1507,10 @@ TEST(Parser, ZeroGapIf)
 TEST(FF7Field, Asm)
 TEST(FF7Field, Asm)
 {
 {
     DummyFormatter dummy;
     DummyFormatter dummy;
-    FieldEngine eng(dummy, "test");
+    FF7::FieldEngine eng(dummy, "test");
 
 
     InstVec insts;
     InstVec insts;
-    FieldDisassembler d(dummy, &eng, insts);
+    FF7::FieldDisassembler d(dummy, &eng, insts);
 
 
 
 
 }
 }

+ 76 - 0
V-Gears-Installer/include/decompiler/world/WorldCodeGenerator.h

@@ -0,0 +1,76 @@
+/*
+ * V-Gears
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "decompiler/decompiler_codegen.h"
+
+namespace FF7{
+
+    class WorldCodeGenerator : public CodeGenerator{
+
+        public:
+
+            /**
+             * Constructor.
+             *
+             * @param engine[in] The engine.
+             * @param output[out] The generated script.
+             */
+            WorldCodeGenerator(Engine *engine, std::ostream &output);
+
+            /**
+             * Finds the first function call.
+             *
+             * @return A pointer to the first call instruction.
+             */
+            const InstPtr FindFirstCall();
+
+            /**
+             * Finds the last function call.
+             *
+             * @return A pointer to the last call instruction.
+             */
+            const InstPtr FindLastCall();
+
+            /**
+             * Processes special metadata in an instruction.
+             *
+             * @param inst[in] The instruction to process.
+             * @param c[in]
+             * @param pos[in]
+             * @todo understand and document.
+             */
+            virtual void ProcessSpecialMetadata(const InstPtr inst, char c, int pos);
+
+        protected:
+
+            /**
+             * Constructs the function signature.
+             *
+             * The function signature is the LUA function declaration, and it
+             * looks like this:
+             *
+             * <function_name> = function(self)
+             *
+             * @param function[in] The function to construct the signature for.
+             * @return The function signature.
+             */
+            std::string ConstructFuncSignature(const Function &function);
+    };
+}

+ 83 - 0
V-Gears-Installer/include/decompiler/world/WorldDisassembler.h

@@ -0,0 +1,83 @@
+/*
+ * 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 "decompiler/simple_disassembler.h"
+
+namespace FF7{
+
+    class WorldEngine;
+
+    class WorldDisassembler : public SimpleDisassembler{
+
+        public:
+
+            /**
+             * CConstructor.
+             *
+             * @param engine[in] The engine to use to disassemble.
+             * @param insts[in] The list of instructions.
+             * @param script_number[in] The script number to process.
+             */
+            WorldDisassembler(WorldEngine* engine, InstVec& insts, int script_number);
+
+            /**
+             * Destructor.
+             */
+            ~WorldDisassembler();
+
+            /**
+             * Disassembles the instructions.
+             */
+            void DoDisassemble() override;
+
+        private:
+
+            /**
+             * Parses an opcode.
+             *
+             * Adds properties to an instruction, and adds the instruction to
+             * the list.
+             *
+             * @param opcode[in] The opcode code.
+             * @param name[in] the opcode name.
+             * @param instruction[in][out] A newly created instruction of the
+             * type the opcode belongs to.
+             * @param stack_change[in] Indicates how much the instruction
+             * changes the stack pointer by.
+             * @param argument_format[in] The opcode argument format.
+             */
+            template<typename T> void ParseOpcode(
+              int opcode, std::string name, T instruction,
+              int stack_change, const char* argument_format
+            ){
+                uint32 full_opcode = (full_opcode << 8) + opcode;
+                this->insts_.push_back(instruction);
+                this->insts_.back()->_opcode = full_opcode;
+                this->insts_.back()->_address = this->address_;
+                this->insts_.back()->_stackChange = 0;
+                this->insts_.back()->_name = std::string(name);
+                this->insts_.back()->_codeGenData = "";
+                this->readParams(this->insts_.back(), argument_format);
+            }
+
+            /**
+             * The script number.
+             */
+            int script_number_ = 0;
+    };
+
+} 

+ 115 - 0
V-Gears-Installer/include/decompiler/world/WorldEngine.h

@@ -0,0 +1,115 @@
+/*
+ * V-Gears
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <string>
+#include <vector>
+#include "decompiler/decompiler_engine.h"
+
+namespace FF7{
+
+    /**
+     * Represents the FF7 world map engine.
+     */
+    class WorldEngine : public Engine{
+
+        public:
+
+            /**
+             * A bank value.
+             *
+             * @todo Understand and document.
+             */
+            class BankValue : public VarValue{
+
+                public:
+
+                    /**
+                     * Constructor.
+                     *
+                     * @param name[in] Variable name.
+                     */
+                    BankValue(std::string name);
+            };
+
+            /**
+             * Constructor.
+             *
+             * @param script_number[in] The script number.
+             */
+            WorldEngine(int script_number);
+
+            /**
+             * Retrieves the disassembler.
+             *
+             * @param insts[in] List of instructions.
+             * @return Pointer to the disassembler.
+             */
+            std::unique_ptr<Disassembler> GetDisassembler(InstVec &insts) override;
+
+            /**
+             * Retrieves the code generator.
+             *
+             * @param insts[in] List of instructions. Unused.
+             * @param output[in] Pointer to the output (file, stream...).
+             * @return Pointer to the generator.
+             */
+            std::unique_ptr<CodeGenerator> GetCodeGenerator(
+              const InstVec& insts, std::ostream &output
+            ) override;
+
+            /**
+             * Post-processing actions to apply to the scripts.
+             *
+             * It actually does nothing. CFG stands for control flow group.
+             *
+             * @param insts[in] Instruction list.
+             * @param graph[in] Code graph.
+             */
+            virtual void PostCFG(InstVec &insts, Graph graph) override;
+
+            /**
+             * Retrieves the variants.
+             *
+             * @todo Variants of what? What is this supposed to do?
+             */
+            virtual void GetVariants(std::vector<std::string> &variants) const override;
+
+            /**
+             * Indicates if instructions are purely grouped.
+             *
+             * @return True if instructions are purely grouped. Always false.
+             * @todo What is pure grouping?
+             */
+            virtual bool UsePureGrouping() const override;
+
+        private:
+
+            /**
+             * The script number.
+             */
+            int script_number_;
+
+            /**
+             * Container for strings from the TEXT chunk.
+             */
+            std::vector<std::string> text_strings_;
+    };
+
+}

+ 0 - 21
V-Gears-Installer/include/decompiler/world/ff7_world_codegen.h

@@ -1,21 +0,0 @@
-#pragma  once
-
-#include "decompiler_codegen.h"
-
-namespace FF7
-{
-    class FF7WorldCodeGenerator : public CodeGenerator
-    {
-    public:
-        FF7WorldCodeGenerator(Engine *engine, std::ostream &output)
-            : CodeGenerator(engine, output, FIFO_ARGUMENT_ORDER, LIFO_ARGUMENT_ORDER)
-        {
-
-        }
-        const InstPtr findFirstCall();
-        const InstPtr findLastCall();
-        virtual void processSpecialMetadata(const InstPtr inst, char c, int pos);
-    protected:
-        std::string ConstructFuncSignature(const Function &func);
-    };
-}

+ 0 - 18
V-Gears-Installer/include/decompiler/world/ff7_world_disassembler.h

@@ -1,18 +0,0 @@
-#pragma once
-
-#include "simple_disassembler.h"
-
-namespace FF7 
-{
-    class FF7WorldEngine;
-    class FF7WorldDisassembler : public SimpleDisassembler
-    {
-    public:
-        FF7WorldDisassembler(FF7WorldEngine* engine, InstVec& insts, int scriptNumber);
-        ~FF7WorldDisassembler();
-	    void DoDisassemble() override;
-    private:
-        int mScriptNumber = 0;
-    };
-
-} 

+ 0 - 108
V-Gears-Installer/include/decompiler/world/ff7_world_engine.h

@@ -1,108 +0,0 @@
-#pragma once
-
-#include "decompiler/decompiler_engine.h"
-#include <string>
-#include <vector>
-
-namespace FF7
-{
-    class FF7WorldEngine : public Engine
-    {
-    public:
-        FF7WorldEngine(int scriptNumber)
-            : mScriptNumber(scriptNumber)
-        {
-            setOutputStackEffect(true);
-        }
-        std::unique_ptr<Disassembler> GetDisassembler(InstVec &insts) override;
-        std::unique_ptr<CodeGenerator> GetCodeGenerator(const InstVec& insts, std::ostream &output) override;
-        virtual void PostCFG(InstVec &insts, Graph g) override;
-        virtual void getVariants(std::vector<std::string> &variants) const override;
-        virtual bool UsePureGrouping() const override { return false; }
-        std::vector<std::string> _textStrings; ///< Container for strings from the TEXT chunk.
-    private:
-        int mScriptNumber;
-    };
-
-    class FF7WorldLoadBankInstruction : public LoadInstruction
-    {
-    public:
-        virtual void ProcessInst(Function& func, ValueStack &stack, Engine *engine, CodeGenerator *codeGen) override;
-    };
-
-    class BankValue : public VarValue
-    {
-    public:
-        BankValue(std::string varName) : VarValue(varName) { }
-    };
-
-    class FF7WorldLoadInstruction : public LoadInstruction 
-    {
-    public:
-        virtual void ProcessInst(Function& func, ValueStack &stack, Engine *engine, CodeGenerator *codeGen) override;
-    };
-
-    class FF7SubStackInstruction : public StackInstruction
-    {
-    public:
-        virtual void ProcessInst(Function& func, ValueStack &stack, Engine *engine, CodeGenerator *codeGen) override;
-    };
-
-    class BinaryEqualStackInstruction : public BinaryOpStackInstruction 
-    {
-    public:
-        virtual void ProcessInst(Function& func, ValueStack &stack, Engine *engine, CodeGenerator *codeGen) override
-        {
-            _codeGenData = "==";
-            BinaryOpStackInstruction::ProcessInst(func, stack, engine, codeGen);
-        }
-    };
-
-    class FF7WorldStoreInstruction : public StoreInstruction
-    {
-    public:
-        virtual void ProcessInst(Function& func, ValueStack &stack, Engine *engine, CodeGenerator *codeGen) override;
-    };
-
-
-    class FF7WorldStackInstruction : public StackInstruction
-    {
-    public:
-        virtual void ProcessInst(Function& func, ValueStack &stack, Engine *engine, CodeGenerator *codeGen) override;
-    };
-
-    class FF7WorldCondJumpInstruction : public CondJumpInstruction
-    {
-    public:
-        virtual void ProcessInst(Function& func, ValueStack &stack, Engine *engine, CodeGenerator *codeGen) override;
-        virtual uint32 GetDestAddress() const;
-        virtual std::ostream& print(std::ostream &output) const override;
-    };
-
-    class FF7WorldUncondJumpInstruction : public UncondJumpInstruction
-    {
-    public:
-        bool _isCall;  ///< Whether or not this is really a call to a script function.
-        FF7WorldUncondJumpInstruction() : _isCall(false) { }
-        virtual bool IsFuncCall() const;
-        virtual bool IsUncondJump() const;
-        virtual uint32 GetDestAddress() const;
-        virtual void ProcessInst(Function& func, ValueStack &stack, Engine *engine, CodeGenerator *codeGen) override;
-        virtual std::ostream& print(std::ostream &output) const override;
-
-    };
-
-
-    class FF7WorldKernelCallInstruction : public KernelCallInstruction
-    {
-    public:
-        virtual void ProcessInst(Function& func, ValueStack &stack, Engine *engine, CodeGenerator *codeGen) override;
-    };
-
-    class FF7WorldNoOutputInstruction : public Instruction
-    {
-    public:
-        virtual void ProcessInst(Function& func, ValueStack &stack, Engine *engine, CodeGenerator *codeGen) override;
-    };
-
-}

+ 45 - 0
V-Gears-Installer/include/decompiler/world/instruction/WorldBinaryEqualStackInstruction.h

@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "decompiler/instruction.h"
+#include "decompiler/world/WorldEngine.h"
+
+namespace FF7{
+
+    /**
+     * A binary equals stack instruction.
+     */
+    class WorldBinaryEqualStackInstruction : public BinaryOpStackInstruction{
+
+        public:
+
+            /**
+             * Processes the instruction.
+             *
+             * @param function[in] Function to process.
+             * @param stack[out] Function stack.
+             * @param engine[in] Engine.
+             * @param code_gen[in] Code generator.
+             */
+            virtual void ProcessInst(
+              Function& function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
+    };
+
+}

+ 60 - 0
V-Gears-Installer/include/decompiler/world/instruction/WorldCondJumpInstruction.h

@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "decompiler/instruction.h"
+#include "decompiler/world/WorldEngine.h"
+
+namespace FF7{
+
+    /**
+     * A conditional jump instruction.
+     */
+    class WorldCondJumpInstruction : public CondJumpInstruction{
+
+        public:
+
+            /**
+             * Processes the instruction.
+             *
+             * @param function[in] Function to process.
+             * @param stack[out] Function stack.
+             * @param engine[in] Engine.
+             * @param code_gen[in] Code generator.
+             */
+            virtual void ProcessInst(
+              Function& function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
+
+            /**
+             * Retrieves the destination address of the jump.
+             *
+             * @return The destination address.
+             */
+            virtual uint32 GetDestAddress() const;
+
+            /**
+             * Prints the instruction.
+             *
+             * @param output[in] The output to print.
+             * @return The same as output.
+             */
+            virtual std::ostream& Print(std::ostream &output) const override;
+        };
+
+}

+ 45 - 0
V-Gears-Installer/include/decompiler/world/instruction/WorldKernelCallInstruction.h

@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "decompiler/instruction.h"
+#include "decompiler/world/WorldEngine.h"
+
+namespace FF7{
+
+    /**
+     * A kernel call instruction.
+     */
+    class WorldKernelCallInstruction : public KernelCallInstruction{
+
+        public:
+
+            /**
+             * Processes the instruction.
+             *
+             * @param function[in] Function to process. Unused.
+             * @param stack[out] Function stack.
+             * @param engine[in] Engine. Unused.
+             * @param code_gen[in] Code generator.
+             */
+            virtual void ProcessInst(
+              Function& function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
+
+    };
+}

+ 46 - 0
V-Gears-Installer/include/decompiler/world/instruction/WorldLoadBankInstruction.h

@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "decompiler/instruction.h"
+#include "decompiler/world/WorldEngine.h"
+
+namespace FF7{
+
+    /**
+     * A bank loading instruction.
+     */
+    class WorldLoadBankInstruction : public LoadInstruction{
+
+        public:
+
+            /**
+             * Processes the instruction.
+             *
+             * @param function[in] Function to process. Unused.
+             * @param stack[out] Function stack.
+             * @param engine[in] Engine. Unused.
+             * @param code_gen[in] Code generator. Unused.
+             */
+            virtual void ProcessInst(
+              Function& function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
+
+    };
+
+}

+ 46 - 0
V-Gears-Installer/include/decompiler/world/instruction/WorldLoadInstruction.h

@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "decompiler/instruction.h"
+#include "decompiler/world/WorldEngine.h"
+
+namespace FF7{
+
+    /**
+     * A load instruction.
+     */
+    class WorldLoadInstruction : public LoadInstruction{
+
+        public:
+
+            /**
+             * Processes the instruction.
+             *
+             * @param function[in] Function to process. Unused.
+             * @param stack[out] Function stack.
+             * @param engine[in] Engine. Unused.
+             * @param code_gen[in] Code generator. Unused.
+             */
+            virtual void ProcessInst(
+              Function& function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
+
+    };
+
+}

+ 46 - 0
V-Gears-Installer/include/decompiler/world/instruction/WorldNoOutputInstruction.h

@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "decompiler/instruction.h"
+#include "decompiler/world/WorldEngine.h"
+
+namespace FF7{
+
+    /**
+     * An instruction without output.
+     */
+    class WorldNoOutputInstruction : public Instruction{
+
+        public:
+
+            /**
+             * Processes the instruction.
+             *
+             * @param function[in] Function to process.
+             * @param stack[out] Function stack.
+             * @param engine[in] Engine.
+             * @param code_gen[in] Code generator.
+             */
+            virtual void ProcessInst(
+              Function& function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
+
+    };
+
+}

+ 46 - 0
V-Gears-Installer/include/decompiler/world/instruction/WorldStackInstruction.h

@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "decompiler/instruction.h"
+#include "decompiler/world/WorldEngine.h"
+
+namespace FF7{
+
+    /**
+     * A stack instruction.
+     */
+    class WorldStackInstruction : public StackInstruction{
+
+        public:
+
+            /**
+             * Processes the instruction.
+             *
+             * @param function[in] Function to process.
+             * @param stack[out] Function stack.
+             * @param engine[in] Engine.
+             * @param code_gen[in] Code generator.
+             */
+            virtual void ProcessInst(
+              Function& function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
+
+    };
+
+}

+ 46 - 0
V-Gears-Installer/include/decompiler/world/instruction/WorldStoreInstruction.h

@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "decompiler/instruction.h"
+#include "decompiler/world/WorldEngine.h"
+
+namespace FF7{
+
+    /**
+     * A store instruction.
+     */
+    class WorldStoreInstruction : public StoreInstruction{
+
+        public:
+
+            /**
+             * Processes the instruction.
+             *
+             * @param function[in] Function to process. Unused.
+             * @param stack[out] Function stack.
+             * @param engine[in] Engine. Unused.
+             * @param code_gen[in] Code generator.
+             */
+            virtual void ProcessInst(
+              Function& function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
+
+    };
+
+}

+ 45 - 0
V-Gears-Installer/include/decompiler/world/instruction/WorldSubStackInstruction.h

@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "decompiler/instruction.h"
+#include "decompiler/world/WorldEngine.h"
+
+namespace FF7{
+
+    /**
+     * A substack instruction.
+     */
+    class WorldSubStackInstruction : public StackInstruction{
+
+        public:
+
+            /**
+             * Processes the instruction.
+             *
+             * @param func[in] Function to process. Unused.
+             * @param stack[out] Function stack.
+             * @param engine[in] Engine. Unused.
+             * @param code_gen[in] Code generator. Unused.
+             */
+            virtual void ProcessInst(
+              Function& function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
+    };
+
+}

+ 90 - 0
V-Gears-Installer/include/decompiler/world/instruction/WorldUncondJumpInstruction.h

@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "decompiler/instruction.h"
+#include "decompiler/world/WorldEngine.h"
+
+namespace FF7{
+
+    /**
+     * An unconditional jump instruction.
+     */
+    class WorldUncondJumpInstruction : public UncondJumpInstruction{
+
+        public:
+
+            /**
+             * Constructor.
+             */
+            WorldUncondJumpInstruction();
+
+
+            /**
+             * Indicates if the instruction is a function call.
+             *
+             * @return true if the instruction is a function call, false if not.
+             */
+            virtual bool IsFuncCall() const;
+
+            /**
+             * Indicates if the instruction is an unconditional jump.
+             *
+             * @return true if the instruction is an unconditional jump, false
+             * if it's not.
+             */
+            virtual bool IsUncondJump() const;
+
+            /**
+             * Retrieves the destination address of the jump.
+             *
+             * @return The offset (number of bytes) to jump from the beginning
+             * of the instruction.
+             */
+            virtual uint32 GetDestAddress() const;
+
+            /**
+             * Prints the instruction
+             *
+             * @param[in] output The stream to print the instruction to.
+             * @return The same output.
+             */
+            virtual std::ostream& Print(std::ostream &output) const override;
+
+            /**
+             * Processes the instruction.
+             *
+             * @param function[in] Function to process.
+             * @param stack[out] Function stack.
+             * @param engine[in] Engine.
+             * @param code_gen[in] Code generator.
+             */
+            virtual void ProcessInst(
+              Function& function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+            ) override;
+
+        private:
+
+            /**
+             * Whether or not this is really a call to a script function.
+             */
+            bool is_call_;
+
+    };
+
+}

+ 3 - 9
V-Gears-Installer/src/common/OgreBase.cpp

@@ -17,7 +17,6 @@
 #include <iostream>
 #include <iostream>
 #include <OgreFontManager.h>
 #include <OgreFontManager.h>
 #include <OgreOverlay.h>
 #include <OgreOverlay.h>
-//#include <OgreOverlayManager.h>
 #include <Overlay/OgreOverlayManager.h>
 #include <Overlay/OgreOverlayManager.h>
 
 
 Ogre::Root* root;
 Ogre::Root* root;
@@ -92,9 +91,7 @@ void InitializeOgreBase(const Ogre::String& name){
     misc["title"] = name;
     misc["title"] = name;
     window = root->createRenderWindow("VGearsWindow", 800, 600, false, &misc);
     window = root->createRenderWindow("VGearsWindow", 800, 600, false, &misc);
     // Initialize resources in the current launch directory.
     // Initialize resources in the current launch directory.
-    Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
-      "./", "FileSystem", "General"
-    );
+    Ogre::ResourceGroupManager::getSingleton().addResourceLocation("./", "FileSystem", "General");
     Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
     Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
       "./exported", "FileSystem", "General"
       "./exported", "FileSystem", "General"
     );
     );
@@ -108,9 +105,7 @@ void InitializeOgreBase(const Ogre::String& name){
     scene_manager = root->createSceneManager(Ogre::ST_GENERIC, "Scene");
     scene_manager = root->createSceneManager(Ogre::ST_GENERIC, "Scene");
     scene_manager->clearScene();
     scene_manager->clearScene();
     scene_manager->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
     scene_manager->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
-    Ogre::Light* directional_light = scene_manager->createLight(
-      "directionalLight"
-    );
+    Ogre::Light* directional_light = scene_manager->createLight("directionalLight");
     directional_light->setType(Ogre::Light::LT_DIRECTIONAL);
     directional_light->setType(Ogre::Light::LT_DIRECTIONAL);
     directional_light->setDiffuseColour(Ogre::ColourValue(0.5, 0.5, 0.5));
     directional_light->setDiffuseColour(Ogre::ColourValue(0.5, 0.5, 0.5));
     directional_light->setSpecularColour(Ogre::ColourValue(0.5, 0.5, 0.5));
     directional_light->setSpecularColour(Ogre::ColourValue(0.5, 0.5, 0.5));
@@ -122,8 +117,7 @@ void InitializeOgreBase(const Ogre::String& name){
     viewport = window->addViewport(camera);
     viewport = window->addViewport(camera);
     viewport->setBackgroundColour(Ogre::ColourValue(0.0f, 0.4f, 0.0f));
     viewport->setBackgroundColour(Ogre::ColourValue(0.0f, 0.4f, 0.0f));
     camera->setAspectRatio(
     camera->setAspectRatio(
-      Ogre::Real(viewport->getActualWidth())
-      / Ogre::Real(viewport->getActualHeight())
+      Ogre::Real(viewport->getActualWidth()) / Ogre::Real(viewport->getActualHeight())
     );
     );
     LOGGER = new Logger("game.log");
     LOGGER = new Logger("game.log");
 }
 }

+ 12 - 44
V-Gears-Installer/src/common/OgreGenUtilites.cpp

@@ -25,16 +25,12 @@ void CreateTextureFromVram(
     for (u32 y = 0; y < 256; ++ y){
     for (u32 y = 0; y < 256; ++ y){
         // IVV type cast
         // IVV type cast
         u32* data = static_cast<u32*>(
         u32* data = static_cast<u32*>(
-          (unsigned int *) (
-            (pixel_box.data) + (y + start_y) * pixel_box.rowPitch
-          )
+          (unsigned int *) ((pixel_box.data) + (y + start_y) * pixel_box.rowPitch)
         );
         );
         for (u32 x = 0; x < 256; ++ x){
         for (u32 x = 0; x < 256; ++ x){
             if (bpp == BPP_4){
             if (bpp == BPP_4){
                 u8 pixel = vram->GetU8(texture_x * 2 + x / 2, texture_y + y);
                 u8 pixel = vram->GetU8(texture_x * 2 + x / 2, texture_y + y);
-                u16 clut1 = vram->GetU16(
-                  clut_x * 2 + (pixel & 0xf) * 2, clut_y
-                );
+                u16 clut1 = vram->GetU16(clut_x * 2 + (pixel & 0xf) * 2, clut_y);
                 u16 clut2 = vram->GetU16(clut_x * 2 + (pixel >> 4) * 2, clut_y);
                 u16 clut2 = vram->GetU16(clut_x * 2 + (pixel >> 4) * 2, clut_y);
                 u32 ogre_pixel1
                 u32 ogre_pixel1
                   = (((clut1 & 0x1f) * 255 / 31) << 0x18)
                   = (((clut1 & 0x1f) * 255 / 31) << 0x18)
@@ -78,9 +74,8 @@ void CreateTexture(
     Ogre::TexturePtr ptex;
     Ogre::TexturePtr ptex;
     Ogre::HardwarePixelBufferSharedPtr buffer;
     Ogre::HardwarePixelBufferSharedPtr buffer;
     ptex = Ogre::TextureManager::getSingleton().createManual(
     ptex = Ogre::TextureManager::getSingleton().createManual(
-      "DynaTex", "General", Ogre::TEX_TYPE_2D,
-      mesh_data.tex_width, mesh_data.tex_height,
-      0, Ogre::PF_R8G8B8A8, Ogre::TU_STATIC
+      "DynaTex", "General", Ogre::TEX_TYPE_2D, mesh_data.tex_width,
+      mesh_data.tex_height, 0, Ogre::PF_R8G8B8A8, Ogre::TU_STATIC
     );
     );
     buffer = ptex->getBuffer(0, 0);
     buffer = ptex->getBuffer(0, 0);
     buffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
     buffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
@@ -88,10 +83,8 @@ void CreateTexture(
 
 
     for (unsigned int i = 0; i < textures.size(); ++ i){
     for (unsigned int i = 0; i < textures.size(); ++ i){
         LOGGER->Log(
         LOGGER->Log(
-          "CreateTexture palette_x=\""
-          + Ogre::StringConverter::toString(textures[i].palette_x)
-          + "\" palette_y=\""
-          + Ogre::StringConverter::toString(textures[i].palette_y) + "\" bpp=\""
+          "CreateTexture palette_x=\"" + Ogre::StringConverter::toString(textures[i].palette_x)
+          + "\" palette_y=\"" + Ogre::StringConverter::toString(textures[i].palette_y) + "\" bpp=\""
           + Ogre::StringConverter::toString(textures[i].bpp) + "\"."
           + Ogre::StringConverter::toString(textures[i].bpp) + "\"."
         );
         );
         CreateTextureFromVram(
         CreateTextureFromVram(
@@ -102,8 +95,7 @@ void CreateTexture(
     }
     }
     Ogre::Image image;
     Ogre::Image image;
     image.loadDynamicImage(
     image.loadDynamicImage(
-      (Ogre::uchar*) pixel_box.data, mesh_data.tex_width, mesh_data.tex_height,
-      Ogre::PF_R8G8B8A8
+      (Ogre::uchar*) pixel_box.data, mesh_data.tex_width, mesh_data.tex_height, Ogre::PF_R8G8B8A8
     );
     );
     image.save(texture_file_name);
     image.save(texture_file_name);
     buffer->unlock();
     buffer->unlock();
@@ -116,9 +108,8 @@ CreateMaterial(
   const Ogre::String& texture_name, const Ogre::String& vertex_program,
   const Ogre::String& texture_name, const Ogre::String& vertex_program,
   const Ogre::String& fragment_program
   const Ogre::String& fragment_program
 ){
 ){
-    Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(
-      material_name, "General"
-    );
+    Ogre::MaterialPtr material
+      = Ogre::MaterialManager::getSingleton().create(material_name, "General");
     Ogre::Technique* tech = material->getTechnique(0);
     Ogre::Technique* tech = material->getTechnique(0);
     Ogre::Pass* pass1 = tech->getPass(0);
     Ogre::Pass* pass1 = tech->getPass(0);
     pass1->setVertexColourTracking(Ogre::TVC_AMBIENT);
     pass1->setVertexColourTracking(Ogre::TVC_AMBIENT);
@@ -132,8 +123,7 @@ CreateMaterial(
         tex->setTextureFiltering(Ogre::TFO_NONE);
         tex->setTextureFiltering(Ogre::TFO_NONE);
     }
     }
     if (vertex_program != "") pass1->setVertexProgram(vertex_program, true);
     if (vertex_program != "") pass1->setVertexProgram(vertex_program, true);
-    if (fragment_program != "")
-        pass1->setFragmentProgram(fragment_program, true);
+    if (fragment_program != "") pass1->setFragmentProgram(fragment_program, true);
     Ogre::MaterialSerializer mat;
     Ogre::MaterialSerializer mat;
     mat.exportMaterial(material, material_file_name);
     mat.exportMaterial(material, material_file_name);
 }
 }
@@ -149,17 +139,6 @@ void AddTexture(
             return;
             return;
         }
         }
     }
     }
-    /*
-    if (logger != NULL){
-        logger->Log(
-          "New Texture: X:" + ToHexString(texture.texture_x, 4, '0')
-          + ", Y:" + ToHexString(texture.texture_y, 4, '0') + ", CLUTX:"
-          + ToHexString(texture.palette_x, 4, '0') + ", CLUTY:"
-          + ToHexString(texture.palette_y, 4, '0') + ", bpp:"
-          + ToHexString(texture.bpp, 4, '0') + "\n"
-        );
-    }
-    */
 
 
     float start_x = 0;
     float start_x = 0;
     float start_y = 0;
     float start_y = 0;
@@ -168,11 +147,8 @@ void AddTexture(
         start_y = float(textures[ textures.size() - 1 ].start_y);
         start_y = float(textures[ textures.size() - 1 ].start_y);
         if (start_x + 256 >= data.tex_width){
         if (start_x + 256 >= data.tex_width){
             if (start_y + 256 >= data.tex_height){
             if (start_y + 256 >= data.tex_height){
-                if (logger != NULL){
-                    logger->Log(
-                      "[ERROR] Can't add anymore textures. Increase tex size.\n"
-                    );
-                }
+                if (logger != NULL)
+                    logger->Log("[ERROR] Can't add anymore textures. Increase tex size.\n");
                 return;
                 return;
             }
             }
             start_x = 0;
             start_x = 0;
@@ -183,14 +159,6 @@ void AddTexture(
     texture.start_x = static_cast<int>(start_x);
     texture.start_x = static_cast<int>(start_x);
     texture.start_y = static_cast<int>(start_y);
     texture.start_y = static_cast<int>(start_y);
     textures.push_back(texture);
     textures.push_back(texture);
-    /*
-    if (logger != NULL){
-        logger->Log(
-          "Startx:" + ToHexString(texture.start_x, 4, '0')
-          + ", Starty:" + ToHexString(texture.start_y, 4, '0') + "\n"
-        );
-    }
-    */
 }
 }
 
 
 void AddTransparency(u32& colour, const bool transparency, const bool stp){
 void AddTransparency(u32& colour, const bool transparency, const bool stp){

+ 5 - 12
V-Gears-Installer/src/common/Surface.cpp

@@ -16,14 +16,12 @@
 #include "common/Surface.h"
 #include "common/Surface.h"
 #include <memory.h>
 #include <memory.h>
 #ifdef WIN32
 #ifdef WIN32
-    #include <windows.h>
+#include <windows.h>
 #endif
 #endif
 
 
 Surface::Surface(): pixels(NULL), width(0), height(0){}
 Surface::Surface(): pixels(NULL), width(0), height(0){}
 
 
-Surface::Surface(const Surface &copy):
-  pixels(NULL), width(copy.width), height(copy.height)
-{
+Surface::Surface(const Surface &copy):pixels(NULL), width(copy.width), height(copy.height){
   if (width && height) pixels = copy.pixels;
   if (width && height) pixels = copy.pixels;
 }
 }
 
 
@@ -61,9 +59,7 @@ Surface* CreateSubSurface(
 ){
 ){
     Surface* image = CreateSurface(width, height);
     Surface* image = CreateSurface(width, height);
     if (surface != NULL){
     if (surface != NULL){
-        for (
-          int y_from = y, y_to = y + image->height; y_from < y_to; ++ y_from
-        ){
+        for (int y_from = y, y_to = y + image->height; y_from < y_to; ++ y_from){
             memcpy(
             memcpy(
               image->pixels.data() + (y_from - y) * image->width * 4,
               image->pixels.data() + (y_from - y) * image->width * 4,
               surface->pixels.data() + (y_from * surface->width + x) * 4,
               surface->pixels.data() + (y_from * surface->width + x) * 4,
@@ -74,11 +70,8 @@ Surface* CreateSubSurface(
     return image;
     return image;
 }
 }
 
 
-Surface* CreateSurfaceFrom(
-  const int width, const int height, unsigned char* pixels
-){
+Surface* CreateSurfaceFrom(const int width, const int height, unsigned char* pixels){
     Surface* image = CreateSurface(width, height);
     Surface* image = CreateSurface(width, height);
-    if (pixels != NULL)
-        memcpy(image->pixels.data(), pixels, width * height * 4);
+    if (pixels != NULL) memcpy(image->pixels.data(), pixels, width * height * 4);
     return image;
     return image;
 }
 }

+ 14 - 30
V-Gears-Installer/src/common/TimToVram.cpp

@@ -19,29 +19,21 @@
 #include "common/File.h"
 #include "common/File.h"
 
 
 void LoadTimFileToVram(File* file, int tim_offset, Vram* vram){
 void LoadTimFileToVram(File* file, int tim_offset, Vram* vram){
-    LOGGER->Log(
-      "Load image at offset " + HexToString(tim_offset, 4, '0') + " to VRAM.\n"
-    );
+    LOGGER->Log("Load image at offset " + HexToString(tim_offset, 4, '0') + " to VRAM.\n");
     int next_offset = file->GetU32LE(tim_offset + 0x08);
     int next_offset = file->GetU32LE(tim_offset + 0x08);
     int clut_vram_position_x = file->GetU16LE(tim_offset + 0x0c);
     int clut_vram_position_x = file->GetU16LE(tim_offset + 0x0c);
     int clut_vram_position_y = file->GetU16LE(tim_offset + 0x0e);
     int clut_vram_position_y = file->GetU16LE(tim_offset + 0x0e);
     int clut_width = file->GetU16LE(tim_offset + 0x10);
     int clut_width = file->GetU16LE(tim_offset + 0x10);
     int clut_height = file->GetU16LE(tim_offset + 0x12);
     int clut_height = file->GetU16LE(tim_offset + 0x12);
-
     LOGGER->Log(
     LOGGER->Log(
-      "ClutVramPositionX (" + HexToString(clut_vram_position_x, 4, '0')
-      + ") ClutVramPositionY (" + HexToString(clut_vram_position_y, 4, '0')
-      + ") Width (" + HexToString(clut_width, 4, '0') + ") Height ("
-      +  HexToString(clut_height, 4, '0') + ")\n"
+      "ClutVramPositionX (" + HexToString(clut_vram_position_x, 4, '0') + ") ClutVramPositionY ("
+      + HexToString(clut_vram_position_y, 4, '0') + ") Width (" + HexToString(clut_width, 4, '0')
+      + ") Height (" +  HexToString(clut_height, 4, '0') + ")\n"
     );
     );
     for (int y = 0; y < clut_height; ++ y){
     for (int y = 0; y < clut_height; ++ y){
         for (int x = 0; x < clut_width; ++ x){
         for (int x = 0; x < clut_width; ++ x){
-            u16 color = file->GetU16LE(
-              tim_offset + 0x14 + y * clut_width * 2 + x * 2
-            );
-            vram->PutU16(
-              x * 2 + clut_vram_position_x, y + clut_vram_position_y, color
-            );
+            u16 color = file->GetU16LE(tim_offset + 0x14 + y * clut_width * 2 + x * 2);
+            vram->PutU16(x * 2 + clut_vram_position_x, y + clut_vram_position_y, color);
         }
         }
     }
     }
 
 
@@ -49,33 +41,25 @@ void LoadTimFileToVram(File* file, int tim_offset, Vram* vram){
     while (next_offset != 0){
     while (next_offset != 0){
     */
     */
     // Set image buffer
     // Set image buffer
-    int image_vram_position_x
-      = file->GetU16LE(tim_offset + 0x08 + next_offset + 0x4) * 2;
-    int image_vram_position_y
-      = file->GetU16LE(tim_offset + 0x08 + next_offset + 0x6);
+    int image_vram_position_x = file->GetU16LE(tim_offset + 0x08 + next_offset + 0x4) * 2;
+    int image_vram_position_y = file->GetU16LE(tim_offset + 0x08 + next_offset + 0x6);
     int image_width = file->GetU16LE(tim_offset + 0x08 + next_offset + 0x8) * 2;
     int image_width = file->GetU16LE(tim_offset + 0x08 + next_offset + 0x8) * 2;
     int image_height = file->GetU16LE(tim_offset + 0x08 + next_offset + 0xa);
     int image_height = file->GetU16LE(tim_offset + 0x08 + next_offset + 0xa);
-
     LOGGER->Log(
     LOGGER->Log(
-      "ImageVramPositionX (" + HexToString(image_vram_position_x, 4, '0')
-      + ") ImageVramPositionY (" + HexToString(image_vram_position_y, 4, '0')
-      + ") ImageWidth (" + HexToString(image_width, 4, '0') + ") ImageHeight ("
-      +  HexToString(image_height, 4, '0') + ")\n"
+      "ImageVramPositionX (" + HexToString(image_vram_position_x, 4, '0') + ") ImageVramPositionY ("
+      + HexToString(image_vram_position_y, 4, '0') + ") ImageWidth ("
+      + HexToString(image_width, 4, '0') + ") ImageHeight (" +  HexToString(image_height, 4, '0')
+      + ")\n"
     );
     );
     for (int y = 0; y < image_height; ++ y){
     for (int y = 0; y < image_height; ++ y){
         for (int x = 0; x < image_width; ++ x){
         for (int x = 0; x < image_width; ++ x){
-            u8 data = file->GetU8(
-              tim_offset + 0x08 + next_offset + 0xc + y * image_width + x
-            );
-            vram->PutU8(
-              x + image_vram_position_x, y + image_vram_position_y, data
-            );
+            u8 data = file->GetU8(tim_offset + 0x08 + next_offset + 0xc + y * image_width + x);
+            vram->PutU8(x + image_vram_position_x, y + image_vram_position_y, data);
         }
         }
     }
     }
     /*
     /*
     }
     }
     */
     */
-
     //next_offset = file->GetU16LE(tim_offset + 0x08 + next_offset + 0x0);
     //next_offset = file->GetU16LE(tim_offset + 0x08 + next_offset + 0x0);
 }
 }
 
 

+ 10 - 20
V-Gears-Installer/src/common/Vram.cpp

@@ -36,7 +36,6 @@ void Vram::Save(const Ogre::String& file){
     buffer = ptex->getBuffer(0, 0);
     buffer = ptex->getBuffer(0, 0);
     buffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
     buffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
     const Ogre::PixelBox& pb = buffer->getCurrentLock();
     const Ogre::PixelBox& pb = buffer->getCurrentLock();
-    // IVV type cast
     u32* data = static_cast<u32*>((unsigned int *) pb.data);
     u32* data = static_cast<u32*>((unsigned int *) pb.data);
     for (int i = 0, size = width_ * height_ / 2; i < size; ++ i){
     for (int i = 0, size = width_ * height_ / 2; i < size; ++ i){
         u16 col = (vram_[i * 2 + 1] << 8) | vram_[i * 2 + 0];
         u16 col = (vram_[i * 2 + 1] << 8) | vram_[i * 2 + 0];
@@ -47,9 +46,7 @@ void Vram::Save(const Ogre::String& file){
           | 0xff;
           | 0xff;
     }
     }
     Ogre::Image image;
     Ogre::Image image;
-    image.loadDynamicImage(
-      (Ogre::uchar*) pb.data, width_ / 2, height_, Ogre::PF_R8G8B8A8
-    );
+    image.loadDynamicImage((Ogre::uchar*) pb.data, width_ / 2, height_, Ogre::PF_R8G8B8A8);
     image.save(file + ".png");
     image.save(file + ".png");
     buffer->unlock();
     buffer->unlock();
 }
 }
@@ -57,9 +54,8 @@ void Vram::Save(const Ogre::String& file){
 void Vram::PutU8(u16 x, u16 y, u8 byte){
 void Vram::PutU8(u16 x, u16 y, u8 byte){
     if (x > width_ || y > height_){
     if (x > width_ || y > height_){
         LOGGER->Log(
         LOGGER->Log(
-          "Vram::PutU8: Error: Tried to put byte in Vram x("
-          + Ogre::StringConverter::toString(x) + ") y("
-          + Ogre::StringConverter::toString(y) + ")\n"
+          "Vram::PutU8: Error: Tried to put byte in Vram x(" + Ogre::StringConverter::toString(x)
+          + ") y(" + Ogre::StringConverter::toString(y) + ")\n"
         );
         );
         return;
         return;
     }
     }
@@ -69,10 +65,8 @@ void Vram::PutU8(u16 x, u16 y, u8 byte){
 u8 Vram::GetU8(u16 x, u16 y) const{
 u8 Vram::GetU8(u16 x, u16 y) const{
     if (x > width_ || y > height_){
     if (x > width_ || y > height_){
         LOGGER->Log(
         LOGGER->Log(
-          "Vram::GetU8: Error: Tried to get byte from Vram x("
-          + Ogre::StringConverter::toString(x) + ") y("
-          + Ogre::StringConverter::toString(y) + ")\n"
-
+          "Vram::GetU8: Error: Tried to get byte from Vram x(" + Ogre::StringConverter::toString(x)
+          + ") y(" + Ogre::StringConverter::toString(y) + ")\n"
         );
         );
         return 0;
         return 0;
     }
     }
@@ -82,14 +76,12 @@ u8 Vram::GetU8(u16 x, u16 y) const{
 void Vram::PutU16(u16 x, u16 y, u16 bytes){
 void Vram::PutU16(u16 x, u16 y, u16 bytes){
     if (x + 1 > width_ || y > height_){
     if (x + 1 > width_ || y > height_){
         LOGGER->Log(
         LOGGER->Log(
-          "Vram::PutU16: Error: Tried to put pixel in Vram x("
-          + Ogre::StringConverter::toString(x) + ") y("
-          + Ogre::StringConverter::toString(y) + ")\n"
+          "Vram::PutU16: Error: Tried to put pixel in Vram x(" + Ogre::StringConverter::toString(x)
+          + ") y(" + Ogre::StringConverter::toString(y) + ")\n"
         );
         );
         return;
         return;
     }
     }
-    // This byte order is used to make possible store everything in VRAM
-    // as U8 but get as U16LE.
+    // This byte order is used to make possible store everything in VRAM as U8 but get as U16LE.
     vram_[y * width_ + x + 1] = bytes >> 8;
     vram_[y * width_ + x + 1] = bytes >> 8;
     vram_[y * width_ + x + 0] = bytes & 0x00ff;
     vram_[y * width_ + x + 0] = bytes & 0x00ff;
 }
 }
@@ -98,12 +90,10 @@ u16 Vram::GetU16(u16 x, u16 y) const{
     if (x + 1 > width_ || y > height_){
     if (x + 1 > width_ || y > height_){
         LOGGER->Log(
         LOGGER->Log(
           "Vram::GetU16: Error: Tried to get pixel from Vram x("
           "Vram::GetU16: Error: Tried to get pixel from Vram x("
-          + Ogre::StringConverter::toString(x) + ") y("
-          + Ogre::StringConverter::toString(y) + ")\n"
+          + Ogre::StringConverter::toString(x) + ") y(" + Ogre::StringConverter::toString(y) + ")\n"
         );
         );
         return 0;
         return 0;
     }
     }
-    // This byte order is used to make possible store everything in VRAM
-    // as U8 but get as U16LE.
+    // This byte order is used to make possible store everything in VRAM as U8 but get as U16LE.
     return (vram_[y * width_ + x + 1] << 8) | vram_[y * width_ + x + 0];
     return (vram_[y * width_ + x + 1] << 8) | vram_[y * width_ + x + 0];
 }
 }

+ 31 - 31
V-Gears-Installer/src/decompiler/control_flow.cpp

@@ -113,15 +113,15 @@ void ControlFlow::merge(GraphVertex g1, GraphVertex g2) {
 	// Update property
 	// Update property
 	GroupPtr gr1 = GET(g1);
 	GroupPtr gr1 = GET(g1);
 	GroupPtr gr2 = GET(g2);
 	GroupPtr gr2 = GET(g2);
-	gr1->_end = gr2->_end;
+	gr1->end_ = gr2->end_;
 	PUT(g1, gr1);
 	PUT(g1, gr1);
 
 
 	// Update address map
 	// Update address map
-	ConstInstIterator it = gr2->_start;
+	ConstInstIterator it = gr2->start_;
 	do {
 	do {
 		_addrMap[(*it)->_address] = g1;
 		_addrMap[(*it)->_address] = g1;
 		++it;
 		++it;
-	} while (gr2->_start != gr2->_end && it != gr2->_end);
+	} while (gr2->start_ != gr2->end_ && it != gr2->end_);
 
 
 	// Add outgoing edges from g2
 	// Add outgoing edges from g2
 	OutEdgeRange r = boost::out_edges(g2, _g);
 	OutEdgeRange r = boost::out_edges(g2, _g);
@@ -153,7 +153,7 @@ void ControlFlow::setStackLevel(GraphVertex g, int level) {
 		GroupPtr gr = GET(e.first);
 		GroupPtr gr = GET(e.first);
 		if (gr->_stackLevel != -1) {
 		if (gr->_stackLevel != -1) {
 			if (gr->_stackLevel != e.second)
 			if (gr->_stackLevel != e.second)
-				std::cerr << boost::format("WARNING: Inconsistency in expected stack level for instruction at address 0x%08x (current: %d, requested: %d)\n") % (*gr->_start)->_address % gr->_stackLevel % e.second;
+				std::cerr << boost::format("WARNING: Inconsistency in expected stack level for instruction at address 0x%08x (current: %d, requested: %d)\n") % (*gr->start_)->_address % gr->_stackLevel % e.second;
 			continue;
 			continue;
 		}
 		}
 		gr->_stackLevel = e.second;
 		gr->_stackLevel = e.second;
@@ -162,7 +162,7 @@ void ControlFlow::setStackLevel(GraphVertex g, int level) {
 		for (OutEdgeIterator oe = r.first; oe != r.second; ++oe) {
 		for (OutEdgeIterator oe = r.first; oe != r.second; ++oe) {
 			GraphVertex target = boost::target(*oe, _g);
 			GraphVertex target = boost::target(*oe, _g);
 			if (seen.find(target) == seen.end()) {
 			if (seen.find(target) == seen.end()) {
-				levelStack.push(LevelEntry(target, e.second + (*gr->_start)->_stackChange));
+				levelStack.push(LevelEntry(target, e.second + (*gr->start_)->_stackChange));
 				seen.insert(target);
 				seen.insert(target);
 			}
 			}
 		}
 		}
@@ -234,12 +234,12 @@ void ControlFlow::createGroups()
 		if (!mEngine.UsePureGrouping()) {
 		if (!mEngine.UsePureGrouping()) {
 			// If group has no instructions with stack effect >= 0, don't merge on balanced stack
 			// If group has no instructions with stack effect >= 0, don't merge on balanced stack
 			bool forceMerge = true;
 			bool forceMerge = true;
-			ConstInstIterator it = grCur->_start;
+			ConstInstIterator it = grCur->start_;
 			do {
 			do {
 				if ((*it)->_stackChange >= 0)
 				if ((*it)->_stackChange >= 0)
 					forceMerge = false;
 					forceMerge = false;
 				++it;
 				++it;
-			} while (grCur->_start != grCur->_end && it != grCur->_end);
+			} while (grCur->start_ != grCur->end_ && it != grCur->end_);
 
 
 			// Group ends when stack is balanced, unless just before conditional jump
 			// Group ends when stack is balanced, unless just before conditional jump
 			if (stackLevel == expectedStackLevel && !forceMerge && !(*nextInst)->isCondJump()) {
 			if (stackLevel == expectedStackLevel && !forceMerge && !(*nextInst)->isCondJump()) {
@@ -265,8 +265,8 @@ void ControlFlow::detectShortCircuit() {
 	GroupPtr gr = GET(cur);
 	GroupPtr gr = GET(cur);
 	while (gr->_prev != NULL) {
 	while (gr->_prev != NULL) {
 		bool doMerge = false;
 		bool doMerge = false;
-		cur = find(gr->_start);
-		GraphVertex prev = find(gr->_prev->_start);
+		cur = find(gr->start_);
+		GraphVertex prev = find(gr->_prev->start_);
 		// Block is candidate for short-circuit merging if it and the preceding block both end with conditional jumps
 		// Block is candidate for short-circuit merging if it and the preceding block both end with conditional jumps
 		if (out_degree(cur, _g) == 2 && out_degree(prev, _g) == 2) {
 		if (out_degree(cur, _g) == 2 && out_degree(prev, _g) == 2) {
 			doMerge = true;
 			doMerge = true;
@@ -316,7 +316,7 @@ void ControlFlow::detectWhile() {
 			for (InEdgeIterator e = ier.first; e != ier.second; ++e) {
 			for (InEdgeIterator e = ier.first; e != ier.second; ++e) {
 				GroupPtr sourceGr = GET(boost::source(*e, _g));
 				GroupPtr sourceGr = GET(boost::source(*e, _g));
 				// Block has ingoing edge from block later in the code that isn't a do-while condition
 				// Block has ingoing edge from block later in the code that isn't a do-while condition
-				if ((*sourceGr->_start)->_address > (*gr->_start)->_address && sourceGr->_type != kDoWhileCondGroupType)
+				if ((*sourceGr->start_)->_address > (*gr->start_)->_address && sourceGr->_type != kDoWhileCondGroupType)
 					isWhile = true;
 					isWhile = true;
 			}
 			}
 			if (isWhile)
 			if (isWhile)
@@ -335,7 +335,7 @@ void ControlFlow::detectDoWhile() {
 			for (OutEdgeIterator e = oer.first; e != oer.second; ++e) {
 			for (OutEdgeIterator e = oer.first; e != oer.second; ++e) {
 				GroupPtr targetGr = GET(boost::target(*e, _g));
 				GroupPtr targetGr = GET(boost::target(*e, _g));
 				// ...to earlier in code
 				// ...to earlier in code
-				if ((*targetGr->_start)->_address < (*gr->_start)->_address)
+				if ((*targetGr->start_)->_address < (*gr->start_)->_address)
 					gr->_type = kDoWhileCondGroupType;
 					gr->_type = kDoWhileCondGroupType;
 			}
 			}
 		}
 		}
@@ -347,12 +347,12 @@ void ControlFlow::detectBreak() {
 	for (VertexIterator v = vr.first; v != vr.second; ++v) {
 	for (VertexIterator v = vr.first; v != vr.second; ++v) {
 		GroupPtr gr = GET(*v);
 		GroupPtr gr = GET(*v);
 		// Undetermined block with unconditional jump...
 		// Undetermined block with unconditional jump...
-		if (gr->_type == kNormalGroupType && ((*gr->_end)->IsUncondJump()) && out_degree(*v, _g) == 1) {
+		if (gr->_type == kNormalGroupType && ((*gr->end_)->IsUncondJump()) && out_degree(*v, _g) == 1) {
 			OutEdgeIterator oe = boost::out_edges(*v, _g).first;
 			OutEdgeIterator oe = boost::out_edges(*v, _g).first;
 			GraphVertex target = boost::target(*oe, _g);
 			GraphVertex target = boost::target(*oe, _g);
 			GroupPtr targetGr = GET(target);
 			GroupPtr targetGr = GET(target);
 			// ...to somewhere later in the code...
 			// ...to somewhere later in the code...
-			if ((*gr->_start)->_address >= (*targetGr->_start)->_address)
+			if ((*gr->start_)->_address >= (*targetGr->start_)->_address)
 				continue;
 				continue;
 			InEdgeRange ier = boost::in_edges(target, _g);
 			InEdgeRange ier = boost::in_edges(target, _g);
 			for (InEdgeIterator ie = ier.first; ie != ier.second; ++ie) {
 			for (InEdgeIterator ie = ier.first; ie != ier.second; ++ie) {
@@ -372,7 +372,7 @@ void ControlFlow::detectContinue() {
 	for (VertexIterator v = vr.first; v != vr.second; ++v) {
 	for (VertexIterator v = vr.first; v != vr.second; ++v) {
 		GroupPtr gr = GET(*v);
 		GroupPtr gr = GET(*v);
 		// Undetermined block with unconditional jump...
 		// Undetermined block with unconditional jump...
-		if (gr->_type == kNormalGroupType && ((*gr->_end)->IsUncondJump()) && out_degree(*v, _g) == 1) {
+		if (gr->_type == kNormalGroupType && ((*gr->end_)->IsUncondJump()) && out_degree(*v, _g) == 1) {
 			OutEdgeIterator oe = boost::out_edges(*v, _g).first;
 			OutEdgeIterator oe = boost::out_edges(*v, _g).first;
 			GraphVertex target = boost::target(*oe, _g);
 			GraphVertex target = boost::target(*oe, _g);
 			GroupPtr targetGr = GET(target);
 			GroupPtr targetGr = GET(target);
@@ -387,7 +387,7 @@ void ControlFlow::detectContinue() {
 					if (targetGr->_type == kWhileCondGroupType && GET(boost::target(*toe, _g)) == gr->_next)
 					if (targetGr->_type == kWhileCondGroupType && GET(boost::target(*toe, _g)) == gr->_next)
 						isContinue = false;
 						isContinue = false;
 					// ...or the instruction is placed after all jump targets from condition
 					// ...or the instruction is placed after all jump targets from condition
-					if ((*GET(boost::target(*toe, _g))->_start)->_address > (*gr->_start)->_address)
+					if ((*GET(boost::target(*toe, _g))->start_)->_address > (*gr->start_)->_address)
 						afterJumpTargets = false;
 						afterJumpTargets = false;
 				}
 				}
 				if (afterJumpTargets)
 				if (afterJumpTargets)
@@ -415,19 +415,19 @@ bool ControlFlow::validateBreakOrContinue(GroupPtr gr, GroupPtr condGr) {
 	// Verify that destination deals with innermost while/do-while
 	// Verify that destination deals with innermost while/do-while
 	for (cursor = from; cursor->_next != NULL && cursor != to; cursor = cursor->_next) {
 	for (cursor = from; cursor->_next != NULL && cursor != to; cursor = cursor->_next) {
 		if (cursor->_type == condGr->_type) {
 		if (cursor->_type == condGr->_type) {
-			OutEdgeRange oerValidate = boost::out_edges(find(cursor->_start), _g);
+			OutEdgeRange oerValidate = boost::out_edges(find(cursor->start_), _g);
 			for (OutEdgeIterator oeValidate = oerValidate.first; oeValidate != oerValidate.second; ++oeValidate) {
 			for (OutEdgeIterator oeValidate = oerValidate.first; oeValidate != oerValidate.second; ++oeValidate) {
 				GraphVertex vValidate = boost::target(*oeValidate, _g);
 				GraphVertex vValidate = boost::target(*oeValidate, _g);
 				GroupPtr gValidate = GET(vValidate);
 				GroupPtr gValidate = GET(vValidate);
 				// For all other loops of same type found in range, all targets must fall within that range
 				// For all other loops of same type found in range, all targets must fall within that range
-				if ((*gValidate->_start)->_address < (*from->_start)->_address || (*gValidate->_start)->_address > (*to->_start)->_address )
+				if ((*gValidate->start_)->_address < (*from->start_)->_address || (*gValidate->start_)->_address > (*to->start_)->_address )
 					return false;
 					return false;
 
 
 				InEdgeRange ierValidate = boost::in_edges(vValidate, _g);
 				InEdgeRange ierValidate = boost::in_edges(vValidate, _g);
 				for (InEdgeIterator ieValidate = ierValidate.first; ieValidate != ierValidate.second; ++ieValidate) {
 				for (InEdgeIterator ieValidate = ierValidate.first; ieValidate != ierValidate.second; ++ieValidate) {
 					GroupPtr igValidate = GET(boost::source(*ieValidate, _g));
 					GroupPtr igValidate = GET(boost::source(*ieValidate, _g));
 					// All loops of other type going into range must be placed within range
 					// All loops of other type going into range must be placed within range
-					if (igValidate->_type == ogt && ((*igValidate->_start)->_address < (*from->_start)->_address || (*igValidate->_start)->_address > (*to->_start)->_address ))
+					if (igValidate->_type == ogt && ((*igValidate->start_)->_address < (*from->start_)->_address || (*igValidate->start_)->_address > (*to->start_)->_address ))
 					return false;
 					return false;
 				}
 				}
 			}
 			}
@@ -441,7 +441,7 @@ void ControlFlow::detectIf() {
 	for (VertexIterator v = vr.first; v != vr.second; ++v) {
 	for (VertexIterator v = vr.first; v != vr.second; ++v) {
 		GroupPtr gr = GET(*v);
 		GroupPtr gr = GET(*v);
 		// if: Undetermined block with conditional jump
 		// if: Undetermined block with conditional jump
-		if (gr->_type == kNormalGroupType && ((*gr->_end)->isCondJump())) {
+		if (gr->_type == kNormalGroupType && ((*gr->end_)->isCondJump())) {
 			gr->_type = kIfCondGroupType;
 			gr->_type = kIfCondGroupType;
 		}
 		}
 	}
 	}
@@ -459,22 +459,22 @@ void ControlFlow::detectElse() {
 			// Find jump target
 			// Find jump target
 			for (OutEdgeIterator oe = oer.first; oe != oer.second; ++oe) {
 			for (OutEdgeIterator oe = oer.first; oe != oer.second; ++oe) {
 				targetGr = GET(boost::target(*oe, _g));
 				targetGr = GET(boost::target(*oe, _g));
-				if ((*targetGr->_start)->_address > maxAddress) {
+				if ((*targetGr->start_)->_address > maxAddress) {
 					target = boost::target(*oe, _g);
 					target = boost::target(*oe, _g);
-					maxAddress = (*targetGr->_start)->_address;
+					maxAddress = (*targetGr->start_)->_address;
 				}
 				}
 			}
 			}
 			targetGr = GET(target);
 			targetGr = GET(target);
 			// else: Jump target of if immediately preceded by an unconditional jump...
 			// else: Jump target of if immediately preceded by an unconditional jump...
-			if (!(*targetGr->_prev->_end)->IsUncondJump())
+			if (!(*targetGr->_prev->end_)->IsUncondJump())
 				continue;
 				continue;
 			// ...which is not a break or a continue...
 			// ...which is not a break or a continue...
 			if (targetGr->_prev->_type == kContinueGroupType || targetGr->_prev->_type == kBreakGroupType)
 			if (targetGr->_prev->_type == kContinueGroupType || targetGr->_prev->_type == kBreakGroupType)
 				continue;
 				continue;
 			// ...to later in the code
 			// ...to later in the code
-			OutEdgeIterator toe = boost::out_edges(find((*targetGr->_prev->_start)->_address), _g).first;
+			OutEdgeIterator toe = boost::out_edges(find((*targetGr->_prev->start_)->_address), _g).first;
 			GroupPtr targetTargetGr = GET(boost::target(*toe, _g));
 			GroupPtr targetTargetGr = GET(boost::target(*toe, _g));
-			if ((*targetTargetGr->_start)->_address > (*targetGr->_end)->_address) {
+			if ((*targetTargetGr->start_)->_address > (*targetGr->end_)->_address) {
 				if (validateElseBlock(gr, targetGr, targetTargetGr)) {
 				if (validateElseBlock(gr, targetGr, targetTargetGr)) {
 					targetGr->_startElse = true;
 					targetGr->_startElse = true;
 					targetTargetGr->_prev->_endElse.push_back(targetGr.get());
 					targetTargetGr->_prev->_endElse.push_back(targetGr.get());
@@ -488,12 +488,12 @@ bool ControlFlow::validateElseBlock(GroupPtr ifGroup, GroupPtr start, GroupPtr e
 	for (GroupPtr cursor = start; cursor != end; cursor = cursor->_next) {
 	for (GroupPtr cursor = start; cursor != end; cursor = cursor->_next) {
 		if (cursor->_type == kIfCondGroupType || cursor->_type == kWhileCondGroupType || cursor->_type == kDoWhileCondGroupType) {
 		if (cursor->_type == kIfCondGroupType || cursor->_type == kWhileCondGroupType || cursor->_type == kDoWhileCondGroupType) {
 			// Validate outgoing edges of conditions
 			// Validate outgoing edges of conditions
-			OutEdgeRange oer = boost::out_edges(find(cursor->_start), _g);
+			OutEdgeRange oer = boost::out_edges(find(cursor->start_), _g);
 			for (OutEdgeIterator oe = oer.first; oe != oer.second; ++oe) {
 			for (OutEdgeIterator oe = oer.first; oe != oer.second; ++oe) {
 				GraphVertex target = boost::target(*oe, _g);
 				GraphVertex target = boost::target(*oe, _g);
 				GroupPtr targetGr = GET(target);
 				GroupPtr targetGr = GET(target);
 				// Each edge from condition must not leave the range [start, end]
 				// Each edge from condition must not leave the range [start, end]
-				if ((*start->_start)->_address > (*targetGr->_start)->_address || (*targetGr->_start)->_address > (*end->_start)->_address)
+				if ((*start->start_)->_address > (*targetGr->start_)->_address || (*targetGr->start_)->_address > (*end->start_)->_address)
 					return false;
 					return false;
 			}
 			}
 		}
 		}
@@ -501,16 +501,16 @@ bool ControlFlow::validateElseBlock(GroupPtr ifGroup, GroupPtr start, GroupPtr e
 		// If previous group ends an else, that else must start inside the range
 		// If previous group ends an else, that else must start inside the range
 		for (ElseEndIterator it = cursor->_prev->_endElse.begin(); it != cursor->_prev->_endElse.end(); ++it)
 		for (ElseEndIterator it = cursor->_prev->_endElse.begin(); it != cursor->_prev->_endElse.end(); ++it)
 		{
 		{
-			if ((*(*it)->_start)->_address < (*start->_start)->_address)
+			if ((*(*it)->start_)->_address < (*start->start_)->_address)
 				return false;
 				return false;
 		}
 		}
 
 
 		// Unless group is a simple unconditional jump...
 		// Unless group is a simple unconditional jump...
-		if ((*cursor->_start)->IsUncondJump())
+		if ((*cursor->start_)->IsUncondJump())
 			continue;
 			continue;
 
 
 		// ...validate ingoing edges
 		// ...validate ingoing edges
-		InEdgeRange ier = boost::in_edges(find(cursor->_start), _g);
+		InEdgeRange ier = boost::in_edges(find(cursor->start_), _g);
 		for (InEdgeIterator ie = ier.first; ie != ier.second; ++ie) {
 		for (InEdgeIterator ie = ier.first; ie != ier.second; ++ie) {
 			GraphVertex source = boost::source(*ie, _g);
 			GraphVertex source = boost::source(*ie, _g);
 			GroupPtr sourceGr = GET(source);
 			GroupPtr sourceGr = GET(source);
@@ -518,9 +518,9 @@ bool ControlFlow::validateElseBlock(GroupPtr ifGroup, GroupPtr start, GroupPtr e
 			// Edges going to conditions...
 			// Edges going to conditions...
 			if (sourceGr->_type == kIfCondGroupType || sourceGr->_type == kWhileCondGroupType || sourceGr->_type == kDoWhileCondGroupType) {
 			if (sourceGr->_type == kIfCondGroupType || sourceGr->_type == kWhileCondGroupType || sourceGr->_type == kDoWhileCondGroupType) {
 				// ...must not come from outside the range [start, end]...
 				// ...must not come from outside the range [start, end]...
-				if ((*start->_start)->_address > (*sourceGr->_start)->_address || (*sourceGr->_start)->_address > (*end->_start)->_address) {
+				if ((*start->start_)->_address > (*sourceGr->start_)->_address || (*sourceGr->start_)->_address > (*end->start_)->_address) {
 					// ...unless source is simple unconditional jump...
 					// ...unless source is simple unconditional jump...
-					if ((*sourceGr->_start)->IsUncondJump())
+					if ((*sourceGr->start_)->IsUncondJump())
 						continue;
 						continue;
 					// ...or the edge is from the if condition associated with this else
 					// ...or the edge is from the if condition associated with this else
 					if (ifGroup == sourceGr)
 					if (ifGroup == sourceGr)

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

@@ -27,9 +27,6 @@
 
 
 #include "control_flow.h"
 #include "control_flow.h"
 
 
-//#include "scummv6/engine.h"
-#include "decompiler_engine.h"
-
 #include <fstream>
 #include <fstream>
 #include <iostream>
 #include <iostream>
 #include <map>
 #include <map>
@@ -57,7 +54,7 @@ int main(int argc, char** argv) {
 		std::map<std::string, std::string> engines;
 		std::map<std::string, std::string> engines;
 		ObjectFactory<std::string, Engine> engineFactory;
 		ObjectFactory<std::string, Engine> engineFactory;
 
 
-		ENGINE("scummv6", "SCUMM v6", Engine);//Scumm::v6::Scummv6Engine);
+		ENGINE("scummv6", "SCUMM v6", Scumm::v6::Scummv6Engine);
 
 
         po::options_description visible("Options", 1024);
         po::options_description visible("Options", 1024);
 		visible.add_options()
 		visible.add_options()

+ 27 - 27
V-Gears-Installer/src/decompiler/decompiler_codegen.cpp

@@ -78,14 +78,14 @@ void CodeGenerator::generatePass(InstVec& insts, const Graph& g)
         bool printFuncSignature = !funcSignature.empty();
         bool printFuncSignature = !funcSignature.empty();
         if (printFuncSignature)
         if (printFuncSignature)
         {
         {
-            mCurGroup = GET(entryPoint);
+            cur_group_ = GET(entryPoint);
             if (!(fn == _engine->_functions.begin()))
             if (!(fn == _engine->_functions.begin()))
             {
             {
                  AddOutputLine("");
                  AddOutputLine("");
             }
             }
             OnBeforeStartFunction(fn->second);
             OnBeforeStartFunction(fn->second);
 
 
-            AddOutputLine(funcSignature, false, true); 
+            AddOutputLine(funcSignature, false, true);
 
 
             OnStartFunction(fn->second);
             OnStartFunction(fn->second);
         }
         }
@@ -101,7 +101,7 @@ void CodeGenerator::generatePass(InstVec& insts, const Graph& g)
         {
         {
             DFSEntry e = dfsStack.pop();
             DFSEntry e = dfsStack.pop();
             GroupPtr tmp = GET(e.first);
             GroupPtr tmp = GET(e.first);
-            if ((*tmp->_start)->_address > (*lastGroup->_start)->_address)
+            if ((*tmp->start_)->_address > (*lastGroup->start_)->_address)
             {
             {
                 lastGroup = tmp;
                 lastGroup = tmp;
             }
             }
@@ -123,7 +123,7 @@ void CodeGenerator::generatePass(InstVec& insts, const Graph& g)
         // Write the function end
         // Write the function end
         if (printFuncSignature)
         if (printFuncSignature)
         {
         {
-            mCurGroup = lastGroup;
+            cur_group_ = lastGroup;
             OnEndFunction(fn->second);
             OnEndFunction(fn->second);
         }
         }
 
 
@@ -145,7 +145,7 @@ void CodeGenerator::generatePass(InstVec& insts, const Graph& g)
                 }
                 }
                 else
                 else
                 {
                 {
-                    _output << boost::format("%08X: %s") % (*p->_start)->_address % indentString(it->_line) << std::endl;
+                    _output << boost::format("%08X: %s") % (*p->start_)->_address % indentString(it->_line) << std::endl;
                 }
                 }
 
 
                 if (it->_indentAfter)
                 if (it->_indentAfter)
@@ -171,13 +171,13 @@ void CodeGenerator::Generate(InstVec& insts, const Graph &g)
     generatePass(insts, g);
     generatePass(insts, g);
 }
 }
 
 
-void CodeGenerator::AddOutputLine(std::string s, bool unindentBefore, bool indentAfter) 
+void CodeGenerator::AddOutputLine(std::string s, bool unindentBefore, bool indentAfter)
 {
 {
     // We don't generate output in the labels pass, we just find instructions that
     // We don't generate output in the labels pass, we just find instructions that
     // require a label to be outputted
     // require a label to be outputted
     if (!mIsLabelPass)
     if (!mIsLabelPass)
     {
     {
-        mCurGroup->_code.push_back(CodeLine(s, unindentBefore, indentAfter));
+        cur_group_->_code.push_back(CodeLine(s, unindentBefore, indentAfter));
     }
     }
 }
 }
 
 
@@ -191,10 +191,10 @@ void CodeGenerator::writeAssignment(ValuePtr dst, ValuePtr src)
 void CodeGenerator::process(Function& func, InstVec& insts, GraphVertex v)
 void CodeGenerator::process(Function& func, InstVec& insts, GraphVertex v)
 {
 {
     _curVertex = v;
     _curVertex = v;
-    mCurGroup = GET(v);
+    cur_group_ = GET(v);
 
 
     // Check if we should add else start
     // Check if we should add else start
-    if (mCurGroup->_startElse)
+    if (cur_group_->_startElse)
     {
     {
         AddOutputLine(target_lang_->EndBlock(ITargetLanaguge::eToElseBlock) + " " + target_lang_->Else() + " " + target_lang_->StartBlock(ITargetLanaguge::eBeginElse), true, true);
         AddOutputLine(target_lang_->EndBlock(ITargetLanaguge::eToElseBlock) + " " + target_lang_->Else() + " " + target_lang_->StartBlock(ITargetLanaguge::eBeginElse), true, true);
     }
     }
@@ -217,7 +217,7 @@ void CodeGenerator::process(Function& func, InstVec& insts, GraphVertex v)
             AddOutputLine(target_lang_->DoLoopHeader(), false, true);
             AddOutputLine(target_lang_->DoLoopHeader(), false, true);
             break;
             break;
         case kIfCondGroupType:
         case kIfCondGroupType:
-            if (!mCurGroup->_startElse)
+            if (!cur_group_->_startElse)
             {
             {
                 AddOutputLine(target_lang_->EndBlock(ITargetLanaguge::eEndOfIf), true, false);
                 AddOutputLine(target_lang_->EndBlock(ITargetLanaguge::eEndOfIf), true, false);
             }
             }
@@ -230,7 +230,7 @@ void CodeGenerator::process(Function& func, InstVec& insts, GraphVertex v)
         }
         }
     }
     }
 
 
-    ConstInstIterator it = mCurGroup->_start;
+    ConstInstIterator it = cur_group_->start_;
     do 
     do 
     {
     {
         // If we only want to write labels that targets of goto's then check if this is the pass
         // If we only want to write labels that targets of goto's then check if this is the pass
@@ -241,10 +241,10 @@ void CodeGenerator::process(Function& func, InstVec& insts, GraphVertex v)
             AddOutputLine(target_lang_->Label((*it)->_address));
             AddOutputLine(target_lang_->Label((*it)->_address));
         }
         }
         ProcessInst(func, insts, *it);
         ProcessInst(func, insts, *it);
-    } while (it++ != mCurGroup->_end);
+    } while (it++ != cur_group_->end_);
 
 
     // Add else end if necessary
     // Add else end if necessary
-    for (ElseEndIterator elseIt = mCurGroup->_endElse.begin(); elseIt != mCurGroup->_endElse.end(); ++elseIt)
+    for (ElseEndIterator elseIt = cur_group_->_endElse.begin(); elseIt != cur_group_->_endElse.end(); ++elseIt)
     {
     {
         if (!(*elseIt)->_coalescedElse)
         if (!(*elseIt)->_coalescedElse)
         {
         {
@@ -253,9 +253,9 @@ void CodeGenerator::process(Function& func, InstVec& insts, GraphVertex v)
     }
     }
 }
 }
 
 
-void CodeGenerator::processUncondJumpInst(Function& func, InstVec& insts, const InstPtr inst)
+void CodeGenerator::ProcessUncondJumpInst(Function& func, InstVec& insts, const InstPtr inst)
 {
 {
-    switch (mCurGroup->_type)
+    switch (cur_group_->_type)
     {
     {
     case kBreakGroupType:
     case kBreakGroupType:
         AddOutputLine(target_lang_->LoopBreak());
         AddOutputLine(target_lang_->LoopBreak());
@@ -269,7 +269,7 @@ void CodeGenerator::processUncondJumpInst(Function& func, InstVec& insts, const
         OutEdgeRange jumpTargets = boost::out_edges(_curVertex, _g);
         OutEdgeRange jumpTargets = boost::out_edges(_curVertex, _g);
         for (OutEdgeIterator target = jumpTargets.first; target != jumpTargets.second && printJump; ++target)
         for (OutEdgeIterator target = jumpTargets.first; target != jumpTargets.second && printJump; ++target)
         {
         {
-            Group* next = mCurGroup->_next;
+            Group* next = cur_group_->_next;
             if (next)
             if (next)
             {
             {
                 // Don't output jump to next vertex
                 // Don't output jump to next vertex
@@ -300,7 +300,7 @@ void CodeGenerator::processUncondJumpInst(Function& func, InstVec& insts, const
                 {
                 {
                     // Check if this instruction is the last instruction in the function
                     // Check if this instruction is the last instruction in the function
                     // and its an uncond jump
                     // and its an uncond jump
-                    if (mCurGroup->_type == kDoWhileCondGroupType && inst->_address == func.mEndAddr && inst->IsUncondJump())
+                    if (cur_group_->_type == kDoWhileCondGroupType && inst->_address == func.mEndAddr && inst->IsUncondJump())
                     {
                     {
                         printJump = false;
                         printJump = false;
                         AddOutputLine(target_lang_->DoLoopFooter(true) + "true" + target_lang_->DoLoopFooter(false), true, false);
                         AddOutputLine(target_lang_->DoLoopFooter(true) + "true" + target_lang_->DoLoopFooter(false), true, false);
@@ -376,33 +376,33 @@ void CodeGenerator::writeFunctionCall(std::string functionName, std::string para
     AddOutputLine(strFuncCall);
     AddOutputLine(strFuncCall);
 }
 }
 
 
-void CodeGenerator::processCondJumpInst(const InstPtr inst)
+void CodeGenerator::ProcessCondJumpInst(const InstPtr inst)
 {
 {
     std::stringstream s;
     std::stringstream s;
-    switch (mCurGroup->_type)
+    switch (cur_group_->_type)
     {
     {
     case kIfCondGroupType:
     case kIfCondGroupType:
-        if (mCurGroup->_startElse && mCurGroup->_code.size() == 1)
+        if (cur_group_->_startElse && cur_group_->_code.size() == 1)
         {
         {
             OutEdgeRange oer = boost::out_edges(_curVertex, _g);
             OutEdgeRange oer = boost::out_edges(_curVertex, _g);
             bool coalesceElse = false;
             bool coalesceElse = false;
             for (OutEdgeIterator oe = oer.first; oe != oer.second; ++oe)
             for (OutEdgeIterator oe = oer.first; oe != oer.second; ++oe)
             {
             {
                 GroupPtr oGr = GET(boost::target(*oe, _g))->_prev;
                 GroupPtr oGr = GET(boost::target(*oe, _g))->_prev;
-                if (std::find(oGr->_endElse.begin(), oGr->_endElse.end(), mCurGroup.get()) != oGr->_endElse.end())
+                if (std::find(oGr->_endElse.begin(), oGr->_endElse.end(), cur_group_.get()) != oGr->_endElse.end())
                 {
                 {
                     coalesceElse = true;
                     coalesceElse = true;
                 }
                 }
             }
             }
             if (coalesceElse)
             if (coalesceElse)
             {
             {
-                mCurGroup->_code.clear();
-                mCurGroup->_coalescedElse = true;
+                cur_group_->_code.clear();
+                cur_group_->_coalescedElse = true;
                 s << target_lang_->EndBlock(ITargetLanaguge::eToElseBlock) << " " << target_lang_->Else() << " ";
                 s << target_lang_->EndBlock(ITargetLanaguge::eToElseBlock) << " " << target_lang_->Else() << " ";
             }
             }
         }
         }
         s << target_lang_->If(true) << _stack.pop()->negate() << target_lang_->If(false);
         s << target_lang_->If(true) << _stack.pop()->negate() << target_lang_->If(false);
-        AddOutputLine(s.str(), mCurGroup->_coalescedElse, true);
+        AddOutputLine(s.str(), cur_group_->_coalescedElse, true);
         break;
         break;
     case kWhileCondGroupType:
     case kWhileCondGroupType:
         s << target_lang_->WhileHeader(true) << _stack.pop()->negate() << target_lang_->WhileHeader(false) << " " << target_lang_->StartBlock(ITargetLanaguge::eBeginWhile);
         s << target_lang_->WhileHeader(true) << _stack.pop()->negate() << target_lang_->WhileHeader(false) << " " << target_lang_->StartBlock(ITargetLanaguge::eBeginWhile);
@@ -422,11 +422,11 @@ void CodeGenerator::ProcessInst(Function& func, InstVec& insts, const InstPtr in
     inst->ProcessInst(func, _stack, _engine, this);
     inst->ProcessInst(func, _stack, _engine, this);
     if (inst->isCondJump())
     if (inst->isCondJump())
     {
     {
-        processCondJumpInst(inst);
+        ProcessCondJumpInst(inst);
     }
     }
     else if (inst->IsUncondJump())
     else if (inst->IsUncondJump())
     {
     {
-        processUncondJumpInst(func, insts, inst);
+        ProcessUncondJumpInst(func, insts, inst);
     }
     }
 }
 }
 
 
@@ -438,7 +438,7 @@ void CodeGenerator::addArg(ValuePtr p)
         _argList.push_back(p);
         _argList.push_back(p);
 }
 }
 
 
-void CodeGenerator::processSpecialMetadata(const InstPtr inst, char c, int) 
+void CodeGenerator::ProcessSpecialMetadata(const InstPtr inst, char c, int) 
 {
 {
     switch (c) 
     switch (c) 
     {
     {

+ 8 - 8
V-Gears-Installer/src/decompiler/decompiler_disassembler.cpp

@@ -21,7 +21,7 @@
 
 
 #include "decompiler/decompiler_disassembler.h"
 #include "decompiler/decompiler_disassembler.h"
 
 
-Disassembler::Disassembler(InstVec &insts) : _insts(insts) {
+Disassembler::Disassembler(InstVec &insts) : insts_(insts) {
 	address_base_ = 0;
 	address_base_ = 0;
 }
 }
 
 
@@ -29,21 +29,21 @@ void Disassembler::Open(const char *filename) {
     stream_ = std::make_unique<BinaryReader>(BinaryReader::ReadAll(filename));
     stream_ = std::make_unique<BinaryReader>(BinaryReader::ReadAll(filename));
 }
 }
 
 
-void Disassembler::DoDumpDisassembly(std::ostream &output) {
+void Disassembler::doDumpDisassembly(std::ostream &output) {
 	InstIterator inst;
 	InstIterator inst;
-	for (inst = _insts.begin(); inst != _insts.end(); ++inst) {
+	for (inst = insts_.begin(); inst != insts_.end(); ++inst) {
 		output << *inst << "\n";
 		output << *inst << "\n";
 	}
 	}
 }
 }
 
 
-void Disassembler::Disassemble() {
-	if (_insts.empty()) {
+void Disassembler::disassemble() {
+	if (insts_.empty()) {
         stream_->Seek(0);
         stream_->Seek(0);
 		DoDisassemble();
 		DoDisassemble();
 	}
 	}
 }
 }
 
 
-void Disassembler::DumpDisassembly(std::ostream &output) {
-	Disassemble();
-	DoDumpDisassembly(output);
+void Disassembler::dumpDisassembly(std::ostream &output) {
+	disassemble();
+	doDumpDisassembly(output);
 }
 }

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

@@ -14,28 +14,26 @@
  */
  */
 
 
 #include <boost/algorithm/string/predicate.hpp>
 #include <boost/algorithm/string/predicate.hpp>
-
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldCodeGenerator.h"
+#include "decompiler/field/FieldEngine.h"
 
 
-#include "../../../include/decompiler/field/FieldEngine.h"
-
-const std::string FunctionMetaData::DELIMITER("_");
+const std::string FF7::FunctionMetaData::DELIMITER("_");
 
 
-const std::string FunctionMetaData::START("start");
+const std::string FF7::FunctionMetaData::START("start");
 
 
-const std::string FunctionMetaData::END("end");
+const std::string FF7::FunctionMetaData::END("end");
 
 
-FunctionMetaData::FunctionMetaData(std::string meta_data){Parse(meta_data);}
+FF7::FunctionMetaData::FunctionMetaData(std::string meta_data){Parse(meta_data);}
 
 
-bool FunctionMetaData::IsStart() const{return start_;}
+bool FF7::FunctionMetaData::IsStart() const{return start_;}
 
 
-bool FunctionMetaData::IsEnd() const{return end_;}
+bool FF7::FunctionMetaData::IsEnd() const{return end_;}
 
 
-std::string FunctionMetaData::GetEntityName(){return entity_name_;}
+std::string FF7::FunctionMetaData::GetEntityName(){return entity_name_;}
 
 
-int FunctionMetaData::GetCharacterId(){return character_id_;}
+int FF7::FunctionMetaData::GetCharacterId(){return character_id_;}
 
 
-void FunctionMetaData::Parse(std::string meta_data){
+void FF7::FunctionMetaData::Parse(std::string meta_data){
     std::deque<std::string> strs;
     std::deque<std::string> strs;
     boost::split(strs, meta_data, boost::is_any_of(DELIMITER), boost::token_compress_on);
     boost::split(strs, meta_data, boost::is_any_of(DELIMITER), boost::token_compress_on);
     if (!strs.empty()){
     if (!strs.empty()){
@@ -45,7 +43,7 @@ void FunctionMetaData::Parse(std::string meta_data){
     }
     }
 }
 }
 
 
-void FunctionMetaData::ParseStart(const std::string& item, std::deque<std::string>& strs){
+void FF7::FunctionMetaData::ParseStart(const std::string& item, std::deque<std::string>& strs){
     if (item == START){
     if (item == START){
         start_ = true;
         start_ = true;
         if (!strs.empty()){
         if (!strs.empty()){
@@ -57,7 +55,7 @@ void FunctionMetaData::ParseStart(const std::string& item, std::deque<std::strin
     else ParseEnd(item, strs);
     else ParseEnd(item, strs);
 }
 }
 
 
-void FunctionMetaData::ParseEnd(const std::string& item, std::deque<std::string>& strs){
+void FF7::FunctionMetaData::ParseEnd(const std::string& item, std::deque<std::string>& strs){
     if (item == END){
     if (item == END){
         end_ = true;
         end_ = true;
         if (!strs.empty()){
         if (!strs.empty()){
@@ -69,7 +67,7 @@ void FunctionMetaData::ParseEnd(const std::string& item, std::deque<std::string>
     else ParseCharId(item, strs);
     else ParseCharId(item, strs);
 }
 }
 
 
-void FunctionMetaData::ParseCharId(const std::string& item, std::deque<std::string>& strs){
+void FF7::FunctionMetaData::ParseCharId(const std::string& item, std::deque<std::string>& strs){
     if (!item.empty()) character_id_ = std::stoi(item);
     if (!item.empty()) character_id_ = std::stoi(item);
     if (!strs.empty()){
     if (!strs.empty()){
         auto tmp = strs.front();
         auto tmp = strs.front();
@@ -78,13 +76,13 @@ void FunctionMetaData::ParseCharId(const std::string& item, std::deque<std::stri
     }
     }
 }
 }
 
 
-void FunctionMetaData::ParseEntity(const std::string& item, std::deque<std::string>& strs){
+void FF7::FunctionMetaData::ParseEntity(const std::string& item, std::deque<std::string>& strs){
     entity_name_ = item;
     entity_name_ = item;
     for (auto& part : strs)
     for (auto& part : strs)
         if (!part.empty()) entity_name_ += "_" + part;
         if (!part.empty()) entity_name_ += "_" + part;
 }
 }
 
 
-void FieldCodeGenerator::Generate(InstVec& insts, const Graph& graph){
+void FF7::FieldCodeGenerator::Generate(InstVec& insts, const Graph& graph){
     // TODO: Break into parts
     // TODO: Break into parts
     auto instruction = insts.begin();
     auto instruction = insts.begin();
     
     
@@ -211,14 +209,14 @@ void FieldCodeGenerator::Generate(InstVec& insts, const Graph& graph){
     }
     }
 }
 }
 
 
-void FieldCodeGenerator::AddOutputLine(
+void FF7::FieldCodeGenerator::AddOutputLine(
   std::string line, bool unindent_before, bool indent_after
   std::string line, bool unindent_before, bool indent_after
 ){lines_.push_back(CodeLine(line, unindent_before, indent_after));}
 ){lines_.push_back(CodeLine(line, unindent_before, indent_after));}
 
 
-float FieldCodeGenerator::GetScaleFactor() const
+float FF7::FieldCodeGenerator::GetScaleFactor() const
 {return static_cast<FieldEngine*>(_engine)->GetScaleFactor();}
 {return static_cast<FieldEngine*>(_engine)->GetScaleFactor();}
 
 
-void FieldCodeGenerator::OnBeforeStartFunction(const Function& function){
+void FF7::FieldCodeGenerator::OnBeforeStartFunction(const Function& function){
     FunctionMetaData meta_data(function._metadata);
     FunctionMetaData meta_data(function._metadata);
     if (meta_data.IsStart()){
     if (meta_data.IsStart()){
         AddOutputLine("EntityContainer[\"" + meta_data.GetEntityName() + "\"] = {", false, true);
         AddOutputLine("EntityContainer[\"" + meta_data.GetEntityName() + "\"] = {", false, true);
@@ -229,7 +227,7 @@ void FieldCodeGenerator::OnBeforeStartFunction(const Function& function){
     if (!comment.empty()) AddOutputLine("-- " + comment);
     if (!comment.empty()) AddOutputLine("-- " + comment);
 }
 }
 
 
-void FieldCodeGenerator::OnStartFunction(const Function& func){
+void FF7::FieldCodeGenerator::OnStartFunction(const Function& func){
     AddOutputLine("--[[");
     AddOutputLine("--[[");
     for (const auto& inst : insts_){
     for (const auto& inst : insts_){
         if (inst->_address >= func.mStartAddr && inst->_address <= func.mEndAddr){
         if (inst->_address >= func.mStartAddr && inst->_address <= func.mEndAddr){
@@ -246,7 +244,7 @@ void FieldCodeGenerator::OnStartFunction(const Function& func){
     }
     }
 }
 }
 
 
-void FieldCodeGenerator::OnEndFunction(const Function& function){
+void FF7::FieldCodeGenerator::OnEndFunction(const Function& function){
     // End function.
     // End function.
     AddOutputLine("end,", true, false);
     AddOutputLine("end,", true, false);
     // End class?
     // End class?
@@ -255,17 +253,17 @@ void FieldCodeGenerator::OnEndFunction(const Function& function){
     else AddOutputLine("\n");
     else AddOutputLine("\n");
 }
 }
 
 
-std::string FieldCodeGenerator::ConstructFuncSignature(const Function &function){
+std::string FF7::FieldCodeGenerator::ConstructFuncSignature(const Function &function){
     // Generate name
     // Generate name
     FunctionMetaData meta_data(function._metadata);
     FunctionMetaData meta_data(function._metadata);
     return formatter_.FunctionName(meta_data.GetEntityName(), function._name) + " = function(self)";
     return formatter_.FunctionName(meta_data.GetEntityName(), function._name) + " = function(self)";
 }
 }
 
 
-bool FieldCodeGenerator::OutputOnlyRequiredLabels() const{return true;}
+bool FF7::FieldCodeGenerator::OutputOnlyRequiredLabels() const{return true;}
 
 
-SUDM::IScriptFormatter& FieldCodeGenerator::GetFormatter(){return formatter_;}
+SUDM::IScriptFormatter& FF7::FieldCodeGenerator::GetFormatter(){return formatter_;}
 
 
-const std::string FieldCodeGenerator::FormatInstructionNotImplemented(
+const std::string FF7::FieldCodeGenerator::FormatInstructionNotImplemented(
   const std::string& entity, uint32 address, uint32 opcode
   const std::string& entity, uint32 address, uint32 opcode
 ){
 ){
     return (
     return (
@@ -276,7 +274,7 @@ const std::string FieldCodeGenerator::FormatInstructionNotImplemented(
     ).str();
     ).str();
 }
 }
 
 
-const std::string FieldCodeGenerator::FormatInstructionNotImplemented(
+const std::string FF7::FieldCodeGenerator::FormatInstructionNotImplemented(
   const std::string& entity, uint32 address, const Instruction& instruction
   const std::string& entity, uint32 address, const Instruction& instruction
 ){
 ){
     std::stringstream parameterList;
     std::stringstream parameterList;
@@ -292,10 +290,10 @@ const std::string FieldCodeGenerator::FormatInstructionNotImplemented(
       ).str();
       ).str();
 }
 }
 
 
-const std::string FieldCodeGenerator::FormatBool(uint32 value){
+const std::string FF7::FieldCodeGenerator::FormatBool(uint32 value){
     return value == 0 ? "false" : "true";
     return value == 0 ? "false" : "true";
 }
 }
 
 
-const std::string FieldCodeGenerator::FormatInvertedBool(uint32 value){
+const std::string FF7::FieldCodeGenerator::FormatInvertedBool(uint32 value){
     return value == 0 ? "true" : "false";
     return value == 0 ? "true" : "false";
 }
 }

+ 951 - 438
V-Gears-Installer/src/decompiler/field/FieldDisassembler.cpp

@@ -14,14 +14,13 @@
  */
  */
 
 
 #include <vector>
 #include <vector>
+#include "decompiler/decompiler_engine.h"
 #include <boost/format.hpp>
 #include <boost/format.hpp>
 #include <boost/algorithm/string/split.hpp>
 #include <boost/algorithm/string/split.hpp>
 #include <boost/algorithm/string.hpp>
 #include <boost/algorithm/string.hpp>
-#include "common/Lzs.h"
-#include "decompiler/decompiler_engine.h"
+#include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldDisassembler.h"
 #include "decompiler/field/FieldDisassembler.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldEngine.h"
-#include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/instruction/FieldBackgroundInstruction.h"
 #include "decompiler/field/instruction/FieldBackgroundInstruction.h"
 #include "decompiler/field/instruction/FieldCameraInstruction.h"
 #include "decompiler/field/instruction/FieldCameraInstruction.h"
 #include "decompiler/field/instruction/FieldCondJumpInstruction.h"
 #include "decompiler/field/instruction/FieldCondJumpInstruction.h"
@@ -36,67 +35,65 @@
 #include "decompiler/field/instruction/FieldUncondJumpInstruction.h"
 #include "decompiler/field/instruction/FieldUncondJumpInstruction.h"
 #include "decompiler/field/instruction/FieldWalkmeshInstruction.h"
 #include "decompiler/field/instruction/FieldWalkmeshInstruction.h"
 #include "decompiler/field/instruction/FieldWindowInstruction.h"
 #include "decompiler/field/instruction/FieldWindowInstruction.h"
+#include "common/Lzs.h"
+
 
 
-const int FieldDisassembler::MAGIC(0x0502);
+const int FF7::FieldDisassembler::MAGIC(0x0502);
 
 
-const int FieldDisassembler::NUM_SECTIONS(7);
+const int FF7::FieldDisassembler::NUM_SECTIONS(7);
 
 
-FieldDisassembler::FieldDisassembler(
-  SUDM::IScriptFormatter& formatter, FieldEngine* engine, InstVec& insts,
-  const std::vector<unsigned char>& raw_script_data
-) : SimpleDisassembler(insts), engine_(engine), formatter_(formatter){
-    loaded_from_raw_ = true;
-    // If loading a raw section then we don't have a "sections header" to skip.
+FF7::FieldDisassembler::FieldDisassembler(
+  SUDM::IScriptFormatter& formatter, FieldEngine* engine,
+  InstVec& insts, const std::vector<unsigned char>& raw_script_data
+): SimpleDisassembler(insts), engine_(engine), formatter_(formatter){
+    loaded_from_raw_data_ = true;
+    // If loading a raw section then skip the header section.
     section_pointers_size_ = 0;
     section_pointers_size_ = 0;
     auto data_copy = raw_script_data;
     auto data_copy = raw_script_data;
     stream_ = std::make_unique<BinaryReader>(std::move(data_copy));
     stream_ = std::make_unique<BinaryReader>(std::move(data_copy));
     ReadHeader();
     ReadHeader();
 }
 }
 
 
-FieldDisassembler::FieldDisassembler(
+FF7::FieldDisassembler::FieldDisassembler(
   SUDM::IScriptFormatter& formatter, FieldEngine *engine, InstVec &insts
   SUDM::IScriptFormatter& formatter, FieldEngine *engine, InstVec &insts
-) : SimpleDisassembler(insts), engine_(engine), formatter_(formatter){
+): SimpleDisassembler(insts), engine_(engine), formatter_(formatter){
     section_pointers_size_ = (sizeof(uint32) * NUM_SECTIONS);
     section_pointers_size_ = (sizeof(uint32) * NUM_SECTIONS);
 }
 }
 
 
-FieldDisassembler::~FieldDisassembler(){}
+float FF7::FieldDisassembler::GetScaleFactor() const{return scale_factor_;}
 
 
-void FieldDisassembler::ReadHeader(){
-    if (!loaded_from_raw_){
+FF7::FieldDisassembler::~FieldDisassembler(){}
+
+void FF7::FieldDisassembler::ReadHeader(){
+    if (!loaded_from_raw_data_){
         // First read the file section pointers.
         // First read the file section pointers.
         for (int i = 0; i < NUM_SECTIONS; i ++) sections_[i] = stream_->ReadU32();
         for (int i = 0; i < NUM_SECTIONS; i ++) sections_[i] = stream_->ReadU32();
         // Now fix up from PSX RAM pointers to simple file offsets.
         // Now fix up from PSX RAM pointers to simple file offsets.
-        const uint32 base_ptr = sections_[0];
-        for (int i = 0; i < NUM_SECTIONS; i ++)
-            sections_[i] = (sections_[i] - base_ptr) + section_pointers_size_;
+        const uint32 basePtr = sections_[0];
+        for (int i = 0; i < NUM_SECTIONS; i++)
+            sections_[i] = (sections_[i] - basePtr) + section_pointers_size_;
         // Now seek to the script section.
         // Now seek to the script section.
         stream_->Seek(sections_[SCRIPT]);
         stream_->Seek(sections_[SCRIPT]);
     }
     }
-
     // Read the script header
     // Read the script header
     header_.Read(*stream_);
     header_.Read(*stream_);
     scale_factor_ = static_cast<float>(header_.scale) / 512.0f;
     scale_factor_ = static_cast<float>(header_.scale) / 512.0f;
 }
 }
 
 
-void FieldDisassembler::ReadHeader(BinaryReader& reader){
-    header_.Read(reader);
-    header_end_position_ = reader.GetPosition();
-}
-
-void FieldDisassembler::Open(const char *filename){
+void FF7::FieldDisassembler::Open(const char *filename){
     // Read all of the file, decompress it, then stuff it into a stream.
     // Read all of the file, decompress it, then stuff it into a stream.
     stream_ = std::make_unique<BinaryReader>(Lzs::Decompress(BinaryReader::ReadAll(filename)));
     stream_ = std::make_unique<BinaryReader>(Lzs::Decompress(BinaryReader::ReadAll(filename)));
     ReadHeader();
     ReadHeader();
 }
 }
 
 
-uint32 FieldDisassembler::GetEndOfScriptOffset(
+uint32 FF7::FieldDisassembler::GetEndOfScriptOffset(
   uint16 cur_entry_point, size_t entity_index, size_t script_index
   uint16 cur_entry_point, size_t entity_index, size_t script_index
 ){
 ){
     uint16 next_entry_point = cur_entry_point;
     uint16 next_entry_point = cur_entry_point;
     do{
     do{
         if (script_index + 1 >= 32){
         if (script_index + 1 >= 32){
-            // If this is the very last script, so use the end of its data
-            // which is the offset to strings.
+            // If this is the very last script, so use the end of its
+            // data which is the offset to strings.
             if (entity_index + 1 >= header_.entity_scripts.size()) return header_.offset_to_strings;
             if (entity_index + 1 >= header_.entity_scripts.size()) return header_.offset_to_strings;
             else{
             else{
                 // Wrap around to the next entity
                 // Wrap around to the next entity
@@ -104,14 +101,14 @@ uint32 FieldDisassembler::GetEndOfScriptOffset(
                 script_index = 0;
                 script_index = 0;
             }
             }
         }
         }
-        // Get the next script in the same entity:
+        // Get the next script in the same entity.
         else script_index ++;
         else script_index ++;
         next_entry_point = header_.entity_scripts[entity_index][script_index];
         next_entry_point = header_.entity_scripts[entity_index][script_index];
     } while (next_entry_point == cur_entry_point);
     } while (next_entry_point == cur_entry_point);
     return next_entry_point;
     return next_entry_point;
 }
 }
 
 
-std::unique_ptr<Function> FieldDisassembler::StartFunction(size_t script_index){
+std::unique_ptr<Function> FF7::FieldDisassembler::StartFunction(size_t script_index){
     auto func = std::make_unique<Function>();
     auto func = std::make_unique<Function>();
     func->_retVal = false;
     func->_retVal = false;
     func->_args = 0;
     func->_args = 0;
@@ -120,25 +117,25 @@ std::unique_ptr<Function> FieldDisassembler::StartFunction(size_t script_index){
     return func;
     return func;
 }
 }
 
 
-void FieldDisassembler::DoDisassemble(){
+void FF7::FieldDisassembler::DoDisassemble(){
     // Loop through the scripts for each entity.
     // Loop through the scripts for each entity.
     for (size_t entity_number = 0; entity_number < header_.entity_scripts.size(); entity_number ++){
     for (size_t entity_number = 0; entity_number < header_.entity_scripts.size(); entity_number ++){
         std::string original_name = header_.field_entity_names[entity_number].data();
         std::string original_name = header_.field_entity_names[entity_number].data();
-        // If the entity name was blank in the file then use a consistent generated name.
+        // If the entity name was blank in the file then use a consistent generated name
         if (original_name.empty()) original_name = "entity_" + std::to_string(entity_number);
         if (original_name.empty()) original_name = "entity_" + std::to_string(entity_number);
         const std::string entity_name = formatter_.EntityName(original_name);
         const std::string entity_name = formatter_.EntityName(original_name);
         // Only parse each script one.
         // Only parse each script one.
         std::set<uint16> parsed_scripts;
         std::set<uint16> parsed_scripts;
         std::vector<ScriptInfo> script_info;
         std::vector<ScriptInfo> script_info;
-        // Collect the scripts to parse.
+        // Collect the scripts to parse
         for (
         for (
           size_t script_index = 0;
           size_t script_index = 0;
           script_index < header_.entity_scripts[entity_number].size();
           script_index < header_.entity_scripts[entity_number].size();
           script_index ++
           script_index ++
         ){
         ){
             uint16 script_entry_point = header_.entity_scripts[entity_number][script_index];
             uint16 script_entry_point = header_.entity_scripts[entity_number][script_index];
-            // If this scripts entry point is already parsed, then don't do it again as it means
-            // two scripts have the same entry which only seems to be true for "empty" scripts.
+            // If this scripts entry point is already parsed, don't do it again as it means
+            // two scripts have the same entry, which only seems to be true for "empty" scripts.
             if (parsed_scripts.find(script_entry_point) != std::end(parsed_scripts)) continue;
             if (parsed_scripts.find(script_entry_point) != std::end(parsed_scripts)) continue;
             parsed_scripts.insert(script_entry_point);
             parsed_scripts.insert(script_entry_point);
             const uint32 next_script_entry_point = GetEndOfScriptOffset(
             const uint32 next_script_entry_point = GetEndOfScriptOffset(
@@ -146,13 +143,13 @@ void FieldDisassembler::DoDisassemble(){
             );
             );
             const uint32 script_size = next_script_entry_point - script_entry_point;
             const uint32 script_size = next_script_entry_point - script_entry_point;
             if (script_size > 0){
             if (script_size > 0){
-                ScriptInfo info = { script_entry_point, next_script_entry_point, script_index };
+                ScriptInfo info = {script_entry_point, next_script_entry_point, script_index};
                 script_info.push_back(info);
                 script_info.push_back(info);
             }
             }
         }
         }
         for (auto it = script_info.begin(); it != script_info.end(); it ++){
         for (auto it = script_info.begin(); it != script_info.end(); it ++){
             const bool is_start = it == script_info.begin();
             const bool is_start = it == script_info.begin();
-            const bool is_end = it == (--script_info.end());
+            const bool is_end = it == (-- script_info.end());
             DisassembleIndivdualScript(
             DisassembleIndivdualScript(
               entity_name, entity_number, it->index, it->entry_point,
               entity_name, entity_number, it->index, it->entry_point,
               it->next_entry_point, is_start, is_end
               it->next_entry_point, is_start, is_end
@@ -161,19 +158,17 @@ void FieldDisassembler::DoDisassemble(){
     }
     }
 }
 }
 
 
-float FieldDisassembler::GetScaleFactor() const{return scale_factor_;}
-
-int FieldDisassembler::FindId(uint32 start_addr, uint32 end_addr, const InstVec& insts){
+int FF7::FieldDisassembler::FindId(uint32 start_addr, uint32 end_addr, const InstVec& insts){
     for (const InstPtr& instruction : insts){
     for (const InstPtr& instruction : insts){
         if (instruction->_address >= start_addr && instruction->_address <= end_addr){
         if (instruction->_address >= start_addr && instruction->_address <= end_addr){
-            if (instruction->_opcode == OPCODE::opCodeCHAR)
+            if (instruction->_opcode == FF7::OPCODES::opCodeCHAR)
                 return instruction->_params[0]->getSigned();
                 return instruction->_params[0]->getSigned();
         }
         }
     }
     }
     return -1;
     return -1;
 }
 }
 
 
-void FieldDisassembler::AddFunc(
+void FF7::FieldDisassembler::AddFunc(
   std::string entity_name, size_t entity_index, size_t script_index, uint32 next_script_entry_point,
   std::string entity_name, size_t entity_index, size_t script_index, uint32 next_script_entry_point,
   const bool is_start, bool is_end, bool to_return_only, std::string func_name
   const bool is_start, bool is_end, bool to_return_only, std::string func_name
 ){
 ){
@@ -182,7 +177,7 @@ void FieldDisassembler::AddFunc(
     std::vector<float> point_b = {0, 0, 0};
     std::vector<float> point_b = {0, 0, 0};
     const auto SCRIPT_ENTRY_POINT = stream_->GetPosition();
     const auto SCRIPT_ENTRY_POINT = stream_->GetPosition();
     // Read each block of opcodes up to a return.
     // Read each block of opcodes up to a return.
-    const size_t old_num_instructions = _insts.size();
+    const size_t old_num_instructions = insts_.size();
     // Initialize the function.
     // Initialize the function.
     std::unique_ptr<Function> func = StartFunction(script_index);
     std::unique_ptr<Function> func = StartFunction(script_index);
     // Read.
     // Read.
@@ -197,22 +192,23 @@ void FieldDisassembler::AddFunc(
         if (stream_pos != endPos) is_end = false;
         if (stream_pos != endPos) is_end = false;
     }
     }
     else{
     else{
-        // Keep going till we have all of the script, i.e if we bail at a
-        // return then call again till we have everything
+        // Keep going until all of the scriptis fectched, i.e if bailed at a
+        // return, then call again until everything is parsed.
         while (stream_->GetPosition() != next_script_entry_point + section_pointers_size_){
         while (stream_->GetPosition() != next_script_entry_point + section_pointers_size_){
             is_line = ReadOpCodesToPositionOrReturn(
             is_line = ReadOpCodesToPositionOrReturn(
               next_script_entry_point + section_pointers_size_, point_a, point_b
               next_script_entry_point + section_pointers_size_, point_a, point_b
             );
             );
         }
         }
     }
     }
-    // Read metadata, mark start the function as first and/or last of the class.
+    // Read metadata, mark start and/or end.
     std::string meta_data;
     std::string meta_data;
     if (is_start && is_end) meta_data = "start_end_";
     if (is_start && is_end) meta_data = "start_end_";
     else if (is_start) meta_data = "start_";
     else if (is_start) meta_data = "start_";
     else if (is_end) meta_data = "end_";
     else if (is_end) meta_data = "end_";
-    const size_t new_num_instructions = _insts.size();
+
+    const size_t new_num_instructions = insts_.size();
     func->mNumInstructions = new_num_instructions - old_num_instructions;
     func->mNumInstructions = new_num_instructions - old_num_instructions;
-    func->mEndAddr = _insts.back()->_address;
+    func->mEndAddr = insts_.back()->_address;
     if (!func_name.empty()) func->_name = func_name;
     if (!func_name.empty()) func->_name = func_name;
     if (engine_->EntityIsLine(entity_index)){
     if (engine_->EntityIsLine(entity_index)){
         switch (script_index){
         switch (script_index){
@@ -232,15 +228,13 @@ void FieldDisassembler::AddFunc(
             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->mStartAddr, func->mEndAddr, insts_);
     // If there is no ID check if there was an ID for this entity in any of
     // If there is no ID check if there was an ID for this entity in any of
     // its other functions and use that instead.
     // its other functions and use that instead.
     if (id == -1){
     if (id == -1){
         for (auto& func : engine_->_functions){
         for (auto& func : engine_->_functions){
             FunctionMetaData func_meta_data(func.second._metadata);
             FunctionMetaData func_meta_data(func.second._metadata);
-            if (
-              func_meta_data.GetEntityName() == entity_name && func_meta_data.GetCharacterId() != -1
-            ){
+            if (func_meta_data.GetEntityName() == entity_name && func_meta_data.GetCharacterId() != -1){
                 id = func_meta_data.GetCharacterId();
                 id = func_meta_data.GetCharacterId();
                 break;
                 break;
             }
             }
@@ -254,10 +248,10 @@ void FieldDisassembler::AddFunc(
     if (is_line) engine_->MarkEntityAsLine(entity_index, true, point_a, point_b);
     if (is_line) engine_->MarkEntityAsLine(entity_index, true, point_a, point_b);
 }
 }
 
 
-void FieldDisassembler::DisassembleIndivdualScript(
-    std::string entity_name, size_t entity_index, size_t script_entry_point,
-    size_t script_index, uint32 next_script_entry_point, bool is_start, bool is_end
-){
+void FF7::FieldDisassembler::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)
+{
     script_entry_point += section_pointers_size_;
     script_entry_point += section_pointers_size_;
     stream_->Seek(script_entry_point);
     stream_->Seek(script_entry_point);
     address_base_ = stream_->GetPosition();
     address_base_ = stream_->GetPosition();
@@ -279,56 +273,46 @@ void FieldDisassembler::DisassembleIndivdualScript(
     }
     }
     else{
     else{
         const size_t end_pos = next_script_entry_point + section_pointers_size_;
         const size_t end_pos = next_script_entry_point + section_pointers_size_;
-        // Read the init script, which means stop at the first return
+        // Read the init script, which means stop at the first return.
         AddFunc(
         AddFunc(
           entity_name, entity_index, script_index, next_script_entry_point,
           entity_name, entity_index, script_index, next_script_entry_point,
           is_start, is_end, true, "on_start"
           is_start, is_end, true, "on_start"
         );
         );
-
         // Not at the end of this script? Then the remaining data is the "main" script
         // Not at the end of this script? Then the remaining data is the "main" script
         auto stream_pos = stream_->GetPosition();
         auto stream_pos = stream_->GetPosition();
         if (stream_pos != end_pos){
         if (stream_pos != end_pos){
-            // The "main" script can have more than one return statement
+            // The "main" script can have more than one return statement...
             AddFunc(
             AddFunc(
               entity_name, entity_index, script_index, next_script_entry_point,
               entity_name, entity_index, script_index, next_script_entry_point,
               false, is_end, false, "on_update"
               false, is_end, false, "on_update"
             );
             );
             stream_pos = stream_->GetPosition();
             stream_pos = stream_->GetPosition();
-
-            // But should end exactly on the end pos
+            // ... but should end exactly on the end pos
             if (stream_pos != end_pos) throw InternalDecompilerError();
             if (stream_pos != end_pos) throw InternalDecompilerError();
         }
         }
-
     }
     }
 }
 }
 
 
-/**
- * @todo Understand and document.
- * @todo Maybe add to the class.
- */
-const InstructionRecord kOpcodes[] ={
-    // Flow
-    { 1, OPCODE::RET, "RET", "", FieldControlFlowInstruction::Create },
-    { 1, OPCODE::REQ, "REQ", "BU", FieldControlFlowInstruction::Create },
-    { 1, OPCODE::REQSW, "REQSW", "BU", FieldControlFlowInstruction::Create },
-    { 1, OPCODE::REQEW, "REQEW", "BU", FieldControlFlowInstruction::Create },
-    { 1, OPCODE::NOP, "NOP", "", FieldNoOperationInstruction::Create },
-    { 1, OPCODE::IFUB, "IFUB", "NNBBBL", FieldNoOperationInstruction::Create }
+
+FF7::FieldDisassembler::InstructionRecord FF7::FieldDisassembler::FLOW_OPCODES[] ={
+    {1, FF7::OPCODES::RET, "RET", "", FF7::FF7ControlFlowInstruction::Create},
+    {1, FF7::OPCODES::REQ, "REQ", "BU", FF7::FF7ControlFlowInstruction::Create},
+    {1, FF7::OPCODES::REQSW, "REQSW", "BU", FF7::FF7ControlFlowInstruction::Create},
+    {1, FF7::OPCODES::REQEW, "REQEW", "BU", FF7::FF7ControlFlowInstruction::Create},
+    {1, FF7::OPCODES::NOP, "NOP", "", FF7::FieldNoOperationInstruction::Create},
+    {1, FF7::OPCODES::IFUB, "IFUB", "NNBBBL", FF7::FieldNoOperationInstruction::Create}
 };
 };
 
 
-/**
- * @todo Understand and document.
- * @todo Maybe add to the class.
- */
-std::map<std::string, const InstructionRecord*> FieldInstructions(){
-    // Convert the array to a map that we can query on by mnemonic
+std::map<std::string, const FF7::FieldDisassembler::InstructionRecord*>
+  FF7::FieldDisassembler::FieldInstructions(){
+    // Convert the array to a map that we can query on by opcode name.
     std::map<std::string, const InstructionRecord*> name_to_instruction_records;
     std::map<std::string, const InstructionRecord*> name_to_instruction_records;
-    for (size_t i = 0; i < boost::size(kOpcodes); i++)
-        name_to_instruction_records[kOpcodes[i].opcode_name] = &kOpcodes[i];
+    for (size_t i = 0; i < boost::size(FLOW_OPCODES); i ++)
+        name_to_instruction_records[FLOW_OPCODES[i].opcode_name] = &FLOW_OPCODES[i];
     return name_to_instruction_records;
     return name_to_instruction_records;
 }
 }
 
 
-bool FieldDisassembler::ReadOpCodesToPositionOrReturn(
+bool FF7::FieldDisassembler::ReadOpCodesToPositionOrReturn(
   size_t end_pos, std::vector<float>& point_a, std::vector<float>& point_b
   size_t end_pos, std::vector<float>& point_a, std::vector<float>& point_b
 ){
 ){
     bool is_line = false;
     bool is_line = false;
@@ -336,395 +320,924 @@ bool FieldDisassembler::ReadOpCodesToPositionOrReturn(
     while (stream_->GetPosition() < end_pos){
     while (stream_->GetPosition() < end_pos){
         uint8 opcode = stream_->ReadU8();
         uint8 opcode = stream_->ReadU8();
         uint32 full_opcode = 0;
         uint32 full_opcode = 0;
-        std::string opcodePrefix;
+        full_opcode = (full_opcode << 8) + opcode;
         switch (opcode){
         switch (opcode){
+
             // Flow
             // Flow
-            CASE_OPCODE(OPCODE::IFUB, "IFUB", FieldCondJumpInstruction, 0, "NBBBB");
-            /*case OPCODE::IFUB:
-                full_opcode = (full_opcode << 8) + OPCODE::IFUB;
-                this->_insts.push_back(new FieldCondJumpInstruction());
-                (this->_insts.back())->_opcode = full_opcode;
-                (this->_insts.back())->_address = this->address_;
-                (this->_insts.back())->_stackChange = 0;
-                (this->_insts.back())->_name = opcodePrefix + std::string("IFUB");
-                (this->_insts.back())->_codeGenData = "";
-                this->readParams((this->_insts.back()), "NBBBB");
-                break;*/
-            CASE_OPCODE(OPCODE::RET, "RET", FieldControlFlowInstruction, 0, "");
-            CASE_OPCODE(OPCODE::REQ, "REQ", FieldControlFlowInstruction, 0, "BU");
-            CASE_OPCODE(OPCODE::REQSW, "REQSW", FieldControlFlowInstruction, 0, "BU");
-            CASE_OPCODE(OPCODE::REQEW, "REQEW", FieldControlFlowInstruction, 0, "BU");
-            CASE_OPCODE(OPCODE::PREQ, "PREQ", FieldControlFlowInstruction, 0, "BU");
-            CASE_OPCODE(OPCODE::PRQSW, "PRQSW", FieldControlFlowInstruction, 0, "BU");
-            CASE_OPCODE(OPCODE::PRQEW, "PRQEW", FieldControlFlowInstruction, 0, "BU");
-            CASE_OPCODE(OPCODE::RETTO, "RETTO", FieldControlFlowInstruction, 0, "U");
-            CASE_OPCODE(OPCODE::JMPF, "JMPF", FieldUncondJumpInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::JMPFL, "JMPFL", FieldUncondJumpInstruction, 0, "w");
-            CASE_OPCODE(OPCODE::JMPB, "JMPB", FieldUncondJumpInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::JMPBL, "JMPBL", FieldUncondJumpInstruction, 0, "w");
-            CASE_OPCODE(OPCODE::IFUBL, "IFUBL", FieldCondJumpInstruction, 0, "NBBBw");
-            CASE_OPCODE(OPCODE::IFSW, "IFSW", FieldCondJumpInstruction, 0, "NwwBB");
-            CASE_OPCODE(OPCODE::IFSWL, "IFSWL", FieldCondJumpInstruction, 0, "NwwBw");
-            CASE_OPCODE(OPCODE::IFUW, "IFUW", FieldCondJumpInstruction, 0, "NwwBB");
-            CASE_OPCODE(OPCODE::IFUWL, "IFUWL", FieldCondJumpInstruction, 0, "NwwBw");
-            CASE_OPCODE(OPCODE::WAIT, "WAIT", FieldControlFlowInstruction, 0, "w");
-            CASE_OPCODE(OPCODE::IFKEY, "IFKEY", FieldCondJumpInstruction, 0, "wB");
-            CASE_OPCODE(OPCODE::IFKEYON, "IFKEYON", FieldCondJumpInstruction, 0, "wB");
-            CASE_OPCODE(OPCODE::IFKEYOFF, "IFKEYOFF", FieldCondJumpInstruction, 0, "wB");
-            CASE_OPCODE(OPCODE::NOP, "NOP", FieldNoOperationInstruction, 0, "");
-            CASE_OPCODE(OPCODE::IFPRTYQ, "IFPRTYQ", FieldCondJumpInstruction, 0, "BB");
-            CASE_OPCODE(OPCODE::IFMEMBQ, "IFMEMBQ", FieldCondJumpInstruction, 0, "BB");
+            case OPCODES::IFUB:
+                ParseOpcode(full_opcode, "IFUB", new FieldCondJumpInstruction(), 0, "NBBBB");
+                break;
+            case OPCODES::RET:
+                ParseOpcode(full_opcode, "RET", new FF7ControlFlowInstruction(), 0, "");
+                break;
+            case OPCODES::REQ:
+                ParseOpcode(full_opcode, "REQ", new FF7ControlFlowInstruction(), 0, "BU");
+                break;
+            case OPCODES::REQSW:
+                ParseOpcode(full_opcode, "REQSW", new FF7ControlFlowInstruction(), 0, "BU");
+                break;
+            case OPCODES::REQEW:
+                ParseOpcode(full_opcode, "REQEW", new FF7ControlFlowInstruction(), 0, "BU");
+                break;
+            case OPCODES::PREQ:
+                ParseOpcode(full_opcode, "PREQ", new FF7ControlFlowInstruction(), 0, "BU");
+                break;
+            case OPCODES::PRQSW:
+                ParseOpcode(full_opcode, "PRQSW", new FF7ControlFlowInstruction(), 0, "BU");
+                break;
+            case OPCODES::PRQEW:
+                ParseOpcode(full_opcode, "PRQEW", new FF7ControlFlowInstruction(), 0, "BU");
+                break;
+            case OPCODES::RETTO:
+                ParseOpcode(full_opcode, "RETTO", new FF7ControlFlowInstruction(), 0, "U");
+                break;
+            case OPCODES::JMPF:
+                ParseOpcode(full_opcode, "JMPF", new FieldUncondJumpInstruction(), 0, "B");
+                break;
+            case OPCODES::JMPFL:
+                ParseOpcode(full_opcode, "JMPFL", new FieldUncondJumpInstruction(), 0, "w");
+                break;
+            case OPCODES::JMPB:
+                ParseOpcode(full_opcode, "JMPB", new FieldUncondJumpInstruction(), 0, "B");
+                break;
+            case OPCODES::JMPBL:
+                ParseOpcode(full_opcode, "JMPBL", new FieldUncondJumpInstruction(), 0, "w");
+                break;
+            case OPCODES::IFUBL:
+                ParseOpcode(full_opcode, "IFUBL", new FieldCondJumpInstruction(), 0, "NBBBw");
+                break;
+            case OPCODES::IFSW:
+                ParseOpcode(full_opcode, "IFSW", new FieldCondJumpInstruction(), 0, "NwwBB");
+                break;
+            case OPCODES::IFSWL:
+                ParseOpcode(full_opcode, "IFSWL", new FieldCondJumpInstruction(), 0, "NwwBw");
+                break;
+            case OPCODES::IFUW:
+                ParseOpcode(full_opcode, "IFUW", new FieldCondJumpInstruction(), 0, "NwwBB");
+                break;
+            case OPCODES::IFUWL:
+                ParseOpcode(full_opcode, "IFUWL", new FieldCondJumpInstruction(), 0, "NwwBw");
+                break;
+            case OPCODES::WAIT:
+                ParseOpcode(full_opcode, "WAIT", new FF7ControlFlowInstruction(), 0, "w");
+                break;
+            case OPCODES::IFKEY:
+                ParseOpcode(full_opcode, "IFKEY", new FieldCondJumpInstruction(), 0, "wB");
+                break;
+            case OPCODES::IFKEYON:
+                ParseOpcode(full_opcode, "IFKEYON", new FieldCondJumpInstruction(), 0, "wB");
+                break;
+            case OPCODES::IFKEYOFF:
+                ParseOpcode(full_opcode, "IFKEYOFF", new FieldCondJumpInstruction(), 0, "wB");
+                break;
+            case OPCODES::NOP:
+                ParseOpcode(full_opcode, "NOP", new FieldNoOperationInstruction(), 0, "");
+                break;
+            case OPCODES::IFPRTYQ:
+                ParseOpcode(full_opcode, "IFPRTYQ", new FieldCondJumpInstruction(), 0, "BB");
+                break;
+            case OPCODES::IFMEMBQ:
+                ParseOpcode(full_opcode, "IFMEMBQ", new FieldCondJumpInstruction(), 0, "BB");
+                break;
 
 
             // Module
             // Module
-            CASE_OPCODE(OPCODE::DSKCG, "DSKCG", FieldModuleInstruction, 0, "B");
-            START_SUBOPCODE(OPCODE::SPECIAL)
-                CASE_OPCODE(OPCODE_SPECIAL::ARROW, "ARROW", FieldModuleInstruction, 0, "B");
-            CASE_OPCODE(OPCODE_SPECIAL::PNAME, "PNAME", FieldModuleInstruction, 0, "B");
-            CASE_OPCODE(OPCODE_SPECIAL::GMSPD, "GMSPD", FieldModuleInstruction, 0, "B");
-            CASE_OPCODE(OPCODE_SPECIAL::SMSPD, "SMSPD", FieldModuleInstruction, 0, "BB");
-            CASE_OPCODE(OPCODE_SPECIAL::FLMAT, "FLMAT", FieldModuleInstruction, 0, "");
-            CASE_OPCODE(OPCODE_SPECIAL::FLITM, "FLITM", FieldModuleInstruction, 0, "");
-            CASE_OPCODE(OPCODE_SPECIAL::BTLCK, "BTLCK", FieldModuleInstruction, 0, "B");
-            CASE_OPCODE(OPCODE_SPECIAL::MVLCK, "MVLCK", FieldModuleInstruction, 0, "B");
-            CASE_OPCODE(OPCODE_SPECIAL::SPCNM, "SPCNM", FieldModuleInstruction, 0, "BB");
-            CASE_OPCODE(OPCODE_SPECIAL::RSGLB, "RSGLB", FieldModuleInstruction, 0, "");
-            CASE_OPCODE(OPCODE_SPECIAL::CLITM, "CLITM", FieldModuleInstruction, 0, "");
-            END_SUBOPCODE
-                CASE_OPCODE(OPCODE::MINIGAME, "MINIGAME", FieldModuleInstruction, 0, "wsswBB");
-            CASE_OPCODE(OPCODE::BTMD2, "BTMD2", FieldModuleInstruction, 0, "d");
-            CASE_OPCODE(OPCODE::BTRLD, "BTRLD", FieldModuleInstruction, 0, "NB");
-            CASE_OPCODE(OPCODE::BTLTB, "BTLTB", FieldModuleInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::MAPJUMP, "MAPJUMP", FieldModuleInstruction, 0, "wsswB");
-            CASE_OPCODE(OPCODE::LSTMP, "LSTMP", FieldModuleInstruction, 0, "NB");
-            CASE_OPCODE(OPCODE::BATTLE, "BATTLE", FieldModuleInstruction, 0, "Nw");
-            CASE_OPCODE(OPCODE::BTLON, "BTLON", FieldModuleInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::BTLMD, "BTLMD", FieldModuleInstruction, 0, "w");
-            CASE_OPCODE(OPCODE::MPJPO, "MPJPO", FieldModuleInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::PMJMP, "PMJMP", FieldModuleInstruction, 0, "w");
-            CASE_OPCODE(OPCODE::PMJMP2, "PMJMP2", FieldModuleInstruction, 0, "");
-            CASE_OPCODE(OPCODE::GAMEOVER, "GAMEOVER", FieldModuleInstruction, 0, "");
+            case OPCODES::DSKCG:
+                ParseOpcode(full_opcode, "DSKCG", new FieldModuleInstruction(), 0, "B");
+                break;
+            case OPCODES::SPECIAL:
+                full_opcode = 0;
+                full_opcode = (full_opcode << 8) + OPCODES::SPECIAL;
+                opcode = this->stream_->ReadU8();
+                switch (opcode){
+                    case OPCODES_SPECIAL::ARROW:
+                        ParseOpcode(full_opcode, "ARROW", new FieldModuleInstruction(), 0, "B");
+                        break;
+                    case OPCODES_SPECIAL::PNAME:
+                        ParseOpcode(full_opcode, "PNAME", new FieldModuleInstruction(), 0, "B");
+                        break;
+                    case OPCODES_SPECIAL::GMSPD:
+                        ParseOpcode(full_opcode, "GMSPD", new FieldModuleInstruction(), 0, "B");
+                        break;
+                    case OPCODES_SPECIAL::SMSPD:
+                        ParseOpcode(full_opcode, "SMSPD", new FieldModuleInstruction(), 0, "BB");
+                        break;
+                    case OPCODES_SPECIAL::FLMAT:
+                        ParseOpcode(full_opcode, "FLMAT", new FieldModuleInstruction(), 0, "");
+                        break;
+                    case OPCODES_SPECIAL::FLITM:
+                        ParseOpcode(full_opcode, "FLITM", new FieldModuleInstruction(), 0, "");
+                        break;
+                    case OPCODES_SPECIAL::BTLCK:
+                        ParseOpcode(full_opcode, "BTLCK", new FieldModuleInstruction(), 0, "B");
+                        break;
+                    case OPCODES_SPECIAL::MVLCK:
+                        ParseOpcode(full_opcode, "MVLCK", new FieldModuleInstruction(), 0, "B");
+                        break;
+                    case OPCODES_SPECIAL::SPCNM:
+                        ParseOpcode(full_opcode, "SPCNM", new FieldModuleInstruction(), 0, "BB");
+                        break;
+                    case OPCODES_SPECIAL::RSGLB:
+                        ParseOpcode(full_opcode, "RSGLB", new FieldModuleInstruction(), 0, "");
+                        break;
+                    case OPCODES_SPECIAL::CLITM:
+                        ParseOpcode(full_opcode, "CLITM", new FieldModuleInstruction(), 0, "");
+                        break;
+                    default:
+                        throw UnknownSubOpcodeException(this->address_, opcode);\
+                }
+                this->address_++ ;
+                break;
+            case OPCODES::MINIGAME:
+                ParseOpcode(full_opcode, "MINIGAME", new FieldModuleInstruction(), 0, "wsswBB");
+                break;
+            case OPCODES::BTMD2:
+                ParseOpcode(full_opcode, "BTMD2", new FieldModuleInstruction(), 0, "d");
+                break;
+            case OPCODES::BTRLD:
+                ParseOpcode(full_opcode, "BTRLD", new FieldModuleInstruction(), 0, "NB");
+                break;
+            case OPCODES::BTLTB:
+                ParseOpcode(full_opcode, "BTLTB", new FieldModuleInstruction(), 0, "B");
+                break;
+            case OPCODES::MAPJUMP:
+                ParseOpcode(full_opcode, "MAPJUMP", new FieldModuleInstruction(), 0, "wsswB");
+                break;
+            case OPCODES::LSTMP:
+                ParseOpcode(full_opcode, "LSTMP", new FieldModuleInstruction(), 0, "NB");
+                break;
+            case OPCODES::BATTLE:
+                ParseOpcode(full_opcode, "BATTLE", new FieldModuleInstruction(), 0, "Nw");
+                break;
+            case OPCODES::BTLON:
+                ParseOpcode(full_opcode, "BTLON", new FieldModuleInstruction(), 0, "B");
+                break;
+            case OPCODES::BTLMD:
+                ParseOpcode(full_opcode, "BTLMD", new FieldModuleInstruction(), 0, "w");
+                break;
+            case OPCODES::MPJPO:
+                ParseOpcode(full_opcode, "MPJPO", new FieldModuleInstruction(), 0, "B");
+                break;
+            case OPCODES::PMJMP:
+                ParseOpcode(full_opcode, "PMJMP", new FieldModuleInstruction(), 0, "w");
+                break;
+            case OPCODES::PMJMP2:
+                ParseOpcode(full_opcode, "PMJMP2", new FieldModuleInstruction(), 0, "");
+                break;
+            case OPCODES::GAMEOVER:
+                ParseOpcode(full_opcode, "GAMEOVER", new FieldModuleInstruction(), 0, "");
+                break;
 
 
             // Math
             // Math
-            CASE_OPCODE(OPCODE::PLUS_, "PLUS!", FieldMathInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::PLUS2_, "PLUS2!", FieldMathInstruction, 0, "NBw");
-            CASE_OPCODE(OPCODE::MINUS_, "MINUS!", FieldMathInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::MINUS2_, "MINUS2!", FieldMathInstruction, 0, "NBw");
-            CASE_OPCODE(OPCODE::INC_, "INC!", FieldMathInstruction, 0, "BB");
-            CASE_OPCODE(OPCODE::INC2_, "INC2!", FieldMathInstruction, 0, "BB");
-            CASE_OPCODE(OPCODE::DEC_, "DEC!", FieldMathInstruction, 0, "BB");
-            CASE_OPCODE(OPCODE::DEC2_, "DEC2!", FieldMathInstruction, 0, "BB");
-            CASE_OPCODE(OPCODE::RDMSD, "RDMSD", FieldMathInstruction, 0, "NB");
-            CASE_OPCODE(OPCODE::SETBYTE, "SETBYTE", FieldMathInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::SETWORD, "SETWORD", FieldMathInstruction, 0, "NBw");
-            CASE_OPCODE(OPCODE::BITON, "BITON", FieldMathInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::BITOFF, "BITOFF", FieldMathInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::BITXOR, "BITXOR", FieldMathInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::PLUS, "PLUS", FieldMathInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::PLUS2, "PLUS2", FieldMathInstruction, 0, "NBw");
-            CASE_OPCODE(OPCODE::MINUS, "MINUS", FieldMathInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::MINUS2, "MINUS2", FieldMathInstruction, 0, "NBw");
-            CASE_OPCODE(OPCODE::MUL, "MUL", FieldMathInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::MUL2, "MUL2", FieldMathInstruction, 0, "NBw");
-            CASE_OPCODE(OPCODE::DIV, "DIV", FieldMathInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::DIV2, "DIV2", FieldMathInstruction, 0, "NBw");
-            CASE_OPCODE(OPCODE::MOD, "MOD", FieldMathInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::MOD2, "MOD2", FieldMathInstruction, 0, "NBw");
-            CASE_OPCODE(OPCODE::AND, "AND", FieldMathInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::AND2, "AND2", FieldMathInstruction, 0, "NBw");
-            CASE_OPCODE(OPCODE::OR, "OR", FieldMathInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::OR2, "OR2", FieldMathInstruction, 0, "NBw");
-            CASE_OPCODE(OPCODE::XOR, "XOR", FieldMathInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::XOR2, "XOR2", FieldMathInstruction, 0, "NBw");
-            CASE_OPCODE(OPCODE::INC, "INC", FieldMathInstruction, 0, "BB");
-            CASE_OPCODE(OPCODE::INC2, "INC2", FieldMathInstruction, 0, "BB");
-            CASE_OPCODE(OPCODE::DEC, "DEC", FieldMathInstruction, 0, "BB");
-            CASE_OPCODE(OPCODE::DEC2, "DEC2", FieldMathInstruction, 0, "BB");
-            CASE_OPCODE(OPCODE::RANDOM, "RANDOM", FieldMathInstruction, 0, "BB");
-            CASE_OPCODE(OPCODE::LBYTE, "LBYTE", FieldMathInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::HBYTE, "HBYTE", FieldMathInstruction, 0, "NBw");
-            CASE_OPCODE(OPCODE::TWOBYTE, "2BYTE", FieldMathInstruction, 0, "NNBBB");
-            CASE_OPCODE(OPCODE::SIN, "SIN", FieldMathInstruction, 0, "NNwwwB");
-            CASE_OPCODE(OPCODE::COS, "COS", FieldMathInstruction, 0, "NNwwwB");
+            case OPCODES::PLUS_:
+                ParseOpcode(full_opcode, "PLUS!", new FieldMathInstruction(), 0, "NBB");
+                break;
+            case OPCODES::PLUS2_:
+                ParseOpcode(full_opcode, "PLUS2!", new FieldMathInstruction(), 0, "NBw");
+                break;
+            case OPCODES::MINUS_:
+                ParseOpcode(full_opcode, "MINUS!", new FieldMathInstruction(), 0, "NBB");
+                break;
+            case OPCODES::MINUS2_:
+                ParseOpcode(full_opcode, "MINUS2!", new FieldMathInstruction(), 0, "NBw");
+                break;
+            case OPCODES::INC_:
+                ParseOpcode(full_opcode, "INC!", new FieldMathInstruction(), 0, "BB");
+                break;
+            case OPCODES::INC2_:
+                ParseOpcode(full_opcode, "INC2!", new FieldMathInstruction(), 0, "BB");
+                break;
+            case OPCODES::DEC_:
+                ParseOpcode(full_opcode, "DEC!", new FieldMathInstruction(), 0, "BB");
+                break;
+            case OPCODES::DEC2_:
+                ParseOpcode(full_opcode, "DEC2!", new FieldMathInstruction(), 0, "BB");
+                break;
+            case OPCODES::RDMSD:
+                ParseOpcode(full_opcode, "RDMSD", new FieldMathInstruction(), 0, "NB");
+                break;
+            case OPCODES::SETBYTE:
+                ParseOpcode(full_opcode, "SETBYTE", new FieldMathInstruction(), 0, "NBB");
+                break;
+            case OPCODES::SETWORD:
+                ParseOpcode(full_opcode, "SETWORD", new FieldMathInstruction(), 0, "NBw");
+                break;
+            case OPCODES::BITON:
+                ParseOpcode(full_opcode, "BITON", new FieldMathInstruction(), 0, "NBB");
+                break;
+            case OPCODES::BITOFF:
+                ParseOpcode(full_opcode, "BITOFF", new FieldMathInstruction(), 0, "NBB");
+                break;
+            case OPCODES::BITXOR:
+                ParseOpcode(full_opcode, "BITXOR", new FieldMathInstruction(), 0, "NBB");
+                break;
+            case OPCODES::PLUS:
+                ParseOpcode(full_opcode, "PLUS", new FieldMathInstruction(), 0, "NBB");
+                break;
+            case OPCODES::PLUS2:
+                ParseOpcode(full_opcode, "PLUS2", new FieldMathInstruction(), 0, "NBw");
+                break;
+            case OPCODES::MINUS:
+                ParseOpcode(full_opcode, "MINUS", new FieldMathInstruction(), 0, "NBB");
+                break;
+            case OPCODES::MINUS2:
+                ParseOpcode(full_opcode, "MINUS2", new FieldMathInstruction(), 0, "NBw");
+                break;
+            case OPCODES::MUL:
+                ParseOpcode(full_opcode, "MUL", new FieldMathInstruction(), 0, "NBB");
+                break;
+            case OPCODES::MUL2:
+                ParseOpcode(full_opcode, "MUL2", new FieldMathInstruction(), 0, "NBw");
+                break;
+            case OPCODES::DIV:
+                ParseOpcode(full_opcode, "DIV", new FieldMathInstruction(), 0, "NBB");
+                break;
+            case OPCODES::DIV2:
+                ParseOpcode(full_opcode, "DIV2", new FieldMathInstruction(), 0, "NBw");
+                break;
+            case OPCODES::MOD:
+                ParseOpcode(full_opcode, "MOD", new FieldMathInstruction(), 0, "NBB");
+                break;
+            case OPCODES::MOD2:
+                ParseOpcode(full_opcode, "MOD2", new FieldMathInstruction(), 0, "NBw");
+                break;
+            case OPCODES::AND:
+                ParseOpcode(full_opcode, "AND", new FieldMathInstruction(), 0, "NBB");
+                break;
+            case OPCODES::AND2:
+                ParseOpcode(full_opcode, "AND2", new FieldMathInstruction(), 0, "NBw");
+                break;
+            case OPCODES::OR:
+                ParseOpcode(full_opcode, "OR", new FieldMathInstruction(), 0, "NBB");
+                break;
+            case OPCODES::OR2:
+                ParseOpcode(full_opcode, "OR2", new FieldMathInstruction(), 0, "NBw");
+                break;
+            case OPCODES::XOR:
+                ParseOpcode(full_opcode, "XOR", new FieldMathInstruction(), 0, "NBB");
+                break;
+            case OPCODES::XOR2:
+                ParseOpcode(full_opcode, "XOR2", new FieldMathInstruction(), 0, "NBw");
+                break;
+            case OPCODES::INC:
+                ParseOpcode(full_opcode, "INC", new FieldMathInstruction(), 0, "BB");
+                break;
+            case OPCODES::INC2:
+                ParseOpcode(full_opcode, "INC2", new FieldMathInstruction(), 0, "BB");
+                break;
+            case OPCODES::DEC:
+                ParseOpcode(full_opcode, "DEC", new FieldMathInstruction(), 0, "BB");
+                break;
+            case OPCODES::DEC2:
+                ParseOpcode(full_opcode, "DEC2", new FieldMathInstruction(), 0, "BB");
+                break;
+            case OPCODES::RANDOM:
+                ParseOpcode(full_opcode, "RANDOM", new FieldMathInstruction(), 0, "BB");
+                break;
+            case OPCODES::LBYTE:
+                ParseOpcode(full_opcode, "LBYTE", new FieldMathInstruction(), 0, "NBB");
+                break;
+            case OPCODES::HBYTE:
+                ParseOpcode(full_opcode, "HBYTE", new FieldMathInstruction(), 0, "NBw");
+                break;
+            case OPCODES::TWOBYTE:
+                ParseOpcode(full_opcode, "2BYTE", new FieldMathInstruction(), 0, "NNBBB");
+                break;
+            case OPCODES::SIN:
+                ParseOpcode(full_opcode, "SIN", new FieldMathInstruction(), 0, "NNwwwB");
+                break;
+            case OPCODES::COS:
+                ParseOpcode(full_opcode, "COS", new FieldMathInstruction(), 0, "NNwwwB");
+                break;
 
 
             // Window
             // Window
-            CASE_OPCODE(OPCODE::TUTOR, "TUTOR", FieldWindowInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::WCLS, "WCLS", FieldWindowInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::WSIZW, "WSIZW", FieldWindowInstruction, 0, "Bwwww");
-            CASE_OPCODE(OPCODE::WSPCL, "WSPCL", FieldWindowInstruction, 0, "BBBB");
-            CASE_OPCODE(OPCODE::WNUMB, "WNUMB", FieldWindowInstruction, 0, "NBwwB"); // NBdB when N == 0
-            CASE_OPCODE(OPCODE::STTIM, "STTIM", FieldWindowInstruction, 0, "NNBBB");
-            CASE_OPCODE(OPCODE::MESSAGE, "MESSAGE", FieldWindowInstruction, 0, "BB");
-            CASE_OPCODE(OPCODE::MPARA, "MPARA", FieldWindowInstruction, 0, "NBBB");
-            CASE_OPCODE(OPCODE::MPRA2, "MPRA2", FieldWindowInstruction, 0, "NBBw");
-            CASE_OPCODE(OPCODE::MPNAM, "MPNAM", FieldWindowInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::ASK, "ASK", FieldWindowInstruction, 0, "NBBBBB");
-            CASE_OPCODE(OPCODE::MENU, "MENU", FieldWindowInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::MENU2, "MENU2", FieldWindowInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::WINDOW, "WINDOW", FieldWindowInstruction, 0, "Bwwww");
-            CASE_OPCODE(OPCODE::WMOVE, "WMOVE", FieldWindowInstruction, 0, "Bss");
-            CASE_OPCODE(OPCODE::WMODE, "WMODE", FieldWindowInstruction, 0, "BBB");
-            CASE_OPCODE(OPCODE::WREST, "WREST", FieldWindowInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::WCLSE, "WCLSE", FieldWindowInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::WROW, "WROW", FieldWindowInstruction, 0, "BB");
-            CASE_OPCODE(OPCODE::GWCOL, "GWCOL", FieldWindowInstruction, 0, "NNBBBB");
-            CASE_OPCODE(OPCODE::SWCOL, "SWCOL", FieldWindowInstruction, 0, "NNBBBB");
+            case OPCODES::TUTOR:
+                ParseOpcode(full_opcode, "TUTOR", new FieldWindowInstruction(), 0, "B");
+                break;
+            case OPCODES::WCLS:
+                ParseOpcode(full_opcode, "WCLS", new FieldWindowInstruction(), 0, "B");
+                break;
+            case OPCODES::WSIZW:
+                ParseOpcode(full_opcode, "WSIZW", new FieldWindowInstruction(), 0, "Bwwww");
+                break;
+            case OPCODES::WSPCL:
+                ParseOpcode(full_opcode, "WSPCL", new FieldWindowInstruction(), 0, "BBBB");
+                break;
+            case OPCODES::WNUMB:
+                ParseOpcode(full_opcode, "WNUMB", new FieldWindowInstruction(), 0, "NBwwB");
+                break;
+            case OPCODES::STTIM:
+                ParseOpcode(full_opcode, "STTIM", new FieldWindowInstruction(), 0, "NNBBB");
+                break;
+            case OPCODES::MESSAGE:
+                ParseOpcode(full_opcode, "MESSAGE", new FieldWindowInstruction(), 0, "BB");
+                break;
+            case OPCODES::MPARA:
+                ParseOpcode(full_opcode, "MPARA", new FieldWindowInstruction(), 0, "NBBB");
+                break;
+            case OPCODES::MPRA2:
+                ParseOpcode(full_opcode, "MPRA2", new FieldWindowInstruction(), 0, "NBBw");
+                break;
+            case OPCODES::MPNAM:
+                ParseOpcode(full_opcode, "MPNAM", new FieldWindowInstruction(), 0, "B");
+                break;
+            case OPCODES::ASK:
+                ParseOpcode(full_opcode, "ASK", new FieldWindowInstruction(), 0, "NBBBBB");
+                break;
+            case OPCODES::MENU:
+                ParseOpcode(full_opcode, "MENU", new FieldWindowInstruction(), 0, "NBB");
+                break;
+            case OPCODES::MENU2:
+                ParseOpcode(full_opcode, "MENU2", new FieldWindowInstruction(), 0, "B");
+                break;
+            case OPCODES::WINDOW:
+                ParseOpcode(full_opcode, "WINDOW", new FieldWindowInstruction(), 0, "Bwwww");
+                break;
+            case OPCODES::WMOVE:
+                ParseOpcode(full_opcode, "WMOVE", new FieldWindowInstruction(), 0, "Bss");
+                break;
+            case OPCODES::WMODE:
+                ParseOpcode(full_opcode, "WMODE", new FieldWindowInstruction(), 0, "BBB");
+                break;
+            case OPCODES::WREST:
+                ParseOpcode(full_opcode, "WREST", new FieldWindowInstruction(), 0, "B");
+                break;
+            case OPCODES::WCLSE:
+                ParseOpcode(full_opcode, "WCLSE", new FieldWindowInstruction(), 0, "B");
+                break;
+            case OPCODES::WROW:
+                ParseOpcode(full_opcode, "WROW", new FieldWindowInstruction(), 0, "BB");
+                break;
+            case OPCODES::GWCOL:
+                ParseOpcode(full_opcode, "GWCOL", new FieldWindowInstruction(), 0, "NNBBBB");
+                break;
+            case OPCODES::SWCOL:
+                ParseOpcode(full_opcode, "SWCOL", new FieldWindowInstruction(), 0, "NNBBBB");
+                break;
 
 
             // Party
             // Party
-            CASE_OPCODE(OPCODE::SPTYE, "SPTYE", FieldPartyInstruction, 0, "NNBBB");
-            CASE_OPCODE(OPCODE::GTPYE, "GTPYE", FieldPartyInstruction, 0, "NNBBB");
-            CASE_OPCODE(OPCODE::GOLDU, "GOLDU", FieldPartyInstruction, 0, "Nww"); // Nd when N == 0
-            CASE_OPCODE(OPCODE::GOLDD, "GOLDD", FieldPartyInstruction, 0, "Nww"); // Nd when N == 0
-            CASE_OPCODE(OPCODE::CHGLD, "CHGLD", FieldPartyInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::HMPMAX1, "HMPMAX1", FieldPartyInstruction, 0, "");
-            CASE_OPCODE(OPCODE::HMPMAX2, "HMPMAX2", FieldPartyInstruction, 0, "");
-            CASE_OPCODE(OPCODE::MHMMX, "MHMMX", FieldPartyInstruction, 0, "");
-            CASE_OPCODE(OPCODE::HMPMAX3, "HMPMAX3", FieldPartyInstruction, 0, "");
-            CASE_OPCODE(OPCODE::MPU, "MPU", FieldPartyInstruction, 0, "NBw");
-            CASE_OPCODE(OPCODE::MPD, "MPD", FieldPartyInstruction, 0, "NBw");
-            CASE_OPCODE(OPCODE::HPU, "HPU", FieldPartyInstruction, 0, "NBw");
-            CASE_OPCODE(OPCODE::HPD, "HPD", FieldPartyInstruction, 0, "NBw");
-            CASE_OPCODE(OPCODE::STITM, "STITM", FieldPartyInstruction, 0, "NwB");
-            CASE_OPCODE(OPCODE::DLITM, "DLITM", FieldPartyInstruction, 0, "NwB");
-            CASE_OPCODE(OPCODE::CKITM, "CKITM", FieldPartyInstruction, 0, "NwB");
-            CASE_OPCODE(OPCODE::SMTRA, "SMTRA", FieldPartyInstruction, 0, "NNBBBB");
-            CASE_OPCODE(OPCODE::DMTRA, "DMTRA", FieldPartyInstruction, 0, "NNBBBBB");
-            CASE_OPCODE(OPCODE::CMTRA, "CMTRA", FieldPartyInstruction, 0, "NNNBBBBBB");
-            CASE_OPCODE(OPCODE::GETPC, "GETPC", FieldPartyInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::PRTYP, "PRTYP", FieldPartyInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::PRTYM, "PRTYM", FieldPartyInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::PRTYE, "PRTYE", FieldPartyInstruction, 0, "BBB");
-            CASE_OPCODE(OPCODE::MMBUD, "MMBUD", FieldPartyInstruction, 0, "BB");
-            CASE_OPCODE(OPCODE::MMBLK, "MMBLK", FieldPartyInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::MMBUK, "MMBUK", FieldPartyInstruction, 0, "B");
+            case OPCODES::SPTYE:
+                ParseOpcode(full_opcode, "SPTYE", new FieldPartyInstruction(), 0, "NNBBB");
+                break;
+            case OPCODES::GTPYE:
+                ParseOpcode(full_opcode, "GTPYE", new FieldPartyInstruction(), 0, "NNBBB");
+                break;
+            case OPCODES::GOLDU:
+                ParseOpcode(full_opcode, "GOLDU", new FieldPartyInstruction(), 0, "Nww");
+                break;
+            case OPCODES::GOLDD:
+                ParseOpcode(full_opcode, "GOLDD", new FieldPartyInstruction(), 0, "Nww");
+                break;
+            case OPCODES::CHGLD:
+                ParseOpcode(full_opcode, "CHGLD", new FieldPartyInstruction(), 0, "NBB");
+                break;
+            case OPCODES::HMPMAX1:
+                ParseOpcode(full_opcode, "HMPMAX1", new FieldPartyInstruction(), 0, "");
+                break;
+            case OPCODES::HMPMAX2:
+                ParseOpcode(full_opcode, "HMPMAX2", new FieldPartyInstruction(), 0, "");
+                break;
+            case OPCODES::MHMMX:
+                ParseOpcode(full_opcode, "MHMMX", new FieldPartyInstruction(), 0, "");
+                break;
+            case OPCODES::HMPMAX3:
+                ParseOpcode(full_opcode, "HMPMAX3", new FieldPartyInstruction(), 0, "");
+                break;
+            case OPCODES::MPU:
+                ParseOpcode(full_opcode, "MPU", new FieldPartyInstruction(), 0, "NBw");
+                break;
+            case OPCODES::MPD:
+                ParseOpcode(full_opcode, "MPD", new FieldPartyInstruction(), 0, "NBw");
+                break;
+            case OPCODES::HPU:
+                ParseOpcode(full_opcode, "HPU", new FieldPartyInstruction(), 0, "NBw");
+                break;
+            case OPCODES::HPD:
+                ParseOpcode(full_opcode, "HPD", new FieldPartyInstruction(), 0, "NBw");
+                break;
+            case OPCODES::STITM:
+                ParseOpcode(full_opcode, "STITM", new FieldPartyInstruction(), 0, "NwB");
+                break;
+            case OPCODES::DLITM:
+                ParseOpcode(full_opcode, "DLITM", new FieldPartyInstruction(), 0, "NwB");
+                break;
+            case OPCODES::CKITM:
+                ParseOpcode(full_opcode, "CKITM", new FieldPartyInstruction(), 0, "NwB");
+                break;
+            case OPCODES::SMTRA:
+                ParseOpcode(full_opcode, "SMTRA", new FieldPartyInstruction(), 0, "NNBBBB");
+                break;
+            case OPCODES::DMTRA:
+                ParseOpcode(full_opcode, "DMTRA", new FieldPartyInstruction(), 0, "NNBBBBB");
+                break;
+            case OPCODES::CMTRA:
+                ParseOpcode(full_opcode, "CMTRA", new FieldPartyInstruction(), 0, "NNNBBBBBB");
+                break;
+            case OPCODES::GETPC:
+                ParseOpcode(full_opcode, "GETPC", new FieldPartyInstruction(), 0, "NBB");
+                break;
+            case OPCODES::PRTYP:
+                ParseOpcode(full_opcode, "PRTYP", new FieldPartyInstruction(), 0, "B");
+                break;
+            case OPCODES::PRTYM:
+                ParseOpcode(full_opcode, "PRTYM", new FieldPartyInstruction(), 0, "B");
+                break;
+            case OPCODES::PRTYE:
+                ParseOpcode(full_opcode, "PRTYE", new FieldPartyInstruction(), 0, "BBB");
+                break;
+            case OPCODES::MMBUD:
+                ParseOpcode(full_opcode, "MMBUD", new FieldPartyInstruction(), 0, "BB");
+                break;
+            case OPCODES::MMBLK:
+                ParseOpcode(full_opcode, "MMBLK", new FieldPartyInstruction(), 0, "B");
+                break;
+            case OPCODES::MMBUK:
+                ParseOpcode(full_opcode, "MMBUK", new FieldPartyInstruction(), 0, "B");
+                break;
 
 
             // Model
             // Model
-            CASE_OPCODE(OPCODE::JOIN, "JOIN", FieldModelInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::SPLIT, "SPLIT", FieldModelInstruction, 0, "NNNssBssBB");
-            CASE_OPCODE(OPCODE::BLINK, "BLINK", FieldModelInstruction, 0, "B");
-            OPCODE_BASE(OPCODE::KAWAI){
-                int length = this->stream_->ReadU8();
-                assert(length >= 3);
-                std::ostringstream paramStream;
-                for (int i = 3; i < length; ++ i) paramStream << "B";
-                auto parameters = paramStream.str();
-
-                opcode = this->stream_->ReadU8();
-                switch (opcode){
-                    CASE_OPCODE(
-                        OPCODE_KAWAI::EYETX, "EYETX", FieldModelInstruction, 0, parameters.c_str()
-                    ); // was BBBB
-                    CASE_OPCODE(
-                        OPCODE_KAWAI::TRNSP, "TRNSP", FieldModelInstruction, 0, parameters.c_str()
-                    ); // was B
-                    CASE_OPCODE(
-                        OPCODE_KAWAI::AMBNT, "AMBNT", FieldModelInstruction, 0, parameters.c_str()
-                    ); // was BBBBBBB
-                    CASE_OPCODE(
-                        OPCODE_KAWAI::Unknown03, "Unknown03",
-                        FieldModelInstruction, 0, parameters.c_str()
-                    );
-                    CASE_OPCODE(
-                        OPCODE_KAWAI::Unknown04, "Unknown04",
-                        FieldModelInstruction, 0, parameters.c_str()
-                    );
-                    CASE_OPCODE(
-                        OPCODE_KAWAI::Unknown05, "Unknown05",
-                        FieldModelInstruction, 0, parameters.c_str()
-                    );
-                    CASE_OPCODE(
-                        OPCODE_KAWAI::LIGHT, "LIGHT",FieldModelInstruction, 0, parameters.c_str()
-                    );
-                    CASE_OPCODE(
-                        OPCODE_KAWAI::Unknown07, "Unknown07",
-                        FieldModelInstruction, 0, parameters.c_str()
-                    );
-                    CASE_OPCODE(
-                        OPCODE_KAWAI::Unknown08, "Unknown08",
-                        FieldModelInstruction, 0, parameters.c_str()
-                    );
-                    CASE_OPCODE(
-                        OPCODE_KAWAI::Unknown09, "Unknown09",
-                        FieldModelInstruction, 0, parameters.c_str()
-                    );
-                    CASE_OPCODE(
-                        OPCODE_KAWAI::SBOBJ, "SBOBJ",
-                        FieldModelInstruction, 0, parameters.c_str()
-                    );
-                    CASE_OPCODE(
-                      OPCODE_KAWAI::Unknown0B, "Unknown0B",
-                      FieldModelInstruction, 0, parameters.c_str()
-                    );
-                    CASE_OPCODE(
-                        OPCODE_KAWAI::Unknown0C, "Unknown0C",
-                        FieldModelInstruction, 0, parameters.c_str()
-                    );
-                    CASE_OPCODE(
-                        OPCODE_KAWAI::SHINE, "SHINE", FieldModelInstruction, 0, parameters.c_str()
-                    );
-                    CASE_OPCODE(
-                        OPCODE_KAWAI::RESET, "RESET", FieldModelInstruction, 0, parameters.c_str()
-                    );
-                default:
-                    throw UnknownSubOpcodeException(this->address_, opcode);
+            case OPCODES::JOIN:
+                ParseOpcode(full_opcode, "JOIN", new FieldModelInstruction(), 0, "B");
+                break;
+            case OPCODES::SPLIT:
+                ParseOpcode(full_opcode, "SPLIT", new FieldModelInstruction(), 0, "NNNssBssBB");
+                break;
+            case OPCODES::BLINK:
+                ParseOpcode(full_opcode, "BLINK", new FieldModelInstruction(), 0, "B");
+                break;
+            case OPCODES::KAWAI:
+                {
+                    full_opcode = 0;
+                    full_opcode = (full_opcode << 8) + OPCODES::KAWAI;
+                    int length = this->stream_->ReadU8();
+                    assert(length >= 3);
+                    std::ostringstream param_stream;
+                    for (int i = 3; i < length; ++ i) param_stream << "B";
+                    auto parameters = param_stream.str();
+                    opcode = this->stream_->ReadU8();
+                    switch (opcode){
+                        case OPCODES_KAWAI::EYETX:
+                            // Parameters were "BBBB"
+                            ParseOpcode(
+                              opcode, "EYETX", new FieldModelInstruction(), 0, parameters.c_str()
+                            );
+                            break;
+                        case OPCODES_KAWAI::TRNSP:
+                            // Parameters were "B"
+                            ParseOpcode(
+                              opcode, "TRNSP", new FieldModelInstruction(), 0, parameters.c_str()
+                            );
+                            break;
+                        case OPCODES_KAWAI::AMBNT:
+                            // Parameters were "AMBNT"
+                            ParseOpcode(
+                              opcode, "AMBNT",
+                              new FieldModelInstruction(), 0, parameters.c_str()
+                            );
+                            break;
+                        case OPCODES_KAWAI::Unknown03:
+                            ParseOpcode(
+                              opcode, "Unknown03",
+                              new FieldModelInstruction(), 0, parameters.c_str()
+                            );
+                            break;
+                        case OPCODES_KAWAI::Unknown04:
+                            ParseOpcode(
+                              opcode, "Unknown04",
+                              new FieldModelInstruction(), 0, parameters.c_str()
+                            );
+                            break;
+                        case OPCODES_KAWAI::Unknown05:
+                            ParseOpcode(
+                              opcode, "Unknown03",
+                              new FieldModelInstruction(), 0, parameters.c_str()
+                            );
+                            break;
+                        case OPCODES_KAWAI::LIGHT:
+                            ParseOpcode(
+                              opcode, "LIGHT",
+                              new FieldModelInstruction(), 0, parameters.c_str()
+                            );
+                            break;
+                        case OPCODES_KAWAI::Unknown07:
+                            ParseOpcode(
+                              opcode, "Unknown07",
+                              new FieldModelInstruction(), 0, parameters.c_str()
+                            );
+                            break;
+                        case OPCODES_KAWAI::Unknown08:
+                            ParseOpcode(
+                              opcode, "Unknown08",
+                              new FieldModelInstruction(), 0, parameters.c_str()
+                            );
+                            break;
+                        case OPCODES_KAWAI::Unknown09:
+                            ParseOpcode(
+                              opcode, "Unknown09",
+                              new FieldModelInstruction(), 0, parameters.c_str()
+                            );
+                            break;
+                        case OPCODES_KAWAI::SBOBJ:
+                            ParseOpcode(
+                              opcode, "SBOBJ", new FieldModelInstruction(), 0, parameters.c_str()
+                            );
+                            break;
+                        case OPCODES_KAWAI::Unknown0B:
+                            ParseOpcode(
+                              opcode, "Unknown0B",
+                              new FieldModelInstruction(), 0, parameters.c_str()
+                            );
+                            break;
+                        case OPCODES_KAWAI::Unknown0C:
+                            ParseOpcode(
+                              opcode, "Unknown0C", new FieldModelInstruction(), 0, parameters.c_str()
+                            );
+                            break;
+                        case OPCODES_KAWAI::SHINE:
+                            ParseOpcode(
+                              opcode, "SHINE", new FieldModelInstruction(), 0, parameters.c_str()
+                            );
+                            break;
+                        case OPCODES_KAWAI::RESET:
+                            ParseOpcode(
+                              opcode, "RESET", new FieldModelInstruction(), 0, parameters.c_str()
+                            );
+                            break;
+                        default:
+                            throw UnknownSubOpcodeException(this->address_, opcode);
+                    }
+                    this->address_ ++;
+                    this->address_ ++;
+                    break;
                 }
                 }
-                INC_ADDR;
-                INC_ADDR;
-            }
-            OPCODE_END
-            CASE_OPCODE(OPCODE::KAWIW, "KAWIW", FieldModelInstruction, 0, "");
-            CASE_OPCODE(OPCODE::PMOVA, "PMOVA", FieldModelInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::PDIRA, "PDIRA", FieldModelInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::PTURA, "PTURA", FieldModelInstruction, 0, "BBB");
-            CASE_OPCODE(OPCODE::PGTDR, "PGTDR", FieldModelInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::PXYZI, "PXYZI", FieldModelInstruction, 0, "NNBBBBB");
-            CASE_OPCODE(OPCODE::TLKON, "TLKON", FieldModelInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::PC, "PC", FieldModelInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::opCodeCHAR, "CHAR", FieldModelInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::DFANM, "DFANM", FieldModelInstruction, 0, "BB");
-            CASE_OPCODE(OPCODE::ANIME1, "ANIME1", FieldModelInstruction, 0, "BB");
-            CASE_OPCODE(OPCODE::VISI, "VISI", FieldModelInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::XYZI, "XYZI", FieldModelInstruction, 0, "NNsssw");
-            CASE_OPCODE(OPCODE::XYI, "XYI", FieldModelInstruction, 0, "NNssw");
-            CASE_OPCODE(OPCODE::XYZ, "XYZ", FieldModelInstruction, 0, "NNsss");
-            CASE_OPCODE(OPCODE::MOVE, "MOVE", FieldModelInstruction, 0, "Nss");
-            CASE_OPCODE(OPCODE::CMOVE, "CMOVE", FieldModelInstruction, 0, "Nss");
-            CASE_OPCODE(OPCODE::MOVA, "MOVA", FieldModelInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::TURA, "TURA", FieldModelInstruction, 0, "BBB");
-            CASE_OPCODE(OPCODE::ANIMW, "ANIMW", FieldModelInstruction, 0, "");
-            CASE_OPCODE(OPCODE::FMOVE, "FMOVE", FieldModelInstruction, 0, "Nss");
-            CASE_OPCODE(OPCODE::ANIME2, "ANIME2", FieldModelInstruction, 0, "BB");
-            CASE_OPCODE(OPCODE::ANIM_1, "ANIM!1", FieldModelInstruction, 0, "BB");
-            CASE_OPCODE(OPCODE::CANIM1, "CANIM1", FieldModelInstruction, 0, "BBBB");
-            CASE_OPCODE(OPCODE::CANM_1, "CANM!1", FieldModelInstruction, 0, "BBBB");
-            CASE_OPCODE(OPCODE::MSPED, "MSPED", FieldModelInstruction, 0, "Nw");
-            CASE_OPCODE(OPCODE::DIR, "DIR", FieldModelInstruction, 0, "BB");
-            CASE_OPCODE(OPCODE::TURNGEN, "TURNGEN", FieldModelInstruction, 0, "NBBBB");
-            CASE_OPCODE(OPCODE::TURN, "TURN", FieldModelInstruction, 0, "NBBBB");
-            CASE_OPCODE(OPCODE::DIRA, "DIRA", FieldModelInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::GETDIR, "GETDIR", FieldModelInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::GETAXY, "GETAXY", FieldModelInstruction, 0, "NBBB");
-            CASE_OPCODE(OPCODE::GETAI, "GETAI", FieldModelInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::ANIM_2, "ANIM!2", FieldModelInstruction, 0, "BB");
-            CASE_OPCODE(OPCODE::CANIM2, "CANIM2", FieldModelInstruction, 0, "BBBB");
-            CASE_OPCODE(OPCODE::CANM_2, "CANM!2", FieldModelInstruction, 0, "BBBB");
-            CASE_OPCODE(OPCODE::ASPED, "ASPED", FieldModelInstruction, 0, "Nw");
-            CASE_OPCODE(OPCODE::CC, "CC", FieldModelInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::JUMP, "JUMP", FieldModelInstruction, 0, "NNssww");
-            CASE_OPCODE(OPCODE::AXYZI, "AXYZI", FieldModelInstruction, 0, "NNBBBBB");
-            CASE_OPCODE(OPCODE::LADER, "LADER", FieldModelInstruction, 0, "NNssswBBBB");
-            CASE_OPCODE(OPCODE::OFST, "OFST", FieldModelInstruction, 0, "NNBsssw");
-            CASE_OPCODE(OPCODE::OFSTW, "OFSTW", FieldModelInstruction, 0, "");
-            CASE_OPCODE(OPCODE::TALKR, "TALKR", FieldModelInstruction, 0, "NB");
-            CASE_OPCODE(OPCODE::SLIDR, "SLIDR", FieldModelInstruction, 0, "NB");
-            CASE_OPCODE(OPCODE::SOLID, "SOLID", FieldModelInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::TLKR2, "TLKR2", FieldModelInstruction, 0, "Nw");
-            CASE_OPCODE(OPCODE::SLDR2, "SLDR2", FieldModelInstruction, 0, "Nw");
-            CASE_OPCODE(OPCODE::CCANM, "CCANM", FieldModelInstruction, 0, "BBB");
-            CASE_OPCODE(OPCODE::FCFIX, "FCFIX", FieldModelInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::ANIMB, "ANIMB", FieldModelInstruction, 0, "");
-            CASE_OPCODE(OPCODE::TURNW, "TURNW", FieldModelInstruction, 0, "");
+            case OPCODES::KAWIW:
+                ParseOpcode(full_opcode, "KAWIW", new FieldModelInstruction(), 0, "");
+                break;
+            case OPCODES::PMOVA:
+                ParseOpcode(full_opcode, "PMOVA", new FieldModelInstruction(), 0, "B");
+                break;
+            case OPCODES::PDIRA:
+                ParseOpcode(full_opcode, "PDIRA", new FieldModelInstruction(), 0, "B");
+                break;
+            case OPCODES::PTURA:
+                ParseOpcode(full_opcode, "PTURA", new FieldModelInstruction(), 0, "BBB");
+                break;
+            case OPCODES::PGTDR:
+                ParseOpcode(full_opcode, "PGTDR", new FieldModelInstruction(), 0, "NBB");
+                break;
+            case OPCODES::PXYZI:
+                ParseOpcode(full_opcode, "PXYZI", new FieldModelInstruction(), 0, "NNBBBBB");
+                break;
+            case OPCODES::TLKON:
+                ParseOpcode(full_opcode, "TLKON", new FieldModelInstruction(), 0, "B");
+                break;
+            case OPCODES::PC:
+                ParseOpcode(full_opcode, "PC", new FieldModelInstruction(), 0, "B");
+                break;
+            case OPCODES::opCodeCHAR:
+                ParseOpcode(full_opcode, "CHAR", new FieldModelInstruction(), 0, "B");
+                break;
+            case OPCODES::DFANM:
+                ParseOpcode(full_opcode, "DFANM", new FieldModelInstruction(), 0, "BB");
+                break;
+            case OPCODES::ANIME1:
+                ParseOpcode(full_opcode, "ANIME1", new FieldModelInstruction(), 0, "BB");
+                break;
+            case OPCODES::VISI:
+                ParseOpcode(full_opcode, "VISI", new FieldModelInstruction(), 0, "B");
+                break;
+            case OPCODES::XYZI:
+                ParseOpcode(full_opcode, "XYZI", new FieldModelInstruction(), 0, "NNsssw");
+                break;
+            case OPCODES::XYI:
+                ParseOpcode(full_opcode, "XYI", new FieldModelInstruction(), 0, "NNssw");
+                break;
+            case OPCODES::XYZ:
+                ParseOpcode(full_opcode, "XYZ", new FieldModelInstruction(), 0, "NNsss");
+                break;
+            case OPCODES::MOVE:
+                ParseOpcode(full_opcode, "MOVE", new FieldModelInstruction(), 0, "Nss");
+                break;
+            case OPCODES::CMOVE:
+                ParseOpcode(full_opcode, "CMOVE", new FieldModelInstruction(), 0, "Nss");
+                break;
+            case OPCODES::MOVA:
+                ParseOpcode(full_opcode, "MOVA", new FieldModelInstruction(), 0, "B");
+                break;
+            case OPCODES::TURA:
+                ParseOpcode(full_opcode, "TURA", new FieldModelInstruction(), 0, "BBB");
+                break;
+            case OPCODES::ANIMW:
+                ParseOpcode(full_opcode, "ANIMW", new FieldModelInstruction(), 0, "");
+                break;
+            case OPCODES::FMOVE:
+                ParseOpcode(full_opcode, "FMOVE", new FieldModelInstruction(), 0, "Nss");
+                break;
+            case OPCODES::ANIME2:
+                ParseOpcode(full_opcode, "ANIME2", new FieldModelInstruction(), 0, "BB");
+                break;
+            case OPCODES::ANIM_1:
+                ParseOpcode(full_opcode, "ANIM!1", new FieldModelInstruction(), 0, "BB");
+                break;
+            case OPCODES::CANIM1:
+                ParseOpcode(full_opcode, "CANIM1", new FieldModelInstruction(), 0, "BBBB");
+                break;
+            case OPCODES::CANM_1:
+                ParseOpcode(full_opcode, "CANM!1", new FieldModelInstruction(), 0, "BBBB");
+                break;
+            case OPCODES::MSPED:
+                ParseOpcode(full_opcode, "MSPED", new FieldModelInstruction(), 0, "Nw");
+                break;
+            case OPCODES::DIR:
+                ParseOpcode(full_opcode, "DIR", new FieldModelInstruction(), 0, "BB");
+                break;
+            case OPCODES::TURNGEN:
+                ParseOpcode(full_opcode, "TURNGEN", new FieldModelInstruction(), 0, "NBBBB");
+                break;
+            case OPCODES::TURN:
+                ParseOpcode(full_opcode, "TURN", new FieldModelInstruction(), 0, "NBBBB");
+                break;
+            case OPCODES::DIRA:
+                ParseOpcode(full_opcode, "DIRA", new FieldModelInstruction(), 0, "B");
+                break;
+            case OPCODES::GETDIR:
+                ParseOpcode(full_opcode, "GETDIR", new FieldModelInstruction(), 0, "NBB");
+                break;
+            case OPCODES::GETAXY:
+                ParseOpcode(full_opcode, "GETAXY", new FieldModelInstruction(), 0, "NBBB");
+                break;
+            case OPCODES::GETAI:
+                ParseOpcode(full_opcode, "GETAI", new FieldModelInstruction(), 0, "NBB");
+                break;
+            case OPCODES::ANIM_2:
+                ParseOpcode(full_opcode, "ANIM!2", new FieldModelInstruction(), 0, "BB");
+                break;
+            case OPCODES::CANIM2:
+                ParseOpcode(full_opcode, "CANIM2", new FieldModelInstruction(), 0, "BBBB");
+                break;
+            case OPCODES::CANM_2:
+                ParseOpcode(full_opcode, "CANM!2", new FieldModelInstruction(), 0, "BBBB");
+                break;
+            case OPCODES::ASPED:
+                ParseOpcode(full_opcode, "ASPED", new FieldModelInstruction(), 0, "Nw");
+                break;
+            case OPCODES::CC:
+                ParseOpcode(full_opcode, "CC", new FieldModelInstruction(), 0, "B");
+                break;
+            case OPCODES::JUMP:
+                ParseOpcode(full_opcode, "JUMP", new FieldModelInstruction(), 0, "NNssww");
+                break;
+            case OPCODES::AXYZI:
+                ParseOpcode(full_opcode, "AXYZI", new FieldModelInstruction(), 0, "NNBBBBB");
+                break;
+            case OPCODES::LADER:
+                ParseOpcode(full_opcode, "LADER", new FieldModelInstruction(), 0, "NNssswBBBB");
+                break;
+            case OPCODES::OFST:
+                ParseOpcode(full_opcode, "OFST", new FieldModelInstruction(), 0, "NNBsssw");
+                break;
+            case OPCODES::OFSTW:
+                ParseOpcode(full_opcode, "OFSTW", new FieldModelInstruction(), 0, "");
+                break;
+            case OPCODES::TALKR:
+                ParseOpcode(full_opcode, "TALKR", new FieldModelInstruction(), 0, "NB");
+                break;
+            case OPCODES::SLIDR:
+                ParseOpcode(full_opcode, "SLIDR", new FieldModelInstruction(), 0, "NB");
+                break;
+            case OPCODES::SOLID:
+                ParseOpcode(full_opcode, "SOLID", new FieldModelInstruction(), 0, "B");
+                break;
+            case OPCODES::TLKR2:
+                ParseOpcode(full_opcode, "TLKR2", new FieldModelInstruction(), 0, "Nw");
+                break;
+            case OPCODES::SLDR2:
+                ParseOpcode(full_opcode, "SLDR2", new FieldModelInstruction(), 0, "Nw");
+                break;
+            case OPCODES::CCANM:
+                ParseOpcode(full_opcode, "CCANM", new FieldModelInstruction(), 0, "BBB");
+                break;
+            case OPCODES::FCFIX:
+                ParseOpcode(full_opcode, "FCFIX", new FieldModelInstruction(), 0, "B");
+                break;
+            case OPCODES::ANIMB:
+                ParseOpcode(full_opcode, "ANIMB", new FieldModelInstruction(), 0, "");
+                break;
+            case OPCODES::TURNW:
+                ParseOpcode(full_opcode, "TURNW", new FieldModelInstruction(), 0, "");
+                break;
 
 
             // Walkmesh
             // Walkmesh
-            CASE_OPCODE(OPCODE::SLIP, "SLIP", FieldWalkmeshInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::UC, "UC", FieldWalkmeshInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::IDLCK, "IDLCK", FieldWalkmeshInstruction, 0, "wB");
-            CASE_OPCODE(OPCODE::LINON, "LINON", FieldWalkmeshInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::SLINE, "SLINE", FieldWalkmeshInstruction, 0, "NNNssssss");
-            //CASE_OPCODE(OPCODE::LINE, "LINE", FieldWalkmeshInstruction, 0, "ssssss");
-            // LINE is done like this to save opcode params to the function out params.
-            case OPCODE::LINE:
+            case OPCODES::SLIP:
+                ParseOpcode(full_opcode, "SLIP", new FieldWalkmeshInstruction(), 0, "B");
+                break;
+            case OPCODES::UC:
+                ParseOpcode(full_opcode, "UC", new FieldWalkmeshInstruction(), 0, "B");
+                break;
+            case OPCODES::IDLCK:
+                ParseOpcode(full_opcode, "IDLCK", new FieldWalkmeshInstruction(), 0, "wB");
+                break;
+            case OPCODES::LINON:
+                ParseOpcode(full_opcode, "LINON", new FieldWalkmeshInstruction(), 0, "B");
+                break;
+            case OPCODES::SLINE:
+                ParseOpcode(full_opcode, "SLINE", new FieldWalkmeshInstruction(), 0, "NNNssssss");
+                break;
+            case OPCODES::LINE:
+                // Mark function entity owner as line.
                 is_line = true;
                 is_line = true;
-                full_opcode = (full_opcode << 8) + OPCODE::LINE;
-                this->_insts.push_back(new FieldWalkmeshInstruction());
-                (this->_insts.back())->_opcode = full_opcode;
-                (this->_insts.back())->_address = this->address_;
-                (this->_insts.back())->_stackChange = 0;
-                (this->_insts.back())->_name = opcodePrefix + std::string("LINE");
-                (this->_insts.back())->_codeGenData = "";
-                this->readParams((this->_insts.back()), "ssssss");
-                point_a[0] = this->_insts.back()->_params[0]->getSigned();
-                point_a[1] = this->_insts.back()->_params[1]->getSigned();
-                point_a[2] = this->_insts.back()->_params[2]->getSigned();
-                point_b[0] = this->_insts.back()->_params[3]->getSigned();
-                point_b[1] = this->_insts.back()->_params[4]->getSigned();
-                point_b[2] = this->_insts.back()->_params[5]->getSigned();
+                ParseOpcode(full_opcode, "LINE", new FieldWalkmeshInstruction(), 0, "ssssss");
+                point_a[0] = this->insts_.back()->_params[0]->getSigned();
+                point_a[1] = this->insts_.back()->_params[1]->getSigned();
+                point_a[2] = this->insts_.back()->_params[2]->getSigned();
+                point_b[0] = this->insts_.back()->_params[3]->getSigned();
+                point_b[1] = this->insts_.back()->_params[4]->getSigned();
+                point_b[2] = this->insts_.back()->_params[5]->getSigned();
                 break;
                 break;
 
 
             // Backgnd
             // Backgnd
-            CASE_OPCODE(OPCODE::BGPDH, "BGPDH", FieldBackgroundInstruction, 0, "NBs");
-            CASE_OPCODE(OPCODE::BGSCR, "BGSCR", FieldBackgroundInstruction, 0, "NBss");
-            CASE_OPCODE(OPCODE::MPPAL, "MPPAL", FieldBackgroundInstruction, 0, "NNNBBBBBBB");
-            CASE_OPCODE(OPCODE::BGON, "BGON", FieldBackgroundInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::BGOFF, "BGOFF", FieldBackgroundInstruction, 0, "NBB");
-            CASE_OPCODE(OPCODE::BGROL, "BGROL", FieldBackgroundInstruction, 0, "NB");
-            CASE_OPCODE(OPCODE::BGROL2, "BGROL2", FieldBackgroundInstruction, 0, "NB");
-            CASE_OPCODE(OPCODE::BGCLR, "BGCLR", FieldBackgroundInstruction, 0, "NB");
-            CASE_OPCODE(OPCODE::STPAL, "STPAL", FieldBackgroundInstruction, 0, "NBBB");
-            CASE_OPCODE(OPCODE::LDPAL, "LDPAL", FieldBackgroundInstruction, 0, "NBBB");
-            CASE_OPCODE(OPCODE::CPPAL, "CPPAL", FieldBackgroundInstruction, 0, "NBBB");
-            CASE_OPCODE(OPCODE::RTPAL, "RTPAL", FieldBackgroundInstruction, 0, "NNBBBB");
-            CASE_OPCODE(OPCODE::ADPAL, "ADPAL", FieldBackgroundInstruction, 0, "NNNBBBBBB");
-            CASE_OPCODE(OPCODE::MPPAL2, "MPPAL2", FieldBackgroundInstruction, 0, "NNNBBBBBB");
-            CASE_OPCODE(OPCODE::STPLS, "STPLS", FieldBackgroundInstruction, 0, "BBBB");
-            CASE_OPCODE(OPCODE::LDPLS, "LDPLS", FieldBackgroundInstruction, 0, "BBBB");
-            CASE_OPCODE(OPCODE::CPPAL2, "CPPAL2", FieldBackgroundInstruction, 0, "BBBBBBB");
-            CASE_OPCODE(OPCODE::RTPAL2, "RTPAL2", FieldBackgroundInstruction, 0, "BBBBBBB");
-            CASE_OPCODE(OPCODE::ADPAL2, "ADPAL2", FieldBackgroundInstruction, 0, "BBBBBBBBBB");
+            case OPCODES::BGPDH:
+                ParseOpcode(full_opcode, "BGPDH", new FieldBackgroundInstruction(), 0, "NBs");
+                break;
+            case OPCODES::BGSCR:
+                ParseOpcode(full_opcode, "BGSCR", new FieldBackgroundInstruction(), 0, "NBss");
+                break;
+            case OPCODES::MPPAL:
+                ParseOpcode(full_opcode, "MPPAL", new FieldBackgroundInstruction(), 0, "NNNBBBBBBB");
+                break;
+            case OPCODES::BGON:
+                ParseOpcode(full_opcode, "BGON", new FieldBackgroundInstruction(), 0, "NBB");
+                break;
+            case OPCODES::BGOFF:
+                ParseOpcode(full_opcode, "BGOFF", new FieldBackgroundInstruction(), 0, "NBB");
+                break;
+            case OPCODES::BGROL:
+                ParseOpcode(full_opcode, "BGROL", new FieldBackgroundInstruction(), 0, "NB");
+                break;
+            case OPCODES::BGROL2:
+                ParseOpcode(full_opcode, "BGROL2", new FieldBackgroundInstruction(), 0, "NB");
+                break;
+            case OPCODES::BGCLR:
+                ParseOpcode(full_opcode, "BGCLR", new FieldBackgroundInstruction(), 0, "NB");
+                break;
+            case OPCODES::STPAL:
+                ParseOpcode(full_opcode, "STPAL", new FieldBackgroundInstruction(), 0, "NBBB");
+                break;
+            case OPCODES::LDPAL:
+                ParseOpcode(full_opcode, "LDPAL", new FieldBackgroundInstruction(), 0, "NBBB");
+                break;
+            case OPCODES::CPPAL:
+                ParseOpcode(full_opcode, "CPPAL", new FieldBackgroundInstruction(), 0, "NBBB");
+                break;
+            case OPCODES::RTPAL:
+                ParseOpcode(full_opcode, "RTPAL", new FieldBackgroundInstruction(), 0, "NNBBBB");
+                break;
+            case OPCODES::ADPAL:
+                ParseOpcode(full_opcode, "ADPAL", new FieldBackgroundInstruction(), 0, "NNNBBBBBB");
+                break;
+            case OPCODES::MPPAL2:
+                ParseOpcode(
+                  full_opcode, "MPPAL2", new FieldBackgroundInstruction(), 0, "NNNBBBBBB"
+                );
+                break;
+            case OPCODES::STPLS:
+                ParseOpcode(full_opcode, "STPLS", new FieldBackgroundInstruction(), 0, "BBBB");
+                break;
+            case OPCODES::LDPLS:
+                ParseOpcode(full_opcode, "LDPLS", new FieldBackgroundInstruction(), 0, "BBBB");
+                break;
+            case OPCODES::CPPAL2:
+                ParseOpcode(full_opcode, "CPPAL2", new FieldBackgroundInstruction(), 0, "BBBBBBB");
+                break;
+            case OPCODES::RTPAL2:
+                ParseOpcode(full_opcode, "RTPAL2", new FieldBackgroundInstruction(), 0, "BBBBBBB");
+                break;
+            case OPCODES::ADPAL2:
+                ParseOpcode(full_opcode, "ADPAL2", new FieldBackgroundInstruction(), 0, "BBBBBBBBBB");
+                break;
 
 
             // Camera
             // Camera
-            CASE_OPCODE(OPCODE::NFADE, "NFADE", FieldCameraInstruction, 0, "NNBBBBBB");
-            CASE_OPCODE(OPCODE::SHAKE, "SHAKE", FieldCameraInstruction, 0, "BBBBBBB");
-            CASE_OPCODE(OPCODE::SCRLO, "SCRLO", FieldCameraInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::SCRLC, "SCRLC", FieldCameraInstruction, 0, "BBBB");
-            CASE_OPCODE(OPCODE::SCRLA, "SCRLA", FieldCameraInstruction, 0, "NwBB");
-            CASE_OPCODE(OPCODE::SCR2D, "SCR2D", FieldCameraInstruction, 0, "Nss");
-            CASE_OPCODE(OPCODE::SCRCC, "SCRCC", FieldCameraInstruction, 0, "");
-            CASE_OPCODE(OPCODE::SCR2DC, "SCR2DC", FieldCameraInstruction, 0, "NNssw");
-            CASE_OPCODE(OPCODE::SCRLW, "SCRLW", FieldCameraInstruction, 0, "");
-            CASE_OPCODE(OPCODE::SCR2DL, "SCR2DL", FieldCameraInstruction, 0, "NNssw");
-            CASE_OPCODE(OPCODE::VWOFT, "VWOFT", FieldCameraInstruction, 0, "NssB");
-            CASE_OPCODE(OPCODE::FADE, "FADE", FieldCameraInstruction, 0, "NNBBBBBB");
-            CASE_OPCODE(OPCODE::FADEW, "FADEW", FieldCameraInstruction, 0, "");
-            CASE_OPCODE(OPCODE::SCRLP, "SCRLP", FieldCameraInstruction, 0, "NwBB");
-            CASE_OPCODE(OPCODE::MVCAM, "MVCAM", FieldCameraInstruction, 0, "B");
+            case OPCODES::NFADE:
+                ParseOpcode(full_opcode, "NFADE", new FieldCameraInstruction(), 0, "NNBBBBBB");
+                break;
+            case OPCODES::SHAKE:
+                ParseOpcode(full_opcode, "SHAKE", new FieldCameraInstruction(), 0, "BBBBBBB");
+                break;
+            case OPCODES::SCRLO:
+                ParseOpcode(full_opcode, "SCRLO", new FieldCameraInstruction(), 0, "B");
+                break;
+            case OPCODES::SCRLC:
+                ParseOpcode(full_opcode, "SCRLC", new FieldCameraInstruction(), 0, "BBBB");
+                break;
+            case OPCODES::SCRLA:
+                ParseOpcode(full_opcode, "SCRLA", new FieldCameraInstruction(), 0, "NwBB");
+                break;
+            case OPCODES::SCR2D:
+                ParseOpcode(full_opcode, "SCR2D", new FieldCameraInstruction(), 0, "Nss");
+                break;
+            case OPCODES::SCRCC:
+                ParseOpcode(full_opcode, "SCRCC", new FieldCameraInstruction(), 0, "");
+                break;
+            case OPCODES::SCR2DC:
+                ParseOpcode(full_opcode, "SCR2DC", new FieldCameraInstruction(), 0, "NNssw");
+                break;
+            case OPCODES::SCRLW:
+                ParseOpcode(full_opcode, "SCRLW", new FieldCameraInstruction(), 0, "");
+                break;
+            case OPCODES::SCR2DL:
+                ParseOpcode(full_opcode, "SCR2DL", new FieldCameraInstruction(), 0, "NNssw");
+                break;
+            case OPCODES::VWOFT:
+                ParseOpcode(full_opcode, "VWOFT", new FieldCameraInstruction(), 0, "NssB");
+                break;
+            case OPCODES::FADE:
+                ParseOpcode(full_opcode, "FADE", new FieldCameraInstruction(), 0, "NNBBBBBB");
+                break;
+            case OPCODES::FADEW:
+                ParseOpcode(full_opcode, "FADEW", new FieldCameraInstruction(), 0, "");
+                break;
+            case OPCODES::SCRLP:
+                ParseOpcode(full_opcode, "SCRLP", new FieldCameraInstruction(), 0, "NwBB");
+                break;
+            case OPCODES::MVCAM:
+                ParseOpcode(full_opcode, "MVCAM", new FieldCameraInstruction(), 0, "B");
+                break;
 
 
             // AV
             // AV
-            CASE_OPCODE(OPCODE::BGMOVIE, "BGMOVIE", FieldMediaInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::AKAO2, "AKAO2", FieldMediaInstruction, 0, "NNNBwwwww");
-            CASE_OPCODE(OPCODE::MUSIC, "MUSIC", FieldMediaInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::SOUND, "SOUND", FieldMediaInstruction, 0, "NwB");
-            CASE_OPCODE(OPCODE::AKAO, "AKAO", FieldMediaInstruction, 0, "NNNBBwwww");
-            CASE_OPCODE(OPCODE::MUSVT, "MUSVT", FieldMediaInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::MUSVM, "MUSVM", FieldMediaInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::MULCK, "MULCK", FieldMediaInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::BMUSC, "BMUSC", FieldMediaInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::CHMPH, "CHMPH", FieldMediaInstruction, 0, "BBB");
-            CASE_OPCODE(OPCODE::PMVIE, "PMVIE", FieldMediaInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::MOVIE, "MOVIE", FieldMediaInstruction, 0, "");
-            CASE_OPCODE(OPCODE::MVIEF, "MVIEF", FieldMediaInstruction, 0, "NB");
-            CASE_OPCODE(OPCODE::FMUSC, "FMUSC", FieldMediaInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::CMUSC, "CMUSC", FieldMediaInstruction, 0, "BBBBBBB");
-            CASE_OPCODE(OPCODE::CHMST, "CHMST", FieldMediaInstruction, 0, "NB");
+            case OPCODES::BGMOVIE:
+                ParseOpcode(full_opcode, "BGMOVIE", new FieldMediaInstruction(), 0, "B");
+                break;
+            case OPCODES::AKAO2:
+                ParseOpcode(full_opcode, "AKAO2", new FieldMediaInstruction(), 0, "NNNBwwwww");
+                break;
+            case OPCODES::MUSIC:
+                ParseOpcode(full_opcode, "MUSIC", new FieldMediaInstruction(), 0, "B");
+                break;
+            case OPCODES::SOUND:
+                ParseOpcode(full_opcode, "SOUND", new FieldMediaInstruction(), 0, "NwB");
+                break;
+            case OPCODES::AKAO:
+                ParseOpcode(full_opcode, "AKAO", new FieldMediaInstruction(), 0, "NNNBBwwww");
+                break;
+            case OPCODES::MUSVT:
+                ParseOpcode(full_opcode, "MUSVT", new FieldMediaInstruction(), 0, "B");
+                break;
+            case OPCODES::MUSVM:
+                ParseOpcode(full_opcode, "MUSVM", new FieldMediaInstruction(), 0, "B");
+                break;
+            case OPCODES::MULCK:
+                ParseOpcode(full_opcode, "MULCK", new FieldMediaInstruction(), 0, "B");
+                break;
+            case OPCODES::BMUSC:
+                ParseOpcode(full_opcode, "BMUSC", new FieldMediaInstruction(), 0, "B");
+                break;
+            case OPCODES::CHMPH:
+                ParseOpcode(full_opcode, "CHMPH", new FieldMediaInstruction(), 0, "BBB");
+                break;
+            case OPCODES::PMVIE:
+                ParseOpcode(full_opcode, "PMVIE", new FieldMediaInstruction(), 0, "B");
+                break;
+            case OPCODES::MOVIE:
+                ParseOpcode(full_opcode, "MOVIE", new FieldMediaInstruction(), 0, "");
+                break;
+            case OPCODES::MVIEF:
+                ParseOpcode(full_opcode, "MVIEF", new FieldMediaInstruction(), 0, "NB");
+                break;
+            case OPCODES::FMUSC:
+                ParseOpcode(full_opcode, "FMUSC", new FieldMediaInstruction(), 0, "B");
+                break;
+            case OPCODES::CMUSC:
+                ParseOpcode(full_opcode, "CMUSC", new FieldMediaInstruction(), 0, "BBBBBBB");
+                break;
+            case OPCODES::CHMST:
+                ParseOpcode(full_opcode, "CHMST", new FieldMediaInstruction(), 0, "NB");
+                break;
 
 
             // Uncat
             // Uncat
-            CASE_OPCODE(OPCODE::MPDSP, "MPDSP", FieldUncategorizedInstruction, 0, "B");
-            CASE_OPCODE(OPCODE::SETX, "SETX", FieldUncategorizedInstruction, 0, "BBBBBB");
-            CASE_OPCODE(OPCODE::GETX, "GETX", FieldUncategorizedInstruction, 0, "BBBBBB");
-            CASE_OPCODE(OPCODE::SEARCHX, "SEARCHX", FieldUncategorizedInstruction, 0, "BBBBBBBBBB");
+            case OPCODES::MPDSP:
+                ParseOpcode(full_opcode, "MPDSP", new FieldUncategorizedInstruction(), 0, "B");
+                break;
+            case OPCODES::SETX:
+                ParseOpcode(full_opcode, "SETX", new FieldUncategorizedInstruction(), 0, "BBBBBB");
+                break;
+            case OPCODES::GETX:
+                ParseOpcode(full_opcode, "GETX", new FieldUncategorizedInstruction(), 0, "BBBBBB");
+                break;
+            case OPCODES::SEARCHX:
+                ParseOpcode(full_opcode, "SEARCHX", new FieldUncategorizedInstruction(), 0, "BBBBBBBBBB");
+                break;
 
 
             default:
             default:
                 throw UnknownOpcodeException(this->address_, opcode);
                 throw UnknownOpcodeException(this->address_, opcode);
         }
         }
-        INC_ADDR;
+        this->address_++;
 
 
         // Is it within an "if" statement tracking?
         // Is it within an "if" statement tracking?
-        InstPtr i = this->_insts.back();
+        InstPtr i = this->insts_.back();
         if (i->isCondJump()) exitAddrs.push_back(i->GetDestAddress());
         if (i->isCondJump()) exitAddrs.push_back(i->GetDestAddress());
         if (!exitAddrs.empty())
         if (!exitAddrs.empty())
             if (i->_address == exitAddrs.back()) exitAddrs.pop_back();
             if (i->_address == exitAddrs.back()) exitAddrs.pop_back();
-
         // Only bail if its the first RET that isn't within an "if" block.
         // Only bail if its the first RET that isn't within an "if" block.
-        if (full_opcode == OPCODE::RET && exitAddrs.empty()) return is_line;
+        if (full_opcode == OPCODES::RET && exitAddrs.empty()) return is_line;
     }
     }
     return is_line;
     return is_line;
 }
 }

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

@@ -24,58 +24,53 @@
 #include "decompiler/field/FieldDisassembler.h"
 #include "decompiler/field/FieldDisassembler.h"
 #include "decompiler/field/instruction/FieldNoOperationInstruction.h"
 #include "decompiler/field/instruction/FieldNoOperationInstruction.h"
 
 
-#define GET(vertex) (boost::get(boost::vertex_name, g, vertex))
+/**
+ * @todo Understand and document
+ */
+#define GET(vertex) (boost::get(boost::vertex_name, graph, vertex))
 
 
 /*
 /*
-OpCodes which need implementing (already done in DAT dumper)
-
-"BLINK"
-"XYI"
-"CMOVE"
-"MOVA"
-"TURA"
-"ANIMW"
-"FMOVE"
-"ANIME2"
-"ANIM_1"
-"CANIM1" ?
-"CANM_1"
-"TURN"
-"DIRA"
-"GETDIR"
-"GETAXY"
-"JUMP"
-"AXYZI"
-"LADER"
-"OFST"
-"TALKR"
-"ANIMB"
-"TURNW"
-*/
-
-FieldEngine::FieldEngine(SUDM::IScriptFormatter& formatter, std::string script_name) :
-mFormatter(formatter), script_name_(script_name)
-{setOutputStackEffect(false);}
+ * TODO: OpCodes which need implementing.
+ *
+ * BLINK
+ * XYI
+ * CMOVE
+ * MOVA
+ * TURA
+ * ANIMW
+ * FMOVE
+ * ANIME2
+ * ANIM_1
+ * CANIM1 ?
+ * CANM_1
+ * TURN
+ * DIRA
+ * GETDIR
+ * GETAXY
+ * TALKR
+ * ANIMB
+ * TURNW
+ */
 
 
-FieldEngine::Entity::Entity(const std::string& name, size_t index):
+FF7::FieldEngine::Entity::Entity(const std::string& name, size_t index):
   name_(name), index_(index), is_line_(false)
   name_(name), index_(index), is_line_(false)
 {}
 {}
 
 
-std::string FieldEngine::Entity::GetName() const{return name_;}
+std::string FF7::FieldEngine::Entity::GetName() const{return name_;}
 
 
-size_t FieldEngine::Entity::GetIndex() const{return index_;}
+size_t FF7::FieldEngine::Entity::GetIndex() const{return index_;}
 
 
-std::string FieldEngine::Entity::FunctionByIndex(size_t index) const{
+std::string FF7::FieldEngine::Entity::FunctionByIndex(size_t index) const{
     auto it = functions_.find(index);
     auto it = functions_.find(index);
     if (it == std::end(functions_)) throw InternalDecompilerError();
     if (it == std::end(functions_)) throw InternalDecompilerError();
     return it->second;
     return it->second;
 }
 }
 
 
-void FieldEngine::Entity::AddFunction(const std::string& name, size_t index){
+void FF7::FieldEngine::Entity::AddFunction(const std::string& name, size_t index){
     functions_[index] = name;
     functions_[index] = name;
 }
 }
 
 
-void FieldEngine::Entity::MarkAsLine(
+void FF7::FieldEngine::Entity::MarkAsLine(
   bool line, std::vector<float> point_a, std::vector<float> point_b
   bool line, std::vector<float> point_a, std::vector<float> point_b
 ){
 ){
     is_line_ = line;
     is_line_ = line;
@@ -100,74 +95,77 @@ void FieldEngine::Entity::MarkAsLine(
     AddFunction("on_leave_line", 4);
     AddFunction("on_leave_line", 4);
 }
 }
 
 
-bool FieldEngine::Entity::IsLine(){return is_line_;}
+bool FF7::FieldEngine::Entity::IsLine(){return is_line_;}
 
 
-std::vector<float> FieldEngine::Entity::GetLinePointA(){return point_a_;}
+std::vector<float> FF7::FieldEngine::Entity::GetLinePointA(){return point_a_;}
 
 
-std::vector<float> FieldEngine::Entity::GetLinePointB(){return point_b_;}
+std::vector<float> FF7::FieldEngine::Entity::GetLinePointB(){return point_b_;}
 
 
-std::unique_ptr<Disassembler> FieldEngine::GetDisassembler(
+FF7::FieldEngine::FieldEngine(SUDM::IScriptFormatter& formatter, std::string script_name) :
+  formatter_(formatter), script_name_(script_name), scale_factor_(1.0f)
+{setOutputStackEffect(false);}
+
+std::unique_ptr<Disassembler> FF7::FieldEngine::GetDisassembler(
   InstVec &insts, const std::vector<unsigned char>& raw_script_data
   InstVec &insts, const std::vector<unsigned char>& raw_script_data
 ){
 ){
-    auto ret = std::make_unique<FieldDisassembler>(mFormatter, this, insts, raw_script_data);
+    auto ret = std::make_unique<FieldDisassembler>(formatter_, this, insts, raw_script_data);
     scale_factor_ = ret->GetScaleFactor();
     scale_factor_ = ret->GetScaleFactor();
     return std::move(ret);
     return std::move(ret);
 }
 }
 
 
-std::unique_ptr<Disassembler> FieldEngine::GetDisassembler(InstVec &insts){
-    auto ret = std::make_unique<FieldDisassembler>(mFormatter, this, insts);
+std::unique_ptr<Disassembler> FF7::FieldEngine::GetDisassembler(InstVec &insts){
+    auto ret = std::make_unique<FieldDisassembler>(formatter_, this, insts);
     scale_factor_ = ret->GetScaleFactor();
     scale_factor_ = ret->GetScaleFactor();
     return std::move(ret);
     return std::move(ret);
 }
 }
 
 
-std::unique_ptr<CodeGenerator> FieldEngine::GetCodeGenerator(
+std::unique_ptr<CodeGenerator> FF7::FieldEngine::GetCodeGenerator(
   const InstVec& insts, std::ostream &output
   const InstVec& insts, std::ostream &output
 ){
 ){
     // The broken version:
     // The broken version:
-    //return std::make_unique<FF7CodeGenerator>(this, insts, output);
+    //return std::make_unique<FieldCodeGenerator>(this, insts, output);
     // The not-as-nice-but-at-least-it-works version:
     // The not-as-nice-but-at-least-it-works version:
-    return std::make_unique<FieldCodeGenerator>(this, insts, output, mFormatter);
+    return std::make_unique<FF7::FieldCodeGenerator>(this, insts, output, formatter_);
 }
 }
 
 
-void FieldEngine::PostCFG(InstVec& insts, Graph graph){
-
+void FF7::FieldEngine::PostCFG(InstVec& insts, Graph graph){
     // In FF7 some scripts ends with an infinite loop to "keep it alive"
     // In FF7 some scripts ends with an infinite loop to "keep it alive"
-    // in VGears this isn't required so we can remove them
+    // in V-Gears this isn't required so they can be removed.
     //RemoveTrailingInfiniteLoops(insts, graph);
     //RemoveTrailingInfiniteLoops(insts, graph);
 
 
     // This could generate bad code, but it always seems to follow that pattern that if the last
     // This could generate bad code, but it always seems to follow that pattern that if the last
     // instruction is an uncond jump back into the script then it simply nests all of those blocks
     // instruction is an uncond jump back into the script then it simply nests all of those blocks
-    // in an infinite loop
+    // in an infinite loop.
     //MarkInfiniteLoopGroups(insts, graph);
     //MarkInfiniteLoopGroups(insts, graph);
 
 
-    // Scripts end with a "return" this isn't required so strip them out
+    // Scripts end with a "return". This isn't required so strip them out.
     //RemoveExtraneousReturnStatements(insts, graph);
     //RemoveExtraneousReturnStatements(insts, graph);
 }
 }
 
 
-bool FieldEngine::UsePureGrouping() const{return false;}
+bool FF7::FieldEngine::UsePureGrouping() const{return false;}
 
 
-std::map<std::string, int> FieldEngine::GetEntities() const{
+std::map<std::string, int> FF7::FieldEngine::GetEntities() const{
     std::map<std::string, int> r;
     std::map<std::string, int> r;
     for (auto& f : _functions){
     for (auto& f : _functions){
         const Function& func = f.second;
         const Function& func = f.second;
-        FunctionMetaData meta(func._metadata);
+        FF7::FunctionMetaData meta(func._metadata);
         auto it = r.find(meta.GetEntityName());
         auto it = r.find(meta.GetEntityName());
         if (it != std::end(r)){
         if (it != std::end(r)){
-            // Try to find a function in this entity has that has a char id
+            // Try to find a function in this entity has that has a char id.
             // don't overwrite a valid char id with a "blank" one.
             // don't overwrite a valid char id with a "blank" one.
             if (it->second == -1) it->second = meta.GetCharacterId();
             if (it->second == -1) it->second = meta.GetCharacterId();
         }
         }
-        // TODO: Don't add lines here:
+        // TODO: Don't add line entities here:
         else r[meta.GetEntityName()] = meta.GetCharacterId();
         else r[meta.GetEntityName()] = meta.GetCharacterId();
     }
     }
     return r;
     return r;
 }
 }
 
 
-std::vector<SUDM::Field::FieldEntity> FieldEngine::GetEntityList() const{
-    std::vector<SUDM::Field::FieldEntity> entities;
+std::vector<SUDM::FF7::Field::FieldEntity> FF7::FieldEngine::GetEntityList() const{
+    std::vector<SUDM::FF7::Field::FieldEntity> entities;
     for (auto entity: entity_index_map_){
     for (auto entity: entity_index_map_){
         if (entity.second.IsLine() == false){
         if (entity.second.IsLine() == false){
-            SUDM::Field::FieldEntity ent;
+            SUDM::FF7::Field::FieldEntity ent;
             ent.name = entity.second.GetName();
             ent.name = entity.second.GetName();
             ent.index = entity.second.GetIndex();
             ent.index = entity.second.GetIndex();
 
 
@@ -176,7 +174,7 @@ std::vector<SUDM::Field::FieldEntity> FieldEngine::GetEntityList() const{
             std::map<std::string, int> r;
             std::map<std::string, int> r;
             for (auto& f : _functions){
             for (auto& f : _functions){
                 const Function& func = f.second;
                 const Function& func = f.second;
-                FunctionMetaData meta(func._metadata);
+                FF7::FunctionMetaData meta(func._metadata);
                 if (meta.GetEntityName() == ent.name){
                 if (meta.GetEntityName() == ent.name){
                     ent.char_id = meta.GetCharacterId();
                     ent.char_id = meta.GetCharacterId();
                     break;
                     break;
@@ -188,11 +186,11 @@ std::vector<SUDM::Field::FieldEntity> FieldEngine::GetEntityList() const{
     return entities;
     return entities;
 }
 }
 
 
-std::vector<SUDM::Field::Line> FieldEngine::GetLineList() const{
-    std::vector<SUDM::Field::Line> lines;
+std::vector<SUDM::FF7::Field::Line> FF7::FieldEngine::GetLineList() const{
+    std::vector<SUDM::FF7::Field::Line> lines;
     for (auto entity: entity_index_map_){
     for (auto entity: entity_index_map_){
         if (entity.second.IsLine() == true){
         if (entity.second.IsLine() == true){
-            SUDM::Field::Line line;
+            SUDM::FF7::Field::Line line;
             line.name = entity.second.GetName();
             line.name = entity.second.GetName();
             line.point_a = entity.second.GetLinePointA();
             line.point_a = entity.second.GetLinePointA();
             line.point_b = entity.second.GetLinePointB();
             line.point_b = entity.second.GetLinePointB();
@@ -202,7 +200,7 @@ std::vector<SUDM::Field::Line> FieldEngine::GetLineList() const{
     return lines;
     return lines;
 }
 }
 
 
-void FieldEngine::AddEntityFunction(
+void FF7::FieldEngine::AddEntityFunction(
   const std::string& entity_name, size_t entity_index,
   const std::string& entity_name, size_t entity_index,
   const std::string& func_name, size_t func_index
   const std::string& func_name, size_t func_index
 ){
 ){
@@ -215,7 +213,7 @@ void FieldEngine::AddEntityFunction(
     }
     }
 }
 }
 
 
-void FieldEngine::MarkEntityAsLine(
+void FF7::FieldEngine::MarkEntityAsLine(
   size_t entity_index, bool line, std::vector<float> point_a, std::vector<float> point_b
   size_t entity_index, bool line, std::vector<float> point_a, std::vector<float> point_b
 ){
 ){
     auto it = entity_index_map_.find(entity_index);
     auto it = entity_index_map_.find(entity_index);
@@ -224,34 +222,34 @@ void FieldEngine::MarkEntityAsLine(
     }
     }
 }
 }
 
 
-bool FieldEngine::EntityIsLine(size_t entity_index){
+bool FF7::FieldEngine::EntityIsLine(size_t entity_index){
     auto it = entity_index_map_.find(entity_index);
     auto it = entity_index_map_.find(entity_index);
     if (it != std::end(entity_index_map_)) return (*it).second.IsLine();
     if (it != std::end(entity_index_map_)) return (*it).second.IsLine();
     return false;
     return false;
 }
 }
 
 
-const FieldEngine::Entity& FieldEngine::EntityByIndex(size_t index) const{
+const FF7::FieldEngine::Entity& FF7::FieldEngine::EntityByIndex(size_t index) const{
     auto it = entity_index_map_.find(index);
     auto it = entity_index_map_.find(index);
     if (it == std::end(entity_index_map_)) throw InternalDecompilerError();
     if (it == std::end(entity_index_map_)) throw InternalDecompilerError();
     return it->second;
     return it->second;
 }
 }
 
 
-float FieldEngine::GetScaleFactor() const {return scale_factor_;}
+float FF7::FieldEngine::GetScaleFactor() const {return scale_factor_;}
 
 
-const std::string& FieldEngine::ScriptName() const {return script_name_;}
+const std::string& FF7::FieldEngine::GetScriptName() const {return script_name_;}
 
 
-void FieldEngine::RemoveExtraneousReturnStatements(InstVec& insts, Graph g){
+void FF7::FieldEngine::RemoveExtraneousReturnStatements(InstVec& insts, Graph graph){
     for (auto& f : _functions){
     for (auto& f : _functions){
         Function& func = f.second;
         Function& func = f.second;
         for (auto it = insts.begin(); it != insts.end(); it ++){
         for (auto it = insts.begin(); it != insts.end(); it ++){
             // Is it the last instruction in the function, and is it a return statement?
             // Is it the last instruction in the function, and is it a return statement?
             if ((*it)->_address == func.mEndAddr){
             if ((*it)->_address == func.mEndAddr){
-                if ((*it)->_opcode == OPCODE::RET){
+                if ((*it)->_opcode == OPCODES::RET){
                     // Set new end address to be before the NOP.
                     // Set new end address to be before the NOP.
                     func.mEndAddr = (*(it - 1))->_address;
                     func.mEndAddr = (*(it - 1))->_address;
                     func.mNumInstructions --;
                     func.mNumInstructions --;
                     Instruction* nop = new FieldNoOperationInstruction();
                     Instruction* nop = new FieldNoOperationInstruction();
-                    nop->_opcode = OPCODE::NOP;
+                    nop->_opcode = OPCODES::NOP;
                     nop->_address = (*it)->_address;
                     nop->_address = (*it)->_address;
                     (*it).reset(nop);
                     (*it).reset(nop);
                     break;
                     break;
@@ -261,7 +259,7 @@ void FieldEngine::RemoveExtraneousReturnStatements(InstVec& insts, Graph g){
     }
     }
 }
 }
 
 
-void FieldEngine::RemoveTrailingInfiniteLoops(InstVec& insts, Graph g){
+void FF7::FieldEngine::RemoveTrailingInfiniteLoops(InstVec& insts, Graph graph){
     for (auto& f : _functions){
     for (auto& f : _functions){
         Function& func = f.second;
         Function& func = f.second;
         for (auto it = insts.begin(); it != insts.end(); it ++){
         for (auto it = insts.begin(); it != insts.end(); it ++){
@@ -272,7 +270,7 @@ void FieldEngine::RemoveTrailingInfiniteLoops(InstVec& insts, Graph g){
                     func.mEndAddr = (*(it - 1))->_address;
                     func.mEndAddr = (*(it - 1))->_address;
                     func.mNumInstructions--;
                     func.mNumInstructions--;
                     Instruction* nop = new FieldNoOperationInstruction();
                     Instruction* nop = new FieldNoOperationInstruction();
-                    nop->_opcode = OPCODE::NOP;
+                    nop->_opcode = OPCODES::NOP;
                     nop->_address = (*it)->_address;
                     nop->_address = (*it)->_address;
                     (*it).reset(nop);
                     (*it).reset(nop);
                     break;
                     break;
@@ -282,7 +280,7 @@ void FieldEngine::RemoveTrailingInfiniteLoops(InstVec& insts, Graph g){
     }
     }
 }
 }
 
 
-void FieldEngine::MarkInfiniteLoopGroups(InstVec& insts, Graph g){
+void FF7::FieldEngine::MarkInfiniteLoopGroups(InstVec& insts, Graph graph){
     for (auto& f : _functions){
     for (auto& f : _functions){
         Function& func = f.second;
         Function& func = f.second;
         for (auto it = insts.begin(); it != insts.end(); it ++){
         for (auto it = insts.begin(); it != insts.end(); it ++){
@@ -292,10 +290,10 @@ void FieldEngine::MarkInfiniteLoopGroups(InstVec& insts, Graph g){
                 if ((*it)->IsUncondJump()){
                 if ((*it)->IsUncondJump()){
                     // Then assume its an infinite do { } while(true)
                     // Then assume its an infinite do { } while(true)
                     // loop that wraps part of the script.
                     // loop that wraps part of the script.
-                    VertexRange vr = boost::vertices(g);
+                    VertexRange vr = boost::vertices(graph);
                     for (VertexIterator v = vr.first; v != vr.second; ++ v){
                     for (VertexIterator v = vr.first; v != vr.second; ++ v){
                         GroupPtr gr = GET(*v);
                         GroupPtr gr = GET(*v);
-                        if ((*gr->_start)->_address == func.mEndAddr){
+                        if ((*gr->start_)->_address == func.mEndAddr){
                             // Then assume its an infinite do { } while(true) loop
                             // Then assume its an infinite do { } while(true) loop
                             // that wraps part of the script.
                             // that wraps part of the script.
                             gr->_type = kDoWhileCondGroupType;
                             gr->_type = kDoWhileCondGroupType;
@@ -307,3 +305,4 @@ void FieldEngine::MarkInfiniteLoopGroups(InstVec& insts, Graph g){
         }
         }
     }
     }
 }
 }
+

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

@@ -16,48 +16,51 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
 #include "decompiler/field/instruction/FieldBackgroundInstruction.h"
 #include "decompiler/field/instruction/FieldBackgroundInstruction.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldDisassembler.h"
 #include "decompiler/field/FieldDisassembler.h"
 
 
-void FieldBackgroundInstruction::ProcessInst(
+void FF7::FieldBackgroundInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
 ){
     FunctionMetaData md(func._metadata);
     FunctionMetaData md(func._metadata);
     switch (_opcode){
     switch (_opcode){
-        case OPCODE::BGPDH: WriteTodo(code_gen, md.GetEntityName(), "BGPDH");break;
-        case OPCODE::BGSCR: WriteTodo(code_gen, md.GetEntityName(), "BGSCR"); break;
-        case OPCODE::MPPAL: WriteTodo(code_gen, md.GetEntityName(), "MPPAL"); break;
-        case OPCODE::BGON: ProcessBGON(code_gen); break;
-        case OPCODE::BGOFF: ProcessBGOFF(code_gen); break;
-        case OPCODE::BGROL: WriteTodo(code_gen, md.GetEntityName(), "BGROL"); break;
-        case OPCODE::BGROL2: WriteTodo(code_gen, md.GetEntityName(), "BGROL2"); break;
-        case OPCODE::BGCLR: ProcessBGCLR(code_gen); break;
-        case OPCODE::STPAL: ProcessSTPAL(code_gen); break;
-        case OPCODE::LDPAL: ProcessLDPAL(code_gen); break;
-        case OPCODE::CPPAL: ProcessCPPAL(code_gen); break;
-        case OPCODE::RTPAL: WriteTodo(code_gen, md.GetEntityName(), "RTPAL"); break;
-        case OPCODE::ADPAL: ProcessADPAL(code_gen); break;
-        case OPCODE::MPPAL2: ProcessMPPAL2(code_gen); break;
-        case OPCODE::STPLS: ProcessSTPLS(code_gen); break;
-        case OPCODE::LDPLS: ProcessLDPLS(code_gen); break;
-        case OPCODE::CPPAL2: WriteTodo(code_gen, md.GetEntityName(), "CPPAL2"); break;
-        case OPCODE::ADPAL2: WriteTodo(code_gen, md.GetEntityName(), "ADPAL2"); break;
-        case OPCODE::RTPAL2: WriteTodo(code_gen, md.GetEntityName(), "RTPAL2"); break;
+        case OPCODES::BGPDH: code_gen->WriteTodo(md.GetEntityName(), "BGPDH");break;
+        case OPCODES::BGSCR: code_gen->WriteTodo(md.GetEntityName(), "BGSCR"); break;
+        case OPCODES::MPPAL: code_gen->WriteTodo(md.GetEntityName(), "MPPAL"); break;
+        case OPCODES::BGON: ProcessBGON(code_gen); break;
+        case OPCODES::BGOFF: ProcessBGOFF(code_gen); break;
+        case OPCODES::BGROL: code_gen->WriteTodo(md.GetEntityName(), "BGROL"); break;
+        case OPCODES::BGROL2: code_gen->WriteTodo(md.GetEntityName(), "BGROL2"); break;
+        case OPCODES::BGCLR: ProcessBGCLR(code_gen); break;
+        case OPCODES::STPAL: ProcessSTPAL(code_gen); break;
+        case OPCODES::LDPAL: ProcessLDPAL(code_gen); break;
+        case OPCODES::CPPAL: ProcessCPPAL(code_gen); break;
+        case OPCODES::RTPAL: code_gen->WriteTodo(md.GetEntityName(), "RTPAL"); break;
+        case OPCODES::ADPAL: ProcessADPAL(code_gen); break;
+        case OPCODES::MPPAL2: ProcessMPPAL2(code_gen); break;
+        case OPCODES::STPLS: ProcessSTPLS(code_gen); break;
+        case OPCODES::LDPLS: ProcessLDPLS(code_gen); break;
+        case OPCODES::CPPAL2: code_gen->WriteTodo(md.GetEntityName(), "CPPAL2"); break;
+        case OPCODES::ADPAL2: code_gen->WriteTodo(md.GetEntityName(), "ADPAL2"); break;
+        case OPCODES::RTPAL2: code_gen->WriteTodo(md.GetEntityName(), "RTPAL2"); break;
         default:
         default:
-            code_gen->AddOutputLine(FieldCodeGenerator::FormatInstructionNotImplemented(
+            code_gen->AddOutputLine(FF7::FieldCodeGenerator::FormatInstructionNotImplemented(
               md.GetEntityName(), _address, _opcode
               md.GetEntityName(), _address, _opcode
             ));
             ));
     }
     }
 }
 }
 
 
-void FieldBackgroundInstruction::ProcessBGON(CodeGenerator* code_gen){
+void FF7::FieldBackgroundInstruction::ProcessBGON(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
-    const auto& background_id = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& background_id = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
     );
     );
-    const auto& layer_id = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& layer_id = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
     );
     );
     code_gen->AddOutputLine(
     code_gen->AddOutputLine(
@@ -65,12 +68,12 @@ void FieldBackgroundInstruction::ProcessBGON(CodeGenerator* code_gen){
     );
     );
 }
 }
 
 
-void FieldBackgroundInstruction::ProcessBGOFF(CodeGenerator* code_gen){
+void FF7::FieldBackgroundInstruction::ProcessBGOFF(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
-    const auto& background_id = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& background_id = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
     );
     );
-    const auto& layer_id = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& layer_id = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
     );
     );
     code_gen->AddOutputLine(
     code_gen->AddOutputLine(
@@ -78,9 +81,9 @@ void FieldBackgroundInstruction::ProcessBGOFF(CodeGenerator* code_gen){
     );
     );
 }
 }
 
 
-void FieldBackgroundInstruction::ProcessBGCLR(CodeGenerator* code_gen){
+void FF7::FieldBackgroundInstruction::ProcessBGCLR(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
-    const auto& background_id = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& background_id = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[2]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[2]->getUnsigned()
     );
     );
     code_gen->AddOutputLine(
     code_gen->AddOutputLine(
@@ -88,12 +91,12 @@ void FieldBackgroundInstruction::ProcessBGCLR(CodeGenerator* code_gen){
     );
     );
 }
 }
 
 
-void FieldBackgroundInstruction::ProcessSTPAL(CodeGenerator* code_gen){
+void FF7::FieldBackgroundInstruction::ProcessSTPAL(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
-    const auto& source = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& source = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
     );
     );
-    const auto& destination = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& destination = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
     );
     );
     auto num_entries = _params[4]->getUnsigned() + 1;
     auto num_entries = _params[4]->getUnsigned() + 1;
@@ -103,12 +106,12 @@ void FieldBackgroundInstruction::ProcessSTPAL(CodeGenerator* code_gen){
     ).str());
     ).str());
 }
 }
 
 
-void FieldBackgroundInstruction::ProcessLDPAL(CodeGenerator* code_gen){
+void FF7::FieldBackgroundInstruction::ProcessLDPAL(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
-    const auto& source = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& source = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
     );
     );
-    const auto& destination = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& destination = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
     );
     );
     auto num_entries = _params[4]->getUnsigned() + 1;
     auto num_entries = _params[4]->getUnsigned() + 1;
@@ -118,12 +121,12 @@ void FieldBackgroundInstruction::ProcessLDPAL(CodeGenerator* code_gen){
     ).str());
     ).str());
 }
 }
 
 
-void FieldBackgroundInstruction::ProcessCPPAL(CodeGenerator* code_gen){
+void FF7::FieldBackgroundInstruction::ProcessCPPAL(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
-    const auto& source = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& source = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
     );
     );
-    const auto& destination = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& destination = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
     );
     );
     auto num_entries = _params[4]->getUnsigned() + 1;
     auto num_entries = _params[4]->getUnsigned() + 1;
@@ -133,21 +136,21 @@ void FieldBackgroundInstruction::ProcessCPPAL(CodeGenerator* code_gen){
     ).str());
     ).str());
 }
 }
 
 
-void FieldBackgroundInstruction::ProcessADPAL(CodeGenerator* code_gen){
+void FF7::FieldBackgroundInstruction::ProcessADPAL(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
-    const auto& source = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& source = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[6]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[6]->getUnsigned()
     );
     );
-    const auto& destination = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& destination = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[7]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[7]->getUnsigned()
     );
     );
-    const auto& r = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& r = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[4]->getUnsigned(), _params[10]->getUnsigned()
       cg->GetFormatter(), _params[4]->getUnsigned(), _params[10]->getUnsigned()
     );
     );
-    const auto& g = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& g = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[9]->getUnsigned()
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[9]->getUnsigned()
     );
     );
-    const auto& b = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& b = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[8]->getUnsigned()
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[8]->getUnsigned()
     );
     );
     auto num_entries = _params[11]->getUnsigned() + 1;
     auto num_entries = _params[11]->getUnsigned() + 1;
@@ -159,21 +162,21 @@ void FieldBackgroundInstruction::ProcessADPAL(CodeGenerator* code_gen){
     ).str());
     ).str());
 }
 }
 
 
-void FieldBackgroundInstruction::ProcessMPPAL2(CodeGenerator* code_gen){
+void FF7::FieldBackgroundInstruction::ProcessMPPAL2(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
-    const auto& source = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& source = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[6]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[6]->getUnsigned()
     );
     );
-    const auto& destination = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& destination = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[7]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[7]->getUnsigned()
     );
     );
-    const auto& r = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& r = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[4]->getUnsigned(), _params[10]->getUnsigned()
       cg->GetFormatter(), _params[4]->getUnsigned(), _params[10]->getUnsigned()
     );
     );
-    const auto& g = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& g = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[9]->getUnsigned()
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[9]->getUnsigned()
     );
     );
-    const auto& b = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& b = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[8]->getUnsigned()
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[8]->getUnsigned()
     );
     );
     auto num_entries = _params[11]->getUnsigned() + 1;
     auto num_entries = _params[11]->getUnsigned() + 1;
@@ -184,7 +187,7 @@ void FieldBackgroundInstruction::ProcessMPPAL2(CodeGenerator* code_gen){
       ) % source % destination % r % g % b % num_entries).str());
       ) % source % destination % r % g % b % num_entries).str());
 }
 }
 
 
-void FieldBackgroundInstruction::ProcessSTPLS(CodeGenerator* code_gen){
+void FF7::FieldBackgroundInstruction::ProcessSTPLS(CodeGenerator* code_gen){
     auto source = _params[0]->getUnsigned();
     auto source = _params[0]->getUnsigned();
     auto destination = _params[1]->getUnsigned();
     auto destination = _params[1]->getUnsigned();
     auto start_clut = _params[2]->getUnsigned();
     auto start_clut = _params[2]->getUnsigned();
@@ -195,7 +198,7 @@ void FieldBackgroundInstruction::ProcessSTPLS(CodeGenerator* code_gen){
     ).str());
     ).str());
 }
 }
 
 
-void FieldBackgroundInstruction::ProcessLDPLS(CodeGenerator* code_gen){
+void FF7::FieldBackgroundInstruction::ProcessLDPLS(CodeGenerator* code_gen){
     auto source = _params[0]->getUnsigned();
     auto source = _params[0]->getUnsigned();
     auto destination = _params[1]->getUnsigned();
     auto destination = _params[1]->getUnsigned();
     auto startClut = _params[2]->getUnsigned();
     auto startClut = _params[2]->getUnsigned();

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

@@ -16,39 +16,42 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
 #include "decompiler/field/instruction/FieldCameraInstruction.h"
 #include "decompiler/field/instruction/FieldCameraInstruction.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldDisassembler.h"
 #include "decompiler/field/FieldDisassembler.h"
 
 
-void FieldCameraInstruction::ProcessInst(
+void FF7::FieldCameraInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
 ){
     FunctionMetaData md(func._metadata);
     FunctionMetaData md(func._metadata);
     switch (_opcode){
     switch (_opcode){
-    case OPCODE::NFADE: ProcessNFADE(code_gen); break;
-    case OPCODE::SHAKE: WriteTodo(code_gen, md.GetEntityName(), "SHAKE"); break;
-    case OPCODE::SCRLO: WriteTodo(code_gen, md.GetEntityName(), "SCRLO"); break;
-    case OPCODE::SCRLC: WriteTodo(code_gen, md.GetEntityName(), "SCRLC"); break;
-    case OPCODE::SCR2D: ProcessSCR2D(code_gen); break;
-    case OPCODE::SCRCC: WriteTodo(code_gen, md.GetEntityName(), "SCRCC"); break;
-    case OPCODE::SCR2DC: ProcessSCR2DC(code_gen); break;
-    case OPCODE::SCRLW: WriteTodo(code_gen, md.GetEntityName(), "SCRLW"); break;
-    case OPCODE::SCR2DL: WriteTodo(code_gen, md.GetEntityName(), "SCR2DL"); break;
-    case OPCODE::VWOFT: WriteTodo(code_gen, md.GetEntityName(), "VWOFT"); break;
-    case OPCODE::FADE: ProcessFADE(code_gen); break;
-    case OPCODE::FADEW: WriteTodo(code_gen, md.GetEntityName(), "FADEW"); break;
-    case OPCODE::SCRLP: WriteTodo(code_gen, md.GetEntityName(), "SCRLP"); break;
-    case OPCODE::MVCAM: WriteTodo(code_gen, md.GetEntityName(), "MVCAM"); break;
-    case OPCODE::SCRLA: WriteTodo(code_gen, md.GetEntityName(), "SCRLA"); break;
+    case OPCODES::NFADE: ProcessNFADE(code_gen); break;
+    case OPCODES::SHAKE: code_gen->WriteTodo(md.GetEntityName(), "SHAKE"); break;
+    case OPCODES::SCRLO: code_gen->WriteTodo(md.GetEntityName(), "SCRLO"); break;
+    case OPCODES::SCRLC: code_gen->WriteTodo(md.GetEntityName(), "SCRLC"); break;
+    case OPCODES::SCR2D: ProcessSCR2D(code_gen); break;
+    case OPCODES::SCRCC: code_gen->WriteTodo(md.GetEntityName(), "SCRCC"); break;
+    case OPCODES::SCR2DC: ProcessSCR2DC(code_gen); break;
+    case OPCODES::SCRLW: code_gen->WriteTodo(md.GetEntityName(), "SCRLW"); break;
+    case OPCODES::SCR2DL: code_gen->WriteTodo(md.GetEntityName(), "SCR2DL"); break;
+    case OPCODES::VWOFT: code_gen->WriteTodo(md.GetEntityName(), "VWOFT"); break;
+    case OPCODES::FADE: ProcessFADE(code_gen); break;
+    case OPCODES::FADEW: code_gen->WriteTodo(md.GetEntityName(), "FADEW"); break;
+    case OPCODES::SCRLP: code_gen->WriteTodo(md.GetEntityName(), "SCRLP"); break;
+    case OPCODES::MVCAM: code_gen->WriteTodo(md.GetEntityName(), "MVCAM"); break;
+    case OPCODES::SCRLA: code_gen->WriteTodo(md.GetEntityName(), "SCRLA"); break;
     default:
     default:
-        code_gen->AddOutputLine(FieldCodeGenerator::FormatInstructionNotImplemented(
+        code_gen->AddOutputLine(FF7::FieldCodeGenerator::FormatInstructionNotImplemented(
           md.GetEntityName(), _address, _opcode
           md.GetEntityName(), _address, _opcode
         ));
         ));
     }
     }
 }
 }
 
 
-void FieldCameraInstruction::ProcessNFADE(CodeGenerator* code_gen){
+void FF7::FieldCameraInstruction::ProcessNFADE(CodeGenerator* code_gen){
     // TODO: Not fully reversed.
     // TODO: Not fully reversed.
     auto raw_type = _params[4]->getUnsigned();
     auto raw_type = _params[4]->getUnsigned();
     if (raw_type == 0){
     if (raw_type == 0){
@@ -57,16 +60,16 @@ void FieldCameraInstruction::ProcessNFADE(CodeGenerator* code_gen){
     }
     }
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     const std::string type = raw_type == 12 ? "Fade.SUBTRACT" : "Fade.ADD";
     const std::string type = raw_type == 12 ? "Fade.SUBTRACT" : "Fade.ADD";
-    const auto& r = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& r = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[5]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[5]->getUnsigned()
     );
     );
-    const auto& g = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& g = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[6]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[6]->getUnsigned()
     );
     );
-    const auto& b = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& b = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[7]->getUnsigned()
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[7]->getUnsigned()
     );
     );
-    const auto& unknown = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& unknown = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[8]->getUnsigned()
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[8]->getUnsigned()
     );
     );
     code_gen->AddOutputLine(
     code_gen->AddOutputLine(
@@ -74,13 +77,13 @@ void FieldCameraInstruction::ProcessNFADE(CodeGenerator* code_gen){
     );
     );
 }
 }
 
 
-void FieldCameraInstruction::ProcessSCR2D(CodeGenerator* code_gen){
+void FF7::FieldCameraInstruction::ProcessSCR2D(CodeGenerator* code_gen){
     // kUpScaler.
     // kUpScaler.
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
-    const auto& x = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& x = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getSigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getSigned()
     );
     );
-    const auto& y = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& y = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getSigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getSigned()
     );
     );
     code_gen->AddOutputLine((
     code_gen->AddOutputLine((
@@ -89,17 +92,17 @@ void FieldCameraInstruction::ProcessSCR2D(CodeGenerator* code_gen){
     ).str());
     ).str());
 }
 }
 
 
-void FieldCameraInstruction::ProcessSCR2DC(CodeGenerator* code_gen){
+void FF7::FieldCameraInstruction::ProcessSCR2DC(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
-    const auto& x = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& x = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[4]->getSigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[4]->getSigned()
     );
     );
-    const auto& y = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& y = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[5]->getSigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[5]->getSigned()
     );
     );
-    const auto& speed = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& speed = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[6]->getUnsigned(),
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[6]->getUnsigned(),
-      FieldCodeGenerator::ValueType::Float, 30.0f
+      FF7::FieldCodeGenerator::ValueType::Float, 30.0f
     );
     );
     code_gen->AddOutputLine((
     code_gen->AddOutputLine((
       boost::format("background2d:scroll_to_position(%1% * 3, %2% * 3, Background2D.SMOOTH, %3%)")
       boost::format("background2d:scroll_to_position(%1% * 3, %2% * 3, Background2D.SMOOTH, %3%)")
@@ -107,7 +110,7 @@ void FieldCameraInstruction::ProcessSCR2DC(CodeGenerator* code_gen){
     ).str());
     ).str());
 }
 }
 
 
-void FieldCameraInstruction::ProcessFADE(CodeGenerator* code_gen){
+void FF7::FieldCameraInstruction::ProcessFADE(CodeGenerator* code_gen){
     // TODO: not fully reversed
     // TODO: not fully reversed
     auto raw_type = _params[8]->getUnsigned();
     auto raw_type = _params[8]->getUnsigned();
     std::string type;
     std::string type;
@@ -123,13 +126,13 @@ void FieldCameraInstruction::ProcessFADE(CodeGenerator* code_gen){
     }
     }
 
 
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
-    const auto& r = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& r = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[4]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[4]->getUnsigned()
     );
     );
-    const auto& g = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& g = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[5]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[5]->getUnsigned()
     );
     );
-    const auto& b = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& b = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[6]->getUnsigned()
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[6]->getUnsigned()
     );
     );
     // TODO: needs to be divided by 30.0f?
     // TODO: needs to be divided by 30.0f?

+ 30 - 27
V-Gears-Installer/src/decompiler/field/instruction/FieldCondJumpInstruction.cpp

@@ -16,21 +16,25 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
 #include "decompiler/field/instruction/FieldCondJumpInstruction.h"
 #include "decompiler/field/instruction/FieldCondJumpInstruction.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldDisassembler.h"
 #include "decompiler/field/FieldDisassembler.h"
 
 
-void FieldCondJumpInstruction::ProcessInst(
+void FF7::FieldCondJumpInstruction::ProcessInst(
   Function& function, ValueStack &stack, Engine* engine, CodeGenerator* code_gen
   Function& function, ValueStack &stack, Engine* engine, CodeGenerator* code_gen
 ){
 ){
-    FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
+    FF7::FieldCodeGenerator* cg = static_cast<FF7::FieldCodeGenerator*>(code_gen);
     std::string func_name;
     std::string func_name;
-    if (_opcode == OPCODE::IFKEYON) func_name = "entity_manager:is_key_on";
-    else if (_opcode == OPCODE::IFKEYOFF) func_name = "entity_manager:is_key_off";
-    else if (_opcode == OPCODE::IFKEY) func_name = "Key";
-    else if (_opcode == OPCODE::IFMEMBQ) func_name = "IFMEMBQ";
-    else if (_opcode == OPCODE::IFPRTYQ) func_name = "IFPRTYQ";
+    if (_opcode == OPCODES::IFKEYON) func_name = "entity_manager:is_key_on";
+    else if (_opcode == OPCODES::IFKEYOFF) func_name = "entity_manager:is_key_off";
+    else if (_opcode == OPCODES::IFKEY) func_name = "Key";
+    else if (_opcode == OPCODES::IFMEMBQ) func_name = "IFMEMBQ";
+    else if (_opcode == OPCODES::IFPRTYQ) func_name = "IFPRTYQ";
+
     // If condition is a function, add and stop.
     // If condition is a function, add and stop.
     if (!func_name.empty()){
     if (!func_name.empty()){
         uint32 param = _params[0]->getUnsigned();
         uint32 param = _params[0]->getUnsigned();
@@ -38,9 +42,9 @@ void FieldCondJumpInstruction::ProcessInst(
         // can be ORed to get the individual keys, but there are two invalid
         // can be ORed to get the individual keys, but there are two invalid
         // ones: 512 and 1024. They must be XORed.
         // ones: 512 and 1024. They must be XORed.
         if (
         if (
-          _opcode == OPCODE::IFKEY
-          || _opcode == OPCODE::IFKEYON
-          || _opcode == OPCODE::IFKEYOFF
+          _opcode == OPCODES::IFKEY
+          || _opcode == OPCODES::IFKEYON
+          || _opcode == OPCODES::IFKEYOFF
         ){
         ){
             if (param >= 1024) param = param ^ 1024;
             if (param >= 1024) param = param ^ 1024;
             if (param >= 512) param = param ^ 512;
             if (param >= 512) param = param ^ 512;
@@ -51,12 +55,13 @@ void FieldCondJumpInstruction::ProcessInst(
     }
     }
     std::string op;
     std::string op;
     uint32 type = _params[4]->getUnsigned();
     uint32 type = _params[4]->getUnsigned();
-    const auto& source = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& source = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
     );
     );
-    const auto& destination = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& destination = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
     );
     );
+
     switch (type){
     switch (type){
         case 0: op = "=="; break;
         case 0: op = "=="; break;
         case 1: op = "~="; break;
         case 1: op = "~="; break;
@@ -69,7 +74,6 @@ void FieldCondJumpInstruction::ProcessInst(
         case 8: op = "|"; break;
         case 8: op = "|"; break;
         case 9:
         case 9:
             {
             {
-                // TODO: Use FormatValueOrVariable
                 op = "bit(" + _params[0]->getString() + ", " + _params[2]->getString()
                 op = "bit(" + _params[0]->getString() + ", " + _params[2]->getString()
                   + ", " + destination + ") == 1";
                   + ", " + destination + ") == 1";
                 ValuePtr v = new UnqotedStringValue(op);
                 ValuePtr v = new UnqotedStringValue(op);
@@ -78,7 +82,6 @@ void FieldCondJumpInstruction::ProcessInst(
             return;
             return;
         case 0xA:
         case 0xA:
             {
             {
-                // TODO: Use FormatValueOrVariable
                 op = "bit(" + _params[0]->getString() + ", " + _params[2]->getString()
                 op = "bit(" + _params[0]->getString() + ", " + _params[2]->getString()
                   + ", " + destination + ") == 0";
                   + ", " + destination + ") == 0";
                 ValuePtr v = new UnqotedStringValue(op);
                 ValuePtr v = new UnqotedStringValue(op);
@@ -91,24 +94,24 @@ void FieldCondJumpInstruction::ProcessInst(
     stack.push(v);
     stack.push(v);
 }
 }
 
 
-uint32 FieldCondJumpInstruction::GetDestAddress() const{
+uint32 FF7::FieldCondJumpInstruction::GetDestAddress() const{
     uint32 params_size = 0;
     uint32 params_size = 0;
     uint32 jump_param_index = 5;
     uint32 jump_param_index = 5;
     switch (_opcode){
     switch (_opcode){
-        case OPCODE::IFUB: params_size = 5; break;
-        case OPCODE::IFUBL: params_size = 5; break;
-        case OPCODE::IFSW: params_size = 7; break;
-        case OPCODE::IFSWL: params_size = 7; break;
-        case OPCODE::IFUW: params_size = 7; break;
-        case OPCODE::IFUWL: params_size = 7; break;
-        case OPCODE::IFKEYON:
-        case OPCODE::IFKEYOFF:
-        case OPCODE::IFKEY:
+        case OPCODES::IFUB: params_size = 5; break;
+        case OPCODES::IFUBL: params_size = 5; break;
+        case OPCODES::IFSW: params_size = 7; break;
+        case OPCODES::IFSWL: params_size = 7; break;
+        case OPCODES::IFUW: params_size = 7; break;
+        case OPCODES::IFUWL: params_size = 7; break;
+        case OPCODES::IFKEYON:
+        case OPCODES::IFKEYOFF:
+        case OPCODES::IFKEY:
             params_size = 3;
             params_size = 3;
             jump_param_index = 1;
             jump_param_index = 1;
             break;
             break;
-        case OPCODE::IFPRTYQ:
-        case OPCODE::IFMEMBQ:
+        case OPCODES::IFPRTYQ:
+        case OPCODES::IFMEMBQ:
             params_size = 2;
             params_size = 2;
             jump_param_index = 1;
             jump_param_index = 1;
             break;
             break;
@@ -117,7 +120,7 @@ uint32 FieldCondJumpInstruction::GetDestAddress() const{
     return _address + _params[jump_param_index]->getUnsigned() + params_size;
     return _address + _params[jump_param_index]->getUnsigned() + params_size;
 }
 }
 
 
-std::ostream& FieldCondJumpInstruction::Print(std::ostream &output) const{
+std::ostream& FF7::FieldCondJumpInstruction::Print(std::ostream &output) const{
     Instruction::Print(output);
     Instruction::Print(output);
     output << " (False target address: 0x" << std::hex << GetDestAddress() << std::dec << ")";
     output << " (False target address: 0x" << std::hex << GetDestAddress() << std::dec << ")";
     return output;
     return output;

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

@@ -16,18 +16,21 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
 #include "decompiler/field/instruction/FieldControlFlowInstruction.h"
 #include "decompiler/field/instruction/FieldControlFlowInstruction.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldDisassembler.h"
 #include "decompiler/field/FieldDisassembler.h"
 
 
-void FieldControlFlowInstruction::ProcessInst(
+void FF7::FF7ControlFlowInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
 ){
-    FieldEngine& eng = static_cast<FieldEngine&>(*engine);
+    FF7::FieldEngine& eng = static_cast<FF7::FieldEngine&>(*engine);
     FunctionMetaData md(func._metadata);
     FunctionMetaData md(func._metadata);
     switch (_opcode){
     switch (_opcode){
-        case OPCODE::RET:
+        case OPCODES::RET:
             // A few notes in RET.
             // A few notes in RET.
             // - Lua requires all functions to end with a return.
             // - Lua requires all functions to end with a return.
             // - Lua doesn's like returns if not followed by an end.
             // - Lua doesn's like returns if not followed by an end.
@@ -38,22 +41,22 @@ void FieldControlFlowInstruction::ProcessInst(
             //     so it's OK not to include it here.
             //     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;
             break;
-        case OPCODE::REQ: ProcessREQ(code_gen, eng); break;
-        case OPCODE::REQSW: ProcessREQSW(code_gen, eng); break;
-        case OPCODE::REQEW: ProcessREQEW(code_gen, eng); break;
-        case OPCODE::PREQ: WriteTodo(code_gen, md.GetEntityName(), "PREQ"); break;
-        case OPCODE::PRQSW: WriteTodo(code_gen, md.GetEntityName(), "PRQSW"); break;
-        case OPCODE::PRQEW: WriteTodo(code_gen, md.GetEntityName(), "PRQEW"); break;
-        case OPCODE::RETTO: ProcessRETTO(code_gen); break;
-        case OPCODE::WAIT: ProcessWAIT(code_gen); break;
+        case OPCODES::REQ: ProcessREQ(code_gen, eng); break;
+        case OPCODES::REQSW: ProcessREQSW(code_gen, eng); break;
+        case OPCODES::REQEW: ProcessREQEW(code_gen, eng); break;
+        case OPCODES::PREQ: code_gen->WriteTodo(md.GetEntityName(), "PREQ"); break;
+        case OPCODES::PRQSW: code_gen->WriteTodo(md.GetEntityName(), "PRQSW"); break;
+        case OPCODES::PRQEW: code_gen->WriteTodo(md.GetEntityName(), "PRQEW"); break;
+        case OPCODES::RETTO: ProcessRETTO(code_gen); break;
+        case OPCODES::WAIT: ProcessWAIT(code_gen); break;
         default:
         default:
-            code_gen->AddOutputLine(FieldCodeGenerator::FormatInstructionNotImplemented(
+            code_gen->AddOutputLine(FF7::FieldCodeGenerator::FormatInstructionNotImplemented(
               md.GetEntityName(), _address, _opcode
               md.GetEntityName(), _address, _opcode
             ));
             ));
     }
     }
 }
 }
 
 
-void FieldControlFlowInstruction::ProcessREQ(
+void FF7::FF7ControlFlowInstruction::ProcessREQ(
   CodeGenerator* code_gen, const FieldEngine& engine
   CodeGenerator* code_gen, const FieldEngine& engine
 ){
 ){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
@@ -68,7 +71,7 @@ void FieldControlFlowInstruction::ProcessREQ(
     ).str());
     ).str());
 }
 }
 
 
-void FieldControlFlowInstruction::ProcessREQSW(
+void FF7::FF7ControlFlowInstruction::ProcessREQSW(
   CodeGenerator* code_gen, const FieldEngine& engine
   CodeGenerator* code_gen, const FieldEngine& engine
 ){
 ){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
@@ -83,7 +86,7 @@ void FieldControlFlowInstruction::ProcessREQSW(
     ).str());
     ).str());
 }
 }
 
 
-void FieldControlFlowInstruction::ProcessREQEW(
+void FF7::FF7ControlFlowInstruction::ProcessREQEW(
   CodeGenerator* code_gen, const FieldEngine& engine
   CodeGenerator* code_gen, const FieldEngine& engine
 ){
 ){
     try{
     try{
@@ -106,7 +109,7 @@ void FieldControlFlowInstruction::ProcessREQEW(
     }
     }
 }
 }
 
 
-void FieldControlFlowInstruction::ProcessRETTO(CodeGenerator* code_gen){
+void FF7::FF7ControlFlowInstruction::ProcessRETTO(CodeGenerator* code_gen){
     auto entity_index = _params[0]->getUnsigned();
     auto entity_index = _params[0]->getUnsigned();
     auto priority = _params[1]->getUnsigned();
     auto priority = _params[1]->getUnsigned();
     code_gen->AddOutputLine((
     code_gen->AddOutputLine((
@@ -115,9 +118,8 @@ void FieldControlFlowInstruction::ProcessRETTO(CodeGenerator* code_gen){
     ).str());
     ).str());
 }
 }
 
 
-void FieldControlFlowInstruction::ProcessWAIT(CodeGenerator* code_gen){
+void FF7::FF7ControlFlowInstruction::ProcessWAIT(CodeGenerator* code_gen){
     code_gen->AddOutputLine((
     code_gen->AddOutputLine((
       boost::format("script:wait(%1%)") % (_params[0]->getUnsigned() / 30.0f)
       boost::format("script:wait(%1%)") % (_params[0]->getUnsigned() / 30.0f)
     ).str());
     ).str());
 }
 }
-

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

@@ -16,55 +16,58 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
 #include "decompiler/field/instruction/FieldMathInstruction.h"
 #include "decompiler/field/instruction/FieldMathInstruction.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldDisassembler.h"
 #include "decompiler/field/FieldDisassembler.h"
 
 
-void FieldMathInstruction::ProcessInst(
+void FF7::FieldMathInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
 ){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FunctionMetaData md(func._metadata);
     FunctionMetaData md(func._metadata);
     switch (_opcode){
     switch (_opcode){
-        case OPCODE::PLUS_: ProcessSaturatedPLUS(code_gen); break;
-        case OPCODE::PLUS2_: ProcessSaturatedPLUS2(code_gen); break;
-        case OPCODE::MINUS_: ProcessSaturatedMINUS(code_gen); break;
-        case OPCODE::MINUS2_: ProcessSaturatedMINUS2(code_gen); break;
-        case OPCODE::INC_: ProcessSaturatedINC(code_gen); break;
-        case OPCODE::INC2_: ProcessSaturatedINC2(code_gen); break;
-        case OPCODE::DEC_: ProcessSaturatedDEC(code_gen); break;
-        case OPCODE::DEC2_: ProcessSaturatedDEC2(code_gen); break;
-        case OPCODE::RDMSD: ProcessRDMSD(code_gen); break;
-        case OPCODE::SETBYTE:
-        case OPCODE::SETWORD:
+        case OPCODES::PLUS_: ProcessSaturatedPLUS(code_gen); break;
+        case OPCODES::PLUS2_: ProcessSaturatedPLUS2(code_gen); break;
+        case OPCODES::MINUS_: ProcessSaturatedMINUS(code_gen); break;
+        case OPCODES::MINUS2_: ProcessSaturatedMINUS2(code_gen); break;
+        case OPCODES::INC_: ProcessSaturatedINC(code_gen); break;
+        case OPCODES::INC2_: ProcessSaturatedINC2(code_gen); break;
+        case OPCODES::DEC_: ProcessSaturatedDEC(code_gen); break;
+        case OPCODES::DEC2_: ProcessSaturatedDEC2(code_gen); break;
+        case OPCODES::RDMSD: ProcessRDMSD(code_gen); break;
+        case OPCODES::SETBYTE:
+        case OPCODES::SETWORD:
             ProcessSETBYTE_SETWORD(code_gen);
             ProcessSETBYTE_SETWORD(code_gen);
             break;
             break;
-        case OPCODE::BITON: ProcessBITON(code_gen); break;
-        case OPCODE::BITOFF: ProcessBITOFF(code_gen); break;
-        case OPCODE::BITXOR: WriteTodo(code_gen, md.GetEntityName(), "BITXOR"); break;
-        case OPCODE::PLUS:
-        case OPCODE::PLUS2:
+        case OPCODES::BITON: ProcessBITON(code_gen); break;
+        case OPCODES::BITOFF: ProcessBITOFF(code_gen); break;
+        case OPCODES::BITXOR: code_gen->WriteTodo(md.GetEntityName(), "BITXOR"); break;
+        case OPCODES::PLUS:
+        case OPCODES::PLUS2:
             ProcessPLUSx_MINUSx(code_gen, "+");
             ProcessPLUSx_MINUSx(code_gen, "+");
             break;
             break;
-        case OPCODE::MINUS:
-        case OPCODE::MINUS2:
+        case OPCODES::MINUS:
+        case OPCODES::MINUS2:
             ProcessPLUSx_MINUSx(code_gen, "-");
             ProcessPLUSx_MINUSx(code_gen, "-");
             break;
             break;
-        case OPCODE::MUL: WriteTodo(code_gen, md.GetEntityName(), "MUL"); break;
-        case OPCODE::MUL2: WriteTodo(code_gen, md.GetEntityName(), "MUL2"); break;
-        case OPCODE::DIV: WriteTodo(code_gen, md.GetEntityName(), "DIV"); break;
-        case OPCODE::DIV2: WriteTodo(code_gen, md.GetEntityName(), "DIV2"); break;
-        case OPCODE::MOD:
+        case OPCODES::MUL: code_gen->WriteTodo(md.GetEntityName(), "MUL"); break;
+        case OPCODES::MUL2: code_gen->WriteTodo(md.GetEntityName(), "MUL2"); break;
+        case OPCODES::DIV: code_gen->WriteTodo(md.GetEntityName(), "DIV"); break;
+        case OPCODES::DIV2: code_gen->WriteTodo(md.GetEntityName(), "DIV2"); break;
+        case OPCODES::MOD:
             {
             {
                 const uint32 source_bank = _params[0]->getUnsigned();
                 const uint32 source_bank = _params[0]->getUnsigned();
                 const uint32 source_address_or_value = _params[2]->getUnsigned();
                 const uint32 source_address_or_value = _params[2]->getUnsigned();
-                auto source = FieldCodeGenerator::FormatValueOrVariable(
+                auto source = FF7::FieldCodeGenerator::FormatValueOrVariable(
                   cg->GetFormatter(), source_bank, source_address_or_value
                   cg->GetFormatter(), source_bank, source_address_or_value
                 );
                 );
                 const uint32 dest_bank = _params[1]->getUnsigned();
                 const uint32 dest_bank = _params[1]->getUnsigned();
                 const uint32 dest_address = _params[3]->getUnsigned();
                 const uint32 dest_address = _params[3]->getUnsigned();
-                auto dest = FieldCodeGenerator::FormatValueOrVariable(
+                auto dest = FF7::FieldCodeGenerator::FormatValueOrVariable(
                   cg->GetFormatter(), dest_bank, dest_address
                   cg->GetFormatter(), dest_bank, dest_address
                 );
                 );
                 code_gen->AddOutputLine(
                 code_gen->AddOutputLine(
@@ -72,41 +75,41 @@ void FieldMathInstruction::ProcessInst(
                 );
                 );
             }
             }
         break;
         break;
-        case OPCODE::MOD2: WriteTodo(code_gen, md.GetEntityName(), "MOD2"); break;
-        case OPCODE::AND: WriteTodo(code_gen, md.GetEntityName(), "AND"); break;
-        case OPCODE::AND2: WriteTodo(code_gen, md.GetEntityName(), "AND2"); break;
-        case OPCODE::OR: WriteTodo(code_gen, md.GetEntityName(), "OR"); break;
-        case OPCODE::OR2: WriteTodo(code_gen, md.GetEntityName(), "OR2"); break;
-        case OPCODE::XOR: WriteTodo(code_gen, md.GetEntityName(), "XOR"); break;
-        case OPCODE::XOR2: WriteTodo(code_gen, md.GetEntityName(), "XOR2"); break;
-        case OPCODE::INC:
-        case OPCODE::INC2:
+        case OPCODES::MOD2: code_gen->WriteTodo(md.GetEntityName(), "MOD2"); break;
+        case OPCODES::AND: code_gen->WriteTodo(md.GetEntityName(), "AND"); break;
+        case OPCODES::AND2: code_gen->WriteTodo(md.GetEntityName(), "AND2"); break;
+        case OPCODES::OR: code_gen->WriteTodo(md.GetEntityName(), "OR"); break;
+        case OPCODES::OR2: code_gen->WriteTodo(md.GetEntityName(), "OR2"); break;
+        case OPCODES::XOR: code_gen->WriteTodo(md.GetEntityName(), "XOR"); break;
+        case OPCODES::XOR2: code_gen->WriteTodo(md.GetEntityName(), "XOR2"); break;
+        case OPCODES::INC:
+        case OPCODES::INC2:
             ProcessINCx_DECx(code_gen, "+");
             ProcessINCx_DECx(code_gen, "+");
             break;
             break;
-        case OPCODE::DEC:
-        case OPCODE::DEC2:
+        case OPCODES::DEC:
+        case OPCODES::DEC2:
             ProcessINCx_DECx(code_gen, "-");
             ProcessINCx_DECx(code_gen, "-");
             break;
             break;
-        case OPCODE::RANDOM: ProcessRANDOM(code_gen); break;
-        case OPCODE::LBYTE: WriteTodo(code_gen, md.GetEntityName(), "LBYTE"); break;
-        case OPCODE::HBYTE: WriteTodo(code_gen, md.GetEntityName(), "HBYTE"); break;
-        case OPCODE::TWOBYTE: WriteTodo(code_gen, md.GetEntityName(), "2BYTE"); break;
-        case OPCODE::SIN: WriteTodo(code_gen, md.GetEntityName(), "SIN"); break;
-        case OPCODE::COS: WriteTodo(code_gen, md.GetEntityName(), "COS"); break;
+        case OPCODES::RANDOM: ProcessRANDOM(code_gen); break;
+        case OPCODES::LBYTE: code_gen->WriteTodo(md.GetEntityName(), "LBYTE"); break;
+        case OPCODES::HBYTE: code_gen->WriteTodo(md.GetEntityName(), "HBYTE"); break;
+        case OPCODES::TWOBYTE: code_gen->WriteTodo(md.GetEntityName(), "2BYTE"); break;
+        case OPCODES::SIN: code_gen->WriteTodo(md.GetEntityName(), "SIN"); break;
+        case OPCODES::COS: code_gen->WriteTodo(md.GetEntityName(), "COS"); break;
         default:
         default:
-            code_gen->AddOutputLine(FieldCodeGenerator::FormatInstructionNotImplemented(
+            code_gen->AddOutputLine(FF7::FieldCodeGenerator::FormatInstructionNotImplemented(
               md.GetEntityName(), _address, _opcode
               md.GetEntityName(), _address, _opcode
             ));
             ));
     }
     }
 }
 }
 
 
-void FieldMathInstruction::ProcessSaturatedPLUS(CodeGenerator* code_gen){
+void FF7::FieldMathInstruction::ProcessSaturatedPLUS(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     // TODO: Check for assignment to value.
     // TODO: Check for assignment to value.
-    const auto& lhs = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& lhs = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
     );
     );
-    const auto& rhs = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& rhs = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
     );
     );
     // TODO: Respect destination bank sizes and negative wrap-around.
     // TODO: Respect destination bank sizes and negative wrap-around.
@@ -114,13 +117,13 @@ void FieldMathInstruction::ProcessSaturatedPLUS(CodeGenerator* code_gen){
     code_gen->AddOutputLine((boost::format("--if (%1% > 255); %1% = 255; end") % lhs).str());
     code_gen->AddOutputLine((boost::format("--if (%1% > 255); %1% = 255; end") % lhs).str());
 }
 }
 
 
-void FieldMathInstruction::ProcessSaturatedPLUS2(CodeGenerator* code_gen){
+void FF7::FieldMathInstruction::ProcessSaturatedPLUS2(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     // TODO: Check for assignment to value.
     // TODO: Check for assignment to value.
-    const auto& lhs = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& lhs = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
     );
     );
-    const auto& rhs = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& rhs = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
     );
     );
     // TODO: Respect destination bank sizes and negative wrap-around.
     // TODO: Respect destination bank sizes and negative wrap-around.
@@ -128,13 +131,13 @@ void FieldMathInstruction::ProcessSaturatedPLUS2(CodeGenerator* code_gen){
     code_gen->AddOutputLine((boost::format("--if (%1% > 32767); %1% = 32767; end") % lhs).str());
     code_gen->AddOutputLine((boost::format("--if (%1% > 32767); %1% = 32767; end") % lhs).str());
 }
 }
 
 
-void FieldMathInstruction::ProcessSaturatedMINUS(CodeGenerator* code_gen){
+void FF7::FieldMathInstruction::ProcessSaturatedMINUS(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     // TODO: Check for assignment to value.
     // TODO: Check for assignment to value.
-    const auto& lhs = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& lhs = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
     );
     );
-    const auto& rhs = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& rhs = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
     );
     );
     // TODO: Respect destination bank sizes and positive wrap-around.
     // TODO: Respect destination bank sizes and positive wrap-around.
@@ -142,13 +145,13 @@ void FieldMathInstruction::ProcessSaturatedMINUS(CodeGenerator* code_gen){
     code_gen->AddOutputLine((boost::format("--if (%1% < 0); %1% = 0; end") % lhs).str());
     code_gen->AddOutputLine((boost::format("--if (%1% < 0); %1% = 0; end") % lhs).str());
 }
 }
 
 
-void FieldMathInstruction::ProcessSaturatedMINUS2(CodeGenerator* code_gen){
+void FF7::FieldMathInstruction::ProcessSaturatedMINUS2(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     // TODO: Check for assignment to value.
     // TODO: Check for assignment to value.
-    const auto& lhs = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& lhs = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
     );
     );
-    const auto& rhs = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& rhs = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
     );
     );
     // TODO: Respect destination bank sizes and positive wrap-around.
     // TODO: Respect destination bank sizes and positive wrap-around.
@@ -156,10 +159,10 @@ void FieldMathInstruction::ProcessSaturatedMINUS2(CodeGenerator* code_gen){
     code_gen->AddOutputLine((boost::format("--if (%1% < 0); %1% = 0; end") % lhs).str());
     code_gen->AddOutputLine((boost::format("--if (%1% < 0); %1% = 0; end") % lhs).str());
 }
 }
 
 
-void FieldMathInstruction::ProcessSaturatedINC(CodeGenerator* code_gen){
+void FF7::FieldMathInstruction::ProcessSaturatedINC(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     // TODO: Check for assignment to value.
     // TODO: Check for assignment to value.
-    const auto& dest = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& dest = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[1]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[1]->getUnsigned()
     );
     );
     // TODO: Respect destination bank sizes and negative wrap-around.
     // TODO: Respect destination bank sizes and negative wrap-around.
@@ -167,10 +170,10 @@ void FieldMathInstruction::ProcessSaturatedINC(CodeGenerator* code_gen){
     code_gen->AddOutputLine((boost::format("--if (%1% > 255); %1% = 255; end") % dest).str());
     code_gen->AddOutputLine((boost::format("--if (%1% > 255); %1% = 255; end") % dest).str());
 }
 }
 
 
-void FieldMathInstruction::ProcessSaturatedINC2(CodeGenerator* code_gen){
+void FF7::FieldMathInstruction::ProcessSaturatedINC2(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     // TODO: Check for assignment to value.
     // TODO: Check for assignment to value.
-    const auto& dest = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& dest = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[1]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[1]->getUnsigned()
     );
     );
     // TODO: Respect destination bank sizes and negative wrap-around.
     // TODO: Respect destination bank sizes and negative wrap-around.
@@ -178,10 +181,10 @@ void FieldMathInstruction::ProcessSaturatedINC2(CodeGenerator* code_gen){
     code_gen->AddOutputLine((boost::format("--if (%1% > 32767); %1% = 32767; end") % dest).str());
     code_gen->AddOutputLine((boost::format("--if (%1% > 32767); %1% = 32767; end") % dest).str());
 }
 }
 
 
-void FieldMathInstruction::ProcessSaturatedDEC(CodeGenerator* code_gen){
+void FF7::FieldMathInstruction::ProcessSaturatedDEC(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     // TODO: Check for assignment to value.
     // TODO: Check for assignment to value.
-    const auto& dest = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& dest = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[1]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[1]->getUnsigned()
     );
     );
     // TODO: Respect destination bank sizes and positive wrap-around.
     // TODO: Respect destination bank sizes and positive wrap-around.
@@ -189,10 +192,10 @@ void FieldMathInstruction::ProcessSaturatedDEC(CodeGenerator* code_gen){
     code_gen->AddOutputLine((boost::format("--if (%1% < 0); %1% = 0; end") % dest).str());
     code_gen->AddOutputLine((boost::format("--if (%1% < 0); %1% = 0; end") % dest).str());
 }
 }
 
 
-void FieldMathInstruction::ProcessSaturatedDEC2(CodeGenerator* code_gen){
+void FF7::FieldMathInstruction::ProcessSaturatedDEC2(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     // TODO: Check for assignment to value.
     // TODO: Check for assignment to value.
-    const auto& dest = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& dest = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[1]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[1]->getUnsigned()
     );
     );
     // TODO: Respect destination bank sizes and positive wrap-around.
     // TODO: Respect destination bank sizes and positive wrap-around.
@@ -200,64 +203,64 @@ void FieldMathInstruction::ProcessSaturatedDEC2(CodeGenerator* code_gen){
     code_gen->AddOutputLine((boost::format("--if (%1% < 0); %1% = 0; end") % dest).str());
     code_gen->AddOutputLine((boost::format("--if (%1% < 0); %1% = 0; end") % dest).str());
 }
 }
 
 
-void FieldMathInstruction::ProcessRDMSD(CodeGenerator* code_gen){
+void FF7::FieldMathInstruction::ProcessRDMSD(CodeGenerator* code_gen){
     // TODO: we don't have os.time...
     // TODO: we don't have os.time...
     // TODO: RNG emulation?
     // TODO: RNG emulation?
     code_gen->AddOutputLine("math.randomseed(os.time())");
     code_gen->AddOutputLine("math.randomseed(os.time())");
 }
 }
 
 
-void FieldMathInstruction::ProcessSETBYTE_SETWORD(CodeGenerator* code_gen){
+void FF7::FieldMathInstruction::ProcessSETBYTE_SETWORD(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     // TODO: Check for assignment to value.
     // TODO: Check for assignment to value.
-    const auto& destination = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& destination = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
     );
     );
-    const auto& source = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& source = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
     );
     );
     // TODO: respect destination bank sizes (16-bit writes only affect low byte)
     // TODO: respect destination bank sizes (16-bit writes only affect low byte)
     code_gen->AddOutputLine((boost::format("%1% = %2%") % destination % source).str());
     code_gen->AddOutputLine((boost::format("%1% = %2%") % destination % source).str());
 }
 }
 
 
-void FieldMathInstruction::ProcessBITON(CodeGenerator* code_gen){
+void FF7::FieldMathInstruction::ProcessBITON(CodeGenerator* code_gen){
     code_gen->AddOutputLine((boost::format("bit_on(%1%, %2%, %3%)")
     code_gen->AddOutputLine((boost::format("bit_on(%1%, %2%, %3%)")
       % _params[0]->getUnsigned() % _params[2]->getUnsigned() % _params[3]->getUnsigned()
       % _params[0]->getUnsigned() % _params[2]->getUnsigned() % _params[3]->getUnsigned()
     ).str());
     ).str());
 }
 }
 
 
-void FieldMathInstruction::ProcessBITOFF(CodeGenerator* code_gen){
+void FF7::FieldMathInstruction::ProcessBITOFF(CodeGenerator* code_gen){
     code_gen->AddOutputLine((boost::format("bit_off(%1%, %2%, %3%)")
     code_gen->AddOutputLine((boost::format("bit_off(%1%, %2%, %3%)")
       % _params[0]->getUnsigned() % _params[2]->getUnsigned() % _params[3]->getUnsigned()
       % _params[0]->getUnsigned() % _params[2]->getUnsigned() % _params[3]->getUnsigned()
     ).str());
     ).str());
 }
 }
 
 
-void FieldMathInstruction::ProcessPLUSx_MINUSx(CodeGenerator* code_gen, const std::string& op){
+void FF7::FieldMathInstruction::ProcessPLUSx_MINUSx(CodeGenerator* code_gen, const std::string& op){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     // TODO: Check for assignment to value.
     // TODO: Check for assignment to value.
-    const auto& lhs = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& lhs = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
     );
     );
-    const auto& rhs = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& rhs = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
     );
     );
     // TODO: repect destination bank sizes and wraparound
     // TODO: repect destination bank sizes and wraparound
     code_gen->AddOutputLine((boost::format("%1% = %1% %2% %3%") % lhs % op % rhs).str());
     code_gen->AddOutputLine((boost::format("%1% = %1% %2% %3%") % lhs % op % rhs).str());
 }
 }
 
 
-void FieldMathInstruction::ProcessINCx_DECx(CodeGenerator* code_gen, const std::string& op){
+void FF7::FieldMathInstruction::ProcessINCx_DECx(CodeGenerator* code_gen, const std::string& op){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     // TODO: Check for assignment to value.
     // TODO: Check for assignment to value.
-    const auto& destination = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& destination = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[1]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[1]->getUnsigned()
     );
     );
     // TODO: repect destination bank sizes and wraparound
     // TODO: repect destination bank sizes and wraparound
     code_gen->AddOutputLine((boost::format("%1% = %1% %2% 1") % destination % op).str());
     code_gen->AddOutputLine((boost::format("%1% = %1% %2% 1") % destination % op).str());
 }
 }
 
 
-void FieldMathInstruction::ProcessRANDOM(CodeGenerator* code_gen){
+void FF7::FieldMathInstruction::ProcessRANDOM(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     // TODO: Check for assignment to value.
     // TODO: Check for assignment to value.
-    const auto& destination = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& destination = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[1]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[1]->getUnsigned()
     );
     );
     // TODO: Respect destination bank sizes (16-bit writes only affect low byte).
     // TODO: Respect destination bank sizes (16-bit writes only affect low byte).

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

@@ -16,54 +16,57 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
 #include "decompiler/field/instruction/FieldMediaInstruction.h"
 #include "decompiler/field/instruction/FieldMediaInstruction.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldDisassembler.h"
 #include "decompiler/field/FieldDisassembler.h"
 
 
-void FieldMediaInstruction::ProcessInst(
+void FF7::FieldMediaInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
 ){
     FunctionMetaData md(func._metadata);
     FunctionMetaData md(func._metadata);
     switch (_opcode){
     switch (_opcode){
-        case OPCODE::BGMOVIE: WriteTodo(code_gen, md.GetEntityName(), "BGMOVIE"); break;
-        case OPCODE::AKAO2: ProcessAKAO2(code_gen); break;
-        case OPCODE::MUSIC: ProcessMUSIC(code_gen); break;
-        case OPCODE::SOUND: ProcessSOUND(code_gen); break;
-        case OPCODE::AKAO: ProcessAKAO(code_gen); break;
-        case OPCODE::MUSVT: WriteTodo(code_gen, md.GetEntityName(), "MUSVT"); break;
-        case OPCODE::MUSVM: WriteTodo(code_gen, md.GetEntityName(), "MUSVM"); break;
-        case OPCODE::MULCK: ProcessMULCK(code_gen); break;
-        case OPCODE::BMUSC: WriteTodo(code_gen, md.GetEntityName(), "BMUSC"); break;
-        case OPCODE::CHMPH: WriteTodo(code_gen, md.GetEntityName(), "CHMPH"); break;
-        case OPCODE::PMVIE: ProcessPMVIE(code_gen); break;
-        case OPCODE::MOVIE: ProcessMOVIE(code_gen); break;
-        case OPCODE::MVIEF: ProcessMVIEF(code_gen); break;
-        case OPCODE::FMUSC: WriteTodo(code_gen, md.GetEntityName(), "FMUSC"); break;
-        case OPCODE::CMUSC: WriteTodo(code_gen, md.GetEntityName(), "CMUSC"); break;
-        case OPCODE::CHMST: WriteTodo(code_gen, md.GetEntityName(), "CHMST"); break;
+        case OPCODES::BGMOVIE: code_gen->WriteTodo(md.GetEntityName(), "BGMOVIE"); break;
+        case OPCODES::AKAO2: ProcessAKAO2(code_gen); break;
+        case OPCODES::MUSIC: ProcessMUSIC(code_gen); break;
+        case OPCODES::SOUND: ProcessSOUND(code_gen); break;
+        case OPCODES::AKAO: ProcessAKAO(code_gen); break;
+        case OPCODES::MUSVT: code_gen->WriteTodo(md.GetEntityName(), "MUSVT"); break;
+        case OPCODES::MUSVM: code_gen->WriteTodo(md.GetEntityName(), "MUSVM"); break;
+        case OPCODES::MULCK: ProcessMULCK(code_gen); break;
+        case OPCODES::BMUSC: code_gen->WriteTodo(md.GetEntityName(), "BMUSC"); break;
+        case OPCODES::CHMPH: code_gen->WriteTodo(md.GetEntityName(), "CHMPH"); break;
+        case OPCODES::PMVIE: ProcessPMVIE(code_gen); break;
+        case OPCODES::MOVIE: ProcessMOVIE(code_gen); break;
+        case OPCODES::MVIEF: ProcessMVIEF(code_gen); break;
+        case OPCODES::FMUSC: code_gen->WriteTodo(md.GetEntityName(), "FMUSC"); break;
+        case OPCODES::CMUSC: code_gen->WriteTodo(md.GetEntityName(), "CMUSC"); break;
+        case OPCODES::CHMST: code_gen->WriteTodo(md.GetEntityName(), "CHMST"); break;
         default:
         default:
-            code_gen->AddOutputLine(FieldCodeGenerator::FormatInstructionNotImplemented(
+            code_gen->AddOutputLine(FF7::FieldCodeGenerator::FormatInstructionNotImplemented(
               md.GetEntityName(), _address, _opcode
               md.GetEntityName(), _address, _opcode
             ));
             ));
     }
     }
 }
 }
 
 
-void FieldMediaInstruction::ProcessAKAO2(CodeGenerator* code_gen){
+void FF7::FieldMediaInstruction::ProcessAKAO2(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
-    const auto& param1 = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& param1 = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[7]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[7]->getUnsigned()
     );
     );
-    const auto& param2 = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& param2 = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[8]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[8]->getUnsigned()
     );
     );
-    const auto& param3 = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& param3 = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[9]->getUnsigned()
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[9]->getUnsigned()
     );
     );
-    const auto& param4 = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& param4 = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[10]->getUnsigned()
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[10]->getUnsigned()
     );
     );
-    const auto& param5 = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& param5 = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[5]->getUnsigned(), _params[11]->getUnsigned()
       cg->GetFormatter(), _params[5]->getUnsigned(), _params[11]->getUnsigned()
     );
     );
     auto op = _params[6]->getUnsigned();
     auto op = _params[6]->getUnsigned();
@@ -73,19 +76,19 @@ void FieldMediaInstruction::ProcessAKAO2(CodeGenerator* code_gen){
     ).str());
     ).str());
 }
 }
 
 
-void FieldMediaInstruction::ProcessMUSIC(CodeGenerator* code_gen){
+void FF7::FieldMediaInstruction::ProcessMUSIC(CodeGenerator* code_gen){
     code_gen->AddOutputLine((
     code_gen->AddOutputLine((
       boost::format("-- music:execute_akao(0x10, pointer_to_field_AKAO_%1%)")
       boost::format("-- music:execute_akao(0x10, pointer_to_field_AKAO_%1%)")
       % _params[0]->getUnsigned()
       % _params[0]->getUnsigned()
     ).str());
     ).str());
 }
 }
 
 
-void FieldMediaInstruction::ProcessSOUND(CodeGenerator* code_gen){
+void FF7::FieldMediaInstruction::ProcessSOUND(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
-    const auto& soundId = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& soundId = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
     );
     );
-    const auto& panning = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& panning = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
     );
     );
     code_gen->AddOutputLine(
     code_gen->AddOutputLine(
@@ -93,21 +96,21 @@ void FieldMediaInstruction::ProcessSOUND(CodeGenerator* code_gen){
     );
     );
 }
 }
 
 
-void FieldMediaInstruction::ProcessAKAO(CodeGenerator* code_gen){
+void FF7::FieldMediaInstruction::ProcessAKAO(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
-    const auto& param1 = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& param1 = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[7]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[7]->getUnsigned()
     );
     );
-    const auto& param2 = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& param2 = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[8]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[8]->getUnsigned()
     );
     );
-    const auto& param3 = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& param3 = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[9]->getUnsigned()
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[9]->getUnsigned()
     );
     );
-    const auto& param4 = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& param4 = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[10]->getUnsigned()
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[10]->getUnsigned()
     );
     );
-    const auto& param5 = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& param5 = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[5]->getUnsigned(), _params[11]->getUnsigned()
       cg->GetFormatter(), _params[5]->getUnsigned(), _params[11]->getUnsigned()
     );
     );
     auto op = _params[6]->getUnsigned();
     auto op = _params[6]->getUnsigned();
@@ -117,27 +120,27 @@ void FieldMediaInstruction::ProcessAKAO(CodeGenerator* code_gen){
     ).str());
     ).str());
 }
 }
 
 
-void FieldMediaInstruction::ProcessMULCK(CodeGenerator* code_gen){
+void FF7::FieldMediaInstruction::ProcessMULCK(CodeGenerator* code_gen){
     code_gen->AddOutputLine((
     code_gen->AddOutputLine((
       boost::format("-- music:lock(%1%)")
       boost::format("-- music:lock(%1%)")
-      % FieldCodeGenerator::FormatBool(_params[0]->getUnsigned())
+      % FF7::FieldCodeGenerator::FormatBool(_params[0]->getUnsigned())
     ).str());
     ).str());
 }
 }
 
 
-void FieldMediaInstruction::ProcessPMVIE(CodeGenerator* code_gen){
+void FF7::FieldMediaInstruction::ProcessPMVIE(CodeGenerator* code_gen){
     code_gen->AddOutputLine(
     code_gen->AddOutputLine(
       (boost::format("-- field:movie_set(%1%)") % _params[0]->getUnsigned()
       (boost::format("-- field:movie_set(%1%)") % _params[0]->getUnsigned()
     ).str());
     ).str());
 }
 }
 
 
-void FieldMediaInstruction::ProcessMOVIE(CodeGenerator* code_gen){
+void FF7::FieldMediaInstruction::ProcessMOVIE(CodeGenerator* code_gen){
     code_gen->AddOutputLine("-- field:play_movie()");
     code_gen->AddOutputLine("-- field:play_movie()");
 }
 }
 
 
-void FieldMediaInstruction::ProcessMVIEF(CodeGenerator* code_gen){
+void FF7::FieldMediaInstruction::ProcessMVIEF(CodeGenerator* code_gen){
     // TODO: Check for assignment to value.
     // TODO: Check for assignment to value.
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
-    const auto& destination = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& destination = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[2]->getUnsigned());
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[2]->getUnsigned());
     code_gen->AddOutputLine(
     code_gen->AddOutputLine(
       (boost::format("-- %1% = field:get_movie_frame()") % destination).str()
       (boost::format("-- %1% = field:get_movie_frame()") % destination).str()

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

@@ -16,156 +16,167 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
 #include "decompiler/field/instruction/FieldModelInstruction.h"
 #include "decompiler/field/instruction/FieldModelInstruction.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldDisassembler.h"
 #include "decompiler/field/FieldDisassembler.h"
 
 
-void FieldModelInstruction::ProcessInst(
+void FF7::FieldModelInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
 ){
-    FieldEngine& eng = static_cast<FieldEngine&>(*engine);
+    FF7::FieldEngine& eng = static_cast<FF7::FieldEngine&>(*engine);
     FunctionMetaData md(func._metadata);
     FunctionMetaData md(func._metadata);
     switch (_opcode){
     switch (_opcode){
-        case OPCODE::JOIN: ProcessJOIN(code_gen); break;
-        case OPCODE::SPLIT: ProcessSPLIT(code_gen); break;
-        case OPCODE::BLINK: WriteTodo(code_gen, md.GetEntityName(), "BLINK"); break;
-        case (OPCODE::KAWAI << 8) | OPCODE_KAWAI::EYETX:
-            WriteTodo(code_gen, md.GetEntityName(), "EYETX");
+        case OPCODES::JOIN: ProcessJOIN(code_gen); break;
+        case OPCODES::SPLIT: ProcessSPLIT(code_gen); break;
+        case OPCODES::BLINK: code_gen->WriteTodo(md.GetEntityName(), "BLINK"); break;
+        case (OPCODES::KAWAI << 8) | OPCODES_KAWAI::EYETX:
+            code_gen->WriteTodo(md.GetEntityName(), "EYETX");
             break;
             break;
-        case (OPCODE::KAWAI << 8) | OPCODE_KAWAI::TRNSP:
-            WriteTodo(code_gen, md.GetEntityName(), "TRNSP");
+        case (OPCODES::KAWAI << 8) | OPCODES_KAWAI::TRNSP:
+            code_gen->WriteTodo(md.GetEntityName(), "TRNSP");
             break;
             break;
-        case (OPCODE::KAWAI << 8) | OPCODE_KAWAI::AMBNT:
-            WriteTodo(code_gen, md.GetEntityName(), "AMBNT");
+        case (OPCODES::KAWAI << 8) | OPCODES_KAWAI::AMBNT:
+            code_gen->WriteTodo(md.GetEntityName(), "AMBNT");
             break;
             break;
-        case (OPCODE::KAWAI << 8) | OPCODE_KAWAI::Unknown03:
-            WriteTodo(code_gen, md.GetEntityName(), "Unknown03");
+        case (OPCODES::KAWAI << 8) | OPCODES_KAWAI::Unknown03:
+            code_gen->WriteTodo(md.GetEntityName(), "Unknown03");
             break;
             break;
-        case (OPCODE::KAWAI << 8) | OPCODE_KAWAI::Unknown04:
-            WriteTodo(code_gen, md.GetEntityName(), "Unknown04");
+        case (OPCODES::KAWAI << 8) | OPCODES_KAWAI::Unknown04:
+            code_gen->WriteTodo(md.GetEntityName(), "Unknown04");
             break;
             break;
-        case (OPCODE::KAWAI << 8) | OPCODE_KAWAI::Unknown05:
-            WriteTodo(code_gen, md.GetEntityName(), "Unknown05");
+        case (OPCODES::KAWAI << 8) | OPCODES_KAWAI::Unknown05:
+            code_gen->WriteTodo(md.GetEntityName(), "Unknown05");
             break;
             break;
-        case (OPCODE::KAWAI << 8) | OPCODE_KAWAI::LIGHT:
-            WriteTodo(code_gen, md.GetEntityName(), "LIGHT");
+        case (OPCODES::KAWAI << 8) | OPCODES_KAWAI::LIGHT:
+            code_gen->WriteTodo(md.GetEntityName(), "LIGHT");
             break;
             break;
-        case (OPCODE::KAWAI << 8) | OPCODE_KAWAI::Unknown07:
-            WriteTodo(code_gen, md.GetEntityName(), "Unknown07");
+        case (OPCODES::KAWAI << 8) | OPCODES_KAWAI::Unknown07:
+            code_gen->WriteTodo(md.GetEntityName(), "Unknown07");
             break;
             break;
-        case (OPCODE::KAWAI << 8) | OPCODE_KAWAI::Unknown08:
-            WriteTodo(code_gen, md.GetEntityName(), "Unknown08");
+        case (OPCODES::KAWAI << 8) | OPCODES_KAWAI::Unknown08:
+            code_gen->WriteTodo(md.GetEntityName(), "Unknown08");
             break;
             break;
-        case (OPCODE::KAWAI << 8) | OPCODE_KAWAI::Unknown09:
-            WriteTodo(code_gen, md.GetEntityName(), "Unknown09");
+        case (OPCODES::KAWAI << 8) | OPCODES_KAWAI::Unknown09:
+            code_gen->WriteTodo(md.GetEntityName(), "Unknown09");
             break;
             break;
-        case (OPCODE::KAWAI << 8) | OPCODE_KAWAI::SBOBJ:
-            WriteTodo(code_gen, md.GetEntityName(), "SBOBJ");
+        case (OPCODES::KAWAI << 8) | OPCODES_KAWAI::SBOBJ:
+            code_gen->WriteTodo(md.GetEntityName(), "SBOBJ");
             break;
             break;
-        case (OPCODE::KAWAI << 8) | OPCODE_KAWAI::Unknown0B:
-            WriteTodo(code_gen, md.GetEntityName(), "Unknown0B");
+        case (OPCODES::KAWAI << 8) | OPCODES_KAWAI::Unknown0B:
+            code_gen->WriteTodo(md.GetEntityName(), "Unknown0B");
             break;
             break;
-        case (OPCODE::KAWAI << 8) | OPCODE_KAWAI::Unknown0C:
-            WriteTodo(code_gen, md.GetEntityName(), "Unknown0C");
+        case (OPCODES::KAWAI << 8) | OPCODES_KAWAI::Unknown0C:
+            code_gen->WriteTodo(md.GetEntityName(), "Unknown0C");
             break;
             break;
-        case (OPCODE::KAWAI << 8) | OPCODE_KAWAI::SHINE:
-            WriteTodo(code_gen, md.GetEntityName(), "SHINE");
+        case (OPCODES::KAWAI << 8) | OPCODES_KAWAI::SHINE:
+            code_gen->WriteTodo(md.GetEntityName(), "SHINE");
             break;
             break;
-        case (OPCODE::KAWAI << 8) | OPCODE_KAWAI::RESET:
-            WriteTodo(code_gen, md.GetEntityName(), "RESET");
+        case (OPCODES::KAWAI << 8) | OPCODES_KAWAI::RESET:
+            code_gen->WriteTodo(md.GetEntityName(), "RESET");
             break;
             break;
-        case OPCODE::KAWIW: WriteTodo(code_gen, md.GetEntityName(), "KAWIW"); break;
-        case OPCODE::PMOVA: WriteTodo(code_gen, md.GetEntityName(), "PMOVA"); break;
-        case OPCODE::PDIRA: WriteTodo(code_gen, md.GetEntityName(), "PDIRA"); break;
-        case OPCODE::PTURA: WriteTodo(code_gen, md.GetEntityName(), "PTURA"); break;
-        case OPCODE::PGTDR: WriteTodo(code_gen, md.GetEntityName(), "PGTDR"); break;
-        case OPCODE::PXYZI: WriteTodo(code_gen, md.GetEntityName(), "PXYZI"); break;
-        case OPCODE::TLKON: ProcessTLKON(code_gen, md.GetEntityName()); break;
-        case OPCODE::PC: ProcessPC(code_gen, md.GetEntityName()); break;
-        case OPCODE::opCodeCHAR: ProcessCHAR(code_gen, md.GetEntityName()); break;
-        case OPCODE::DFANM: ProcessDFANM(code_gen, md.GetEntityName(), md.GetCharacterId()); break;
-        case OPCODE::ANIME1: ProcessANIME1(code_gen, md.GetEntityName(), md.GetCharacterId()); break;
-        case OPCODE::VISI: ProcessVISI(code_gen, md.GetEntityName()); break;
-        case OPCODE::XYZI: ProcessXYZI(code_gen, md.GetEntityName()); break;
-        case OPCODE::XYI: WriteTodo(code_gen, md.GetEntityName(), "XYI"); break;
-        case OPCODE::XYZ: WriteTodo(code_gen, md.GetEntityName(), "XYZ"); break;
-        case OPCODE::MOVE: ProcessMOVE(code_gen, md.GetEntityName()); break;
-        case OPCODE::CMOVE: WriteTodo(code_gen, md.GetEntityName(), "CMOVE"); break;
-        case OPCODE::MOVA: WriteTodo(code_gen, md.GetEntityName(), "MOVA"); break;
-        case OPCODE::TURA: WriteTodo(code_gen, md.GetEntityName(), "TURA"); break;
-        case OPCODE::ANIMW: WriteTodo(code_gen, md.GetEntityName(), "ANIMW"); break;
-        case OPCODE::FMOVE: WriteTodo(code_gen, md.GetEntityName(), "FMOVE"); break;
-        case OPCODE::ANIME2: WriteTodo(code_gen, md.GetEntityName(), "ANIME2"); break;
-        case OPCODE::ANIM_1: WriteTodo(code_gen, md.GetEntityName(), "ANIM_1"); break;
-        case OPCODE::CANIM1: WriteTodo(code_gen, md.GetEntityName(), "CANIM1"); break;
-        case OPCODE::CANM_1: WriteTodo(code_gen, md.GetEntityName(), "CANM_1"); break;
-        case OPCODE::MSPED: ProcessMSPED(code_gen, md.GetEntityName()); break;
-        case OPCODE::DIR: ProcessDIR(code_gen, md.GetEntityName()); break;
-        case OPCODE::TURNGEN: ProcessTURNGEN(code_gen, md.GetEntityName()); break;
-        case OPCODE::TURN: WriteTodo(code_gen, md.GetEntityName(), "TURN"); break;
-        case OPCODE::DIRA: WriteTodo(code_gen, md.GetEntityName(), "DIRA"); break;
-        case OPCODE::GETDIR: WriteTodo(code_gen, md.GetEntityName(), "GETDIR"); break;
-        case OPCODE::GETAXY: WriteTodo(code_gen, md.GetEntityName(), "GETAXY"); break;
-        case OPCODE::GETAI: ProcessGETAI(code_gen, eng); break;
-        case OPCODE::ANIM_2: ProcessANIM_2(code_gen, md.GetEntityName(), md.GetCharacterId()); break;
-        case OPCODE::CANIM2: ProcessCANIM2(code_gen, md.GetEntityName(), md.GetCharacterId()); break;
-        case OPCODE::CANM_2: ProcessCANM_2(code_gen, md.GetEntityName(), md.GetCharacterId()); break;
-        case OPCODE::ASPED: WriteTodo(code_gen, md.GetEntityName(), "ASPED"); break;
-        case OPCODE::CC: ProcessCC(code_gen, eng); break;
-        case OPCODE::JUMP: ProcessJUMP(code_gen, md.GetEntityName()); break;
-        case OPCODE::AXYZI: ProcessAXYZI(code_gen); break;
-        case OPCODE::LADER: ProcessLADER(code_gen, md.GetEntityName()); break;
-        case OPCODE::OFST: ProcessOFST(code_gen, md.GetEntityName()); break;
-        case OPCODE::OFSTW:
+        case OPCODES::KAWIW: code_gen->WriteTodo(md.GetEntityName(), "KAWIW"); break;
+        case OPCODES::PMOVA: code_gen->WriteTodo(md.GetEntityName(), "PMOVA"); break;
+        case OPCODES::PDIRA: code_gen->WriteTodo(md.GetEntityName(), "PDIRA"); break;
+        case OPCODES::PTURA: code_gen->WriteTodo(md.GetEntityName(), "PTURA"); break;
+        case OPCODES::PGTDR: code_gen->WriteTodo(md.GetEntityName(), "PGTDR"); break;
+        case OPCODES::PXYZI: code_gen->WriteTodo(md.GetEntityName(), "PXYZI"); break;
+        case OPCODES::TLKON: ProcessTLKON(code_gen, md.GetEntityName()); break;
+        case OPCODES::PC: ProcessPC(code_gen, md.GetEntityName()); break;
+        case OPCODES::opCodeCHAR: ProcessCHAR(code_gen, md.GetEntityName()); break;
+        case OPCODES::DFANM: ProcessDFANM(code_gen, md.GetEntityName(), md.GetCharacterId()); break;
+        case OPCODES::ANIME1:
+            ProcessANIME1(code_gen, md.GetEntityName(), md.GetCharacterId());
+            break;
+        case OPCODES::VISI: ProcessVISI(code_gen, md.GetEntityName()); break;
+        case OPCODES::XYZI: ProcessXYZI(code_gen, md.GetEntityName()); break;
+        case OPCODES::XYI: code_gen->WriteTodo(md.GetEntityName(), "XYI"); break;
+        case OPCODES::XYZ: code_gen->WriteTodo(md.GetEntityName(), "XYZ"); break;
+        case OPCODES::MOVE: ProcessMOVE(code_gen, md.GetEntityName()); break;
+        case OPCODES::CMOVE: code_gen->WriteTodo(md.GetEntityName(), "CMOVE"); break;
+        case OPCODES::MOVA: code_gen->WriteTodo(md.GetEntityName(), "MOVA"); break;
+        case OPCODES::TURA: code_gen->WriteTodo(md.GetEntityName(), "TURA"); break;
+        case OPCODES::ANIMW: code_gen->WriteTodo(md.GetEntityName(), "ANIMW"); break;
+        case OPCODES::FMOVE: code_gen->WriteTodo(md.GetEntityName(), "FMOVE"); break;
+        case OPCODES::ANIME2: code_gen->WriteTodo(md.GetEntityName(), "ANIME2"); break;
+        case OPCODES::ANIM_1: code_gen->WriteTodo(md.GetEntityName(), "ANIM_1"); break;
+        case OPCODES::CANIM1: code_gen->WriteTodo(md.GetEntityName(), "CANIM1"); break;
+        case OPCODES::CANM_1: code_gen->WriteTodo(md.GetEntityName(), "CANM_1"); break;
+        case OPCODES::MSPED: ProcessMSPED(code_gen, md.GetEntityName()); break;
+        case OPCODES::DIR: ProcessDIR(code_gen, md.GetEntityName()); break;
+        case OPCODES::TURNGEN: ProcessTURNGEN(code_gen, md.GetEntityName()); break;
+        case OPCODES::TURN: code_gen->WriteTodo(md.GetEntityName(), "TURN"); break;
+        case OPCODES::DIRA: code_gen->WriteTodo(md.GetEntityName(), "DIRA"); break;
+        case OPCODES::GETDIR: code_gen->WriteTodo(md.GetEntityName(), "GETDIR"); break;
+        case OPCODES::GETAXY: code_gen->WriteTodo(md.GetEntityName(), "GETAXY"); break;
+        case OPCODES::GETAI: ProcessGETAI(code_gen, eng); break;
+        case OPCODES::ANIM_2:
+            ProcessANIM_2(code_gen, md.GetEntityName(), md.GetCharacterId());
+            break;
+        case OPCODES::CANIM2:
+            ProcessCANIM2(code_gen, md.GetEntityName(), md.GetCharacterId());
+            break;
+        case OPCODES::CANM_2:
+            ProcessCANM_2(code_gen, md.GetEntityName(), md.GetCharacterId());
+            break;
+        case OPCODES::ASPED: code_gen->WriteTodo(md.GetEntityName(), "ASPED"); break;
+        case OPCODES::CC: ProcessCC(code_gen, eng); break;
+        case OPCODES::JUMP: ProcessJUMP(code_gen, md.GetEntityName()); break;
+        case OPCODES::AXYZI: ProcessAXYZI(code_gen); break;
+        case OPCODES::LADER: ProcessLADER(code_gen, md.GetEntityName()); break;
+        case OPCODES::OFST: ProcessOFST(code_gen, md.GetEntityName()); break;
+        case OPCODES::OFSTW:
             code_gen->AddOutputLine("self." + md.GetEntityName() + ":offset_sync()");
             code_gen->AddOutputLine("self." + md.GetEntityName() + ":offset_sync()");
             break;
             break;
-        case OPCODE::TALKR: WriteTodo(code_gen, md.GetEntityName(), "TALKR"); break;
-        case OPCODE::SLIDR: WriteTodo(code_gen, md.GetEntityName(), "SLIDR"); break;
-        case OPCODE::SOLID: ProcessSOLID(code_gen, md.GetEntityName()); break;
-        case OPCODE::TLKR2: WriteTodo(code_gen, md.GetEntityName(), "TLKR2"); break;
-        case OPCODE::SLDR2: WriteTodo(code_gen, md.GetEntityName(), "SLDR2"); break;
-        case OPCODE::CCANM: WriteTodo(code_gen, md.GetEntityName(), "CCANM"); break;
-        case OPCODE::FCFIX: WriteTodo(code_gen, md.GetEntityName(), "FCFIX"); break;
-        case OPCODE::ANIMB: WriteTodo(code_gen, md.GetEntityName(), "ANIMB"); break;
-        case OPCODE::TURNW: WriteTodo(code_gen, md.GetEntityName(), "TURNW"); break;
+        case OPCODES::TALKR: code_gen->WriteTodo(md.GetEntityName(), "TALKR"); break;
+        case OPCODES::SLIDR: code_gen->WriteTodo(md.GetEntityName(), "SLIDR"); break;
+        case OPCODES::SOLID: ProcessSOLID(code_gen, md.GetEntityName()); break;
+        case OPCODES::TLKR2: code_gen->WriteTodo(md.GetEntityName(), "TLKR2"); break;
+        case OPCODES::SLDR2: code_gen->WriteTodo(md.GetEntityName(), "SLDR2"); break;
+        case OPCODES::CCANM: code_gen->WriteTodo(md.GetEntityName(), "CCANM"); break;
+        case OPCODES::FCFIX: code_gen->WriteTodo(md.GetEntityName(), "FCFIX"); break;
+        case OPCODES::ANIMB: code_gen->WriteTodo(md.GetEntityName(), "ANIMB"); break;
+        case OPCODES::TURNW: code_gen->WriteTodo(md.GetEntityName(), "TURNW"); break;
         default:
         default:
-            code_gen->AddOutputLine(FieldCodeGenerator::FormatInstructionNotImplemented(
+            code_gen->AddOutputLine(FF7::FieldCodeGenerator::FormatInstructionNotImplemented(
               md.GetEntityName(), _address, _opcode
               md.GetEntityName(), _address, _opcode
             ));
             ));
     }
     }
 }
 }
 
 
-void FieldModelInstruction::ProcessJOIN(CodeGenerator* code_gen){
+void FF7::FieldModelInstruction::ProcessJOIN(CodeGenerator* code_gen){
     code_gen->AddOutputLine("join_party(" + std::to_string(_params[0]->getUnsigned()) + ")");
     code_gen->AddOutputLine("join_party(" + std::to_string(_params[0]->getUnsigned()) + ")");
 }
 }
 
 
-void FieldModelInstruction::ProcessSPLIT(CodeGenerator* code_gen){
+void FF7::FieldModelInstruction::ProcessSPLIT(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     const float scale = 128.0f * cg->GetScaleFactor();
     const float scale = 128.0f * cg->GetScaleFactor();
-    const auto& ax = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& ax = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[6]->getSigned(),
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[6]->getSigned(),
-      FieldCodeGenerator::ValueType::Float, scale
+      FF7::FieldCodeGenerator::ValueType::Float, scale
     );
     );
-    const auto& ay = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& ay = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[7]->getSigned(),
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[7]->getSigned(),
-      FieldCodeGenerator::ValueType::Float, scale
+      FF7::FieldCodeGenerator::ValueType::Float, scale
     );
     );
-    const auto& ar = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& ar = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[8]->getSigned(),
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[8]->getSigned(),
-      FieldCodeGenerator::ValueType::Float, scale
+      FF7::FieldCodeGenerator::ValueType::Float, scale
     );
     );
-    const auto& bx = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& bx = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[9]->getSigned(),
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[9]->getSigned(),
-      FieldCodeGenerator::ValueType::Float, scale
+      FF7::FieldCodeGenerator::ValueType::Float, scale
     );
     );
-    const auto& by = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& by = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[4]->getUnsigned(), _params[10]->getSigned(),
       cg->GetFormatter(), _params[4]->getUnsigned(), _params[10]->getSigned(),
-      FieldCodeGenerator::ValueType::Float, scale
+      FF7::FieldCodeGenerator::ValueType::Float, scale
     );
     );
-    const auto& br = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& br = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[5]->getUnsigned(), _params[11]->getSigned(),
       cg->GetFormatter(), _params[5]->getUnsigned(), _params[11]->getSigned(),
-      FieldCodeGenerator::ValueType::Float, scale
+      FF7::FieldCodeGenerator::ValueType::Float, scale
     );
     );
     const auto& speed = _params[12]->getUnsigned();
     const auto& speed = _params[12]->getUnsigned();
     code_gen->AddOutputLine((
     code_gen->AddOutputLine((
@@ -174,26 +185,26 @@ void FieldModelInstruction::ProcessSPLIT(CodeGenerator* code_gen){
     ).str());
     ).str());
 }
 }
 
 
-void FieldModelInstruction::ProcessTLKON(CodeGenerator* code_gen, const std::string& entity){
+void FF7::FieldModelInstruction::ProcessTLKON(CodeGenerator* code_gen, const std::string& entity){
     code_gen->AddOutputLine((
     code_gen->AddOutputLine((
       boost::format("self.%1%:set_talkable(%2%)")
       boost::format("self.%1%:set_talkable(%2%)")
-      % entity % FieldCodeGenerator::FormatInvertedBool(_params[0]->getUnsigned())
+      % entity % FF7::FieldCodeGenerator::FormatInvertedBool(_params[0]->getUnsigned())
     ).str());
     ).str());
 }
 }
 
 
-void FieldModelInstruction::ProcessPC(CodeGenerator* code_gen, const std::string& entity){
+void FF7::FieldModelInstruction::ProcessPC(CodeGenerator* code_gen, const std::string& entity){
     code_gen->AddOutputLine(
     code_gen->AddOutputLine(
       (boost::format("set_entity_to_character(\"%1%\", \"%1%\")") % entity).str()
       (boost::format("set_entity_to_character(\"%1%\", \"%1%\")") % entity).str()
     );
     );
 }
 }
 
 
-void FieldModelInstruction::ProcessCHAR(CodeGenerator* code_gen, const std::string& entity){
+void FF7::FieldModelInstruction::ProcessCHAR(CodeGenerator* code_gen, const std::string& entity){
     code_gen->AddOutputLine(
     code_gen->AddOutputLine(
       (boost::format("self.%1% = entity_manager:get_entity(\"%1%\")") % entity).str()
       (boost::format("self.%1% = entity_manager:get_entity(\"%1%\")") % entity).str()
     );
     );
 }
 }
 
 
-void FieldModelInstruction::ProcessDFANM(
+void FF7::FieldModelInstruction::ProcessDFANM(
   CodeGenerator* code_gen, const std::string& entity, int char_id
   CodeGenerator* code_gen, const std::string& entity, int char_id
 ){
 ){
     // ID will be fixed-up downstream.
     // ID will be fixed-up downstream.
@@ -211,7 +222,7 @@ void FieldModelInstruction::ProcessDFANM(
     ).str());
     ).str());
 }
 }
 
 
-void FieldModelInstruction::ProcessANIME1(
+void FF7::FieldModelInstruction::ProcessANIME1(
   CodeGenerator* code_gen, const std::string& entity, int char_id
   CodeGenerator* code_gen, const std::string& entity, int char_id
 ){
 ){
     // ID will be fixed-up downstream.
     // ID will be fixed-up downstream.
@@ -226,29 +237,29 @@ void FieldModelInstruction::ProcessANIME1(
     code_gen->AddOutputLine((boost::format("self.%1%:animation_sync()") % entity).str());
     code_gen->AddOutputLine((boost::format("self.%1%:animation_sync()") % entity).str());
 }
 }
 
 
-void FieldModelInstruction::ProcessVISI(CodeGenerator* code_gen, const std::string& entity){
+void FF7::FieldModelInstruction::ProcessVISI(CodeGenerator* code_gen, const std::string& entity){
     code_gen->AddOutputLine((
     code_gen->AddOutputLine((
       boost::format("self.%1%:set_visible(%2%)")
       boost::format("self.%1%:set_visible(%2%)")
-      % entity % FieldCodeGenerator::FormatBool(_params[0]->getUnsigned())
+      % entity % FF7::FieldCodeGenerator::FormatBool(_params[0]->getUnsigned())
     ).str());
     ).str());
 }
 }
 
 
-void FieldModelInstruction::ProcessXYZI(CodeGenerator* code_gen, const std::string& entity){
+void FF7::FieldModelInstruction::ProcessXYZI(CodeGenerator* code_gen, const std::string& entity){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     const float scale = 128.0f * cg->GetScaleFactor();
     const float scale = 128.0f * cg->GetScaleFactor();
-    const auto& x = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& x = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[4]->getSigned(),
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[4]->getSigned(),
-      FieldCodeGenerator::ValueType::Float, scale
+      FF7::FieldCodeGenerator::ValueType::Float, scale
     );
     );
-    const auto& y = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& y = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[5]->getSigned(),
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[5]->getSigned(),
-      FieldCodeGenerator::ValueType::Float, scale
+      FF7::FieldCodeGenerator::ValueType::Float, scale
     );
     );
-    const auto& z = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& z = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[6]->getSigned(),
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[6]->getSigned(),
-      FieldCodeGenerator::ValueType::Float, scale
+      FF7::FieldCodeGenerator::ValueType::Float, scale
     );
     );
-    const auto& triangle_id = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& triangle_id = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[7]->getUnsigned()
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[7]->getUnsigned()
     );
     );
     code_gen->AddOutputLine((
     code_gen->AddOutputLine((
@@ -257,16 +268,16 @@ void FieldModelInstruction::ProcessXYZI(CodeGenerator* code_gen, const std::stri
     ).str());
     ).str());
 }
 }
 
 
-void FieldModelInstruction::ProcessMOVE(CodeGenerator* code_gen, const std::string& entity){
+void FF7::FieldModelInstruction::ProcessMOVE(CodeGenerator* code_gen, const std::string& entity){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     const float scale = 128.0f * cg->GetScaleFactor();
     const float scale = 128.0f * cg->GetScaleFactor();
-    const auto& x = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& x = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getSigned(),
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getSigned(),
-      FieldCodeGenerator::ValueType::Float, scale
+      FF7::FieldCodeGenerator::ValueType::Float, scale
     );
     );
-    const auto& y = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& y = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getSigned(),
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getSigned(),
-      FieldCodeGenerator::ValueType::Float, scale
+      FF7::FieldCodeGenerator::ValueType::Float, scale
     );
     );
     code_gen->AddOutputLine(
     code_gen->AddOutputLine(
       (boost::format("self.%1%:move_to_position(%2%, %3%)") % entity % x % y).str()
       (boost::format("self.%1%:move_to_position(%2%, %3%)") % entity % x % y).str()
@@ -274,32 +285,32 @@ void FieldModelInstruction::ProcessMOVE(CodeGenerator* code_gen, const std::stri
     code_gen->AddOutputLine((boost::format("self.%1%:move_sync()") % entity).str());
     code_gen->AddOutputLine((boost::format("self.%1%:move_sync()") % entity).str());
 }
 }
 
 
-void FieldModelInstruction::ProcessMSPED(CodeGenerator* code_gen, const std::string& entity){
+void FF7::FieldModelInstruction::ProcessMSPED(CodeGenerator* code_gen, const std::string& entity){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     const float scale = 128.0f * cg->GetScaleFactor();
     const float scale = 128.0f * cg->GetScaleFactor();
-    const auto& speed = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& speed = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[2]->getUnsigned(),
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[2]->getUnsigned(),
-      FieldCodeGenerator::ValueType::Float, 256.0f * scale / 30.0f
+      FF7::FieldCodeGenerator::ValueType::Float, 256.0f * scale / 30.0f
     );
     );
     code_gen->AddOutputLine(
     code_gen->AddOutputLine(
       (boost::format("self.%1%:set_move_auto_speed(%2%)") % entity % speed).str()
       (boost::format("self.%1%:set_move_auto_speed(%2%)") % entity % speed).str()
     );
     );
 }
 }
 
 
-void FieldModelInstruction::ProcessDIR(CodeGenerator* code_gen, const std::string& entity){
+void FF7::FieldModelInstruction::ProcessDIR(CodeGenerator* code_gen, const std::string& entity){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
-    const auto& degrees = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& degrees = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[1]->getUnsigned(),
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[1]->getUnsigned(),
-      FieldCodeGenerator::ValueType::Float, 256.0f / 360.0f
+      FF7::FieldCodeGenerator::ValueType::Float, 256.0f / 360.0f
     );
     );
     code_gen->AddOutputLine((boost::format("self.%1%:set_rotation(%2%)") % entity % degrees).str());
     code_gen->AddOutputLine((boost::format("self.%1%:set_rotation(%2%)") % entity % degrees).str());
 }
 }
 
 
-void FieldModelInstruction::ProcessTURNGEN(CodeGenerator* code_gen, const std::string& entity){
+void FF7::FieldModelInstruction::ProcessTURNGEN(CodeGenerator* code_gen, const std::string& entity){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
-    const auto& degrees = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& degrees = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[2]->getUnsigned(),
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[2]->getUnsigned(),
-      FieldCodeGenerator::ValueType::Float, 256.0f / 360.0f
+      FF7::FieldCodeGenerator::ValueType::Float, 256.0f / 360.0f
     );
     );
     std::string direction;
     std::string direction;
     switch (_params[3]->getUnsigned()){
     switch (_params[3]->getUnsigned()){
@@ -325,10 +336,10 @@ void FieldModelInstruction::ProcessTURNGEN(CodeGenerator* code_gen, const std::s
     code_gen->AddOutputLine((boost::format("self.%1%:turn_sync()") % entity).str());
     code_gen->AddOutputLine((boost::format("self.%1%:turn_sync()") % entity).str());
 }
 }
 
 
-void FieldModelInstruction::ProcessGETAI(CodeGenerator* code_gen, const FieldEngine& engine){
+void FF7::FieldModelInstruction::ProcessGETAI(CodeGenerator* code_gen, const FieldEngine& engine){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     // TODO: check for assignment to literal.
     // TODO: check for assignment to literal.
-    const auto& variable = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& variable = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
     );
     );
     const auto& entity = engine.EntityByIndex(_params[2]->getUnsigned());
     const auto& entity = engine.EntityByIndex(_params[2]->getUnsigned());
@@ -338,7 +349,7 @@ void FieldModelInstruction::ProcessGETAI(CodeGenerator* code_gen, const FieldEng
     ).str());
     ).str());
 }
 }
 
 
-void FieldModelInstruction::ProcessANIM_2(
+void FF7::FieldModelInstruction::ProcessANIM_2(
   CodeGenerator* code_gen, const std::string& entity, int char_id
   CodeGenerator* code_gen, const std::string& entity, int char_id
 ){
 ){
     // ID will be fixed-up downstream.
     // ID will be fixed-up downstream.
@@ -353,7 +364,7 @@ void FieldModelInstruction::ProcessANIM_2(
     code_gen->AddOutputLine((boost::format("self.%1%:animation_sync()") % entity).str());
     code_gen->AddOutputLine((boost::format("self.%1%:animation_sync()") % entity).str());
 }
 }
 
 
-void FieldModelInstruction::ProcessCANIM2(
+void FF7::FieldModelInstruction::ProcessCANIM2(
   CodeGenerator* code_gen, const std::string& entity, int char_id
   CodeGenerator* code_gen, const std::string& entity, int char_id
 ){
 ){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
@@ -370,7 +381,7 @@ void FieldModelInstruction::ProcessCANIM2(
     code_gen->AddOutputLine((boost::format("self.%1%:animation_sync()") % entity).str());
     code_gen->AddOutputLine((boost::format("self.%1%:animation_sync()") % entity).str());
 }
 }
 
 
-void FieldModelInstruction::ProcessCANM_2(
+void FF7::FieldModelInstruction::ProcessCANM_2(
   CodeGenerator* code_gen, const std::string& entity, int char_id
   CodeGenerator* code_gen, const std::string& entity, int char_id
 ){
 ){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
@@ -388,28 +399,28 @@ void FieldModelInstruction::ProcessCANM_2(
     code_gen->AddOutputLine((boost::format("self.%1%:animation_sync()") % entity).str());
     code_gen->AddOutputLine((boost::format("self.%1%:animation_sync()") % entity).str());
 }
 }
 
 
-void FieldModelInstruction::ProcessCC(CodeGenerator* code_gen, const FieldEngine& engine){
+void FF7::FieldModelInstruction::ProcessCC(CodeGenerator* code_gen, const FieldEngine& engine){
     const auto& entity = engine.EntityByIndex(_params[0]->getUnsigned());
     const auto& entity = engine.EntityByIndex(_params[0]->getUnsigned());
     code_gen->AddOutputLine(
     code_gen->AddOutputLine(
       (boost::format("entity_manager:set_player_entity(\"%1%\")") % entity.GetName()).str()
       (boost::format("entity_manager:set_player_entity(\"%1%\")") % entity.GetName()).str()
     );
     );
 }
 }
 
 
-void FieldModelInstruction::ProcessJUMP(CodeGenerator* code_gen, const std::string& entity){
+void FF7::FieldModelInstruction::ProcessJUMP(CodeGenerator* code_gen, const std::string& entity){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     const float scale = 128.0f * cg->GetScaleFactor();
     const float scale = 128.0f * cg->GetScaleFactor();
-    float x = std::stof(FieldCodeGenerator::FormatValueOrVariable(
+    float x = std::stof(FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[4]->getSigned(),
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[4]->getSigned(),
-      FieldCodeGenerator::ValueType::Float, scale
+      FF7::FieldCodeGenerator::ValueType::Float, scale
     ));
     ));
-    float y = std::stof(FieldCodeGenerator::FormatValueOrVariable(
+    float y = std::stof(FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[5]->getSigned(),
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[5]->getSigned(),
-      FieldCodeGenerator::ValueType::Float, scale
+      FF7::FieldCodeGenerator::ValueType::Float, scale
     ));
     ));
-    int i = atoi(FieldCodeGenerator::FormatValueOrVariable(
+    int i = atoi(FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[6]->getSigned()
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[6]->getSigned()
     ).c_str());
     ).c_str());
-    int steps = atoi(FieldCodeGenerator::FormatValueOrVariable(
+    int steps = atoi(FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[7]->getSigned()
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[7]->getSigned()
     ).c_str());
     ).c_str());
     //x *= 0.00781250273224;
     //x *= 0.00781250273224;
@@ -427,7 +438,7 @@ void FieldModelInstruction::ProcessJUMP(CodeGenerator* code_gen, const std::stri
     code_gen->AddOutputLine((boost::format("self.%1%:jump_sync()") % entity).str());
     code_gen->AddOutputLine((boost::format("self.%1%:jump_sync()") % entity).str());
 }
 }
 
 
-void FieldModelInstruction::ProcessAXYZI(CodeGenerator* code_gen){
+void FF7::FieldModelInstruction::ProcessAXYZI(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     const float scale = 128.0f * cg->GetScaleFactor();
     const float scale = 128.0f * cg->GetScaleFactor();
     code_gen->AddOutputLine((
     code_gen->AddOutputLine((
@@ -439,30 +450,30 @@ void FieldModelInstruction::ProcessAXYZI(CodeGenerator* code_gen){
     ).str());
     ).str());
 }
 }
 
 
-void FieldModelInstruction::ProcessLADER(CodeGenerator* code_gen, const std::string& entity){
+void FF7::FieldModelInstruction::ProcessLADER(CodeGenerator* code_gen, const std::string& entity){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     const float scale = 128.0f * cg->GetScaleFactor();
     const float scale = 128.0f * cg->GetScaleFactor();
-    const auto& x = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& x = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[4]->getSigned(),
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[4]->getSigned(),
-      FieldCodeGenerator::ValueType::Float, scale
+      FF7::FieldCodeGenerator::ValueType::Float, scale
     );
     );
-    const auto& y = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& y = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[5]->getSigned(),
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[5]->getSigned(),
-      FieldCodeGenerator::ValueType::Float, scale
+      FF7::FieldCodeGenerator::ValueType::Float, scale
     );
     );
-    const auto& z = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& z = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[6]->getSigned(),
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[6]->getSigned(),
-      FieldCodeGenerator::ValueType::Float, scale
+      FF7::FieldCodeGenerator::ValueType::Float, scale
     );
     );
-    uint end_triangle = atoi(FieldCodeGenerator::FormatValueOrVariable(
+    uint end_triangle = atoi(FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[7]->getUnsigned()
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[7]->getUnsigned()
     ).c_str());
     ).c_str());
     uint keys = _params[8]->getUnsigned();
     uint keys = _params[8]->getUnsigned();
     uint animation = _params[9]->getUnsigned();
     uint animation = _params[9]->getUnsigned();
     //float orientation = _params[10]->getUnsigned() / (256.0f / 360.0f);
     //float orientation = _params[10]->getUnsigned() / (256.0f / 360.0f);
-    const auto& orientation = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& orientation = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), 0, _params[10]->getSigned(),
       cg->GetFormatter(), 0, _params[10]->getSigned(),
-      FieldCodeGenerator::ValueType::Float, 256.0f / 360.0f
+      FF7::FieldCodeGenerator::ValueType::Float, 256.0f / 360.0f
     );
     );
     uint speed = _params[11]->getUnsigned();
     uint speed = _params[11]->getUnsigned();
     // TODO: Animation hardcoded as "btce".
     // TODO: Animation hardcoded as "btce".
@@ -476,29 +487,29 @@ void FieldModelInstruction::ProcessLADER(CodeGenerator* code_gen, const std::str
     code_gen->AddOutputLine((boost::format("self.%1%:linear_sync()") % entity).str());
     code_gen->AddOutputLine((boost::format("self.%1%:linear_sync()") % entity).str());
 }
 }
 
 
-void FieldModelInstruction::ProcessSOLID(CodeGenerator* code_gen, const std::string& entity){
+void FF7::FieldModelInstruction::ProcessSOLID(CodeGenerator* code_gen, const std::string& entity){
     code_gen->AddOutputLine((
     code_gen->AddOutputLine((
       boost::format("self.%1%:set_solid(%2%)")
       boost::format("self.%1%:set_solid(%2%)")
-      % entity % FieldCodeGenerator::FormatInvertedBool(_params[0]->getUnsigned())
+      % entity % FF7::FieldCodeGenerator::FormatInvertedBool(_params[0]->getUnsigned())
     ).str());
     ).str());
 }
 }
 
 
-void FieldModelInstruction::ProcessOFST(CodeGenerator* code_gen, const std::string& entity){
+void FF7::FieldModelInstruction::ProcessOFST(CodeGenerator* code_gen, const std::string& entity){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     const float scale = 128.0f * cg->GetScaleFactor();
     const float scale = 128.0f * cg->GetScaleFactor();
-    float x = std::stof(FieldCodeGenerator::FormatValueOrVariable(
+    float x = std::stof(FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[5]->getSigned(),
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[5]->getSigned(),
-      FieldCodeGenerator::ValueType::Float, scale
+      FF7::FieldCodeGenerator::ValueType::Float, scale
     ));
     ));
-    float y = std::stof(FieldCodeGenerator::FormatValueOrVariable(
+    float y = std::stof(FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(),_params[6]->getSigned(),
       cg->GetFormatter(), _params[1]->getUnsigned(),_params[6]->getSigned(),
-      FieldCodeGenerator::ValueType::Float, scale
+      FF7::FieldCodeGenerator::ValueType::Float, scale
     ));
     ));
-    float z = std::stof(FieldCodeGenerator::FormatValueOrVariable(
+    float z = std::stof(FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[7]->getSigned(),
       cg->GetFormatter(), _params[2]->getUnsigned(), _params[7]->getSigned(),
-      FieldCodeGenerator::ValueType::Float, scale
+      FF7::FieldCodeGenerator::ValueType::Float, scale
     ));
     ));
-    float speed = std::stof(FieldCodeGenerator::FormatValueOrVariable(
+    float speed = std::stof(FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[8]->getUnsigned()
       cg->GetFormatter(), _params[3]->getUnsigned(), _params[8]->getUnsigned()
     ));
     ));
     // Spatial coordinates need to be scaled down.
     // Spatial coordinates need to be scaled down.

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

@@ -16,69 +16,72 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
 #include "decompiler/field/instruction/FieldModuleInstruction.h"
 #include "decompiler/field/instruction/FieldModuleInstruction.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldDisassembler.h"
 #include "decompiler/field/FieldDisassembler.h"
 
 
-void FieldModuleInstruction::ProcessInst(
+void FF7::FieldModuleInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
 ){
     FunctionMetaData md(func._metadata);
     FunctionMetaData md(func._metadata);
     switch (_opcode){
     switch (_opcode){
-        case OPCODE::DSKCG: WriteTodo(code_gen, md.GetEntityName(), "DSKCG"); break;
-        case (OPCODE::SPECIAL << 8) | OPCODE_SPECIAL::ARROW:
+        case OPCODES::DSKCG: code_gen->WriteTodo(md.GetEntityName(), "DSKCG"); break;
+        case (OPCODES::SPECIAL << 8) | OPCODES_SPECIAL::ARROW:
             code_gen->AddOutputLine((
             code_gen->AddOutputLine((
               boost::format("game:pointer_enable(%1%)")
               boost::format("game:pointer_enable(%1%)")
               % (_params[0]->getUnsigned() ? "true" : "false")
               % (_params[0]->getUnsigned() ? "true" : "false")
             ).str());
             ).str());
             break;
             break;
-        case (OPCODE::SPECIAL << 8) | OPCODE_SPECIAL::PNAME:
-            WriteTodo(code_gen, md.GetEntityName(), "PNAME");
+        case (OPCODES::SPECIAL << 8) | OPCODES_SPECIAL::PNAME:
+            code_gen->WriteTodo(md.GetEntityName(), "PNAME");
             break;
             break;
-        case (OPCODE::SPECIAL << 8) | OPCODE_SPECIAL::GMSPD:
-            WriteTodo(code_gen, md.GetEntityName(), "GMSPD");
+        case (OPCODES::SPECIAL << 8) | OPCODES_SPECIAL::GMSPD:
+            code_gen->WriteTodo(md.GetEntityName(), "GMSPD");
             break;
             break;
-        case (OPCODE::SPECIAL << 8) | OPCODE_SPECIAL::SMSPD:
-            WriteTodo(code_gen, md.GetEntityName(), "SMSPD");
+        case (OPCODES::SPECIAL << 8) | OPCODES_SPECIAL::SMSPD:
+            code_gen->WriteTodo(md.GetEntityName(), "SMSPD");
             break;
             break;
-        case (OPCODE::SPECIAL << 8) | OPCODE_SPECIAL::FLMAT:
+        case (OPCODES::SPECIAL << 8) | OPCODES_SPECIAL::FLMAT:
             code_gen->AddOutputLine("game:fill_materia()");
             code_gen->AddOutputLine("game:fill_materia()");
             break;
             break;
-        case (OPCODE::SPECIAL << 8) | OPCODE_SPECIAL::FLITM:
-            WriteTodo(code_gen, md.GetEntityName(), "FLITM");
+        case (OPCODES::SPECIAL << 8) | OPCODES_SPECIAL::FLITM:
+            code_gen->WriteTodo(md.GetEntityName(), "FLITM");
             break;
             break;
-        case (OPCODE::SPECIAL << 8) | OPCODE_SPECIAL::BTLCK:
+        case (OPCODES::SPECIAL << 8) | OPCODES_SPECIAL::BTLCK:
             code_gen->AddOutputLine((
             code_gen->AddOutputLine((
               boost::format("game:battle_enable(%1%)")
               boost::format("game:battle_enable(%1%)")
               % (_params[0]->getUnsigned() ? "true" : "false")
               % (_params[0]->getUnsigned() ? "true" : "false")
             ).str());
             ).str());
             break;
             break;
-        case (OPCODE::SPECIAL << 8) | OPCODE_SPECIAL::MVLCK:
+        case (OPCODES::SPECIAL << 8) | OPCODES_SPECIAL::MVLCK:
             code_gen->AddOutputLine((
             code_gen->AddOutputLine((
               boost::format("game:movie_enable(%1%)")
               boost::format("game:movie_enable(%1%)")
               % (_params[0]->getUnsigned() ? "true" : "false")
               % (_params[0]->getUnsigned() ? "true" : "false")
             ).str());
             ).str());
             break;
             break;
-        case (OPCODE::SPECIAL << 8) | OPCODE_SPECIAL::SPCNM:
-            WriteTodo(code_gen, md.GetEntityName(), "SPCNM");
+        case (OPCODES::SPECIAL << 8) | OPCODES_SPECIAL::SPCNM:
+            code_gen->WriteTodo(md.GetEntityName(), "SPCNM");
             break;
             break;
-        case (OPCODE::SPECIAL << 8) | OPCODE_SPECIAL::RSGLB:
+        case (OPCODES::SPECIAL << 8) | OPCODES_SPECIAL::RSGLB:
             code_gen->AddOutputLine("game:global_reset()");
             code_gen->AddOutputLine("game:global_reset()");
             break;
             break;
-        case (OPCODE::SPECIAL << 8) | OPCODE_SPECIAL::CLITM:
-            WriteTodo(code_gen, md.GetEntityName(), "CLITM");
+        case (OPCODES::SPECIAL << 8) | OPCODES_SPECIAL::CLITM:
+            code_gen->WriteTodo(md.GetEntityName(), "CLITM");
             break;
             break;
-        case OPCODE::MINIGAME: WriteTodo(code_gen, md.GetEntityName(), "MINIGAME"); break;
-        case OPCODE::BTMD2: WriteTodo(code_gen, md.GetEntityName(), "BTMD2"); break;
-        case OPCODE::BTRLD: WriteTodo(code_gen, md.GetEntityName(), "BTRLD"); break;
-        case OPCODE::BTLTB: WriteTodo(code_gen, md.GetEntityName(), "BTLTB"); break;
-        case OPCODE::MAPJUMP: ProcessMAPJUMP(code_gen, func); break;
-        case OPCODE::LSTMP: WriteTodo(code_gen, md.GetEntityName(), "LSTMP"); break;
-        case OPCODE::BATTLE: ProcessBATTLE(code_gen); break;
-        case OPCODE::BTLON: ProcessBTLON(code_gen); break;
-        case OPCODE::BTLMD: WriteTodo(code_gen, md.GetEntityName(), "BTLMD"); break;
-        case OPCODE::MPJPO:
+        case OPCODES::MINIGAME: code_gen->WriteTodo(md.GetEntityName(), "MINIGAME"); break;
+        case OPCODES::BTMD2: code_gen->WriteTodo(md.GetEntityName(), "BTMD2"); break;
+        case OPCODES::BTRLD: code_gen->WriteTodo(md.GetEntityName(), "BTRLD"); break;
+        case OPCODES::BTLTB: code_gen->WriteTodo(md.GetEntityName(), "BTLTB"); break;
+        case OPCODES::MAPJUMP: ProcessMAPJUMP(code_gen, func); break;
+        case OPCODES::LSTMP: code_gen->WriteTodo(md.GetEntityName(), "LSTMP"); break;
+        case OPCODES::BATTLE: ProcessBATTLE(code_gen); break;
+        case OPCODES::BTLON: ProcessBTLON(code_gen); break;
+        case OPCODES::BTLMD: code_gen->WriteTodo(md.GetEntityName(), "BTLMD"); break;
+        case OPCODES::MPJPO:
             // Gateway function will do nothing if this is set to true
             // Gateway function will do nothing if this is set to true
             code_gen->AddOutputLine(
             code_gen->AddOutputLine(
               std::string("FFVII.Data.DisableGateways=")
               std::string("FFVII.Data.DisableGateways=")
@@ -86,40 +89,40 @@ void FieldModuleInstruction::ProcessInst(
             );
             );
             break;
             break;
         // Prepare to change map, don't need to output anything for this.
         // Prepare to change map, don't need to output anything for this.
-        case OPCODE::PMJMP: code_gen->AddOutputLine("-- Prepare map change"); break;
+        case OPCODES::PMJMP: code_gen->AddOutputLine("-- Prepare map change"); break;
         // Prepare to change map, don't need to output anything for this,
         // Prepare to change map, don't need to output anything for this,
-        // seems to be the same thing as PMJMP
-        case OPCODE::PMJMP2: code_gen->AddOutputLine("-- Prepare map change 2"); break;
-        case OPCODE::GAMEOVER: WriteTodo(code_gen, md.GetEntityName(), "GAMEOVER"); break;
+        // seems to be the same thing as PMJMP.
+        case OPCODES::PMJMP2: code_gen->AddOutputLine("-- Prepare map change 2"); break;
+        case OPCODES::GAMEOVER: code_gen->WriteTodo(md.GetEntityName(), "GAMEOVER"); break;
         default:
         default:
-            code_gen->AddOutputLine(FieldCodeGenerator::FormatInstructionNotImplemented(
+            code_gen->AddOutputLine(FF7::FieldCodeGenerator::FormatInstructionNotImplemented(
               md.GetEntityName(), _address, _opcode
               md.GetEntityName(), _address, _opcode
             ));
             ));
     }
     }
 }
 }
 
 
-void FieldModuleInstruction::ProcessBATTLE(CodeGenerator* code_gen){
+void FF7::FieldModuleInstruction::ProcessBATTLE(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
-    const auto& battle_id = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& battle_id = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[1]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[1]->getUnsigned()
     );
     );
     code_gen->AddOutputLine((boost::format("entity_manager:battle_run(%1%)") % battle_id).str());
     code_gen->AddOutputLine((boost::format("entity_manager:battle_run(%1%)") % battle_id).str());
 }
 }
 
 
-void FieldModuleInstruction::ProcessBTLON(CodeGenerator* code_gen){
+void FF7::FieldModuleInstruction::ProcessBTLON(CodeGenerator* code_gen){
     code_gen->AddOutputLine((
     code_gen->AddOutputLine((
       boost::format("entity_manager:random_encounters_on(%1%)")
       boost::format("entity_manager:random_encounters_on(%1%)")
-      % FieldCodeGenerator::FormatInvertedBool(_params[0]->getUnsigned())
+      % FF7::FieldCodeGenerator::FormatInvertedBool(_params[0]->getUnsigned())
     ).str());
     ).str());
 }
 }
 
 
-void FieldModuleInstruction::ProcessMAPJUMP(CodeGenerator* code_gen, Function& func){
+void FF7::FieldModuleInstruction::ProcessMAPJUMP(CodeGenerator* code_gen, Function& func){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     const auto target_map_id = _params[0]->getUnsigned();
     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);
-
+    const std::string source_spawn_point_name = cg->GetFormatter().SpawnPointName(
+      target_map_id, md.GetEntityName(), func._name, _address
+    );
     cg->GetFormatter().AddSpawnPoint(
     cg->GetFormatter().AddSpawnPoint(
       target_map_id, md.GetEntityName(), func._name, _address,
       target_map_id, md.GetEntityName(), func._name, _address,
       _params[1]->getSigned(), // X
       _params[1]->getSigned(), // X
@@ -127,7 +130,6 @@ void FieldModuleInstruction::ProcessMAPJUMP(CodeGenerator* code_gen, Function& f
       _params[3]->getSigned(), // Walk mesh triangle ID
       _params[3]->getSigned(), // Walk mesh triangle ID
       _params[4]->getSigned()  // Angle
       _params[4]->getSigned()  // Angle
     );
     );
-
     const std::string target_map_name = cg->GetFormatter().MapName(target_map_id);
     const std::string target_map_name = cg->GetFormatter().MapName(target_map_id);
     code_gen->AddOutputLine(
     code_gen->AddOutputLine(
       "load_field_map_request(\"" + target_map_name + "\", \"" + source_spawn_point_name + "\")"
       "load_field_map_request(\"" + target_map_name + "\", \"" + source_spawn_point_name + "\")"

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

@@ -16,11 +16,14 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
 #include "decompiler/field/instruction/FieldNoOperationInstruction.h"
 #include "decompiler/field/instruction/FieldNoOperationInstruction.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldDisassembler.h"
 #include "decompiler/field/FieldDisassembler.h"
 
 
-void FieldNoOperationInstruction::ProcessInst(
+void FF7::FieldNoOperationInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){}
 ){}

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

@@ -16,61 +16,64 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
 #include "decompiler/field/instruction/FieldPartyInstruction.h"
 #include "decompiler/field/instruction/FieldPartyInstruction.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldDisassembler.h"
 #include "decompiler/field/FieldDisassembler.h"
 
 
-void FieldPartyInstruction::ProcessInst(
+void FF7::FieldPartyInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
 ){
     FunctionMetaData md(func._metadata);
     FunctionMetaData md(func._metadata);
     switch (_opcode){
     switch (_opcode){
-        case OPCODE::SPTYE: WriteTodo(code_gen, md.GetEntityName(), "SPTYE"); break;
-        case OPCODE::GTPYE: WriteTodo(code_gen, md.GetEntityName(), "GTPYE"); break;
-        case OPCODE::GOLDU: WriteTodo(code_gen, md.GetEntityName(), "GOLDU"); break;
-        case OPCODE::GOLDD: WriteTodo(code_gen, md.GetEntityName(), "GOLDD"); break;
-        case OPCODE::HMPMAX1: WriteTodo(code_gen, md.GetEntityName(), "HMPMAX1"); break;
-        case OPCODE::HMPMAX2: WriteTodo(code_gen, md.GetEntityName(), "HMPMAX2"); break;
-        case OPCODE::MHMMX: WriteTodo(code_gen, md.GetEntityName(), "MHMMX"); break;
-        case OPCODE::HMPMAX3: WriteTodo(code_gen, md.GetEntityName(), "HMPMAX3"); break;
-        case OPCODE::MPU: WriteTodo(code_gen, md.GetEntityName(), "MPU"); break;
-        case OPCODE::MPD: WriteTodo(code_gen, md.GetEntityName(), "MPD"); break;
-        case OPCODE::HPU: WriteTodo(code_gen, md.GetEntityName(), "HPU"); break;
-        case OPCODE::HPD: WriteTodo(code_gen, md.GetEntityName(), "HPD"); break;
-        case OPCODE::STITM: ProcessSTITM(code_gen); break;
-        case OPCODE::DLITM: WriteTodo(code_gen, md.GetEntityName(), "DLITM"); break;
-        case OPCODE::CKITM: WriteTodo(code_gen, md.GetEntityName(), "CKITM"); break;
-        case OPCODE::SMTRA: WriteTodo(code_gen, md.GetEntityName(), "SMTRA"); break;
-        case OPCODE::DMTRA: WriteTodo(code_gen, md.GetEntityName(), "DMTRA"); break;
-        case OPCODE::CMTRA: WriteTodo(code_gen, md.GetEntityName(), "CMTRA"); break;
-        case OPCODE::GETPC: WriteTodo(code_gen, md.GetEntityName(), "GETPC"); break;
-        case OPCODE::PRTYP: WriteTodo(code_gen, md.GetEntityName(), "PRTYP"); break;
-        case OPCODE::PRTYM: WriteTodo(code_gen, md.GetEntityName(), "PRTYM"); break;
-        case OPCODE::PRTYE: ProcessPRTYE(code_gen); break;
-        case OPCODE::MMBUD: WriteTodo(code_gen, md.GetEntityName(), "MMBUD"); break;
-        case OPCODE::MMBLK: WriteTodo(code_gen, md.GetEntityName(), "MMBLK"); break;
-        case OPCODE::MMBUK: WriteTodo(code_gen, md.GetEntityName(), "MMBUK"); break;
-        case OPCODE::CHGLD: WriteTodo(code_gen, md.GetEntityName(), "CHGLD"); break;
+        case OPCODES::SPTYE: code_gen->WriteTodo(md.GetEntityName(), "SPTYE"); break;
+        case OPCODES::GTPYE: code_gen->WriteTodo(md.GetEntityName(), "GTPYE"); break;
+        case OPCODES::GOLDU: code_gen->WriteTodo(md.GetEntityName(), "GOLDU"); break;
+        case OPCODES::GOLDD: code_gen->WriteTodo(md.GetEntityName(), "GOLDD"); break;
+        case OPCODES::HMPMAX1: code_gen->WriteTodo(md.GetEntityName(), "HMPMAX1"); break;
+        case OPCODES::HMPMAX2: code_gen->WriteTodo(md.GetEntityName(), "HMPMAX2"); break;
+        case OPCODES::MHMMX: code_gen->WriteTodo(md.GetEntityName(), "MHMMX"); break;
+        case OPCODES::HMPMAX3: code_gen->WriteTodo(md.GetEntityName(), "HMPMAX3"); break;
+        case OPCODES::MPU: code_gen->WriteTodo(md.GetEntityName(), "MPU"); break;
+        case OPCODES::MPD: code_gen->WriteTodo(md.GetEntityName(), "MPD"); break;
+        case OPCODES::HPU: code_gen->WriteTodo(md.GetEntityName(), "HPU"); break;
+        case OPCODES::HPD: code_gen->WriteTodo(md.GetEntityName(), "HPD"); break;
+        case OPCODES::STITM: ProcessSTITM(code_gen); break;
+        case OPCODES::DLITM: code_gen->WriteTodo(md.GetEntityName(), "DLITM"); break;
+        case OPCODES::CKITM: code_gen->WriteTodo(md.GetEntityName(), "CKITM"); break;
+        case OPCODES::SMTRA: code_gen->WriteTodo(md.GetEntityName(), "SMTRA"); break;
+        case OPCODES::DMTRA: code_gen->WriteTodo(md.GetEntityName(), "DMTRA"); break;
+        case OPCODES::CMTRA: code_gen->WriteTodo(md.GetEntityName(), "CMTRA"); break;
+        case OPCODES::GETPC: code_gen->WriteTodo(md.GetEntityName(), "GETPC"); break;
+        case OPCODES::PRTYP: code_gen->WriteTodo(md.GetEntityName(), "PRTYP"); break;
+        case OPCODES::PRTYM: code_gen->WriteTodo(md.GetEntityName(), "PRTYM"); break;
+        case OPCODES::PRTYE: ProcessPRTYE(code_gen); break;
+        case OPCODES::MMBUD: code_gen->WriteTodo(md.GetEntityName(), "MMBUD"); break;
+        case OPCODES::MMBLK: code_gen->WriteTodo(md.GetEntityName(), "MMBLK"); break;
+        case OPCODES::MMBUK: code_gen->WriteTodo(md.GetEntityName(), "MMBUK"); break;
+        case OPCODES::CHGLD: code_gen->WriteTodo(md.GetEntityName(), "CHGLD"); break;
         default:
         default:
-            code_gen->AddOutputLine(FieldCodeGenerator::FormatInstructionNotImplemented(
+            code_gen->AddOutputLine(FF7::FieldCodeGenerator::FormatInstructionNotImplemented(
               md.GetEntityName(), _address, _opcode
               md.GetEntityName(), _address, _opcode
             ));
             ));
     }
     }
 }
 }
 
 
-void FieldPartyInstruction::ProcessSTITM(CodeGenerator* code_gen){
+void FF7::FieldPartyInstruction::ProcessSTITM(CodeGenerator* code_gen){
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
-    const auto& item_id = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& item_id = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
       cg->GetFormatter(), _params[0]->getUnsigned(), _params[2]->getUnsigned()
     );
     );
-    const auto& amount = FieldCodeGenerator::FormatValueOrVariable(
+    const auto& amount = FF7::FieldCodeGenerator::FormatValueOrVariable(
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
       cg->GetFormatter(), _params[1]->getUnsigned(), _params[3]->getUnsigned()
     );
     );
     code_gen->AddOutputLine((boost::format("FFVII.add_item(%1%, %2%)") % item_id % amount).str());
     code_gen->AddOutputLine((boost::format("FFVII.add_item(%1%, %2%)") % item_id % amount).str());
 }
 }
 
 
-void FieldPartyInstruction::ProcessPRTYE(CodeGenerator* code_gen){
+void FF7::FieldPartyInstruction::ProcessPRTYE(CodeGenerator* code_gen){
     FieldCodeGenerator* gc = static_cast<FieldCodeGenerator*>(code_gen);
     FieldCodeGenerator* gc = static_cast<FieldCodeGenerator*>(code_gen);
     auto char_id_1 = gc->GetFormatter().CharName(_params[0]->getUnsigned());
     auto char_id_1 = gc->GetFormatter().CharName(_params[0]->getUnsigned());
     char_id_1 = (char_id_1 == "") ? "nil" : ("\"" + char_id_1 + "\"");
     char_id_1 = (char_id_1 == "") ? "nil" : ("\"" + char_id_1 + "\"");

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

@@ -16,22 +16,25 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
 #include "decompiler/field/instruction/FieldUncategorizedInstruction.h"
 #include "decompiler/field/instruction/FieldUncategorizedInstruction.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldDisassembler.h"
 #include "decompiler/field/FieldDisassembler.h"
 
 
-void FieldUncategorizedInstruction::ProcessInst(
+void FF7::FieldUncategorizedInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
 ){
     FunctionMetaData md(func._metadata);
     FunctionMetaData md(func._metadata);
     switch (_opcode){
     switch (_opcode){
-        case OPCODE::MPDSP: WriteTodo(code_gen, md.GetEntityName(), "MPDSP"); break;
-        case OPCODE::SETX: WriteTodo(code_gen, md.GetEntityName(), "SETX"); break;
-        case OPCODE::GETX: WriteTodo(code_gen, md.GetEntityName(), "GETX"); break;
-        case OPCODE::SEARCHX: WriteTodo(code_gen, md.GetEntityName(), "SEARCHX"); break;
+        case OPCODES::MPDSP: code_gen->WriteTodo(md.GetEntityName(), "MPDSP"); break;
+        case OPCODES::SETX: code_gen->WriteTodo(md.GetEntityName(), "SETX"); break;
+        case OPCODES::GETX: code_gen->WriteTodo(md.GetEntityName(), "GETX"); break;
+        case OPCODES::SEARCHX: code_gen->WriteTodo(md.GetEntityName(), "SEARCHX"); break;
         default:
         default:
-            code_gen->AddOutputLine(FieldCodeGenerator::FormatInstructionNotImplemented(
+            code_gen->AddOutputLine(FF7::FieldCodeGenerator::FormatInstructionNotImplemented(
               md.GetEntityName(), _address, _opcode)
               md.GetEntityName(), _address, _opcode)
             );
             );
     }
     }

+ 22 - 18
V-Gears-Installer/src/decompiler/field/instruction/FieldUncondJumpInstruction.cpp

@@ -16,43 +16,47 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
 #include "decompiler/field/instruction/FieldUncondJumpInstruction.h"
 #include "decompiler/field/instruction/FieldUncondJumpInstruction.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldDisassembler.h"
 #include "decompiler/field/FieldDisassembler.h"
 
 
-FieldUncondJumpInstruction::FieldUncondJumpInstruction() : call_(false) {}
+FF7::FieldUncondJumpInstruction::FieldUncondJumpInstruction() : is_func_call_(false) {}
 
 
-bool FieldUncondJumpInstruction::IsFuncCall() const{return call_;}
+bool FF7::FieldUncondJumpInstruction::IsFuncCall() const{return is_func_call_;}
 
 
-bool FieldUncondJumpInstruction::IsUncondJump() const{return !call_;}
+bool FF7::FieldUncondJumpInstruction::IsUncondJump() const{return !is_func_call_;}
 
 
-uint32 FieldUncondJumpInstruction::GetDestAddress() const{
+uint32 FF7::FieldUncondJumpInstruction::GetDestAddress() const{
     if (
     if (
-      static_cast<OPCODE>(_opcode) == OPCODE::JMPF
-      || static_cast<OPCODE>(_opcode) == OPCODE::JMPFL){
+      static_cast<OPCODES>(_opcode) == OPCODES::JMPF
+      || static_cast<OPCODES>(_opcode) == OPCODES::JMPFL){
         // Short or long forward jump.
         // Short or long forward jump.
         return _address + _params[0]->getUnsigned() + 1;
         return _address + _params[0]->getUnsigned() + 1;
     }
     }
-    // Backwards jump,  OPCODE::JMPB/L.
+    // Backwards jump,  eOpcodes::JMPB/L.
     return _address - _params[0]->getUnsigned();
     return _address - _params[0]->getUnsigned();
 }
 }
 
 
-void FieldUncondJumpInstruction::ProcessInst(
-  Function& func, ValueStack&, Engine* engine, CodeGenerator* code_gen
+std::ostream& FF7::FieldUncondJumpInstruction::Print(std::ostream &output) const{
+    Instruction::Print(output);
+    output << " (Jump target address: 0x" << std::hex << GetDestAddress() << std::dec << ")";
+    return output;
+}
+
+
+void FF7::FieldUncondJumpInstruction::ProcessInst(
+  Function& func, ValueStack& stack, Engine* engine, CodeGenerator* code_gen
 ){
 ){
     switch (_opcode){
     switch (_opcode){
-        case OPCODE::JMPB:
-        case OPCODE::JMPBL:
+        case OPCODES::JMPB:
+        case OPCODES::JMPBL:
             // HACK: Hard loop will hang the game, insert a wait to yield control.
             // HACK: Hard loop will hang the game, insert a wait to yield control.
-            code_gen->AddOutputLine("-- Hack, yield control for possible inf loop");
+            code_gen->AddOutputLine("-- HACK: Yield control for possible infinite loop");
             code_gen->AddOutputLine("script:wait(0)");
             code_gen->AddOutputLine("script:wait(0)");
             break;
             break;
     }
     }
 }
 }
-
-std::ostream& FieldUncondJumpInstruction::Print(std::ostream &output) const{
-    Instruction::Print(output);
-    output << " (Jump target address: 0x" << std::hex << GetDestAddress() << std::dec << ")";
-    return output;
-}

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

@@ -16,43 +16,46 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
 #include "decompiler/field/instruction/FieldWalkmeshInstruction.h"
 #include "decompiler/field/instruction/FieldWalkmeshInstruction.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldDisassembler.h"
 #include "decompiler/field/FieldDisassembler.h"
 
 
-void FieldWalkmeshInstruction::ProcessInst(
+void FF7::FieldWalkmeshInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
 ){
     FunctionMetaData md(func._metadata);
     FunctionMetaData md(func._metadata);
     switch (_opcode){
     switch (_opcode){
-        case OPCODE::SLIP: WriteTodo(code_gen, md.GetEntityName(), "SLIP"); break;
-        case OPCODE::UC: ProcessUC(code_gen); break;
-        case OPCODE::IDLCK:
+        case OPCODES::SLIP: code_gen->WriteTodo(md.GetEntityName(), "SLIP"); break;
+        case OPCODES::UC: ProcessUC(code_gen); break;
+        case OPCODES::IDLCK:
             // Triangle id, on or off
             // Triangle id, on or off
             code_gen->AddOutputLine(
             code_gen->AddOutputLine(
                 (boost::format("walkmesh:lock_walkmesh(%1%, %2%)")
                 (boost::format("walkmesh:lock_walkmesh(%1%, %2%)")
                 % _params[0]->getUnsigned()
                 % _params[0]->getUnsigned()
-                % FieldCodeGenerator::FormatBool(_params[1]->getUnsigned())).str());
+                % FF7::FieldCodeGenerator::FormatBool(_params[1]->getUnsigned())).str());
             break;
             break;
-        case OPCODE::LINE: ProcessLINE(code_gen, md.GetEntityName()); break;
-        case OPCODE::LINON: WriteTodo(code_gen, md.GetEntityName(), "LINON"); break;
-        case OPCODE::SLINE: WriteTodo(code_gen, md.GetEntityName(), "SLINE"); break;
+        case OPCODES::LINE: ProcessLINE(code_gen, md.GetEntityName()); break;
+        case OPCODES::LINON: code_gen->WriteTodo(md.GetEntityName(), "LINON"); break;
+        case OPCODES::SLINE: code_gen->WriteTodo(md.GetEntityName(), "SLINE"); break;
         default:
         default:
-            code_gen->AddOutputLine(FieldCodeGenerator::FormatInstructionNotImplemented(
+            code_gen->AddOutputLine(FF7::FieldCodeGenerator::FormatInstructionNotImplemented(
               md.GetEntityName(), _address, _opcode
               md.GetEntityName(), _address, _opcode
             ));
             ));
     }
     }
 }
 }
 
 
-void FieldWalkmeshInstruction::ProcessUC(CodeGenerator* code_gen){
+void FF7::FieldWalkmeshInstruction::ProcessUC(CodeGenerator* code_gen){
     code_gen->AddOutputLine((
     code_gen->AddOutputLine((
       boost::format("entity_manager:player_lock(%1%)")
       boost::format("entity_manager:player_lock(%1%)")
-      % FieldCodeGenerator::FormatBool(_params[0]->getUnsigned())
+      % FF7::FieldCodeGenerator::FormatBool(_params[0]->getUnsigned())
     ).str());
     ).str());
 }
 }
 
 
-void FieldWalkmeshInstruction::ProcessLINE(CodeGenerator* code_gen, const std::string& entity){
+void FF7::FieldWalkmeshInstruction::ProcessLINE(CodeGenerator* code_gen, const std::string& entity){
     float xa = _params[0]->getSigned();
     float xa = _params[0]->getSigned();
     float ya = _params[1]->getSigned();
     float ya = _params[1]->getSigned();
     float za = _params[2]->getSigned();
     float za = _params[2]->getSigned();

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

@@ -16,47 +16,50 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
 #include "decompiler/field/instruction/FieldWindowInstruction.h"
 #include "decompiler/field/instruction/FieldWindowInstruction.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldEngine.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/FieldDisassembler.h"
 #include "decompiler/field/FieldDisassembler.h"
 
 
-void FieldWindowInstruction::ProcessInst(
+void FF7::FieldWindowInstruction::ProcessInst(
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
   Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
 ){
 ){
-    FieldEngine& eng = static_cast<FieldEngine&>(*engine);
+    FF7::FieldEngine& eng = static_cast<FF7::FieldEngine&>(*engine);
     FunctionMetaData md(func._metadata);
     FunctionMetaData md(func._metadata);
     switch (_opcode){
     switch (_opcode){
-        case OPCODE::TUTOR: WriteTodo(code_gen, md.GetEntityName(), "TUTOR"); break;
-        case OPCODE::WCLS: WriteTodo(code_gen, md.GetEntityName(), "WCLS"); break;
-        case OPCODE::WSIZW: WriteTodo(code_gen, md.GetEntityName(), "WSIZW"); break;
-        case OPCODE::WSPCL: WriteTodo(code_gen, md.GetEntityName(), "WSPCL"); break;
-        case OPCODE::WNUMB: WriteTodo(code_gen, md.GetEntityName(), "WNUMB"); break;
-        case OPCODE::STTIM: WriteTodo(code_gen, md.GetEntityName(), "STTIM"); break;
-        case OPCODE::MESSAGE: ProcessMESSAGE(code_gen, eng.ScriptName()); break;
-        case OPCODE::MPARA: WriteTodo(code_gen, md.GetEntityName(), "MPARA"); break;
-        case OPCODE::MPRA2: WriteTodo(code_gen, md.GetEntityName(), "MPRA2"); break;
-        case OPCODE::MPNAM: ProcessMPNAM(code_gen); break;
-        case OPCODE::ASK: WriteTodo(code_gen, md.GetEntityName(), "ASK"); break;
-        case OPCODE::MENU: WriteTodo(code_gen, md.GetEntityName(), "MENU"); break;
-        case OPCODE::MENU2: ProcessMENU2(code_gen); break;
-        case OPCODE::WINDOW: ProcessWINDOW(code_gen); break;
-        case OPCODE::WMOVE: WriteTodo(code_gen, md.GetEntityName(), "WMOVE"); break;
-        case OPCODE::WMODE: WriteTodo(code_gen, md.GetEntityName(), "WMODE"); break;
-        case OPCODE::WREST: WriteTodo(code_gen, md.GetEntityName(), "WREST"); break;
-        case OPCODE::WCLSE: ProcessWCLSE(code_gen); break;
-        case OPCODE::WROW: WriteTodo(code_gen, md.GetEntityName(), "WROW"); break;
-        case OPCODE::GWCOL: WriteTodo(code_gen, md.GetEntityName(), "GWCOL"); break;
-        case OPCODE::SWCOL: WriteTodo(code_gen, md.GetEntityName(), "SWCOL"); break;
+        case OPCODES::TUTOR: code_gen->WriteTodo(md.GetEntityName(), "TUTOR"); break;
+        case OPCODES::WCLS: code_gen->WriteTodo(md.GetEntityName(), "WCLS"); break;
+        case OPCODES::WSIZW: code_gen->WriteTodo(md.GetEntityName(), "WSIZW"); break;
+        case OPCODES::WSPCL: code_gen->WriteTodo(md.GetEntityName(), "WSPCL"); break;
+        case OPCODES::WNUMB: code_gen->WriteTodo(md.GetEntityName(), "WNUMB"); break;
+        case OPCODES::STTIM: code_gen->WriteTodo(md.GetEntityName(), "STTIM"); break;
+        case OPCODES::MESSAGE: ProcessMESSAGE(code_gen, eng.GetScriptName()); break;
+        case OPCODES::MPARA: code_gen->WriteTodo(md.GetEntityName(), "MPARA"); break;
+        case OPCODES::MPRA2: code_gen->WriteTodo(md.GetEntityName(), "MPRA2"); break;
+        case OPCODES::MPNAM: ProcessMPNAM(code_gen); break;
+        case OPCODES::ASK: code_gen->WriteTodo(md.GetEntityName(), "ASK"); break;
+        case OPCODES::MENU: code_gen->WriteTodo(md.GetEntityName(), "MENU"); break;
+        case OPCODES::MENU2: ProcessMENU2(code_gen); break;
+        case OPCODES::WINDOW: ProcessWINDOW(code_gen); break;
+        case OPCODES::WMOVE: code_gen->WriteTodo(md.GetEntityName(), "WMOVE"); break;
+        case OPCODES::WMODE: code_gen->WriteTodo(md.GetEntityName(), "WMODE"); break;
+        case OPCODES::WREST: code_gen->WriteTodo(md.GetEntityName(), "WREST"); break;
+        case OPCODES::WCLSE: ProcessWCLSE(code_gen); break;
+        case OPCODES::WROW: code_gen->WriteTodo(md.GetEntityName(), "WROW"); break;
+        case OPCODES::GWCOL: code_gen->WriteTodo(md.GetEntityName(), "GWCOL"); break;
+        case OPCODES::SWCOL: code_gen->WriteTodo(md.GetEntityName(), "SWCOL"); break;
         default:
         default:
-            code_gen->AddOutputLine(FieldCodeGenerator::FormatInstructionNotImplemented(
+            code_gen->AddOutputLine(FF7::FieldCodeGenerator::FormatInstructionNotImplemented(
               md.GetEntityName(), _address, _opcode
               md.GetEntityName(), _address, _opcode
             ));
             ));
     }
     }
 }
 }
 
 
-void FieldWindowInstruction::ProcessWINDOW(CodeGenerator* code_gen){
-    // Init a new window. It won't be displayed until MESSAGE is used.
+void FF7::FieldWindowInstruction::ProcessWINDOW(CodeGenerator* code_gen){
+    // Initializes a new window. It won't be displayed until MESSAGE is used.
     auto windowId = _params[0]->getUnsigned();
     auto windowId = _params[0]->getUnsigned();
     auto x = _params[1]->getUnsigned();
     auto x = _params[1]->getUnsigned();
     auto y = _params[2]->getUnsigned();
     auto y = _params[2]->getUnsigned();
@@ -68,7 +71,7 @@ void FieldWindowInstruction::ProcessWINDOW(CodeGenerator* code_gen){
     ).str());
     ).str());
 }
 }
 
 
-void FieldWindowInstruction::ProcessMESSAGE(
+void FF7::FieldWindowInstruction::ProcessMESSAGE(
   CodeGenerator* code_gen, const std::string& script_name
   CodeGenerator* code_gen, const std::string& script_name
 ){
 ){
     // Displays a dialog in the WINDOW that has previously been initialized to display this dialog.
     // Displays a dialog in the WINDOW that has previously been initialized to display this dialog.
@@ -81,23 +84,24 @@ void FieldWindowInstruction::ProcessMESSAGE(
     code_gen->AddOutputLine(
     code_gen->AddOutputLine(
       (boost::format("dialog:dialog_wait_for_close(\"%1%\")") % window_id).str()
       (boost::format("dialog:dialog_wait_for_close(\"%1%\")") % window_id).str()
     );
     );
+
 }
 }
 
 
-void FieldWindowInstruction::ProcessWCLSE(CodeGenerator* code_gen){
+void FF7::FieldWindowInstruction::ProcessWCLSE(CodeGenerator* code_gen){
     // Close a dialog.
     // Close a dialog.
     auto windowId = _params[0]->getUnsigned();
     auto windowId = _params[0]->getUnsigned();
     code_gen->AddOutputLine((boost::format("dialog:dialog_close(\"%1%\")") % windowId).str());
     code_gen->AddOutputLine((boost::format("dialog:dialog_close(\"%1%\")") % windowId).str());
 }
 }
 
 
-void FieldWindowInstruction::ProcessMPNAM(CodeGenerator* code_gen){
+void FF7::FieldWindowInstruction::ProcessMPNAM(CodeGenerator* code_gen){
     code_gen->AddOutputLine(
     code_gen->AddOutputLine(
       (boost::format("-- field:map_name(%1%)") % _params[0]->getUnsigned()).str()
       (boost::format("-- field:map_name(%1%)") % _params[0]->getUnsigned()).str()
     );
     );
 }
 }
 
 
-void FieldWindowInstruction::ProcessMENU2(CodeGenerator* code_gen){
+void FF7::FieldWindowInstruction::ProcessMENU2(CodeGenerator* code_gen){
     code_gen->AddOutputLine((
     code_gen->AddOutputLine((
       boost::format("-- field:menu_lock(%1%)")
       boost::format("-- field:menu_lock(%1%)")
-      % FieldCodeGenerator::FormatBool(_params[0]->getUnsigned())
+      % FF7::FieldCodeGenerator::FormatBool(_params[0]->getUnsigned())
     ).str());
     ).str());
 }
 }

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

@@ -29,10 +29,6 @@ void setOutputStackEffect(bool value) {
 	outputStackEffect = value;
 	outputStackEffect = value;
 }
 }
 
 
-void Instruction::WriteTodo(CodeGenerator *code_gen, std::string owner, std::string instruction){
-    code_gen->AddOutputLine("-- Todo(\"" + instruction + "\")");
-}
-
 bool Instruction::isJump() const {
 bool Instruction::isJump() const {
 	return isCondJump() || IsUncondJump();
 	return isCondJump() || IsUncondJump();
 }
 }
@@ -156,7 +152,7 @@ void KernelCallStackInstruction::ProcessInst(Function&, ValueStack &stack, Engin
 	bool returnsValue = (_codeGenData.find("r") == 0);
 	bool returnsValue = (_codeGenData.find("r") == 0);
 	std::string metadata = (!returnsValue ? _codeGenData : _codeGenData.substr(1));
 	std::string metadata = (!returnsValue ? _codeGenData : _codeGenData.substr(1));
 	for (size_t i = 0; i < metadata.length(); i++)
 	for (size_t i = 0; i < metadata.length(); i++)
-		codeGen->processSpecialMetadata(this, metadata[i], i);
+		codeGen->ProcessSpecialMetadata(this, metadata[i], i);
 	stack.push(new CallValue(_name, codeGen->_argList));
 	stack.push(new CallValue(_name, codeGen->_argList));
 	if (!returnsValue) {
 	if (!returnsValue) {
 		std::stringstream stream;
 		std::stringstream stream;

+ 40 - 38
V-Gears-Installer/src/decompiler/sudm.cpp

@@ -15,54 +15,56 @@
 
 
 #include "decompiler/sudm.h"
 #include "decompiler/sudm.h"
 
 
+#include "../../include/decompiler/field/FieldCodeGenerator.h"
 #include "../../include/decompiler/field/FieldDisassembler.h"
 #include "../../include/decompiler/field/FieldDisassembler.h"
 #include "../../include/decompiler/field/FieldEngine.h"
 #include "../../include/decompiler/field/FieldEngine.h"
-#include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/control_flow.h"
 #include "decompiler/control_flow.h"
 
 
 namespace SUDM{
 namespace SUDM{
-    namespace Animation{} // TODO
+    namespace FF7{
+        namespace Animation{} // TODO
 
 
-    namespace AI{} // TODO
+        namespace AI{} // TODO
 
 
-    namespace World{} // TODO
+        namespace World{} // TODO
 
 
-    namespace Field{
+        namespace Field{
 
 
-        float ScaleFactor(const std::vector<unsigned char>& script_bytes){
-            // Could be cleaner, but just does enough work to pull out the fields scale.
-            IScriptFormatter formatter;
-            FieldEngine engine(formatter, "Unused");
-            InstVec insts;
-            engine.GetDisassembler(insts, script_bytes);
-            return engine.GetScaleFactor();
-        }
+            float ScaleFactor(const std::vector<unsigned char>& script_bytes){
+                // Could be cleaner, but just does enough work to pull out the fields scale.
+                IScriptFormatter formatter;
+                ::FF7::FieldEngine engine(formatter, "Unused");
+                InstVec insts;
+                engine.GetDisassembler(insts, script_bytes);
+                return engine.GetScaleFactor();
+            }
 
 
-        DecompiledScript Decompile(
-          std::string script_name, const std::vector<unsigned char>& script_bytes,
-          IScriptFormatter& formatter, std::string text_after, std::string text_before
-        ){
-            // Disassemble the script.
-            FieldEngine engine(formatter, script_name);
-            InstVec insts;
-            auto disassembler = engine.GetDisassembler(insts, script_bytes);
-            disassembler->Disassemble();
-            // Create control flow group.
-            auto control_flow = std::make_unique<ControlFlow>(insts, engine);
-            control_flow->createGroups();
-            // Decompile/analyze
-            //Graph graph = controlFlow->analyze();
-            //engine.PostCFG(insts, graph);
-            Graph graph;
-            DecompiledScript ds;
-            // Generate code and return it.
-            std::stringstream output;
-            auto cg = engine.GetCodeGenerator(insts, output);
-            cg->Generate(insts, graph);
-            ds.luaScript = text_before + output.str() + text_after;
-            for (auto entity : engine.GetEntityList()) ds.entities.push_back(entity);
-            for (auto line : engine.GetLineList()) ds.lines.push_back(line);
-            return ds;
+            DecompiledScript Decompile(
+              std::string script_name, const std::vector<unsigned char>& script_bytes,
+              IScriptFormatter& formatter, std::string text_after, std::string text_before
+            ){
+                // Disassemble the script.
+                ::FF7::FieldEngine engine(formatter, script_name);
+                InstVec insts;
+                auto disassembler = engine.GetDisassembler(insts, script_bytes);
+                disassembler->disassemble();
+                // Create control flow group.
+                auto control_flow = std::make_unique<ControlFlow>(insts, engine);
+                control_flow->createGroups();
+                // Decompile/analyze
+                //Graph graph = controlFlow->analyze();
+                //engine.PostCFG(insts, graph);
+                Graph graph;
+                DecompiledScript ds;
+                // Generate code and return it.
+                std::stringstream output;
+                auto cg = engine.GetCodeGenerator(insts, output);
+                cg->Generate(insts, graph);
+                ds.luaScript = text_before + output.str() + text_after;
+                for (auto entity : engine.GetEntityList()) ds.entities.push_back(entity);
+                for (auto line : engine.GetLineList()) ds.lines.push_back(line);
+                return ds;
+            }
         }
         }
     }
     }
 
 

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

@@ -0,0 +1,44 @@
+/*
+ * 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/world/WorldCodeGenerator.h"
+
+#include "decompiler/world/WorldEngine.h"
+
+FF7::WorldCodeGenerator::WorldCodeGenerator(Engine *engine, std::ostream &output)
+: CodeGenerator(engine, output, FIFO_ARGUMENT_ORDER, LIFO_ARGUMENT_ORDER){}
+
+std::string FF7::WorldCodeGenerator::ConstructFuncSignature(const Function& function){
+    // TODO: Implement.
+    return function._name + " = function(self)";
+}
+
+const InstPtr FF7::WorldCodeGenerator::FindFirstCall(){
+    ConstInstIterator it = cur_group_->start_;
+    do{
+        if ((*it)->IsFuncCall() || (*it)->isKernelCall()) return *it;
+    } while (it ++ != cur_group_->end_);
+    return *cur_group_->start_;
+}
+
+const InstPtr FF7::WorldCodeGenerator::FindLastCall(){
+    ConstInstIterator it = cur_group_->end_;
+    do {
+        if ((*it)->IsFuncCall() || (*it)->isKernelCall()) return *it;
+    } while (it -- != cur_group_->start_);
+    return *cur_group_->end_;
+}
+
+void FF7::WorldCodeGenerator::ProcessSpecialMetadata(const InstPtr inst, char c, int pos){}

+ 573 - 0
V-Gears-Installer/src/decompiler/world/WorldDisassembler.cpp

@@ -0,0 +1,573 @@
+/*
+ * 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 <boost/format.hpp>
+#include "decompiler/world/WorldDisassembler.h"
+#include "decompiler/world/WorldEngine.h"
+#include "decompiler/world/instruction/WorldBinaryEqualStackInstruction.h"
+#include "decompiler/world/instruction/WorldCondJumpInstruction.h"
+#include "decompiler/world/instruction/WorldKernelCallInstruction.h"
+#include "decompiler/world/instruction/WorldLoadBankInstruction.h"
+#include "decompiler/world/instruction/WorldLoadInstruction.h"
+#include "decompiler/world/instruction/WorldNoOutputInstruction.h"
+#include "decompiler/world/instruction/WorldStackInstruction.h"
+#include "decompiler/world/instruction/WorldStoreInstruction.h"
+#include "decompiler/world/instruction/WorldSubStackInstruction.h"
+#include "decompiler/world/instruction/WorldUncondJumpInstruction.h"
+
+FF7::WorldDisassembler::WorldDisassembler(WorldEngine*, InstVec &insts, int script_number)
+  : SimpleDisassembler(insts), script_number_(script_number){}
+
+FF7::WorldDisassembler::~WorldDisassembler(){}
+
+/*
+00000202: reset stack (0)
+00000203: push byte from bank 0 897 (2)
+00000205: jump if false 25 (0)
+
+00000207: reset stack (0)
+00000208: push byte from bank 0 897 (2)
+0000020a: push byte from bank 0 897 (2)
+0000020c: push constant 1 (2)
+0000020e: push sub (2)
+0000020f: write bank (0)
+
+00000210: reset stack (0)
+00000211: push byte from bank 0 897 (2)
+00000213: push constant 0 (2)
+00000215: push equal (2)
+00000216: jump if false 25 (0)
+
+00000218: unknown 320 (0)
+00000219: return (0)
+
+if(!Read(897))
+{
+    Write(897-1)
+    if (!(Read(897) == 0))
+    {
+        unknown320()
+    }
+}
+
+*/
+void FF7::WorldDisassembler::DoDisassemble(){
+    struct WorldScriptData{
+        uint16 type = 0;
+        uint16 instruction_pointer = 0;
+    };
+    std::vector<WorldScriptData> world_data;
+    world_data.reserve(256);
+    for (int i = 0; i < 256; i ++){
+        WorldScriptData tmp;
+        tmp.type = this->stream_->ReadU16();
+        tmp.instruction_pointer = this->stream_->ReadU16();
+        world_data.emplace_back(tmp);
+    }
+    int i = this->script_number_;
+    for (int i = 1; i < 2; i ++){ //for (int i = 1; i < 2; i ++){
+        WorldScriptData data = world_data[i];
+        this->stream_->Seek((256 * sizeof(int)) + (data.instruction_pointer*sizeof(uint16)));
+        this->address_ = this->stream_->GetPosition();
+        bool end = false;
+        for (;;){ //    while (this->_f.pos() != (int)this->_f.size())
+            uint32 full_opcode = 0;
+            uint16 opcode = this->stream_->ReadU16();
+            std::string opcode_prefix;
+            if (end) break;
+            if (opcode == 0x203) end = true;
+            if (opcode >= 0x204 && opcode < 0x300)
+                ParseOpcode(opcode, "reset stack", new WorldKernelCallInstruction(), 0, "");
+            else{
+                switch (opcode){
+                    case 0x100:
+                        ParseOpcode(
+                          opcode, "reset stack", new WorldNoOutputInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x201:
+                        ParseOpcode(
+                          opcode, "jump if false", new WorldCondJumpInstruction(), 0, "w"
+                        );
+                        break;
+                    case 0x203:
+                        ParseOpcode(opcode, "return", new WorldKernelCallInstruction(), 0, "");
+                        break;
+                    case 0x200:
+                        ParseOpcode(opcode, "jump", new WorldUncondJumpInstruction(), 0, "w");
+                        break;
+
+                    case 0x118:
+                        ParseOpcode(
+                          opcode, "push byte from bank 0", new WorldLoadBankInstruction(), 2, "w"
+                        );
+                        break;
+                    case 0x110:
+                        ParseOpcode(opcode, "push constant", new WorldLoadInstruction(), 2, "w");
+                        break;
+                    case 0x119:
+                        ParseOpcode(
+                          opcode, "push byte from bank 1", new WorldLoadBankInstruction(), 2, "w"
+                        );
+                        break;
+                    case 0x11c:
+                        ParseOpcode(
+                          opcode, "push word from bank 0", new WorldLoadBankInstruction(), 2, "w"
+                        );
+                        break;
+                    case 0x114:
+                        ParseOpcode(
+                          opcode, "push bit from bank 0", new WorldLoadBankInstruction(), 2, "w"
+                        );
+                        break;
+                    case 0x11b:
+                        ParseOpcode(
+                          opcode, "push special", new WorldLoadBankInstruction(), 2, "w"
+                        );
+                        break;
+                    case 0x11f:
+                        ParseOpcode(opcode, "push special", new WorldLoadInstruction(), 2, "w");
+                        break;
+                    case 0x117:
+                        ParseOpcode(
+                          opcode, "push special", new WorldLoadBankInstruction(), 2, "w"
+                        );
+                        break;
+
+                    case 0x0e0:
+                        ParseOpcode(opcode, "write bank", new WorldStoreInstruction(), 0, "");
+                        break;
+                    case 0x019:
+                        ParseOpcode(
+                          opcode, "push distance from active entity to entity by model id",
+                          new WorldKernelCallInstruction(), 2, ""
+                        );
+                        break;
+                    case 0x018:
+                        ParseOpcode(
+                          opcode, "push distance from active entity to light",
+                          new WorldKernelCallInstruction(), 2, ""
+                        );
+                        break;
+
+                    case 0x061:
+                        ParseOpcode(opcode, "push greater", new WorldSubStackInstruction(), 2, "");
+                        break;
+                    case 0x0b0:
+                        ParseOpcode(opcode, "push logicand", new WorldSubStackInstruction(), 2, "");
+                        break;
+                    case 0x062:
+                        ParseOpcode(opcode, "push lessequal", new WorldSubStackInstruction(), 2, "");
+                        break;
+                    case 0x030:
+                        ParseOpcode(opcode, "push mul", new WorldSubStackInstruction(), 2, "");
+                        break;
+                    case 0x051:
+                        ParseOpcode(opcode, "push shr", new WorldSubStackInstruction(), 2, "");
+                        break;
+                    case 0x080:
+                        ParseOpcode(opcode, "push and", new WorldSubStackInstruction(), 2, "");
+                        break;
+                    case 0x0a0:
+                        ParseOpcode(opcode, "push or", new WorldSubStackInstruction(), 2, "");
+                        break;
+                    case 0x070:
+                        ParseOpcode(opcode, "push equal", new WorldBinaryEqualStackInstruction(), 2, "");
+                        break;
+                    case 0x041:
+                        ParseOpcode(opcode, "push sub", new WorldSubStackInstruction(), 2, "");
+                        break;
+                    case 0x063:
+                        ParseOpcode(
+                          opcode, "push greaterequal", new WorldSubStackInstruction(), 2, ""
+                        );
+                        break;
+                    case 0x017:
+                        ParseOpcode(opcode, "push logicnot", new WorldSubStackInstruction(), 2, "");
+                        break;
+                    case 0x060:
+                        ParseOpcode(opcode, "push less", new WorldSubStackInstruction(), 2, "");
+                        break;
+                    case 0x0c0:
+                        ParseOpcode(opcode, "push logicor", new WorldSubStackInstruction(), 2, "");
+                        break;
+                    case 0x040:
+                        ParseOpcode(opcode, "push add", new WorldSubStackInstruction(), 2, "");
+                        break;
+                    case 0x015:
+                        ParseOpcode(opcode, "push neg", new WorldSubStackInstruction(), 2, "");
+                        break;
+
+                    case 0x320:
+                        ParseOpcode(
+                          opcode, "unknown 320", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x34a:
+                        ParseOpcode(
+                          opcode, "unknown 34a", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x334:
+                        ParseOpcode(
+                          opcode, "unknown 334", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x33a:
+                        ParseOpcode(
+                          opcode, "unknown 33a", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x31c:
+                        ParseOpcode(
+                          opcode, "unknown 31c", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x32f:
+                        ParseOpcode(
+                          opcode, "unknown 32f", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x339:
+                        ParseOpcode(
+                          opcode, "unknown 339", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x30d:
+                        ParseOpcode(
+                          opcode, "unknown 30d", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x354:
+                        ParseOpcode(
+                          opcode, "unknown 354", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x332:
+                        ParseOpcode(
+                          opcode, "unknown 332", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x31f:
+                        ParseOpcode(
+                          opcode, "unknown 31f", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x329:
+                        ParseOpcode(
+                          opcode, "unknown 329", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x32a:
+                        ParseOpcode(
+                          opcode, "unknown 32a", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x34d:
+                        ParseOpcode(
+                          opcode, "unknown 3d4", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x34e:
+                        ParseOpcode(
+                          opcode, "unknown 3de", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x30a:
+                        ParseOpcode(
+                          opcode, "unknown 30a", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x333:
+                        ParseOpcode(
+                          opcode, "unknown 333", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x331:
+                        ParseOpcode(
+                          opcode, "unknown 331", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x319:
+                        ParseOpcode(
+                          opcode, "unknown 319", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x353:
+                        ParseOpcode(
+                          opcode, "unknown 353", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x33e:
+                        ParseOpcode(
+                          opcode, "unknown 33e", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x321:
+                        ParseOpcode(
+                          opcode, "unknown 321", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+
+                    case 0x31d:
+                        ParseOpcode(
+                          opcode, "play sound effect", new WorldKernelCallInstruction(), 2, "w"
+                        );
+                        break;
+                    case 0x336:
+                        ParseOpcode(
+                          opcode, "set active entity movespeed (honor walkmesh)",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x328:
+                        ParseOpcode(
+                          opcode, "set active entity direction",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x33d:
+                        ParseOpcode(
+                          opcode, "set field entry point2?",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x351:
+                        ParseOpcode(
+                          opcode, "set music volume", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x352:
+                        ParseOpcode(
+                          opcode, "shake camera on / off",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x34f:
+                        ParseOpcode(
+                          opcode, "set active entity y position",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x30b:
+                        ParseOpcode(
+                          opcode, "set active entity y offset",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x347:
+                        ParseOpcode(
+                          opcode, "move active entity to entity by model id ?",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x30e:
+                        ParseOpcode(
+                          opcode, "active entity play animation",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x305:
+                        ParseOpcode(
+                          opcode, "set wait frames", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x306:
+                        ParseOpcode(opcode, "wait?", new WorldKernelCallInstruction(), 0, "");
+                        break;
+                    case 0x307:
+                        ParseOpcode(
+                          opcode, "set control lock", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x303:
+                        ParseOpcode(
+                          opcode, "set active entity movespeed",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x32c:
+                        ParseOpcode(
+                          opcode, "set window parameters",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x32d:
+                        ParseOpcode(
+                          opcode, "wait for window ready",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x324:
+                        ParseOpcode(
+                          opcode, "set window dimensions",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x325:
+                        ParseOpcode(
+                          opcode, "set window message", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x32e:
+                        ParseOpcode(
+                          opcode, "wait for message acknowledge",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x32b:
+                        ParseOpcode(
+                          opcode, "set battle lock", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x326:
+                        ParseOpcode(
+                          opcode, "set window prompt", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x327:
+                        ParseOpcode(
+                          opcode, "wait for prompt acknowledge ?",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x318:
+                        ParseOpcode(
+                          opcode, "enter field scene", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x33b:
+                        ParseOpcode(
+                          opcode, "fade out?", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x348:
+                        ParseOpcode(
+                          opcode, "fade in ?", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x330:
+                        ParseOpcode(
+                          opcode, "set active entity", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x350:
+                        ParseOpcode(
+                          opcode, "set meteor texture on/off",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x34b:
+                        ParseOpcode(
+                          opcode, "set chocobo type", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x34c:
+                        ParseOpcode(
+                          opcode, "set submarine color", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x349:
+                        ParseOpcode(
+                          opcode, "set world progress", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x300:
+                        ParseOpcode(
+                          opcode, "load model", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x302:
+                        ParseOpcode(
+                          opcode, "set player entity", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x30c:
+                        ParseOpcode(
+                          opcode, "enter vehicle?", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x308:
+                        ParseOpcode(
+                          opcode, "set active entity mesh coordinates",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x309:
+                        ParseOpcode(
+                          opcode, "set active entity coordinates in mesh",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x304:
+                        ParseOpcode(
+                          opcode, "set active entity direction & facing",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x310:
+                        ParseOpcode(
+                          opcode, "set active point", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x311:
+                        ParseOpcode(
+                          opcode, "set point mesh coordinates",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x312:
+                        ParseOpcode(
+                          opcode, "set point coordinates in mesh",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x313:
+                        ParseOpcode(
+                          opcode, "set point terrain BGR",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x314:
+                        ParseOpcode(
+                          opcode, "set point dropoff parameters",
+                          new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x315:
+                        ParseOpcode(
+                          opcode, "set point sky BGR", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x316:
+                        ParseOpcode(
+                          opcode, "set point BGR3?", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    case 0x317:
+                        ParseOpcode(
+                          opcode, "trigger battle", new WorldKernelCallInstruction(), 0, ""
+                        );
+                        break;
+                    default:
+                        throw UnknownOpcodeException(this->address_, opcode);
+                }
+            }
+            this->address_ += 2;
+        }
+        for (auto& instruction : this->insts_) instruction->_address = instruction->_address / 2;
+    }
+}
+

+ 61 - 0
V-Gears-Installer/src/decompiler/world/WorldEngine.cpp

@@ -0,0 +1,61 @@
+/*
+ * V-Gears
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
+#include "decompiler/world/WorldCodeGenerator.h"
+#include "decompiler/world/WorldDisassembler.h"
+#include "decompiler/world/WorldEngine.h"
+
+/**
+ * @todo Understand and document
+ */
+#define GET(vertex) (boost::get(boost::vertex_name, g, vertex))
+
+FF7::WorldEngine::BankValue::BankValue(std::string name) : VarValue(name){}
+
+FF7::WorldEngine::WorldEngine(int script_number) : script_number_(script_number){
+    setOutputStackEffect(true);
+}
+
+std::unique_ptr<Disassembler> FF7::WorldEngine::GetDisassembler(InstVec &insts){
+    return std::make_unique<WorldDisassembler>(this, insts, script_number_);
+}
+
+std::unique_ptr<CodeGenerator> FF7::WorldEngine::GetCodeGenerator(
+  const InstVec& insts, std::ostream &output){
+    return std::make_unique<WorldCodeGenerator>(this, output);
+}
+
+void FF7::WorldEngine::PostCFG(InstVec&, Graph graph){
+    /*
+    VertexRange vr = boost::vertices(graph);
+    for (VertexIterator v = vr.first; v != vr.second; ++ v){
+        GroupPtr gr = GET(*v);
+        // If this group is the last instruction and its an unconditional jump
+        if ((*gr->_start)->_address == insts.back()->_address && insts.back()->IsUncondJump()){
+            // Then assume its an infinite do { } while(true) loop that wraps part of the script
+            gr->_type = kDoWhileCondGroupType;
+        }
+    }*/
+}
+
+void FF7::WorldEngine::GetVariants(std::vector<std::string>&) const{}
+
+bool FF7::WorldEngine::UsePureGrouping() const {return false;}

+ 0 - 35
V-Gears-Installer/src/decompiler/world/ff7_world_codegen.cpp

@@ -1,35 +0,0 @@
-#include "ff7_world_codegen.h"
-#include "ff7_world_engine.h"
-
-std::string FF7::FF7WorldCodeGenerator::ConstructFuncSignature(const Function&)
-{
-    return "";
-}
-
-const InstPtr FF7::FF7WorldCodeGenerator::findFirstCall()
-{
-    ConstInstIterator it = mCurGroup->_start;
-    do
-    {
-        if ((*it)->IsFuncCall() || (*it)->isKernelCall())
-            return *it;
-    } while (it++ != mCurGroup->_end);
-
-    return *mCurGroup->_start;
-}
-
-const InstPtr FF7::FF7WorldCodeGenerator::findLastCall()
-{
-    ConstInstIterator it = mCurGroup->_end;
-    do {
-        if ((*it)->IsFuncCall() || (*it)->isKernelCall())
-            return *it;
-    } while (it-- != mCurGroup->_start);
-
-    return *mCurGroup->_end;
-}
-
-void FF7::FF7WorldCodeGenerator::processSpecialMetadata(const InstPtr inst, char, int)
-{
-
-}

+ 0 - 229
V-Gears-Installer/src/decompiler/world/ff7_world_disassembler.cpp

@@ -1,229 +0,0 @@
-#include "ff7_world_disassembler.h"
-#include "ff7_world_engine.h"
-#include "decompiler_engine.h"
-#include <boost/format.hpp>
-
-FF7::FF7WorldDisassembler::FF7WorldDisassembler(FF7WorldEngine*, InstVec &insts, int scriptNumber)
-    : SimpleDisassembler(insts), mScriptNumber(scriptNumber)
-{
-
-}
-
-FF7::FF7WorldDisassembler::~FF7WorldDisassembler()
-{
-
-}
-
-/*
-00000202: reset stack (0)
-00000203: push byte from bank 0 897 (2)
-00000205: jump if false 25 (0)
-
-00000207: reset stack (0)
-00000208: push byte from bank 0 897 (2)
-0000020a: push byte from bank 0 897 (2)
-0000020c: push constant 1 (2)
-0000020e: push sub (2)
-0000020f: write bank (0)
-
-00000210: reset stack (0)
-00000211: push byte from bank 0 897 (2)
-00000213: push constant 0 (2)
-00000215: push equal (2)
-00000216: jump if false 25 (0)
-
-00000218: unknown 320 (0)
-00000219: return (0)
-
-if(!Read(897))
-{
-    Write(897-1)
-    if (!(Read(897) == 0))
-    {
-        unknown320()
-    }
-}
-
-*/
-void FF7::FF7WorldDisassembler::DoDisassemble()
-{
-    struct wmScriptData
-    {
-        uint16 mType = 0;
-        uint16 mInstructionPointer = 0;
-    };
-
-    std::vector<wmScriptData> mData;
-    mData.reserve(256);
-
-    for (int i = 0; i < 256; i++)
-    {
-        wmScriptData tmp;
-        tmp.mType = this->stream_->ReadU16();
-        tmp.mInstructionPointer = this->stream_->ReadU16();
-        mData.emplace_back(tmp);
-    }
-
-
-    int i = this->mScriptNumber;
-  //  for (int i = 1; i < 256; i++)
-    {
-        wmScriptData data = mData[i];
-
-        this->stream_->Seek((256 * sizeof(int)) + (data.mInstructionPointer*sizeof(uint16)));
-        this->_address = this->stream_->Position();
-
-        bool end = false;
-        //    while (this->_f.pos() != (int)this->_f.size())
-        for (;;)
-        {
-            uint32 full_opcode = 0;
-            uint16 opcode = this->stream_->ReadU16();
-            std::string opcodePrefix;
-            if (end)
-            {
-                break;
-            }
-            if (opcode == 0x203)
-            {
-                end = true;
-            }
-
-            if (opcode >= 0x204 && opcode < 0x300)
-            {
-                this->_insts.push_back(new FF7WorldKernelCallInstruction());
-                this->_insts.back()->_opcode = opcode;
-                this->_insts.back()->_address = this->_address;
-                this->_insts.back()->_stackChange = 0;
-                this->_insts.back()->_name = std::string("function call");
-                this->_insts.back()->_codeGenData = "";
-                this->readParams(this->_insts.back(), "");
-            }
-            else
-            {
-                switch (opcode)
-                {
-                case 0x100:
-                    this->_insts.push_back(new FF7WorldNoOutputInstruction());
-                    this->_insts.back()->_opcode = 0x100;
-                    this->_insts.back()->_address = this->_address;
-                    this->_insts.back()->_stackChange = 0;
-                    this->_insts.back()->_name = std::string("reset stack");
-                    this->_insts.back()->_codeGenData = "";
-                    this->readParams(this->_insts.back(), "");
-                    break;
-
-                    OPCODE(0x201, "jump if false", FF7WorldCondJumpInstruction, 0, "w"); 
-                    OPCODE(0x203, "return", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x200, "jump", FF7WorldUncondJumpInstruction, 0, "w");
-
-                    OPCODE(0x118, "push byte from bank 0", FF7WorldLoadBankInstruction, 2, "w");
-                    OPCODE(0x110, "push constant", FF7WorldLoadInstruction, 2, "w");
-                    OPCODE(0x119, "push byte from bank 1", FF7WorldLoadBankInstruction, 2, "w");
-                    OPCODE(0x11c, "push word from bank 0", FF7WorldLoadBankInstruction, 2, "w");
-                    OPCODE(0x114, "push bit from bank 0", FF7WorldLoadBankInstruction, 2, "w");
-                    OPCODE(0x11b, "push special", FF7WorldLoadBankInstruction, 2, "w");
-                    OPCODE(0x11f, "push special", FF7WorldLoadInstruction, 2, "w");
-                    OPCODE(0x117, "push special", FF7WorldLoadBankInstruction, 2, "w");
-           
-                    OPCODE(0x0e0, "write bank", FF7WorldStoreInstruction, 0, "");
-                    OPCODE(0x019, "push distance from active entity to entity by model id", FF7WorldKernelCallInstruction, 2, "");
-                    OPCODE(0x018, "push distance from active entity to light", FF7WorldKernelCallInstruction, 2, "");
-
-                    OPCODE(0x061, "push greater", FF7SubStackInstruction, 2, "");
-                    OPCODE(0x0b0, "push logicand", FF7SubStackInstruction, 2, "");
-                    OPCODE(0x062, "push lessequal", FF7SubStackInstruction, 2, "");
-                    OPCODE(0x030, "push mul", FF7SubStackInstruction, 2, "");
-                    OPCODE(0x051, "push shr", FF7SubStackInstruction, 2, "");
-                    OPCODE(0x080, "push and", FF7SubStackInstruction, 2, "");
-                    OPCODE(0x0a0, "push or", FF7SubStackInstruction, 2, "");
-                    OPCODE(0x070, "push equal", BinaryEqualStackInstruction, 2, "");
-                    OPCODE(0x041, "push sub", FF7SubStackInstruction, 2, "");
-                    OPCODE(0x063, "push greaterequal", FF7SubStackInstruction, 2, "")
-                    OPCODE(0x017, "push logicnot", FF7SubStackInstruction, 2, "");
-                    OPCODE(0x060, "push less", FF7SubStackInstruction, 2, "");
-                    OPCODE(0x0c0, "push logicor", FF7SubStackInstruction, 2, "");
-                    OPCODE(0x040, "push add", FF7SubStackInstruction, 2, "");
-                    OPCODE(0x015, "push neg", FF7SubStackInstruction, 2, "");
-
-                    OPCODE(0x320, "unknown 320", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x34a, "unknown 34a", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x334, "unknown 334", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x33a, "unknown 33a", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x31c, "unknown 31c", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x32f, "unknown 32f", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x339, "unknown 339", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x30d, "unknown 30d", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x354, "unknown 354", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x332, "unknown 332", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x31f, "unknown 31f", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x329, "unknown 329", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x32a, "unknown 32a", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x34d, "unknown 3d4", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x34e, "unknown 3de", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x30a, "unknown 30a", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x333, "unknown 333", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x331, "unknown 331", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x319, "unknown 319", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x353, "unknown 353", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x33e, "unknown 33e", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x321, "unknown 321", FF7WorldKernelCallInstruction, 0, "");
-
-                    OPCODE(0x31d, "play sound effect", FF7WorldKernelCallInstruction, 2, "w");
-                    OPCODE(0x336, "set active entity movespeed (honor walkmesh)", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x328, "set active entity direction", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x33d, "set field entry point2?", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x351, "set music volume", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x352, "shake camera on / off", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x34f, "set active entity y position", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x30b, "set active entity y offset", FF7WorldKernelCallInstruction, 0, "");                   
-                    OPCODE(0x347, "move active entity to entity by model id ?", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x30e, "active entity play animation", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x305, "set wait frames", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x306, "wait?", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x307, "set control lock", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x303, "set active entity movespeed", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x32c, "set window parameters", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x32d, "wait for window ready", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x324, "set window dimensions", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x325, "set window message", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x32e, "wait for message acknowledge", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x32b, "set battle lock", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x326, "set window prompt", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x327, "wait for prompt acknowledge ?", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x318, "enter field scene", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x33b, "fade out?", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x348, "fade in ?", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x330, "set active entity", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x350, "set meteor texture on/off", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x34b, "set chocobo type", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x34c, "set submarine color", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x349, "set world progress", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x300, "load model", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x302, "set player entity", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x30c, "enter vehicle?", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x308, "set active entity mesh coordinates", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x309, "set active entity coordinates in mesh", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x304, "set active entity direction & facing", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x310, "set active point", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x311, "set point mesh coordinates", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x312, "set point coordinates in mesh", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x313, "set point terrain BGR", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x314, "set point dropoff parameters", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x315, "set point sky BGR", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x316, "set point BGR3?", FF7WorldKernelCallInstruction, 0, "");
-                    OPCODE(0x317, "trigger battle", FF7WorldKernelCallInstruction, 0, "");
-                default:
-                    throw UnknownOpcodeException(this->_address, opcode);
-                }
-            }
-            this->_address += 2;
-        }
-
-        for (auto& instruction : this->_insts)
-        {
-            instruction->_address = instruction->_address / 2;
-        }
-    }
-}
-

+ 0 - 469
V-Gears-Installer/src/decompiler/world/ff7_world_engine.cpp

@@ -1,469 +0,0 @@
-#include "ff7_world_engine.h"
-#include "ff7_world_disassembler.h"
-#include "ff7_world_codegen.h" 
-
-#include <iostream>
-#include <sstream>
-#include <boost/format.hpp>
-
-#define GET(vertex) (boost::get(boost::vertex_name, g, vertex))
-
-std::unique_ptr<Disassembler> FF7::FF7WorldEngine::GetDisassembler(InstVec &insts)
-{
-    return std::make_unique<FF7WorldDisassembler>(this, insts, mScriptNumber);
-}
-
-std::unique_ptr<CodeGenerator> FF7::FF7WorldEngine::GetCodeGenerator(const InstVec& /*insts*/, std::ostream &output)
-{
-    return std::make_unique<FF7WorldCodeGenerator>(this, output);
-}
-
-void FF7::FF7WorldEngine::PostCFG(InstVec&, Graph g)
-{
-    /*
-    VertexRange vr = boost::vertices(g);
-    for (VertexIterator v = vr.first; v != vr.second; ++v) 
-    {
-        GroupPtr gr = GET(*v);
-
-        // If this group is the last instruction and its an unconditional jump
-        if ((*gr->_start)->_address == insts.back()->_address && insts.back()->IsUncondJump())
-        {
-            // Then assume its an infinite do { } while(true) loop that wraps part of the script
-            gr->_type = kDoWhileCondGroupType;
-        }
-    }*/
-}
-
-void FF7::FF7WorldEngine::getVariants(std::vector<std::string>&) const
-{
-
-}
-
-void FF7::FF7WorldLoadBankInstruction::ProcessInst(Function&, ValueStack &stack, Engine*, CodeGenerator*)
-{
-    stack.push(new BankValue("Read(" + _params[0]->getString() + ")"));
-}
-
-void FF7::FF7WorldLoadInstruction::ProcessInst(Function&, ValueStack &stack, Engine*, CodeGenerator*)
-{
-    stack.push(new VarValue(_params[0]->getString()));
-}
-
-void FF7::FF7SubStackInstruction::ProcessInst(Function&, ValueStack &stack, Engine*, CodeGenerator*)
-{
-    std::string op;
-    switch (_opcode)
-    {
-    case 0x41:
-        op = "-";
-        break;
-
-    case 0x40:
-        op = "+";
-        break;
-
-    case 0x80:
-        op = "&&";
-        break;
-
-    case 0xa0:
-        op = "||";
-        break;
-
-    case 0xc0:
-        op = "|";
-        break;
-
-    case 0x15: // neg
-    case 0x17: // not
-        stack.push(stack.pop()->negate());
-        return;
-
-    case 0x30:
-        op = "*";
-        break;
-
-    case 0x60:
-        op = "<";
-        break;
-
-    case 0x61:
-        op = ">";
-        break;
-
-    case 0x62:
-        op = "<=";
-        break;
-
-    case 0x63:
-        op = ">=";
-        break;
-
-    case 0x0b0:
-        op = "&";
-        break;
-
-    case 0x51:
-        op = "<<";
-        break;
-
-    default:
-        op = "unknown_operation";
-    }
-
-    std::string strValue = stack.pop()->getString() + " " + op + " " + stack.pop()->getString();
-    stack.push(new VarValue(strValue));
-}
-
-void FF7::FF7WorldStoreInstruction::ProcessInst(Function&, ValueStack &stack, Engine*, CodeGenerator *codeGen)
-{
-    std::string strValue = stack.pop()->getString();
-
-    // If the bank address is from a load bank instruction, then we only want
-    // the bank address, not whats *at* the bank address
-    ValuePtr bankValue = stack.pop();
-    std::string bankAddr = bankValue->getString();
-    codeGen->AddOutputLine("Write(" + bankAddr + ", " + strValue + ");");
-}
-
-void FF7::FF7WorldStackInstruction::ProcessInst(Function&, ValueStack&, Engine*, CodeGenerator*)
-{
-
-}
-
-void FF7::FF7WorldCondJumpInstruction::ProcessInst(Function&, ValueStack&, Engine*, CodeGenerator*)
-{
-
-}
-
-uint32 FF7::FF7WorldCondJumpInstruction::GetDestAddress() const
-{
-    return 0x200 + _params[0]->getUnsigned();
-}
-
-std::ostream& FF7::FF7WorldCondJumpInstruction::print(std::ostream &output) const
-{
-    Instruction::print(output);
-    return output;
-}
-
-
-bool FF7::FF7WorldUncondJumpInstruction::IsFuncCall() const
-{
-	return _isCall;
-}
-
-bool FF7::FF7WorldUncondJumpInstruction::IsUncondJump() const
-{
-	return !_isCall;
-}
-
-uint32 FF7::FF7WorldUncondJumpInstruction::GetDestAddress() const
-{
-    // the world map while loops are incorrect without +1'in this, but
-    // doing that will break some if elses.. hmm
-    return 0x200 + _params[0]->getUnsigned();// +1; // TODO: +1 to skip param?
-}
-
-std::ostream& FF7::FF7WorldUncondJumpInstruction::print(std::ostream &output) const
-{
-    Instruction::print(output);
- //   output << " (Jump target address: 0x" << std::hex << GetDestAddress() << std::dec << ")";
-    return output;
-}
-
-
-void FF7::FF7WorldUncondJumpInstruction::ProcessInst(Function& , ValueStack&, Engine*, CodeGenerator*)
-{
-
-}
-
-void FF7::FF7WorldKernelCallInstruction::ProcessInst(Function& , ValueStack &stack, Engine*, CodeGenerator *codeGen)
-{
-    std::string strFunc;
-    switch (_opcode)
-    {
-    case 0x203:
-        strFunc = "return;";
-        break;
-
-    case 0x317:
-        strFunc = "TriggerBattle(" + stack.pop()->getString() + ");";
-        break;
-
-    case 0x324:
-        // x, y, w, h
-        strFunc = "SetWindowDimensions(" + 
-            stack.pop()->getString() + ", " +
-            stack.pop()->getString() + ", " +
-            stack.pop()->getString() + ", " +
-            stack.pop()->getString() + ");";
-        break;
-
-    case 0x32D:
-        strFunc = "WaitForWindowReady();";
-        break;
-
-    case 0x325:
-        strFunc = "SetWindowMessage(" + stack.pop()->getString() + ");";
-        break;
-
-    case 0x333:
-        strFunc = "Unknown333(" +
-            stack.pop()->getString() + ", " +
-            stack.pop()->getString() + ");";
-        break;
-
-    case 0x308:
-        strFunc = "SetActiveEntityMeshCoordinates(" +
-            stack.pop()->getString() + ", " +
-            stack.pop()->getString() + ");";
-        break;
-
-    case 0x309:
-        strFunc = "SetActiveEntityMeshCoordinatesInMesh(" +
-            stack.pop()->getString() + ", " +
-            stack.pop()->getString() + ");";
-        break;
-
-    case 0x32e:
-        strFunc = "WaitForMessageAcknowledge();";
-        break;
-
-    case 0x32c:
-        // Mode, Permanency
-        strFunc = "SetWindowParameters(" +
-            stack.pop()->getString() + ", " +
-            stack.pop()->getString() + ");";
-        break;
-
-    case 0x318:
-        strFunc = "EnterFieldScene(" +
-            stack.pop()->getString() + ", " +
-            stack.pop()->getString() + ");";
-        break;
-
-    case 0x348:
-        strFunc = "FadeIn(" +
-            stack.pop()->getString() + ", " +
-            stack.pop()->getString() + ");";
-        break;
-
-    case 0x33b:
-        strFunc = "FadeOut(" +
-            stack.pop()->getString() + ", " +
-            stack.pop()->getString() + ");";
-        break;
-
-    case 0x310:
-        strFunc = "SetActivePoint(" +
-            stack.pop()->getString() + ", " +
-            stack.pop()->getString() + ");";
-        break;
-
-    case 0x311:
-        strFunc = "SetLightMeshCoordinates(" +
-            stack.pop()->getString() + ", " +
-            stack.pop()->getString() + ");";
-        break;
-
-    case 0x312:
-        strFunc = "SetLightMeshCoordinatesInMesh(" +
-            stack.pop()->getString() + ", " +
-            stack.pop()->getString() + ");";
-        break;
-
-    case 0x31D:
-        strFunc = "PlaySoundEffect(" + stack.pop()->getString() + ");";
-        break;
-
-    case 0x328:
-        strFunc = "SetActiveEntityDirection(" + stack.pop()->getString() + ");";
-        break;
-
-    case 0x336: // honours walk mesh
-    case 0x303:
-        strFunc = "SetActiveEntityMovespeed(" + stack.pop()->getString() + ");";
-        break;
-
-    case 0x304:
-        strFunc = "SetActiveEntityDirectionAndFacing(" + stack.pop()->getString() + ");";
-        break;
-
-    case 0x32b:
-        strFunc = "SetBattleLock(" + stack.pop()->getString() + ");";
-        break;
-
-    case 0x305:
-        strFunc = "SetWaitFrames(" + stack.pop()->getString() + ");";
-        break;
-
-    case 0x33e:
-        strFunc = "Unknown_AKAO(" + stack.pop()->getString() + ");";
-        break;
-
-    case 0x306:
-        strFunc = "Wait();";
-        break;
-
-    case 0x350:
-        strFunc = "SetMeteorTexture(" + stack.pop()->getString() + ");";
-        break;
-
-    case 0x34b:
-    {
-        std::string type = stack.pop()->getString();
-        switch (std::stoi(type))
-        {
-        case 0:
-            type = "yellow";
-            break;
-
-        case 1:
-            type = "green";
-            break;
-
-        case 2:
-            type = "blue";
-            break;
-
-        case 3:
-            type = "black";
-            break;
-
-        case 4:
-            type = "gold";
-            break;
-        }
-        strFunc = "SetChocoboType(" + type + ");";
-    }
-        break;
-
-    case 0x34c:
-    {
-        std::string type = stack.pop()->getString();
-        switch (std::stoi(type))
-        {
-        case 0:
-            type = "red";
-            break;
-
-        case 1:
-            type = "blue";
-            break;
-
-        // Hack - not really supported, but works
-        case -1:
-            type = "gold";
-            break;
-
-        case -2:
-            type = "black";
-            break;
-        }
-        strFunc = "SetSubmarineColor(" + type + ");";
-    }
-    break;
-
-    case 0x349:
-    {
-        std::string type = stack.pop()->getString();
-        std::string comment = "// ";
-        switch (std::stoi(type))
-        {
-        case 0:
-            comment += "before temple of the ancients,";
-            break;
-
-        case 1:
-            comment += "after temple of the ancients";
-            break;
-
-        case 2:
-            comment += " after ultimate weapon appears,";
-            break;
-
-        case 3:
-            comment += "after mideel";
-            break;
-
-        case 4:
-            comment += "after ultimate weapon killed";
-            break;
-
-        default:
-            comment += "??";
-            break;
-        }
-        strFunc = "SetWorldProgress(" + type + "); "  +comment;
-    }
-        break;
-
-    case 0x300:
-    {
-        std::string type = stack.pop()->getString();
-        std::string comment = "// ";
-        try
-        {
-            switch (std::stoi(type))
-            {
-            case 0: comment += "Cloud"; break;
-            case 1: comment += "Tifa?"; break;
-            case 2: comment += "Cid?"; break;
-            case 3: comment += "Ultimate Weapon"; break;
-            case 4: comment += "Unknown"; break;
-            case 5: comment += "Unknown"; break;
-            case 6: comment += "Unknown"; break;
-            case 7: comment += "Unknown"; break;
-            case 8: comment += "Unknown"; break;
-            case 9: comment += "Unknown"; break;
-            case 10: comment += "Unknown"; break;
-            case 11: comment += "Highwind"; break;
-            case 12: comment += "Unknown"; break;
-            case 13: comment += "Submarine"; break;
-            case 14: comment += "Unknown"; break;
-            case 15: comment += "Unknown"; break;
-            case 16: comment += "Unknown"; break;
-            case 17: comment += "Unknown"; break;
-            case 18: comment += "Unknown"; break;
-            case 19: comment += "Chocobo"; break;
-            case 20: comment += "Unknown"; break;
-            case 21: comment += "Unknown"; break;
-            case 22: comment += "Unknown"; break;
-            case 23: comment += "Unknown"; break;
-            case 24: comment += "Unknown"; break;
-            case 25: comment += "Unknown"; break;
-
-            default:
-                comment += "??";
-                break;
-            }
-        }
-        catch (std::invalid_argument&)
-        {
-
-        }
-        strFunc = "LoadModel(" + type + "); " + comment;
-    }
-        break;
-
-    case 0x307:
-        strFunc = "SetControlLock(" + stack.pop()->getString() + ");";
-        break;
-
-    case 0x30c:
-        strFunc = "EnterVehicle();";
-        break;
-
-    default:
-        strFunc = "kernel_unknown_" + AddressValue(_opcode).getString() + "();";
-        break;
-    }
-    codeGen->AddOutputLine(strFunc);
-}
-
-void FF7::FF7WorldNoOutputInstruction::ProcessInst(Function&, ValueStack&, Engine*, CodeGenerator*)
-{
-
-}

+ 33 - 0
V-Gears-Installer/src/decompiler/world/instruction/WorldBinaryEqualStackInstruction.cpp

@@ -0,0 +1,33 @@
+
+/*
+ * V-Gears
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
+#include "decompiler/world/instruction/WorldBinaryEqualStackInstruction.h"
+#include "decompiler/world/WorldEngine.h"
+#include "decompiler/world/WorldCodeGenerator.h"
+#include "decompiler/world/WorldDisassembler.h"
+
+void FF7::WorldBinaryEqualStackInstruction::ProcessInst(
+    Function& function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+){
+    _codeGenData = "==";
+    BinaryOpStackInstruction::ProcessInst(function, stack, engine, code_gen);
+}

+ 39 - 0
V-Gears-Installer/src/decompiler/world/instruction/WorldCondJumpInstruction.cpp

@@ -0,0 +1,39 @@
+
+/*
+ * V-Gears
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
+#include "decompiler/world/instruction/WorldCondJumpInstruction.h"
+#include "decompiler/world/WorldEngine.h"
+#include "decompiler/world/WorldCodeGenerator.h"
+#include "decompiler/world/WorldDisassembler.h"
+
+void FF7::WorldCondJumpInstruction::ProcessInst(Function&, ValueStack&, Engine*, CodeGenerator*){
+    // TODO
+}
+
+uint32 FF7::WorldCondJumpInstruction::GetDestAddress() const{
+    return 0x200 + _params[0]->getUnsigned();
+}
+
+std::ostream& FF7::WorldCondJumpInstruction::Print(std::ostream &output) const{
+    Instruction::Print(output);
+    return output;
+}

+ 182 - 0
V-Gears-Installer/src/decompiler/world/instruction/WorldKernelCallInstruction.cpp

@@ -0,0 +1,182 @@
+
+/*
+ * V-Gears
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
+#include "decompiler/world/instruction/WorldKernelCallInstruction.h"
+#include "decompiler/world/WorldEngine.h"
+#include "decompiler/world/WorldCodeGenerator.h"
+#include "decompiler/world/WorldDisassembler.h"
+
+void FF7::WorldKernelCallInstruction::ProcessInst(
+    Function& function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+){
+    std::string func;
+    switch (_opcode){
+        case 0x203: func = "return;"; break;
+        case 0x317: func = "TriggerBattle(" + stack.pop()->getString() + ");"; break;
+        case 0x324:
+            // x, y, w, h
+            func = "SetWindowDimensions("
+              + stack.pop()->getString() + ", " + stack.pop()->getString() + ", "
+              + stack.pop()->getString() + ", " + stack.pop()->getString() + ");";
+            break;
+        case 0x32D: func = "WaitForWindowReady();"; break;
+        case 0x325: func = "SetWindowMessage(" + stack.pop()->getString() + ");"; break;
+        case 0x333:
+            func = "Unknown333("
+              + stack.pop()->getString() + ", " + stack.pop()->getString() + ");";
+            break;
+        case 0x308:
+            func = "SetActiveEntityMeshCoordinates("
+              + stack.pop()->getString() + ", " + stack.pop()->getString() + ");";
+            break;
+        case 0x309:
+            func = "SetActiveEntityMeshCoordinatesInMesh("
+              + stack.pop()->getString() + ", " + stack.pop()->getString() + ");";
+            break;
+        case 0x32e: func = "WaitForMessageAcknowledge();"; break;
+        case 0x32c:
+            // Mode, Permanency.
+            func = "SetWindowParameters("
+              + stack.pop()->getString() + ", " + stack.pop()->getString() + ");";
+            break;
+        case 0x318:
+            func = "EnterFieldScene("
+              + stack.pop()->getString() + ", " + stack.pop()->getString() + ");";
+            break;
+        case 0x348:
+            func = "FadeIn(" + stack.pop()->getString() + ", " + stack.pop()->getString() + ");";
+            break;
+        case 0x33b:
+            func = "FadeOut(" + stack.pop()->getString() + ", " + stack.pop()->getString() + ");";
+            break;
+        case 0x310:
+            func = "SetActivePoint("
+              + stack.pop()->getString() + ", " + stack.pop()->getString() + ");";
+            break;
+        case 0x311:
+            func = "SetLightMeshCoordinates("
+              + stack.pop()->getString() + ", " + stack.pop()->getString() + ");";
+            break;
+        case 0x312:
+            func = "SetLightMeshCoordinatesInMesh("
+              + stack.pop()->getString() + ", " + stack.pop()->getString() + ");";
+            break;
+        case 0x31D: func = "PlaySoundEffect(" + stack.pop()->getString() + ");"; break;
+        case 0x328: func = "SetActiveEntityDirection(" + stack.pop()->getString() + ");"; break;
+        case 0x336: // Honor walk mesh.
+        case 0x303:
+            func = "SetActiveEntityMovespeed(" + stack.pop()->getString() + ");";
+            break;
+        case 0x304:
+            func = "SetActiveEntityDirectionAndFacing(" + stack.pop()->getString() + ");";
+            break;
+        case 0x32b: func = "SetBattleLock(" + stack.pop()->getString() + ");"; break;
+        case 0x305: func = "SetWaitFrames(" + stack.pop()->getString() + ");"; break;
+        case 0x33e: func = "Unknown_AKAO(" + stack.pop()->getString() + ");"; break;
+        case 0x306: func = "Wait();"; break;
+        case 0x350: func = "SetMeteorTexture(" + stack.pop()->getString() + ");"; break;
+        case 0x34b:
+            {
+                std::string type = stack.pop()->getString();
+                switch (std::stoi(type)){
+                    case 0: type = "yellow"; break;
+                    case 1: type = "green"; break;
+                    case 2: type = "blue"; break;
+                    case 3: type = "black"; break;
+                    case 4: type = "gold"; break;
+                }
+                func = "SetChocoboType(" + type + ");";
+            }
+            break;
+        case 0x34c:
+            {
+                std::string type = stack.pop()->getString();
+                switch (std::stoi(type)){
+                    case 0: type = "red"; break;
+                    case 1: type = "blue"; break;
+                    // HACK - not really supported, but works.
+                    case -1: type = "gold"; break;
+                    case -2: type = "black"; break;
+                }
+                func = "SetSubmarineColor(" + type + ");";
+            }
+            break;
+        case 0x349:
+            {
+                std::string type = stack.pop()->getString();
+                std::string comment = "// ";
+                switch (std::stoi(type)){
+                    case 0: comment += "before temple of the ancients,"; break;
+                    case 1: comment += "after temple of the ancients"; break;
+                    case 2: comment += " after ultimate weapon appears,"; break;
+                    case 3: comment += "after mideel"; break;
+                    case 4: comment += "after ultimate weapon killed"; break;
+                    default: comment += "??"; break;
+                }
+                func = "SetWorldProgress(" + type + "); "  +comment;
+            }
+            break;
+        case 0x300:
+            {
+                std::string type = stack.pop()->getString();
+                std::string comment = "// ";
+                try{
+                    switch (std::stoi(type)){
+                        case 0: comment += "Cloud"; break;
+                        case 1: comment += "Tifa?"; break;
+                        case 2: comment += "Cid?"; break;
+                        case 3: comment += "Ultimate Weapon"; break;
+                        case 4: comment += "Unknown"; break;
+                        case 5: comment += "Unknown"; break;
+                        case 6: comment += "Unknown"; break;
+                        case 7: comment += "Unknown"; break;
+                        case 8: comment += "Unknown"; break;
+                        case 9: comment += "Unknown"; break;
+                        case 10: comment += "Unknown"; break;
+                        case 11: comment += "Highwind"; break;
+                        case 12: comment += "Unknown"; break;
+                        case 13: comment += "Submarine"; break;
+                        case 14: comment += "Unknown"; break;
+                        case 15: comment += "Unknown"; break;
+                        case 16: comment += "Unknown"; break;
+                        case 17: comment += "Unknown"; break;
+                        case 18: comment += "Unknown"; break;
+                        case 19: comment += "Chocobo"; break;
+                        case 20: comment += "Unknown"; break;
+                        case 21: comment += "Unknown"; break;
+                        case 22: comment += "Unknown"; break;
+                        case 23: comment += "Unknown"; break;
+                        case 24: comment += "Unknown"; break;
+                        case 25: comment += "Unknown"; break;
+                        default: comment += "??"; break;
+                    }
+                }
+                catch (std::invalid_argument&){}
+                func = "LoadModel(" + type + "); " + comment;
+            }
+            break;
+        case 0x307: func = "SetControlLock(" + stack.pop()->getString() + ");"; break;
+        case 0x30c: func = "EnterVehicle();"; break;
+        default: func = "kernel_unknown_" + AddressValue(_opcode).getString() + "();"; break;
+    }
+    code_gen->AddOutputLine(func);
+}

+ 31 - 0
V-Gears-Installer/src/decompiler/world/instruction/WorldLoadBankInstruction.cpp

@@ -0,0 +1,31 @@
+/*
+ * V-Gears
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
+#include "decompiler/world/instruction/WorldLoadBankInstruction.h"
+#include "decompiler/world/WorldEngine.h"
+#include "decompiler/world/WorldCodeGenerator.h"
+#include "decompiler/world/WorldDisassembler.h"
+
+void FF7::WorldLoadBankInstruction::ProcessInst(
+  Function &function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+){
+    stack.push(new WorldEngine::BankValue("Read(" + _params[0]->getString() + ")"));
+}

+ 31 - 0
V-Gears-Installer/src/decompiler/world/instruction/WorldLoadInstruction.cpp

@@ -0,0 +1,31 @@
+/*
+ * V-Gears
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
+#include "decompiler/world/instruction/WorldLoadInstruction.h"
+#include "decompiler/world/WorldEngine.h"
+#include "decompiler/world/WorldCodeGenerator.h"
+#include "decompiler/world/WorldDisassembler.h"
+
+void FF7::WorldLoadInstruction::ProcessInst(
+  Function &function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+){
+    stack.push(new VarValue(_params[0]->getString()));
+}

+ 32 - 0
V-Gears-Installer/src/decompiler/world/instruction/WorldNoOutputInstruction.cpp

@@ -0,0 +1,32 @@
+
+/*
+ * V-Gears
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
+#include "decompiler/world/instruction/WorldNoOutputInstruction.h"
+#include "decompiler/world/WorldEngine.h"
+#include "decompiler/world/WorldCodeGenerator.h"
+#include "decompiler/world/WorldDisassembler.h"
+
+void FF7::WorldNoOutputInstruction::ProcessInst(
+  Function& function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+){
+    // TODO
+}

+ 32 - 0
V-Gears-Installer/src/decompiler/world/instruction/WorldStackInstruction.cpp

@@ -0,0 +1,32 @@
+
+/*
+ * V-Gears
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
+#include "decompiler/world/instruction/WorldStackInstruction.h"
+#include "decompiler/world/WorldEngine.h"
+#include "decompiler/world/WorldCodeGenerator.h"
+#include "decompiler/world/WorldDisassembler.h"
+
+void FF7::WorldStackInstruction::ProcessInst(
+    Function& function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+){
+    // TODO
+}

+ 36 - 0
V-Gears-Installer/src/decompiler/world/instruction/WorldStoreInstruction.cpp

@@ -0,0 +1,36 @@
+
+/*
+ * V-Gears
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
+#include "decompiler/world/instruction/WorldStoreInstruction.h"
+#include "decompiler/world/WorldEngine.h"
+#include "decompiler/world/WorldCodeGenerator.h"
+#include "decompiler/world/WorldDisassembler.h"
+
+void FF7::WorldStoreInstruction::ProcessInst(
+    Function& function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+){
+    std::string value = stack.pop()->getString();
+    // If the bank address is from a load bank instruction, then only
+    // the bank address is needed, not whats *at* the bank address.
+    ValuePtr bank_addr = stack.pop();
+    code_gen->AddOutputLine("Write(" + bank_addr->getString() + ", " + value + ");");
+}

+ 53 - 0
V-Gears-Installer/src/decompiler/world/instruction/WorldSubStackInstruction.cpp

@@ -0,0 +1,53 @@
+/*
+ * V-Gears
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
+#include "decompiler/world/instruction/WorldSubStackInstruction.h"
+#include "decompiler/world/WorldEngine.h"
+#include "decompiler/world/WorldCodeGenerator.h"
+#include "decompiler/world/WorldDisassembler.h"
+
+void FF7::WorldSubStackInstruction::ProcessInst(
+    Function& function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+){
+    std::string op;
+    switch (_opcode){
+        case 0x41: op = "-"; break;
+        case 0x40: op = "+"; break;
+        case 0x80: op = "&&"; break;
+        case 0xa0: op = "||"; break;
+        case 0xc0: op = "|"; break;
+        case 0x15: // neg
+        case 0x17: // not
+            stack.push(stack.pop()->negate());
+            return;
+            break;
+        case 0x30: op = "*";break;
+        case 0x60: op = "<"; break;
+        case 0x61: op = ">"; break;
+        case 0x62: op = "<="; break;
+        case 0x63: op = ">="; break;
+        case 0x0b0: op = "&"; break; // TODO: Review op
+        case 0x51: op = "<<"; break;
+        default:op = "unknown_operation";
+    }
+    std::string value = stack.pop()->getString() + " " + op + " " + stack.pop()->getString();
+    stack.push(new VarValue(value));
+}

+ 50 - 0
V-Gears-Installer/src/decompiler/world/instruction/WorldUncondJumpInstruction.cpp

@@ -0,0 +1,50 @@
+/*
+ * V-Gears
+ * Copyright (C) 2022 V-Gears Team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
+#include "decompiler/world/instruction/WorldUncondJumpInstruction.h"
+#include "decompiler/world/WorldEngine.h"
+#include "decompiler/world/WorldCodeGenerator.h"
+#include "decompiler/world/WorldDisassembler.h"
+
+FF7::WorldUncondJumpInstruction::WorldUncondJumpInstruction() : is_call_(false) { }
+
+bool FF7::WorldUncondJumpInstruction::IsFuncCall() const{return is_call_;}
+
+bool FF7::WorldUncondJumpInstruction::IsUncondJump() const{return !is_call_;}
+
+uint32 FF7::WorldUncondJumpInstruction::GetDestAddress() const{
+    // The world map while loops are incorrect without +1'in this, but
+    // doing that will break some if elses...
+    return 0x200 + _params[0]->getUnsigned();// +1; // TODO: +1 to skip param?
+}
+
+std::ostream& FF7::WorldUncondJumpInstruction::Print(std::ostream &output) const{
+    Instruction::Print(output);
+    // output << " (Jump target address: 0x" << std::hex << GetDestAddress() << std::dec << ")";
+    return output;
+}
+
+
+void FF7::WorldUncondJumpInstruction::ProcessInst(
+    Function& function, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
+){
+    // TODO
+}

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä