Ejemplo n.º 1
0
        public static void Decompile()
        {
            var fStrings = new Text(Path.Combine(Common.InputPath, "strings.txt"));
            var fSource  = new Win32FileWriter(Path.Combine(Common.OutputPath, "module_strings.py"));

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.Strings);
            fStrings.GetString();
            int iStrings = Convert.ToInt32(fStrings.GetString(), CultureInfo.GetCultureInfo("en-US")); //fStrings.GetInt();

            for (int s = 0; s < iStrings; s++)
            {
                var str = fStrings.GetString();
                if (str == null)
                {
                    continue;
                }
                var strDataArray = str.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries); //.st
                //string strID = fStrings.GetWord();
                //string strText = fStrings.GetWord();
                var strId   = strDataArray[0];
                var strText = strDataArray[1];
                //Console.WriteLine($@"process {s} = ""{strID}""");
                fSource.WriteLine("  (\"{0}\", \"{1}\"),", strId.Remove(0, 4), strText.Replace('_', ' '));
                //fSource.Close();
            }

            fSource.Write("]");
            fSource.Close();
            fStrings.Close();

            Common.GenerateId("ID_strings.py", Common.Strings, "str");
        }
Ejemplo n.º 2
0
        public static void Decompile()
        {
            var fTableaus = new Text(Path.Combine(Common.InputPath, "tableau_materials.txt"));
            var fSource   = new Win32FileWriter(Path.Combine(Common.OutputPath, "module_tableau_materials.py"));

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.TableauMaterials);
            int iCount = fTableaus.GetInt();

            for (int i = 0; i < iCount; i++)
            {
                fSource.Write("  (\"{0}\", {1}, \"{2}\", ", fTableaus.GetWord().Remove(0, 4), fTableaus.GetDWord(), fTableaus.GetWord());
                for (int j = 0; j < 6; j++)
                {
                    fSource.Write(" {0},", fTableaus.GetInt());
                }
                fSource.WriteLine("\r\n  [");
                Common.PrintStatement(ref fTableaus, ref fSource, fTableaus.GetInt(), "    ");
                fSource.WriteLine("  ]),\r\n");
            }
            fSource.Write("]");
            fSource.Close();
            fTableaus.Close();
            Common.GenerateId("ID_tableau_materials.py", Common.Tableaus, "tableau");
        }
Ejemplo n.º 3
0
        public static void Decompile()
        {
            var fTriggers = new Text(Path.Combine(Common.InputPath, "simple_triggers.txt"));
            var fSource   = new Win32FileWriter(Path.Combine(Common.OutputPath, "module_simple_triggers.py"));

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.SimpleTriggers);
            fTriggers.GetString();
            int iSimpleTriggers = fTriggers.GetInt();

            for (int t = 0; t < iSimpleTriggers; t++)
            {
                fSource.Write("  ({0},\r\n  [", Common.GetTriggerParam(fTriggers.GetDouble()));
                int iRecords = fTriggers.GetInt();
                if (iRecords != 0)
                {
                    fSource.WriteLine();
                    Common.PrintStatement(ref fTriggers, ref fSource, iRecords, "    ");
                    fSource.Write("  ");
                }
                fSource.Write("]),\r\n\r\n");
            }
            fSource.Write("]");
            fSource.Close();
            fTriggers.Close();
        }
Ejemplo n.º 4
0
        public static void WriteAllText(string fileName, string data)
        {
            var writer = new Win32FileWriter(fileName);

            writer.Write(data);
            writer.Close();
        }
Ejemplo n.º 5
0
 public static void GenerateId(string fileOut, string[] content, string prefix = "")
 {
     if (!NeedId) return;
     var f = new Win32FileWriter(Path.Combine(OutputPath, fileOut));
     if (prefix.Length > 0 && prefix[prefix.Length - 1] != '_') prefix += '_';
     for (int i = 0; i < content.Length; i++) f.WriteLine("{0}{1} = {2}", prefix, content[i], i);
     f.Close();
 } 
Ejemplo n.º 6
0
        public static void Decompile()
        {
            var fTemplates = new Text(Path.Combine(Common.InputPath, "party_templates.txt"));
            var fSource    = new Win32FileWriter(Path.Combine(Common.OutputPath, "module_party_templates.py"));

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.PartyTemplates);
            fTemplates.GetString();
            var iTemplates = fTemplates.GetInt();

            for (int i = 0; i < iTemplates; i++)
            {
                fSource.Write("  (\"{0}\", \"{1}\"", fTemplates.GetWord().Remove(0, 3), fTemplates.GetWord());

                var dwFlag = fTemplates.GetUInt64();
                fSource.Write(", {0}, {1}", DecompileFlags(dwFlag), fTemplates.GetInt());

                var iFaction = fTemplates.GetInt();
                if (iFaction >= 0 && iFaction < Common.Factions.Count)
                {
                    fSource.Write(", fac_{0}", Common.Factions[iFaction]);
                }
                else
                {
                    fSource.Write(", {0}", iFaction);
                }

                var dwPersonality = fTemplates.GetUInt();
                fSource.Write(", {0}, [", DecompilePersonality(dwPersonality));


                var sbTroopList = new StringBuilder(1024);
                for (int iStack = 0; iStack < 6; iStack++)
                {
                    var iTroop = fTemplates.GetInt();
                    if (-1 == iTroop)
                    {
                        continue;
                    }
                    var iMinTroops   = fTemplates.GetInt();
                    var iMaxTroops   = fTemplates.GetInt();
                    var dwMemberFlag = fTemplates.GetDWord();
                    sbTroopList.Append($"({(iTroop < Common.Troops.Count ? "trp_" + Common.Troops[iTroop] : iTroop.ToString(CultureInfo.GetCultureInfo("en-US")))}, {iMinTroops}, {iMaxTroops}{(dwMemberFlag == 1 ? ", pmf_is_prisoner" : "")}),");
                }
                if (sbTroopList.Length != 0)
                {
                    sbTroopList.Length--;
                }
                fSource.WriteLine("{0}]),", sbTroopList);
            }
            fSource.Write("]");
            fSource.Close();
            fTemplates.Close();

            Common.GenerateId("ID_party_templates.py", Common.PTemps, "pt");
        }
Ejemplo n.º 7
0
        public static void Decompile()
        {
            var fActions = new Text(Path.Combine(Common.InputPath, "actions.txt"));
            var fSource  = new Win32FileWriter(Path.Combine(Common.OutputPath, "module_animations.py"));

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.Animations);
            var iActions = fActions.GetInt();

            for (int a = 0; a < iActions; a++)
            {
                var strAnimId         = fActions.GetWord();
                var dwAnimFlags       = fActions.GetDWord();
                var dwMasterAnimFlags = fActions.GetDWord();
                fSource.WriteLine("  [\"{0}\", {1}, {2},", strAnimId, DecompileFlags(dwAnimFlags), DecompileMasterFlags(dwMasterAnimFlags));
                var iAnimSequences = fActions.GetInt();
                for (int s = 0; s < iAnimSequences; s++)
                {
                    var dDuration = fActions.GetDouble();
                    var strName   = fActions.GetWord();
                    fSource.Write("    [{0}, \"{1}\",", dDuration.ToString(CultureInfo.GetCultureInfo("en-US")), strName);
                    int iBeginFrame = fActions.GetInt(), iEndingFrame = fActions.GetInt();
                    var dwSequenceFlags = fActions.GetDWord();

                    var dd      = new string[5]; //NOTE: Type string for non-english version of windows
                    var bZeroes = true;
                    for (int d = 0; d < 5; d++)
                    {
                        dd[d] = fActions.GetDouble().ToString(CultureInfo.GetCultureInfo("en-US"));
                        if (dd[d] != "0")
                        {
                            bZeroes = false;
                        }
                    }
                    if (bZeroes)
                    {
                        fSource.Write(" {0}, {1}, {2}],\r\n", iBeginFrame, iEndingFrame, DecompileSequenceFlags(dwSequenceFlags));
                    }
                    else
                    {
                        fSource.Write(" {0}, {1}, {2}, {3}, ({4}, {5}, {6}), {7}],\r\n", iBeginFrame, iEndingFrame,
                                      DecompileSequenceFlags(dwSequenceFlags), DecompilePack((DWORD)Convert.ToDouble(dd[0], CultureInfo.GetCultureInfo("en-US"))), dd[1], dd[2], dd[3], dd[4]);
                    }
                }
                fSource.WriteLine("  ],");
            }
            fSource.Write("]");
            fSource.Close();
            fActions.Close();

            Common.GenerateId("ID_animations.py", Common.Animations, "anim");
        }
Ejemplo n.º 8
0
        public static void Decompile()
        {
            var fIcons  = new Text(Path.Combine(Common.InputPath, "map_icons.txt"));
            var fSource = new Win32FileWriter(Path.Combine(Common.OutputPath, "module_map_icons.py"));

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.Icons);
            fIcons.GetString();
            int iMapIcons = fIcons.GetInt();

            for (int iMIcon = 0; iMIcon < iMapIcons; iMIcon++)
            {
                var strName = fIcons.GetWord();
                fSource.Write("  (\"{0}\",", strName);

                DWORD dwFlags = fIcons.GetDWord();
                fSource.Write(" {0},", dwFlags == 1 ? "mcn_no_shadow" : "0");

                var strMeshName = fIcons.GetWord();
                fSource.Write(" \"{0}\",", strMeshName);

                var    dScale = fIcons.GetDouble();
                int    iSound = fIcons.GetInt();
                double dX = fIcons.GetDouble(), dY = fIcons.GetDouble(), dZ = fIcons.GetDouble();

                fSource.Write(" {0}, {1}, {2}, {3}, {4}", dScale.ToString(CultureInfo.GetCultureInfo("en-US")), iSound != 0 ? iSound < Common.Sounds.Count ? "snd_" + Common.Sounds[iSound] : iSound.ToString(CultureInfo.GetCultureInfo("en-US")) : "0",
                              dX.ToString(CultureInfo.GetCultureInfo("en-US")), dY.ToString(CultureInfo.GetCultureInfo("en-US")), dZ.ToString(CultureInfo.GetCultureInfo("en-US")));

                int iTriggers = fIcons.GetInt();
                if (iTriggers > 0)
                {
                    fSource.Write(",\r\n  [\r\n");
                    for (int t = 0; t < iTriggers; t++)
                    {
                        double dInterval = fIcons.GetDouble();
                        fSource.WriteLine("    ({0},[", Common.GetTriggerParam(dInterval));

                        int iRecords = fIcons.GetInt();
                        Common.PrintStatement(ref fIcons, ref fSource, iRecords, "      ");

                        fSource.WriteLine("    ]),");
                    }
                    fSource.Write("  ]");
                }
                fSource.WriteLine("),");
            }
            fSource.Write("]");
            fSource.Close();
            fIcons.Close();

            Common.GenerateId("ID_map_icons.py", Common.MapIcons, "icon");
        }
Ejemplo n.º 9
0
        public static void Decompile()
        {
            var fSkyboxes = new Text(Common.InputPath + "/skyboxes.txt");
            var fSource   = new Win32FileWriter(Common.OutputPath + "/module_skyboxes.py");

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.Skyboxes);

            int iSkyboxes = fSkyboxes.GetInt();

            for (int i = 0; i < iSkyboxes; i++)
            {
                string strID   = fSkyboxes.GetWord();
                DWORD  dwFlags = fSkyboxes.GetDWord();
                fSource.Write("  (\"{0}\", {1},", strID, DecompileFlags(dwFlags));

                for (int j = 0; j < 3; j++)
                {
                    fSource.Write(" {0},", fSkyboxes.GetDouble().ToString(CultureInfo.GetCultureInfo("en-US")));
                }

                fSource.Write(" \"{0}\",", fSkyboxes.GetWord());

                for (int j = 0; j < 3; j++)
                {
                    fSource.Write(" ({0}, {1}, {2}),", fSkyboxes.GetDouble().ToString(CultureInfo.GetCultureInfo("en-US")),
                                  fSkyboxes.GetDouble().ToString(CultureInfo.GetCultureInfo("en-US")),
                                  fSkyboxes.GetDouble().ToString(CultureInfo.GetCultureInfo("en-US")));
                }

                fSource.WriteLine(" ({0}, 0x{1:X8})),", fSkyboxes.GetDouble().ToString(CultureInfo.GetCultureInfo("en-US")), fSkyboxes.GetDWord());
            }
            fSource.Write(@"]
def save_skyboxes():
  file = open(export_dir + ""Data/skyboxes.txt"",""w"")
  file.write(""d\n""%len(skyboxes))
  for skybox in  skyboxes:
    file.write(""%s %d %f %f %f %s\n""%(skybox[0],skybox[1],skybox[2],skybox[3],skybox[4],skybox[5]))
    file.write("" %f %f %f ""%skybox[6])
    file.write("" %f %f %f ""%skybox[7])
    file.write("" %f %f %f ""%skybox[8])
    file.write("" %f %d\n""%skybox[9])
  file.close()

print ""Exporting skyboxes...""
save_skyboxes()");
            fSource.Close();
            fSkyboxes.Close();
        }
Ejemplo n.º 10
0
        public static void Decompile()
        {
            var fPresentations = new Text(Common.InputPath + "/presentations.txt");
            var fSource        = new Win32FileWriter(Common.OutputPath + "/module_presentations.py");

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.Presentations);
            fPresentations.GetString();
            int iPresentations = fPresentations.GetInt();

            for (int i = 0; i < iPresentations; i++)
            {
                fSource.Write("  (\"{0}\"", fPresentations.GetWord().Remove(0, 6));

                int iFlag = fPresentations.GetInt();
                fSource.Write(", {0}", DecompileFlags(iFlag));

                int iMesh = fPresentations.GetInt();
                if (iMesh >= 0 && iMesh < Common.Meshes.Length)
                {
                    fSource.Write(", mesh_{0}", Common.Meshes[iMesh]);
                }
                else
                {
                    fSource.Write(", {0}", iMesh);
                }
                fSource.Write(",\r\n  [\r\n");

                int iTriggers = fPresentations.GetInt();
                for (int t = 0; t < iTriggers; t++)
                {
                    double dInterval = fPresentations.GetDouble();
                    fSource.Write("    ({0},\r\n    [\r\n", Common.GetTriggerParam(dInterval));
                    int iRecords = fPresentations.GetInt();
                    if (iRecords != 0)
                    {
                        //memcpy(indention, "      ", 7);
                        Common.PrintStatement(ref fPresentations, ref fSource, iRecords, "      ");
                    }
                    fSource.Write("    ]),\r\n");
                }
                fSource.Write("  ]),\r\n\r\n");
            }
            fSource.Write("]");
            fSource.Close();
            fPresentations.Close();

            Common.GenerateId("ID_presentations.py", Common.Presentations, "prsnt");
        }
Ejemplo n.º 11
0
        public static void Decompile()
        {
            var fParticles = new Text(Path.Combine(Common.InputPath, "particle_systems.txt"));
            var fSource    = new Win32FileWriter(Path.Combine(Common.OutputPath, "module_particle_systems.py"));

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.ParticleSystems);
            fParticles.GetString();
            int iParticles = fParticles.GetInt();

            for (int i = 0; i < iParticles; i++)
            {
                fSource.Write("  (\"{0}\", ", fParticles.GetWord().Remove(0, 5));

                DWORD dwFlag = fParticles.GetDWord();
                fSource.Write("{0}, \"{1}\",\r\n   ", DecompileFlags(dwFlag), fParticles.GetWord());
                for (int j = 0; j < 6; j++)
                {
                    fSource.Write(" {0},", fParticles.GetDouble().ToString(CultureInfo.GetCultureInfo("en-US")));
                }
                fSource.WriteLine();

                double d0, d1;
                for (int j = 0; j < 5; j++)
                {
                    d0 = fParticles.GetDouble(); d1 = fParticles.GetDouble();
                    fSource.Write("    ({0}, {1}),", d0.ToString(CultureInfo.GetCultureInfo("en-US")), d1.ToString(CultureInfo.GetCultureInfo("en-US")));
                    d0 = fParticles.GetDouble(); d1 = fParticles.GetDouble();
                    fSource.WriteLine(" ({0}, {1}),", d0.ToString(CultureInfo.GetCultureInfo("en-US")), d1.ToString(CultureInfo.GetCultureInfo("en-US")));
                }

                d0 = fParticles.GetDouble(); d1 = fParticles.GetDouble(); var d2 = fParticles.GetDouble();
                fSource.WriteLine("    ({0}, {1}, {2}),", d0.ToString(CultureInfo.GetCultureInfo("en-US")), d1.ToString(CultureInfo.GetCultureInfo("en-US")), d2.ToString(CultureInfo.GetCultureInfo("en-US")));

                d0 = fParticles.GetDouble(); d1 = fParticles.GetDouble(); d2 = fParticles.GetDouble();
                fSource.WriteLine("    ({0}, {1}, {2}),", d0.ToString(CultureInfo.GetCultureInfo("en-US")), d1.ToString(CultureInfo.GetCultureInfo("en-US")), d2.ToString(CultureInfo.GetCultureInfo("en-US")));

                d0 = fParticles.GetDouble(); d1 = fParticles.GetDouble(); d2 = fParticles.GetDouble();
                fSource.WriteLine("    {0},\r\n    {1}, {2}\r\n  ),\r\n", d0.ToString(CultureInfo.GetCultureInfo("en-US")), d1.ToString(CultureInfo.GetCultureInfo("en-US")), d2.ToString(CultureInfo.GetCultureInfo("en-US")));
            }
            fSource.Write("]");
            fSource.Close();
            fParticles.Close();

            Common.GenerateId("ID_particle_systems.py", Common.ParticleSystems, "psys");
        }
Ejemplo n.º 12
0
        public static void Decompile()
        {
            var fPostfx = new Text(Path.Combine(Common.InputPath, "postfx.txt"));
            var fSource = new Win32FileWriter(Path.Combine(Common.OutputPath, "module_postfx.py"));

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.Postfx);
            fPostfx.GetString();
            int iPostFXs   = fPostfx.GetInt();
            var postfxList = new string[iPostFXs];

            for (int i = 0; i < iPostFXs; i++)
            {
                postfxList[i] = fPostfx.GetWord().Remove(0, 4);
                fSource.Write("  (\"{0}\"", postfxList[i]);

                var dwFlag = fPostfx.GetDWord();
                if (dwFlag == 1)
                {
                    fSource.Write(", fxf_highhdr");
                }
                else
                {
                    fSource.Write(", {0}", dwFlag);
                }

                var iOpType = fPostfx.GetInt();
                fSource.Write(", {0},", iOpType);
                for (int p = 0; p < 3; p++)
                {
                    double d1 = fPostfx.GetDouble(), d2 = fPostfx.GetDouble(), d3 = fPostfx.GetDouble(), d4 = fPostfx.GetDouble();
                    fSource.Write(" [{0}, {1}, {2}, {3}]{4}", d1.ToString(CultureInfo.GetCultureInfo("en-US")), d2.ToString(CultureInfo.GetCultureInfo("en-US")),
                                  d3.ToString(CultureInfo.GetCultureInfo("en-US")), d4.ToString(CultureInfo.GetCultureInfo("en-US")), p < 2 ? "," : "");
                }
                fSource.WriteLine("),");
            }
            fSource.Write("]");
            fSource.Close();
            fPostfx.Close();

            Common.GenerateId("ID_postfx_params.py", postfxList, "pfx");
        }
Ejemplo n.º 13
0
        public static void Decompile()
        {
            var fSkills = new Text(Path.Combine(Common.InputPath, "skills.txt"));
            var fSource = new Win32FileWriter(Path.Combine(Common.OutputPath, "module_skills.py"));

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.Skills);
            int iSkills = fSkills.GetInt();

            for (int s = 0; s < iSkills; s++)
            {
                fSource.WriteLine("  (\"{0}\", \"{1}\", {2}, {3}, \"{4}\"),", fSkills.GetWord().Remove(0, 4), fSkills.GetWord().Replace('_', ' '),
                                  DecompileFlags(fSkills.GetDWord()), fSkills.GetInt(), fSkills.GetWord().Replace('_', ' '));
            }
            fSource.Write("]");
            fSource.Close();
            fSkills.Close();

            Common.GenerateId("ID_skills.py", Common.Skills, "skl");
        }
Ejemplo n.º 14
0
        public static void Decompile()
        {
            var fMusic = new Text(Common.InputPath + "/music.txt");
            var fSource = new Win32FileWriter(Common.OutputPath + "/module_music.py");
            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.Music);
            int iTracks = fMusic.GetInt();
            for (int t = 0; t < iTracks; t++)
            {
                string strTrack = fMusic.GetWord();
                DWORD dwTrackFlags = fMusic.GetUInt();
                DWORD dwContinueFlags = fMusic.GetUInt();
                string strTrackID = strTrack.Length >= 4 ? strTrack.Remove(strTrack.Length - 4, 4) : strTrack;
                fSource.WriteLine("  (\"{0}\", \"{1}\", {2}, {3}),", strTrackID, strTrack, DecompileFlags(dwTrackFlags), DecompileFlags(dwContinueFlags ^ dwTrackFlags));
            }
            fSource.Write("]");
            fSource.Close();
            fMusic.Close();

            Common.GenerateId("ID_music.py", Common.Music, "track");
        }
Ejemplo n.º 15
0
        public static void Decompile()
        {
            var fQuests = new Text(Common.InputPath + "/quests.txt");
            var fSource = new Win32FileWriter(Common.OutputPath + "/module_quests.py");

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.Quests);
            fQuests.GetString();
            int iQuests = fQuests.GetInt();

            for (int iQuest = 0; iQuest < iQuests; iQuest++)
            {
                fSource.WriteLine("  (\"{0}\", \"{1}\", {2}, \"{3}\"),", fQuests.GetWord().Remove(0, 4), fQuests.GetWord().Replace('_', ' '), DecompileFlags(fQuests.GetInt()), fQuests.GetWord().Replace('_', ' '));
            }

            fSource.Write("]");
            fSource.Close();
            fQuests.Close();

            Common.GenerateId("ID_quests.py", Common.Quests, "qst");
        }
Ejemplo n.º 16
0
        public static void Decompile()
        {
            var fSceneProps = new Text(Path.Combine(Common.InputPath, "scene_props.txt"));
            var fSource     = new Win32FileWriter(Path.Combine(Common.OutputPath, "module_scene_props.py"));

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.SceneProps);
            fSceneProps.GetString();
            var iSceneProps = fSceneProps.GetInt();

            for (int i = 0; i < iSceneProps; i++)
            {
                var strId  = fSceneProps.GetWord();
                var dwFlag = fSceneProps.GetUInt();
                fSceneProps.GetInt();
                fSource.Write("  (\"{0}\", {1}, \"{2}\", \"{3}\", [", strId.Remove(0, 4), DecompileFlags(dwFlag), fSceneProps.GetWord(), fSceneProps.GetWord());

                var iTriggers = fSceneProps.GetInt();

                for (int t = 0; t < iTriggers; t++)
                {
                    var dInterval = fSceneProps.GetDouble();
                    fSource.Write("\r\n    ({0},[\r\n", Common.GetTriggerParam(dInterval));

                    var iRecords = fSceneProps.GetInt();
                    if (iRecords != 0)
                    {
                        Common.PrintStatement(ref fSceneProps, ref fSource, iRecords, "      ");
                    }
                    fSource.WriteLine("    ]),");
                }
                fSource.WriteLine(iTriggers > 0 ? "  ]),\r\n" : "]),\r\n");
            }
            fSource.Write("]");
            fSource.Close();
            fSceneProps.Close();

            Common.GenerateId("ID_scene_props.py", Common.SceneProps, "spr");
        }
Ejemplo n.º 17
0
        public static void Decompile()
        {
            var fSounds = new Text(Common.InputPath + "/sounds.txt");
            var fSource = new Win32FileWriter(Common.OutputPath + "/module_sounds.py");

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.Sounds);
            fSounds.GetString();
            int iSamples = fSounds.GetInt();
            var aSamples = new List <string>();

            for (int s = 0; s < iSamples; s++)
            {
                aSamples.Add(fSounds.GetWord());
                fSounds.GetString();
            }

            int iSounds = fSounds.GetInt();

            for (int s = 0; s < iSounds; s++)
            {
                fSource.Write("  (\"{0}\", {1},", fSounds.GetWord().Remove(0, 4), DecompileFlags(fSounds.GetDWord()));
                int iListCount = fSounds.GetInt();
                fSource.Write(" [");
                for (int l = 0; l < iListCount; l++)
                {
                    int iSample = fSounds.GetInt();
                    fSounds.GetInt();
                    fSource.Write("\"{0}\"{1}", aSamples[iSample], l == iListCount - 1 ? "" : ", ");
                }
                fSource.WriteLine("]),");
            }

            fSource.Write("]");
            fSource.Close();
            fSounds.Close();

            Common.GenerateId("ID_sounds.py", Common.Sounds, "snd");
        }
Ejemplo n.º 18
0
        public static void Decompile()
        {
            var fSounds = new Text(Path.Combine(Common.InputPath, "sounds.txt"));
            var fSource = new Win32FileWriter(Path.Combine(Common.OutputPath, "module_sounds.py"));

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.Sounds);
            fSounds.GetString();
            int iSamples = fSounds.GetInt();
            var aSamples = new string[iSamples];

            for (int s = 0; s < iSamples; s++)
            {
                aSamples[s] = fSounds.GetWord();
                fSounds.GetString();
            }

            int iSounds = fSounds.GetInt();

            for (int s = 0; s < iSounds; s++)
            {
                fSource.Write("  (\"{0}\", {1},", fSounds.GetWord().Remove(0, 4), DecompileFlags(fSounds.GetDWord()));
                int iListCount = fSounds.GetInt();
                fSource.Write(" [");
                for (int l = 0; l < iListCount; l++)
                {
                    int iSample = fSounds.GetInt();
                    fSounds.GetInt();
                    fSource.Write("{0}{1}", iSample < aSamples.Length ? '"' + aSamples[iSample] + '"' : iSample.ToString(CultureInfo.GetCultureInfo("en-US")), l == iListCount - 1 ? "" : ", ");
                }
                fSource.WriteLine("]),");
            }

            fSource.Write("]");
            fSource.Close();
            fSounds.Close();

            Common.GenerateId("ID_sounds.py", Common.Sounds, "snd");
        }
Ejemplo n.º 19
0
        public static void Decompile()
        {
            var fMeshes = new Text(Common.InputPath + "/meshes.txt");
            var fSource = new Win32FileWriter(Common.OutputPath + "/module_meshes.py");

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.Meshes);
            int iMeshes = fMeshes.GetInt();

            for (int m = 0; m < iMeshes; m++)
            {
                fSource.Write("  (\"{0}\", ", fMeshes.GetWord().Remove(0, 5));

                int iFlag = fMeshes.GetInt();
                if (iFlag == 1)
                {
                    fSource.Write("render_order_plus_1,");
                }
                else
                {
                    fSource.Write("{0},", iFlag);
                }

                fSource.Write(" \"{0}\"", fMeshes.GetWord());

                for (int i = 0; i < 9; i++)
                {
                    fSource.Write(", {0}", fMeshes.GetDouble().ToString(CultureInfo.GetCultureInfo("en-US")));
                }
                fSource.WriteLine("),");
            }
            fSource.Write("]");
            fSource.Close();
            fMeshes.Close();

            Common.GenerateId("ID_meshes.py", Common.Meshes, "mesh");
        }
Ejemplo n.º 20
0
        public static void Decompile()
        {
            var fScripts = new Text(Path.Combine(Common.InputPath, "scripts.txt"));
            var fSource  = new Win32FileWriter(Path.Combine(Common.OutputPath, "module_scripts.py"));

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.Scripts);
            fScripts.GetString();
            int iScripts = fScripts.GetInt();

            for (int s = 0; s < iScripts; s++)
            {
                fSource.Write("  (\"{0}\",\r\n  [\r\n", fScripts.GetWord());
                fScripts.GetInt();
                int iRecords = fScripts.GetInt();
                Common.PrintStatement(ref fScripts, ref fSource, iRecords, "    ");
                fSource.Write("  ]),\r\n\r\n");
            }
            fSource.Write("]");
            fSource.Close();
            fScripts.Close();

            Common.GenerateId("ID_scripts.py", Common.Procedures, "script");
        }
Ejemplo n.º 21
0
        public static void Decompile()
        {
            var fTriggers = new Text(Path.Combine(Common.InputPath, "triggers.txt"));
            var fSource   = new Win32FileWriter(Path.Combine(Common.OutputPath, "module_triggers.py"));

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.Triggers);
            fTriggers.GetString();
            int iTriggers = fTriggers.GetInt();

            for (int t = 0; t < iTriggers; t++)
            {
                double dCheckInterval = fTriggers.GetDouble(), dDelayInterval = fTriggers.GetDouble(), dReArmInterval = fTriggers.GetDouble();
                fSource.Write("  ({0}, {1}, {2},[", GetTriggerParam(dCheckInterval), GetTriggerParam(dDelayInterval), GetTriggerParam(dReArmInterval));
                int iConditionRecords = fTriggers.GetInt();
                if (iConditionRecords != 0)
                {
                    fSource.WriteLine();
                    Common.PrintStatement(ref fTriggers, ref fSource, iConditionRecords, "    ");
                    fSource.Write("  ");
                }
                fSource.Write("],\r\n  [");
                iConditionRecords = fTriggers.GetInt();
                if (iConditionRecords != 0)
                {
                    fSource.WriteLine();
                    Common.PrintStatement(ref fTriggers, ref fSource, iConditionRecords, "    ");
                    fSource.Write("  ");
                }

                fSource.WriteLine("]),\r\n");
            }
            fSource.Write("]");
            fSource.Close();
            fTriggers.Close();
        }
Ejemplo n.º 22
0
        public static void Decompile()
        {
            var fInfoPages = new Text(Path.Combine(Common.InputPath, "info_pages.txt"));
            var fSource    = new Win32FileWriter(Path.Combine(Common.OutputPath, "module_info_pages.py"));

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.InfoPages);
            fInfoPages.GetString();
            int iInfoPages = fInfoPages.GetInt();

            var infoPages = new string[iInfoPages];

            for (int i = 0; i < iInfoPages; i++)
            {
                infoPages[i] = fInfoPages.GetWord().Remove(0, 3);
                fSource.WriteLine("  (\"{0}\", \"{1}\", \"{2}\"),", infoPages[i], fInfoPages.GetWord().Replace('_', ' '), fInfoPages.GetWord().Replace('_', ' '));
            }

            fSource.Write("]");
            fSource.Close();
            fInfoPages.Close();

            Common.GenerateId("ID_info_pages.py", infoPages, "ip");
        }
Ejemplo n.º 23
0
        public static void Decompile()
        {
            var fScenes = new Text(Common.InputPath + "/scenes.txt");
            var fSource = new Win32FileWriter(Common.OutputPath + "/module_scenes.py");

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.Scenes);
            fScenes.GetString();
            int iScenes = fScenes.GetInt();

            for (int iS = 0; iS < iScenes; iS++)
            {
                fScenes.GetWord();
                fSource.Write(" (\"{0}\"", fScenes.GetWord());

                DWORD dwFlag = fScenes.GetDWord();
                fSource.Write(", {0}, \"{1}\", \"{2}\"", DecompileFlags(dwFlag), fScenes.GetWord(), fScenes.GetWord());

                double d1 = fScenes.GetDouble(), d2 = fScenes.GetDouble();
                fSource.Write(", ({0}, {1})", d1.ToString(CultureInfo.GetCultureInfo("en-US")), d2.ToString(CultureInfo.GetCultureInfo("en-US")));
                d1 = fScenes.GetDouble(); d2 = fScenes.GetDouble();
                fSource.Write(", ({0}, {1})", d1.ToString(CultureInfo.GetCultureInfo("en-US")), d2.ToString(CultureInfo.GetCultureInfo("en-US")));

                fSource.Write(", {0}, \"{1}\",[", fScenes.GetDouble().ToString(CultureInfo.GetCultureInfo("en-US")), fScenes.GetWord());

                int iPassages = fScenes.GetInt();
                for (int i = 0; i < iPassages; i++)
                {
                    int iScene = fScenes.GetInt();
                    if (iScene == 100000)
                    {
                        fSource.Write("\"exit\"");
                    }
                    //else if (iScene == 0)
                    //    fprintf(g_fOutput, "\"\"");
                    else
                    {
                        fSource.Write("\"{0}\"", Common.Scenes[iScene]);
                    }
                    if (i < (iPassages - 1))
                    {
                        fSource.Write(", ");
                    }
                }
                fSource.Write("], [");

                int iChestTroops = fScenes.GetInt();

                for (int i = 0; i < iChestTroops; i++)
                {
                    int iTroop = fScenes.GetInt();
                    if (iTroop < Common.Troops.Length)
                    {
                        fSource.Write("\"{0}\"", Common.Troops[iTroop]);
                    }
                    else
                    {
                        fSource.Write("{0}", iTroop);
                    }
                    if (i < (iChestTroops - 1))
                    {
                        fSource.Write(", ");
                    }
                }
                fSource.Write("]");

                string strTerrain = fScenes.GetWord();
                if (strTerrain != "0")
                {
                    fSource.Write(", \"{0}\"", strTerrain);
                }

                fSource.WriteLine("),");
            }
            fSource.Write("]");
            fSource.Close();
            fScenes.Close();

            Common.GenerateId("ID_scenes.py", Common.Scenes, "scn");
        }
Ejemplo n.º 24
0
        public static void Decompile()
        {
            var fDialogs = new Text(Common.InputPath + "/conversation.txt");
            var fSource  = new Win32FileWriter(Common.OutputPath + "/module_dialogs.py");

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.Dialogs);
            fDialogs.GetString();
            int iDialogs = fDialogs.GetInt();

            for (int t = 0; t < iDialogs; t++)
            {
                fDialogs.GetWord();
                DWORD dwDialogPartner      = fDialogs.GetUInt();
                int   iStartingDialogState = fDialogs.GetInt();
                var   sbDialogPartner      = new StringBuilder(256);

                string[] strRepeatsPrefix = { "repeat_for_factions", "repeat_for_parties", "repeat_for_troops", "repeat_for_100", "repeat_for_1000" };
                uint     iRepeat          = (dwDialogPartner & 0x00007000) >> 12;
                if (iRepeat != 0)
                {
                    sbDialogPartner.Append(strRepeatsPrefix[iRepeat - 1]);
                    sbDialogPartner.Append('|');
                }

                string[] strPartnerPrefix = { "plyr", "party_tpl", "auto_proceed", "multi_line" };
                int[]    iPartnerPrefix   = { 0x00010000, 0x00020000, 0x00040000, 0x00080000 };
                for (int i = 0; i < 4; i++)
                {
                    if ((iPartnerPrefix[i] & dwDialogPartner) != 0)
                    {
                        sbDialogPartner.Append(strPartnerPrefix[i]);
                        sbDialogPartner.Append('|');
                    }
                }

                DWORD dwPartner = dwDialogPartner & 0x00000FFF;
                if (dwPartner == 0x00000FFF)
                {
                    sbDialogPartner.Append("anyone|");
                }
                else if (dwPartner != 0)
                {
                    sbDialogPartner.Append(dwPartner < Common.Troops.Length ? "trp_" + Common.Troops[dwPartner] + "|" : $"{dwPartner}|");
                }

                DWORD dwOther = (dwDialogPartner & 0xFFF00000) >> 20;
                if (dwOther != 0)
                {
                    sbDialogPartner.Append(dwOther < Common.Troops.Length ? "other(trp_" + Common.Troops[dwOther] + ")|" : $"other({dwOther})|");
                }

                if (sbDialogPartner.Length == 0)
                {
                    sbDialogPartner.Append('0');
                }
                else
                {
                    sbDialogPartner.Length--;
                }

                fSource.Write("  [{0}, \"{1}\",\r\n    [", sbDialogPartner, Common.DialogStates[iStartingDialogState]);

                int iRecords = fDialogs.GetInt();
                if (iRecords != 0)
                {
                    fSource.WriteLine();
                    Common.PrintStatement(ref fDialogs, ref fSource, iRecords, "      ");
                    fSource.WriteLine("    ],");
                }
                else
                {
                    fSource.WriteLine("],");
                }

                string strDialogText = fDialogs.GetWord();
                fSource.WriteLine("    \"{0}\",", strDialogText.Replace('_', ' '));

                int iEndingDialogState = fDialogs.GetInt();
                fSource.Write("    \"{0}\",\r\n    [", Common.DialogStates[iEndingDialogState]);

                iRecords = fDialogs.GetInt();
                if (iRecords != 0)
                {
                    fSource.WriteLine();
                    Common.PrintStatement(ref fDialogs, ref fSource, iRecords, "      ");
                    fSource.Write("    ]");
                }
                else
                {
                    fSource.Write("]");
                }

                string strVoiceOver = fDialogs.GetWord();
                if (strVoiceOver.Trim() != "NO_VOICEOVER")
                {
                    fSource.Write(",\r\n    [\"{0}\"]", strVoiceOver);
                }

                fSource.WriteLine("],\r\n");
            }
            fSource.Write("]");
            fSource.Close();
            fDialogs.Close();
        }
Ejemplo n.º 25
0
        public static void Decompile()
        {
            var fGroundSpecs = new Text(Path.Combine(Common.InputPath, "ground_specs.txt"));
            var fSource      = new Win32FileWriter(Path.Combine(Common.OutputPath, "module_ground_specs.py"));

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.GroundSpecs);

            int n = GetLexemsInFile(Path.Combine(Common.InputPath, "ground_specs.txt")) >> 3;  // / 8;

            for (int i = 0; i < n; i++)
            {
                var    strId                   = fGroundSpecs.GetWord();
                var    dwFlag                  = fGroundSpecs.GetUInt();
                var    strMaterial             = fGroundSpecs.GetWord();
                var    dblUVScale              = fGroundSpecs.GetDouble();
                var    strMultitexMaterialName = fGroundSpecs.GetWord();
                double dColor1                 = fGroundSpecs.GetDouble(),
                       dColor2                 = fGroundSpecs.GetDouble(),
                       dColor3                 = fGroundSpecs.GetDouble();

                var      sbFlag   = new StringBuilder(64);
                string[] strFlags = { "gtf_overlay", "gtf_dusty", "gtf_has_color" };
                DWORD[]  dwFlags  = { 1, 2, 4 };

                for (int j = 0; j < dwFlags.Length; j++)
                {
                    if ((dwFlag & dwFlags[j]) == 0)
                    {
                        continue;
                    }
                    dwFlag ^= dwFlags[j];
                    sbFlag.Append(strFlags[j]);
                    sbFlag.Append('|');
                }

                if (sbFlag.Length == 0)
                {
                    sbFlag.Append('0');
                }
                else
                {
                    sbFlag.Length--;
                }

                fSource.WriteLine("  (\"{0}\", {1}, \"{2}\", {3}, \"{4}\", ({5}, {6}, {7})),", strId, sbFlag, strMaterial,
                                  dblUVScale.ToString(CultureInfo.GetCultureInfo("en-US")), strMultitexMaterialName,
                                  dColor1.ToString(CultureInfo.GetCultureInfo("en-US")), dColor2.ToString(CultureInfo.GetCultureInfo("en-US")),
                                  dColor3.ToString(CultureInfo.GetCultureInfo("en-US")));
            }
            fSource.WriteLine(@"]

def write_vec(file,vec):
  file.write("" %f %f %f ""%vec)
  
def save_ground_specs():
  file = open(export_dir + ""Data/ground_specs.txt"",""w"")
  for ground_spec in ground_specs:
    file.write("" %s %d %s %f %s""%(ground_spec[0],ground_spec[1],ground_spec[2],ground_spec[3],ground_spec[4]))
    if (ground_spec[1] & gtf_has_color):
      file.write("" %f %f %f""%ground_spec[5])
    file.write(""\n"")
  file.close()

def save_c_header():
  file = open(export_dir + ""ground_spec_codes.h"",""w"")
  file.write(""#ifndef _GROUND_SPEC_CODES_H\n"")
  file.write(""#define _GROUND_SPEC_CODES_H\n\n"")
  file.write(""typedef enum {\n"")
  for ground_spec in ground_specs:
    file.write(""  ground_%s,\n""%ground_spec[0])
  file.write(""}Ground_spec_codes;\n"")
  file.write(""const int num_ground_specs = %d;\n""%(len(ground_specs)))
  file.write(""\n\n"")
  file.write(""\n#endif\n"")
  file.close()
  
def save_python_header():
  file = open(""./header_ground_types.py"",""w"")
  for ig in xrange(len(ground_specs)):
    ground_spec = ground_specs[ig]
    file.write(""ground_%s = %d\n""%(ground_spec[0], ig))
  file.write(""\n\n"")
  file.close()

print ""Exporting ground_spec data...""
save_ground_specs()
save_c_header()
save_python_header()");
            fSource.Close();
            fGroundSpecs.Close();
        }
Ejemplo n.º 26
0
        public static void Decompile()
        {
            var fMenus  = new Text(Common.InputPath + "/menus.txt");
            var fSource = new Win32FileWriter(Common.OutputPath + "/module_game_menus.py");

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.Menus);
            fMenus.GetString();
            int iMenus = fMenus.GetInt();

            for (int m = 0; m < iMenus; m++)
            {
                string strMenuID = fMenus.GetWord();
                fSource.Write("  (\"{0}\",", strMenuID.Remove(0, 5));

                ulong lMenuFlags = fMenus.GetUInt64();
                fSource.WriteLine(" {0},", DecompileFlags(lMenuFlags));

                string strMenuText = fMenus.GetWord();
                fSource.WriteLine("    \"{0}\",", strMenuText.Replace('_', ' '));

                fSource.WriteLine("    \"{0}\",", fMenus.GetWord());

                int iRecords = fMenus.GetInt();
                if (iRecords != 0)
                {
                    fSource.WriteLine("    [");
                    Common.PrintStatement(ref fMenus, ref fSource, iRecords, "      ");
                    fSource.WriteLine("    ],");
                }
                else
                {
                    fSource.WriteLine("    [],");
                }

                int iMenuOptions = fMenus.GetInt();

                fSource.WriteLine("    [");
                for (int i = 0; i < iMenuOptions; i++)
                {
                    string szMenuOption = fMenus.GetWord();
                    fSource.WriteLine("      (\"{0}\",", szMenuOption.Remove(0, 4));

                    iRecords = fMenus.GetInt();
                    if (iRecords != 0)
                    {
                        fSource.WriteLine("      [");
                        Common.PrintStatement(ref fMenus, ref fSource, iRecords, "        ");
                        fSource.WriteLine("      ],");
                    }
                    else
                    {
                        fSource.WriteLine("      [],");
                    }

                    string strMenuOptionText = fMenus.GetWord();
                    fSource.WriteLine("      \"{0}\",", strMenuOptionText);

                    iRecords = fMenus.GetInt();
                    if (iRecords != 0)
                    {
                        fSource.WriteLine("      [");
                        Common.PrintStatement(ref fMenus, ref fSource, iRecords, "        ");
                        fSource.WriteLine("      ]");
                    }
                    else
                    {
                        fSource.WriteLine("      []");
                    }

                    string strDoorName = fMenus.GetWord();
                    if (strDoorName != ".")
                    {
                        fSource.WriteLine(",\r\n      \"{0}\"", strDoorName);
                    }
                    fSource.Write("      ),\r\n");

                    if ((iMenuOptions - i - 1) != 0)
                    {
                        fSource.WriteLine();
                    }
                }
                fSource.WriteLine("    ],");

                if (iMenuOptions == 0)
                {
                    fSource.WriteLine("    [],");
                }

                fSource.WriteLine("  ),\r\n");
            }
            fSource.Write("]");
            fSource.Close();
            fMenus.Close();

            Common.GenerateId("ID_menus.py", Common.Menus, "menu");
        }
Ejemplo n.º 27
0
        private static void ProcessFullModule()
        {
            File.Copy(Path.Combine(Common.InputPath, "variables.txt"), Path.Combine(Common.OutputPath, "variables.txt"), true);

            var decompileShaders = Common.DecompileShaders;

            if (!Common.IsVanillaMode)
            {
                Win32FileWriter.WriteAllText(Path.Combine(Common.OutputPath, "module_constants.py"), Header.Standard + Common.ModuleConstantsText);
            }
            else
            {
                Win32FileWriter.WriteAllText(Path.Combine(Common.OutputPath, "module_constants.py"), Header.Standard + Common.ModuleConstantsVanillaText);
            }

            string[] strModFiles = { "actions.txt", "conversation.txt",  "factions.txt",          "info_pages.txt",  "item_kinds1.txt",       "map_icons.txt",
                                     "menus.txt",   "meshes.txt",        "mission_templates.txt", "music.txt",       "particle_systems.txt",  "parties.txt",  "party_templates.txt",
                                     "postfx.txt",  "presentations.txt", "quests.txt",            "scene_props.txt", "scenes.txt",            "scripts.txt",  "simple_triggers.txt",
                                     "skills.txt",  "skins.txt",         "sounds.txt",            "strings.txt",     "tableau_materials.txt", "triggers.txt", "troops.txt" };
            string[] strModDataFiles = { "flora_kinds.txt", "ground_specs.txt", "skyboxes.txt" };

            int iNumFiles = strModFiles.Length;

            if (Common.IsVanillaMode)
            {
                iNumFiles -= 2;
            }

            iNumFiles += strModDataFiles.Count(strModDataFile => File.Exists(Path.Combine(Common.InputPath, "Data", strModDataFile)));

            var sShadersFile = GetShadersFullFileName(out var b);

            if (b && decompileShaders)
            {
                iNumFiles++;
            }

            double dblProgressForOneFile = 100.0 / iNumFiles, dblProgress = 0;

            foreach (var strModFile in strModFiles.Where(strModFile => !(Common.IsVanillaMode && (strModFile == "info_pages.txt" || strModFile == "postfx.txt"))))
            {
                ProcessFile(strModFile);
                dblProgress += dblProgressForOneFile;
                Status       = $"Decompiling {dblProgress:F2}%";
            }

            if (b && decompileShaders)
            {
                ProcessShaders(sShadersFile);
                dblProgress += dblProgressForOneFile;
                Status       = $"Decompiling  {dblProgress:F2}%";
            }

            Common.InputPath = Path.Combine(Common.InputPath, "Data");

            foreach (var strModDataFile in strModDataFiles.Where(strModDataFile => File.Exists(Common.InputPath + "/" + strModDataFile)))
            {
                ProcessFile(strModDataFile);
                dblProgress += dblProgressForOneFile;
                Status       = $"Decompiling  {dblProgress:F2}%";
            }
        }
Ejemplo n.º 28
0
        public static void Decompile()
        {
            var fMissionTemplates = new Text(Common.InputPath + "/mission_templates.txt");
            var fSource           = new Win32FileWriter(Common.OutputPath + "/module_mission_templates.py");

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.MissionTemplates);
            fMissionTemplates.GetString();
            int iMissionTemplates = fMissionTemplates.GetInt();

            for (int m = 0; m < iMissionTemplates; m++)
            {
                fMissionTemplates.GetWord();
                fSource.Write("  (\"{0}\",", fMissionTemplates.GetWord());

                DWORD    dwFlag   = fMissionTemplates.GetDWord();
                string   strFlag  = "";
                string[] strFlags = { "mtf_arena_fight", "mtf_battle_mode", "mtf_commit_casualties", "mtf_no_blood", "mtf_synch_inventory" };
                DWORD[]  dwFlags  = { 0x00000001, 0x00000002, 0x00000010, 0x00000100, 0x00010000 };
                for (int i = 0; i < dwFlags.Length; i++)
                {
                    if ((dwFlag & dwFlags[i]) != 0)
                    {
                        dwFlag  ^= dwFlags[i];
                        strFlag += strFlags[i] + "|";
                    }
                }

                /*for (int i = dwFlags.Length - 1; i >= 0; i--)
                 * {
                 *  if (dwFlag >= dwFlags[i])
                 *  {
                 *      strFlag = strFlag + strFlags[i] + "|";
                 *  }
                 * }*/

                strFlag = strFlag == "" ? "0" : strFlag.Remove(strFlag.Length - 1, 1);

                /*var sbFlag = new StringBuilder(256);
                 * string[] strFlags = { "mtf_arena_fight", "mtf_battle_mode", "mtf_commit_casualties", "mtf_no_blood", "mtf_synch_inventory" };
                 * DWORD[] dwFlags = { 0x00000001, 0x00000002, 0x00000010, 0x00000100, 0x00010000 };
                 * for (int i = 0; i < dwFlags.Length; i++)
                 * {
                 *  if ((dwFlag & dwFlags[i]) != 0)
                 *  {
                 *      dwFlag ^= dwFlags[i];
                 *      sbFlag.Append(strFlags[i]);
                 *      sbFlag.Append('|');
                 *  }
                 * }
                 * if (sbFlag.Length == 0)
                 *  sbFlag.Append('0');
                 * else
                 *  sbFlag.Length--;*/

                fSource.Write(" {0},", strFlag);

                int    iType   = fMissionTemplates.GetInt();
                string strType = "";
                if (iType == 8)
                {
                    strType = "charge";
                }
                else if (iType == 10)
                {
                    strType = "charge_with_ally";
                }
                if (strType != "")
                {
                    fSource.WriteLine(" {0},", strType);
                }
                else
                {
                    fSource.WriteLine(" {0},", iType);
                }

                fSource.WriteLine("  \"{0}\",\r\n  [", fMissionTemplates.GetWord().Replace('_', ' '));
                int iSpawnRecords = fMissionTemplates.GetInt();
                for (int i = 0; i < iSpawnRecords; i++)
                {
                    int   iNum        = fMissionTemplates.GetInt();
                    DWORD dwSpawnFlag = fMissionTemplates.GetDWord();
                    DWORD dwAlterFlag = fMissionTemplates.GetDWord();
                    DWORD dwAIFlag    = fMissionTemplates.GetDWord();
                    int   iTroops     = fMissionTemplates.GetInt();
                    int   iItems      = fMissionTemplates.GetInt();
                    fSource.Write("    ({0}, {1}, {2}", iNum, DecompileSpawnFlags(dwSpawnFlag), DecompileAlterFlags(dwAlterFlag));

                    if (dwAIFlag == 0x00000010)
                    {
                        fSource.Write(", aif_start_alarmed");
                    }
                    else
                    {
                        fSource.Write(", {0}", dwAIFlag);
                    }

                    fSource.Write(", {0}, [", iTroops);

                    string strItemList = "";
                    for (int j = 0; j < iItems; j++)
                    {
                        //fSource.Write("{0},", Common.Items[fMissionTemplates.GetInt()]);
                        strItemList = strItemList + $"itm_{Common.Items[fMissionTemplates.GetInt()]},";
                    }
                    if (strItemList.Length > 0)
                    {
                        strItemList = strItemList.Remove(strItemList.Length - 1, 1);
                    }
                    fSource.WriteLine("{0}]),", strItemList);
                }
                fSource.WriteLine("  ],\r\n  [");

                int iTriggers = fMissionTemplates.GetInt();
                for (int i = 0; i < iTriggers; i++)
                {
                    fSource.Write("    (");
                    for (int j = 0; j < 3; j++)
                    {
                        double dInterval = fMissionTemplates.GetDouble();
                        fSource.Write("{0}, ", Common.GetTriggerParam(dInterval));
                    }
                    fSource.Write("\r\n    [");

                    int iConditionRecords = fMissionTemplates.GetInt();
                    if (iConditionRecords != 0)
                    {
                        fSource.WriteLine();
                        Common.PrintStatement(ref fMissionTemplates, ref fSource, iConditionRecords, "      ");
                        fSource.Write("    ");
                    }
                    fSource.Write("],\r\n    [");
                    iConditionRecords = fMissionTemplates.GetInt();
                    if (iConditionRecords != 0)
                    {
                        fSource.WriteLine();
                        Common.PrintStatement(ref fMissionTemplates, ref fSource, iConditionRecords, "      ");
                        fSource.Write("    ");
                    }

                    fSource.Write("]),\r\n\r\n");
                }
                fSource.Write("  ]),\r\n\r\n");
            }
            fSource.Write("]");
            fSource.Close();
            fMissionTemplates.Close();

            Common.GenerateId("ID_mission_templates.py", Common.MissionTemplates, "mst");
        }
Ejemplo n.º 29
0
        public static void Decompile()
        {
            var fSkins  = new Text(Common.InputPath + "/skins.txt");
            var fSource = new Win32FileWriter(Common.OutputPath + "/module_skins.py");

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.Skins);
            fSkins.GetString();
            int iSkins = fSkins.GetInt();

            for (int s = 0; s < iSkins; s++)
            {
                fSource.WriteLine("  (\r\n    \"{0}\", {1},", fSkins.GetWord(), fSkins.GetInt());
                fSource.WriteLine("    \"{0}\", \"{1}\", \"{2}\",", fSkins.GetWord(), fSkins.GetWord(), fSkins.GetWord());
                fSource.WriteLine("    \"{0}\",\r\n    [", fSkins.GetWord());

                int iFaceKeys = fSkins.GetInt();
                for (int i = 0; i < iFaceKeys; i++)
                {
                    fSkins.GetWord();
                    double d1 = fSkins.GetDouble(), d2 = fSkins.GetDouble(), d3 = fSkins.GetDouble(), d4 = fSkins.GetDouble();
                    string strText = fSkins.GetWord();
                    fSource.WriteLine("      ({0}, {1}, {2}, {3}, \"{4}\"),", d1.ToString(CultureInfo.GetCultureInfo("en-US")), d2.ToString(CultureInfo.GetCultureInfo("en-US")),
                                      d3.ToString(CultureInfo.GetCultureInfo("en-US")), d4.ToString(CultureInfo.GetCultureInfo("en-US")), strText.Replace('_', ' '));
                }
                fSource.WriteLine("    ],");

                int iMeshesHair = fSkins.GetInt();
                fSource.Write("    [");
                for (int i = 0; i < iMeshesHair; i++)
                {
                    fSource.Write("\"{0}\"{1}", fSkins.GetWord(), i != iMeshesHair - 1 ? ", " : "");
                }
                fSource.WriteLine("],");

                int iMeshesBeard = fSkins.GetInt();
                fSource.Write("    [");
                for (int i = 0; i < iMeshesBeard; i++)
                {
                    fSource.Write("\"{0}\"{1}", fSkins.GetWord(), i != iMeshesBeard - 1 ? ", " : "");
                }
                fSource.WriteLine("],");

                for (int i = 0; i < 2; i++)
                {
                    int iTextures = fSkins.GetInt();
                    fSource.Write("    [");
                    for (int t = 0; t < iTextures; t++)
                    {
                        fSource.Write("\"{0}\"{1}", fSkins.GetWord(), t != iTextures - 1 ? ", " : "");
                    }
                    fSource.WriteLine("],");
                }

                int iTexturesFace = fSkins.GetInt();
                fSource.WriteLine("    [");
                for (int i = 0; i < iTexturesFace; i++)
                {
                    fSource.Write("      (\"{0}\", 0x{1:X}, ", fSkins.GetWord(), fSkins.GetDWord());
                    int iHairMats   = fSkins.GetInt();
                    int iHairColors = fSkins.GetInt();
                    for (int m = 0; m < iHairMats; m++)
                    {
                        fSource.Write("[\"{0}\"], ", fSkins.GetWord());
                    }
                    fSource.Write("[");
                    for (int c = 0; c < iHairColors; c++)
                    {
                        //fprintf( g_fOutput, " 0x%X,", GetDWord() );
                        fSource.Write("0x{0:x}{1}", fSkins.GetUInt64(), c != iHairColors - 1 ? ", " : "");
                    }
                    fSource.WriteLine("]),");
                }
                fSource.WriteLine("    ],");

                int iVoices = fSkins.GetInt();
                fSource.Write("    [");
                for (int v = 0; v < iVoices; v++)
                {
                    DWORD    dwFlag   = fSkins.GetDWord();
                    string[] strFlags = { "voice_die", "voice_hit", "voice_grunt", "voice_grunt_long", "voice_yell", "voice_warcry", "voice_victory", "voice_stun" };
                    if (dwFlag <= 7)
                    {
                        fSource.Write("({0},", strFlags[dwFlag]);
                    }
                    else
                    {
                        fSource.Write("({0},", dwFlag);
                    }

                    string strSound = fSkins.GetWord();
                    fSource.Write(" \"{0}\"){1}", strSound, v != iVoices - 1 ? "," : "");
                }
                fSource.WriteLine("],");

                string strSkeleton = fSkins.GetWord();
                fSource.WriteLine("    \"{0}\", {1},", strSkeleton, fSkins.GetWord());

                int ixParticleSystem1 = fSkins.GetInt(),
                    ixParticleSystem2 = fSkins.GetInt();
                fSource.WriteLine("    psys_{0}, psys_{1},", Common.ParticleSystems[ixParticleSystem1], Common.ParticleSystems[ixParticleSystem2]);

                int iConstraints = fSkins.GetInt();
                fSource.Write("    [");
                for (int i = 0; i < iConstraints; i++)
                {
                    double d1 = fSkins.GetDouble();
                    fSource.Write("\r\n      [{0},", d1.ToString(CultureInfo.GetCultureInfo("en-US")));

                    int    i1 = fSkins.GetInt();
                    string c1 = i1 == 1 ? "comp_greater_than" : i1 == -1 ? "comp_less_than" : "0";
                    if (c1 != "0")
                    {
                        fSource.Write(" {0}, ", c1);
                    }
                    else
                    {
                        fSource.Write(" {0}, ", i1);
                    }

                    int count = fSkins.GetInt();
                    for (int c = 0; c < count; c++)
                    {
                        double dc1 = fSkins.GetDouble();
                        int    ic1 = fSkins.GetInt();

                        fSource.Write("({0}, {1}){2}", dc1.ToString(CultureInfo.GetCultureInfo("en-US")), ic1, c != count - 1 ? "," : "");
                    }
                    fSource.Write("],");
                }
                fSource.WriteLine("\r\n  ]),\r\n");
            }
            fSource.Write("]");
            fSource.Close();
            fSkins.Close();
        }
Ejemplo n.º 30
0
        public static void Decompile()
        {
            var fParties = new Text(Common.InputPath + "/parties.txt");
            var fSource  = new Win32FileWriter(Common.OutputPath + "/module_parties.py");

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.Parties);
            fParties.GetString();
            int iParties = fParties.GetInt();

            fParties.GetInt();
            for (int i = 0; i < iParties; i++)
            {
                fParties.GetInt(); fParties.GetInt(); fParties.GetInt();
                fSource.Write(" (\"{0}\", \"{1}\", {2}", fParties.GetWord().Remove(0, 2), fParties.GetWord().Replace('_', ' '), DecompileFlags(fParties.GetDWord()));

                int iMenu = fParties.GetInt();
                fSource.Write(", {0}", iMenu == 0 ? "no_menu" : "mnu_" + Common.Menus[iMenu]);

                int iParty = fParties.GetInt();
                fSource.Write(", {0}", iParty == 0 ? "pt_none" : "pt_" + Common.PTemps[iParty]);

                int iFaction = fParties.GetInt();
                fSource.Write(", {0}", "fac_" + Common.Factions[iFaction]);

                int iPersonality = fParties.GetInt(); fParties.GetInt();
                fSource.Write(", {0}", iPersonality);

                int      iAIbehaviour    = fParties.GetInt(); fParties.GetInt();
                string[] strAIbehaviours = { "ai_bhvr_hold",           "ai_bhvr_travel_to_party", "ai_bhvr_patrol_location", "ai_bhvr_patrol_party",
                                             "ai_bhvr_attack_party",   "ai_bhvr_avoid_party",     "ai_bhvr_travel_to_point", "ai_bhvr_negotiate_party","ai_bhvr_in_town",
                                             "ai_bhvr_travel_to_ship", "ai_bhvr_escort_party",    "ai_bhvr_driven_by_party" };
                fSource.Write(", {0}", iAIbehaviour <= 11 ? strAIbehaviours[iAIbehaviour] : iAIbehaviour.ToString(CultureInfo.GetCultureInfo("en-US")));

                int iAITargetParty = fParties.GetInt();
                fSource.Write(", {0}", iAITargetParty);

                double dX = fParties.GetDouble(), dY = fParties.GetDouble();
                fSource.Write(", ({0}, {1}), [", dX.ToString(CultureInfo.GetCultureInfo("en-US")), dY.ToString(CultureInfo.GetCultureInfo("en-US")));
                fParties.GetDouble(); fParties.GetDouble(); fParties.GetDouble(); fParties.GetDouble(); fParties.GetDouble();

                int iRecords = fParties.GetInt();
                for (int j = 0; j < iRecords; j++)
                {
                    int iTroop     = fParties.GetInt();
                    int iNumTroops = fParties.GetInt(); fParties.GetInt();
                    int iFlag      = fParties.GetInt();
                    fSource.Write("(trp_{0}, {1}, {2}){3}", Common.Troops[iTroop], iNumTroops, iFlag == 1 ? "pmf_is_prisoner" : "0", j == (iRecords - 1) ? "" : ",");
                }
                fSource.Write("]");
                double dAngle = fParties.GetDouble();
                if (Math.Abs(dAngle) > 0.0000001)
                {
                    fSource.Write(", {0}", (Math.Round(dAngle * (180 / Math.PI))).ToString(CultureInfo.GetCultureInfo("en-US")));
                }

                fSource.WriteLine("),");
            }
            fSource.Write("]");
            fSource.Close();
            fParties.Close();

            Common.GenerateId("ID_parties.py", Common.Parties, "p");
        }