Decompiled source of KatanaScrap v0.2.0

KatanaMod.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
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("KatanaMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("KatanaMod")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("74e4fdeb-9304-4b8f-86c2-ec99e2c5dadb")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
public class SwordItem : GrabbableObject
{
	public AudioSource swordAudio;

	private List<RaycastHit> objectsHitBySwordList = new List<RaycastHit>();

	public PlayerControllerB previousPlayerHeldBy;

	private RaycastHit[] objectsHitBySword;

	public int swordHitForce;

	public AudioClip[] hitSFX;

	public AudioClip[] swingSFX;

	private int swordMask = 11012424;

	private float timeAtLastDamageDealt;

	public override void ItemActivate(bool used, bool buttonDown = true)
	{
		RoundManager.PlayRandomClip(swordAudio, swingSFX, true, 1f, 0, 1000);
		if ((Object)(object)base.playerHeldBy != (Object)null)
		{
			previousPlayerHeldBy = base.playerHeldBy;
			if (((NetworkBehaviour)base.playerHeldBy).IsOwner)
			{
				base.playerHeldBy.playerBodyAnimator.SetTrigger("UseHeldItem1");
			}
		}
		if (((NetworkBehaviour)this).IsOwner)
		{
			HitSword();
		}
	}

	public override void PocketItem()
	{
		((GrabbableObject)this).PocketItem();
	}

	public override void DiscardItem()
	{
		((GrabbableObject)this).DiscardItem();
	}

	public override void EquipItem()
	{
		((GrabbableObject)this).EquipItem();
	}

	public void HitSword(bool cancel = false)
	{
		//IL_005f: 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_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_034e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: 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_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0211: Unknown result type (might be due to invalid IL or missing references)
		//IL_0215: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0286: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0236: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)previousPlayerHeldBy == (Object)null)
		{
			Debug.LogError((object)"Previousplayerheldby is null on this client when HitSword is called.");
			return;
		}
		previousPlayerHeldBy.activatingItem = false;
		bool flag = false;
		bool flag2 = false;
		int num = -1;
		if (!cancel)
		{
			previousPlayerHeldBy.twoHanded = false;
			objectsHitBySword = Physics.SphereCastAll(((Component)previousPlayerHeldBy.gameplayCamera).transform.position + ((Component)previousPlayerHeldBy.gameplayCamera).transform.right * 0.1f, 0.8f, ((Component)previousPlayerHeldBy.gameplayCamera).transform.forward, 1.4f, swordMask, (QueryTriggerInteraction)2);
			objectsHitBySwordList = objectsHitBySword.OrderBy((RaycastHit x) => ((RaycastHit)(ref x)).distance).ToList();
			IHittable val2 = default(IHittable);
			for (int i = 0; i < objectsHitBySwordList.Count; i++)
			{
				RaycastHit val = objectsHitBySwordList[i];
				if (((Component)((RaycastHit)(ref val)).transform).gameObject.layer != 8)
				{
					val = objectsHitBySwordList[i];
					if (((Component)((RaycastHit)(ref val)).transform).gameObject.layer != 11)
					{
						val = objectsHitBySwordList[i];
						if (!((Component)((RaycastHit)(ref val)).transform).TryGetComponent<IHittable>(ref val2))
						{
							continue;
						}
						val = objectsHitBySwordList[i];
						if ((Object)(object)((RaycastHit)(ref val)).transform == (Object)(object)((Component)previousPlayerHeldBy).transform)
						{
							continue;
						}
						val = objectsHitBySwordList[i];
						if (!(((RaycastHit)(ref val)).point == Vector3.zero))
						{
							Vector3 position = ((Component)previousPlayerHeldBy.gameplayCamera).transform.position;
							RaycastHit val3 = objectsHitBySwordList[i];
							if (Physics.Linecast(position, ((RaycastHit)(ref val3)).point, ref val, StartOfRound.Instance.collidersAndRoomMaskAndDefault))
							{
								continue;
							}
						}
						flag = true;
						Vector3 forward = ((Component)previousPlayerHeldBy.gameplayCamera).transform.forward;
						try
						{
							if (Time.realtimeSinceStartup - timeAtLastDamageDealt > 0.43f)
							{
								timeAtLastDamageDealt = Time.realtimeSinceStartup;
								val2.Hit(swordHitForce, forward, previousPlayerHeldBy, true, 5);
							}
							flag2 = true;
						}
						catch (Exception arg)
						{
							Debug.Log((object)$"Exception caught when hitting object with sword from player #{previousPlayerHeldBy.playerClientId}: {arg}");
						}
						continue;
					}
				}
				flag = true;
				val = objectsHitBySwordList[i];
				string tag = ((Component)((RaycastHit)(ref val)).collider).gameObject.tag;
				for (int j = 0; j < StartOfRound.Instance.footstepSurfaces.Length; j++)
				{
					if (StartOfRound.Instance.footstepSurfaces[j].surfaceTag == tag)
					{
						num = j;
						break;
					}
				}
			}
		}
		if (flag)
		{
			RoundManager.PlayRandomClip(swordAudio, hitSFX, true, 1f, 0, 1000);
			Object.FindObjectOfType<RoundManager>().PlayAudibleNoise(((Component)this).transform.position, 17f, 0.8f, 0, false, 0);
			if (!flag2 && num != -1)
			{
				swordAudio.PlayOneShot(StartOfRound.Instance.footstepSurfaces[num].hitSurfaceSFX);
				WalkieTalkie.TransmitOneShotAudio(swordAudio, StartOfRound.Instance.footstepSurfaces[num].hitSurfaceSFX, 1f);
			}
			HitSwordServerRpc(num);
		}
	}

	[ServerRpc]
	public void HitSwordServerRpc(int hitSurfaceID)
	{
		HitSwordClientRpc(hitSurfaceID);
	}

	[ClientRpc]
	public void HitSwordClientRpc(int hitSurfaceID)
	{
		if (!((NetworkBehaviour)this).IsOwner)
		{
			RoundManager.PlayRandomClip(swordAudio, hitSFX, true, 1f, 0, 1000);
			if (hitSurfaceID != -1)
			{
				HitSurfaceWithSword(hitSurfaceID);
			}
		}
	}

	private void HitSurfaceWithSword(int hitSurfaceID)
	{
		swordAudio.PlayOneShot(StartOfRound.Instance.footstepSurfaces[hitSurfaceID].hitSurfaceSFX);
		WalkieTalkie.TransmitOneShotAudio(swordAudio, StartOfRound.Instance.footstepSurfaces[hitSurfaceID].hitSurfaceSFX, 1f);
	}
}
namespace KatanaMod;

[BepInPlugin("APM.KatanaMod", "KatanaItemMod", "0.1.0")]
public class Plugin : BaseUnityPlugin
{
	private const string GUID = "APM.KatanaMod";

	private const string NAME = "KatanaItemMod";

	private const string VERSION = "0.1.0";

	private const string GUID2 = "ainavt.lc.lethalconfig";

	public static Plugin instance;

	private static AssetBundle bundle;

	private static ConfigEntry<bool> config_KatanaModRarity;

	private static string[] DisableMoonsList = new string[1] { "None" };

	public static bool IsAvailable => Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig");

	private void Awake()
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Expected O, but got Unknown
		instance = this;
		((BaseUnityPlugin)this).Logger.LogInfo((object)("LethalConfig Available: " + IsAvailable));
		config_KatanaModRarity = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawn", "Enable Item Spawning", false, new ConfigDescription("Check this box to disable item spawning", (AcceptableValueBase)null, Array.Empty<object>()));
		string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "katanamod");
		bundle = AssetBundle.LoadFromFile(text);
		LoadScrap(text, "Assets/LethalCompany/Mods/Items/APKatana/KatanaItem.asset", "Katana", 35);
		Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "APM.KatanaMod");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded KatanaMod");
	}

	private void LoadScrap(string assetDir, string innerAssetPath, string name, int rarity)
	{
		//IL_0017: 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_0045: Expected O, but got Unknown
		//IL_0045: Expected O, but got Unknown
		ConfigEntry<int> val = ((BaseUnityPlugin)this).Config.Bind<int>(new ConfigDefinition("General", name + " Rarity"), rarity, new ConfigDescription("How often " + name + " will show up. Higher value means more common", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
		Item val2 = bundle.LoadAsset<Item>(innerAssetPath);
		NetworkPrefabs.RegisterNetworkPrefab(val2.spawnPrefab);
		Utilities.FixMixerGroups(val2.spawnPrefab);
		if (config_KatanaModRarity.Value)
		{
			Items.RegisterScrap(val2, val.Value, (LevelTypes)1, DisableMoonsList);
		}
		else
		{
			Items.RegisterScrap(val2, val.Value, (LevelTypes)(-1));
		}
		if (IsAvailable)
		{
			AddIntSlider(val, restartRequired: true);
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)(name + " Loaded, Rarity: " + val.Value));
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	public static void AddIntSlider(ConfigEntry<int> entry, bool restartRequired)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Expected O, but got Unknown
		LethalConfigManager.AddConfigItem((BaseConfigItem)new IntSliderConfigItem(entry, restartRequired));
	}
}