Decompiled source of TargetPractice v1.0.1

plugins/TargetPractice/TargetPractice.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameplayEntities;
using HarmonyLib;
using LLBML;
using LLBML.Math;
using LLBML.States;
using LLBML.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("TargetPractice (fr.glomzubuk.plugins.llb.targetpractice)")]
[assembly: AssemblyProduct("TargetPractice")]
[assembly: AssemblyVersion("1.0.1.0")]
namespace TargetPractice;

public static class BallCheckTargets
{
	[HarmonyTranspiler]
	[HarmonyPatch(typeof(GetHitBallEntity), "CheckSweep")]
	public static IEnumerable<CodeInstruction> CheckSweep_transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator iL)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Expected O, but got Unknown
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Expected O, but got Unknown
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Expected O, but got Unknown
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Expected O, but got Unknown
		CodeMatcher val = new CodeMatcher(instructions, iL);
		PatchUtils.LogInstructions(val.InstructionEnumeration(), 5, 20, (ManualLogSource)null);
		val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[3]
		{
			new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
			new CodeMatch((OpCode?)OpCodes.Callvirt, (object)null, (string)null),
			new CodeMatch((OpCode?)OpCodes.Callvirt, (object)null, (string)null)
		});
		PatchUtils.LogInstruction(val.Instruction);
		val.Advance(1);
		val.Insert((CodeInstruction[])(object)new CodeInstruction[2]
		{
			new CodeInstruction(OpCodes.Ldarg_0, (object)null),
			Transpilers.EmitDelegate<Action<GetHitBallEntity>>((Action<GetHitBallEntity>)delegate(GetHitBallEntity ghbEntity)
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				foreach (TargetEntity target in TargetPractice.targets)
				{
					if (target.CheckHit(((Entity)ghbEntity).GetPosition(), ((HitableData)ghbEntity.ballData).team))
					{
						TargetPractice.Score();
					}
				}
			})
		});
		PatchUtils.LogInstructions(val.InstructionEnumeration(), 5, 20, (ManualLogSource)null);
		return val.InstructionEnumeration();
	}

	public static void test(Transform hatTf)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		hatTf.localRotation = Quaternion.Euler(0f, 180f, 0f);
	}
}
[BepInPlugin("fr.glomzubuk.plugins.llb.targetpractice", "TargetPractice", "1.0.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInProcess("LLBlaze.exe")]
public class TargetPractice : BaseUnityPlugin
{
	internal ConfigEntry<int> maxTargets;

	internal ConfigEntry<int> targetSpawnInterval;

	internal static List<TargetEntity> targets = new List<TargetEntity>();

	internal static int score = 0;

	private int gameStartTime = -1;

	public static TargetPractice Instance { get; private set; } = null;


	private void Awake()
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Expected O, but got Unknown
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Expected O, but got Unknown
		Instance = this;
		Harmony val = new Harmony("fr.glomzubuk.plugins.llb.targetpractice");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Patching BallCheckTargets");
		val.PatchAll(typeof(BallCheckTargets));
		maxTargets = ((BaseUnityPlugin)this).Config.Bind<int>("Values", "maxTargets", 3, new ConfigDescription("Maximum amount of targets on screen.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 20), new object[0]));
		targetSpawnInterval = ((BaseUnityPlugin)this).Config.Bind<int>("Values", "targetSpawnInterval", 3, new ConfigDescription("Time between target spawns in second.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 120), new object[0]));
	}

	private void Start()
	{
		ModDependenciesUtils.RegisterToModMenu(((BaseUnityPlugin)this).Info, (List<string>)null);
	}

	private void FixedUpdate()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Invalid comparison between Unknown and I4
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Invalid comparison between Unknown and I4
		GameState current = GameStates.GetCurrent();
		if ((int)StateApi.CurrentGameMode != 100)
		{
			return;
		}
		if ((EnumWrapper<JOFJHDJHJGI>)(object)current == (EnumWrapper<JOFJHDJHJGI>)(object)GameState.GAME || (EnumWrapper<JOFJHDJHJGI>)(object)current == (EnumWrapper<JOFJHDJHJGI>)(object)GameState.GAME_PAUSE)
		{
			if (Input.GetKey((KeyCode)304) && Input.GetMouseButtonDown(0))
			{
				Camera main = Camera.main;
				Vector3? val = ((main != null) ? new Vector3?(main.ScreenToWorldPoint(Input.mousePosition)) : null);
				if (val.HasValue)
				{
					SpawnTarget((Vector2f)val.Value * Floatf.op_Implicit(2));
				}
			}
			if (targetSpawnInterval.Value <= 0)
			{
				return;
			}
			BallEntity ball = BallApi.GetBall(0);
			if (gameStartTime == -1)
			{
				if (ball == null)
				{
					return;
				}
				BallData ballData = ((GetHitBallEntity)ball).ballData;
				if (ballData != null)
				{
					_ = ((BouncingData)ballData).ballState;
					if (true && (int)((BouncingData)((GetHitBallEntity)ball).ballData).ballState == 3)
					{
						gameStartTime = GameStatesGameUtils.currentFrame;
					}
				}
			}
			else
			{
				int num = GameStatesGameUtils.currentFrame - gameStartTime;
				int num2 = World.FPS * targetSpawnInterval.Value;
				if (num % num2 == 0)
				{
					Vector2f val2 = Vector2f.op_Implicit(World.instance.stageMax);
					Vector2f val3 = Vector2f.op_Implicit(World.instance.stageMin);
					Floatf f = ControlledRandom.GetF(1, val3.x, val2.x);
					Floatf f2 = ControlledRandom.GetF(1, val3.y, val2.y);
					SpawnTarget(new Vector2f(f, f2));
				}
			}
			return;
		}
		if (targets.Count > 0)
		{
			targets.ForEach(delegate(TargetEntity entity)
			{
				Object.Destroy((Object)(object)((Component)entity).gameObject);
			});
			targets.Clear();
		}
		score = 0;
	}

	private void SpawnTarget(Vector2f position)
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Expected O, but got Unknown
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		if (targets.Count((TargetEntity te) => ((Entity)te).entityData.active) < maxTargets.Value)
		{
			TargetEntity val = new GameObject().AddComponent<TargetEntity>();
			((Entity)val).Init((object)new AnimatableData(1));
			((Entity)val).SetPosition(Vector2f.op_Implicit(position));
			((Entity)val).UpdateUnityTransform();
			targets.Add(val);
			World.instance.AddEntity((Entity)(object)val);
		}
	}

	internal static void Score()
	{
		score++;
	}

	private void OnGUI()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Invalid comparison between Unknown and I4
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: 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_0048: Expected O, but got Unknown
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		if ((int)StateApi.CurrentGameMode == 100)
		{
			GameState current = GameStates.GetCurrent();
			if ((EnumWrapper<JOFJHDJHJGI>)(object)current == (EnumWrapper<JOFJHDJHJGI>)(object)GameState.GAME || (EnumWrapper<JOFJHDJHJGI>)(object)current == (EnumWrapper<JOFJHDJHJGI>)(object)GameState.GAME_PAUSE)
			{
				GUIStyle val = new GUIStyle
				{
					fontSize = 24
				};
				val.normal.textColor = Color.red;
				GUIStyle val2 = val;
				GUI.Label(new Rect(20f, 20f, 400f, 25f), $"Score : {score}", val2);
			}
		}
	}
}
public class PluginInfos
{
	public const string PLUGIN_NAME = "TargetPractice";

	public const string PLUGIN_ID = "fr.glomzubuk.plugins.llb.targetpractice";

	public const string PLUGIN_VERSION = "1.0.1";
}