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 Sunflowered v1.0.1
Sunflowered.dll
Decompiled 7 months agousing System; using System.Collections; using System.Collections.Generic; 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 GameNetcodeStuff; using HarmonyLib; using LethalLib.Modules; using Microsoft.CodeAnalysis; using Sunflowered; using Sunflowered.NetcodePatcher; using Unity.Mathematics; using Unity.Netcode; 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: AssemblyCompany("Sunflowered")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.1.0")] [assembly: AssemblyInformationalVersion("1.0.1+46800a7ce8d9dd13b6bd4ade45d02bf9dbf6e181")] [assembly: AssemblyProduct("Sunflowered")] [assembly: AssemblyTitle("Sunflowered")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.1.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] [module: NetcodePatchedAssembly] 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; } } } public class FlowerManager : NetworkBehaviour { public PlayerControllerB? Controller; public GameObject? FlowerInstance; [ClientRpc] public void SpawnFlowerClientRpc() { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Invalid comparison between Unknown and I4 //IL_005f: 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_006d: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: 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) //IL_0109: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager; if (networkManager == null || !networkManager.IsListening) { return; } if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost)) { ClientRpcParams val = default(ClientRpcParams); FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(4182626042u, val, (RpcDelivery)0); ((NetworkBehaviour)this).__endSendClientRpc(ref val2, 4182626042u, val, (RpcDelivery)0); } if ((int)base.__rpc_exec_stage != 1 || (!networkManager.IsClient && !networkManager.IsHost)) { return; } base.__rpc_exec_stage = (__RpcExecStage)0; if ((Object)(object)FlowerInstance == (Object)null && (Object)(object)Controller != (Object)null) { FlowerInstance = Object.Instantiate<GameObject>(global::Sunflowered.Sunflowered.Instance.flowerprefab, ((Component)Controller).transform.position, quaternion.op_Implicit(quaternion.identity)); NetworkObject component = FlowerInstance.GetComponent<NetworkObject>(); if ((Object)(object)component != (Object)null) { component.Spawn(false); } } } [ClientRpc] public void DeSpawnFlowerClientRpc() { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Invalid comparison between Unknown and I4 //IL_005f: 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_006d: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager; if (networkManager == null || !networkManager.IsListening) { return; } if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost)) { ClientRpcParams val = default(ClientRpcParams); FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3563514973u, val, (RpcDelivery)0); ((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3563514973u, val, (RpcDelivery)0); } if ((int)base.__rpc_exec_stage != 1 || (!networkManager.IsClient && !networkManager.IsHost)) { return; } base.__rpc_exec_stage = (__RpcExecStage)0; if (!((Object)(object)FlowerInstance != (Object)null)) { return; } if (((GrabbableObject)FlowerInstance.GetComponent<PhysicsProp>()).isHeld) { ((GrabbableObject)FlowerInstance.GetComponent<PhysicsProp>()).playerHeldBy.DropAllHeldItemsAndSync(); } if (((NetworkBehaviour)this).IsServer) { NetworkObject component = FlowerInstance.GetComponent<NetworkObject>(); if ((Object)(object)component != (Object)null) { component.Despawn(true); } } Object.Destroy((Object)(object)FlowerInstance); } protected override void __initializeVariables() { ((NetworkBehaviour)this).__initializeVariables(); } protected override void __initializeRpcs() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown ((NetworkBehaviour)this).__registerRpc(4182626042u, new RpcReceiveHandler(__rpc_handler_4182626042), "SpawnFlowerClientRpc"); ((NetworkBehaviour)this).__registerRpc(3563514973u, new RpcReceiveHandler(__rpc_handler_3563514973), "DeSpawnFlowerClientRpc"); ((NetworkBehaviour)this).__initializeRpcs(); } private static void __rpc_handler_4182626042(NetworkBehaviour? target, FastBufferReader reader, __RpcParams rpcParams) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = target.NetworkManager; if (networkManager != null && networkManager.IsListening) { target.__rpc_exec_stage = (__RpcExecStage)1; ((FlowerManager)(object)target).SpawnFlowerClientRpc(); target.__rpc_exec_stage = (__RpcExecStage)0; } } private static void __rpc_handler_3563514973(NetworkBehaviour? target, FastBufferReader reader, __RpcParams rpcParams) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = target.NetworkManager; if (networkManager != null && networkManager.IsListening) { target.__rpc_exec_stage = (__RpcExecStage)1; ((FlowerManager)(object)target).DeSpawnFlowerClientRpc(); target.__rpc_exec_stage = (__RpcExecStage)0; } } [MethodImpl(MethodImplOptions.NoInlining)] protected internal override string? __getTypeName() { return "FlowerManager"; } } public class SunflowerItem : GrabbableObject { public override void EquipItem() { ((GrabbableObject)this).EquipItem(); } protected override void __initializeVariables() { ((GrabbableObject)this).__initializeVariables(); } protected override void __initializeRpcs() { ((GrabbableObject)this).__initializeRpcs(); } [MethodImpl(MethodImplOptions.NoInlining)] protected internal override string __getTypeName() { return "SunflowerItem"; } } namespace Sunflowered { public static class AssetLoader { private static AssetBundle? _assetBundle; public static AssetBundle LoadAssetBundle() { if ((Object)(object)_assetBundle == (Object)null) { string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (directoryName == null) { throw new InvalidOperationException("Unable to determine assembly location."); } string text = Path.Combine(directoryName, "sunfloweredassets"); _assetBundle = AssetBundle.LoadFromFile(text); if ((Object)(object)_assetBundle == (Object)null) { throw new InvalidOperationException("Failed to load Sunflowered AssetBundle."); } } return _assetBundle; } public static T LoadAsset<T>(string assetName) where T : Object { if (!assetName.EndsWith(".asset") && !assetName.EndsWith(".prefab") && !assetName.EndsWith(".wav") && !assetName.EndsWith(".mat") && !assetName.EndsWith(".ogg") && !assetName.EndsWith(".mp3") && !assetName.EndsWith(".mp4") && !assetName.EndsWith(".anim") && !assetName.EndsWith(".png")) { assetName += ".asset"; } AssetBundle val = LoadAssetBundle(); T val2 = val.LoadAsset<T>(assetName); if (!val.Contains(assetName)) { throw new InvalidOperationException("Asset not found in bundle: " + assetName); } if ((Object)(object)val2 == (Object)null) { throw new InvalidOperationException("Failed to load asset: " + assetName + ". Asset exists in bundle but couldn't be loaded."); } return val2; } } [HarmonyPatch(typeof(GameNetworkManager))] internal class GameNetworkManagerPatch { public static bool HasInitalized; [HarmonyPatch("Start")] [HarmonyPostfix] public static void Init() { if (HasInitalized) { Sunflowered.Logger.LogWarning((object)"Already initalized Sunflowermod!!"); return; } if ((Object)(object)Sunflowered.Instance.flowerprefab != (Object)null) { NetworkManager.Singleton.AddNetworkPrefab(Sunflowered.Instance.flowerprefab); Sunflowered.Logger.LogInfo((object)"Added flower.prefab to network prefabs!"); } else { Sunflowered.Logger.LogError((object)"Failed to load flower.prefab!"); } if ((Object)(object)Sunflowered.Instance.FlowerManagerPre != (Object)null) { NetworkManager.Singleton.AddNetworkPrefab(Sunflowered.Instance.FlowerManagerPre); Sunflowered.Logger.LogInfo((object)"Added flowerMan.prefab to network prefabs!"); } else { Sunflowered.Logger.LogError((object)"Failed to load flowerMan.prefab!"); } HasInitalized = true; } } [HarmonyPatch(typeof(PlayerControllerB))] internal class PlayerControllerBPatch { [CompilerGenerated] private sealed class <SpawnFlowerManagerWhenReady>d__1 : IEnumerator<object>, IEnumerator, IDisposable { private int <>1__state; private object <>2__current; public PlayerControllerB player; private GameObject <FlowerManagerInstance>5__1; private NetworkObject <networkObject>5__2; private FlowerManager <FlowerManager>5__3; private Exception <ex>5__4; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <SpawnFlowerManagerWhenReady>d__1(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <FlowerManagerInstance>5__1 = null; <networkObject>5__2 = null; <FlowerManager>5__3 = null; <ex>5__4 = null; <>1__state = -2; } private bool MoveNext() { //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) switch (<>1__state) { default: return false; case 0: <>1__state = -1; break; case 1: <>1__state = -1; break; } if ((Object)(object)((NetworkBehaviour)player).NetworkObject == (Object)null || !((NetworkBehaviour)player).NetworkObject.IsSpawned) { <>2__current = null; <>1__state = 1; return true; } if (NetworkManager.Singleton.IsServer) { <FlowerManagerInstance>5__1 = Object.Instantiate<GameObject>(Sunflowered.Instance.FlowerManagerPre, ((Component)player).transform.position, Quaternion.identity); <networkObject>5__2 = <FlowerManagerInstance>5__1.GetComponent<NetworkObject>(); if ((Object)(object)<networkObject>5__2 != (Object)null) { try { <networkObject>5__2.SpawnWithOwnership(((NetworkBehaviour)player).NetworkObject.OwnerClientId, false); <FlowerManager>5__3 = <FlowerManagerInstance>5__1.GetComponent<FlowerManager>(); if ((Object)(object)<FlowerManager>5__3 != (Object)null) { <FlowerManager>5__3.Controller = player; } if (NetworkManager.Singleton.IsServer) { <FlowerManagerInstance>5__1.transform.SetParent(((Component)player).transform); } Sunflowered.Logger.LogInfo((object)("Spawned and parented FlowerManager for player: " + player.playerUsername)); <FlowerManager>5__3 = null; } catch (Exception ex) { <ex>5__4 = ex; Sunflowered.Logger.LogInfo((object)$"Failed to spawn FlowerManager for player: {player.playerUsername} Due to : {<ex>5__4}"); } } else { Sunflowered.Logger.LogError((object)"FlowerManager prefab is missing NetworkObject component!"); Object.Destroy((Object)(object)<FlowerManagerInstance>5__1); } <FlowerManagerInstance>5__1 = null; <networkObject>5__2 = null; } else { Sunflowered.Logger.LogInfo((object)("Requested FlowerManager spawn for player: " + player.playerUsername)); SpawnFlowerManagerServerRpc(((NetworkBehaviour)player).NetworkObject.OwnerClientId); } return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [HarmonyPatch("Start")] [HarmonyPostfix] private static void StartPostfix(PlayerControllerB __instance) { if (((NetworkBehaviour)__instance).IsOwner) { ((MonoBehaviour)__instance).StartCoroutine(SpawnFlowerManagerWhenReady(__instance)); } } [IteratorStateMachine(typeof(<SpawnFlowerManagerWhenReady>d__1))] private static IEnumerator SpawnFlowerManagerWhenReady(PlayerControllerB player) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <SpawnFlowerManagerWhenReady>d__1(0) { player = player }; } [ServerRpc(RequireOwnership = false)] private static void SpawnFlowerManagerServerRpc(ulong ownerClientId) { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) PlayerControllerB component = ((Component)NetworkManager.Singleton.ConnectedClients[ownerClientId].PlayerObject).GetComponent<PlayerControllerB>(); if ((Object)(object)component == (Object)null) { Sunflowered.Logger.LogError((object)$"Failed to find PlayerControllerB for client: {ownerClientId}"); return; } GameObject val = Object.Instantiate<GameObject>(Sunflowered.Instance.FlowerManagerPre, ((Component)component).transform.position, Quaternion.identity); NetworkObject component2 = val.GetComponent<NetworkObject>(); if ((Object)(object)component2 != (Object)null) { try { if (NetworkManager.Singleton.IsServer) { val.transform.SetParent(((Component)component).transform); } component2.SpawnWithOwnership(ownerClientId, false); FlowerManager component3 = val.GetComponent<FlowerManager>(); if ((Object)(object)component3 != (Object)null) { component3.Controller = component; } Sunflowered.Logger.LogInfo((object)$"Spawned and parented FlowerManager for client: {ownerClientId}"); return; } catch (Exception arg) { Sunflowered.Logger.LogInfo((object)$"Failed to spawn FlowerManager for client({ownerClientId}) Due to : {arg}"); return; } } Sunflowered.Logger.LogError((object)"FlowerManager prefab is missing NetworkObject component!"); Object.Destroy((Object)(object)val); } } [HarmonyPatch(typeof(StartOfRound))] internal class StartOfRoundPatch { [HarmonyPatch("OnClientDisconnect")] [HarmonyPrefix] private static void getSunflowered(ulong clientId) { if (!NetworkManager.Singleton.IsServer || !StartOfRound.Instance.ClientPlayerList.TryGetValue(clientId, out var value)) { return; } FlowerManager[] array = Object.FindObjectsOfType<FlowerManager>(); FlowerManager[] array2 = array; foreach (FlowerManager flowerManager in array2) { if ((Object)(object)flowerManager.Controller == (Object)(object)StartOfRound.Instance.allPlayerScripts[value]) { flowerManager.SpawnFlowerClientRpc(); break; } } } [HarmonyPatch("OnClientConnect")] [HarmonyPostfix] private static void WeOnlyHaveOneSunflower(ulong clientId) { if (!NetworkManager.Singleton.IsServer || !StartOfRound.Instance.ClientPlayerList.TryGetValue(clientId, out var value)) { return; } FlowerManager[] array = Object.FindObjectsOfType<FlowerManager>(); FlowerManager[] array2 = array; foreach (FlowerManager flowerManager in array2) { if ((Object)(object)flowerManager.Controller == (Object)(object)StartOfRound.Instance.allPlayerScripts[value]) { flowerManager.DeSpawnFlowerClientRpc(); break; } } } } [BepInPlugin("Sunflowered", "Sunflowered", "1.0.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Sunflowered : BaseUnityPlugin { public GameObject flowerprefab = null; public GameObject FlowerManagerPre = null; public static Sunflowered Instance { get; private set; } internal static ManualLogSource Logger { get; private set; } internal static Harmony? Harmony { get; set; } private void Awake() { Logger = ((BaseUnityPlugin)this).Logger; Instance = this; NetcodePatcher(); Patch(); flowerprefab = AssetLoader.LoadAsset<GameObject>("Assets/Sunfloweredassets/Sunflower.prefab"); FlowerManagerPre = AssetLoader.LoadAsset<GameObject>("Assets/Sunfloweredassets/lol.prefab"); FlowerManagerPre.AddComponent<FlowerManager>(); Item val = AssetLoader.LoadAsset<Item>("Assets/Sunfloweredassets/Sunflower.asset"); val.creditsWorth = 5; Utilities.FixMixerGroups(val.spawnPrefab); Items.RegisterItem(val); Logger.LogInfo((object)"Sunflowered v1.0.1 has loaded!"); } internal static void Patch() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown if (Harmony == null) { Harmony = new Harmony("Sunflowered"); } Logger.LogDebug((object)"Patching..."); Harmony.PatchAll(); Logger.LogDebug((object)"Finished patching!"); } internal static void Unpatch() { Logger.LogDebug((object)"Unpatching..."); Harmony? harmony = Harmony; if (harmony != null) { harmony.UnpatchSelf(); } Logger.LogDebug((object)"Finished unpatching!"); } private void NetcodePatcher() { Type[] types = Assembly.GetExecutingAssembly().GetTypes(); Type[] array = types; foreach (Type type in array) { MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic); MethodInfo[] array2 = methods; foreach (MethodInfo methodInfo in array2) { object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false); if (customAttributes.Length != 0) { methodInfo.Invoke(null, null); } } } } } public static class MyPluginInfo { public const string PLUGIN_GUID = "Sunflowered"; public const string PLUGIN_NAME = "Sunflowered"; public const string PLUGIN_VERSION = "1.0.1"; } } namespace __GEN { internal class NetworkVariableSerializationHelper { [RuntimeInitializeOnLoadMethod] internal static void InitializeSerialization() { } } } namespace Sunflowered.NetcodePatcher { [AttributeUsage(AttributeTargets.Module)] internal class NetcodePatchedAssemblyAttribute : Attribute { } }