Decompiled source of LivingSiege v1.0.2

LivingSiege.dll

Decompiled 10 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using DM;
using HarmonyLib;
using Landfall.TABS;
using LivingSiege;
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("SuperUnits")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("GeeztJeez")]
[assembly: AssemblyProduct("SuperUnits")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7acfaef0-7669-4401-8bff-5a9a02e18c75")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
namespace LivingSiege;

[BepInPlugin("GeeztJeez.LivingSiege", "LivingSiege", "1.0.2")]
internal class Loader : BaseUnityPlugin
{
	private static ConfigEntry<float> configDepartRadius;

	private static ConfigEntry<bool> configEnableMod;

	private static ConfigEntry<bool> configLivingVehicle;

	private static ConfigEntry<bool> configUseDepartion;

	public static bool Enabled => configEnableMod.Value;

	public static bool LivingVehicleEnabled => configLivingVehicle.Value;

	public static bool UseDepartion => configUseDepartion.Value;

	public static float DepartRadius => configDepartRadius.Value;

	private void Awake()
	{
		((MonoBehaviour)this).StartCoroutine("Call");
	}

	private IEnumerator Call()
	{
		yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)Object.FindObjectOfType<ServiceLocator>() != (Object)null));
		yield return (object)new WaitUntil((Func<bool>)(() => ServiceLocator.GetService<ISaveLoaderService>() != null));
		Debug.Log((object)"Loading LivingSiege...");
		SLMALoader.GetInstance();
		_ = ContentDatabase.Instance().LandfallContentDatabase;
		new Harmony("LivingSiege").PatchAll();
		GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>();
		for (int i = 0; i < array.Length; i++)
		{
			if (Object.op_Implicit((Object)(object)array[i].GetComponentInChildren<Unit>()))
			{
				array[i].AddComponent<LivingSieges>();
			}
		}
		DoConfig();
		((MonoBehaviour)this).StartCoroutine(GenerateSettings());
		Debug.Log((object)"Loaded LivingSiege Successfully!");
	}

	private IEnumerator GenerateSettings()
	{
		GlobalSettingsHandler service = null;
		yield return (object)new WaitUntil((Func<bool>)(() => Object.op_Implicit((Object)(object)(service = ServiceLocator.GetService<GlobalSettingsHandler>()))));
		List<SettingsInstance> list = service.GameplaySettings.ToList();
		SettingsInstance val2 = new SettingsInstance();
		val2.settingsType = (SettingsType)0;
		val2.options = new string[2] { "On", "Off" };
		val2.currentValue = ((!configEnableMod.Value) ? 1 : 0);
		val2.m_settingsKey = "Use Living Siege";
		val2.toolTip = "Enables Living Siege mod.";
		SettingsInstance val3 = val2;
		val3.OnValueChanged += delegate(int val)
		{
			configEnableMod.Value = val == 0;
		};
		list.Add(val3);
		val2 = new SettingsInstance();
		val2.settingsType = (SettingsType)0;
		val2.options = new string[2] { "On", "Off" };
		val2.currentValue = ((!configLivingVehicle.Value) ? 1 : 0);
		val2.m_settingsKey = "Living Vehicle";
		val2.toolTip = "Enables vehicles to also be alive on departion. (default: On)";
		SettingsInstance val4 = val2;
		val4.OnValueChanged += delegate(int val)
		{
			configLivingVehicle.Value = val == 0;
		};
		list.Add(val4);
		val2 = new SettingsInstance();
		val2.settingsType = (SettingsType)0;
		val2.options = new string[2] { "On", "Off" };
		val2.currentValue = ((!configUseDepartion.Value) ? 1 : 0);
		val2.m_settingsKey = "Close Departion";
		val2.toolTip = "Enable departion on close distance. (Default: On)";
		SettingsInstance val5 = val2;
		val5.OnValueChanged += delegate(int val)
		{
			configUseDepartion.Value = val == 0;
		};
		list.Add(val5);
		SettingsInstance val6 = new SettingsInstance
		{
			currentSliderValue = configDepartRadius.Value,
			defaultSliderValue = 2f,
			max = 4f,
			min = 0.5f,
			m_settingsKey = "Depart Radius",
			settingsType = (SettingsType)1,
			toolTip = "Determines the distance required when rider departs. (default: 2)"
		};
		val6.OnSliderValueChanged += delegate(float val)
		{
			configDepartRadius.Value = val;
		};
		list.Add(val6);
		((object)service).GetType().GetField("m_gameplaySettings", (BindingFlags)(-1)).SetValue(service, list.ToArray());
	}

	private void DoConfig()
	{
		configDepartRadius = ((BaseUnityPlugin)this).Config.Bind<float>("General", "DepartRadius", 2f, "Determines the distance required when rider departs");
		configEnableMod = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable Living Siege Mod");
		configLivingVehicle = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "LivingVehicle", true, "Enable living vehicles");
		configUseDepartion = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DepartOnRange", true, "Enable departion on close range");
	}
}
public class LivingSieges : MonoBehaviour
{
	private Unit unit;

	public void Update()
	{
		if (Loader.Enabled && Loader.UseDepartion && Object.op_Implicit((Object)(object)unit))
		{
			MountPos[] componentsInChildren = ((Component)unit).GetComponentsInChildren<MountPos>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].dropMountWithinRange = Loader.DepartRadius;
			}
		}
	}

	public void Start()
	{
		((Behaviour)this).enabled = Loader.Enabled;
		if (!Loader.Enabled)
		{
			return;
		}
		unit = ((Component)((Component)this).gameObject.transform.root).GetComponentInChildren<Unit>();
		if (unit.IsRider)
		{
			unit.unitBlueprint.excludeFromWinCondition = false;
		}
		MountPos[] componentsInChildren = ((Component)unit).GetComponentsInChildren<MountPos>();
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			if (Loader.Enabled)
			{
				componentsInChildren[i].killRiderIfVehicleDies = false;
			}
			if (Loader.LivingVehicleEnabled)
			{
				componentsInChildren[i].killVehicleIfRiderDies = false;
			}
		}
	}
}