Decompiled source of Fixes v1.0.0

BepInEx/plugins/DiceModders.Fixes.dll

Decompiled 9 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using DiceModders.ModCore;
using DiceModders.ModCore.Tools;
using Fivemid.FiveTime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem;
using MLAPI;
using MLAPI.Configuration;
using MLAPI.Transports;
using Microsoft.CodeAnalysis;
using Steamworks;
using Steamworks.Data;
using UnityEngine;
using Utility.Steamworks;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("DiceModders")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Fixes for bugs of Dice Kingdoms itself: rejoining after the host left, joining with a wrong PC clock.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DiceModders.Fixes")]
[assembly: AssemblyTitle("DiceModders.Fixes")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DiceModders.Fixes
{
	internal static class ClockFix
	{
		private static readonly TimeSpan Tolerance = TimeSpan.FromSeconds(2.0);

		internal static void Install(Patcher patcher)
		{
			patcher.Patch(typeof(SteamClient), "Init", typeof(ClockFix), (string)null, "SteamInitPostfix");
		}

		internal static void SteamInitPostfix()
		{
			Apply();
		}

		internal static void Apply()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			try
			{
				if (!Plugin.On || !SteamClient.IsValid || FiveTime.deltaTimeTicks != 0L)
				{
					return;
				}
				DateTime val = SteamUtils.SteamServerTime;
				long ticks = ((DateTime)(ref val)).Ticks;
				val = DateTime.UtcNow;
				long ticks2 = ((DateTime)(ref val)).Ticks;
				TimeSpan timeSpan = TimeSpan.FromTicks(ticks - ticks2);
				if (!(timeSpan.Duration() < Tolerance))
				{
					FiveTime.deltaTimeTicks = timeSpan.Ticks;
					ManualLogSource l = Plugin.L;
					bool flag = default(bool);
					BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(76, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[clock] no internet time yet; the PC clock is ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<double>(timeSpan.TotalSeconds, "0");
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" s off Steam's time, corrected");
					}
					l.LogInfo(val2);
				}
			}
			catch (Exception ex)
			{
				Plugin.L.LogWarning((object)("[clock] " + ex.Message));
			}
		}
	}
	internal static class LobbyOwner
	{
		internal static void Install()
		{
			Match.Started += delegate
			{
				Check("match started");
			};
			Match.Rejoined += delegate
			{
				Check("match joined again");
			};
			Lobby.Changed += delegate
			{
				Check("lobby changed");
			};
		}

		internal static void Check(string why)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Expected O, but got Unknown
			try
			{
				if (!Plugin.On)
				{
					return;
				}
				Lobby? current = Lobby.Current;
				if (!current.HasValue || !SteamClient.IsValid)
				{
					return;
				}
				NetworkingManager singleton = NetworkingManager.Singleton;
				if ((Object)(object)singleton == (Object)null || singleton.IsServer || !singleton.IsConnectedClient)
				{
					return;
				}
				NetworkConfig networkConfig = singleton.NetworkConfig;
				object obj;
				if (networkConfig == null)
				{
					obj = null;
				}
				else
				{
					Transport networkTransport = networkConfig.NetworkTransport;
					obj = ((networkTransport != null) ? ((Il2CppObjectBase)networkTransport).TryCast<SteamworksTransport>() : null);
				}
				SteamworksTransport val = (SteamworksTransport)obj;
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				ulong connectToSteamId = val.connectToSteamId;
				ulong value = SteamClient.SteamId.Value;
				if (connectToSteamId == 0L || connectToSteamId == value)
				{
					return;
				}
				Lobby value2 = current.Value;
				if (!((Lobby)(ref value2)).IsOwnedBy(SteamClient.SteamId))
				{
					return;
				}
				bool flag = false;
				foreach (LobbyMember member in Lobby.Members)
				{
					LobbyMember current2 = member;
					if (((LobbyMember)(ref current2)).SteamId == connectToSteamId)
					{
						flag = true;
						break;
					}
				}
				if (flag)
				{
					((Lobby)(ref value2)).Owner = new Friend(SteamId.op_Implicit(connectToSteamId));
					ManualLogSource l = Plugin.L;
					bool flag2 = default(bool);
					BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(84, 2, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[lobby] handed the lobby to the host ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<ulong>(connectToSteamId);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" (");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(why);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("), so its keep-alive keeps the match joinable");
					}
					l.LogInfo(val2);
				}
			}
			catch (Exception ex)
			{
				Plugin.L.LogWarning((object)("[lobby] owner check: " + ex.Message));
			}
		}
	}
	[BepInPlugin("org.dicemodders.dicekingdoms.fixes", "DiceKingdoms Fixes", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("Dice-Kingdoms.exe")]
	public sealed class Plugin : BasePlugin
	{
		public const string Guid = "org.dicemodders.dicekingdoms.fixes";

		public const string Name = "DiceKingdoms Fixes";

		public const string Version = "1.0.0";

		internal static ManualLogSource L;

		internal static bool On;

		public override void Load()
		{
			//IL_0016: 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_0026: Expected O, but got Unknown
			L = ((BasePlugin)this).Log;
			Patcher val = new Patcher("org.dicemodders.dicekingdoms.fixes", ((BasePlugin)this).Log);
			LobbyOwner.Install();
			ClockFix.Install(val);
			val.Summary();
			Mods.Switch(((BasePlugin)this).Config, false, false, "Turns every fix of this mod on or off.").WhenOn((Action)delegate
			{
				On = true;
				LobbyOwner.Check("switched on");
				ClockFix.Apply();
			}, (Action)delegate
			{
				On = false;
			});
		}
	}
}