#define DEBUG
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BoplFixedMath;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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(".NETFramework,Version=v4.6", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("BetterTimeStop")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BetterTimeStop")]
[assembly: AssemblyTitle("BetterTimeStop")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace BetterTimeStop
{
[BepInPlugin("com.maxgamertyper1.bettertimestop", "Better Time Stop", "1.0.0")]
public class BetterTimeStop : BaseUnityPlugin
{
internal static ConfigFile config;
internal static ConfigEntry<int> MinimumDuration;
internal static ConfigEntry<int> MaximumDuration;
internal static ConfigEntry<bool> MaximumOverride;
public void Log(string message)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)message);
}
private void Awake()
{
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
Log("Plugin BetterTimeStop is loaded!");
DoPatching();
config = ((BaseUnityPlugin)this).Config;
MinimumDuration = config.Bind<int>("Duration", "MinimumDuration", 5, "The Minimum duration of the TimeStop (Vanilla is 10)");
MaximumDuration = config.Bind<int>("Duration", "MaximumDuration", 15, "The Maximum duration of the TimeStop (Vanilla is 10)");
Patches.MaximumDuration = new Fix(MaximumDuration.Value);
Patches.MinimumDuration = new Fix(MinimumDuration.Value);
}
private void DoPatching()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
Harmony harmony = new Harmony("com.maxgamertyper1.bettertimestop");
Patch(harmony, typeof(CastSpell), "Awake", "MinDurationPatch", prefix: false, transpiler: false);
Patch(harmony, typeof(CastSpell), "Update", "UpdateTimeData", prefix: false, transpiler: false);
Patch(harmony, typeof(CastSpell), "UpdateSim", "IfStatementOverride", prefix: false, transpiler: true);
Patch(harmony, typeof(TimeStop), "Init", "DurationPatch", prefix: false, transpiler: false);
}
private void OnDestroy()
{
Log("Bye Bye From BetterTimeStop");
}
private void Patch(Harmony harmony, Type OriginalClass, string OriginalMethod, string PatchMethod, bool prefix, bool transpiler)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Expected O, but got Unknown
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Expected O, but got Unknown
MethodInfo methodInfo = AccessTools.Method(OriginalClass, OriginalMethod, (Type[])null, (Type[])null);
MethodInfo methodInfo2 = AccessTools.Method(typeof(Patches), PatchMethod, (Type[])null, (Type[])null);
if (prefix)
{
harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
else if (transpiler)
{
harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null);
}
else
{
harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
Log("Patched " + OriginalMethod + " in " + OriginalClass.ToString());
}
}
public class Patches
{
public static Fix MaximumDuration;
public static Fix MinimumDuration;
private static Dictionary<int, Fix> TimeData = new Dictionary<int, Fix>();
public static void MinDurationPatch(ref CastSpell __instance)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
if (((Object)__instance.spell).name == "TimeStopSphere")
{
__instance.castTime = MinimumDuration;
}
}
private static IEnumerable<CodeInstruction> IfStatementOverride(IEnumerable<CodeInstruction> instructions)
{
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Expected O, but got Unknown
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Ldfld && list[i].operand is FieldInfo fieldInfo && fieldInfo.Name == "castTime" && fieldInfo.DeclaringType == typeof(CastSpell))
{
Debug.Print("Found load to stack and replaced with MaximumDuration");
FieldInfo field = typeof(Patches).GetField("MaximumDuration", BindingFlags.Static | BindingFlags.Public);
list[i] = new CodeInstruction(OpCodes.Ldsfld, (object)field);
list.RemoveAt(i - 1);
Debug.Print("Printing BetterTimeStop Transpiler Change: (used for debuging in errors)");
Debug.Print(((object)list[i - 2])?.ToString() ?? "");
Debug.Print(((object)list[i - 1])?.ToString() ?? "");
Debug.Print(((object)list[i])?.ToString() ?? "");
Debug.Print(((object)list[i + 1])?.ToString() ?? "");
Debug.Print("Finished Printing BetterTimeStop Transpiler Change");
break;
}
}
return list;
}
public static void UpdateTimeData(ref CastSpell __instance)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
TimeData[__instance.playerInfo.playerId] = __instance.timeSinceActivation;
}
public static void DurationPatch(ref TimeStop __instance)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: 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_0036: Unknown result type (might be due to invalid IL or missing references)
__instance.duration = ((TimeData[((Component)__instance).GetComponent<IPlayerIdHolder>().GetPlayerId()] > MaximumDuration) ? ((float)MaximumDuration) : ((float)TimeData[((Component)__instance).GetComponent<IPlayerIdHolder>().GetPlayerId()]));
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "BetterTimeStop";
public const string PLUGIN_NAME = "BetterTimeStop";
public const string PLUGIN_VERSION = "1.0.0";
}
}