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.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using Dawn;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("FacilityMeltdown")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FacilityMeltdown")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9e8e631e-3b88-4f4d-b0da-5c8a63613076")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
}
}
}
namespace FacilityMeltdown
{
public class Class1
{
}
internal class Class2
{
}
public static class MeltdownKeys
{
public static readonly NamespacedKey<DawnItemInfo> GeigerCounter = NamespacedKey<DawnItemInfo>.From("facility_meltdown", "geiger_counter");
}
[BepInPlugin("facilitymeltdown.geigeronly", "FacilityMeltdown Geiger Only", "1.1.0")]
public class GeigerOnlyPlugin : BaseUnityPlugin
{
public static GeigerOnlyPlugin Instance;
private static AssetBundle _bundle;
private static Item _geigerItemDef;
private static TerminalNode _geigerInfoNode;
private static bool _registered;
private void Awake()
{
Instance = this;
LoadBundleAndAssets();
RegisterGeigerWithDawnLib();
((BaseUnityPlugin)this).Logger.LogInfo((object)"FacilityMeltdown Geiger Only loaded");
}
private void LoadBundleAndAssets()
{
try
{
string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
if (string.IsNullOrEmpty(directoryName) || !Directory.Exists(directoryName))
{
((BaseUnityPlugin)this).Logger.LogError((object)"Impossible de déterminer le dossier du plugin.");
return;
}
string[] ignoredExtensions = new string[7] { ".dll", ".pdb", ".xml", ".json", ".cfg", ".txt", ".md" };
string text = Directory.GetFiles(directoryName).FirstOrDefault(delegate(string f)
{
string value = Path.GetExtension(f).ToLowerInvariant();
return !ignoredExtensions.Contains(value);
});
if (string.IsNullOrEmpty(text) || !File.Exists(text))
{
((BaseUnityPlugin)this).Logger.LogError((object)("Aucun bundle valide trouvé dans : " + directoryName));
return;
}
((BaseUnityPlugin)this).Logger.LogInfo((object)("Bundle détecté automatiquement : " + Path.GetFileName(text)));
_bundle = AssetBundle.LoadFromFile(text);
if ((Object)(object)_bundle == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Impossible de charger le bundle : " + text));
return;
}
_geigerItemDef = _bundle.LoadAsset<Item>("assets/lethalcompany/mods/facilitymeltdown/geiger counter/geigercounteritemdef.asset") ?? ((IEnumerable<Item>)_bundle.LoadAllAssets<Item>()).FirstOrDefault((Func<Item, bool>)((Item i) => (Object)(object)i != (Object)null && !string.IsNullOrEmpty(((Object)i).name) && ((Object)i).name.Equals("GeigerCounterItemDef", StringComparison.OrdinalIgnoreCase)));
_geigerInfoNode = _bundle.LoadAsset<TerminalNode>("assets/lethalcompany/mods/facilitymeltdown/geiger counter/geigercounternode.asset") ?? ((IEnumerable<TerminalNode>)_bundle.LoadAllAssets<TerminalNode>()).FirstOrDefault((Func<TerminalNode, bool>)((TerminalNode n) => (Object)(object)n != (Object)null && !string.IsNullOrEmpty(((Object)n).name) && ((Object)n).name.Equals("GeigerCounterNode", StringComparison.OrdinalIgnoreCase)));
if ((Object)(object)_geigerItemDef == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogError((object)"GeigerCounterItemDef.asset introuvable dans le bundle");
return;
}
_geigerItemDef.itemName = "Geiger counter";
((BaseUnityPlugin)this).Logger.LogInfo((object)("Geiger item trouvé : " + _geigerItemDef.itemName));
if ((Object)(object)_geigerInfoNode != (Object)null)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)("Geiger terminal node trouvé : " + ((Object)_geigerInfoNode).name));
}
else
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"GeigerCounterNode.asset introuvable, DawnLib utilisera seulement l'item");
}
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Erreur lors du chargement du bundle : " + ex));
}
}
private void RegisterGeigerWithDawnLib()
{
if (_registered || (Object)(object)_geigerItemDef == (Object)null)
{
return;
}
try
{
if ((Object)(object)_geigerItemDef.spawnPrefab != (Object)null && (Object)(object)NetworkManager.Singleton != (Object)null)
{
try
{
NetworkManager.Singleton.AddNetworkPrefab(_geigerItemDef.spawnPrefab);
}
catch
{
}
}
DawnLib.DefineItem(MeltdownKeys.GeigerCounter, _geigerItemDef, (Action<ItemInfoBuilder>)delegate(ItemInfoBuilder item)
{
item.DefineShop((Action<ShopBuilder>)delegate(ShopBuilder shopItem)
{
shopItem.OverrideCost(90);
if ((Object)(object)_geigerInfoNode != (Object)null)
{
shopItem.OverrideInfoNode(_geigerInfoNode);
}
});
});
_registered = true;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Geiger enregistré via DawnLib");
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Erreur DawnLib lors de l'enregistrement du Geiger : " + ex));
}
}
}
}
namespace FacilityMeltdown.Equipment
{
public class GeigerCounterItem : GrabbableObject
{
[Space(15f)]
[Header("Audio")]
public AudioSource generalAudioSource;
public AudioSource lowRadiation;
public AudioSource mediumRadiation;
public AudioSource highRadiation;
public AudioClip toggle;
public AudioClip outOfBattery;
public GameObject needle;
[Header("Needle")]
public float maxRotation = 25f;
public float maxDetection = 50f;
public float needleMoveSpeed = 180f;
public float needleOffRotation = 35f;
[Header("Needle Vibration")]
public float jitterStartThreshold = 0.6f;
public float jitterMax = 3f;
public float jitterSpeed = 10f;
public override void ItemActivate(bool used, bool buttonDown = true)
{
((GrabbableObject)this).ItemActivate(used, buttonDown);
SwitchPoweredState(used);
if ((Object)(object)generalAudioSource != (Object)null && (Object)(object)toggle != (Object)null)
{
generalAudioSource.clip = toggle;
generalAudioSource.Play();
}
}
public override void UseUpBatteries()
{
((GrabbableObject)this).UseUpBatteries();
SwitchPoweredState(on: false);
if ((Object)(object)generalAudioSource != (Object)null && (Object)(object)outOfBattery != (Object)null)
{
generalAudioSource.clip = outOfBattery;
generalAudioSource.Play();
}
}
public void SwitchPoweredState(bool on)
{
if (base.isBeingUsed)
{
if ((Object)(object)lowRadiation != (Object)null && !lowRadiation.isPlaying)
{
lowRadiation.Play();
}
if ((Object)(object)mediumRadiation != (Object)null && !mediumRadiation.isPlaying)
{
mediumRadiation.Play();
}
if ((Object)(object)highRadiation != (Object)null && !highRadiation.isPlaying)
{
highRadiation.Play();
}
}
else
{
if ((Object)(object)lowRadiation != (Object)null)
{
lowRadiation.Stop();
}
if ((Object)(object)mediumRadiation != (Object)null)
{
mediumRadiation.Stop();
}
if ((Object)(object)highRadiation != (Object)null)
{
highRadiation.Stop();
}
}
}
public override void Update()
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
((GrabbableObject)this).Update();
float num;
if (!base.isBeingUsed)
{
num = 0f - needleOffRotation;
}
else
{
float num2 = CollectRadiationFromClosestApparatus(((Component)this).transform.position);
float num3 = Mathf.Clamp01(num2 / maxDetection);
if ((Object)(object)lowRadiation != (Object)null)
{
lowRadiation.volume = 0f;
}
if ((Object)(object)mediumRadiation != (Object)null)
{
mediumRadiation.volume = 0f;
}
if ((Object)(object)highRadiation != (Object)null)
{
highRadiation.volume = 0f;
}
if (num2 > maxDetection)
{
if ((Object)(object)highRadiation != (Object)null)
{
highRadiation.volume = 1f;
}
}
else if (num2 > maxDetection / 2f)
{
if ((Object)(object)mediumRadiation != (Object)null)
{
mediumRadiation.volume = 1f;
}
}
else if (num2 > 0f && (Object)(object)lowRadiation != (Object)null)
{
lowRadiation.volume = 1f;
}
num = num3 * maxRotation * 2f - maxRotation;
if (num3 > jitterStartThreshold)
{
float num4 = (num3 - jitterStartThreshold) / (1f - jitterStartThreshold);
float num5 = (Mathf.PerlinNoise(Time.time * jitterSpeed, 0f) - 0.5f) * 2f * jitterMax * num4;
num += num5;
}
}
MoveNeedleSmoothly(num);
}
private void MoveNeedleSmoothly(float targetY)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)needle == (Object)null))
{
float num = Mathf.MoveTowardsAngle(needle.transform.localEulerAngles.y, targetY, needleMoveSpeed * Time.deltaTime);
needle.transform.localEulerAngles = new Vector3(-90f, num, 0f);
}
}
private float CollectRadiationFromClosestApparatus(Vector3 point)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
LungProp[] array = Object.FindObjectsOfType<LungProp>(false);
if (array == null || array.Length == 0)
{
return 0f;
}
float num = float.MaxValue;
LungProp[] array2 = array;
foreach (LungProp val in array2)
{
if (!((Object)(object)val == (Object)null))
{
float num2 = Vector3.Distance(point, ((Component)val).transform.position);
if (num2 < num)
{
num = num2;
}
}
}
if (num >= maxDetection)
{
return 0f;
}
return maxDetection - num;
}
}
}