diff --git a/FModel/Creator/Bases/BaseIcon.cs b/FModel/Creator/Bases/BaseIcon.cs index 0141de45..78d412a4 100644 --- a/FModel/Creator/Bases/BaseIcon.cs +++ b/FModel/Creator/Bases/BaseIcon.cs @@ -103,6 +103,8 @@ namespace FModel.Creator.Bases Description = Text.GetTextPropertyBase(arrayDescription); if (export.GetExport("MaxStackSize") is StructProperty maxStackSize) ShortDescription = Text.GetMaxStackSize(maxStackSize); + else if (export.GetExport("XpRewardAmount") is StructProperty xpRewardAmount) + ShortDescription = Text.GetXpRewardAmount(xpRewardAmount); else if (export.GetExport("ShortDescription") is TextProperty shortDescription) ShortDescription = Text.GetTextPropertyBase(shortDescription); else if (exportType.Equals("AthenaItemWrapDefinition")) // if no ShortDescription it's most likely a wrap @@ -116,8 +118,13 @@ namespace FModel.Creator.Bases if (export.GetExport("AmmoData") is SoftObjectProperty ammoData) Statistics.GetAmmoData(this, ammoData); - if (export.GetExport("WeaponStatHandle") is StructProperty weaponStatHandle) + if (export.GetExport("WeaponStatHandle") is StructProperty weaponStatHandle && + (exportType.Equals("FortWeaponMeleeItemDefinition") || + (export.GetExport("StatList") is SoftObjectProperty statList && + !statList.Value.AssetPathName.String.StartsWith("/Game/UI/Tooltips/NoTooltipStats")))) + { Statistics.GetWeaponStats(this, weaponStatHandle); + } if (export.GetExport("HeroGameplayDefinition") is ObjectProperty heroGameplayDefinition) Statistics.GetHeroStats(this, heroGameplayDefinition); diff --git a/FModel/Creator/Stats/Statistics.cs b/FModel/Creator/Stats/Statistics.cs index d1444e36..e1041ff9 100644 --- a/FModel/Creator/Stats/Statistics.cs +++ b/FModel/Creator/Stats/Statistics.cs @@ -14,20 +14,23 @@ namespace FModel.Creator.Stats { public static void GetAmmoData(BaseIcon icon, SoftObjectProperty ammoData) { - PakPackage p = Utils.GetPropertyPakPackage(ammoData.Value.AssetPathName.String); - if (p.HasExport() && !p.Equals(default)) + if (!ammoData.Value.AssetPathName.String.StartsWith("/Game/Athena/Items/Consumables/")) { - var obj = p.GetExport(); - if (obj != null) + PakPackage p = Utils.GetPropertyPakPackage(ammoData.Value.AssetPathName.String); + if (p.HasExport() && !p.Equals(default)) { - if (obj.TryGetValue("DisplayName", out var v1) && v1 is TextProperty displayName && - obj.TryGetValue("SmallPreviewImage", out var v2) && v2 is SoftObjectProperty smallPreviewImage) + var obj = p.GetExport(); + if (obj != null) { - icon.Stats.Add(new Statistic + if (obj.TryGetValue("DisplayName", out var v1) && v1 is TextProperty displayName && + obj.TryGetValue("SmallPreviewImage", out var v2) && v2 is SoftObjectProperty smallPreviewImage) { - Icon = Utils.GetSoftObjectTexture(smallPreviewImage), - Description = Text.GetTextPropertyBase(displayName).ToUpper() - }); + icon.Stats.Add(new Statistic + { + Icon = Utils.GetSoftObjectTexture(smallPreviewImage), + Description = Text.GetTextPropertyBase(displayName).ToUpper() + }); + } } } } diff --git a/FModel/Creator/Texts/Text.cs b/FModel/Creator/Texts/Text.cs index d38be445..b12767ca 100644 --- a/FModel/Creator/Texts/Text.cs +++ b/FModel/Creator/Texts/Text.cs @@ -87,6 +87,35 @@ namespace FModel.Creator.Texts return string.Empty; } + public static string GetXpRewardAmount(StructProperty xpRewardAmount) + { + if (xpRewardAmount.Value is UObject o1) + { + if ( + o1.TryGetValue("Curve", out var c1) && c1 is StructProperty curve && curve.Value is UObject o2 && + o2.TryGetValue("CurveTable", out var c2) && c2 is ObjectProperty curveTable && + o2.TryGetValue("RowName", out var c3) && c3 is NameProperty rowName) // new way + { + PakPackage p = Utils.GetPropertyPakPackage(curveTable.Value.Resource.OuterIndex.Resource.ObjectName.String); + if (p.HasExport() && !p.Equals(default)) + { + var table = p.GetExport(); + if (table != null) + { + if (table.TryGetValue(rowName.Value.String, out var v1) && v1 is UObject maxStackAmount && + maxStackAmount.TryGetValue("Keys", out var v2) && v2 is ArrayProperty keys && + keys.Value.Length > 0 && (keys.Value[0] as StructProperty).Value is FSimpleCurveKey amount && + amount.KeyValue != -1) + { + return $"{amount.KeyValue} Xp"; + } + } + } + } + } + return string.Empty; + } + public static void DrawBackground(SKCanvas c, IBase icon) { switch ((EIconDesign)Properties.Settings.Default.AssetsIconDesign) diff --git a/FModel/Creator/Utils.cs b/FModel/Creator/Utils.cs index f7677170..e750ec6b 100644 --- a/FModel/Creator/Utils.cs +++ b/FModel/Creator/Utils.cs @@ -4,11 +4,13 @@ using PakReader.Parsers.Class; using PakReader.Parsers.PropertyTagData; using SkiaSharp; using System; +using System.Runtime.CompilerServices; namespace FModel.Creator { static class Utils { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string GetFullPath(string partialPath) { foreach (var fileReader in Globals.CachedPakFiles.Values) @@ -45,7 +47,9 @@ namespace FModel.Creator return default; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SKBitmap NewZeroedBitmap(int width, int height) => new SKBitmap(new SKImageInfo(width, height), SKBitmapAllocFlags.ZeroPixels); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SKBitmap Resize(this SKBitmap me, int width, int height) { var bmp = NewZeroedBitmap(width, height); diff --git a/FModel/PakReader/AESDecryptor.cs b/FModel/PakReader/AESDecryptor.cs index 2b2121ca..d59b9d10 100644 --- a/FModel/PakReader/AESDecryptor.cs +++ b/FModel/PakReader/AESDecryptor.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Runtime.CompilerServices; using System.Security.Cryptography; namespace PakReader @@ -18,6 +19,7 @@ namespace PakReader Cipher.BlockSize = BLOCK_SIZE; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] static ICryptoTransform GetDecryptor(byte[] key) { if (!CachedTransforms.TryGetValue(key, out var ret)) diff --git a/FModel/PakReader/BinaryHelper.cs b/FModel/PakReader/BinaryHelper.cs index 754f2fce..c60215c9 100644 --- a/FModel/PakReader/BinaryHelper.cs +++ b/FModel/PakReader/BinaryHelper.cs @@ -12,6 +12,7 @@ namespace PakReader return val + alignment - 1 & ~(alignment - 1); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint Flip(uint value) => (value & 0x000000FFU) << 24 | (value & 0x0000FF00U) << 8 | (value & 0x00FF0000U) >> 8 | (value & 0xFF000000U) >> 24; @@ -19,6 +20,8 @@ namespace PakReader string s = i.ToString("X2"); return s[0] + ((uint)s[1] << 16); }).ToArray(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHex(params byte[] bytes) { if (bytes == null) return null; @@ -32,10 +35,14 @@ namespace PakReader } return new string(result); } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToStringKey(this byte[] byteKey) { return "0x" + BitConverter.ToString(byteKey).Replace("-", ""); } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] ToBytesKey(this string stringKey) { byte[] arr = new byte[stringKey.Length >> 1]; @@ -45,6 +52,8 @@ namespace PakReader } return arr; } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static int GetHexVal(char hex) { int val = (int)hex; diff --git a/FModel/PakReader/LocMetaReader.cs b/FModel/PakReader/LocMetaReader.cs index 8a5fffee..70ca684f 100644 --- a/FModel/PakReader/LocMetaReader.cs +++ b/FModel/PakReader/LocMetaReader.cs @@ -6,12 +6,9 @@ namespace PakReader public class LocMetaReader { static readonly FGuid Magic = new FGuid(0xA14CEE4F, 0x83554868, 0xBD464C6C, 0x7C50DA70); - public readonly string NativeCulture; public readonly string NativeLocRes; - public LocMetaReader(string path) : this(File.OpenRead(path)) { } - public LocMetaReader(Stream stream) : this(new BinaryReader(stream)) { } public LocMetaReader(BinaryReader reader) diff --git a/FModel/PakReader/LocResReader.cs b/FModel/PakReader/LocResReader.cs index 9a3c7b00..64d8808d 100644 --- a/FModel/PakReader/LocResReader.cs +++ b/FModel/PakReader/LocResReader.cs @@ -8,11 +8,8 @@ namespace PakReader public class LocResReader { static readonly FGuid Magic = new FGuid(0x7574140E, 0xFC034A67, 0x9D90154A, 0x1B7F37C3); - public readonly Dictionary> Entries = new Dictionary>(); - public LocResReader(string path) : this(File.OpenRead(path)) { } - public LocResReader(Stream stream) : this(new BinaryReader(stream)) { } public LocResReader(BinaryReader reader) @@ -127,13 +124,6 @@ namespace PakReader } } - public string this[string ns, string key] => Entries[ns][key]; - public bool TryGetValue(string ns, string key, out string value) - { - value = null; - return Entries.TryGetValue(ns, out var nsret) && nsret.TryGetValue(key, out value); - } - public enum Version : byte { /** Legacy format file - will be missing the magic number. */ diff --git a/FModel/PakReader/Pak/PakFileReader.cs b/FModel/PakReader/Pak/PakFileReader.cs index ec460150..a153aec0 100644 --- a/FModel/PakReader/Pak/PakFileReader.cs +++ b/FModel/PakReader/Pak/PakFileReader.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.IO; +using System.Runtime.CompilerServices; using System.Text; using System.Text.RegularExpressions; using FModel.Logger; @@ -462,7 +463,9 @@ namespace PakReader.Pak return false; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryGetValue(string key, out FPakEntry value) => Entries.TryGetValue(key, out value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryGetPartialKey(string partialKey, out string key) { foreach (string path in Entries.Keys) @@ -478,11 +481,7 @@ namespace PakReader.Pak return false; } - public ReadOnlyMemory GetFile(string path) => Entries[CaseSensitive ? path : path.ToLowerInvariant()].GetData(Stream, AesKey, Info.CompressionMethods); - // IReadOnlyDictionary implementation (to prevent writing to the Entries dictionary - - // TODO: Make these methods respect CaseSensitive property FPakEntry IReadOnlyDictionary.this[string key] => Entries[key]; IEnumerable IReadOnlyDictionary.Keys => Entries.Keys; IEnumerable IReadOnlyDictionary.Values => Entries.Values; diff --git a/FModel/PakReader/Parsers/Class/IUExport.cs b/FModel/PakReader/Parsers/Class/IUExport.cs index e8d65e62..cf6687b1 100644 --- a/FModel/PakReader/Parsers/Class/IUExport.cs +++ b/FModel/PakReader/Parsers/Class/IUExport.cs @@ -1,5 +1,6 @@ using PakReader.Parsers.PropertyTagData; using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace PakReader.Parsers.Class { @@ -14,6 +15,7 @@ namespace PakReader.Parsers.Class public static class IUExportExtension { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T GetExport(this IUExport export, params string[] names) { foreach (string name in names) diff --git a/FModel/PakReader/Parsers/Class/UAkAudioEvent.cs b/FModel/PakReader/Parsers/Class/UAkAudioEvent.cs index 17d4393b..e8f432dd 100644 --- a/FModel/PakReader/Parsers/Class/UAkAudioEvent.cs +++ b/FModel/PakReader/Parsers/Class/UAkAudioEvent.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace PakReader.Parsers.Class { @@ -20,10 +21,14 @@ namespace PakReader.Parsers.Class public IEnumerable Keys => Map.Keys; public IEnumerable Values => Map.Values; public int Count => Map.Count; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool ContainsKey(string key) => Map.ContainsKey(key); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerator> GetEnumerator() => Map.GetEnumerator(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] IEnumerator IEnumerable.GetEnumerator() => Map.GetEnumerator(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryGetValue(string key, out object value) => Map.TryGetValue(key, out value); } } diff --git a/FModel/PakReader/Parsers/Class/UCurveTable.cs b/FModel/PakReader/Parsers/Class/UCurveTable.cs index 3d81466a..7296db5e 100644 --- a/FModel/PakReader/Parsers/Class/UCurveTable.cs +++ b/FModel/PakReader/Parsers/Class/UCurveTable.cs @@ -1,6 +1,7 @@ using PakReader.Parsers.Objects; using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace PakReader.Parsers.Class { @@ -35,10 +36,14 @@ namespace PakReader.Parsers.Class public IEnumerable Keys => RowMap.Keys; public IEnumerable Values => RowMap.Values; public int Count => RowMap.Count; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool ContainsKey(string key) => RowMap.ContainsKey(key); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerator> GetEnumerator() => RowMap.GetEnumerator(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] IEnumerator IEnumerable.GetEnumerator() => RowMap.GetEnumerator(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryGetValue(string key, out object value) => RowMap.TryGetValue(key, out value); } } diff --git a/FModel/PakReader/Parsers/Class/UDataTable.cs b/FModel/PakReader/Parsers/Class/UDataTable.cs index 377d7f4e..07d7ac74 100644 --- a/FModel/PakReader/Parsers/Class/UDataTable.cs +++ b/FModel/PakReader/Parsers/Class/UDataTable.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace PakReader.Parsers.Class { @@ -33,11 +34,16 @@ namespace PakReader.Parsers.Class public IEnumerable Keys => RowMap.Keys; public IEnumerable Values => RowMap.Values; public int Count => RowMap.Count; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool ContainsKey(string key) => RowMap.ContainsKey(key); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerator> GetEnumerator() => RowMap.GetEnumerator(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] IEnumerator IEnumerable.GetEnumerator() => RowMap.GetEnumerator(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryGetValue(string key, out object value) => RowMap.TryGetValue(key, out value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryGetCaseInsensitiveValue(string key, out object value) { foreach (var r in RowMap) diff --git a/FModel/PakReader/Parsers/Class/UFontFace.cs b/FModel/PakReader/Parsers/Class/UFontFace.cs index 959a154c..cc7e4f46 100644 --- a/FModel/PakReader/Parsers/Class/UFontFace.cs +++ b/FModel/PakReader/Parsers/Class/UFontFace.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.IO; +using System.Runtime.CompilerServices; namespace PakReader.Parsers.Class { @@ -33,10 +34,14 @@ namespace PakReader.Parsers.Class public IEnumerable Keys => FontFaceAsset.Keys; public IEnumerable Values => FontFaceAsset.Values; public int Count => FontFaceAsset.Count; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool ContainsKey(string key) => FontFaceAsset.ContainsKey(key); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerator> GetEnumerator() => FontFaceAsset.GetEnumerator(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] IEnumerator IEnumerable.GetEnumerator() => FontFaceAsset.GetEnumerator(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryGetValue(string key, out object value) => FontFaceAsset.TryGetValue(key, out value); } } diff --git a/FModel/PakReader/Parsers/Class/UObject.cs b/FModel/PakReader/Parsers/Class/UObject.cs index e8a9dcfa..f0f3a1ff 100644 --- a/FModel/PakReader/Parsers/Class/UObject.cs +++ b/FModel/PakReader/Parsers/Class/UObject.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; using PakReader.Parsers.Objects; using PakReader.Parsers.PropertyTagData; @@ -55,10 +56,14 @@ namespace PakReader.Parsers.Class public IEnumerable Keys => Dict.Keys; public IEnumerable Values => Dict.Values; public int Count => Dict.Count; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool ContainsKey(string key) => Dict.ContainsKey(key); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerator> GetEnumerator() => Dict.GetEnumerator(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] IEnumerator IEnumerable.GetEnumerator() => Dict.GetEnumerator(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryGetValue(out object value, params string[] keys) { foreach (string key in keys) @@ -72,6 +77,7 @@ namespace PakReader.Parsers.Class value = null; return false; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryGetValue(string key, out object value) => Dict.TryGetValue(key, out value); } } diff --git a/FModel/PakReader/Parsers/Class/UStringTable.cs b/FModel/PakReader/Parsers/Class/UStringTable.cs index 949343f0..3118b079 100644 --- a/FModel/PakReader/Parsers/Class/UStringTable.cs +++ b/FModel/PakReader/Parsers/Class/UStringTable.cs @@ -1,6 +1,7 @@ using PakReader.Parsers.Objects; using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace PakReader.Parsers.Class { @@ -23,10 +24,14 @@ namespace PakReader.Parsers.Class public IEnumerable Keys => Map.Keys; public IEnumerable Values => Map.Values; public int Count => Map.Count; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool ContainsKey(string key) => Map.ContainsKey(key); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerator> GetEnumerator() => Map.GetEnumerator(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] IEnumerator IEnumerable.GetEnumerator() => Map.GetEnumerator(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryGetValue(string key, out object value) => Map.TryGetValue(key, out value); } } diff --git a/FModel/PakReader/Parsers/Objects/FPakEntry.cs b/FModel/PakReader/Parsers/Objects/FPakEntry.cs index 63a98c83..e1cf4ba2 100644 --- a/FModel/PakReader/Parsers/Objects/FPakEntry.cs +++ b/FModel/PakReader/Parsers/Objects/FPakEntry.cs @@ -1,6 +1,7 @@ using Ionic.Zlib; using System; using System.IO; +using System.Runtime.CompilerServices; namespace PakReader.Parsers.Objects { @@ -229,16 +230,25 @@ namespace PakReader.Parsers.Objects public FPakEntry Uexp = null; public FPakEntry Ubulk = null; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool IsUE4Package() => Name[Name.LastIndexOf(".")..].Equals(".uasset"); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool IsLocres() => Name[Name.LastIndexOf(".")..].Equals(".locres"); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool IsUE4Map() => Name[Name.LastIndexOf(".")..].Equals(".umap"); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool IsUE4Font() => Name[Name.LastIndexOf(".")..].Equals(".ufont"); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool HasUexp() => Uexp != null; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool HasUbulk() => Ubulk != null; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool IsCompressed() => UncompressedSize != Size || CompressionMethodIndex != (int)ECompressionFlags.COMPRESS_None; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public string GetExtension() => Name[Name.LastIndexOf(".")..]; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public string GetPathWithoutFile() { int stop = Name.LastIndexOf("/"); @@ -246,14 +256,18 @@ namespace PakReader.Parsers.Objects stop = 0; return Name.Substring(0, stop); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public string GetPathWithoutExtension() => Name.Substring(0, Name.LastIndexOf(".")); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public string GetNameWithExtension() => Name.Substring(Name.LastIndexOf("/") + 1); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public string GetNameWithoutExtension() { int start = Name.LastIndexOf("/") + 1; int stop = Name.LastIndexOf(".") - start; return Name.Substring(start, stop); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public string GetFirstFolder() => Name.Substring(Name.StartsWith('/') ? 1 : 0, Name.IndexOf('/')); public override string ToString() => Name; diff --git a/FModel/PakReader/Parsers/PackageReader.cs b/FModel/PakReader/Parsers/PackageReader.cs index 60453e97..7049894e 100644 --- a/FModel/PakReader/Parsers/PackageReader.cs +++ b/FModel/PakReader/Parsers/PackageReader.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Linq; +using System.Runtime.CompilerServices; using PakReader.Parsers.Class; using PakReader.Parsers.Objects; @@ -18,7 +19,6 @@ namespace PakReader.Parsers public IUExport[] DataExports { get; } public FName[] DataExportTypes { get; } - public PackageReader(string path) : this(path + ".uasset", path + ".uexp", path + ".ubulk") { } public PackageReader(string uasset, string uexp, string ubulk) : this(File.OpenRead(uasset), File.OpenRead(uexp), File.Exists(ubulk) ? File.OpenRead(ubulk) : null) { } public PackageReader(Stream uasset, Stream uexp, Stream ubulk) : this(new BinaryReader(uasset), new BinaryReader(uexp), ubulk) { } @@ -121,6 +121,7 @@ namespace PakReader.Parsers return Array.Empty(); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public FName ReadFName() { var NameIndex = Loader.ReadInt32(); @@ -141,19 +142,32 @@ namespace PakReader.Parsers public static implicit operator BinaryReader(PackageReader reader) => reader.Loader; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public byte ReadByte() => Loader.ReadByte(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public sbyte ReadSByte() => Loader.ReadSByte(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public byte[] ReadBytes(int count) => Loader.ReadBytes(count); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public string ReadFString() => Loader.ReadFString(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T[] ReadTArray(Func Getter) => Loader.ReadTArray(Getter); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public short ReadInt16() => Loader.ReadInt16(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ushort ReadUInt16() => Loader.ReadUInt16(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public int ReadInt32() => Loader.ReadInt32(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public uint ReadUInt32() => Loader.ReadUInt32(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public long ReadInt64() => Loader.ReadInt64(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ulong ReadUInt64() => Loader.ReadUInt64(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public float ReadFloat() => Loader.ReadSingle(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public double ReadDouble() => Loader.ReadDouble(); public long Position { get => Loader.BaseStream.Position; set => Loader.BaseStream.Position = value; } diff --git a/FModel/PakReader/Parsers/PropertyAttribute.cs b/FModel/PakReader/Parsers/PropertyAttribute.cs deleted file mode 100644 index e9929d3a..00000000 --- a/FModel/PakReader/Parsers/PropertyAttribute.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace PakReader.Parsers -{ - [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = true, AllowMultiple = false)] - public sealed class UPropAttribute : Attribute - { - public string Name { get; } - - public UPropAttribute(string name) => - Name = name; - } -} diff --git a/FModel/PakReader/Parsers/ReflectionHelper.cs b/FModel/PakReader/Parsers/ReflectionHelper.cs deleted file mode 100644 index b6a46e63..00000000 --- a/FModel/PakReader/Parsers/ReflectionHelper.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; - -namespace PakReader.Parsers -{ - static class ReflectionHelper - { - readonly static Dictionary Setter)> PropertyCache = new Dictionary)>(); - - static class New - { - public static readonly Func Instance = GetInstance(); - public static readonly IReadOnlyDictionary<(string Name, Type Type), Action> ActionMap = GetActionMap(); - - static Func GetInstance() - { - var constructor = typeof(T).GetConstructor(Type.EmptyTypes); - return () => (T)constructor.Invoke(Array.Empty()); - } - - static IReadOnlyDictionary<(string Name, Type Type), Action> GetActionMap() - { - var dict = new Dictionary<(string Name, Type Type), Action>(); - - var Fields = typeof(T).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); - var Properties = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); - - for (int i = 0; i < Properties.Length; i++) - { - dict[((Properties[i].GetCustomAttribute()?.Name ?? Properties[i].Name).ToLowerInvariant(), Properties[i].PropertyType)] = Properties[i].SetValue; - } - for (int i = 0; i < Fields.Length; i++) - { - dict[((Fields[i].GetCustomAttribute()?.Name ?? Fields[i].Name).ToLowerInvariant(), Fields[i].FieldType)] = Fields[i].SetValue; - } - - return dict; - } - } - - internal static T NewInstance() => New.Instance(); - internal static IReadOnlyDictionary<(string Name, Type Type), Action> GetActionMap() => New.ActionMap; - - internal static (Type BaseType, Func Getter) GetPropertyInfo(Type property) - { - if (!PropertyCache.TryGetValue(property, out var info)) - { - var baseType = property.BaseType; - // PropertyCache[property] = info = (baseType.GenericTypeArguments[0], baseType.GetField("Value").GetValue); - // Currently don't have this because of array/map/set property schenanigans - PropertyCache[property] = info = (property, (prop) => prop); - } - return info; - } - } -} diff --git a/FModel/PakReader/ReaderExtensions.cs b/FModel/PakReader/ReaderExtensions.cs index 5368868e..a486e2ee 100644 --- a/FModel/PakReader/ReaderExtensions.cs +++ b/FModel/PakReader/ReaderExtensions.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Runtime.CompilerServices; using System.Text; namespace PakReader @@ -44,6 +45,7 @@ namespace PakReader } } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] ReadTArray(this BinaryReader reader, Func Getter) { int SerializeNum = reader.ReadInt32(); diff --git a/FModel/Utils/Assets.cs b/FModel/Utils/Assets.cs index 6b3e8a36..ba8a74ac 100644 --- a/FModel/Utils/Assets.cs +++ b/FModel/Utils/Assets.cs @@ -25,6 +25,7 @@ using System.Text; using FModel.ViewModels.DataGrid; using ICSharpCode.AvalonEdit.Highlighting; using static FModel.Creator.Creator; +using System.Runtime.CompilerServices; namespace FModel.Utils { @@ -339,6 +340,7 @@ namespace FModel.Utils return false; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Filter(string filter, string item, out bool bSearch) { if (filter.StartsWith("!=")) @@ -436,6 +438,7 @@ namespace FModel.Utils } Copy(sb.ToString().Trim()); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Copy(FPakEntry entry, ECopy mode) { if (Globals.CachedPakFiles.TryGetValue(entry.PakFileName, out var r)) @@ -455,6 +458,7 @@ namespace FModel.Utils } return string.Empty; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Copy(string fullPath, ECopy mode) { string toCopy = string.Empty; diff --git a/FModel/Utils/Folders.cs b/FModel/Utils/Folders.cs index e7cb4ca0..39b37c0c 100644 --- a/FModel/Utils/Folders.cs +++ b/FModel/Utils/Folders.cs @@ -4,6 +4,7 @@ using Ionic.Zip; using System; using System.Diagnostics; using System.IO; +using System.Runtime.CompilerServices; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -17,6 +18,7 @@ namespace FModel.Utils CreateDefaultSubFolders(); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SetGameName(string pakPath) { int index = pakPath.LastIndexOf("\\Content\\Paks", StringComparison.Ordinal); @@ -40,7 +42,9 @@ namespace FModel.Utils } } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string GetGameName() => GetGameName(Globals.Game.ActualGame); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string GetGameName(EGame game) => game switch { diff --git a/FModel/Utils/Strings.cs b/FModel/Utils/Strings.cs index 1d65753d..83b46b3e 100644 --- a/FModel/Utils/Strings.cs +++ b/FModel/Utils/Strings.cs @@ -1,9 +1,11 @@ -using System.Text.RegularExpressions; +using System.Runtime.CompilerServices; +using System.Text.RegularExpressions; namespace FModel.Utils { static class Strings { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string GetReadableSize(double size) { string[] sizes = { Properties.Resources.B, Properties.Resources.KB, Properties.Resources.MB, Properties.Resources.GB, Properties.Resources.TB }; @@ -16,6 +18,7 @@ namespace FModel.Utils return string.Format("{0:# ###.##} {1}", size, sizes[order]).TrimStart(); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string FixPath(string path) { if (string.IsNullOrWhiteSpace(path)) @@ -23,7 +26,7 @@ namespace FModel.Utils string trigger; { - string tempPath = path.Substring(1); + string tempPath = path[1..]; trigger = tempPath.Substring(0, tempPath.IndexOf("/")); }