Decompiled source of Stick Bots v1.1.0

StickBots.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("StickFightTheGameMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("StickFightTheGameMod")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("07ad7751-658e-41ea-b1ee-8a7e59ffbe73")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace soloaibots;

[BepInPlugin("stfg.bayturtleking.botmode", "Bot Mode", "1.0.0")]
public class soloaibotsmod : BaseUnityPlugin
{
	public static soloaibotsmod instance;

	public ConfigEntry<KeyCode> keythatstartsd;

	public ConfigEntry<int> howmanybots;

	public ConfigEntry<float> spawnspread;

	public ConfigEntry<float> bothealthmultiplier;

	private bool fighting;

	private Controller mainguy;

	private readonly List<Controller> stillkicking = new List<Controller>();

	private HoardHandler fakehoard;

	private bool automode;

	private bool wasinfight;

	private void Awake()
	{
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		instance = this;
		keythatstartsd = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "keyforbots", (KeyCode)287, "the key to start bot mode");
		howmanybots = ((BaseUnityPlugin)this).Config.Bind<int>("General", "howmanybots", 3, "how many bots to spawn");
		spawnspread = ((BaseUnityPlugin)this).Config.Bind<float>("General", "spreadapart", 4f, "how far apart the bots spawn");
		bothealthmultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "bothealthmultiplier", 1.5f, "multiplies bot max health, 1 is normal, 2 = double");
		new Harmony("stfg.bayturtleking.soloaibots").PatchAll();
	}

	private void Update()
	{
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		bool flag = (Object)(object)GameManager.Instance != (Object)null && GameManager.inFight;
		if (automode && !fighting && flag && !wasinfight)
		{
			trytostartfight();
		}
		wasinfight = flag;
		if (Input.GetKeyDown(keythatstartsd.Value))
		{
			if (fighting)
			{
				getout();
			}
			else
			{
				trytostartfight();
			}
		}
	}

	private void trytostartfight()
	{
		if ((Object)(object)GameManager.Instance == (Object)null || (Object)(object)ControllerHandler.Instance == (Object)null || (!GameManager.inFight && !GameManager.stillInMenu))
		{
			return;
		}
		List<Controller> players = ControllerHandler.Instance.players;
		if (players != null && players.Count == 1)
		{
			mainguy = players[0];
			if (!((Object)(object)mainguy == (Object)null) && !((Component)mainguy).GetComponent<CharacterInformation>().isDead)
			{
				fighting = true;
				automode = true;
				stillkicking.Clear();
				((MonoBehaviour)this).StartCoroutine(spawntheguys(mainguy, Mathf.Max(1, howmanybots.Value)));
			}
		}
	}

	private IEnumerator spawntheguys(Controller player, int count)
	{
		spawnemup();
		ControllerHandler ch = ControllerHandler.Instance;
		Vector3 basepos = ((Component)player).transform.position;
		Vector3 val = default(Vector3);
		for (int i = 0; i < count; i++)
		{
			((Vector3)(ref val))..ctor(Random.Range(0f - spawnspread.Value, spawnspread.Value), 6f, Random.Range(0f - spawnspread.Value, spawnspread.Value));
			GameObject val2 = Object.Instantiate<GameObject>(ch.playerPrefab, basepos + val, Quaternion.identity);
			Controller component = val2.GetComponent<Controller>();
			component.isAI = true;
			component.playerID = -1;
			val2.AddComponent<AI>().goForGuns = true;
			component.SetCollision(true);
			component.TakeLocalControl(CharacterActions.CreateWithControllerBindings());
			if ((Object)(object)GameManager.Instance != (Object)null)
			{
				GameManager.Instance.RevivePlayer(component, true);
			}
			HealthHandler component2 = val2.GetComponent<HealthHandler>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.health *= bothealthmultiplier.Value;
				component2.maxHealth = component2.health;
			}
			if (ch.colors != null && ch.colors.Length != 0)
			{
				colorfulsticks(val2, ch.colors[(i + 1) % ch.colors.Length]);
			}
			stillkicking.Add(component);
			yield return (object)new WaitForSeconds(0.15f);
		}
	}

	private void colorfulsticks(GameObject go, Material mat)
	{
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		LineRenderer[] componentsInChildren = go.GetComponentsInChildren<LineRenderer>();
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			((Renderer)componentsInChildren[i]).sharedMaterial = mat;
		}
		SpriteRenderer[] componentsInChildren2 = go.GetComponentsInChildren<SpriteRenderer>();
		foreach (SpriteRenderer val in componentsInChildren2)
		{
			if (((Component)((Component)val).transform).tag != "DontChangeColor")
			{
				val.color = mat.color;
			}
		}
		CharacterInformation component = go.GetComponent<CharacterInformation>();
		if ((Object)(object)component != (Object)null)
		{
			component.myMaterial = mat;
		}
	}

	private void spawnemup()
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)fakehoard != (Object)null))
		{
			fakehoard = Object.FindObjectOfType<HoardHandler>();
			if (!((Object)(object)fakehoard != (Object)null))
			{
				fakehoard = new GameObject("soloaibots_HoardStub").AddComponent<HoardHandler>();
				fakehoard.waves = false;
				fakehoard.specificNumber = 0;
			}
		}
	}

	public void somebodydied(Controller c)
	{
		if (!fighting || (Object)(object)c == (Object)null)
		{
			return;
		}
		if (stillkicking.Remove(c))
		{
			if ((Object)(object)GameManager.Instance != (Object)null)
			{
				GameManager.Instance.RemovePlayer(c);
			}
			if (stillkicking.Count == 0)
			{
				youwon();
			}
		}
		else if ((Object)(object)c == (Object)(object)mainguy)
		{
			fighting = false;
			forceittdude();
		}
	}

	private void youwon()
	{
		fighting = false;
		AccessTools.Method(typeof(GameManager), "AllButOnePlayersDied", (Type[])null, (Type[])null).Invoke(GameManager.Instance, null);
	}

	private void getout()
	{
		fighting = false;
		forceittdude();
	}

	private void forceittdude()
	{
		AccessTools.Method(typeof(GameManager), "AllButOnePlayersDied", (Type[])null, (Type[])null).Invoke(GameManager.Instance, null);
		nomoreremains();
	}

	private void nomoreremains()
	{
		foreach (Controller item in stillkicking)
		{
			if ((Object)(object)item != (Object)null)
			{
				if ((Object)(object)GameManager.Instance != (Object)null)
				{
					GameManager.Instance.RemovePlayer(item);
				}
				Object.Destroy((Object)(object)((Component)item).gameObject);
			}
		}
		stillkicking.Clear();
	}
}
[HarmonyPatch(typeof(HealthHandler), "Die")]
public static class nosnitch
{
	private static void Postfix(HealthHandler __instance)
	{
		soloaibotsmod.instance?.somebodydied(((Component)__instance).GetComponent<Controller>());
	}
}