Decompiled source of Scrapheads v1.0.5

ScrapHeads.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using UnityEngine;
using UnityEngine.AddressableAssets;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ThundergunRevised")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ThundergunRevised")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5711e2a0-d5a7-4ddf-b8d4-00f355fe9397")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: NeutralResourcesLanguage("en-FI")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Scrapheads;

internal class BeamID : MonoBehaviour
{
}
[BepInPlugin("plonk.scrapheads", "scraphead ocs", "1.0.0")]
public class MainCode : BaseUnityPlugin
{
	[HarmonyPatch]
	public class Patches
	{
		private static bool injectedEndless;

		private static bool injectedSpawnmenu;

		[HarmonyPrefix]
		[HarmonyPatch(typeof(BeamgunBeam), "FixedUpdate")]
		public static bool BeamFixedUpdatePatch(BeamgunBeam __instance)
		{
			if (Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<BeamID>()))
			{
				return true;
			}
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(BeamgunBeam), "Update")]
		public static bool BeamUpdatePatch(BeamgunBeam __instance)
		{
			//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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: 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_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<BeamID>()))
			{
				return true;
			}
			if (__instance.fakeStartPoint != Vector3.zero)
			{
				__instance.line.SetPosition(0, __instance.fakeStartPoint);
			}
			else
			{
				__instance.line.SetPosition(0, ((Component)__instance.line).transform.position);
			}
			Vector3 forward = ((Component)__instance).transform.forward * -1f;
			LayerMask val = LayerMaskDefaults.Get((LMD)3);
			if (__instance.canHitPlayer && __instance.playerDamageCooldown <= 0f)
			{
				val = LayerMaskDefaults.Get((LMD)6);
			}
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(((Component)__instance).transform.position, ((Component)__instance).transform.forward, ref val2, float.PositiveInfinity, LayerMask.op_Implicit(val), (QueryTriggerInteraction)1))
			{
				__instance.hitPosition = ((RaycastHit)(ref val2)).point;
				forward = ((RaycastHit)(ref val2)).normal;
			}
			else
			{
				__instance.hitPosition = ((Component)__instance).transform.position + ((Component)__instance).transform.forward * 100f;
			}
			__instance.line.SetPosition(1, __instance.hitPosition);
			((Component)__instance.hitParticle).transform.position = __instance.hitPosition;
			((Component)__instance.hitParticle).transform.forward = forward;
			return false;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(EndlessGrid), "Start")]
		public static void OnStart(EndlessGrid __instance, ref PrefabDatabase ___prefabs)
		{
			if (!injectedEndless)
			{
				injectedEndless = true;
				EndlessEnemy[] projectileEnemies = ___prefabs.projectileEnemies;
				EndlessEnemy[] array = (EndlessEnemy[])(object)new EndlessEnemy[projectileEnemies.Length + 3];
				Array.Copy(projectileEnemies, array, projectileEnemies.Length);
				array[^3] = MainCode.FetchFromBundle<EndlessEnemy>("HazardData.asset", autofill: true);
				array[^2] = MainCode.FetchFromBundle<EndlessEnemy>("ArmedSentryData.asset", autofill: true);
				array[^1] = MainCode.FetchFromBundle<EndlessEnemy>("MannequinData.asset", autofill: true);
				___prefabs.projectileEnemies = array;
				EndlessEnemy[] meleeEnemies = ___prefabs.meleeEnemies;
				EndlessEnemy[] array2 = (EndlessEnemy[])(object)new EndlessEnemy[meleeEnemies.Length + 1];
				Array.Copy(meleeEnemies, array2, meleeEnemies.Length);
				array2[^1] = MainCode.FetchFromBundle<EndlessEnemy>("FilthmachineData.asset", autofill: true);
				___prefabs.meleeEnemies = array2;
				Debug.Log((object)("injected scrapheads: " + ((object)MainCode.FetchFromBundle<EndlessEnemy>("ArmedSentryData.asset", autofill: true).prefab)?.ToString() + ", " + ((object)MainCode.FetchFromBundle<EndlessEnemy>("HazardData.asset", autofill: true).prefab)?.ToString() + ", " + ((object)MainCode.FetchFromBundle<EndlessEnemy>("FilthmachineData.asset", autofill: true).prefab)?.ToString() + ", " + (object)MainCode.FetchFromBundle<EndlessEnemy>("MannequinData.asset", autofill: true).prefab));
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SpawnMenu), "Awake")]
		public static void InjectSpawnmenu(ref SpawnableObjectsDatabase ___objects)
		{
			if (!injectedEndless)
			{
				injectedEndless = true;
				SpawnableObject[] enemies = ___objects.enemies;
				SpawnableObject[] array = (SpawnableObject[])(object)new SpawnableObject[enemies.Length + 5];
				Array.Copy(enemies, array, enemies.Length);
				array[^4] = MainCode.FetchFromBundle<SpawnableObject>("FilthmachineSpawnable.asset", autofill: true);
				array[^3] = MainCode.FetchFromBundle<SpawnableObject>("HazardSpawnable.asset", autofill: true);
				array[^2] = MainCode.FetchFromBundle<SpawnableObject>("ArmedsentrySpawnable.asset", autofill: true);
				array[^1] = MainCode.FetchFromBundle<SpawnableObject>("SentryquinSpawnable.asset", autofill: true);
				___objects.enemies = array;
			}
		}
	}

	public static AssetBundle tcbundle;

	public static GameObject beam;

	public static BeamgunBeam bgbeam;

	private static bool candoshit;

	public static bool ForceNoIgnore;

	private static bool canswitchstate = true;

	public static void SendHudMessage(string msg, int delay, bool silent)
	{
		MonoSingleton<HudMessageReceiver>.Instance.SendHudMessage(msg, "", "", delay, silent);
	}

	public static Type Fetch<Type>(string name)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		return Addressables.LoadAssetAsync<Type>((object)name).WaitForCompletion();
	}

	public static Type FetchFromBundle<Type>(string name, bool autofill = false) where Type : Object
	{
		if (!autofill)
		{
			return tcbundle.LoadAsset<Type>(name);
		}
		return tcbundle.LoadAsset<Type>("assets/formods/scrapheads/" + name);
	}

	public static void SetLayerRecursive(GameObject gobject, string layername)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Expected O, but got Unknown
		gobject.layer = LayerMask.NameToLayer(layername);
		foreach (Transform item in gobject.transform)
		{
			Transform val = item;
			((Component)val).gameObject.layer = LayerMask.NameToLayer(layername);
			Transform componentInChildren = ((Component)val).GetComponentInChildren<Transform>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				SetLayerRecursive(((Component)val).gameObject, layername);
			}
		}
	}

	public Vector3 Shake(Vector3 originpos, Vector3 pos, float shakeamt)
	{
		//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)
		//IL_0007: 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)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: 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)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: 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)
		Vector3 val = Vector3.zero;
		val = pos + new Vector3(Random.Range(0f - shakeamt, shakeamt), Random.Range(0f - shakeamt, shakeamt), Random.Range(0f - shakeamt, shakeamt));
		((Vector3)(ref val))..ctor(Mathf.Clamp(val.x, originpos.x - 0.01f, originpos.x + 0.01f), Mathf.Clamp(val.y, originpos.y - 0.01f, originpos.y + 0.01f), Mathf.Clamp(val.z, originpos.z - 0.01f, originpos.z + 0.01f));
		return val;
	}

	public static void Log(string log, int type)
	{
		switch (type)
		{
		case 1:
			Debug.Log((object)log);
			break;
		case 2:
			Debug.LogWarning((object)log);
			break;
		case 3:
			Debug.LogError((object)log);
			break;
		}
	}

	public void Awake()
	{
		if ((Object)(object)tcbundle == (Object)null)
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			tcbundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "scrapheads"));
			Log("Got bundle " + (object)tcbundle, 1);
			for (int i = 0; i < tcbundle.GetAllAssetNames().Length; i++)
			{
				Log(tcbundle.GetAllAssetNames()[i].ToString(), 1);
			}
		}
		Log("kaboom (scrapheads loaded)", 1);
	}

	public void Start()
	{
		//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("plonk.scrapheads");
		val.PatchAll();
	}

	public void Update()
	{
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		if (!candoshit && SceneHelper.CurrentScene == "Main Menu")
		{
			if ((Object)(object)tcbundle != (Object)null)
			{
				candoshit = true;
			}
			else
			{
				SendHudMessage("Scrapheads mod failed to load.\r\n<color=green>The asset bundle (filename \"scrapheads\") is missing or in the wrong place. please place it where the mod's .dll is located.</color>", 0, silent: true);
			}
		}
		if (candoshit && SceneHelper.CurrentScene != "Main Menu" && (Object)(object)beam == (Object)null)
		{
			beam = Object.Instantiate<GameObject>(Fetch<GameObject>("Assets/Prefabs/Unused/BeamgunBeam.prefab"), ((Component)MonoSingleton<CameraController>.instance).transform.position, ((Component)MonoSingleton<CameraController>.instance).transform.rotation, ((Component)MonoSingleton<CameraController>.instance).transform);
			bgbeam = beam.GetComponent<BeamgunBeam>();
			bgbeam.beamWidth = 0f;
			bgbeam.beamCheckSpeed = 0f;
			beam.AddComponent<BeamID>();
		}
	}

	public static GameObject MakeGun(int type = 1)
	{
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: 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_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(Random.Range(-0.5f, 0.5f), Random.Range(-0.5f, 0.5f), Random.Range(-0.5f, 0.5f));
		GameObject val2 = null;
		switch (type)
		{
		case 1:
			val2 = MainCode.FetchFromBundle<GameObject>("sentry with arms/armedsentry.prefab", autofill: true);
			break;
		case 2:
			val2 = MainCode.FetchFromBundle<GameObject>("filthmachine/filth zombie.prefab", autofill: true);
			break;
		case 3:
			val += new Vector3(0f, 4f, 0f);
			val2 = MainCode.FetchFromBundle<GameObject>("scrapflayer/sh156-2.prefab", autofill: true);
			break;
		case 4:
			val2 = MainCode.FetchFromBundle<GameObject>("scrappequin/mannequin.prefab", autofill: true);
			break;
		}
		GameObject val3 = Object.Instantiate<GameObject>(val2, bgbeam.hitPosition + val, ((Component)MonoSingleton<NewMovement>.instance).transform.rotation);
		val3.GetComponent<EnemyIdentifier>().ignoredByEnemies = !ForceNoIgnore;
		return val3;
	}
}