using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.turtledsr.peaktimer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.2.3.0")]
[assembly: AssemblyInformationalVersion("1.2.3+7e757a95fdff16cccdde718318ab0bfee456d25c")]
[assembly: AssemblyProduct("PeakTimer")]
[assembly: AssemblyTitle("com.turtledsr.peaktimer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.3.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 peaktimer
{
[BepInPlugin("com.turtledsr.peaktimer", "PeakTimer", "1.2.3")]
[BepInProcess("Peak.exe")]
public class Plugin : BaseUnityPlugin
{
public enum StartLocation
{
Shore,
Tropics,
Alpine,
Caldera,
Kiln
}
public enum StopLocation
{
Tropics,
Alpine,
Caldera,
Kiln,
Peak
}
public enum TimingMethod
{
RTA,
IGT
}
[HarmonyPatch(typeof(PauseOptionsMenu), "OnOpen")]
private static class PauseoptionsMenu_OnOpen_Patch
{
private static bool Prefix()
{
if (timingMethod == TimingMethod.IGT)
{
Logger.LogInfo((object)"Timer Paused (GAME PAUSE)");
timing = false;
}
return true;
}
}
[HarmonyPatch(typeof(PauseOptionsMenu), "OnClose")]
private static class PauseoptionsMenu_OnClose_Patch
{
private static bool Prefix()
{
if (timingMethod == TimingMethod.IGT)
{
Logger.LogInfo((object)"Timer Unpaused (GAME UNPAUSE)");
timing = true;
}
return true;
}
}
[HarmonyPatch(typeof(SteamLobbyHandler), "LeaveLobby")]
private static class SteamLobbyHandler_LeaveLobby_Patch
{
private static bool Prefix()
{
Logger.LogInfo((object)"Lobby Left");
Unbind();
return true;
}
}
[HarmonyPatch(typeof(RunManager), "StartRun")]
private static class RunManager_StartRun_Patch
{
private static bool Prefix()
{
Bind();
return true;
}
}
[HarmonyPatch(typeof(GlobalEvents), "TriggerRunEnded")]
private static class GlobalEvents_TriggerRunEnded_Patch
{
private static bool Prefix()
{
if (goalPoint == StopLocation.Peak)
{
Logger.LogInfo((object)"Run Ended By game End");
timing = false;
}
return true;
}
}
internal static ManualLogSource Logger;
private static ConfigEntry<StopLocation> goalConfig;
private static ConfigEntry<StartLocation> startConfig;
private static ConfigEntry<TimingMethod> timingMethodConfig;
private static ConfigEntry<string> versionConfig;
private static GameObject mountainProgress;
private static Component progressScript;
private static Campfire beachCampfire;
private static Campfire jungleCampfire;
private static Campfire snowCampfire;
private static Campfire volcanoCampfire;
private static bool timing;
private static TimingMethod timingMethod;
private static StopLocation goalPoint;
private static StartLocation startPoint;
private static float time;
private static string timeString;
private static Vector2 timerPos;
private static float timerStartDelay;
private static Version currentVersion = new Version("1.2.3");
private void Awake()
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Expected O, but got Unknown
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
Init();
Logger = ((BaseUnityPlugin)this).Logger;
Harmony val = new Harmony("com.turtledsr.peaktimer");
val.PatchAll();
ConfigDefinition val2 = new ConfigDefinition("info", "version");
bool flag = false;
versionConfig = ((BaseUnityPlugin)this).Config.Bind<string>("Info", "version", "", (ConfigDescription)null);
if (versionConfig.Value != "")
{
Version version = new Version("1.2.2");
Logger.LogInfo((object)versionConfig.Value);
Logger.LogInfo((object)version.ToString());
Logger.LogInfo((object)new Version(versionConfig.Value).CompareTo(version));
if (new Version(versionConfig.Value).CompareTo(version) < 0)
{
Logger.LogInfo((object)"New mod version detected: Resetting config");
flag = true;
}
((BaseUnityPlugin)this).Config.Save();
((BaseUnityPlugin)this).Config.Reload();
}
else
{
Logger.LogInfo((object)"New mod version detected: Resetting config");
flag = true;
}
versionConfig = null;
((BaseUnityPlugin)this).Config.Remove(val2);
((BaseUnityPlugin)this).Config.Reload();
startConfig = ((BaseUnityPlugin)this).Config.Bind<StartLocation>("Timing", "Start", StartLocation.Shore, "Start point for the timer");
startPoint = startConfig.Value;
startConfig.SettingChanged += delegate
{
startPoint = startConfig.Value;
};
goalConfig = ((BaseUnityPlugin)this).Config.Bind<StopLocation>("Timing", "Goal", StopLocation.Peak, "Goal point for the timer");
goalPoint = goalConfig.Value;
goalConfig.SettingChanged += delegate
{
goalPoint = goalConfig.Value;
};
timingMethodConfig = ((BaseUnityPlugin)this).Config.Bind<TimingMethod>("Timing", "Timing Method", TimingMethod.RTA, "Timing method for the timer");
timingMethod = timingMethodConfig.Value;
timingMethodConfig.SettingChanged += delegate
{
timingMethod = timingMethodConfig.Value;
};
if (flag)
{
startConfig.Value = StartLocation.Shore;
goalConfig.Value = StopLocation.Peak;
timingMethodConfig.Value = TimingMethod.RTA;
((BaseUnityPlugin)this).Config.Save();
}
Logger.LogInfo((object)"Peak Timer is loaded!");
}
private void OnGUI()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
GUIStyle val = new GUIStyle
{
fontSize = 30,
fontStyle = (FontStyle)1
};
val.normal.textColor = Color.white;
GUI.Label(new Rect(timerPos.x, timerPos.y, 200f, 30f), timeString, val);
}
private void Update()
{
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Invalid comparison between Unknown and I4
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Invalid comparison between Unknown and I4
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Invalid comparison between Unknown and I4
//IL_0141: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Invalid comparison between Unknown and I4
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
//IL_01c4: Invalid comparison between Unknown and I4
//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
//IL_01f4: Invalid comparison between Unknown and I4
//IL_021b: Unknown result type (might be due to invalid IL or missing references)
//IL_0221: Invalid comparison between Unknown and I4
//IL_0248: Unknown result type (might be due to invalid IL or missing references)
//IL_024e: Invalid comparison between Unknown and I4
if (timerStartDelay > 0f)
{
timerStartDelay -= Time.deltaTime;
if (timerStartDelay <= 0f)
{
timerStartDelay = -1f;
timing = true;
}
}
if (timing && (Object)(object)mountainProgress != (Object)null)
{
time += Time.deltaTime;
timeString = GetTimeString();
switch (goalPoint)
{
case StopLocation.Tropics:
if ((Object)(object)beachCampfire != (Object)null && (int)beachCampfire.state > 0)
{
timing = false;
}
break;
case StopLocation.Alpine:
if ((Object)(object)jungleCampfire != (Object)null && (int)jungleCampfire.state > 0)
{
timing = false;
}
break;
case StopLocation.Caldera:
if ((Object)(object)snowCampfire != (Object)null && (int)snowCampfire.state > 0)
{
timing = false;
}
break;
case StopLocation.Kiln:
if ((Object)(object)volcanoCampfire != (Object)null && (int)volcanoCampfire.state > 0)
{
timing = false;
}
break;
}
}
else
{
if (timing || !((Object)(object)mountainProgress != (Object)null))
{
return;
}
switch (startPoint)
{
case StartLocation.Tropics:
if ((Object)(object)beachCampfire != (Object)null && (int)beachCampfire.state > 0)
{
timing = true;
}
break;
case StartLocation.Alpine:
if ((Object)(object)jungleCampfire != (Object)null && (int)jungleCampfire.state > 0)
{
timing = true;
}
break;
case StartLocation.Caldera:
if ((Object)(object)snowCampfire != (Object)null && (int)snowCampfire.state > 0)
{
timing = true;
}
break;
case StartLocation.Kiln:
if ((Object)(object)volcanoCampfire != (Object)null && (int)volcanoCampfire.state > 0)
{
timing = true;
}
break;
}
}
}
public void OnApplicationQuit()
{
Logger.LogInfo((object)"Application Quitting!");
ConfigEntry<string> val = ((BaseUnityPlugin)this).Config.Bind<string>("Info", "version", currentVersion.ToString(), (ConfigDescription)null);
val.Value = currentVersion.ToString();
((BaseUnityPlugin)this).Config.Save();
}
private void Init()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
timing = false;
time = 0f;
timeString = "00:00:00.000";
Resolution currentResolution = Screen.currentResolution;
timerPos = new Vector2((float)(((Resolution)(ref currentResolution)).width - 210), 10f);
timerStartDelay = -1f;
}
private static void Bind()
{
goalPoint = goalConfig.Value;
timingMethod = timingMethodConfig.Value;
mountainProgress = GameObject.Find("MountainProgress");
timing = false;
if ((Object)(object)mountainProgress != (Object)null)
{
timeString = "00:00:00.000";
time = 0f;
Logger.LogInfo((object)"Bound MountainProgress!");
progressScript = mountainProgress.GetComponentAtIndex(1);
if (startPoint == StartLocation.Shore)
{
timerStartDelay = 6f;
}
if ((Object)(object)progressScript == (Object)null)
{
Logger.LogWarning((object)"Couldn't bind progressScript");
}
LoadCampfires();
}
else
{
Logger.LogWarning((object)"Couldn't bind MountainProgress :(");
}
}
private static void Unbind()
{
mountainProgress = null;
progressScript = null;
timing = false;
Logger.LogInfo((object)"Unbound RunManager!");
}
public static void LoadCampfires()
{
Logger.LogInfo((object)"Loading Campfires");
try
{
beachCampfire = ((Component)GameObject.Find("Map").transform.GetChild(1).GetChild(3).GetChild(0)).gameObject.GetComponentAtIndex<Campfire>(1);
if ((Object)(object)beachCampfire == (Object)null)
{
Logger.LogError((object)"Could not find Beach_Campfire");
}
else
{
Logger.LogInfo((object)"Found Beach_Campfire");
}
}
catch (Exception)
{
Logger.LogError((object)"Could not find Beach_Campfire");
}
try
{
jungleCampfire = ((Component)GameObject.Find("Map").transform.GetChild(3).GetChild(3).GetChild(0)).gameObject.GetComponentAtIndex<Campfire>(1);
if ((Object)(object)jungleCampfire == (Object)null)
{
Logger.LogError((object)"Could not find Jungle_Campfire");
}
else
{
Logger.LogInfo((object)"Found Jungle_Campfire");
}
}
catch (Exception)
{
Logger.LogError((object)"Could not find Jungle_Campfire");
}
try
{
snowCampfire = ((Component)GameObject.Find("Map").transform.GetChild(5).GetChild(3).GetChild(0)).gameObject.GetComponentAtIndex<Campfire>(1);
if ((Object)(object)snowCampfire == (Object)null)
{
Logger.LogError((object)"Could not find Snow_Campfire");
}
else
{
Logger.LogInfo((object)"Found Snow_Campfire");
}
}
catch (Exception)
{
Logger.LogError((object)"Could not find Snow_Campfire");
}
try
{
volcanoCampfire = ((Component)GameObject.Find("Map").transform.GetChild(6).GetChild(0).GetChild(7)
.GetChild(1)
.GetChild(1)
.GetChild(0)).gameObject.GetComponentAtIndex<Campfire>(1);
if ((Object)(object)volcanoCampfire == (Object)null)
{
Logger.LogError((object)"Could not find Volcano_Campfire");
}
else
{
Logger.LogInfo((object)"Found Volcano_Campfire");
}
}
catch (Exception)
{
Logger.LogError((object)"Could not find Volcano_Campfire");
}
}
private string GetTimeString()
{
int num = (int)(time / 3600f);
float num2 = time - (float)(num * 3600);
int num3 = (int)(num2 / 60f);
num2 -= (float)(num3 * 60);
int num4 = (int)num2;
int num5 = (int)(((double)num2 - Math.Truncate(num2)) * 1000.0);
return num.ToString("00") + ":" + num3.ToString("00") + ":" + num4.ToString("00") + "." + num5.ToString("000");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.turtledsr.peaktimer";
public const string PLUGIN_NAME = "PeakTimer";
public const string PLUGIN_VERSION = "1.2.3";
}
}