Jelajahi Sumber

Invalid entity movement no longer crash the app.
Installer: Removed return from the middle of on_start functions, and fixed them everywhere else.

Iñigo Valentin 3 tahun lalu
induk
melakukan
aa34c0a83d

+ 150 - 350
V-Gears-Installer/src/ff7DataInstaller.cpp

@@ -66,8 +66,7 @@ FF7DataInstaller::FF7DataInstaller(
     output_dir_(output_dir),
     write_output_line(write_output_line)
 {
-    if (!application_.initOgre(true))
-        throw std::runtime_error("Ogre init failure");
+    if (!application_.initOgre(true)) throw std::runtime_error("Ogre init failure");
     Ogre::Log* default_log( Ogre::LogManager::getSingleton().getDefaultLog());
     assert( default_log );
     default_log->setLogDetail(Ogre::LL_LOW);
@@ -144,9 +143,7 @@ std::vector<std::string> materials_;
  */
 void TexToPng(const std::string name){
     Ogre::DataStreamPtr stream(
-      Ogre::ResourceGroupManager::getSingleton().openResource(
-        name, "FFVIITextures", true, NULL
-      )
+      Ogre::ResourceGroupManager::getSingleton().openResource(name, "FFVIITextures", true, NULL)
     );
     QGears::TexFile* tex = new QGears::TexFile();
     tex->Read(stream);
@@ -156,10 +153,9 @@ void TexToPng(const std::string name){
     );
     for (int y = 0; y < image_data->height; y ++){
         for (int x = 0; x < image_data->width; x ++){
-            // This is the position from which to read from the tex file colour
-            // data
-            // TODO: It doesn't work for non-square images. For example, the
-            // lower part of bxje is all wrong.
+            // This is the position from which to read from the tex file colour data
+            // TODO: It doesn't work for non-square images. For example, the lower part of bxje is
+            // all wrong.
             int i = (image_data->height * y) + x;
             image->setColourAt(
               Ogre::ColourValue(
@@ -209,34 +205,24 @@ static void ExportMesh(std::string outdir, const Ogre::MeshPtr &mesh){
           sub_mesh->getMaterialName())
         );
         if (mat != nullptr){
-            for (
-              size_t techs = 0; techs < mat->getNumTechniques(); techs ++
-            ){
+            for (size_t techs = 0; techs < mat->getNumTechniques(); techs ++){
                 Ogre::Technique* tech = mat->getTechnique(techs);
                 if (tech){
-                    for (
-                      size_t pass_num = 0;
-                      pass_num < tech->getNumPasses();
-                      pass_num ++
-                    ){
+                    for (size_t pass_num = 0; pass_num < tech->getNumPasses(); pass_num ++){
                         Ogre::Pass* pass = tech->getPass(pass_num);
                         if (pass){
                             for (
                               size_t texture_unit_num = 0;
-                              texture_unit_num
-                                < pass->getNumTextureUnitStates();
+                              texture_unit_num < pass->getNumTextureUnitStates();
                               texture_unit_num ++
                             ){
                                 Ogre::TextureUnitState* unit
                                   = pass->getTextureUnitState(texture_unit_num);
-                                if (
-                                  unit
-                                  && unit->getTextureName().empty() == false
-                                ){
+                                if (unit && unit->getTextureName().empty() == false){
                                     // Convert the texture from .tex to .png.
                                     TexToPng(unit->getTextureName());
-                                    // Ensure the output material script
-                                    // references png files rather than tex
+                                    // Ensure the output material script references png files
+                                    // rather than tex
                                     // files.
                                     Ogre::String base_name;
                                     QGears::StringUtil::splitBase(
@@ -251,13 +237,10 @@ static void ExportMesh(std::string outdir, const Ogre::MeshPtr &mesh){
                                     // TODO: obtain the "data" folder
                                     // programatically.
                                     boost::filesystem::copy_file(
+                                      "data/" + FieldModelDir() + "/" + base_name + ".png",
                                       "data/" + FieldModelDir() + "/"
-                                        + base_name + ".png",
-                                      "data/" + FieldModelDir() + "/"
-                                        + base_mesh_name + "_"
-                                        + base_name + ".png",
-                                        boost::filesystem::copy_option
-                                          ::overwrite_if_exists
+                                        + base_mesh_name + "_" + base_name + ".png",
+                                      boost::filesystem::copy_option::overwrite_if_exists
                                     );
                                     textures.insert(unit->getTextureName());
                                 }
@@ -266,12 +249,7 @@ static void ExportMesh(std::string outdir, const Ogre::MeshPtr &mesh){
                     }
                 }
             }
-            if (
-              std::count(
-                materials_.begin(), materials_.end(),
-                sub_mesh->getMaterialName()
-              ) == 0
-            ){
+            if (std::count(materials_.begin(), materials_.end(), sub_mesh->getMaterialName()) == 0){
                 //std::cout << "[MATERIAL] Writting material "
                 // << sub_mesh->getMaterialName() << std::endl;
                 mat_ser.queueForExport(mat);
@@ -286,10 +264,7 @@ static void ExportMesh(std::string outdir, const Ogre::MeshPtr &mesh){
         std::string tex_name = texture_name.c_str();
         try{
             Ogre::TexturePtr texture_ptr
-              = Ogre::TextureManager::getSingleton().load(
-                tex_name, "FFVIITextures" //"FFVII"
-              );
-
+              = Ogre::TextureManager::getSingleton().load(tex_name, "FFVIITextures" /*"FFVII"*/);
             Ogre::Image image;
             texture_ptr->convertToImage(image);
             Ogre::String base_name;
@@ -313,7 +288,6 @@ static void ExportMesh(std::string outdir, const Ogre::MeshPtr &mesh){
 static std::string FieldName(const std::string& name){return "ffvii_" + name;}
 
 void FF7DataInstaller::CreateDir(const std::string& path){
-
     QString target = QString::fromStdString(output_dir_ + path);
     QDir dir(target);
     if (!dir.mkpath(".")) throw std::runtime_error("Failed to mkpath");
@@ -341,12 +315,10 @@ class BaseFF7FieldScriptFormatter : public SUDM::IScriptFormatter{
          * @param spawn_points[in] The list of spawn points.
          */
         BaseFF7FieldScriptFormatter(
-          const std::string& field_name,
-          const std::vector<std::string>& field_id_to_name_lookup,
+          const std::string& field_name, const std::vector<std::string>& field_id_to_name_lookup,
           FieldSpawnPointsMap& spawn_points
         ) :
-          field_name_(field_name),
-          field_id_to_name_lookup_(field_id_to_name_lookup),
+          field_name_(field_name), field_id_to_name_lookup_(field_id_to_name_lookup),
           spawn_points_(spawn_points)
         {}
 
@@ -367,8 +339,7 @@ class BaseFF7FieldScriptFormatter : public SUDM::IScriptFormatter{
           const std::string& function_name, unsigned int address
         ) override{
             return
-              field_name_ + "_" + entity + "_" + function_name
-              + "_addr_" + std::to_string(address);
+              field_name_ + "_" + entity + "_" + function_name + "_addr_" + std::to_string(address);
         }
 
         /**
@@ -487,9 +458,7 @@ class FF7FieldScriptFormatter : public BaseFF7FieldScriptFormatter{
           const std::vector<std::string>& field_id_to_name_lookup,
           FieldSpawnPointsMap& spawn_points
         ) :
-          BaseFF7FieldScriptFormatter(
-            field_name, field_id_to_name_lookup, spawn_points
-          ),
+          BaseFF7FieldScriptFormatter(field_name, field_id_to_name_lookup, spawn_points),
           model_loader_(models)
         {}
 
@@ -505,10 +474,7 @@ class FF7FieldScriptFormatter : public BaseFF7FieldScriptFormatter{
         virtual std::string AnimationName(int char_id, int id) override{
             // Get the animation file name, then look up the friendly name of
             // the "raw" animation.
-            if (
-              static_cast<unsigned int>(char_id)
-              >= model_loader_->GetModels().size()
-            ){
+            if (static_cast<unsigned int>(char_id) >= model_loader_->GetModels().size()){
                 std::cerr << "FF7FieldScriptFormatter::AnimationName ERROR:"
                   << "Char ID " << char_id << " out of bounds" << std::endl;
                 return std::to_string(id);
@@ -516,10 +482,9 @@ class FF7FieldScriptFormatter : public BaseFF7FieldScriptFormatter{
             const auto& model_info = model_loader_->GetModels().at(char_id);
             if (static_cast<unsigned int>(id) >= model_info.animations.size()){
                 std::cerr << "FF7FieldScriptFormatter::AnimationName ERROR:"
-                  << "In field " << field_name_ << " the model "
-                  << model_info.name << " animation with ID " << id
-                  << " is out of bounds (" << model_info.animations.size() << ")"
-                  << std::endl;
+                  << "In field " << field_name_ << " the model " << model_info.name
+                  << " animation with ID " << id << " is out of bounds ("
+                  << model_info.animations.size() << ")" << std::endl;
                 return std::to_string(id);
             }
             const auto raw_name = model_info.animations.at(id).name;
@@ -650,21 +615,17 @@ static void FF7PcFieldToQGearsField(
     for (size_t i = 0; i < gateways.size(); i ++){
         const QGears::TriggersFile::Gateway& gateway = gateways[i];
         if (gateway.destination_field_id != INACTIVE_GATEWAY_ID){
-            const std::string gateway_entity_name
-              = "Gateway" + std::to_string(i);
+            const std::string gateway_entity_name = "Gateway" + std::to_string(i);
             gateway_script_data += CreateGateWayScript(
               gateway_entity_name,
-              FieldName(field_id_to_name_lookup.at(
-                gateway.destination_field_id
-              )),
+              FieldName(field_id_to_name_lookup.at(gateway.destination_field_id)),
               "Spawn_" + field->getName() + "_" + std::to_string(i)
             );
         }
     }
     const QGears::ModelListFilePtr& models = field->GetModelList();
     SUDM::FF7::Field::DecompiledScript decompiled;
-    FF7FieldScriptFormatter formatter(
-      field->getName(), models, field_id_to_name_lookup, spawn_map);
+    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();
@@ -681,8 +642,7 @@ static void FF7PcFieldToQGearsField(
             try{field_text_writter.Write(raw_field_data, field->getName());}
             catch (const std::out_of_range& ex){
                 write_output_line(
-                  "[ERROR] Failed to read texts from field " + field->getName()
-                  + ": " + ex.what()
+                  "[ERROR] Failed to read texts from field " + field->getName() + ": " + ex.what()
                 );
                 std::cerr << "[ERROR] Failed to read texts from field "
                   << field->getName() << ": " << ex.what() << std::endl;
@@ -690,8 +650,7 @@ static void FF7PcFieldToQGearsField(
         }
         else{
             write_output_line(
-              "[ERROR] Failed to open script file from field "
-              + field->getName() + " for writing."
+              "[ERROR] Failed to open script file from field " + field->getName() + " for writing."
             );
             std::cerr << "[ERROR] Failed to open script file from field "
               << field->getName() << "for writing." << std::endl;
@@ -699,82 +658,62 @@ static void FF7PcFieldToQGearsField(
     }
     catch (const ::InternalDecompilerError& ex){
         write_output_line(
-          "[ERROR] Internal decompiler error in field " + field->getName()
-          + ": " + ex.what()
+          "[ERROR] Internal decompiler error in field " + field->getName() + ": " + ex.what()
         );
         std::cerr << "[ERROR] Internal decompiler error in field "
           << field->getName() << ": " << ex.what() << std::endl;
     }
-    // Write out the map file which links all the other files together for a
-    // given field.
+    // Write out the map file which links all the other files together for a given field.
     {
         TiXmlDocument doc;
         std::unique_ptr<TiXmlElement> element(new TiXmlElement("map"));
         // Script.
-        std::unique_ptr<TiXmlElement> xml_script_element(
-          new TiXmlElement("script")
-        );
+        std::unique_ptr<TiXmlElement> xml_script_element(new TiXmlElement("script"));
         xml_script_element->SetAttribute(
           "file_name", FieldMapDir() + "/" + field->getName() + "/script.lua"
         );
         element->LinkEndChild(xml_script_element.release());
         // Background.
-        std::unique_ptr<TiXmlElement> xml_background_2d(
-          new TiXmlElement("background2d")
-        );
+        std::unique_ptr<TiXmlElement> xml_background_2d(new TiXmlElement("background2d"));
         xml_background_2d->SetAttribute(
           "file_name", FieldMapDir() + "/" + field->getName() + "/bg.xml"
         );
         element->LinkEndChild(xml_background_2d.release());
         // Walkmesh.
-        std::unique_ptr<TiXmlElement> xml_walkmesh(
-          new TiXmlElement("walkmesh")
-        );
+        std::unique_ptr<TiXmlElement> xml_walkmesh(new TiXmlElement("walkmesh"));
         xml_walkmesh->SetAttribute(
           "file_name", FieldMapDir() + "/" + field->getName() + "/wm.xml"
         );
         element->LinkEndChild(xml_walkmesh.release());
         // Forward direction (angle player moves when "up" is pressed)
-        std::unique_ptr<TiXmlElement> xml_forward_direction(
-          new TiXmlElement("movement_rotation")
-        );
+        std::unique_ptr<TiXmlElement> xml_forward_direction(new TiXmlElement("movement_rotation"));
         xml_forward_direction->SetAttribute(
           "degree", std::to_string(triggers->MovementRotation())
         );
         element->LinkEndChild(xml_forward_direction.release());
         // Get this fields Id.
-        const size_t this_field_id = FieldId(
-          field->getName(), field_id_to_name_lookup
-        );
-        // Use the ID to find the pre-computed list of gateways in all other
-        // fields that link to this field.
+        const size_t this_field_id = FieldId(field->getName(), field_id_to_name_lookup);
+        // Use the ID to find the pre-computed list of gateways in all other fields that link to
+        // this field.
         auto spawn_iterator = spawn_map.find(this_field_id);
         Ogre::Vector3 first_entity_point = Ogre::Vector3::ZERO;
 
-        // If none found it probably just means no other fields have doors
-        // to this one.
+        // If none found it probably just means no other fields have doors to this one.
         if (spawn_iterator != std::end(spawn_map)){
             const std::vector<SpawnPointDb::Record>& spawn_point_records
               = spawn_iterator->second.gateways_to_this_field;
             for (size_t i = 0; i < spawn_point_records.size(); i ++){
-                const QGears::TriggersFile::Gateway& gateway
-                  = spawn_point_records[i].gateway;
+                const QGears::TriggersFile::Gateway& gateway = spawn_point_records[i].gateway;
                 // Entity_point:
-                std::unique_ptr<TiXmlElement> xml_entity_point(
-                  new TiXmlElement("entity_point")
-                );
+                std::unique_ptr<TiXmlElement> xml_entity_point(new TiXmlElement("entity_point"));
                 if (spawn_point_records[i].from_script){
                     // Spawn points from map jumps have a another algorithm.
                     xml_entity_point->SetAttribute(
                       "name",
                       field_id_to_name_lookup.at(
-                        spawn_point_records[i].field_id) + "_"
-                        + spawn_point_records[i].entity_name + "_"
-                        + spawn_point_records[i].script_function_name + "_addr_"
-                        + std::to_string(
-                          spawn_point_records[i]
-                            .gateway_index_or_map_jump_address
-                        )
+                        spawn_point_records[i].field_id) + "_" + spawn_point_records[i].entity_name
+                        + "_" + spawn_point_records[i].script_function_name + "_addr_"
+                        + std::to_string(spawn_point_records[i].gateway_index_or_map_jump_address)
                       );
                 }
                 else{
@@ -783,65 +722,45 @@ static void FF7PcFieldToQGearsField(
                     xml_entity_point->SetAttribute(
                       "name",
                       "Spawn_"
-                      + field_id_to_name_lookup.at(
-                        spawn_point_records[i].field_id
-                      )
-                      + "_"
-                      + std::to_string(
-                        spawn_point_records[i].gateway_index_or_map_jump_address
-                      )
+                        + field_id_to_name_lookup.at(spawn_point_records[i].field_id)
+                        + "_"
+                        + std::to_string(spawn_point_records[i].gateway_index_or_map_jump_address)
                     );
                 }
                 const float downscaler_next = 128.0f * FieldScaleFactor(
                   scale_factor_map, gateway.destination_field_id
                 );
 
-                // Position Z is actually the target walkmesh triangle ID, so
-                // this is tiny bit more complex. Now "get the Z value of the
-                // triangle with that ID". Note that ID actually just means
-                // index.
-                unsigned int triangle_index = static_cast<unsigned int>(
-                  gateway.destination.z
-                );
+                // Position Z is actually the target walkmesh triangle ID, so this is tiny bit more
+                // complex. Now "get the Z value of the triangle with that ID". Note that ID
+                // actually just means index.
+                unsigned int triangle_index = static_cast<unsigned int>(gateway.destination.z);
                 if (
                   triangle_index >= field->GetWalkmesh()->GetTriangles().size()
                 ){
                     write_output_line(
-                      "[WARNING] In field " + field->getName()
-                      + ": Map jump triangle ("
+                      "[WARNING] In field " + field->getName() + ": Map jump triangle ("
                       + std::to_string(triangle_index) + ") out of bounds ("
-                      + std::to_string(
-                        field->GetWalkmesh()->GetTriangles().size()
-                      ) + ")"
+                      + std::to_string(field->GetWalkmesh()->GetTriangles().size()) + ")"
                     );
                     std::cerr << "[WARNING] In field " << field->getName()
-                      << ": Map jump triangle (" << triangle_index
-                      << ") out of bounds ("
-                      << field->GetWalkmesh()->GetTriangles().size() << ")"
-                      << std::endl;
+                      << ": Map jump triangle (" << triangle_index << ") out of bounds ("
+                      << field->GetWalkmesh()->GetTriangles().size() << ")" << std::endl;
                     triangle_index = 0;
                 }
                 const float z_of_triangle_with_id
                   = field->GetWalkmesh()->GetTriangles().at(triangle_index).a.z;
                 const Ogre::Vector3 position(
-                  gateway.destination.x / downscaler_next,
-                  gateway.destination.y / downscaler_next,
+                  gateway.destination.x / downscaler_next, gateway.destination.y / downscaler_next,
                   z_of_triangle_with_id
                 );
-                if (
-                  position != Ogre::Vector3::ZERO
-                  && first_entity_point == Ogre::Vector3::ZERO
-                ){
+                if (position != Ogre::Vector3::ZERO && first_entity_point == Ogre::Vector3::ZERO)
                     first_entity_point = position;
-                }
                 xml_entity_point->SetAttribute(
                   "position", Ogre::StringConverter::toString(position)
                 );
-                const float rotation
-                  = (360.0f * static_cast<float>(gateway.dir)) / 255.0f;
-                xml_entity_point->SetAttribute(
-                  "rotation", std::to_string(rotation)
-                );
+                const float rotation = (360.0f * static_cast<float>(gateway.dir)) / 255.0f;
+                xml_entity_point->SetAttribute("rotation", std::to_string(rotation));
                 element->LinkEndChild(xml_entity_point.release());
             }
         }
@@ -850,75 +769,57 @@ static void FF7PcFieldToQGearsField(
             if (char_id != -1){
                 const QGears::ModelListFile::ModelDescription& desc
                   = models->GetModels().at(char_id);
-                auto& animations = model_animation_db.ModelAnimations(
-                  desc.hrc_name
-                );
-                for (auto& anim : desc.animations){
-                    animations.insert(
-                      model_animation_db.NormalizeAnimationName(anim.name)
-                    );
-                }
-                std::unique_ptr<TiXmlElement> xml_entity_script(
-                  new TiXmlElement("entity_model")
-                );
+                auto& animations = model_animation_db.ModelAnimations(desc.hrc_name);
+                for (auto& anim : desc.animations)
+                    animations.insert(model_animation_db.NormalizeAnimationName(anim.name));
+                std::unique_ptr<TiXmlElement> xml_entity_script(new TiXmlElement("entity_model"));
                 xml_entity_script->SetAttribute("name", it.first);
-                // TODO: Add to list of HRC's to convert, obtain name of target
-                // converted .mesh file
+                // TODO: Add to list of HRC's to convert, obtain name of converted .mesh file.
                 auto lower_case_hrc_name = desc.hrc_name;
                 QGears::StringUtil::toLowerCase(lower_case_hrc_name);
                 xml_entity_script->SetAttribute(
                   "file_name",
-                  FieldModelDir() + "/"
-                  + model_animation_db.ModelMetaDataName(lower_case_hrc_name)
+                  FieldModelDir() + "/" + model_animation_db.ModelMetaDataName(lower_case_hrc_name)
                 );
                 if (desc.type == QGears::ModelListFile::PLAYER){
-                    // For player models the position is set manually  in the
-                    // xml because if a map is loaded manually this is where
-                    // the player will end up. Hence we set the position to the
-                    // first entity_point that we have.
+                    // For player models the position is set manually in the xml because if a map
+                    // is loaded manually this is where the player will end up. Hence we set the
+                    // position to the first entity_point that we have.
                     xml_entity_script->SetAttribute(
-                      "position",
-                      Ogre::StringConverter::toString(first_entity_point)
+                      "position", Ogre::StringConverter::toString(first_entity_point)
                     );
                 }
                 else{
                     xml_entity_script->SetAttribute(
-                      "position",
-                      Ogre::StringConverter::toString(Ogre::Vector3::ZERO)
+                      "position", Ogre::StringConverter::toString(Ogre::Vector3::ZERO)
                     );
                 }
                 xml_entity_script->SetAttribute("direction", "0");
                 // TODO: This isn't quite right, the models animation
                 // translation seems to be inverted?
+                xml_entity_script->SetAttribute("scale", "0.03125 0.03125 0.03125");
                 xml_entity_script->SetAttribute(
-                  "scale", "0.03125 0.03125 0.03125"
-                );
-                xml_entity_script->SetAttribute(
-                  "root_orientation",
-                  "0.7071067811865476 0.7071067811865476 0 0"
+                  "root_orientation", "0.7071067811865476 0.7071067811865476 0 0"
                 );
                 element->LinkEndChild(xml_entity_script.release());
             }
             else{
-                std::unique_ptr<TiXmlElement> xml_entity_script(
-                  new TiXmlElement("entity_script")
-                );
+                // TODO: Lines go here.
+                std::unique_ptr<TiXmlElement> xml_entity_script(new TiXmlElement("entity_script"));
                 xml_entity_script->SetAttribute("name", it.first);
                 element->LinkEndChild(xml_entity_script.release());
             }
         }
-        const float downscaler_this = 128.0f * FieldScaleFactor(
-          scale_factor_map, this_field_id
-        );
+        const float downscaler_this = 128.0f * FieldScaleFactor(scale_factor_map, this_field_id);
         const auto& gateways = triggers->GetGateways();
         for (size_t i = 0; i < gateways.size(); i ++){
             const QGears::TriggersFile::Gateway& gateway = gateways[i];
             // If non-inactive gateway:
             if (gateway.destination_field_id != INACTIVE_GATEWAY_ID){
-                std::unique_ptr<TiXmlElement> xml_entity_trigger(new TiXmlElement("entity_trigger"));
-                xml_entity_trigger->SetAttribute(
-                  "name", "Gateway" + std::to_string(i)
+                std::unique_ptr<TiXmlElement> xml_entity_trigger(
+                  new TiXmlElement("entity_trigger")
                 );
+                xml_entity_trigger->SetAttribute("name", "Gateway" + std::to_string(i));
                 xml_entity_trigger->SetAttribute(
                   "point1",
                   Ogre::StringConverter::toString(
@@ -943,21 +844,15 @@ static void FF7PcFieldToQGearsField(
             }
         }
         doc.LinkEndChild(element.release());
-        doc.SaveFile(
-          out_dir + "/" + FieldMapDir() + "/" + field->getName() + "/map.xml"
-        );
+        doc.SaveFile(out_dir + "/" + FieldMapDir() + "/" + field->getName() + "/map.xml");
         const QGears::PaletteFilePtr& pal = field->GetPalette();
         const QGears::BackgroundFilePtr& bg = field->GetBackground();
         std::unique_ptr<Ogre::Image> bg_image(bg->CreateImage(pal));
         bg_image->encode("png");
-        bg_image->save(
-          out_dir + "/" + FieldMapDir() + "/" + field->getName() + "/tiles.png"
-        );
+        bg_image->save(out_dir + "/" + FieldMapDir() + "/" + field->getName() + "/tiles.png");
         {
             TiXmlDocument doc;
-            std::unique_ptr<TiXmlElement> element(
-              new TiXmlElement("background2d")
-            );
+            std::unique_ptr<TiXmlElement> element(new TiXmlElement("background2d"));
             // Magic constants.
             const int BG_SCALE_UP_FACTOR = 3;
             const int BG_PSX_SCREEN_WIDTH = 320;
@@ -965,35 +860,20 @@ static void FF7PcFieldToQGearsField(
             // Get texture atlas size.
             const int width = bg_image->getWidth();
             const int height = bg_image->getHeight();
-            const QGears::CameraMatrixFilePtr& camera_matrix
-              = field->GetCameraMatrix();
+            const QGears::CameraMatrixFilePtr& camera_matrix = field->GetCameraMatrix();
             const Ogre::Vector3 position
-              = camera_matrix->GetPosition()
-                / FieldScaleFactor(scale_factor_map, this_field_id);
-            const Ogre::Quaternion orientation
-              = camera_matrix->GetOrientation();
+              = camera_matrix->GetPosition() / FieldScaleFactor(scale_factor_map, this_field_id);
+            const Ogre::Quaternion orientation = camera_matrix->GetOrientation();
             const Ogre::Degree fov
               = camera_matrix->GetFov(static_cast<float>(BG_PSX_SCREEN_HEIGHT));
-            const int min_x
-              = triggers->GetCameraRange().left * BG_SCALE_UP_FACTOR;
-            const int min_y
-              = triggers->GetCameraRange().top * BG_SCALE_UP_FACTOR;
-            const int max_x
-              = triggers->GetCameraRange().right * BG_SCALE_UP_FACTOR;
-            const int max_y
-              = triggers->GetCameraRange().bottom * BG_SCALE_UP_FACTOR;
-            element->SetAttribute(
-              "image", FieldMapDir() + "/" + field->getName() + "/tiles.png"
-            );
-            element->SetAttribute(
-              "position", Ogre::StringConverter::toString(position)
-            );
-            element->SetAttribute(
-              "orientation", Ogre::StringConverter::toString(orientation)
-            );
-            element->SetAttribute(
-              "fov", Ogre::StringConverter::toString(fov)
-            );
+            const int min_x = triggers->GetCameraRange().left * BG_SCALE_UP_FACTOR;
+            const int min_y = triggers->GetCameraRange().top * BG_SCALE_UP_FACTOR;
+            const int max_x = triggers->GetCameraRange().right * BG_SCALE_UP_FACTOR;
+            const int max_y = triggers->GetCameraRange().bottom * BG_SCALE_UP_FACTOR;
+            element->SetAttribute("image", FieldMapDir() + "/" + field->getName() + "/tiles.png");
+            element->SetAttribute("position", Ogre::StringConverter::toString(position));
+            element->SetAttribute("orientation", Ogre::StringConverter::toString(orientation));
+            element->SetAttribute("fov", Ogre::StringConverter::toString(fov));
             element->SetAttribute(
               "range",
               std::to_string(min_x) + " " + std::to_string(min_y) + " "
@@ -1006,54 +886,31 @@ static void FF7PcFieldToQGearsField(
             );
             // Write out the *_BG.XML data.
             auto& layers = bg->GetLayers();
-            for (const auto& layer : layers)
-            {
-                // TODO: Should only the tiles to construct enabled layers be
-                // outputted?
+            for (const auto& layer : layers){
+                // TODO: Should only the tiles to construct enabled layers be outputted?
                 //  if (layer.enabled){
 
-                for (
-                  const QGears::BackgroundFile::SpriteData& sprite
-                    : layer.sprites
-                ){
-                    std::unique_ptr<TiXmlElement> xml_element(
-                      new TiXmlElement("tile")
-                    );
+                for (const QGears::BackgroundFile::SpriteData& sprite : layer.sprites){
+                    std::unique_ptr<TiXmlElement> xml_element(new TiXmlElement("tile"));
                     xml_element->SetAttribute(
                       "destination",
-                      Ogre::StringConverter::toString(
-                        sprite.dst.x * BG_SCALE_UP_FACTOR
-                      ) + " "
-                      + Ogre::StringConverter::toString(
-                        sprite.dst.y * BG_SCALE_UP_FACTOR
-                      )
+                      Ogre::StringConverter::toString(sprite.dst.x * BG_SCALE_UP_FACTOR) + " "
+                      + Ogre::StringConverter::toString(sprite.dst.y * BG_SCALE_UP_FACTOR)
                     );
                     xml_element->SetAttribute(
-                      "width",
-                      Ogre::StringConverter::toString(
-                        sprite.width * BG_SCALE_UP_FACTOR
-                      )
+                      "width", Ogre::StringConverter::toString(sprite.width * BG_SCALE_UP_FACTOR)
                     );
                     xml_element->SetAttribute(
-                      "height",
-                      Ogre::StringConverter::toString(
-                        sprite.height * BG_SCALE_UP_FACTOR
-                      )
+                      "height", Ogre::StringConverter::toString(sprite.height * BG_SCALE_UP_FACTOR)
                     );
-                    // Each tile is added to a big texture atlas with hard
-                    // coded size of 1024x1024, convert UV's to the 0.0f to
-                    // 1.0f range.
-                    const float u0
-                      = static_cast<float>(sprite.src.x) / bg_image->getWidth();
-                    const float v0
-                      = static_cast<float>(sprite.src.y)
-                        / bg_image->getHeight();
+                    // Each tile is added to a big texture atlas with hard coded size of 1024x1024,
+                    // convert UV's to the 0.0f to 1.0f range.
+                    const float u0 = static_cast<float>(sprite.src.x) / bg_image->getWidth();
+                    const float v0 = static_cast<float>(sprite.src.y) / bg_image->getHeight();
                     const float u1
-                      = static_cast<float>(sprite.src.x + sprite.width)
-                        / bg_image->getWidth();
+                      = static_cast<float>(sprite.src.x + sprite.width) / bg_image->getWidth();
                     const float v1
-                      = static_cast<float>(sprite.src.y + sprite.height)
-                        / bg_image->getHeight();
+                      = static_cast<float>(sprite.src.y + sprite.height) / bg_image->getHeight();
                     xml_element->SetAttribute(
                       "uv",
                       Ogre::StringConverter::toString(u0) + " "
@@ -1061,20 +918,17 @@ static void FF7PcFieldToQGearsField(
                       + Ogre::StringConverter::toString(u1) + " "
                       + Ogre::StringConverter::toString(v1)
                     );
+                    // TODO: It works (on FFVII PC), but why this number?
                     xml_element->SetAttribute(
                       "depth",
-                      Ogre::StringConverter::toString(
-                        // TODO: It works (on FFVII PC), but why this number?
-                        static_cast<float>(sprite.depth) * (0.03125f) // ??
-                      )
+                      Ogre::StringConverter::toString(static_cast<float>(sprite.depth) * (0.03125f))
                     );
                     // TODO: Copied from DatFile::AddTile.
                     // Add to common method.
                     Ogre::String blending_str = "";
                     if (sprite.blending == 0) blending_str = "alpha";
                     // 3 is source + 0.25 * destination:
-                    else if (sprite.blending == 1 || sprite.blending == 3)
-                        blending_str = "add";
+                    else if (sprite.blending == 1 || sprite.blending == 3) blending_str = "add";
                     else if (sprite.blending == 2) blending_str = "subtract";
                     // TODO: Should probably throw to fail conversion:
                     else blending_str = "unknown";
@@ -1084,9 +938,7 @@ static void FF7PcFieldToQGearsField(
                 //}
             }
             doc.LinkEndChild(element.release());
-            doc.SaveFile(
-              out_dir + "/" + FieldMapDir() + "/" + field->getName() + "/bg.xml"
-            );
+            doc.SaveFile(out_dir + "/" + FieldMapDir() + "/" + field->getName() + "/bg.xml");
         }
     }
     {
@@ -1095,33 +947,17 @@ static void FF7PcFieldToQGearsField(
         TiXmlDocument doc;
         std::unique_ptr<TiXmlElement> element(new TiXmlElement("walkmesh"));
         for (QGears::WalkmeshFile::Triangle& tri : walkmesh->GetTriangles()){
-            std::unique_ptr<TiXmlElement> xml_element(
-              new TiXmlElement("triangle")
-            );
-            xml_element->SetAttribute(
-              "a", Ogre::StringConverter::toString(tri.a)
-            );
-            xml_element->SetAttribute(
-              "b", Ogre::StringConverter::toString(tri.b)
-            );
-            xml_element->SetAttribute(
-              "c", Ogre::StringConverter::toString(tri.c)
-            );
-            xml_element->SetAttribute(
-              "a_b", std::to_string(tri.access_side[0])
-            );
-            xml_element->SetAttribute(
-              "b_c", std::to_string(tri.access_side[1])
-            );
-            xml_element->SetAttribute(
-              "c_a", std::to_string(tri.access_side[2])
-            );
+            std::unique_ptr<TiXmlElement> xml_element(new TiXmlElement("triangle"));
+            xml_element->SetAttribute("a", Ogre::StringConverter::toString(tri.a));
+            xml_element->SetAttribute("b", Ogre::StringConverter::toString(tri.b));
+            xml_element->SetAttribute("c", Ogre::StringConverter::toString(tri.c));
+            xml_element->SetAttribute("a_b", std::to_string(tri.access_side[0]));
+            xml_element->SetAttribute("b_c", std::to_string(tri.access_side[1]));
+            xml_element->SetAttribute("c_a", std::to_string(tri.access_side[2]));
             element->LinkEndChild(xml_element.release());
         }
         doc.LinkEndChild(element.release());
-        doc.SaveFile(
-          out_dir + "/" + FieldMapDir() + "/" + field->getName() + "/wm.xml"
-        );
+        doc.SaveFile(out_dir + "/" + FieldMapDir() + "/" + field->getName() + "/wm.xml");
     }
     maps.insert(field->getName());
 }
@@ -1139,13 +975,10 @@ class FF7FieldScriptGatewayCollector : public BaseFF7FieldScriptFormatter{
          * Cosntructor.
          */
         FF7FieldScriptGatewayCollector(
-          const std::string& field_name,
-          const std::vector<std::string>& field_id_to_name_lookup,
+          const std::string& field_name, const std::vector<std::string>& field_id_to_name_lookup,
           FieldSpawnPointsMap& spawn_points, size_t this_field_id
         ) :
-          BaseFF7FieldScriptFormatter(
-            field_name,field_id_to_name_lookup, spawn_points
-          ),
+          BaseFF7FieldScriptFormatter(field_name,field_id_to_name_lookup, spawn_points),
           field_id_(this_field_id)
         {}
 
@@ -1166,9 +999,8 @@ class FF7FieldScriptGatewayCollector : public BaseFF7FieldScriptFormatter{
          * @param angle[in] Orientation at which to spawn.
          */
         virtual void AddSpawnPoint(
-          unsigned int map_id, const std::string& entity,
-          const std::string& function_name, unsigned int address,
-          int x, int y, int z, int angle
+          unsigned int map_id, const std::string& entity, const std::string& function_name,
+          unsigned int address, int x, int y, int z, int angle
         ) override {
             auto it = spawn_points_.find(map_id);
             QGears::TriggersFile::Gateway gw = {};
@@ -1178,8 +1010,7 @@ class FF7FieldScriptGatewayCollector : public BaseFF7FieldScriptFormatter{
             gw.destination.z = z;
             gw.dir = angle;
             if (it != std::end(spawn_points_)){
-                // Add to the list of gateways that link to
-                // destination_field_id.
+                // Add to the list of gateways that link to destination_field_id.
                 SpawnPointDb::Record rec;
                 rec.from_script = true;
                 rec.field_id = field_id_;
@@ -1227,15 +1058,12 @@ class FF7FieldScriptGatewayCollector : public BaseFF7FieldScriptFormatter{
  * of this map.
  */
 static void CollectSpawnPoints(
-  QGears::FLevelFilePtr& field,
-  const std::vector<std::string>& field_id_to_name_lookup,
+  QGears::FLevelFilePtr& field, const std::vector<std::string>& field_id_to_name_lookup,
   FieldSpawnPointsMap& spawn_points
 ){
-    const size_t this_field_id = FieldId(
-      field->getName(), field_id_to_name_lookup
-    );
-    // Decompile the script just so the MAPJUMPs can be collected. This is
-    // needed to construct the full list of entries to each field.
+    const size_t this_field_id = FieldId(field->getName(), field_id_to_name_lookup);
+    // Decompile the script just so the MAPJUMPs can be collected. This is needed to construct the
+    // full list of entries to each field.
     try{
         // Get the raw script bytes.
         SUDM::FF7::Field::DecompiledScript decompiled;
@@ -1245,13 +1073,11 @@ static void CollectSpawnPoints(
           field->getName(), field_id_to_name_lookup, spawn_points, this_field_id
         );
         decompiled = SUDM::FF7::Field::Decompile(
-          field->getName(), raw_field_data, formatter,
-          "", "EntityContainer = {}\n\n"
+          field->getName(), raw_field_data, formatter, "", "EntityContainer = {}\n\n"
         );
     }
     catch (const ::InternalDecompilerError& ex){
-        std::cerr << "CollectSpawnPoints: InternalDecompilerError: "
-          << ex.what() << std::endl;
+        std::cerr << "CollectSpawnPoints: InternalDecompilerError: " << ex.what() << std::endl;
     }
     const QGears::TriggersFilePtr& triggers = field->GetTriggers();
     const auto& gateways = triggers->GetGateways();
@@ -1379,9 +1205,7 @@ void FF7DataInstaller::InitCollectSpawnAndScaleFactors(){
     CreateDir(FieldMapDir());
     CreateDir(FieldModelDir());
     // List what's in the LGP archive.
-    flevel_file_list_ = application_.ResMgr()->listResourceNames(
-      "FFVIIFields", "*"
-    );
+    flevel_file_list_ = application_.ResMgr()->listResourceNames("FFVIIFields", "*");
     // Load the map list field.
     QGears::MapListFilePtr map_list
       = QGears::MapListFileManager::GetSingleton().load(
@@ -1427,9 +1251,7 @@ void FF7DataInstaller::CollectionFieldSpawnAndScaleFactors(){
         field_.reset();
         iterator_counter_ = 0;
         installation_state_ = CONVERT_FIELDS;
-        field_text_writer_.Begin(
-          output_dir_ + "/texts/english/dialogs_mission1.xml"
-        );
+        field_text_writer_.Begin(output_dir_ + "/texts/english/dialogs_mission1.xml");
     }
 }
 
@@ -1441,24 +1263,23 @@ void FF7DataInstaller::ConvertFieldsIteration(){
         // Exclude things that are not fields.
         if (IsAFieldFile(resource_name)){
             if (/*IsTestField(resource_name) &&*/ !WillCrash(resource_name)){
+            // TODO: DEBUG: Only test fields
+            //if (IsTestField(resource_name) && !WillCrash(resource_name)){
                 //write_output_line("Converting field " + resource_name);
-                //std::cout << " - Converting field: " << resource_name
-                //  << std::endl;
+                //std::cout << " - Converting field: " << resource_name << std::endl;
                 CreateDir(FieldMapDir() + "/" + resource_name);
                 QGears::FLevelFilePtr field
                   = QGears::LZSFLevelFileManager::GetSingleton().load(
                     resource_name, "FFVIIFields"
                   ).staticCast<QGears::FLevelFile>();
                 FF7PcFieldToQGearsField(
-                  field_text_writer_, field, output_dir_, map_list_,
-                  spawn_points_, scale_factors_, used_models_and_anims_,
-                  converted_map_list_, write_output_line
+                  field_text_writer_, field, output_dir_, map_list_, spawn_points_, scale_factors_,
+                  used_models_and_anims_, converted_map_list_, write_output_line
                 );
             }
             else{
                 write_output_line(
-                  "[ERROR] Skip field " + resource_name
-                  + " due to crash or hang issue."
+                  "[ERROR] Skip field " + resource_name + " due to crash or hang issue."
                 );
                 std::cerr << "[ERROR] Skip field: " << resource_name
                   << " due to crash or hang issue." << std::endl;
@@ -1492,9 +1313,7 @@ void FF7DataInstaller::WriteMapsXmlIteration(){
         write_output_line("Writing field " + FieldName(map));
         std::unique_ptr<TiXmlElement> xml_element(new TiXmlElement("map"));
         xml_element->SetAttribute("name", FieldName(map));
-        xml_element->SetAttribute(
-          "file_name", FieldMapDir() + "/" + map + "/map.xml"
-        );
+        xml_element->SetAttribute("file_name", FieldMapDir() + "/" + map + "/map.xml");
         element_->LinkEndChild(xml_element.release());
         iterator_counter_++;
         converted_map_list_iterator_++;
@@ -1515,9 +1334,7 @@ void FF7DataInstaller::ConvertFieldModelsBegin(){
     field_models_lgp_ = std::make_unique<ScopedLgp>(
       application_.getRoot(), input_dir_ + "field/char.lgp", "LGP", "FFVII"
     );
-    field_model_file_list_ = application_.ResMgr()->listResourceNames(
-      "FFVII", "*"
-    );
+    field_model_file_list_ = application_.ResMgr()->listResourceNames("FFVII", "*");
     iterator_counter_ = 0;
     installation_state_ = CONVERT_FIELD_MODELS;
     iterator_counter_ = 0;
@@ -1529,41 +1346,26 @@ void FF7DataInstaller::ConvertFieldModelsIteration(){
     progress_step_num_elements_ = used_models_and_anims_.map.size();
     if (model_animation_map_iterator_ != used_models_and_anims_.map.end()){
         if (conversion_step_ == 0){
-            write_output_line(
-              "Converting model " + model_animation_map_iterator_->first
-            );
+            write_output_line("Converting model " + model_animation_map_iterator_->first);
             conversion_step_++;
         }
         else{
             try{
-                Ogre::ResourcePtr hrc
-                  = QGears::HRCFileManager::GetSingleton().load(
+                Ogre::ResourcePtr hrc = QGears::HRCFileManager::GetSingleton().load(
                     model_animation_map_iterator_->first, "FFVII"
                   );
                 Ogre::String base_name;
-                QGears::StringUtil::splitBase(
-                  model_animation_map_iterator_->first, base_name
-                );
-                auto mesh_name
-                  = QGears::FF7::NameLookup::model(base_name) + ".mesh";
-
-                Ogre::MeshPtr mesh(Ogre::MeshManager::getSingleton().load(
-                  mesh_name, "FFVII"
-                ));
+                QGears::StringUtil::splitBase(model_animation_map_iterator_->first, base_name);
+                auto mesh_name = QGears::FF7::NameLookup::model(base_name) + ".mesh";
+                Ogre::MeshPtr mesh(Ogre::MeshManager::getSingleton().load(mesh_name, "FFVII"));
                 Ogre::SkeletonPtr skeleton(mesh->getSkeleton());
                 for (auto& anim : model_animation_map_iterator_->second){
-                    QGears::AFileManager &afl_mgr(
-                      QGears::AFileManager::GetSingleton()
-                    );
-                    QGears::AFilePtr a
-                      = afl_mgr.load(anim, "FFVII").staticCast<QGears::AFile>();
-                    // Convert the FF7 name to a more readable name set in the
-                    // meta data.
+                    QGears::AFileManager &afl_mgr(QGears::AFileManager::GetSingleton());
+                    QGears::AFilePtr a = afl_mgr.load(anim, "FFVII").staticCast<QGears::AFile>();
+                    // Convert the FF7 name to a more readable name set in the meta data.
                     Ogre::String base_name;
                     QGears::StringUtil::splitBase(anim, base_name);
-                    a->AddTo(
-                      skeleton, QGears::FF7::NameLookup::Animation(base_name)
-                    );
+                    a->AddTo(skeleton, QGears::FF7::NameLookup::Animation(base_name));
                 }
                 ExportMesh(output_dir_ + "/" + FieldModelDir() + "/", mesh);
             }
@@ -1573,8 +1375,7 @@ void FF7DataInstaller::ConvertFieldModelsIteration(){
                   + model_animation_map_iterator_->first + ": " + ex.what()
                 );
                 std::cerr << "[ERROR] Ogre exception converting model "
-                  << model_animation_map_iterator_->first <<": " << ex.what()
-                  << std::endl;
+                  << model_animation_map_iterator_->first <<": " << ex.what() << std::endl;
             }
             catch (const std::exception& ex){
                 write_output_line(
@@ -1582,8 +1383,7 @@ void FF7DataInstaller::ConvertFieldModelsIteration(){
                   + model_animation_map_iterator_->first + ": " + ex.what()
                 );
                 std::cerr << "[ERROR] Exception converting model "
-                  << model_animation_map_iterator_->first << ": " << ex.what()
-                  << std::endl;
+                  << model_animation_map_iterator_->first << ": " << ex.what() << std::endl;
             }
             iterator_counter_++;
             model_animation_map_iterator_++;

+ 4 - 2
V-Gears/src/core/DialogsManager.cpp

@@ -75,8 +75,10 @@ void DialogsManager::Initialise(){
         data->widget = widget;
         data->window = widget->GetChild("Window");
         data->text_area = text_area;
-        data->text_area->SetTextPrintSpeed(256);
-        data->text_area->SetTextScrollTime(0.267f);
+        //data->text_area->SetTextPrintSpeed(256);
+        data->text_area->SetTextPrintSpeed(25);
+        //data->text_area->SetTextScrollTime(0.267f);
+        data->text_area->SetTextScrollTime(0.1f);
         data->cursor = widget->GetChild("Cursor");
         if (data->cursor != NULL)
             data->cursor->GetY(data->cursor_percent_y, data->cursor_y);

+ 7 - 2
V-Gears/src/core/EntityManager.cpp

@@ -13,6 +13,7 @@
  * GNU General Public License for more details.
  */
 
+#include <cmath>
 #include <OgreEntity.h>
 #include <OgreRoot.h>
 #include <OgreViewport.h>
@@ -1322,7 +1323,10 @@ void EntityManager::SetNextOffsetStep(Entity* entity){
     Ogre::Vector3 start = entity->GetOffsetPositionStart();
     Ogre::Vector3 end = entity->GetOffsetPositionEnd();
     float x = current / total;
-    float smooth_modifier = (type == AT_SMOOTH) ? -2 * x * x * x + 3 * x * x : x;
+    // Prevent division by 0:
+    if (std::isnan(x)) x = 0.0f;
+    float smooth_modifier
+      = (type == AT_SMOOTH) ? -2 * x * x * x + 3 * x * x : x;
     Ogre::Vector3 offset = start + (end - start) * smooth_modifier;
     entity->SetOffset(offset);
     if (current == total) entity->UnsetOffset();
@@ -1338,7 +1342,8 @@ void EntityManager::SetNextTurnStep(Entity* entity){
     Ogre::Degree start = entity->GetTurnDirectionStart();
     Ogre::Degree end = entity->GetTurnDirectionEnd();
     float x = current / total;
-    float smooth_modifier = (type == AT_SMOOTH) ? -2 * x * x * x + 3 * x * x : x;
+    float smooth_modifier
+      = (type == AT_SMOOTH) ? -2 * x * x * x + 3 * x * x : x;
     Ogre::Degree rotation = start + (end - start) * smooth_modifier;
     entity->SetRotation(rotation);
     if (current == total) entity->UnsetTurn();

+ 80 - 69
lib/SUDM/decompiler/ff7_field/ff7_field_codegen.cpp

@@ -8,7 +8,7 @@ void FF7::FF7CodeGenerator::onBeforeStartFunction(const Function& func)
     FunctionMetaData metaData(func._metadata);
     if (metaData.IsStart())
     {
-        addOutputLine("EntityContainer[ \"" + metaData.EntityName() + "\" ] = {", false, true);
+        addOutputLine("EntityContainer[\"" + metaData.EntityName() + "\"] = {", false, true);
         if (metaData.CharacterId() != -1)
         {
             addOutputLine(metaData.EntityName() + " = nil,");
@@ -48,117 +48,128 @@ void FF7::FF7CodeGenerator::onEndFunction(const Function& func)
 std::string FF7::FF7CodeGenerator::constructFuncSignature(const Function &func)
 {
     // Generate name
-    return func._name + " = function( self )";
+    return func._name + " = function(self)";
 }
 
-void FF7::FF7SimpleCodeGenerator::generate(InstVec& insts, const Graph& /*g*/)
-{
-    // TODO: yes, this is a big monolithic whatever. it's also WIP and i will be breaking it into digestable chunks when it's ready :D
+void FF7::FF7SimpleCodeGenerator::generate(InstVec& insts, const Graph& /*g*/){
+    // TODO: Break into parts
 
     auto instruction = insts.begin();
     
-    std::vector<std::pair<Function&, InstVec>> functionsWithBodies;
-    for (auto function = _engine->_functions.begin(); function != _engine->_functions.end(); ++function)
-    {
+    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);
-        }
-        functionsWithBodies.push_back(std::pair<Function&, InstVec> { function->second, body });
+        functions_with_bodies.push_back(std::pair<Function&, InstVec> {function->second, body});
     }
 
-    for (auto function = functionsWithBodies.begin(); function != functionsWithBodies.end(); ++function)
-    {
+    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())
-            {
+        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() });
-                }
+                if (label == labels.end()) labels.insert({targetAddr, InstVec()});
                 labels[targetAddr].push_back(*instruction);
             }
         }
 
-        std::string last_instruction = "";
-        for (auto instruction = function->second.begin(); instruction != function->second.end(); ++instruction)
-        {
+        // Implemented instructions.
+        for (
+          auto instruction = function->second.begin();
+          instruction != function->second.end();
+          ++instruction
+        ){
             auto label = labels.find((*instruction)->_address);
-            if (label != labels.end())
-            {
-                bool needLabel = false, needNewline = false;
-                for (auto origin = label->second.begin(); origin != label->second.end(); ++origin)
-                {
-                    if ((*origin)->isCondJump())
-                    {
+            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);
-                        needNewline = true;
-                    }
-                    else
-                    {
-                        needLabel = true;
+                        needs_new_line = true;
                     }
+                    else needs_label = true;
                 }
 
-                if (needNewline)
-                {
-                    addOutputLine("");
-                }
-                
-                if (needLabel)
-                {
+                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 ((*instruction)->isCondJump())
-            {
-                addOutputLine((boost::format("if (%s) then") % stack.pop()->getString()).str(), false, true);
+            if ((*instruction)->isCondJump()){
+                addOutputLine(
+                  (boost::format("if (%s) then") % stack.pop()->getString()).str(), false, true
+                );
 
-                // If there are no more instructions then ensure end is outputted
-                if (instruction + 1 == std::end(function->second))
-                {
+                // If there are no more instructions then ensure end is outputted.
+                if (instruction + 1 == std::end(function->second)){
                     addOutputLine("end", true, false);
                 }
             }
-            else if ((*instruction)->isUncondJump())
-            {
-                addOutputLine((boost::format("goto label_0x%1$X") % (*instruction)->getDestAddress()).str());
+            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");
+                }
+                else{
+                    addOutputLine(
+                      (boost::format("goto label_0x%1$X") % (*instruction)->getDestAddress()).str()
+                    );
+                }
             }
-            // else, was already output'd
+            // Else, already output'd.
         }
 
-        if ("return 0" != mLines.at(mLines.size() - 1)._line)
-            addOutputLine("return 0 -- Missing original return", false, false);
-
+        if (
+          "return 0" != mLines.at(mLines.size() - 1)._line
+          && "do return 0 end" != mLines.at(mLines.size() - 1)._line
+        ){
+            /*if (function->first._name == "Init"){
+                addOutputLine("--do return 0 end -- INIT return, omit.", false, false);
+            }
+            addOutputLine("-- " + function->first._name + ": Missing original RET", false, false);
+            addOutputLine("--LAST --" + mLines.at(mLines.size() - 1)._line + "--", false, false);*/
+            addOutputLine("do return 0 end", false, false);
+        }
         onEndFunction(function->first);
     }
 
-    for (auto i = mLines.begin(); i != mLines.end(); ++i)
-    {
-        if (i->_unindentBefore)
-        {
+    for (auto i = mLines.begin(); i != mLines.end(); ++i){
+        if (i->_unindentBefore){
             assert(_indentLevel > 0);
-            _indentLevel--;
+            _indentLevel --;
         }
         _output << indentString(i->_line) << std::endl;
-        if (i->_indentAfter)
-        {
-            _indentLevel++;
-        }
+        if (i->_indentAfter) _indentLevel++;
     }
 }
 
@@ -178,7 +189,7 @@ void FF7::FF7SimpleCodeGenerator::onBeforeStartFunction(const Function& func)
     FunctionMetaData metaData(func._metadata);
     if (metaData.IsStart())
     {
-        addOutputLine("EntityContainer[ \"" + metaData.EntityName() + "\" ] = {", false, true);
+        addOutputLine("EntityContainer[\"" + metaData.EntityName() + "\"] = {", false, true);
         if (metaData.CharacterId() != -1)
         {
             addOutputLine(metaData.EntityName() + " = nil,\n");
@@ -235,7 +246,7 @@ std::string FF7::FF7SimpleCodeGenerator::constructFuncSignature(const Function &
 {
     // Generate name
     FunctionMetaData metaData(func._metadata);
-    return mFormatter.FunctionName(metaData.EntityName(), func._name) + " = function( self )";
+    return mFormatter.FunctionName(metaData.EntityName(), func._name) + " = function(self)";
 }
 
 const std::string FF7::FF7CodeGeneratorHelpers::FormatInstructionNotImplemented(const std::string& entity, uint32 address, uint32 opcode)
@@ -254,7 +265,7 @@ const std::string FF7::FF7CodeGeneratorHelpers::FormatInstructionNotImplemented(
         }
         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();
+    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)

+ 8 - 2
lib/SUDM/decompiler/ff7_field/ff7_field_disassembler.cpp

@@ -175,8 +175,11 @@ static int FindId(uint32 startAddr, uint32 endAddr, const InstVec& insts)
     return -1;
 }
 
-void FF7::FF7Disassembler::AddFunc(std::string entityName, size_t entityIndex, size_t scriptIndex, uint32 nextScriptEntryPoint, const bool isStart, bool isEnd, bool toReturnOnly, std::string funcName)
-{
+void FF7::FF7Disassembler::AddFunc(
+  std::string entityName, size_t entityIndex, size_t scriptIndex,
+  uint32 nextScriptEntryPoint, const bool isStart, bool isEnd,
+  bool toReturnOnly, std::string funcName
+){
 
     const auto kScriptEntryPoint = mStream->Position();
 
@@ -287,6 +290,9 @@ void FF7::FF7Disassembler::DisassembleIndivdualScript(std::string entityName,
         // Read the init script, which means stop at the first return
         AddFunc(entityName, entityIndex, scriptIndex, nextScriptEntryPoint, isStart, isEnd, true, "on_start");
 
+        // TODO: Delete the last return in the "init" function before
+        // concatenating the main function starting with.
+
         // Not at the end of this script? Then the remaining data is the "main" script
         auto streamPos = mStream->Position();
         if (streamPos != endPos)

+ 8 - 1
lib/SUDM/decompiler/ff7_field/ff7_field_disassembler.h

@@ -324,7 +324,14 @@ namespace FF7
             bool isStart,
             bool isEnd);
 
-        void AddFunc(std::string entityName, size_t entityIndex, size_t scriptIndex, uint32 nextScriptEntryPoint, const bool isStart, const bool isEnd, bool toReturnOnly, std::string funcName);
+        /**
+         * Adds a function to
+         */
+        void AddFunc(
+          std::string entityName, size_t entityIndex, size_t scriptIndex,
+          uint32 nextScriptEntryPoint, const bool isStart, const bool isEnd,
+          bool toReturnOnly, std::string funcName
+        );
 
         void ReadOpCodesToPositionOrReturn(size_t endPos);
         std::unique_ptr<Function> StartFunction(size_t scriptIndex);

+ 65 - 85
lib/SUDM/decompiler/ff7_field/ff7_field_engine.cpp

@@ -419,8 +419,19 @@ void FF7::FF7ControlFlowInstruction::processInst(Function& func, ValueStack&, En
     switch (_opcode)
     {
     case eOpcodes::RET:
-        // TODO: Lua won't allow return if not followeb by end;
-        codeGen->addOutputLine("do return 0 end"); // Seems all our functions must return zero
+        // A few notes in RET.
+        // - Lua requires all functions to end with a return.
+        // - Lua doesn's like returns if not followed by an end.
+        // - Don't add a return statement to on_start functions.
+        //     Game 'init' and 'main' code is concatenated in V-Gears. If the
+        //     'main' return is kept, the code of 'main' is never executed.
+        //     There are safeguards forfunctions without a return in the end,
+        //     so it's OK not to include it here.
+        if (func._name != "on_start")
+            codeGen->addOutputLine("do return 0 end");
+        // TODO: Lua won't allow return if not followed by end;
+        //codeGen->addOutputLine("--RET : " + func._name); // Seems all our functions must return zero
+        //codeGen->addOutputLine("do return 0 end"); // Seems all our functions must return zero
         //codeGen->addOutputLine("do return end");
         //codeGen->addOutputLine("-- do return end");
         break;
@@ -468,7 +479,7 @@ void FF7::FF7ControlFlowInstruction::processREQ(CodeGenerator* codeGen, const FF
     const auto& entity = engine.EntityByIndex(_params[0]->getSigned());
     const auto& scriptName = cg->mFormatter.FunctionName(entity.Name(), entity.FunctionByIndex(_params[2]->getUnsigned()));
     auto priority = _params[1]->getUnsigned();
-    codeGen->addOutputLine((boost::format("script:request( Script.ENTITY, \"%1%\", \"%2%\", %3% )") % entity.Name() % scriptName % priority).str());
+    codeGen->addOutputLine((boost::format("script:request(Script.ENTITY, \"%1%\", \"%2%\", %3%)") % entity.Name() % scriptName % priority).str());
 }
 
 void FF7::FF7ControlFlowInstruction::processREQSW(CodeGenerator* codeGen, const FF7FieldEngine& engine)
@@ -477,7 +488,7 @@ void FF7::FF7ControlFlowInstruction::processREQSW(CodeGenerator* codeGen, const
     const auto& entity = engine.EntityByIndex(_params[0]->getSigned());
     const auto& scriptName = cg->mFormatter.FunctionName(entity.Name(), entity.FunctionByIndex(_params[2]->getUnsigned()));
     auto priority = _params[1]->getUnsigned();
-    codeGen->addOutputLine((boost::format("script:request_start_sync( Script.ENTITY, \"%1%\", \"%2%\", %3% )") % entity.Name() % scriptName % priority).str());
+    codeGen->addOutputLine((boost::format("script:request_start_sync(Script.ENTITY, \"%1%\", \"%2%\", %3%)") % entity.Name() % scriptName % priority).str());
 }
 
 void FF7::FF7ControlFlowInstruction::processREQEW(CodeGenerator* codeGen, const FF7FieldEngine& engine)
@@ -488,7 +499,7 @@ void FF7::FF7ControlFlowInstruction::processREQEW(CodeGenerator* codeGen, const
         const auto& entity = engine.EntityByIndex(_params[0]->getSigned());
         const auto& scriptName = cg->mFormatter.FunctionName(entity.Name(), entity.FunctionByIndex(_params[2]->getUnsigned()));
         auto priority = _params[1]->getUnsigned();
-        codeGen->addOutputLine((boost::format("script:request_end_sync( Script.ENTITY, \"%1%\", \"%2%\", %3% )") % entity.Name() % scriptName % priority).str());
+        codeGen->addOutputLine((boost::format("script:request_end_sync(Script.ENTITY, \"%1%\", \"%2%\", %3%)") % entity.Name() % scriptName % priority).str());
     }
     catch (const InternalDecompilerError&)
     {
@@ -501,12 +512,12 @@ void FF7::FF7ControlFlowInstruction::processRETTO(CodeGenerator* codeGen)
 {
     auto entityIndex = _params[0]->getUnsigned();
     auto priority = _params[1]->getUnsigned();
-    codeGen->addOutputLine((boost::format("-- return_to( script_id_in_current_entity=%2%, priority=%1% )") % entityIndex % priority).str());
+    codeGen->addOutputLine((boost::format("-- return_to(script_id_in_current_entity=%2%, priority=%1%)") % entityIndex % priority).str());
 }
 
 void FF7::FF7ControlFlowInstruction::processWAIT(CodeGenerator* codeGen)
 {
-    codeGen->addOutputLine((boost::format("script:wait( %1% )") % (_params[0]->getUnsigned() / 30.0f)).str());
+    codeGen->addOutputLine((boost::format("script:wait(%1%)") % (_params[0]->getUnsigned() / 30.0f)).str());
 }
 
 void FF7::FF7ModuleInstruction::processInst(Function& func, ValueStack&, Engine* /*engine*/, CodeGenerator *codeGen)
@@ -652,9 +663,10 @@ void FF7::FF7ModuleInstruction::processMAPJUMP(CodeGenerator* codeGen, Function&
         _params[1]->getSigned(), // X
         _params[2]->getSigned(), // Y
         _params[3]->getSigned(), // Walk mesh triangle ID
-        _params[4]->getSigned());
+        _params[4]->getSigned()); // Angle
 
     const std::string targetMapName = cg->mFormatter.MapName(targetMapId);
+    //std::cout << "[processMAPJUMP] Map ID: " << targetMapId << " Name: " << targetMapName << std::endl;
     codeGen->addOutputLine("load_field_map_request(\"" + targetMapName + "\", \"" + sourceSpawnPointName + "\")");
 }
 
@@ -922,7 +934,7 @@ void FF7::FF7MathInstruction::processRDMSD(CodeGenerator* codeGen)
 {
     // TODO: we don't have os.time...
     // TODO: RNG emulation?
-    codeGen->addOutputLine("math.randomseed( os.time() )");
+    codeGen->addOutputLine("math.randomseed(os.time())");
 }
 
 void FF7::FF7MathInstruction::processSETBYTE_SETWORD(CodeGenerator* codeGen)
@@ -945,7 +957,7 @@ void FF7::FF7MathInstruction::processBITON(CodeGenerator* codeGen)
     const auto& bitIndex = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[1]->getUnsigned(), _params[3]->getUnsigned());
     // TODO: respect destination bank sizes (16-bit writes only affect low byte)
     // TODO: Lua didn't get bitwise ops until a later version than we are using. these need to be handled C++-side
-    codeGen->addOutputLine((boost::format("-- %1% = %1% | (0x01 << %2%) -- alt: %1% = bit32.bor( %1%, bit32.lshift( 1, %2% ) )") % destination % bitIndex).str());
+    codeGen->addOutputLine((boost::format("-- %1% = %1% | (0x01 << %2%) -- alt: %1% = bit32.bor(%1%, bit32.lshift(1, %2%))") % destination % bitIndex).str());
     codeGen->addOutputLine((boost::format("bit_on(%1%, %2%, %3%)") % _params[0]->getUnsigned() % _params[2]->getUnsigned() % _params[3]->getUnsigned()).str());
 }
 
@@ -978,7 +990,7 @@ void FF7::FF7MathInstruction::processRANDOM(CodeGenerator* codeGen)
     const auto& destination = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[0]->getUnsigned(), _params[1]->getUnsigned());
     // TODO: repect destination bank sizes (16-bit writes only affect low byte)
     // TODO: RNG emulation?
-    codeGen->addOutputLine((boost::format("%1% = math.random( 0, 255 )") % destination).str());
+    codeGen->addOutputLine((boost::format("%1% = math.random(0, 255)") % destination).str());
 }
 
 // ===========================================================================================================================================================
@@ -1088,7 +1100,7 @@ void FF7::FF7WindowInstruction::processWINDOW(CodeGenerator* codeGen)
     auto y = _params[2]->getUnsigned();
     auto width = _params[3]->getUnsigned();
     auto height = _params[4]->getUnsigned();
-    codeGen->addOutputLine((boost::format("dialog:dialog_open( \"%1%\", %2%, %3%, %4%, %5%)") % windowId % x % y % width % height).str());
+    codeGen->addOutputLine((boost::format("dialog:dialog_open(\"%1%\", %2%, %3%, %4%, %5%)") % windowId % x % y % width % height).str());
 }
 
 void FF7::FF7WindowInstruction::processMESSAGE(CodeGenerator* codeGen, const std::string& scriptName)
@@ -1096,8 +1108,8 @@ void FF7::FF7WindowInstruction::processMESSAGE(CodeGenerator* codeGen, const std
     // Displays a dialog in the WINDOW that has previously been initialized to display this dialog.
     auto windowId = _params[0]->getUnsigned();
     auto dialogId = _params[1]->getUnsigned();
-    codeGen->addOutputLine((boost::format("dialog:dialog_set_text( \"%1%\", \"%2%_%3%\" )") % windowId % scriptName % dialogId).str());
-    codeGen->addOutputLine((boost::format("dialog:dialog_wait_for_close( \"%1%\" )") % windowId).str());
+    codeGen->addOutputLine((boost::format("dialog:dialog_set_text(\"%1%\", \"%2%_%3%\")") % windowId % scriptName % dialogId).str());
+    codeGen->addOutputLine((boost::format("dialog:dialog_wait_for_close(\"%1%\")") % windowId).str());
 
 }
 
@@ -1105,17 +1117,17 @@ void FF7::FF7WindowInstruction::processWCLSE(CodeGenerator* codeGen)
 {
     // Close a dialog
     auto windowId = _params[0]->getUnsigned();
-    codeGen->addOutputLine((boost::format("dialog:dialog_close( \"%1%\" )") % windowId).str());
+    codeGen->addOutputLine((boost::format("dialog:dialog_close(\"%1%\")") % windowId).str());
 }
 
 void FF7::FF7WindowInstruction::processMPNAM(CodeGenerator* codeGen)
 {
-    codeGen->addOutputLine((boost::format("-- field:map_name( %1% )") % _params[0]->getUnsigned()).str());
+    codeGen->addOutputLine((boost::format("-- field:map_name(%1%)") % _params[0]->getUnsigned()).str());
 }
 
 void FF7::FF7WindowInstruction::processMENU2(CodeGenerator* codeGen)
 {
-    codeGen->addOutputLine((boost::format("-- field:menu_lock( %1% )") % FF7CodeGeneratorHelpers::FormatBool(_params[0]->getUnsigned())).str());
+    codeGen->addOutputLine((boost::format("-- field:menu_lock(%1%)") % FF7CodeGeneratorHelpers::FormatBool(_params[0]->getUnsigned())).str());
 }
 
 
@@ -1245,7 +1257,7 @@ void FF7::FF7PartyInstruction::processSTITM(CodeGenerator* codeGen)
 
     const auto& itemId = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[0]->getUnsigned(), _params[2]->getUnsigned());
     const auto& amount = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[1]->getUnsigned(), _params[3]->getUnsigned());
-    codeGen->addOutputLine((boost::format("FFVII.add_item( %1%, %2% )") % itemId % amount).str());
+    codeGen->addOutputLine((boost::format("FFVII.add_item(%1%, %2%)") % itemId % amount).str());
 }
 
 void FF7::FF7PartyInstruction::processPRTYE(CodeGenerator* codeGen)
@@ -1257,7 +1269,7 @@ void FF7::FF7PartyInstruction::processPRTYE(CodeGenerator* codeGen)
     characterId2 = (characterId2 == "") ? "nil" : ("\"" + characterId2 + "\"");
     auto characterId3 = gc->mFormatter.CharName(_params[2]->getUnsigned());
     characterId3 = (characterId3 == "") ? "nil" : ("\"" + characterId3 + "\"");
-    codeGen->addOutputLine((boost::format("FFVII.set_party( %1%, %2%, %3% )") % characterId1 % characterId2 % characterId3).str());
+    codeGen->addOutputLine((boost::format("FFVII.set_party(%1%, %2%, %3%)") % characterId1 % characterId2 % characterId3).str());
 }
 
 void FF7::FF7ModelInstruction::processInst(Function& func, ValueStack&, Engine* engine, CodeGenerator *codeGen)
@@ -1506,38 +1518,6 @@ void FF7::FF7ModelInstruction::processInst(Function& func, ValueStack&, Engine*
 
     case eOpcodes::OFST:
         processOFST(codeGen, md.EntityName());
-    //{
-        /* TODO: Implement me
-        FF7SimpleCodeGenerator* cg = static_cast<FF7SimpleCodeGenerator*>(codeGen);
-
-        const auto& x = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[0]->getUnsigned(), _params[2]->getUnsigned());
-        const auto& y = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[1]->getUnsigned(), _params[3]->getUnsigned());
-        const auto& z = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[1]->getUnsigned(), _params[3]->getUnsigned());
-        const auto& speed = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[1]->getUnsigned(), _params[3]->getUnsigned());
-
-        codeGen->addOutputLine((boost::format("%1%:offset_to_position( %2%, %3%, %4%, %5% )") % 
-            md.EntityName() %
-            x %
-            y %
-            z %
-            (_params[2]->getUnsigned() ? "Entity.SMOOTH" : "Entity.LINEAR") %
-            (_params[6]->getUnsigned() / 30.0f)
-            ).str());
-
-       
-        export_script->Log(entity_list[i] + ":offset_to_position( " + 
-            ParseGetVariable(GetU8(script + 1) >> 4, 
-            (s16)GetU16LE(script + 4), 0, downscaler) + ", " + 
-            ParseGetVariable(GetU8(script + 1) & 0x0F, 
-            (s16)GetU16LE(script + 6), false, downscaler) + ", " + 
-            ParseGetVariable(GetU8(script + 2) >> 4, 
-            (s16)GetU16LE(script + 8), false, downscaler) + ", " + 
-            ((type == 2) ? "Entity.SMOOTH" : "Entity.LINEAR") + ", " +
-            ParseGetVariable(GetU8(script + 2) & 0x0F, GetU16LE(script + 10), 0, 30.0f) + " )\n");
-            */
-       // WriteTodo(codeGen, md.EntityName(), "OFST");
-      
-    //}
         break;
 
     case eOpcodes::OFSTW:
@@ -1588,17 +1568,17 @@ void FF7::FF7ModelInstruction::processInst(Function& func, ValueStack&, Engine*
 
 void FF7::FF7ModelInstruction::processTLKON(CodeGenerator* codeGen, const std::string& entity)
 {
-    codeGen->addOutputLine((boost::format("self.%1%:set_talkable( %2% )") % entity % FF7CodeGeneratorHelpers::FormatInvertedBool(_params[0]->getUnsigned())).str());
+    codeGen->addOutputLine((boost::format("self.%1%:set_talkable(%2%)") % entity % FF7CodeGeneratorHelpers::FormatInvertedBool(_params[0]->getUnsigned())).str());
 }
 
 void FF7::FF7ModelInstruction::processPC(CodeGenerator* codeGen, const std::string& entity)
 {
-    codeGen->addOutputLine((boost::format("set_entity_to_character( \"%1%\", \"%1%\" )") % entity).str());
+    codeGen->addOutputLine((boost::format("set_entity_to_character(\"%1%\", \"%1%\")") % entity).str());
 }
 
 void FF7::FF7ModelInstruction::processCHAR(CodeGenerator* codeGen, const std::string& entity)
 {
-    codeGen->addOutputLine((boost::format("self.%1% = entity_manager:get_entity( \"%1%\" )") % entity).str());
+    codeGen->addOutputLine((boost::format("self.%1% = entity_manager:get_entity(\"%1%\")") % entity).str());
 }
 
 void FF7::FF7ModelInstruction::processDFANM(CodeGenerator* codeGen, const std::string& entity, int charId)
@@ -1608,9 +1588,9 @@ void FF7::FF7ModelInstruction::processDFANM(CodeGenerator* codeGen, const std::s
     auto animationId = _params[0]->getUnsigned();
     // TODO: check for zero
     auto speed = 1.0f / _params[1]->getUnsigned();
-    codeGen->addOutputLine((boost::format("self.%1%:set_default_animation( \"%2%\" ) -- speed %3%") % entity % cg->mFormatter.AnimationName(charId, animationId) % speed).str());
+    codeGen->addOutputLine((boost::format("self.%1%:set_default_animation(\"%2%\") -- speed %3%") % entity % cg->mFormatter.AnimationName(charId, animationId) % speed).str());
 
-    codeGen->addOutputLine((boost::format("self.%1%:play_animation( \"%2%\" )") % entity % cg->mFormatter.AnimationName(charId, animationId)).str());
+    codeGen->addOutputLine((boost::format("self.%1%:play_animation(\"%2%\")") % entity % cg->mFormatter.AnimationName(charId, animationId)).str());
 }
 
 void FF7::FF7ModelInstruction::processANIME1(CodeGenerator* codeGen, const std::string& entity, int charId)
@@ -1620,13 +1600,13 @@ void FF7::FF7ModelInstruction::processANIME1(CodeGenerator* codeGen, const std::
     auto animationId = _params[0]->getUnsigned();
     // TODO: check for zero
     auto speed = 1.0f / _params[1]->getUnsigned();
-    codeGen->addOutputLine((boost::format("self.%1%:play_animation( \"%2%\" ) -- speed %3%") % entity % cg->mFormatter.AnimationName(charId, animationId) % speed).str());
+    codeGen->addOutputLine((boost::format("self.%1%:play_animation(\"%2%\") -- speed %3%") % entity % cg->mFormatter.AnimationName(charId, animationId) % speed).str());
     codeGen->addOutputLine((boost::format("self.%1%:animation_sync()") % entity).str());
 }
 
 void FF7::FF7ModelInstruction::processVISI(CodeGenerator* codeGen, const std::string& entity)
 {
-    codeGen->addOutputLine((boost::format("self.%1%:set_visible( %2% )") % entity % FF7CodeGeneratorHelpers::FormatBool(_params[0]->getUnsigned())).str());
+    codeGen->addOutputLine((boost::format("self.%1%:set_visible(%2%)") % entity % FF7CodeGeneratorHelpers::FormatBool(_params[0]->getUnsigned())).str());
 }
 
 void FF7::FF7ModelInstruction::processXYZI(CodeGenerator* codeGen, const std::string& entity)
@@ -1637,7 +1617,7 @@ void FF7::FF7ModelInstruction::processXYZI(CodeGenerator* codeGen, const std::st
     const auto& y = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[1]->getUnsigned(), _params[5]->getSigned(), FF7CodeGeneratorHelpers::ValueType::Float, scale);
     const auto& z = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[2]->getUnsigned(), _params[6]->getSigned(), FF7CodeGeneratorHelpers::ValueType::Float, scale);
     const auto& triangleId = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[3]->getUnsigned(), _params[7]->getUnsigned());
-    codeGen->addOutputLine((boost::format("self.%1%:set_position( %2%, %3%, %4% ) -- triangle ID %5%") % entity % x % y % z % triangleId).str());
+    codeGen->addOutputLine((boost::format("self.%1%:set_position(%2%, %3%, %4%) -- triangle ID %5%") % entity % x % y % z % triangleId).str());
 }
 
 void FF7::FF7ModelInstruction::processMOVE(CodeGenerator* codeGen, const std::string& entity)
@@ -1646,7 +1626,7 @@ void FF7::FF7ModelInstruction::processMOVE(CodeGenerator* codeGen, const std::st
     const float scale = 128.0f * cg->ScaleFactor();
     const auto& x = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[0]->getUnsigned(), _params[2]->getSigned(), FF7CodeGeneratorHelpers::ValueType::Float, scale);
     const auto& y = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[1]->getUnsigned(), _params[3]->getSigned(), FF7CodeGeneratorHelpers::ValueType::Float, scale);
-    codeGen->addOutputLine((boost::format("self.%1%:move_to_position( %2%, %3% )") % entity % x % y).str());
+    codeGen->addOutputLine((boost::format("self.%1%:move_to_position(%2%, %3%)") % entity % x % y).str());
     codeGen->addOutputLine((boost::format("self.%1%:move_sync()") % entity).str());
 }
 
@@ -1655,7 +1635,7 @@ void FF7::FF7ModelInstruction::processMSPED(CodeGenerator* codeGen, const std::s
     FF7SimpleCodeGenerator* cg = static_cast<FF7SimpleCodeGenerator*>(codeGen);
     const float scale = 128.0f * cg->ScaleFactor();
     const auto& speed = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[1]->getUnsigned(), _params[2]->getUnsigned(), FF7CodeGeneratorHelpers::ValueType::Float, 256.0f * scale / 30.0f);
-    codeGen->addOutputLine((boost::format("self.%1%:set_move_auto_speed( %2% )") % entity % speed).str());
+    codeGen->addOutputLine((boost::format("self.%1%:set_move_auto_speed(%2%)") % entity % speed).str());
 }
 
 void FF7::FF7ModelInstruction::processDIR(CodeGenerator* codeGen, const std::string& entity)
@@ -1663,7 +1643,7 @@ void FF7::FF7ModelInstruction::processDIR(CodeGenerator* codeGen, const std::str
     FF7SimpleCodeGenerator* cg = static_cast<FF7SimpleCodeGenerator*>(codeGen);
 
     const auto& degrees = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[0]->getUnsigned(), _params[1]->getUnsigned(), FF7CodeGeneratorHelpers::ValueType::Float, 256.0f / 360.0f);
-    codeGen->addOutputLine((boost::format("self.%1%:set_rotation( %2% )") % entity % degrees).str());
+    codeGen->addOutputLine((boost::format("self.%1%:set_rotation(%2%)") % entity % degrees).str());
 }
 
 void FF7::FF7ModelInstruction::processTURNGEN(CodeGenerator* codeGen, const std::string& entity)
@@ -1708,7 +1688,7 @@ void FF7::FF7ModelInstruction::processTURNGEN(CodeGenerator* codeGen, const std:
     }
 
     const float scaledSteps = static_cast<float>(steps) / 30.0f;
-    codeGen->addOutputLine((boost::format("self.%1%:turn_to_direction( %2%, %3%, %4%, %5% )") % entity % degrees % direction % stepType % scaledSteps).str());
+    codeGen->addOutputLine((boost::format("self.%1%:turn_to_direction(%2%, %3%, %4%, %5%)") % entity % degrees % direction % stepType % scaledSteps).str());
     codeGen->addOutputLine((boost::format("self.%1%:turn_sync()") % entity).str());
 }
 
@@ -1719,7 +1699,7 @@ void FF7::FF7ModelInstruction::processGETAI(CodeGenerator* codeGen, const FF7Fie
     // TODO: check for assignment to literal
     const auto& variable = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[1]->getUnsigned(), _params[3]->getUnsigned());
     const auto& entity = engine.EntityByIndex(_params[2]->getUnsigned());
-    codeGen->addOutputLine((boost::format("%1% = entity_manager:get_entity( \"%2%\" ):get_move_triangle_id()") % variable % entity.Name()).str());
+    codeGen->addOutputLine((boost::format("%1% = entity_manager:get_entity(\"%2%\"):get_move_triangle_id()") % variable % entity.Name()).str());
 }
 
 void FF7::FF7ModelInstruction::processANIM_2(CodeGenerator* codeGen, const std::string& entity, int charId)
@@ -1729,7 +1709,7 @@ void FF7::FF7ModelInstruction::processANIM_2(CodeGenerator* codeGen, const std::
     auto animationId = _params[0]->getUnsigned();
     // TODO: check for zero
     auto speed = 1.0f / _params[1]->getUnsigned();
-    codeGen->addOutputLine((boost::format("self.%1%:play_animation_stop( \"%2%\" ) -- speed %3%") % entity % cg->mFormatter.AnimationName(charId, animationId) % speed).str());
+    codeGen->addOutputLine((boost::format("self.%1%:play_animation_stop(\"%2%\") -- speed %3%") % entity % cg->mFormatter.AnimationName(charId, animationId) % speed).str());
     codeGen->addOutputLine((boost::format("self.%1%:animation_sync()") % entity).str());
 }
 
@@ -1741,7 +1721,7 @@ void FF7::FF7ModelInstruction::processCANIM2(CodeGenerator* codeGen, const std::
     auto endFrame = _params[2]->getUnsigned() / 30.0f;
     // TODO: check for zero
     auto speed = 1.0f / _params[3]->getUnsigned();
-    codeGen->addOutputLine((boost::format("self.%1%:play_animation( \"%2%\", %3%, %4% ) -- speed %5%") % entity % cg->mFormatter.AnimationName(charId, animationId) % startFrame % endFrame % speed).str());
+    codeGen->addOutputLine((boost::format("self.%1%:play_animation(\"%2%\", %3%, %4%) -- speed %5%") % entity % cg->mFormatter.AnimationName(charId, animationId) % startFrame % endFrame % speed).str());
     codeGen->addOutputLine((boost::format("self.%1%:animation_sync()") % entity).str());
 }
 
@@ -1756,19 +1736,19 @@ void FF7::FF7ModelInstruction::processCANM_2(CodeGenerator* codeGen, const std::
     // TODO: check for zero
     auto speed = 1.0f / _params[3]->getUnsigned();
 
-    codeGen->addOutputLine((boost::format("self.%1%:play_animation_stop( \"%2%\", %3%, %4% ) -- speed %5%") % entity % cg->mFormatter.AnimationName(charId, animationId) % startFrame % endFrame % speed).str());
+    codeGen->addOutputLine((boost::format("self.%1%:play_animation_stop(\"%2%\", %3%, %4%) -- speed %5%") % entity % cg->mFormatter.AnimationName(charId, animationId) % startFrame % endFrame % speed).str());
     codeGen->addOutputLine((boost::format("self.%1%:animation_sync()") % entity).str());
 }
 
 void FF7::FF7ModelInstruction::processCC(CodeGenerator* codeGen, const FF7FieldEngine& engine)
 {
     const auto& entity = engine.EntityByIndex(_params[0]->getUnsigned());
-    codeGen->addOutputLine((boost::format("entity_manager:set_player_entity( \"%1%\" )") % entity.Name()).str());
+    codeGen->addOutputLine((boost::format("entity_manager:set_player_entity(\"%1%\")") % entity.Name()).str());
 }
 
 void FF7::FF7ModelInstruction::processSOLID(CodeGenerator* codeGen, const std::string& entity)
 {
-    codeGen->addOutputLine((boost::format("self.%1%:set_solid( %2% )") % entity % FF7CodeGeneratorHelpers::FormatInvertedBool(_params[0]->getUnsigned())).str());
+    codeGen->addOutputLine((boost::format("self.%1%:set_solid(%2%)") % entity % FF7CodeGeneratorHelpers::FormatInvertedBool(_params[0]->getUnsigned())).str());
 }
 
 void FF7::FF7ModelInstruction::processOFST(CodeGenerator* codeGen, const std::string& entity){
@@ -1803,7 +1783,7 @@ void FF7::FF7ModelInstruction::processOFST(CodeGenerator* codeGen, const std::st
     speed /= 30.0f;
     codeGen->addOutputLine(
       (
-        boost::format("self.%1%:offset_to_position( %2%, %3%, %4%, %5%, %6%)")
+        boost::format("self.%1%:offset_to_position(%2%, %3%, %4%, %5%, %6%)")
           % entity % x % y % z
           % (_params[4]->getUnsigned() ? "Entity.SMOOTH" : "Entity.LINEAR")
           % speed
@@ -1829,7 +1809,7 @@ void FF7::FF7WalkmeshInstruction::processInst(Function& func, ValueStack&, Engin
     case eOpcodes::IDLCK:
         // Triangle id, on or off
         codeGen->addOutputLine(
-            (boost::format("walkmesh:lock_walkmesh( %1%, %2% )")
+            (boost::format("walkmesh:lock_walkmesh(%1%, %2%)")
             % _params[0]->getUnsigned()
             % FF7CodeGeneratorHelpers::FormatBool(_params[1]->getUnsigned())).str());
         break;
@@ -1853,7 +1833,7 @@ void FF7::FF7WalkmeshInstruction::processInst(Function& func, ValueStack&, Engin
 
 void FF7::FF7WalkmeshInstruction::processUC(CodeGenerator* codeGen)
 {
-    codeGen->addOutputLine((boost::format("entity_manager:player_lock( %1% )") % FF7CodeGeneratorHelpers::FormatBool(_params[0]->getUnsigned())).str());
+    codeGen->addOutputLine((boost::format("entity_manager:player_lock(%1%)") % FF7CodeGeneratorHelpers::FormatBool(_params[0]->getUnsigned())).str());
 }
 
 void FF7::FF7BackgroundInstruction::processInst(Function& func, ValueStack&, Engine* /*engine*/, CodeGenerator *codeGen)
@@ -1950,7 +1930,7 @@ void FF7::FF7BackgroundInstruction::processBGON(CodeGenerator* codeGen)
     FF7SimpleCodeGenerator* cg = static_cast<FF7SimpleCodeGenerator*>(codeGen);
     const auto& backgroundId = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[0]->getUnsigned(), _params[2]->getUnsigned());
     const auto& layerId = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[1]->getUnsigned(), _params[3]->getUnsigned());
-    codeGen->addOutputLine((boost::format("-- field:background_on( %1%, %2% )") % backgroundId % layerId).str());
+    codeGen->addOutputLine((boost::format("-- field:background_on(%1%, %2%)") % backgroundId % layerId).str());
 }
 
 void FF7::FF7BackgroundInstruction::processBGOFF(CodeGenerator* codeGen)
@@ -1958,14 +1938,14 @@ void FF7::FF7BackgroundInstruction::processBGOFF(CodeGenerator* codeGen)
     FF7SimpleCodeGenerator* cg = static_cast<FF7SimpleCodeGenerator*>(codeGen);
     const auto& backgroundId = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[0]->getUnsigned(), _params[2]->getUnsigned());
     const auto& layerId = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[1]->getUnsigned(), _params[3]->getUnsigned());
-    codeGen->addOutputLine((boost::format("-- field:background_off( %1%, %2% )") % backgroundId % layerId).str());
+    codeGen->addOutputLine((boost::format("-- field:background_off(%1%, %2%)") % backgroundId % layerId).str());
 }
 
 void FF7::FF7BackgroundInstruction::processBGCLR(CodeGenerator* codeGen)
 {
     FF7SimpleCodeGenerator* cg = static_cast<FF7SimpleCodeGenerator*>(codeGen);
     const auto& backgroundId = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[1]->getUnsigned(), _params[2]->getUnsigned());
-    codeGen->addOutputLine((boost::format("-- field:background_clear( %1% )") % backgroundId).str());
+    codeGen->addOutputLine((boost::format("-- field:background_clear(%1%)") % backgroundId).str());
 }
 
 void FF7::FF7BackgroundInstruction::processSTPAL(CodeGenerator* codeGen)
@@ -2125,7 +2105,7 @@ void FF7::FF7CameraInstruction::processNFADE(CodeGenerator* codeGen)
     const auto& g = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[1]->getUnsigned(), _params[6]->getUnsigned());
     const auto& b = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[2]->getUnsigned(), _params[7]->getUnsigned());
     const auto& unknown = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[3]->getUnsigned(), _params[8]->getUnsigned());
-    codeGen->addOutputLine((boost::format("-- fade:fade( %2%, %3%, %4%, %1%, %5% )") % type % r % g % b % unknown).str());
+    codeGen->addOutputLine((boost::format("-- fade:fade(%2%, %3%, %4%, %1%, %5%)") % type % r % g % b % unknown).str());
 }
 
 void FF7::FF7CameraInstruction::processSCR2D(CodeGenerator* codeGen)
@@ -2135,7 +2115,7 @@ void FF7::FF7CameraInstruction::processSCR2D(CodeGenerator* codeGen)
     FF7SimpleCodeGenerator* cg = static_cast<FF7SimpleCodeGenerator*>(codeGen);
     const auto& x = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[0]->getUnsigned(), _params[2]->getSigned());
     const auto& y = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[1]->getUnsigned(), _params[3]->getSigned());
-    codeGen->addOutputLine((boost::format("background2d:scroll_to_position( %1% * 3, %2% * 3, Background2D.NONE, 0 )") % x % y).str());
+    codeGen->addOutputLine((boost::format("background2d:scroll_to_position(%1% * 3, %2% * 3, Background2D.NONE, 0)") % x % y).str());
 }
 
 void FF7::FF7CameraInstruction::processSCR2DC(CodeGenerator* codeGen)
@@ -2144,7 +2124,7 @@ void FF7::FF7CameraInstruction::processSCR2DC(CodeGenerator* codeGen)
     const auto& x = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[0]->getUnsigned(), _params[4]->getSigned());
     const auto& y = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[1]->getUnsigned(), _params[5]->getSigned());
     const auto& speed = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[3]->getUnsigned(), _params[6]->getUnsigned(), FF7CodeGeneratorHelpers::ValueType::Float, 30.0f);
-    codeGen->addOutputLine((boost::format("background2d:scroll_to_position( %1% * 3, %2% * 3, Background2D.SMOOTH, %3% )") % x % y % speed).str());
+    codeGen->addOutputLine((boost::format("background2d:scroll_to_position(%1% * 3, %2% * 3, Background2D.SMOOTH, %3%)") % x % y % speed).str());
 }
 
 void FF7::FF7CameraInstruction::processFADE(CodeGenerator* codeGen)
@@ -2175,7 +2155,7 @@ void FF7::FF7CameraInstruction::processFADE(CodeGenerator* codeGen)
     // TODO: needs to be divided by 30.0f?
     auto speed = _params[7]->getUnsigned();
     auto start = _params[9]->getUnsigned();
-    codeGen->addOutputLine((boost::format("-- fade:fade( %2%, %3%, %4%, %1%, %5%, %6% )") % type % r % g % b % speed % start).str());
+    codeGen->addOutputLine((boost::format("-- fade:fade(%2%, %3%, %4%, %1%, %5%, %6%)") % type % r % g % b % speed % start).str());
 }
 
 void FF7::FF7AudioVideoInstruction::processInst(Function& func, ValueStack&, Engine* /*engine*/, CodeGenerator *codeGen)
@@ -2264,12 +2244,12 @@ void FF7::FF7AudioVideoInstruction::processAKAO2(CodeGenerator* codeGen)
     const auto& param4 = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[3]->getUnsigned(), _params[10]->getUnsigned());
     const auto& param5 = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[5]->getUnsigned(), _params[11]->getUnsigned());
     auto op = _params[6]->getUnsigned();
-    codeGen->addOutputLine((boost::format("-- music:execute_akao( 0x%6$02x, %1%, %2%, %3%, %4%, %5% )") % param1 % param2 % param3 % param4 % param5 % op).str());
+    codeGen->addOutputLine((boost::format("-- music:execute_akao(0x%6$02x, %1%, %2%, %3%, %4%, %5%)") % param1 % param2 % param3 % param4 % param5 % op).str());
 }
 
 void FF7::FF7AudioVideoInstruction::processMUSIC(CodeGenerator* codeGen)
 {
-    codeGen->addOutputLine((boost::format("-- music:execute_akao( 0x10, pointer_to_field_AKAO_%1% )") % _params[0]->getUnsigned()).str());
+    codeGen->addOutputLine((boost::format("-- music:execute_akao(0x10, pointer_to_field_AKAO_%1%)") % _params[0]->getUnsigned()).str());
 }
 
 void FF7::FF7AudioVideoInstruction::processSOUND(CodeGenerator* codeGen)
@@ -2277,7 +2257,7 @@ void FF7::FF7AudioVideoInstruction::processSOUND(CodeGenerator* codeGen)
     FF7SimpleCodeGenerator* cg = static_cast<FF7SimpleCodeGenerator*>(codeGen);
     const auto& soundId = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[0]->getUnsigned(), _params[2]->getUnsigned());
     const auto& panning = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[1]->getUnsigned(), _params[3]->getUnsigned());
-    codeGen->addOutputLine((boost::format("-- music:execute_akao( 0x20, %1%, %2% )") % soundId % panning).str());
+    codeGen->addOutputLine((boost::format("-- music:execute_akao(0x20, %1%, %2%)") % soundId % panning).str());
 }
 
 void FF7::FF7AudioVideoInstruction::processAKAO(CodeGenerator* codeGen)
@@ -2289,17 +2269,17 @@ void FF7::FF7AudioVideoInstruction::processAKAO(CodeGenerator* codeGen)
     const auto& param4 = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[3]->getUnsigned(), _params[10]->getUnsigned());
     const auto& param5 = FF7CodeGeneratorHelpers::FormatValueOrVariable(cg->mFormatter, _params[5]->getUnsigned(), _params[11]->getUnsigned());
     auto op = _params[6]->getUnsigned();
-    codeGen->addOutputLine((boost::format("-- music:execute_akao( 0x%6$02x, %1%, %2%, %3%, %4%, %5% )") % param1 % param2 % param3 % param4 % param5 % op).str());
+    codeGen->addOutputLine((boost::format("-- music:execute_akao(0x%6$02x, %1%, %2%, %3%, %4%, %5%)") % param1 % param2 % param3 % param4 % param5 % op).str());
 }
 
 void FF7::FF7AudioVideoInstruction::processMULCK(CodeGenerator* codeGen)
 {
-    codeGen->addOutputLine((boost::format("-- music:lock( %1% )") % FF7CodeGeneratorHelpers::FormatBool(_params[0]->getUnsigned())).str());
+    codeGen->addOutputLine((boost::format("-- music:lock(%1%)") % FF7CodeGeneratorHelpers::FormatBool(_params[0]->getUnsigned())).str());
 }
 
 void FF7::FF7AudioVideoInstruction::processPMVIE(CodeGenerator* codeGen)
 {
-    codeGen->addOutputLine((boost::format("-- field:movie_set( %1% )") % _params[0]->getUnsigned()).str());
+    codeGen->addOutputLine((boost::format("-- field:movie_set(%1%)") % _params[0]->getUnsigned()).str());
 }
 
 void FF7::FF7AudioVideoInstruction::processMOVIE(CodeGenerator* codeGen)