Decompiled source of Venture Debugger v0.0.3

Plugins/VentureValheim.VentureDebugger.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("VentureValheim.VentureDebugger")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VentureValheim.VentureDebugger")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("A82A5D10-06F4-4D15-B1FD-493801A89164")]
[assembly: AssemblyFileVersion("0.0.3")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.3.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace VentureValheim.VentureDebugger
{
	[BepInPlugin("com.orianaventure.mod.VentureDebugger", "VentureDebugger", "0.0.3")]
	public class VentureDebuggerPlugin : BaseUnityPlugin
	{
		private const string ModName = "VentureDebugger";

		private const string ModVersion = "0.0.3";

		private const string Author = "com.orianaventure.mod";

		private const string ModGUID = "com.orianaventure.mod.VentureDebugger";

		private readonly Harmony HarmonyInstance = new Harmony("com.orianaventure.mod.VentureDebugger");

		public static readonly ManualLogSource VentureDebuggerLogger = Logger.CreateLogSource("VentureDebugger");

		public void Awake()
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			HarmonyInstance.PatchAll(executingAssembly);
		}
	}
	public class VentureDebugger
	{
		[HarmonyPatch(typeof(Pickable), "UpdateRespawn")]
		public static class Patch_Pickable_UpdateRespawn
		{
			private static Exception Finalizer(Pickable __instance, Exception __exception)
			{
				if ((Object)(object)__instance != (Object)null && __exception != null)
				{
					VentureDebuggerPlugin.VentureDebuggerLogger.LogDebug((object)"Catching exception and fixing:");
					VentureDebuggerPlugin.VentureDebuggerLogger.LogDebug((object)__exception);
					DateTime time = ZNet.instance.GetTime();
					__instance.m_nview.GetZDO().Set(ZDOVars.s_pickedTime, time.Ticks);
				}
				return null;
			}
		}

		[HarmonyPatch(typeof(ZPlayFabMatchmaking), "CreateLobby")]
		public static class Patch_ZPlayFabMatchmaking_CreateLobby
		{
			private static void Prefix()
			{
				RemoveDuplicates(ref ZPlayFabMatchmaking.m_instance.m_serverData.modifiers);
			}
		}

		[HarmonyPatch(typeof(ZSteamMatchmaking), "RegisterServer")]
		public static class Patch_ZSteamMatchmaking_RegisterServer
		{
			private static void Prefix(ref List<string> modifiers)
			{
				RemoveDuplicates(ref modifiers);
			}
		}

		private static void RemoveDuplicates(ref List<string> keys)
		{
			if (keys == null)
			{
				return;
			}
			HashSet<string> hashSet = new HashSet<string>();
			foreach (string key in keys)
			{
				if (!hashSet.Contains(key))
				{
					hashSet.Add(key);
				}
				else
				{
					VentureDebuggerPlugin.VentureDebuggerLogger.LogWarning((object)("Found duplicate world modifier key " + key + ", fixing."));
				}
			}
			keys = hashSet.ToList();
		}
	}
}