Skip to content

Instantly share code, notes, and snippets.

@PichotM
Created August 15, 2019 03:21
Show Gist options
  • Save PichotM/3b0a28fbb6e463744578b036af68479f to your computer and use it in GitHub Desktop.
Save PichotM/3b0a28fbb6e463744578b036af68479f to your computer and use it in GitHub Desktop.
using CodeWalker.GameFiles;
using CodeWalker.World;
using SharpDX;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConvertIVTrain
{
class Program
{
private static int trainIndex = 13;
static void Main(string[] args)
{
string nodePath = "path/to/iv_nodes";
foreach (string filePath in Directory.GetFiles(nodePath))
{
string fileName = Path.GetFileName(filePath);
if (fileName.EndsWith(".dat") && !fileName.Contains("trains"))
{
Console.WriteLine("Converting " + fileName);
ConvertPath(filePath);
trainIndex++;
}
}
Console.ReadKey();
}
private static void ConvertPath(string path)
{
string trainName = "trains" + trainIndex.ToString() + ".dat";
TrainTrack track = new TrainTrack();
track.RpfFileEntry = new RpfResourceFileEntry();
track.RpfFileEntry.Name = Path.GetFileName(trainName);
track.FilePath = path;
track.Name = track.RpfFileEntry.Name;
string[] lines = File.ReadAllLines(path);
for (int i = 1; i < lines.Length - 1; i++)
{
string[] lineData = lines[i].Split(' ');
Vector3 position = new Vector3(float.Parse(lineData[0], CultureInfo.InvariantCulture.NumberFormat), float.Parse(lineData[1], CultureInfo.InvariantCulture.NumberFormat), float.Parse(lineData[2], CultureInfo.InvariantCulture.NumberFormat));
// my offsets
position.X += 68.1858f;
position.Y += 839.7f;
int unkType = Convert.ToInt32(lineData[3]);
if (!String.IsNullOrEmpty(lineData[4]))
{
string stationName = lineData[4];
}
TrainTrackNode node = track.AddNode();
node.Position = position;
node.NodeType = unkType == 0 ? 4 : 5;
}
track.BuildBVH();
track.BuildVertices();
byte[] newData = track.Save();
File.WriteAllBytes(Path.GetDirectoryName(path) + "//" + trainName, newData);
Console.WriteLine("Done for " + trainName);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment