using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;
using Assets.Scripts.Inventory__Items__Pickups.Items;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace RarityForce;
[BepInPlugin("com.worldspawn.rarityforce", "RarityForce", "1.1.0")]
public class Plugin : BasePlugin
{
[HarmonyPatch]
public static class GameManager_StartPatch
{
private static MethodBase TargetMethod()
{
return AccessTools.Method(AccessTools.TypeByName("GameManager"), "Start", (Type[])null, (Type[])null);
}
private static void Postfix()
{
gameStarted = true;
Log.LogDebug((object)"GameManager.Start - game started");
}
}
[HarmonyPatch]
public static class GameManager_UpdatePatch
{
private static Type InputType;
private static Type KeyCodeType;
private static MethodInfo GetKeyDownMethod;
private static MethodInfo GetAxisMethod;
private static float lastScrollValue;
private static MethodBase TargetMethod()
{
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Expected O, but got Unknown
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Expected O, but got Unknown
InputType = AccessTools.TypeByName("UnityEngine.Input");
KeyCodeType = AccessTools.TypeByName("UnityEngine.KeyCode");
bool flag = default(bool);
if (InputType != null && KeyCodeType != null)
{
GetKeyDownMethod = AccessTools.Method(InputType, "GetKeyDown", new Type[1] { KeyCodeType }, (Type[])null);
GetAxisMethod = AccessTools.Method(InputType, "GetAxis", new Type[1] { typeof(string) }, (Type[])null);
if (GetKeyDownMethod != null && GetAxisMethod != null)
{
Log.LogDebug((object)"Input methods found successfully");
}
else
{
ManualLogSource log = Log;
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(51, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failed to find Input methods: GetKeyDown=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<MethodInfo>(GetKeyDownMethod);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", GetAxis=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<MethodInfo>(GetAxisMethod);
}
log.LogError(val);
}
}
else
{
ManualLogSource log2 = Log;
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(46, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failed to find types: InputType=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Type>(InputType);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", KeyCodeType=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Type>(KeyCodeType);
}
log2.LogError(val);
}
return AccessTools.Method(AccessTools.TypeByName("GameManager"), "Update", (Type[])null, (Type[])null);
}
private static void Postfix()
{
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Expected O, but got Unknown
if (!gameStarted || GetKeyDownMethod == null || GetAxisMethod == null)
{
return;
}
try
{
object obj = Enum.ToObject(KeyCodeType, 282);
if ((bool)GetKeyDownMethod.Invoke(null, new object[1] { obj }))
{
ToggleForce();
}
object obj2 = Enum.ToObject(KeyCodeType, 283);
if ((bool)GetKeyDownMethod.Invoke(null, new object[1] { obj2 }))
{
ToggleSounds();
}
float num = (float)GetAxisMethod.Invoke(null, new object[1] { "Mouse ScrollWheel" });
if (num > 0.01f && lastScrollValue <= 0.01f)
{
CycleRarityUp();
}
else if (num < -0.01f && lastScrollValue >= -0.01f)
{
CycleRarityDown();
}
lastScrollValue = num;
}
catch (Exception ex)
{
ManualLogSource log = Log;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(22, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Input handling error: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
}
log.LogError(val);
}
}
}
[HarmonyPatch]
public static class Rarity_GetItemRarity_ForcePatch
{
private static MethodBase TargetMethod()
{
Type type = AccessTools.TypeByName("Assets.Scripts.Inventory__Items__Pickups.Rarity") ?? AccessTools.TypeByName("Rarity");
if (type == null)
{
Log.LogError((object)"Failed to find Rarity class!");
return null;
}
MethodInfo methodInfo = AccessTools.Method(type, "GetItemRarity", new Type[1] { typeof(float) }, (Type[])null);
if (methodInfo == null)
{
Log.LogError((object)"Failed to find GetItemRarity method!");
}
return methodInfo;
}
private static bool Prefix(float luck, ref EItemRarity __result)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected I4, but got Unknown
if (!ForceToggle)
{
return true;
}
__result = (EItemRarity)(int)forcedItemRarity;
return false;
}
}
public const string MODNAME = "RarityForce";
public const string GUID = "com.worldspawn.rarityforce";
public const string VERSION = "1.1.0";
public static ManualLogSource Log;
public static bool ForceToggle = false;
public static bool gameStarted = false;
public static bool soundsEnabled = true;
private static readonly EItemRarity[] itemRarityCycle;
private static int rarityIndex;
public static EItemRarity forcedItemRarity => itemRarityCycle[rarityIndex];
public override void Load()
{
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Expected O, but got Unknown
//IL_0010: 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_002a: Expected O, but got Unknown
Log = ((BasePlugin)this).Log;
bool flag = default(bool);
try
{
new Harmony("com.worldspawn.rarityforce").PatchAll();
ManualLogSource log = Log;
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(23, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("RarityForce");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" v");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.1.0");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded successfully!");
}
log.LogInfo(val);
Log.LogInfo((object)"Controls: [F1] - toggle force, [F2] - toggle sounds, [Mouse Wheel] - cycle rarity");
}
catch (Exception ex)
{
ManualLogSource log2 = Log;
BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(20, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to load mod: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
}
log2.LogError(val2);
}
}
public static void ToggleForce()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
ForceToggle = !ForceToggle;
ManualLogSource log = Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(28, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[RarityForce] Forced rarity ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ForceToggle ? "ENABLED" : "DISABLED");
}
log.LogInfo(val);
if (!soundsEnabled)
{
return;
}
Task.Run(delegate
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Expected O, but got Unknown
try
{
if (ForceToggle)
{
Console.Beep(1000, 100);
}
else
{
Console.Beep(500, 100);
}
}
catch (Exception ex)
{
ManualLogSource log2 = Log;
bool flag2 = default(bool);
BepInExDebugLogInterpolatedStringHandler val2 = new BepInExDebugLogInterpolatedStringHandler(22, 1, ref flag2);
if (flag2)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to play sound: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
}
log2.LogDebug(val2);
}
});
}
public static void ToggleSounds()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
soundsEnabled = !soundsEnabled;
ManualLogSource log = Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(21, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[RarityForce] Sounds ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(soundsEnabled ? "ENABLED" : "DISABLED");
}
log.LogInfo(val);
if (!soundsEnabled)
{
return;
}
Task.Run(delegate
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
try
{
Console.Beep(800, 60);
}
catch (Exception ex)
{
ManualLogSource log2 = Log;
bool flag2 = default(bool);
BepInExDebugLogInterpolatedStringHandler val2 = new BepInExDebugLogInterpolatedStringHandler(22, 1, ref flag2);
if (flag2)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to play sound: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
}
log2.LogDebug(val2);
}
});
}
public static void CycleRarityUp()
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
rarityIndex = (rarityIndex + 1) % itemRarityCycle.Length;
ManualLogSource log = Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(33, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[RarityForce] Rarity changed to: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(GetRarityName(forcedItemRarity));
}
log.LogInfo(val);
PlayRaritySound();
}
public static void CycleRarityDown()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
rarityIndex = (rarityIndex - 1 + itemRarityCycle.Length) % itemRarityCycle.Length;
ManualLogSource log = Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(33, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[RarityForce] Rarity changed to: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(GetRarityName(forcedItemRarity));
}
log.LogInfo(val);
PlayRaritySound();
}
private static void PlayRaritySound()
{
if (!soundsEnabled)
{
return;
}
Task.Run(delegate
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Expected I4, but got Unknown
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Expected O, but got Unknown
try
{
switch ((int)forcedItemRarity)
{
case 0:
Console.Beep(600, 80);
break;
case 1:
Console.Beep(800, 80);
break;
case 2:
Console.Beep(1000, 80);
break;
case 3:
Console.Beep(1200, 80);
Thread.Sleep(50);
Console.Beep(1400, 80);
break;
}
}
catch (Exception ex)
{
ManualLogSource log = Log;
bool flag = default(bool);
BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(22, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failed to play sound: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
log.LogDebug(val);
}
});
}
public static string GetRarityName(EItemRarity rarity)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Expected I4, but got Unknown
return (int)rarity switch
{
0 => "Common",
1 => "Uncommon",
2 => "Rare",
3 => "Legendary",
_ => "Unknown",
};
}
static Plugin()
{
EItemRarity[] array = new EItemRarity[4];
RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
itemRarityCycle = (EItemRarity[])(object)array;
rarityIndex = 0;
}
}