using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using Zorro.Core;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace PeakRandomCustomRunMod;
[BepInPlugin("peak.dailyexpeditions", "PEAK: Daily Expeditions", "1.0.0")]
public class RandomCustomRunPlugin : BaseUnityPlugin
{
public const string MOD_GUID = "peak.dailyexpeditions";
public const string MOD_NAME = "PEAK: Daily Expeditions";
public const string MOD_VERSION = "1.0.0";
internal static ManualLogSource Logger;
internal static RandomCustomRunPlugin Instance;
private Harmony _harmony;
private static bool _isChallengeRunActive = false;
public static bool IsChallengeRunActive
{
get
{
if (_isChallengeRunActive)
{
return true;
}
if (RunSettings.IsCustomRun && RunSettings.GetValue((SETTINGTYPE)10050, true) == 777)
{
return true;
}
return false;
}
set
{
_isChallengeRunActive = value;
if (value)
{
RunSettings.SetValue((SETTINGTYPE)10050, 777);
}
else if (RunSettings.GetValue((SETTINGTYPE)10050, true) == 777)
{
RunSettings.SetValue((SETTINGTYPE)10050, 0);
}
}
}
private void Awake()
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Expected O, but got Unknown
Instance = this;
Logger = ((BaseUnityPlugin)this).Logger;
Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
try
{
_harmony = new Harmony("peak.dailyexpeditions");
_harmony.PatchAll();
}
catch (Exception arg)
{
Logger.LogError((object)$"Ошибка Harmony: {arg}");
}
}
public static void RandomizeSettings(CustomOptionsWindow window)
{
//IL_008a: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
try
{
Random random = new Random();
if (RunSettings.alphabetizedIndices != null)
{
string[] alphabetizedIndices = RunSettings.alphabetizedIndices;
foreach (string text in alphabetizedIndices)
{
switch (text)
{
case "MiniRun":
case "MiniRunBiome":
case "GameMode":
case "GrappleMode":
case "ChaosItems":
case "HelpingHand":
case "TimeScale":
{
if (Enum.TryParse<SETTINGTYPE>(text, out SETTINGTYPE result))
{
RunSettings.SetValue(result, 0);
}
continue;
}
}
SETTINGTYPE result2;
if (text.StartsWith("Item_"))
{
string text2 = text.Substring("Item_".Length);
int num = random.Next(0, 2);
RunSettings.SetItemValue(text2, num);
}
else if (Enum.TryParse<SETTINGTYPE>(text, out result2))
{
int maxValue = RunSettings.GetMaxValue(result2);
if (maxValue > 0)
{
int num2 = random.Next(0, maxValue + 1);
RunSettings.SetValue(result2, num2);
}
}
}
}
RunSettings.SaveToDisk();
if (!((Object)(object)window != (Object)null))
{
return;
}
CustomOptionBase[] componentsInChildren = ((Component)window).GetComponentsInChildren<CustomOptionBase>(true);
for (int j = 0; j < componentsInChildren.Length; j++)
{
if ((Object)(object)componentsInChildren[j] != (Object)null)
{
componentsInChildren[j].RestoreDefault();
}
}
if ((Object)(object)window.miniRunOptions != (Object)null)
{
window.miniRunOptions.SetActive(RunSettings.GetValue((SETTINGTYPE)10000, true) != RunSettings.GetDefaultValue((SETTINGTYPE)10000));
}
}
catch (Exception ex)
{
if (Logger != null)
{
Logger.LogError((object)("Ошибка рандомизации: " + ex));
}
}
}
}
[HarmonyPatch(typeof(NextLevelUI))]
public static class NextLevelUIPatch
{
private static GameObject _randomRunBoardObj;
private static TMP_Text _randomRunTimerTmp;
private static TMP_Text _randomRunHeaderTmp;
[HarmonyPatch("Start")]
[HarmonyPostfix]
public static void Postfix_Start(NextLevelUI __instance)
{
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: 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_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
try
{
if ((Object)(object)__instance == (Object)null)
{
return;
}
Transform parent = ((Component)__instance).transform.parent;
if ((Object)(object)parent == (Object)null)
{
return;
}
Transform val = parent.Find("RandomRunFlightBoardBlock");
if ((Object)(object)val != (Object)null)
{
_randomRunBoardObj = ((Component)val).gameObject;
}
else
{
_randomRunBoardObj = Object.Instantiate<GameObject>(((Component)__instance).gameObject, parent);
((Object)_randomRunBoardObj).name = "RandomRunFlightBoardBlock";
NextLevelUI component = _randomRunBoardObj.GetComponent<NextLevelUI>();
if ((Object)(object)component != (Object)null)
{
Object.DestroyImmediate((Object)(object)component);
}
LocalizedText[] componentsInChildren = _randomRunBoardObj.GetComponentsInChildren<LocalizedText>(true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
if ((Object)(object)componentsInChildren[i] != (Object)null)
{
Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
}
}
RectTransform component2 = _randomRunBoardObj.GetComponent<RectTransform>();
RectTransform component3 = ((Component)__instance).GetComponent<RectTransform>();
if ((Object)(object)component2 != (Object)null && (Object)(object)component3 != (Object)null)
{
component2.anchorMin = component3.anchorMin;
component2.anchorMax = component3.anchorMax;
component2.pivot = component3.pivot;
float num = Mathf.Max(55f, component3.sizeDelta.y + 16f);
component2.anchoredPosition = new Vector2(component3.anchoredPosition.x, component3.anchoredPosition.y - num);
}
_randomRunBoardObj.transform.SetSiblingIndex(((Component)__instance).transform.GetSiblingIndex() + 1);
}
if (!((Object)(object)_randomRunBoardObj != (Object)null))
{
return;
}
_randomRunBoardObj.SetActive(false);
TMP_Text[] componentsInChildren2 = _randomRunBoardObj.GetComponentsInChildren<TMP_Text>(true);
if (componentsInChildren2 != null && componentsInChildren2.Length > 0)
{
if (componentsInChildren2.Length >= 2)
{
_randomRunHeaderTmp = componentsInChildren2[0];
_randomRunTimerTmp = componentsInChildren2[1];
}
else
{
_randomRunTimerTmp = componentsInChildren2[0];
}
}
}
catch (Exception ex)
{
RandomCustomRunPlugin.Logger.LogError((object)("Error in NextLevelUI Postfix_Start: " + ex));
}
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
public static void Postfix_Update(NextLevelUI __instance)
{
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Invalid comparison between Unknown and I4
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Unknown result type (might be due to invalid IL or missing references)
try
{
if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.timer == (Object)null || (Object)(object)_randomRunBoardObj == (Object)null)
{
return;
}
bool flag = ((Component)__instance).gameObject.activeInHierarchy && ((Component)__instance.timer).gameObject.activeInHierarchy && !string.IsNullOrEmpty(((TMP_Text)__instance.timer).text) && ((TMP_Text)__instance.timer).text != "-- -- --";
if (_randomRunBoardObj.activeSelf != flag)
{
_randomRunBoardObj.SetActive(flag);
}
if (flag)
{
bool flag2 = (int)LocalizedText.CURRENT_LANGUAGE == 7;
string text = ((TMP_Text)__instance.timer).text;
if ((Object)(object)_randomRunHeaderTmp != (Object)null && (Object)(object)_randomRunTimerTmp != (Object)null)
{
_randomRunHeaderTmp.text = (flag2 ? "НОВЫЙ СЛУЧАЙНЫЙ ЗАБЕГ ЧЕРЕЗ" : "NEW RANDOM RUN IN");
((Graphic)_randomRunHeaderTmp).color = ((Graphic)__instance.timer).color;
_randomRunTimerTmp.text = text;
((Graphic)_randomRunTimerTmp).color = ((Graphic)__instance.timer).color;
}
else if ((Object)(object)_randomRunTimerTmp != (Object)null)
{
_randomRunTimerTmp.text = (flag2 ? ("НОВЫЙ СЛУЧАЙНЫЙ ЗАБЕГ ЧЕРЕЗ " + text) : ("NEW RANDOM RUN IN " + text));
((Graphic)_randomRunTimerTmp).color = ((Graphic)__instance.timer).color;
}
}
}
catch
{
}
}
}
[HarmonyPatch(typeof(AscentUI), "Start")]
public static class AscentUIPatch
{
public static void Postfix(AscentUI __instance)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Invalid comparison between Unknown and I4
try
{
if (!((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.text == (Object)null) && RunSettings.IsCustomRun && RandomCustomRunPlugin.IsChallengeRunActive)
{
bool flag = (int)LocalizedText.CURRENT_LANGUAGE == 7;
((TMP_Text)__instance.text).text = (flag ? "СЛУЧАЙНЫЙ ЗАБЕГ" : "RANDOM RUN");
}
}
catch
{
}
}
}
[HarmonyPatch(typeof(BoardingPass), "UpdateAscent")]
public static class BoardingPassPatch
{
private static float _originalAscentDescFontSize;
private static bool _originalFontSizeCaptured;
public static void Postfix(BoardingPass __instance)
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Invalid comparison between Unknown and I4
try
{
if (!((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.ascentDesc == (Object)null))
{
if (!_originalFontSizeCaptured)
{
_originalAscentDescFontSize = __instance.ascentDesc.fontSize;
_originalFontSizeCaptured = true;
}
if (RunSettings.IsCustomRun)
{
bool flag = (int)LocalizedText.CURRENT_LANGUAGE == 7;
__instance.ascentDesc.text = (flag ? "НАСТРОЙТЕ ЭКСПЕДИЦИЮ ПО СВОЕМУ ВКУСУ ИЛИ ИСПЫТАЙТЕ СЕБЯ В ЕЖЕДНЕВНОМ СЛУЧАЙНОМ ЗАБЕГЕ!" : "CUSTOMIZE YOUR EXPEDITION TO YOUR LIKING OR CHALLENGE YOURSELF IN THE DAILY RANDOM RUN!");
__instance.ascentDesc.fontSize = Mathf.Max(10f, _originalAscentDescFontSize - 3f);
}
else
{
__instance.ascentDesc.fontSize = _originalAscentDescFontSize;
}
}
}
catch
{
}
}
}
[HarmonyPatch(typeof(MenuWindow))]
public static class MenuWindowTestClosePatch
{
[HarmonyPrefix]
[HarmonyPatch("TestCloseViaInput")]
public static bool Prefix_TestCloseViaInput(MenuWindow __instance)
{
if (CustomOptionsWindowPatch.IsCountingDown && __instance is CustomOptionsWindow)
{
if (Object.op_Implicit((Object)(object)Character.localCharacter) && (Object)(object)Character.localCharacter.input != (Object)null)
{
Character.localCharacter.input.pauseWasPressed = false;
}
if ((Object)(object)Singleton<UIInputHandler>.Instance != (Object)null)
{
Singleton<UIInputHandler>.Instance.cancelWasPressed = false;
}
return false;
}
return true;
}
}
[HarmonyPatch(typeof(AchievementManager))]
public static class AchievementManagerChallengePatch
{
[HarmonyPostfix]
[HarmonyPatch("TryCompleteAscent")]
public static void Postfix_TryCompleteAscent()
{
try
{
if (RandomCustomRunPlugin.IsChallengeRunActive)
{
CustomOptionsWindowPatch.CompletedRandomRunsCount++;
int num = DateTime.UtcNow.Year * 10000 + DateTime.UtcNow.Month * 100 + DateTime.UtcNow.Day;
int num2 = PlayerPrefs.GetInt("PeakMod_CompletedToday_" + num, 0);
PlayerPrefs.SetInt("PeakMod_CompletedToday_" + num, num2 + 1);
PlayerPrefs.DeleteKey("PeakMod_Challenge_Saved");
PlayerPrefs.DeleteKey("PeakMod_ChallengeDay");
PlayerPrefs.Save();
RandomCustomRunPlugin.IsChallengeRunActive = false;
}
}
catch
{
}
}
}
[HarmonyPatch(typeof(RunSettings))]
public static class RunSettingsBlockingAchievementsPatch
{
[HarmonyPrefix]
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
public static bool Prefix_blockingAchievements(ref bool __result)
{
if (RandomCustomRunPlugin.IsChallengeRunActive)
{
__result = false;
return false;
}
return true;
}
}
[HarmonyPatch(typeof(LootData))]
public static class LootDataPatch
{
[HarmonyPostfix]
[HarmonyPatch("PopulateLootData")]
public static void Postfix_PopulateLootData()
{
//IL_0086: 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)
try
{
if (LootData.AllSpawnWeightData == null)
{
LootData.AllSpawnWeightData = new Dictionary<SpawnPool, Dictionary<ushort, int>>();
}
Dictionary<ushort, int> dictionary = new Dictionary<ushort, int>();
if ((Object)(object)SingletonAsset<ItemDatabase>.Instance != (Object)null && SingletonAsset<ItemDatabase>.Instance.itemLookup != null)
{
foreach (KeyValuePair<ushort, Item> item in SingletonAsset<ItemDatabase>.Instance.itemLookup)
{
if ((Object)(object)item.Value != (Object)null)
{
LootData component = ((Component)item.Value).GetComponent<LootData>();
int value = 50;
if ((Object)(object)component != (Object)null && LootData.RarityWeights != null && LootData.RarityWeights.ContainsKey(component.Rarity))
{
value = LootData.RarityWeights[component.Rarity];
}
dictionary[item.Key] = value;
}
}
}
LootData.AllSpawnWeightData[(SpawnPool)134217728] = dictionary;
}
catch (Exception ex)
{
RandomCustomRunPlugin.Logger.LogError((object)("Ошибка в LootDataPatch.Postfix_PopulateLootData: " + ex));
}
}
[HarmonyPatch("GetRandomItems")]
[HarmonyPrefix]
public static void Prefix_GetRandomItems()
{
try
{
if (LootData.AllSpawnWeightData == null || !LootData.AllSpawnWeightData.ContainsKey((SpawnPool)134217728) || LootData.AllSpawnWeightData[(SpawnPool)134217728].Count == 0)
{
LootData.PopulateLootData();
}
}
catch (Exception ex)
{
RandomCustomRunPlugin.Logger.LogError((object)("Ошибка в LootDataPatch.Prefix_GetRandomItems: " + ex));
}
}
}
[HarmonyPatch(typeof(CharacterAfflictions))]
public static class PetrifyDamagePatch
{
[HarmonyPatch("AddStatus", new Type[]
{
typeof(STATUSTYPE),
typeof(float),
typeof(bool),
typeof(bool),
typeof(bool),
typeof(bool)
})]
[HarmonyPrefix]
public static void Prefix_AddStatus(STATUSTYPE statusType, ref float amount)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Invalid comparison between Unknown and I4
try
{
if ((int)statusType == 13 && RunSettings.IsCustomRun)
{
switch (RunSettings.GetValue((SETTINGTYPE)450, false))
{
case 0:
amount = 0f;
break;
case 1:
amount *= 0.5f;
break;
case 3:
amount *= 1.6f;
break;
case 2:
break;
}
}
}
catch
{
}
}
[HarmonyPatch("AddPetrify", new Type[] { typeof(int) })]
[HarmonyPrefix]
public static void Prefix_AddPetrify(ref int petrify)
{
try
{
if (RunSettings.IsCustomRun)
{
switch (RunSettings.GetValue((SETTINGTYPE)450, false))
{
case 0:
petrify = 0;
break;
case 1:
petrify = Mathf.RoundToInt((float)petrify * 0.5f);
break;
case 3:
petrify = Mathf.RoundToInt((float)petrify * 1.6f);
break;
case 2:
break;
}
}
}
catch
{
}
}
}
[HarmonyPatch(typeof(CustomOptionTooltip))]
public static class CustomOptionTooltipPatch
{
[HarmonyPrefix]
[HarmonyPatch("ShowTooltip")]
public static bool Prefix_ShowTooltip(CustomOptionTooltip __instance)
{
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
//IL_01b3: Invalid comparison between Unknown and I4
try
{
if ((Object)(object)__instance == (Object)null)
{
return true;
}
CustomOptionToggle componentInParent = ((Component)__instance).GetComponentInParent<CustomOptionToggle>();
CustomOptionMulti componentInParent2 = ((Component)__instance).GetComponentInParent<CustomOptionMulti>();
string text = ((Object)((Component)__instance).gameObject).name;
if ((Object)(object)((Component)__instance).transform.parent != (Object)null)
{
text = text + " " + ((Object)((Component)__instance).transform.parent).name;
}
if ((Object)(object)componentInParent != (Object)null)
{
string text2 = text;
text = text2 + " " + ((Object)((Component)componentInParent).gameObject).name + " " + ((object)componentInParent.settingType).ToString();
}
if ((Object)(object)componentInParent2 != (Object)null)
{
string text3 = text;
text = text3 + " " + ((Object)((Component)componentInParent2).gameObject).name + " " + ((object)componentInParent2.settingType).ToString();
}
if (text.IndexOf("Petrification", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Revival", StringComparison.OrdinalIgnoreCase) >= 0)
{
if ((Object)(object)__instance.text != (Object)null)
{
((Component)__instance.text).gameObject.SetActive(false);
}
return false;
}
if ((Object)(object)__instance.text == (Object)null)
{
CustomOptionTooltip[] array = Object.FindObjectsOfType<CustomOptionTooltip>();
for (int i = 0; i < array.Length; i++)
{
if ((Object)(object)array[i] != (Object)null && (Object)(object)array[i] != (Object)(object)__instance && (Object)(object)array[i].text != (Object)null)
{
__instance.text = array[i].text;
break;
}
}
}
bool flag = (int)LocalizedText.CURRENT_LANGUAGE == 7;
if (text.IndexOf("Chaos", StringComparison.OrdinalIgnoreCase) >= 0 && (Object)(object)__instance.text != (Object)null)
{
__instance.text.SetText(flag ? "В любых чемоданах может выпасть абсолютно любой предмет из всей игры." : "Any luggage can drop absolutely any item in the game.");
((Component)__instance.text).gameObject.SetActive(true);
return false;
}
if ((text.IndexOf("TimeScale", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Speed", StringComparison.OrdinalIgnoreCase) >= 0) && (Object)(object)__instance.text != (Object)null)
{
__instance.text.SetText(flag ? "Все движется в два раза быстрее, а голоса в микрофоне становятся писклявыми." : "Everything moves twice as fast, and players' voices become high-pitched squeaks.");
((Component)__instance.text).gameObject.SetActive(true);
return false;
}
}
catch (Exception ex)
{
RandomCustomRunPlugin.Logger.LogError((object)("Ошибка в CustomOptionTooltipPatch: " + ex));
}
return true;
}
}
[HarmonyPatch(typeof(LocalizedText))]
public static class LocalizedTextPatch
{
[HarmonyPrefix]
[HarmonyPatch("GetText", new Type[]
{
typeof(string),
typeof(bool)
})]
public static bool Prefix_GetText(string id, ref string __result)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Invalid comparison between Unknown and I4
if (string.IsNullOrEmpty(id))
{
return true;
}
string text = id.ToUpperInvariant();
bool flag = (int)LocalizedText.CURRENT_LANGUAGE == 7;
if (text.Contains("CHAOS"))
{
__result = (flag ? "В любых чемоданах может выпасть абсолютно любой предмет из всей игры." : "Any luggage can drop absolutely any item in the game.");
return false;
}
if (text.Contains("TIMESCALE") || text.Contains("SPEED"))
{
__result = (flag ? "Все движется в два раза быстрее, а голоса в микрофоне становятся писклявыми." : "Everything moves twice as fast, and players' voices become high-pitched squeaks.");
return false;
}
return true;
}
}
[HarmonyPatch(typeof(CustomOptionsWindow))]
public static class CustomOptionsWindowPatch
{
private static GameObject _randomBtnObj;
private static GameObject _randomRunBtnObj;
private static bool _layoutDone = false;
private static Vector2 _originalDefPos;
private static Vector2 _originalDefSize;
private static Vector2 _originalTitlePos;
private static Vector2 _originalBadgesPos;
private static Coroutine _countdownCoroutine;
private static bool _isCountingDown = false;
private static Dictionary<string, int> _backupSettings = new Dictionary<string, int>();
private static Dictionary<ushort, int> _backupItems = new Dictionary<ushort, int>();
private static TMP_Text _badgesTextComponent;
private static Color _originalBadgesColor = Color.white;
private static bool _originalBadgesColorCaptured = false;
private static CanvasGroup _panelsCanvasGroup;
public static bool IsCountingDown => _isCountingDown;
public static int CompletedRandomRunsCount
{
get
{
return PlayerPrefs.GetInt("PeakMod_CompletedRandomRunsCount", 0);
}
set
{
PlayerPrefs.SetInt("PeakMod_CompletedRandomRunsCount", value);
PlayerPrefs.Save();
}
}
[HarmonyPatch("Initialize")]
[HarmonyPostfix]
public static void Postfix_Initialize(CustomOptionsWindow __instance)
{
EnsureDefaultRevivalSetting();
SetupButtons(__instance);
InjectHiddenFeatureToggles(__instance);
}
[HarmonyPostfix]
[HarmonyPatch("OnOpen")]
public static void Postfix_OnOpen(CustomOptionsWindow __instance)
{
EnsureDefaultRevivalSetting();
SetupButtons(__instance);
InjectHiddenFeatureToggles(__instance);
}
private static void EnsureDefaultRevivalSetting()
{
try
{
int value = RunSettings.GetValue((SETTINGTYPE)900, true);
if (value <= 0)
{
RunSettings.SetValue((SETTINGTYPE)900, 1);
}
}
catch
{
}
}
public static void UpdateBadgesDisclaimerText()
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Invalid comparison between Unknown and I4
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_badgesTextComponent == (Object)null)
{
return;
}
bool flag = (int)LocalizedText.CURRENT_LANGUAGE == 7;
int completedRandomRunsCount = CompletedRandomRunsCount;
if (_isCountingDown)
{
string text = (flag ? "ЗНАЧКИ ВКЛЮЧЕНЫ (СЛУЧАЙНЫЙ ЗАБЕГ)" : "BADGES ENABLED (RANDOM RUN)");
string text2 = (flag ? (" | Пройдено случайных забегов: " + completedRandomRunsCount) : (" | Completed random runs: " + completedRandomRunsCount));
_badgesTextComponent.text = text + text2;
((Graphic)_badgesTextComponent).color = new Color(0.2f, 1f, 0.3f);
return;
}
LocalizedText component = ((Component)_badgesTextComponent).GetComponent<LocalizedText>();
if ((Object)(object)component != (Object)null)
{
component.RefreshText();
}
string text3 = _badgesTextComponent.text;
if (string.IsNullOrEmpty(text3))
{
text3 = (flag ? "В своих экспедициях нельзя получить значки." : "Custom runs disable badges.");
}
if (text3.Contains(" | "))
{
text3 = text3.Substring(0, text3.IndexOf(" | "));
}
string text4 = (flag ? (" | Пройдено случайных забегов: " + completedRandomRunsCount) : (" | Completed random runs: " + completedRandomRunsCount));
_badgesTextComponent.text = text3 + text4;
((Graphic)_badgesTextComponent).color = _originalBadgesColor;
}
public static void SetupButtons(CustomOptionsWindow window)
{
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_0167: Invalid comparison between Unknown and I4
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
//IL_0221: Unknown result type (might be due to invalid IL or missing references)
//IL_024a: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Expected O, but got Unknown
//IL_0205: Unknown result type (might be due to invalid IL or missing references)
//IL_020c: Expected O, but got Unknown
//IL_0337: Unknown result type (might be due to invalid IL or missing references)
//IL_0357: Unknown result type (might be due to invalid IL or missing references)
//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0308: Expected O, but got Unknown
//IL_031b: Unknown result type (might be due to invalid IL or missing references)
//IL_0322: Expected O, but got Unknown
//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
//IL_0407: Unknown result type (might be due to invalid IL or missing references)
//IL_0413: Unknown result type (might be due to invalid IL or missing references)
//IL_041f: Unknown result type (might be due to invalid IL or missing references)
//IL_042b: Unknown result type (might be due to invalid IL or missing references)
//IL_043f: Unknown result type (might be due to invalid IL or missing references)
//IL_044f: Unknown result type (might be due to invalid IL or missing references)
//IL_0465: Unknown result type (might be due to invalid IL or missing references)
//IL_0492: Unknown result type (might be due to invalid IL or missing references)
//IL_0497: Unknown result type (might be due to invalid IL or missing references)
//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
UnityAction val = null;
UnityAction val2 = null;
try
{
if ((Object)(object)window == (Object)null)
{
return;
}
Transform val3 = ((Component)window).transform.Find("CustomOptions/Panel");
if ((Object)(object)val3 == (Object)null)
{
return;
}
Transform val4 = val3.Find("RestoreDefaultsButton");
if ((Object)(object)val4 == (Object)null)
{
return;
}
RectTransform component = ((Component)val4).GetComponent<RectTransform>();
if ((Object)(object)component == (Object)null)
{
return;
}
Transform val5 = val3.Find("Title");
RectTransform val6 = (((Object)(object)val5 != (Object)null) ? ((Component)val5).GetComponent<RectTransform>() : null);
Transform val7 = val3.Find("BadgesDisabled");
RectTransform val8 = (((Object)(object)val7 != (Object)null) ? ((Component)val7).GetComponent<RectTransform>() : null);
if (!_layoutDone)
{
_originalDefPos = component.anchoredPosition;
_originalDefSize = component.sizeDelta;
if ((Object)(object)val6 != (Object)null)
{
_originalTitlePos = val6.anchoredPosition;
}
if ((Object)(object)val8 != (Object)null)
{
_originalBadgesPos = val8.anchoredPosition;
}
_layoutDone = true;
}
float x = _originalDefSize.x;
_ = _originalDefSize.y;
float num = 12f;
float num2 = x + num;
component.sizeDelta = _originalDefSize;
component.anchoredPosition = new Vector2(_originalDefPos.x - num2, _originalDefPos.y);
bool flag = (int)LocalizedText.CURRENT_LANGUAGE == 7;
Transform val9 = val3.Find("RandomSettingsButton");
if ((Object)(object)val9 != (Object)null)
{
_randomBtnObj = ((Component)val9).gameObject;
}
else
{
_randomBtnObj = Object.Instantiate<GameObject>(((Component)val4).gameObject, val3);
((Object)_randomBtnObj).name = "RandomSettingsButton";
LocalizedText componentInChildren = _randomBtnObj.GetComponentInChildren<LocalizedText>();
if ((Object)(object)componentInChildren != (Object)null)
{
Object.DestroyImmediate((Object)(object)componentInChildren);
}
Button component2 = _randomBtnObj.GetComponent<Button>();
if ((Object)(object)component2 != (Object)null)
{
component2.onClick = new ButtonClickedEvent();
ButtonClickedEvent onClick = component2.onClick;
if (val == null)
{
val = (UnityAction)delegate
{
if (_isCountingDown)
{
CancelChallengeCountdown(window);
}
RandomCustomRunPlugin.RandomizeSettings(window);
};
}
((UnityEvent)onClick).AddListener(val);
}
}
RectTransform component3 = _randomBtnObj.GetComponent<RectTransform>();
component3.sizeDelta = _originalDefSize;
component3.anchoredPosition = new Vector2(_originalDefPos.x - num2 * 2f, _originalDefPos.y);
TMP_Text componentInChildren2 = _randomBtnObj.GetComponentInChildren<TMP_Text>();
if ((Object)(object)componentInChildren2 != (Object)null)
{
componentInChildren2.text = (flag ? "СЛУЧАЙНЫЕ" : "RANDOM");
}
Transform val10 = val3.Find("RandomRunButton");
if ((Object)(object)val10 != (Object)null)
{
_randomRunBtnObj = ((Component)val10).gameObject;
}
else
{
_randomRunBtnObj = Object.Instantiate<GameObject>(((Component)val4).gameObject, val3);
((Object)_randomRunBtnObj).name = "RandomRunButton";
LocalizedText componentInChildren3 = _randomRunBtnObj.GetComponentInChildren<LocalizedText>();
if ((Object)(object)componentInChildren3 != (Object)null)
{
Object.DestroyImmediate((Object)(object)componentInChildren3);
}
Button component4 = _randomRunBtnObj.GetComponent<Button>();
if ((Object)(object)component4 != (Object)null)
{
component4.onClick = new ButtonClickedEvent();
ButtonClickedEvent onClick2 = component4.onClick;
if (val2 == null)
{
val2 = (UnityAction)delegate
{
StartChallengeRun(window);
};
}
((UnityEvent)onClick2).AddListener(val2);
}
}
RectTransform component5 = _randomRunBtnObj.GetComponent<RectTransform>();
component5.sizeDelta = _originalDefSize;
component5.anchoredPosition = new Vector2(_originalDefPos.x, _originalDefPos.y);
if (!_isCountingDown)
{
TMP_Text componentInChildren4 = _randomRunBtnObj.GetComponentInChildren<TMP_Text>();
if ((Object)(object)componentInChildren4 != (Object)null)
{
componentInChildren4.text = (flag ? "СЛУЧАЙНЫЙ ЗАБЕГ" : "RANDOM RUN");
}
}
if ((Object)(object)val6 != (Object)null)
{
val6.anchoredPosition = new Vector2(_originalTitlePos.x, _originalTitlePos.y + 14f);
}
if (!((Object)(object)val6 != (Object)null) || !((Object)(object)val8 != (Object)null))
{
return;
}
val8.anchorMin = val6.anchorMin;
val8.anchorMax = val6.anchorMax;
val8.pivot = new Vector2(0f, 1f);
float num3 = val6.anchoredPosition.x - val6.sizeDelta.x * val6.pivot.x;
val8.anchoredPosition = new Vector2(num3, val6.anchoredPosition.y - 23f);
val8.sizeDelta = new Vector2(450f, 25f);
TMP_Text component6 = ((Component)val7).GetComponent<TMP_Text>();
if ((Object)(object)component6 != (Object)null)
{
_badgesTextComponent = component6;
if (!_originalBadgesColorCaptured)
{
_originalBadgesColor = ((Graphic)component6).color;
_originalBadgesColorCaptured = true;
}
if (!_isCountingDown)
{
((Graphic)component6).color = _originalBadgesColor;
}
LocalizedText component7 = ((Component)component6).GetComponent<LocalizedText>();
if ((Object)(object)component7 != (Object)null)
{
component7.RefreshText();
}
component6.alignment = (TextAlignmentOptions)257;
component6.enableWordWrapping = true;
UpdateBadgesDisclaimerText();
}
}
catch (Exception ex)
{
RandomCustomRunPlugin.Logger.LogError((object)("Ошибка в SetupButtons: " + ex));
}
}
private static void SetWindowInteractive(CustomOptionsWindow window, bool interactive)
{
if ((Object)(object)window == (Object)null)
{
return;
}
try
{
Transform val = ((Component)window).transform.Find("CustomOptions/Panel");
if (!((Object)(object)val != (Object)null))
{
return;
}
Transform val2 = val.Find("Panels");
if ((Object)(object)val2 != (Object)null)
{
if ((Object)(object)_panelsCanvasGroup == (Object)null)
{
_panelsCanvasGroup = ((Component)val2).GetComponent<CanvasGroup>();
if ((Object)(object)_panelsCanvasGroup == (Object)null)
{
_panelsCanvasGroup = ((Component)val2).gameObject.AddComponent<CanvasGroup>();
}
}
if ((Object)(object)_panelsCanvasGroup != (Object)null)
{
_panelsCanvasGroup.interactable = interactive;
_panelsCanvasGroup.blocksRaycasts = interactive;
}
}
Transform val3 = val.Find("RestoreDefaultsButton");
if ((Object)(object)val3 != (Object)null)
{
Button component = ((Component)val3).GetComponent<Button>();
if ((Object)(object)component != (Object)null)
{
((Selectable)component).interactable = interactive;
}
}
if ((Object)(object)_randomBtnObj != (Object)null)
{
Button component2 = _randomBtnObj.GetComponent<Button>();
if ((Object)(object)component2 != (Object)null)
{
((Selectable)component2).interactable = interactive;
}
}
Transform val4 = val.Find("CloseButton");
if ((Object)(object)val4 != (Object)null)
{
Button component3 = ((Component)val4).GetComponent<Button>();
if ((Object)(object)component3 != (Object)null)
{
((Selectable)component3).interactable = interactive;
}
}
if ((Object)(object)window.closeButtonCustom != (Object)null)
{
((Selectable)window.closeButtonCustom).interactable = interactive;
}
}
catch
{
}
}
public static void StartChallengeRun(CustomOptionsWindow window)
{
if ((Object)(object)window == (Object)null)
{
return;
}
if (_isCountingDown)
{
CancelChallengeCountdown(window);
return;
}
BackupCurrentSettings();
int num = DateTime.UtcNow.Year * 10000 + DateTime.UtcNow.Month * 100 + DateTime.UtcNow.Day;
int num2 = PlayerPrefs.GetInt("PeakMod_ChallengeDay", 0);
if (num2 != num || !PlayerPrefs.HasKey("PeakMod_Challenge_Saved"))
{
GenerateNewDailyChallenge();
PlayerPrefs.SetInt("PeakMod_ChallengeDay", num);
PlayerPrefs.SetInt("PeakMod_Challenge_Saved", 1);
PlayerPrefs.Save();
}
else
{
ApplySavedDailyChallenge();
}
RefreshAllWindows(window);
_isCountingDown = true;
UpdateBadgesDisclaimerText();
_isCountingDown = true;
SetWindowInteractive(window, interactive: false);
_countdownCoroutine = ((MonoBehaviour)window).StartCoroutine(CountdownRoutine(window));
}
private static void CancelChallengeCountdown(CustomOptionsWindow window)
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Invalid comparison between Unknown and I4
if (_countdownCoroutine != null && (Object)(object)window != (Object)null)
{
((MonoBehaviour)window).StopCoroutine(_countdownCoroutine);
_countdownCoroutine = null;
}
_isCountingDown = false;
RandomCustomRunPlugin.IsChallengeRunActive = false;
SetWindowInteractive(window, interactive: true);
RestoreBackupSettings();
RefreshAllWindows(window);
bool flag = (int)LocalizedText.CURRENT_LANGUAGE == 7;
if ((Object)(object)_randomRunBtnObj != (Object)null)
{
TMP_Text componentInChildren = _randomRunBtnObj.GetComponentInChildren<TMP_Text>(true);
if ((Object)(object)componentInChildren != (Object)null)
{
componentInChildren.text = (flag ? "СЛУЧАЙНЫЙ ЗАБЕГ" : "RANDOM RUN");
}
}
UpdateBadgesDisclaimerText();
}
private static IEnumerator CountdownRoutine(CustomOptionsWindow window)
{
for (int seconds = 30; seconds > 0; seconds--)
{
bool isRu = (int)LocalizedText.CURRENT_LANGUAGE == 7;
if ((Object)(object)_randomRunBtnObj != (Object)null)
{
TMP_Text componentInChildren = _randomRunBtnObj.GetComponentInChildren<TMP_Text>(true);
if ((Object)(object)componentInChildren != (Object)null)
{
componentInChildren.text = (isRu ? ("ОТМЕНА (" + seconds + "с)") : ("CANCEL (" + seconds + "s)"));
}
}
yield return (object)new WaitForSecondsRealtime(1f);
}
_isCountingDown = false;
RandomCustomRunPlugin.IsChallengeRunActive = true;
SetWindowInteractive(window, interactive: true);
if ((Object)(object)window != (Object)null)
{
if ((Object)(object)window.closeButtonCustom != (Object)null)
{
((UnityEvent)window.closeButtonCustom.onClick).Invoke();
}
if ((Object)(object)window.boardingPass != (Object)null)
{
window.boardingPass.StartGame();
}
}
}
private static void BackupCurrentSettings()
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
_backupSettings.Clear();
_backupItems.Clear();
Array values = Enum.GetValues(typeof(SETTINGTYPE));
foreach (SETTINGTYPE item in values)
{
_backupSettings[((object)item).ToString()] = RunSettings.GetValue(item, true);
}
if (!((Object)(object)SingletonAsset<ItemDatabase>.Instance != (Object)null) || SingletonAsset<ItemDatabase>.Instance.itemLookup == null)
{
return;
}
foreach (KeyValuePair<ushort, Item> item2 in SingletonAsset<ItemDatabase>.Instance.itemLookup)
{
if ((Object)(object)item2.Value != (Object)null)
{
_backupItems[item2.Key] = RunSettings.GetItemValue(item2.Value, true);
}
}
}
private static void RestoreBackupSettings()
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
foreach (KeyValuePair<string, int> backupSetting in _backupSettings)
{
try
{
SETTINGTYPE val = (SETTINGTYPE)Enum.Parse(typeof(SETTINGTYPE), backupSetting.Key);
RunSettings.SetValue(val, backupSetting.Value);
}
catch
{
}
}
if (!((Object)(object)SingletonAsset<ItemDatabase>.Instance != (Object)null) || SingletonAsset<ItemDatabase>.Instance.itemLookup == null)
{
return;
}
foreach (KeyValuePair<ushort, int> backupItem in _backupItems)
{
if (SingletonAsset<ItemDatabase>.Instance.itemLookup.TryGetValue(backupItem.Key, out var value) && (Object)(object)value != (Object)null)
{
RunSettings.SetItemValue(value, backupItem.Value);
}
}
}
private static void GenerateNewDailyChallenge()
{
//IL_0242: Unknown result type (might be due to invalid IL or missing references)
//IL_026b: Unknown result type (might be due to invalid IL or missing references)
//IL_0282: Unknown result type (might be due to invalid IL or missing references)
int num = DateTime.UtcNow.Year * 10000 + DateTime.UtcNow.Month * 100 + DateTime.UtcNow.Day;
int num2 = PlayerPrefs.GetInt("PeakMod_CompletedToday_" + num, 0);
int num3 = num + num2 * 1337;
Random.InitState(num3);
int num4 = Random.Range(0, 1000);
int num5 = 0;
int num6 = 0;
int num7 = 0;
int num8 = 0;
if (num4 >= 500)
{
if (num4 < 625)
{
num5 = 1;
}
else if (num4 < 750)
{
num6 = 1;
}
else if (num4 < 875)
{
num7 = 1;
}
else
{
num8 = 1;
}
}
RunSettings.SetValue((SETTINGTYPE)10200, num5);
RunSettings.SetValue((SETTINGTYPE)20010, num6);
RunSettings.SetValue((SETTINGTYPE)30000, num7);
RunSettings.SetValue((SETTINGTYPE)20000, num8);
RunSettings.SetValue((SETTINGTYPE)10000, 0);
RunSettings.SetValue((SETTINGTYPE)10100, 0);
PlayerPrefs.SetInt("PeakMod_C_Kick", num5);
PlayerPrefs.SetInt("PeakMod_C_Chaos", num6);
PlayerPrefs.SetInt("PeakMod_C_Speed", num7);
PlayerPrefs.SetInt("PeakMod_C_Grapple", num8);
SETTINGTYPE[] array = (SETTINGTYPE[])(object)new SETTINGTYPE[6]
{
(SETTINGTYPE)300,
(SETTINGTYPE)400,
(SETTINGTYPE)200,
(SETTINGTYPE)600,
(SETTINGTYPE)800,
(SETTINGTYPE)450
};
for (int i = 0; i < array.Length; i++)
{
int num9 = Random.Range(1, 4);
RunSettings.SetValue(array[i], num9);
PlayerPrefs.SetInt("PeakMod_C_" + ((object)array[i]).ToString(), num9);
}
SETTINGTYPE[] array2 = (SETTINGTYPE[])(object)new SETTINGTYPE[4]
{
(SETTINGTYPE)700,
(SETTINGTYPE)900,
(SETTINGTYPE)100,
(SETTINGTYPE)500
};
for (int j = 0; j < array2.Length; j++)
{
int num10 = Random.Range(0, 2);
RunSettings.SetValue(array2[j], num10);
PlayerPrefs.SetInt("PeakMod_C_" + ((object)array2[j]).ToString(), num10);
}
CustomOptionToggle[] array3 = Object.FindObjectsOfType<CustomOptionToggle>();
for (int k = 0; k < array3.Length; k++)
{
if ((Object)(object)array3[k] != (Object)null && ((object)array3[k].settingType).ToString().StartsWith("Hazard_"))
{
int num11 = Random.Range(0, 2);
RunSettings.SetValue(array3[k].settingType, num11);
PlayerPrefs.SetInt("PeakMod_C_" + ((object)array3[k].settingType).ToString(), num11);
}
}
if ((Object)(object)SingletonAsset<ItemDatabase>.Instance != (Object)null && SingletonAsset<ItemDatabase>.Instance.itemLookup != null)
{
foreach (KeyValuePair<ushort, Item> item in SingletonAsset<ItemDatabase>.Instance.itemLookup)
{
if ((Object)(object)item.Value != (Object)null)
{
int num12 = Random.Range(0, 2);
RunSettings.SetItemValue(item.Value, num12);
PlayerPrefs.SetInt("PeakMod_C_Item_" + item.Key, num12);
}
}
}
PlayerPrefs.Save();
}
private static void ApplySavedDailyChallenge()
{
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_0194: Unknown result type (might be due to invalid IL or missing references)
//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
RunSettings.SetValue((SETTINGTYPE)10200, PlayerPrefs.GetInt("PeakMod_C_Kick", 0));
RunSettings.SetValue((SETTINGTYPE)20010, PlayerPrefs.GetInt("PeakMod_C_Chaos", 0));
RunSettings.SetValue((SETTINGTYPE)30000, PlayerPrefs.GetInt("PeakMod_C_Speed", 0));
RunSettings.SetValue((SETTINGTYPE)20000, PlayerPrefs.GetInt("PeakMod_C_Grapple", 0));
RunSettings.SetValue((SETTINGTYPE)10000, 0);
RunSettings.SetValue((SETTINGTYPE)10100, 0);
SETTINGTYPE[] array = (SETTINGTYPE[])(object)new SETTINGTYPE[6]
{
(SETTINGTYPE)300,
(SETTINGTYPE)400,
(SETTINGTYPE)200,
(SETTINGTYPE)600,
(SETTINGTYPE)800,
(SETTINGTYPE)450
};
for (int i = 0; i < array.Length; i++)
{
int num = PlayerPrefs.GetInt("PeakMod_C_" + ((object)array[i]).ToString(), 2);
RunSettings.SetValue(array[i], num);
}
SETTINGTYPE[] array2 = (SETTINGTYPE[])(object)new SETTINGTYPE[4]
{
(SETTINGTYPE)700,
(SETTINGTYPE)900,
(SETTINGTYPE)100,
(SETTINGTYPE)500
};
for (int j = 0; j < array2.Length; j++)
{
int num2 = PlayerPrefs.GetInt("PeakMod_C_" + ((object)array2[j]).ToString(), 1);
RunSettings.SetValue(array2[j], num2);
}
CustomOptionToggle[] array3 = Object.FindObjectsOfType<CustomOptionToggle>();
for (int k = 0; k < array3.Length; k++)
{
if ((Object)(object)array3[k] != (Object)null && ((object)array3[k].settingType).ToString().StartsWith("Hazard_"))
{
int num3 = PlayerPrefs.GetInt("PeakMod_C_" + ((object)array3[k].settingType).ToString(), 1);
RunSettings.SetValue(array3[k].settingType, num3);
}
}
if (!((Object)(object)SingletonAsset<ItemDatabase>.Instance != (Object)null) || SingletonAsset<ItemDatabase>.Instance.itemLookup == null)
{
return;
}
foreach (KeyValuePair<ushort, Item> item in SingletonAsset<ItemDatabase>.Instance.itemLookup)
{
if ((Object)(object)item.Value != (Object)null)
{
int num4 = PlayerPrefs.GetInt("PeakMod_C_Item_" + item.Key, 1);
RunSettings.SetItemValue(item.Value, num4);
}
}
}
private static void RefreshAllWindows(CustomOptionsWindow window)
{
if ((Object)(object)window == (Object)null)
{
return;
}
CustomOptionBase[] componentsInChildren = ((Component)window).GetComponentsInChildren<CustomOptionBase>(true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
if ((Object)(object)componentsInChildren[i] != (Object)null)
{
componentsInChildren[i].RestoreDefault();
}
}
if ((Object)(object)window.miniRunOptions != (Object)null)
{
window.miniRunOptions.SetActive(RunSettings.GetValue((SETTINGTYPE)10000, true) != RunSettings.GetDefaultValue((SETTINGTYPE)10000));
}
}
private static void CleanWrongCopies(CustomOptionsWindow window, Transform targetParent, string targetName)
{
if ((Object)(object)window == (Object)null)
{
return;
}
Transform[] componentsInChildren = ((Component)window).GetComponentsInChildren<Transform>(true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
if ((Object)(object)componentsInChildren[i] != (Object)null && ((Object)componentsInChildren[i]).name == targetName && ((Object)(object)targetParent == (Object)null || (Object)(object)componentsInChildren[i].parent != (Object)(object)targetParent))
{
Object.DestroyImmediate((Object)(object)((Component)componentsInChildren[i]).gameObject);
}
}
}
private static void InjectHiddenFeatureToggles(CustomOptionsWindow window)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Invalid comparison between Unknown and I4
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Invalid comparison between Unknown and I4
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Invalid comparison between Unknown and I4
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Invalid comparison between Unknown and I4
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Invalid comparison between Unknown and I4
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Invalid comparison between Unknown and I4
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Invalid comparison between Unknown and I4
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Invalid comparison between Unknown and I4
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Invalid comparison between Unknown and I4
//IL_05cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Invalid comparison between Unknown and I4
try
{
if ((Object)(object)window == (Object)null)
{
return;
}
Canvas.ForceUpdateCanvases();
bool flag = (int)LocalizedText.CURRENT_LANGUAGE == 7;
if ((Object)(object)_randomBtnObj != (Object)null)
{
TMP_Text componentInChildren = _randomBtnObj.GetComponentInChildren<TMP_Text>(true);
if ((Object)(object)componentInChildren != (Object)null)
{
componentInChildren.text = (flag ? "СЛУЧАЙНЫЕ" : "RANDOM");
}
}
CustomOptionBase[] componentsInChildren = ((Component)window).GetComponentsInChildren<CustomOptionBase>(true);
CustomOptionMulti val = null;
CustomOptionMulti val2 = null;
CustomOptionToggle val3 = null;
foreach (CustomOptionBase val4 in componentsInChildren)
{
if ((Object)(object)val4 == (Object)null)
{
continue;
}
CustomOptionMulti val5 = (CustomOptionMulti)(object)((val4 is CustomOptionMulti) ? val4 : null);
if ((Object)(object)val5 != (Object)null)
{
if ((int)val5.settingType == 300 || (int)val5.settingType == 200 || (int)val5.settingType == 400 || (int)val5.settingType == 800)
{
val = val5;
}
if ((int)val5.settingType == 100 || (int)val5.settingType == 500 || (int)val5.settingType == 700)
{
val2 = val5;
}
}
CustomOptionToggle val6 = (CustomOptionToggle)(object)((val4 is CustomOptionToggle) ? val4 : null);
if ((Object)(object)val6 != (Object)null && ((int)val6.settingType == 20000 || (int)val6.settingType == 10200 || ((Object)((Component)val6).gameObject).name.IndexOf("Grapple", StringComparison.OrdinalIgnoreCase) >= 0 || ((Object)((Component)val6).gameObject).name.IndexOf("Kick", StringComparison.OrdinalIgnoreCase) >= 0))
{
val3 = val6;
}
}
if ((Object)(object)val != (Object)null)
{
Transform parent = ((Component)val).transform.parent;
CustomOptionMulti template = (((Object)(object)val2 != (Object)null) ? val2 : val);
CleanWrongCopies(window, parent, "Option_PetrificationDamage");
CleanWrongCopies(window, parent, "Option_RevivalAllowed");
if (!PlayerPrefs.HasKey("PeakMod_PetrifyUserSet") || PlayerPrefs.GetInt("PeakMod_PetrifyUserSet", 0) == 0)
{
RunSettings.SetValue((SETTINGTYPE)450, 2);
}
Transform val7 = parent.Find("Option_PetrificationDamage");
if ((Object)(object)val7 == (Object)null)
{
CreateOptionMulti(val, parent, "Option_PetrificationDamage", flag ? "???? ??????????" : "PETRIFY DAMAGE", (SETTINGTYPE)450);
val7 = parent.Find("Option_PetrificationDamage");
}
else
{
((Component)val7).gameObject.SetActive(true);
}
SetOptionTitle(val7, flag ? "УРОН ОКАМЕНЕНИЯ" : "PETRIFY DAMAGE");
if (!PlayerPrefs.HasKey("PeakMod_RevivalUserSet") || PlayerPrefs.GetInt("PeakMod_RevivalUserSet", 0) == 0)
{
RunSettings.SetValue((SETTINGTYPE)900, 1);
}
Transform val8 = parent.Find("Option_RevivalAllowed");
if ((Object)(object)val8 == (Object)null)
{
CreateOptionMulti(template, parent, "Option_RevivalAllowed", flag ? "??????????? ???????" : "PLAYER REVIVAL", (SETTINGTYPE)900);
val8 = parent.Find("Option_RevivalAllowed");
}
else
{
((Component)val8).gameObject.SetActive(true);
}
SetOptionTitle(val8, flag ? "ВОСКРЕШЕНИЕ ИГРОКОВ" : "PLAYER REVIVAL");
SortContainerPreservingSeparators(parent);
}
if ((Object)(object)val3 != (Object)null)
{
Transform parent2 = ((Component)val3).transform.parent;
CleanWrongCopies(window, parent2, "Option_ChaosItems");
CleanWrongCopies(window, parent2, "Option_TimeScale");
Transform val9 = parent2.Find("Option_ChaosItems");
if ((Object)(object)val9 == (Object)null)
{
CreateOptionToggle(val3, parent2, "Option_ChaosItems", flag ? "????-????????" : "CHAOS ITEMS", (SETTINGTYPE)20010);
val9 = parent2.Find("Option_ChaosItems");
}
else
{
((Component)val9).gameObject.SetActive(true);
}
SetOptionTitle(val9, flag ? "ХАОС-ПРЕДМЕТЫ" : "CHAOS ITEMS");
Transform val10 = parent2.Find("Option_TimeScale");
if ((Object)(object)val10 == (Object)null)
{
CreateOptionToggle(val3, parent2, "Option_TimeScale", flag ? "?????????? ?????" : "SPEEDY MODE", (SETTINGTYPE)30000);
val10 = parent2.Find("Option_TimeScale");
}
else
{
((Component)val10).gameObject.SetActive(true);
}
SetOptionTitle(val10, flag ? "СКОРОСТНОЙ РЕЖИМ" : "SPEEDY MODE");
Transform val11 = parent2.Find("Option_MiniRun");
Transform val12 = parent2.Find("Option_MiniRunBiome");
Transform val13 = parent2.Find("Option_LINEBREAK");
Transform val14 = parent2.Find("Title (1)");
Transform val15 = parent2.Find("Option_GrappleMode");
Transform val16 = parent2.Find("Option_KickMode");
Transform val17 = parent2.Find("Option_GameMode");
Transform val18 = parent2.Find("TooltipPanel");
List<Transform> list = new List<Transform>();
if ((Object)(object)val10 != (Object)null)
{
list.Add(val10);
}
if ((Object)(object)val9 != (Object)null)
{
list.Add(val9);
}
if ((Object)(object)val15 != (Object)null)
{
list.Add(val15);
}
if ((Object)(object)val16 != (Object)null)
{
list.Add(val16);
}
list.Sort(delegate(Transform a, Transform b)
{
float optionVisualPixelWidth = GetOptionVisualPixelWidth(a);
int num4 = GetOptionVisualPixelWidth(b).CompareTo(optionVisualPixelWidth);
return (num4 != 0) ? num4 : string.Compare(GetOptionTitleText(a), GetOptionTitleText(b), StringComparison.OrdinalIgnoreCase);
});
int num = 0;
if ((Object)(object)val11 != (Object)null)
{
val11.SetSiblingIndex(num++);
}
if ((Object)(object)val12 != (Object)null)
{
val12.SetSiblingIndex(num++);
}
if ((Object)(object)val13 != (Object)null)
{
val13.SetSiblingIndex(num++);
}
if ((Object)(object)val14 != (Object)null)
{
val14.SetSiblingIndex(num++);
}
for (int num2 = 0; num2 < list.Count; num2++)
{
list[num2].SetSiblingIndex(num++);
}
if ((Object)(object)val17 != (Object)null)
{
val17.SetSiblingIndex(num++);
}
if ((Object)(object)val18 != (Object)null)
{
val18.SetSiblingIndex(num++);
}
RectTransform component = ((Component)parent2).GetComponent<RectTransform>();
if ((Object)(object)component != (Object)null)
{
LayoutRebuilder.ForceRebuildLayoutImmediate(component);
}
}
HashSet<Transform> hashSet = new HashSet<Transform>();
foreach (CustomOptionBase obj in componentsInChildren)
{
CustomOptionToggle val19 = (CustomOptionToggle)(object)((obj is CustomOptionToggle) ? obj : null);
if ((Object)(object)val19 != (Object)null && ((object)val19.settingType).ToString().StartsWith("Hazard_") && (Object)(object)((Component)val19).transform.parent != (Object)null)
{
hashSet.Add(((Component)val19).transform.parent);
}
}
foreach (Transform item in hashSet)
{
SortContainerPreservingSeparators(item);
}
if ((Object)(object)window.spawnPoolList != (Object)null)
{
SortContainerPreservingSeparators(window.spawnPoolList);
}
if ((Object)(object)window.mysticalSpawnPoolList != (Object)null)
{
SortContainerPreservingSeparators(window.mysticalSpawnPoolList);
}
}
catch (Exception ex)
{
RandomCustomRunPlugin.Logger.LogError((object)("Ошибка в InjectHiddenFeatureToggles: " + ex));
}
}
private static void PrintHierarchy(Transform t, string indent)
{
if ((Object)(object)t == (Object)null)
{
return;
}
string text = "";
Component[] components = ((Component)t).GetComponents<Component>();
for (int i = 0; i < components.Length; i++)
{
if ((Object)(object)components[i] != (Object)null)
{
text = text + ((object)components[i]).GetType().Name + " ";
}
}
for (int j = 0; j < t.childCount; j++)
{
PrintHierarchy(t.GetChild(j), indent + " ");
}
}
private static void SetOptionTitle(Transform optionObj, string text)
{
if ((Object)(object)optionObj == (Object)null)
{
return;
}
Transform val = optionObj.Find("Title");
if ((Object)(object)val != (Object)null)
{
LocalizedText component = ((Component)val).GetComponent<LocalizedText>();
if ((Object)(object)component != (Object)null)
{
((Behaviour)component).enabled = false;
}
TMP_Text component2 = ((Component)val).GetComponent<TMP_Text>();
if ((Object)(object)component2 != (Object)null)
{
component2.text = text;
}
return;
}
TMP_Text[] componentsInChildren = ((Component)optionObj).GetComponentsInChildren<TMP_Text>(true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
if (((Object)((Component)componentsInChildren[i]).gameObject).name.IndexOf("Title", StringComparison.OrdinalIgnoreCase) >= 0)
{
componentsInChildren[i].text = text;
break;
}
}
}
private static void SortContainerPreservingSeparators(Transform parent)
{
try
{
if ((Object)(object)parent == (Object)null || parent.childCount <= 1 || ((Object)parent).name.IndexOf("Expedition", StringComparison.OrdinalIgnoreCase) >= 0 || (Object)(object)parent.Find("MiniRun") != (Object)null || (Object)(object)parent.Find("Option_MiniRun") != (Object)null || (Object)(object)parent.Find("MiniRunOptions") != (Object)null)
{
return;
}
for (int i = 0; i < parent.childCount; i++)
{
Transform child = parent.GetChild(i);
if ((Object)(object)child != (Object)null && (((Object)child).name.IndexOf("MiniRun", StringComparison.OrdinalIgnoreCase) >= 0 || ((Object)child).name.IndexOf("Expedition", StringComparison.OrdinalIgnoreCase) >= 0))
{
return;
}
}
List<Transform> list = new List<Transform>();
for (int j = 0; j < parent.childCount; j++)
{
list.Add(parent.GetChild(j));
}
List<List<Transform>> list2 = new List<List<Transform>>();
List<Transform> list3 = new List<Transform>();
for (int k = 0; k < list.Count; k++)
{
Transform val = list[k];
if (!((Object)(object)((Component)val).GetComponent<CustomOptionBase>() != (Object)null))
{
if (list3.Count > 0)
{
list2.Add(list3);
list3 = new List<Transform>();
}
List<Transform> list4 = new List<Transform>();
list4.Add(val);
list2.Add(list4);
}
else
{
list3.Add(val);
}
}
if (list3.Count > 0)
{
list2.Add(list3);
}
for (int l = 0; l < list2.Count; l++)
{
if (list2[l].Count > 1 && (Object)(object)((Component)list2[l][0]).GetComponent<CustomOptionBase>() != (Object)null)
{
list2[l].Sort(delegate(Transform a, Transform b)
{
float optionVisualPixelWidth = GetOptionVisualPixelWidth(a);
int num4 = GetOptionVisualPixelWidth(b).CompareTo(optionVisualPixelWidth);
return (num4 != 0) ? num4 : string.Compare(GetOptionTitleText(a), GetOptionTitleText(b), StringComparison.OrdinalIgnoreCase);
});
}
}
int num = 0;
for (int num2 = 0; num2 < list2.Count; num2++)
{
for (int num3 = 0; num3 < list2[num2].Count; num3++)
{
list2[num2][num3].SetSiblingIndex(num++);
}
}
RectTransform component = ((Component)parent).GetComponent<RectTransform>();
if ((Object)(object)component != (Object)null)
{
LayoutRebuilder.ForceRebuildLayoutImmediate(component);
}
}
catch (Exception ex)
{
RandomCustomRunPlugin.Logger.LogError((object)("Ошибка динамической сортировки: " + ex));
}
}
private static float GetOptionVisualPixelWidth(Transform item)
{
//IL_00a5: 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)
if ((Object)(object)item == (Object)null)
{
return 0f;
}
string text = GetOptionTitleText(item);
if (string.IsNullOrEmpty(text))
{
if (((Object)item).name == "Option_TimeScale")
{
text = "СКОРОСТНОЙ РЕЖИМ (X2)";
}
else if (((Object)item).name == "Option_ChaosItems")
{
text = "ХАОС-ПРЕДМЕТЫ";
}
else if (((Object)item).name == "Option_PetrificationDamage")
{
text = "УРОН ОКАМЕНЕНИЯ";
}
else if (((Object)item).name == "Option_RevivalAllowed")
{
text = "ВОСКРЕШЕНИЕ ИГРОКОВ";
}
}
if (string.IsNullOrEmpty(text))
{
return 0f;
}
TMP_Text componentInChildren = ((Component)item).GetComponentInChildren<TMP_Text>(true);
if ((Object)(object)componentInChildren != (Object)null)
{
Vector2 preferredValues = componentInChildren.GetPreferredValues(text);
if (preferredValues.x > 1f)
{
return preferredValues.x;
}
}
return (float)text.Length * 12f;
}
private static string GetOptionTitleText(Transform item)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Invalid comparison between Unknown and I4
if ((Object)(object)item == (Object)null)
{
return "";
}
bool flag = (int)LocalizedText.CURRENT_LANGUAGE == 7;
if (((Object)item).name == "Option_TimeScale")
{
if (!flag)
{
return "SPEEDY MODE";
}
return "СКОРОСТНОЙ РЕЖИМ";
}
if (((Object)item).name == "Option_ChaosItems")
{
if (!flag)
{
return "CHAOS ITEMS";
}
return "ХАОС-ПРЕДМЕТЫ";
}
if (((Object)item).name == "Option_PetrificationDamage")
{
if (!flag)
{
return "PETRIFY DAMAGE";
}
return "УРОН ОКАМЕНЕНИЯ";
}
if (((Object)item).name == "Option_RevivalAllowed")
{
if (!flag)
{
return "PLAYER REVIVAL";
}
return "ВОСКРЕШЕНИЕ ИГРОКОВ";
}
CustomOptionMulti component = ((Component)item).GetComponent<CustomOptionMulti>();
if ((Object)(object)component != (Object)null && (Object)(object)component.label != (Object)null)
{
TMP_Text component2 = ((Component)component.label).GetComponent<TMP_Text>();
if ((Object)(object)component2 != (Object)null && !string.IsNullOrEmpty(component2.text))
{
return component2.text.Trim();
}
}
CustomOptionItemToggle component3 = ((Component)item).GetComponent<CustomOptionItemToggle>();
if ((Object)(object)component3 != (Object)null)
{
if ((Object)(object)component3.text != (Object)null)
{
TMP_Text component4 = ((Component)component3.text).GetComponent<TMP_Text>();
if ((Object)(object)component4 != (Object)null && !string.IsNullOrEmpty(component4.text))
{
return component4.text.Trim();
}
}
if ((Object)(object)component3.item != (Object)null && component3.item.UIData != null && !string.IsNullOrEmpty(component3.item.UIData.itemName))
{
return component3.item.UIData.itemName.Trim();
}
}
TMP_Text[] componentsInChildren = ((Component)item).GetComponentsInChildren<TMP_Text>(true);
string text = "";
for (int i = 0; i < componentsInChildren.Length; i++)
{
if ((Object)(object)componentsInChildren[i] == (Object)null || ((Object)(object)componentsInChildren[i].transform.parent != (Object)null && ((Object)componentsInChildren[i].transform.parent).name.IndexOf("Tooltip", StringComparison.OrdinalIgnoreCase) >= 0))
{
continue;
}
string text2 = ((componentsInChildren[i].text != null) ? componentsInChildren[i].text.Trim() : "");
switch (text2)
{
case "ВКЛ":
case "ВЫКЛ":
case "ОТКЛ":
case "ВКЛЮЧЕНО":
case "ВЫКЛЮЧЕНО":
case "НИЗКИЙ":
case "НОРМА":
case "ВЫСОКИЙ":
case "МЕДЛЕННО":
case "БЫСТРО":
case "МАЛО":
case "МНОГО":
case "ЛЕГКИЙ":
case "НОРМАЛЬНЫЙ":
case "ON":
case "OFF":
case "DEFAULT":
case "CUSTOM":
case "LOW":
case "NORMAL":
case "HIGH":
case "DISABLED":
case "ENABLED":
continue;
}
if (!text2.StartsWith("SETTING_") && text2.Length > text.Length)
{
text = text2;
}
}
return text;
}
private static void CreateOptionToggle(CustomOptionToggle template, Transform parent, string gameObjectName, string title, SETTINGTYPE settingType)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: 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)
try
{
GameObject val = Object.Instantiate<GameObject>(((Component)template).gameObject, parent, false);
((Object)val).name = gameObjectName;
val.transform.localScale = Vector3.one;
val.SetActive(true);
CustomOptionToggle component = val.GetComponent<CustomOptionToggle>();
if ((Object)(object)component != (Object)null)
{
component.settingType = settingType;
}
LocalizedText componentInChildren = val.GetComponentInChildren<LocalizedText>();
if ((Object)(object)componentInChildren != (Object)null)
{
Object.DestroyImmediate((Object)(object)componentInChildren);
}
TMP_Text componentInChildren2 = val.GetComponentInChildren<TMP_Text>();
if ((Object)(object)componentInChildren2 != (Object)null)
{
componentInChildren2.text = title;
}
CustomOptionTooltip component2 = ((Component)template).GetComponent<CustomOptionTooltip>();
CustomOptionTooltip component3 = val.GetComponent<CustomOptionTooltip>();
if ((Object)(object)component3 != (Object)null)
{
if ((Object)(object)component2 != (Object)null && (Object)(object)component2.text != (Object)null)
{
component3.text = component2.text;
}
component3.index = new string[1] { gameObjectName };
}
if ((Object)(object)component != (Object)null)
{
((CustomOptionBase)component).RestoreDefault();
}
}
catch (Exception ex)
{
RandomCustomRunPlugin.Logger.LogError((object)("Ошибка создания переключателя " + title + ": " + ex));
}
}
private static void CreateOptionMulti(CustomOptionMulti template, Transform parent, string gameObjectName, string title, SETTINGTYPE settingType)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: 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)
try
{
GameObject val = Object.Instantiate<GameObject>(((Component)template).gameObject, parent, false);
((Object)val).name = gameObjectName;
val.transform.localScale = Vector3.one;
val.SetActive(true);
CustomOptionMulti component = val.GetComponent<CustomOptionMulti>();
if (!((Object)(object)component != (Object)null))
{
return;
}
component.settingType = settingType;
if (template.labels != null)
{
component.labels = (string[])template.labels.Clone();
}
if ((Object)(object)component.label != (Object)null)
{
((Behaviour)component.label).enabled = false;
TMP_Text component2 = ((Component)component.label).GetComponent<TMP_Text>();
if ((Object)(object)component2 != (Object)null)
{
component2.text = title;
}
}
CustomOptionTooltip component3 = val.GetComponent<CustomOptionTooltip>();
if ((Object)(object)component3 != (Object)null)
{
Object.DestroyImmediate((Object)(object)component3);
}
((CustomOptionBase)component).RestoreDefault();
}
catch (Exception ex)
{
RandomCustomRunPlugin.Logger.LogError((object)("Ошибка создания переключателя " + title + ": " + ex));
}
}
}
[HarmonyPatch(typeof(LocalizedText), "RefreshAllText")]
public static class LocalizedTextRefreshAllPatch
{
public static void Postfix()
{
try
{
CustomOptionsWindow[] array = Object.FindObjectsOfType<CustomOptionsWindow>();
for (int i = 0; i < array.Length; i++)
{
if ((Object)(object)array[i] != (Object)null && ((Component)array[i]).gameObject.activeInHierarchy)
{
CustomOptionsWindowPatch.SetupButtons(array[i]);
}
}
}
catch
{
}
}
}