From 86237eb31dc30117986cea605b4dacc3f152283a Mon Sep 17 00:00:00 2001 From: kmyuhkyuk <2451614940@qq.com> Date: Wed, 26 Oct 2022 10:06:24 +0800 Subject: [PATCH] Update --- SkinHide/SkinHidePlugin.cs | 8 +++---- SkinHide/Utils/RefHelp.cs | 49 ++++++++++++++++++++++++++++---------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/SkinHide/SkinHidePlugin.cs b/SkinHide/SkinHidePlugin.cs index bcf120e..1e9d811 100644 --- a/SkinHide/SkinHidePlugin.cs +++ b/SkinHide/SkinHidePlugin.cs @@ -56,10 +56,10 @@ namespace SkinHide new PlayerModelViewPatch().Enable(); new PlayerPatch().Enable(); - 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("Renderers"); + 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.RefRenderers = RefHelp.FieldRef.Create(new string[] { "Renderers" }); } void Update() diff --git a/SkinHide/Utils/RefHelp.cs b/SkinHide/Utils/RefHelp.cs index 9ffb644..2344d51 100644 --- a/SkinHide/Utils/RefHelp.cs +++ b/SkinHide/Utils/RefHelp.cs @@ -139,12 +139,24 @@ namespace SkinHide.Utils public PropertyRef(PropertyInfo propertyinfo, object instance = null) { + if (propertyinfo == null) + { + throw new Exception("PropertyInfo is null"); + } + Init(propertyinfo, instance); } - public PropertyRef(Type type, string propertyname, object instance = null) + public PropertyRef(Type type, string[] propertynames, object instance = null) { - Init(type.GetProperty(propertyname, AccessTools.all), instance); + PropertyInfo propertyInfo = propertynames.Select(x => type.GetProperty(x, AccessTools.all)).FirstOrDefault(x => x != null); + + if (propertyInfo == null) + { + throw new Exception(propertynames.First() + " is null"); + } + + Init(propertyInfo, instance); } private void Init(PropertyInfo propertyinfo, object instance) @@ -179,14 +191,14 @@ namespace SkinHide.Utils return new PropertyRef(propertyinfo, instance); } - public static PropertyRef Create(string propertyname, object instance = null) + public static PropertyRef Create(string[] propertynames, object instance = null) { - return new PropertyRef(typeof(T), propertyname, instance); + return new PropertyRef(typeof(T), propertynames, instance); } - public static PropertyRef Create(Type type, string propertyname, object instance = null) + public static PropertyRef Create(Type type, string[] propertynames, object instance = null) { - return new PropertyRef(type, propertyname, instance); + return new PropertyRef(type, propertynames, instance); } public F GetValue(T instance) @@ -244,12 +256,24 @@ namespace SkinHide.Utils public FieldRef(FieldInfo fieldinfo, object instance = null) { + if (fieldinfo == null) + { + throw new Exception("FieldInfo is null"); + } + Init(fieldinfo, instance); } - public FieldRef(Type type, string fieldname, object instance = null) + public FieldRef(Type type, string[] fieldnames, object instance = null) { - Init(type.GetField(fieldname, AccessTools.all), instance); + FieldInfo fieldInfo = fieldnames.Select(x => type.GetField(x, AccessTools.all)).FirstOrDefault(x => x != null); + + if (fieldInfo == null) + { + throw new Exception(fieldnames.First() + " is null"); + } + + Init(fieldInfo, instance); } public static FieldRef Create(FieldInfo fieldinfo, object instance = null) @@ -257,14 +281,14 @@ namespace SkinHide.Utils return new FieldRef(fieldinfo, instance); } - public static FieldRef Create(string fieldname, object instance = null) + public static FieldRef Create(string[] fieldnames, object instance = null) { - return new FieldRef(typeof(T), fieldname, instance); + return new FieldRef(typeof(T), fieldnames, instance); } - public static FieldRef Create(Type type, string fieldname, object instance = null) + public static FieldRef Create(Type type, string[] fieldnames, object instance = null) { - return new FieldRef(type, fieldname, instance); + return new FieldRef(type, fieldnames, instance); } private void Init(FieldInfo fieldinfo, object instance = null) @@ -336,4 +360,5 @@ namespace SkinHide.Utils return GetEftMethod(GetEftType(func), flags, func2); } } + }