public static IFileSystem CreateFileSystem(string installationFolder, string dataDirectory) { Logger.Info("Using ToEE installation from '{0}'", installationFolder); var vfs = TroikaVfs.CreateFromInstallationDir(installationFolder); if (dataDirectory == null) { // We usually assume that the Data directory is right below our executable location var entryAssembly = Assembly.GetEntryAssembly(); if (entryAssembly == null) { Logger.Error("Failed to determine entry point assembly."); return(vfs); } var location = Path.GetDirectoryName(entryAssembly.Location); dataDirectory = Path.Join(location, "Data"); #if DEBUG if (!Directory.Exists(dataDirectory)) { dataDirectory = Path.GetFullPath("../Data"); } #endif } if (!Directory.Exists(dataDirectory)) { throw new FileNotFoundException("Failed to find data folder. Tried: " + dataDirectory); } Logger.Info("Using additional data from: {0}", dataDirectory); vfs.AddDataDir(dataDirectory, true); return(vfs); }
private static void DumpObjectTable(string toeePath, string gsiPath) { using var vfs = TroikaVfs.CreateFromInstallationDir(toeePath); Tig.FS = vfs; var sgi = SaveGameInfoReader.Read(gsiPath); Console.WriteLine($"Loading {sgi.Name}"); var tempDir = Path.GetTempFileName(); File.Delete(tempDir); Directory.CreateDirectory(tempDir); try { var tfaiFile = sgi.BasePath + ".tfai"; var tfafFile = sgi.BasePath + ".tfaf"; ExtractSaveArchive.Extract(tfaiFile, tfafFile, tempDir); DumpObjectTableForSaveDir(tempDir); } finally { Directory.Delete(tempDir, true); } }
public static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("Usage: scriptconversion <scripts|file> ..."); return; } string mode = args[0]; if (mode == "scripts") { ConvertScripts(args.Skip(1).ToArray()); return; } else if (mode == "folder") { Tig.FS = TroikaVfs.CreateFromInstallationDir(args[1]); Directory.CreateDirectory("temp"); var conversion = new ScriptConversion("temp"); foreach (var pythonFile in Directory.EnumerateFiles(args[2], "*.py")) { conversion.ConvertSingleFile(pythonFile, ScriptType.TemplePlusCondition); } } else { Console.WriteLine("Unknown mode: " + mode); } }
private static void ConvertScripts(string[] args) { var outputDir = "scripts"; if (args.Length != 1 && args.Length != 2) { Console.WriteLine("Usage: scriptconversion <toee-dir> [<script-out-dir>]"); return; } var installationDir = args[0]; if (args.Length > 1) { outputDir = args[1]; } Directory.CreateDirectory(outputDir); Tig.FS = TroikaVfs.CreateFromInstallationDir(installationDir); var conversion = new ScriptConversion(outputDir); conversion.LoadTyping(outputDir); conversion.ConvertScripts(); conversion.ConvertDialog(); }
private static void Convert(string toeeDir, string outputDir) { Directory.CreateDirectory(outputDir); using var fs = TroikaVfs.CreateFromInstallationDir(toeeDir); // Loads the map list var maps = MapListParser.Parse(fs); var entries = fs.ReadMesFile("rules/townmap_ui_placed_flag_locations.mes"); var mapCount = int.Parse(entries[1]); for (var mapIndex = 0; mapIndex < mapCount; mapIndex++) { var mapKey = 100 * (mapIndex + 1); var mapId = int.Parse(entries[mapKey]); // See MapSystem.GetDataDir var mapDataDir = Path.Join(outputDir, $"maps/{maps[mapId].name}"); Directory.CreateDirectory(mapDataDir); using var stream = new FileStream($"{mapDataDir}/map_markers.json", FileMode.Create); var options = new JsonWriterOptions { Indented = true }; using var writer = new Utf8JsonWriter(stream, options); writer.WriteStartObject(); writer.WriteString("$schema", "https://schemas.opentemple.de/townMapMarkers.json"); writer.WritePropertyName("markers"); writer.WriteStartArray(); var markerCount = int.Parse(entries[mapKey + 1]); for (var markerIndex = 0; markerIndex < markerCount; markerIndex++) { var markerKey = mapKey + 20 + markerIndex; var locationParts = entries[markerKey].Split(","); var x = int.Parse(locationParts[0].Trim()); var y = int.Parse(locationParts[1].Trim()); // Interestingly, ToEE applied a hard coded offset x -= 4; y -= 8; writer.WriteStartObject(); writer.WriteNumber("id", markerIndex); writer.WriteBoolean("initiallyVisible", false); // For the text, we reference the translation file // It however uses a different numbering scheme since ToEE itself will read it sequentially // rather than by key, but our translation system must reference it by key. var translationKey = markerKey - 110; writer.WriteString("text", $"#{{townmap_markers:{translationKey}}}"); writer.WriteNumber("x", x); writer.WriteNumber("y", y); writer.WriteEndObject(); } writer.WriteEndArray(); // markers writer.WriteEndObject(); } }
public virtual void Dispose() { if (FS != null) { FS.Dispose(); if (Tig.FS == FS) { Tig.FS = _oldVfs; } _oldVfs = null; FS = null; } }
public RealGameFiles() { _oldVfs = Tig.FS; var toeeDir = Environment.GetEnvironmentVariable("TOEE_DIR"); if (toeeDir == null) { throw new NotSupportedException( "Cannot run a test based on real data because TOEE_DIR environment variable is not set." ); } var dataFolder = Path.Join(TestData.SolutionDir, "Data"); FS = (TroikaVfs)Tig.CreateFileSystem(toeeDir, dataFolder); Tig.FS = FS; }