Decompiled source of Meadhall Chronicles v1.0.1

plugins/Meadhall Chronicles.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
[BepInPlugin("com.yourname.MeadhallChronicles", "Sword Stab Tuner", "1.0.0")]
public class SwordStabTuner : BaseUnityPlugin
{
	[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
	private static class ODB_CopyOtherDB_Patch
	{
		private static void Postfix(ObjectDB __instance)
		{
			ApplyToAllSwords(__instance, "ObjectDB.CopyOtherDB");
		}
	}

	[HarmonyPatch(typeof(ZNetScene), "Awake")]
	private static class ZNetScene_Awake_Patch
	{
		private static void Postfix()
		{
			if ((Object)(object)ObjectDB.instance != (Object)null)
			{
				ApplyToAllSwords(ObjectDB.instance, "ZNetScene.Awake");
			}
		}
	}

	[CompilerGenerated]
	private sealed class <ApplySoon>d__4 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public SwordStabTuner <>4__this;

		private int <i>5__1;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <ApplySoon>d__4(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<i>5__1 = 0;
				break;
			case 1:
				<>1__state = -1;
				<i>5__1++;
				break;
			}
			if (<i>5__1 < 90 && !((Object)(object)ObjectDB.instance != (Object)null))
			{
				<>2__current = null;
				<>1__state = 1;
				return true;
			}
			if ((Object)(object)ObjectDB.instance != (Object)null)
			{
				ApplyToAllSwords(ObjectDB.instance, "[ApplySoon]");
			}
			return false;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	private const float SecondaryMultiplier = 2.3f;

	private Harmony _harmony;

	private void Awake()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		_harmony = new Harmony("com.yourname.SwordStabTuner");
		_harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)("[SwordStabTuner] Loaded (stab-only). Multiplier = " + 2.3f));
		((MonoBehaviour)this).StartCoroutine(ApplySoon());
	}

	private void OnDestroy()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}

	[IteratorStateMachine(typeof(<ApplySoon>d__4))]
	private IEnumerator ApplySoon()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <ApplySoon>d__4(0)
		{
			<>4__this = this
		};
	}

	private static void ApplyToAllSwords(ObjectDB db, string reason)
	{
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Invalid comparison between Unknown and I4
		ManualLogSource val = Logger.CreateLogSource("SwordStabTuner");
		if ((Object)(object)db == (Object)null)
		{
			val.LogInfo((object)"[SwordStabTuner] ObjectDB is null; cannot apply.");
			return;
		}
		int num = 0;
		foreach (GameObject item in db.m_items)
		{
			if (!Object.op_Implicit((Object)(object)item))
			{
				continue;
			}
			ItemDrop component = item.GetComponent<ItemDrop>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				continue;
			}
			SharedData val2 = component.m_itemData?.m_shared;
			if (val2 != null && (int)val2.m_skillType == 1)
			{
				Attack secondaryAttack = val2.m_secondaryAttack;
				if (secondaryAttack != null)
				{
					secondaryAttack.m_damageMultiplier = 2.3f;
					num++;
				}
			}
		}
		val.LogInfo((object)$"[SwordStabTuner] Applied to {num} sword(s). Reason={reason}. Stab multiplier={2.3f}");
	}
}
namespace Meadhall_Chronicles;

public class Class1
{
}