using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
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 GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Snowlance.Coins.NetcodePatcher;
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: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: AssemblyCompany("Snowlance.Coins")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+c0110615b787bad5826a42bcf819a1d70add4bf8")]
[assembly: AssemblyProduct("Coins")]
[assembly: AssemblyTitle("Snowlance.Coins")]
[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;
}
}
}
namespace Coins
{
internal class CoinBehavior : NetworkBehaviour
{
public AudioClip CoinCollectSFX;
private static Terminal terminal;
public void Start()
{
if ((Object)(object)terminal == (Object)null)
{
terminal = Object.FindObjectOfType<Terminal>();
}
}
public void OnTriggerEnter(Collider other)
{
PlayerControllerB val = default(PlayerControllerB);
if (((Component)other).gameObject.TryGetComponent<PlayerControllerB>(ref val))
{
val.statusEffectAudio.PlayOneShot(CoinCollectSFX, Plugin.configCoinVolume.Value);
CollectCoinServerRpc();
}
}
[ServerRpc(RequireOwnership = false)]
public void CollectCoinServerRpc()
{
//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)
{
if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3398974476u, val, (RpcDelivery)0);
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3398974476u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && Plugin.IsServerOrHost)
{
CollectCoinClientRpc();
((NetworkBehaviour)this).NetworkObject.Despawn(true);
}
}
}
[ClientRpc]
public void CollectCoinClientRpc()
{
//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)
{
if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1517459593u, val, (RpcDelivery)0);
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1517459593u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
Terminal obj = terminal;
obj.groupCredits += Plugin.configCoinValue.Value;
}
}
}
protected override void __initializeVariables()
{
((NetworkBehaviour)this).__initializeVariables();
}
[RuntimeInitializeOnLoadMethod]
internal static void InitializeRPCS_CoinBehavior()
{
//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(3398974476u, new RpcReceiveHandler(__rpc_handler_3398974476));
NetworkManager.__rpc_func_table.Add(1517459593u, new RpcReceiveHandler(__rpc_handler_1517459593));
}
private static void __rpc_handler_3398974476(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;
((CoinBehavior)(object)target).CollectCoinServerRpc();
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_1517459593(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;
((CoinBehavior)(object)target).CollectCoinClientRpc();
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
protected internal override string __getTypeName()
{
return "CoinBehavior";
}
}
internal class TESTING : MonoBehaviour
{
private static ManualLogSource logger = Plugin.LoggerInstance;
private static bool toggle;
[HarmonyPostfix]
[HarmonyPatch(typeof(HUDManager), "PingScan_performed")]
public static void PingScan_performedPostFix()
{
}
[HarmonyPrefix]
[HarmonyPatch(typeof(HUDManager), "SubmitChat_performed")]
public static void SubmitChat_performedPrefix(HUDManager __instance)
{
try
{
string text = __instance.chatTextField.text;
string[] array = text.Split(" ");
switch (array[0])
{
case "/crash":
Application.Quit();
break;
case "/refresh":
RoundManager.Instance.RefreshEnemiesList();
HoarderBugAI.RefreshGrabbableObjectsInMapList();
break;
case "/levels":
{
SelectableLevel[] levels = StartOfRound.Instance.levels;
foreach (SelectableLevel val2 in levels)
{
logger.LogDebug((object)((Object)val2).name);
}
break;
}
case "/dungeon":
logger.LogDebug((object)((Object)RoundManager.Instance.dungeonGenerator.Generator.DungeonFlow).name);
break;
case "/dungeons":
{
IndoorMapType[] dungeonFlowTypes = RoundManager.Instance.dungeonFlowTypes;
foreach (IndoorMapType val in dungeonFlowTypes)
{
logger.LogDebug((object)((Object)val.dungeonFlow).name);
}
break;
}
}
}
catch
{
logger.LogError((object)"Invalid chat command");
}
}
}
[BepInPlugin("Snowlance.Coins", "Coins", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public static Plugin PluginInstance;
public static ManualLogSource LoggerInstance;
private readonly Harmony harmony = new Harmony("Snowlance.Coins");
public static AssetBundle? ModAssets;
public static GameObject CoinPrefab;
public static ConfigEntry<int> configCoinValue;
public static ConfigEntry<float> configInsideAmount;
public static ConfigEntry<float> configOutsideAmount;
public static ConfigEntry<float> configCoinVolume;
public static PlayerControllerB localPlayer => GameNetworkManager.Instance.localPlayerController;
public static bool IsServerOrHost => NetworkManager.Singleton.IsServer || NetworkManager.Singleton.IsHost;
public static PlayerControllerB PlayerFromId(ulong id)
{
return StartOfRound.Instance.allPlayerScripts.Where((PlayerControllerB x) => x.actualClientId == id).First();
}
private void Awake()
{
if ((Object)(object)PluginInstance == (Object)null)
{
PluginInstance = this;
}
LoggerInstance = ((BaseUnityPlugin)PluginInstance).Logger;
harmony.PatchAll();
InitializeNetworkBehaviours();
configCoinValue = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Coin Value", 1, "How many credits will be added when a coin is collected");
configInsideAmount = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Inside Amount", 1f, "The percentage of AI nodes from 0-1 that a coin will spawn on inside.");
configOutsideAmount = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Outside Amount", 0f, "The percentage of AI nodes from 0-1 that a coin will spawn on outside.");
configCoinVolume = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Coin Volume", 0.5f, "The volume of the collect coin sound effect when a coin is collected. Needs to be 0-1.");
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
ModAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "coin_assets"));
if ((Object)(object)ModAssets == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load custom assets.");
return;
}
LoggerInstance.LogDebug((object)("Got AssetBundle at: " + Path.Combine(directoryName, "coin_assets")));
CoinPrefab = ModAssets.LoadAsset<GameObject>("Assets/ModAssets/Coin.prefab");
if ((Object)(object)CoinPrefab == (Object)null)
{
LoggerInstance.LogError((object)"CoinPrefab is null");
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"Snowlance.Coins v1.0.0 has loaded!");
}
private static void InitializeNetworkBehaviours()
{
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);
}
}
}
LoggerInstance.LogDebug((object)"Finished initializing network behaviours");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "Snowlance.Coins";
public const string PLUGIN_NAME = "Coins";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace Coins.Patches
{
[HarmonyPatch(typeof(GameNetworkManager))]
internal class GameNetworkManagerPatch
{
private static ManualLogSource logger = Plugin.LoggerInstance;
[HarmonyPostfix]
[HarmonyPatch("Start")]
public static void GameNetworkManagerPostfix()
{
NetworkManager.Singleton.AddNetworkPrefab(Plugin.CoinPrefab);
logger.LogDebug((object)"Added network prefab for coin");
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
private static ManualLogSource logger = Plugin.LoggerInstance;
private const float verticalOffset = 0.5f;
[HarmonyPostfix]
[HarmonyPatch("OnShipLandedMiscEvents")]
public static void OnShipLandedMiscEventsPostfix()
{
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
//IL_01af: Unknown result type (might be due to invalid IL or missing references)
//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
if (!Plugin.IsServerOrHost)
{
return;
}
if (Plugin.configInsideAmount.Value != 0f)
{
int num = (int)((float)RoundManager.Instance.insideAINodes.Length * Plugin.configInsideAmount.Value);
logger.LogDebug((object)$"Spawning {num} coins inside");
List<GameObject> list = RoundManager.Instance.insideAINodes.ToList();
for (int i = 0; i < num; i++)
{
GameObject randomAINode = GetRandomAINode(list);
list.Remove(randomAINode);
if ((Object)(object)randomAINode == (Object)null)
{
i--;
continue;
}
CoinBehavior component = Object.Instantiate<GameObject>(Plugin.CoinPrefab, randomAINode.transform.position + Vector3.up * 0.5f, Quaternion.identity).GetComponent<CoinBehavior>();
((NetworkBehaviour)component).NetworkObject.Spawn(true);
}
}
if (Plugin.configOutsideAmount.Value == 0f)
{
return;
}
int num2 = (int)((float)RoundManager.Instance.outsideAINodes.Length * Plugin.configOutsideAmount.Value);
logger.LogDebug((object)$"Spawning {num2} coins outside");
List<GameObject> list2 = RoundManager.Instance.outsideAINodes.ToList();
for (int j = 0; j < num2; j++)
{
GameObject randomAINode2 = GetRandomAINode(list2);
list2.Remove(randomAINode2);
if ((Object)(object)randomAINode2 == (Object)null)
{
j--;
continue;
}
CoinBehavior component2 = Object.Instantiate<GameObject>(Plugin.CoinPrefab, randomAINode2.transform.position + Vector3.up * 0.5f, Quaternion.identity).GetComponent<CoinBehavior>();
((NetworkBehaviour)component2).NetworkObject.Spawn(true);
}
}
private static GameObject GetRandomAINode(List<GameObject> nodes)
{
int index = Random.Range(0, nodes.Count);
return nodes[index];
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}
namespace Snowlance.Coins.NetcodePatcher
{
[AttributeUsage(AttributeTargets.Module)]
internal class NetcodePatchedAssemblyAttribute : Attribute
{
}
}