mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
Add methods for StateMachineWrapper
This commit is contained in:
1 parent
d89bce6956
commit
00a60bb7ad
2 files changed
+17
-2
No files matched your search
@@ -8,7 +8,7 @@
|
||||
|
||||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
|
||||
|
||||
<VersionPrefix>0.3.8</VersionPrefix>
|
||||
<VersionPrefix>0.3.9</VersionPrefix>
|
||||
<VersionSuffix>dev</VersionSuffix>
|
||||
|
||||
<Authors>All Of Us, XtraCube, Angxl</Authors>
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes;
|
||||
using Object = Il2CppSystem.Object;
|
||||
|
||||
namespace MiraAPI.Utilities;
|
||||
|
||||
@@ -17,6 +18,7 @@ public class StateMachineWrapper<T> where T : Il2CppObjectBase
|
||||
// normally it is fields, but IL2CPP turns them into properties
|
||||
private readonly PropertyInfo _thisProperty;
|
||||
private readonly PropertyInfo _stateProperty;
|
||||
private readonly PropertyInfo _currentProperty;
|
||||
private readonly Dictionary<string, PropertyInfo> _propertyCache;
|
||||
|
||||
private T? _parentInstance;
|
||||
@@ -37,8 +39,9 @@ public class StateMachineWrapper<T> where T : Il2CppObjectBase
|
||||
var type = _stateMachine.GetType();
|
||||
_thisProperty = AccessTools.Property(type, "__4__this");
|
||||
_stateProperty = AccessTools.Property(type, "__1__state");
|
||||
_currentProperty = AccessTools.Property(type, "__2__current");
|
||||
|
||||
if (_thisProperty == null || _stateProperty == null)
|
||||
if (_thisProperty == null || _stateProperty == null || _currentProperty == null)
|
||||
{
|
||||
throw new MissingMemberException($"Could not find required properties in type '{type}'.");
|
||||
}
|
||||
@@ -52,6 +55,18 @@ public class StateMachineWrapper<T> where T : Il2CppObjectBase
|
||||
/// <returns>The current state as an integer.</returns>
|
||||
public int GetState() => (int)_stateProperty.GetValue(_stateMachine)!;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the current state of the state machine.
|
||||
/// </summary>
|
||||
/// <param name="newState">The new state to use.</param>
|
||||
public void SetState(int newState) => _stateProperty.SetValue(_stateMachine, newState);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the newest yield return of the state machine.
|
||||
/// </summary>
|
||||
/// <param name="newReturn">The new return to use.</param>
|
||||
public void SetRecentReturn(Object newReturn) => _currentProperty.SetValue(_stateMachine, newReturn);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a parameter from the state machine by its name.
|
||||
/// </summary>
|
||||
|
||||
Reference in new issue
Block a user