mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
Merge branch 'dev' into android
# Conflicts: # MiraAPI/Patches/IntroCutscenePatches.cs
This commit is contained in:
commit
ac2201b3ef
5 files changed
+180
-16
No files matched your search
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
|
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
|
||||||
|
|
||||||
<VersionPrefix>0.3.0</VersionPrefix>
|
<VersionPrefix>0.3.1</VersionPrefix>
|
||||||
<VersionSuffix>dev</VersionSuffix>
|
<VersionSuffix>dev</VersionSuffix>
|
||||||
|
|
||||||
<Authors>All Of Us, XtraCube, Angxl</Authors>
|
<Authors>All Of Us, XtraCube, Angxl</Authors>
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using AmongUs.GameOptions;
|
||||||
|
using HarmonyLib;
|
||||||
|
using Il2CppSystem.Collections.Generic;
|
||||||
|
using MiraAPI.Roles;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace MiraAPI.Patches;
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(DetectiveNotesMinigame), nameof(DetectiveNotesMinigame.OpenBodyPopup))]
|
||||||
|
public static class DetectiveNotesMinigamePatch
|
||||||
|
{
|
||||||
|
public static void Prefix(DetectiveNotesMinigame __instance, bool active)
|
||||||
|
{
|
||||||
|
__instance.impostorTypePopup.SetActive(active);
|
||||||
|
if (!active)
|
||||||
|
{
|
||||||
|
ControllerManager.Instance.CloseOverlayMenu(__instance.ImpostorOverlay);
|
||||||
|
ControllerManager.Instance.SetUpSelectables(ControllerManager.Instance.CurrentUiState, __instance.ControllerSelectable[0], __instance.ControllerSelectable);
|
||||||
|
ControllerManager.Instance.SetCurrentSelected(__instance.ControllerSelectable[2]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (__instance.impostorButton != null)
|
||||||
|
{
|
||||||
|
ControllerManager.Instance.OpenOverlayMenu(__instance.ImpostorOverlay, null, __instance.ImpostorIconControllerSelectables[0], __instance.ImpostorIconControllerSelectables, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
__instance.impostorButton = new List<GameObject>();
|
||||||
|
int num = 0;
|
||||||
|
var allRoles = DestroyableSingleton<RoleManager>.Instance.AllRoles;
|
||||||
|
var customRoles = CustomRoleManager.CustomRoleBehaviours;
|
||||||
|
foreach (var role in allRoles)
|
||||||
|
{
|
||||||
|
if (role.TeamType != RoleTeamTypes.Impostor || role.Role == RoleTypes.ImpostorGhost || customRoles.Contains(role) )
|
||||||
|
continue;
|
||||||
|
GameObject gameObject = Object.Instantiate<GameObject>(__instance.impostorTypePrefab, __instance.impostorTypeParent);
|
||||||
|
__instance.impostorButton.Add(gameObject);
|
||||||
|
gameObject.GetComponent<DetectiveImpostorType>().Initialize(__instance, role);
|
||||||
|
num++;
|
||||||
|
__instance.ImpostorIconControllerSelectables.Add(gameObject.GetComponent<PassiveButton>());
|
||||||
|
}
|
||||||
|
ControllerManager.Instance.OpenOverlayMenu(__instance.ImpostorOverlay, null, __instance.ImpostorIconControllerSelectables[0], __instance.ImpostorIconControllerSelectables, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
using HarmonyLib;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using HarmonyLib;
|
||||||
|
using Il2CppInterop.Runtime.InteropTypes;
|
||||||
using MiraAPI.Events;
|
using MiraAPI.Events;
|
||||||
using MiraAPI.Events.Vanilla.Gameplay;
|
using MiraAPI.Events.Vanilla.Gameplay;
|
||||||
using MiraAPI.Roles;
|
using MiraAPI.Roles;
|
||||||
using MiraAPI.Utilities;
|
using MiraAPI.Utilities;
|
||||||
|
using Reactor.Utilities;
|
||||||
|
|
||||||
namespace MiraAPI.Patches;
|
namespace MiraAPI.Patches;
|
||||||
|
|
||||||
@@ -29,15 +33,30 @@ public static class IntroCutscenePatches
|
|||||||
MiraEventManager.InvokeEvent(@event);
|
MiraEventManager.InvokeEvent(@event);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPostfix]
|
[HarmonyPatch]
|
||||||
[HarmonyPatch(typeof(IntroCutscene._ShowRole_d__40), nameof(IntroCutscene._ShowRole_d__40.MoveNext))]
|
public static class IntroCutsceneShowRolePatch
|
||||||
[HarmonyPriority(Priority.Last)]
|
|
||||||
public static void ShowRolePatch(IntroCutscene._ShowRole_d__40 __instance)
|
|
||||||
{
|
{
|
||||||
var realInstance = __instance.__4__this;
|
public static MethodBase TargetMethod()
|
||||||
var @event = new IntroRoleRevealEvent(realInstance);
|
{
|
||||||
|
return Helpers.GetStateMachineMoveNext<IntroCutscene>("ShowRole")!;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Postfix(Il2CppObjectBase __instance)
|
||||||
|
{
|
||||||
|
var wrapper = new StateMachineWrapper<IntroCutscene>(__instance);
|
||||||
|
// run before the first yield
|
||||||
|
if (wrapper.GetState() != 1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var introCutscene = wrapper.Instance;
|
||||||
|
|
||||||
|
Logger<MiraApiPlugin>.Info("IntroCutscene ShowRole reached");
|
||||||
|
var @event = new IntroRoleRevealEvent(introCutscene);
|
||||||
MiraEventManager.InvokeEvent(@event);
|
MiraEventManager.InvokeEvent(@event);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
[HarmonyPatch(nameof(IntroCutscene.BeginImpostor))]
|
[HarmonyPatch(nameof(IntroCutscene.BeginImpostor))]
|
||||||
@@ -66,16 +85,48 @@ public static class IntroCutscenePatches
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPostfix]
|
[HarmonyPatch]
|
||||||
[HarmonyPatch(typeof(IntroCutscene._CoBegin_d__34), nameof(IntroCutscene._CoBegin_d__34.MoveNext))]
|
public static class IntroCutsceneDestroyPatch
|
||||||
public static void GameBeginPatch(IntroCutscene._CoBegin_d__34 __instance)
|
|
||||||
{
|
{
|
||||||
if (__instance.__1__state != -1)
|
private static bool _usedFallback;
|
||||||
|
|
||||||
|
public static MethodBase TargetMethod()
|
||||||
|
{
|
||||||
|
var onDestroy = AccessTools.Method(typeof(IntroCutscene), "OnDestroy");
|
||||||
|
if (onDestroy != null)
|
||||||
|
{
|
||||||
|
_usedFallback = false;
|
||||||
|
Logger<MiraApiPlugin>.Info("Using OnDestroy for IntroCutsceneDestroyPatch");
|
||||||
|
return onDestroy;
|
||||||
|
}
|
||||||
|
|
||||||
|
_usedFallback = true;
|
||||||
|
return Helpers.GetStateMachineMoveNext<IntroCutscene>("CoBegin")!;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Postfix(Il2CppObjectBase __instance)
|
||||||
|
{
|
||||||
|
IntroCutscene introCutscene;
|
||||||
|
|
||||||
|
if (_usedFallback)
|
||||||
|
{
|
||||||
|
var wrapper = new StateMachineWrapper<IntroCutscene>(__instance);
|
||||||
|
// run after the final yield
|
||||||
|
if (wrapper.GetState() != -1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
introCutscene = wrapper.Instance;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
introCutscene = __instance.Cast<IntroCutscene>();
|
||||||
|
}
|
||||||
|
|
||||||
MiraEventManager.InvokeEvent(new IntroEndEvent(__instance.__4__this));
|
|
||||||
|
Logger<MiraApiPlugin>.Info("IntroCutscene ended");
|
||||||
|
|
||||||
|
MiraEventManager.InvokeEvent(new IntroEndEvent(introCutscene));
|
||||||
|
|
||||||
var @event = new BeforeRoundStartEvent(true);
|
var @event = new BeforeRoundStartEvent(true);
|
||||||
MiraEventManager.InvokeEvent(@event);
|
MiraEventManager.InvokeEvent(@event);
|
||||||
@@ -84,3 +135,4 @@ public static class IntroCutscenePatches
|
|||||||
MiraEventManager.InvokeEvent(new RoundStartEvent(true));
|
MiraEventManager.InvokeEvent(new RoundStartEvent(true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
using System;
|
using System.Collections;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using HarmonyLib;
|
||||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||||
using MiraAPI.Keybinds;
|
|
||||||
using MiraAPI.Roles;
|
using MiraAPI.Roles;
|
||||||
using MiraAPI.Utilities.Assets;
|
using MiraAPI.Utilities.Assets;
|
||||||
|
using Reactor.Utilities;
|
||||||
using Rewired;
|
using Rewired;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using MethodBase = System.Reflection.MethodBase;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
namespace MiraAPI.Utilities;
|
namespace MiraAPI.Utilities;
|
||||||
@@ -38,6 +39,31 @@ public static class Helpers
|
|||||||
return keybindIcon;
|
return keybindIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MethodBase? GetStateMachineMoveNext<T>(string methodName)
|
||||||
|
{
|
||||||
|
var typeName = typeof(T).FullName;
|
||||||
|
var showRoleStateMachine =
|
||||||
|
typeof(T)
|
||||||
|
.GetNestedTypes()
|
||||||
|
.FirstOrDefault(x=>x.Name.Contains(methodName));
|
||||||
|
|
||||||
|
if (showRoleStateMachine == null)
|
||||||
|
{
|
||||||
|
Logger<MiraApiPlugin>.Error($"Failed to find {methodName} state machine for {typeName}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var moveNext = AccessTools.Method(showRoleStateMachine, "MoveNext");
|
||||||
|
if (moveNext == null)
|
||||||
|
{
|
||||||
|
Logger<MiraApiPlugin>.Error($"Failed to find MoveNext method for {typeName}.{methodName}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger<MiraApiPlugin>.Info($"Found {methodName}.MoveNext");
|
||||||
|
return moveNext;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a draggable scroller. Add items into the scroller.Inner transform. This does not automatically position children.
|
/// Creates a draggable scroller. Add items into the scroller.Inner transform. This does not automatically position children.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using HarmonyLib;
|
||||||
|
using Il2CppInterop.Runtime.InteropTypes;
|
||||||
|
|
||||||
|
namespace MiraAPI.Utilities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A wrapper for state machine objects to access their parent instance and state.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of the parent class that owns the state machine.</typeparam>
|
||||||
|
public class StateMachineWrapper<T> where T : Il2CppObjectBase
|
||||||
|
{
|
||||||
|
private readonly Il2CppObjectBase _stateMachine;
|
||||||
|
private readonly PropertyInfo _thisProperty;
|
||||||
|
private readonly PropertyInfo _stateProperty;
|
||||||
|
|
||||||
|
private T? _parentInstance;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the instance of the parent class that owns the state machine.
|
||||||
|
/// </summary>
|
||||||
|
public T Instance => _parentInstance ??= (T)_thisProperty.GetValue(_stateMachine)!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="StateMachineWrapper{T}"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="stateMachine">The state machine instance to wrap.</param>
|
||||||
|
public StateMachineWrapper(Il2CppObjectBase stateMachine)
|
||||||
|
{
|
||||||
|
_stateMachine = stateMachine;
|
||||||
|
|
||||||
|
var type = _stateMachine.GetType();
|
||||||
|
_thisProperty = AccessTools.Property(type, "__4__this");
|
||||||
|
_stateProperty = AccessTools.Property(type, "__1__state");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the current state of the state machine.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The current state as an integer.</returns>
|
||||||
|
public int GetState() => (int)_stateProperty.GetValue(_stateMachine)!;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user