Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of AerodynamicLobsterDisconnectFix v1.0.0
BepInEx/plugins/asm.LobsterDisconnectFix/LobsterDisconnectFix.dll
Decompiled 5 months agousing 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.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Unity.Netcode; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")] [assembly: AssemblyCompany("LobsterDisconnectFix")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+9cb8e50c55a4ae05e0c6461fec53dcc365f1b2c6")] [assembly: AssemblyProduct("LobsterDisconnectFix")] [assembly: AssemblyTitle("LobsterDisconnectFix")] [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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace LobsterDisconnectFix { [BepInPlugin("LobsterDisconnectFix", "LobsterDisconnectFix", "1.0.0")] [HarmonyPatch] public class Plugin : BaseUnityPlugin { [HarmonyPatch(typeof(GameNetworkManager))] private static class GameNetworkManager_Patch { [HarmonyPatch("Singleton_OnClientDisconnectCallback")] [HarmonyPostfix] [HarmonyWrapSafe] private static void Singleton_OnClientDisconnectCallback_Postfix(GameNetworkManager __instance, ulong clientId) { if ((clientId == 0L || clientId == NetworkManager.Singleton.LocalClientId) && NetworkManager.Singleton.IsClient && !NetworkManager.Singleton.IsServer) { __instance.disconnectReason = 1; __instance.Disconnect(); } } } [HarmonyPatch(typeof(MenuManager))] private static class DisplayMenuNotification_Patch { [HarmonyPatch("DisplayMenuNotification")] [HarmonyPrefix] [HarmonyWrapSafe] private static void DisplayMenuNotification_Postfix(MenuManager __instance, string notificationText, string buttonText) { //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) Transform val = __instance.menuNotification.transform.Find("Panel"); Transform val2 = val.Find("LobsterImage"); GameObject val3 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).gameObject : null); if ((Object)(object)val3 == (Object)null) { if ((Object)(object)LobsterSprite == (Object)null) { Logger.LogWarning((object)"Sprite not loaded, skipping lobster."); return; } val3 = new GameObject("LobsterImage"); val3.transform.SetParent(val, false); Image obj = val3.AddComponent<Image>(); obj.sprite = LobsterSprite; obj.preserveAspect = true; ((Graphic)obj).raycastTarget = false; val3.AddComponent<LayoutElement>().ignoreLayout = true; RectTransform component = val3.GetComponent<RectTransform>(); component.anchorMin = new Vector2(0.5f, 1f); component.anchorMax = new Vector2(0.5f, 1f); component.pivot = new Vector2(0.5f, 0f); component.anchoredPosition = new Vector2(0f, 35f); component.sizeDelta = new Vector2(200f, 200f); if ((Object)(object)LobsterSound != (Object)null) { AudioSource val4 = val3.GetComponent<AudioSource>(); if ((Object)(object)val4 == (Object)null) { val4 = val3.AddComponent<AudioSource>(); } val4.clip = LobsterSound; val4.volume = 1f; } } if (GameNetworkManager.Instance.disconnectReason == 1) { AudioSource component2 = val3.GetComponent<AudioSource>(); if ((Object)(object)component2 != (Object)null) { component2.Play(); } val3.SetActive(true); } else { val3.SetActive(false); } } } internal static ManualLogSource Logger; internal static Harmony Harmony = new Harmony("LobsterDisconnectFix"); internal static Sprite LobsterSprite; internal static AudioClip LobsterSound; private void Awake() { Logger = ((BaseUnityPlugin)this).Logger; Logger.LogInfo((object)"Plugin LobsterDisconnectFix is loaded!"); LobsterSprite = LoadSpriteFromEmbeddedResource("lobster.png"); byte[] resourceBytes = GetResourceBytes("lobster.wav"); if (resourceBytes != null) { LobsterSound = WavUtility.ToAudioClip(resourceBytes, "LobsterMusic"); } Harmony.PatchAll(); } private static byte[] GetResourceBytes(string resourceName, string firstName = "LobsterDisconnectFix.Embedded") { try { using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(firstName + "." + resourceName); if (stream == null) { Logger.LogError((object)("Resource not found: " + resourceName)); return null; } byte[] array = new byte[stream.Length]; stream.Read(array, 0, (int)stream.Length); return array; } catch (Exception ex) { Logger.LogError((object)ex); return null; } } private static Sprite LoadSpriteFromEmbeddedResource(string resourceName, string firstName = "LobsterDisconnectFix.Embedded") { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) try { byte[] resourceBytes = GetResourceBytes(resourceName, firstName); Texture2D val = new Texture2D(2, 2); if (ImageConversion.LoadImage(val, resourceBytes)) { ((Texture)val).filterMode = (FilterMode)1; return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)); } } catch (Exception ex) { Logger.LogError((object)("Error loading sprite: " + ex.Message)); } return null; } } public static class WavUtility { public static AudioClip ToAudioClip(byte[] wavFile, string name = "wav") { int num = BitConverter.ToInt32(wavFile, 16); BitConverter.ToInt16(wavFile, 20); int num2 = BitConverter.ToInt16(wavFile, 22); int num3 = BitConverter.ToInt32(wavFile, 24); int num4 = BitConverter.ToInt16(wavFile, 34); int i; for (i = 20 + num; i < wavFile.Length; i++) { if (wavFile[i] == 100 && wavFile[i + 1] == 97 && wavFile[i + 2] == 116 && wavFile[i + 3] == 97) { i += 4; break; } } int num5 = BitConverter.ToInt32(wavFile, i); i += 4; float[] array = new float[num5 / (num4 / 8)]; int num6 = 0; switch (num4) { case 16: { for (int k = 0; k < array.Length; k++) { short num7 = BitConverter.ToInt16(wavFile, i + num6); array[k] = (float)num7 / 32768f; num6 += 2; } break; } case 8: { for (int l = 0; l < array.Length; l++) { array[l] = (float)(wavFile[i + num6] - 128) / 128f; num6++; } break; } case 32: { for (int j = 0; j < array.Length; j++) { array[j] = BitConverter.ToSingle(wavFile, i + num6); num6 += 4; } break; } } AudioClip obj = AudioClip.Create(name, array.Length / num2, num2, num3, false); obj.SetData(array, 0); return obj; } } public static class MyPluginInfo { public const string PLUGIN_GUID = "LobsterDisconnectFix"; public const string PLUGIN_NAME = "LobsterDisconnectFix"; public const string PLUGIN_VERSION = "1.0.0"; } }