using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Unity.Collections;
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: AssemblyTitle("LethalBeacons")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LethalBeacons")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("96d515ea-5fc3-46f1-8f04-3c7503e38cf2")]
[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 LethalBeacons;
[BepInDependency("evaisa.lethallib", "0.13.2")]
[BepInPlugin("Comet.LETHALBEACONS", "Leathal Beacons", "1.4.0")]
public class BeaconsMod : BaseUnityPlugin
{
public const string GUID = "Comet.LETHALBEACONS";
private readonly Harmony harmony = new Harmony("Comet.LETHALBEACONS");
public static ConfigEntry<int> beaconPrice;
public static ConfigEntry<int> beaconRange;
public static Item beaconItem;
private void Awake()
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Expected O, but got Unknown
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Expected O, but got Unknown
beaconPrice = ((BaseUnityPlugin)this).Config.Bind<int>("Server-side", "Beacon Price", 65, new ConfigDescription("[Host only] The cost of a Beacon in the store. This will sync with other clients who have the mod.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 999), Array.Empty<object>()));
beaconRange = ((BaseUnityPlugin)this).Config.Bind<int>("Server-side", "Beacon Range", 75, new ConfigDescription("[Host only] From how far away the beacon can be scanned. This will sync with other clients who have the mod.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>()));
string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "itemmod");
AssetBundle val = AssetBundle.LoadFromFile(text);
beaconItem = val.LoadAsset<Item>("Assets/BeaconItem.asset");
((Component)beaconItem.spawnPrefab.GetComponentInChildren<ScanNodeProperties>()).gameObject.AddComponent<InfRangeScan>();
NetworkPrefabs.RegisterNetworkPrefab(beaconItem.spawnPrefab);
Utilities.FixMixerGroups(beaconItem.spawnPrefab);
Items.RegisterShopItem(beaconItem, beaconPrice.Value);
harmony.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"ITEM HAS BEEN PATCHED");
}
}
[HarmonyPatch(typeof(GrabbableObject))]
[HarmonyPatch("EnableItemMeshes")]
public class PatchedObject
{
private static void Postfix(GrabbableObject __instance, bool enable)
{
if (Object.op_Implicit((Object)(object)((Component)__instance).GetComponentInChildren<InfRangeScan>()))
{
Light[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Light>();
foreach (Light val in componentsInChildren)
{
((Behaviour)val).enabled = enable;
}
}
}
}
[HarmonyPatch]
public class NetworkingBeaconPrice
{
private static bool syncStatus = false;
private static int beaconprice = 65;
private static float beaconrange = 75f;
[HarmonyPatch(typeof(StartOfRound), "Awake")]
[HarmonyPostfix]
public static void ResetValues()
{
syncStatus = false;
}
[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
[HarmonyPostfix]
public static void Init()
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Expected O, but got Unknown
syncStatus = false;
if (NetworkManager.Singleton.IsServer)
{
NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("LethalBeacons.OnRequestSyncServerRpc", new HandleNamedMessageDelegate(OnRequestSyncServerRpc));
beaconprice = BeaconsMod.beaconPrice.Value;
beaconrange = BeaconsMod.beaconRange.Value;
OnSyncedWithServer();
}
else if (NetworkManager.Singleton.IsClient)
{
NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("LethalBeacons.OnRequestSyncClientRpc", new HandleNamedMessageDelegate(OnRequestSyncClientRpc));
RequestSyncWithServer();
}
}
[HarmonyPatch(typeof(HUDManager), "AssignNewNodes")]
[HarmonyPrefix]
public static bool ForceAddBeacons(HUDManager __instance, ref List<ScanNodeProperties> ___nodesOnScreen, ref RectTransform[] ___scanElements, ref RaycastHit[] ___scanNodesHit, ref int ___scannedScrapNum, PlayerControllerB playerScript)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: 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_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0203: Unknown result type (might be due to invalid IL or missing references)
//IL_0208: Unknown result type (might be due to invalid IL or missing references)
//IL_02da: Unknown result type (might be due to invalid IL or missing references)
//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
Physics.SphereCastNonAlloc(new Ray(((Component)playerScript.gameplayCamera).transform.position + ((Component)playerScript.gameplayCamera).transform.forward * 20f, ((Component)playerScript.gameplayCamera).transform.forward), 20f, ___scanNodesHit, 80f, 4194304);
List<ScanNodeProperties> list = new List<ScanNodeProperties>();
int num = 0;
___nodesOnScreen.Clear();
___scannedScrapNum = 0;
if (___scanNodesHit != null)
{
RaycastHit[] array = ___scanNodesHit;
ScanNodeProperties val2 = default(ScanNodeProperties);
for (int i = 0; i < array.Length; i++)
{
RaycastHit val = array[i];
if (!((Object)(object)((RaycastHit)(ref val)).transform != (Object)null) || !((Component)((RaycastHit)(ref val)).transform).gameObject.TryGetComponent<ScanNodeProperties>(ref val2))
{
continue;
}
Vector3 val3 = ((Component)playerScript.gameplayCamera).transform.InverseTransformPoint(((RaycastHit)(ref val)).transform.position);
if (val3.z > 0f && !(Mathf.Abs(val3.x) / val3.z > 0.5f))
{
GrabbableObject componentInParent = ((Component)val2).gameObject.GetComponentInParent<GrabbableObject>();
if (!((Object)(object)componentInParent != (Object)null) || (!componentInParent.isPocketed && !componentInParent.isHeld))
{
list.Add(val2);
num++;
}
}
}
}
if (InfRangeScan.allBeacons != null)
{
foreach (InfRangeScan allBeacon in InfRangeScan.allBeacons)
{
if (!((Object)(object)allBeacon != (Object)null) || !Object.op_Implicit((Object)(object)((Component)allBeacon).gameObject))
{
continue;
}
ScanNodeProperties component = ((Component)allBeacon).GetComponent<ScanNodeProperties>();
if ((Object)(object)component != (Object)null)
{
Vector3 val4 = ((Component)playerScript.gameplayCamera).transform.InverseTransformPoint(((Component)component).transform.position);
float magnitude = ((Vector3)(ref val4)).magnitude;
allBeacon.myNodes.subText = $"Dist: {(int)magnitude}m";
if (!list.Contains(component) && ((Component)component).gameObject.activeInHierarchy && !(magnitude > beaconrange) && playerScript.isInsideFactory == allBeacon.parentItem.isInFactory && !((Object)(object)allBeacon.parentItem.playerHeldBy != (Object)null) && !allBeacon.parentItem.isPocketed && !allBeacon.parentItem.isHeld && val4.z > 0f && !(Mathf.Abs(val4.x) / val4.z > 0.5f))
{
list.Add(component);
num++;
}
}
}
}
if (num > ___scanElements.Length)
{
num = ___scanElements.Length;
}
for (int j = 0; j < num; j++)
{
ScanNodeProperties val5 = list[j];
MethodInfo method = ((object)__instance).GetType().GetMethod("AttemptScanNode", BindingFlags.Instance | BindingFlags.NonPublic);
method.Invoke(__instance, new object[3] { val5, j, playerScript });
}
return false;
}
private static void RequestSyncWithServer()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("LethalBeacons.OnRequestSyncServerRpc", 0uL, new FastBufferWriter(0, (Allocator)2, -1), (NetworkDelivery)3);
}
private static void OnRequestSyncServerRpc(ulong clientId, FastBufferReader reader)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
if (NetworkManager.Singleton.IsServer)
{
FastBufferWriter val = default(FastBufferWriter);
((FastBufferWriter)(ref val))..ctor(4, (Allocator)2, -1);
((FastBufferWriter)(ref val)).WriteValue<int>(ref beaconprice, default(ForPrimitives));
((FastBufferWriter)(ref val)).WriteValue<float>(ref beaconrange, default(ForPrimitives));
NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("LethalBeacons.OnRequestSyncClientRpc", clientId, val, (NetworkDelivery)3);
}
}
private static void OnRequestSyncClientRpc(ulong clientId, FastBufferReader reader)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: 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)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
if (NetworkManager.Singleton.IsClient && !NetworkManager.Singleton.IsServer)
{
int num = default(int);
((FastBufferReader)(ref reader)).ReadValue<int>(ref num, default(ForPrimitives));
beaconprice = num;
float num2 = default(float);
((FastBufferReader)(ref reader)).ReadValue<float>(ref num2, default(ForPrimitives));
beaconrange = num2;
OnSyncedWithServer();
}
}
private static void OnSyncedWithServer()
{
syncStatus = true;
Items.UpdateShopItemPrice(BeaconsMod.beaconItem, beaconprice);
}
}
public class InfRangeScan : MonoBehaviour
{
public static List<InfRangeScan> allBeacons = new List<InfRangeScan>();
public static RaycastHit[] foundbeacons = (RaycastHit[])(object)new RaycastHit[13];
public ScanNodeProperties myNodes;
public GrabbableObject parentItem;
private void Start()
{
allBeacons.Add(this);
myNodes = ((Component)this).GetComponent<ScanNodeProperties>();
parentItem = ((Component)this).GetComponentInParent<GrabbableObject>();
}
}