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 BreadScrap.NetcodePatcher;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("BreadScrap")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Adds a bread plushie that might spawn on landmines")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("BreadScrap")]
[assembly: AssemblyTitle("BreadScrap")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace BreadScrap
{
public class BreadProp : GrabbableObject
{
public Landmine landmine;
[ClientRpc]
internal void SyncSpawnClientRpc(NetworkBehaviourReference landmineRef, 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)
{
if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(498821397u, val, (RpcDelivery)0);
((FastBufferWriter)(ref val2)).WriteValueSafe<NetworkBehaviourReference>(ref landmineRef, default(ForNetworkSerializable));
BytePacker.WriteValueBitPacked(val2, value);
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 498821397u, val, (RpcDelivery)0);
}
Landmine val3 = default(Landmine);
if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && ((NetworkBehaviourReference)(ref landmineRef)).TryGet<Landmine>(ref val3, (NetworkManager)null))
{
landmine = val3;
((GrabbableObject)this).SetScrapValue(value);
}
}
}
public override void GrabItemFromEnemy(EnemyAI enemy)
{
landmine.TriggerMineOnLocalClientByExiting();
}
public override void GrabItem()
{
if (((NetworkBehaviour)this).IsOwner && !((Object)(object)landmine == (Object)null) && !landmine.hasExploded && !((Object)(object)landmine.mineAudio == (Object)null))
{
switch (Random.Range(0, 6))
{
case 0:
case 1:
FakeDetonate();
break;
case 2:
DelayedDetonate();
break;
default:
landmine.TriggerMineOnLocalClientByExiting();
break;
}
}
}
private void DelayedDetonate()
{
float delay = Random.Range(5f, 30f);
((MonoBehaviour)this).StartCoroutine(DelayedDetonate(delay));
DelayedDetonateServerRpc(delay);
}
[ServerRpc(RequireOwnership = false)]
private void DelayedDetonateServerRpc(float delay)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: 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_0097: 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 != 1 && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2836049302u, val, (RpcDelivery)0);
((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref delay, default(ForPrimitives));
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2836049302u, val, (RpcDelivery)0);
}
if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
{
DelayedDetonateClientRpc(delay);
}
}
}
[ClientRpc]
private void DelayedDetonateClientRpc(float delay)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: 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_0097: 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(650966569u, val, (RpcDelivery)0);
((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref delay, default(ForPrimitives));
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 650966569u, val, (RpcDelivery)0);
}
if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
((MonoBehaviour)this).StartCoroutine(DelayedDetonate(delay));
}
}
}
private IEnumerator DelayedDetonate(float delay)
{
Landmine landmine = this.landmine;
if (!((Object)(object)landmine == (Object)null))
{
landmine.mineAudio.PlayOneShot(landmine.mineTrigger);
yield return FlashLandmineLights();
this.landmine = null;
yield return (object)new WaitForSeconds(delay);
if (!landmine.hasExploded)
{
((Behaviour)landmine.mineAnimator).enabled = false;
landmine.hasExploded = true;
landmine.Detonate();
((Renderer)((Component)landmine).GetComponent<MeshRenderer>()).enabled = false;
((Component)((Component)landmine).transform.Find("Particles")).gameObject.SetActive(true);
yield return (object)new WaitForSeconds(1f / 15f);
((Behaviour)((Component)((Component)landmine).transform.Find("BlastMark")).GetComponent<DecalProjector>()).enabled = true;
}
}
}
private void FakeDetonate()
{
landmine.mineAudio.PlayOneShot(landmine.mineTrigger);
((MonoBehaviour)this).StartCoroutine(FlashLandmineLights());
landmine = null;
FakeDetonateServerRpc();
}
[ServerRpc(RequireOwnership = false)]
private void FakeDetonateServerRpc()
{
//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)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(777897774u, val, (RpcDelivery)0);
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 777897774u, val, (RpcDelivery)0);
}
if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
{
FakeDetonateClientRpc();
}
}
}
[ClientRpc]
private void FakeDetonateClientRpc()
{
//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)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3473401815u, val, (RpcDelivery)0);
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3473401815u, val, (RpcDelivery)0);
}
if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && !((Object)(object)landmine == (Object)null) && !landmine.hasExploded)
{
((MonoBehaviour)this).StartCoroutine(FlashLandmineLights());
landmine.mineAudio.PlayOneShot(landmine.mineTrigger);
landmine = null;
}
}
}
private IEnumerator FlashLandmineLights()
{
Animator animator = landmine.mineAnimator;
Light light1 = ((Component)((Component)landmine).transform.Find("BrightLight")).GetComponent<Light>();
Light light2 = ((Component)((Component)landmine).transform.Find("BrightLight2")).GetComponent<Light>();
Light light3 = ((Component)((Component)landmine).transform.Find("IndirectLight")).GetComponent<Light>();
((Behaviour)animator).enabled = false;
yield return (object)new WaitForSeconds(1f / 60f);
((Behaviour)light1).enabled = true;
((Behaviour)light2).enabled = true;
((Behaviour)light3).enabled = true;
yield return (object)new WaitForSeconds(1f / 30f);
((Behaviour)light1).enabled = false;
((Behaviour)light2).enabled = false;
((Behaviour)light3).enabled = false;
yield return (object)new WaitForSeconds(1f / 12f);
((Behaviour)light1).enabled = true;
((Behaviour)light2).enabled = true;
((Behaviour)light3).enabled = true;
yield return (object)new WaitForSeconds(1f / 30f);
((Behaviour)light1).enabled = false;
((Behaviour)light2).enabled = false;
((Behaviour)light3).enabled = false;
yield return (object)new WaitForSeconds(1f / 12f);
((Behaviour)light1).enabled = true;
((Behaviour)light2).enabled = true;
((Behaviour)light3).enabled = true;
yield return (object)new WaitForSeconds(1f / 30f);
((Behaviour)light1).enabled = false;
((Behaviour)light2).enabled = false;
((Behaviour)light3).enabled = false;
((Behaviour)animator).enabled = true;
}
protected override void __initializeVariables()
{
((GrabbableObject)this).__initializeVariables();
}
[RuntimeInitializeOnLoadMethod]
internal static void InitializeRPCS_BreadProp()
{
//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
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Expected O, but got Unknown
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Expected O, but got Unknown
NetworkManager.__rpc_func_table.Add(498821397u, new RpcReceiveHandler(__rpc_handler_498821397));
NetworkManager.__rpc_func_table.Add(2836049302u, new RpcReceiveHandler(__rpc_handler_2836049302));
NetworkManager.__rpc_func_table.Add(650966569u, new RpcReceiveHandler(__rpc_handler_650966569));
NetworkManager.__rpc_func_table.Add(777897774u, new RpcReceiveHandler(__rpc_handler_777897774));
NetworkManager.__rpc_func_table.Add(3473401815u, new RpcReceiveHandler(__rpc_handler_3473401815));
}
private static void __rpc_handler_498821397(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)
{
NetworkBehaviourReference landmineRef = default(NetworkBehaviourReference);
((FastBufferReader)(ref reader)).ReadValueSafe<NetworkBehaviourReference>(ref landmineRef, default(ForNetworkSerializable));
int value = default(int);
ByteUnpacker.ReadValueBitPacked(reader, ref value);
target.__rpc_exec_stage = (__RpcExecStage)2;
((BreadProp)(object)target).SyncSpawnClientRpc(landmineRef, value);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_2836049302(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_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
float delay = default(float);
((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref delay, default(ForPrimitives));
target.__rpc_exec_stage = (__RpcExecStage)1;
((BreadProp)(object)target).DelayedDetonateServerRpc(delay);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_650966569(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_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
float delay = default(float);
((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref delay, default(ForPrimitives));
target.__rpc_exec_stage = (__RpcExecStage)2;
((BreadProp)(object)target).DelayedDetonateClientRpc(delay);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_777897774(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;
((BreadProp)(object)target).FakeDetonateServerRpc();
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_3473401815(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;
((BreadProp)(object)target).FakeDetonateClientRpc();
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
protected internal override string __getTypeName()
{
return "BreadProp";
}
}
[BepInPlugin("BreadScrap", "BreadScrap", "1.0.2")]
public class Plugin : BaseUnityPlugin
{
private static readonly Harmony harmony = new Harmony("BreadScrap");
private static GameObject prefab;
private static Item itemProperties;
private static Vector3 serverRotationOffset = new Vector3(0f, 220f, 0f);
private void Awake()
{
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
for (int i = 0; i < types.Length; i++)
{
MethodInfo[] methods = types[i].GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
foreach (MethodInfo methodInfo in methods)
{
if (methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false).Length != 0)
{
methodInfo.Invoke(null, null);
}
}
}
AssetBundle obj = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "breadscrap"));
prefab = obj.LoadAsset<GameObject>("BreadScrap.prefab");
itemProperties = obj.LoadAsset<Item>("BreadScrapProperties.asset");
obj.Unload(false);
harmony.PatchAll(typeof(Plugin));
((BaseUnityPlugin)this).Logger.LogInfo((object)"get breddy...");
}
[HarmonyPrefix]
[HarmonyPatch(typeof(GameNetworkManager), "Start")]
private static void RegisterPrefab()
{
NetworkManager.Singleton.AddNetworkPrefab(prefab);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(StartOfRound), "Start")]
private static void AddBreadScrap(StartOfRound __instance)
{
int count = __instance.allItemsList.itemsList.Count;
__instance.allItemsList.itemsList.Add(itemProperties);
itemProperties.itemId = count;
SelectableLevel[] levels = StartOfRound.Instance.levels;
for (int i = 0; i < levels.Length; i++)
{
SpawnableItemWithRarity val = ((IEnumerable<SpawnableItemWithRarity>)levels[i].spawnableScrap).FirstOrDefault((Func<SpawnableItemWithRarity, bool>)((SpawnableItemWithRarity x) => x.spawnableItem.itemName == "Zed Dog"));
if (val != null)
{
itemProperties.itemIcon = val.spawnableItem.itemIcon;
itemProperties.dropSFX = val.spawnableItem.grabSFX;
break;
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Landmine), "Start")]
private static void SpawnOnLandmine(Landmine __instance)
{
//IL_003c: 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_004b: 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)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
if (((NetworkBehaviour)RoundManager.Instance).IsServer && RoundManager.Instance.AnomalyRandom.Next(0, 10) == 0)
{
BreadProp component = Object.Instantiate<GameObject>(prefab).GetComponent<BreadProp>();
((Component)component).transform.position = ((Component)__instance).transform.position + Vector3.up * 0.28f;
((Component)component).transform.eulerAngles = new Vector3(0f, (float)RoundManager.Instance.AnomalyRandom.Next(0, 360), 0f);
((Component)component).GetComponent<NetworkObject>().Spawn(false);
component.SyncSpawnClientRpc(NetworkBehaviourReference.op_Implicit((NetworkBehaviour)(object)__instance), RoundManager.Instance.AnomalyRandom.Next(itemProperties.minValue, itemProperties.maxValue));
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "BreadScrap";
public const string PLUGIN_NAME = "BreadScrap";
public const string PLUGIN_VERSION = "1.0.2";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}
namespace BreadScrap.NetcodePatcher
{
[AttributeUsage(AttributeTargets.Module)]
internal class NetcodePatchedAssemblyAttribute : Attribute
{
}
}