Decompiled source of Bunject Difficulty v1.3.2

Bunject.Difficulty.Contracts.dll

Decompiled 12 minutes ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Bunject.Levels;
using Levels;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Bunject.Difficulty.Contracts")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+0eddd3790f0056a92947bfc95a9e9166555bfa48")]
[assembly: AssemblyProduct("Bunject.Difficulty.Contracts")]
[assembly: AssemblyTitle("Bunject.Difficulty.Contracts")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Bunject.Difficulty;

public static class LevelDifficultyExtensions
{
	public const int MaxDifficulty = 10;

	private const string PropertyKey = "sergedev.bunject.difficulty";

	public static void SetDifficulty(this LevelObject level, int? difficulty)
	{
		LevelProperties.SetProperty(level, "sergedev.bunject.difficulty", (object)Math.Max(0, Math.Min(10, difficulty.GetValueOrDefault())));
	}

	public static int GetDifficulty(this LevelObject level)
	{
		int result = default(int);
		if (!LevelProperties.TryGetProperty<int>(level, "sergedev.bunject.difficulty", ref result))
		{
			return 0;
		}
		return result;
	}
}

Bunject.Difficulty.dll

Decompiled 12 minutes ago
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();
	}
}