using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyTitle("Pick Your Number and Age")]
[assembly: AssemblyInformationalVersion("1.2.1")]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyDescription("BepInEx mod for Casualties: Unknown. Lets you pick your specimen number, age and height on the keypad when starting a run.")]
[assembly: AssemblyProduct("Pick Your Number and Age")]
[assembly: AssemblyCopyright("Copyright (c) casualexpie. All rights reserved.")]
[assembly: AssemblyMetadata("Notice", "Copyright (c) casualexpie. All rights reserved. Do NOT decompile, disassemble, or reverse-engineer this assembly. Report bug symptoms on the Nexus Bugs page; do not post decompiled or reconstructed source. Reverse-engineering this DLL is not authorized.")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: AssemblyVersion("1.2.1.0")]
namespace PickYourNumber;
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("pickyournumber", "Pick Your Number and Age", "1.2.1")]
public class Plugin : BaseUnityPlugin
{
public const string Version = "1.2.1";
public const int Min = 1;
public const int Max = 99999;
public const int MinAge = 10;
public const int MaxAge = 25;
internal static ManualLogSource Log;
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<int> LastNumber;
internal static ConfigEntry<int> LastAge;
internal static int Pending = -1;
internal static int PendingAge = -1;
internal static int PendingHeight = -1;
internal static ConfigEntry<int> LastHeight;
internal static ConfigEntry<bool> Secrets;
private static readonly float[] HeightMult = new float[3] { 1f, 0.8f, 1.1f };
internal static bool Bypass;
internal static int[] HeightRange(int character)
{
float num = ((character >= 0 && character < HeightMult.Length) ? HeightMult[character] : 1f);
return new int[2]
{
(int)(130f * num),
(int)(160f * num)
};
}
private void Awake()
{
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Show the number, age and height picker when you press Start.");
LastNumber = ((BaseUnityPlugin)this).Config.Bind<int>("General", "LastNumber", 0, "The last number you picked. It's typed in for you next time (0 = none).");
LastAge = ((BaseUnityPlugin)this).Config.Bind<int>("General", "LastAge", 0, "The last age you picked. It's typed in for you next time (0 = none).");
LastHeight = ((BaseUnityPlugin)this).Config.Bind<int>("General", "LastHeight", 0, "The last height (cm) you picked. It's typed in for you next time if it fits your character (0 = none).");
Secrets = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Secrets", true, "Lets secret codes on the keypad do things. Turn off if you only want to pick numbers.");
Harmony h = new Harmony("pickyournumber");
int num = 0;
num += Hook(h, typeof(PreRunScript), "StartRun", Type.EmptyTypes, "StartRunPrefix", null);
num += Hook(h, typeof(PlayerCamera), "Start", Type.EmptyTypes, null, "CameraStartPostfix");
Log.LogInfo((object)("Pick Your Number and Age 1.2.1 loaded (" + num + "/2 hooks). Game version " + Application.version + "."));
Mp.Init(h);
}
private static int Hook(Harmony h, Type t, string name, Type[] args, string prefix, string postfix)
{
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
try
{
MethodInfo methodInfo = AccessTools.Method(t, name, args, (Type[])null);
if (methodInfo == null)
{
Log.LogWarning((object)("Couldn't find " + t.Name + "." + name + ", skipping it."));
return 0;
}
h.Patch((MethodBase)methodInfo, (prefix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(Patches), prefix, (Type[])null), (postfix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(Patches), postfix, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
return 1;
}
catch (Exception ex)
{
Log.LogWarning((object)("Couldn't patch " + t.Name + "." + name + ": " + ex.Message));
return 0;
}
}
}
internal static class Mp
{
private static Assembly asm;
private static MethodInfo click;
private static PropertyInfo waiting;
private static PropertyInfo confirmed;
private static PropertyInfo lateJoin;
private static MethodInfo startRun;
internal static bool Bypass;
internal static void Init(Harmony h)
{
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Expected O, but got Unknown
try
{
Type type = AccessTools.TypeByName("Together.CharacterSelectWait");
if (!(type == null))
{
asm = type.Assembly;
startRun = AccessTools.Method(typeof(PreRunScript), "StartRun", Type.EmptyTypes, (Type[])null);
click = AccessTools.Method(type, "OnStartOrLoadClicked", new Type[1] { typeof(bool) }, (Type[])null);
waiting = AccessTools.Property(type, "Waiting");
confirmed = AccessTools.Property(type, "LocalConfirmed");
lateJoin = AccessTools.Property(type, "LateJoinPicking");
if (click == null || waiting == null || confirmed == null)
{
Plugin.Log.LogWarning((object)"Casualties Together found, but its ready-up step has changed. The keypad stays off in multiplayer.");
click = null;
}
else
{
h.Patch((MethodBase)click, new HarmonyMethod(typeof(Mp), "ClickPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Plugin.Log.LogInfo((object)"Casualties Together found. In multiplayer the keypad opens when you ready up.");
}
}
}
catch (Exception ex)
{
click = null;
Plugin.Log.LogWarning((object)("Couldn't hook Casualties Together: " + ex.Message));
}
}
internal static bool OwnsStartRun()
{
if (asm == null || startRun == null)
{
return false;
}
try
{
Patches patchInfo = Harmony.GetPatchInfo((MethodBase)startRun);
if (patchInfo == null)
{
return false;
}
foreach (Patch prefix in patchInfo.Prefixes)
{
if (prefix.PatchMethod != null && prefix.PatchMethod.DeclaringType != null && prefix.PatchMethod.DeclaringType.Assembly == asm)
{
return true;
}
}
}
catch (Exception)
{
}
return false;
}
private static bool Flag(PropertyInfo p)
{
if (p != null)
{
return (bool)p.GetValue(null, null);
}
return false;
}
public static bool ClickPrefix(bool __0)
{
if (Bypass)
{
Bypass = false;
return true;
}
if (Picker.IsOpen)
{
return false;
}
if (!Plugin.Enabled.Value || __0)
{
return true;
}
try
{
if (!Flag(waiting))
{
return true;
}
if (Flag(confirmed) && !Flag(lateJoin))
{
return true;
}
PreRunScript instance = PreRunScript.instance;
if ((Object)(object)instance == (Object)null)
{
return true;
}
Plugin.Pending = -1;
Plugin.PendingAge = -1;
Plugin.PendingHeight = -1;
if (Picker.Open(instance, Continue))
{
return false;
}
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("Couldn't open the picker: " + ex.Message));
}
return true;
}
private static void Continue()
{
if (click == null)
{
return;
}
Bypass = true;
try
{
click.Invoke(null, new object[1] { false });
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("Couldn't ready up: " + ((ex.InnerException != null) ? ex.InnerException.Message : ex.Message)));
}
finally
{
Bypass = false;
}
}
}
internal static class Patches
{
private static readonly FieldInfo StartedLoading = AccessTools.Field(typeof(PreRunScript), "startedLoading");
public static bool StartRunPrefix(PreRunScript __instance)
{
if (Plugin.Bypass)
{
Plugin.Bypass = false;
return true;
}
if (!Plugin.Enabled.Value || Picker.IsOpen)
{
return !Picker.IsOpen;
}
try
{
if (Mp.OwnsStartRun())
{
return true;
}
if (StartedLoading != null && (bool)StartedLoading.GetValue(__instance))
{
return true;
}
if (PlayerPrefs.GetInt("didbasiccourse") == 0)
{
return true;
}
Plugin.Pending = -1;
Plugin.PendingAge = -1;
Plugin.PendingHeight = -1;
PreRunScript m = __instance;
if (Picker.Open(__instance, delegate
{
if ((Object)(object)m == (Object)null)
{
return;
}
Plugin.Bypass = true;
try
{
m.StartRun();
}
finally
{
Plugin.Bypass = false;
}
}))
{
return false;
}
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("Couldn't open the picker: " + ex.Message));
}
return true;
}
public static void CameraStartPostfix()
{
int pending = Plugin.Pending;
int pendingAge = Plugin.PendingAge;
int pendingHeight = Plugin.PendingHeight;
Plugin.Pending = -1;
Plugin.PendingAge = -1;
Plugin.PendingHeight = -1;
bool flag = pending >= 1 && pending <= 99999;
bool flag2 = pendingAge >= 10 && pendingAge <= 25;
bool flag3 = pendingHeight >= 50 && pendingHeight <= 300;
if (!flag && !flag2 && !flag3)
{
return;
}
try
{
if (!SaveSystem.loadedRun && !((Object)(object)WoundView.view == (Object)null))
{
int[] cInfo = WoundView.view.cInfo;
int num = (flag3 ? pendingHeight : cInfo[0]);
int num2 = (flag2 ? pendingAge : cInfo[1]);
int num3 = (flag ? pending : cInfo[2]);
WoundView.view.SetCharDetails(num, num2, num3, cInfo[3]);
Plugin.Log.LogInfo((object)("This run: #" + num3 + (flag ? "" : " (random)") + ", age " + num2 + (flag2 ? "" : " (random)") + ", height " + num + "cm" + (flag3 ? "" : " (random)") + "."));
}
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("Couldn't set your details: " + ex.Message));
}
}
}
internal static class Hands
{
private static readonly Dictionary<string, Sprite> cache = new Dictionary<string, Sprite>();
public static Sprite Get(string name)
{
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Expected O, but got Unknown
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
if (cache.TryGetValue(name, out var value) && (Object)(object)value != (Object)null)
{
return value;
}
try
{
using Stream stream = typeof(Hands).Assembly.GetManifestResourceStream("PickYourNumber." + name + ".png");
if (stream == null)
{
return null;
}
byte[] array = new byte[stream.Length];
int num;
for (int i = 0; i < array.Length; i += num)
{
num = stream.Read(array, i, array.Length - i);
if (num <= 0)
{
break;
}
}
Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
if (!ImageConversion.LoadImage(val, array))
{
return null;
}
((Texture)val).filterMode = (FilterMode)0;
((Texture)val).wrapMode = (TextureWrapMode)1;
((Object)val).hideFlags = (HideFlags)61;
value = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
((Object)value).hideFlags = (HideFlags)61;
cache[name] = value;
return value;
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("Couldn't load hand art " + name + ": " + ex.Message));
return null;
}
}
}
internal class PadButton
{
public RectTransform Rect;
public Image Img;
public Action Click;
public float PressedUntil;
}
internal class Picker : MonoBehaviour
{
private const float Scale = 0.82f;
private static readonly Color HandColor = new Color(1f, 1f, 1f, 0.8235294f);
private static Picker current;
private PreRunScript menu;
private Action done;
private string typed = "";
private string seq = "";
private int stage;
private TextMeshProUGUI header;
private TextMeshProUGUI display;
private TextMeshProUGUI tipText;
private float flashUntil;
private readonly List<PadButton> buttons = new List<PadButton>();
private RectTransform rootRect;
private RectTransform hand;
private Image handImg;
private Sprite[] handFrames;
private Vector2 handPos;
private Vector2 handVel;
private bool cursorWasVisible = true;
private static readonly string[] StageNames = new string[3] { "NUMBER", "AGE", "HEIGHT" };
private static readonly string[] StageWords = new string[3] { "number", "age", "height" };
private int[] mins;
private int[] maxs;
private readonly string[] saved = new string[3];
private readonly int[] picked = new int[3] { -1, -1, -1 };
public static bool IsOpen => (Object)(object)current != (Object)null;
public static bool Open(PreRunScript menu, Action done)
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Expected O, but got Unknown
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
GameObject val = Resources.Load<GameObject>("Special/LifepodMinigame");
if ((Object)(object)val == (Object)null)
{
Plugin.Log.LogWarning((object)"Keypad art not found, starting normally.");
return false;
}
GameObject val2 = new GameObject("PickYourNumber");
Canvas val3 = val2.AddComponent<Canvas>();
val3.renderMode = (RenderMode)0;
val3.sortingOrder = 30000;
CanvasScaler val4 = val2.AddComponent<CanvasScaler>();
val4.uiScaleMode = (ScaleMode)1;
val4.referenceResolution = new Vector2(1920f, 1080f);
val4.matchWidthOrHeight = 0.5f;
val2.AddComponent<GraphicRaycaster>();
GameObject val5 = new GameObject("Dim");
val5.transform.SetParent(val2.transform, false);
Image val6 = val5.AddComponent<Image>();
((Graphic)val6).color = new Color(0f, 0f, 0f, 0.88f);
RectTransform component = val5.GetComponent<RectTransform>();
component.anchorMin = Vector2.zero;
component.anchorMax = Vector2.one;
component.offsetMin = Vector2.zero;
component.offsetMax = Vector2.zero;
GameObject val7 = Object.Instantiate<GameObject>(val, val2.transform, false);
((Object)val7).name = "Keypad";
RectTransform component2 = val7.GetComponent<RectTransform>();
((Transform)component2).localScale = new Vector3(0.82f, 0.82f, 1f);
component2.anchoredPosition = new Vector2(0f, 40f);
Picker picker = val2.AddComponent<Picker>();
picker.menu = menu;
picker.done = done;
picker.rootRect = val2.GetComponent<RectTransform>();
if (!picker.Build(val7.transform))
{
Object.Destroy((Object)(object)val2);
return false;
}
picker.MakeHand(val2.transform);
current = picker;
if (Plugin.Secrets.Value)
{
Jumpscare.Preload();
}
return true;
}
private static TextMeshProUGUI TextOf(Transform t)
{
if (t.childCount <= 0)
{
return null;
}
return ((Component)t.GetChild(0)).GetComponent<TextMeshProUGUI>();
}
private void AddButton(GameObject g, Action onClick)
{
PadButton padButton = new PadButton();
padButton.Rect = g.GetComponent<RectTransform>();
padButton.Img = g.GetComponent<Image>();
padButton.Click = onClick;
buttons.Add(padButton);
}
private bool Build(Transform pad)
{
//IL_014c: Unknown result type (might be due to invalid IL or missing references)
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
//IL_0217: Unknown result type (might be due to invalid IL or missing references)
//IL_029d: Unknown result type (might be due to invalid IL or missing references)
if (pad.childCount < 13)
{
return false;
}
Graphic[] componentsInChildren = ((Component)pad).GetComponentsInChildren<Graphic>(true);
foreach (Graphic val in componentsInChildren)
{
val.raycastTarget = false;
}
header = TextOf(pad.GetChild(0));
display = TextOf(pad.GetChild(1));
if ((Object)(object)header == (Object)null || (Object)(object)display == (Object)null)
{
return false;
}
((TMP_Text)header).enableAutoSizing = true;
((TMP_Text)header).fontSizeMax = 36f;
((TMP_Text)header).fontSizeMin = 14f;
Transform child = pad.GetChild(2);
AddButton(((Component)child).gameObject, delegate
{
Beep("0");
typed = "";
seq = "";
});
for (int num = 3; num < 13; num++)
{
Transform child2 = pad.GetChild(num);
TextMeshProUGUI val2 = TextOf(child2);
if (!((Object)(object)val2 == (Object)null))
{
string d = ((TMP_Text)val2).text.Trim();
AddButton(((Component)child2).gameObject, delegate
{
Press(d);
});
}
}
GameObject val3 = Object.Instantiate<GameObject>(((Component)child).gameObject, pad, false);
((Object)val3).name = "Skip";
Shape(val3, new Vector2(-180f, -470f), new Vector2(330f, 110f), "SKIP", 46f);
AddButton(val3, Skip);
GameObject val4 = Object.Instantiate<GameObject>(((Component)child).gameObject, pad, false);
((Object)val4).name = "Confirm";
Shape(val4, new Vector2(180f, -470f), new Vector2(330f, 110f), "CONFIRM", 46f);
AddButton(val4, Confirm);
GameObject val5 = Object.Instantiate<GameObject>(((Component)pad.GetChild(0)).gameObject, pad, false);
((Object)val5).name = "Tip";
RectTransform component = val5.GetComponent<RectTransform>();
component.anchoredPosition = new Vector2(0f, -585f);
Image component2 = val5.GetComponent<Image>();
if ((Object)(object)component2 != (Object)null)
{
((Behaviour)component2).enabled = false;
}
tipText = TextOf(val5.transform);
if ((Object)(object)tipText != (Object)null)
{
((TMP_Text)tipText).enableAutoSizing = true;
((TMP_Text)tipText).fontSizeMax = 24f;
((TMP_Text)tipText).fontSizeMin = 12f;
((Graphic)tipText).color = new Color(0.75f, 0.75f, 0.75f);
}
int[] array = Plugin.HeightRange(PreRunScript.characterSelected);
mins = new int[3]
{
1,
10,
array[0]
};
maxs = new int[3]
{
99999,
25,
array[1]
};
EnterStage(0);
return true;
}
private int LastFor(int s)
{
return s switch
{
1 => Plugin.LastAge.Value,
0 => Plugin.LastNumber.Value,
_ => Plugin.LastHeight.Value,
};
}
private void EnterStage(int s)
{
stage = s;
string text = saved[s];
if (text == null)
{
int num = LastFor(s);
text = ((num >= mins[s] && num <= maxs[s]) ? num.ToString() : "");
}
typed = text;
seq = "";
flashUntil = 0f;
((TMP_Text)header).text = "PICK YOUR " + StageNames[s] + " (" + mins[s] + " - " + maxs[s] + ")";
if ((Object)(object)tipText != (Object)null)
{
string text2 = ((s == 0) ? "Esc = back" : ("Esc = back to your " + StageWords[s - 1]));
((TMP_Text)tipText).text = "Step " + (s + 1) + " of 3. Type with the keypad or your keyboard. Enter = confirm, " + text2 + ".\nSkip lets the game pick a random " + StageWords[s] + ", like normal.";
}
Refresh();
}
private void Next(int value)
{
picked[stage] = value;
saved[stage] = typed;
Plugin.Pending = picked[0];
Plugin.PendingAge = picked[1];
Plugin.PendingHeight = picked[2];
if (stage < 2)
{
EnterStage(stage + 1);
}
else
{
Proceed();
}
}
private void MakeHand(Transform root)
{
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Expected O, but got Unknown
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_017a: Unknown result type (might be due to invalid IL or missing references)
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
string text = ((PreRunScript.characterSelected == 2) ? "alt" : "");
handFrames = (Sprite[])(object)new Sprite[3]
{
Hands.Get("handPointIdle1" + text),
Hands.Get("handPointIdle2" + text),
Hands.Get("handPointClick" + text)
};
if (!((Object)(object)handFrames[0] == (Object)null) && !((Object)(object)handFrames[1] == (Object)null) && !((Object)(object)handFrames[2] == (Object)null))
{
GameObject val = new GameObject("Hand");
val.transform.SetParent(root, false);
val.transform.SetAsLastSibling();
handImg = val.AddComponent<Image>();
((Graphic)handImg).raycastTarget = false;
((Graphic)handImg).color = HandColor;
handImg.sprite = handFrames[Random.Range(0, 2)];
hand = val.GetComponent<RectTransform>();
RectTransform obj = hand;
Vector2 anchorMin = (hand.anchorMax = new Vector2(0.5f, 0.5f));
obj.anchorMin = anchorMin;
hand.pivot = new Vector2(0.25420797f, 0.86340046f);
hand.sizeDelta = new Vector2(768.0077f, 1890.0189f);
((Transform)hand).localScale = new Vector3(0.82f, 0.82f, 1f);
handPos = MouseLocal();
hand.anchoredPosition = handPos;
cursorWasVisible = Cursor.visible;
Cursor.visible = false;
}
}
private Vector2 MouseLocal()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: 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)
Vector2 result = default(Vector2);
RectTransformUtility.ScreenPointToLocalPointInRectangle(rootRect, Vector2.op_Implicit(Input.mousePosition), (Camera)null, ref result);
return result;
}
private Vector2 PointerScreen()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)hand != (Object)null)
{
return RectTransformUtility.WorldToScreenPoint((Camera)null, ((Transform)hand).position);
}
return Vector2.op_Implicit(Input.mousePosition);
}
private static void Shape(GameObject g, Vector2 pos, Vector2 size, string label, float fontSize)
{
//IL_0008: 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)
RectTransform component = g.GetComponent<RectTransform>();
component.anchoredPosition = pos;
component.sizeDelta = size;
TextMeshProUGUI val = TextOf(g.transform);
if ((Object)(object)val != (Object)null)
{
((TMP_Text)val).text = label;
((TMP_Text)val).enableAutoSizing = true;
((TMP_Text)val).fontSizeMax = fontSize;
((TMP_Text)val).fontSizeMin = 14f;
}
}
private static void Beep(string d)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
try
{
Sound.Play("beep" + d, Vector2.zero, true, false, (Transform)null, 1f, 1f, true, false);
}
catch (Exception)
{
}
}
private void Press(string d)
{
if (d.Length != 1 || d[0] < '0' || d[0] > '9')
{
return;
}
Beep(d);
if (stage == 0 && Plugin.Secrets.Value)
{
seq += d;
if (seq.Length > 8)
{
seq = seq.Substring(seq.Length - 8);
}
if (seq.EndsWith("2296"))
{
Close();
Jumpscare.Run();
return;
}
}
if (typed.Length < maxs[stage].ToString().Length && (typed.Length != 0 || !(d == "0")))
{
typed += d;
}
}
private int Value()
{
if (!int.TryParse(typed, out var result))
{
return -1;
}
return result;
}
private bool Valid()
{
int num = Value();
if (num >= mins[stage])
{
return num <= maxs[stage];
}
return false;
}
private void Confirm()
{
if (!Valid())
{
flashUntil = Time.unscaledTime + 1.2f;
Beep("0");
return;
}
int num = Value();
if (stage == 0)
{
Plugin.LastNumber.Value = num;
}
else if (stage == 1)
{
Plugin.LastAge.Value = num;
}
else
{
Plugin.LastHeight.Value = num;
}
Plugin.Log.LogInfo((object)("Picked " + StageWords[stage] + " " + num + "."));
Next(num);
}
private void Skip()
{
Plugin.Log.LogInfo((object)("Skipped the " + StageWords[stage] + ". The game picks it."));
Next(-1);
}
private void Back()
{
if (stage > 0)
{
saved[stage] = typed;
EnterStage(stage - 1);
return;
}
Plugin.Pending = -1;
Plugin.PendingAge = -1;
Plugin.PendingHeight = -1;
Close();
}
private void Proceed()
{
Action action = done;
Close();
if (!((Object)(object)menu == (Object)null))
{
action?.Invoke();
}
}
private void Close()
{
if ((Object)(object)current == (Object)(object)this)
{
current = null;
}
Object.Destroy((Object)(object)((Component)this).gameObject);
}
private void Refresh()
{
if (!((Object)(object)display == (Object)null))
{
string text = ((typed.Length == 0) ? "_" : typed);
string text2 = ((stage == 0) ? ("#" + text) : ((stage == 1) ? (text + "y") : (text + "cm")));
if (Time.unscaledTime < flashUntil)
{
((TMP_Text)display).text = "<color=#ff5050>" + text2 + "</color>";
}
else if (typed.Length > 0 && !Valid())
{
((TMP_Text)display).text = "<color=#bbbbbb>" + text2 + "</color>";
}
else
{
((TMP_Text)display).text = text2;
}
}
}
private PadButton Under(Vector2 screen)
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
for (int num = buttons.Count - 1; num >= 0; num--)
{
PadButton padButton = buttons[num];
if ((Object)(object)padButton.Rect != (Object)null && ((Component)padButton.Rect).gameObject.activeInHierarchy && RectTransformUtility.RectangleContainsScreenPoint(padButton.Rect, screen, (Camera)null))
{
return padButton;
}
}
return null;
}
private void MoveHand()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: 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_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: 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_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: 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_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)hand == (Object)null))
{
float num = Mathf.Min(Time.unscaledDeltaTime, 0.05f);
Vector2 val = handPos;
handPos = Vector2.Lerp(handPos, MouseLocal(), num * 10f);
handVel = Vector2.Lerp(handVel, (num > 0f) ? ((handPos - val) / (num * 120f)) : Vector2.zero, 0.5f);
hand.anchoredPosition = handPos;
((Transform)hand).localEulerAngles = new Vector3(0f, 0f, Mathf.Clamp(handVel.x * 0.5f, -30f, 30f));
if (Input.GetMouseButtonDown(0))
{
handImg.sprite = handFrames[2];
}
if (Input.GetMouseButtonUp(0))
{
handImg.sprite = handFrames[Random.Range(0, 2)];
}
}
}
private void Update()
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: 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)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)menu == (Object)null)
{
Close();
return;
}
MoveHand();
Vector2 screen = PointerScreen();
PadButton padButton = Under(screen);
float unscaledTime = Time.unscaledTime;
foreach (PadButton button in buttons)
{
if (!((Object)(object)button.Img == (Object)null))
{
if (unscaledTime < button.PressedUntil)
{
((Graphic)button.Img).color = new Color(0.6f, 0.6f, 0.6f);
}
else if (button == padButton)
{
((Graphic)button.Img).color = new Color(1f, 0.85f, 0.45f);
}
else
{
((Graphic)button.Img).color = Color.white;
}
}
}
if (Input.GetMouseButtonDown(0) && padButton != null)
{
padButton.PressedUntil = unscaledTime + 0.12f;
padButton.Click();
if ((Object)(object)current != (Object)(object)this)
{
return;
}
}
for (int i = 0; i <= 9; i++)
{
if (Input.GetKeyDown((KeyCode)(48 + i)) || Input.GetKeyDown((KeyCode)(256 + i)))
{
Press(i.ToString());
if ((Object)(object)current != (Object)(object)this)
{
return;
}
}
}
if (Input.GetKeyDown((KeyCode)8) && typed.Length > 0)
{
Beep("0");
typed = typed.Substring(0, typed.Length - 1);
seq = "";
}
if (Input.GetKeyDown((KeyCode)13) || Input.GetKeyDown((KeyCode)271))
{
Confirm();
if ((Object)(object)current != (Object)(object)this)
{
return;
}
}
else if (Input.GetKeyDown((KeyCode)27))
{
Back();
if ((Object)(object)current != (Object)(object)this)
{
return;
}
}
Refresh();
}
private void OnDestroy()
{
if ((Object)(object)current == (Object)(object)this)
{
current = null;
}
if ((Object)(object)hand != (Object)null)
{
Cursor.visible = cursorWasVisible;
}
Jumpscare.Release();
}
}
internal class Jumpscare : MonoBehaviour
{
private static Jumpscare inst;
private static bool running;
private Canvas canvas;
private RawImage screen;
private VideoPlayer vp;
private AudioSource src;
private bool prepared;
private bool failed;
private bool active;
private bool quitting;
private float started;
private float limit;
internal static void Preload()
{
if ((Object)(object)inst != (Object)null || running)
{
return;
}
try
{
inst = Create();
inst.Load();
}
catch (Exception)
{
}
}
internal static void Release()
{
if (!running && !((Object)(object)inst == (Object)null))
{
Object.Destroy((Object)(object)((Component)inst).gameObject);
inst = null;
}
}
internal static void Run()
{
if (running)
{
return;
}
running = true;
if ((Object)(object)inst == (Object)null)
{
inst = Create();
try
{
inst.Load();
}
catch (Exception)
{
}
}
inst.Go();
}
private static Jumpscare Create()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Expected O, but got Unknown
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("PYN_Overlay");
Object.DontDestroyOnLoad((Object)(object)val);
Canvas val2 = val.AddComponent<Canvas>();
val2.renderMode = (RenderMode)0;
val2.sortingOrder = 32767;
((Behaviour)val2).enabled = false;
val.AddComponent<GraphicRaycaster>();
GameObject val3 = new GameObject("Screen");
val3.transform.SetParent(val.transform, false);
RawImage val4 = val3.AddComponent<RawImage>();
((Graphic)val4).color = Color.black;
RectTransform rectTransform = ((Graphic)val4).rectTransform;
rectTransform.anchorMin = Vector2.zero;
rectTransform.anchorMax = Vector2.one;
rectTransform.offsetMin = Vector2.zero;
rectTransform.offsetMax = Vector2.zero;
Jumpscare jumpscare = val.AddComponent<Jumpscare>();
jumpscare.canvas = val2;
jumpscare.screen = val4;
return jumpscare;
}
private static string Find(params string[] names)
{
string location = typeof(Plugin).Assembly.Location;
string path = (string.IsNullOrEmpty(location) ? Paths.PluginPath : Path.GetDirectoryName(location));
string[] array = new string[2] { "PickYourNumber", "" };
foreach (string path2 in array)
{
foreach (string path3 in names)
{
string text = Path.Combine(Path.Combine(path, path2), path3);
if (File.Exists(text))
{
return text;
}
}
}
return null;
}
private void Load()
{
//IL_018a: Unknown result type (might be due to invalid IL or missing references)
//IL_0194: Expected O, but got Unknown
//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
//IL_01ab: Expected O, but got Unknown
//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
//IL_01c2: Expected O, but got Unknown
string text = Find("jumpscare.wav");
if (text != null)
{
AudioClip val = null;
try
{
val = Wav.Load(text);
}
catch (Exception)
{
}
if ((Object)(object)val != (Object)null)
{
src = ((Component)this).gameObject.AddComponent<AudioSource>();
src.clip = val;
src.playOnAwake = false;
src.loop = false;
src.spatialBlend = 0f;
src.volume = 1f;
src.priority = 0;
src.ignoreListenerPause = true;
src.bypassReverbZones = true;
}
}
string text2 = Find("jumpscare.webm", "jumpscare.mp4");
if (text2 != null)
{
vp = ((Component)this).gameObject.AddComponent<VideoPlayer>();
vp.playOnAwake = false;
vp.source = (VideoSource)1;
vp.url = text2;
vp.isLooping = false;
vp.skipOnDrop = true;
vp.renderMode = (VideoRenderMode)4;
if ((Object)(object)src != (Object)null)
{
vp.audioOutputMode = (VideoAudioOutputMode)0;
}
else
{
vp.audioOutputMode = (VideoAudioOutputMode)2;
vp.controlledAudioTrackCount = 1;
vp.EnableAudioTrack((ushort)0, true);
vp.SetDirectAudioVolume((ushort)0, 1f);
}
vp.prepareCompleted += new EventHandler(OnPrepared);
vp.loopPointReached += new EventHandler(OnEnd);
vp.errorReceived += new ErrorEventHandler(OnError);
vp.Prepare();
}
}
private void Go()
{
active = true;
started = Time.unscaledTime;
((Behaviour)canvas).enabled = true;
Cursor.visible = false;
AudioSource[] array = Object.FindObjectsOfType<AudioSource>();
foreach (AudioSource val in array)
{
if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)src && val.loop)
{
val.mute = true;
}
}
if ((Object)(object)vp != (Object)null && !failed)
{
limit = 12f;
if (prepared)
{
StartPlayback();
}
}
else if ((Object)(object)src != (Object)null)
{
src.Play();
limit = src.clip.length + 0.1f;
}
else
{
limit = 0.35f;
}
}
private void StartPlayback()
{
vp.Play();
if ((Object)(object)src != (Object)null)
{
src.Play();
}
double length = vp.length;
limit = Time.unscaledTime - started + ((length > 0.1) ? ((float)length + 2f) : 12f);
}
private void OnPrepared(VideoPlayer p)
{
prepared = true;
if (active)
{
StartPlayback();
}
}
private void OnEnd(VideoPlayer p)
{
if (active)
{
Quit();
}
}
private void OnError(VideoPlayer p, string message)
{
failed = true;
if (!active)
{
return;
}
float num = 0.35f;
if ((Object)(object)src != (Object)null)
{
if (!src.isPlaying)
{
src.Play();
}
num = Mathf.Max(0.35f, src.clip.length - src.time);
}
limit = Time.unscaledTime - started + num;
}
private void Update()
{
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
if (active)
{
Cursor.visible = false;
if ((Object)(object)vp != (Object)null && !failed && (Object)(object)vp.texture != (Object)null && (Object)(object)screen.texture != (Object)(object)vp.texture)
{
screen.texture = vp.texture;
((Graphic)screen).color = Color.white;
}
if (Time.unscaledTime - started > limit)
{
Quit();
}
}
}
private void Quit()
{
if (quitting)
{
return;
}
quitting = true;
Thread thread = new Thread((ThreadStart)delegate
{
Thread.Sleep(1500);
try
{
Process.GetCurrentProcess().Kill();
}
catch (Exception)
{
}
});
thread.IsBackground = true;
thread.Start();
Application.Quit();
}
}
internal static class Wav
{
internal static AudioClip Load(string path)
{
byte[] array = File.ReadAllBytes(path);
if (array.Length < 44 || array[0] != 82 || array[1] != 73 || array[2] != 70 || array[3] != 70)
{
return null;
}
int num = 0;
int num2 = 0;
int num3 = 0;
int num4 = 0;
int num5 = -1;
int num6 = 0;
int num7 = 12;
while (num7 + 8 <= array.Length)
{
string text = Encoding.ASCII.GetString(array, num7, 4);
int num8 = BitConverter.ToInt32(array, num7 + 4);
int num9 = num7 + 8;
if (text == "fmt " && num9 + 16 <= array.Length)
{
num = BitConverter.ToInt16(array, num9);
num2 = BitConverter.ToInt16(array, num9 + 2);
num3 = BitConverter.ToInt32(array, num9 + 4);
num4 = BitConverter.ToInt16(array, num9 + 14);
}
else if (text == "data")
{
num5 = num9;
num6 = ((num8 < 0 || num8 > array.Length - num9) ? (array.Length - num9) : num8);
break;
}
if (num8 < 0)
{
break;
}
num7 = num9 + num8 + (num8 & 1);
}
if (num != 1 || num4 != 16 || num2 < 1 || num3 <= 0 || num5 < 0)
{
return null;
}
int num10 = num6 / 2;
num10 -= num10 % num2;
if (num10 <= 0)
{
return null;
}
float[] array2 = new float[num10];
for (int i = 0; i < num10; i++)
{
array2[i] = (float)BitConverter.ToInt16(array, num5 + i * 2) / 32768f;
}
AudioClip val = AudioClip.Create("pyn_js", num10 / num2, num2, num3, false);
val.SetData(array2, 0);
return val;
}
}