Decompiled source of ChangeHostSlot v1.0.0

ChangeHostSlot.dll

Decompiled 8 months ago
using System;
using System.CodeDom.Compiler;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Hook;
using GTFO.API;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppInterop.Runtime.Runtime;
using Microsoft.CodeAnalysis;
using SNetwork;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ChangeHostSlot")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ChangeHostSlot")]
[assembly: AssemblyTitle("ChangeHostSlot")]
[assembly: TargetPlatform("Windows7.0")]
[assembly: SupportedOSPlatform("Windows7.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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 NativeIntegerAttribute : Attribute
	{
		public readonly bool[] TransformFlags;

		public NativeIntegerAttribute()
		{
			TransformFlags = new bool[1] { true };
		}

		public NativeIntegerAttribute(bool[] P_0)
		{
			TransformFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 ChangeHostSlot
{
	[BepInPlugin("HostSlot.GUID", "ChangeHostSlot", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class EntryPoint : BasePlugin
	{
		public override void Load()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			SlotConfig.CreateBind();
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(20, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Patching on slot ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(SlotConfig.Slot);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>((new string[4] { "Pink/Woods", "Green/Dauda", "Blue/Hackett", "Purple/Bishop" })[SlotConfig.Slot]);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
			}
			Logger.Info(val);
			Patch.ApplyNative();
			Logger.Info("Loaded successfully");
		}
	}
	internal static class Logger
	{
		private static readonly ManualLogSource _Logger;

		static Logger()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			_Logger = new ManualLogSource("ChangeHostSlot");
			Logger.Sources.Add((ILogSource)(object)_Logger);
		}

		private static string Format(object msg)
		{
			return msg.ToString();
		}

		public static void Info(BepInExInfoLogInterpolatedStringHandler handler)
		{
			_Logger.LogInfo(handler);
		}

		public static void Info(string str)
		{
			_Logger.LogMessage((object)str);
		}

		public static void Info(object data)
		{
			_Logger.LogMessage((object)Format(data));
		}

		public static void Debug(BepInExDebugLogInterpolatedStringHandler handler)
		{
			_Logger.LogDebug(handler);
		}

		public static void Debug(string str)
		{
			_Logger.LogDebug((object)str);
		}

		public static void Debug(object data)
		{
			_Logger.LogDebug((object)Format(data));
		}

		public static void Error(BepInExErrorLogInterpolatedStringHandler handler)
		{
			_Logger.LogError(handler);
		}

		public static void Error(string str)
		{
			_Logger.LogError((object)str);
		}

		public static void Error(object data)
		{
			_Logger.LogError((object)Format(data));
		}

		public static void Fatal(BepInExFatalLogInterpolatedStringHandler handler)
		{
			_Logger.LogFatal(handler);
		}

		public static void Fatal(string str)
		{
			_Logger.LogFatal((object)str);
		}

		public static void Fatal(object data)
		{
			_Logger.LogFatal((object)Format(data));
		}

		public static void Warn(BepInExWarningLogInterpolatedStringHandler handler)
		{
			_Logger.LogWarning(handler);
		}

		public static void Warn(string str)
		{
			_Logger.LogWarning((object)str);
		}

		public static void Warn(object data)
		{
			_Logger.LogWarning((object)Format(data));
		}

		[Conditional("DEBUG")]
		public static void DebugOnly(object data)
		{
			_Logger.LogDebug((object)Format(data));
		}
	}
	internal static class Patch
	{
		private unsafe delegate bool d_Internal_ManageSlot(nint _this, nint player, nint* pSlot, nint slots, SNet_SlotType type, SNet_SlotHandleType handle, int index, Il2CppMethodInfo* methodInfo);

		private static INativeDetour Internal_ManageSlotDetour;

		private static d_Internal_ManageSlot orig_Internal_ManageSlot;

		internal unsafe static void ApplyNative()
		{
			Internal_ManageSlotDetour = INativeDetour.CreateAndApply<d_Internal_ManageSlot>((IntPtr)(nint)Il2CppAPI.GetIl2CppMethod<SNet_PlayerSlotManager>("Internal_ManageSlot", "System.Boolean", false, new string[6]
			{
				"SNet_Player",
				"SNet_Slot",
				typeof(SNet_Slot).FullName,
				"SNet_SlotType",
				"SNet_SlotHandleType",
				"System.Int32"
			}), (d_Internal_ManageSlot)Internal_ManageSlotPatch, ref orig_Internal_ManageSlot);
		}

		public unsafe static bool Internal_ManageSlotPatch(nint _this_ptr, nint player_ptr, nint* pSlot, nint slots_ptr, SNet_SlotType type, SNet_SlotHandleType handle, int index, Il2CppMethodInfo* methodInfo)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Invalid comparison between Unknown and I4
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Invalid comparison between Unknown and I4
			SNet_PlayerSlotManager val = new SNet_PlayerSlotManager((IntPtr)_this_ptr);
			SNet_Player val2 = new SNet_Player((IntPtr)player_ptr);
			Il2CppReferenceArray<SNet_Slot> val3 = new Il2CppReferenceArray<SNet_Slot>((IntPtr)slots_ptr);
			if (val2.IsMaster && val2.IsLocal && (int)handle == 0)
			{
				int slot = SlotConfig.Slot;
				SNet_Slot val4 = ((Il2CppArrayBase<SNet_Slot>)(object)val3)[slot];
				val4.player = val2;
				if ((int)type == 0)
				{
					val2.PlayerSlot = val4;
				}
				else
				{
					val2.CharacterSlot = val4;
				}
				if (!val.SlottedPlayers.Contains(val2))
				{
					val.SlottedPlayers.Add(val2);
				}
				return true;
			}
			return orig_Internal_ManageSlot(_this_ptr, player_ptr, pSlot, slots_ptr, type, handle, index, methodInfo);
		}
	}
	public static class SlotConfig
	{
		public static int Slot;

		public static void CreateBind()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			BindSlot(new ConfigFile(Path.Combine(Paths.ConfigPath, "ChangeHostSlot.cfg"), true));
			if (Slot < 0 || Slot > 3)
			{
				Logger.Error("Slot option not in valid range (0-3), defaulting to 0");
				Slot = 0;
			}
		}

		private static void BindSlot(ConfigFile config)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_002f: Expected O, but got Unknown
			string text = "ChangeHostSlot";
			string text2 = "Slot";
			int num = 0;
			string text3 = "Slot to host in. 0 = Pink/Woods, 1 = Green/Dauda, 2 = Blue/Hackett, 3 = Purple/Bishop";
			Slot = config.Bind<int>(new ConfigDefinition(text, text2), num, new ConfigDescription(text3, (AcceptableValueBase)null, Array.Empty<object>())).Value;
		}
	}
	[GeneratedCode("VersionInfoGenerator", "2.1.3+git35c0c2a-master")]
	[CompilerGenerated]
	internal static class VersionInfo
	{
		public const string RootNamespace = "ChangeHostSlot";

		public const string Version = "1.0.0";

		public const string VersionPrerelease = null;

		public const string VersionMetadata = null;

		public const string SemVer = "1.0.0";

		public const string GitRevShort = null;

		public const string GitRevLong = null;

		public const string GitBranch = null;

		public const string GitTag = null;

		public const int GitCommitsSinceTag = 0;

		public const bool GitIsDirty = false;
	}
}