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.Text;
using BepInEx;
using BepInEx.Logging;
using Bunburrows;
using Bunject.Internal;
using Bunject.Monitoring;
using Characters.Bunny.Data;
using Levels;
using Newtonsoft.Json;
using Tiling.Behaviour;
using UnityEngine;
using UnityEngine.Tilemaps;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace Bunject.Difficulty;
public class CoreDifficultyTable
{
private const string FileName = "CoreDifficulty.json";
private readonly Dictionary<string, int> table;
private CoreDifficultyTable(Dictionary<string, int> table)
{
this.table = table;
}
public int Get(LevelIdentity identity)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: 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)
if (!table.TryGetValue($"{BunburrowExtension.ToIndicator(identity.Bunburrow)}-{identity.Depth}", out var value))
{
return 0;
}
return value;
}
public static CoreDifficultyTable Load(ManualLogSource log)
{
string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "CoreDifficulty.json");
try
{
if (!File.Exists(text))
{
log.LogWarning((object)("No CoreDifficulty.json found at " + text + "; core levels will show no difficulty."));
return Empty();
}
Dictionary<string, int> dictionary = JsonConvert.DeserializeObject<Dictionary<string, int>>(File.ReadAllText(text));
if (dictionary == null)
{
return Empty();
}
log.LogInfo((object)("Loaded core difficulty table from " + text));
return new CoreDifficultyTable(new Dictionary<string, int>(dictionary, StringComparer.OrdinalIgnoreCase));
}
catch (Exception ex)
{
log.LogError((object)("Failed to load core difficulty table: " + ex));
return Empty();
}
}
private static CoreDifficultyTable Empty()
{
return new CoreDifficultyTable(new Dictionary<string, int>());
}
}
[BepInPlugin("sergedev.bunject.difficulty", "Bunject Difficulty", "1.3.2")]
public class DifficultyPlugin : BaseUnityPlugin, IMonitor, IBunjectorPlugin
{
public const string pluginGuid = "sergedev.bunject.difficulty";
public const string pluginName = "Bunject Difficulty";
public const string pluginVersion = "1.3.2";
private CoreDifficultyTable coreTable;
public void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Bunject Difficulty Plugin Awakened. v1.3.2");
coreTable = CoreDifficultyTable.Load(((BaseUnityPlugin)this).Logger);
BunjectAPI.RegisterPlugin((IBunjectorPlugin)(object)this);
}
public void OnAssetsLoaded()
{
}
public void OnProgressionLoaded(GeneralProgression progression)
{
}
public LevelObject OnLevelLoad(LevelObject level, LevelIdentity identity)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: 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)
if ((Object)(object)level != (Object)null && CustomBunburrowExtension.IsCoreBunburrow(identity.Bunburrow) && LevelDifficultyExtensions.GetDifficulty(level) == 0)
{
LevelDifficultyExtensions.SetDifficulty(level, (int?)coreTable.Get(identity));
}
return level;
}
public string OnLevelTitle(string title, LevelIdentity identity, bool useWhite)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
if (identity.Depth <= 0)
{
return title;
}
if ((Object)(object)GameManager.ElevatorController != (Object)null && GameManager.ElevatorController.IsElevating)
{
return title;
}
Level currentLevel = GameManager.CurrentLevel;
int? obj;
if (currentLevel == null)
{
obj = null;
}
else
{
LevelObject baseData = currentLevel.BaseData;
obj = ((baseData != null) ? new int?(LevelDifficultyExtensions.GetDifficulty(baseData)) : ((int?)null));
}
int? num = obj;
int valueOrDefault = num.GetValueOrDefault();
if (valueOrDefault <= 0)
{
return title;
}
return title + "\n" + DifficultyStars.Render(valueOrDefault);
}
public LevelsList LoadEmergencyLevelsList(LevelsList original)
{
return original;
}
public void OnBunnyCapture(BunnyIdentity bunnyIdentity, bool wasHomeCapture)
{
}
public void OnMainMenu()
{
}
public void OnShowCredits()
{
}
public void OnPowerTile(PowerUnlockTile tile, LevelIdentity identity, Action dismiss)
{
}
public bool TryResolvePowerTileSprite(PowerUnlockTile tile, LevelIdentity identity, out TileBase sprite)
{
sprite = null;
return false;
}
}
public static class DifficultyStars
{
private const char Star = '*';
private const string FilledAlpha = "<alpha=#FF>";
private const string EmptyAlpha = "<alpha=#40>";
public static string Render(int difficulty)
{
int num = 10;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("<alpha=#FF>").Append('*', difficulty);
if (difficulty < num)
{
stringBuilder.Append("<alpha=#40>").Append('*', num - difficulty);
}
stringBuilder.Append("<alpha=#FF>");
return stringBuilder.ToString();
}
}