瀏覽代碼

Some old code of SUDM removed. Of the rest, part formatted and documented. Compiles against C++20 specification.

Iñigo Valentin 3 年之前
父節點
當前提交
85fe59cc2a
共有 70 個文件被更改,包括 3696 次插入6870 次删除
  1. 3 1
      CMakeLists.txt
  2. 6 18
      V-Gears-Installer/CMakeLists.txt
  3. 170 0
      V-Gears-Installer/include/common/BinaryReader.h
  4. 76 0
      V-Gears-Installer/include/common/Lzs.h
  5. 8 25
      V-Gears-Installer/include/common/OgreBase.h
  6. 0 228
      V-Gears-Installer/include/common/algorithm.h
  7. 0 97
      V-Gears-Installer/include/common/binaryreader.h
  8. 0 546
      V-Gears-Installer/include/common/func.h
  9. 0 92
      V-Gears-Installer/include/common/lzs.h
  10. 0 21
      V-Gears-Installer/include/common/make_unique.h
  11. 0 47
      V-Gears-Installer/include/common/noncopyable.h
  12. 221 233
      V-Gears-Installer/include/common/scummsys.h
  13. 0 257
      V-Gears-Installer/include/common/str.h
  14. 0 85
      V-Gears-Installer/include/common/util.h
  15. 11 11
      V-Gears-Installer/include/decompiler/decompiler_codegen.h
  16. 8 8
      V-Gears-Installer/include/decompiler/decompiler_disassembler.h
  17. 414 0
      V-Gears-Installer/include/decompiler/field/FieldCodeGenerator.h
  18. 737 0
      V-Gears-Installer/include/decompiler/field/FieldDisassembler.h
  19. 0 244
      V-Gears-Installer/include/decompiler/field/ff7_field_codegen.h
  20. 0 479
      V-Gears-Installer/include/decompiler/field/ff7_field_disassembler.h
  21. 6 6
      V-Gears-Installer/include/decompiler/field/ff7_field_engine.h
  22. 0 103
      V-Gears-Installer/include/decompiler/scummv6/codegen.h
  23. 0 63
      V-Gears-Installer/include/decompiler/scummv6/disassembler.h
  24. 0 121
      V-Gears-Installer/include/decompiler/scummv6/engine.h
  25. 11 11
      V-Gears-Installer/include/decompiler/simple_disassembler.h
  26. 76 77
      V-Gears-Installer/include/decompiler/sudm.h
  27. 0 1
      V-Gears-Installer/include/decompiler/test/cfg_test.cpp
  28. 0 1
      V-Gears-Installer/include/decompiler/test/codegen.cpp
  29. 2 2
      V-Gears-Installer/include/decompiler/test/disassembler/pasc.cpp
  30. 1 1
      V-Gears-Installer/include/decompiler/test/disassembler/pasc.h
  31. 1 1
      V-Gears-Installer/include/decompiler/test/disassembler/subopcode.cpp
  32. 1 1
      V-Gears-Installer/include/decompiler/test/disassembler/subopcode.h
  33. 71 72
      V-Gears-Installer/include/decompiler/test/ff7_field_all_opcodes_disassembler_test.cpp
  34. 17 18
      V-Gears-Installer/include/decompiler/test/ff7_field_control_flow_test.cpp
  35. 146 146
      V-Gears-Installer/include/decompiler/test/ff7_field_disasm_all_opcodes_by_category_test.cpp
  36. 15 16
      V-Gears-Installer/include/decompiler/test/main.cpp
  37. 2 2
      V-Gears-Installer/include/decompiler/world/ff7_world_codegen.h
  38. 1 1
      V-Gears-Installer/include/decompiler/world/ff7_world_disassembler.h
  39. 0 1
      V-Gears-Installer/include/ff7DataInstaller.h
  40. 0 437
      V-Gears-Installer/src/common/str.cpp
  41. 3 3
      V-Gears-Installer/src/decompiler/decompiler.cpp
  42. 38 39
      V-Gears-Installer/src/decompiler/decompiler_codegen.cpp
  43. 10 11
      V-Gears-Installer/src/decompiler/decompiler_disassembler.cpp
  44. 300 0
      V-Gears-Installer/src/decompiler/field/FieldCodeGenerator.cpp
  45. 707 0
      V-Gears-Installer/src/decompiler/field/FieldDisassembler.cpp
  46. 0 293
      V-Gears-Installer/src/decompiler/field/ff7_field_codegen.cpp
  47. 0 744
      V-Gears-Installer/src/decompiler/field/ff7_field_disassembler.cpp
  48. 553 555
      V-Gears-Installer/src/decompiler/field/ff7_field_engine.cpp
  49. 5 5
      V-Gears-Installer/src/decompiler/instruction.cpp
  50. 0 274
      V-Gears-Installer/src/decompiler/scummv6/codegen.cpp
  51. 0 542
      V-Gears-Installer/src/decompiler/scummv6/disassembler.cpp
  52. 0 185
      V-Gears-Installer/src/decompiler/scummv6/engine.cpp
  53. 18 18
      V-Gears-Installer/src/decompiler/simple_disassembler.cpp
  54. 40 41
      V-Gears-Installer/src/decompiler/sudm.cpp
  55. 1 1
      V-Gears-Installer/src/decompiler/world/ff7_world_codegen.cpp
  56. 6 6
      V-Gears-Installer/src/decompiler/world/ff7_world_disassembler.cpp
  57. 2 3
      V-Gears-Installer/src/decompiler/world/ff7_world_engine.cpp
  58. 8 9
      V-Gears-Installer/src/ff7DataInstaller.cpp
  59. 0 1
      V-Gears/CMakeLists.txt
  60. 0 30
      V-Gears/include/common/make_unique.h
  61. 1 2
      V-Gears/src/Main.cpp
  62. 0 1
      V-Gears/src/common/VGearsApplication.cpp
  63. 0 1
      V-Gears/src/core/ConfigCmdManager.cpp
  64. 0 4
      lib/SUDM/.gitignore
  65. 0 3
      lib/SUDM/.gitmodules
  66. 0 78
      lib/SUDM/.travis.yml
  67. 0 198
      lib/SUDM/CMakeLists.txt
  68. 0 340
      lib/SUDM/LICENSE
  69. 0 9
      lib/SUDM/README.md
  70. 0 1
      lib/SUDM/decompiler/.gitignore

+ 3 - 1
CMakeLists.txt

@@ -208,6 +208,8 @@ set(VGears_INCLUDE_DIRS
     ${CMAKE_CURRENT_SOURCE_DIR}/lib/tinyxml
 )
 
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20 -fPIC")
+
 if (MSVC)
     # 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")
@@ -215,7 +217,7 @@ if (MSVC)
     add_definitions( -D_CRT_SECURE_NO_WARNINGS )
 else()
     # 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++11 -fPIC")
+    #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -fPIC")
 endif()
 
 if (UNIX AND $ENV{COVERAGE}==1)

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

@@ -35,20 +35,12 @@ set(HEADER_FILES
     include/decompiler/unknown_opcode_exception.h
     include/decompiler/value.h
     include/decompiler/wrongtype.h
-    include/decompiler/scummv6/codegen.h
-    include/decompiler/scummv6/disassembler.h
-    include/decompiler/scummv6/engine.h
-    include/decompiler/field/ff7_field_disassembler.h
+    include/decompiler/field/FieldDisassembler.h
     include/decompiler/field/ff7_field_engine.h
-    include/decompiler/field/ff7_field_codegen.h
-    include/common/algorithm.h
-    include/common/noncopyable.h
+    include/decompiler/field/FieldCodeGenerator.h
     include/common/scummsys.h
-    include/common/str.h
-    include/common/util.h
-    include/common/binaryreader.h
-    include/common/lzs.h
-    include/common/make_unique.h
+    include/common/BinaryReader.h
+    include/common/Lzs.h
 )
 
 
@@ -72,13 +64,9 @@ set(SOURCE_FILES
     src/decompiler/simple_disassembler.cpp
     src/decompiler/unknown_opcode_exception.cpp
     src/decompiler/value.cpp
-    src/decompiler/scummv6/codegen.cpp
-    src/decompiler/scummv6/disassembler.cpp
-    src/decompiler/scummv6/engine.cpp
-    src/decompiler/field/ff7_field_disassembler.cpp
+    src/decompiler/field/FieldDisassembler.cpp
     src/decompiler/field/ff7_field_engine.cpp
-    src/decompiler/field/ff7_field_codegen.cpp
-    src/common/str.cpp
+    src/decompiler/field/FieldCodeGenerator.cpp
 )
 
 # For SUDM. TODO: Add elses.

+ 170 - 0
V-Gears-Installer/include/common/BinaryReader.h

@@ -0,0 +1,170 @@
+/*
+ * 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 <fstream> 
+#include <sstream>
+#include <iterator>
+#include "decompiler/unknown_opcode_exception.h"
+
+/**
+ * REader for binary files.
+ */
+class BinaryReader{
+
+    public:
+
+        /**
+         * Reads a file, from start to end.
+         *
+         * @oaram file_name[in] Path and name of the file to read.
+         * @return Read bytes.
+         * @throws std::runtime_error if the file can't be opened for reading.
+         */
+        static std::vector<unsigned char> ReadAll(std::string file_name){
+            std::ifstream file(file_name.c_str(), std::ios::binary | std::ios::ate);
+            if (file.is_open()){
+                size_t file_size_in_bytes = size_t(file.tellg());
+                std::vector<unsigned char> file_contents(file_size_in_bytes);
+                file.seekg(0, std::ios::beg);
+                file.read(reinterpret_cast<char*>(file_contents.data()), file_contents.size());
+                return file_contents;
+            }
+            else throw std::runtime_error("Can't open file");
+        }
+
+        /**
+         * Constructor.
+         *
+         * @param data[in] Bytes for the reader
+         */
+        BinaryReader(std::vector<unsigned char>&& data){
+            size_ = data.size();
+            std::copy(data.begin(), data.end(), std::ostream_iterator<unsigned char>(stream_));
+            stream_.seekg(std::ios::beg);
+        }
+
+        /**
+         * Retrieves the size of the data in the reader.
+         *
+         * @return The size of the data in bytes.
+         */
+        size_t GetSize() const{return size_;}
+
+        /**
+         * Moves the stream cursor.
+         *
+         * @param position[in] Position (offset) of the cursor.
+         * @throws InternalDecompilerError if the position is invalid.
+         */
+        void Seek(unsigned int position){
+            if (!stream_.seekg(position)) throw InternalDecompilerError();
+        }
+
+        /**
+         * Retrieves the current stream cursor position.
+         *
+         * @return position[in] Position (offset) of the cursor.
+         */
+        unsigned int GetPosition(){return static_cast<unsigned int>(stream_.tellg());}
+
+        /**
+         * Reads 32 bits of data as an unsigned integer.
+         *
+         * It advances the stream cursor.
+         *
+         * @return Read bits.
+         * @throws InternalDecompilerError if there is not enough data.
+         */
+        unsigned int ReadU32(){return InternalRead<unsigned int>();}
+
+        /**
+         * Reads 32 bits of data as a signed integer.
+         *
+         * It advances the stream cursor.
+         *
+         * @return Read bits.
+         * @throws InternalDecompilerError if there is not enough data.
+         */
+        signed int ReadS32(){return InternalRead<signed int>();}
+
+        /**
+         * Reads 16 bits of data as an unsigned integer.
+         *
+         * It advances the stream cursor.
+         *
+         * @return Read bits.
+         * @throws InternalDecompilerError if there is not enough data.
+         */
+        signed short int ReadS16(){return InternalRead<signed short int>();}
+
+        /**
+         * Reads 16 bits of data as a signed integer.
+         *
+         * It advances the stream cursor.
+         *
+         * @return Read bits.
+         * @throws InternalDecompilerError if there is not enough data.
+         */
+        unsigned short int ReadU16(){return InternalRead<unsigned short int>();}
+
+        /**
+         * Reads 8 bits of data as an unsigned integer.
+         *
+         * It advances the stream cursor.
+         *
+         * @return Read bits.
+         * @throws InternalDecompilerError if there is not enough data.
+         */
+        unsigned char ReadU8(){return InternalRead<unsigned char>();}
+
+        /**
+         * Reads 8 bits of data as a signed integer.
+         *
+         * It advances the stream cursor.
+         *
+         * @return Read bits.
+         * @throws InternalDecompilerError if there is not enough data.
+         */
+        signed char ReadS8(){return InternalRead<signed char>();}
+
+    private:
+
+        /**
+         * Reads T bits of data as a signed integer.
+         *
+         * It advances the stream cursor.
+         *
+         * @return Read bits.
+         * @throws InternalDecompilerError if there is not enough data.
+         */
+        template<class T> T InternalRead(){
+            T r = {};
+            if (!stream_.read(reinterpret_cast<char*>(&r), sizeof(r)))
+                throw InternalDecompilerError();
+            return r;
+        }
+
+        /**
+         * The data stream.
+         */
+        std::stringstream stream_;
+
+        /**
+         * The size of the data, in bytes.
+         */
+        size_t size_ = 0;
+};

+ 76 - 0
V-Gears-Installer/include/common/Lzs.h

@@ -0,0 +1,76 @@
+/*
+ * 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
+
+namespace Lzs{
+
+    /**
+     * Decompresses LZS data.
+     *
+     * @param compressed[in] Compressed data.
+     * @return Decompressed data.
+     */
+    inline std::vector<unsigned char> Decompress(const std::vector<unsigned char>& compressed){
+        if (compressed.size() < 4) abort();
+        const unsigned int inpuit_buffer_size = static_cast<unsigned int>(compressed.size());
+        const unsigned int input_length =
+          (((compressed[0] & 0xFF) << 0) |
+          ((compressed[1] & 0xFF) << 8) |
+          ((compressed[2] & 0xFF) << 16) |
+          ((compressed[3] & 0xFF) << 24)) + 4;
+        if (input_length != inpuit_buffer_size) abort();
+        unsigned int extract_size = (inpuit_buffer_size + 255) & ~255;
+        std::vector<unsigned char> extract_buffer(extract_size);
+        unsigned int input_offset = 4;
+        unsigned int output_offset = 0;
+        unsigned char control_byte = 0;
+        unsigned char control_bit = 0;
+        while (input_offset < inpuit_buffer_size){
+            if (control_bit == 0){
+                control_byte = compressed[input_offset ++];
+                control_bit = 8;
+            }
+            if (control_byte & 1){
+                extract_buffer[output_offset++] = compressed[input_offset ++];
+                if (output_offset == extract_size){
+                    extract_size += 256;
+                    extract_buffer.resize(extract_size);
+                }
+            }
+            else{
+                const unsigned char reference1 = compressed[input_offset ++];
+                const unsigned char reference2 = compressed[input_offset ++];
+                const unsigned short int reference_offset = reference1 | ((reference2 & 0xF0) << 4);
+                const unsigned char reference_length = (reference2 & 0xF) + 3;
+                int real_offset = output_offset - ((output_offset - 18 - reference_offset) & 0xFFF);
+                for (int j = 0; j < reference_length; ++ j){
+                    if (real_offset < 0) extract_buffer[output_offset ++] = 0;
+                    else extract_buffer[output_offset ++] = extract_buffer[real_offset];
+                    if (output_offset == extract_size) {
+                        extract_size += 256;
+                        extract_buffer.resize(extract_size);
+                    }
+                    ++ real_offset;
+                }
+            }
+            control_byte >>= 1;
+            control_bit --;
+        }
+        // Truncate to exact size.
+        extract_buffer.resize(output_offset);
+        return extract_buffer;
+    }
+}

+ 8 - 25
V-Gears-Installer/include/common/OgreBase.h

@@ -17,8 +17,6 @@
 
 #include <Ogre.h>
 #include <OgreTextAreaOverlayElement.h>
-//#include <OgreOverlayManager.h>
-//#include <Overlay/OgreOverlayManager.h>
 #include <OgreOverlay.h>
 #include <OgreOverlayManager.h>
 #include <Bites/OgreWindowEventUtilities.h>
@@ -65,7 +63,6 @@ class DisplayFrameListener :
 {
 
     public:
-        // Constructor takes a RenderWindow because it uses that to determine input context
 
         /**
          * Constructor.
@@ -78,9 +75,7 @@ class DisplayFrameListener :
         {
 
             using namespace OIS;
-            Ogre::LogManager::getSingletonPtr()->logMessage(
-              "[OIS] Initializing..."
-            );
+            Ogre::LogManager::getSingletonPtr()->logMessage("[OIS] Initializing...");
             ParamList pl;
             size_t window_hnd = 0; // TODO What does HND stand for?
             std::ostringstream window_hnd_str;
@@ -90,7 +85,6 @@ class DisplayFrameListener :
               std::make_pair(std::string("WINDOW"), window_hnd_str.str())
             );
             input_manager_ = InputManager::createInputSystem(pl);
-
             keyboard_ = static_cast<Keyboard*> (
               input_manager_->createInputObject(OIS::OISKeyboard, true)
             );
@@ -108,9 +102,7 @@ class DisplayFrameListener :
             info_text->setPosition(5, 5);
            // info_text->setFontName("BlueHighway");
             info_text->setCharHeight(18);
-            info_overlay = Ogre::OverlayManager::getSingleton().create(
-              "DebugOverlay"
-            );
+            info_overlay = Ogre::OverlayManager::getSingleton().create("DebugOverlay");
             info_overlay->setZOrder(1);
             info_overlay->add2D((Ogre::OverlayContainer*) info_text);
             info_overlay->show();
@@ -120,9 +112,7 @@ class DisplayFrameListener :
             input_manager_->destroyInputObject(keyboard_);
             OIS::InputManager::destroyInputSystem(input_manager_);
             //Remove self as a Window listener.
-            Ogre::WindowEventUtilities::removeWindowEventListener(
-              window_, this
-            );
+            Ogre::WindowEventUtilities::removeWindowEventListener(window_, this);
             windowClosed(window_);
         }
 
@@ -154,15 +144,13 @@ class DisplayFrameListener :
             for (unsigned int i = 0; i < entities.size(); ++ i){
                 if (entities[i]->isVisible() == true){
                     Ogre::AnimationStateIterator animations
-                      = entities[i]->getAllAnimationStates()
-                        ->getAnimationStateIterator();
+                      = entities[i]->getAllAnimationStates()->getAnimationStateIterator();
                     while (animations.hasMoreElements() == true){
                         Ogre::AnimationState* state = animations.getNext();
                         if (state->getEnabled() == true){
                             state->addTime(evt.timeSinceLastFrame);
                             info_text->setCaption(
-                              entities[i]->getName() + ": "
-                              + state->getAnimationName()
+                              entities[i]->getName() + ": " + state->getAnimationName()
                             );
                         }
                     }
@@ -213,10 +201,7 @@ class DisplayFrameListener :
                                 entities[i]->setVisible(true);
                                 break;
                             }
-                            if (
-                              entities[i]->isVisible() == true
-                              && (i != entities.size() - 1)
-                            ){
+                            if (entities[i]->isVisible() == true && (i != entities.size() - 1)){
                                 entities[i]->setVisible(false);
                                 change = true;
                             }
@@ -268,11 +253,9 @@ class DisplayFrameListener :
                     for (unsigned int i = 0; i < entities.size(); ++ i){
                         if (entities[i]->isVisible() == true){
                             Ogre::AnimationStateIterator animations
-                              = entities[i]->getAllAnimationStates()
-                                ->getAnimationStateIterator();
+                              = entities[i]->getAllAnimationStates()->getAnimationStateIterator();
                             while (animations.hasMoreElements() == true){
-                                Ogre::AnimationState* state
-                                  = animations.getNext();
+                                Ogre::AnimationState* state = animations.getNext();
                                 if (change == true){
                                     state->setEnabled(true);
                                     state->setLoop(true);

+ 0 - 228
V-Gears-Installer/include/common/algorithm.h

@@ -1,228 +0,0 @@
-/* ScummVM Tools
- *
- * ScummVM Tools is the legal property of its developers, whose
- * names are too numerous to list here. Please refer to the
- * COPYRIGHT file distributed with this source distribution.
- *
- * 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.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifndef COMMON_ALGORITHM_H
-#define COMMON_ALGORITHM_H
-
-#include "common/scummsys.h"
-#include "common/func.h"
-
-namespace Common {
-
-/**
- * Copies data from the range [first, last) to [dst, dst + (last - first)).
- * It requires the range [dst, dst + (last - first)) to be valid.
- * It also requires dst not to be in the range [first, last).
- */
-template<class In, class Out>
-Out copy(In first, In last, Out dst) {
-	while (first != last)
-		*dst++ = *first++;
-	return dst;
-}
-
-/**
- * Copies data from the range [first, last) to [dst - (last - first), dst).
- * It requires the range [dst - (last - first), dst) to be valid.
- * It also requires dst not to be in the range [first, last).
- *
- * Unlike copy copy_backward copies the data from the end to the beginning.
- */
-template<class In, class Out>
-Out copy_backward(In first, In last, Out dst) {
-	while (first != last)
-		*--dst = *--last;
-	return dst;
-}
-
-/**
- * Copies data from the range [first, last) to [dst, dst + (last - first)).
- * It requires the range [dst, dst + (last - first)) to be valid.
- * It also requires dst not to be in the range [first, last).
- *
- * Unlike copy or copy_backward it does not copy all data. It only copies
- * a data element when operator() of the op parameter returns true for the
- * passed data element.
- */
-template<class In, class Out, class Op>
-Out copy_if(In first, In last, Out dst, Op op) {
-	while (first != last) {
-		if (op(*first))
-			*dst++ = *first;
-		++first;
-	}
-	return dst;
-}
-
-// Our 'specialized' 'set_to' template for char, signed char and unsigned char arrays.
-// Since C++ doesn't support partial specialized template functions (currently) we
-// are going this way...
-// With this we assure the usage of memset for those, which should be
-// faster than a simple loop like for the generic 'set_to'.
-template<class Value>
-signed char *set_to(signed char *first, signed char *last, Value val) {
-	memset(first, (val & 0xFF), last - first);
-	return last;
-}
-
-template<class Value>
-unsigned char *set_to(unsigned char *first, unsigned char *last, Value val) {
-	memset(first, (val & 0xFF), last - first);
-	return last;
-}
-
-template<class Value>
-char *set_to(char *first, char *last, Value val) {
-	memset(first, (val & 0xFF), last - first);
-	return last;
-}
-
-/**
- * Sets all elements in the range [first, last) to val.
- */
-template<class In, class Value>
-In set_to(In first, In last, Value val) {
-	while (first != last)
-		*first++ = val;
-	return first;
-}
-
-/**
- * Finds the first data value in the range [first, last) matching v.
- * For data comperance it uses operator == of the data elements.
- */
-template<class In, class T>
-In find(In first, In last, const T &v) {
-	while (first != last) {
-		if (*first == v)
-			return first;
-		++first;
-	}
-	return last;
-}
-
-/**
- * Finds the first data value in the range [first, last) for which
- * the specified predicate p returns true.
- */
-template<class In, class Pred>
-In find_if(In first, In last, Pred p) {
-	while (first != last) {
-		if (p(*first))
-			return first;
-		++first;
-	}
-	return last;
-}
-
-/**
- * Applies the function f on all elements of the range [first, last).
- * The processing order is from beginning to end.
- */
-template<class In, class Op>
-Op for_each(In first, In last, Op f) {
-	while (first != last) f(*first++);
-	return f;
-}
-
-template<typename T>
-unsigned int distance(T *first, T *last) {
-	return last - first;
-}
-
-template<typename T>
-unsigned int distance(T first, T last) {
-	unsigned int n = 0;
-	while (first != last) {
-		++n;
-		++first;
-	}
-	return n;
-}
-
-template<typename T>
-T *sortChoosePivot(T *first, T *last) {
-	return first + distance(first, last) / 2;
-}
-
-template<typename T>
-T sortChoosePivot(T first, T last) {
-	unsigned int n = distance(first, last);
-	n /= 2;
-	while (n--)
-		++first;
-	return first;
-}
-
-template<typename T, class StrictWeakOrdering>
-T sortPartition(T first, T last, T pivot, StrictWeakOrdering &comp) {
-	--last;
-	SWAP(*pivot, *last);
-
-	T sorted;
-	for (sorted = first; first != last; ++first) {
-		if (!comp(*last, *first)) {
-			if (first != sorted)
-				SWAP(*first, *sorted);
-			++sorted;
-		}
-	}
-
-	SWAP(*last, *sorted);
-	return sorted;
-}
-
-/**
- * Simple sort function, modeled after std::sort.
- * It compares data with the given comparator object comp.
- */
-template<typename T, class StrictWeakOrdering>
-void sort(T first, T last, StrictWeakOrdering comp) {
-	if (first == last)
-		return;
-
-	T pivot = sortChoosePivot(first, last);
-	pivot = sortPartition(first, last, pivot, comp);
-	sort<T, StrictWeakOrdering>(first, pivot, comp);
-	sort<T, StrictWeakOrdering>(++pivot, last, comp);
-}
-
-/**
- * Simple sort function, modeled after std::sort.
- */
-template<typename T>
-void sort(T *first, T *last) {
-	sort(first, last, Common::Less<T>());
-}
-
-template<class T>
-void sort(T first, T last) {
-	sort(first, last, Common::Less<typename T::ValueType>());
-}
-
-} // End of namespace Common
-#endif
-

+ 0 - 97
V-Gears-Installer/include/common/binaryreader.h

@@ -1,97 +0,0 @@
-#pragma once
-
-#include <fstream> 
-#include <sstream>
-#include <iterator>
-#include "decompiler/unknown_opcode_exception.h"
-
-class BinaryReader
-{
-public:
-    static std::vector<unsigned char> ReadAll(std::string fileName)
-    {
-        std::ifstream file(fileName.c_str(), std::ios::binary | std::ios::ate);
-        if (file.is_open())
-        {
-            size_t fileSizeInBytes = size_t(file.tellg());
-            std::vector<unsigned char> fileContents(fileSizeInBytes);
-            file.seekg(0, std::ios::beg);
-            file.read(reinterpret_cast<char*>(fileContents.data()), fileContents.size());
-            return fileContents;
-        }
-        else
-        {
-            throw std::runtime_error("Can't open file");
-        }
-    }
-
-    BinaryReader(std::vector<unsigned char>&& data)
-    {
-        mSize = data.size();
-        std::copy(data.begin(), data.end(), std::ostream_iterator<unsigned char>(mStream));
-        mStream.seekg(std::ios::beg);
-    }
-
-    size_t Size() const
-    {
-        return mSize;
-    }
-
-    void Seek(unsigned int pos)
-    {
-        if (!mStream.seekg(pos))
-        {
-            throw InternalDecompilerError();
-        }
-    }
-
-    unsigned int Position()
-    {
-        return static_cast<unsigned int>(mStream.tellg());
-    }
-
-    unsigned int ReadU32()
-    {
-        return InternalRead<unsigned int>();
-    }
-
-    signed int ReadS32()
-    {
-        return InternalRead<signed int>();
-    }
-
-    signed short int ReadS16()
-    {
-        return InternalRead<signed short int>();
-    }
-
-    unsigned short int ReadU16()
-    {
-        return InternalRead<unsigned short int>();
-    }
-
-    unsigned char ReadU8()
-    {
-        return InternalRead<unsigned char>();
-    }
-
-    signed char ReadS8()
-    {
-        return InternalRead<signed char>();
-    }
-
-private:
-    template<class T>
-    T InternalRead()
-    {
-        T r = {};
-        if (!mStream.read(reinterpret_cast<char*>(&r), sizeof(r)))
-        {
-            throw InternalDecompilerError();
-        }
-        return r;
-    }
-
-    std::stringstream mStream;
-    size_t mSize = 0;
-};

+ 0 - 546
V-Gears-Installer/include/common/func.h

@@ -1,546 +0,0 @@
-/* ScummVM Tools
- *
- * ScummVM Tools is the legal property of its developers, whose
- * names are too numerous to list here. Please refer to the
- * COPYRIGHT file distributed with this source distribution.
- *
- * 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.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifndef COMMON_FUNC_H
-#define COMMON_FUNC_H
-
-#include "common/scummsys.h"
-
-namespace Common {
-
-/**
- * Generic unary function.
- */
-template<class Arg, class Result>
-struct UnaryFunction {
-	typedef Arg ArgumenType;
-	typedef Result ResultType;
-};
-
-/**
- * Generic binary function.
- */
-template<class Arg1, class Arg2, class Result>
-struct BinaryFunction {
-	typedef Arg1 FirstArgumentType;
-	typedef Arg2 SecondArgumentType;
-	typedef Result ResultType;
-};
-
-/**
- * Predicate to check for equallity of two data elements.
- */
-template<class T>
-struct EqualTo : public BinaryFunction<T, T, bool> {
-	bool operator()(const T &x, const T &y) const { return x == y; }
-};
-
-/**
- * Predicate to check for x being less than y.
- */
-template<class T>
-struct Less : public BinaryFunction<T, T, bool> {
-	bool operator()(const T &x, const T &y) const { return x < y; }
-};
-
-/**
- * Predicate to check for x being greater than y.
- */
-template<class T>
-struct Greater : public BinaryFunction<T, T, bool> {
-	bool operator()(const T &x, const T &y) const { return x > y; }
-};
-
-template<class Op>
-class Binder1st : public UnaryFunction<typename Op::SecondArgumentType, typename Op::ResultType> {
-private:
-	Op _op;
-	typename Op::FirstArgumentType _arg1;
-public:
-	Binder1st(const Op &op, typename Op::FirstArgumentType arg1) : _op(op), _arg1(arg1) {}
-
-	typename Op::ResultType operator()(typename Op::SecondArgumentType v) const {
-		return _op(_arg1, v);
-	}
-};
-
-/**
- * Transforms a binary function object into an unary function object.
- * To achieve that the first parameter is bound to the passed value t.
- */
-template<class Op>
-inline Binder1st<Op> bind1st(const Op &op, typename Op::FirstArgumentType t) {
-	return Binder1st<Op>(op, t);
-}
-
-template<class Op>
-class Binder2nd : public UnaryFunction<typename Op::FirstArgumentType, typename Op::ResultType> {
-private:
-	Op _op;
-	typename Op::SecondArgumentType _arg2;
-public:
-	Binder2nd(const Op &op, typename Op::SecondArgumentType arg2) : _op(op), _arg2(arg2) {}
-
-	typename Op::ResultType operator()(typename Op::FirstArgumentType v) const {
-		return _op(v, _arg2);
-	}
-};
-
-/**
- * Transforms a binary function object into an unary function object.
- * To achieve that the first parameter is bound to the passed value t.
- */
-template<class Op>
-inline Binder2nd<Op> bind2nd(const Op &op, typename Op::SecondArgumentType t) {
-	return Binder2nd<Op>(op, t);
-}
-
-template<class Arg, class Result>
-class PointerToUnaryFunc : public UnaryFunction<Arg, Result> {
-private:
-	Result (*_func)(Arg);
-public:
-	typedef Result (*FuncType)(Arg);
-
-	PointerToUnaryFunc(const FuncType &func) : _func(func) {}
-	Result operator()(Arg v) const {
-		return _func(v);
-	}
-};
-
-template<class Arg1, class Arg2, class Result>
-class PointerToBinaryFunc : public BinaryFunction<Arg1, Arg2, Result> {
-private:
-	Result (*_func)(Arg1, Arg2);
-public:
-	typedef Result (*FuncType)(Arg1, Arg2);
-
-	PointerToBinaryFunc(const FuncType &func) : _func(func) {}
-	Result operator()(Arg1 v1, Arg2 v2) const {
-		return _func(v1, v2);
-	}
-};
-
-/**
- * Creates an unary function object from a function pointer.
- */
-template<class Arg, class Result>
-inline PointerToUnaryFunc<Arg, Result> ptr_fun(Result (*func)(Arg)) {
-	return PointerToUnaryFunc<Arg, Result>(func);
-}
-
-/**
- * Creates an binary function object from a function pointer.
- */
-template<class Arg1, class Arg2, class Result>
-inline PointerToBinaryFunc<Arg1, Arg2, Result> ptr_fun(Result (*func)(Arg1, Arg2)) {
-	return PointerToBinaryFunc<Arg1, Arg2, Result>(func);
-}
-
-template<class Result, class T>
-class MemFunc0 : public UnaryFunction<T *, Result> {
-private:
-	Result (T::*_func)();
-public:
-	typedef Result (T::*FuncType)();
-
-	MemFunc0(const FuncType &func) : _func(func) {}
-	Result operator()(T *v) const {
-		return (v->*_func)();
-	}
-};
-
-template<class Result, class T>
-class ConstMemFunc0 : public UnaryFunction<T *, Result> {
-private:
-	Result (T::*_func)() const;
-public:
-	typedef Result (T::*FuncType)() const;
-
-	ConstMemFunc0(const FuncType &func) : _func(func) {}
-	Result operator()(const T *v) const {
-		return (v->*_func)();
-	}
-};
-
-template<class Result, class Arg, class T>
-class MemFunc1 : public BinaryFunction<T *, Arg, Result> {
-private:
-	Result (T::*_func)(Arg);
-public:
-	typedef Result (T::*FuncType)(Arg);
-
-	MemFunc1(const FuncType &func) : _func(func) {}
-	Result operator()(T *v1, Arg v2) const {
-		return (v1->*_func)(v2);
-	}
-};
-
-template<class Result, class Arg, class T>
-class ConstMemFunc1 : public BinaryFunction<T *, Arg, Result> {
-private:
-	Result (T::*_func)(Arg) const;
-public:
-	typedef Result (T::*FuncType)(Arg) const;
-
-	ConstMemFunc1(const FuncType &func) : _func(func) {}
-	Result operator()(const T *v1, Arg v2) const {
-		return (v1->*_func)(v2);
-	}
-};
-
-/**
- * Creates a unary function object from a class member function pointer.
- * The parameter passed to the function object is the 'this' pointer to
- * be used for the function call.
- */
-template<class Result, class T>
-inline MemFunc0<Result, T> mem_fun(Result (T::*f)()) {
-	return MemFunc0<Result, T>(f);
-}
-
-/**
- * Creates a unary function object from a class member function pointer.
- * The parameter passed to the function object is the 'this' pointer to
- * be used for the function call.
- */
-template<class Result, class T>
-inline ConstMemFunc0<Result, T> mem_fun(Result (T::*f)() const) {
-	return ConstMemFunc0<Result, T>(f);
-}
-
-/**
- * Creates a binary function object from a class member function pointer.
- * The first parameter passed to the function object is the 'this' pointer to
- * be used for the function call.
- * The second one is the parameter passed to the member function.
- */
-template<class Result, class Arg, class T>
-inline MemFunc1<Result, Arg, T> mem_fun(Result (T::*f)(Arg)) {
-	return MemFunc1<Result, Arg, T>(f);
-}
-
-/**
- * Creates a binary function object from a class member function pointer.
- * The first parameter passed to the function object is the 'this' pointer to
- * be used for the function call.
- * The second one is the parameter passed to the member function.
- */
-template<class Result, class Arg, class T>
-inline ConstMemFunc1<Result, Arg, T> mem_fun(Result (T::*f)(Arg) const) {
-	return ConstMemFunc1<Result, Arg, T>(f);
-}
-
-template<class Result, class T>
-class MemFuncRef0 : public UnaryFunction<T &, Result> {
-private:
-	Result (T::*_func)();
-public:
-	typedef Result (T::*FuncType)();
-
-	MemFuncRef0(const FuncType &func) : _func(func) {}
-	Result operator()(T &v) const {
-		return (v.*_func)();
-	}
-};
-
-template<class Result, class T>
-class ConstMemFuncRef0 : public UnaryFunction<T &, Result> {
-private:
-	Result (T::*_func)() const;
-public:
-	typedef Result (T::*FuncType)() const;
-
-	ConstMemFuncRef0(const FuncType &func) : _func(func) {}
-	Result operator()(const T &v) const {
-		return (v.*_func)();
-	}
-};
-
-template<class Result, class Arg, class T>
-class MemFuncRef1 : public BinaryFunction<T &, Arg, Result> {
-private:
-	Result (T::*_func)(Arg);
-public:
-	typedef Result (T::*FuncType)(Arg);
-
-	MemFuncRef1(const FuncType &func) : _func(func) {}
-	Result operator()(T &v1, Arg v2) const {
-		return (v1.*_func)(v2);
-	}
-};
-
-template<class Result, class Arg, class T>
-class ConstMemFuncRef1 : public BinaryFunction<T &, Arg, Result> {
-private:
-	Result (T::*_func)(Arg) const;
-public:
-	typedef Result (T::*FuncType)(Arg) const;
-
-	ConstMemFuncRef1(const FuncType &func) : _func(func) {}
-	Result operator()(const T &v1, Arg v2) const {
-		return (v1.*_func)(v2);
-	}
-};
-
-/**
- * Creates a unary function object from a class member function pointer.
- * The parameter passed to the function object is the object instance to
- * be used for the function call. Note unlike mem_fun, it takes a reference
- * as parameter. Note unlike mem_fun, it takes a reference
- * as parameter.
- */
-template<class Result, class T>
-inline MemFuncRef0<Result, T> mem_fun_ref(Result (T::*f)()) {
-	return MemFuncRef0<Result, T>(f);
-}
-
-/**
- * Creates a unary function object from a class member function pointer.
- * The parameter passed to the function object is the object instance to
- * be used for the function call. Note unlike mem_fun, it takes a reference
- * as parameter.
- */
-template<class Result, class T>
-inline ConstMemFuncRef0<Result, T> mem_fun_Ref(Result (T::*f)() const) {
-	return ConstMemFuncRef0<Result, T>(f);
-}
-
-/**
- * Creates a binary function object from a class member function pointer.
- * The first parameter passed to the function object is the object instance to
- * be used for the function call. Note unlike mem_fun, it takes a reference
- * as parameter.
- * The second one is the parameter passed to the member function.
- */
-template<class Result, class Arg, class T>
-inline MemFuncRef1<Result, Arg, T> mem_fun_ref(Result (T::*f)(Arg)) {
-	return MemFuncRef1<Result, Arg, T>(f);
-}
-
-/**
- * Creates a binary function object from a class member function pointer.
- * The first parameter passed to the function object is the object instance to
- * be used for the function call. Note unlike mem_fun, it takes a reference
- * as parameter.
- * The second one is the parameter passed to the member function.
- */
-template<class Result, class Arg, class T>
-inline ConstMemFuncRef1<Result, Arg, T> mem_fun_ref(Result (T::*f)(Arg) const) {
-	return ConstMemFuncRef1<Result, Arg, T>(f);
-}
-
-// functor code
-
-/**
- * Generic functor object for function objects without parameters.
- *
- * @see Functor1
- */
-template<class Res>
-struct Functor0 {
-	virtual ~Functor0() {}
-
-	virtual bool isValid() const = 0;
-	virtual Res operator()() const = 0;
-};
-
-/**
- * Functor object for a class member function without parameter.
- *
- * Example creation:
- *
- * Foo bar;
- * Functor0Mem<void, Foo> myFunctor(&bar, &Foo::myFunc);
- *
- * Example usage:
- *
- * myFunctor();
- */
-template<class Res, class T>
-class Functor0Mem : public Functor0<Res> {
-public:
-	typedef Res (T::*FuncType)();
-
-	Functor0Mem(T *t, const FuncType &func) : _t(t), _func(func) {}
-
-	bool isValid() const { return _func != 0 && _t != 0; }
-	Res operator()() const {
-		return (_t->*_func)();
-	}
-private:
-	mutable T *_t;
-	const FuncType _func;
-};
-
-/**
- * Generic functor object for unary function objects.
- *
- * A typical usage for an unary function object is for executing opcodes
- * in a script interpreter. To achieve that one can create an Common::Array
- * object with 'Functor1<Arg, Res> *' as type. Now after the right engine version
- * has been determined and the opcode table to use is found one could easily
- * add the opcode implementations like this:
- *
- * Common::Array<Functor1<ScriptState, void> *> opcodeTable;
- * opcodeTable[0] = new Functor1Mem<ScriptState, void, MyEngine_v1>(&myEngine, &MyEngine_v1::o1_foo);
- * opcodeTable[1] = new Functor1Mem<ScriptState, void, MyEngine_v2>(&myEngine, &MyEngine_v2::o2_foo);
- * // unimplemented/unused opcode
- * opcodeTable[2] = 0;
- * etc.
- *
- * This makes it easy to add member functions of different classes as
- * opcode functions to the function table. Since with the generic
- * Functor1<ScriptState, void> object the only requirement for an
- * function to be used is 'ScriptState' as argument and 'void' as return
- * value.
- *
- * Now for calling the opcodes one has simple to do:
- * if (opcodeTable[opcodeNum] && opcodeTable[opcodeNum]->isValid())
- *     (*opcodeTable[opcodeNum])(scriptState);
- * else
- *     warning("Unimplemented opcode %d", opcodeNum);
- *
- * If you want to see an real world example check the kyra engine.
- * Files: engines/kyra/script.cpp and .h and engines/kyra/script_*.cpp
- * are interesting for that matter.
- */
-template<class Arg, class Res>
-struct Functor1 : public Common::UnaryFunction<Arg, Res> {
-	virtual ~Functor1() {}
-
-	virtual bool isValid() const = 0;
-	virtual Res operator()(Arg) const = 0;
-};
-
-/**
- * Functor object for an unary class member function.
- * Usage is like with Functor0Mem. The resulting functor object
- * will take one parameter though.
- *
- * @see Functor0Mem
- */
-template<class Arg, class Res, class T>
-class Functor1Mem : public Functor1<Arg, Res> {
-public:
-	typedef Res (T::*FuncType)(Arg);
-
-	Functor1Mem(T *t, const FuncType &func) : _t(t), _func(func) {}
-
-	bool isValid() const { return _func != 0 && _t != 0; }
-	Res operator()(Arg v1) const {
-		return (_t->*_func)(v1);
-	}
-private:
-	mutable T *_t;
-	const FuncType _func;
-};
-
-/**
- * Generic functor object for binary function objects.
- *
- * @see Functor1
- */
-template<class Arg1, class Arg2, class Res>
-struct Functor2 : public Common::BinaryFunction<Arg1, Arg2, Res> {
-	virtual ~Functor2() {}
-
-	virtual bool isValid() const = 0;
-	virtual Res operator()(Arg1, Arg2) const = 0;
-};
-
-/**
- * Functor object for a binary function.
- *
- * @see Functor2Mem
- */
-template<class Arg1, class Arg2, class Res>
-class Functor2Fun : public Functor2<Arg1, Arg2, Res> {
-public:
-	typedef Res (*FuncType)(Arg1, Arg2);
-
-	Functor2Fun(const FuncType func) : _func(func) {}
-
-	bool isValid() const { return _func != 0; }
-	Res operator()(Arg1 v1, Arg2 v2) const {
-		return (*_func)(v1, v2);
-	}
-private:
-	const FuncType _func;
-};
-
-/**
- * Functor object for a binary class member function.
- * Usage is like with Functor0Mem. The resulting functor object
- * will take two parameter though.
- *
- * @see Functor0Mem
- */
-template<class Arg1, class Arg2, class Res, class T>
-class Functor2Mem : public Functor2<Arg1, Arg2, Res> {
-public:
-	typedef Res (T::*FuncType)(Arg1, Arg2);
-
-	Functor2Mem(T *t, const FuncType &func) : _t(t), _func(func) {}
-
-	bool isValid() const { return _func != 0 && _t != 0; }
-	Res operator()(Arg1 v1, Arg2 v2) const {
-		return (_t->*_func)(v1, v2);
-	}
-private:
-	mutable T *_t;
-	const FuncType _func;
-};
-
-/**
- * Base template for hash functor objects, used by HashMap.
- * This needs to be specialized for every type that you need to hash.
- */
-template<typename T> struct Hash;
-
-
-#define GENERATE_TRIVIAL_HASH_FUNCTOR(T) \
-	template<> struct Hash<T> : public UnaryFunction<T, uint> { \
-		uint operator()(T val) const { return (uint)val; } \
-	}
-
-GENERATE_TRIVIAL_HASH_FUNCTOR(bool);
-GENERATE_TRIVIAL_HASH_FUNCTOR(char);
-GENERATE_TRIVIAL_HASH_FUNCTOR(signed char);
-GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned char);
-GENERATE_TRIVIAL_HASH_FUNCTOR(short);
-GENERATE_TRIVIAL_HASH_FUNCTOR(int);
-GENERATE_TRIVIAL_HASH_FUNCTOR(long);
-GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned short);
-GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned int);
-GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned long);
-
-#undef GENERATE_TRIVIAL_HASH_FUNCTOR
-
-}	// End of namespace Common
-
-#endif
-

+ 0 - 92
V-Gears-Installer/include/common/lzs.h

@@ -1,92 +0,0 @@
-#pragma once
-
-namespace Lzs
-{
-    inline std::vector<unsigned char> Decompress(const std::vector<unsigned char>& compressed)
-    {
-        if (compressed.size() < 4)
-        {
-            abort();
-        }
-
-        const unsigned int inputBufferSize = static_cast<unsigned int>(compressed.size());
-        const unsigned int input_length =
-            (((compressed[0] & 0xFF) << 0) |
-            ((compressed[1] & 0xFF) << 8) |
-            ((compressed[2] & 0xFF) << 16) |
-            ((compressed[3] & 0xFF) << 24)) + 4;
-
-        if (input_length != inputBufferSize)
-        {
-            abort();
-        }
-
-        unsigned int extract_size = (inputBufferSize + 255) & ~255;
-        std::vector<unsigned char> extract_buffer(extract_size);
-
-
-
-        unsigned int input_offset = 4;
-        unsigned int output_offset = 0;
-        unsigned char control_byte = 0;
-        unsigned char control_bit = 0;
-
-        while (input_offset < inputBufferSize)
-        {
-            if (control_bit == 0)
-            {
-                control_byte = compressed[input_offset++];
-                control_bit = 8;
-            }
-
-            if (control_byte & 1)
-            {
-                extract_buffer[output_offset++] = compressed[input_offset++];
-
-                if (output_offset == extract_size)
-                {
-                    extract_size += 256;
-                    extract_buffer.resize(extract_size);
-                }
-            }
-            else
-            {
-                const unsigned char reference1 = compressed[input_offset++];
-                const unsigned char reference2 = compressed[input_offset++];
-
-                const unsigned short int reference_offset = reference1 | ((reference2 & 0xF0) << 4);
-
-                const unsigned char reference_length = (reference2 & 0xF) + 3;
-
-                int real_offset = output_offset - ((output_offset - 18 - reference_offset) & 0xFFF);
-
-                for (int j = 0; j < reference_length; ++j)
-                {
-                    if (real_offset < 0)
-                    {
-                        extract_buffer[output_offset++] = 0;
-                    }
-                    else
-                    {
-                        extract_buffer[output_offset++] = extract_buffer[real_offset];
-                    }
-
-                    if (output_offset == extract_size)
-                    {
-                        extract_size += 256;
-                        extract_buffer.resize(extract_size);
-                    }
-
-                    ++real_offset;
-                }
-            }
-
-            control_byte >>= 1;
-            control_bit--;
-        }
-
-        // Truncate to exact size
-        extract_buffer.resize(output_offset);
-        return extract_buffer;
-    }
-}

+ 0 - 21
V-Gears-Installer/include/common/make_unique.h

@@ -1,21 +0,0 @@
-// TODO: This file can be deleted
-
-#pragma once
-
-#ifndef _MAKE_UNIQUE_
-#define _MAKE_UNIQUE_
-
-#include <memory>
-
-#ifndef _MSC_VER
-namespace std
-{
-    template<typename T, typename ...Args>
-    std::unique_ptr<T> make_unique( Args&& ...args )
-    {
-        return std::unique_ptr<T>( new T( std::forward<Args>(args)... ) );
-    }
-}
-#endif
-
-#endif // _MAKE_UNIQUE_

+ 0 - 47
V-Gears-Installer/include/common/noncopyable.h

@@ -1,47 +0,0 @@
-/* ScummVM Tools
- *
- * ScummVM Tools is the legal property of its developers, whose
- * names are too numerous to list here. Please refer to the
- * COPYRIGHT file distributed with this source distribution.
- *
- * 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.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifndef COMMON_NONCOPYABLE_H
-#define COMMON_NONCOPYABLE_H
-
-namespace Common {
-
-/**
- * Subclass of NonCopyable can not be copied due to the fact that
- * we made the copy constructor and assigment operator private.
- */
-class NonCopyable {
-public:
-	NonCopyable() {}
-private:
-	// Prevent copying instances by accident
-	NonCopyable(const NonCopyable&);
-	NonCopyable& operator=(const NonCopyable&);
-};
-
-} // End of namespace Common
-
-#endif

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

@@ -1,101 +1,89 @@
-/* ScummVM Tools
+/*
+ * Copyright (C) 2022 The V-Gears Team
  *
- * ScummVM Tools is the legal property of its developers, whose
- * names are too numerous to list here. Please refer to the
- * COPYRIGHT file distributed with this source distribution.
+ * This file is part of V-Gears
  *
- * 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 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.
  *
- * 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,
+ * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
-
 #ifndef COMMON_SCUMMSYS_H
 #define COMMON_SCUMMSYS_H
 
 
 #if defined(_WIN32_WCE) && _WIN32_WCE < 300
-	#define NONSTANDARD_PORT
+    #define NONSTANDARD_PORT
 #endif
 
 #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)
 
-	#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
 
@@ -153,223 +141,223 @@
 
 #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)
 
-	#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)
 
-	#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__)
 
-	#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)
 
-	#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
 
-		#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__
-	#include <extras_string.h>
+    #include <extras_string.h>
 #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__)
 
-	#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__)
 
-	#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__)
 
-	#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__)
 
-	#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__)
 
-	#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__)
 
-	#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__)
 
-	#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__)
 
-	#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
-	#error No system type defined
+    #error No system type defined
 
 #endif
 
@@ -378,16 +366,16 @@
 // GCC specific stuff
 //
 #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
-	#define PACKED_STRUCT
-	#define GCC_PRINTF(x,y)
+    #define PACKED_STRUCT
+    #define GCC_PRINTF(x,y)
 #endif
 
 
@@ -403,11 +391,11 @@
 #endif
 
 #ifndef NORETURN_PRE
-#define	NORETURN_PRE
+#define    NORETURN_PRE
 #endif
 
 #ifndef NORETURN_POST
-#define	NORETURN_POST
+#define    NORETURN_POST
 #endif
 
 #ifndef STRINGBUFLEN
@@ -427,14 +415,14 @@
 // Typedef our system types unless SCUMMVM_DONT_DEFINE_TYPES is set.
 //
 #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
 
 
@@ -443,11 +431,11 @@
 // Overlay color type (FIXME: shouldn't be declared here)
 //
 #if defined(NEWGUI_256)
-	// 256 color only on PalmOS
-	typedef byte OverlayColor;
+    // 256 color only on PalmOS
+    typedef byte OverlayColor;
 #else
-	// 15/16 bit color mode everywhere else...
-	typedef uint16 OverlayColor;
+    // 15/16 bit color mode everywhere else...
+    typedef uint16 OverlayColor;
 #endif
 
 

+ 0 - 257
V-Gears-Installer/include/common/str.h

@@ -1,257 +0,0 @@
-/* ScummVM Tools
- *
- * ScummVM Tools is the legal property of its developers, whose
- * names are too numerous to list here. Please refer to the
- * COPYRIGHT file distributed with this source distribution.
- *
- * 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.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifndef COMMON_STRING_H
-#define COMMON_STRING_H
-
-#include "common/scummsys.h"
-#include <string>
-
-namespace Common {
-
-/**
- * Simple string class for ScummVM. Provides automatic storage managment,
- * and overloads several operators in a 'natural' fashion, mimicking
- * the std::string class. Even provides simple iterators.
- *
- */
-class String {
-protected:
-	/**
-	 * Pointer to the actual string storage. Either points to _storage,
-	 * or to a block allocated on the heap via malloc.
-	 */
-	std::string		_str;
-
-public:
-	/** Construct a new empty string. */
-    String() = default;
-
-	/** Construct a new string from the given NULL-terminated C string. */
-	String(const char *str);
-
-	/** Construct a new string containing exactly len characters read from address str. */
-	String(const char *str, uint32 len);
-
-	/** Construct a new string containing the characters between beginP (including) and endP (excluding). */
-	String(const char *beginP, const char *endP);
-
-	/** Construct a copy of the given string. */
-	String(const String &str);
-
-	/** Construct a string consisting of the given character. */
-	explicit String(char c);
-
-	~String();
-
-	String &operator  =(const char *str);
-	String &operator  =(const String &str);
-	String &operator  =(char c);
-	String &operator +=(const char *str);
-	String &operator +=(const String &str);
-	String &operator +=(char c);
-
-	bool operator ==(const String &x) const;
-	bool operator ==(const char *x) const;
-	bool operator !=(const String &x) const;
-	bool operator !=(const char *x) const;
-
-	bool operator <(const String &x) const;
-	bool operator <=(const String &x) const;
-	bool operator >(const String &x) const;
-	bool operator >=(const String &x) const;
-
-	bool equals(const String &x) const;
-	bool equalsIgnoreCase(const String &x) const;
-	int compareTo(const String &x) const;	// strcmp clone
-	int compareToIgnoreCase(const String &x) const;	// stricmp clone
-
-	bool equals(const char *x) const;
-	bool equalsIgnoreCase(const char *x) const;
-	int compareTo(const char *x) const;	// strcmp clone
-	int compareToIgnoreCase(const char *x) const;	// stricmp clone
-
-	bool hasSuffix(const String &x) const;
-	bool hasSuffix(const char *x) const;
-
-	bool hasPrefix(const String &x) const;
-	bool hasPrefix(const char *x) const;
-
-	bool contains(const String &x) const;
-	bool contains(const char *x) const;
-	bool contains(char x) const;
-
-	/**
-	 * Simple DOS-style pattern matching function (understands * and ? like used in DOS).
-	 * Taken from exult/files/listfiles.cc
-	 *
-	 * Token meaning:
-	 *		"*": any character, any amount of times.
-	 *		"?": any character, only once.
-	 *
-	 * Example strings/patterns:
-	 *		String: monkey.s01	 Pattern: monkey.s??	=> true
-	 *		String: monkey.s101	 Pattern: monkey.s??	=> false
-	 *		String: monkey.s99	 Pattern: monkey.s?1	=> false
-	 *		String: monkey.s101	 Pattern: monkey.s*		=> true
-	 *		String: monkey.s99	 Pattern: monkey.s*1	=> false
-	 *
-	 * @param str Text to be matched against the given pattern.
-	 * @param pat Glob pattern.
-	 * @param ignoreCase Whether to ignore the case when doing pattern match
-	 * @param pathMode Whether to use path mode, i.e., whether slashes must be matched explicitly.
-	 *
-	 * @return true if str matches the pattern, false otherwise.
-	 */
-	bool matchString(const char *pat, bool ignoreCase = false, bool pathMode = false) const;
-	bool matchString(const String &pat, bool ignoreCase = false, bool pathMode = false) const;
-
-
-	inline const char *c_str() const		{ return _str.c_str(); }
-	inline uint size() const				{ return uint(_str.size()); }
-
-	inline bool empty() const	{ return (_str.empty() == 0); }
-	char lastChar() const	{ return (_str.size() > 0) ? _str[_str.size()-1] : 0; }
-
-	char operator[](int idx) const {
-		assert(idx >= 0 && idx < (int)_str.size());
-		return _str[idx];
-	}
-
-	/** Set character c at position p, replacing the previous character there. */
-	void setChar(char c, uint32 p);
-
-	/** Insert character c before position p. */
-	void insertChar(char c, uint32 p);
-
-	/** Clears the string, making it empty. */
-	void clear();
-
-	/** Convert all characters in the string to lowercase. */
-	void toLowercase();
-
-	/** Convert all characters in the string to uppercase. */
-	void toUppercase();
-
-public:
-	typedef char *        iterator;
-	typedef const char *  const_iterator;
-
-	iterator		begin() {
-		return &_str[0];
-	}
-
-	iterator		end() {
-		return begin() + size();
-	}
-
-	const_iterator	begin() const {
-		return &_str[0];
-	}
-
-	const_iterator	end() const {
-		return begin() + size();
-	}
-
-protected:
-	void initWithCStr(const char *str, uint32 len);
-};
-
-// Append two strings to form a new (temp) string
-String operator +(const String &x, const String &y);
-
-String operator +(const char *x, const String &y);
-String operator +(const String &x, const char *y);
-
-String operator +(const String &x, char y);
-String operator +(char x, const String &y);
-
-// Some useful additional comparison operators for Strings
-bool operator == (const char *x, const String &y);
-bool operator != (const char *x, const String &y);
-
-// Utility functions to remove leading and trailing whitespaces
-extern char *ltrim(char *t);
-extern char *rtrim(char *t);
-extern char *trim(char *t);
-
-
-/**
- * Returns the last component of a given path.
- *
- * Examples:
- *			/foo/bar.txt would return 'bar.txt'
- *			/foo/bar/    would return 'bar'
- *			/foo/./bar//    would return 'bar'
- *
- * @param path the path of which we want to know the last component
- * @param sep character used to separate path components
- * @return The last component of the path.
- */
-Common::String lastPathComponent(const Common::String &path, const char sep);
-
-/**
- * Normalize a gien path to a canonical form. In particular:
- * - trailing separators are removed:  /foo/bar/ -> /foo/bar
- * - double separators (= empty components) are removed:   /foo//bar -> /foo/bar
- * - dot components are removed:  /foo/./bar -> /foo/bar
- *
- * @todo remove double dot components:  /foo/baz/../bar -> /foo/bar
- *
- * @param path	the path to normalize
- * @param sep	the separator token (usually '/' on Unix-style systems, or '\\' on Windows based stuff)
- * @return	the normalized path
- */
-Common::String normalizePath(const Common::String &path, const char sep);
-
-
-/**
- * Simple DOS-style pattern matching function (understands * and ? like used in DOS).
- * Taken from exult/files/listfiles.cc
- *
- * Token meaning:
- *		"*": any character, any amount of times.
- *		"?": any character, only once.
- *
- * Example strings/patterns:
- *		String: monkey.s01	 Pattern: monkey.s??	=> true
- *		String: monkey.s101	 Pattern: monkey.s??	=> false
- *		String: monkey.s99	 Pattern: monkey.s?1	=> false
- *		String: monkey.s101	 Pattern: monkey.s*		=> true
- *		String: monkey.s99	 Pattern: monkey.s*1	=> false
- *
- * @param str Text to be matched against the given pattern.
- * @param pat Glob pattern.
- * @param ignoreCase Whether to ignore the case when doing pattern match
- * @param pathMode Whether to use path mode, i.e., whether slashes must be matched explicitly.
- *
- * @return true if str matches the pattern, false otherwise.
- */
-bool matchString(const char *str, const char *pat, bool ignoreCase = false, bool pathMode = false);
-
-}	// End of namespace Common
-
-#endif

+ 0 - 85
V-Gears-Installer/include/common/util.h

@@ -1,85 +0,0 @@
-/* ScummVM Tools
- *
- * ScummVM Tools is the legal property of its developers, whose
- * names are too numerous to list here. Please refer to the
- * COPYRIGHT file distributed with this source distribution.
- *
- * 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.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifndef COMMON_UTIL_H
-#define COMMON_UTIL_H
-
-#include "common/scummsys.h"
-#include <streambuf>
-#include <ostream>
-
-#ifdef MIN
-#undef MIN
-#endif
-
-#ifdef MAX
-#undef MAX
-#endif
-
-// Define an ostream which doesn't output anything to avoid clutter
-// Source: http://groups.google.com/group/comp.lang.c++/msg/4a81a74500f9f4d3?hl=en
-template<class cT, class traits = std::char_traits<cT> >
-class basic_nullbuf : public std::basic_streambuf < cT, traits > {
-    typename traits::int_type overflow(typename traits::int_type c)
-    {
-        return traits::not_eof(c);
-    }
-};
-
-template<class cT, class traits = std::char_traits<cT> >
-class basic_onullstream : public std::basic_ostream < cT, traits > {
-public:
-    basic_onullstream() :
-        std::basic_ios<cT, traits>(&m_sbuf),
-        std::basic_ostream<cT, traits>(&m_sbuf)
-    {
-        this->init(&m_sbuf);
-    }
-
-private:
-    basic_nullbuf<cT, traits> m_sbuf;
-};
-
-typedef basic_onullstream<char> onullstream;
-
-template<typename T> inline T ABS (T x)			{ return (x>=0) ? x : -x; }
-template<typename T> inline T MIN (T a, T b)	{ return (a<b) ? a : b; }
-template<typename T> inline T MAX (T a, T b)	{ return (a>b) ? a : b; }
-template<typename T> inline T CLIP (T v, T amin, T amax)
-		{ if (v < amin) return amin; else if (v > amax) return amax; else return v; }
-
-
-/**
- * Template method which swaps the vaulues of its two parameters.
- */
-template<typename T> inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; }
-
-/**
- * Macro which determines the number of entries in a fixed size array.
- */
-#define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))
-
-#endif

+ 11 - 11
V-Gears-Installer/include/decompiler/decompiler_codegen.h

@@ -43,8 +43,8 @@ const int kIndentAmount = 4; ///< How many spaces to use for each indent.
  */
 enum ArgOrder
 {
-    kFIFOArgOrder, ///< First argument is pushed to stack first.
-    kLIFOArgOrder  ///< First argument is pushed to stack last.
+    FIFO_ARGUMENT_ORDER, ///< First argument is pushed to stack first.
+    LIFO_ARGUMENT_ORDER  ///< First argument is pushed to stack last.
 };
 
 class ITargetLanaguge
@@ -296,7 +296,7 @@ protected:
     ValueStack _stack;      ///< The stack currently being processed.
     uint _indentLevel;      ///< Indentation level.
     GraphVertex _curVertex; ///< Graph vertex currently being processed.
-    std::unique_ptr<ITargetLanaguge> mTargetLang;
+    std::unique_ptr<ITargetLanaguge> target_lang_;
 
     /**
      * Processes an instruction. Called by process() for each instruction.
@@ -322,10 +322,10 @@ protected:
      *
      * @param func Reference to the function to construct the signature for.
      */
-    virtual std::string constructFuncSignature(const Function& func);
-    virtual void onBeforeStartFunction(const Function& func);
-    virtual void onEndFunction(const Function& func);
-    virtual void onStartFunction(const Function&) { }
+    virtual std::string ConstructFuncSignature(const Function& func);
+    virtual void OnBeforeStartFunction(const Function& func);
+    virtual void OnEndFunction(const Function& func);
+    virtual void OnStartFunction(const Function&) { }
     virtual bool OutputOnlyRequiredLabels() const { return false; }
 
     void generatePass(InstVec& insts, const Graph& g);
@@ -334,8 +334,8 @@ protected:
 public:
     ITargetLanaguge& TargetLang()
     {
-        assert(mTargetLang);
-        return *mTargetLang;
+        assert(target_lang_);
+        return *target_lang_;
     }
 
     void writeFunctionCall(std::string functionName, std::string paramsFormat, const std::vector<ValuePtr>& params);
@@ -362,7 +362,7 @@ public:
      *
      * @param g The annotated graph of the script.
      */
-    virtual void generate(InstVec& insts, const Graph &g);
+    virtual void Generate(InstVec& insts, const Graph &g);
 
     /**
      * Adds a line of code to the current group.
@@ -371,7 +371,7 @@ public:
      * @param unindentBefore Whether or not to remove an indentation level before the line. Defaults to false.
      * @param indentAfter Whether or not to add an indentation level after the line. Defaults to false.
      */
-    virtual void addOutputLine(std::string s, bool unindentBefore = false, bool indentAfter = false);
+    virtual void AddOutputLine(std::string s, bool unindentBefore = false, bool indentAfter = false);
 
     /**
      * Generate an assignment statement.

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

@@ -26,7 +26,7 @@
 #include <vector>
 
 #include "instruction.h"
-#include "common/binaryreader.h"
+#include "common/BinaryReader.h"
 #include "unknown_opcode_exception.h"
 #include "objectFactory.h"
 
@@ -35,23 +35,23 @@
  */
 class Disassembler {
 protected:
-	std::unique_ptr<BinaryReader> mStream;                         ///< Used to perform file I/O.
+	std::unique_ptr<BinaryReader> stream_;                         ///< Used to perform file I/O.
 	InstVec &_insts;                              ///< Container for disassembled instructions.
-	uint32 _addressBase;                          ///< Base address where the script starts.
+	uint32 address_base_;                          ///< Base address where the script starts.
 
 	/**
 	 * Performs disassembly.
 	 *
 	 * @throws UnknownOpcodeException on unknown opcode. May throw std::exception on other failures.
 	 */
-	virtual void doDisassemble() = 0;
+	virtual void DoDisassemble() = 0;
 
 	/**
 	 * Outputs the disassembled code.
 	 *
 	 * @param output The std::ostream to output to.
 	 */
-	virtual void doDumpDisassembly(std::ostream &output);
+	virtual void DoDumpDisassembly(std::ostream &output);
 
 public:
 	/**
@@ -67,20 +67,20 @@ public:
 	 *
 	 * @param filename The file to disassemble.
 	 */
-	virtual void open(const char *filename);
+	virtual void Open(const char *filename);
 
 	/**
 	 * Request 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.
 	 *
 	 * @param output The std::ostream to output to.
 	 */
-	void dumpDisassembly(std::ostream &output);
+	void DumpDisassembly(std::ostream &output);
 };
 #endif

+ 414 - 0
V-Gears-Installer/include/decompiler/field/FieldCodeGenerator.h

@@ -0,0 +1,414 @@
+/*
+ * 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/decompiler_codegen.h"
+#include <boost/algorithm/string.hpp>
+#include <deque>
+#include <unordered_map>
+#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();
+            }
+        }
+
+        /**
+         * 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_;
+
+};

+ 737 - 0
V-Gears-Installer/include/decompiler/field/FieldDisassembler.h

@@ -0,0 +1,737 @@
+/*
+ * 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 <array>
+#include "decompiler/simple_disassembler.h"
+#include "decompiler/sudm.h"
+
+
+class BinaryReader;
+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{
+
+    /**
+     * 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;
+};
+
+std::map<std::string, const InstructionRecord*> FieldInstructions();
+
+class FF7FieldEngine;
+
+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, FF7FieldEngine* 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, FF7FieldEngine* 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.
+         */
+        FF7FieldEngine* 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{
+
+            /**
+             * 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
+        };
+
+        /**
+         * 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{
+
+            /**
+             * 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;
+        };
+
+        /**
+         * A script header.
+         */
+        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);
+                }
+            }
+        };
+
+        /**
+         * 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;
+};

+ 0 - 244
V-Gears-Installer/include/decompiler/field/ff7_field_codegen.h

@@ -1,244 +0,0 @@
-#pragma  once
-
-#include "decompiler/decompiler_codegen.h"
-#include <boost/algorithm/string.hpp>
-#include <deque>
-#include <unordered_map>
-#include "common/make_unique.h"
-#include "decompiler/sudm.h"
-
-namespace FF7
-{
-    class FunctionMetaData
-    {
-    public:
-        // Meta data format can be:
-        // start_end_entityname
-        // start_entityname
-        // end_entity_name
-        FunctionMetaData(std::string metaData)
-        {
-            Parse(metaData);
-        }
-
-        bool IsStart() const
-        {
-            return mStart;
-        }
-
-        bool IsEnd() const
-        {
-            return mEnd;
-        }
-
-        std::string EntityName()
-        {
-            return mEntityName;
-        }
-
-        int CharacterId()
-        {
-            return mCharacterId;
-        }
-
-    private:
-        void Parse(std::string str)
-        {
-            std::deque<std::string> strs;
-            boost::split(strs, str, boost::is_any_of("_"), boost::token_compress_on);
-            if (!strs.empty())
-            {
-                auto tmp = strs.front();
-                strs.pop_front();
-                ParseStart(tmp, strs);
-            }
-        }
-
-        void ParseStart(const std::string& item, std::deque<std::string>& strs)
-        {
-            if (item == "start")
-            {
-                mStart = true;
-                if (!strs.empty())
-                {
-                    auto tmp = strs.front();
-                    strs.pop_front();
-                    ParseEnd(tmp, strs);
-                }
-            }
-            else
-            {
-                ParseEnd(item, strs);
-            }
-        }
-
-        void ParseEnd(const std::string& item, std::deque<std::string>& strs)
-        {
-            if (item == "end")
-            {
-                mEnd = true;
-                if (!strs.empty())
-                {
-                    auto tmp = strs.front();
-                    strs.pop_front();
-                    ParseCharId(tmp, strs);
-                }
-            }
-            else
-            {
-                ParseCharId(item, strs);
-            }
-        }
-
-        void ParseCharId(const std::string& item, std::deque<std::string>& strs)
-        {
-            if (!item.empty())
-            {
-                mCharacterId = std::stoi(item);
-            }
-            if (!strs.empty())
-            {
-                auto tmp = strs.front();
-                strs.pop_front();
-                ParseEntity(tmp, strs);
-            }
-        }
-
-        void ParseEntity(const std::string& item, std::deque<std::string>& strs)
-        {
-            mEntityName = item;
-            for (auto& part : strs)
-            {
-                if (!part.empty())
-                {
-                    mEntityName += "_" + part;
-                }
-            }
-        }
-
-        bool mEnd = false;
-        bool mStart = false;
-        std::string mEntityName;
-        int mCharacterId = -1;
-    };
-
-    class FF7CodeGenerator : public CodeGenerator
-    {
-    public:
-        FF7CodeGenerator(Engine *engine, const InstVec& insts, std::ostream &output)
-            : CodeGenerator(engine, output, kFIFOArgOrder, kLIFOArgOrder),
-              mInsts(insts)
-        {
-            mTargetLang = std::make_unique<LuaTargetLanguage>();
-        }
-    protected:
-        virtual std::string constructFuncSignature(const Function &func) override;
-        virtual void onEndFunction(const Function& func) override;
-        virtual void onBeforeStartFunction(const Function& func) override;
-        virtual void onStartFunction(const Function& func) override;
-        virtual bool OutputOnlyRequiredLabels() const override { return true; }
-    private:
-        const InstVec& mInsts;
-    };
-
-
-    class FF7SimpleCodeGenerator : public CodeGenerator
-    {
-    public:
-        FF7SimpleCodeGenerator(Engine *engine, const InstVec& insts, std::ostream &output, SUDM::IScriptFormatter& formatter)
-            : CodeGenerator(engine, output, kFIFOArgOrder, kLIFOArgOrder),
-            mInsts(insts), mFormatter(formatter)
-        {
-            mTargetLang = std::make_unique<LuaTargetLanguage>();
-        }
-        virtual void generate(InstVec& insts, const Graph &g) override;
-        virtual void addOutputLine(std::string s, bool unindentBefore = false, bool indentAfter = false) override;
-        float ScaleFactor() const;
-    protected:
-        virtual std::string constructFuncSignature(const Function &func) override;
-        virtual void onEndFunction(const Function& func) override;
-        virtual void onBeforeStartFunction(const Function& func) override;
-        virtual void onStartFunction(const Function& func) override;
-        virtual bool OutputOnlyRequiredLabels() const override { return true; }
-    private:
-        const InstVec& mInsts;
-        std::vector<CodeLine> mLines;
-    public:
-        SUDM::IScriptFormatter& mFormatter;
-    };
-
-    namespace FF7CodeGeneratorHelpers
-    {
-        enum struct ValueType : int
-        {
-            Integer = 0,
-            Float = 1
-        };
-
-        const std::string FormatInstructionNotImplemented(const std::string& entity, uint32 address, uint32 opcode);
-        const std::string FormatInstructionNotImplemented(const std::string& entity, uint32 address, const Instruction& instruction);
-        const std::string FormatBool(uint32 value);
-        const std::string FormatInvertedBool(uint32 value);
- 
-        template<typename TValue>
-
-        /**
-         * 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.
-         */
-        const std::string FormatValueOrVariable(
-          SUDM::IScriptFormatter& formatter, uint32 bank, TValue valueOrAddress,
-          ValueType valueType = ValueType::Integer, float scale = 1.0f
-        ){
-            switch (bank){
-                case 0:
-                    switch (valueType){
-                        // TODO: check for zero
-                        case ValueType::Float: return std::to_string(valueOrAddress / scale);
-                        case ValueType::Integer: return std::to_string(valueOrAddress);
-                        default: return std::to_string(valueOrAddress);
-                    }
-                case 1:
-                case 2:
-                case 3:
-                case 13:
-                case 15:
-                    {
-                        const auto address = static_cast<uint32>(valueOrAddress) & 0xFF;
-                        const auto friendly_name = formatter.VarName(bank, valueOrAddress);
-                        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>(valueOrAddress)& 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:
-                    //throw UnknownBankException();
-                    return (boost::format(
-                      "FFVII.Banks[%1%][%2%]") % bank % (static_cast<uint32>(valueOrAddress) & 0xFF)
-                    ).str();
-            }
-        }
-    }
-}

+ 0 - 479
V-Gears-Installer/include/decompiler/field/ff7_field_disassembler.h

@@ -1,479 +0,0 @@
-#pragma once
-
-#include "decompiler/simple_disassembler.h"
-#include "decompiler/sudm.h"
-#include <array>
-
-class BinaryReader;
-class Function;
-
-namespace FF7
-{
-    enum eOpcodes
-    {
-        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
-    };
-
-    enum eSpecialOpcodes
-    {
-        ARROW = 0xF5,
-        PNAME = 0xF6,
-        GMSPD = 0xF7,
-        SMSPD = 0xF8,
-        FLMAT = 0xF9,
-        FLITM = 0xFA,
-        BTLCK = 0xFB,
-        MVLCK = 0xFC,
-        SPCNM = 0xFD,
-        RSGLB = 0xFE,
-        CLITM = 0xFF
-    };
-
-    enum eKawaiOpcodes
-    {
-        EYETX = 0x00,
-        TRNSP = 0x01,
-        AMBNT = 0x02,
-        Unknown03 = 0x03, // Makou Reactor can write these unknowns, so we'll include them for now
-        Unknown04 = 0x04,
-        Unknown05 = 0x05,
-        LIGHT = 0x06,
-        Unknown07 = 0x07,
-        Unknown08 = 0x08,
-        Unknown09 = 0x09,
-        SBOBJ = 0x0A,
-        Unknown0B = 0x0B,
-        Unknown0C = 0x0C,
-        SHINE = 0x0D,
-        RESET = 0xFF
-    };
-
-    struct TInstructRecord
-    {
-        unsigned char mOpCodeSize;
-        unsigned int mOpCode;
-        const char* mMnemonic;
-        const char* mArgumentFormat;
-        std::function<InstPtr()> mFactoryFunc;
-    };
-
-    std::map<std::string, const TInstructRecord*> FieldInstructions();
-
-    class FF7FieldEngine;
-    class FF7Disassembler : public SimpleDisassembler
-    {
-    public:
-        FF7Disassembler(SUDM::IScriptFormatter& formatter, FF7FieldEngine* engine, InstVec& insts);
-        FF7Disassembler(SUDM::IScriptFormatter& formatter, FF7FieldEngine* engine, InstVec& insts, const std::vector<unsigned char>& rawScriptData);
-        ~FF7Disassembler();
-
-    private:
-        // DO NOT USE - todo, remove from base
-        virtual void open(const char *filename) override;
-    public:
-        virtual void doDisassemble() override;
-        float ScaleFactor() const { return mScaleFactor; }
-    private:
-        void DisassembleIndivdualScript(std::string entityName,
-            size_t entityIndex,
-            size_t scriptEntryPoint,
-            size_t scriptIndex,
-            uint32 nextScriptEntryPoint,
-            bool isStart,
-            bool isEnd);
-
-        /**
-         * 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.
-         */
-        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 scriptIndex);
-
-        FF7FieldEngine* mEngine;
-
-        uint32 mHeaderEndPos = 0;
-        void ReadHeader();
-        void ReadHeader(BinaryReader& reader)
-        {
-            mHeader.Read(reader);
-            mHeaderEndPos = reader.Position();
-        }
-
-        const static int kMagic = 0x0502;
-        const static int kNumSections = 7;
-        int16 kSectionPointersSize = sizeof(uint32) * kNumSections;
-        enum eSections
-        {
-            eScript = 0,
-            eWalkMesh = 1,
-            eTileMap = 2,
-            eCameraMatrix = 3,
-            eTriggers = 4,
-            eEncounter = 5,
-            eModels = 6
-        };
-
-        std::array<uint32, 7> mSections;
-        uint32 GetEndOfScriptOffset(uint16 curEntryPoint, size_t entityIndex, size_t scriptIndex);
-
-        struct ScriptHeader
-        {
-            uint16 mMagic;
-            uint8 mNumberOfEntities;
-            uint8 mNumberOfModels;
-            uint16 mOffsetToStrings;
-            uint16 mNumberOfAkaoOffsets; // Specifies the number of Akao/tuto blocks/offsets
-            uint16 mScale; // Scale of field. For move and talk calculation (9bit fixed point).
-            std::array<uint16, 3> mBlank;
-            std::array<char, 8> mCreator;// Field creator (never shown)
-            std::array<char, 8> mName;// Field name (never shown)
-            std::vector<std::array<char, 8>> mFieldEntityNames;  // Count is mNumberOfEntities
-            std::vector<uint32> mAkaoOffsets; // Akao/Tuto block offsets, count is mNumberOfAkaoOffsets
-
-            // Entity script entry points, or more explicitly, subroutine offsets
-            std::vector<std::array<uint16, 32>> mEntityScripts; // Count is mNumberOfEntities
-
-            void Read(BinaryReader& r)
-            {
-                mMagic = r.ReadU16();
-                if (mMagic != kMagic)
-                {
-                    throw FF7ScriptHeaderInvalidException();
-                }
-                mNumberOfEntities = r.ReadU8();
-                mNumberOfModels = r.ReadU8();
-                mOffsetToStrings = r.ReadU16();
-                mNumberOfAkaoOffsets = r.ReadU16();
-                mScale = r.ReadU16();
-                for (int i = 0; i < 3; i++)
-                {
-                    mBlank[i] = r.ReadU16();
-                }
-
-                for (int i = 0; i < 8; i++)
-                {
-                    mCreator[i] = r.ReadU8();
-                }
-
-                for (int i = 0; i < 8; i++)
-                {
-                    mName[i] = r.ReadU8();
-                }
-
-                for (int i = 0; i < mNumberOfEntities; i++)
-                {
-                    std::array<char, 8> name;
-                    for (int j = 0; j < 8; j++)
-                    {
-                        name[j] = r.ReadU8();
-                    }
-                    mFieldEntityNames.emplace_back(name);
-                }
-
-                for (int i = 0; i < mNumberOfAkaoOffsets; i++)
-                {
-                    mAkaoOffsets.emplace_back(r.ReadU32());
-                }
-
-                mEntityScripts.reserve(mNumberOfEntities);
-                for (int i = 0; i < mNumberOfEntities; i++)
-                {
-                    std::array<uint16, 32> scripts;
-                    for (int j = 0; j < 32; j++)
-                    {
-                        scripts[j] = r.ReadU16();
-                    }
-                    mEntityScripts.push_back(scripts);
-                }
-            }
-        };
-        ScriptHeader mHeader;
-        bool mbFromRaw = false;
-        SUDM::IScriptFormatter& mFormatter;
-        float mScaleFactor = 1.0f;
-    };
-
-}

+ 6 - 6
V-Gears-Installer/include/decompiler/field/ff7_field_engine.h

@@ -23,7 +23,7 @@
 #include <vector>
 #include "decompiler/sudm.h"
 
-namespace FF7{
+//namespace FF7{
 
     /**
      * Represents the FF7 Field engine.
@@ -296,14 +296,14 @@ namespace FF7{
              *
              * @return A list of non-line entities.
              */
-            std::vector<SUDM::FF7::Field::FieldEntity> GetEntityList() const;
+            std::vector<SUDM::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;
+            std::vector<SUDM::Field::Line> GetLineList() const;
 
             /**
              * Retrieves all entities in the map.
@@ -368,7 +368,7 @@ namespace FF7{
              *
              * @return Map scale factor.
              */
-            float ScaleFactor() const {return mScaleFactor;}
+            float GetScaleFactor() const {return scale_factor_;}
 
             /**
              * Retrieves the script name.
@@ -430,7 +430,7 @@ namespace FF7{
             /**
              * The map scale factor.
              */
-            float mScaleFactor = 1.0f;
+            float scale_factor_ = 1.0f;
 
             /**
              * The script name.
@@ -1551,4 +1551,4 @@ namespace FF7{
               Function& func, ValueStack &stack, Engine *engine, CodeGenerator *code_gen
             ) override;
     };
-}
+//}

+ 0 - 103
V-Gears-Installer/include/decompiler/scummv6/codegen.h

@@ -1,103 +0,0 @@
-/* ScummVM Tools
- *
- * ScummVM Tools is the legal property of its developers, whose
- * names are too numerous to list here. Please refer to the
- * COPYRIGHT file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifndef SCUMM_V6_CODEGEN_H
-#define SCUMM_V6_CODEGEN_H
-
-#include "../decompiler_codegen.h"
-
-namespace Scumm {
-
-namespace v6 {
-
-/**
- * SCUMM v6 list value.
- */
-class ListValue : public Value {
-protected:
-	const ValueList _items; ///< The list items.
-
-public:
-    ListValue(const ListValue&) = delete;
-    ListValue& operator = (const ListValue&) = delete;
-
-	/**
-	 * Constructor for ListValue.
-	 *
-	 * @param items The list items, stored left-to-right.
-	 */
-	ListValue(ValueList items) : _items(items) { }
-
-	virtual std::ostream &print(std::ostream &output) const;
-};
-
-/**
- * SCUMMv6 code generator.
- */
-class Scummv6CodeGenerator : public CodeGenerator {
-public:
-	/**
-	 * Constructor for Scumm::v6::CodeGenerator.
-	 *
-	 * @param engine Pointer to the Engine used for the script.
-	 * @param output The std::ostream to output the code to.
-	 */
-	Scummv6CodeGenerator(Engine *engine, std::ostream &output) : CodeGenerator(engine, output, kFIFOArgOrder, kFIFOArgOrder) {}
-
-	/**
-	 * Get the name associated with a variable ID.
-	 *
-	 * @param varID The ID to get the name for.
-	 * @return Pointer to char array containing the name of the variable, or NULL if no name exists.
-	 */
-	const char *getVarName(uint16 varID);
-
-	/**
-	 * Decode a variable ID to a name.
-	 *
-	 * @param varID The ID to decode.
-	 * @return The decoded variable name.
-	 */
-	std::string decodeVarName(uint16 varID);
-
-	/**
-	 * Decode an array ID to a name.
-	 *
-	 * @param arrID The ID to decode.
-	 * @return The decoded array name.
-	 */
-	std::string decodeArrayName(uint16 arrID);
-
-	/**
-	 * Creates a ListValue from the stack.
-	 *
-	 * @return The ListValue created from the stack.
-	 */
-	ValuePtr createListValue();
-
-	virtual void processSpecialMetadata(const InstPtr inst, char c, int pos);
-};
-
-} // End of namespace v6
-
-} // End of namespace Scumm
-
-#endif

+ 0 - 63
V-Gears-Installer/include/decompiler/scummv6/disassembler.h

@@ -1,63 +0,0 @@
-/* ScummVM Tools
- *
- * ScummVM Tools is the legal property of its developers, whose
- * names are too numerous to list here. Please refer to the
- * COPYRIGHT file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifndef DEC_SCUMMV6_DISASM_H
-#define DEC_SCUMMV6_DISASM_H
-
-#include "decompiler/simple_disassembler.h"
-#include "engine.h"
-
-namespace Scumm {
-
-namespace v6 {
-
-/**
- * Disassembler for SCUMMv6.
- */
-class Scummv6Disassembler : public SimpleDisassembler {
-public:
-	/**
-	 * Constructor for Scummv6Disassembler.
-	 *
-	 * @param insts Reference to the vector in which disassembled instructions should be placed.
-	 */
-	Scummv6Disassembler(InstVec &insts);
-
-	void doDisassemble();
-
-	virtual ValuePtr readParameter(InstPtr inst, std::string type);
-
-	/**
-	 * Determines the actual stack effect of an opcode with a variable stack effect.
-	 *
-	 * @param it        Iterator pointing to the instruction to be fixed.
-	 * @param popBefore Number of pops prior to the variable-length list.
-	 * @param popAfter  Number of pops after the variable-length list.
-	 * @param pushTotal Number of values pushed from the instruction.
-	 */
-	void fixStackEffect(InstIterator &it, int popBefore, int popAfter, int pushTotal);
-};
-
-} // End of namespace v6
-
-} // End of namespace Scumm
-
-#endif

+ 0 - 121
V-Gears-Installer/include/decompiler/scummv6/engine.h

@@ -1,121 +0,0 @@
-/* ScummVM Tools
- *
- * ScummVM Tools is the legal property of its developers, whose
- * names are too numerous to list here. Please refer to the
- * COPYRIGHT file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifndef SCUMM_V6_ENGINE_H
-#define SCUMM_V6_ENGINE_H
-
-#include "../decompiler_engine.h"
-#include "../instruction.h"
-#include "../value.h"
-
-namespace Scumm {
-
-namespace v6 {
-
-const int kArrayOpInst = kFirstCustomInst;
-const int kIncDecInst = kFirstCustomInst + 1;
-
-/**
- * SCUMMv6 engine.
- */
-class Scummv6Engine : public Engine {
-public:
-    virtual std::unique_ptr<Disassembler> getDisassembler(InstVec &insts) override;
-    virtual std::unique_ptr<CodeGenerator> getCodeGenerator(const InstVec& insts, std::ostream &output) override;
-};
-
-/**
- * SCUMM v6 string value.
- */
-class Scummv6StringValue : public StringValue {
-public:
-	/**
-	 * Constructor for Scummv6StringValue.
-	 *
-	 * @param str The string value.
-	 */
-	Scummv6StringValue(std::string str) : StringValue(str) { }
-
-	virtual std::ostream &print(std::ostream &output) const;
-};
-
-/**
- * SCUMM v6 load instruction.
- */
-class Scummv6LoadInstruction : public LoadInstruction {
-public:
-	virtual void processInst(Function& func, ValueStack &stack, Engine *engine, CodeGenerator *codeGen) override;
-};
-
-/**
- * SCUMM v6 store instruction.
- */
-class Scummv6StoreInstruction : public StoreInstruction {
-public:
-	virtual void processInst(Function& func, ValueStack &stack, Engine *engine, CodeGenerator *codeGen) override;
-};
-
-/**
- * SCUMM v6 stack operation.
- */
-class Scummv6StackInstruction : public StackInstruction {
-public:
-	virtual void processInst(Function& func, ValueStack &stack, Engine *engine, CodeGenerator *codeGen) override;
-};
-
-/**
- * SCUMM v6 conditional jump.
- */
-class Scummv6CondJumpInstruction : public CondJumpInstruction {
-public:
-	virtual void processInst(Function& func, ValueStack &stack, Engine *engine, CodeGenerator *codeGen) override;
-	virtual uint32 getDestAddress() const;
-};
-
-/**
- * SCUMM v6 unconditional jump.
- */
-class Scummv6JumpInstruction : public UncondJumpInstruction {
-public:
-	virtual uint32 getDestAddress() const;
-};
-
-/**
- * SCUMM v6 variable increment/decrement.
- */
-class Scummv6IncDecInstruction : public UnaryOpPostfixStackInstruction {
-public:
-	virtual void processInst(Function& func, ValueStack &stack, Engine *engine, CodeGenerator *codeGen) override;
-};
-
-/**
- * SCUMM v6 array operation.
- */
-class Scummv6ArrayOpInstruction : public StoreInstruction {
-public:
-	virtual void processInst(Function& func, ValueStack &stack, Engine *engine, CodeGenerator *codeGen) override;
-};
-
-} // End of namespace v6
-
-} // End of namespace Scumm
-
-#endif

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

@@ -29,7 +29,7 @@
  */
 class SimpleDisassembler : public Disassembler {
 protected:
-	uint32 _address; ///< Variable to maintain the current address.
+	uint32 address_; ///< Variable to maintain the current address.
 
 	/**
 	 * Read parameters and associate them with an instruction.
@@ -58,20 +58,20 @@ public:
 	SimpleDisassembler(InstVec &insts);
 };
 
-#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 START_OPCODES \
-	this->_address = this->_addressBase; \
-            	while (this->mStream->Position() != (unsigned int)this->mStream->Size()) { \
+	this->address_ = this->address_base_; \
+            	while (this->stream_->Position() != (unsigned int)this->stream_->Size()) { \
 		uint32 full_opcode = 0; \
-		uint8 opcode = this->mStream->ReadU8(); \
+		uint8 opcode = this->stream_->ReadU8(); \
 		std::string opcodePrefix; \
 		switch (opcode) {
 #define END_OPCODES \
 		default: \
-			throw UnknownOpcodeException(this->_address, opcode);\
+			throw UnknownOpcodeException(this->address_, opcode);\
 		} \
 		INC_ADDR; \
 	}
@@ -86,7 +86,7 @@ public:
 #define OPCODE_BODY(name, category, stackChange, params, codeGenData) \
 		ADD_INST(category); \
 		LAST_INST->_opcode = full_opcode; \
-		LAST_INST->_address = this->_address; \
+		LAST_INST->_address = this->address_; \
 		LAST_INST->_stackChange = stackChange; \
 		LAST_INST->_name = opcodePrefix + std::string(name); \
 		LAST_INST->_codeGenData = codeGenData; \
@@ -97,21 +97,21 @@ public:
 		OPCODE_BODY(name, category, stackChange, params, codeGenData)\
 		OPCODE_END;
 
-#define OPCODE(val, name, category, stackChange, params) \
+#define CASE_OPCODE(val, name, category, stackChange, params) \
 	OPCODE_MD(val, name, category, stackChange, params, "")
 
 #define START_SUBOPCODE_WITH_PREFIX(val,prefix) \
 	OPCODE_BASE(val) \
 		opcodePrefix = prefix + std::string("."); \
-		opcode = this->mStream->ReadU8(); \
+		opcode = this->stream_->ReadU8(); \
 		switch (opcode) {
 #define START_SUBOPCODE(val) \
 	OPCODE_BASE(val) \
-		opcode = this->mStream->ReadU8(); \
+		opcode = this->stream_->ReadU8(); \
 		switch (opcode) {
 #define END_SUBOPCODE \
 		default: \
-			throw UnknownSubOpcodeException(this->_address, opcode);\
+			throw UnknownSubOpcodeException(this->address_, opcode);\
 		} \
 		INC_ADDR; \
 		OPCODE_END;

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

@@ -140,104 +140,103 @@ namespace SUDM{
             ){return "";}
         };
 
-    namespace FF7{
 
-        namespace Field{
 
-            /**
-             * A line.
-             */
-            struct Line{
-
-                /**
-                 * Name of the line entity.
-                 */
-                std::string name;
+    namespace Field{
 
-                /**
-                 * First point of the line.
-                 */
-                std::vector<float> point_a;
+        /**
+         * A line.
+         */
+        struct Line{
 
-                /**
-                 * Second point of the line.
-                 */
-                std::vector<float> point_b;
-            };
+            /**
+             * Name of the line entity.
+             */
+            std::string name;
 
             /**
-             * An entity.
+             * First point of the line.
              */
-            struct FieldEntity{
+            std::vector<float> point_a;
 
-                /**
-                 * Character identifier of the entity.
-                 */
-                uint char_id;
+            /**
+             * Second point of the line.
+             */
+            std::vector<float> point_b;
+        };
 
-                /**
-                 * Index of the entity in the field.
-                 */
-                uint index;
+        /**
+         * An entity.
+         */
+        struct FieldEntity{
 
-                /**
-                 * Name of the entity.
-                 */
-                std::string name;
-            };
+            /**
+             * Character identifier of the entity.
+             */
+            uint char_id;
 
             /**
-             * The field decompiled script.
+             * Index of the entity in the field.
              */
-            struct DecompiledScript{
+            uint index;
 
-                /**
-                 * The LUA script for the field.
-                 */
-                std::string luaScript;
+            /**
+             * Name of the entity.
+             */
+            std::string name;
+        };
 
-                /**
-                 * The field entities.
-                 *
-                 * Lines are not included.
-                 */
-                std::vector<FieldEntity> entities;
+        /**
+         * The field decompiled script.
+         */
+        struct DecompiledScript{
 
-                /**
-                 * Lines in the field.
-                 */
-                std::vector<Line> lines;
-            };
+            /**
+             * The LUA script for the field.
+             */
+            std::string luaScript;
 
             /**
-             * Retrieves the scale factor of a field.
+             * The field entities.
              *
-             * @param script_bytes[in] Vector of raw byte data that makes up
-             * the script.
-             * @return The scale fctor.
+             * Lines are not included.
              */
-            float ScaleFactor(const std::vector<unsigned char>& script_bytes);
+            std::vector<FieldEntity> entities;
 
             /**
-             * 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 = ""
-            );
-        }
+             * 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 = ""
+        );
     }
 }

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

@@ -25,7 +25,6 @@
 #include "decompiler/scummv6/engine.h"
 #include <gmock/gmock.h>
 #include <vector>
-#include "make_unique.h"
 
 #define GET(vertex) (boost::get(boost::vertex_name, g, vertex))
 

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

@@ -33,7 +33,6 @@
 #include <ostream>
 #include <gmock/gmock.h>
 #include "util.h"
-#include "make_unique.h"
 
 std::string removeSpaces(std::string s) {
     size_t found;

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

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

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

@@ -27,7 +27,7 @@
 class PasCDisassembler : public SimpleDisassembler {
 public:
 	PasCDisassembler(InstVec &insts);
-	virtual void doDisassemble() override;
+	virtual void DoDisassemble() 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) {
 }
 
-void SubOpcodeDisassembler::doDisassemble() {
+void SubOpcodeDisassembler::DoDisassemble() {
 	START_OPCODES;
 		START_SUBOPCODE(0xFF)
 			OPCODE(0xFF, "FOO", SubOpcodeFakeInstruction, 0, "");

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

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

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

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

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

@@ -4,7 +4,6 @@
 #include "decompiler/ff7_field/ff7_field_codegen.h"
 #include "control_flow.h"
 #include "util.h"
-#include "make_unique.h"
 #include "ff7_field_dummy_formatter.h"
 
 // Verify next 3 instructions are NOP's and return address of final NOP
@@ -13,7 +12,7 @@ static uint32 Is3Nops(InstVec& insts, uint32& pos)
     for (int i = 0; i < 3; i++)
     {
         pos++;
-        EXPECT_EQ(insts[pos]->_opcode, FF7::eOpcodes::NOP);
+        EXPECT_EQ(insts[pos]->_opcode, OPCODE::NOP);
         EXPECT_EQ(insts[pos]->_params.size(), 0);
     }
     return insts[pos]->_address;
@@ -22,7 +21,7 @@ static uint32 Is3Nops(InstVec& insts, uint32& pos)
 // 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
 // and should be the target address of the jump.
-static void CheckForwardJump(FF7::eOpcodes opCode, size_t paramsSize, InstVec& insts, uint32& pos)
+static void CheckForwardJump(OPCODE opCode, size_t paramsSize, InstVec& insts, uint32& pos)
 {
     pos++;
     const InstPtr& jumpInst = insts[pos];
@@ -37,7 +36,7 @@ static void CheckForwardJump(FF7::eOpcodes opCode, size_t paramsSize, InstVec& i
 static uint32 IsNop(InstVec& insts, uint32& pos)
 {
     pos++;
-    EXPECT_EQ(insts[pos]->_opcode, FF7::eOpcodes::NOP);
+    EXPECT_EQ(insts[pos]->_opcode, OPCODE::NOP);
     EXPECT_EQ(insts[pos]->_params.size(), 0);
     return insts[pos]->_address;
 }
@@ -45,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
 // should be targeting the second/middle NOP
-static void CheckBackwardJump(FF7::eOpcodes opCode, size_t paramsSize, InstVec& insts, uint32& pos)
+static void CheckBackwardJump(OPCODE opCode, size_t paramsSize, InstVec& insts, uint32& pos)
 {
     IsNop(insts, pos);
 
@@ -69,7 +68,7 @@ TEST(FF7Field, ControlFlow)
 {
     InstVec insts;
     DummyFormatter formatter;
-    FF7::FF7FieldEngine engine(formatter, "test");
+    FF7FieldEngine engine(formatter, "test");
 
     auto d = engine.getDisassembler(insts);
     d->open("decompiler/test/ff7_control_flow_test.dat");
@@ -78,18 +77,18 @@ TEST(FF7Field, ControlFlow)
     std::cout << std::endl;
 
     uint32 pos = 0;
-    ASSERT_EQ(insts[pos]->_opcode, FF7::eOpcodes::RET);
+    ASSERT_EQ(insts[pos]->_opcode, OPCODE::RET);
     ASSERT_EQ(insts[pos]->_params.size(), 0);
 
-    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);
+    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);
 }

文件差異過大導致無法顯示
+ 146 - 146
V-Gears-Installer/include/decompiler/test/ff7_field_disasm_all_opcodes_by_category_test.cpp


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

@@ -1,5 +1,6 @@
 #include <gmock/gmock.h>
 
+#include "../../common/Lzs.h"
 #include "decompiler/ff7_field/ff7_field_disassembler.h"
 #include "decompiler/ff7_field/ff7_field_engine.h"
 #include "decompiler/ff7_field/ff7_field_codegen.h"
@@ -10,9 +11,7 @@
 #include "control_flow.h"
 #include "util.h"
 #include "graph.h"
-#include "make_unique.h"
 #include "sudm.h"
-#include "lzs.h"
 #include "ff7_field_dummy_formatter.h"
 
 #define GET(vertex) (boost::get(boost::vertex_name, g, vertex))
@@ -24,7 +23,7 @@ public:
     TestReadParameterDisassembler(std::vector<unsigned char>&& data, InstVec& insts)
         : SimpleDisassembler(insts)
     {
-        mStream = std::make_unique<BinaryReader>(std::move(data));
+        stream_ = std::make_unique<BinaryReader>(std::move(data));
     }
 
     void readParams(InstPtr inst, const char *typeString)
@@ -33,7 +32,7 @@ public:
     }
 
 
-    virtual void doDisassemble() override final
+    virtual void DoDisassemble() override final
     {
         // NOP
     }
@@ -125,7 +124,7 @@ TEST(SimpleDisassembler, readParameter_d)
 
 TEST(FF7Field, FunctionMetaData_Parse_Empty)
 {
-    FF7::FunctionMetaData meta("");
+    FunctionMetaData meta("");
     ASSERT_EQ("", meta.EntityName());
     ASSERT_EQ(false, meta.IsEnd());
     ASSERT_EQ(false, meta.IsStart());
@@ -133,7 +132,7 @@ TEST(FF7Field, FunctionMetaData_Parse_Empty)
 
 TEST(FF7Field, FunctionMetaData_Parse_Empties)
 {
-    FF7::FunctionMetaData meta("__________________");
+    FunctionMetaData meta("__________________");
     ASSERT_EQ("", meta.EntityName());
     ASSERT_EQ(false, meta.IsEnd());
     ASSERT_EQ(false, meta.IsStart());
@@ -141,7 +140,7 @@ TEST(FF7Field, FunctionMetaData_Parse_Empties)
 
 TEST(FF7Field, FunctionMetaData_Parse_Start)
 {
-    FF7::FunctionMetaData meta("start_-1_entity");
+    FunctionMetaData meta("start_-1_entity");
     ASSERT_EQ("entity", meta.EntityName());
     ASSERT_EQ(false, meta.IsEnd());
     ASSERT_EQ(true, meta.IsStart());
@@ -149,7 +148,7 @@ TEST(FF7Field, FunctionMetaData_Parse_Start)
 
 TEST(FF7Field, FunctionMetaData_Parse_End)
 {
-    FF7::FunctionMetaData meta("end_-1_entity");
+    FunctionMetaData meta("end_-1_entity");
     ASSERT_EQ("entity", meta.EntityName());
     ASSERT_EQ(true, meta.IsEnd());
     ASSERT_EQ(false, meta.IsStart());
@@ -157,7 +156,7 @@ TEST(FF7Field, FunctionMetaData_Parse_End)
 
 TEST(FF7Field, FunctionMetaData_Parse_EntityName)
 {
-    FF7::FunctionMetaData meta("end_-1_TheName");
+    FunctionMetaData meta("end_-1_TheName");
     ASSERT_EQ("TheName", meta.EntityName());
     ASSERT_EQ(true, meta.IsEnd());
     ASSERT_EQ(false, meta.IsStart());
@@ -167,7 +166,7 @@ TEST(FF7Field, FunctionMetaData_Parse_EntityName)
 
 TEST(FF7Field, FunctionMetaData_Parse_EntityNameAndId)
 {
-    FF7::FunctionMetaData meta("end_99_The_Name");
+    FunctionMetaData meta("end_99_The_Name");
     ASSERT_EQ("The_Name", meta.EntityName());
     ASSERT_EQ(99, meta.CharacterId());
 
@@ -178,7 +177,7 @@ TEST(FF7Field, FunctionMetaData_Parse_EntityNameAndId)
 
 TEST(FF7Field, FunctionMetaData_Parse_StartEnd)
 {
-    FF7::FunctionMetaData meta("start_end_-1_entity");
+    FunctionMetaData meta("start_end_-1_entity");
     ASSERT_EQ("entity", meta.EntityName());
     ASSERT_EQ(true, meta.IsEnd());
     ASSERT_EQ(true, meta.IsStart());
@@ -1160,10 +1159,10 @@ private:
         }
 
         // TODO: Handle arguments correctly, validate labels
-        const FF7::TInstructRecord* rec = it->second;
-        const char* fmt = rec->mArgumentFormat;
+        const FF7::InstructionRecord* rec = it->second;
+        const char* fmt = rec->argument_format;
 
-        // method.AddInstruction(rec->mOpCode, rec->mOpCodeSize);
+        // method.AddInstruction(rec->opcode, rec->opcode_size);
         // TODO: Flow control needs special handling
 
         while (*fmt)
@@ -1508,10 +1507,10 @@ TEST(Parser, ZeroGapIf)
 TEST(FF7Field, Asm)
 {
     DummyFormatter dummy;
-    FF7::FF7FieldEngine eng(dummy, "test");
+    FF7FieldEngine eng(dummy, "test");
 
     InstVec insts;
-    FF7::FF7Disassembler d(dummy, &eng, insts);
+    FieldDisassembler d(dummy, &eng, insts);
 
 
 }

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

@@ -8,7 +8,7 @@ namespace FF7
     {
     public:
         FF7WorldCodeGenerator(Engine *engine, std::ostream &output)
-            : CodeGenerator(engine, output, kFIFOArgOrder, kLIFOArgOrder)
+            : CodeGenerator(engine, output, FIFO_ARGUMENT_ORDER, LIFO_ARGUMENT_ORDER)
         {
 
         }
@@ -16,6 +16,6 @@ namespace FF7
         const InstPtr findLastCall();
         virtual void processSpecialMetadata(const InstPtr inst, char c, int pos);
     protected:
-        std::string constructFuncSignature(const Function &func);
+        std::string ConstructFuncSignature(const Function &func);
     };
 }

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

@@ -10,7 +10,7 @@ namespace FF7
     public:
         FF7WorldDisassembler(FF7WorldEngine* engine, InstVec& insts, int scriptNumber);
         ~FF7WorldDisassembler();
-	    void doDisassemble() override;
+	    void DoDisassemble() override;
     private:
         int mScriptNumber = 0;
     };

+ 0 - 1
V-Gears-Installer/include/ff7DataInstaller.h

@@ -18,7 +18,6 @@
 #include <string>
 #include <vector>
 #include <iostream>
-#include "common/make_unique.h"
 #include "common/VGearsApplication.h"
 #include "common/FinalFantasy7/FF7NameLookup.h"
 #include "data/VGearsTriggersFile.h"

+ 0 - 437
V-Gears-Installer/src/common/str.cpp

@@ -1,437 +0,0 @@
-/* ScummVM Tools
- *
- * ScummVM Tools is the legal property of its developers, whose
- * names are too numerous to list here. Please refer to the
- * COPYRIGHT file distributed with this source distribution.
- *
- * 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.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#include "common/str.h"
-#include "common/util.h"
-
-#include <stdarg.h>
-
-#if !defined(__SYMBIAN32__)
-#include <new>
-#endif
-
-
-namespace Common {
-
-String::String(const char *str)  {
-	initWithCStr(str, strlen(str));
-}
-
-String::String(const char *str, uint32 len) {
-	initWithCStr(str, len);
-}
-
-String::String(const char *beginP, const char *endP) {
-	assert(endP >= beginP);
-	initWithCStr(beginP, endP - beginP);
-}
-
-void String::initWithCStr(const char *str, uint32 len) {
-	assert(str);
-
-    _str = std::string(str, len);
-}
-
-String::String(const String &str)
-{
-    _str = str._str;
-}
-
-String::String(char c)
-{
-    _str += c;
-}
-
-String::~String() 
-{
-
-}
-
-String& String::operator  =(const char *str) {
-    _str = std::string(str);
-	return *this;
-}
-
-String &String::operator  =(const String &str) {
-    if (&str == this)
-        return *this;
-
-    _str = str._str;
-
-    return *this;
-}
-
-String& String::operator  =(char c) {
-    _str.clear();
-    _str += c;
-	return *this;
-}
-
-String &String::operator +=(const char *str) {
-    _str += std::string(str);
-	return *this;
-}
-
-String &String::operator +=(const String &str) {
-	if (&str == this)
-		return operator+=(Common::String(str));
-    _str += str._str;
-	return *this;
-}
-
-String &String::operator +=(char c) {
-    _str += c;
-	return *this;
-}
-
-bool String::hasPrefix(const String &x) const {
-	return hasPrefix(x.c_str());
-}
-
-bool String::hasPrefix(const char *x) const {
-	assert(x != 0);
-	// Compare x with the start of _str.
-	const char *y = c_str();
-	while (*x && *x == *y) {
-		++x;
-		++y;
-	}
-	// It's a prefix, if and only if all letters in x are 'used up' before
-	// _str ends.
-	return *x == 0;
-}
-
-bool String::hasSuffix(const String &x) const {
-	return hasSuffix(x.c_str());
-}
-
-bool String::hasSuffix(const char *x) const {
-	assert(x != 0);
-	// Compare x with the end of _str.
-	const uint32 x_size = strlen(x);
-	if (x_size > _str.size())
-		return false;
-    const char *y = c_str() + _str.size() - x_size;
-	while (*x && *x == *y) {
-		++x;
-		++y;
-	}
-	// It's a suffix, if and only if all letters in x are 'used up' before
-	// _str ends.
-	return *x == 0;
-}
-
-bool String::contains(const String &x) const {
-	return strstr(c_str(), x.c_str()) != NULL;
-}
-
-bool String::contains(const char *x) const {
-	assert(x != 0);
-	return strstr(c_str(), x) != NULL;
-}
-
-bool String::contains(char x) const {
-	return strchr(c_str(), x) != NULL;
-}
-
-bool String::matchString(const char *pat, bool ignoreCase, bool pathMode) const {
-	return Common::matchString(c_str(), pat, ignoreCase, pathMode);
-}
-
-bool String::matchString(const String &pat, bool ignoreCase, bool pathMode) const {
-	return Common::matchString(c_str(), pat.c_str(), ignoreCase, pathMode);
-}
-
-void String::clear() {
-    _str.clear();
-}
-
-void String::setChar(char c, uint32 p) {
-    assert(p <= _str.size());
-	_str[p] = c;
-}
-
-void String::insertChar(char c, uint32 p) {
-    assert(p <= _str.size());
-
-    _str += c;
-	for (auto i = _str.size(); i > p; --i)
-		_str[i] = _str[i-1];
-	_str[p] = c;
-}
-
-void String::toLowercase() {
-    for (auto i = 0u; i < _str.size(); ++i)
-		_str[i] = static_cast<char>(tolower(_str[i]));
-}
-
-void String::toUppercase() {
-	for (auto i = 0u; i < _str.size(); ++i)
-		_str[i] = static_cast<char>(toupper(_str[i]));
-}
-
-bool String::operator ==(const String &x) const {
-	return equals(x);
-}
-
-bool String::operator ==(const char *x) const {
-	assert(x != 0);
-	return equals(x);
-}
-
-bool String::operator !=(const String &x) const {
-	return !equals(x);
-}
-
-bool String::operator !=(const char *x) const {
-	assert(x != 0);
-	return !equals(x);
-}
-
-bool String::operator < (const String &x) const {
-	return compareTo(x) < 0;
-}
-
-bool String::operator <= (const String &x) const {
-	return compareTo(x) <= 0;
-}
-
-bool String::operator > (const String &x) const {
-	return compareTo(x) > 0;
-}
-
-bool String::operator >= (const String &x) const {
-	return compareTo(x) >= 0;
-}
-
-bool operator == (const char* y, const String &x) {
-	return (x == y);
-}
-
-bool operator != (const char* y, const String &x) {
-	return x != y;
-}
-
-bool String::equals(const String &x) const {
-	return (0 == compareTo(x));
-}
-
-bool String::equals(const char *x) const {
-	assert(x != 0);
-	return (0 == compareTo(x));
-}
-
-bool String::equalsIgnoreCase(const String &x) const {
-	return (0 == compareToIgnoreCase(x));
-}
-
-bool String::equalsIgnoreCase(const char *x) const {
-	assert(x != 0);
-	return (0 == compareToIgnoreCase(x));
-}
-
-int String::compareTo(const String &x) const {
-	return compareTo(x.c_str());
-}
-
-int String::compareTo(const char *x) const {
-	assert(x != 0);
-	return strcmp(c_str(), x);
-}
-
-int String::compareToIgnoreCase(const String &x) const {
-	return compareToIgnoreCase(x.c_str());
-}
-
-int String::compareToIgnoreCase(const char *x) const {
-	assert(x != 0);
-	return scumm_stricmp(c_str(), x);
-}
-
-String operator +(const String &x, const String &y) {
-	String temp(x);
-	temp += y;
-	return temp;
-}
-
-String operator +(const char *x, const String &y) {
-	String temp(x);
-	temp += y;
-	return temp;
-}
-
-String operator +(const String &x, const char *y) {
-	String temp(x);
-	temp += y;
-	return temp;
-}
-
-String operator +(char x, const String &y) {
-	String temp(x);
-	temp += y;
-	return temp;
-}
-
-String operator +(const String &x, char y) {
-	String temp(x);
-	temp += y;
-	return temp;
-}
-
-char *ltrim(char *t) {
-	while (isspace(*t))
-		t++;
-	return t;
-}
-
-char *rtrim(char *t) {
-	int l = strlen(t) - 1;
-	while (l >= 0 && isspace(t[l]))
-		t[l--] = 0;
-	return t;
-}
-
-char *trim(char *t) {
-	return rtrim(ltrim(t));
-}
-
-Common::String lastPathComponent(const Common::String &path, const char sep) {
-	const char *str = path.c_str();
-	const char *last = str + path.size();
-
-	// Skip over trailing slashes
-	while (last > str && *(last-1) == sep)
-		--last;
-
-	// Path consisted of only slashes -> return empty string
-	if (last == str)
-		return Common::String();
-
-	// Now scan the whole component
-	const char *first = last - 1;
-	while (first >= str && *first != sep)
-		--first;
-
-	if (*first == sep)
-		first++;
-
-	return Common::String(first, last);
-}
-
-Common::String normalizePath(const Common::String &path, const char sep) {
-	if (path.empty())
-		return path;
-
-	const char *cur = path.c_str();
-	Common::String result;
-
-	// If there is a leading slash, preserve that:
-	if (*cur == sep) {
-		result += sep;
-		while (*cur == sep)
-			++cur;
-	}
-
-	// Scan till the end of the String
-	while (*cur != 0) {
-		const char *start = cur;
-
-		// Scan till the next path separator resp. the end of the string
-		while (*cur != sep && *cur != 0)
-			cur++;
-
-		const Common::String component(start, cur);
-
-		// Skip empty components and dot components, add all others
-		if (!component.empty() && component != ".") {
-			// Add a separator before the component, unless the result
-			// string already ends with one (which happens only if the
-			// path *starts* with a separator).
-			if (!result.empty() && result.lastChar() != sep)
-				result += sep;
-
-			// Add the component
-			result += component;
-		}
-
-		// Skip over separator chars
-		while (*cur == sep)
-			cur++;
-	}
-
-	return result;
-}
-
-bool matchString(const char *str, const char *pat, bool ignoreCase, bool pathMode) {
-	assert(str);
-	assert(pat);
-
-	const char *p = 0;
-	const char *q = 0;
-
-	for (;;) {
-		if (pathMode && *str == '/') {
-			p = 0;
-			q = 0;
-			if (*pat == '?')
-				return false;
-		}
-
-		switch (*pat) {
-		case '*':
-			// Record pattern / string position for backtracking
-			p = ++pat;
-			q = str;
-			// If pattern ended with * -> match
-			if (!*pat)
-				return true;
-			break;
-
-		default:
-			if ((!ignoreCase && *pat != *str) ||
-				(ignoreCase && tolower(*pat) != tolower(*str))) {
-				if (p) {
-					// No match, oops -> try to backtrack
-					pat = p;
-					str = ++q;
-					if (!*str)
-						return !*pat;
-					break;
-				}
-				else
-					return false;
-			}
-			// fallthrough
-		case '?':
-			if (!*str)
-				return !*pat;
-			pat++;
-			str++;
-		}
-	}
-}
-
-}	// End of namespace Common

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

@@ -27,7 +27,8 @@
 
 #include "control_flow.h"
 
-#include "scummv6/engine.h"
+//#include "scummv6/engine.h"
+#include "decompiler_engine.h"
 
 #include <fstream>
 #include <iostream>
@@ -45,7 +46,6 @@
 #ifdef _MSC_VER
 #pragma warning (pop)
 #endif
-#include "make_unique.h"
 
 
 namespace po = boost::program_options;
@@ -57,7 +57,7 @@ int main(int argc, char** argv) {
 		std::map<std::string, std::string> engines;
 		ObjectFactory<std::string, Engine> engineFactory;
 
-		ENGINE("scummv6", "SCUMM v6", Scumm::v6::Scummv6Engine);
+		ENGINE("scummv6", "SCUMM v6", Engine);//Scumm::v6::Scummv6Engine);
 
         po::options_description visible("Options", 1024);
 		visible.add_options()

+ 38 - 39
V-Gears-Installer/src/decompiler/decompiler_codegen.cpp

@@ -25,21 +25,20 @@
 #include <iostream>
 #include <set>
 #include <boost/format.hpp>
-#include "common/make_unique.h"
 
 #define GET(vertex)    (boost::get(boost::vertex_name, _g, vertex))
 #define GET_EDGE(edge) (boost::get(boost::edge_attribute, _g, edge))
 
-void CodeGenerator::onBeforeStartFunction(const Function&)
+void CodeGenerator::OnBeforeStartFunction(const Function&)
 {
 }
 
-void CodeGenerator::onEndFunction(const Function &)
+void CodeGenerator::OnEndFunction(const Function &)
 {
-    addOutputLine("}", true, false);
+    AddOutputLine("}", true, false);
 }
 
-std::string CodeGenerator::constructFuncSignature(const Function &)
+std::string CodeGenerator::ConstructFuncSignature(const Function &)
 {
     return "";
 }
@@ -58,7 +57,7 @@ CodeGenerator::CodeGenerator(Engine *engine, std::ostream &output, ArgOrder binO
 {
     _engine = engine;
     _indentLevel = 0;
-    mTargetLang = std::make_unique<CTargetLanguage>();
+    target_lang_ = std::make_unique<CTargetLanguage>();
 }
 
 typedef std::pair<GraphVertex, ValueStack> DFSEntry;
@@ -73,7 +72,7 @@ void CodeGenerator::generatePass(InstVec& insts, const Graph& g)
             _stack.pop();
         }
         GraphVertex entryPoint = fn->second._v;
-        std::string funcSignature = constructFuncSignature(fn->second);
+        std::string funcSignature = ConstructFuncSignature(fn->second);
 
         // Write the function start
         bool printFuncSignature = !funcSignature.empty();
@@ -82,13 +81,13 @@ void CodeGenerator::generatePass(InstVec& insts, const Graph& g)
             mCurGroup = GET(entryPoint);
             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);
         }
 
         GroupPtr lastGroup = GET(entryPoint);
@@ -125,7 +124,7 @@ void CodeGenerator::generatePass(InstVec& insts, const Graph& g)
         if (printFuncSignature)
         {
             mCurGroup = lastGroup;
-            onEndFunction(fn->second);
+            OnEndFunction(fn->second);
         }
 
         // Print output
@@ -159,7 +158,7 @@ void CodeGenerator::generatePass(InstVec& insts, const Graph& g)
     }
 }
 
-void CodeGenerator::generate(InstVec& insts, const Graph &g)
+void CodeGenerator::Generate(InstVec& insts, const Graph &g)
 {
     if (OutputOnlyRequiredLabels())
     {
@@ -172,7 +171,7 @@ void CodeGenerator::generate(InstVec& insts, const Graph &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
     // require a label to be outputted
@@ -185,8 +184,8 @@ void CodeGenerator::addOutputLine(std::string s, bool unindentBefore, bool inden
 void CodeGenerator::writeAssignment(ValuePtr dst, ValuePtr src) 
 {
     std::stringstream s;
-    s << dst << " = " << src << mTargetLang->LineTerminator();
-    addOutputLine(s.str());
+    s << dst << " = " << src << target_lang_->LineTerminator();
+    AddOutputLine(s.str());
 }
 
 void CodeGenerator::process(Function& func, InstVec& insts, GraphVertex v)
@@ -197,7 +196,7 @@ void CodeGenerator::process(Function& func, InstVec& insts, GraphVertex v)
     // Check if we should add else start
     if (mCurGroup->_startElse)
     {
-        addOutputLine(mTargetLang->EndBlock(ITargetLanaguge::eToElseBlock) + " " + mTargetLang->Else() + " " + mTargetLang->StartBlock(ITargetLanaguge::eBeginElse), true, true);
+        AddOutputLine(target_lang_->EndBlock(ITargetLanaguge::eToElseBlock) + " " + target_lang_->Else() + " " + target_lang_->StartBlock(ITargetLanaguge::eBeginElse), true, true);
     }
 
     // Check ingoing edges to see if we want to add any extra output
@@ -215,16 +214,16 @@ void CodeGenerator::process(Function& func, InstVec& insts, GraphVertex v)
         switch (inGroup->_type)
         {
         case kDoWhileCondGroupType:
-            addOutputLine(mTargetLang->DoLoopHeader(), false, true);
+            AddOutputLine(target_lang_->DoLoopHeader(), false, true);
             break;
         case kIfCondGroupType:
             if (!mCurGroup->_startElse)
             {
-                addOutputLine(mTargetLang->EndBlock(ITargetLanaguge::eEndOfIf), true, false);
+                AddOutputLine(target_lang_->EndBlock(ITargetLanaguge::eEndOfIf), true, false);
             }
             break;
         case kWhileCondGroupType:
-            addOutputLine(mTargetLang->EndBlock(ITargetLanaguge::eEndOfWhile), true, false);
+            AddOutputLine(target_lang_->EndBlock(ITargetLanaguge::eEndOfWhile), true, false);
             break;
         default:
             break;
@@ -239,7 +238,7 @@ void CodeGenerator::process(Function& func, InstVec& insts, GraphVertex v)
         // so write one out.
         if (OutputOnlyRequiredLabels() && !mIsLabelPass && (*it)->mLabelRequired)
         {
-            addOutputLine(mTargetLang->Label((*it)->_address));
+            AddOutputLine(target_lang_->Label((*it)->_address));
         }
         processInst(func, insts, *it);
     } while (it++ != mCurGroup->_end);
@@ -249,7 +248,7 @@ void CodeGenerator::process(Function& func, InstVec& insts, GraphVertex v)
     {
         if (!(*elseIt)->_coalescedElse)
         {
-            addOutputLine(mTargetLang->EndBlock(ITargetLanaguge::eEndIfElseChain), true, false);
+            AddOutputLine(target_lang_->EndBlock(ITargetLanaguge::eEndIfElseChain), true, false);
         }
     }
 }
@@ -259,10 +258,10 @@ void CodeGenerator::processUncondJumpInst(Function& func, InstVec& insts, const
     switch (mCurGroup->_type)
     {
     case kBreakGroupType:
-        addOutputLine(mTargetLang->LoopBreak());
+        AddOutputLine(target_lang_->LoopBreak());
         break;
     case kContinueGroupType:
-        addOutputLine(mTargetLang->LoopContinue());
+        AddOutputLine(target_lang_->LoopContinue());
         break;
     default: // Might be a goto
     {
@@ -304,7 +303,7 @@ void CodeGenerator::processUncondJumpInst(Function& func, InstVec& insts, const
                     if (mCurGroup->_type == kDoWhileCondGroupType && inst->_address == func.mEndAddr && inst->isUncondJump())
                     {
                         printJump = false;
-                        addOutputLine(mTargetLang->DoLoopFooter(true) + "true" + mTargetLang->DoLoopFooter(false), true, false);
+                        AddOutputLine(target_lang_->DoLoopFooter(true) + "true" + target_lang_->DoLoopFooter(false), true, false);
                     }
                 }
             }
@@ -325,7 +324,7 @@ void CodeGenerator::processUncondJumpInst(Function& func, InstVec& insts, const
                     }
                 }
             }
-            addOutputLine(mTargetLang->Goto(dstAddr));
+            AddOutputLine(target_lang_->Goto(dstAddr));
         }
     }
         break;
@@ -334,7 +333,7 @@ void CodeGenerator::processUncondJumpInst(Function& func, InstVec& insts, const
 
 void CodeGenerator::writeFunctionCall(std::string functionName, std::string paramsFormat, const std::vector<ValuePtr>& params)
 {
-    std::string strFuncCall = functionName + mTargetLang->FunctionCallBegin();
+    std::string strFuncCall = functionName + target_lang_->FunctionCallBegin();
     const char* str = paramsFormat.c_str();
     int paramIndex = 0;
     while (*str)
@@ -369,12 +368,12 @@ void CodeGenerator::writeFunctionCall(std::string functionName, std::string para
             // There is another param
             if (!skipArgument)
             {
-                strFuncCall += mTargetLang->FunctionCallArgumentSeperator() + " ";
+                strFuncCall += target_lang_->FunctionCallArgumentSeperator() + " ";
             }
         }
     }
-    strFuncCall += mTargetLang->FunctionCallEnd();
-    addOutputLine(strFuncCall);
+    strFuncCall += target_lang_->FunctionCallEnd();
+    AddOutputLine(strFuncCall);
 }
 
 void CodeGenerator::processCondJumpInst(const InstPtr inst)
@@ -399,19 +398,19 @@ void CodeGenerator::processCondJumpInst(const InstPtr inst)
             {
                 mCurGroup->_code.clear();
                 mCurGroup->_coalescedElse = true;
-                s << mTargetLang->EndBlock(ITargetLanaguge::eToElseBlock) << " " << mTargetLang->Else() << " ";
+                s << target_lang_->EndBlock(ITargetLanaguge::eToElseBlock) << " " << target_lang_->Else() << " ";
             }
         }
-        s << mTargetLang->If(true) << _stack.pop()->negate() << mTargetLang->If(false);
-        addOutputLine(s.str(), mCurGroup->_coalescedElse, true);
+        s << target_lang_->If(true) << _stack.pop()->negate() << target_lang_->If(false);
+        AddOutputLine(s.str(), mCurGroup->_coalescedElse, true);
         break;
     case kWhileCondGroupType:
-        s << mTargetLang->WhileHeader(true) << _stack.pop()->negate() << mTargetLang->WhileHeader(false) << " " << mTargetLang->StartBlock(ITargetLanaguge::eBeginWhile);
-        addOutputLine(s.str(), false, true);
+        s << target_lang_->WhileHeader(true) << _stack.pop()->negate() << target_lang_->WhileHeader(false) << " " << target_lang_->StartBlock(ITargetLanaguge::eBeginWhile);
+        AddOutputLine(s.str(), false, true);
         break;
     case kDoWhileCondGroupType:
-        s << mTargetLang->EndBlock(ITargetLanaguge::eEndWhile) <<  " " << mTargetLang->WhileHeader(true) << _stack.pop() << mTargetLang->WhileHeader(false);
-        addOutputLine(s.str(), true, false);
+        s << target_lang_->EndBlock(ITargetLanaguge::eEndWhile) <<  " " << target_lang_->WhileHeader(true) << _stack.pop() << target_lang_->WhileHeader(false);
+        AddOutputLine(s.str(), true, false);
         break;
     default:
         break;
@@ -433,9 +432,9 @@ void CodeGenerator::processInst(Function& func, InstVec& insts, const InstPtr in
 
 void CodeGenerator::addArg(ValuePtr p) 
 {
-    if (_callOrder == kFIFOArgOrder)
+    if (_callOrder == FIFO_ARGUMENT_ORDER)
         _argList.push_front(p);
-    else if (_callOrder == kLIFOArgOrder)
+    else if (_callOrder == LIFO_ARGUMENT_ORDER)
         _argList.push_back(p);
 }
 

+ 10 - 11
V-Gears-Installer/src/decompiler/decompiler_disassembler.cpp

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

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

@@ -0,0 +1,300 @@
+/*
+ * 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/algorithm/string/predicate.hpp>
+
+#include "decompiler/field/FieldCodeGenerator.h"
+#include "decompiler/field/ff7_field_engine.h"
+
+const std::string FunctionMetaData::DELIMITER("_");
+
+const std::string FunctionMetaData::START("start");
+
+const std::string FunctionMetaData::END("end");
+
+FunctionMetaData::FunctionMetaData(std::string meta_data){Parse(meta_data);}
+
+bool FunctionMetaData::IsStart() const{return start_;}
+
+bool FunctionMetaData::IsEnd() const{return end_;}
+
+std::string FunctionMetaData::GetEntityName(){return entity_name_;}
+
+int FunctionMetaData::GetCharacterId(){return character_id_;}
+
+void FunctionMetaData::Parse(std::string meta_data){
+    std::deque<std::string> strs;
+    boost::split(strs, meta_data, boost::is_any_of(DELIMITER), boost::token_compress_on);
+    if (!strs.empty()){
+        auto tmp = strs.front();
+        strs.pop_front();
+        ParseStart(tmp, strs);
+    }
+}
+
+void FunctionMetaData::ParseStart(const std::string& item, std::deque<std::string>& strs){
+    if (item == START){
+        start_ = true;
+        if (!strs.empty()){
+            auto tmp = strs.front();
+            strs.pop_front();
+            ParseEnd(tmp, strs);
+        }
+    }
+    else ParseEnd(item, strs);
+}
+
+void FunctionMetaData::ParseEnd(const std::string& item, std::deque<std::string>& strs){
+    if (item == END){
+        end_ = true;
+        if (!strs.empty()){
+            auto tmp = strs.front();
+            strs.pop_front();
+            ParseCharId(tmp, strs);
+        }
+    }
+    else ParseCharId(item, strs);
+}
+
+void FunctionMetaData::ParseCharId(const std::string& item, std::deque<std::string>& strs){
+    if (!item.empty()) character_id_ = std::stoi(item);
+    if (!strs.empty()){
+        auto tmp = strs.front();
+        strs.pop_front();
+        ParseEntity(tmp, strs);
+    }
+}
+
+void FunctionMetaData::ParseEntity(const std::string& item, std::deque<std::string>& strs){
+    entity_name_ = item;
+    for (auto& part : strs)
+        if (!part.empty()) entity_name_ += "_" + part;
+}
+
+void FieldCodeGenerator::Generate(InstVec& insts, const Graph& graph){
+    // TODO: Break into parts
+    auto instruction = insts.begin();
+    
+    std::vector<std::pair<Function&, InstVec>> functions_with_bodies;
+    for (
+      auto function = _engine->_functions.begin();
+      function != _engine->_functions.end();
+      ++ function
+    ){
+        InstVec body;
+        for (size_t i = 0; i < function->second.mNumInstructions; ++ i, ++ instruction)
+            body.push_back(*instruction);
+        functions_with_bodies.push_back(std::pair<Function&, InstVec> {function->second, body});
+    }
+
+    for (
+      auto function = functions_with_bodies.begin();
+      function != functions_with_bodies.end();
+      ++ function
+    ){
+
+        OnBeforeStartFunction(function->first);
+        auto signature = ConstructFuncSignature(function->first);
+        AddOutputLine(signature, false, true);
+        OnStartFunction(function->first);
+        
+        // Comment with original instructions.
+        std::unordered_map<uint32, InstVec> labels;
+        for (
+          auto instruction = function->second.begin();
+          instruction != function->second.end();
+          ++ instruction
+        ){
+            if ((*instruction)->isCondJump() || (*instruction)->isUncondJump()){
+                auto targetAddr = (*instruction)->getDestAddress();
+                auto label = labels.find(targetAddr);
+                if (label == labels.end()) labels.insert({targetAddr, InstVec()});
+                labels[targetAddr].push_back(*instruction);
+            }
+        }
+
+        // Implemented instructions.
+        bool end_needed = false;
+        for (
+          auto instruction = function->second.begin();
+          instruction != function->second.end();
+          ++instruction
+        ){
+            auto label = labels.find((*instruction)->_address);
+            if (label != labels.end()){
+                bool needs_label = false;
+                bool needs_new_line = false;
+                for (auto origin = label->second.begin(); origin != label->second.end(); ++ origin){
+                    if ((*origin)->isCondJump()){
+                        AddOutputLine("end", true, false);
+                        needs_new_line = true;
+                    }
+                    else needs_label = true;
+                }
+                if (needs_new_line) AddOutputLine("");
+                if (needs_label)
+                    AddOutputLine((boost::format("::label_0x%1$X::") % label->first).str());
+            }
+            ValueStack stack;
+            (*instruction)->processInst(function->first, stack, _engine, this);
+            if (end_needed){
+                AddOutputLine("end -- end if", true, false);
+                end_needed = false;
+            }
+            if ((*instruction)->isCondJump()){
+                AddOutputLine(
+                  (boost::format("if (%s) then") % stack.pop()->getString()).str(), false, true
+                );
+                // If the next instruction is the last in the function, mark the next pass to
+                // add an 'end' after the instruction to close the if.
+                if ((*(instruction + 1))->_address == (*(function->second.back()))._address)
+                    end_needed = true;
+            }
+            else if ((*instruction)->isUncondJump()){
+                // If destination address is outside the functions, turn goto into a return.
+                if ((*instruction)->getDestAddress() > function->first.mEndAddr){
+                    AddOutputLine(
+                      "-- Overflowed jump to "
+                      + (boost::format("0x%1$X") % (*instruction)->getDestAddress()).str()
+                      + " (last address in function is "
+                      + (boost::format("0x%1$X)") % function->first.mEndAddr).str()
+                    );
+                    AddOutputLine("do return 0 end");
+                }
+                // Prevent backward jumps in the on_start script.
+                else if (
+                  "on_start" == function->first._name
+                  && (*instruction)->getDestAddress() <= (*instruction)->_address
+                ){
+                    AddOutputLine("-- No infinite loops in the on_start script.");
+                    AddOutputLine((
+                      boost::format("-- goto label_0x%1$X") % (*instruction)->getDestAddress()
+                    ).str());
+                }
+                else{
+                    AddOutputLine(
+                      (boost::format("goto label_0x%1$X") % (*instruction)->getDestAddress()).str()
+                    );
+                }
+            }
+            // Else, already output'd.
+        }
+        // Add missing return:
+        if (
+          "return 0" != lines_.at(lines_.size() - 1)._line
+          && "do return 0 end" != lines_.at(lines_.size() - 1)._line
+        ){
+            AddOutputLine("do return 0 end", false, false);
+        }
+        OnEndFunction(function->first);
+    }
+
+    for (auto i = lines_.begin(); i != lines_.end(); ++i){
+        if (i->_unindentBefore && _indentLevel > 0){
+            _indentLevel --;
+        }
+        _output << indentString(i->_line) << std::endl;
+        if (i->_indentAfter) _indentLevel++;
+    }
+}
+
+void FieldCodeGenerator::AddOutputLine(
+  std::string line, bool unindent_before, bool indent_after
+){lines_.push_back(CodeLine(line, unindent_before, indent_after));}
+
+float FieldCodeGenerator::GetScaleFactor() const
+{return static_cast<FF7FieldEngine*>(_engine)->GetScaleFactor();}
+
+void FieldCodeGenerator::OnBeforeStartFunction(const Function& function){
+    FunctionMetaData meta_data(function._metadata);
+    if (meta_data.IsStart()){
+        AddOutputLine("EntityContainer[\"" + meta_data.GetEntityName() + "\"] = {", false, true);
+        if (meta_data.GetCharacterId() != -1)
+            AddOutputLine(meta_data.GetEntityName() + " = nil,\n");
+    }
+    const auto comment = formatter_.FunctionComment(meta_data.GetEntityName(), function._name);
+    if (!comment.empty()) AddOutputLine("-- " + comment);
+}
+
+void FieldCodeGenerator::OnStartFunction(const Function& func){
+    AddOutputLine("--[[");
+    for (const auto& inst : insts_){
+        if (inst->_address >= func.mStartAddr && inst->_address <= func.mEndAddr){
+            std::stringstream output;
+            output << inst;
+            AddOutputLine(output.str());
+        }
+    }
+    AddOutputLine("]]\n");
+    // TODO: If this hack is needed, maybe it can just be added to the "Direcor" entity.
+    if (func._name == "on_start" || func._name == "init"){
+        AddOutputLine("-- HACK ensure camera follows cloud, fix in engine properly later");
+        AddOutputLine("background2d:autoscroll_to_entity(entity_manager:get_entity(\"Cloud\"))");
+    }
+}
+
+void FieldCodeGenerator::OnEndFunction(const Function& function){
+    // End function.
+    AddOutputLine("end,", true, false);
+    // End class?
+    FunctionMetaData meta_data(function._metadata);
+    if (meta_data.IsEnd()) AddOutputLine("}\n\n\n", true, false);
+    else AddOutputLine("\n");
+}
+
+std::string FieldCodeGenerator::ConstructFuncSignature(const Function &function){
+    // Generate name
+    FunctionMetaData meta_data(function._metadata);
+    return formatter_.FunctionName(meta_data.GetEntityName(), function._name) + " = function(self)";
+}
+
+bool FieldCodeGenerator::OutputOnlyRequiredLabels() const{return true;}
+
+SUDM::IScriptFormatter& FieldCodeGenerator::GetFormatter(){return formatter_;}
+
+const std::string FieldCodeGenerator::FormatInstructionNotImplemented(
+  const std::string& entity, uint32 address, uint32 opcode
+){
+    return (
+      boost::format(
+        "-- log:log(\"In entity \\\"%1%\\\", address 0x%2$08x: "
+        "instruction 0x%3$04x not implemented\")"
+      ) % entity % address % opcode
+    ).str();
+}
+
+const std::string FieldCodeGenerator::FormatInstructionNotImplemented(
+  const std::string& entity, uint32 address, const Instruction& instruction
+){
+    std::stringstream parameterList;
+    for (auto i = instruction._params.begin(); i != instruction._params.end(); ++ i){
+        if (i != instruction._params.begin()) parameterList << ", ";
+        parameterList << *i;
+    }
+    return(
+      boost::format(
+        "-- log:log(\"In entity \\\"%1%\\\", address 0x%2$08x: "
+        "instruction %3%(%4%) not implemented\")"
+        ) % entity % address % instruction._name % parameterList.str()
+      ).str();
+}
+
+const std::string FieldCodeGenerator::FormatBool(uint32 value){
+    return value == 0 ? "false" : "true";
+}
+
+const std::string FieldCodeGenerator::FormatInvertedBool(uint32 value){
+    return value == 0 ? "true" : "false";
+}

+ 707 - 0
V-Gears-Installer/src/decompiler/field/FieldDisassembler.cpp

@@ -0,0 +1,707 @@
+/*
+ * 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 <vector>
+#include <boost/format.hpp>
+#include <boost/algorithm/string/split.hpp>
+#include <boost/algorithm/string.hpp>
+
+#include "../../../include/decompiler/field/FieldDisassembler.h"
+#include "common/Lzs.h"
+#include "decompiler/field/ff7_field_engine.h"
+#include "decompiler/decompiler_engine.h"
+#include "decompiler/field/FieldCodeGenerator.h"
+
+const int FieldDisassembler::MAGIC(0x0502);
+
+const int FieldDisassembler::NUM_SECTIONS(7);
+
+FieldDisassembler::FieldDisassembler(
+  SUDM::IScriptFormatter& formatter, FF7FieldEngine* 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.
+    section_pointers_size_ = 0;
+    auto data_copy = raw_script_data;
+    stream_ = std::make_unique<BinaryReader>(std::move(data_copy));
+    ReadHeader();
+}
+
+FieldDisassembler::FieldDisassembler(
+  SUDM::IScriptFormatter& formatter, FF7FieldEngine *engine, InstVec &insts
+) : SimpleDisassembler(insts), engine_(engine), formatter_(formatter){
+    section_pointers_size_ = (sizeof(uint32) * NUM_SECTIONS);
+}
+
+FieldDisassembler::~FieldDisassembler(){}
+
+void FieldDisassembler::ReadHeader(){
+    if (!loaded_from_raw_){
+        // First read the file section pointers.
+        for (int i = 0; i < NUM_SECTIONS; i ++) sections_[i] = stream_->ReadU32();
+        // 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_;
+        // Now seek to the script section.
+        stream_->Seek(sections_[SCRIPT]);
+    }
+
+    // Read the script header
+    header_.Read(*stream_);
+    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){
+    // Read all of the file, decompress it, then stuff it into a stream.
+    stream_ = std::make_unique<BinaryReader>(Lzs::Decompress(BinaryReader::ReadAll(filename)));
+    ReadHeader();
+}
+
+uint32 FieldDisassembler::GetEndOfScriptOffset(
+  uint16 cur_entry_point, size_t entity_index, size_t script_index
+){
+    uint16 next_entry_point = cur_entry_point;
+    do{
+        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 (entity_index + 1 >= header_.entity_scripts.size()) return header_.offset_to_strings;
+            else{
+                // Wrap around to the next entity
+                entity_index ++;
+                script_index = 0;
+            }
+        }
+        // Get the next script in the same entity:
+        else script_index ++;
+        next_entry_point = header_.entity_scripts[entity_index][script_index];
+    } while (next_entry_point == cur_entry_point);
+    return next_entry_point;
+}
+
+std::unique_ptr<Function> FieldDisassembler::StartFunction(size_t script_index){
+    auto func = std::make_unique<Function>();
+    func->_retVal = false;
+    func->_args = 0;
+    func->_name = "script_" + std::to_string(script_index);
+    func->mStartAddr = address_;
+    return func;
+}
+
+void FieldDisassembler::DoDisassemble(){
+    // Loop through the scripts for each entity.
+    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();
+        // 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);
+        const std::string entity_name = formatter_.EntityName(original_name);
+        // Only parse each script one.
+        std::set<uint16> parsed_scripts;
+        std::vector<ScriptInfo> script_info;
+        // Collect the scripts to parse.
+        for (
+          size_t script_index = 0;
+          script_index < header_.entity_scripts[entity_number].size();
+          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 (parsed_scripts.find(script_entry_point) != std::end(parsed_scripts)) continue;
+            parsed_scripts.insert(script_entry_point);
+            const uint32 next_script_entry_point = GetEndOfScriptOffset(
+              script_entry_point, entity_number, script_index
+            );
+            const uint32 script_size = next_script_entry_point - script_entry_point;
+            if (script_size > 0){
+                ScriptInfo info = { script_entry_point, next_script_entry_point, script_index };
+                script_info.push_back(info);
+            }
+        }
+        for (auto it = script_info.begin(); it != script_info.end(); it ++){
+            const bool is_start = it == script_info.begin();
+            const bool is_end = it == (--script_info.end());
+            DisassembleIndivdualScript(
+              entity_name, entity_number, it->index, it->entry_point,
+              it->next_entry_point, is_start, is_end
+            );
+        }
+    }
+}
+
+float FieldDisassembler::GetScaleFactor() const{return scale_factor_;}
+
+int FieldDisassembler::FindId(uint32 start_addr, uint32 end_addr, const InstVec& insts){
+    for (const InstPtr& instruction : insts){
+        if (instruction->_address >= start_addr && instruction->_address <= end_addr){
+            if (instruction->_opcode == OPCODE::opCodeCHAR)
+                return instruction->_params[0]->getSigned();
+        }
+    }
+    return -1;
+}
+
+void FieldDisassembler::AddFunc(
+  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
+){
+    bool is_line = false;
+    std::vector<float> point_a = {0, 0, 0};
+    std::vector<float> point_b = {0, 0, 0};
+    const auto SCRIPT_ENTRY_POINT = stream_->GetPosition();
+    // Read each block of opcodes up to a return.
+    const size_t old_num_instructions = _insts.size();
+    // Initialize the function.
+    std::unique_ptr<Function> func = StartFunction(script_index);
+    // Read.
+    if (to_return_only){
+        // Read opcodes to the end or bail at the first return.
+        is_line = ReadOpCodesToPositionOrReturn(
+          next_script_entry_point + section_pointers_size_, point_a, point_b
+        );
+        auto stream_pos = stream_->GetPosition();
+        const size_t endPos = next_script_entry_point + section_pointers_size_;
+        // Can't be the end if there is more data:
+        if (stream_pos != endPos) is_end = false;
+    }
+    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
+        while (stream_->GetPosition() != next_script_entry_point + section_pointers_size_){
+            is_line = ReadOpCodesToPositionOrReturn(
+              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.
+    std::string meta_data;
+    if (is_start && is_end) meta_data = "start_end_";
+    else if (is_start) meta_data = "start_";
+    else if (is_end) meta_data = "end_";
+    const size_t new_num_instructions = _insts.size();
+    func->mNumInstructions = new_num_instructions - old_num_instructions;
+    func->mEndAddr = _insts.back()->_address;
+    if (!func_name.empty()) func->_name = func_name;
+    if (engine_->EntityIsLine(entity_index)){
+        switch (script_index){
+            // main   - on_update
+            case 0: break;
+            // [OK]   - on_interact
+            case 1: break;
+            // Move - on_enter_line
+            case 2: func->_name = "on_enter_line"; break;
+            // Move - on_move_to_line
+            case 3: func->_name = "on_move_to_line"; break;
+            // Go - on_cross_line
+            case 4: func->_name = "on_cross_line"; break;
+            // Go1x - on_cross_line
+            case 5: func->_name = "on_cross_line_once"; break;
+            // GoAway - on_leave_line
+            case 6: func->_name = "on_leave_line"; break;
+        }
+    }
+    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
+    // its other functions and use that instead.
+    if (id == -1){
+        for (auto& func : engine_->_functions){
+            FunctionMetaData func_meta_data(func.second._metadata);
+            if (
+              func_meta_data.GetEntityName() == entity_name && func_meta_data.GetCharacterId() != -1
+            ){
+                id = func_meta_data.GetCharacterId();
+                break;
+            }
+        }
+    }
+    meta_data += std::to_string(id) + "_" + entity_name;
+    func->_metadata = meta_data;
+    engine_->_functions[SCRIPT_ENTRY_POINT] = *func;
+    engine_->AddEntityFunction(entity_name, entity_index, func->_name, script_index);
+    // If the entity is a line, mark it as so.
+    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
+){
+    script_entry_point += section_pointers_size_;
+    stream_->Seek(script_entry_point);
+    address_base_ = stream_->GetPosition();
+    address_ = address_base_;
+    // "Normal" script
+    if (script_index > 0){
+        if (script_index == 1){
+            AddFunc(
+              entity_name, entity_index, script_index, next_script_entry_point,
+              is_start, is_end, false, "on_interact"
+            );
+        }
+        else{
+            AddFunc(
+              entity_name, entity_index, script_index, next_script_entry_point,
+              is_start, is_end, false, ""
+            );
+        }
+    }
+    else{
+        const size_t end_pos = next_script_entry_point + section_pointers_size_;
+        // Read the init script, which means stop at the first return
+        AddFunc(
+          entity_name, entity_index, script_index, next_script_entry_point,
+          is_start, is_end, true, "on_start"
+        );
+
+        // Not at the end of this script? Then the remaining data is the "main" script
+        auto stream_pos = stream_->GetPosition();
+        if (stream_pos != end_pos){
+            // The "main" script can have more than one return statement
+            AddFunc(
+              entity_name, entity_index, script_index, next_script_entry_point,
+              false, is_end, false, "on_update"
+            );
+            stream_pos = stream_->GetPosition();
+
+            // But should end exactly on the end pos
+            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", "", FF7ControlFlowInstruction::Create },
+    { 1, OPCODE::REQ, "REQ", "BU", FF7ControlFlowInstruction::Create },
+    { 1, OPCODE::REQSW, "REQSW", "BU", FF7ControlFlowInstruction::Create },
+    { 1, OPCODE::REQEW, "REQEW", "BU", FF7ControlFlowInstruction::Create },
+    { 1, OPCODE::NOP, "NOP", "", FF7NoOperationInstruction::Create },
+    { 1, OPCODE::IFUB, "IFUB", "NNBBBL", FF7NoOperationInstruction::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 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];
+    return name_to_instruction_records;
+}
+
+bool FieldDisassembler::ReadOpCodesToPositionOrReturn(
+  size_t end_pos, std::vector<float>& point_a, std::vector<float>& point_b
+){
+    bool is_line = false;
+    std::vector<unsigned int> exitAddrs;
+    while (stream_->GetPosition() < end_pos){
+        uint8 opcode = stream_->ReadU8();
+        uint32 full_opcode = 0;
+        std::string opcodePrefix;
+        switch (opcode){
+            // Flow
+            CASE_OPCODE(OPCODE::IFUB, "IFUB", FF7CondJumpInstruction, 0, "NBBBB");
+            CASE_OPCODE(OPCODE::RET, "RET", FF7ControlFlowInstruction, 0, "");
+            CASE_OPCODE(OPCODE::REQ, "REQ", FF7ControlFlowInstruction, 0, "BU");
+            CASE_OPCODE(OPCODE::REQSW, "REQSW", FF7ControlFlowInstruction, 0, "BU");
+            CASE_OPCODE(OPCODE::REQEW, "REQEW", FF7ControlFlowInstruction, 0, "BU");
+            CASE_OPCODE(OPCODE::PREQ, "PREQ", FF7ControlFlowInstruction, 0, "BU");
+            CASE_OPCODE(OPCODE::PRQSW, "PRQSW", FF7ControlFlowInstruction, 0, "BU");
+            CASE_OPCODE(OPCODE::PRQEW, "PRQEW", FF7ControlFlowInstruction, 0, "BU");
+            CASE_OPCODE(OPCODE::RETTO, "RETTO", FF7ControlFlowInstruction, 0, "U");
+            CASE_OPCODE(OPCODE::JMPF, "JMPF", FF7UncondJumpInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::JMPFL, "JMPFL", FF7UncondJumpInstruction, 0, "w");
+            CASE_OPCODE(OPCODE::JMPB, "JMPB", FF7UncondJumpInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::JMPBL, "JMPBL", FF7UncondJumpInstruction, 0, "w");
+            CASE_OPCODE(OPCODE::IFUBL, "IFUBL", FF7CondJumpInstruction, 0, "NBBBw");
+            CASE_OPCODE(OPCODE::IFSW, "IFSW", FF7CondJumpInstruction, 0, "NwwBB");
+            CASE_OPCODE(OPCODE::IFSWL, "IFSWL", FF7CondJumpInstruction, 0, "NwwBw");
+            CASE_OPCODE(OPCODE::IFUW, "IFUW", FF7CondJumpInstruction, 0, "NwwBB");
+            CASE_OPCODE(OPCODE::IFUWL, "IFUWL", FF7CondJumpInstruction, 0, "NwwBw");
+            CASE_OPCODE(OPCODE::WAIT, "WAIT", FF7ControlFlowInstruction, 0, "w");
+            CASE_OPCODE(OPCODE::IFKEY, "IFKEY", FF7CondJumpInstruction, 0, "wB");
+            CASE_OPCODE(OPCODE::IFKEYON, "IFKEYON", FF7CondJumpInstruction, 0, "wB");
+            CASE_OPCODE(OPCODE::IFKEYOFF, "IFKEYOFF", FF7CondJumpInstruction, 0, "wB");
+            CASE_OPCODE(OPCODE::NOP, "NOP", FF7NoOperationInstruction, 0, "");
+            CASE_OPCODE(OPCODE::IFPRTYQ, "IFPRTYQ", FF7CondJumpInstruction, 0, "BB");
+            CASE_OPCODE(OPCODE::IFMEMBQ, "IFMEMBQ", FF7CondJumpInstruction, 0, "BB");
+
+            // Module
+            CASE_OPCODE(OPCODE::DSKCG, "DSKCG", FF7ModuleInstruction, 0, "B");
+            START_SUBOPCODE(OPCODE::SPECIAL)
+                CASE_OPCODE(OPCODE_SPECIAL::ARROW, "ARROW", FF7ModuleInstruction, 0, "B");
+            CASE_OPCODE(OPCODE_SPECIAL::PNAME, "PNAME", FF7ModuleInstruction, 0, "B");
+            CASE_OPCODE(OPCODE_SPECIAL::GMSPD, "GMSPD", FF7ModuleInstruction, 0, "B");
+            CASE_OPCODE(OPCODE_SPECIAL::SMSPD, "SMSPD", FF7ModuleInstruction, 0, "BB");
+            CASE_OPCODE(OPCODE_SPECIAL::FLMAT, "FLMAT", FF7ModuleInstruction, 0, "");
+            CASE_OPCODE(OPCODE_SPECIAL::FLITM, "FLITM", FF7ModuleInstruction, 0, "");
+            CASE_OPCODE(OPCODE_SPECIAL::BTLCK, "BTLCK", FF7ModuleInstruction, 0, "B");
+            CASE_OPCODE(OPCODE_SPECIAL::MVLCK, "MVLCK", FF7ModuleInstruction, 0, "B");
+            CASE_OPCODE(OPCODE_SPECIAL::SPCNM, "SPCNM", FF7ModuleInstruction, 0, "BB");
+            CASE_OPCODE(OPCODE_SPECIAL::RSGLB, "RSGLB", FF7ModuleInstruction, 0, "");
+            CASE_OPCODE(OPCODE_SPECIAL::CLITM, "CLITM", FF7ModuleInstruction, 0, "");
+            END_SUBOPCODE
+                CASE_OPCODE(OPCODE::MINIGAME, "MINIGAME", FF7ModuleInstruction, 0, "wsswBB");
+            CASE_OPCODE(OPCODE::BTMD2, "BTMD2", FF7ModuleInstruction, 0, "d");
+            CASE_OPCODE(OPCODE::BTRLD, "BTRLD", FF7ModuleInstruction, 0, "NB");
+            CASE_OPCODE(OPCODE::BTLTB, "BTLTB", FF7ModuleInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::MAPJUMP, "MAPJUMP", FF7ModuleInstruction, 0, "wsswB");
+            CASE_OPCODE(OPCODE::LSTMP, "LSTMP", FF7ModuleInstruction, 0, "NB");
+            CASE_OPCODE(OPCODE::BATTLE, "BATTLE", FF7ModuleInstruction, 0, "Nw");
+            CASE_OPCODE(OPCODE::BTLON, "BTLON", FF7ModuleInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::BTLMD, "BTLMD", FF7ModuleInstruction, 0, "w");
+            CASE_OPCODE(OPCODE::MPJPO, "MPJPO", FF7ModuleInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::PMJMP, "PMJMP", FF7ModuleInstruction, 0, "w");
+            CASE_OPCODE(OPCODE::PMJMP2, "PMJMP2", FF7ModuleInstruction, 0, "");
+            CASE_OPCODE(OPCODE::GAMEOVER, "GAMEOVER", FF7ModuleInstruction, 0, "");
+
+            // Math
+            CASE_OPCODE(OPCODE::PLUS_, "PLUS!", FF7MathInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::PLUS2_, "PLUS2!", FF7MathInstruction, 0, "NBw");
+            CASE_OPCODE(OPCODE::MINUS_, "MINUS!", FF7MathInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::MINUS2_, "MINUS2!", FF7MathInstruction, 0, "NBw");
+            CASE_OPCODE(OPCODE::INC_, "INC!", FF7MathInstruction, 0, "BB");
+            CASE_OPCODE(OPCODE::INC2_, "INC2!", FF7MathInstruction, 0, "BB");
+            CASE_OPCODE(OPCODE::DEC_, "DEC!", FF7MathInstruction, 0, "BB");
+            CASE_OPCODE(OPCODE::DEC2_, "DEC2!", FF7MathInstruction, 0, "BB");
+            CASE_OPCODE(OPCODE::RDMSD, "RDMSD", FF7MathInstruction, 0, "NB");
+            CASE_OPCODE(OPCODE::SETBYTE, "SETBYTE", FF7MathInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::SETWORD, "SETWORD", FF7MathInstruction, 0, "NBw");
+            CASE_OPCODE(OPCODE::BITON, "BITON", FF7MathInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::BITOFF, "BITOFF", FF7MathInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::BITXOR, "BITXOR", FF7MathInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::PLUS, "PLUS", FF7MathInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::PLUS2, "PLUS2", FF7MathInstruction, 0, "NBw");
+            CASE_OPCODE(OPCODE::MINUS, "MINUS", FF7MathInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::MINUS2, "MINUS2", FF7MathInstruction, 0, "NBw");
+            CASE_OPCODE(OPCODE::MUL, "MUL", FF7MathInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::MUL2, "MUL2", FF7MathInstruction, 0, "NBw");
+            CASE_OPCODE(OPCODE::DIV, "DIV", FF7MathInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::DIV2, "DIV2", FF7MathInstruction, 0, "NBw");
+            CASE_OPCODE(OPCODE::MOD, "MOD", FF7MathInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::MOD2, "MOD2", FF7MathInstruction, 0, "NBw");
+            CASE_OPCODE(OPCODE::AND, "AND", FF7MathInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::AND2, "AND2", FF7MathInstruction, 0, "NBw");
+            CASE_OPCODE(OPCODE::OR, "OR", FF7MathInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::OR2, "OR2", FF7MathInstruction, 0, "NBw");
+            CASE_OPCODE(OPCODE::XOR, "XOR", FF7MathInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::XOR2, "XOR2", FF7MathInstruction, 0, "NBw");
+            CASE_OPCODE(OPCODE::INC, "INC", FF7MathInstruction, 0, "BB");
+            CASE_OPCODE(OPCODE::INC2, "INC2", FF7MathInstruction, 0, "BB");
+            CASE_OPCODE(OPCODE::DEC, "DEC", FF7MathInstruction, 0, "BB");
+            CASE_OPCODE(OPCODE::DEC2, "DEC2", FF7MathInstruction, 0, "BB");
+            CASE_OPCODE(OPCODE::RANDOM, "RANDOM", FF7MathInstruction, 0, "BB");
+            CASE_OPCODE(OPCODE::LBYTE, "LBYTE", FF7MathInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::HBYTE, "HBYTE", FF7MathInstruction, 0, "NBw");
+            CASE_OPCODE(OPCODE::TWOBYTE, "2BYTE", FF7MathInstruction, 0, "NNBBB");
+            CASE_OPCODE(OPCODE::SIN, "SIN", FF7MathInstruction, 0, "NNwwwB");
+            CASE_OPCODE(OPCODE::COS, "COS", FF7MathInstruction, 0, "NNwwwB");
+
+            // Window
+            CASE_OPCODE(OPCODE::TUTOR, "TUTOR", FF7WindowInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::WCLS, "WCLS", FF7WindowInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::WSIZW, "WSIZW", FF7WindowInstruction, 0, "Bwwww");
+            CASE_OPCODE(OPCODE::WSPCL, "WSPCL", FF7WindowInstruction, 0, "BBBB");
+            CASE_OPCODE(OPCODE::WNUMB, "WNUMB", FF7WindowInstruction, 0, "NBwwB"); // NBdB when N == 0
+            CASE_OPCODE(OPCODE::STTIM, "STTIM", FF7WindowInstruction, 0, "NNBBB");
+            CASE_OPCODE(OPCODE::MESSAGE, "MESSAGE", FF7WindowInstruction, 0, "BB");
+            CASE_OPCODE(OPCODE::MPARA, "MPARA", FF7WindowInstruction, 0, "NBBB");
+            CASE_OPCODE(OPCODE::MPRA2, "MPRA2", FF7WindowInstruction, 0, "NBBw");
+            CASE_OPCODE(OPCODE::MPNAM, "MPNAM", FF7WindowInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::ASK, "ASK", FF7WindowInstruction, 0, "NBBBBB");
+            CASE_OPCODE(OPCODE::MENU, "MENU", FF7WindowInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::MENU2, "MENU2", FF7WindowInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::WINDOW, "WINDOW", FF7WindowInstruction, 0, "Bwwww");
+            CASE_OPCODE(OPCODE::WMOVE, "WMOVE", FF7WindowInstruction, 0, "Bss");
+            CASE_OPCODE(OPCODE::WMODE, "WMODE", FF7WindowInstruction, 0, "BBB");
+            CASE_OPCODE(OPCODE::WREST, "WREST", FF7WindowInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::WCLSE, "WCLSE", FF7WindowInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::WROW, "WROW", FF7WindowInstruction, 0, "BB");
+            CASE_OPCODE(OPCODE::GWCOL, "GWCOL", FF7WindowInstruction, 0, "NNBBBB");
+            CASE_OPCODE(OPCODE::SWCOL, "SWCOL", FF7WindowInstruction, 0, "NNBBBB");
+
+            // Party
+            CASE_OPCODE(OPCODE::SPTYE, "SPTYE", FF7PartyInstruction, 0, "NNBBB");
+            CASE_OPCODE(OPCODE::GTPYE, "GTPYE", FF7PartyInstruction, 0, "NNBBB");
+            CASE_OPCODE(OPCODE::GOLDU, "GOLDU", FF7PartyInstruction, 0, "Nww"); // Nd when N == 0
+            CASE_OPCODE(OPCODE::GOLDD, "GOLDD", FF7PartyInstruction, 0, "Nww"); // Nd when N == 0
+            CASE_OPCODE(OPCODE::CHGLD, "CHGLD", FF7PartyInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::HMPMAX1, "HMPMAX1", FF7PartyInstruction, 0, "");
+            CASE_OPCODE(OPCODE::HMPMAX2, "HMPMAX2", FF7PartyInstruction, 0, "");
+            CASE_OPCODE(OPCODE::MHMMX, "MHMMX", FF7PartyInstruction, 0, "");
+            CASE_OPCODE(OPCODE::HMPMAX3, "HMPMAX3", FF7PartyInstruction, 0, "");
+            CASE_OPCODE(OPCODE::MPU, "MPU", FF7PartyInstruction, 0, "NBw");
+            CASE_OPCODE(OPCODE::MPD, "MPD", FF7PartyInstruction, 0, "NBw");
+            CASE_OPCODE(OPCODE::HPU, "HPU", FF7PartyInstruction, 0, "NBw");
+            CASE_OPCODE(OPCODE::HPD, "HPD", FF7PartyInstruction, 0, "NBw");
+            CASE_OPCODE(OPCODE::STITM, "STITM", FF7PartyInstruction, 0, "NwB");
+            CASE_OPCODE(OPCODE::DLITM, "DLITM", FF7PartyInstruction, 0, "NwB");
+            CASE_OPCODE(OPCODE::CKITM, "CKITM", FF7PartyInstruction, 0, "NwB");
+            CASE_OPCODE(OPCODE::SMTRA, "SMTRA", FF7PartyInstruction, 0, "NNBBBB");
+            CASE_OPCODE(OPCODE::DMTRA, "DMTRA", FF7PartyInstruction, 0, "NNBBBBB");
+            CASE_OPCODE(OPCODE::CMTRA, "CMTRA", FF7PartyInstruction, 0, "NNNBBBBBB");
+            CASE_OPCODE(OPCODE::GETPC, "GETPC", FF7PartyInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::PRTYP, "PRTYP", FF7PartyInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::PRTYM, "PRTYM", FF7PartyInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::PRTYE, "PRTYE", FF7PartyInstruction, 0, "BBB");
+            CASE_OPCODE(OPCODE::MMBUD, "MMBUD", FF7PartyInstruction, 0, "BB");
+            CASE_OPCODE(OPCODE::MMBLK, "MMBLK", FF7PartyInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::MMBUK, "MMBUK", FF7PartyInstruction, 0, "B");
+
+            // Model
+            CASE_OPCODE(OPCODE::JOIN, "JOIN", FF7ModelInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::SPLIT, "SPLIT", FF7ModelInstruction, 0, "NNNssBssBB");
+            CASE_OPCODE(OPCODE::BLINK, "BLINK", FF7ModelInstruction, 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", FF7ModelInstruction, 0, parameters.c_str()
+                    ); // was BBBB
+                    CASE_OPCODE(
+                        OPCODE_KAWAI::TRNSP, "TRNSP", FF7ModelInstruction, 0, parameters.c_str()
+                    ); // was B
+                    CASE_OPCODE(
+                        OPCODE_KAWAI::AMBNT, "AMBNT", FF7ModelInstruction, 0, parameters.c_str()
+                    ); // was BBBBBBB
+                    CASE_OPCODE(
+                        OPCODE_KAWAI::Unknown03, "Unknown03",
+                        FF7ModelInstruction, 0, parameters.c_str()
+                    );
+                    CASE_OPCODE(
+                        OPCODE_KAWAI::Unknown04, "Unknown04",
+                        FF7ModelInstruction, 0, parameters.c_str()
+                    );
+                    CASE_OPCODE(
+                        OPCODE_KAWAI::Unknown05, "Unknown05",
+                        FF7ModelInstruction, 0, parameters.c_str()
+                    );
+                    CASE_OPCODE(
+                        OPCODE_KAWAI::LIGHT, "LIGHT",FF7ModelInstruction, 0, parameters.c_str()
+                    );
+                    CASE_OPCODE(
+                        OPCODE_KAWAI::Unknown07, "Unknown07",
+                        FF7ModelInstruction, 0, parameters.c_str()
+                    );
+                    CASE_OPCODE(
+                        OPCODE_KAWAI::Unknown08, "Unknown08",
+                        FF7ModelInstruction, 0, parameters.c_str()
+                    );
+                    CASE_OPCODE(
+                        OPCODE_KAWAI::Unknown09, "Unknown09",
+                        FF7ModelInstruction, 0, parameters.c_str()
+                    );
+                    CASE_OPCODE(
+                        OPCODE_KAWAI::SBOBJ, "SBOBJ",
+                        FF7ModelInstruction, 0, parameters.c_str()
+                    );
+                    CASE_OPCODE(
+                      OPCODE_KAWAI::Unknown0B, "Unknown0B",
+                      FF7ModelInstruction, 0, parameters.c_str()
+                    );
+                    CASE_OPCODE(
+                        OPCODE_KAWAI::Unknown0C, "Unknown0C",
+                        FF7ModelInstruction, 0, parameters.c_str()
+                    );
+                    CASE_OPCODE(
+                        OPCODE_KAWAI::SHINE, "SHINE", FF7ModelInstruction, 0, parameters.c_str()
+                    );
+                    CASE_OPCODE(
+                        OPCODE_KAWAI::RESET, "RESET", FF7ModelInstruction, 0, parameters.c_str()
+                    );
+                default:
+                    throw UnknownSubOpcodeException(this->address_, opcode);
+                }
+                INC_ADDR;
+                INC_ADDR;
+            }
+            OPCODE_END
+            CASE_OPCODE(OPCODE::KAWIW, "KAWIW", FF7ModelInstruction, 0, "");
+            CASE_OPCODE(OPCODE::PMOVA, "PMOVA", FF7ModelInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::PDIRA, "PDIRA", FF7ModelInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::PTURA, "PTURA", FF7ModelInstruction, 0, "BBB");
+            CASE_OPCODE(OPCODE::PGTDR, "PGTDR", FF7ModelInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::PXYZI, "PXYZI", FF7ModelInstruction, 0, "NNBBBBB");
+            CASE_OPCODE(OPCODE::TLKON, "TLKON", FF7ModelInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::PC, "PC", FF7ModelInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::opCodeCHAR, "CHAR", FF7ModelInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::DFANM, "DFANM", FF7ModelInstruction, 0, "BB");
+            CASE_OPCODE(OPCODE::ANIME1, "ANIME1", FF7ModelInstruction, 0, "BB");
+            CASE_OPCODE(OPCODE::VISI, "VISI", FF7ModelInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::XYZI, "XYZI", FF7ModelInstruction, 0, "NNsssw");
+            CASE_OPCODE(OPCODE::XYI, "XYI", FF7ModelInstruction, 0, "NNssw");
+            CASE_OPCODE(OPCODE::XYZ, "XYZ", FF7ModelInstruction, 0, "NNsss");
+            CASE_OPCODE(OPCODE::MOVE, "MOVE", FF7ModelInstruction, 0, "Nss");
+            CASE_OPCODE(OPCODE::CMOVE, "CMOVE", FF7ModelInstruction, 0, "Nss");
+            CASE_OPCODE(OPCODE::MOVA, "MOVA", FF7ModelInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::TURA, "TURA", FF7ModelInstruction, 0, "BBB");
+            CASE_OPCODE(OPCODE::ANIMW, "ANIMW", FF7ModelInstruction, 0, "");
+            CASE_OPCODE(OPCODE::FMOVE, "FMOVE", FF7ModelInstruction, 0, "Nss");
+            CASE_OPCODE(OPCODE::ANIME2, "ANIME2", FF7ModelInstruction, 0, "BB");
+            CASE_OPCODE(OPCODE::ANIM_1, "ANIM!1", FF7ModelInstruction, 0, "BB");
+            CASE_OPCODE(OPCODE::CANIM1, "CANIM1", FF7ModelInstruction, 0, "BBBB");
+            CASE_OPCODE(OPCODE::CANM_1, "CANM!1", FF7ModelInstruction, 0, "BBBB");
+            CASE_OPCODE(OPCODE::MSPED, "MSPED", FF7ModelInstruction, 0, "Nw");
+            CASE_OPCODE(OPCODE::DIR, "DIR", FF7ModelInstruction, 0, "BB");
+            CASE_OPCODE(OPCODE::TURNGEN, "TURNGEN", FF7ModelInstruction, 0, "NBBBB");
+            CASE_OPCODE(OPCODE::TURN, "TURN", FF7ModelInstruction, 0, "NBBBB");
+            CASE_OPCODE(OPCODE::DIRA, "DIRA", FF7ModelInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::GETDIR, "GETDIR", FF7ModelInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::GETAXY, "GETAXY", FF7ModelInstruction, 0, "NBBB");
+            CASE_OPCODE(OPCODE::GETAI, "GETAI", FF7ModelInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::ANIM_2, "ANIM!2", FF7ModelInstruction, 0, "BB");
+            CASE_OPCODE(OPCODE::CANIM2, "CANIM2", FF7ModelInstruction, 0, "BBBB");
+            CASE_OPCODE(OPCODE::CANM_2, "CANM!2", FF7ModelInstruction, 0, "BBBB");
+            CASE_OPCODE(OPCODE::ASPED, "ASPED", FF7ModelInstruction, 0, "Nw");
+            CASE_OPCODE(OPCODE::CC, "CC", FF7ModelInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::JUMP, "JUMP", FF7ModelInstruction, 0, "NNssww");
+            CASE_OPCODE(OPCODE::AXYZI, "AXYZI", FF7ModelInstruction, 0, "NNBBBBB");
+            CASE_OPCODE(OPCODE::LADER, "LADER", FF7ModelInstruction, 0, "NNssswBBBB");
+            CASE_OPCODE(OPCODE::OFST, "OFST", FF7ModelInstruction, 0, "NNBsssw");
+            CASE_OPCODE(OPCODE::OFSTW, "OFSTW", FF7ModelInstruction, 0, "");
+            CASE_OPCODE(OPCODE::TALKR, "TALKR", FF7ModelInstruction, 0, "NB");
+            CASE_OPCODE(OPCODE::SLIDR, "SLIDR", FF7ModelInstruction, 0, "NB");
+            CASE_OPCODE(OPCODE::SOLID, "SOLID", FF7ModelInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::TLKR2, "TLKR2", FF7ModelInstruction, 0, "Nw");
+            CASE_OPCODE(OPCODE::SLDR2, "SLDR2", FF7ModelInstruction, 0, "Nw");
+            CASE_OPCODE(OPCODE::CCANM, "CCANM", FF7ModelInstruction, 0, "BBB");
+            CASE_OPCODE(OPCODE::FCFIX, "FCFIX", FF7ModelInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::ANIMB, "ANIMB", FF7ModelInstruction, 0, "");
+            CASE_OPCODE(OPCODE::TURNW, "TURNW", FF7ModelInstruction, 0, "");
+
+            // Walkmesh
+            CASE_OPCODE(OPCODE::SLIP, "SLIP", FF7WalkmeshInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::UC, "UC", FF7WalkmeshInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::IDLCK, "IDLCK", FF7WalkmeshInstruction, 0, "wB");
+            CASE_OPCODE(OPCODE::LINON, "LINON", FF7WalkmeshInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::SLINE, "SLINE", FF7WalkmeshInstruction, 0, "NNNssssss");
+            //CASE_OPCODE(OPCODE::LINE, "LINE", FF7WalkmeshInstruction, 0, "ssssss");
+            // LINE is done like this to save opcode params to the function out params.
+            case OPCODE::LINE:
+                is_line = true;
+                full_opcode = (full_opcode << 8) + OPCODE::LINE;
+                this->_insts.push_back(new FF7WalkmeshInstruction());
+                (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();
+                break;
+
+            // Backgnd
+            CASE_OPCODE(OPCODE::BGPDH, "BGPDH", FF7BackgroundInstruction, 0, "NBs");
+            CASE_OPCODE(OPCODE::BGSCR, "BGSCR", FF7BackgroundInstruction, 0, "NBss");
+            CASE_OPCODE(OPCODE::MPPAL, "MPPAL", FF7BackgroundInstruction, 0, "NNNBBBBBBB");
+            CASE_OPCODE(OPCODE::BGON, "BGON", FF7BackgroundInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::BGOFF, "BGOFF", FF7BackgroundInstruction, 0, "NBB");
+            CASE_OPCODE(OPCODE::BGROL, "BGROL", FF7BackgroundInstruction, 0, "NB");
+            CASE_OPCODE(OPCODE::BGROL2, "BGROL2", FF7BackgroundInstruction, 0, "NB");
+            CASE_OPCODE(OPCODE::BGCLR, "BGCLR", FF7BackgroundInstruction, 0, "NB");
+            CASE_OPCODE(OPCODE::STPAL, "STPAL", FF7BackgroundInstruction, 0, "NBBB");
+            CASE_OPCODE(OPCODE::LDPAL, "LDPAL", FF7BackgroundInstruction, 0, "NBBB");
+            CASE_OPCODE(OPCODE::CPPAL, "CPPAL", FF7BackgroundInstruction, 0, "NBBB");
+            CASE_OPCODE(OPCODE::RTPAL, "RTPAL", FF7BackgroundInstruction, 0, "NNBBBB");
+            CASE_OPCODE(OPCODE::ADPAL, "ADPAL", FF7BackgroundInstruction, 0, "NNNBBBBBB");
+            CASE_OPCODE(OPCODE::MPPAL2, "MPPAL2", FF7BackgroundInstruction, 0, "NNNBBBBBB");
+            CASE_OPCODE(OPCODE::STPLS, "STPLS", FF7BackgroundInstruction, 0, "BBBB");
+            CASE_OPCODE(OPCODE::LDPLS, "LDPLS", FF7BackgroundInstruction, 0, "BBBB");
+            CASE_OPCODE(OPCODE::CPPAL2, "CPPAL2", FF7BackgroundInstruction, 0, "BBBBBBB");
+            CASE_OPCODE(OPCODE::RTPAL2, "RTPAL2", FF7BackgroundInstruction, 0, "BBBBBBB");
+            CASE_OPCODE(OPCODE::ADPAL2, "ADPAL2", FF7BackgroundInstruction, 0, "BBBBBBBBBB");
+
+            // Camera
+            CASE_OPCODE(OPCODE::NFADE, "NFADE", FF7CameraInstruction, 0, "NNBBBBBB");
+            CASE_OPCODE(OPCODE::SHAKE, "SHAKE", FF7CameraInstruction, 0, "BBBBBBB");
+            CASE_OPCODE(OPCODE::SCRLO, "SCRLO", FF7CameraInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::SCRLC, "SCRLC", FF7CameraInstruction, 0, "BBBB");
+            CASE_OPCODE(OPCODE::SCRLA, "SCRLA", FF7CameraInstruction, 0, "NwBB");
+            CASE_OPCODE(OPCODE::SCR2D, "SCR2D", FF7CameraInstruction, 0, "Nss");
+            CASE_OPCODE(OPCODE::SCRCC, "SCRCC", FF7CameraInstruction, 0, "");
+            CASE_OPCODE(OPCODE::SCR2DC, "SCR2DC", FF7CameraInstruction, 0, "NNssw");
+            CASE_OPCODE(OPCODE::SCRLW, "SCRLW", FF7CameraInstruction, 0, "");
+            CASE_OPCODE(OPCODE::SCR2DL, "SCR2DL", FF7CameraInstruction, 0, "NNssw");
+            CASE_OPCODE(OPCODE::VWOFT, "VWOFT", FF7CameraInstruction, 0, "NssB");
+            CASE_OPCODE(OPCODE::FADE, "FADE", FF7CameraInstruction, 0, "NNBBBBBB");
+            CASE_OPCODE(OPCODE::FADEW, "FADEW", FF7CameraInstruction, 0, "");
+            CASE_OPCODE(OPCODE::SCRLP, "SCRLP", FF7CameraInstruction, 0, "NwBB");
+            CASE_OPCODE(OPCODE::MVCAM, "MVCAM", FF7CameraInstruction, 0, "B");
+
+            // AV
+            CASE_OPCODE(OPCODE::BGMOVIE, "BGMOVIE", FF7AudioVideoInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::AKAO2, "AKAO2", FF7AudioVideoInstruction, 0, "NNNBwwwww");
+            CASE_OPCODE(OPCODE::MUSIC, "MUSIC", FF7AudioVideoInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::SOUND, "SOUND", FF7AudioVideoInstruction, 0, "NwB");
+            CASE_OPCODE(OPCODE::AKAO, "AKAO", FF7AudioVideoInstruction, 0, "NNNBBwwww");
+            CASE_OPCODE(OPCODE::MUSVT, "MUSVT", FF7AudioVideoInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::MUSVM, "MUSVM", FF7AudioVideoInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::MULCK, "MULCK", FF7AudioVideoInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::BMUSC, "BMUSC", FF7AudioVideoInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::CHMPH, "CHMPH", FF7AudioVideoInstruction, 0, "BBB");
+            CASE_OPCODE(OPCODE::PMVIE, "PMVIE", FF7AudioVideoInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::MOVIE, "MOVIE", FF7AudioVideoInstruction, 0, "");
+            CASE_OPCODE(OPCODE::MVIEF, "MVIEF", FF7AudioVideoInstruction, 0, "NB");
+            CASE_OPCODE(OPCODE::FMUSC, "FMUSC", FF7AudioVideoInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::CMUSC, "CMUSC", FF7AudioVideoInstruction, 0, "BBBBBBB");
+            CASE_OPCODE(OPCODE::CHMST, "CHMST", FF7AudioVideoInstruction, 0, "NB");
+
+            // Uncat
+            CASE_OPCODE(OPCODE::MPDSP, "MPDSP", FF7UncategorizedInstruction, 0, "B");
+            CASE_OPCODE(OPCODE::SETX, "SETX", FF7UncategorizedInstruction, 0, "BBBBBB");
+            CASE_OPCODE(OPCODE::GETX, "GETX", FF7UncategorizedInstruction, 0, "BBBBBB");
+            CASE_OPCODE(OPCODE::SEARCHX, "SEARCHX", FF7UncategorizedInstruction, 0, "BBBBBBBBBB");
+
+            default:
+                throw UnknownOpcodeException(this->address_, opcode);
+        }
+        INC_ADDR;
+
+        // Is it within an "if" statement tracking?
+        InstPtr i = this->_insts.back();
+        if (i->isCondJump()) exitAddrs.push_back(i->getDestAddress());
+        if (!exitAddrs.empty())
+            if (i->_address == exitAddrs.back()) exitAddrs.pop_back();
+
+        // Only bail if its the first RET that isn't within an "if" block.
+        if (full_opcode == OPCODE::RET && exitAddrs.empty()) return is_line;
+    }
+    return is_line;
+}

+ 0 - 293
V-Gears-Installer/src/decompiler/field/ff7_field_codegen.cpp

@@ -1,293 +0,0 @@
-#include "decompiler/field/ff7_field_codegen.h"
-#include "decompiler/field/ff7_field_engine.h"
-#include <boost/algorithm/string/predicate.hpp>
-
-void FF7::FF7CodeGenerator::onBeforeStartFunction(const Function& func)
-{
-    // Start class
-    FunctionMetaData metaData(func._metadata);
-    if (metaData.IsStart())
-    {
-        addOutputLine("EntityContainer[\"" + metaData.EntityName() + "\"] = {", false, true);
-        if (metaData.CharacterId() != -1)
-        {
-            addOutputLine(metaData.EntityName() + " = nil,");
-        }
-        addOutputLine("");
-    }
-}
-
-void FF7::FF7CodeGenerator::onStartFunction(const Function& func)
-{
-    addOutputLine("--[[");
-    for (const auto& inst : mInsts)
-    {
-        if (inst->_address >= func.mStartAddr && inst->_address <= func.mEndAddr)
-        {
-            std::stringstream output;
-            output << inst;
-            addOutputLine(output.str());
-        }
-    }
-    addOutputLine("]]\n");
-}
-
-void FF7::FF7CodeGenerator::onEndFunction(const Function& func)
-{
-    // End function
-    addOutputLine("end,", true, false);
-    
-    // End class
-    FunctionMetaData metaData(func._metadata);
-    if (metaData.IsEnd())
-    {
-        addOutputLine("}", true, false);
-    }
-}
-
-std::string FF7::FF7CodeGenerator::constructFuncSignature(const Function &func)
-{
-    // Generate name
-    return func._name + " = function(self)";
-}
-
-void FF7::FF7SimpleCodeGenerator::generate(InstVec& insts, const Graph& /*g*/){
-    // TODO: Break into parts
-
-    auto instruction = insts.begin();
-    
-    std::vector<std::pair<Function&, InstVec>> functions_with_bodies;
-    for (
-      auto function = _engine->_functions.begin();
-      function != _engine->_functions.end();
-      ++ function
-    ){
-        InstVec body;
-        for (size_t i = 0; i < function->second.mNumInstructions; ++i, ++instruction)
-            body.push_back(*instruction);
-        functions_with_bodies.push_back(std::pair<Function&, InstVec> {function->second, body});
-    }
-
-    for (
-      auto function = functions_with_bodies.begin();
-      function != functions_with_bodies.end();
-      ++ function
-    ){
-
-        onBeforeStartFunction(function->first);
-        auto signature = constructFuncSignature(function->first);
-        addOutputLine(signature, false, true);
-        onStartFunction(function->first);
-        
-        // Comment with original instructions.
-        std::unordered_map<uint32, InstVec> labels;
-        for (
-          auto instruction = function->second.begin();
-          instruction != function->second.end();
-          ++ instruction
-        ){
-            if ((*instruction)->isCondJump() || (*instruction)->isUncondJump()){
-                auto targetAddr = (*instruction)->getDestAddress();
-                auto label = labels.find(targetAddr);
-                if (label == labels.end()) labels.insert({targetAddr, InstVec()});
-                labels[targetAddr].push_back(*instruction);
-            }
-        }
-
-        // Implemented instructions.
-        bool end_needed = false;
-        for (
-          auto instruction = function->second.begin();
-          instruction != function->second.end();
-          ++instruction
-        ){
-
-            auto label = labels.find((*instruction)->_address);
-            if (label != labels.end()){
-                bool needs_label = false;
-                bool needs_new_line = false;
-                for (auto origin = label->second.begin(); origin != label->second.end(); ++ origin){
-                    if ((*origin)->isCondJump()){
-                        addOutputLine("end", true, false);
-                        needs_new_line = true;
-                    }
-                    else needs_label = true;
-                }
-                if (needs_new_line) addOutputLine("");
-                if (needs_label)
-                    addOutputLine((boost::format("::label_0x%1$X::") % label->first).str());
-            }
-
-            ValueStack stack;
-            (*instruction)->processInst(function->first, stack, _engine, this);
-
-            if (end_needed){
-                addOutputLine("end -- end if", true, false);
-                end_needed = false;
-            }
-
-            if ((*instruction)->isCondJump()){
-                addOutputLine(
-                  (boost::format("if (%s) then") % stack.pop()->getString()).str(), false, true
-                );
-
-                // If the next instruction is the last in the function, mark the next pass to
-                // add an 'end' after the instruction to clode the if.
-                if ((*(instruction + 1))->_address == (*(function->second.back()))._address)
-                    end_needed = true;
-
-            }
-            else if ((*instruction)->isUncondJump()){
-                // If destination address is outside the functions, turn goto into a return.
-                if ((*instruction)->getDestAddress() > function->first.mEndAddr){
-                    addOutputLine(
-                      "-- Overflowed jump to "
-                      + (boost::format("0x%1$X") % (*instruction)->getDestAddress()).str()
-                      + " (last address in function is "
-                      + (boost::format("0x%1$X)") % function->first.mEndAddr).str()
-                    );
-                    addOutputLine("do return 0 end");
-                }
-                // Prevent backward jumps in the on_start script.
-                else if (
-                  "on_start" == function->first._name
-                  && (*instruction)->getDestAddress() <= (*instruction)->_address
-                ){
-                    addOutputLine("-- No infinite loops in the on_start script.");
-                    addOutputLine((
-                      boost::format("-- goto label_0x%1$X") % (*instruction)->getDestAddress()
-                    ).str());
-                }
-                else{
-                    addOutputLine(
-                      (boost::format("goto label_0x%1$X") % (*instruction)->getDestAddress()).str()
-                    );
-                }
-            }
-
-            // Else, already output'd.
-        }
-
-        // Add missing return:
-        if (
-          "return 0" != mLines.at(mLines.size() - 1)._line
-          && "do return 0 end" != mLines.at(mLines.size() - 1)._line
-        ){
-            addOutputLine("do return 0 end", false, false);
-        }
-        onEndFunction(function->first);
-    }
-
-    for (auto i = mLines.begin(); i != mLines.end(); ++i){
-        if (i->_unindentBefore && _indentLevel > 0){
-            _indentLevel --;
-        }
-        _output << indentString(i->_line) << std::endl;
-        if (i->_indentAfter) _indentLevel++;
-    }
-}
-
-void FF7::FF7SimpleCodeGenerator::addOutputLine(std::string s, bool unindentBefore, bool indentAfter)
-{
-    mLines.push_back(CodeLine(s, unindentBefore, indentAfter));
-}
-
-float FF7::FF7SimpleCodeGenerator::ScaleFactor() const
-{
-    return static_cast<FF7::FF7FieldEngine*>(_engine)->ScaleFactor();
-}
-
-void FF7::FF7SimpleCodeGenerator::onBeforeStartFunction(const Function& func)
-{
-    // Start class
-    FunctionMetaData metaData(func._metadata);
-    if (metaData.IsStart())
-    {
-        addOutputLine("EntityContainer[\"" + metaData.EntityName() + "\"] = {", false, true);
-        if (metaData.CharacterId() != -1)
-        {
-            addOutputLine(metaData.EntityName() + " = nil,\n");
-        }
-    }
-
-    const auto comment = mFormatter.FunctionComment(metaData.EntityName(), func._name);
-    if (!comment.empty())
-    {
-        addOutputLine("-- " + comment);
-    }
-}
-
-void FF7::FF7SimpleCodeGenerator::onStartFunction(const Function& func)
-{
-    addOutputLine("--[[");
-    for (const auto& inst : mInsts)
-    {
-        if (inst->_address >= func.mStartAddr && inst->_address <= func.mEndAddr)
-        {
-            std::stringstream output;
-            output << inst;
-            addOutputLine(output.str());
-        }
-    }
-    addOutputLine("]]\n");
-
-    if (func._name == "on_start" || func._name == "init")
-    {
-        addOutputLine("-- HACK ensure camera follows cloud, fix in engine properly later");
-        addOutputLine("background2d:autoscroll_to_entity(entity_manager:get_entity(\"Cloud\"))");
-    }
-  
-}
-
-void FF7::FF7SimpleCodeGenerator::onEndFunction(const Function& func)
-{
-    // End function
-    addOutputLine("end,", true, false);
-
-    // End class
-    FunctionMetaData metaData(func._metadata);
-    if (metaData.IsEnd())
-    {
-        addOutputLine("}\n\n\n", true, false);
-    }
-    else
-    {
-        addOutputLine("\n");
-    }
-}
-
-std::string FF7::FF7SimpleCodeGenerator::constructFuncSignature(const Function &func)
-{
-    // Generate name
-    FunctionMetaData metaData(func._metadata);
-    return mFormatter.FunctionName(metaData.EntityName(), func._name) + " = function(self)";
-}
-
-const std::string FF7::FF7CodeGeneratorHelpers::FormatInstructionNotImplemented(const std::string& entity, uint32 address, uint32 opcode)
-{
-    return (boost::format("-- log:log(\"In entity \\\"%1%\\\", address 0x%2$08x: instruction 0x%3$04x not implemented\")") % entity % address % opcode).str();
-}
-
-const std::string FF7::FF7CodeGeneratorHelpers::FormatInstructionNotImplemented(const std::string& entity, uint32 address, const Instruction& instruction)
-{
-    std::stringstream parameterList;
-    for (auto i = instruction._params.begin(); i != instruction._params.end(); ++i)
-    {
-        if (i != instruction._params.begin())
-        {
-            parameterList << ", ";
-        }
-        parameterList << *i;
-    }
-    return (boost::format("-- log:log(\"In entity \\\"%1%\\\", address 0x%2$08x: instruction %3%(%4%) not implemented\")") % entity % address % instruction._name % parameterList.str()).str();
-}
-
-const std::string FF7::FF7CodeGeneratorHelpers::FormatBool(uint32 value)
-{
-    return value == 0 ? "false" : "true";
-}
-
-const std::string FF7::FF7CodeGeneratorHelpers::FormatInvertedBool(uint32 value)
-{
-    return value == 0 ? "true" : "false";
-}

+ 0 - 744
V-Gears-Installer/src/decompiler/field/ff7_field_disassembler.cpp

@@ -1,744 +0,0 @@
-#include <vector>
-#include "decompiler/field/ff7_field_disassembler.h"
-#include "decompiler/field/ff7_field_engine.h"
-#include "decompiler/decompiler_engine.h"
-#include <boost/format.hpp>
-#include "common/lzs.h"
-#include "common/make_unique.h"
-#include <boost/algorithm/string/split.hpp>
-#include <boost/algorithm/string.hpp>
-#include "decompiler/field/ff7_field_codegen.h"
-
-FF7::FF7Disassembler::FF7Disassembler(SUDM::IScriptFormatter& formatter, FF7FieldEngine* engine, InstVec& insts, const std::vector<unsigned char>& rawScriptData)
-    : SimpleDisassembler(insts),
-    mEngine(engine),
-    mFormatter(formatter)
-{
-    mbFromRaw = true;
-    kSectionPointersSize = 0; // If loading a raw section then we don't have a "sections header" to skip
-    auto dataCopy = rawScriptData;
-    mStream = std::make_unique<BinaryReader>(std::move(dataCopy));
-    ReadHeader();
-}
-
-FF7::FF7Disassembler::FF7Disassembler(SUDM::IScriptFormatter& formatter, FF7FieldEngine *engine, InstVec &insts)
-    : SimpleDisassembler(insts),
-    mEngine(engine),
-    mFormatter(formatter)
-{
-
-}
-
-FF7::FF7Disassembler::~FF7Disassembler()
-{
-
-}
-
-void FF7::FF7Disassembler::ReadHeader()
-{
-    if (!mbFromRaw)
-    {
-        // First read the file section pointers
-        for (int i = 0; i < kNumSections; i++)
-        {
-            mSections[i] = mStream->ReadU32();
-        }
-
-        // Now fix up from PSX RAM pointers to simple file offsets
-        const uint32 basePtr = mSections[0];
-        for (int i = 0; i < kNumSections; i++)
-        {
-            mSections[i] = (mSections[i] - basePtr) + kSectionPointersSize;
-        }
-
-        // Now seek to the script section
-        mStream->Seek(mSections[eScript]);
-    }
-
-    // Read the script header
-    mHeader.Read(*mStream);
-
-    mScaleFactor = static_cast<float>(mHeader.mScale) / 512.0f;
-}
-
-void FF7::FF7Disassembler::open(const char *filename)
-{
-    // Read all of the file, decompress it, then stuff it into a stream
-    mStream = std::make_unique<BinaryReader>(Lzs::Decompress(BinaryReader::ReadAll(filename)));
-    ReadHeader();
-}
-
-uint32 FF7::FF7Disassembler::GetEndOfScriptOffset(uint16 curEntryPoint, size_t entityIndex, size_t scriptIndex)
-{
-    uint16 nextEntryPoint = curEntryPoint;
-    do
-    {
-        if (scriptIndex + 1 >= 32)
-        {
-            if (entityIndex + 1 >= mHeader.mEntityScripts.size())
-            {
-                // This is the very last script, so use the end of its data which is the offset to strings
-                return mHeader.mOffsetToStrings;
-            }
-            else
-            {
-                // Wrap around to the next entity
-                entityIndex++;
-                scriptIndex = 0;
-            }
-        }
-        else
-        {
-            // Get the next script in the same entity
-            scriptIndex++;
-        }
-        nextEntryPoint = mHeader.mEntityScripts[entityIndex][scriptIndex];
-    } while (nextEntryPoint == curEntryPoint);
-    return nextEntryPoint;
-}
-
-std::unique_ptr<Function> FF7::FF7Disassembler::StartFunction(size_t scriptIndex)
-{
-    auto func = std::make_unique<Function>();
-    func->_retVal = false;
-    func->_args = 0;
-    func->_name = "script_" + std::to_string(scriptIndex);
-    func->mStartAddr = _address;
-    return func;
-}
-
-struct ScriptInfo
-{
-    uint16 mEntryPoint;
-    uint32 mNextEntryPoint;
-    size_t mIndex;
-};
-
-void FF7::FF7Disassembler::doDisassemble()
-{
-    // Loop through the scripts for each entity
-    for (size_t entityNumber = 0; entityNumber < mHeader.mEntityScripts.size(); entityNumber++)
-    {
-        std::string strOriginalName = mHeader.mFieldEntityNames[entityNumber].data();
-        if (strOriginalName.empty())
-        {
-            // If the entity name was blank in the file then use a consistent generated name
-            strOriginalName = "entity_" + std::to_string(entityNumber);
-        }
-        const std::string entityName = mFormatter.EntityName(strOriginalName);
-
-        // Only parse each script one
-        std::set<uint16> parsedScripts;
-        std::vector<ScriptInfo> scriptInfo;
-
-        // Collect the scripts to parse
-        for (size_t scriptIndex = 0; scriptIndex < mHeader.mEntityScripts[entityNumber].size(); scriptIndex++)
-        {
-            uint16 scriptEntryPoint = mHeader.mEntityScripts[entityNumber][scriptIndex];
-            if (parsedScripts.find(scriptEntryPoint) != std::end(parsedScripts))
-            {
-                // If we've already parsed this scripts entry point, then don't do it again as it means
-                // two scripts have the same entry which only seems to be true for "empty" scripts
-                continue;
-            }
-            parsedScripts.insert(scriptEntryPoint);
-
-            const uint32 nextScriptEntryPoint = GetEndOfScriptOffset(scriptEntryPoint, entityNumber, scriptIndex);
-            const uint32 scriptSize = nextScriptEntryPoint - scriptEntryPoint;
-            if (scriptSize > 0)
-            {
-                ScriptInfo info = { scriptEntryPoint, nextScriptEntryPoint, scriptIndex };
-                scriptInfo.push_back(info);
-            }
-        }
-
-        for (auto it = scriptInfo.begin(); it != scriptInfo.end(); it++)
-        {
-            const bool isStart = it == scriptInfo.begin();
-            const bool isEnd = it == (--scriptInfo.end());
-            DisassembleIndivdualScript(entityName, entityNumber, it->mIndex, it->mEntryPoint, it->mNextEntryPoint, isStart, isEnd);
-        }
-    }
-}
-
-static int FindId(uint32 startAddr, uint32 endAddr, const InstVec& insts)
-{
-    for (const InstPtr& instruction : insts)
-    {
-        if (instruction->_address >= startAddr && instruction->_address <= endAddr)
-        {
-            if (instruction->_opcode == FF7::eOpcodes::opCodeCHAR)
-            {
-                return instruction->_params[0]->getSigned();
-            }
-        }
-    }
-    return -1;
-}
-
-void FF7::FF7Disassembler::AddFunc(
-  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
-){
-
-    bool is_line = false;
-    std::vector<float> point_a = {0, 0, 0};
-    std::vector<float> point_b = {0, 0, 0};
-    const auto SCRIPT_ENTRY_POINT = mStream->Position();
-
-    // Read each block of opcodes up to a return.
-    const size_t old_num_instructions = _insts.size();
-
-    // Initialize the function.
-    std::unique_ptr<Function> func = StartFunction(script_index);
-
-    // Read.
-    if (to_return_only){
-        // Read opcodes to the end or bail at the first return.
-        is_line = ReadOpCodesToPositionOrReturn(
-          next_script_entry_point + kSectionPointersSize, point_a, point_b
-        );
-        auto stream_pos = mStream->Position();
-        const size_t endPos = next_script_entry_point + kSectionPointersSize;
-        // Can't be the end if there is more data:
-        if (stream_pos != endPos) is_end = false;
-    }
-    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
-        while (mStream->Position() != next_script_entry_point + kSectionPointersSize){
-            is_line = ReadOpCodesToPositionOrReturn(
-              next_script_entry_point + kSectionPointersSize, point_a, point_b
-            );
-        }
-    }
-
-    // Read metadata, mark start and/or end.
-    std::string meta_data;
-    if (is_start && is_end) meta_data = "start_end_";
-    else if (is_start) meta_data = "start_";
-    else if (is_end) meta_data = "end_";
-
-    const size_t new_num_instructions = _insts.size();
-    func->mNumInstructions = new_num_instructions - old_num_instructions;
-    func->mEndAddr = _insts.back()->_address;
-
-    if (!func_name.empty()) func->_name = func_name;
-
-    if (mEngine->EntityIsLine(entity_index)){
-        switch (script_index){
-            // main   - on_update
-            case 0: break;
-            // [OK]   - on_interact
-            case 1: break;
-            // Move - on_enter_line
-            case 2: func->_name = "on_enter_line"; break;
-            // Move - on_move_to_line
-            case 3: func->_name = "on_move_to_line"; break;
-            // Go - on_cross_line
-            case 4: func->_name = "on_cross_line"; break;
-            // Go1x - on_cross_line
-            case 5: func->_name = "on_cross_line_once"; break;
-            // GoAway - on_leave_line
-            case 6: func->_name = "on_leave_line"; break;
-        }
-    }
-
-    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
-    // its other functions and use that instead.
-    if (id == -1){
-        for (auto& func : mEngine->_functions){
-            FunctionMetaData func_meta_data(func.second._metadata);
-            if (func_meta_data.EntityName() == entity_name && func_meta_data.CharacterId() != -1){
-                id = func_meta_data.CharacterId();
-                break;
-            }
-        }
-    }
-
-    meta_data += std::to_string(id) + "_" + entity_name;
-    func->_metadata = meta_data;
-
-    mEngine->_functions[SCRIPT_ENTRY_POINT] = *func;
-    mEngine->AddEntityFunction(entity_name, entity_index, func->_name, script_index);
-
-    // If the entity is a line, mark it as so.
-    if (is_line) mEngine->MarkEntityAsLine(entity_index, true, point_a, point_b);
-
-
-}
-
-void FF7::FF7Disassembler::DisassembleIndivdualScript(std::string entityName,
-    size_t entityIndex,
-    size_t scriptIndex,
-    size_t scriptEntryPoint,
-    uint32 nextScriptEntryPoint,
-    bool isStart,
-    bool isEnd)
-{
-
-    scriptEntryPoint += kSectionPointersSize;
-
-    mStream->Seek(scriptEntryPoint);
-
-    _addressBase = mStream->Position();
-    _address = _addressBase;
-
-    // "Normal" script
-    if (scriptIndex > 0)
-    {
-        if (scriptIndex == 1)
-        {
-            AddFunc(entityName, entityIndex, scriptIndex, nextScriptEntryPoint, isStart, isEnd, false, "on_interact");
-        }
-        else
-        {
-            AddFunc(entityName, entityIndex, scriptIndex, nextScriptEntryPoint, isStart, isEnd, false, "");
-        }
-    }
-    else
-    {
-        const size_t endPos = nextScriptEntryPoint + kSectionPointersSize;
-
-        // Read the init script, which means stop at the first return
-        AddFunc(entityName, entityIndex, scriptIndex, nextScriptEntryPoint, isStart, isEnd, true, "on_start");
-
-        // Not at the end of this script? Then the remaining data is the "main" script
-        auto streamPos = mStream->Position();
-        if (streamPos != endPos)
-        {
-            // The "main" script can have more than one return statement
-            AddFunc(entityName, entityIndex, scriptIndex, nextScriptEntryPoint, false, isEnd, false, "on_update");
-            streamPos = mStream->Position();
-
-            // But should end exactly on the end pos
-            if (streamPos != endPos)
-            {
-                throw InternalDecompilerError();
-            }
-        }
-
-    }
-}
-
-
-const FF7::TInstructRecord kOpcodes[] =
-{
-    // Flow
-    { 1, FF7::eOpcodes::RET, "RET", "", FF7::FF7ControlFlowInstruction::Create },
-    { 1, FF7::eOpcodes::REQ, "REQ", "BU", FF7::FF7ControlFlowInstruction::Create },
-    { 1, FF7::eOpcodes::REQSW, "REQSW", "BU", FF7::FF7ControlFlowInstruction::Create },
-    { 1, FF7::eOpcodes::REQEW, "REQEW", "BU", FF7::FF7ControlFlowInstruction::Create },
-    { 1, FF7::eOpcodes::NOP, "NOP", "", FF7::FF7NoOperationInstruction::Create },
-    { 1, FF7::eOpcodes::IFUB, "IFUB", "NNBBBL", FF7::FF7NoOperationInstruction::Create }
-};
-
-std::map<std::string, const FF7::TInstructRecord*> FF7::FieldInstructions()
-{
-    // Convert the array to a map that we can query on by mnemonic
-    std::map<std::string, const TInstructRecord*> mnemonicToInstructionRecords;
-    for (size_t i = 0; i < boost::size(kOpcodes); i++)
-    {
-        mnemonicToInstructionRecords[kOpcodes[i].mMnemonic] = &kOpcodes[i];
-    }
-    return mnemonicToInstructionRecords;
-}
-
-bool FF7::FF7Disassembler::ReadOpCodesToPositionOrReturn(
-  size_t end_pos, std::vector<float>& point_a, std::vector<float>& point_b
-){
-
-    bool is_line = false;
-    std::vector<unsigned int> exitAddrs;
-    while (mStream->Position() < end_pos){
-        uint8 opcode = mStream->ReadU8();
-        uint32 full_opcode = 0;
-        std::string opcodePrefix;
-        switch (opcode){
-            // Flow
-            OPCODE(eOpcodes::IFUB, "IFUB", FF7CondJumpInstruction, 0, "NBBBB");
-            OPCODE(eOpcodes::RET, "RET", FF7ControlFlowInstruction, 0, "");
-            OPCODE(eOpcodes::REQ, "REQ", FF7ControlFlowInstruction, 0, "BU");
-            OPCODE(eOpcodes::REQSW, "REQSW", FF7ControlFlowInstruction, 0, "BU");
-            OPCODE(eOpcodes::REQEW, "REQEW", FF7ControlFlowInstruction, 0, "BU");
-            OPCODE(eOpcodes::PREQ, "PREQ", FF7ControlFlowInstruction, 0, "BU");
-            OPCODE(eOpcodes::PRQSW, "PRQSW", FF7ControlFlowInstruction, 0, "BU");
-            OPCODE(eOpcodes::PRQEW, "PRQEW", FF7ControlFlowInstruction, 0, "BU");
-            OPCODE(eOpcodes::RETTO, "RETTO", FF7ControlFlowInstruction, 0, "U");
-            OPCODE(eOpcodes::JMPF, "JMPF", FF7UncondJumpInstruction, 0, "B");
-            OPCODE(eOpcodes::JMPFL, "JMPFL", FF7UncondJumpInstruction, 0, "w");
-            OPCODE(eOpcodes::JMPB, "JMPB", FF7UncondJumpInstruction, 0, "B");
-            OPCODE(eOpcodes::JMPBL, "JMPBL", FF7UncondJumpInstruction, 0, "w");
-            OPCODE(eOpcodes::IFUBL, "IFUBL", FF7CondJumpInstruction, 0, "NBBBw");
-            OPCODE(eOpcodes::IFSW, "IFSW", FF7CondJumpInstruction, 0, "NwwBB");
-            OPCODE(eOpcodes::IFSWL, "IFSWL", FF7CondJumpInstruction, 0, "NwwBw");
-            OPCODE(eOpcodes::IFUW, "IFUW", FF7CondJumpInstruction, 0, "NwwBB");
-            OPCODE(eOpcodes::IFUWL, "IFUWL", FF7CondJumpInstruction, 0, "NwwBw");
-            OPCODE(eOpcodes::WAIT, "WAIT", FF7ControlFlowInstruction, 0, "w");
-            OPCODE(eOpcodes::IFKEY, "IFKEY", FF7CondJumpInstruction, 0, "wB");
-            OPCODE(eOpcodes::IFKEYON, "IFKEYON", FF7CondJumpInstruction, 0, "wB");
-            OPCODE(eOpcodes::IFKEYOFF, "IFKEYOFF", FF7CondJumpInstruction, 0, "wB");
-            OPCODE(eOpcodes::NOP, "NOP", FF7NoOperationInstruction, 0, "");
-            OPCODE(eOpcodes::IFPRTYQ, "IFPRTYQ", FF7CondJumpInstruction, 0, "BB");
-            OPCODE(eOpcodes::IFMEMBQ, "IFMEMBQ", FF7CondJumpInstruction, 0, "BB");
-
-            // Module
-            OPCODE(eOpcodes::DSKCG, "DSKCG", FF7ModuleInstruction, 0, "B");
-            START_SUBOPCODE(eOpcodes::SPECIAL)
-                OPCODE(eSpecialOpcodes::ARROW, "ARROW", FF7ModuleInstruction, 0, "B");
-            OPCODE(eSpecialOpcodes::PNAME, "PNAME", FF7ModuleInstruction, 0, "B");
-            OPCODE(eSpecialOpcodes::GMSPD, "GMSPD", FF7ModuleInstruction, 0, "B");
-            OPCODE(eSpecialOpcodes::SMSPD, "SMSPD", FF7ModuleInstruction, 0, "BB");
-            OPCODE(eSpecialOpcodes::FLMAT, "FLMAT", FF7ModuleInstruction, 0, "");
-            OPCODE(eSpecialOpcodes::FLITM, "FLITM", FF7ModuleInstruction, 0, "");
-            OPCODE(eSpecialOpcodes::BTLCK, "BTLCK", FF7ModuleInstruction, 0, "B");
-            OPCODE(eSpecialOpcodes::MVLCK, "MVLCK", FF7ModuleInstruction, 0, "B");
-            OPCODE(eSpecialOpcodes::SPCNM, "SPCNM", FF7ModuleInstruction, 0, "BB");
-            OPCODE(eSpecialOpcodes::RSGLB, "RSGLB", FF7ModuleInstruction, 0, "");
-            OPCODE(eSpecialOpcodes::CLITM, "CLITM", FF7ModuleInstruction, 0, "");
-            END_SUBOPCODE
-                OPCODE(eOpcodes::MINIGAME, "MINIGAME", FF7ModuleInstruction, 0, "wsswBB");
-            OPCODE(eOpcodes::BTMD2, "BTMD2", FF7ModuleInstruction, 0, "d");
-            OPCODE(eOpcodes::BTRLD, "BTRLD", FF7ModuleInstruction, 0, "NB");
-            OPCODE(eOpcodes::BTLTB, "BTLTB", FF7ModuleInstruction, 0, "B");
-            OPCODE(eOpcodes::MAPJUMP, "MAPJUMP", FF7ModuleInstruction, 0, "wsswB");
-            OPCODE(eOpcodes::LSTMP, "LSTMP", FF7ModuleInstruction, 0, "NB");
-            OPCODE(eOpcodes::BATTLE, "BATTLE", FF7ModuleInstruction, 0, "Nw");
-            OPCODE(eOpcodes::BTLON, "BTLON", FF7ModuleInstruction, 0, "B");
-            OPCODE(eOpcodes::BTLMD, "BTLMD", FF7ModuleInstruction, 0, "w");
-            OPCODE(eOpcodes::MPJPO, "MPJPO", FF7ModuleInstruction, 0, "B");
-            OPCODE(eOpcodes::PMJMP, "PMJMP", FF7ModuleInstruction, 0, "w");
-            OPCODE(eOpcodes::PMJMP2, "PMJMP2", FF7ModuleInstruction, 0, "");
-            OPCODE(eOpcodes::GAMEOVER, "GAMEOVER", FF7ModuleInstruction, 0, "");
-
-            // Math
-            OPCODE(eOpcodes::PLUS_, "PLUS!", FF7MathInstruction, 0, "NBB");
-            OPCODE(eOpcodes::PLUS2_, "PLUS2!", FF7MathInstruction, 0, "NBw");
-            OPCODE(eOpcodes::MINUS_, "MINUS!", FF7MathInstruction, 0, "NBB");
-            OPCODE(eOpcodes::MINUS2_, "MINUS2!", FF7MathInstruction, 0, "NBw");
-            OPCODE(eOpcodes::INC_, "INC!", FF7MathInstruction, 0, "BB");
-            OPCODE(eOpcodes::INC2_, "INC2!", FF7MathInstruction, 0, "BB");
-            OPCODE(eOpcodes::DEC_, "DEC!", FF7MathInstruction, 0, "BB");
-            OPCODE(eOpcodes::DEC2_, "DEC2!", FF7MathInstruction, 0, "BB");
-            OPCODE(eOpcodes::RDMSD, "RDMSD", FF7MathInstruction, 0, "NB");
-            OPCODE(eOpcodes::SETBYTE, "SETBYTE", FF7MathInstruction, 0, "NBB");
-            OPCODE(eOpcodes::SETWORD, "SETWORD", FF7MathInstruction, 0, "NBw");
-            OPCODE(eOpcodes::BITON, "BITON", FF7MathInstruction, 0, "NBB");
-            OPCODE(eOpcodes::BITOFF, "BITOFF", FF7MathInstruction, 0, "NBB");
-            OPCODE(eOpcodes::BITXOR, "BITXOR", FF7MathInstruction, 0, "NBB");
-            OPCODE(eOpcodes::PLUS, "PLUS", FF7MathInstruction, 0, "NBB");
-            OPCODE(eOpcodes::PLUS2, "PLUS2", FF7MathInstruction, 0, "NBw");
-            OPCODE(eOpcodes::MINUS, "MINUS", FF7MathInstruction, 0, "NBB");
-            OPCODE(eOpcodes::MINUS2, "MINUS2", FF7MathInstruction, 0, "NBw");
-            OPCODE(eOpcodes::MUL, "MUL", FF7MathInstruction, 0, "NBB");
-            OPCODE(eOpcodes::MUL2, "MUL2", FF7MathInstruction, 0, "NBw");
-            OPCODE(eOpcodes::DIV, "DIV", FF7MathInstruction, 0, "NBB");
-            OPCODE(eOpcodes::DIV2, "DIV2", FF7MathInstruction, 0, "NBw");
-            OPCODE(eOpcodes::MOD, "MOD", FF7MathInstruction, 0, "NBB");
-            OPCODE(eOpcodes::MOD2, "MOD2", FF7MathInstruction, 0, "NBw");
-            OPCODE(eOpcodes::AND, "AND", FF7MathInstruction, 0, "NBB");
-            OPCODE(eOpcodes::AND2, "AND2", FF7MathInstruction, 0, "NBw");
-            OPCODE(eOpcodes::OR, "OR", FF7MathInstruction, 0, "NBB");
-            OPCODE(eOpcodes::OR2, "OR2", FF7MathInstruction, 0, "NBw");
-            OPCODE(eOpcodes::XOR, "XOR", FF7MathInstruction, 0, "NBB");
-            OPCODE(eOpcodes::XOR2, "XOR2", FF7MathInstruction, 0, "NBw");
-            OPCODE(eOpcodes::INC, "INC", FF7MathInstruction, 0, "BB");
-            OPCODE(eOpcodes::INC2, "INC2", FF7MathInstruction, 0, "BB");
-            OPCODE(eOpcodes::DEC, "DEC", FF7MathInstruction, 0, "BB");
-            OPCODE(eOpcodes::DEC2, "DEC2", FF7MathInstruction, 0, "BB");
-            OPCODE(eOpcodes::RANDOM, "RANDOM", FF7MathInstruction, 0, "BB");
-            OPCODE(eOpcodes::LBYTE, "LBYTE", FF7MathInstruction, 0, "NBB");
-            OPCODE(eOpcodes::HBYTE, "HBYTE", FF7MathInstruction, 0, "NBw");
-            OPCODE(eOpcodes::TWOBYTE, "2BYTE", FF7MathInstruction, 0, "NNBBB");
-            OPCODE(eOpcodes::SIN, "SIN", FF7MathInstruction, 0, "NNwwwB");
-            OPCODE(eOpcodes::COS, "COS", FF7MathInstruction, 0, "NNwwwB");
-
-            // Window
-            OPCODE(eOpcodes::TUTOR, "TUTOR", FF7WindowInstruction, 0, "B");
-            OPCODE(eOpcodes::WCLS, "WCLS", FF7WindowInstruction, 0, "B");
-            OPCODE(eOpcodes::WSIZW, "WSIZW", FF7WindowInstruction, 0, "Bwwww");
-            OPCODE(eOpcodes::WSPCL, "WSPCL", FF7WindowInstruction, 0, "BBBB");
-            OPCODE(eOpcodes::WNUMB, "WNUMB", FF7WindowInstruction, 0, "NBwwB"); // NBdB when N == 0
-            OPCODE(eOpcodes::STTIM, "STTIM", FF7WindowInstruction, 0, "NNBBB");
-            OPCODE(eOpcodes::MESSAGE, "MESSAGE", FF7WindowInstruction, 0, "BB");
-            OPCODE(eOpcodes::MPARA, "MPARA", FF7WindowInstruction, 0, "NBBB");
-            OPCODE(eOpcodes::MPRA2, "MPRA2", FF7WindowInstruction, 0, "NBBw");
-            OPCODE(eOpcodes::MPNAM, "MPNAM", FF7WindowInstruction, 0, "B");
-            OPCODE(eOpcodes::ASK, "ASK", FF7WindowInstruction, 0, "NBBBBB");
-            OPCODE(eOpcodes::MENU, "MENU", FF7WindowInstruction, 0, "NBB");
-            OPCODE(eOpcodes::MENU2, "MENU2", FF7WindowInstruction, 0, "B");
-            OPCODE(eOpcodes::WINDOW, "WINDOW", FF7WindowInstruction, 0, "Bwwww");
-            OPCODE(eOpcodes::WMOVE, "WMOVE", FF7WindowInstruction, 0, "Bss");
-            OPCODE(eOpcodes::WMODE, "WMODE", FF7WindowInstruction, 0, "BBB");
-            OPCODE(eOpcodes::WREST, "WREST", FF7WindowInstruction, 0, "B");
-            OPCODE(eOpcodes::WCLSE, "WCLSE", FF7WindowInstruction, 0, "B");
-            OPCODE(eOpcodes::WROW, "WROW", FF7WindowInstruction, 0, "BB");
-            OPCODE(eOpcodes::GWCOL, "GWCOL", FF7WindowInstruction, 0, "NNBBBB");
-            OPCODE(eOpcodes::SWCOL, "SWCOL", FF7WindowInstruction, 0, "NNBBBB");
-
-            // Party
-            OPCODE(eOpcodes::SPTYE, "SPTYE", FF7PartyInstruction, 0, "NNBBB");
-            OPCODE(eOpcodes::GTPYE, "GTPYE", FF7PartyInstruction, 0, "NNBBB");
-            OPCODE(eOpcodes::GOLDU, "GOLDU", FF7PartyInstruction, 0, "Nww"); // Nd when N == 0
-            OPCODE(eOpcodes::GOLDD, "GOLDD", FF7PartyInstruction, 0, "Nww"); // Nd when N == 0
-            OPCODE(eOpcodes::CHGLD, "CHGLD", FF7PartyInstruction, 0, "NBB");
-            OPCODE(eOpcodes::HMPMAX1, "HMPMAX1", FF7PartyInstruction, 0, "");
-            OPCODE(eOpcodes::HMPMAX2, "HMPMAX2", FF7PartyInstruction, 0, "");
-            OPCODE(eOpcodes::MHMMX, "MHMMX", FF7PartyInstruction, 0, "");
-            OPCODE(eOpcodes::HMPMAX3, "HMPMAX3", FF7PartyInstruction, 0, "");
-            OPCODE(eOpcodes::MPU, "MPU", FF7PartyInstruction, 0, "NBw");
-            OPCODE(eOpcodes::MPD, "MPD", FF7PartyInstruction, 0, "NBw");
-            OPCODE(eOpcodes::HPU, "HPU", FF7PartyInstruction, 0, "NBw");
-            OPCODE(eOpcodes::HPD, "HPD", FF7PartyInstruction, 0, "NBw");
-            OPCODE(eOpcodes::STITM, "STITM", FF7PartyInstruction, 0, "NwB");
-            OPCODE(eOpcodes::DLITM, "DLITM", FF7PartyInstruction, 0, "NwB");
-            OPCODE(eOpcodes::CKITM, "CKITM", FF7PartyInstruction, 0, "NwB");
-            OPCODE(eOpcodes::SMTRA, "SMTRA", FF7PartyInstruction, 0, "NNBBBB");
-            OPCODE(eOpcodes::DMTRA, "DMTRA", FF7PartyInstruction, 0, "NNBBBBB");
-            OPCODE(eOpcodes::CMTRA, "CMTRA", FF7PartyInstruction, 0, "NNNBBBBBB");
-            OPCODE(eOpcodes::GETPC, "GETPC", FF7PartyInstruction, 0, "NBB");
-            OPCODE(eOpcodes::PRTYP, "PRTYP", FF7PartyInstruction, 0, "B");
-            OPCODE(eOpcodes::PRTYM, "PRTYM", FF7PartyInstruction, 0, "B");
-            OPCODE(eOpcodes::PRTYE, "PRTYE", FF7PartyInstruction, 0, "BBB");
-            OPCODE(eOpcodes::MMBUD, "MMBUD", FF7PartyInstruction, 0, "BB");
-            OPCODE(eOpcodes::MMBLK, "MMBLK", FF7PartyInstruction, 0, "B");
-            OPCODE(eOpcodes::MMBUK, "MMBUK", FF7PartyInstruction, 0, "B");
-
-            // Model
-            OPCODE(eOpcodes::JOIN, "JOIN", FF7ModelInstruction, 0, "B");
-            OPCODE(eOpcodes::SPLIT, "SPLIT", FF7ModelInstruction, 0, "NNNssBssBB");
-            OPCODE(eOpcodes::BLINK, "BLINK", FF7ModelInstruction, 0, "B");
-            OPCODE_BASE(eOpcodes::KAWAI)
-            {
-                int length = this->mStream->ReadU8();
-                assert(length >= 3);
-                std::ostringstream paramStream;
-                for (int i = 3; i < length; ++i)
-                {
-                    paramStream << "B";
-                }
-                auto parameters = paramStream.str();
-
-                opcode = this->mStream->ReadU8();
-                switch (opcode)
-                {
-                    OPCODE(
-                      eKawaiOpcodes::EYETX, "EYETX", FF7ModelInstruction, 0, parameters.c_str()
-                    ); // was BBBB
-                    OPCODE(
-                      eKawaiOpcodes::TRNSP, "TRNSP", FF7ModelInstruction, 0, parameters.c_str()
-                    ); // was B
-                    OPCODE(
-                      eKawaiOpcodes::AMBNT, "AMBNT", FF7ModelInstruction, 0, parameters.c_str()
-                    ); // was BBBBBBB
-                    OPCODE(
-                      eKawaiOpcodes::Unknown03, "Unknown03",
-                      FF7ModelInstruction, 0, parameters.c_str()
-                    );
-                    OPCODE(
-                      eKawaiOpcodes::Unknown04, "Unknown04",
-                      FF7ModelInstruction, 0, parameters.c_str()
-                    );
-                    OPCODE(
-                      eKawaiOpcodes::Unknown05, "Unknown05",
-                      FF7ModelInstruction, 0, parameters.c_str()
-                    );
-                    OPCODE(
-                      eKawaiOpcodes::LIGHT, "LIGHT",FF7ModelInstruction, 0, parameters.c_str()
-                    );
-                    OPCODE(
-                      eKawaiOpcodes::Unknown07, "Unknown07",
-                      FF7ModelInstruction, 0, parameters.c_str()
-                    );
-                    OPCODE(
-                      eKawaiOpcodes::Unknown08, "Unknown08",
-                      FF7ModelInstruction, 0, parameters.c_str()
-                    );
-                    OPCODE(
-                      eKawaiOpcodes::Unknown09, "Unknown09",
-                      FF7ModelInstruction, 0, parameters.c_str()
-                    );
-                    OPCODE(
-                      eKawaiOpcodes::SBOBJ, "SBOBJ",
-                      FF7ModelInstruction, 0, parameters.c_str()
-                    );
-                    OPCODE(
-                      eKawaiOpcodes::Unknown0B, "Unknown0B",
-                      FF7ModelInstruction, 0, parameters.c_str()
-                    );
-                    OPCODE(
-                      eKawaiOpcodes::Unknown0C, "Unknown0C",
-                      FF7ModelInstruction, 0, parameters.c_str()
-                    );
-                    OPCODE(
-                      eKawaiOpcodes::SHINE, "SHINE", FF7ModelInstruction, 0, parameters.c_str()
-                    );
-                    OPCODE(
-                      eKawaiOpcodes::RESET, "RESET", FF7ModelInstruction, 0, parameters.c_str()
-                    );
-                default:
-                    throw UnknownSubOpcodeException(this->_address, opcode);
-                }
-                INC_ADDR;
-                INC_ADDR;
-            }
-            OPCODE_END
-                OPCODE(eOpcodes::KAWIW, "KAWIW", FF7ModelInstruction, 0, "");
-            OPCODE(eOpcodes::PMOVA, "PMOVA", FF7ModelInstruction, 0, "B");
-            OPCODE(eOpcodes::PDIRA, "PDIRA", FF7ModelInstruction, 0, "B");
-            OPCODE(eOpcodes::PTURA, "PTURA", FF7ModelInstruction, 0, "BBB");
-            OPCODE(eOpcodes::PGTDR, "PGTDR", FF7ModelInstruction, 0, "NBB");
-            OPCODE(eOpcodes::PXYZI, "PXYZI", FF7ModelInstruction, 0, "NNBBBBB");
-            OPCODE(eOpcodes::TLKON, "TLKON", FF7ModelInstruction, 0, "B");
-            OPCODE(eOpcodes::PC, "PC", FF7ModelInstruction, 0, "B");
-            OPCODE(eOpcodes::opCodeCHAR, "CHAR", FF7ModelInstruction, 0, "B");
-            OPCODE(eOpcodes::DFANM, "DFANM", FF7ModelInstruction, 0, "BB");
-            OPCODE(eOpcodes::ANIME1, "ANIME1", FF7ModelInstruction, 0, "BB");
-            OPCODE(eOpcodes::VISI, "VISI", FF7ModelInstruction, 0, "B");
-            OPCODE(eOpcodes::XYZI, "XYZI", FF7ModelInstruction, 0, "NNsssw");
-            OPCODE(eOpcodes::XYI, "XYI", FF7ModelInstruction, 0, "NNssw");
-            OPCODE(eOpcodes::XYZ, "XYZ", FF7ModelInstruction, 0, "NNsss");
-            OPCODE(eOpcodes::MOVE, "MOVE", FF7ModelInstruction, 0, "Nss");
-            OPCODE(eOpcodes::CMOVE, "CMOVE", FF7ModelInstruction, 0, "Nss");
-            OPCODE(eOpcodes::MOVA, "MOVA", FF7ModelInstruction, 0, "B");
-            OPCODE(eOpcodes::TURA, "TURA", FF7ModelInstruction, 0, "BBB");
-            OPCODE(eOpcodes::ANIMW, "ANIMW", FF7ModelInstruction, 0, "");
-            OPCODE(eOpcodes::FMOVE, "FMOVE", FF7ModelInstruction, 0, "Nss");
-            OPCODE(eOpcodes::ANIME2, "ANIME2", FF7ModelInstruction, 0, "BB");
-            OPCODE(eOpcodes::ANIM_1, "ANIM!1", FF7ModelInstruction, 0, "BB");
-            OPCODE(eOpcodes::CANIM1, "CANIM1", FF7ModelInstruction, 0, "BBBB");
-            OPCODE(eOpcodes::CANM_1, "CANM!1", FF7ModelInstruction, 0, "BBBB");
-            OPCODE(eOpcodes::MSPED, "MSPED", FF7ModelInstruction, 0, "Nw");
-            OPCODE(eOpcodes::DIR, "DIR", FF7ModelInstruction, 0, "BB");
-            OPCODE(eOpcodes::TURNGEN, "TURNGEN", FF7ModelInstruction, 0, "NBBBB");
-            OPCODE(eOpcodes::TURN, "TURN", FF7ModelInstruction, 0, "NBBBB");
-            OPCODE(eOpcodes::DIRA, "DIRA", FF7ModelInstruction, 0, "B");
-            OPCODE(eOpcodes::GETDIR, "GETDIR", FF7ModelInstruction, 0, "NBB");
-            OPCODE(eOpcodes::GETAXY, "GETAXY", FF7ModelInstruction, 0, "NBBB");
-            OPCODE(eOpcodes::GETAI, "GETAI", FF7ModelInstruction, 0, "NBB");
-            OPCODE(eOpcodes::ANIM_2, "ANIM!2", FF7ModelInstruction, 0, "BB");
-            OPCODE(eOpcodes::CANIM2, "CANIM2", FF7ModelInstruction, 0, "BBBB");
-            OPCODE(eOpcodes::CANM_2, "CANM!2", FF7ModelInstruction, 0, "BBBB");
-            OPCODE(eOpcodes::ASPED, "ASPED", FF7ModelInstruction, 0, "Nw");
-            OPCODE(eOpcodes::CC, "CC", FF7ModelInstruction, 0, "B");
-            OPCODE(eOpcodes::JUMP, "JUMP", FF7ModelInstruction, 0, "NNssww");
-            OPCODE(eOpcodes::AXYZI, "AXYZI", FF7ModelInstruction, 0, "NNBBBBB");
-            OPCODE(eOpcodes::LADER, "LADER", FF7ModelInstruction, 0, "NNssswBBBB");
-            OPCODE(eOpcodes::OFST, "OFST", FF7ModelInstruction, 0, "NNBsssw");
-            OPCODE(eOpcodes::OFSTW, "OFSTW", FF7ModelInstruction, 0, "");
-            OPCODE(eOpcodes::TALKR, "TALKR", FF7ModelInstruction, 0, "NB");
-            OPCODE(eOpcodes::SLIDR, "SLIDR", FF7ModelInstruction, 0, "NB");
-            OPCODE(eOpcodes::SOLID, "SOLID", FF7ModelInstruction, 0, "B");
-            OPCODE(eOpcodes::TLKR2, "TLKR2", FF7ModelInstruction, 0, "Nw");
-            OPCODE(eOpcodes::SLDR2, "SLDR2", FF7ModelInstruction, 0, "Nw");
-            OPCODE(eOpcodes::CCANM, "CCANM", FF7ModelInstruction, 0, "BBB");
-            OPCODE(eOpcodes::FCFIX, "FCFIX", FF7ModelInstruction, 0, "B");
-            OPCODE(eOpcodes::ANIMB, "ANIMB", FF7ModelInstruction, 0, "");
-            OPCODE(eOpcodes::TURNW, "TURNW", FF7ModelInstruction, 0, "");
-
-            // Walkmesh
-            OPCODE(eOpcodes::SLIP, "SLIP", FF7WalkmeshInstruction, 0, "B");
-            OPCODE(eOpcodes::UC, "UC", FF7WalkmeshInstruction, 0, "B");
-            OPCODE(eOpcodes::IDLCK, "IDLCK", FF7WalkmeshInstruction, 0, "wB");
-            OPCODE(eOpcodes::LINON, "LINON", FF7WalkmeshInstruction, 0, "B");
-            OPCODE(eOpcodes::SLINE, "SLINE", FF7WalkmeshInstruction, 0, "NNNssssss");
-            //OPCODE(eOpcodes::LINE, "LINE", FF7WalkmeshInstruction, 0, "ssssss");
-            // LINE is done like this to save opcode params to the function out params.
-            case eOpcodes::LINE:
-                is_line = true;
-                full_opcode = (full_opcode << 8) + eOpcodes::LINE;
-                this->_insts.push_back(new FF7WalkmeshInstruction());
-                (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();
-                break;
-
-            // Backgnd
-            OPCODE(eOpcodes::BGPDH, "BGPDH", FF7BackgroundInstruction, 0, "NBs");
-            OPCODE(eOpcodes::BGSCR, "BGSCR", FF7BackgroundInstruction, 0, "NBss");
-            OPCODE(eOpcodes::MPPAL, "MPPAL", FF7BackgroundInstruction, 0, "NNNBBBBBBB");
-            OPCODE(eOpcodes::BGON, "BGON", FF7BackgroundInstruction, 0, "NBB");
-            OPCODE(eOpcodes::BGOFF, "BGOFF", FF7BackgroundInstruction, 0, "NBB");
-            OPCODE(eOpcodes::BGROL, "BGROL", FF7BackgroundInstruction, 0, "NB");
-            OPCODE(eOpcodes::BGROL2, "BGROL2", FF7BackgroundInstruction, 0, "NB");
-            OPCODE(eOpcodes::BGCLR, "BGCLR", FF7BackgroundInstruction, 0, "NB");
-            OPCODE(eOpcodes::STPAL, "STPAL", FF7BackgroundInstruction, 0, "NBBB");
-            OPCODE(eOpcodes::LDPAL, "LDPAL", FF7BackgroundInstruction, 0, "NBBB");
-            OPCODE(eOpcodes::CPPAL, "CPPAL", FF7BackgroundInstruction, 0, "NBBB");
-            OPCODE(eOpcodes::RTPAL, "RTPAL", FF7BackgroundInstruction, 0, "NNBBBB");
-            OPCODE(eOpcodes::ADPAL, "ADPAL", FF7BackgroundInstruction, 0, "NNNBBBBBB");
-            OPCODE(eOpcodes::MPPAL2, "MPPAL2", FF7BackgroundInstruction, 0, "NNNBBBBBB");
-            OPCODE(eOpcodes::STPLS, "STPLS", FF7BackgroundInstruction, 0, "BBBB");
-            OPCODE(eOpcodes::LDPLS, "LDPLS", FF7BackgroundInstruction, 0, "BBBB");
-            OPCODE(eOpcodes::CPPAL2, "CPPAL2", FF7BackgroundInstruction, 0, "BBBBBBB");
-            OPCODE(eOpcodes::RTPAL2, "RTPAL2", FF7BackgroundInstruction, 0, "BBBBBBB");
-            OPCODE(eOpcodes::ADPAL2, "ADPAL2", FF7BackgroundInstruction, 0, "BBBBBBBBBB");
-
-            // Camera
-            OPCODE(eOpcodes::NFADE, "NFADE", FF7CameraInstruction, 0, "NNBBBBBB");
-            OPCODE(eOpcodes::SHAKE, "SHAKE", FF7CameraInstruction, 0, "BBBBBBB");
-            OPCODE(eOpcodes::SCRLO, "SCRLO", FF7CameraInstruction, 0, "B");
-            OPCODE(eOpcodes::SCRLC, "SCRLC", FF7CameraInstruction, 0, "BBBB");
-            OPCODE(eOpcodes::SCRLA, "SCRLA", FF7CameraInstruction, 0, "NwBB");
-            OPCODE(eOpcodes::SCR2D, "SCR2D", FF7CameraInstruction, 0, "Nss");
-            OPCODE(eOpcodes::SCRCC, "SCRCC", FF7CameraInstruction, 0, "");
-            OPCODE(eOpcodes::SCR2DC, "SCR2DC", FF7CameraInstruction, 0, "NNssw");
-            OPCODE(eOpcodes::SCRLW, "SCRLW", FF7CameraInstruction, 0, "");
-            OPCODE(eOpcodes::SCR2DL, "SCR2DL", FF7CameraInstruction, 0, "NNssw");
-            OPCODE(eOpcodes::VWOFT, "VWOFT", FF7CameraInstruction, 0, "NssB");
-            OPCODE(eOpcodes::FADE, "FADE", FF7CameraInstruction, 0, "NNBBBBBB");
-            OPCODE(eOpcodes::FADEW, "FADEW", FF7CameraInstruction, 0, "");
-            OPCODE(eOpcodes::SCRLP, "SCRLP", FF7CameraInstruction, 0, "NwBB");
-            OPCODE(eOpcodes::MVCAM, "MVCAM", FF7CameraInstruction, 0, "B");
-
-            // AV
-            OPCODE(eOpcodes::BGMOVIE, "BGMOVIE", FF7AudioVideoInstruction, 0, "B");
-            OPCODE(eOpcodes::AKAO2, "AKAO2", FF7AudioVideoInstruction, 0, "NNNBwwwww");
-            OPCODE(eOpcodes::MUSIC, "MUSIC", FF7AudioVideoInstruction, 0, "B");
-            OPCODE(eOpcodes::SOUND, "SOUND", FF7AudioVideoInstruction, 0, "NwB");
-            OPCODE(eOpcodes::AKAO, "AKAO", FF7AudioVideoInstruction, 0, "NNNBBwwww");
-            OPCODE(eOpcodes::MUSVT, "MUSVT", FF7AudioVideoInstruction, 0, "B");
-            OPCODE(eOpcodes::MUSVM, "MUSVM", FF7AudioVideoInstruction, 0, "B");
-            OPCODE(eOpcodes::MULCK, "MULCK", FF7AudioVideoInstruction, 0, "B");
-            OPCODE(eOpcodes::BMUSC, "BMUSC", FF7AudioVideoInstruction, 0, "B");
-            OPCODE(eOpcodes::CHMPH, "CHMPH", FF7AudioVideoInstruction, 0, "BBB");
-            OPCODE(eOpcodes::PMVIE, "PMVIE", FF7AudioVideoInstruction, 0, "B");
-            OPCODE(eOpcodes::MOVIE, "MOVIE", FF7AudioVideoInstruction, 0, "");
-            OPCODE(eOpcodes::MVIEF, "MVIEF", FF7AudioVideoInstruction, 0, "NB");
-            OPCODE(eOpcodes::FMUSC, "FMUSC", FF7AudioVideoInstruction, 0, "B");
-            OPCODE(eOpcodes::CMUSC, "CMUSC", FF7AudioVideoInstruction, 0, "BBBBBBB");
-            OPCODE(eOpcodes::CHMST, "CHMST", FF7AudioVideoInstruction, 0, "NB");
-
-            // Uncat
-            OPCODE(eOpcodes::MPDSP, "MPDSP", FF7UncategorizedInstruction, 0, "B");
-            OPCODE(eOpcodes::SETX, "SETX", FF7UncategorizedInstruction, 0, "BBBBBB");
-            OPCODE(eOpcodes::GETX, "GETX", FF7UncategorizedInstruction, 0, "BBBBBB");
-            OPCODE(eOpcodes::SEARCHX, "SEARCHX", FF7UncategorizedInstruction, 0, "BBBBBBBBBB");
-
-            default:
-                throw UnknownOpcodeException(this->_address, opcode);
-        }
-        INC_ADDR;
-
-        // Is it within an "if" statement tracking?
-        InstPtr i = this->_insts.back();
-        if (i->isCondJump()) exitAddrs.push_back(i->getDestAddress());
-        if (!exitAddrs.empty())
-            if (i->_address == exitAddrs.back()) exitAddrs.pop_back();
-
-        // Only bail if its the first RET that isn't within an "if" block.
-        if (full_opcode == eOpcodes::RET && exitAddrs.empty()) return is_line;
-    }
-    return is_line;
-}

文件差異過大導致無法顯示
+ 553 - 555
V-Gears-Installer/src/decompiler/field/ff7_field_engine.cpp


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

@@ -113,7 +113,7 @@ void DupStackInstruction::processInst(Function&, ValueStack &stack, Engine*, Cod
 	std::stringstream s;
 	ValuePtr p = stack.pop()->dup(s);
 	if (s.str().length() > 0)
-		codeGen->addOutputLine(s.str());
+		codeGen->AddOutputLine(s.str());
 	stack.push(p);
 	stack.push(p);
 }
@@ -125,9 +125,9 @@ void BoolNegateStackInstruction::processInst(Function&, ValueStack &stack, Engin
 void BinaryOpStackInstruction::processInst(Function&, ValueStack &stack, Engine*, CodeGenerator *codeGen) {
 	ValuePtr op1 = stack.pop();
 	ValuePtr op2 = stack.pop();
-	if (codeGen->_binOrder == kFIFOArgOrder)
+	if (codeGen->_binOrder == FIFO_ARGUMENT_ORDER)
 		stack.push(new BinaryOpValue(op2, op1, _codeGenData));
-	else if (codeGen->_binOrder == kLIFOArgOrder)
+	else if (codeGen->_binOrder == LIFO_ARGUMENT_ORDER)
 		stack.push(new BinaryOpValue(op1, op2, _codeGenData));
 }
 
@@ -136,7 +136,7 @@ bool ReturnInstruction::isReturn() const {
 }
 
 void ReturnInstruction::processInst(Function&, ValueStack&, Engine*, CodeGenerator *codeGen) {
-	codeGen->addOutputLine("return;");
+	codeGen->AddOutputLine("return;");
 }
 
 void UnaryOpPrefixStackInstruction::processInst(Function&, ValueStack &stack, Engine*, CodeGenerator*) {
@@ -157,7 +157,7 @@ void KernelCallStackInstruction::processInst(Function&, ValueStack &stack, Engin
 	if (!returnsValue) {
 		std::stringstream stream;
 		stream << stack.pop() << ";";
-		codeGen->addOutputLine(stream.str());
+		codeGen->AddOutputLine(stream.str());
 	}
 }
 

+ 0 - 274
V-Gears-Installer/src/decompiler/scummv6/codegen.cpp

@@ -1,274 +0,0 @@
-/* ScummVM Tools
- *
- * ScummVM Tools is the legal property of its developers, whose
- * names are too numerous to list here. Please refer to the
- * COPYRIGHT file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#include "decompiler/scummv6/codegen.h"
-
-std::ostream &Scumm::v6::ListValue::print(std::ostream &output) const {
-	output << "[";
-	for (ValueList::const_iterator i = _items.begin(); i != _items.end(); ++i) {
-		if (i != _items.begin())
-			output << ", ";
-		output << *i;
-	}
-	output << "]";
-	return output;
-}
-
-ValuePtr Scumm::v6::Scummv6CodeGenerator::createListValue() {
-	ValueList list;
-	ValuePtr countValue = _stack.pop();
-	std::stringstream s;
-	s << countValue;
-	int count = atoi(s.str().c_str());
-	for (int i = 0; i < count; i++) {
-		list.push_front(_stack.pop());
-	}
-	return new ListValue(list);
-}
-
-const char *var_names[] = {
-	/* 0 */
-	NULL,
-	"VAR_EGO",
-	"VAR_CAMERA_POS_X",
-	"VAR_HAVE_MSG",
-	/* 4 */
-	"VAR_ROOM",
-	"VAR_OVERRIDE",
-	"VAR_MACHINE_SPEED",
-	NULL,
-	/* 8 */
-	"VAR_NUM_ACTOR",
-	"VAR_V6_SOUNDMODE",
-	"VAR_CURRENTDRIVE",
-	"VAR_TMR_1",
-	/* 12 */
-	"VAR_TMR_2",
-	"VAR_TMR_3",
-	NULL,
-	NULL,
-	/* 16 */
-	NULL,
-	"VAR_CAMERA_MIN_X",
-	"VAR_CAMERA_MAX_X",
-	"VAR_TIMER_NEXT",
-	/* 20 */
-	"VAR_VIRT_MOUSE_X",
-	"VAR_VIRT_MOUSE_Y",
-	"VAR_ROOM_RESOURCE",
-	"VAR_LAST_SOUND",
-	/* 24 */
-	"VAR_CUTSCENEEXIT_KEY",
-	"VAR_TALK_ACTOR",
-	"VAR_CAMERA_FAST_X",
-	"VAR_SCROLL_SCRIPT",
-	/* 28 */
-	"VAR_ENTRY_SCRIPT",
-	"VAR_ENTRY_SCRIPT2",
-	"VAR_EXIT_SCRIPT",
-	"VAR_EXIT_SCRIPT2",
-	/* 32 */
-	"VAR_VERB_SCRIPT",
-	"VAR_SENTENCE_SCRIPT",
-	"VAR_INVENTORY_SCRIPT",
-	"VAR_CUTSCENE_START_SCRIPT",
-	/* 36 */
-	"VAR_CUTSCENE_END_SCRIPT",
-	"VAR_CHARINC",
-	"VAR_WALKTO_OBJ",
-	"VAR_DEBUGMODE",
-	/* 40 */
-	"VAR_HEAPSPACE",
-	"VAR_ROOM_WIDTH",
-	"VAR_RESTART_KEY",
-	"VAR_PAUSE_KEY",
-	/* 44 */
-	"VAR_MOUSE_X",
-	"VAR_MOUSE_Y",
-	"VAR_TIMER",
-	"VAR_TMR_4",
-	/* 48 */
-	NULL,
-	"VAR_VIDEOMODE",
-	"VAR_MAINMENU_KEY",
-	"VAR_FIXEDDISK",
-	/* 52 */
-	"VAR_CURSORSTATE",
-	"VAR_USERPUT",
-	"VAR_ROOM_HEIGHT",
-	NULL,
-	/* 56 */
-	"VAR_SOUNDRESULT",
-	"VAR_TALKSTOP_KEY",
-	NULL,
-	"VAR_FADE_DELAY",
-	/* 60 */
-	"VAR_NOSUBTITLES",
-	"VAR_SAVELOAD_SCRIPT",
-	"VAR_SAVELOAD_SCRIPT2",
-	NULL,
-	/* 64 */
-	"VAR_SOUNDPARAM",
-	"VAR_SOUNDPARAM2",
-	"VAR_SOUNDPARAM3",
-	"VAR_INPUTMODE",
-	/* 68 */
-	"VAR_MEMORY_PERFORMANCE",
-	"VAR_VIDEO_PERFORMANCE",
-	"VAR_ROOM_FLAG",
-	"VAR_GAME_LOADED",
-	/* 72 */
-	"VAR_NEW_ROOM",
-	NULL,
-	"VAR_LEFTBTN_DOWN",
-	"VAR_RIGHTBTN_DOWN",
-	/* 76 */
-	"VAR_V6_EMSSPACE",
-	NULL,
-	NULL,
-	NULL,
-	/* 80 */
-	NULL,
-	NULL,
-	NULL,
-	NULL,
-	/* 84 */
-	NULL,
-	NULL,
-	NULL,
-	NULL,
-	/* 88 */
-	NULL,
-	NULL,
-	"VAR_GAME_DISK_MSG",
-	"VAR_OPEN_FAILED_MSG",
-	/* 92 */
-	"VAR_READ_ERROR_MSG",
-	"VAR_PAUSE_MSG",
-	"VAR_RESTART_MSG",
-	"VAR_QUIT_MSG",
-	/* 96 */
-	"VAR_SAVE_BTN",
-	"VAR_LOAD_BTN",
-	"VAR_PLAY_BTN",
-	"VAR_CANCEL_BTN",
-	/* 100 */
-	"VAR_QUIT_BTN",
-	"VAR_OK_BTN",
-	"VAR_SAVE_DISK_MSG",
-	"VAR_ENTER_NAME_MSG",
-	/* 104 */
-	"VAR_NOT_SAVED_MSG",
-	"VAR_NOT_LOADED_MSG",
-	"VAR_SAVE_MSG",
-	"VAR_LOAD_MSG",
-	/* 108 */
-	"VAR_SAVE_MENU_TITLE",
-	"VAR_LOAD_MENU_TITLE",
-	"VAR_GUI_COLORS",
-	"VAR_DEBUG_PASSWORD",
-	/* 112 */
-	NULL,
-	NULL,
-	NULL,
-	NULL,
-	/* 116 */
-	NULL,
-	"VAR_MAIN_MENU_TITLE",
-	"VAR_RANDOM_NR",
-	"VAR_TIMEDATE_YEAR",
-	/* 120 */
-	NULL,
-	"VAR_GAME_VERSION",
-	NULL,
-	"VAR_CHARSET_MASK",
-	/* 124 */
-	NULL,
-	"VAR_TIMEDATE_HOUR",
-	"VAR_TIMEDATE_MINUTE",
-	NULL,
-	/* 128 */
-	"VAR_TIMEDATE_DAY",
-	"VAR_TIMEDATE_MONTH",
-	NULL,
-	NULL,
-};
-
-const char *Scumm::v6::Scummv6CodeGenerator::getVarName(uint16 varID) {
-	if (varID >= sizeof(var_names) / sizeof(var_names[0]))
-		return NULL;
-	return var_names[varID];
-}
-
-std::string Scumm::v6::Scummv6CodeGenerator::decodeVarName(uint16 varID) {
-	std::stringstream s;
-	if (!(varID & 0xF000)) {
-		uint16 var = varID & 0xFFF;
-		const char* varName = getVarName(var);
-		if (varName	 != NULL)
-			return varName;
-		else
-			s << boost::format("var%d") % (varID & 0xFFF);
-	} else if (varID & 0x8000) {
-		s << boost::format("bitvar%d") % (varID & 0x7FFF);
-	} else if (varID & 0x4000) {
-		s << boost::format("localvar%d") % (varID & 0xFFF);
-	} else {
-		s << boost::format("?var?%d") % varID;
-	}
-	return s.str();
-}
-
-std::string Scumm::v6::Scummv6CodeGenerator::decodeArrayName(uint16 arrID) {
-	std::stringstream s;
-	const char *varName;
-	if (!(arrID & 0xF000) && (varName = getVarName(arrID & 0xFFF)) != NULL)
-		return varName;
-	s << boost::format("array%d") % arrID;
-	return s.str();
-}
-
-void Scumm::v6::Scummv6CodeGenerator::processSpecialMetadata(const InstPtr inst, char c, int pos) {
-	switch (c) {
-	// All of these meanings are taken from descumm.
-	case 'l':
-		addArg(createListValue());
-		break;
-	// No SCUMMv6 opcodes using these types have more than one parameter, so it's safe to assume it's the first parameter we want.
-	case 'w':
-	case 'j':
-	case 'i':
-		addArg(inst->_params[0]);
-	case 'v':
-		addArg(new VarValue(decodeVarName(static_cast<uint16>(inst->_params[0]->getUnsigned()))));
-		break;
-	case 's':
-		addArg(inst->_params[0]);
-		break;
-	case 'z':
-		addArg(_stack.pop());
-		addArg(_stack.pop());
-		break;
-	default:
-		CodeGenerator::processSpecialMetadata(inst, c, pos);
-		break;
-	}
-}

+ 0 - 542
V-Gears-Installer/src/decompiler/scummv6/disassembler.cpp

@@ -1,542 +0,0 @@
-/* ScummVM Tools
- *
- * ScummVM Tools is the legal property of its developers, whose
- * names are too numerous to list here. Please refer to the
- * COPYRIGHT file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#include <iostream>
-#include <sstream>
-
-#include <boost/format.hpp>
-
-#include "decompiler/scummv6/disassembler.h"
-
-Scumm::v6::Scummv6Disassembler::Scummv6Disassembler(InstVec &insts) : SimpleDisassembler(insts) {
-}
-
-void Scumm::v6::Scummv6Disassembler::doDisassemble(){
-	std::string blockName;
-	for (int i = 0; i < 4; i++) {
-		blockName += mStream->ReadS8();
-	}
-	if (blockName == "SCRP") {
-		//std::clog << "Input is global script\n";
-		mStream->Seek(8);
-	} else if (blockName == "LSCR") {
-		//std::clog << "Input is local script\n";
-		mStream->Seek(9);
-	} else if (blockName == "ENCD") {
-		//std::clog << "Input is room entry script\n";
-		mStream->Seek(8);
-	} else if (blockName == "EXCD") {
-		//std::clog << "Input is room exit script\n";
-		mStream->Seek(8);
-	} else if (blockName == "VERB") {
-		//std::clog << "Input is object script\n";
-		mStream->Seek(8);
-		//std::clog << "Offset table:\n";
-        uint32 verb = mStream->ReadU8();
-		while (verb != 0) {
-			/*std::clog << boost::format("%02x - %04x\n") % verb %*/ mStream->ReadU16();
-			verb = mStream->ReadU8();
-		}
-	} else {
-		std::stringstream s;
-		s << "Unknown block name " << blockName;
-		throw std::runtime_error(s.str());
-	}
-
-	START_OPCODES;
-		OPCODE(0x00, "pushByte", Scummv6LoadInstruction, 1, "B");
-		OPCODE(0x01, "pushWord", Scummv6LoadInstruction, 1, "s");
-		OPCODE(0x02, "pushByteVar", Scummv6LoadInstruction, 1, "B");
-		OPCODE(0x03, "pushWordVar", Scummv6LoadInstruction, 1, "w");
-		OPCODE(0x06, "byteArrayRead", Scummv6LoadInstruction, 0, "B");
-		OPCODE(0x07, "wordArrayRead", Scummv6LoadInstruction, 0, "w");
-		OPCODE(0x0A, "byteArrayIndexedRead", Scummv6LoadInstruction, -1, "B");
-		OPCODE(0x0B, "wordArrayIndexedRead", Scummv6LoadInstruction, -1, "w");
-		OPCODE(0x0C, "dup", DupStackInstruction, 1, "");
-		OPCODE(0x0D, "not", BoolNegateStackInstruction, 0, "");
-		OPCODE_MD(0x0E, "eq", BinaryOpStackInstruction, -1, "", "==");
-		OPCODE_MD(0x0F, "neq", BinaryOpStackInstruction, -1, "", "!=");
-		OPCODE_MD(0x10, "gt", BinaryOpStackInstruction, -1, "", ">");
-		OPCODE_MD(0x11, "lt", BinaryOpStackInstruction, -1, "", "<");
-		OPCODE_MD(0x12, "le", BinaryOpStackInstruction, -1, "", "<=");
-		OPCODE_MD(0x13, "ge", BinaryOpStackInstruction, -1, "", ">=");
-		OPCODE_MD(0x14, "add", BinaryOpStackInstruction, -1, "", "+");
-		OPCODE_MD(0x15, "sub", BinaryOpStackInstruction, -1, "", "-");
-		OPCODE_MD(0x16, "mul", BinaryOpStackInstruction, -1, "", "*");
-		OPCODE_MD(0x17, "div", BinaryOpStackInstruction, -1, "", "/");
-		OPCODE_MD(0x18, "land", BinaryOpStackInstruction, -1, "", "&&");
-		OPCODE_MD(0x19, "lor", BinaryOpStackInstruction, -1, "", "||");
-		OPCODE(0x1A, "pop", Scummv6StackInstruction, -1, "");
-		OPCODE(0x42, "writeByteVar", Scummv6StoreInstruction, -1, "B");
-		OPCODE(0x43, "writeWordVar", Scummv6StoreInstruction, -1, "w");
-		OPCODE(0x46, "byteArrayWrite", Scummv6StoreInstruction, -2, "B");
-		OPCODE(0x47, "wordArrayWrite", Scummv6StoreInstruction, -2, "w");
-		OPCODE(0x4A, "byteArrayIndexedWrite", Scummv6StoreInstruction, -3, "B");
-		OPCODE(0x4B, "wordArrayIndexedWrite", Scummv6StoreInstruction, -3, "w");
-		OPCODE_MD(0x4E, "byteVarInc", Scummv6IncDecInstruction, 0, "B", "++");
-		OPCODE_MD(0x4F, "wordVarInc", Scummv6IncDecInstruction, 0, "w", "++");
-		OPCODE_MD(0x52, "byteArrayInc", Scummv6IncDecInstruction, -1, "B", "++");
-		OPCODE_MD(0x53, "wordArrayInc", Scummv6IncDecInstruction, -1, "w", "++");
-		OPCODE_MD(0x56, "byteVarDec", Scummv6IncDecInstruction, 0, "B", "--");
-		OPCODE_MD(0x57, "wordVarDec", Scummv6IncDecInstruction, 0, "w", "--");
-		OPCODE_MD(0x5A, "byteArrayDec", Scummv6IncDecInstruction, -1, "B", "--");
-		OPCODE_MD(0x5B, "wordArrayDec", Scummv6IncDecInstruction, -1, "w", "--");
-		OPCODE(0x5C, "jumpTrue", Scummv6CondJumpInstruction, -1, "a");
-		OPCODE(0x5D, "jumpFalse", Scummv6CondJumpInstruction, -1, "a");
-		OPCODE_MD(0x5E, "startScript", KernelCallStackInstruction, 0x1020, "", "lpp"); // Variable stack arguments
-		OPCODE_MD(0x5F, "startScriptQuick", KernelCallStackInstruction, 0x1010, "", "lp"); // Variable stack arguments
-		OPCODE_MD(0x60, "startObject", KernelCallStackInstruction, 0x1030, "", "lppp"); // Variable stack arguments
-		OPCODE_MD(0x61, "drawObject", KernelCallStackInstruction, -2, "", "pp");
-		OPCODE_MD(0x62, "drawObjectAt", KernelCallStackInstruction, -3, "", "ppp");
-		OPCODE_MD(0x63, "drawBlastObject", KernelCallStackInstruction, -5, "", "ppppp");
-		OPCODE_MD(0x64, "setBlastObjectWindow", KernelCallStackInstruction, -4, "", "pppp");
-		OPCODE(0x65, "stopObjectCodeA", KernelCallStackInstruction, 0, "");
-		OPCODE(0x66, "stopObjectCodeB", KernelCallStackInstruction, 0, "");
-		OPCODE(0x67, "endCutscene", KernelCallStackInstruction, 0, "");
-		OPCODE_MD(0x68, "beginCutscene", KernelCallStackInstruction, 0x1000, "", "l"); // Variable stack arguments
-		OPCODE(0x69, "stopMusic", KernelCallStackInstruction, 0, "");
-		OPCODE_MD(0x6A, "freezeUnfreeze", KernelCallStackInstruction, -1, "", "p");
-		START_SUBOPCODE_WITH_PREFIX(0x6B, "cursorCommand");
-			OPCODE(0x90, "cursorOn", KernelCallStackInstruction, 0, "");
-			OPCODE(0x91, "cursorOff", KernelCallStackInstruction, 0, "");
-			OPCODE(0x92, "userputOn", KernelCallStackInstruction, 0, "");
-			OPCODE(0x93, "userputOff", KernelCallStackInstruction, 0, "");
-			OPCODE(0x94, "softCursorOn", KernelCallStackInstruction, 0, "");
-			OPCODE(0x95, "softCursorOff", KernelCallStackInstruction, 0, "");
-			OPCODE(0x96, "softUserputOn", KernelCallStackInstruction, 0, "");
-			OPCODE(0x97, "softUserputOff", KernelCallStackInstruction, 0, "");
-			OPCODE_MD(0x99, "setCursorImg", KernelCallStackInstruction, -2, "", "z");
-			OPCODE_MD(0x9A, "setCursorHotspot", KernelCallStackInstruction, -2, "", "pp");
-			OPCODE_MD(0x9C, "initCharset", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x9D, "charsetColors", KernelCallStackInstruction, 0x1000, "", "l"); // Variable stack arguments
-			OPCODE_MD(0xD6, "setCursorTransparency", KernelCallStackInstruction, -1, "", "p");
-		END_SUBOPCODE;
-		OPCODE(0x6C, "breakHere", KernelCallStackInstruction, 0, "");
-		OPCODE_MD(0x6D, "ifClassOfIs", KernelCallStackInstruction, 0x1011, "", "rlp"); // Variable stack arguments
-		OPCODE_MD(0x6E, "setClass", KernelCallStackInstruction, 0x1010, "", "lp"); // Variable stack arguments
-		OPCODE_MD(0x6F, "getState", KernelCallStackInstruction, 0, "", "rp");
-		OPCODE_MD(0x70, "setState", KernelCallStackInstruction, -2, "", "pp");
-		OPCODE_MD(0x71, "setOwner", KernelCallStackInstruction, -2, "", "pp");
-		OPCODE_MD(0x72, "getOwner", KernelCallStackInstruction, 0, "", "rp");
-		OPCODE(0x73, "jump", Scummv6JumpInstruction, 0, "a");
-		OPCODE_MD(0x74, "startSound", KernelCallStackInstruction, -1, "", "p");
-		OPCODE_MD(0x75, "stopSound", KernelCallStackInstruction, -1, "", "p");
-		OPCODE_MD(0x76, "startMusic", KernelCallStackInstruction, -1, "", "p");
-		OPCODE_MD(0x77, "stopObjectScript", KernelCallStackInstruction, -1, "", "p");
-		OPCODE_MD(0x78, "panCameraTo", KernelCallStackInstruction, -1, "", "p");
-		OPCODE_MD(0x79, "actorFollowCamera", KernelCallStackInstruction, -1, "", "p");
-		OPCODE_MD(0x7A, "setCameraAt", KernelCallStackInstruction, -1, "", "p");
-		OPCODE_MD(0x7B, "loadRoom", KernelCallStackInstruction, -1, "", "p");
-		OPCODE_MD(0x7C, "stopScript", KernelCallStackInstruction, -1, "", "p");
-		OPCODE_MD(0x7D, "walkActorToObj", KernelCallStackInstruction, -3, "", "ppp");
-		OPCODE_MD(0x7E, "walkActorTo", KernelCallStackInstruction, -3, "", "ppp");
-		OPCODE_MD(0x7F, "putActorAtXY", KernelCallStackInstruction, -4, "", "pppp");
-		OPCODE_MD(0x80, "putActorAtObject", KernelCallStackInstruction, -3, "", "zp");
-		OPCODE_MD(0x81, "faceActor", KernelCallStackInstruction, -2, "", "pp");
-		OPCODE_MD(0x82, "animateActor", KernelCallStackInstruction, -2, "", "pp");
-		OPCODE_MD(0x83, "doSentence", KernelCallStackInstruction, -4, "", "pppp");
-		OPCODE_MD(0x84, "pickupObject", KernelCallStackInstruction, -2, "", "z");
-		OPCODE_MD(0x85, "loadRoomWithEgo", KernelCallStackInstruction, -4, "", "ppz");
-		OPCODE_MD(0x87, "getRandomNumber", KernelCallStackInstruction, 0, "", "rp");
-		OPCODE_MD(0x88, "getRandomNumberRange", KernelCallStackInstruction, -1, "", "rpp");
-		OPCODE_MD(0x8A, "getActorMoving", KernelCallStackInstruction, 0, "", "rp");
-		OPCODE_MD(0x8B, "isScriptRunning", KernelCallStackInstruction, 0, "", "rp");
-		OPCODE_MD(0x8C, "getActorRoom", KernelCallStackInstruction, 0, "", "rp");
-		OPCODE_MD(0x8D, "getObjectX", KernelCallStackInstruction, 0, "", "rp");
-		OPCODE_MD(0x8E, "getObjectY", KernelCallStackInstruction, 0, "", "rp");
-		OPCODE_MD(0x8F, "getObjectDir", KernelCallStackInstruction, 0, "", "rp");
-		OPCODE_MD(0x90, "getActorWalkBox", KernelCallStackInstruction, 0, "", "rp");
-		OPCODE_MD(0x91, "getActorCostume", KernelCallStackInstruction, 0, "", "rp");
-		OPCODE_MD(0x92, "findInventory", KernelCallStackInstruction, -1, "", "rpp");
-		OPCODE_MD(0x93, "getInventoryCount", KernelCallStackInstruction, 0, "", "rp");
-		OPCODE_MD(0x94, "getVerbFromXY", KernelCallStackInstruction, -1, "", "rpp");
-		OPCODE_BASE(0x95)
-			OPCODE_BODY("beginOverride", KernelCallStackInstruction, 0, "", "");
-			// FIXME/TODO: beginOverride skips the following jump - that jump is instead to a "finally" handler
-			// To simulate this, we simply skip the jump instruction, so the sequential order appears the same.
-			// Semantically, it would probably be more correct to model this as a conditional jump,
-			// but since precious little time remains of GSoC and that might not play very nice with the rest of the code,
-			// this is the simplest way to handle the issue right now. Eventually, it should probably be fixed more properly.
-			mStream->Seek(3);
-			_address += 3;
-			OPCODE_END;
-		OPCODE(0x96, "endOverride", KernelCallStackInstruction, 0, "");
-		OPCODE_MD(0x97, "setObjectName", KernelCallStackInstruction, -1, "c", "ps");
-		OPCODE_MD(0x98, "isSoundRunning", KernelCallStackInstruction, 0, "", "rp");
-		OPCODE_MD(0x99, "setBoxFlags", KernelCallStackInstruction, 0x1100, "", "pl"); // Variable stack arguments
-		OPCODE(0x9A, "createBoxMatrix", KernelCallStackInstruction, 0, "");
-		START_SUBOPCODE_WITH_PREFIX(0x9B, "resourceRoutines");
-			OPCODE_MD(0x64, "loadScript", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x65, "loadSound", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x66, "loadCostume", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x67, "loadRoom", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x68, "nukeScript", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x69, "nukeSound", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x6A, "nukeCostume", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x6B, "nukeRoom", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x6C, "lockScript", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x6D, "lockSound", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x6E, "lockCostume", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x6F, "lockRoom", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x70, "unlockScript", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x71, "unlockSound", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x72, "unlockCostume", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x73, "unlockRoom", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x75, "loadCharset", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x76, "nukeCharset", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x77, "loadFlObject", KernelCallStackInstruction, -2, "", "pp");
-		END_SUBOPCODE;
-		START_SUBOPCODE_WITH_PREFIX(0x9C, "roomOps");
-			OPCODE_MD(0xAC, "roomScroll", KernelCallStackInstruction, -2, "", "pp");
-			OPCODE_MD(0xAE, "setScreen", KernelCallStackInstruction, -2, "", "pp");
-			OPCODE_MD(0xAF, "setPalColor", KernelCallStackInstruction, -4, "", "pppp");
-			OPCODE(0xB0, "shakeOn", KernelCallStackInstruction, 0, "");
-			OPCODE(0xB1, "shakeOff", KernelCallStackInstruction, 0, "");
-			OPCODE_MD(0xB3, "darkenPalette", KernelCallStackInstruction, -3, "", "ppp");
-			OPCODE_MD(0xB4, "saveLoadRoom", KernelCallStackInstruction, -2, "", "pp");
-			OPCODE_MD(0xB5, "screenEffect", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0xB6, "darkenPaletteRGB", KernelCallStackInstruction, -5, "", "ppppp");
-			OPCODE_MD(0xB7, "setupShadowPalette", KernelCallStackInstruction, -5, "", "ppppp");
-			OPCODE_MD(0xBA, "palManipulate", KernelCallStackInstruction, -4, "", "pppp");
-			OPCODE_MD(0xBB, "colorCycleDelay", KernelCallStackInstruction, -2, "", "pp");
-			OPCODE_MD(0xD5, "setPalette", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0xDC, "copyPalColor", KernelCallStackInstruction, -2, "", "pp");
-		END_SUBOPCODE;
-		START_SUBOPCODE_WITH_PREFIX(0x9D, "actorOps");
-			OPCODE_MD(0x4C, "setCostume", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x4D, "setWalkSpeed", KernelCallStackInstruction, -2, "", "pp");
-			OPCODE_MD(0x4E, "setSound", KernelCallStackInstruction, 0x1000, "", "l"); // Variable stack arguments
-			OPCODE_MD(0x4F, "setWalkFrame", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x50, "setTalkFrame", KernelCallStackInstruction, -2, "", "pp");
-			OPCODE_MD(0x51, "setStandFrame", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x52, "82?", KernelCallStackInstruction, -3, "", "ppp");
-			OPCODE(0x53, "init", KernelCallStackInstruction, 0, "");
-			OPCODE_MD(0x54, "setElevation", KernelCallStackInstruction, -1, "", "p");
-			OPCODE(0x55, "setDefAnim", KernelCallStackInstruction, 0, "");
-			OPCODE_MD(0x56, "setPalette", KernelCallStackInstruction, -2, "", "pp");
-			OPCODE_MD(0x57, "setTalkColor", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x58, "setName", KernelCallStackInstruction, 0, "c", "s");
-			OPCODE_MD(0x59, "setInitFrame", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x5B, "setWidth", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x5C, "setScale", KernelCallStackInstruction, -1, "", "p");
-			OPCODE(0x5D, "setNeverZClip", KernelCallStackInstruction, 0, "");
-			OPCODE_MD(0x5E, "setAlwaysZClip", KernelCallStackInstruction, -1, "", "p");
-			OPCODE(0x5F, "setIgnoreBoxes", KernelCallStackInstruction, 0, "");
-			OPCODE(0x60, "setFollowBoxes", KernelCallStackInstruction, 0, "");
-			OPCODE_MD(0x61, "setAnimSpeed", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x62, "setShadowMode", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x63, "setTalkPos", KernelCallStackInstruction, -2, "", "pp");
-			OPCODE_MD(0xC5, "setCurActor", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0xC6, "setAnimVar", KernelCallStackInstruction, -2, "", "pp");
-			OPCODE(0xD7, "setIgnoreTurnsOn", KernelCallStackInstruction, 0, "");
-			OPCODE(0xD8, "setIgnoreTurnsOff", KernelCallStackInstruction, 0, "");
-			OPCODE(0xD9, "initLittle", KernelCallStackInstruction, 0, "");
-			OPCODE_MD(0xE1, "setAlwaysZClip?", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0xE3, "setLayer", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0xE4, "setWalkScript", KernelCallStackInstruction, -1, "", "p");
-			OPCODE(0xE5, "setStanding", KernelCallStackInstruction, 0, "");
-			OPCODE_MD(0xE6, "setDirection", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0xE7, "turnToDirection", KernelCallStackInstruction, -1, "", "p");
-			OPCODE(0xE9, "freeze", KernelCallStackInstruction, 0, "");
-			OPCODE(0xEA, "unfreeze", KernelCallStackInstruction, 0, "");
-			OPCODE_MD(0xEB, "setTalkScript", KernelCallStackInstruction, -1, "", "p");
-		END_SUBOPCODE;
-		START_SUBOPCODE_WITH_PREFIX(0x9E, "verbOps");
-			OPCODE_MD(0x7C, "loadImg", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x7D, "loadString", KernelCallStackInstruction, 0, "c", "s");
-			OPCODE_MD(0x7E, "setColor", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x7F, "setHiColor", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x80, "setXY", KernelCallStackInstruction, -2, "", "pp");
-			OPCODE(0x81, "setOn", KernelCallStackInstruction, 0, "");
-			OPCODE(0x82, "setOff", KernelCallStackInstruction, 0, "");
-			OPCODE(0x83, "kill", KernelCallStackInstruction, 0, "");
-			OPCODE(0x84, "init", KernelCallStackInstruction, 0, "");
-			OPCODE_MD(0x85, "setDimColor", KernelCallStackInstruction, -1, "", "p");
-			OPCODE(0x86, "setDimmed", KernelCallStackInstruction, 0, "");
-			OPCODE_MD(0x87, "setKey", KernelCallStackInstruction, -1, "", "p");
-			OPCODE(0x88, "setCenter", KernelCallStackInstruction, 0, "");
-			OPCODE_MD(0x89, "setToString", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x8B, "setToObject", KernelCallStackInstruction, -2, "", "pp");
-			OPCODE_MD(0x8C, "setBkColor", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0xC4, "setCurVerb", KernelCallStackInstruction, -1, "", "p");
-			OPCODE(0xFF, "redraw", KernelCallStackInstruction, 0, "");
-		END_SUBOPCODE;
-		OPCODE_MD(0x9F, "getActorFromXY", KernelCallStackInstruction, -1, "", "rpp");
-		OPCODE_MD(0xA0, "findObject", KernelCallStackInstruction, -1, "", "rpp");
-		OPCODE_MD(0xA1, "pseudoRoom", KernelCallStackInstruction, 0x1010, "", "lp"); // Variable stack arguments
-		OPCODE_MD(0xA2, "getActorElevation", KernelCallStackInstruction, 0, "", "rp");
-		OPCODE_MD(0xA3, "getVerbEntrypoint", KernelCallStackInstruction, -1, "", "rpp");
-		START_SUBOPCODE_WITH_PREFIX(0xA4, "arrayOps");
-			OPCODE_MD(0xCD, "assignString", Scummv6ArrayOpInstruction, -1, "wc", "");
-			OPCODE_MD(0xD0, "assignIntList", Scummv6ArrayOpInstruction, 0x1100, "w", ""); // Variable stack arguments
-			OPCODE_MD(0xD4, "assign2DimList", Scummv6ArrayOpInstruction, 0x1100, "w", ""); // Variable stack arguments
-		END_SUBOPCODE;
-		START_SUBOPCODE_WITH_PREFIX(0xA5, "saveRestoreVerbs");
-			OPCODE_MD(0x8D, "saveVerbs", KernelCallStackInstruction, -3, "", "ppp");
-			OPCODE_MD(0x8E, "restoreVerbs", KernelCallStackInstruction, -3, "", "ppp");
-			OPCODE_MD(0x8F, "deleteVerbs", KernelCallStackInstruction, -3, "", "ppp");
-		END_SUBOPCODE;
-		OPCODE_MD(0xA6, "drawBox", KernelCallStackInstruction, -5, "", "ppppp");
-		OPCODE(0xA7, "pop", Scummv6StackInstruction, -1, "");
-		OPCODE_MD(0xA8, "getActorWidth", KernelCallStackInstruction, 0, "", "rp");
-		START_SUBOPCODE(0xA9); // wait
-			OPCODE_MD(0xA8, "waitForActor", KernelCallStackInstruction, -1, "s", "pj");
-			OPCODE(0xA9, "waitForMessage", KernelCallStackInstruction, 0, "");
-			OPCODE(0xAA, "waitForCamera", KernelCallStackInstruction, 0, "");
-			OPCODE(0xAB, "waitForSentence", KernelCallStackInstruction, 0, "");
-			OPCODE_MD(0xE2, "waitUntilActorDrawn", KernelCallStackInstruction, -1, "s", "pj");
-			OPCODE_MD(0xE8, "waitUntilActorTurned", KernelCallStackInstruction, -1, "s", "pj");
-		END_SUBOPCODE;
-		OPCODE_MD(0xAA, "getActorScaleX", KernelCallStackInstruction, 0, "", "rp");
-		OPCODE_MD(0xAB, "getActorAnimCounter", KernelCallStackInstruction, 0, "", "rp");
-		OPCODE_MD(0xAC, "soundKludge", KernelCallStackInstruction, 0x1000, "", "l"); // Variable stack arguments
-		OPCODE_MD(0xAD, "isAnyOf", KernelCallStackInstruction, 0x1011, "", "rlp"); // Variable stack arguments
-		START_SUBOPCODE_WITH_PREFIX(0xAE, "systemOps");
-			OPCODE(0x9E, "restartGame", KernelCallStackInstruction, 0, "");
-			OPCODE(0x9F, "pauseGame", KernelCallStackInstruction, 0, "");
-			OPCODE(0xA0, "shutDown", KernelCallStackInstruction, 0, "");
-		END_SUBOPCODE;
-		OPCODE_MD(0xAF, "isActorInBox", KernelCallStackInstruction, -1, "", "rpp");
-		OPCODE_MD(0xB0, "delay", KernelCallStackInstruction, -1, "", "p");
-		OPCODE_MD(0xB1, "delaySeconds", KernelCallStackInstruction, -1, "", "p");
-		OPCODE_MD(0xB2, "delayMinutes", KernelCallStackInstruction, -1, "", "p");
-		OPCODE(0xB3, "stopSentence", KernelCallStackInstruction, 0, "");
-		START_SUBOPCODE_WITH_PREFIX(0xB4, "printLine");
-			OPCODE_MD(0x41, "XY", KernelCallStackInstruction, -2, "", "pp");
-			OPCODE_MD(0x42, "color", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x43, "right", KernelCallStackInstruction, -1, "", "p");
-			OPCODE(0x45, "center", KernelCallStackInstruction, 0, "");
-			OPCODE(0x47, "left", KernelCallStackInstruction, 0, "");
-			OPCODE(0x48, "overhead", KernelCallStackInstruction, 0, "");
-			OPCODE(0x4A, "mumble", KernelCallStackInstruction, 0, "");
-			OPCODE_MD(0x4B, "msg", KernelCallStackInstruction, 0, "c", "s");
-			OPCODE(0xFE, "begin", KernelCallStackInstruction, 0, "");
-			OPCODE(0xFF, "end", KernelCallStackInstruction, 0, "");
-		END_SUBOPCODE;
-		START_SUBOPCODE_WITH_PREFIX(0xB5, "printText");
-			OPCODE_MD(0x41, "XY", KernelCallStackInstruction, -2, "", "pp");
-			OPCODE_MD(0x42, "color", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x43, "right", KernelCallStackInstruction, -1, "", "p");
-			OPCODE(0x45, "center", KernelCallStackInstruction, 0, "");
-			OPCODE(0x47, "left", KernelCallStackInstruction, 0, "");
-			OPCODE(0x48, "overhead", KernelCallStackInstruction, 0, "");
-			OPCODE(0x4A, "mumble", KernelCallStackInstruction, 0, "");
-			OPCODE_MD(0x4B, "msg", KernelCallStackInstruction, 0, "c", "s");
-			OPCODE(0xFE, "begin", KernelCallStackInstruction, 0, "");
-			OPCODE(0xFF, "end", KernelCallStackInstruction, 0, "");
-		END_SUBOPCODE;
-		START_SUBOPCODE_WITH_PREFIX(0xB6, "printDebug");
-			OPCODE_MD(0x41, "XY", KernelCallStackInstruction, -2, "", "pp");
-			OPCODE_MD(0x42, "color", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x43, "right", KernelCallStackInstruction, -1, "", "p");
-			OPCODE(0x45, "center", KernelCallStackInstruction, 0, "");
-			OPCODE(0x47, "left", KernelCallStackInstruction, 0, "");
-			OPCODE(0x48, "overhead", KernelCallStackInstruction, 0, "");
-			OPCODE(0x4A, "mumble", KernelCallStackInstruction, 0, "");
-			OPCODE_MD(0x4B, "msg", KernelCallStackInstruction, 0, "c", "s");
-			OPCODE(0xFE, "begin", KernelCallStackInstruction, 0, "");
-			OPCODE(0xFF, "end", KernelCallStackInstruction, 0, "");
-		END_SUBOPCODE;
-		START_SUBOPCODE_WITH_PREFIX(0xB7, "printSystem");
-			OPCODE_MD(0x41, "XY", KernelCallStackInstruction, -2, "", "pp");
-			OPCODE_MD(0x42, "color", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x43, "right", KernelCallStackInstruction, -1, "", "p");
-			OPCODE(0x45, "center", KernelCallStackInstruction, 0, "");
-			OPCODE(0x47, "left", KernelCallStackInstruction, 0, "");
-			OPCODE(0x48, "overhead", KernelCallStackInstruction, 0, "");
-			OPCODE(0x4A, "mumble", KernelCallStackInstruction, 0, "");
-			OPCODE_MD(0x4B, "msg", KernelCallStackInstruction, 0, "c", "s");
-			OPCODE(0xFE, "begin", KernelCallStackInstruction, 0, "");
-			OPCODE(0xFF, "end", KernelCallStackInstruction, 0, "");
-		END_SUBOPCODE;
-		START_SUBOPCODE_WITH_PREFIX(0xB8, "printActor");
-			OPCODE_MD(0x41, "XY", KernelCallStackInstruction, -2, "", "pp");
-			OPCODE_MD(0x42, "color", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x43, "right", KernelCallStackInstruction, -1, "", "p");
-			OPCODE(0x45, "center", KernelCallStackInstruction, 0, "");
-			OPCODE(0x47, "left", KernelCallStackInstruction, 0, "");
-			OPCODE(0x48, "overhead", KernelCallStackInstruction, 0, "");
-			OPCODE(0x4A, "mumble", KernelCallStackInstruction, 0, "");
-			OPCODE_MD(0x4B, "msg", KernelCallStackInstruction, 0, "c", "s");
-			OPCODE_MD(0xFE, "begin", KernelCallStackInstruction, -1, "", "p");
-			OPCODE(0xFF, "end", KernelCallStackInstruction, 0, "");
-		END_SUBOPCODE;
-		START_SUBOPCODE_WITH_PREFIX(0xB9, "printEgo");
-			OPCODE_MD(0x41, "XY", KernelCallStackInstruction, -2, "", "pp");
-			OPCODE_MD(0x42, "color", KernelCallStackInstruction, -1, "", "p");
-			OPCODE_MD(0x43, "right", KernelCallStackInstruction, -1, "", "p");
-			OPCODE(0x45, "center", KernelCallStackInstruction, 0, "");
-			OPCODE(0x47, "left", KernelCallStackInstruction, 0, "");
-			OPCODE(0x48, "overhead", KernelCallStackInstruction, 0, "");
-			OPCODE(0x4A, "mumble", KernelCallStackInstruction, 0, "");
-			OPCODE_MD(0x4B, "msg", KernelCallStackInstruction, 0, "c", "s");
-			OPCODE(0xFE, "begin", KernelCallStackInstruction, 0, "");
-			OPCODE(0xFF, "end", KernelCallStackInstruction, 0, "");
-		END_SUBOPCODE;
-		OPCODE_MD(0xBA, "talkActor", KernelCallStackInstruction, -1, "c", "ps");
-		OPCODE_MD(0xBB, "talkEgo", KernelCallStackInstruction, 0, "c", "s");
-		START_SUBOPCODE(0xBC); // dimArray
-			OPCODE_MD(0xC7, "dimArrayInt", KernelCallStackInstruction, -1, "w", "pv");
-			OPCODE_MD(0xC8, "dimArrayBit", KernelCallStackInstruction, -1, "w", "pv");
-			OPCODE_MD(0xC9, "dimArrayNibble", KernelCallStackInstruction, -1, "w", "pv");
-			OPCODE_MD(0xCA, "dimArrayByte", KernelCallStackInstruction, -1, "w", "pv");
-			OPCODE_MD(0xCB, "dimArrayString", KernelCallStackInstruction, -1, "w", "pv");
-			OPCODE_MD(0xCC, "dimArray_nukeArray", KernelCallStackInstruction, 0, "w", "v");
-		END_SUBOPCODE;
-		OPCODE_MD(0xBE, "startObjectQuick", KernelCallStackInstruction, 0x1020, "", "lpp"); // Variable stack arguments
-		OPCODE_MD(0xBF, "startScriptQuick2", KernelCallStackInstruction, 0x1010, "", "lp"); // Variable stack arguments
-		START_SUBOPCODE(0xC0); // dim2DimArray
-			OPCODE_MD(0xC7, "dim2DimArrayInt", KernelCallStackInstruction, -2, "w", "ppv");
-			OPCODE_MD(0xC8, "dim2DimArrayBit", KernelCallStackInstruction, -2, "w", "ppv");
-			OPCODE_MD(0xC9, "dim2DimArrayNibble", KernelCallStackInstruction, -2, "w", "ppv");
-			OPCODE_MD(0xCA, "dim2DimArrayByte", KernelCallStackInstruction, -2, "w", "ppv");
-			OPCODE_MD(0xCB, "dim2DimArrayString", KernelCallStackInstruction, -2, "w", "ppv");
-		END_SUBOPCODE;
-		OPCODE_MD(0xC4, "abs", KernelCallStackInstruction, 0, "", "rp");
-		OPCODE_MD(0xC5, "getDistObjObj", KernelCallStackInstruction, -1, "", "rpp");
-		OPCODE_MD(0xC6, "getDistObjPt", KernelCallStackInstruction, -2, "", "rppp");
-		OPCODE_MD(0xC7, "getDistPtPt", KernelCallStackInstruction, -3, "", "rpppp");
-		OPCODE_MD(0xC8, "kernelGetFunctions", KernelCallStackInstruction, 0x1000, "", "l"); // Variable stack arguments
-		OPCODE_MD(0xC9, "kernelSetFunctions", KernelCallStackInstruction, 0x1000, "", "l"); // Variable stack arguments
-		OPCODE_MD(0xCA, "delayFrames", KernelCallStackInstruction, -1, "", "p");
-		OPCODE_MD(0xCB, "pickOneOf", KernelCallStackInstruction, 0x1011, "", "rlp"); // Variable stack arguments
-		OPCODE_MD(0xCC, "pickOneOfDefault", KernelCallStackInstruction, 0x111, "", "rplp"); // Variable stack arguments
-		OPCODE_MD(0xCD, "stampObject", KernelCallStackInstruction, -4, "", "pppp");
-		OPCODE(0xD0, "getDateTime", KernelCallStackInstruction, 0, "");
-		OPCODE(0xD1, "stopTalking", KernelCallStackInstruction, 0, "");
-		OPCODE_MD(0xD2, "getAnimateVariable", KernelCallStackInstruction, -1, "", "rpp");
-		OPCODE_MD(0xD4, "shuffle", KernelCallStackInstruction, -2, "w", "vpp");
-		OPCODE_MD(0xD5, "jumpToScript", KernelCallStackInstruction, 0x1020, "", "lpp"); // Variable stack arguments
-		OPCODE_MD(0xD6, "band", BinaryOpStackInstruction, -1, "", "&");
-		OPCODE_MD(0xD7, "bor", BinaryOpStackInstruction, -1, "", "|");
-		OPCODE_MD(0xD8, "isRoomScriptRunning", KernelCallStackInstruction, 0, "", "rp");
-		OPCODE_MD(0xDD, "findAllObjects", KernelCallStackInstruction, 0, "", "rp");
-		OPCODE_MD(0xE1, "getPixel", KernelCallStackInstruction, -1, "", "rpp");
-		OPCODE_MD(0xE3, "pickVarRandom", KernelCallStackInstruction, 0x1001, "w", "rlw"); // Variable stack arguments
-		OPCODE_MD(0xE4, "setBoxSet", KernelCallStackInstruction, -1, "", "p");
-		OPCODE_MD(0xEC, "getActorLayer", KernelCallStackInstruction, 0, "", "rp");
-		OPCODE_MD(0xED, "getObjectNewDir", KernelCallStackInstruction, 0, "", "rp");
-	END_OPCODES;
-
-	InstIterator it;
-	for (it = _insts.begin(); it != _insts.end(); ++it)
-		if ((*it)->_stackChange >= 0x1000)
-			fixStackEffect(it, ((*it)->_stackChange >> 8) & 0xF, ((*it)->_stackChange >> 4) & 0xF, (*it)->_stackChange & 0xF);
-}
-
-void Scumm::v6::Scummv6Disassembler::fixStackEffect(InstIterator &it, int popBefore, int popAfter, int pushTotal) {
-	(*it)->_stackChange = static_cast<int16>(-popBefore - popAfter + pushTotal);
-	InstIterator it2 = it;
-	for (--it2; popBefore != 0; --it2)
-		if ((*it2)->isLoad())
-			--popBefore;
-	(*it)->_stackChange -= static_cast<int16>((*it2)->_params[0]->getSigned() + 1);
-}
-
-ValuePtr Scumm::v6::Scummv6Disassembler::readParameter(InstPtr inst, std::string type) {
-	ValuePtr retval = NULL;
-    assert(type.length() == 1);
-	switch (type.at(0)) {
-	case 'a':
-		retval = new RelAddressValue(inst->_address + 3, mStream->ReadS16());
-		_address += 2;
-		break;
-	case 'c': { // Character string
-		byte cmd;
-		bool inStr = false;
-		std::stringstream s;
-        while ((cmd = mStream->ReadU8()) != 0) {
-			if (cmd == 0xFF || cmd == 0xFE) {
-				if (inStr) {
-					s << '"';
-					inStr = false;
-				}
-				cmd = mStream->ReadU8();
-				switch (cmd) {
-				case 1:
-					s << ":newline:";
-					_address += 2;
-					break;
-				case 2:
-					s << ":keeptext:";
-					_address += 2;
-					break;
-				case 3:
-					s << ":wait:";
-					_address += 2;
-					break;
-				case 4:     // addIntToStack
-				case 5:     // addVerbToStack
-				case 6:     // addNameToStack
-				case 7: {   // addStringToStack
-					uint16 var = mStream->ReadU16();
-					// TODO: Clean output similar to descumm
-					s << ":addToStack=" << var << ":";
-					_address += 4;
-					}
-					break;
-				case 9:
-					s << ":startanim=" << mStream->ReadU16() << ":";
-					_address += 4;
-					break;
-				case 10:
-					s << ":sound:";
-					mStream->Seek(14);
-					_address += 16;
-					break;
-				case 12:
-					s << ":setcolor=" << mStream->ReadU16() << ":";
-					_address += 4;
-					break;
-				case 13:
-					s << ":unk2=" << mStream->ReadU16() << ":";
-					_address += 4;
-					break;
-				case 14:
-					s << ":setfont=" << mStream->ReadU16() << ":";
-					_address += 4;
-					break;
-				default:
-					s << ":unk" << cmd << "=" << mStream->ReadU16() << ":";
-					_address += 4;
-					break;
-				}
-			} else {
-				if (!inStr) {
-					s << '"';
-					inStr = true;
-				}
-				s << cmd;
-				_address++;
-			}
-		}
-		_address++;
-		if (inStr)
-			s << '"';
-		retval = new Scummv6StringValue(s.str());
-		}
-		break;
-	default: // Defer handling to parent implementation
-		retval = SimpleDisassembler::readParameter(inst, type);
-		break;
-	}
-	return retval;
-}

+ 0 - 185
V-Gears-Installer/src/decompiler/scummv6/engine.cpp

@@ -1,185 +0,0 @@
-/* ScummVM Tools
- *
- * ScummVM Tools is the legal property of its developers, whose
- * names are too numerous to list here. Please refer to the
- * COPYRIGHT file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#include "decompiler/scummv6/engine.h"
-#include "decompiler/scummv6/disassembler.h"
-#include "decompiler/scummv6/codegen.h"
-#include "common/make_unique.h"
-
-std::ostream &Scumm::v6::Scummv6StringValue::print(std::ostream &output) const {
-	return output << _str;
-}
-
-std::unique_ptr<Disassembler> Scumm::v6::Scummv6Engine::getDisassembler(InstVec &insts) 
-{
-	return std::make_unique<Scummv6Disassembler>(insts);
-}
-
-std::unique_ptr<CodeGenerator> Scumm::v6::Scummv6Engine::getCodeGenerator(const InstVec&, std::ostream &output)
-{
-	return std::make_unique<Scummv6CodeGenerator>(this, output);
-}
-
-void Scumm::v6::Scummv6LoadInstruction::processInst(Function&, ValueStack &stack, Engine*, CodeGenerator *codeGen) {
-	Scummv6CodeGenerator *cg = (Scummv6CodeGenerator *)codeGen;
-	switch (_opcode) {
-	case 0x00: // pushByte
-	case 0x01: // pushWord
-		stack.push(_params[0]);
-		break;
-	case 0x02: // pushByteVar
-	case 0x03: // pushWordVar
-        stack.push(new VarValue(cg->decodeVarName(static_cast<uint16>(_params[0]->getUnsigned()))));
-		break;
-	case 0x06: // byteArrayRead
-	case 0x07: // wordArrayRead
-		{
-			ValueList idxs;
-			idxs.push_front(stack.pop());
-            stack.push(new ArrayValue(cg->decodeArrayName(static_cast<uint16>(_params[0]->getUnsigned())), idxs));
-			break;
-		}
-	case 0x0A: // byteArrayIndexedRead
-	case 0x0B: // wordArrayIndexedRead
-		{
-			ValueList idxs;
-			idxs.push_front(stack.pop());
-			idxs.push_front(stack.pop());
-            stack.push(new ArrayValue(cg->decodeArrayName(static_cast<uint16>(_params[0]->getUnsigned())), idxs));
-			break;
-		}
-	}
-}
-
-void Scumm::v6::Scummv6StoreInstruction::processInst(Function&, ValueStack &stack, Engine*, CodeGenerator *codeGen) {
-	Scummv6CodeGenerator *cg = (Scummv6CodeGenerator *)codeGen;
-	switch (_opcode) {
-	case 0x42: // writeByteVar
-	case 0x43: // writeWordVar
-		{
-        ValuePtr p = new VarValue(cg->decodeVarName(static_cast<uint16>(_params[0]->getUnsigned())));
-			cg->writeAssignment(p, stack.pop());
-		}
-		break;
-	case 0x46: // byteArrayWrite
-	case 0x47: // wordArrayWrite
-		{
-			ValuePtr value = stack.pop();
-			ValueList idxs;
-			idxs.push_back(stack.pop());
-            ValuePtr p = new ArrayValue(cg->decodeArrayName(static_cast<uint16>(_params[0]->getUnsigned())), idxs);
-			cg->writeAssignment(p, value);
-		}
-		break;
-	case 0x4A: // byteArrayIndexedWrite
-	case 0x4B: // wordArrayIndexedWrite
-		{
-			ValuePtr value = stack.pop();
-			ValueList idxs;
-			idxs.push_front(stack.pop());
-			idxs.push_front(stack.pop());
-            ValuePtr p = new ArrayValue(cg->decodeArrayName(static_cast<uint16>(_params[0]->getUnsigned())), idxs);
-			cg->writeAssignment(p, value);
-		}
-		break;
-	}
-}
-
-void Scumm::v6::Scummv6StackInstruction::processInst(Function&, ValueStack &stack, Engine*, CodeGenerator*) {
-	stack.pop();
-}
-
-void Scumm::v6::Scummv6CondJumpInstruction::processInst(Function&, ValueStack &stack, Engine*, CodeGenerator*) {
-	if (_opcode == 0x5D) // jumpFalse
-		stack.push(stack.pop()->negate());
-}
-
-uint32 Scumm::v6::Scummv6CondJumpInstruction::getDestAddress() const {
-	return _params[0]->getUnsigned();
-}
-
-uint32 Scumm::v6::Scummv6JumpInstruction::getDestAddress() const {
-	return _params[0]->getUnsigned();
-}
-
-void Scumm::v6::Scummv6IncDecInstruction::processInst(Function&, ValueStack &stack, Engine*, CodeGenerator *codeGen) {
-	Scummv6CodeGenerator *cg = (Scummv6CodeGenerator *)codeGen;
-	switch (_opcode) {
-	case 0x4E: // byteVarInc
-	case 0x4F: // wordVarInc
-	case 0x56: // byteVarDec
-	case 0x57: // wordVarDec
-		{
-			std::stringstream s;
-			ValuePtr p = new UnaryOpValue(new VarValue(cg->decodeVarName(static_cast<uint16>(_params[0]->getUnsigned()))), _codeGenData, true);
-			s << p << ";";
-			cg->addOutputLine(s.str());
-		}
-		break;
-	case 0x52: // byteArrayInc
-	case 0x53: // wordArrayInc
-	case 0x5A: // byteArrayDec
-	case 0x5B: // wordArrayDec
-		{
-			std::stringstream s;
-			ValueList idxs;
-			idxs.push_front(stack.pop());
-            ValuePtr p = new UnaryOpValue(new ArrayValue(cg->decodeVarName(static_cast<uint16>(_params[0]->getUnsigned())), idxs), _codeGenData, true);
-			s << p << ";";
-			cg->addOutputLine(s.str());
-		}
-		break;
-	}
-}
-
-void Scumm::v6::Scummv6ArrayOpInstruction::processInst(Function&, ValueStack &stack, Engine*, CodeGenerator *codeGen) {
-	Scummv6CodeGenerator *cg = (Scummv6CodeGenerator *)codeGen;
-	switch (_opcode) {
-	case 0xA4CD: // arrayOp_assignString
-		{
-			ValuePtr value = _params[1];
-			ValueList idxs;
-			idxs.push_front(stack.pop());
-            ValuePtr p = new ArrayValue(cg->decodeArrayName(static_cast<uint16>(_params[0]->getUnsigned())), idxs);
-			cg->writeAssignment(p, value);
-		}
-		break;
-	case 0xA4D0: // arrayOp_assignIntList
-		{
-			ValueList idxs;
-			idxs.push_front(stack.pop());
-			ValuePtr value = cg->createListValue();
-            ValuePtr p = new ArrayValue(cg->decodeArrayName(static_cast<uint16>(_params[0]->getUnsigned())), idxs);
-			cg->writeAssignment(p, value);
-		}
-		break;
-	case 0xA4D4: // arrayOp_assign2DimList
-		{
-			ValueList idxs;
-			idxs.push_front(stack.pop());
-			ValuePtr value = cg->createListValue();
-			idxs.push_front(stack.pop());
-            ValuePtr p = new ArrayValue(cg->decodeArrayName(static_cast<uint16>(_params[0]->getUnsigned())), idxs);
-			cg->writeAssignment(p, value);
-		}
-		break;
-	}
-}

+ 18 - 18
V-Gears-Installer/src/decompiler/simple_disassembler.cpp

@@ -60,18 +60,18 @@ void SimpleDisassembler::readParams(InstPtr inst, const char *typeString)
         std::string typeStr(typeString, 1);
         if (typeStr == "N") // Read nibbles 
         {
-            const uint8 byte = mStream->ReadU8();
+            const uint8 byte = stream_->ReadU8();
 
             inst->_params.push_back(new IntValue(Nib1(byte), false));
             inst->_params.push_back(new IntValue(Nib2(byte), false));
-            _address++;
+            address_++;
         }
         else if (typeStr == "U")
         {
-            const uint8 byte = mStream->ReadU8();
+            const uint8 byte = stream_->ReadU8();
             inst->_params.push_back( new IntValue((byte >> 5) & 0x7, false));
             inst->_params.push_back( new IntValue((byte & 0x1F), false));
-            _address++;
+            address_++;
         }
         else
         {
@@ -89,11 +89,11 @@ void SimpleDisassembler::readParams(InstPtr inst, const char *typeString, const
         if (typeStr == "N") // Read nibbles 
         {
          
-            _address++;
+            address_++;
         }
         else if (typeStr == "U")
         {
-            _address++;
+            address_++;
         }
         else
         {
@@ -108,33 +108,33 @@ ValuePtr SimpleDisassembler::readParameter(InstPtr inst, std::string type) {
 
     if (type == "b") // signed byte
     {
-        retval = new IntValue(mStream->ReadS8(), true);
-        _address++;
+        retval = new IntValue(stream_->ReadS8(), true);
+        address_++;
     }
     else if (type == "B") // unsigned byte
     {
-        retval = new IntValue((uint32)mStream->ReadU8(), false);
-        _address++;
+        retval = new IntValue((uint32)stream_->ReadU8(), false);
+        address_++;
     }
     else if (type == "s") // 16-bit signed integer (short), little-endian
     {
-        retval = new IntValue(mStream->ReadS16(), true);
-        _address += 2;
+        retval = new IntValue(stream_->ReadS16(), true);
+        address_ += 2;
     }
     else if (type == "w") // 16-bit unsigned integer (word), little-endian
     {
-        retval = new IntValue((uint32)mStream->ReadU16(), false);
-        _address += 2;
+        retval = new IntValue((uint32)stream_->ReadU16(), false);
+        address_ += 2;
     }
     else if (type == "i") // 32-bit signed integer (int), little-endian
     {
-        retval = new IntValue(mStream->ReadS32(), true);
-        _address += 4;
+        retval = new IntValue(stream_->ReadS32(), true);
+        address_ += 4;
     }
     else if (type == "d") // 32-bit unsigned integer (dword), little-endian
     {
-        retval = new IntValue(mStream->ReadU32(), false);
-        _address += 4;
+        retval = new IntValue(stream_->ReadU32(), false);
+        address_ += 4;
     }
     else
     {

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

@@ -14,56 +14,55 @@
  */
 
 #include "decompiler/sudm.h"
+
+#include "../../include/decompiler/field/FieldDisassembler.h"
+#include "decompiler/field/FieldCodeGenerator.h"
 #include "decompiler/field/ff7_field_engine.h"
-#include "decompiler/field/ff7_field_disassembler.h"
-#include "decompiler/field/ff7_field_codegen.h"
 #include "decompiler/control_flow.h"
 
 namespace SUDM{
-    namespace FF7{
-        namespace Animation{} // TODO
+    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;
-                ::FF7::FF7FieldEngine engine(formatter, "Unused");
-                InstVec insts;
-                engine.getDisassembler(insts, script_bytes);
-                return engine.ScaleFactor();
-            }
+        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;
+            FF7FieldEngine 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.
-                ::FF7::FF7FieldEngine 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.
+            FF7FieldEngine 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;
         }
     }
 

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

@@ -1,7 +1,7 @@
 #include "ff7_world_codegen.h"
 #include "ff7_world_engine.h"
 
-std::string FF7::FF7WorldCodeGenerator::constructFuncSignature(const Function&)
+std::string FF7::FF7WorldCodeGenerator::ConstructFuncSignature(const Function&)
 {
     return "";
 }

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

@@ -45,7 +45,7 @@ if(!Read(897))
 }
 
 */
-void FF7::FF7WorldDisassembler::doDisassemble()
+void FF7::FF7WorldDisassembler::DoDisassemble()
 {
     struct wmScriptData
     {
@@ -59,8 +59,8 @@ void FF7::FF7WorldDisassembler::doDisassemble()
     for (int i = 0; i < 256; i++)
     {
         wmScriptData tmp;
-        tmp.mType = this->mStream->ReadU16();
-        tmp.mInstructionPointer = this->mStream->ReadU16();
+        tmp.mType = this->stream_->ReadU16();
+        tmp.mInstructionPointer = this->stream_->ReadU16();
         mData.emplace_back(tmp);
     }
 
@@ -70,15 +70,15 @@ void FF7::FF7WorldDisassembler::doDisassemble()
     {
         wmScriptData data = mData[i];
 
-        this->mStream->Seek((256 * sizeof(int)) + (data.mInstructionPointer*sizeof(uint16)));
-        this->_address = this->mStream->Position();
+        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->mStream->ReadU16();
+            uint16 opcode = this->stream_->ReadU16();
             std::string opcodePrefix;
             if (end)
             {

+ 2 - 3
V-Gears-Installer/src/decompiler/world/ff7_world_engine.cpp

@@ -5,7 +5,6 @@
 #include <iostream>
 #include <sstream>
 #include <boost/format.hpp>
-#include "make_unique.h"
 
 #define GET(vertex) (boost::get(boost::vertex_name, g, vertex))
 
@@ -125,7 +124,7 @@ void FF7::FF7WorldStoreInstruction::processInst(Function&, ValueStack &stack, En
     // the bank address, not whats *at* the bank address
     ValuePtr bankValue = stack.pop();
     std::string bankAddr = bankValue->getString();
-    codeGen->addOutputLine("Write(" + bankAddr + ", " + strValue + ");");
+    codeGen->AddOutputLine("Write(" + bankAddr + ", " + strValue + ");");
 }
 
 void FF7::FF7WorldStackInstruction::processInst(Function&, ValueStack&, Engine*, CodeGenerator*)
@@ -461,7 +460,7 @@ void FF7::FF7WorldKernelCallInstruction::processInst(Function& , ValueStack &sta
         strFunc = "kernel_unknown_" + AddressValue(_opcode).getString() + "();";
         break;
     }
-    codeGen->addOutputLine(strFunc);
+    codeGen->AddOutputLine(strFunc);
 }
 
 void FF7::FF7WorldNoOutputInstruction::processInst(Function&, ValueStack&, Engine*, CodeGenerator*)

+ 8 - 9
V-Gears-Installer/src/ff7DataInstaller.cpp

@@ -29,7 +29,7 @@
 #include <OgreHardwarePixelBuffer.h>
 #include <OgreResourceGroupManager.h>
 #include <OgreLog.h>
-#include "../include/ff7DataInstaller.h"
+#include "ff7DataInstaller.h"
 #include "VGearsGameState.h"
 #include "data/VGearsAFileManager.h"
 #include "data/VGearsBackgroundFileManager.h"
@@ -51,7 +51,6 @@
 #include "decompiler/sudm.h"
 #include <memory>
 #include <QtCore/QDir>
-#include "common/make_unique.h"
 
 float FF7DataInstaller::LINE_SCALE_FACTOR = 0.0078124970964f;
 
@@ -626,13 +625,13 @@ static void FF7PcFieldToVGearsField(
         }
     }
     const VGears::ModelListFilePtr& models = field->GetModelList();
-    SUDM::FF7::Field::DecompiledScript decompiled;
+    SUDM::Field::DecompiledScript decompiled;
     FF7FieldScriptFormatter formatter(field->getName(), models, field_id_to_name_lookup, spawn_map);
     try{
         // Get the raw script bytes.
         const std::vector<u8> raw_field_data = field->GetRawScript();
         // Decompile to LUA.
-        decompiled = SUDM::FF7::Field::Decompile(
+        decompiled = SUDM::Field::Decompile(
           field->getName(), raw_field_data, formatter, gateway_script_data,
           "EntityContainer = {}\n\n"
         );
@@ -769,7 +768,7 @@ static void FF7PcFieldToVGearsField(
 
         // Get lines. Add them to a list, so they aren't processed later as regular entities.
         std::vector<std::string> line_entities;
-        for (SUDM::FF7::Field::Line line : decompiled.lines){
+        for (SUDM::Field::Line line : decompiled.lines){
 
             std::unique_ptr<TiXmlElement> xml_entity_trigger(new TiXmlElement("entity_trigger"));
             line_entities.push_back(line.name);
@@ -791,7 +790,7 @@ static void FF7PcFieldToVGearsField(
         }
 
         // Get entities.
-        for (SUDM::FF7::Field::FieldEntity entity : decompiled.entities){
+        for (SUDM::Field::FieldEntity entity : decompiled.entities){
             // If the entity has been added as a line, skip.
             if (line_entities.size() > 0){
                 if (*std::find(line_entities.begin(), line_entities.end(), entity.name) == entity.name) {
@@ -1099,13 +1098,13 @@ static void CollectSpawnPoints(
     // full list of entries to each field.
     try{
         // Get the raw script bytes.
-        SUDM::FF7::Field::DecompiledScript decompiled;
+        SUDM::Field::DecompiledScript decompiled;
         const std::vector<u8> raw_field_data = field->GetRawScript();
         // Decompile to LUA.
         FF7FieldScriptGatewayCollector formatter(
           field->getName(), field_id_to_name_lookup, spawn_points, this_field_id
         );
-        decompiled = SUDM::FF7::Field::Decompile(
+        decompiled = SUDM::Field::Decompile(
           field->getName(), raw_field_data, formatter, "", "EntityContainer = {}\n\n"
         );
     }
@@ -1232,7 +1231,7 @@ static void CollectFieldScaleFactors(
   const std::vector<std::string>& field_id_to_name_lookup
 ){
     scale_factors[FieldId(field->getName(), field_id_to_name_lookup)]
-      = ::SUDM::FF7::Field::ScaleFactor(field->GetRawScript());
+      = ::SUDM::Field::ScaleFactor(field->GetRawScript());
 }
 
 void FF7DataInstaller::InitCollectSpawnAndScaleFactors(){

+ 0 - 1
V-Gears/CMakeLists.txt

@@ -8,7 +8,6 @@ set(HEADER_FILES
     include/common/LzsFile.h
     include/common/File.h
     include/common/FileSystem.h
-    include/common/make_unique.h
     include/map/VGearsBackground2DFile.h
     include/map/VGearsBackground2DFileManager.h
     include/map/VGearsBackground2DFileXMLSerializer.h

+ 0 - 30
V-Gears/include/common/make_unique.h

@@ -1,30 +0,0 @@
-/*
- * 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
-#ifndef _MAKE_UNIQUE_
-#define _MAKE_UNIQUE_
-
-#include <memory>
-
-#ifndef _MSC_VER
-namespace std{
-    template<typename T, typename ...Args>
-    std::unique_ptr<T> make_unique(Args&& ...args){
-        return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
-    }
-}
-#endif
-#endif

+ 1 - 2
V-Gears/src/Main.cpp

@@ -32,7 +32,7 @@
 #include "core/Console.h"
 #include "core/DebugDraw.h"
 #include "core/EntityManager.h"
-#include "../include/core/GameFrameListener.h"
+#include "core/GameFrameListener.h"
 #include "core/InputManager.h"
 #include "core/Logger.h"
 #include "core/ScriptManager.h"
@@ -42,7 +42,6 @@
 #include "core/TextManager.h"
 #include "core/DialogsManager.h"
 #include "data/VGearsLZSFLevelFileManager.h"
-#include "common/make_unique.h"
 #include "modules/worldmap/WorldMapModule.h"
 #include "data/worldmap/MapFileManager.h"
 #include "data/VGearsLGPArchiveFactory.h"

+ 0 - 1
V-Gears/src/common/VGearsApplication.cpp

@@ -37,7 +37,6 @@
 #include "data/VGearsLGPArchiveFactory.h"
 #include "data/VGearsTriggersFile.h"
 #include "data/VGearsMapListFile.h"
-#include "common/make_unique.h"
 #include "vgears_version.h"
 
 template<> VGears::Application

+ 0 - 1
V-Gears/src/core/ConfigCmdManager.cpp

@@ -13,7 +13,6 @@
  * GNU General Public License for more details.
  */
 
-#include "common/make_unique.h"
 #include "core/Assert.h"
 #include "core/ConfigCmdManager.h"
 #include "core/ConfigCmdManagerCommands.h"

+ 0 - 4
lib/SUDM/.gitignore

@@ -1,4 +0,0 @@
-*.suo
-*.exe
-*.dll
-build/

+ 0 - 3
lib/SUDM/.gitmodules

@@ -1,3 +0,0 @@
-[submodule "googlemock"]
-	path = googlemock
-	url = https://github.com/paulsapps/gmock-1.7.0.git

+ 0 - 78
lib/SUDM/.travis.yml

@@ -1,78 +0,0 @@
-language: cpp
-os:
- - linux
- - osx
- 
-matrix:
- exclude:
-  - compiler: clang
-    env: COVERAGE=1
-  - os: gcc
-    env: COVERAGE=0
-    
-env:
-  global:
-   # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
-   #   via the "travis encrypt" command using the project repo's public key
-   - secure: "A4JeyJ/faUkHRFCwKD/l7I6/zY4Jzs9SFxrRxxcvqFCawisCZDK3myw1ZMSEFp6bNBC1onWrEbBp7wgQ3aW5bf+xVtNaHvxvGvwOQMY8enFsTfgZ8YA4WTBwqeaFa6tUOC4/u7cQwTK2vlNZxpbATIOJhseOSi0ExD+8igyi4WU="
-   - secure: "lbql5U+YxidgVE9xyyL78hhkYMI1TfVfl1JYsV8zLwhiEF7hvi2cKYzJEuQjzc4nlAzKXP2iBrCzy5aE4mh/0P7wnHMGuD4l/ixdAlz+QQedK0siw3G9lt8j7Fsn/IucRhFu0k8kwltQsHtq2+E5eCsAqJkwxNPX0xshuV2x6Mk="
-  matrix:
-   - COVERAGE=0
-   - COVERAGE=1
-    
-addons:
-  coverity_scan:
-    project:
-      name: "paulsapps/SUDM"
-      description: "Build submitted via Travis CI"
-    notification_email: coverityscan@paulsapps.com
-    build_command_prepend: "cmake .."
-    build_command: "make -j4"
-    branch_pattern: coverity_scan
-
-compiler:
-  - clang
-  - gcc
-  
-before_install:
-  - sudo add-apt-repository ppa:boost-latest/ppa -y
-  - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
-  - if [ "$CXX" == "clang++" ]; then sudo add-apt-repository ppa:h-rayflood/llvm -y; fi
-  - sudo apt-get update
-  - sudo apt-get install --allow-unauthenticated boost1.55
-  - if [ "$CXX" == "g++" ]; then sudo apt-get install --allow-unauthenticated gcc-4.9; fi
-  - if [ "$CXX" == "g++" ]; then sudo apt-get install --allow-unauthenticated g++-4.9; fi
-  - if [ "$CXX" == "g++" ]; then sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 90; fi
-  - if [ "$CXX" == "g++" ]; then sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 90; fi
-  - if [ "$CXX" == "g++" ]; then sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-4.9 90; fi
-  - if [ "$CXX" == "g++" ]; then sudo update-alternatives --config gcc; fi
-  - if [ "$CXX" == "g++" ]; then sudo update-alternatives --config g++; fi
-  - if [ "$CXX" == "clang++" ]; then sudo apt-get install --allow-unauthenticated -qq clang-3.4; fi
-  - if [ "$CXX" == "clang++" ]; then export CXX="clang++-3.4"; fi
-  - if [ "$CXX" == "clang++" ]; then export CXX="clang++-3.4"; fi
-  - if [ "$CXX" == "g++" ]; then sudo apt-get install ruby1.9.1 ruby1.9.1-dev; fi
-  - if [ "$CXX" == "g++" ]; then sudo apt-get install rubygems1.9.1 irb1.9.1 ri1.9.1; fi
-  - if [ "$CXX" == "g++" ]; then rvmsudo  gem install coveralls-lcov; fi
-  - if [ "$CXX" == "g++" ]; then sudo apt-get install lcov; fi
-  - if [ "$CXX" == "g++" ]; then wget http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.11.orig.tar.gz; fi
-  - if [ "$CXX" == "g++" ]; then tar xf lcov_1.11.orig.tar.gz; fi
-  - if [ "$CXX" == "g++" ]; then sudo make -C lcov-1.11/ install; fi
-  - if [ "$CXX" == "g++" ]; then lcov --version; fi
-  - if [ "$CXX" == "g++" ]; then gcov --version; fi
-
-before_script:
-  - $CXX --version
-  - mkdir build
-  - cd build
-  
-after_success:
-  - if [[ "$CXX" == "g++" && "${COVERAGE}" == 1 ]]; then lcov --directory . --capture --output-file coverage.info; fi
-  - if [[ "$CXX" == "g++" && "${COVERAGE}" == 1 ]]; then lcov --remove coverage.info '*/googlemock/*' '/usr/*' --output-file coverage.info; fi
-  - if [[ "$CXX" == "g++" && "${COVERAGE}" == 1 ]]; then lcov --list coverage.info; fi
-  - if [[ "$CXX" == "g++" && "${COVERAGE}" == 1 ]]; then coveralls-lcov coverage.info; fi
-  
-script: 
-  - cmake ..
-  - if [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then make -j2; fi
-  - if [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then ctest --output-on-failure; fi
-

+ 0 - 198
lib/SUDM/CMakeLists.txt

@@ -1,198 +0,0 @@
-cmake_minimum_required(VERSION 2.6)
-
-project(SUDM)
-
-# Set to true when using SUDM as a submodule of another project such that only the lib is compiled
-option(SUDM_AS_LIB     "Build only lib"     FALSE)
-
-# For now, you'll need to place said files in the appropriate test dir
-# TODO: move this elsewhere?
-option(TEST_COPYRIGHTED_FILES "Enable tests against copyrighted files" FALSE)
-
-if (NOT SUDM_AS_LIB)
-	enable_testing()
-endif()
-
-# The version number
-set(VERSION_MAJOR 0)
-set(VERSION_MINOR 1)
-
-if (CMAKE_BUILD_TYPE STREQUAL "")
-  # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up
-  # differentiation between debug and release builds.
-  set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
-endif ()
-
-if (NOT SUDM_AS_LIB)
-	# On Linux gtest needs pthreads
-	if (UNIX)
-		find_package (Threads)
-	endif()
-
-	include_directories(
-		${CMAKE_CURRENT_SOURCE_DIR}/googlemock
-		${CMAKE_CURRENT_SOURCE_DIR}/googlemock/include
-		${CMAKE_CURRENT_SOURCE_DIR}/googlemock/gtest/include
-		${CMAKE_CURRENT_SOURCE_DIR}/googlemock/gtest
-	)
-
-	SET(gmock_src
-	${CMAKE_CURRENT_SOURCE_DIR}/googlemock/src/gmock-all.cc
-	${CMAKE_CURRENT_SOURCE_DIR}/googlemock/gtest/src/gtest-all.cc)
-	
-	add_library(gmock STATIC ${gmock_src})
-endif()
-
-if (MSVC)
-	# Build cpp files on all cores
-	SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /W4")
-	
-	# can't use the "secure" versions as they're Windows specific
-	add_definitions("/D\"_CRT_SECURE_NO_WARNINGS\"")
-	add_definitions("/D\"_SCL_SECURE_NO_WARNINGS\"")
-
-	add_definitions("/wd4290")
-else()
-	# Enable C++11, you may need to use -std=c++0x if using an older gcc compiler
-	if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
-		SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
-	else()
-		#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-unused-parameter -fPIC -Wall -Weffc++ -pedantic")
-                SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-unused-parameter -fPIC -Wall")
-		#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Wcast-align")
-		#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-qual  -Wchar-subscripts  -Wcomment -Wconversion")
-		#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdisabled-optimization")
-		#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wfloat-equal  -Wformat  -Wformat=2")
-		#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat-nonliteral -Wformat-security")
-		#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat-y2k")
-		#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wimport  -Winit-self")
-		#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Winvalid-pch")
-		#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunsafe-loop-optimizations -Wmissing-braces")
-		#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-field-initializers -Wmissing-format-attribute")
-		#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-include-dirs -Wmissing-noreturn")
-		#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpacked  -Wparentheses  -Wpointer-arith")
-		#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wredundant-decls -Wreturn-type")
-		#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsequence-point  -Wshadow -Wsign-compare  -Wstack-protector")
-		#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wstrict-aliasing -Wstrict-aliasing=2 -Wswitch  -Wswitch-default")
-		#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wswitch-enum -Wtrigraphs  -Wuninitialized")
-                SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wtrigraphs  -Wuninitialized")
-		SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunknown-pragmas  -Wunreachable-code -Wunused")
-		#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-function  -Wunused-label  -Wunused-parameter")
-		#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-value  -Wunused-variable  -Wvariadic-macros")
-		#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wvolatile-register-var  -Wwrite-strings")
-		
-		if (UNIX AND $ENV{COVERAGE}==1)
-                     message("Setting coverage compiler options")
-		     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0") # debug, no optimisation
-		     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") # enabling coverage
-		endif()
-		
-		# we dont want high warning levels on 3rd party things since we won't be fixing those warnings
-		set_source_files_properties(${gmock_src} PROPERTIES COMPILE_FLAGS -Wno-effc++)
-	endif()
-endif()
-
-SET(source
-decompiler/sudm.cpp
-decompiler/sudm.h
-decompiler/decompiler_codegen.cpp
-decompiler/decompiler_codegen.h
-decompiler/control_flow.cpp
-decompiler/control_flow.h
-decompiler/decompiler_disassembler.cpp
-decompiler/decompiler_disassembler.h
-decompiler/decompiler_engine.h
-decompiler/graph.cpp
-decompiler/graph.h
-decompiler/instruction.cpp
-decompiler/instruction.h
-decompiler/objectFactory.h
-decompiler/refcounted.h
-decompiler/simple_disassembler.cpp
-decompiler/simple_disassembler.h
-decompiler/stack.h
-decompiler/unknown_opcode_exception.cpp
-decompiler/unknown_opcode_exception.h
-decompiler/value.cpp
-decompiler/value.h
-decompiler/wrongtype.h
-decompiler/scummv6/codegen.cpp
-decompiler/scummv6/codegen.h
-decompiler/scummv6/disassembler.cpp
-decompiler/scummv6/disassembler.h
-decompiler/scummv6/engine.cpp
-decompiler/scummv6/engine.h
-decompiler/ff7_field/ff7_field_disassembler.cpp
-decompiler/ff7_field/ff7_field_disassembler.h
-decompiler/ff7_field/ff7_field_engine.cpp
-decompiler/ff7_field/ff7_field_engine.h
-decompiler/ff7_field/ff7_field_codegen.cpp
-decompiler/ff7_field/ff7_field_codegen.h
-#decompiler/ff7_world/ff7_world_disassembler.cpp
-#decompiler/ff7_world/ff7_world_disassembler.h
-#decompiler/ff7_world/ff7_world_engine.cpp
-#decompiler/ff7_world/ff7_world_engine.h
-#decompiler/ff7_world/ff7_world_codegen.cpp
-#decompiler/ff7_world/ff7_world_codegen.h
-common/algorithm.h
-common/noncopyable.h
-common/scummsys.h
-common/str.cpp
-common/str.h
-common/util.h
-common/binaryreader.h
-common/lzs.h
-common/make_unique.h
-)
-
-find_package(Boost COMPONENTS program_options filesystem thread date_time system chrono REQUIRED)
-
-include_directories(
-${Boost_INCLUDE_DIR}
-${CMAKE_CURRENT_SOURCE_DIR}
-${CMAKE_CURRENT_SOURCE_DIR}/common
-${CMAKE_CURRENT_SOURCE_DIR}/decompiler
-
-)
-add_definitions(-DBOOST_ALL_NO_LIB)
-add_definitions(-DBOOST_ALL_DYN_LINK)
-
-if (UNIX)
-	add_definitions(-DPOSIX)
-endif()
-
-ADD_LIBRARY(Sudm_Lib STATIC ${source})
-
-if (NOT SUDM_AS_LIB)
-	add_executable(Sudm
-	decompiler/decompiler.cpp
-	)
-	target_link_libraries(Sudm Sudm_Lib ${Boost_LIBRARIES})
-
-	set(safe_test_source
-	decompiler/test/cfg_test.cpp
-	decompiler/test/codegen.cpp
-	decompiler/test/disassembler_test.cpp
-	decompiler/test/disassembler/pasc.cpp
-	decompiler/test/disassembler/pasc.h
-	decompiler/test/disassembler/subopcode.cpp
-	decompiler/test/disassembler/subopcode.h
-	decompiler/test/main.cpp
-	decompiler/test/ff7_field_disasm_all_opcodes_by_category_test.cpp
-	decompiler/test/ff7_field_control_flow_test.cpp
-	decompiler/test/ff7_field_dummy_formatter.h
-	)
-	
-	set(unsafe_test_source
-	)		
-
-	if (TEST_COPYRIGHTED_FILES)
-		add_executable(Sudm_Test ${safe_test_source} ${unsafe_test_source})
-	else()
-		add_executable(Sudm_Test ${safe_test_source})
-	endif()
-	
-	target_link_libraries(Sudm_Test Sudm_Lib gmock ${Boost_LIBRARIES})
-
-	add_test(NAME Sudm_Test COMMAND Sudm_Test WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
-endif()

+ 0 - 340
lib/SUDM/LICENSE

@@ -1,340 +0,0 @@
-GNU GENERAL PUBLIC LICENSE
-                       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-                            Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Lesser General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-                    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-                            NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-                     END OF TERMS AND CONDITIONS
-
-            How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    {description}
-    Copyright (C) {year}  {fullname}
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License along
-    with this program; if not, write to the Free Software Foundation, Inc.,
-    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  {signature of Ty Coon}, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Lesser General
-Public License instead of this License.
-

+ 0 - 9
lib/SUDM/README.md

@@ -1,9 +0,0 @@
-#### Simple Universal Decompilation Machine [![Build Status](https://travis-ci.org/paulsapps/SUDM.svg?branch=master)](https://travis-ci.org/paulsapps/SUDM)  [![Coverity Scan Build Status](https://scan.coverity.com/projects/3895/badge.svg)](https://scan.coverity.com/projects/3895) [![Coverage Status](https://img.shields.io/coveralls/paulsapps/SUDM.svg)](https://coveralls.io/r/paulsapps/SUDM)
-
-This project aims to provide a decompiler framework for simple byte code languages that do not have specific structuring instructions (while/for/if).
-
-The idea is that you will implement a disassmebler that groups instructions into bespoke types (conditional jumps, unconditional jumps, load store, etc). Then SUDM will apply the generic structing. You'll also implement a code generator that will map a scripting languages kernel functions onto the target output, for example if the game calls function 0x28 you can output this as the string "do_save();". Additionally you can also apply extra CFG post processing.
-
-The initial goal is to support disassmeblers for Final Fantasy 7,8 and 9 "field" script bytecode, and a LUA back end (currently only C output is supported).
-
-This work is heavily based on Michael Madsen's decompiler work for SCUMMVM's decompiler.

+ 0 - 1
lib/SUDM/decompiler/.gitignore

@@ -1 +0,0 @@
-/doc/

部分文件因文件數量過多而無法顯示