mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
Merge branch 'dev' into android
# Conflicts: # MiraAPI/Patches/IntroCutscenePatches.cs
This commit is contained in:
commit
ac2201b3ef
5 files changed
+186
-22
No files matched your search
@@ -8,7 +8,7 @@
|
||||
|
||||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
|
||||
|
||||
<VersionPrefix>0.3.0</VersionPrefix>
|
||||
<VersionPrefix>0.3.1</VersionPrefix>
|
||||
<VersionSuffix>dev</VersionSuffix>
|
||||
|
||||
<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.Vanilla.Gameplay;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities;
|
||||
|
||||
namespace MiraAPI.Patches;
|
||||
|
||||
@@ -29,14 +33,29 @@ public static class IntroCutscenePatches
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(IntroCutscene._ShowRole_d__40), nameof(IntroCutscene._ShowRole_d__40.MoveNext))]
|
||||
[HarmonyPriority(Priority.Last)]
|
||||
public static void ShowRolePatch(IntroCutscene._ShowRole_d__40 __instance)
|
||||
[HarmonyPatch]
|
||||
public static class IntroCutsceneShowRolePatch
|
||||
{
|
||||
var realInstance = __instance.__4__this;
|
||||
var @event = new IntroRoleRevealEvent(realInstance);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
public static MethodBase TargetMethod()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
@@ -66,21 +85,54 @@ public static class IntroCutscenePatches
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(IntroCutscene._CoBegin_d__34), nameof(IntroCutscene._CoBegin_d__34.MoveNext))]
|
||||
public static void GameBeginPatch(IntroCutscene._CoBegin_d__34 __instance)
|
||||
[HarmonyPatch]
|
||||
public static class IntroCutsceneDestroyPatch
|
||||
{
|
||||
if (__instance.__1__state != -1)
|
||||
private static bool _usedFallback;
|
||||
|
||||
public static MethodBase TargetMethod()
|
||||
{
|
||||
return;
|
||||
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")!;
|
||||
}
|
||||
|
||||
MiraEventManager.InvokeEvent(new IntroEndEvent(__instance.__4__this));
|
||||
public static void Postfix(Il2CppObjectBase __instance)
|
||||
{
|
||||
IntroCutscene introCutscene;
|
||||
|
||||
var @event = new BeforeRoundStartEvent(true);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
if (_usedFallback)
|
||||
{
|
||||
var wrapper = new StateMachineWrapper<IntroCutscene>(__instance);
|
||||
// run after the final yield
|
||||
if (wrapper.GetState() != -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
introCutscene = wrapper.Instance;
|
||||
}
|
||||
else
|
||||
{
|
||||
introCutscene = __instance.Cast<IntroCutscene>();
|
||||
}
|
||||
|
||||
if (@event.IsCancelled) return;
|
||||
MiraEventManager.InvokeEvent(new RoundStartEvent(true));
|
||||
|
||||
Logger<MiraApiPlugin>.Info("IntroCutscene ended");
|
||||
|
||||
MiraEventManager.InvokeEvent(new IntroEndEvent(introCutscene));
|
||||
|
||||
var @event = new BeforeRoundStartEvent(true);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
|
||||
if (@event.IsCancelled) return;
|
||||
MiraEventManager.InvokeEvent(new RoundStartEvent(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,16 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using MiraAPI.Keybinds;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities;
|
||||
using Rewired;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using MethodBase = System.Reflection.MethodBase;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.Utilities;
|
||||
@@ -38,6 +39,31 @@ public static class Helpers
|
||||
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>
|
||||
/// Creates a draggable scroller. Add items into the scroller.Inner transform. This does not automatically position children.
|
||||
/// </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