diff --git a/BinarySearchForm.cs b/BinarySearchForm.cs index fe82c9c..3e66f5e 100644 --- a/BinarySearchForm.cs +++ b/BinarySearchForm.cs @@ -41,7 +41,7 @@ namespace CodeWalker { Task.Run(() => { - GTA5Keys.LoadFromPath(Settings.Default.GTAFolder); + GTA5Keys.LoadFromPath(Settings.Default.GTAFolder, Settings.Default.Key); RpfMan = new RpfManager(); RpfMan.Init(Settings.Default.GTAFolder, UpdateStatus, UpdateStatus, false, false); RPFScanComplete(); diff --git a/BrowseForm.cs b/BrowseForm.cs index 56bc283..73945b5 100644 --- a/BrowseForm.cs +++ b/BrowseForm.cs @@ -64,7 +64,7 @@ namespace CodeWalker try { - GTA5Keys.LoadFromPath(Settings.Default.GTAFolder); + GTA5Keys.LoadFromPath(Settings.Default.GTAFolder, Settings.Default.Key); KeysLoaded = true; UpdateStatus("Ready to scan..."); } diff --git a/CodeWalker.Core/CodeWalker.Core.csproj b/CodeWalker.Core/CodeWalker.Core.csproj new file mode 100644 index 0000000..efd6c47 --- /dev/null +++ b/CodeWalker.Core/CodeWalker.Core.csproj @@ -0,0 +1,78 @@ + + + + + Debug + AnyCPU + {DE50D3A6-B49E-47A0-ABE6-101473A00759} + Library + Properties + CodeWalker.Core + CodeWalker.Core + v4.5.2 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\SharpDX.4.0.1\lib\net45\SharpDX.dll + + + ..\packages\SharpDX.Mathematics.4.0.1\lib\net45\SharpDX.Mathematics.dll + + + + + + + + + + + + + + + + + + True + True + Resources.resx + + + + + + + + + + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + \ No newline at end of file diff --git a/GameFiles/Resources/Data.cs b/CodeWalker.Core/GameFiles/Utils/Data.cs similarity index 100% rename from GameFiles/Resources/Data.cs rename to CodeWalker.Core/GameFiles/Utils/Data.cs diff --git a/GameFiles/Utils/GTACrypto.cs b/CodeWalker.Core/GameFiles/Utils/GTACrypto.cs similarity index 100% rename from GameFiles/Utils/GTACrypto.cs rename to CodeWalker.Core/GameFiles/Utils/GTACrypto.cs diff --git a/GameFiles/Utils/GTAKeys.cs b/CodeWalker.Core/GameFiles/Utils/GTAKeys.cs similarity index 99% rename from GameFiles/Utils/GTAKeys.cs rename to CodeWalker.Core/GameFiles/Utils/GTAKeys.cs index d7ceff6..7a3c1b9 100644 --- a/GameFiles/Utils/GTAKeys.cs +++ b/CodeWalker.Core/GameFiles/Utils/GTAKeys.cs @@ -27,7 +27,7 @@ //shamelessly stolen -using CodeWalker.Properties; +using CodeWalker.Core.Properties; using System; using System.Collections.Generic; using System.IO; @@ -160,15 +160,12 @@ namespace CodeWalker.GameFiles updateStatus?.Invoke("Searching for AES key..."); PC_AES_KEY = HashSearch.SearchHash(exeStr, GTA5KeyHashes.PC_AES_KEY_HASH, 0x20); - Settings.Default.Key = Convert.ToBase64String(PC_AES_KEY); - Settings.Default.Save(); - updateStatus?.Invoke("Complete."); } - public static void LoadFromPath(string path = ".\\Keys") + public static void LoadFromPath(string path = ".\\Keys", string key = null) { //PC_AES_KEY = File.ReadAllBytes(path + "\\gtav_aes_key.dat"); //PC_NG_KEYS = CryptoIO.ReadNgKeys(path + "\\gtav_ng_key.dat"); @@ -178,7 +175,7 @@ namespace CodeWalker.GameFiles //PC_LUT = File.ReadAllBytes(path + "\\gtav_hash_lut.dat"); //GenerateMagicData(path); - UseMagicData(path); + UseMagicData(path, key); } public static void SaveToPath(string path = ".\\Keys") @@ -248,17 +245,17 @@ namespace CodeWalker.GameFiles } - private static void UseMagicData(string path) + private static void UseMagicData(string path, string key) { - if (string.IsNullOrEmpty(Settings.Default.Key)) + if (string.IsNullOrEmpty(key)) { byte[] exedata = File.ReadAllBytes(path + "\\gta5.exe"); GenerateV2(exedata, null); } else { - PC_AES_KEY = Convert.FromBase64String(Settings.Default.Key); + PC_AES_KEY = Convert.FromBase64String(key); } //GenerateMagicData(); diff --git a/GameFiles/Utils/Jenk.cs b/CodeWalker.Core/GameFiles/Utils/Jenk.cs similarity index 100% rename from GameFiles/Utils/Jenk.cs rename to CodeWalker.Core/GameFiles/Utils/Jenk.cs diff --git a/CodeWalker.Core/Properties/AssemblyInfo.cs b/CodeWalker.Core/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d144d2e --- /dev/null +++ b/CodeWalker.Core/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CodeWalker.Core")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CodeWalker.Core")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("de50d3a6-b49e-47a0-abe6-101473a00759")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/CodeWalker.Core/Properties/Resources.Designer.cs b/CodeWalker.Core/Properties/Resources.Designer.cs new file mode 100644 index 0000000..252a5db --- /dev/null +++ b/CodeWalker.Core/Properties/Resources.Designer.cs @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace CodeWalker.Core.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CodeWalker.Core.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] magic { + get { + object obj = ResourceManager.GetObject("magic", resourceCulture); + return ((byte[])(obj)); + } + } + } +} diff --git a/CodeWalker.Core/Properties/Resources.resx b/CodeWalker.Core/Properties/Resources.resx new file mode 100644 index 0000000..8d010db --- /dev/null +++ b/CodeWalker.Core/Properties/Resources.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\magic.dat;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Resources/magic.dat b/CodeWalker.Core/Resources/magic.dat similarity index 100% rename from Resources/magic.dat rename to CodeWalker.Core/Resources/magic.dat diff --git a/Utils/Cache.cs b/CodeWalker.Core/Utils/Cache.cs similarity index 100% rename from Utils/Cache.cs rename to CodeWalker.Core/Utils/Cache.cs diff --git a/Utils/Matrices.cs b/CodeWalker.Core/Utils/Matrices.cs similarity index 100% rename from Utils/Matrices.cs rename to CodeWalker.Core/Utils/Matrices.cs diff --git a/Utils/Quaternions.cs b/CodeWalker.Core/Utils/Quaternions.cs similarity index 100% rename from Utils/Quaternions.cs rename to CodeWalker.Core/Utils/Quaternions.cs diff --git a/CodeWalker.Core/Utils/Utils.cs b/CodeWalker.Core/Utils/Utils.cs new file mode 100644 index 0000000..891bc9f --- /dev/null +++ b/CodeWalker.Core/Utils/Utils.cs @@ -0,0 +1,197 @@ +using SharpDX; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Globalization; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace CodeWalker +{ + + + public static class TextUtil + { + + public static string GetBytesReadable(long i) + { + //shamelessly stolen from stackoverflow, and a bit mangled + + // Returns the human-readable file size for an arbitrary, 64-bit file size + // The default format is "0.### XB", e.g. "4.2 KB" or "1.434 GB" + // Get absolute value + long absolute_i = (i < 0 ? -i : i); + // Determine the suffix and readable value + string suffix; + double readable; + if (absolute_i >= 0x1000000000000000) // Exabyte + { + suffix = "EB"; + readable = (i >> 50); + } + else if (absolute_i >= 0x4000000000000) // Petabyte + { + suffix = "PB"; + readable = (i >> 40); + } + else if (absolute_i >= 0x10000000000) // Terabyte + { + suffix = "TB"; + readable = (i >> 30); + } + else if (absolute_i >= 0x40000000) // Gigabyte + { + suffix = "GB"; + readable = (i >> 20); + } + else if (absolute_i >= 0x100000) // Megabyte + { + suffix = "MB"; + readable = (i >> 10); + } + else if (absolute_i >= 0x400) // Kilobyte + { + suffix = "KB"; + readable = i; + } + else + { + return i.ToString("0 bytes"); // Byte + } + // Divide by 1024 to get fractional value + readable = (readable / 1024); + + string fmt = "0.### "; + if (readable > 1000) + { + fmt = "0"; + } + else if (readable > 100) + { + fmt = "0.#"; + } + else if (readable > 10) + { + fmt = "0.##"; + } + + // Return formatted number with suffix + return readable.ToString(fmt) + suffix; + } + } + + + + public static class FloatUtil + { + public static bool TryParse(string s, out float f) + { + f = 0.0f; + if (float.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out f)) + { + return true; + } + return false; + } + public static float Parse(string s) + { + float f; + TryParse(s, out f); + return f; + } + public static string ToString(float f) + { + var c = CultureInfo.InvariantCulture; + return f.ToString(c); + } + + + public static string GetVector2String(Vector2 v) + { + var c = CultureInfo.InvariantCulture; + return v.X.ToString(c) + ", " + v.Y.ToString(c); + } + public static string GetVector3String(Vector3 v) + { + var c = CultureInfo.InvariantCulture; + return v.X.ToString(c) + ", " + v.Y.ToString(c) + ", " + v.Z.ToString(c); + } + public static string GetVector3String(Vector3 v, string format) + { + var c = CultureInfo.InvariantCulture; + return v.X.ToString(format, c) + ", " + v.Y.ToString(format, c) + ", " + v.Z.ToString(format, c); + } + public static string GetVector3XmlString(Vector3 v) + { + var c = CultureInfo.InvariantCulture; + return string.Format("x=\"{0}\" y=\"{1}\" z=\"{2}\"", v.X.ToString(c), v.Y.ToString(c), v.Z.ToString(c)); + } + public static string GetVector4XmlString(Vector4 v) + { + var c = CultureInfo.InvariantCulture; + return string.Format("x=\"{0}\" y=\"{1}\" z=\"{2}\" w=\"{3}\"", v.X.ToString(c), v.Y.ToString(c), v.Z.ToString(c), v.W.ToString(c)); + } + public static string GetQuaternionXmlString(Quaternion q) + { + var c = CultureInfo.InvariantCulture; + return string.Format("x=\"{0}\" y=\"{1}\" z=\"{2}\" w=\"{3}\"", q.X.ToString(c), q.Y.ToString(c), q.Z.ToString(c), q.W.ToString(c)); + } + + public static Vector3 ParseVector3String(string s) + { + Vector3 p = new Vector3(0.0f); + string[] ss = s.Split(','); + if (ss.Length > 0) + { + FloatUtil.TryParse(ss[0].Trim(), out p.X); + } + if (ss.Length > 1) + { + FloatUtil.TryParse(ss[1].Trim(), out p.Y); + } + if (ss.Length > 2) + { + FloatUtil.TryParse(ss[2].Trim(), out p.Z); + } + return p; + } + + + + public static string GetVector4String(Vector4 v) + { + var c = CultureInfo.InvariantCulture; + return v.X.ToString(c) + ", " + v.Y.ToString(c) + ", " + v.Z.ToString(c) + ", " + v.W.ToString(c); + } + public static Vector4 ParseVector4String(string s) + { + Vector4 p = new Vector4(0.0f); + string[] ss = s.Split(','); + if (ss.Length > 0) + { + FloatUtil.TryParse(ss[0].Trim(), out p.X); + } + if (ss.Length > 1) + { + FloatUtil.TryParse(ss[1].Trim(), out p.Y); + } + if (ss.Length > 2) + { + FloatUtil.TryParse(ss[2].Trim(), out p.Z); + } + if (ss.Length > 3) + { + FloatUtil.TryParse(ss[3].Trim(), out p.W); + } + return p; + } + + + } + + + +} diff --git a/Utils/Vectors.cs b/CodeWalker.Core/Utils/Vectors.cs similarity index 100% rename from Utils/Vectors.cs rename to CodeWalker.Core/Utils/Vectors.cs diff --git a/Utils/Xml.cs b/CodeWalker.Core/Utils/Xml.cs similarity index 100% rename from Utils/Xml.cs rename to CodeWalker.Core/Utils/Xml.cs diff --git a/CodeWalker.Core/packages.config b/CodeWalker.Core/packages.config new file mode 100644 index 0000000..92b7713 --- /dev/null +++ b/CodeWalker.Core/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/CodeWalker.WinForms/CodeWalker.WinForms.csproj b/CodeWalker.WinForms/CodeWalker.WinForms.csproj index 4fd6b21..3f82a77 100644 --- a/CodeWalker.WinForms/CodeWalker.WinForms.csproj +++ b/CodeWalker.WinForms/CodeWalker.WinForms.csproj @@ -97,6 +97,7 @@ TreeViewFix.cs +