using System;
using System.Collections;
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 BigPresent.Utils;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using com.github.xuuxiaolan.BigPresent.NetcodePatcher;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.xuuxiaolan.BigPresent")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+2730fbf6ca3f7fe775d4b8089d5f701befb182b7")]
[assembly: AssemblyProduct("BigPresent")]
[assembly: AssemblyTitle("com.github.xuuxiaolan.BigPresent")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.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 BigPresent
{
public class PluginConfig
{
public ConfigEntry<string> ConfigBigPresentSpawnWeight;
public ConfigEntry<string> ConfigBlacklistEnemies;
public PluginConfig(ConfigFile cfg)
{
ConfigBigPresentSpawnWeight = cfg.Bind<string>("Big Present", "Big Present | SpawnWeight", "Modded:69,Vanilla:69", "The spawn chance weight for Big Present, relative to other existing items.\nGoes up from 0, lower is more rare, 100 and up is very common. \nAllows the use of Moon names in the config.");
ConfigBlacklistEnemies = cfg.Bind<string>("Big Present", "Big Present | Blacklist Enemies", "", "Comma separated list of enemies to blacklist from the Big Present spawning.");
ClearUnusedEntries(cfg);
}
private void ClearUnusedEntries(ConfigFile cfg)
{
PropertyInfo property = ((object)cfg).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)property.GetValue(cfg, null);
dictionary.Clear();
cfg.Save();
}
}
[BepInPlugin("com.github.xuuxiaolan.BigPresent", "BigPresent", "1.0.3")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Logger;
internal static PluginConfig BoundConfig { get; private set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
BoundConfig = new PluginConfig(((BaseUnityPlugin)this).Config);
InitializeNetworkBehaviours();
string path = "bigpresentassets";
AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "Assets", path));
if ((Object)(object)val == (Object)null)
{
Logger.LogError((object)"Failed to load custom assets.");
return;
}
RegisterBigPresent(val);
Logger.LogInfo((object)"Plugin com.github.xuuxiaolan.BigPresent is loaded!");
}
private void RegisterBigPresent(AssetBundle ModAssets)
{
Item scrap = ModAssets.LoadAsset<Item>("BigPresentDef");
ContentHandler.Instance.RegisterScrapWithConfig(BoundConfig.ConfigBigPresentSpawnWeight.Value, scrap);
}
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);
}
}
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "com.github.xuuxiaolan.BigPresent";
public const string PLUGIN_NAME = "BigPresent";
public const string PLUGIN_VERSION = "1.0.3";
}
}
namespace BigPresent.Utils
{
public class ContentHandler
{
public static ContentHandler Instance = new ContentHandler();
internal void RegisterEnemyWithConfig(string configMoonRarity, EnemyType enemy, TerminalNode terminalNode, TerminalKeyword terminalKeyword, float powerLevel, int spawnCount)
{
enemy.MaxCount = spawnCount;
enemy.PowerLevel = powerLevel;
var (dictionary, dictionary2) = ConfigParsing(configMoonRarity);
Enemies.RegisterEnemy(enemy, dictionary, dictionary2, terminalNode, terminalKeyword);
}
internal void RegisterScrapWithConfig(string configMoonRarity, Item scrap)
{
var (dictionary, dictionary2) = ConfigParsing(configMoonRarity);
Utilities.FixMixerGroups(scrap.spawnPrefab);
NetworkPrefabs.RegisterNetworkPrefab(scrap.spawnPrefab);
Items.RegisterScrap(scrap, dictionary, dictionary2);
}
internal void RegisterShopItemWithConfig(bool enabledScrap, Item item, TerminalNode terminalNode, int itemCost, string configMoonRarity)
{
Items.RegisterShopItem(item, (TerminalNode)null, (TerminalNode)null, terminalNode, itemCost);
if (enabledScrap)
{
RegisterScrapWithConfig(configMoonRarity, item);
}
}
internal (Dictionary<LevelTypes, int> spawnRateByLevelType, Dictionary<string, int> spawnRateByCustomLevelType) ConfigParsing(string configMoonRarity)
{
//IL_0097: 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)
Dictionary<LevelTypes, int> dictionary = new Dictionary<LevelTypes, int>();
Dictionary<string, int> dictionary2 = new Dictionary<string, int>();
foreach (string item in from s in configMoonRarity.Split(',')
select s.Trim())
{
string[] array = item.Split(':');
if (array.Length != 2)
{
continue;
}
string text = array[0].ToLowerInvariant();
if (!int.TryParse(array[1], out var result))
{
continue;
}
if (text == "custom")
{
text = "modded";
}
if (Enum.TryParse<LevelTypes>(text, ignoreCase: true, out LevelTypes result2))
{
dictionary[result2] = result;
continue;
}
string value = text + "Level";
if (Enum.TryParse<LevelTypes>(value, ignoreCase: true, out result2))
{
dictionary[result2] = result;
}
else
{
dictionary2[text] = result;
}
}
return (dictionary, dictionary2);
}
}
}
namespace BigPresent.Items
{
public class BigPresent : GrabbableObject
{
private List<Item> items = new List<Item>();
private Random presentRandom = new Random();
public override void Start()
{
((GrabbableObject)this).Start();
presentRandom = new Random(StartOfRound.Instance.randomMapSeed);
foreach (SpawnableItemWithRarity item in RoundManager.Instance.currentLevel.spawnableScrap)
{
items.Add(item.spawnableItem);
}
}
public override void ItemActivate(bool used, bool buttonDown = true)
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
((GrabbableObject)this).ItemActivate(used, buttonDown);
Plugin.Logger.LogInfo((object)"Item Activated");
if (((NetworkBehaviour)this).IsServer)
{
SpawnItemOrExplodeServerRpc();
}
if (((NetworkBehaviour)this).IsServer)
{
((MonoBehaviour)this).StartCoroutine(DestroyPresentDelay());
}
base.playerHeldBy.DiscardHeldObject(false, (NetworkObject)null, default(Vector3), true);
((Component)this).GetComponentInChildren<ParticleSystem>().Play();
((Component)this).GetComponent<MeshFilter>().mesh = null;
}
private IEnumerator DestroyPresentDelay()
{
yield return (object)new WaitForSeconds(2f);
((NetworkBehaviour)this).NetworkObject.Despawn(true);
}
[ServerRpc(RequireOwnership = false)]
private void SpawnItemOrExplodeServerRpc()
{
//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_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_024f: Unknown result type (might be due to invalid IL or missing references)
//IL_0269: Unknown result type (might be due to invalid IL or missing references)
//IL_0276: 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)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2930525845u, val, (RpcDelivery)0);
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2930525845u, val, (RpcDelivery)0);
}
if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost))
{
return;
}
if (Random.Range(0f, 1f) > 0.5f)
{
int num = presentRandom.Next(10, 21);
Vector3 position = ((Component)this).transform.position;
for (int i = 0; i < num; i++)
{
Item val3 = items[presentRandom.Next(0, items.Count)];
GameObject val4 = Object.Instantiate<GameObject>(val3.spawnPrefab, position, Quaternion.Euler(val3.restingRotation), StartOfRound.Instance.propsContainer);
val4.GetComponent<NetworkObject>().Spawn(false);
int num2 = presentRandom.Next(val3.minValue, val3.maxValue);
ScanNodeProperties componentInChildren = val4.GetComponentInChildren<ScanNodeProperties>();
componentInChildren.scrapValue = num2;
componentInChildren.subText = $"Value: ${num2}";
val4.GetComponent<GrabbableObject>().scrapValue = num2;
UpdateScanNodeClientRpc(new NetworkObjectReference(val4), num2);
}
return;
}
List<EnemyType> list = new List<EnemyType>();
foreach (SpawnableEnemyWithRarity enemy in RoundManager.Instance.currentLevel.Enemies)
{
if (!Plugin.BoundConfig.ConfigBlacklistEnemies.Value.Contains(enemy.enemyType.enemyName))
{
list.Add(enemy.enemyType);
}
}
EnemyType val5 = list[presentRandom.Next(0, list.Count)];
SpawnExplosionClientRpc(((Component)base.playerHeldBy).transform.position);
RoundManager.Instance.SpawnEnemyGameObject(((Component)base.playerHeldBy).transform.position, 0f, -1, val5);
}
[ClientRpc]
private void SpawnExplosionClientRpc(Vector3 spawnPosition)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: 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_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2229349877u, val, (RpcDelivery)0);
((FastBufferWriter)(ref val2)).WriteValueSafe(ref spawnPosition);
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2229349877u, val, (RpcDelivery)0);
}
if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
((MonoBehaviour)this).StartCoroutine(DelayedExplosion(spawnPosition));
}
}
}
private IEnumerator DelayedExplosion(Vector3 spawnPosition)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
yield return (object)new WaitForSeconds(0.2f);
Landmine.SpawnExplosion(spawnPosition, true, 5f, 20f, 80, 100f, (GameObject)null, true);
}
[ClientRpc]
public void UpdateScanNodeClientRpc(NetworkObjectReference go, int value)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: 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_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: 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)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3406021643u, val, (RpcDelivery)0);
((FastBufferWriter)(ref val2)).WriteValueSafe<NetworkObjectReference>(ref go, default(ForNetworkSerializable));
BytePacker.WriteValueBitPacked(val2, value);
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3406021643u, val, (RpcDelivery)0);
}
if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
NetworkObject val3 = default(NetworkObject);
((NetworkObjectReference)(ref go)).TryGet(ref val3, (NetworkManager)null);
GrabbableObject val4 = default(GrabbableObject);
if ((Object)(object)val3 != (Object)null && ((Component)val3).gameObject.TryGetComponent<GrabbableObject>(ref val4))
{
val4.SetScrapValue(value);
}
}
}
protected override void __initializeVariables()
{
((GrabbableObject)this).__initializeVariables();
}
[RuntimeInitializeOnLoadMethod]
internal static void InitializeRPCS_BigPresent()
{
//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
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
NetworkManager.__rpc_func_table.Add(2930525845u, new RpcReceiveHandler(__rpc_handler_2930525845));
NetworkManager.__rpc_func_table.Add(2229349877u, new RpcReceiveHandler(__rpc_handler_2229349877));
NetworkManager.__rpc_func_table.Add(3406021643u, new RpcReceiveHandler(__rpc_handler_3406021643));
}
private static void __rpc_handler_2930525845(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;
((BigPresent)(object)target).SpawnItemOrExplodeServerRpc();
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_2229349877(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
Vector3 spawnPosition = default(Vector3);
((FastBufferReader)(ref reader)).ReadValueSafe(ref spawnPosition);
target.__rpc_exec_stage = (__RpcExecStage)2;
((BigPresent)(object)target).SpawnExplosionClientRpc(spawnPosition);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_3406021643(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
NetworkObjectReference go = default(NetworkObjectReference);
((FastBufferReader)(ref reader)).ReadValueSafe<NetworkObjectReference>(ref go, default(ForNetworkSerializable));
int value = default(int);
ByteUnpacker.ReadValueBitPacked(reader, ref value);
target.__rpc_exec_stage = (__RpcExecStage)2;
((BigPresent)(object)target).UpdateScanNodeClientRpc(go, value);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
protected internal override string __getTypeName()
{
return "BigPresent";
}
}
}
namespace com.github.xuuxiaolan.BigPresent.NetcodePatcher
{
[AttributeUsage(AttributeTargets.Module)]
internal class NetcodePatchedAssemblyAttribute : Attribute
{
}
}