-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
138 lines (120 loc) · 5.95 KB
/
Program.cs
File metadata and controls
138 lines (120 loc) · 5.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Xml;
using GTA5_RealHandlingNames.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Formatting = Newtonsoft.Json.Formatting;
namespace GTA5_RealHandlingNames
{
class Program
{
private static Dictionary<uint, uint> _realHandlingNames;
private static void Main(string[] args)
{
_realHandlingNames = new Dictionary<uint, uint>();
HandlingNames();
HandlingValues();
Console.ReadKey();
}
private static void HandlingValues()
{
if(_realHandlingNames == null || _realHandlingNames.Count <= 0) throw new Exception("Real handling names are null");
var result = new Dictionary<uint, HandlingResult>();
var sw = new Stopwatch();
sw.Start();
var directory = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "vehicle-handlings"));
if (!directory.Exists)
{
Console.WriteLine($"Path {Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "vehicle-handlings")} is invalid");
return;
}
var files = directory.GetFiles();
foreach (var fileInfo in files)
{
var fileContent = File.ReadAllText(fileInfo.FullName);
var doc = new XmlDocument();
doc.LoadXml(fileContent);
AddJsonNetRootAttribute(doc);
var json = JsonConvert.SerializeXmlNode(doc, Formatting.Indented);
var vehicleHandling = VehicleHandling.FromJson(json);
if (vehicleHandling == null) throw new Exception($"Couldn't convert meta file in file {fileInfo.FullName}.");
var handlingHash = GTA5Hasher.GetHashKey(vehicleHandling.CHandlingDataMgr.HandlingData.Item.HandlingName);
var vehicleModelsWithHandling = _realHandlingNames.Where(d => d.Value == handlingHash).Select(v => v.Key).ToList();
if (vehicleModelsWithHandling.Count <= 0) continue;
var handling = vehicleHandling.CHandlingDataMgr.HandlingData.Item;
var handlingResult = new HandlingResult
{
MonetaryValue = int.Parse(handling.NMonetaryValue.Value),
InitialDriveGears = int.Parse(handling.NInitialDriveGears.Value),
CollisionDamageMult = float.Parse(handling.FCollisionDamageMult.Value, CultureInfo.InvariantCulture.NumberFormat),
EngineDamageMult = float.Parse(handling.FEngineDamageMult.Value, CultureInfo.InvariantCulture.NumberFormat),
};
foreach (var vehicleModel in vehicleModelsWithHandling)
{
result.Add(vehicleModel, handlingResult);
}
}
File.WriteAllText("addonVehiclesHandling.json", JsonConvert.SerializeObject(result, Formatting.Indented, new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
}));
sw.Stop();
Console.WriteLine($"Converted handling values in {sw.ElapsedMilliseconds} ms.");
}
private static void HandlingNames()
{
var realHandlingNamesCount = 0;
var sw = new Stopwatch();
sw.Start();
var directory = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "vehicle-metas"));
if (!directory.Exists)
{
Console.WriteLine($"Path {Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "vehicle-metas")} is invalid");
return;
}
var files = directory.GetFiles();
foreach (var fileInfo in files)
{
var fileContent = File.ReadAllText(fileInfo.FullName);
var doc = new XmlDocument();
doc.LoadXml(fileContent);
AddJsonNetRootAttribute(doc);
var elements = doc.DocumentElement.SelectNodes("InitDatas/Item");
foreach (var element in elements)
{
if (element is XmlElement el)
{
var jsonArray = doc.CreateAttribute("json", "Array", "http://james.newtonking.com/projects/json");
jsonArray.Value = "true";
el.SetAttributeNode(jsonArray);
}
}
var json = JsonConvert.SerializeXmlNode(doc, Formatting.Indented);
var vehicleMeta = JsonConvert.DeserializeObject<VehiclesMeta>(json, Converter.Settings);
if (vehicleMeta == null) throw new Exception($"Couldn't convert meta file in file {fileInfo.FullName}.");
foreach (var vehicleInfo in vehicleMeta.CVehicleModelInfoInitDataList.InitDatas.Item)
{
if (!_realHandlingNames.ContainsKey(GTA5Hasher.GetHashKey(vehicleInfo.ModelName)))
{
realHandlingNamesCount++;
_realHandlingNames.Add(GTA5Hasher.GetHashKey(vehicleInfo.ModelName), GTA5Hasher.GetHashKey(vehicleInfo.HandlingId));
}
}
}
File.WriteAllText("realHandlingNames.json", JsonConvert.SerializeObject(_realHandlingNames, Formatting.Indented));
sw.Stop();
Console.WriteLine($"Converted {realHandlingNamesCount} handling names in {sw.ElapsedMilliseconds} ms.");
}
private static void AddJsonNetRootAttribute(XmlDocument xmlD)
{
var jsonNs = xmlD.CreateAttribute("xmlns", "json", "http://www.w3.org/2000/xmlns/");
jsonNs.Value = "http://james.newtonking.com/projects/json";
xmlD.DocumentElement.SetAttributeNode(jsonNs);
}
}
}