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"); }
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"); }
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"); }
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(); }
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(); }
public static void Decompile() { var fFactions = new Text(Common.InputPath + "/factions.txt"); var fSource = new Win32FileWriter(Common.OutputPath + "/module_factions.py"); fSource.WriteLine(Header.Standard); fSource.WriteLine(Header.Factions); fFactions.GetString(); int iFactions = fFactions.GetInt(); for (int f = 0; f < iFactions; f++) { string strFacID = fFactions.GetWord(); if (strFacID == "0") { strFacID = fFactions.GetWord(); } string strFacName = fFactions.GetWord(); fSource.Write(" (\"{0}\", \"{1}\",", strFacID.Remove(0, 4), strFacName); string strFlags = ""; DWORD dwFlags = fFactions.GetUInt(); int iRating = ((int)(dwFlags & 0xFF00)) >> 8; if (iRating != 0) { strFlags = $"max_player_rating({100 - iRating})"; } if ((dwFlags & 1) != 0) { if (strFlags != "") { strFlags = strFlags + "|"; } strFlags += "ff_always_hide_label"; } if (strFlags == "") { strFlags = "0"; } fSource.Write(" {0}, 0.0, [", strFlags); DWORD dwColor = fFactions.GetUInt(); string strRelations = ""; for (int r = 0; r < iFactions; r++) { double rRelation = fFactions.GetDouble(); if (Math.Abs(rRelation) > 0.000001) { strRelations += $"(\"{Common.Factions[r]}\", {rRelation.ToString(CultureInfo.GetCultureInfo("en-US"))}),"; } } if (strRelations != "") { strRelations = strRelations.Remove(strRelations.Length - 1, 1); } fSource.Write("{0}], []", strRelations); if (dwColor != 0xAAAAAA) { fSource.Write(", 0x{0:X}", dwColor); } fSource.WriteLine("),"); } fSource.Write("]"); fSource.Close(); fFactions.Close(); Common.GenerateId("ID_factions.py", Common.Factions, "fac"); }
public static void Decompile() { var fFactions = new Text(Path.Combine(Common.InputPath, "factions.txt")); var fSource = new Win32FileWriter(Path.Combine(Common.OutputPath, "module_factions.py")); fSource.WriteLine(Header.Standard); fSource.WriteLine(Header.Factions); fFactions.GetString(); var iFactions = fFactions.GetInt(); for (int f = 0; f < iFactions; f++) { var strFacId = fFactions.GetWord(); if (strFacId == "0") { strFacId = fFactions.GetWord(); } var strFacName = fFactions.GetWord(); fSource.Write(" (\"{0}\", \"{1}\",", strFacId.Remove(0, 4), strFacName); var sbFlags = new StringBuilder(64); var dwFlags = fFactions.GetUInt(); var iRating = (int)(dwFlags & 0xFF00) >> 8; if (iRating != 0) { sbFlags.Append($"max_player_rating({100 - iRating})"); } if ((dwFlags & 1) != 0) { if (sbFlags.Length > 0) { sbFlags.Append('|'); } sbFlags.Append("ff_always_hide_label"); } if (sbFlags.Length == 0) { sbFlags.Append('0'); } fSource.Write(" {0}, 0.0, [", sbFlags); var dwColor = fFactions.GetUInt(); var sbRelations = new StringBuilder(1024); for (int r = 0; r < iFactions; r++) { var rRelation = fFactions.GetDouble(); if (Math.Abs(rRelation) > 0.000001) { sbRelations.Append($"(\"{Common.Factions[r]}\", {rRelation.ToString(CultureInfo.GetCultureInfo("en-US"))}),"); } } if (sbRelations.Length != 0) { sbRelations.Length--; } fSource.Write("{0}], []", sbRelations); if (dwColor != 0xAAAAAA) { fSource.Write(", 0x{0:X}", dwColor); } fSource.WriteLine("),"); } fSource.Write("]"); fSource.Close(); fFactions.Close(); Common.GenerateId("ID_factions.py", Common.Factions, "fac"); }