Skip to content

Commit cc5036f

Browse files
committed
GetValue and SetValue now works for fields on parent classes
1 parent 14fa2d1 commit cc5036f

File tree

5 files changed

+32
-13
lines changed

5 files changed

+32
-13
lines changed

OWML.Events/TypeExtensions.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,23 @@ public static class TypeExtensions
1010

1111
public static MethodInfo GetAnyMethod(this Type type, string name)
1212
{
13-
return type.GetMethod(name, Flags);
13+
return type.GetMethod(name, Flags) ??
14+
type.BaseType?.GetMethod(name, Flags) ??
15+
type.BaseType?.BaseType?.GetMethod(name, Flags);
1416
}
1517

1618
public static PropertyInfo GetAnyProperty(this Type type, string name)
1719
{
18-
return type.GetProperty(name, Flags);
20+
return type.GetProperty(name, Flags) ??
21+
type.BaseType?.GetProperty(name, Flags) ??
22+
type.BaseType?.BaseType?.GetProperty(name, Flags);
1923
}
2024

2125
public static FieldInfo GetAnyField(this Type type, string name)
2226
{
23-
return type.GetField(name, Flags);
27+
return type.GetField(name, Flags) ??
28+
type.BaseType?.GetField(name, Flags) ??
29+
type.BaseType?.BaseType?.GetField(name, Flags);
2430
}
2531

2632
public static T GetValue<T>(this object obj, string name)

OWML.Launcher/App.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace OWML.Launcher
1111
{
1212
public class App
1313
{
14-
private const string OWMLVersion = "0.1.6";
14+
private const string OWMLVersion = "0.1.7";
1515

1616
private readonly string[] _filesToCopy = { "UnityEngine.CoreModule.dll", "Assembly-CSharp.dll" };
1717

OWML.SampleMods/OWML.EnableDebugMode/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"name": "EnableDebugMode",
55
"uniqueName": "Alek.EnableDebugMode",
66
"version": "0.1",
7-
"owmlVersion": "0.1.6",
7+
"owmlVersion": "0.1.7",
88
"enabled": true
99
}

OWML.SampleMods/OWML.TestMod/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"name": "TestMod",
55
"uniqueName": "Alek.TestMod",
66
"version": "0.1",
7-
"owmlVersion": "0.1.6",
7+
"owmlVersion": "0.1.7",
88
"enabled": false
99
}

Readme.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Note: ModHelper can not be used in Awake, it's not initialized at that time.
7676

7777
### Events
7878

79-
Start in your ModBehaviour will be called when the game starts (at the title menu), which is usually too early for what you want to do. The mod helper contains events we can use to know when certain behaviours start. Here we add an event for when Flashlight has loaded, which is after the player has "woken up":
79+
Start in your ModBehaviour will be called when the game starts (at the title menu), which is usually too early for what you want to do. The mod helper contains events we can use to know when certain things happen. Here we add an event for when Flashlight has started, which is after the player has "woken up":
8080

8181
~~~~
8282
private void Start()
@@ -97,12 +97,14 @@ private void OnEvent(MonoBehaviour behaviour, Events ev)
9797

9898
### Tips and tricks
9999

100+
#### Multiple MonoBehaviours
101+
100102
Your mod can contain more MonoBehaviors which can be added dynamically:
101103
~~~~
102104
AddComponent<SomeBehaviour>();
103105
~~~~
104106

105-
Listen for inputs:
107+
#### Listen for inputs
106108
~~~~
107109
private void Update()
108110
{
@@ -113,19 +115,30 @@ private void Update()
113115
}
114116
~~~~
115117

116-
Decompile the game with [dnSpy](https://github.com/0xd4d/dnSpy). Open {gamePath}\OuterWilds_Data\Managed\Assembly-CSharp.dll in dnSpy to learn how the game works and find what you want to change.
118+
#### Decompile the game
119+
120+
Use [dnSpy](https://github.com/0xd4d/dnSpy) to browse the game code and learn how the game ticks. Open {gamePath}\OuterWilds_Data\Managed\Assembly-CSharp.dll in dnSpy.
121+
122+
#### Reflection
117123

118124
Change private variables with [reflection](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/reflection). Example:
119125
~~~~
120126
typeof(GUIMode).GetAnyField("_renderMode").SetValue(null, _renderValue);
121127
~~~~
122128

123-
Modify existing game methods with [Harmony](https://github.com/pardeike/Harmony). The mod helper contains a wrapper for Harmony, making some of the functionality easy to use. See the source code of HarmonyHelper and ModEvents. As an example, here we remove the contents of DebugInputManagers Awake method which makes sure the debug mode isn't disabled:
129+
OWML.Events.dll contains extension methods for easy reflection. Get and set private variables like this:
130+
124131
~~~~
125-
ModHelper.HarmonyHelper.EmptyMethod<DebugInputManager>("Awake");
132+
var foo = behaviour.GetValue<string>("_foo");
133+
behaviour.SetValue<string>("_bar", foo);
126134
~~~~
127135

128-
If you develop new functionality using Harmony, please consider working with me to expand the mod helper classes, to aid other modders as well.
136+
#### Patch game methods
137+
138+
Modify existing game methods with [Harmony](https://github.com/pardeike/Harmony). The mod helper contains a wrapper for Harmony, making some of the functionality easy to use. See the source code of HarmonyHelper and ModEvents. Here we remove the contents of DebugInputManagers Awake method which makes sure the debug mode isn't disabled:
139+
~~~~
140+
ModHelper.HarmonyHelper.EmptyMethod<DebugInputManager>("Awake");
141+
~~~~
129142

130143
### Manifest
131144

@@ -138,7 +151,7 @@ Add a manifest file called manifest.json. Example:
138151
"name": "EnableDebugMode",
139152
"uniqueName": "Alek.EnableDebugMode",
140153
"version": "0.1",
141-
"owmlVersion": "0.1.6",
154+
"owmlVersion": "0.1.7",
142155
"enabled": true
143156
}
144157
~~~~

0 commit comments

Comments
 (0)