-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatchingExtension.cs
More file actions
63 lines (51 loc) · 1.58 KB
/
PatchingExtension.cs
File metadata and controls
63 lines (51 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System.Collections.Generic;
using HarmonyLib;
using UnityEngine;
namespace SandSpace
{
public static class PatchingExtension
{
public static void SetPrivateFieldValue (object obj, string fieldName, object value)
{
AccessTools.Field (obj.GetType (), fieldName).SetValue (obj, value);
}
public static TResult GetPrivateFieldValue<TResult> (object obj, string fieldName)
{
return (TResult) AccessTools.Field (obj.GetType (), fieldName).GetValue (obj);
}
public static void SetPrivatePropertyValue (object obj, string propName, object value)
{
var property = AccessTools.Property (obj.GetType (), propName);
if (!property.CanWrite)
return;
property.SetValue (obj, value, null);
}
public static TResult GetPrivatePropertyValue<TResult> (object obj, string propName)
{
var property = AccessTools.Property (obj.GetType (), propName);
if (!property.CanRead)
return default;
return (TResult) property.GetValue (obj, null);
}
public static List<string> GetGameObjectComponents (GameObject gameObject)
{
var result = new List<string> ();
foreach (var components in gameObject.GetComponents<object> ())
{
result.Add ($"{gameObject.name}: ({components.GetType ()}) component");
}
return result;
}
}
}
//-------------------------------------------------------------------------
//------------------------- TEST -----------------------------------
//-------------------------------------------------------------------------
//__instance
//__result
//__state
//___fields
//__args
// SymbolExtensions
// Transpilers
// AccessTools