using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DiskCardGame;
using GBC;
using HarmonyLib;
using MoreSliderPuzzles.Util;
using Pixelplacement;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("MoreSliderPuzzles")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("This mod for Inscryption adds more slider puzzles to the GBC section of the game.")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1.0")]
[assembly: AssemblyProduct("MoreSliderPuzzles")]
[assembly: AssemblyTitle("MoreSliderPuzzles")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
namespace MoreSliderPuzzles
{
[BepInPlugin("rageleague.inscryption.moresliderpuzzles", "MoreSliderPuzzles", "1.0.1.0")]
public class Plugin : BaseUnityPlugin
{
public const string PluginGuid = "rageleague.inscryption.moresliderpuzzles";
public const string PluginName = "MoreSliderPuzzles";
public const string PluginVersion = "1.0.1.0";
internal static ManualLogSource Log;
public static ConfigEntry<bool> Randomized;
public void Awake()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded MoreSliderPuzzles! ");
Log = ((BaseUnityPlugin)this).Logger;
new Harmony("rageleague.inscryption.moresliderpuzzles").PatchAll();
Randomized = ((BaseUnityPlugin)this).Config.Bind<bool>("RageLeague.SliderPuzzlesAPI", "Should Puzzles Be Randomized?", true, "Should the Loaded Puzzles order in game be Randomized?");
if (Randomized == null)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Has the Config Been Made?");
}
}
public void Start()
{
Log.LogDebug((object)"APIPlugin Start() begin");
Log.LogDebug((object)"APIPlugin Start() end");
}
public void OnEnable()
{
SceneManager.sceneLoaded += OnSceneLoaded;
}
public void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
}
}
}
namespace MoreSliderPuzzles.Util
{
public static class ContainersMod
{
public static Dictionary<Tuple<string, int>, int> max_open_times = new Dictionary<Tuple<string, int>, int>();
public static int MaxOpenTimes(string scene, int id)
{
if (max_open_times.TryGetValue(new Tuple<string, int>(scene, id), out var value))
{
return value;
}
return 1;
}
public static void AddOpenTimes(string scene, int id, int max_time)
{
max_open_times.Add(new Tuple<string, int>(scene, id), max_time);
}
public static void AddInfiniteOpenTimes(string scene, int id)
{
AddOpenTimes(scene, id, -1);
}
}
public static class SliderPuzzleLoader
{
public static List<SliderPuzzleInfo> LoadAllPuzzles()
{
List<SliderPuzzleInfo> list = new List<SliderPuzzleInfo>();
foreach (string item in Directory.EnumerateFiles(Paths.PluginPath, "*.pdef", SearchOption.AllDirectories))
{
if (!item.EndsWith("_example.pdef") && item != null)
{
string puzzleDef = File.ReadAllText(item);
try
{
list.Add(SliderPuzzleUtil.ConvertToPuzzle(puzzleDef));
Console.Write("Loaded " + item + " puzlle");
}
catch
{
}
}
}
if (Plugin.Randomized.Value)
{
Random random = new Random();
int num = list.Count;
while (num > 1)
{
num--;
int index = random.Next(num + 1);
SliderPuzzleInfo value = list[index];
list[index] = list[num];
list[num] = value;
}
return list;
}
return list;
}
}
public static class SliderPuzzleUtil
{
public static SliderPuzzleInfo ConvertToPuzzle(string[,] puzzleDef)
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Expected O, but got Unknown
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
SliderPuzzleInfo val = ScriptableObject.CreateInstance<SliderPuzzleInfo>();
for (int i = 0; i < puzzleDef.GetLength(0); i++)
{
for (int j = 0; j < puzzleDef.GetLength(1); j++)
{
if (val.tracks[j] == null)
{
val.tracks[j] = new Track();
}
if (val.tracks[j].sliders[i] == null)
{
val.tracks[j].sliders[i] = new Slider();
}
if (puzzleDef[i, j] == null || puzzleDef[i, j].Length == 0)
{
val.tracks[j].sliders[i].empty = true;
val.tracks[j].sliders[i].positionLocked = false;
val.tracks[j].sliders[i].cardInfo = null;
continue;
}
val.tracks[j].sliders[i].empty = false;
if (puzzleDef[i, j][0] == '!')
{
val.tracks[j].sliders[i].positionLocked = true;
val.tracks[j].sliders[i].cardInfo = CardLoader.GetCardByName(puzzleDef[i, j].Substring(1));
}
else
{
val.tracks[j].sliders[i].positionLocked = false;
val.tracks[j].sliders[i].cardInfo = CardLoader.GetCardByName(puzzleDef[i, j]);
}
}
}
return val;
}
public static string[,] ToStringMatrix(string source, int rows, int cols)
{
string[,] array = new string[rows, cols];
string[] array2 = source.Split(new char[1] { '\n' });
int num = 0;
string[] array3 = array2;
for (int i = 0; i < array3.Length; i++)
{
string[] array4 = array3[i].Split(new char[1] { '|' });
if (array4.Length == 1)
{
continue;
}
int num2 = 0;
string[] array5 = array4;
for (int j = 0; j < array5.Length; j++)
{
string text = array5[j].Trim();
array[num, num2] = text;
num2++;
if (num2 >= cols)
{
break;
}
}
num++;
if (num >= rows)
{
break;
}
}
return array;
}
public static SliderPuzzleInfo ConvertToPuzzle(string puzzleDef)
{
return ConvertToPuzzle(ToStringMatrix(puzzleDef, 4, 4));
}
}
}
namespace MoreSliderPuzzles.Patches
{
[HarmonyPatch(typeof(ContainerVolume), "SetOpen")]
public class ContainerVolume_MultiOpen
{
public static bool Prefix(bool open, bool immediate, ContainerVolume __instance)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: 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_0107: Unknown result type (might be due to invalid IL or missing references)
if (open == __instance.Open)
{
return true;
}
if (open)
{
Scene activeScene = SceneManager.GetActiveScene();
string name = ((Scene)(ref activeScene)).name;
int saveId = __instance.saveState.saveId;
if (ContainersMod.MaxOpenTimes(name, saveId) != 1)
{
Plugin.Log.LogDebug((object)$"Found entry for: {name}/{__instance.saveState.saveId}");
int num = ContainersMod.MaxOpenTimes(name, saveId);
Plugin.Log.LogDebug((object)$"Max open times: {num}");
ObjectStateData state = __instance.saveState.State;
if (num == -1 || state.intVal < num - 1)
{
state.intVal++;
Plugin.Log.LogDebug((object)$"Current open times: {state.intVal}");
if (!immediate)
{
AudioController.Instance.PlaySound2D("crunch_short#1", (MixerGroup)0, 0.35f, 0f, (Pitch)null, (Repetition)null, (Randomization)null, (Distortion)null, false);
Tween.Shake(((Component)__instance.containerRenderer).transform, Vector3.zero, Vector2.op_Implicit(__instance.shakeIntensity), __instance.shakeDuration, 0f, (LoopType)0, (Action)null, (Action)null, true);
}
return false;
}
Plugin.Log.LogDebug((object)"Open as normal");
return true;
}
return true;
}
return true;
}
}
[HarmonyPatch(typeof(SliderPuzzleContainer), "OnPlayerInput")]
public static class SliderPuzzleContainer_OnPlayerInput
{
public static List<SliderPuzzleInfo> loadedPuzzles;
public static string overrideSceneId = "GBC_Temple_Nature";
public static int overrideSaveId = 34565083;
public static void Prefix(SliderPuzzleContainer __instance, out SliderPuzzleInfo __state)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
Scene activeScene = SceneManager.GetActiveScene();
string name = ((Scene)(ref activeScene)).name;
int saveId = ((ContainerVolume)__instance).saveState.saveId;
__state = __instance.puzzleInfo;
if (!(name == overrideSceneId) || saveId != overrideSaveId)
{
return;
}
if (loadedPuzzles == null)
{
loadedPuzzles = SliderPuzzleLoader.LoadAllPuzzles();
if (loadedPuzzles.Count > 0)
{
ContainersMod.AddOpenTimes(overrideSceneId, overrideSaveId, loadedPuzzles.Count);
}
}
if (loadedPuzzles.Count > 0)
{
__instance.puzzleInfo = loadedPuzzles[((ContainerVolume)__instance).saveState.State.intVal % loadedPuzzles.Count];
}
}
public static void Postfix(SliderPuzzleContainer __instance, SliderPuzzleInfo __state)
{
__instance.puzzleInfo = __state;
Plugin.Log.LogDebug((object)$"Source object: {((Component)__instance).gameObject}");
Plugin.Log.LogDebug((object)$"Save ID: {((ContainerVolume)__instance).saveState.saveId}");
}
}
}