using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using IShowSeed.Random;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("IShowSeed")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Seeded runs are now a thing!")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+9d36377ebb462c05c778d4c2cdfb544b390b86e0")]
[assembly: AssemblyProduct("IShowSeed")]
[assembly: AssemblyTitle("IShowSeed")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace IShowSeed
{
[BepInPlugin("shishyando.WK.IShowSeed", "IShowSeed", "1.0.1")]
public class IShowSeedPlugin : BaseUnityPlugin
{
internal static IShowSeedPlugin Instance;
internal static ManualLogSource Beep;
private readonly Harmony Harmony = new Harmony("shishyando.WK.IShowSeed");
internal static int StartingSeed;
internal static ConfigEntry<int> configPresetSeed;
private void Awake()
{
Instance = this;
Beep = ((BaseUnityPlugin)this).Logger;
configPresetSeed = ((BaseUnityPlugin)this).Config.Bind<int>("General", "PresetSeed", 0, "Preset seed to use in all gamemodes, `0` to keep the default behaviour");
Harmony.PatchAll();
SceneManager.sceneLoaded += OnSceneLoaded;
SceneManager.sceneUnloaded += OnSceneUnloaded;
Beep.LogInfo((object)"shishyando.WK.IShowSeed is loaded");
}
private void OnSceneLoaded(Scene s, LoadSceneMode m)
{
if (((Scene)(ref s)).name == "Game-Main")
{
Rod.Enable();
}
}
private void OnSceneUnloaded(Scene s)
{
if (((Scene)(ref s)).name == "Game-Main")
{
Rod.Disable();
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "shishyando.WK.IShowSeed";
public const string PLUGIN_NAME = "IShowSeed";
public const string PLUGIN_VERSION = "1.0.1";
}
}
namespace IShowSeed.UI
{
[HarmonyPatch(typeof(UT_SeededEnable), "OnEnable")]
public static class UT_SeededEnable_OnEnable_Patcher
{
public static bool Prefix(UT_SeededEnable __instance)
{
TextMeshProUGUI component = ((Component)__instance).gameObject.GetComponent<TextMeshProUGUI>();
((TMP_Text)component).text = $"SEED: {IShowSeedPlugin.StartingSeed}";
if (WorldLoader.customSeed)
{
((TMP_Text)component).text = "PRESET " + ((TMP_Text)component).text;
}
return false;
}
}
}
namespace IShowSeed.Random
{
public static class Rod
{
public struct Context
{
public State PrevRandomState;
public string SiteKey;
public int Seed;
public bool Valid;
}
private static readonly object _lock = new object();
private static readonly Dictionary<string, State> _stateBySite = new Dictionary<string, State>();
private static bool _enabled;
internal static void Enter(ref Context ctx)
{
//IL_0041: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
if (_enabled)
{
ctx = default(Context);
ctx.SiteKey = ComputeSiteKey();
ctx.Seed = DeriveSeed(ctx.SiteKey);
Monitor.Enter(_lock);
ctx.PrevRandomState = Random.state;
if (!_stateBySite.ContainsKey(ctx.SiteKey))
{
State state = Random.state;
Random.InitState(ctx.Seed);
State state2 = Random.state;
Random.state = state;
_stateBySite[ctx.SiteKey] = state2;
}
Random.state = _stateBySite[ctx.SiteKey];
ctx.Valid = true;
}
}
internal static void Exit(in Context ctx)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
if (_enabled && ctx.Valid)
{
State state = Random.state;
if (ctx.SiteKey == null)
{
IShowSeedPlugin.Beep.LogError((object)("SiteKey is null, " + GetStackTraceStr(0)));
return;
}
_stateBySite[ctx.SiteKey] = state;
Random.state = ctx.PrevRandomState;
Monitor.Exit(_lock);
}
}
private static string ComputeSiteKey()
{
return GetStackTraceStr(2);
}
private static int DeriveSeed(string siteKey)
{
return Animator.StringToHash(siteKey) ^ IShowSeedPlugin.StartingSeed;
}
internal static void Enable()
{
IShowSeedPlugin.Beep.LogWarning((object)"\n===========================\n\n\n eeeeeNNANABBLLELEE \n\n\n===========================\n");
Monitor.Enter(_lock);
_enabled = true;
_stateBySite.Clear();
Monitor.Exit(_lock);
}
internal static void Disable()
{
IShowSeedPlugin.Beep.LogWarning((object)"\n===========================\n\n\n dissable \n\n\n===========================\n");
Monitor.Enter(_lock);
_enabled = false;
_stateBySite.Clear();
Monitor.Exit(_lock);
}
internal static void Reset()
{
IShowSeedPlugin.Beep.LogWarning((object)"\n===========================\n\n\n reset RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRReset \n\n\n===========================\n");
Monitor.Enter(_lock);
_stateBySite.Clear();
Monitor.Exit(_lock);
}
private static string GetStackTraceStr(int frames)
{
StackTrace stackTrace = new StackTrace(frames);
return string.Join(" ==> ", stackTrace.GetFrames().Select(delegate(StackFrame f)
{
MethodBase method = f.GetMethod();
Type declaringType = method.DeclaringType;
return (declaringType == null) ? "" : (declaringType.FullName + "." + method.Name);
}));
}
}
}
namespace IShowSeed.Patches
{
[HarmonyPatch(typeof(App_PerkPage), "GenerateCards")]
public static class App_PerkPage_GenerateCards_Patcher
{
private static readonly FieldRef<App_PerkPage, OS_Manager> osRef = (FieldRef<App_PerkPage, OS_Manager>)(object)AccessTools.FieldRefAccess<OS_Manager>(typeof(App_PerkPage), "os");
public static void Prefix(ref Rod.Context __state, App_PerkPage __instance)
{
Rod.Enter(ref __state);
osRef.Invoke(__instance).worldInterface.SetSeed(-1);
}
public static void Postfix(ref Rod.Context __state, App_PerkPage __instance)
{
osRef.Invoke(__instance).worldInterface.SetSeed(__state.Seed);
Rod.Exit(in __state);
}
}
[HarmonyPatch(typeof(CL_EventManager), "GetPossibleEvents")]
public static class SpawnSettings_GetPossibleEvents_Patcher
{
[HarmonyPostfix]
public static void Postfix(ref List<SessionEvent> __result)
{
__result?.RemoveAll((SessionEvent x) => (int)x.startCheck == 3);
}
}
[HarmonyPatch(typeof(ENV_ArtifactDevice), "Start")]
public static class ENV_ArtifactDevice_Start_Patcher
{
public static void Prefix(ref Rod.Context __state)
{
Rod.Enter(ref __state);
}
public static void Postfix(ref Rod.Context __state)
{
Rod.Exit(in __state);
}
}
[HarmonyPatch(typeof(ENV_VendingMachine), "GenerateOptions")]
public static class ENV_VendingMachine_GenerateOptions_Patcher
{
private static readonly FieldRef<ENV_VendingMachine, int> localSeedRef = AccessTools.FieldRefAccess<ENV_VendingMachine, int>("localSeed");
public static void Prefix(ref Rod.Context __state, ENV_VendingMachine __instance)
{
Rod.Enter(ref __state);
localSeedRef.Invoke(__instance) = __state.Seed;
}
public static void Postfix(ref Rod.Context __state)
{
Rod.Exit(in __state);
}
}
[HarmonyPatch(typeof(ENV_VendingMachine), "SetSeed")]
public static class ENV_VendingMachine_SetSeed_Patcher
{
public static bool Prefix()
{
return false;
}
}
[HarmonyPatch(typeof(M_Level), "Awake")]
public static class M_Level_Awake_Patcher
{
public static void Prefix(M_Level __instance)
{
__instance.canFlip = false;
}
}
[HarmonyPatch(typeof(OS_Computer_Interface), "SetSeed")]
public static class OS_Computer_Interface_SetSeed_Patcher
{
public static bool Prefix()
{
return false;
}
}
[HarmonyPatch(typeof(SpawnSettings), "RandomCheck")]
public static class SpawnSettings_RandomCheck_Patcher
{
public static bool Prefix(ref Rod.Context __state, ref bool __result, SpawnSettings __instance)
{
float effectiveSpawnChance = __instance.GetEffectiveSpawnChance();
if (effectiveSpawnChance == 0f)
{
__result = false;
return false;
}
if (effectiveSpawnChance == 1f)
{
__result = true;
return false;
}
Rod.Enter(ref __state);
return true;
}
public static void Postfix(ref Rod.Context __state)
{
Rod.Exit(in __state);
}
}
[HarmonyPatch(typeof(UT_GameStateController), "RestartScene")]
public static class UT_GameStateController_Start_Patcher
{
public static void Prefix()
{
Rod.Reset();
}
}
[HarmonyPatch(typeof(UT_SpawnChance), "Start")]
public static class UT_SpawnChance_Start_Patcher
{
public static void Prefix(UT_SpawnChance __instance)
{
}
private static string GetPath(Transform t)
{
StringBuilder stringBuilder = new StringBuilder(((Object)t).name);
Transform parent = t.parent;
while ((Object)(object)parent != (Object)null)
{
stringBuilder.Insert(0, ((Object)parent).name + "/");
parent = parent.parent;
}
return stringBuilder.ToString();
}
}
[HarmonyPatch(typeof(WorldLoader), "Awake")]
public static class WorldLoader_Awake_Patcher
{
public static void Prefix()
{
WorldLoader.SetPresetSeed(IShowSeedPlugin.configPresetSeed.Value.ToString());
IShowSeedPlugin.Beep.LogInfo((object)$"custom preset seed: {IShowSeedPlugin.configPresetSeed.Value}");
IShowSeedPlugin.StartingSeed = IShowSeedPlugin.configPresetSeed.Value;
}
}
[HarmonyPatch(typeof(WorldLoader), "Initialize")]
public static class WorldLoader_Initialize_Patcher
{
public static void Prefix()
{
IShowSeedPlugin.Beep.LogInfo((object)$"World initializing with seed: {IShowSeedPlugin.configPresetSeed.Value}, resetting random...");
}
}
}
namespace IShowSeed.Patches.UI
{
[HarmonyPatch(typeof(CL_UIManager), "Update")]
public static class CL_UIManager_Update_Patcher
{
public static void Postfix()
{
DebugMenu.UpdateDebugText("starting-seed", $"<color=blue>Starting seed: {IShowSeedPlugin.StartingSeed}</color>");
}
}
[HarmonyPatch(typeof(MenuManager), "Start")]
public static class MenuManager_Start_Patcher
{
public static void Postfix(MenuManager __instance)
{
GameObject seedWindow = __instance.seedWindow;
TextMeshProUGUI component = ((Component)seedWindow.transform.Find("Overview Titles/Title Text")).gameObject.GetComponent<TextMeshProUGUI>();
TextMeshProUGUI buttonText = ((Component)seedWindow.transform.Find("Tab Selection Hor/Exit/Text (TMP)")).gameObject.GetComponent<TextMeshProUGUI>();
Button component2 = ((Component)seedWindow.transform.Find("Tab Selection Hor/Exit")).gameObject.GetComponent<Button>();
TMP_InputField seedPrompt = ((Component)seedWindow.transform.Find("Seed Input")).gameObject.GetComponent<TMP_InputField>();
TextMeshProUGUI component3 = ((Component)seedWindow.transform.Find("Seed Input/Text Area/Placeholder")).gameObject.GetComponent<TextMeshProUGUI>();
if ((Object)(object)buttonText == (Object)null || (Object)(object)seedPrompt == (Object)null || (Object)(object)component2 == (Object)null || (Object)(object)component == (Object)null || (Object)(object)component3 == (Object)null)
{
IShowSeedPlugin.Beep.LogWarning((object)$"button: {component2}\nbuttonText: {buttonText}\nseedPrompt: {seedPrompt}\ntitle: {component}\nplaceholder {component3}");
}
else
{
PatchTitle(component);
PatchPrompt(seedPrompt, component3);
PatchButton(component2);
}
void PatchButton(Button button)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Expected O, but got Unknown
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Expected O, but got Unknown
((Graphic)buttonText).color = Color.grey;
((TMP_Text)buttonText).text = "Save to Config";
button.onClick = new ButtonClickedEvent();
((UnityEvent)button.onClick).AddListener((UnityAction)delegate
{
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
if (int.TryParse(seedPrompt.text, out var result) || seedPrompt.text == "")
{
IShowSeedPlugin.configPresetSeed.Value = result;
((BaseUnityPlugin)IShowSeedPlugin.Instance).Config.Save();
IShowSeedPlugin.Beep.LogInfo((object)$"Set new seed to {result}");
seedWindow.SetActive(false);
}
else
{
((TMP_Text)buttonText).text = "Invalid seed";
((Graphic)buttonText).color = Color.red;
}
});
}
void PatchPrompt(TMP_InputField prompt, TextMeshProUGUI placeholder)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
prompt.onValueChanged = new OnChangeEvent();
((UnityEvent<string>)(object)prompt.onValueChanged).AddListener((UnityAction<string>)delegate
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
((Graphic)buttonText).color = Color.white;
((TMP_Text)buttonText).text = "Save to Config";
});
prompt.text = IShowSeedPlugin.configPresetSeed.Value.ToString();
if (prompt.text == "0")
{
prompt.text = "";
}
((TMP_Text)placeholder).text = "KEEP RANDOM";
}
static void PatchTitle(TextMeshProUGUI title)
{
((TMP_Text)title).text = "ENTER SEED";
}
}
}
}