Decompiled source of LegacyModPatches v0.0.2

LegacyModPatches.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
using XIVitems;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("LegacyModPatches")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LegacyModPatches")]
[assembly: AssemblyTitle("LegacyModPatches")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace LegacyModPatches;

[BepInPlugin("yourname.LegacyModPatches", "Legacy Mod Patches", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	private void Awake()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		new Harmony("yourname.LegacyModPatches").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Legacy Mod Patches loaded");
	}
}
[HarmonyPatch(typeof(StartOfRound), "Start")]
internal class PatchStartingTeleporter
{
	private const string TELEPORTER_NAME = "Teleporter";

	private const string INVERSE_NAME = "Inverse Teleporter";

	private static void Postfix(StartOfRound __instance)
	{
		if (!((NetworkBehaviour)__instance).IsHost)
		{
			return;
		}
		int num = -1;
		int num2 = -1;
		for (int i = 0; i < __instance.unlockablesList.unlockables.Count; i++)
		{
			string text = __instance.unlockablesList.unlockables[i].unlockableName.ToLower();
			if (text == "Teleporter".ToLower())
			{
				num = i;
			}
			else if (text == "Inverse Teleporter".ToLower())
			{
				num2 = i;
			}
		}
		if (num != -1)
		{
			TryUnlock(__instance, num, "Teleporter");
		}
		if (num2 != -1)
		{
			TryUnlock(__instance, num2, "Inverse Teleporter");
		}
	}

	private static void TryUnlock(StartOfRound instance, int id, string itemName)
	{
		try
		{
			MethodInfo method = ((object)instance).GetType().GetMethod("UnlockShipObject", BindingFlags.Instance | BindingFlags.NonPublic);
			if (method == null)
			{
				Logger.CreateLogSource("LegacyModPatches").LogError((object)"[StartingTeleporter fix] UnlockShipObject method not found — game version mismatch?");
				return;
			}
			method.Invoke(instance, new object[1] { id });
			((object)instance).GetType().GetMethod("SyncShipUnlockablesServerRpc", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.Invoke(instance, null);
			Logger.CreateLogSource("LegacyModPatches").LogInfo((object)$"[StartingTeleporter fix] Granted: {itemName} (ID {id})");
		}
		catch (Exception arg)
		{
			Logger.CreateLogSource("LegacyModPatches").LogError((object)$"[StartingTeleporter fix] Failed to grant {itemName}: {arg}");
		}
	}
}
public class FireBallRelay : NetworkBehaviour
{
	public static FireBallRelay Instance { get; private set; }

	private void Awake()
	{
		Instance = this;
		Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
	}

	[ServerRpc(RequireOwnership = false)]
	public void RequestFireBallServerRpc(NetworkObjectReference staffRef, Vector3 startPos, Vector3 startRot)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		BroadcastFireBallClientRpc(staffRef, startPos, startRot);
	}

	[ClientRpc]
	private void BroadcastFireBallClientRpc(NetworkObjectReference staffRef, Vector3 startPos, Vector3 startRot)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		NetworkObject val = default(NetworkObject);
		if (((NetworkObjectReference)(ref staffRef)).TryGet(ref val, (NetworkManager)null))
		{
			TwoHandWithProjectile component = ((Component)val).GetComponent<TwoHandWithProjectile>();
			if ((Object)(object)component != (Object)null)
			{
				component.ShootFireBall(startPos, startRot);
			}
		}
	}
}
[HarmonyPatch(typeof(GameNetworkManager), "Start")]
internal class PatchSpawnRelay
{
	private static void Postfix()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Expected O, but got Unknown
		if ((Object)(object)FireBallRelay.Instance == (Object)null)
		{
			GameObject val = new GameObject("LegacyModPatches_FireBallRelay");
			NetworkObject val2 = val.AddComponent<NetworkObject>();
			val.AddComponent<FireBallRelay>();
			NetworkManager.Singleton.AddNetworkPrefab(val);
			if (NetworkManager.Singleton.IsServer)
			{
				val2.Spawn(true);
			}
		}
	}
}
[HarmonyPatch(typeof(TwoHandWithProjectile), "ItemActivate")]
internal class PatchItemActivate
{
	private static bool Prefix(TwoHandWithProjectile __instance, bool used, bool buttonDown)
	{
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Expected O, but got Unknown
		if ((Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)null)
		{
			return false;
		}
		__instance.isHoldingButton = buttonDown;
		if (!__instance.reelingUp && buttonDown)
		{
			__instance.reelingUp = true;
			AccessTools.Field(typeof(TwoHandWithProjectile), "previousPlayerHeldBy").SetValue(__instance, ((GrabbableObject)__instance).playerHeldBy);
			Coroutine val = (Coroutine)AccessTools.Field(typeof(TwoHandWithProjectile), "reelingUpCoroutine").GetValue(__instance);
			if (val != null)
			{
				((MonoBehaviour)__instance).StopCoroutine(val);
			}
			Coroutine value = ((MonoBehaviour)__instance).StartCoroutine(FixedReelUpStaff(__instance));
			AccessTools.Field(typeof(TwoHandWithProjectile), "reelingUpCoroutine").SetValue(__instance, value);
		}
		return false;
	}

	private static IEnumerator FixedReelUpStaff(TwoHandWithProjectile instance)
	{
		PlayerControllerB previousPlayerHeldBy = (PlayerControllerB)AccessTools.Field(typeof(TwoHandWithProjectile), "previousPlayerHeldBy").GetValue(instance);
		((GrabbableObject)instance).playerHeldBy.activatingItem = true;
		((GrabbableObject)instance).playerHeldBy.twoHanded = true;
		((GrabbableObject)instance).playerHeldBy.playerBodyAnimator.ResetTrigger("shovelHit");
		((GrabbableObject)instance).playerHeldBy.playerBodyAnimator.SetBool("reelingUp", true);
		instance.staffAudio.PlayOneShot(instance.reelUp);
		instance.ReelUpSFXServerRpc();
		yield return (object)new WaitForSeconds(0.35f);
		yield return (object)new WaitUntil((Func<bool>)(() => !instance.isHoldingButton || !((GrabbableObject)instance).isHeld));
		instance.SwingStaff(!((GrabbableObject)instance).isHeld);
		yield return (object)new WaitForSeconds(0.13f);
		yield return (object)new WaitForEndOfFrame();
		if (((NetworkBehaviour)instance).IsServer)
		{
			instance.ShootFireBallClientRpc(instance.startTransform.transform.position, instance.startTransform.transform.eulerAngles);
		}
		else if ((Object)(object)FireBallRelay.Instance != (Object)null)
		{
			FireBallRelay.Instance.RequestFireBallServerRpc(NetworkObjectReference.op_Implicit(((NetworkBehaviour)instance).NetworkObject), instance.startTransform.transform.position, instance.startTransform.transform.eulerAngles);
		}
		yield return (object)new WaitForSeconds(0.3f);
		instance.reelingUp = false;
		AccessTools.Field(typeof(TwoHandWithProjectile), "reelingUpCoroutine").SetValue(instance, null);
		previousPlayerHeldBy.activatingItem = false;
		previousPlayerHeldBy.twoHanded = false;
	}
}
[HarmonyPatch(typeof(TwoHandWithProjectile), "StartExplosion")]
internal class PatchStartExplosion
{
	private static bool Prefix(TwoHandWithProjectile __instance, Vector3 explosionPosition, Vector3 forwardRotation, bool calledByClient)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		if (((NetworkBehaviour)__instance).IsServer)
		{
			ExplosionHelper.FixedSetExplosion(__instance, explosionPosition, forwardRotation);
		}
		else if (calledByClient)
		{
			ExplosionHelper.FixedSetExplosion(__instance, explosionPosition, forwardRotation);
		}
		return false;
	}
}
internal static class ExplosionHelper
{
	public static void FixedSetExplosion(TwoHandWithProjectile instance, Vector3 explosionPosition, Vector3 forwardRotation)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: 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_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		float num = ((Vector3.Distance(((Component)GameNetworkManager.Instance.localPlayerController).transform.position, explosionPosition - forwardRotation * 0.1f) < 8f) ? 65f : 35f);
		Landmine.SpawnExplosion(explosionPosition - forwardRotation * 0.1f, true, 1f, 7f, 30, num, instance.explosionPrefab, false);
		((Component)instance.explosionAudio).transform.position = explosionPosition + Vector3.up * 0.5f;
		RoundManager.PlayRandomClip(instance.explosionAudio, instance.largeExplosionSFX, true, 1f, 0, 1000);
	}
}