using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("NoGoalTimer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NoGoalTimer")]
[assembly: AssemblyTitle("NoGoalTimer")]
[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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace NoGoalTimer
{
[BepInPlugin("superbattlegolf.nogoaltimer", "No Goal Timer", "1.0.0")]
public class NoGoalTimerPlugin : BaseUnityPlugin
{
private Harmony _harmony;
private 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("superbattlegolf.nogoaltimer");
TryApplyPatch();
}
private void TryApplyPatch()
{
foreach (var item in new List<(string, string)>
{
("CourseManager", "BeginCountdownToMatchEnd"),
("CourseManager", "CountDownToMatchEndRoutine")
})
{
MethodInfo methodInfo = FindTargetMethod(item.Item1, item.Item2);
if (!(methodInfo == null))
{
ApplyPrefixPatch(methodInfo, "target " + item.Item1 + "." + item.Item2);
return;
}
}
((BaseUnityPlugin)this).Logger.LogError((object)"Patch target not found. This game build may have changed the CourseManager countdown method names.");
}
private void ApplyPrefixPatch(MethodInfo targetMethod, string source)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
if (!(targetMethod == null))
{
HarmonyMethod val = new HarmonyMethod(AccessTools.Method(typeof(NoGoalTimerPlugin), "BlockCountdownPrefix", (Type[])null, (Type[])null));
_harmony.Patch((MethodBase)targetMethod, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)("Patched " + targetMethod.DeclaringType?.FullName + "." + targetMethod.Name + " using " + source + ". Post-goal timer is disabled."));
}
}
private static MethodInfo FindTargetMethod(string typeName, string methodName)
{
Type type = AccessTools.TypeByName(typeName);
if (type != null)
{
return AccessTools.DeclaredMethod(type, methodName, (Type[])null, (Type[])null);
}
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
Type[] types;
try
{
types = assembly.GetTypes();
}
catch
{
continue;
}
Type[] array = types;
foreach (Type type2 in array)
{
if (string.Equals(type2.Name, typeName, StringComparison.Ordinal))
{
MethodInfo methodInfo = AccessTools.DeclaredMethod(type2, methodName, (Type[])null, (Type[])null);
if (methodInfo != null)
{
return methodInfo;
}
}
}
}
return null;
}
private static bool BlockCountdownPrefix()
{
return false;
}
}
}