using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Assets.Scripts.Inventory__Items__Pickups.Items;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using UnityEngine;
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(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ForceItemRarity")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("This mod allows you to force item rarity and cycle between them. Toggle On/Off key [G] and Cycle between Rarity key [H]. Note it will disable Leaderboard uploading, and you will not get banned while it is disabled.")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("ForceItemRarity")]
[assembly: AssemblyTitle("ForceItemRarity")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.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 ForceItemRarity
{
[BepInPlugin("BedlessSleeper_ForceItemRarity", "ForceItemRarity", "0.1.1")]
public class Plugin : BasePlugin
{
[HarmonyPatch(typeof(SteamLeaderboardsManagerNew), "UploadLeaderboardScore", new Type[]
{
typeof(string),
typeof(int),
typeof(Il2CppStructArray<int>),
typeof(bool)
})]
internal static class DisableSteamLeaderboardUploading
{
private static bool Prefix(string leaderboardName, int score, Il2CppStructArray<int> details, bool isFriendsLb)
{
return false;
}
}
[HarmonyPatch]
public static class GameManager_StartPatch
{
private static MethodBase TargetMethod()
{
Type type = AccessTools.TypeByName("GameManager");
return AccessTools.Method(type, "Start", (Type[])null, (Type[])null);
}
private static void Postfix()
{
gameStarted = true;
}
}
[HarmonyPatch]
public static class GameManager_UpdatePatch
{
private static MethodBase TargetMethod()
{
Type type = AccessTools.TypeByName("GameManager");
return AccessTools.Method(type, "Update", (Type[])null, (Type[])null);
}
private static void Postfix()
{
if (gameStarted)
{
if (Input.GetKeyDown((KeyCode)103))
{
ToggleForce();
}
if (Input.GetKeyDown((KeyCode)104))
{
CycleRarity();
}
}
}
}
[HarmonyPatch]
public static class Rarity_GetItemRarity_ForcePatch
{
private static MethodBase TargetMethod()
{
Type type = AccessTools.TypeByName("Assets.Scripts.Inventory__Items__Pickups.Rarity") ?? AccessTools.TypeByName("Rarity");
return AccessTools.Method(type, "GetItemRarity", new Type[1] { typeof(float) }, (Type[])null);
}
private static bool Prefix(float luck, ref EItemRarity __result)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected I4, but got Unknown
if (!ForceToggle)
{
return true;
}
__result = (EItemRarity)(int)forcedItemRarity;
return false;
}
}
public class RarityGUI : MonoBehaviour
{
private Text textObj;
private Canvas canvas;
private EItemRarity lastRarity = (EItemRarity)(-1);
private bool lastToggle = false;
private bool lastActive = false;
private void Awake()
{
Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
}
private void Start()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("ForcedRarityCanvas");
canvas = val.AddComponent<Canvas>();
canvas.renderMode = (RenderMode)0;
Object.DontDestroyOnLoad((Object)(object)val);
GameObject val2 = new GameObject("ForcedRarityText");
val2.transform.SetParent(val.transform, false);
textObj = val2.AddComponent<Text>();
textObj.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
textObj.alignment = (TextAnchor)6;
textObj.horizontalOverflow = (HorizontalWrapMode)1;
textObj.verticalOverflow = (VerticalWrapMode)1;
Shadow val3 = val2.AddComponent<Shadow>();
val3.effectColor = Color.black;
val3.effectDistance = new Vector2(2f, -2f);
UpdateTextPositionAndSize();
UpdateDisplayText();
((Behaviour)textObj).enabled = false;
}
private void Update()
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
bool gameStarted = Plugin.gameStarted;
if ((Object)(object)textObj != (Object)null)
{
((Behaviour)textObj).enabled = gameStarted;
}
if (gameStarted != lastActive || forcedItemRarity != lastRarity || ForceToggle != lastToggle)
{
UpdateDisplayText();
lastActive = gameStarted;
lastRarity = forcedItemRarity;
lastToggle = ForceToggle;
}
UpdateTextPositionAndSize();
}
public void UpdateDisplayText()
{
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: 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_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Expected I4, but got Unknown
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: 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_014d: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)textObj == (Object)null)
{
return;
}
if (!ForceToggle)
{
textObj.text = "Rarity: Disabled";
((Graphic)textObj).color = Color.gray;
return;
}
EItemRarity forcedItemRarity = Plugin.forcedItemRarity;
string text = ((object)(EItemRarity)(ref forcedItemRarity)).ToString();
textObj.text = "Rarity: (" + text + ")";
EItemRarity forcedItemRarity2 = Plugin.forcedItemRarity;
EItemRarity val = forcedItemRarity2;
switch ((int)val)
{
case 0:
((Graphic)textObj).color = Color32.op_Implicit(new Color32((byte)144, (byte)238, (byte)144, byte.MaxValue));
break;
case 1:
((Graphic)textObj).color = Color32.op_Implicit(new Color32((byte)93, (byte)169, byte.MaxValue, byte.MaxValue));
break;
case 2:
((Graphic)textObj).color = Color32.op_Implicit(new Color32(byte.MaxValue, (byte)69, (byte)69, byte.MaxValue));
break;
case 3:
((Graphic)textObj).color = Color32.op_Implicit(new Color32(byte.MaxValue, (byte)215, (byte)0, byte.MaxValue));
break;
default:
((Graphic)textObj).color = Color.white;
break;
}
}
private void UpdateTextPositionAndSize()
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)textObj == (Object)null))
{
RectTransform rectTransform = ((Graphic)textObj).rectTransform;
rectTransform.anchorMin = new Vector2(0f, 0f);
rectTransform.anchorMax = new Vector2(0f, 0f);
rectTransform.pivot = new Vector2(0f, 0f);
float num = (float)Screen.width * 0.02f;
float num2 = (float)Screen.height * 0.04f;
rectTransform.anchoredPosition = new Vector2(num, num2);
textObj.fontSize = Mathf.RoundToInt((float)Screen.height * 0.022f);
}
}
private void OnDisable()
{
SafeCleanup();
}
private void OnDestroy()
{
SafeCleanup();
}
private void SafeCleanup()
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Expected O, but got Unknown
try
{
if ((Object)(object)rarityGUIRoot != (Object)null)
{
Object.Destroy((Object)(object)rarityGUIRoot);
rarityGUIRoot = null;
}
}
catch (Exception ex)
{
ManualLogSource log = Plugin.log;
if (log != null)
{
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(38, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ForceItemRarity] GUI cleanup failed: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
}
log.LogError(val);
}
}
}
}
public const string MODNAME = "ForceItemRarity";
public const string AUTHOR = "BedlessSleeper";
public const string GUID = "BedlessSleeper_ForceItemRarity";
public const string VERSION = "0.1.1";
public static ManualLogSource log;
public static bool ForceToggle = false;
public static bool gameStarted = false;
private static readonly EItemRarity[] itemRarityCycle;
private static int rarityIndex;
private static GameObject rarityGUIRoot;
public static EItemRarity forcedItemRarity => itemRarityCycle[rarityIndex];
public Plugin()
{
log = ((BasePlugin)this).Log;
}
public override void Load()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
Harmony val = new Harmony("BedlessSleeper_ForceItemRarity");
try
{
ClassInjector.RegisterTypeInIl2Cpp<RarityGUI>();
val.PatchAll();
CreateGUI();
}
catch (Exception ex)
{
ManualLogSource val2 = log;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(31, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Failed to patch or create GUI: ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Exception>(ex);
}
val2.LogError(val3);
}
}
private static void CreateGUI()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
if (!((Object)(object)rarityGUIRoot != (Object)null))
{
rarityGUIRoot = new GameObject("ForceItemRarityGUI");
rarityGUIRoot.AddComponent<RarityGUI>();
Object.DontDestroyOnLoad((Object)(object)rarityGUIRoot);
}
}
public static void ToggleForce()
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
ForceToggle = !ForceToggle;
ManualLogSource val = log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(39, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[ForceItemRarity] Forced rarity system ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ForceToggle ? "ENABLED" : "DISABLED");
}
val.LogInfo(val2);
}
public static void CycleRarity()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
rarityIndex = (rarityIndex + 1) % itemRarityCycle.Length;
ManualLogSource val = log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(43, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[ForceItemRarity] Forced rarity changed -> ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<EItemRarity>(forcedItemRarity);
}
val.LogInfo(val2);
}
static Plugin()
{
EItemRarity[] array = new EItemRarity[4];
RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
itemRarityCycle = (EItemRarity[])(object)array;
rarityIndex = 0;
}
}
}