using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Keybinds;
using LethalCompanyInputUtils.Api;
using TDP.DanceOff.Patch;
using Tools;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("DanceOff")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DanceOff")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9f8803c8-efb4-47f7-8eeb-e93eac831f94")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Keybinds
{
public class Keybinds : LcInputActions
{
public static Keybinds instance = new Keybinds();
[InputAction("<Keyboard>/F3", Name = "Emote3")]
public InputAction Emote3 { get; set; }
[InputAction("<Keyboard>/F4", Name = "Emote4")]
public InputAction Emote4 { get; set; }
[InputAction("<Keyboard>/F5", Name = "Emote5")]
public InputAction Emote5 { get; set; }
[InputAction("<Keyboard>/F6", Name = "Emote6")]
public InputAction Emote6 { get; set; }
[InputAction("<Keyboard>/5", Name = "Emote7")]
public InputAction Emote7 { get; set; }
[InputAction("<Keyboard>/6", Name = "Emote8")]
public InputAction Emote8 { get; set; }
[InputAction("", Name = "CustomEmote9")]
public InputAction Emote9 { get; set; }
[InputAction("", Name = "CustomEmote10")]
public InputAction Emote10 { get; set; }
[InputAction("", Name = "CustomEmote11")]
public InputAction Emote11 { get; set; }
}
}
namespace Tools
{
public class Reflection
{
public static object GetInstanceField(Type type, object instance, string fieldName)
{
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
FieldInfo field = type.GetField(fieldName, bindingAttr);
return field.GetValue(instance);
}
public static object CallMethod(object instance, string methodName, params object[] args)
{
MethodInfo method = instance.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic);
if (method != null)
{
return method.Invoke(instance, args);
}
return null;
}
}
}
namespace TDP.DanceOff
{
[BepInPlugin("TDP.DanceOff", "Dance Off", "1.0.8")]
public class ModBase : BaseUnityPlugin
{
private const string modGUID = "TDP.DanceOff";
private const string modName = "Dance Off";
private const string modVersion = "1.0.8";
private Harmony harmony;
internal static ModBase instance;
internal ManualLogSource mls;
private void Awake()
{
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Expected O, but got Unknown
if ((Object)(object)instance == (Object)null)
{
instance = this;
}
else
{
Object.Destroy((Object)(object)this);
}
EmotePatch.animationsBundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Animations/animationsbundle"));
EmotePatch.animatorBundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Animations/animatorbundle"));
EmotePatch.local = EmotePatch.animatorBundle.LoadAsset<RuntimeAnimatorController>("DanceOffMetarigLocal.controller");
EmotePatch.others = EmotePatch.animatorBundle.LoadAsset<RuntimeAnimatorController>("DanceOffMetarigOthers.controller");
harmony = new Harmony("TDP.DanceOff");
harmony.PatchAll(typeof(EmotePatch));
mls = Logger.CreateLogSource("TDP.DanceOff");
mls.LogInfo((object)"Dance Off loaded.");
}
}
}
namespace TDP.DanceOff.Patch
{
internal class EmotePatch
{
public static AssetBundle animationsBundle;
public static AssetBundle animatorBundle;
private static CallbackContext context;
public static RuntimeAnimatorController local;
public static RuntimeAnimatorController others;
private static int currentEmoteID;
[HarmonyPatch(typeof(PlayerControllerB), "Start")]
[HarmonyPostfix]
private static void StartPostfix(PlayerControllerB __instance)
{
global::Keybinds.Keybinds.instance.Emote3.performed += delegate
{
TryEmote(needsEmptyHands: true, 3, __instance);
};
global::Keybinds.Keybinds.instance.Emote4.performed += delegate
{
TryEmote(needsEmptyHands: true, 4, __instance);
};
global::Keybinds.Keybinds.instance.Emote5.performed += delegate
{
TryEmote(needsEmptyHands: true, 5, __instance);
};
global::Keybinds.Keybinds.instance.Emote6.performed += delegate
{
TryEmote(needsEmptyHands: true, 6, __instance);
};
global::Keybinds.Keybinds.instance.Emote7.performed += delegate
{
TryEmote(needsEmptyHands: true, 7, __instance);
};
global::Keybinds.Keybinds.instance.Emote8.performed += delegate
{
TryEmote(needsEmptyHands: true, 8, __instance);
};
global::Keybinds.Keybinds.instance.Emote9.performed += delegate
{
TryEmote(needsEmptyHands: true, 9, __instance);
};
global::Keybinds.Keybinds.instance.Emote10.performed += delegate
{
TryEmote(needsEmptyHands: true, 10, __instance);
};
global::Keybinds.Keybinds.instance.Emote11.performed += delegate
{
TryEmote(needsEmptyHands: true, 11, __instance);
};
}
[HarmonyPatch(typeof(PlayerControllerB), "Update")]
[HarmonyPostfix]
private static void UpdatePostfix(PlayerControllerB __instance)
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
//IL_0047: Expected O, but got Unknown
if (!__instance.isPlayerControlled || !((NetworkBehaviour)__instance).IsOwner)
{
__instance.playerBodyAnimator.runtimeAnimatorController = others;
return;
}
if ((Object)__instance.playerBodyAnimator != (Object)local)
{
__instance.playerBodyAnimator.runtimeAnimatorController = local;
}
currentEmoteID = __instance.playerBodyAnimator.GetInteger("emoteNumber");
}
private static void TryEmote(bool needsEmptyHands, int emoteID, PlayerControllerB player)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
if ((!player.isHoldingObject || !needsEmptyHands) && (!player.performingEmote || currentEmoteID != emoteID))
{
player.PerformEmote(context, emoteID);
}
}
[HarmonyPatch(typeof(PlayerControllerB), "PerformEmote")]
[HarmonyPrefix]
private static void PerformEmotePrefix(ref CallbackContext context, int emoteID, PlayerControllerB __instance)
{
if ((emoteID >= 3 || ((CallbackContext)(ref context)).performed) && ((((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerControlled && (!((NetworkBehaviour)__instance).IsServer || __instance.isHostPlayerObject)) || __instance.isTestingPlayer) && (bool)Reflection.CallMethod(__instance, "CheckConditionsForEmote") && !(__instance.timeSinceStartingEmote < 0.5f))
{
__instance.timeSinceStartingEmote = 0f;
__instance.performingEmote = true;
__instance.playerBodyAnimator.SetInteger("emoteNumber", emoteID);
__instance.StartPerformingEmoteServerRpc();
}
}
}
}