Decompiled source of Fighter Drones v1.0.4

plugins/Fighter_Drones/RepoMod.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
using REPOLib.Modules;
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("ZortModBepInex")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ZortModBepInex")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9df868d5-31a0-4d0d-8de2-7370fe2e4989")]
[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 RepoMod;

[BepInPlugin("erne.repo.fighterdrones", "Fighter Drones", "1.0.4")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class FighterDrone : BaseUnityPlugin
{
	public const string pluginGuid = "erne.repo.fighterdrones";

	public const string pluginName = "Fighter Drones";

	public const string pluginVersion = "1.0.4";

	public const int DRONE = 3;

	public static Item[] items = (Item[])(object)new Item[3];

	public static ManualLogSource logger;

	public static FighterDrone instance;

	public ConfigEntry<bool> Reset;

	public ConfigEntry<float>[] batteryDrain = new ConfigEntry<float>[3];

	public ConfigEntry<float>[] cooldown = new ConfigEntry<float>[3];

	public ConfigEntry<int>[] damage = new ConfigEntry<int>[3];

	public ConfigEntry<bool>[] spawn = new ConfigEntry<bool>[3];

	public ConfigEntry<float>[] minPrice = new ConfigEntry<float>[3];

	public ConfigEntry<float>[] maxPrice = new ConfigEntry<float>[3];

	public void Awake()
	{
		instance = this;
		logger = ((BaseUnityPlugin)this).Logger;
		SetConfigs();
		string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		string text = Path.Combine(directoryName, "fighterdronebundle");
		AssetBundle val = AssetBundle.LoadFromFile(text);
		GameObject[] array = (GameObject[])(object)new GameObject[3]
		{
			val.LoadAsset<GameObject>("Item Drone Fighter"),
			val.LoadAsset<GameObject>("Weak Item Drone Fighter"),
			val.LoadAsset<GameObject>("Strong Item Drone Fighter")
		};
		items[0] = array[0].GetComponent<ItemAttributes>().item;
		items[1] = array[1].GetComponent<ItemAttributes>().item;
		items[2] = array[2].GetComponent<ItemAttributes>().item;
		for (int i = 0; i < items.Length; i++)
		{
			if (Object.op_Implicit((Object)(object)items[i]))
			{
				items[i].value = ScriptableObject.CreateInstance<Value>();
				items[i].value.valueMin = minPrice[i].Value / 4f;
				items[i].value.valueMax = maxPrice[i].Value / 4f;
				items[i].prefab = array[i];
				Items.RegisterItem(items[i]);
				items[i].prefab.AddComponent<ItemFighterDrone>().id = i;
				((BaseUnityPlugin)this).Logger.LogInfo((object)(items[i].itemName + " is loaded succesfully"));
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)(((Object)items[i]).name + " is not loaded"));
			}
		}
		PatchUtils.RegisterCallback(typeof(LoadingUI), "LevelAnimationStart", Patch);
	}

	private void SetConfigs()
	{
		Reset = ((BaseUnityPlugin)this).Config.Bind<bool>("A IMPORTANT", "Reset", true, "TRUE MEANS IT WILL RESET THIS FILE EVERYTIME YOU OPEN THE GAME");
		batteryDrain[0] = ((BaseUnityPlugin)this).Config.Bind<float>("FighterDrone", "BatteryDrainRate", 12.5f, "Battery drain per second (Max 100)");
		cooldown[0] = ((BaseUnityPlugin)this).Config.Bind<float>("FighterDrone", "Cooldown", 1.75f, "Cooldown for attacks");
		damage[0] = ((BaseUnityPlugin)this).Config.Bind<int>("FighterDrone", "Damage", 50, "Drone's damage per cooldown");
		spawn[0] = ((BaseUnityPlugin)this).Config.Bind<bool>("FighterDrone", "FirstLevelSpawn", false, "Spawn in first level ?");
		minPrice[0] = ((BaseUnityPlugin)this).Config.Bind<float>("FighterDrone", "MinPrice", 31000f, "Minimum shop price for drone");
		maxPrice[0] = ((BaseUnityPlugin)this).Config.Bind<float>("FighterDrone", "MaxPrice", 45000f, "Maximum shop price for drone");
		batteryDrain[1] = ((BaseUnityPlugin)this).Config.Bind<float>("Weak FighterDrone", "BatteryDrainRate", 15f, "Battery drain per second (Max 100)");
		cooldown[1] = ((BaseUnityPlugin)this).Config.Bind<float>("Weak FighterDrone", "Cooldown", 1.75f, "Cooldown for attacks");
		damage[1] = ((BaseUnityPlugin)this).Config.Bind<int>("Weak FighterDrone", "Damage", 35, "Drone's damage per cooldown");
		spawn[1] = ((BaseUnityPlugin)this).Config.Bind<bool>("Weak FighterDrone", "FirstLevelSpawn", true, "Spawn in first level ?");
		minPrice[1] = ((BaseUnityPlugin)this).Config.Bind<float>("Weak FighterDrone", "MinPrice", 15000f, "Minimum shop price for drone");
		maxPrice[1] = ((BaseUnityPlugin)this).Config.Bind<float>("Weak FighterDrone", "MaxPrice", 30000f, "Maximum shop price for drone");
		batteryDrain[2] = ((BaseUnityPlugin)this).Config.Bind<float>("Strong FighterDrone", "BatteryDrainRate", 10f, "Battery drain per second (Max 100)");
		cooldown[2] = ((BaseUnityPlugin)this).Config.Bind<float>("Strong FighterDrone", "Cooldown", 1.85f, "Cooldown for attacks");
		damage[2] = ((BaseUnityPlugin)this).Config.Bind<int>("Strong FighterDrone", "Damage", 85, "Drone's damage per cooldown");
		spawn[2] = ((BaseUnityPlugin)this).Config.Bind<bool>("Strong FighterDrone", "FirstLevelSpawn", false, "Spawn in first level ?");
		minPrice[2] = ((BaseUnityPlugin)this).Config.Bind<float>("Strong FighterDrone", "MinPrice", 46000f, "Minimum shop price for drone");
		maxPrice[2] = ((BaseUnityPlugin)this).Config.Bind<float>("Strong FighterDrone", "MaxPrice", 60000f, "Maximum shop price for drone");
		if (Reset.Value)
		{
			ResetConfigValues();
		}
	}

	private void ResetConfigValues()
	{
		for (int i = 0; i < 3; i++)
		{
			batteryDrain[i].Value = (float)((ConfigEntryBase)batteryDrain[i]).DefaultValue;
			cooldown[i].Value = (float)((ConfigEntryBase)cooldown[i]).DefaultValue;
			damage[i].Value = (int)((ConfigEntryBase)damage[i]).DefaultValue;
			spawn[i].Value = (bool)((ConfigEntryBase)spawn[i]).DefaultValue;
			minPrice[i].Value = (float)((ConfigEntryBase)minPrice[i]).DefaultValue;
			maxPrice[i].Value = (float)((ConfigEntryBase)maxPrice[i]).DefaultValue;
		}
	}

	private void Patch()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		if (RunManager.instance.levelsCompleted != 0)
		{
			return;
		}
		Vector3 position = Vector3.zero;
		Quaternion identity = Quaternion.identity;
		List<LevelPoint> list = new List<LevelPoint>();
		foreach (LevelPoint levelPathPoint in LevelGenerator.Instance.LevelPathPoints)
		{
			if (levelPathPoint.Room.Truck)
			{
				position = ((Component)levelPathPoint).transform.position;
				break;
			}
		}
		for (int i = 0; i < items.Length; i++)
		{
			if (spawn[i].Value)
			{
				Spawn(position, identity, items[i]);
			}
		}
	}

	public void Spawn(Item item)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		Spawn(Vector3.zero, Quaternion.identity, item);
	}

	public void Spawn(Vector3 position, Quaternion rotation, Item item)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		if (SemiFunc.IsMultiplayer())
		{
			PhotonNetwork.InstantiateRoomObject("Items/" + ((Object)item).name, position, rotation, (byte)0, (object[])null);
		}
		else
		{
			Object.Instantiate<GameObject>(item.prefab, position, rotation);
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)(((Object)item).name + " is spawned"));
	}
}
public class ItemFighterDrone : MonoBehaviour
{
	public int id;

	public float batteryDrain;

	public float cooldown;

	public int damage;

	private float maxCooldown;

	private ItemDrone itemDrone;

	private PhysGrabObject myPhysGrabObject;

	private ItemEquippable itemEquippable;

	private ItemBattery itemBattery;

	public void Awake()
	{
		batteryDrain = FighterDrone.instance.batteryDrain[id].Value;
		cooldown = FighterDrone.instance.cooldown[id].Value;
		damage = FighterDrone.instance.damage[id].Value;
		itemDrone = ((Component)this).GetComponent<ItemDrone>();
		myPhysGrabObject = ((Component)this).GetComponent<PhysGrabObject>();
		itemEquippable = ((Component)this).GetComponent<ItemEquippable>();
		itemBattery = ((Component)this).GetComponent<ItemBattery>();
		itemBattery.batteryDrainRate = batteryDrain;
		maxCooldown = cooldown;
	}

	private void FixedUpdate()
	{
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		if (itemEquippable.IsEquipped() || (GameManager.instance.gameMode == 1 && !SemiFunc.IsMasterClient()) || !itemDrone.itemActivated)
		{
			return;
		}
		if (SemiFunc.IsMasterClientOrSingleplayer())
		{
			myPhysGrabObject.OverrideZeroGravity(0.1f);
			myPhysGrabObject.OverrideDrag(1f, 0.1f);
			myPhysGrabObject.OverrideAngularDrag(10f, 0.1f);
		}
		if (!itemDrone.magnetActive || cooldown > 0f)
		{
			if (cooldown > 0f)
			{
				cooldown -= Time.deltaTime;
			}
			return;
		}
		EnemyParent privateVariable = itemDrone.GetPrivateVariable<EnemyParent>("enemyTarget");
		EnemyHealth componentInChildren = ((Component)privateVariable).GetComponentInChildren<EnemyHealth>();
		if (Object.op_Implicit((Object)(object)componentInChildren))
		{
			componentInChildren.Hurt(damage, Vector3.zero);
			cooldown = maxCooldown;
		}
		else
		{
			FighterDrone.logger.LogWarning((object)"ENEMY HEALTH IS NOT FOUND !");
		}
	}
}
public static class MyUtils
{
	public static T GetPrivateVariable<T>(this object instance, string name)
	{
		Type type = instance.GetType();
		FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
		object value = field.GetValue(instance);
		return (value is T) ? ((T)value) : default(T);
	}

	public static void SetPrivateVariable<T>(this object instance, string name, T value)
	{
		Type type = instance.GetType();
		FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
		field.SetValue(instance, value);
	}
}
public static class PatchUtils
{
	private static Dictionary<string, Action> actions = new Dictionary<string, Action>();

	private static object callback;

	public static void RegisterCallback(Type classType, string callback, Action action, bool oneTime = false)
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Expected O, but got Unknown
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Expected O, but got Unknown
		PatchUtils.callback = callback;
		if (!actions.ContainsKey(callback))
		{
			actions.Add(callback, action);
		}
		else
		{
			actions[callback] = action;
		}
		Harmony val = new Harmony("com.example.patch");
		MethodInfo methodInfo = AccessTools.Method(classType, callback, (Type[])null, (Type[])null);
		MethodInfo methodInfo2 = AccessTools.Method(typeof(PatchUtils), oneTime ? "DynamicPostfixOnce" : "DynamicPostfix", (Type[])null, (Type[])null);
		val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
	}

	public static void UnRegisterCallback(Type classType, string callback)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		Harmony val = new Harmony("com.example.patch");
		MethodInfo methodInfo = AccessTools.Method(classType, callback, (Type[])null, (Type[])null);
		val.Unpatch((MethodBase)methodInfo, (HarmonyPatchType)0, "com.example.patch");
		actions.Remove(callback);
	}

	public static void DynamicPostfix(MethodBase __originalMethod)
	{
		string name = __originalMethod.Name;
		actions[name]?.Invoke();
	}

	public static void DynamicPostfixOnce(MethodBase __originalMethod)
	{
		string name = __originalMethod.Name;
		actions[name]?.Invoke();
		UnRegisterCallback(__originalMethod.DeclaringType, name);
	}
}