using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("WKDemention")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WKDemention")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("82bebeee-d9c5-4e97-aeb5-06b3c95a5f50")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
public class DementionUI : MonoBehaviour
{
public struct PlayerState
{
public Pose pose;
}
[Header("Dementia Timer Settings")]
private readonly float episodeInterval = 360f;
[Header("Transition Durations")]
private readonly float flashFadeInTime = 0.1f;
private readonly float flashFadeOutTime = 0.4f;
private readonly float freezeFrameFadeOutTime = 1.25f;
private GameObject uiInstance;
private RawImage screenshotImage;
private Image flashImage;
private TextMeshProUGUI timerText;
private readonly PlayerState[] locationHistory = new PlayerState[10];
private int historyCount = 0;
private int historyWriteIndex = 0;
private RenderTexture capturedFrame;
private float episodeTimer;
private bool isTransitioning = false;
private bool foundPlayer = false;
private bool hasCapturedAnySnapshot = false;
private CL_GameManager cachedGameManager;
public static DementionUI Instance { get; private set; }
public static void Initialize()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
if (!((Object)(object)Instance != (Object)null))
{
GameObject val = new GameObject("DementionUIHost");
Object.DontDestroyOnLoad((Object)(object)val);
Instance = val.AddComponent<DementionUI>();
Instance.LoadAndBuildUI();
}
}
private void LoadAndBuildUI()
{
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
//IL_01f5: Expected O, but got Unknown
//IL_0234: Unknown result type (might be due to invalid IL or missing references)
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string text = Path.Combine(directoryName, "Assets", "demention");
if (!File.Exists(text))
{
CleanUpFailedInit();
return;
}
AssetBundle val = AssetBundle.LoadFromFile(text);
if ((Object)(object)val == (Object)null)
{
CleanUpFailedInit();
return;
}
GameObject val2 = null;
string[] allAssetNames = val.GetAllAssetNames();
if (allAssetNames.Length != 0)
{
val2 = val.LoadAsset<GameObject>(allAssetNames[0]);
}
if ((Object)(object)val2 == (Object)null)
{
val.Unload(false);
CleanUpFailedInit();
return;
}
uiInstance = Object.Instantiate<GameObject>(val2);
Object.DontDestroyOnLoad((Object)(object)uiInstance);
val.Unload(false);
Canvas component = uiInstance.GetComponent<Canvas>();
if ((Object)(object)component != (Object)null)
{
component.renderMode = (RenderMode)0;
component.worldCamera = null;
component.sortingOrder = 32767;
}
CanvasScaler component2 = uiInstance.GetComponent<CanvasScaler>();
if ((Object)(object)component2 != (Object)null)
{
component2.uiScaleMode = (ScaleMode)1;
component2.referenceResolution = new Vector2(1920f, 1080f);
component2.screenMatchMode = (ScreenMatchMode)0;
component2.matchWidthOrHeight = 0.5f;
}
Transform obj = uiInstance.transform.Find("ScreenshotImage");
screenshotImage = ((obj != null) ? ((Component)obj).GetComponent<RawImage>() : null);
Transform obj2 = uiInstance.transform.Find("FlashImage");
flashImage = ((obj2 != null) ? ((Component)obj2).GetComponent<Image>() : null);
Transform obj3 = uiInstance.transform.Find("TimerText");
timerText = ((obj3 != null) ? ((Component)obj3).GetComponent<TextMeshProUGUI>() : null);
TextMeshProUGUI obj4 = timerText;
if (obj4 != null)
{
((Component)obj4).gameObject.SetActive(false);
}
capturedFrame = new RenderTexture(Screen.width, Screen.height, 0, (RenderTextureFormat)0);
if ((Object)(object)screenshotImage != (Object)null)
{
screenshotImage.texture = (Texture)(object)capturedFrame;
screenshotImage.uvRect = new Rect(0f, 1f, 1f, -1f);
}
RawImage obj5 = screenshotImage;
if (obj5 != null)
{
((Component)obj5).gameObject.SetActive(false);
}
Image obj6 = flashImage;
if (obj6 != null)
{
((Component)obj6).gameObject.SetActive(false);
}
episodeTimer = episodeInterval;
}
private void Update()
{
if ((Object)(object)cachedGameManager == (Object)null)
{
cachedGameManager = Object.FindObjectOfType<CL_GameManager>();
}
if ((Object)(object)cachedGameManager != (Object)null && CL_GameManager.gamemode.allowLeaderboardScoring)
{
CL_GameManager.gamemode.allowLeaderboardScoring = false;
}
if ((Object)(object)ENT_Player.playerObject == (Object)null)
{
if (foundPlayer)
{
foundPlayer = false;
TextMeshProUGUI obj = timerText;
if (obj != null)
{
((Component)obj).gameObject.SetActive(false);
}
}
return;
}
bool flag = (Object)(object)cachedGameManager != (Object)null && cachedGameManager.isPaused;
if ((Object)(object)cachedGameManager != (Object)null && CL_GameManager.IsLoading())
{
episodeTimer = episodeInterval;
hasCapturedAnySnapshot = true;
}
if ((foundPlayer && ((GameEntity)ENT_Player.playerObject).health <= 0f) || flag)
{
TextMeshProUGUI obj2 = timerText;
if (obj2 != null)
{
((Component)obj2).gameObject.SetActive(false);
}
foundPlayer = false;
}
else if (!foundPlayer)
{
foundPlayer = true;
TextMeshProUGUI obj3 = timerText;
if (obj3 != null)
{
((Component)obj3).gameObject.SetActive(true);
}
}
if (!isTransitioning)
{
if (Input.GetKeyDown((KeyCode)104) && !hasCapturedAnySnapshot && episodeTimer > episodeInterval * 0.25f)
{
RecordManualPose();
hasCapturedAnySnapshot = true;
}
HandleTimers();
}
}
private void HandleTimers()
{
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
episodeTimer -= Time.deltaTime;
if ((Object)(object)timerText != (Object)null)
{
TimeSpan timeSpan = TimeSpan.FromSeconds(Mathf.Max(0f, episodeTimer));
((TMP_Text)timerText).text = $"{timeSpan.Minutes:0}:{timeSpan.Seconds:00}:{timeSpan.Milliseconds / 10:00}";
float num = 1f - episodeTimer / episodeInterval;
((Graphic)timerText).color = Color.Lerp(Color.white, Color.red, num);
}
if (!hasCapturedAnySnapshot)
{
float num2 = episodeInterval * 0.5f;
float num3 = 1f;
if (episodeTimer <= num2 && episodeTimer >= num3)
{
RecordCurrentPose();
hasCapturedAnySnapshot = true;
}
else if (episodeTimer <= 0.1f)
{
RecordCurrentPose();
hasCapturedAnySnapshot = true;
}
}
if (episodeTimer <= 0f)
{
((MonoBehaviour)this).StartCoroutine(ExecuteDementionSequence());
}
}
private void RecordManualPose()
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
locationHistory[historyWriteIndex] = new PlayerState
{
pose = new Pose(((Component)ENT_Player.playerObject).transform.position, ((Component)ENT_Player.playerObject).transform.rotation)
};
historyWriteIndex = (historyWriteIndex + 1) % locationHistory.Length;
if (historyCount < locationHistory.Length)
{
historyCount++;
}
hasCapturedAnySnapshot = true;
((MonoBehaviour)this).StartCoroutine(TriggerFlashFeedback());
}
private void RecordCurrentPose()
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
Transform transform = ((Component)ENT_Player.playerObject).transform;
locationHistory[historyWriteIndex] = new PlayerState
{
pose = new Pose(transform.position, transform.rotation)
};
historyWriteIndex = (historyWriteIndex + 1) % locationHistory.Length;
if (historyCount < locationHistory.Length)
{
historyCount++;
}
((MonoBehaviour)this).StartCoroutine(TriggerFlashFeedback());
}
public void ForceTriggerEpisode()
{
if (!isTransitioning && (Object)(object)ENT_Player.playerObject != (Object)null)
{
((MonoBehaviour)this).StartCoroutine(ExecuteDementionSequence());
}
}
private IEnumerator ExecuteDementionSequence()
{
isTransitioning = true;
TextMeshProUGUI obj = timerText;
if (obj != null)
{
((Component)obj).gameObject.SetActive(false);
}
yield return (object)new WaitForEndOfFrame();
ScreenCapture.CaptureScreenshotIntoRenderTexture(capturedFrame);
if ((Object)(object)screenshotImage != (Object)null)
{
((Graphic)screenshotImage).color = Color.white;
((Component)screenshotImage).gameObject.SetActive(true);
}
Image obj2 = flashImage;
if (obj2 != null)
{
((Component)obj2).gameObject.SetActive(true);
}
float elapsed = 0f;
while (elapsed < flashFadeInTime)
{
elapsed += Time.deltaTime;
if ((Object)(object)flashImage != (Object)null)
{
((Graphic)flashImage).color = new Color(1f, 1f, 1f, Mathf.Lerp(0f, 1f, elapsed / flashFadeInTime));
}
yield return null;
}
if (historyCount > 0)
{
int randomIndex = Random.Range(0, historyCount);
PlayerState state = locationHistory[randomIndex];
((Component)ENT_Player.playerObject).transform.position = state.pose.position;
((Component)ENT_Player.playerObject).transform.rotation = state.pose.rotation;
}
elapsed = 0f;
while (elapsed < flashFadeOutTime)
{
elapsed += Time.deltaTime;
if ((Object)(object)flashImage != (Object)null)
{
((Graphic)flashImage).color = new Color(1f, 1f, 1f, Mathf.Lerp(1f, 0f, elapsed / flashFadeOutTime));
}
yield return null;
}
Image obj3 = flashImage;
if (obj3 != null)
{
((Component)obj3).gameObject.SetActive(false);
}
elapsed = 0f;
Color fullOpacity = Color.white;
while (elapsed < freezeFrameFadeOutTime)
{
elapsed += Time.deltaTime;
fullOpacity.a = Mathf.Lerp(1f, 0f, elapsed / freezeFrameFadeOutTime);
if ((Object)(object)screenshotImage != (Object)null)
{
((Graphic)screenshotImage).color = fullOpacity;
}
yield return null;
}
RawImage obj4 = screenshotImage;
if (obj4 != null)
{
((Component)obj4).gameObject.SetActive(false);
}
if ((Object)(object)timerText != (Object)null)
{
TimeSpan t = TimeSpan.FromSeconds(episodeInterval);
((TMP_Text)timerText).text = $"{t.Minutes:0}:{t.Seconds:00}:{t.Milliseconds / 10:00}";
((Graphic)timerText).color = Color.white;
((Component)timerText).gameObject.SetActive(true);
((TMP_Text)timerText).alpha = 0f;
float fadeElapsed = 0f;
float fadeDuration = 0.5f;
while (fadeElapsed < fadeDuration)
{
fadeElapsed += Time.deltaTime;
((TMP_Text)timerText).alpha = Mathf.Lerp(0f, 1f, fadeElapsed / fadeDuration);
yield return null;
}
((TMP_Text)timerText).alpha = 1f;
}
historyCount = 0;
historyWriteIndex = 0;
episodeTimer = episodeInterval;
hasCapturedAnySnapshot = false;
isTransitioning = false;
}
private IEnumerator TriggerFlashFeedback()
{
if (!((Object)(object)flashImage == (Object)null))
{
((Component)flashImage).gameObject.SetActive(true);
((Graphic)flashImage).color = new Color(1f, 1f, 1f, 0.2f);
yield return (object)new WaitForSeconds(0.1f);
float elapsed = 0f;
while (elapsed < 0.2f)
{
elapsed += Time.deltaTime;
((Graphic)flashImage).color = new Color(1f, 1f, 1f, Mathf.Lerp(0.2f, 0f, elapsed / 0.2f));
yield return null;
}
((Component)flashImage).gameObject.SetActive(false);
}
}
private void CleanUpFailedInit()
{
if ((Object)(object)uiInstance != (Object)null)
{
Object.Destroy((Object)(object)uiInstance);
}
Object.Destroy((Object)(object)((Component)this).gameObject);
}
private void OnDestroy()
{
RenderTexture obj = capturedFrame;
if (obj != null)
{
obj.Release();
}
}
}
namespace Demention
{
[BepInPlugin("com.nimius.demention", "Demention", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
private Harmony _harmony;
private void Awake()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
_harmony = new Harmony("com.nimius.demention");
_harmony.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Demention Harmony Patches applied successfully.");
DementionUI.Initialize();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Demention UI Engine Initialized.");
}
}
}
namespace Demention.Patches
{
[HarmonyPatch(typeof(EventSystem), "Update")]
public static class DementionUIUpdatePatch
{
private static void Postfix()
{
if ((Object)(object)DementionUI.Instance == (Object)null)
{
DementionUI.Initialize();
}
if (Input.GetKeyDown((KeyCode)286))
{
DementionUI.Instance?.ForceTriggerEpisode();
}
}
}
}