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.Versioning;
using BepInEx;
using HarmonyLib;
using LaterNights.Patches;
using Microsoft.CodeAnalysis;
using TMPro;
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 = "")]
[assembly: AssemblyCompany("LaterNights")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LaterNights")]
[assembly: AssemblyTitle("LaterNights")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
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 LaterNights
{
[BepInPlugin("atk.lethalcompany.laternights", "Later Nights", "1.0.0")]
public class LaterNightsMod : BaseUnityPlugin
{
public const string pluginGuid = "atk.lethalcompany.laternights";
public const string pluginName = "Later Nights";
public const string pluginVersion = "1.0.0";
public static Harmony harmony;
public void Awake()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
harmony = new Harmony("atk.lethalcompany.laternights");
harmony.PatchAll(typeof(LaterNights.Patches.Patches));
((BaseUnityPlugin)this).Logger.LogInfo((object)"Later Nights mod loaded");
}
}
}
namespace LaterNights.Patches
{
[HarmonyPatch]
internal class Patches
{
private static float realTotalTime;
private static float offset;
[HarmonyPatch(typeof(TimeOfDay), "Start")]
[HarmonyPostfix]
public static void Start(ref TimeOfDay __instance)
{
realTotalTime = __instance.lengthOfHours * (float)__instance.numberOfHours;
__instance.numberOfHours = 24;
__instance.totalTime = __instance.lengthOfHours * (float)__instance.numberOfHours;
offset = (float)(__instance.numberOfHours - 18) / (float)__instance.numberOfHours;
}
[HarmonyPatch(typeof(TimeOfDay), "MoveTimeOfDay")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> MoveTimeOfDay(IEnumerable<CodeInstruction> instructions)
{
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Expected O, but got Unknown
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Expected O, but got Unknown
FieldInfo fieldInfo = AccessTools.Field(typeof(Patches), "offset");
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Ldfld && list[i + 1].opcode == OpCodes.Ldc_R4 && (float)list[i + 1].operand == 0f)
{
list.Insert(i + 1, new CodeInstruction(OpCodes.Ldsfld, (object)fieldInfo));
list.Insert(i + 2, new CodeInstruction(OpCodes.Add, (object)null));
}
}
return list.AsEnumerable();
}
[HarmonyPatch(typeof(HUDManager), "SetClock")]
[HarmonyPrefix]
public static bool SetClock(ref HUDManager __instance, ref string __result, ref string ___newLine, ref string ___amPM, float timeNormalized, float numberOfHours, bool createNewLine = true)
{
int num = (int)(timeNormalized * (60f * numberOfHours)) + 360;
int num2 = (int)Mathf.Floor((float)(num / 60));
if (!createNewLine)
{
___newLine = " ";
}
else
{
___newLine = "\n";
}
___amPM = ___newLine + "AM";
if (num2 >= 24)
{
num2 %= 24;
}
if (num2 < 12)
{
___amPM = ___newLine + "AM";
}
else
{
___amPM = ___newLine + "PM";
}
if (num2 > 12)
{
num2 %= 12;
}
int num3 = num % 60;
string text = $"{num2:00}:{num3:00}" + ___amPM;
((TMP_Text)__instance.clockNumber).text = text;
__result = text;
return false;
}
[HarmonyPatch(typeof(RoundManager), "SpawnEnemiesOutside")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> SpawnEnemiesOutside(IEnumerable<CodeInstruction> instructions)
{
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Expected O, but got Unknown
FieldInfo fieldInfo = AccessTools.Field(typeof(TimeOfDay), "totalTime");
FieldInfo fieldInfo2 = AccessTools.Field(typeof(Patches), "realTotalTime");
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 0; i < list.Count; i++)
{
if (CodeInstructionExtensions.LoadsField(list[i], fieldInfo, false))
{
list[i] = new CodeInstruction(OpCodes.Ldsfld, (object)fieldInfo2);
list.RemoveAt(i - 1);
list.RemoveAt(i - 2);
i -= -2;
}
}
return list.AsEnumerable();
}
[HarmonyPatch(typeof(RoundManager), "SpawnDaytimeEnemiesOutside")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> SpawnDaytimeEnemiesOutside(IEnumerable<CodeInstruction> instructions)
{
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Expected O, but got Unknown
FieldInfo fieldInfo = AccessTools.Field(typeof(TimeOfDay), "totalTime");
FieldInfo fieldInfo2 = AccessTools.Field(typeof(Patches), "realTotalTime");
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 0; i < list.Count; i++)
{
if (CodeInstructionExtensions.LoadsField(list[i], fieldInfo, false))
{
list[i] = new CodeInstruction(OpCodes.Ldsfld, (object)fieldInfo2);
list.RemoveAt(i - 1);
list.RemoveAt(i - 2);
i -= -2;
}
}
return list.AsEnumerable();
}
[HarmonyPatch(typeof(RoundManager), "SpawnRandomDaytimeEnemy")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> SpawnRandomDaytimeEnemy(IEnumerable<CodeInstruction> instructions)
{
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Expected O, but got Unknown
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Expected O, but got Unknown
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Expected O, but got Unknown
FieldInfo fieldInfo = AccessTools.Field(typeof(TimeOfDay), "totalTime");
FieldInfo fieldInfo2 = AccessTools.Field(typeof(TimeOfDay), "normalizedTimeOfDay");
FieldInfo fieldInfo3 = AccessTools.Field(typeof(Patches), "realTotalTime");
FieldInfo fieldInfo4 = AccessTools.Field(typeof(Patches), "offset");
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 0; i < list.Count; i++)
{
if (CodeInstructionExtensions.LoadsField(list[i], fieldInfo, false))
{
list[i] = new CodeInstruction(OpCodes.Ldsfld, (object)fieldInfo3);
list.RemoveAt(i - 1);
list.RemoveAt(i - 2);
i -= -2;
}
else if (CodeInstructionExtensions.LoadsField(list[i], fieldInfo2, false))
{
list.Insert(i + 1, new CodeInstruction(OpCodes.Add, (object)null));
list.Insert(i + 1, new CodeInstruction(OpCodes.Ldsfld, (object)fieldInfo4));
}
}
return list.AsEnumerable();
}
[HarmonyPatch(typeof(RoundManager), "AssignRandomEnemyToVent")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> AssignRandomEnemyToVent(IEnumerable<CodeInstruction> instructions)
{
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Expected O, but got Unknown
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Expected O, but got Unknown
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Expected O, but got Unknown
FieldInfo fieldInfo = AccessTools.Field(typeof(TimeOfDay), "totalTime");
FieldInfo fieldInfo2 = AccessTools.Field(typeof(TimeOfDay), "normalizedTimeOfDay");
FieldInfo fieldInfo3 = AccessTools.Field(typeof(Patches), "realTotalTime");
FieldInfo fieldInfo4 = AccessTools.Field(typeof(Patches), "offset");
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 0; i < list.Count; i++)
{
if (CodeInstructionExtensions.LoadsField(list[i], fieldInfo, false))
{
list[i] = new CodeInstruction(OpCodes.Ldsfld, (object)fieldInfo3);
list.RemoveAt(i - 1);
list.RemoveAt(i - 2);
i -= -2;
}
else if (CodeInstructionExtensions.LoadsField(list[i], fieldInfo2, false))
{
list.Insert(i + 1, new CodeInstruction(OpCodes.Add, (object)null));
list.Insert(i + 1, new CodeInstruction(OpCodes.Ldsfld, (object)fieldInfo4));
}
}
return list.AsEnumerable();
}
[HarmonyPatch(typeof(RoundManager), "AdvanceHourAndSpawnNewBatchOfEnemies")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> AdvanceHourAndSpawnNewBatchOfEnemies(IEnumerable<CodeInstruction> instructions)
{
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Expected O, but got Unknown
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Expected O, but got Unknown
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Expected O, but got Unknown
FieldInfo fieldInfo = AccessTools.Field(typeof(TimeOfDay), "totalTime");
FieldInfo fieldInfo2 = AccessTools.Field(typeof(TimeOfDay), "normalizedTimeOfDay");
FieldInfo fieldInfo3 = AccessTools.Field(typeof(Patches), "realTotalTime");
FieldInfo fieldInfo4 = AccessTools.Field(typeof(Patches), "offset");
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 0; i < list.Count; i++)
{
if (CodeInstructionExtensions.LoadsField(list[i], fieldInfo, false))
{
list[i] = new CodeInstruction(OpCodes.Ldsfld, (object)fieldInfo3);
list.RemoveAt(i - 1);
list.RemoveAt(i - 2);
i -= -2;
}
else if (CodeInstructionExtensions.LoadsField(list[i], fieldInfo2, false))
{
list.Insert(i + 1, new CodeInstruction(OpCodes.Add, (object)null));
list.Insert(i + 1, new CodeInstruction(OpCodes.Ldsfld, (object)fieldInfo4));
}
}
return list.AsEnumerable();
}
}
}