using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("AIToDummy")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AIToDummy")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("bcdfe256-4804-48b8-92eb-dd0896eae1c5")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AIToDummyMod;
[BepInPlugin("com.morsecodeguy.aitodummy", "AIToDummy", "1.1.0")]
public class AIToDummy : BaseUnityPlugin
{
private bool isDummyMode = false;
private bool showMenu = false;
private List<GameObject> aiCharacters = new List<GameObject>();
private GameObject playerHealthObject;
private ConfigEntry<KeyCode> toggleMenuKey;
private void Start()
{
toggleMenuKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybinds", "Toggle Menu Key", (KeyCode)282, "Key to toggle the AIToDummy menu");
((MonoBehaviour)this).StartCoroutine(MonitorAICharacters());
}
private void Update()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
if (Input.GetKeyDown(toggleMenuKey.Value))
{
showMenu = !showMenu;
}
}
private void OnGUI()
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
if (showMenu && aiCharacters.Count > 0 && (Object)(object)playerHealthObject != (Object)null)
{
int width = Screen.width;
int num = 160;
int num2 = 30;
Rect val = default(Rect);
((Rect)(ref val))..ctor((float)(width / 2 - num / 2), 20f, (float)num, (float)num2);
if (GUI.Button(val, isDummyMode ? "Disable Dummy Mode" : "Enable Dummy Mode"))
{
ToggleDummyMode();
}
Rect val2 = default(Rect);
((Rect)(ref val2))..ctor((float)(width / 2 - num / 2), 60f, (float)num, (float)num2);
if (GUI.Button(val2, "Remove Weapon"))
{
RemoveWeapon();
}
Rect val3 = default(Rect);
((Rect)(ref val3))..ctor((float)(width / 2 - num / 2), 100f, (float)num, (float)num2);
if (GUI.Button(val3, "Remove Arms"))
{
RemoveArms();
}
Rect val4 = default(Rect);
((Rect)(ref val4))..ctor((float)(width / 2 - num / 2), 140f, (float)num, (float)num2);
if (GUI.Button(val4, "Remove Legs"))
{
RemoveLegs();
}
}
}
private void ToggleDummyMode()
{
isDummyMode = !isDummyMode;
if (isDummyMode)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Dummy Mode Enabled: Disabling AI components.");
}
else
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Dummy Mode Disabled: Re-enabling AI components.");
}
UpdateAIComponents();
}
private void UpdateAIComponents()
{
foreach (GameObject aiCharacter in aiCharacters)
{
if (!((Object)(object)aiCharacter != (Object)null))
{
continue;
}
Component component = aiCharacter.GetComponent("PlayerInputAIManager");
Transform val = aiCharacter.transform.Find("PlayerModelAnimation");
if (!((Object)(object)component != (Object)null) || !((Object)(object)val != (Object)null))
{
continue;
}
Component component2 = ((Component)val).GetComponent("PlayerAnimator");
if (isDummyMode)
{
if ((Object)(object)component != (Object)null)
{
((Behaviour)((component is Behaviour) ? component : null)).enabled = false;
}
if ((Object)(object)component2 != (Object)null)
{
((Behaviour)((component2 is Behaviour) ? component2 : null)).enabled = false;
}
}
else
{
if ((Object)(object)component != (Object)null)
{
((Behaviour)((component is Behaviour) ? component : null)).enabled = true;
}
if ((Object)(object)component2 != (Object)null)
{
((Behaviour)((component2 is Behaviour) ? component2 : null)).enabled = true;
}
}
}
}
private void RemoveWeapon()
{
string[] names = new string[5] { "Bardiche(Clone)", "BeardedAxe(Clone)", "Shield(Clone)", "ShortSword(Clone)", "Longsword(Clone)" };
foreach (GameObject aiCharacter in aiCharacters)
{
if ((Object)(object)aiCharacter != (Object)null)
{
DisableChildrenByNames(aiCharacter.transform, names);
}
}
}
private void RemoveArms()
{
string[] names = new string[2] { "SCAPULA_RIGHT", "SCAPULA_LEFT" };
foreach (GameObject aiCharacter in aiCharacters)
{
if ((Object)(object)aiCharacter != (Object)null)
{
DisableChildrenByNames(aiCharacter.transform, names);
}
}
}
private void RemoveLegs()
{
string[] names = new string[2] { "HIP_JOINT_LEFT", "HIP_JOINT_RIGHT" };
foreach (GameObject aiCharacter in aiCharacters)
{
if ((Object)(object)aiCharacter != (Object)null)
{
DisableChildrenByNames(aiCharacter.transform, names);
}
}
}
private void DisableChildrenByNames(Transform parent, string[] names)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
foreach (Transform item in parent)
{
Transform child = item;
if (Array.Exists(names, (string element) => element == ((Object)child).name))
{
((Component)child).gameObject.SetActive(false);
((BaseUnityPlugin)this).Logger.LogInfo((object)("Disabled object: " + ((Object)child).name));
}
DisableChildrenByNames(child, names);
}
}
private IEnumerator MonitorAICharacters()
{
while (true)
{
aiCharacters.Clear();
playerHealthObject = null;
GameObject[] allObjects = Object.FindObjectsOfType<GameObject>();
GameObject[] array = allObjects;
foreach (GameObject obj in array)
{
if (((Object)obj).name == "PlayerCharacter(Clone) ai" && !aiCharacters.Contains(obj))
{
aiCharacters.Add(obj);
((BaseUnityPlugin)this).Logger.LogInfo((object)("Found AI Character: " + ((Object)obj).name));
}
if ((Object)(object)obj.GetComponent("PlayerHealth") != (Object)null)
{
playerHealthObject = obj;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Found PlayerHealth object.");
}
}
if (isDummyMode)
{
UpdateAIComponents();
}
yield return (object)new WaitForSeconds(1f);
}
}
}