filtering what consumable does player damage before generating its stats

This commit is contained in:
iAmAsval 2020-09-29 12:43:23 +02:00
parent 0d2c489360
commit 4ad0e9f039
24 changed files with 146 additions and 101 deletions

View File

@ -103,6 +103,8 @@ namespace FModel.Creator.Bases
Description = Text.GetTextPropertyBase(arrayDescription);
if (export.GetExport<StructProperty>("MaxStackSize") is StructProperty maxStackSize)
ShortDescription = Text.GetMaxStackSize(maxStackSize);
else if (export.GetExport<StructProperty>("XpRewardAmount") is StructProperty xpRewardAmount)
ShortDescription = Text.GetXpRewardAmount(xpRewardAmount);
else if (export.GetExport<TextProperty>("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<SoftObjectProperty>("AmmoData") is SoftObjectProperty ammoData)
Statistics.GetAmmoData(this, ammoData);
if (export.GetExport<StructProperty>("WeaponStatHandle") is StructProperty weaponStatHandle)
if (export.GetExport<StructProperty>("WeaponStatHandle") is StructProperty weaponStatHandle &&
(exportType.Equals("FortWeaponMeleeItemDefinition") ||
(export.GetExport<SoftObjectProperty>("StatList") is SoftObjectProperty statList &&
!statList.Value.AssetPathName.String.StartsWith("/Game/UI/Tooltips/NoTooltipStats"))))
{
Statistics.GetWeaponStats(this, weaponStatHandle);
}
if (export.GetExport<ObjectProperty>("HeroGameplayDefinition") is ObjectProperty heroGameplayDefinition)
Statistics.GetHeroStats(this, heroGameplayDefinition);

View File

@ -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<UObject>();
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<UObject>();
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()
});
}
}
}
}

View File

@ -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<UCurveTable>();
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)

View File

@ -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);

View File

@ -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))

View File

@ -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;

View File

@ -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)

View File

@ -8,11 +8,8 @@ namespace PakReader
public class LocResReader
{
static readonly FGuid Magic = new FGuid(0x7574140E, 0xFC034A67, 0x9D90154A, 0x1B7F37C3);
public readonly Dictionary<string, Dictionary<string, string>> Entries = new Dictionary<string, Dictionary<string, string>>();
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. */

View File

@ -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<byte> 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<string, FPakEntry>.this[string key] => Entries[key];
IEnumerable<string> IReadOnlyDictionary<string, FPakEntry>.Keys => Entries.Keys;
IEnumerable<FPakEntry> IReadOnlyDictionary<string, FPakEntry>.Values => Entries.Values;

View File

@ -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<T>(this IUExport export, params string[] names)
{
foreach (string name in names)

View File

@ -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<string> Keys => Map.Keys;
public IEnumerable<object> Values => Map.Values;
public int Count => Map.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ContainsKey(string key) => Map.ContainsKey(key);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IEnumerator<KeyValuePair<string, object>> 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);
}
}

View File

@ -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<string> Keys => RowMap.Keys;
public IEnumerable<object> Values => RowMap.Values;
public int Count => RowMap.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ContainsKey(string key) => RowMap.ContainsKey(key);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IEnumerator<KeyValuePair<string, object>> 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);
}
}

View File

@ -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<string> Keys => RowMap.Keys;
public IEnumerable<object> Values => RowMap.Values;
public int Count => RowMap.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ContainsKey(string key) => RowMap.ContainsKey(key);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IEnumerator<KeyValuePair<string, object>> 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)

View File

@ -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<string> Keys => FontFaceAsset.Keys;
public IEnumerable<object> Values => FontFaceAsset.Values;
public int Count => FontFaceAsset.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ContainsKey(string key) => FontFaceAsset.ContainsKey(key);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IEnumerator<KeyValuePair<string, object>> 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);
}
}

View File

@ -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<string> Keys => Dict.Keys;
public IEnumerable<object> Values => Dict.Values;
public int Count => Dict.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ContainsKey(string key) => Dict.ContainsKey(key);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IEnumerator<KeyValuePair<string, object>> 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);
}
}

View File

@ -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<string> Keys => Map.Keys;
public IEnumerable<object> Values => Map.Values;
public int Count => Map.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ContainsKey(string key) => Map.ContainsKey(key);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IEnumerator<KeyValuePair<string, object>> 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);
}
}

View File

@ -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;

View File

@ -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<FObjectExport>();
}
[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<T>(Func<T> 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; }

View File

@ -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;
}
}

View File

@ -1,57 +0,0 @@
using System;
using System.Collections.Generic;
using System.Reflection;
namespace PakReader.Parsers
{
static class ReflectionHelper
{
readonly static Dictionary<Type, (Type BaseType, Func<object, object> Setter)> PropertyCache = new Dictionary<Type, (Type, Func<object, object>)>();
static class New<T>
{
public static readonly Func<T> Instance = GetInstance();
public static readonly IReadOnlyDictionary<(string Name, Type Type), Action<object, object>> ActionMap = GetActionMap();
static Func<T> GetInstance()
{
var constructor = typeof(T).GetConstructor(Type.EmptyTypes);
return () => (T)constructor.Invoke(Array.Empty<object>());
}
static IReadOnlyDictionary<(string Name, Type Type), Action<object, object>> GetActionMap()
{
var dict = new Dictionary<(string Name, Type Type), Action<object, object>>();
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<UPropAttribute>()?.Name ?? Properties[i].Name).ToLowerInvariant(), Properties[i].PropertyType)] = Properties[i].SetValue;
}
for (int i = 0; i < Fields.Length; i++)
{
dict[((Fields[i].GetCustomAttribute<UPropAttribute>()?.Name ?? Fields[i].Name).ToLowerInvariant(), Fields[i].FieldType)] = Fields[i].SetValue;
}
return dict;
}
}
internal static T NewInstance<T>() => New<T>.Instance();
internal static IReadOnlyDictionary<(string Name, Type Type), Action<object, object>> GetActionMap<T>() => New<T>.ActionMap;
internal static (Type BaseType, Func<object, object> 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;
}
}
}

View File

@ -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<T>(this BinaryReader reader, Func<T> Getter)
{
int SerializeNum = reader.ReadInt32();

View File

@ -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;

View File

@ -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
{

View File

@ -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("/"));
}