Пример #1
0
        public static void Decompile()
        {
            var fTriggers = new Text(Common.InputPath + "/simple_triggers.txt");
            var fSource   = new Win32FileWriter(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();
        }
Пример #2
0
        public static void Decompile()
        {
            var fActions = new Text(Common.InputPath + "/actions.txt");
            var fSource  = new Win32FileWriter(Common.OutputPath + "/module_animations.py");

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

            for (int a = 0; a < iActions; a++)
            {
                string strAnimID   = fActions.GetWord();
                DWORD  dwAnimFlags = fActions.GetDWord();
                fSource.WriteLine("  [\"{0}\", {1},", strAnimID, Core.Animations.DecompileFlags(dwAnimFlags));
                int iAnimSequences = fActions.GetInt();
                for (int s = 0; s < iAnimSequences; s++)
                {
                    double dDuration = fActions.GetDouble();
                    string strName   = fActions.GetWord();
                    fSource.Write("    [{0}, \"{1}\",", dDuration.ToString(CultureInfo.GetCultureInfo("en-US")), strName);
                    int   iBeginFrame = fActions.GetInt(), iEndingFrame = fActions.GetInt();
                    DWORD dwSequenceFlags = fActions.GetDWord();

                    var  dd      = new string[5]; //NOTE: Type string for non-english version of windows
                    bool 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, Core.Animations.DecompileSequenceFlags(dwSequenceFlags));
                    }
                    else
                    {
                        fSource.Write(" {0}, {1}, {2}, {3}, ({4}, {5}, {6}), {7}],\r\n", iBeginFrame, iEndingFrame,
                                      Core.Animations.DecompileSequenceFlags(dwSequenceFlags), Core.Animations.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");
        }
Пример #3
0
        public static void Decompile()
        {
            var fMaterials = new Win32BinaryFileReader(Path.Combine(Common.InputPath, "core_physics_materials.brf"));
            var fSource    = new Win32FileWriter(Path.Combine(Common.OutputPath, "resource_physics_materials.py"));

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

            // 6 + 4 = 10 for "rfver "
            // 4 for 1 (__int32)
            // 16 + 4 = 20 for "physics_material"
            fMaterials.SkipBytes(34);
            var iMaterials = fMaterials.ReadInt32();

            for (int m = 0; m < iMaterials; m++)
            {
                var name       = fMaterials.ReadAsciiString();
                var intValue   = fMaterials.ReadInt32();
                var floatValue = fMaterials.ReadFloat();
                fSource.WriteLine("  (\"{0}\", {1}, {2}),", name, intValue,
                                  floatValue.ToString(CultureInfo.GetCultureInfo("en-US")));
            }

            fSource.Write("]");
            fSource.Close();
            fMaterials.Close();
        }
Пример #4
0
        public static void Decompile()
        {
            var fScripts = new Text(Common.InputPath + "/scripts.txt");
            var fSource  = new Win32FileWriter(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();
        }
Пример #5
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), Core.Sounds.DecompileFlags(fSounds.GetDWord()));
                int iListCount = fSounds.GetInt();
                fSource.Write(" [");
                for (int l = 0; l < iListCount; l++)
                {
                    int iSample = 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");
        }
Пример #6
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();
            var iSamples = fSounds.GetInt();
            var aSamples = new string[iSamples];

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

            var iSounds = fSounds.GetInt();

            for (int s = 0; s < iSounds; s++)
            {
                fSource.Write("  (\"{0}\", {1},", fSounds.GetWord().Remove(0, 4), Core.Sounds.DecompileFlags(fSounds.GetDWord()));
                var iListCount = fSounds.GetInt();
                fSource.Write(" [");
                for (int l = 0; l < iListCount; l++)
                {
                    var iSample = 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");
        }
Пример #7
0
        public static void Decompile()
        {
            var fTriggers = new Text(Common.InputPath + "/triggers.txt");
            var fSource   = new Win32FileWriter(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();
        }
Пример #8
0
        public static void Decompile()
        {
            var fShaders = new Win32BinaryFileReader(Path.Combine(Common.InputPath, "core_shaders.brf"));
            var fSource  = new Win32FileWriter(Path.Combine(Common.OutputPath, "resource_shaders.py"));

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

            // 6 + 4 = 10 for "rfver "
            // 4 for 1 (__int32)
            // 6 + 4 = 10 for "shader"
            fShaders.SkipBytes(24);
            var iShaders = fShaders.ReadInt32();

            for (int s = 0; s < iShaders; s++)
            {
                var name       = fShaders.ReadAsciiString();
                var flags      = fShaders.ReadUInt32();
                var quality    = fShaders.ReadUInt32();
                var technique  = fShaders.ReadAsciiString();
                var technique2 = fShaders.ReadAsciiString();

                var iAlternatives = fShaders.ReadInt32();
                var alternatives  = new string[iAlternatives];
                for (int i = 0; i < iAlternatives; i++)
                {
                    alternatives[i] = fShaders.ReadAsciiString();
                }

                fShaders.ReadInt32(); //F*****G MAGIC!

                fSource.WriteLine("  (\"{0}\", \"{1}\", \"{2}\", {3}, {4}, [{5}]),", name, technique, technique2,
                                  DecompileFlags(flags), DecompileQuality(quality), String.Join(",", alternatives.Select(j => '"' + j + '"')));
            }


            fSource.Write("]");
            fSource.Close();
            fShaders.Close();
        }
Пример #9
0
        public static void Decompile()
        {
            var fInfoPages = new Text(Common.InputPath + "/info_pages.txt");
            var fSource    = new Win32FileWriter(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");
        }
Пример #10
0
        public static void Decompile()
        {
            var fItems  = new Text(Common.InputPath + "/item_kinds1.txt");
            var fSource = new Win32FileWriter(Common.OutputPath + "/module_items.py");

            fSource.WriteLine(Header.Standard);
            fSource.WriteLine(Header.Items);
            fItems.GetString();
            int iItems = fItems.GetInt();

            for (int i = 0; i < iItems; i++)
            {
                string strItemID = fItems.GetWord().Remove(0, 4);
                fSource.Write("  [\"{0}\"", strItemID);
                string strItemName = fItems.GetWord();

                fItems.GetWord(); // skip second name
                fSource.Write(",\"{0}\", [", strItemName);

                int iMeshes = fItems.GetInt();

                string strMeshes = "";
                for (int m = 0; m < iMeshes; m++)
                {
                    string  strMeshName = fItems.GetWord();
                    DWORD64 dwMeshBits  = fItems.GetUInt64();
                    strMeshes = strMeshes + $"(\"{strMeshName}\", {Core.Items.DecompileMeshesImodBits(dwMeshBits)}),";
                }
                if (strMeshes.Length > 0)
                {
                    strMeshes = strMeshes.Remove(strMeshes.Length - 1, 1);
                }

                fSource.Write("{0}]", strMeshes);

                DWORD64 dwItemFlags = fItems.GetUInt64();
                ulong   lItemCaps   = fItems.GetUInt64();

                BYTE bType = 0;

                fSource.Write(", {0}, {1},", DecompileFlags(dwItemFlags, ref bType), Core.Items.DecompileCapabilities(lItemCaps));

                int     iCost      = fItems.GetInt();
                DWORD64 dwImodBits = fItems.GetUInt64();

                string   strItemStats = "weight(" + fItems.GetDouble().ToString(CultureInfo.GetCultureInfo("en-US")) + ")";
                string[] strStats     = { "abundance", "head_armor",  "body_armor",    "leg_armor", "difficulty",    "hit_points",
                                          "spd_rtng",      "shoot_speed", "weapon_length", "max_ammo",  "thrust_damage", "swing_damage" };
                for (int v = 0; v < 12; v++)
                {
                    int iValue = fItems.GetInt();

                    string strState = strStats[v];

                    if (bType == HORSE_TYPE && strState == "shoot_speed")
                    {
                        strState = "horse_speed";
                    }
                    else if (bType == HORSE_TYPE && strState == "spd_rtng")
                    {
                        strState = "horse_maneuver";
                    }
                    else if (bType == GOODS_TYPE && strState == "head_armor")
                    {
                        strState = "food_quality";
                    }
                    else if ((bType == BOW_TYPE || bType == CROSSBOW_TYPE || bType == MUSKET_TYPE || bType == PISTOL_TYPE) && strState == "leg_armor")
                    {
                        strState = "accuracy";
                    }

                    if (iValue != 0)
                    {
                        if (v >= 10)
                        {
                            int    iDamage       = iValue & 0xFF;
                            int    iDamageType   = (iValue - iDamage) >> 8;
                            string strDamageType = "";
                            switch (iDamageType)
                            {
                            case 0:
                                strDamageType = "cut";
                                break;

                            case 1:
                                strDamageType = "pierce";
                                break;

                            case 2:
                                strDamageType = "blunt";
                                break;
                            }
                            if (bType == HORSE_TYPE && strState == "thrust_damage" && iDamageType == 0)
                            {
                                strItemStats = strItemStats + $"|horse_charge({iDamage})";
                            }
                            else
                            {
                                strItemStats = strItemStats + $"|{strState}({iDamage}, {strDamageType})";
                            }
                        }
                        else
                        {
                            strItemStats = strItemStats + $"|{strState}({iValue})";
                        }
                    }
                }
                fSource.Write("{0}, {1}, {2}", iCost, strItemStats, Core.Items.DecompileImodBits(dwImodBits));

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

                        int iRecords = fItems.GetInt();
                        //memcpy(indention, "      ", 7);
                        Common.PrintStatement(ref fItems, ref fSource, iRecords, "      ");

                        fSource.Write("    ]),\r\n   ");
                    }
                    fSource.Write("]");
                }
                else
                {
                    fSource.Write(", []");
                }

                fSource.WriteLine("],");
            }

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

            Common.GenerateId("ID_items.py", Common.Items, "itm");
        }
Пример #11
0
        public static void Decompile()
        {
            var fTroops = new Text(Common.InputPath + "/troops.txt");
            var fSource = new Win32FileWriter(Common.OutputPath + "/module_troops.py");

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

            for (int s = 0; s < Common.Skins.Length; s++)
            {
                fSource.WriteLine("tf_" + Common.Skins[s] + " = " + s);
            }
            fSource.WriteLine("\r\ntroops = [");

            fTroops.GetString();
            int iTroops = fTroops.GetInt();

            var strUpList = new List <string>();

            for (int t = 0; t < iTroops; t++)
            {
                fSource.Write("  [\"{0}\", \"{1}\", \"{2}\",", fTroops.GetWord().Remove(0, 4), fTroops.GetWord().Replace('_', ' '), fTroops.GetWord().Replace('_', ' '));

                DWORD dwFlag = fTroops.GetDWord();
                fSource.Write(" {0},", Core.Troops.DecompileFlags(dwFlag));

                DWORD dwScene = fTroops.GetDWord();
                fSource.Write(" {0},", dwScene == 0 ? "0" : Core.Troops.GetScene(dwScene));

                fSource.Write(" {0},", fTroops.GetWord()); // reserved "0"

                int iFaction = fTroops.GetInt();
                if (iFaction > 0 && iFaction < Common.Factions.Length)
                {
                    fSource.WriteLine(" fac_{0},", Common.Factions[iFaction]);
                }
                else
                {
                    fSource.WriteLine(" {0},", iFaction);
                }

                int iUp1 = fTroops.GetInt();
                int iUp2 = fTroops.GetInt();

                if (iUp1 != 0 && iUp2 != 0)
                {
                    strUpList.Add(
                        $"upgrade2(troops,\"{Common.Troops[t]}\",\"{Common.Troops[iUp1]}\",\"{Common.Troops[iUp2]}\")");
                }
                else if (iUp1 != 0 && iUp2 == 0)
                {
                    strUpList.Add($"upgrade(troops,\"{Common.Troops[t]}\",\"{Common.Troops[iUp1]}\")");
                }

                string strItemList = "";
                for (int i = 0; i < 64; i++)
                {
                    int iItem = fTroops.GetInt();
                    fTroops.GetInt(); //skip 0
                    if (-1 == iItem)
                    {
                        continue;
                    }
                    strItemList += $"itm_{Common.Items[iItem]},";
                }
                if (strItemList.Length > 0)
                {
                    strItemList = strItemList.Remove(strItemList.Length - 1, 1);
                }
                fSource.WriteLine("  [{0}],", strItemList);

                int iStregth      = fTroops.GetInt(),
                    iAgility      = fTroops.GetInt(),
                    iIntelligence = fTroops.GetInt(),
                    iCharisma     = fTroops.GetInt(),
                    iLevel        = fTroops.GetInt();

                fSource.Write("  strength({0})|agility({1})|intellect({2})|charisma({3})|level({4}), ", iStregth, iAgility, iIntelligence, iCharisma, iLevel);

                var iWP = new int[7];
                for (int i = 0; i < 7; i++)
                {
                    iWP[i] = fTroops.GetInt();
                }

                if (iWP[0] == iWP[1] && iWP[1] == iWP[2] && iWP[2] == iWP[3] && iWP[3] == iWP[4] && iWP[4] == iWP[5])
                {
                    fSource.Write("wp({0}){1},", iWP[0], iWP[6] == 0 ? "" : "|wp_firearm(" + iWP[6] + ")");
                }
                else if (iWP[0] == iWP[1] && iWP[1] == iWP[2])
                {
                    fSource.Write("wpe({0},{1},{2},{3}){4},", iWP[0], iWP[3], iWP[4], iWP[5], iWP[6] == 0 ? "" : "|wp_firearm(" + iWP[6] + ")");
                }
                else
                {
                    fSource.Write("wpex({0},{1},{2},{3},{4},{5}){6},", iWP[0], iWP[1], iWP[2], iWP[3], iWP[4], iWP[5], iWP[6] == 0 ? "" : "|wp_firearm(" + iWP[6] + ")");
                }

                string strKnow = "";
                for (int x = 0; x < 6; x++)
                {
                    DWORD dword = fTroops.GetDWord();
                    if (dword == 0)
                    {
                        continue;
                    }
                    for (int q = 0; q < 8; q++)
                    {
                        DWORD dwKnow = (0xF & (dword >> (q * 4)));

                        /*if (dwKnow != 0 && dwKnow <= 8)
                         *  strKnow = strKnow + String.Format("knows_{0}_{1}|", Common.Skills[x * 8 + q], dwKnow);
                         * else*/
                        if (dwKnow != 0)
                        {
                            strKnow += $"knows_{Common.Skills[x*8 + q]}_{dwKnow}|";
                        }
                    }
                }
                strKnow = strKnow == "" ? "0" : strKnow.Remove(strKnow.Length - 1, 1);
                fSource.Write(" {0},", strKnow);

                string strFase =
                    $"0x{fTroops.GetUInt64():x16}{fTroops.GetUInt64():x16}{fTroops.GetUInt64():x16}{fTroops.GetUInt64():x16}, 0x{fTroops.GetUInt64():x16}{fTroops.GetUInt64():x16}{fTroops.GetUInt64():x16}{fTroops.GetUInt64():x16}";
                fSource.WriteLine("{0}],", strFase);
            }

            fSource.WriteLine("]");
            foreach (var strUp in strUpList)
            {
                fSource.WriteLine(strUp);
            }
            fSource.Close();
            fTroops.Close();

            Common.GenerateId("ID_troops.py", Common.Troops, "trp");
        }
Пример #12
0
        public static void Decompile()
        {
            var fSkins  = new Text(Path.Combine(Common.InputPath, "skins.txt"));
            var fSource = new Win32FileWriter(Path.Combine(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();
                    var    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("],");
                }

                var iTexturesFace = fSkins.GetInt();
                fSource.WriteLine("    [");
                for (int i = 0; i < iTexturesFace; i++)
                {
                    fSource.Write("      (\"{0}\", ", fSkins.GetWord()); //0

                    var iColors     = fSkins.GetInt();                   //1
                    var iHairMats   = fSkins.GetInt();                   //2
                    var iHairColors = fSkins.GetInt();                   //4
                    var dwColor     = fSkins.GetDWord();                 //3

                    fSource.Write("[");
                    for (int c = 0; c < iColors; c++)
                    {
                        fSource.Write("0x{0:x}{1}", fSkins.GetUInt64(), c != iColors - 1 ? ", " : "");
                    }
                    fSource.Write("], ");
                    for (int m = 0; m < iHairMats; m++)
                    {
                        fSource.Write("[\"{0}\"], ", fSkins.GetWord());
                    }
                    fSource.Write("0x{0:x}, [", dwColor);
                    for (int c = 0; c < iHairColors; c++)
                    {
                        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++)
                {
                    var      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);
                    }

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

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

                int ixParticleSystem1 = fSkins.GetInt(),
                    ixParticleSystem2 = fSkins.GetInt();
                fSource.WriteLine("    {0}, {1},",
                                  ixParticleSystem1 < Common.ParticleSystems.Count ? "psys_" + Common.ParticleSystems[ixParticleSystem1] : ixParticleSystem1.ToString(CultureInfo.GetCultureInfo("en-US")),
                                  ixParticleSystem2 < Common.ParticleSystems.Count ? "psys_" + Common.ParticleSystems[ixParticleSystem2] : ixParticleSystem2.ToString(CultureInfo.GetCultureInfo("en-US")));

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

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

                    var count = fSkins.GetInt();
                    for (int c = 0; c < count; c++)
                    {
                        var dc1 = fSkins.GetDouble();
                        var 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();
        }
Пример #13
0
        public static void Decompile()
        {
            var fTroops = new Text(Path.Combine(Common.InputPath, "troops.txt"));
            var fSource = new Win32FileWriter(Path.Combine(Common.OutputPath, "module_troops.py"));

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

            for (int s = 0; s < Common.Skins.Count; s++)
            {
                fSource.WriteLine("tf_" + Common.Skins[s] + " = " + s);
            }
            fSource.WriteLine("\r\ntroops = [");

            fTroops.GetString();
            var iTroops = fTroops.GetInt();

            var strUpList = new List <string>();

            for (int t = 0; t < iTroops; t++)
            {
                fSource.Write("  [\"{0}\", \"{1}\", \"{2}\",", fTroops.GetWord().Remove(0, 4), fTroops.GetWord().Replace('_', ' '), fTroops.GetWord().Replace('_', ' '));

                var dwFlag = fTroops.GetDWord();
                fSource.Write(" {0},", Core.Troops.DecompileFlags(dwFlag));

                var dwScene = fTroops.GetDWord();
                fSource.Write(" {0},", dwScene == 0 ? "0" : Core.Troops.GetScene(dwScene));

                fSource.Write(" {0},", fTroops.GetWord()); // reserved "0"

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

                var iUp1 = fTroops.GetInt();
                var iUp2 = fTroops.GetInt();

                // ReSharper disable once InconsistentNaming
                string fnGetTroopForUpgrade(int id) => id >= 0 && id < Common.Troops.Count ? '"' + Common.Troops[id] + '"' : id.ToString(CultureInfo.GetCultureInfo("en-US"));

                if (iUp1 != 0 && iUp2 != 0)
                {
                    strUpList.Add(
                        $"upgrade2(troops,{fnGetTroopForUpgrade(t)},{fnGetTroopForUpgrade(iUp1)},{fnGetTroopForUpgrade(iUp2)})");
                }
                else if (iUp1 != 0 && iUp2 == 0)
                {
                    strUpList.Add($"upgrade(troops,{fnGetTroopForUpgrade(t)},{fnGetTroopForUpgrade(iUp1)})");
                }

                var itemList = new List <int>(64);
                for (int i = 0; i < 64; i++)
                {
                    var iItem = fTroops.GetInt();
                    fTroops.GetInt(); //skip 0
                    if (-1 == iItem)
                    {
                        continue;
                    }
                    itemList.Add(iItem);
                }
                fSource.WriteLine("  [{0}],", String.Join(",", itemList.Select(item => item < Common.Items.Count ? $"itm_{Common.Items[item]}" : $"{item}")));

                int iStregth      = fTroops.GetInt(),
                    iAgility      = fTroops.GetInt(),
                    iIntelligence = fTroops.GetInt(),
                    iCharisma     = fTroops.GetInt(),
                    iLevel        = fTroops.GetInt();

                fSource.Write("  strength({0})|agility({1})|intellect({2})|charisma({3})|level({4}), ", iStregth, iAgility, iIntelligence, iCharisma, iLevel);

                var iWP = new int[7];
                for (int i = 0; i < 7; i++)
                {
                    iWP[i] = fTroops.GetInt();
                }

                if (iWP[0] == iWP[1] && iWP[1] == iWP[2] && iWP[2] == iWP[3] && iWP[3] == iWP[4] && iWP[4] == iWP[5])
                {
                    fSource.Write("wp({0}){1},", iWP[0], iWP[6] == 0 ? "" : "|wp_firearm(" + iWP[6] + ")");
                }
                else if (iWP[0] == iWP[1] && iWP[1] == iWP[2])
                {
                    fSource.Write("wpe({0},{1},{2},{3}){4},", iWP[0], iWP[3], iWP[4], iWP[5], iWP[6] == 0 ? "" : "|wp_firearm(" + iWP[6] + ")");
                }
                else
                {
                    fSource.Write("wpex({0},{1},{2},{3},{4},{5}){6},", iWP[0], iWP[1], iWP[2], iWP[3], iWP[4], iWP[5], iWP[6] == 0 ? "" : "|wp_firearm(" + iWP[6] + ")");
                }

                var sbKnow = new StringBuilder(512);
                for (int x = 0; x < 6; x++)
                {
                    var dword = fTroops.GetDWord();
                    if (dword == 0)
                    {
                        continue;
                    }
                    for (int q = 0; q < 8; q++)
                    {
                        var dwKnow = 0xF & (dword >> (q << 2));
                        if (dwKnow != 0 && (x << 3) + q < Common.Skills.Count)
                        {
                            sbKnow.Append($"knows_{Common.Skills[(x << 3) + q]}_{dwKnow}|");
                        }
                    }
                }

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

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

                var strFace =
                    $"0x{fTroops.GetUInt64():x16}{fTroops.GetUInt64():x16}{fTroops.GetUInt64():x16}{fTroops.GetUInt64():x16}, 0x{fTroops.GetUInt64():x16}{fTroops.GetUInt64():x16}{fTroops.GetUInt64():x16}{fTroops.GetUInt64():x16}";
                fSource.WriteLine("{0}],", strFace);
            }

            fSource.WriteLine("]");
            foreach (var strUp in strUpList)
            {
                fSource.WriteLine(strUp);
            }
            fSource.Close();
            fTroops.Close();

            Common.GenerateId("ID_troops.py", Common.Troops, "trp");
        }
Пример #14
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();
                string strDialogPartner     = "";

                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)
                {
                    strDialogPartner = strRepeatsPrefix[iRepeat - 1] + "|";
                }

                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)
                    {
                        strDialogPartner += strPartnerPrefix[i] + "|";
                    }
                }

                DWORD dwPartner = (dwDialogPartner & 0x00000FFF);
                if (dwPartner == 0x00000FFF)
                {
                    strDialogPartner += "anyone" + "|";
                }
                else if (dwPartner != 0)
                {
                    strDialogPartner += "trp_" + Common.Troops[dwPartner] + "|";
                }

                DWORD dwOther = (dwDialogPartner & 0xFFF00000) >> 20;
                if (dwOther != 0)
                {
                    strDialogPartner += "other(trp_" + Common.Troops[dwOther] + ")|";
                }

                strDialogPartner = strDialogPartner == "" ? "0" : strDialogPartner.Remove(strDialogPartner.Length - 1, 1);
                fSource.Write("  [{0}, \"{1}\",\r\n    [", strDialogPartner, 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("]");
                }

                fSource.WriteLine("],\r\n");
            }
            fSource.Write("]");
            fSource.Close();
            fDialogs.Close();
        }
Пример #15
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++)
                {
                    //("manface_young_2", 0xFFCBE0E0, ["hair_blonde"], [0xffffffff, 0xffb04717, 0xff502a19]),

                    fSource.Write("      (\"{0}\", 0x{1:X}, ", fSkins.GetWord(), fSkins.GetDWord());
                    fSkins.GetWord();
                    int iHairColors = fSkins.GetInt();
                    fSource.Write("{0:x8}, {1:x8}, {2:x8}, {3:x8}, ", fSkins.GetInt64(), fSkins.GetInt64(), fSkins.GetInt64(), fSkins.GetInt64());
                    fSource.Write("[\"{0}\"], ", fSkins.GetWord());
                    for (int m = 0; m < iHairColors; m++)
                    {
                        fSource.Write("{0:x8}", fSkins.GetInt64());
                        if (m != iHairColors - 1)
                        {
                            fSource.Write(", ");
                        }
                    }
                    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();
        }
Пример #16
0
        public static void Decompile()
        {
            var fDialogs = new Text(Path.Combine(Common.InputPath, "conversation.txt"));
            var fSource  = new Win32FileWriter(Path.Combine(Common.OutputPath, "module_dialogs.py"));

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

            for (int t = 0; t < iDialogs; t++)
            {
                fDialogs.GetWord();
                var dwDialogPartner      = fDialogs.GetUInt();
                var 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)
                    {
                        continue;
                    }
                    sbDialogPartner.Append(strPartnerPrefix[i]);
                    sbDialogPartner.Append('|');
                }

                // ReSharper disable once InconsistentNaming
                const DWORD PARTY_TPL = 0x00020000;
                DWORD       dwPartner = dwDialogPartner & 0x00000FFF;
                if (dwPartner == 0x00000FFF)
                {
                    sbDialogPartner.Append("anyone|");
                }
                else if (dwPartner != 0)
                {
                    if ((dwDialogPartner & PARTY_TPL) != 0)
                    {
                        sbDialogPartner.Append(dwPartner < Common.PTemps.Count ? "pt_" + Common.PTemps[(int)dwPartner] + "|" : $"{dwPartner}|");
                    }
                    else
                    {
                        sbDialogPartner.Append(dwPartner < Common.Troops.Count ? "trp_" + Common.Troops[(int)dwPartner] + "|" : $"{dwPartner}|");
                    }
                }

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

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

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

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

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

                int iEndingDialogState = fDialogs.GetInt();

                if (iEndingDialogState < Common.DialogStates.Count)
                {
                    fSource.Write("    \"{0}\",\r\n    [", Common.DialogStates[iEndingDialogState]);
                }
                else
                {
                    fSource.Write("    {0},\r\n    [", iEndingDialogState);
                }

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

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