Decompiled source of JesterZapper v0.1.1

jesterGunMod.dll

Decompiled 5 months ago
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.Logging;
using LethalLib.Modules;
using Unity.Netcode;
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("jesterGunMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HP Inc.")]
[assembly: AssemblyProduct("jesterGunMod")]
[assembly: AssemblyCopyright("Copyright © HP Inc. 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4e34b94b-4e99-479b-9ae2-8410b15b3afa")]
[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")]
public class JesterGunBehavior : PhysicsProp
{
	[SerializeField]
	private float fireRange = 100f;

	[SerializeField]
	private ParticleSystem muzzleFlash;

	[SerializeField]
	private AudioSource fireSound;

	public override void Start()
	{
		((GrabbableObject)this).Start();
		muzzleFlash = ((Component)this).GetComponent<ParticleSystem>();
		fireSound = ((Component)this).GetComponent<AudioSource>();
		if ((Object)(object)muzzleFlash == (Object)null)
		{
			Debug.LogWarning((object)"Muzzle flash not found on parent.");
		}
		if ((Object)(object)fireSound == (Object)null)
		{
			Debug.LogWarning((object)"Fire sound not found on parent.");
		}
	}

	public override void ItemActivate(bool used, bool buttonDown = true)
	{
		((GrabbableObject)this).ItemActivate(used, buttonDown);
		if (buttonDown && !((Object)(object)((GrabbableObject)this).playerHeldBy == (Object)null))
		{
			FireAtTarget();
		}
	}

	private void FireAtTarget()
	{
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: 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)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		((GrabbableObject)this).insertedBattery.charge = 0f;
		ParticleSystem obj = muzzleFlash;
		if (obj != null)
		{
			obj.Play();
		}
		AudioSource obj2 = fireSound;
		if (obj2 != null)
		{
			obj2.Play();
		}
		((GrabbableObject)this).UseUpBatteries();
		((GrabbableObject)this).UseUpItemBatteriesServerRpc();
		if ((Object)(object)((GrabbableObject)this).playerHeldBy == (Object)null || (Object)(object)((GrabbableObject)this).playerHeldBy.gameplayCamera == (Object)null)
		{
			Debug.LogError((object)"playerHeldBy or camera is null — aborting.");
			return;
		}
		Camera gameplayCamera = ((GrabbableObject)this).playerHeldBy.gameplayCamera;
		Vector3 position = ((Component)gameplayCamera).transform.position;
		Vector3 forward = ((Component)gameplayCamera).transform.forward;
		Debug.DrawRay(position, forward * fireRange, Color.red, 2f);
		Debug.Log((object)"Firing ray...");
		int mask = LayerMask.GetMask(new string[1] { "Enemies" });
		RaycastHit val = default(RaycastHit);
		if (Physics.Raycast(position, forward, ref val, fireRange, mask, (QueryTriggerInteraction)1))
		{
			Debug.Log((object)("Raycast hit: " + ((Object)((RaycastHit)(ref val)).collider).name));
			Transform val2 = ((Component)((RaycastHit)(ref val)).collider).transform;
			EnemyAI val3 = null;
			while ((Object)(object)val2 != (Object)null)
			{
				val3 = ((Component)val2).GetComponent<EnemyAI>();
				if ((Object)(object)val3 != (Object)null)
				{
					break;
				}
				val2 = val2.parent;
			}
			if ((Object)(object)val3 == (Object)null)
			{
				Debug.Log((object)"EnemyAI not found in hierarchy.");
				return;
			}
			Debug.Log((object)("Hit enemy: " + val3.enemyType.enemyName));
			if (!val3.enemyType.enemyName.ToLower().Contains("jester"))
			{
				Debug.Log((object)"Hit enemy, but not a Jester.");
			}
			else if (((object)val3).GetType().GetMethod("KillEnemy") != null)
			{
				Debug.Log((object)"Killing Jester via Destroy()");
				Object.Destroy((Object)(object)((Component)val3).gameObject);
			}
			else
			{
				Debug.LogWarning((object)"KillEnemy() not available on this enemy.");
			}
		}
		else
		{
			Debug.Log((object)"Raycast hit nothing.");
		}
	}

	public void KillJesterServerRpc(NetworkObjectReference enemyRef)
	{
		NetworkObject val = default(NetworkObject);
		if (((NetworkObjectReference)(ref enemyRef)).TryGet(ref val, (NetworkManager)null))
		{
			EnemyAI component = ((Component)val).GetComponent<EnemyAI>();
			if ((Object)(object)component != (Object)null && component.enemyType.enemyName.ToLower().Contains("jester"))
			{
				Object.Destroy((Object)(object)((Component)component).gameObject);
				Debug.Log((object)"Attempted ServerRPC Kill");
			}
		}
	}
}
namespace jesterGunMod;

[BepInPlugin("arsonistLink.jesterGun", "Jester Gun", "0.1.0")]
public class jesterGun : BaseUnityPlugin
{
	private const string modGUID = "arsonistLink.jesterGun";

	private const string modName = "Jester Gun";

	private const string modVersion = "0.1.0";

	public static jesterGun instance;

	private ManualLogSource mls;

	private bool debugCheck = false;

	private void Awake()
	{
		//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
		instance = this;
		mls = Logger.CreateLogSource("arsonistLink.jesterGun");
		mls.LogInfo((object)"The JesterGun has awaken");
		string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "jestergunbundle");
		AssetBundle val = AssetBundle.LoadFromFile(text);
		Item val2 = val.LoadAsset<Item>("Assets/jesterDeleteGun/jesterGun.asset");
		TerminalNode val3 = val.LoadAsset<TerminalNode>("Assets/jesterDeleteGun/iTerminalNode.asset");
		TerminalNode val4 = val.LoadAsset<TerminalNode>("Assets/jesterDeleteGun/Buy Jester Gun.asset");
		TerminalNode val5 = val.LoadAsset<TerminalNode>("Assets/jesterDeleteGun/gunInfo.asset");
		TerminalKeyword val6 = val.LoadAsset<TerminalKeyword>("Assets/jesterDeleteGun/jesterGunKeyword.asset");
		TerminalKeyword val7 = val.LoadAsset<TerminalKeyword>("Assets/jesterDeleteGun/Confirm.asset");
		TerminalKeyword val8 = val.LoadAsset<TerminalKeyword>("Assets/jesterDeleteGun/Deny.asset");
		if (debugCheck)
		{
			if ((Object)(object)val2 == (Object)null || (Object)(object)val5 == (Object)null || (Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null || (Object)(object)val6 == (Object)null)
			{
				mls.LogError((object)"One or more assets failed to load!");
				if ((Object)(object)val2 == (Object)null)
				{
					mls.LogError((object)"Asset Bundle failed to load!");
				}
				else if ((Object)(object)val5 == (Object)null)
				{
					mls.LogError((object)"Item Info failed to load!");
				}
				else if ((Object)(object)val3 == (Object)null)
				{
					mls.LogError((object)"BuyNode1 failed to load!");
				}
				else if ((Object)(object)val4 == (Object)null)
				{
					mls.LogError((object)"BuyNode2 failed to load!");
				}
				else if ((Object)(object)val6 == (Object)null)
				{
					mls.LogError((object)"Shop Keyword Reference failed to load!");
				}
				return;
			}
			mls.LogInfo((object)$"RestingRotation: {val2.restingRotation}");
			mls.LogInfo((object)$"ParentObject (from prefab): {((GrabbableObject)(val2.spawnPrefab.GetComponent<PhysicsProp>()?)).parentObject}");
			mls.LogInfo((object)("Item name: " + val2.itemName));
			mls.LogInfo((object)("SpawnPrefab: " + (((Object)(object)val2.spawnPrefab != (Object)null) ? ((Object)val2.spawnPrefab).name : "NULL")));
			if ((Object)(object)val2.spawnPrefab != (Object)null)
			{
				mls.LogInfo((object)$"Prefab has GrabbableObject: {(Object)(object)val2.spawnPrefab.GetComponent<GrabbableObject>() != (Object)null}");
				mls.LogInfo((object)$"Prefab has NetworkObject: {(Object)(object)val2.spawnPrefab.GetComponent<NetworkObject>() != (Object)null}");
			}
			if ((Object)(object)val2.spawnPrefab == (Object)null)
			{
				mls.LogError((object)"FATAL: spawnPrefab is NULL — RegisterShopItem will fail.");
				return;
			}
		}
		JesterGunBehavior jesterGunBehavior = val2.spawnPrefab.AddComponent<JesterGunBehavior>();
		((GrabbableObject)jesterGunBehavior).grabbable = true;
		((GrabbableObject)jesterGunBehavior).grabbableToEnemies = true;
		((GrabbableObject)jesterGunBehavior).isInFactory = true;
		((GrabbableObject)jesterGunBehavior).itemProperties = val2;
		NetworkPrefabs.RegisterNetworkPrefab(val2.spawnPrefab);
		Items.RegisterShopItem(val2, val3, val4, val5, 750);
		Items.RegisterItem(val2);
		mls.LogInfo((object)"Jester Gun item successfully registered.");
	}
}