Browse Source

Modify GetFieldValue and remove SetFieldValue#

GetFieldValue can now get static fields without the need for an instance
SetFieldValue now has a TValue parameter that will be used
habeebweeb 3 years ago
parent
commit
94ab0722dd

+ 6 - 6
MultipleMaids/CM3D2/MultipleMaids/Plugin/MultipleMaids.Gui.cs

@@ -5236,7 +5236,7 @@ namespace CM3D2.MultipleMaids.Plugin
                             DynamicSkirtBone fieldValue =
                                     GetFieldValue<BoneHair3, DynamicSkirtBone>(maid.body0.goSlot[index2].bonehair3, "m_SkirtBone");
                             SkirtListArray[selectMaidIndex][index2] = fieldValue;
-                            SetFieldValue8<BoneHair3, DynamicSkirtBone>(maid.body0.goSlot[index2].bonehair3,
+                            SetFieldValue<BoneHair3, DynamicSkirtBone>(maid.body0.goSlot[index2].bonehair3,
                                                                         "m_SkirtBone",
                                                                          null);
                         }
@@ -5245,7 +5245,7 @@ namespace CM3D2.MultipleMaids.Plugin
                     {
                         for (int index2 = 0; index2 < maid.body0.goSlot.Count; ++index2)
                         {
-                            SetFieldValue8<BoneHair3, DynamicSkirtBone>(maid.body0.goSlot[index2].bonehair3,
+                            SetFieldValue<BoneHair3, DynamicSkirtBone>(maid.body0.goSlot[index2].bonehair3,
                                                                         "m_SkirtBone",
                                                                         SkirtListArray[selectMaidIndex][index2]);
                         }
@@ -9030,7 +9030,7 @@ namespace CM3D2.MultipleMaids.Plugin
                 mFontSize = fontSize;
                 GameObject gameObject = GameObject.Find("__GameMain__/SystemUI Root").transform.Find("MessageWindowPanel").gameObject;
                 //MessageClass messageClass = new MessageClass(gameObject, GameMain.Instance.ScriptMgr.adv_kag.MessageWindowMgr);
-                SetFieldValue2<UILabel, int>(UTY.GetChildObject(gameObject, "MessageViewer/MsgParent/Message", false)
+                SetFieldValue<UILabel, int>(UTY.GetChildObject(gameObject, "MessageViewer/MsgParent/Message", false)
                                                 .GetComponent<UILabel>(),
                                              "mFontSize",
                                              fontSize);
@@ -9065,11 +9065,11 @@ namespace CM3D2.MultipleMaids.Plugin
                 component.gameObject.SetActive(true);
                 nameComponent.gameObject.SetActive(true);
                 UTY.GetChildObject(gameObject1, "MessageViewer/MsgParent/MessageBox", false).SetActive(true);
-                SetFieldValue5<MessageClass, UILabel>(inst, "message_label_", component);
-                SetFieldValue5<MessageClass, UILabel>(inst, "name_label_", nameComponent);
+                SetFieldValue<MessageClass, UILabel>(inst, "message_label_", component);
+                SetFieldValue<MessageClass, UILabel>(inst, "name_label_", nameComponent);
 
                 component.ProcessText();
-                SetFieldValue2<UILabel, int>(component, "mFontSize", fontSize);
+                SetFieldValue<UILabel, int>(component, "mFontSize", fontSize);
 
                 inst.SetText(inName, inText, "", 0, AudioSourceMgr.Type.System);
                 inst.FinishChAnime();

+ 4 - 4
MultipleMaids/CM3D2/MultipleMaids/Plugin/MultipleMaids.Init.cs

@@ -38,7 +38,7 @@ namespace CM3D2.MultipleMaids.Plugin
                 {
                     for (int index2 = 0; index2 < stockMaid.body0.goSlot.Count; ++index2)
                     {
-                        SetFieldValue8<BoneHair3, DynamicSkirtBone>(stockMaid.body0.goSlot[index2].bonehair3,
+                        SetFieldValue<BoneHair3, DynamicSkirtBone>(stockMaid.body0.goSlot[index2].bonehair3,
                                                                     "m_SkirtBone",
                                                                     SkirtListArray[index1][index2]);
                     }
@@ -121,7 +121,7 @@ namespace CM3D2.MultipleMaids.Plugin
             MessageWindowMgr messageWindowMgr = GameMain.Instance.ScriptMgr.adv_kag.MessageWindowMgr;
             new MessageClass(gameObject, messageWindowMgr).Clear();
             messageWindowMgr.CloseMessageWindowPanel();
-            SetFieldValue2<UILabel, int>(UTY.GetChildObject(gameObject, "MessageViewer/MsgParent/Message", false).GetComponent<UILabel>(),
+            SetFieldValue<UILabel, int>(UTY.GetChildObject(gameObject, "MessageViewer/MsgParent/Message", false).GetComponent<UILabel>(),
                                          "mFontSize",
                                          fontSize);
             ikMaid = 0;
@@ -499,7 +499,7 @@ namespace CM3D2.MultipleMaids.Plugin
                 {
                     for (int index2 = 0; index2 < stockMaid.body0.goSlot.Count; ++index2)
                     {
-                        SetFieldValue8<BoneHair3, DynamicSkirtBone>(stockMaid.body0.goSlot[index2].bonehair3,
+                        SetFieldValue<BoneHair3, DynamicSkirtBone>(stockMaid.body0.goSlot[index2].bonehair3,
                                                                     "m_SkirtBone",
                                                                     SkirtListArray[index1][index2]);
                     }
@@ -638,7 +638,7 @@ namespace CM3D2.MultipleMaids.Plugin
             MessageWindowMgr messageWindowMgr = GameMain.Instance.ScriptMgr.adv_kag.MessageWindowMgr;
             new MessageClass(gameObject, messageWindowMgr).Clear();
             messageWindowMgr.CloseMessageWindowPanel();
-            SetFieldValue2<UILabel, int>(UTY.GetChildObject(gameObject, "MessageViewer/MsgParent/Message", false).GetComponent<UILabel>(),
+            SetFieldValue<UILabel, int>(UTY.GetChildObject(gameObject, "MessageViewer/MsgParent/Message", false).GetComponent<UILabel>(),
                                          "mFontSize",
                                          fontSize);
             ikMaid = 0;

+ 3 - 3
MultipleMaids/CM3D2/MultipleMaids/Plugin/MultipleMaids.Update.cs

@@ -186,10 +186,10 @@ namespace CM3D2.MultipleMaids.Plugin
                                + UTY.GetChildObject(mainCamera.gameObject, VRCamera, false).transform.rotation
                                * Vector3.forward
                                * (Input.GetAxis("Mouse ScrollWheel") * (float)(5.0 * Time.deltaTime * 2.0 * 5.0));
-                SetFieldValue3<OvrCamera, Vector3>(GameMain.Instance.OvrMgr.OvrCamera, "v", maid);
+                SetFieldValue<OvrCamera, Vector3>(GameMain.Instance.OvrMgr.OvrCamera, "v", maid);
                 Transform fieldValue = GetFieldValue<OvrCamera, Transform>(GameMain.Instance.OvrMgr.OvrCamera, "m_trBaseHead");
                 fieldValue.position = maid;
-                SetFieldValue4<OvrCamera, Transform>(GameMain.Instance.OvrMgr.OvrCamera, "m_trBaseHead", fieldValue);
+                SetFieldValue<OvrCamera, Transform>(GameMain.Instance.OvrMgr.OvrCamera, "m_trBaseHead", fieldValue);
             }
 
             if (isMekure1a || isMekure2a || isZurasia)
@@ -574,7 +574,7 @@ namespace CM3D2.MultipleMaids.Plugin
                                 fieldValue[TBody.SlotID.accSenaka] = isAccSenaka;
                             }
 
-                            SetFieldValue6<TBody, Hashtable>(maidArray[index1].body0, "m_hFoceHide", fieldValue);
+                            SetFieldValue<TBody, Hashtable>(maidArray[index1].body0, "m_hFoceHide", fieldValue);
                             maidArray[index1].body0.FixMaskFlag();
                             maidArray[index1].body0.FixVisibleFlag(false);
                         }

+ 6 - 52
MultipleMaids/CM3D2/MultipleMaids/Plugin/MultipleMaids.cs

@@ -5210,70 +5210,24 @@ namespace CM3D2.MultipleMaids.Plugin
             maidProp.boTempDut = false;
         }
 
-
-        internal static TResult GetFieldValue<T, TResult>(T inst, string name)
-        {
-            if (inst == null)
-            {
-                return default(TResult);
-            }
-
-            FieldInfo fieldInfo = GetFieldInfo<T>(name);
-            if (fieldInfo == null)
-            {
-                return default(TResult);
-            }
-
-            return (TResult)fieldInfo.GetValue(inst);
-        }
-
         internal static FieldInfo GetFieldInfo<T>(string name)
         {
             BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
             return typeof(T).GetField(name, bindingAttr);
         }
 
-        internal static void SetFieldValue<T, TResult>(T inst, string name, Maid maid)
+        internal static TValue GetFieldValue<TType, TValue>(TType instance, string field)
         {
-            GetFieldInfo<T>(name).SetValue(inst, maid);
+            FieldInfo fieldInfo = GetFieldInfo<TType>(field);
+            if (fieldInfo == null || !fieldInfo.IsStatic && instance == null) return default(TValue);
+            return (TValue)fieldInfo.GetValue(instance);
         }
 
-        internal static void SetFieldValue2<T, TResult>(T inst, string name, int maid)
+        internal static void SetFieldValue<TType, TValue>(TType instance, string name, TValue value)
         {
-            GetFieldInfo<T>(name).SetValue(inst, maid);
+            GetFieldInfo<TType>(name).SetValue(instance, value);
         }
 
-        internal static void SetFieldValue3<T, TResult>(T inst, string name, Vector3 maid)
-        {
-            GetFieldInfo<T>(name).SetValue(inst, maid);
-        }
-
-        internal static void SetFieldValue4<T, TResult>(T inst, string name, Transform maid)
-        {
-            GetFieldInfo<T>(name).SetValue(inst, maid);
-        }
-
-        internal static void SetFieldValue5<T, TResult>(T inst, string name, UILabel maid)
-        {
-            GetFieldInfo<T>(name).SetValue(inst, maid);
-        }
-
-        internal static void SetFieldValue6<T, TResult>(T inst, string name, Hashtable maid)
-        {
-            GetFieldInfo<T>(name).SetValue(inst, maid);
-        }
-
-        internal static void SetFieldValue7<T, TResult>(T inst, string name, float[] maid)
-        {
-            GetFieldInfo<T>(name).SetValue(inst, maid);
-        }
-
-        internal static void SetFieldValue8<T, TResult>(T inst, string name, DynamicSkirtBone maid)
-        {
-            GetFieldInfo<T>(name).SetValue(inst, maid);
-        }
-
-
         private void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode)
         {
             sceneLevel = scene.buildIndex;