Decompiled source of Genehmigt v1.0.4

BepInEx/plugins/Genehmigt/Genehmigt.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.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using ComputerysModdingUtilities;
using FishNet.Managing;
using FishNet.Object;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: StraftatMod(false)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: AssemblyCompany("Genehmigt")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("6.9.4.20")]
[assembly: AssemblyInformationalVersion("6.9.4.20+d243eaf6915c0984b28b000913dda7a1c92fe644")]
[assembly: AssemblyProduct("debugPlgn")]
[assembly: AssemblyTitle("Genehmigt")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("6.9.4.20")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
[BepInPlugin("dimolade.libraries.Genehmigt", "Genehmigt", "1.0.0.0")]
public class GenehmigtLoader : BaseUnityPlugin
{
	private void Awake()
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Expected O, but got Unknown
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Expected O, but got Unknown
		string location = ((BaseUnityPlugin)this).Info.Location;
		string directoryName = Path.GetDirectoryName(location);
		Genehmigt.Logger = ((BaseUnityPlugin)this).Logger;
		Genehmigt.dllFolder = directoryName;
		Genehmigt.Logger.LogInfo((object)"Genehmigt says Haiiii :3");
		Genehmigt.weaponPhysMat = new PhysicMaterial();
		Genehmigt.weaponPhysMat.dynamicFriction = 0.51f;
		Genehmigt.weaponPhysMat.staticFriction = 0.52f;
		Genehmigt.weaponPhysMat.bounciness = 0.1f;
		Genehmigt.weaponPhysMat.frictionCombine = (PhysicMaterialCombine)0;
		Genehmigt.weaponPhysMat.bounceCombine = (PhysicMaterialCombine)0;
		GameObject val = Resources.Load<GameObject>(SpawnerManager.WeaponsPath + "/Propeller");
		ItemBehaviour component = val.GetComponent<ItemBehaviour>();
		Genehmigt.DefaultCrosshair = component.standCrosshair;
		Genehmigt.hitSurfaceClip = component.hitSurfaceClip;
		Genehmigt.grabClip = component.grabClip;
		Genehmigt.depopVFX = component.depopVFX;
		Genehmigt.groundLayer = component.groundLayer;
		Harmony val2 = new Harmony("dimolade.harmony.Genehmigt");
		val2.PatchAll();
	}
}
public static class Genehmigt
{
	public static Dictionary<string, GameObject> ModdedRandomWeaponPool;

	public static bool onlySpawnModded = false;

	public static List<GenehmigtWeapon> ModWeaponList = new List<GenehmigtWeapon>();

	public static ManualLogSource Logger;

	public static string dllFolder;

	public static Sprite DefaultCrosshair;

	public static AudioClip hitSurfaceClip;

	public static AudioClip grabClip;

	public static GameObject depopVFX;

	public static LayerMask groundLayer;

	public static PhysicMaterial weaponPhysMat;

	public static event Func<WeaponDropper, bool> OnWeaponTryDrop;

	public static event Func<ItemSpawner, bool> OnWeaponTrySpawn;

	public static bool InvokeOnWeaponTrySpawn(ItemSpawner wd)
	{
		bool result = true;
		if (Genehmigt.OnWeaponTrySpawn != null)
		{
			Delegate[] invocationList = Genehmigt.OnWeaponTrySpawn.GetInvocationList();
			for (int i = 0; i < invocationList.Length; i++)
			{
				Func<ItemSpawner, bool> func = (Func<ItemSpawner, bool>)invocationList[i];
				if (!func(wd))
				{
					result = false;
				}
			}
		}
		return result;
	}

	public static bool InvokeOnWeaponTryDrop(WeaponDropper wd)
	{
		bool result = true;
		if (Genehmigt.OnWeaponTryDrop != null)
		{
			Delegate[] invocationList = Genehmigt.OnWeaponTryDrop.GetInvocationList();
			for (int i = 0; i < invocationList.Length; i++)
			{
				Func<WeaponDropper, bool> func = (Func<WeaponDropper, bool>)invocationList[i];
				if (!func(wd))
				{
					result = false;
				}
			}
		}
		return result;
	}

	private static void LoadBundle(string bundlePath, out GameObject go)
	{
		go = null;
		AssetBundle val = AssetBundle.LoadFromFile(bundlePath);
		GameObject[] array = val.LoadAllAssets<GameObject>();
		if (array.Length != 0)
		{
			go = array[0];
		}
		val.Unload(false);
	}

	private static GameObject LoadSample()
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		LoadBundle(Path.Combine(dllFolder, "genehmigt"), out var go);
		go.transform.position = Vector3.zero;
		go.transform.localScale = new Vector3(2f, 2f, 2f);
		go.AddComponent<ItemBehaviour>();
		BoxCollider val = go.AddComponent<BoxCollider>();
		val.size = new Vector3(0.13836f, 0.13836f, 0.13836f);
		go.AddComponent<NetworkObject>();
		((Collider)val).material = weaponPhysMat;
		Transform child = go.transform.GetChild(0);
		((Component)child).gameObject.AddComponent<ElbowPivotPoint>();
		child.localPosition = new Vector3(0f, 0f, -0.1685f);
		child.localScale = new Vector3(0.5f, 0.5f, 0.5f);
		Transform child2 = child.GetChild(0);
		((Component)child2).gameObject.AddComponent<AimStrafePivot>();
		child2.localPosition = new Vector3(0f, 0.283f, 0.367f);
		Transform child3 = child2.GetChild(0);
		Transform child4 = child2.GetChild(1);
		AddGrip(child3);
		AddGrip(child4);
		child3.localPosition = new Vector3(0f, -0.2806f, -0.58f);
		child4.localPosition = new Vector3(0f, -0.2806f, -0.667f);
		return go;
		static void AddGrip(Transform G)
		{
			((Component)G).gameObject.AddComponent<Grip>();
		}
	}

	public static GameObject CreateWeapon(GenehmigtWeapon GW)
	{
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = LoadSample();
		if ((Object)(object)val == (Object)null)
		{
			Logger.LogError((object)"Failed to load Sample prefab!");
			return null;
		}
		GameObject val2 = val;
		val2.layer = 8;
		ItemBehaviour component = val2.GetComponent<ItemBehaviour>();
		component.weaponName = GW.Name;
		component.heavy = GW.Heavy;
		component.vertical = GW.Vertical;
		component.aimWeapon = GW.Aim;
		component.aimFOV = GW.AimFOV;
		component.instantAimLens = GW.InstantAimLense;
		component.standCrosshair = DefaultCrosshair;
		component.sprintCrosshair = DefaultCrosshair;
		if ((Object)(object)GW.AimCrosshair != (Object)null)
		{
			component.aimCrosshair = GW.AimCrosshair;
		}
		if ((Object)(object)GW.StandCrosshair != (Object)null)
		{
			component.standCrosshair = GW.StandCrosshair;
		}
		if ((Object)(object)GW.SprintCrosshair != (Object)null)
		{
			component.sprintCrosshair = GW.SprintCrosshair;
		}
		component.camChildIndex = 8;
		component.camChildIndexLeftHand = 8;
		component.aimIndex = 0;
		component.vfxAttachedOnGun = false;
		component.hitSurfaceClip = hitSurfaceClip;
		component.grabClip = grabClip;
		component.depopVFX = depopVFX;
		component.groundLayer = groundLayer;
		component.ejectForce = GW.EjectForce;
		component.torqueForce = GW.TorqueForce;
		component.gravityAdded = GW.GravityAdded;
		if ((Object)(object)GW.HitSurfaceClip != (Object)null)
		{
			component.hitSurfaceClip = GW.HitSurfaceClip;
		}
		if ((Object)(object)GW.PickupClip != (Object)null)
		{
			component.grabClip = GW.PickupClip;
		}
		GW.WeaponObject = val2;
		GW.NO = val2.GetComponent<NetworkObject>();
		((Object)val2).name = GW.Name;
		ModWeaponList.Add(GW);
		Logger.LogInfo((object)("Made Genehmigt Weapon: " + GW.Name));
		return val2;
	}
}
[HarmonyPatch(typeof(NetworkManager))]
internal static class NetworkManagerPatch
{
	[HarmonyPatch("Awake")]
	[HarmonyPostfix]
	public static void RefreshPrefabs(NetworkManager __instance)
	{
		foreach (GenehmigtWeapon modWeapon in Genehmigt.ModWeaponList)
		{
			if ((Object)(object)modWeapon.NO != (Object)null)
			{
				Genehmigt.Logger.LogInfo((object)("Added Genehmigt Weapon to Prefab Pool: " + modWeapon.Name));
			}
			__instance.SpawnablePrefabs.AddObject(modWeapon.NO, false);
		}
	}
}
[HarmonyPatch(typeof(ResourcesAPI), "Load")]
internal class ResourceLoadPatch
{
	private static bool Prefix(ref Object __result, string path, Type systemTypeInstance)
	{
		if (path.StartsWith(SpawnerManager.WeaponsPath) && systemTypeInstance == typeof(GameObject))
		{
			foreach (GenehmigtWeapon modWeapon in Genehmigt.ModWeaponList)
			{
				if (path == SpawnerManager.WeaponsPath + "/" + modWeapon.Name)
				{
					__result = (Object)(object)modWeapon.WeaponObject;
					Genehmigt.Logger.LogInfo((object)("Tried Loading Genehmigt Weapon with Name: " + modWeapon.Name));
					return false;
				}
			}
		}
		return true;
	}
}
[HarmonyPatch(typeof(ResourcesAPI), "LoadAll")]
internal class ResourceLoadAllPatch
{
	private static void Postfix(ref Object[] __result, string path, Type systemTypeInstance)
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Expected O, but got Unknown
		if (!path.StartsWith(SpawnerManager.WeaponsPath) || !(systemTypeInstance == typeof(GameObject)))
		{
			return;
		}
		int num = 0;
		List<int> list = new List<int>();
		Object[] array = __result;
		for (int i = 0; i < array.Length; i++)
		{
			GameObject val = (GameObject)array[i];
			foreach (GenehmigtWeapon modWeapon in Genehmigt.ModWeaponList)
			{
				if (((Object)val).name == modWeapon.Name)
				{
					Genehmigt.Logger.LogInfo((object)("Tried Loading All doing Genehmigt Weapon with Name: " + modWeapon.Name));
					__result[num] = (Object)(object)modWeapon.WeaponObject;
					list.Add(num);
				}
			}
			num++;
		}
		List<Object> list2 = new List<Object>(__result);
		num = 0;
		foreach (GenehmigtWeapon modWeapon2 in Genehmigt.ModWeaponList)
		{
			if (!list.Contains(num))
			{
				list2.Add((Object)(object)modWeapon2.WeaponObject);
				num++;
			}
		}
		__result = list2.ToArray();
	}
}
public class GenehmigtWeapon
{
	public string Name = "GenehmigtWeapon";

	public GameObject WeaponObject;

	public NetworkObject NO;

	public bool Heavy = false;

	public bool Vertical = false;

	public bool Aim = false;

	public float AimFOV = 75f;

	public bool InstantAimLense = false;

	public Sprite AimCrosshair = null;

	public Sprite StandCrosshair = null;

	public Sprite SprintCrosshair = null;

	public float EjectForce = 9f;

	public float TorqueForce = 11f;

	public float GravityAdded = 6.5f;

	public AudioClip PickupClip = null;

	public AudioClip HitSurfaceClip = null;
}
[HarmonyPatch(typeof(WeaponDropper), "Spawn")]
public class GENEHMIGT_WeaponTryDrop
{
	public static bool Prefix(WeaponDropper __instance)
	{
		return Genehmigt.InvokeOnWeaponTryDrop(__instance);
	}
}
[HarmonyPatch(typeof(ItemSpawner), "Spawn")]
public class GENEHMIGT_WeaponTrySpawn
{
	public static bool Prefix(ItemSpawner __instance)
	{
		return Genehmigt.InvokeOnWeaponTrySpawn(__instance);
	}
}
namespace STRAFMOD
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Genehmigt";

		public const string PLUGIN_NAME = "debugPlgn";

		public const string PLUGIN_VERSION = "6.9.4.20";
	}
}