diff --git a/SkinHide/SkinHidePlugin.cs b/SkinHide/SkinHidePlugin.cs index 1e9d811..a9bbf7a 100644 --- a/SkinHide/SkinHidePlugin.cs +++ b/SkinHide/SkinHidePlugin.cs @@ -56,9 +56,9 @@ namespace SkinHide new PlayerModelViewPatch().Enable(); new PlayerPatch().Enable(); - ReflectionDatas.RefSlotViews = RefHelp.FieldRef.Create(new string[] { "SlotViews" }); - ReflectionDatas.RefSlotList = RefHelp.FieldRef>.Create(ReflectionDatas.RefSlotViews.FieldType, new string[] { "list_0" }); - ReflectionDatas.RefDresses = RefHelp.FieldRef.Create(ReflectionDatas.RefSlotList.FieldType.GetGenericArguments()[0], new string[] { "Dresses" }); + ReflectionDatas.RefSlotViews = RefHelp.FieldRef.Create("SlotViews"); + ReflectionDatas.RefSlotList = RefHelp.FieldRef>.Create(ReflectionDatas.RefSlotViews.FieldType, "list_0"); + ReflectionDatas.RefDresses = RefHelp.FieldRef.Create(ReflectionDatas.RefSlotList.FieldType.GetGenericArguments()[0], "Dresses"); ReflectionDatas.RefRenderers = RefHelp.FieldRef.Create(new string[] { "Renderers" }); } diff --git a/SkinHide/Utils/RefHelp.cs b/SkinHide/Utils/RefHelp.cs index 2344d51..16b6ae4 100644 --- a/SkinHide/Utils/RefHelp.cs +++ b/SkinHide/Utils/RefHelp.cs @@ -147,6 +147,18 @@ namespace SkinHide.Utils Init(propertyinfo, instance); } + public PropertyRef(Type type, string propertyname, object instance = null) + { + PropertyInfo propertyInfo = type.GetProperty(propertyname, AccessTools.all); + + if (propertyInfo == null) + { + throw new Exception(propertyname + " is null"); + } + + Init(propertyInfo, instance); + } + public PropertyRef(Type type, string[] propertynames, object instance = null) { PropertyInfo propertyInfo = propertynames.Select(x => type.GetProperty(x, AccessTools.all)).FirstOrDefault(x => x != null); @@ -191,11 +203,21 @@ namespace SkinHide.Utils return new PropertyRef(propertyinfo, instance); } + public static PropertyRef Create(string propertyname, object instance = null) + { + return new PropertyRef(typeof(T), propertyname, instance); + } + public static PropertyRef Create(string[] propertynames, object instance = null) { return new PropertyRef(typeof(T), propertynames, instance); } + public static PropertyRef Create(Type type, string propertyname, object instance = null) + { + return new PropertyRef(type, propertyname, instance); + } + public static PropertyRef Create(Type type, string[] propertynames, object instance = null) { return new PropertyRef(type, propertynames, instance); @@ -264,6 +286,18 @@ namespace SkinHide.Utils Init(fieldinfo, instance); } + public FieldRef(Type type, string fieldname, object instance = null) + { + FieldInfo fieldInfo = type.GetField(fieldname, AccessTools.all); + + if (fieldInfo == null) + { + throw new Exception(fieldInfo + " is null"); + } + + Init(fieldInfo, instance); + } + public FieldRef(Type type, string[] fieldnames, object instance = null) { FieldInfo fieldInfo = fieldnames.Select(x => type.GetField(x, AccessTools.all)).FirstOrDefault(x => x != null); @@ -281,11 +315,21 @@ namespace SkinHide.Utils return new FieldRef(fieldinfo, instance); } + public static FieldRef Create(string fieldname, object instance = null) + { + return new FieldRef(typeof(T), fieldname, instance); + } + public static FieldRef Create(string[] fieldnames, object instance = null) { return new FieldRef(typeof(T), fieldnames, instance); } + public static FieldRef Create(Type type, string fieldname, object instance = null) + { + return new FieldRef(type, fieldname, instance); + } + public static FieldRef Create(Type type, string[] fieldnames, object instance = null) { return new FieldRef(type, fieldnames, instance); @@ -361,4 +405,5 @@ namespace SkinHide.Utils } } + }