using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.Json;
using Agents;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Enemies;
using GameData;
using Gear;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MTFO.Managers;
using Microsoft.CodeAnalysis;
using Player;
using SDN.SilencedWeapons.SilencedWeaponsBase;
using SDN.SilencedWeapons.SilencedWeaponsBase.Patches;
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(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("EdnKrs.SDN")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EdnKrs.SDN")]
[assembly: AssemblyTitle("EdnKrs.SDN")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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 Logging
{
internal static class Logging
{
private static readonly ManualLogSource _logger;
static Logging()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
_logger = new ManualLogSource("SilencedWeapons");
Logger.Sources.Add((ILogSource)(object)_logger);
}
private static string Format(object msg)
{
return msg.ToString();
}
public static void Info(object data)
{
_logger.LogMessage((object)Format(data));
}
public static void Verbose(object data)
{
}
public static void Debug(object data)
{
_logger.LogDebug((object)Format(data));
}
public static void Error(object data)
{
_logger.LogError((object)Format(data));
}
}
}
namespace EntryPoint
{
internal static class ModuleInfo
{
public const string GUID = "EdnKrs.SDN";
public const string Name = "SDN";
public const string Version = "1.0.0";
}
[BepInPlugin("EdnKrs.SDN", "SDN", "1.0.0")]
internal class Injection : BasePlugin
{
private static Harmony? harmony;
public override void Load()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Expected O, but got Unknown
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
ClassInjector.RegisterTypeInIl2Cpp<SilencerNoiseHandler>();
harmony = new Harmony("EdnKrs.SDN");
new Harmony("SDN").PatchAll();
}
}
}
namespace SDN.SilencedWeapons.SilencedWeaponsBase
{
public class SilencerDatablock
{
public uint ArchetypeID { get; set; }
public string InternalName { get; set; } = "Internal name - not referenced ingame";
public bool InternalEnabled { get; set; }
public SilencerSettings SilencerSettingsData { get; set; } = new SilencerSettings();
}
internal class SilencerManager
{
public static string? Filepath { get; set; }
public static string? Content { get; set; }
public static Dictionary<uint, SilencerDatablock> SilencerData { get; set; } = new Dictionary<uint, SilencerDatablock>();
public static void Deserialize()
{
Filepath = Path.Combine(ConfigManager.CustomPath, "EdnKrs.SDN");
if (!Directory.Exists(Filepath))
{
Directory.CreateDirectory(Filepath);
}
Filepath = Path.Combine(Filepath, "SDN.json");
if (!File.Exists(Filepath))
{
Content = JsonSerializer.Serialize(new List<SilencerDatablock>
{
new SilencerDatablock()
}, new JsonSerializerOptions
{
WriteIndented = true
});
File.WriteAllText(Filepath, Content);
}
else
{
Content = File.ReadAllText(Filepath);
}
if (Content == null)
{
return;
}
foreach (SilencerDatablock item in JsonSerializer.Deserialize<List<SilencerDatablock>>(Content))
{
SilencerData.Add(item.ArchetypeID, item);
}
}
public static bool TryApplySilencerData(ref BulletWeapon bulletWeapon, out SilencerNoiseHandler? noiseHandler)
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
if (!SilencerData.TryGetValue(((GameDataBlockBase<ArchetypeDataBlock>)(object)((ItemEquippable)bulletWeapon).ArchetypeData).persistentID, out SilencerDatablock value) || !value.InternalEnabled)
{
noiseHandler = null;
return false;
}
noiseHandler = ((Component)bulletWeapon).gameObject.AddComponent<SilencerNoiseHandler>();
noiseHandler.SoftAlert_Radius = value.SilencerSettingsData.Audio_SoftAlertRadius;
noiseHandler.HardAlert_Radius = value.SilencerSettingsData.Audio_HardAlertRadius;
return true;
}
public static void BulletWeaponFire(IntPtr pointer, PlayerAgent owner)
{
if (Patch_GearBuilder.SilencedWeapons.TryGetValue(pointer, out SilencerNoiseHandler value))
{
((Agent)owner).m_noise = (NoiseType)1;
value.Fire();
}
}
}
internal class SilencerNoiseHandler : MonoBehaviour
{
public NM_NoiseData SoftAlert_NoiseData;
public NM_NoiseData HardAlert_NoiseData;
public float SoftAlert_Radius;
public float HardAlert_Radius;
public PlayerAgent Owner;
public float cooldown;
public SilencerNoiseHandler(IntPtr value)
: base(value)
{
}
public void Start()
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Expected O, but got Unknown
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: 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)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Expected O, but got Unknown
SoftAlert_NoiseData = new NM_NoiseData
{
radiusMin = 0.01f,
radiusMax = 1f,
yScale = 1f,
type = (NM_NoiseType)1,
includeToNeightbourAreas = true,
raycastFirstNode = true
};
HardAlert_NoiseData = new NM_NoiseData
{
radiusMin = 0.01f,
radiusMax = 1f,
yScale = 1f,
type = (NM_NoiseType)0,
includeToNeightbourAreas = true,
raycastFirstNode = true
};
}
public void Fire()
{
//IL_0054: 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_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0154: Unknown result type (might be due to invalid IL or missing references)
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
if (Time.time < cooldown)
{
return;
}
cooldown = Time.time + 1f;
if (Owner == null)
{
Owner = ((Item)((Component)this).gameObject.GetComponent<BulletWeapon>()).Owner;
}
Il2CppReferenceArray<Collider> val = Physics.OverlapSphere(((Agent)Owner).Position, MathF.Max(SoftAlert_Radius, HardAlert_Radius), LayerManager.MASK_ENEMY_DAMAGABLE);
List<string> list = new List<string>();
foreach (Collider item in (Il2CppArrayBase<Collider>)(object)val)
{
Dam_EnemyDamageLimb component = ((Component)item).GetComponent<Dam_EnemyDamageLimb>();
if ((Object)(object)component == (Object)null)
{
continue;
}
EnemyAgent glueTargetEnemyAgent = component.GlueTargetEnemyAgent;
if ((Object)(object)glueTargetEnemyAgent == (Object)null || list.Contains(((Object)((Component)glueTargetEnemyAgent).gameObject).name))
{
continue;
}
list.Add(((Object)((Component)glueTargetEnemyAgent).gameObject).name);
if (!Physics.Linecast(((Agent)Owner).EyePosition, ((Agent)glueTargetEnemyAgent).EyePosition, LayerManager.MASK_WORLD) && ((int)((Agent)glueTargetEnemyAgent).CourseNode.m_zone.LocalIndex == 0 || ((Agent)glueTargetEnemyAgent).CourseNode.m_zone.m_sourceGate.HasBeenOpenedDuringPlay))
{
if (Vector3.Distance(((Agent)Owner).EyePosition, ((Agent)glueTargetEnemyAgent).EyePosition) <= HardAlert_Radius)
{
HardAlert_NoiseData.noiseMaker = ((Il2CppObjectBase)Owner).Cast<INM_NoiseMaker>();
HardAlert_NoiseData.position = glueTargetEnemyAgent.Position;
HardAlert_NoiseData.node = ((Agent)glueTargetEnemyAgent).CourseNode;
NoiseManager.MakeNoise(HardAlert_NoiseData);
}
else
{
SoftAlert_NoiseData.noiseMaker = ((Il2CppObjectBase)Owner).Cast<INM_NoiseMaker>();
SoftAlert_NoiseData.position = glueTargetEnemyAgent.Position;
SoftAlert_NoiseData.node = ((Agent)glueTargetEnemyAgent).CourseNode;
NoiseManager.MakeNoise(SoftAlert_NoiseData);
}
}
}
}
}
public class SilencerSettings
{
public float Audio_SoftAlertRadius { get; set; }
public float Audio_HardAlertRadius { get; set; }
}
}
namespace SDN.SilencedWeapons.SilencedWeaponsBase.Patches
{
[HarmonyPatch]
internal class Patch_BulletWeapon
{
[HarmonyPostfix]
[HarmonyPatch(typeof(BulletWeapon), "Fire")]
public static void Fire(BulletWeapon __instance)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
SilencerManager.BulletWeaponFire(((Il2CppObjectBase)__instance).Pointer, ((Item)__instance).Owner);
}
}
[HarmonyPatch]
internal class Patch_BulletWeaponSynced
{
[HarmonyPostfix]
[HarmonyPatch(typeof(BulletWeaponSynced), "Fire")]
public static void Fire(BulletWeaponSynced __instance)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
SilencerManager.BulletWeaponFire(((Il2CppObjectBase)__instance).Pointer, ((Item)__instance).Owner);
}
}
[HarmonyPatch]
internal class Patch_GameDataInit
{
[HarmonyPostfix]
[HarmonyPatch(typeof(GameDataInit), "Initialize")]
public static void Initialize()
{
SilencerManager.Deserialize();
}
}
[HarmonyPatch]
internal class Patch_GearBuilder
{
public static PlayerAgent? Owner { get; set; } = null;
public static bool DoSilence { get; set; } = false;
public static Dictionary<IntPtr, SilencerNoiseHandler> SilencedWeapons { get; set; } = new Dictionary<IntPtr, SilencerNoiseHandler>();
[HarmonyPostfix]
[HarmonyPatch(typeof(GearBuilder), "AssembleGearAsync")]
public static void AssembleGearAsync(ItemEquippable __result)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Expected O, but got Unknown
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Expected O, but got Unknown
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)__result == (Object)null))
{
BulletWeapon bulletWeapon = ((Component)__result).gameObject.GetComponent<BulletWeapon>();
if (!((Object)bulletWeapon == (Object)null) && SilencerManager.TryApplySilencerData(ref bulletWeapon, out SilencerNoiseHandler noiseHandler) && !SilencedWeapons.ContainsKey(((Il2CppObjectBase)bulletWeapon).Pointer))
{
SilencedWeapons.Add(((Il2CppObjectBase)bulletWeapon).Pointer, noiseHandler);
}
}
}
}
[HarmonyPatch]
internal class Patch_Shotgun
{
[HarmonyPostfix]
[HarmonyPatch(typeof(Shotgun), "Fire")]
public static void Fire(Shotgun __instance)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
SilencerManager.BulletWeaponFire(((Il2CppObjectBase)__instance).Pointer, ((Item)__instance).Owner);
}
}
[HarmonyPatch]
internal class Patch_ShotgunSynced
{
[HarmonyPostfix]
[HarmonyPatch(typeof(ShotgunSynced), "Fire")]
public static void Fire(ShotgunSynced __instance)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
SilencerManager.BulletWeaponFire(((Il2CppObjectBase)__instance).Pointer, ((Item)__instance).Owner);
}
}
}