mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-03 10:29:22 +00:00
99 lines
No EOL
3.1 KiB
C#
99 lines
No EOL
3.1 KiB
C#
using ABI_RC.Core.Player;
|
|
using ABI_RC.Systems.IK;
|
|
using System;
|
|
using System.Reflection;
|
|
|
|
namespace ml_pmc
|
|
{
|
|
static class GameEvents
|
|
{
|
|
internal class GameEvent
|
|
{
|
|
event Action m_action;
|
|
public void AddListener(Action p_listener) => m_action += p_listener;
|
|
public void RemoveListener(Action p_listener) => m_action -= p_listener;
|
|
public void Invoke() => m_action?.Invoke();
|
|
}
|
|
|
|
public static readonly GameEvent OnAvatarSetup = new GameEvent();
|
|
public static readonly GameEvent OnAvatarClear = new GameEvent();
|
|
public static readonly GameEvent OnAvatarPreReuse = new GameEvent();
|
|
public static readonly GameEvent OnAvatarPostReuse = new GameEvent();
|
|
|
|
internal static void Init(HarmonyLib.Harmony p_instance)
|
|
{
|
|
try
|
|
{
|
|
p_instance.Patch(
|
|
typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.ClearAvatar)),
|
|
null,
|
|
new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnAvatarClear_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
|
|
);
|
|
|
|
p_instance.Patch(
|
|
typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar)),
|
|
null,
|
|
new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnSetupAvatar_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
|
|
);
|
|
|
|
p_instance.Patch(
|
|
typeof(IKSystem).GetMethod(nameof(IKSystem.ReinitializeAvatar), BindingFlags.Instance | BindingFlags.Public),
|
|
new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnAvatarReinitialize_Prefix), BindingFlags.Static | BindingFlags.NonPublic)),
|
|
new HarmonyLib.HarmonyMethod(typeof(GameEvents).GetMethod(nameof(OnAvatarReinitialize_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
|
|
);
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
MelonLoader.MelonLogger.Error(e);
|
|
}
|
|
}
|
|
|
|
static void OnAvatarClear_Postfix()
|
|
{
|
|
try
|
|
{
|
|
OnAvatarClear.Invoke();
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
MelonLoader.MelonLogger.Error(e);
|
|
}
|
|
}
|
|
|
|
static void OnSetupAvatar_Postfix()
|
|
{
|
|
try
|
|
{
|
|
OnAvatarSetup.Invoke();
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
MelonLoader.MelonLogger.Error(e);
|
|
}
|
|
}
|
|
|
|
static void OnAvatarReinitialize_Prefix()
|
|
{
|
|
try
|
|
{
|
|
OnAvatarPreReuse.Invoke();
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
MelonLoader.MelonLogger.Error(e);
|
|
}
|
|
}
|
|
|
|
static void OnAvatarReinitialize_Postfix()
|
|
{
|
|
try
|
|
{
|
|
OnAvatarPostReuse.Invoke();
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
MelonLoader.MelonLogger.Error(e);
|
|
}
|
|
}
|
|
}
|
|
} |