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 BakaMODs.VaiTerCebola.NetcodePatcher;
using BakaMODs.VaiTerCebola.Patches;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
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("BakaMODs.VaiTerCebola")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+0864a05544691c96bb0f101813317f1ce77b7629")]
[assembly: AssemblyProduct("VaiTerCebola")]
[assembly: AssemblyTitle("BakaMODs.VaiTerCebola")]
[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 BakaMODs.VaiTerCebola
{
public class CebolaEfeitos : MonoBehaviour
{
[CompilerGenerated]
private sealed class <RefreshScanAfterDelay>d__17 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public CebolaEfeitos <>4__this;
object? IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object? IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <RefreshScanAfterDelay>d__17(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = null;
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(0.1f);
<>1__state = 2;
return true;
case 2:
<>1__state = -1;
if ((Object)(object)<>4__this.grabbableObject != (Object)null)
{
<>4__this.AtualizarTextoDoScan(<>4__this.grabbableObject.scrapValue);
}
<>4__this.refreshRoutine = null;
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();
}
}
[Header("Sons da Cebola")]
public AudioClip? somInteracao;
public AudioClip? somSoltar;
public AudioClip? somVendaMaldita;
private GrabbableObject grabbableObject = null;
private AudioSource audioSource = null;
private Rigidbody? rigidbodyComponent;
private ScanNodeProperties? scanNodeProperties;
private string? originalScanHeader;
private string? originalScanSubText;
private Coroutine? refreshRoutine;
private static readonly List<PlayerControllerB> playersComEfeitoDecaindo = new List<PlayerControllerB>();
private PlayerControllerB? jogadorSegurandoAtualmente;
private float tempoSegurando;
private void Awake()
{
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Invalid comparison between Unknown and I4
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Invalid comparison between Unknown and I4
grabbableObject = ((Component)this).GetComponent<GrabbableObject>();
rigidbodyComponent = ((Component)this).GetComponent<Rigidbody>();
if ((Object)(object)rigidbodyComponent != (Object)null)
{
rigidbodyComponent.isKinematic = false;
rigidbodyComponent.useGravity = true;
if ((int)rigidbodyComponent.collisionDetectionMode == 0)
{
rigidbodyComponent.collisionDetectionMode = (CollisionDetectionMode)1;
}
if ((int)rigidbodyComponent.interpolation == 0)
{
rigidbodyComponent.interpolation = (RigidbodyInterpolation)1;
}
}
scanNodeProperties = ((Component)this).GetComponentInChildren<ScanNodeProperties>(true);
if ((Object)(object)scanNodeProperties != (Object)null)
{
originalScanHeader = scanNodeProperties.headerText;
originalScanSubText = scanNodeProperties.subText;
Collider[] componentsInChildren = ((Component)scanNodeProperties).GetComponentsInChildren<Collider>();
foreach (Collider val in componentsInChildren)
{
val.isTrigger = true;
}
}
audioSource = ((Component)this).GetComponent<AudioSource>();
if ((Object)(object)audioSource == (Object)null)
{
audioSource = ((Component)this).gameObject.AddComponent<AudioSource>();
audioSource.playOnAwake = false;
audioSource.spatialBlend = 1f;
}
audioSource.dopplerLevel = 0f;
}
private void Start()
{
ScheduleScanRefresh();
}
public void AtualizarValorScrap(int novoValor)
{
if ((Object)(object)grabbableObject != (Object)null)
{
grabbableObject.scrapValue = novoValor;
}
AtualizarTextoDoScan(novoValor);
}
public void ScheduleScanRefresh()
{
if (refreshRoutine != null)
{
((MonoBehaviour)this).StopCoroutine(refreshRoutine);
}
refreshRoutine = ((MonoBehaviour)this).StartCoroutine(RefreshScanAfterDelay());
}
[IteratorStateMachine(typeof(<RefreshScanAfterDelay>d__17))]
private IEnumerator RefreshScanAfterDelay()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <RefreshScanAfterDelay>d__17(0)
{
<>4__this = this
};
}
private void AtualizarTextoDoScan(int valor)
{
if (!((Object)(object)scanNodeProperties == (Object)null))
{
scanNodeProperties.scrapValue = valor;
if (!string.IsNullOrWhiteSpace(originalScanHeader))
{
scanNodeProperties.headerText = $"{originalScanHeader} (${valor})";
}
string arg = (string.IsNullOrWhiteSpace(originalScanSubText) ? string.Empty : ("\n" + originalScanSubText));
scanNodeProperties.subText = $"Valor: {valor}{arg}";
}
}
private void Update()
{
if (playersComEfeitoDecaindo.Count > 0)
{
for (int num = playersComEfeitoDecaindo.Count - 1; num >= 0; num--)
{
PlayerControllerB val = playersComEfeitoDecaindo[num];
if ((Object)(object)val != (Object)null && val.drunkness > 0f)
{
val.drunkness = Mathf.Max(val.drunkness - Time.deltaTime / 120f, 0f);
}
else
{
playersComEfeitoDecaindo.RemoveAt(num);
}
}
}
if (!((Object)(object)grabbableObject == (Object)null))
{
PlayerControllerB val2 = (grabbableObject.isHeld ? grabbableObject.playerHeldBy : null);
if ((Object)(object)val2 != (Object)null && (Object)(object)jogadorSegurandoAtualmente == (Object)null)
{
OnPickup(val2);
}
else if ((Object)(object)val2 == (Object)null && (Object)(object)jogadorSegurandoAtualmente != (Object)null)
{
OnDrop(jogadorSegurandoAtualmente);
}
else if ((Object)(object)val2 != (Object)null)
{
tempoSegurando += Time.deltaTime;
val2.drunkness = Mathf.Min(tempoSegurando / 60f, 1f);
}
jogadorSegurandoAtualmente = val2;
}
}
private void OnPickup(PlayerControllerB player)
{
if (playersComEfeitoDecaindo.Contains(player))
{
playersComEfeitoDecaindo.Remove(player);
}
tempoSegurando = player.drunkness * 60f;
if ((Object)(object)somInteracao != (Object)null)
{
audioSource.Stop();
audioSource.PlayOneShot(somInteracao);
}
}
private void OnDrop(PlayerControllerB player)
{
if (!playersComEfeitoDecaindo.Contains(player))
{
playersComEfeitoDecaindo.Add(player);
}
tempoSegurando = 0f;
if ((Object)(object)somSoltar != (Object)null)
{
audioSource.Stop();
audioSource.PlayOneShot(somSoltar);
}
}
}
[BepInPlugin("BakaMODs.VaiTerCebola", "VaiTerCebola", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class VaiTerCebolaPlugin : BaseUnityPlugin
{
internal static ManualLogSource Logger;
private readonly Harmony harmony = new Harmony("BakaMODs.VaiTerCebola");
private const string AssetBundleName = "cebolaassets";
private const string ScrapItemAssetPath = "Assets/ModAssets/Cebola/Cebola.asset";
public static Item? CebolaScrap;
public static AssetBundle? ModAssetBundle;
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location) ?? "", "cebolaassets");
ModAssetBundle = AssetBundle.LoadFromFile(text);
if ((Object)(object)ModAssetBundle == (Object)null)
{
Logger.LogError((object)"Falha ao carregar o AssetBundle! Verifique se o arquivo 'cebolaassets' está na pasta do mod.");
return;
}
CebolaScrap = ModAssetBundle.LoadAsset<Item>("Assets/ModAssets/Cebola/Cebola.asset");
if ((Object)(object)CebolaScrap == (Object)null)
{
Logger.LogError((object)"Falha ao carregar o asset do item 'Assets/ModAssets/Cebola/Cebola.asset' do AssetBundle.");
return;
}
Items.RegisterScrap(CebolaScrap, 20, (LevelTypes)(-1));
NetworkPrefabs.RegisterNetworkPrefab(CebolaScrap.spawnPrefab);
Logger.LogInfo((object)"Cebola registrada como sucata.");
harmony.PatchAll(typeof(RoundManagerPatch));
harmony.PatchAll(typeof(GrabbableObjectPatch));
harmony.PatchAll(typeof(DepositItemsDeskPatch));
Logger.LogInfo((object)"Patch do RoundManager para spawn da cebola aplicado.");
Logger.LogInfo((object)"Plugin BakaMODs.VaiTerCebola foi carregado!");
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "BakaMODs.VaiTerCebola";
public const string PLUGIN_NAME = "VaiTerCebola";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace BakaMODs.VaiTerCebola.Patches
{
[HarmonyPatch(typeof(DepositItemsDesk))]
internal class DepositItemsDeskPatch
{
[CompilerGenerated]
private sealed class <VendaMalditaCoroutine>d__2 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public DepositItemsDesk desk;
public CebolaEfeitos cebola;
public PlayerControllerB player;
private AudioClip <somVenda>5__1;
private float <tempoDeEspera>5__2;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <VendaMalditaCoroutine>d__2(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<somVenda>5__1 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Expected O, but got Unknown
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<somVenda>5__1 = cebola.somVendaMaldita;
<tempoDeEspera>5__2 = 2.5f;
if ((Object)(object)<somVenda>5__1 != (Object)null)
{
desk.deskAudio.PlayOneShot(<somVenda>5__1);
<tempoDeEspera>5__2 = <somVenda>5__1.length;
}
<>2__current = (object)new WaitForSeconds(<tempoDeEspera>5__2);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
if ((Object)(object)NetworkManager.Singleton != (Object)null)
{
if (NetworkManager.Singleton.IsServer)
{
desk.Attack();
}
else
{
desk.AttackPlayersServerRpc();
}
}
else
{
desk.Attack();
}
if ((Object)(object)player != (Object)null)
{
<>2__current = (object)new WaitForSeconds(0.15f);
<>1__state = 2;
return true;
}
break;
case 2:
<>1__state = -1;
player.KillPlayer(Vector3.zero, true, (CauseOfDeath)0, 0, default(Vector3));
break;
}
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();
}
}
private static readonly HashSet<GrabbableObject> cebolasAmaldicoadas = new HashSet<GrabbableObject>();
[HarmonyPatch("PlaceItemOnCounter")]
[HarmonyPrefix]
public static bool OnPlaceItemOnCounter(DepositItemsDesk __instance, PlayerControllerB playerWhoTriggered)
{
GrabbableObject currentlyHeldObjectServer = playerWhoTriggered.currentlyHeldObjectServer;
if ((Object)(object)currentlyHeldObjectServer == (Object)null)
{
return true;
}
CebolaEfeitos component = ((Component)currentlyHeldObjectServer).GetComponent<CebolaEfeitos>();
if ((Object)(object)component == (Object)null)
{
return true;
}
if (cebolasAmaldicoadas.Contains(currentlyHeldObjectServer))
{
cebolasAmaldicoadas.Remove(currentlyHeldObjectServer);
return true;
}
cebolasAmaldicoadas.Add(currentlyHeldObjectServer);
((MonoBehaviour)__instance).StartCoroutine(VendaMalditaCoroutine(__instance, component, playerWhoTriggered));
return false;
}
[IteratorStateMachine(typeof(<VendaMalditaCoroutine>d__2))]
private static IEnumerator VendaMalditaCoroutine(DepositItemsDesk desk, CebolaEfeitos cebola, PlayerControllerB player)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <VendaMalditaCoroutine>d__2(0)
{
desk = desk,
cebola = cebola,
player = player
};
}
}
[HarmonyPatch(typeof(GrabbableObject))]
internal static class GrabbableObjectPatch
{
[HarmonyPatch("SetScrapValue")]
[HarmonyPostfix]
private static void OnSetScrapValue(GrabbableObject __instance, int setValueTo)
{
CebolaEfeitos cebolaEfeitos = default(CebolaEfeitos);
if (((Component)__instance).TryGetComponent<CebolaEfeitos>(ref cebolaEfeitos))
{
cebolaEfeitos.AtualizarValorScrap(setValueTo);
}
}
}
[HarmonyPatch(typeof(RoundManager))]
internal class RoundManagerPatch
{
[HarmonyPatch("SpawnScrapInLevel")]
[HarmonyPostfix]
public static void SpawnCebolasPatch(RoundManager __instance)
{
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_014d: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_0206: Unknown result type (might be due to invalid IL or missing references)
//IL_0213: Unknown result type (might be due to invalid IL or missing references)
Item cebolaScrap = VaiTerCebolaPlugin.CebolaScrap;
if (!((NetworkBehaviour)__instance).IsHost || (Object)(object)cebolaScrap == (Object)null)
{
return;
}
List<Transform> list = (from s in Object.FindObjectsOfType<RandomScrapSpawn>()
select ((Component)s).transform).ToList();
if (list.Count == 0)
{
VaiTerCebolaPlugin.Logger.LogWarning((object)"Nenhum ponto de spawn de sucata (RandomScrapSpawn) encontrado!");
return;
}
VaiTerCebolaPlugin.Logger.LogInfo((object)$"Encontrados {list.Count} pontos de spawn. Spawning de 10 cebolas...");
RaycastHit val4 = default(RaycastHit);
for (int i = 0; i < 10; i++)
{
Transform val = list[Random.Range(0, list.Count)];
Vector3 val2 = val.position;
Quaternion val3 = val.rotation;
if (Physics.Raycast(val2 + Vector3.up * 2f, Vector3.down, ref val4, 20f, -1, (QueryTriggerInteraction)1))
{
val2 = ((RaycastHit)(ref val4)).point + ((RaycastHit)(ref val4)).normal * 0.02f;
if (((RaycastHit)(ref val4)).normal != Vector3.zero)
{
val3 = Quaternion.FromToRotation(Vector3.up, ((RaycastHit)(ref val4)).normal) * val3;
}
}
GameObject val5 = Object.Instantiate<GameObject>(cebolaScrap.spawnPrefab, val2, val3);
GrabbableObject component = val5.GetComponent<GrabbableObject>();
CebolaEfeitos component2 = val5.GetComponent<CebolaEfeitos>();
if ((Object)(object)component != (Object)null)
{
if (component.propColliders == null || component.propColliders.Length == 0)
{
component.propColliders = val5.GetComponentsInChildren<Collider>();
}
if ((Object)(object)component.propBody == (Object)null)
{
component.propBody = val5.GetComponent<Rigidbody>();
}
if ((Object)(object)component.propBody != (Object)null)
{
Rigidbody propBody = component.propBody;
propBody.useGravity = true;
propBody.isKinematic = false;
propBody.collisionDetectionMode = (CollisionDetectionMode)2;
propBody.velocity = Vector3.zero;
propBody.angularVelocity = Vector3.zero;
}
}
component2?.ScheduleScanRefresh();
NetworkObject component3 = val5.GetComponent<NetworkObject>();
if ((Object)(object)component3 != (Object)null)
{
component3.Spawn(false);
}
}
VaiTerCebolaPlugin.Logger.LogInfo((object)"10 cebolas foram adicionadas ao mapa!");
}
}
}
namespace BakaMODs.VaiTerCebola.Configuration
{
public class PluginConfig
{
public PluginConfig(ConfigFile cfg)
{
}
}
}
namespace BakaMODs.VaiTerCebola.NetcodePatcher
{
[AttributeUsage(AttributeTargets.Module)]
internal class NetcodePatchedAssemblyAttribute : Attribute
{
}
}