public void ExportShapePathTests(FarmSimulatorVersion version, string shapeFileName) { var gameMapPath = GamePaths.GetGameMapsPath(version); if (!Directory.Exists(gameMapPath)) { var message = $"Game map path not found: \"{version}\"."; Trace.WriteLine(message); Assert.Inconclusive(message); } var mapPath = Path.Combine(gameMapPath, shapeFileName); if (!File.Exists(mapPath)) { var message = $"Map not found \"{version}\": \"{mapPath}\"."; Trace.WriteLine(message); Assert.Inconclusive(message); } var xmlMapFilePath = mapPath.Replace(GameConstants.SchapesFileExtension, GameConstants.XmlMapFileExtension); var mapFile = MapFile.Load(xmlMapFilePath); var shapePaths = FindShapePath(mapFile) .OrderBy(v => v.Id) .ToArray(); File.WriteAllLines(Path.Combine(Output, version.ToString(), "shapes.path"), shapePaths.Select(v => v.ToString())); }
public void GenerateCsCode() { var mapsPath = GamePaths.GetGameMapsPath(FarmSimulatorVersion.FarmingSimulator2019); var mapFilePath = Path.Combine(mapsPath, "mapUS.i3d"); var xml = new XmlDocument(); using var stream = File.OpenRead(mapFilePath); xml.Load(stream); var codeClases = ExportCodeClasses(xml.DocumentElement); var code = string.Join("\n", codeClases.Select(v => GenerateCsCode(v.Value))); var names = string.Join("\n", codeClases.Select(v => $"typeof({UpFirstChar(v.Value.Name)}),")); }
public void OpenXmlFileMapTest(FarmSimulatorVersion version, string fileName) { var mapsPath = GamePaths.GetGameMapsPath(version); if (mapsPath == null) { Assert.Inconclusive("Maps path by \"{0}\" not found.", version); } var mapFilePath = Path.Combine(mapsPath, fileName); if (!File.Exists(mapFilePath)) { Assert.Inconclusive("Map file \"{0}\" by \"{1}\" not found.", fileName, version); } using (var stream = File.OpenRead(mapFilePath)) { var mapFile = MapFile.Serializer.Deserialize(stream) as MapFile; Assert.IsNotNull(mapFile); } }
public void LoadTypedShape <T>(FarmSimulatorVersion version, string shapeFileName, int rawType, Func <BinaryReader, int, T> loadShape) { var gameMapPath = GamePaths.GetGameMapsPath(version); if (!Directory.Exists(gameMapPath)) { var message = $"Game map path not found: \"{version}\"."; Trace.WriteLine(message); Assert.Inconclusive(message); } var mapPath = Path.Combine(gameMapPath, shapeFileName); if (!File.Exists(mapPath)) { var message = $"Map not found \"{version}\": \"{mapPath}\"."; Trace.WriteLine(message); Assert.Inconclusive(message); } // Clear directory by error shapes var errorOutputPath = Path.Combine(OutputErrorShapes, version.ToString(), shapeFileName); if (Directory.Exists(errorOutputPath)) { Directory.Delete(errorOutputPath, true); } var fileContainer = new FileContainer(mapPath); var entities = fileContainer.GetEntities(); var error = false; fileContainer.ReadRawData(entities) .Where(v => v.Entity.Type == rawType) .ForEach( v => { try { using var stream = new MemoryStream(v.RawData); using var reader = new EndianBinaryReader(stream, fileContainer.Endian); var shape = loadShape(reader, fileContainer.Header.Version); } catch (Exception ex) { error = true; using var stream = new MemoryStream(v.RawData); using var reader = new EndianBinaryReader(stream, fileContainer.Endian); Trace.WriteLine($"Error load shape."); var errorShape2 = new ReverseEngineeringNamedShape1Object( v.Entity.Type, reader, fileContainer.Endian ); Save(errorOutputPath, version, errorShape2, v.RawData); } } ); if (error) { Assert.Fail(); } }