Decompiled source of Tubby Semibots v1.0.0

SlenderSemi.dll

Decompiled 2 months ago
using System;
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SlenderSemi")]
[assembly: AssemblyTitle("SlenderSemi")]
[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 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;
		}
	}
	[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 Empress.CheesewhizAvatar
{
	[BepInPlugin("empress.repo.cheesewhizavatar", "Cheesewhiz Player Avatar Replacer", "1.0.0")]
	public class CheesewhizAvatarPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "empress.repo.cheesewhizavatar";

		public const string PluginName = "Cheesewhiz Player Avatar Replacer";

		public const string PluginVersion = "1.0.0";

		private Harmony _harmony;

		private static AssetBundle _bundle;

		private static GameObject _avatarPrefab;

		private static ConfigEntry<bool> _enabled;

		private static ConfigEntry<string> _bundleFileName;

		private static ConfigEntry<string> _prefabName;

		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable replacing the Player Avatar with the prefab from the cheesewhiz asset bundle.");
			_bundleFileName = ((BaseUnityPlugin)this).Config.Bind<string>("General", "BundleFile", "cheesewhiz", "AssetBundle filename sitting next to this DLL (no extension needed).");
			_prefabName = ((BaseUnityPlugin)this).Config.Bind<string>("General", "PrefabName", "PlayerAvatar", "Prefab name inside the asset bundle to use as the player avatar.");
			Log = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("empress.repo.cheesewhizavatar");
			_harmony.PatchAll(typeof(CheesewhizAvatarPlugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Cheesewhiz Player Avatar Replacer 1.0.0 loaded.");
		}

		private void OnDestroy()
		{
			try
			{
				Harmony harmony = _harmony;
				if (harmony != null)
				{
					harmony.UnpatchSelf();
				}
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)$"Failed to unpatch: {arg}");
			}
			if ((Object)(object)_bundle != (Object)null)
			{
				_bundle.Unload(false);
				_bundle = null;
			}
		}

		internal static bool TryPreparePrefab(out GameObject prefab)
		{
			prefab = null;
			if (!_enabled.Value)
			{
				Log.LogInfo((object)"Cheesewhiz replacement disabled by config.");
				return false;
			}
			if ((Object)(object)_avatarPrefab != (Object)null)
			{
				prefab = _avatarPrefab;
				return true;
			}
			string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? Paths.PluginPath;
			string[] array = new string[3]
			{
				Path.Combine(path, _bundleFileName.Value),
				Path.Combine(path, _bundleFileName.Value + ".bundle"),
				Path.Combine(path, _bundleFileName.Value + ".assetbundle")
			};
			string text = null;
			string[] array2 = array;
			foreach (string text2 in array2)
			{
				if (File.Exists(text2))
				{
					text = text2;
					break;
				}
			}
			if (string.IsNullOrEmpty(text))
			{
				Log.LogError((object)("AssetBundle not found next to DLL. Looked for: " + string.Join(", ", array)));
				return false;
			}
			try
			{
				_bundle = AssetBundle.LoadFromFile(text);
				if ((Object)(object)_bundle == (Object)null)
				{
					Log.LogError((object)("Failed to load AssetBundle at '" + text + "'."));
					return false;
				}
				GameObject val = _bundle.LoadAsset<GameObject>(_prefabName.Value);
				if ((Object)(object)val == (Object)null)
				{
					Log.LogError((object)("Prefab '" + _prefabName.Value + "' not found inside AssetBundle '" + Path.GetFileName(text) + "'."));
					return false;
				}
				((Object)val).name = _prefabName.Value;
				_avatarPrefab = val;
				prefab = _avatarPrefab;
				Log.LogInfo((object)("Loaded avatar prefab '" + ((Object)val).name + "' from '" + Path.GetFileName(text) + "'."));
				return true;
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Exception while loading AssetBundle/prefab: {arg}");
				return false;
			}
		}
	}
	[HarmonyPatch(typeof(NetworkManager), "Start")]
	public static class Patch_NetworkManager_Start
	{
		private static void Prefix(NetworkManager __instance)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			if (!CheesewhizAvatarPlugin.TryPreparePrefab(out GameObject prefab))
			{
				return;
			}
			try
			{
				IPunPrefabPool prefabPool = PhotonNetwork.PrefabPool;
				DefaultPool val = (DefaultPool)(object)((prefabPool is DefaultPool) ? prefabPool : null);
				if (val == null)
				{
					val = (DefaultPool)(object)(PhotonNetwork.PrefabPool = (IPunPrefabPool)new DefaultPool());
				}
				if (val.ResourceCache.ContainsKey(((Object)prefab).name))
				{
					val.ResourceCache[((Object)prefab).name] = prefab;
				}
				else
				{
					val.ResourceCache.Add(((Object)prefab).name, prefab);
				}
				CheesewhizAvatarPlugin.Log.LogInfo((object)("Photon DefaultPool mapped '" + ((Object)prefab).name + "' to cheesewhiz prefab."));
			}
			catch (Exception arg)
			{
				CheesewhizAvatarPlugin.Log.LogError((object)$"Failed to register prefab in Photon DefaultPool: {arg}");
			}
		}
	}
}
namespace SlenderSemi
{
	[BepInPlugin("Omniscye.SlenderSemi", "SlenderSemi", "1.0")]
	public class SlenderSemi : BaseUnityPlugin
	{
		internal static SlenderSemi Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		internal void Patch()
		{
			//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_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
		}
	}
}