Decompiled source of TimeoutLimit v0.1.0

TimeoutLimit.dll

Decompiled a year ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
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: AssemblyTitle("TimeoutLimit")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TimeoutLimit")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("FE8B42E3-7082-4DFF-A5CC-6B62B0315ACA")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace TimeoutLimit;

public static class CodeMatcherExtensions
{
	public static CodeMatcher GetPosition(this CodeMatcher codeMatcher, out int position)
	{
		position = codeMatcher.Pos;
		return codeMatcher;
	}

	public static CodeMatcher AddLabel(this CodeMatcher codeMatcher, out Label label)
	{
		label = default(Label);
		codeMatcher.AddLabels((IEnumerable<Label>)new Label[1] { label });
		return codeMatcher;
	}

	public static CodeMatcher GetLabels(this CodeMatcher codeMatcher, out List<Label> label)
	{
		label = codeMatcher.Labels;
		return codeMatcher;
	}

	public static CodeMatcher GetOperand(this CodeMatcher codeMatcher, out object operand)
	{
		operand = codeMatcher.Operand;
		return codeMatcher;
	}

	internal static CodeMatcher Print(this CodeMatcher codeMatcher, int before, int after)
	{
		for (int i = -before; i <= after; i++)
		{
			int num = i;
			int num2 = codeMatcher.Pos + num;
			if (num2 > 0)
			{
				if (num2 >= codeMatcher.Length)
				{
					break;
				}
				try
				{
					CodeInstruction val = codeMatcher.InstructionAt(num);
					Debug.Log((object)($"[{num}] " + ((object)val).ToString()));
				}
				catch (Exception ex)
				{
					Debug.Log((object)ex.Message);
				}
			}
		}
		return codeMatcher;
	}

	public static bool IsVirtCall(this CodeInstruction i, string declaringType, string name)
	{
		return i.opcode == OpCodes.Callvirt && i.operand is MethodInfo methodInfo && methodInfo.DeclaringType?.Name == declaringType && methodInfo.Name == name;
	}
}
[BepInPlugin("com.maxsch.valheim.TimeoutLimit", "TimeoutLimit", "1.0.0")]
[HarmonyPatch]
public class Plugin : BaseUnityPlugin
{
	public const string ModName = "TimeoutLimit";

	public const string ModGuid = "com.maxsch.valheim.TimeoutLimit";

	public const string ModVersion = "1.0.0";

	private static ConfigEntry<float> Timeout { get; set; }

	private void Awake()
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		Timeout = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Timeout", 90f, "Timeout in seconds");
		Harmony val = new Harmony("com.maxsch.valheim.TimeoutLimit");
		val.PatchAll();
	}

	[HarmonyPatch(typeof(ZRpc), "SetLongTimeout")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> SetLongTimeoutTranspiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Expected O, but got Unknown
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Expected O, but got Unknown
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		CodeMatch[] array = (CodeMatch[])(object)new CodeMatch[2]
		{
			new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)null, (string)null),
			new CodeMatch((OpCode?)OpCodes.Stsfld, (object)null, (string)null)
		};
		CodeInstruction[] array2 = (CodeInstruction[])(object)new CodeInstruction[2]
		{
			new CodeInstruction(OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(Plugin), "Timeout")),
			new CodeInstruction(OpCodes.Callvirt, (object)AccessTools.PropertyGetter(typeof(ConfigEntry<float>), "Value"))
		};
		List<Label> label;
		return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, array).RemoveInstructions(1).InsertAndAdvance(array2)
			.MatchForward(false, array)
			.GetLabels(out label)
			.RemoveInstructions(1)
			.Insert(array2)
			.AddLabels((IEnumerable<Label>)label)
			.InstructionEnumeration();
	}
}