using System;
using System.Collections;
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.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Sunflowered")]
[assembly: AssemblyTitle("Sunflowered")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
static <Module>()
{
}
}
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_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: 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 != 2 && (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 == 2 && (networkManager.IsClient || networkManager.IsHost) && (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)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager == null || !networkManager.IsListening)
{
return;
}
if ((int)base.__rpc_exec_stage != 2 && (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 != 2 || (!networkManager.IsClient && !networkManager.IsHost) || !((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();
}
[RuntimeInitializeOnLoadMethod]
internal static void InitializeRPCS_FlowerManager()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
NetworkManager.__rpc_func_table.Add(4182626042u, new RpcReceiveHandler(__rpc_handler_4182626042));
NetworkManager.__rpc_func_table.Add(3563514973u, new RpcReceiveHandler(__rpc_handler_3563514973));
}
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)2;
((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)2;
((FlowerManager)(object)target).DeSpawnFlowerClientRpc();
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
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 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
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void StartPostfix(PlayerControllerB __instance)
{
if (((NetworkBehaviour)__instance).IsOwner)
{
((MonoBehaviour)__instance).StartCoroutine(SpawnFlowerManagerWhenReady(__instance));
}
}
private static IEnumerator SpawnFlowerManagerWhenReady(PlayerControllerB player)
{
while ((Object)(object)((NetworkBehaviour)player).NetworkObject == (Object)null || !((NetworkBehaviour)player).NetworkObject.IsSpawned)
{
yield return null;
}
if (NetworkManager.Singleton.IsServer)
{
GameObject FlowerManagerInstance = Object.Instantiate<GameObject>(Sunflowered.Instance.FlowerManagerPre, ((Component)player).transform.position, Quaternion.identity);
NetworkObject networkObject = FlowerManagerInstance.GetComponent<NetworkObject>();
if ((Object)(object)networkObject != (Object)null)
{
try
{
networkObject.SpawnWithOwnership(((NetworkBehaviour)player).NetworkObject.OwnerClientId, false);
FlowerManager FlowerManager = FlowerManagerInstance.GetComponent<FlowerManager>();
if ((Object)(object)FlowerManager != (Object)null)
{
FlowerManager.Controller = player;
}
if (NetworkManager.Singleton.IsServer)
{
FlowerManagerInstance.transform.SetParent(((Component)player).transform);
}
Sunflowered.Logger.LogInfo((object)("Spawned and parented FlowerManager for player: " + player.playerUsername));
}
catch (Exception ex2)
{
Exception ex = ex2;
Sunflowered.Logger.LogInfo((object)$"Failed to spawn FlowerManager for player: {player.playerUsername} Due to : {ex}");
}
}
else
{
Sunflowered.Logger.LogError((object)"FlowerManager prefab is missing NetworkObject component!");
Object.Destroy((Object)(object)FlowerManagerInstance);
}
}
else
{
Sunflowered.Logger.LogInfo((object)("Requested FlowerManager spawn for player: " + player.playerUsername));
SpawnFlowerManagerServerRpc(((NetworkBehaviour)player).NetworkObject.OwnerClientId);
}
}
[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.0")]
[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.RegisterScrap(val, 0, (LevelTypes)(-1));
Logger.LogInfo((object)"Sunflowered v1.0.0 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.0";
}
}
namespace Sunflowered.NetcodePatcher
{
[AttributeUsage(AttributeTargets.Module)]
internal class NetcodePatchedAssemblyAttribute : Attribute
{
}
}