From 6b34ab6e361d3f7023e7de838b3d8d78fa2603df Mon Sep 17 00:00:00 2001 From: sardelka9515 Date: Fri, 21 Oct 2022 19:41:38 +0800 Subject: [PATCH] DataDumper --- Client/DataDumper/Program.cs | 143 +++++++++++++++++++++- Client/Scripts/DevTools/DevTool.cs | 10 +- Client/Scripts/Properties/AssemblyInfo.cs | 4 +- Client/Scripts/Util/PedExtensions.cs | 18 ++- Client/Scripts/Util/WeaponUtil.cs | 1 + RageCoop-V.sln | 10 ++ 6 files changed, 171 insertions(+), 15 deletions(-) diff --git a/Client/DataDumper/Program.cs b/Client/DataDumper/Program.cs index 2594c3d..d0e286e 100644 --- a/Client/DataDumper/Program.cs +++ b/Client/DataDumper/Program.cs @@ -1,15 +1,154 @@ using RageCoop.Core; using Newtonsoft.Json; -using System.Data.HashFunction.Jenkins; +using Formatting = Newtonsoft.Json.Formatting; using System; +using System.Xml; +using System.Linq; +using System.Text; namespace RageCoop.Client.DataDumper { + class WeaponInfo + { + public WeaponInfo(XmlNode node) + { + if (node.Attributes["type"].Value != "CWeaponInfo") + { + throw new Exception("Not a CWeaponInfo node"); + + } + foreach (XmlNode info in node.ChildNodes) + { + switch (info.Name) + { + case "Name": + Name = info.InnerText; break; + case "Audio": + Audio = info.InnerText; break; + case "FireType": + FireType = info.InnerText; break; + case "DamageType": + DamageType = info.InnerText; break; + case "Damage": + Damage = info.GetFloat(); break; + case "Speed": + Speed = info.GetFloat(); break; + } + } + IsVehicleWeapon = Name.StartsWith("VEHICLE_WEAPON"); + } + public string Name; + public string Audio; + public string FireType; + public string DamageType; + public float Damage; + public float Speed; + public bool IsVehicleWeapon; + } public static class Program { - + public static float GetFloat(this XmlNode n) + { + return float.Parse(n.Attributes["value"].Value); + } + public static void Main() + { + Dictionary weapons = new(); + foreach (var f in Directory.GetFiles("meta", "*.meta")) + { + Parse(f, weapons); + } + Directory.CreateDirectory("Weapons"); + File.WriteAllText("Weapons\\Weapons.json", JsonConvert.SerializeObject(weapons, Formatting.Indented)); + DumpWeaponHash(weapons, true); + } + static void Parse(string filename, Dictionary weap) + { + Console.WriteLine("Parsing " + filename); + var doc = new XmlDocument(); + try + { + doc.Load(filename); + } + catch (Exception ex) + { + Console.WriteLine(ex); return; + } + var nodes = doc.ChildNodes.ToList(); + if (nodes.Any(x => x.Name == "CWeaponInfoBlob")) + { + var infosNode = doc.GetElementsByTagName("Item"); + foreach (XmlNode n in infosNode) + { + if (n.Attributes["type"]?.Value == "CWeaponInfo") + { + var info = new WeaponInfo(n); + if (!info.Name.StartsWith("VEHICLE_WEAPON") && !info.Name.StartsWith("WEAPON")) + { continue; } + var hash = Hash(info.Name); + if (weap.ContainsKey(hash)) + { + weap[hash] = info; + } + else + { + weap.Add(hash, info); + } + } + } + } + } + static void DumpWeaponHash(Dictionary weapons, bool sort = false, string path = @"Weapons\WeaponHash.cs") + { + StringBuilder output = new(); + List lines = new(); + var weps = weapons.Where(x => x.Value.Name.StartsWith("WEAPON")); + var vehWeaps = weapons.Where(x => x.Value.Name.StartsWith("VEHICLE_WEAPON")); + output.Append("public enum WeaponHash : uint\r\n{"); + foreach (var info in weps) + { + lines.Add($"{CoreUtils.FormatToSharpStyle(info.Value.Name, 7)} = {info.Key.ToHex()}"); + } + if (sort) + { + lines.Sort(); + } + foreach (var l in lines) + { + output.Append($"\r\n\t{l},"); + } + output.AppendLine("\r\n}"); + output.AppendLine(); + output.Append("public enum VehicleWeaponHash : uint\r\n{\r\n\tInvalid = 0xFFFFFFFF,"); + lines = new(); + foreach (var info in vehWeaps) + { + lines.Add($"{CoreUtils.FormatToSharpStyle(info.Value.Name)} = {info.Key.ToHex()}"); + } + if (sort) + { + lines.Sort(); + } + foreach (var l in lines) + { + output.Append($"\r\n\t{l},"); + } + output.Append("\r\n}"); + File.WriteAllText(path, output.ToString()); + + } + static List ToList(this XmlNodeList l) + { + var nodes = new List(); + foreach(XmlNode n in l) + { + nodes.Add(n); + } + return nodes; + } static UInt32 Hash(string key) { + key = key.ToLower(); int i = 0; uint hash = 0; while (i != key.Length) diff --git a/Client/Scripts/DevTools/DevTool.cs b/Client/Scripts/DevTools/DevTool.cs index c8c59c9..244f87a 100644 --- a/Client/Scripts/DevTools/DevTool.cs +++ b/Client/Scripts/DevTools/DevTool.cs @@ -5,6 +5,7 @@ using System; using System.Drawing; using System.Threading; using System.Windows.Forms; +using RageCoop.Core; namespace RageCoop.Client { @@ -28,16 +29,23 @@ namespace RageCoop.Client World.DrawLine(wb.Position, wb.Position + wb.RightVector, Color.Blue); } if (ToMark == null) return; + if (WeaponUtil.VehicleWeapons.TryGetValue((uint)(int)ToMark.Model, out var info)) { foreach (var ws in info.Weapons) { foreach (var w in ws.Value.Bones) { - DrawBone(w.BoneName, ws.Value.Name); + DrawBone(w.BoneName, ws.Value.Name+":"+ws.Key.ToHex()); } } } + var P = Game.Player.Character; + var b = ToMark.GetMuzzleBone(P.VehicleWeapon); + if (b != null) + { + World.DrawLine(b.Position, b.Position + b.ForwardVector * 5, Color.Brown); + } } void FindAndDraw() { diff --git a/Client/Scripts/Properties/AssemblyInfo.cs b/Client/Scripts/Properties/AssemblyInfo.cs index 83ad61a..81299a4 100644 --- a/Client/Scripts/Properties/AssemblyInfo.cs +++ b/Client/Scripts/Properties/AssemblyInfo.cs @@ -16,7 +16,7 @@ using System.Resources; // Version informationr( -[assembly: AssemblyVersion("1.5.6.98")] -[assembly: AssemblyFileVersion("1.5.6.98")] +[assembly: AssemblyVersion("1.5.6.104")] +[assembly: AssemblyFileVersion("1.5.6.104")] [assembly: NeutralResourcesLanguageAttribute( "en-US" )] diff --git a/Client/Scripts/Util/PedExtensions.cs b/Client/Scripts/Util/PedExtensions.cs index 56ad5fa..51af06b 100644 --- a/Client/Scripts/Util/PedExtensions.cs +++ b/Client/Scripts/Util/PedExtensions.cs @@ -327,20 +327,18 @@ namespace RageCoop.Client } public static Vector3 GetAimCoord(this Ped p) { - var weapon = p.Weapons.CurrentWeaponObject; + Prop weapon; - var v = p.CurrentVehicle; - // Rhino - if (v != null && v.Model.Hash == 782665360) - { - return v.Bones[35].Position + v.Bones[35].ForwardVector * 100; - } + EntityBone b; if (p.IsOnTurretSeat()) { - var b = p.CurrentVehicle.GetMuzzleBone(p.VehicleWeapon); - return b.Position + b.ForwardVector * 50; + if((b = p.CurrentVehicle.GetMuzzleBone(p.VehicleWeapon)) != null) + { + return b.Position + b.ForwardVector * 50; + } + return GetLookingCoord(p); } - if (weapon != null) + if ((weapon= p.Weapons.CurrentWeaponObject) != null) { // Not very accurate, but doesn't matter Vector3 dir = weapon.RightVector; diff --git a/Client/Scripts/Util/WeaponUtil.cs b/Client/Scripts/Util/WeaponUtil.cs index cb1c5db..dc5fb9a 100644 --- a/Client/Scripts/Util/WeaponUtil.cs +++ b/Client/Scripts/Util/WeaponUtil.cs @@ -281,6 +281,7 @@ namespace RageCoop.Client } public static EntityBone GetMuzzleBone(this Vehicle v, VehicleWeaponHash hash) { + if ((uint)hash == 1422046295) { hash = VehicleWeaponHash.WaterCannon; } // Weird... var i = v.GetMuzzleIndex(hash); if (i == -1) { return null; } return v.Bones[i]; diff --git a/RageCoop-V.sln b/RageCoop-V.sln index ad4a479..b09d04c 100644 --- a/RageCoop-V.sln +++ b/RageCoop-V.sln @@ -20,6 +20,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .editorconfig = .editorconfig EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RageCoop.Client.DataDumper", "Client\DataDumper\RageCoop.Client.DataDumper.csproj", "{F3DFDDC8-D5B1-4E96-959E-492AD7A8BA30}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -68,6 +70,14 @@ Global {FC8CBDBB-6DC3-43AF-B34D-092E476410A5}.Release|Any CPU.Build.0 = Release|Any CPU {FC8CBDBB-6DC3-43AF-B34D-092E476410A5}.Release|x64.ActiveCfg = Release|Any CPU {FC8CBDBB-6DC3-43AF-B34D-092E476410A5}.Release|x64.Build.0 = Release|Any CPU + {F3DFDDC8-D5B1-4E96-959E-492AD7A8BA30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F3DFDDC8-D5B1-4E96-959E-492AD7A8BA30}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F3DFDDC8-D5B1-4E96-959E-492AD7A8BA30}.Debug|x64.ActiveCfg = Debug|Any CPU + {F3DFDDC8-D5B1-4E96-959E-492AD7A8BA30}.Debug|x64.Build.0 = Debug|Any CPU + {F3DFDDC8-D5B1-4E96-959E-492AD7A8BA30}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F3DFDDC8-D5B1-4E96-959E-492AD7A8BA30}.Release|Any CPU.Build.0 = Release|Any CPU + {F3DFDDC8-D5B1-4E96-959E-492AD7A8BA30}.Release|x64.ActiveCfg = Release|Any CPU + {F3DFDDC8-D5B1-4E96-959E-492AD7A8BA30}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE