using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Steamworks;
using TimelineMod.Patches;
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("galfarious.TimelineMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Steam Timeline Integration")]
[assembly: AssemblyTitle("galfarious.TimelineMod")]
[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 TimelineMod
{
public static class LogManager
{
private static ManualLogSource _logger;
public static ManualLogSource Logger => _logger;
public static void Initialize(ManualLogSource l)
{
_logger = l;
}
public static void Info(string m, string type = null)
{
_logger.LogInfo((object)((type != null) ? ("[" + type + "] ") : (m ?? "")));
}
public static void Error(string m, string type = null)
{
_logger.LogError((object)((type != null) ? ("[" + type + "] ") : (m ?? "")));
}
public static void Warning(string m, string type = null)
{
_logger.LogWarning((object)((type != null) ? ("[" + type + "] ") : (m ?? "")));
}
public static void Debug(string m, string type = null)
{
_logger.LogDebug((object)((type != null) ? ("[" + type + "] ") : (m ?? "")));
}
}
[BepInPlugin("galfarious.TimelineMod", "Steam Timeline Integration", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
private static Harmony _harmony;
private void Awake()
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
LogManager.Initialize(((BaseUnityPlugin)this).Logger);
LogManager.Info("Plugin galfarious.TimelineMod vgalfarious.TimelineMod is loaded!");
_harmony = new Harmony("galfarious.TimelineMod");
_harmony.PatchAll();
}
}
public static class SteamTimelineHelper
{
public static class Icons
{
public const string Marker = "steam_marker";
public const string Achievement = "steam_achievement";
public const string Attack = "steam_attack";
public const string Bolt = "steam_bolt";
public const string Bookmark = "steam_bookmark";
public const string Bug = "steam_bug";
public const string Cart = "steam_cart";
public const string Caution = "steam_caution";
public const string Chat = "steam_chat";
public const string Checkmark = "steam_checkmark";
public const string Chest = "steam_chest";
public const string Circle = "steam_circle";
public const string Combat = "steam_combat";
public const string Completed = "steam_completed";
public const string Crown = "steam_crown";
public const string Death = "steam_death";
public const string Defend = "steam_defend";
public const string Diamond = "steam_diamond";
public const string Edit = "steam_edit";
public const string Effect = "steam_effect";
public const string Explosion = "steam_explosion";
public const string Fix = "steam_fix";
public const string Flag = "steam_flag";
public const string Gem = "steam_gem";
public const string Group = "steam_group";
public const string Heart = "steam_heart";
public const string Info = "steam_info";
public const string Invalid = "steam_invalid";
public const string Minus = "steam_minus";
public const string Pair = "steam_pair";
public const string Person = "steam_person";
public const string Plus = "steam_plus";
public const string Purchase = "steam_purchase";
public const string Question = "steam_question";
public const string Ribbon = "steam_ribbon";
public const string Screenshot = "steam_screenshot";
public const string Scroll = "steam_scroll";
public const string Square = "steam_square";
public const string Star = "steam_star";
public const string Starburst = "steam_starburst";
public const string Timer = "steam_timer";
public const string Transfer = "steam_transfer";
public const string Triangle = "steam_triangle";
public const string Trophy = "steam_trophy";
public const string View = "steam_view";
public const string X = "steam_x";
}
public static void AddPoint(string title, string description, string icon = "steam_marker", float offsetSeconds = 0f)
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
if (!SteamClient.IsValid)
{
return;
}
try
{
SteamTimeline.AddInstantaneousTimelineEvent(title, description, icon, 0u, offsetSeconds, (TimelineEventClipPriority)2);
LogManager.Debug("Added Steam Timeline Point: " + title);
}
catch (Exception ex)
{
LogManager.Error("Failed to send timeline event '" + title + "': " + ex.Message);
}
}
public static void SetState(string description, float offsetSeconds = 0f)
{
if (!SteamClient.IsValid)
{
return;
}
try
{
SteamTimeline.SetTimelineTooltip(description, offsetSeconds);
}
catch
{
}
}
public static void StartNewRun()
{
if (!SteamClient.IsValid)
{
return;
}
try
{
SteamTimeline.StartGamePhase();
string gamePhaseId = "run_" + DateTime.Now.Ticks;
SteamTimeline.SetGamePhaseId(gamePhaseId);
LogManager.Debug("Started new Steam Timeline Game Phase (New Run)");
}
catch (Exception ex)
{
LogManager.Error("Timeline Phase Error: " + ex.Message);
}
}
public static void EndRun()
{
if (!SteamClient.IsValid)
{
return;
}
try
{
SteamTimeline.EndGamePhase();
ClearAllStates();
LogManager.Debug("Ended Steam Timeline Game Phase (End Run)");
}
catch
{
}
}
public static void UpdateRegionState(string region, string subRegion, float offset = 0f)
{
if (!SteamClient.IsValid)
{
return;
}
try
{
string text = "Region: " + region;
if (!string.IsNullOrEmpty(subRegion))
{
text = text + " - " + subRegion;
}
SteamTimeline.SetTimelineTooltip(text, offset);
LogManager.Debug("Timeline Region Updated: " + text);
}
catch (Exception ex)
{
LogManager.Error("Timeline State Error: " + ex.Message);
}
}
public static void ClearAllStates()
{
if (!SteamClient.IsValid)
{
return;
}
try
{
SteamTimeline.SetTimelineTooltip("", 0f);
RegionDataKeeper.LastRegion = "";
RegionDataKeeper.LastSubRegion = "";
LogManager.Debug("All Steam Timeline Regions Cleared");
}
catch
{
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "galfarious.TimelineMod";
public const string PLUGIN_NAME = "Steam Timeline Integration";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace TimelineMod.Patches
{
[HarmonyPatch(typeof(CL_AchievementManager))]
public class AchManagerPatches
{
[HarmonyPatch("ShowAchievement")]
[HarmonyPostfix]
public static void ShowAchievement(CL_AchievementManager __instance, string announceText)
{
SteamTimelineHelper.AddPoint("Achievement", announceText, "steam_achievement");
}
}
[HarmonyPatch(typeof(CL_GameManager))]
public class GameManagerPatches
{
[CompilerGenerated]
private sealed class <WaitForReviveToFinish>d__3 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public CL_GameManager gMan;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <WaitForReviveToFinish>d__3(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
break;
case 1:
<>1__state = -1;
break;
}
if (gMan.IsReviving())
{
<>2__current = null;
<>1__state = 1;
return true;
}
if (!CL_GameManager.isDead())
{
SteamTimelineHelper.AddPoint("Revived", "Wuckling as usual again.", "steam_defend");
SteamTimelineHelper.SetState("Recovering from death...");
}
return false;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[HarmonyPatch("LoadIn")]
[HarmonyPostfix]
public static void StartPatch()
{
SteamTimelineHelper.StartNewRun();
RegionDataKeeper.LastRegion = "";
RegionDataKeeper.LastSubRegion = "";
}
[HarmonyPatch("EndGameSequence")]
[HarmonyPostfix]
public static void OnRunEnded(bool win)
{
if (win)
{
SteamTimelineHelper.AddPoint("Victory!", "You escaped (for now).", "steam_crown");
}
SteamTimelineHelper.EndRun();
}
[HarmonyPatch("Die")]
[HarmonyPostfix]
public static void OnPlayerDie(CL_GameManager __instance, string type)
{
string text = "Unknown";
if (CL_GameManager.gMan.deathTypes != null && CL_GameManager.gMan.deathTypes.Count > 0)
{
foreach (DeathType deathType in CL_GameManager.gMan.deathTypes)
{
if (type == deathType.name)
{
text = deathType.deathText;
break;
}
}
}
if (__instance.IsReviving())
{
SteamTimelineHelper.AddPoint("Reviving", "Death Reason: " + text, "steam_heart");
((MonoBehaviour)__instance).StartCoroutine(WaitForReviveToFinish(__instance));
}
else
{
SteamTimelineHelper.AddPoint("Perma Death", "Death Reason: " + text, "steam_death");
SteamTimelineHelper.EndRun();
}
}
[IteratorStateMachine(typeof(<WaitForReviveToFinish>d__3))]
private static IEnumerator WaitForReviveToFinish(CL_GameManager gMan)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <WaitForReviveToFinish>d__3(0)
{
gMan = gMan
};
}
}
[HarmonyPatch(typeof(UT_GameStateController))]
public class GameStateControllerPatches
{
[HarmonyPatch("LoadMainMenu")]
[HarmonyPostfix]
public static void LoadMainMenuPatch(UT_GameStateController __instance)
{
SteamTimelineHelper.EndRun();
}
}
[HarmonyPatch(typeof(ENT_Player))]
public static class PlayerPatches
{
[HarmonyPatch("AddPerk")]
[HarmonyPostfix]
public static void AddPerkPatch(ENT_Player __instance, Perk perk, int stackAmount, bool firstTime)
{
if (firstTime)
{
SteamTimelineHelper.AddPoint("Perk Added", perk.title ?? "", "steam_gem");
}
}
}
public static class RegionDataKeeper
{
public static string LastRegion = "";
public static string LastSubRegion = "";
}
[HarmonyPatch(typeof(UT_TextScrawl))]
public class TextScrawlerPatches
{
private static string[] doorDialogues = new string[8] { "GO IN GO IN GO IN GO IN GO IN", "DREAMS DREAMS DREAMS DREAMS", "THINK OF ALL YOU COULD HAVE", "POWER BEYOND ALL UNDERSTANDING", "GO IN GO IN GO IN GO IN", "WE HAVE FOUND YOU, JOIN US AND WITNESS TRUE STRENGTH", "A GIFT A GIFT A GIFT A GIFT A GIFT", "WE FOUND YOU WE FOUND YOU WE FOUND YOU" };
public static void TriggerMilestone(string text)
{
SteamTimelineHelper.AddPoint("Milestone Reached", text, "steam_ribbon");
}
[HarmonyPatch("ShowText")]
[HarmonyPostfix]
public static void ShowText(UT_TextScrawl __instance, string s)
{
if (string.IsNullOrEmpty(s))
{
return;
}
string text = Regex.Replace(s, "<.*?>", string.Empty).Trim();
if (text.ToLower().Contains("climbed") && text.ToLower().Contains("meters"))
{
int.TryParse(text.Split(" ")[1], out var result);
if (result <= 1000)
{
if (result % 250 == 0)
{
TriggerMilestone(text);
}
}
else if (result <= 10000)
{
if (result % 500 == 0)
{
TriggerMilestone(text);
}
}
else if (result % 1000 == 0)
{
TriggerMilestone(text);
}
return;
}
string[] array = text.Split(new string[2] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);
if (array.Length == 0)
{
return;
}
string text2 = array[0].Trim();
string text3 = ((array.Length > 1) ? array[1].Trim() : "");
if (!(text2 != RegionDataKeeper.LastRegion) && !(text3 != RegionDataKeeper.LastSubRegion))
{
return;
}
RegionDataKeeper.LastRegion = text2;
RegionDataKeeper.LastSubRegion = text3;
SteamTimelineHelper.UpdateRegionState(text2, text3);
string text4 = (string.IsNullOrEmpty(text3) ? text2 : text3);
bool flag = false;
string[] array2 = doorDialogues;
foreach (string value in array2)
{
if (text4.Contains(value))
{
flag = true;
break;
}
}
if (flag)
{
SteamTimelineHelper.AddPoint("New Area", text4, "steam_view");
}
else
{
SteamTimelineHelper.AddPoint("New Area", text4);
}
}
}
}