using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using FacilityMeltdown.Effects;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("FacilityMeltdownPatch")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FacilityMeltdownPatch")]
[assembly: AssemblyCopyright("Copyright © RtPoogle 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d8b4d3d1-d526-429d-a235-9bec5d550d2f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
internal IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}
namespace FacilityMeltdownPatch
{
[BepInPlugin("xyz.poogle.facilitymeltdownpatch", "Facility Meltdown Patch", "1.1.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class FacilityMeltdownPatchPlugin : BaseUnityPlugin
{
public const string GUID = "xyz.poogle.facilitymeltdownpatch";
public const string NAME = "Facility Meltdown Patch";
public const string VER = "1.1.1";
public readonly Harmony harmony = new Harmony("xyz.poogle.facilitymeltdownpatch");
public ManualLogSource LogSrc;
public static FacilityMeltdownPatchPlugin Instance;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
LogSrc = Logger.CreateLogSource("xyz.poogle.facilitymeltdownpatch");
Patches.InitPatches();
LogSrc.LogInfo((object)"Initialized!");
}
}
internal class Patches
{
[HarmonyPatch(typeof(WarningAnnouncerEffect))]
[HarmonyPatch("Setup")]
public static class WarningAnnouncerEffect_Setup_Patch
{
public static void Postfix(WarningAnnouncerEffect __instance)
{
__instance.warningAudioSource.rolloffMode = (AudioRolloffMode)1;
__instance.warningAudioSource.maxDistance = 175f;
__instance.warningAudioSource.minDistance = __instance.warningAudioSource.maxDistance - 1f;
__instance.warningAudioSource.spatialBlend = 1f;
}
}
[HarmonyPatch]
public static class WarningAnnouncerEffect_Play_Patch
{
public static MethodBase TargetMethod()
{
return AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(WarningAnnouncerEffect), "Play", (Type[])null, (Type[])null));
}
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator il)
{
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_0146: Expected O, but got Unknown
//IL_0152: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Expected O, but got Unknown
//IL_0168: Unknown result type (might be due to invalid IL or missing references)
//IL_0172: Expected O, but got Unknown
//IL_017a: Unknown result type (might be due to invalid IL or missing references)
//IL_0184: Expected O, but got Unknown
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Expected O, but got Unknown
FacilityMeltdownPatchPlugin.Instance.LogSrc.LogInfo((object)"Patching Play!");
FieldInfo obj = AccessTools.Field(typeof(WarningAnnouncerEffect), "warningAudioSource");
MethodInfo methodInfo = AccessTools.Method(typeof(AudioSource), "Play", (Type[])null, (Type[])null);
MethodInfo methodInfo2 = AccessTools.Method(typeof(WarningAnnouncerEffect_Play_Patch), "PlayAtPos", (Type[])null, (Type[])null);
MethodInfo methodInfo3 = AccessTools.Method(typeof(Object), "FindObjectsOfType", (Type[])null, new Type[1] { typeof(EntranceTeleport) });
MethodInfo methodInfo4 = AccessTools.Method(typeof(Enumerable), "ToList", (Type[])null, new Type[1] { typeof(EntranceTeleport) });
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
int num = -1;
for (int i = 0; i < list.Count - 1; i++)
{
if (list[i].opcode == OpCodes.Ldfld && list[i].operand.Equals(obj) && CodeInstructionExtensions.Calls(list[i + 1], methodInfo))
{
num = i;
break;
}
}
if (num == -1)
{
FacilityMeltdownPatchPlugin.Instance.LogSrc.LogError((object)"Could not find IL to transpile, bailing patch!");
return list;
}
list[num] = new CodeInstruction(OpCodes.Nop, (object)null);
list[num + 1] = new CodeInstruction(OpCodes.Nop, (object)null);
List<CodeInstruction> collection = new List<CodeInstruction>
{
new CodeInstruction(OpCodes.Call, (object)methodInfo3),
new CodeInstruction(OpCodes.Call, (object)methodInfo4),
new CodeInstruction(OpCodes.Call, (object)methodInfo2)
};
list.InsertRange(num, collection);
FacilityMeltdownPatchPlugin.Instance.LogSrc.LogInfo((object)"Patched Play!");
return list;
}
public static void PlayAtPos(WarningAnnouncerEffect instance, List<EntranceTeleport> AllEntrances)
{
AllEntrances.ForEach(delegate(EntranceTeleport entrance)
{
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: 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_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: 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)
if (instance == null || entrance == null)
{
FacilityMeltdownPatchPlugin.Instance.LogSrc.LogError((object)"null check failed!");
}
else
{
float num = 1f;
Vector3 position = ((Component)GameNetworkManager.Instance.localPlayerController).transform.position;
Vector3 position2 = ((Component)entrance.entrancePoint).transform.position;
if (GameNetworkManager.Instance.localPlayerController.isInsideFactory && (entrance.gotExitPoint || entrance.FindExitPoint()))
{
num = 1.5f;
position2 = ((Component)entrance.exitPoint).transform.position;
}
((Component)instance.warningAudioSource).transform.position = position2;
instance.warningAudioSource.PlayOneShot(instance.warningAudioSource.clip, 1f - Vector3.Distance(position2, position) / (instance.warningAudioSource.maxDistance * num));
}
});
}
}
internal static void InitPatches()
{
FacilityMeltdownPatchPlugin.Instance.harmony.PatchAll();
}
}
}