using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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 HG.Reflection;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using RoR2;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ScrapMe")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ScrapMe")]
[assembly: AssemblyTitle("ScrapMe")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 ScrapMe
{
internal static class Log
{
private static ManualLogSource _logSource;
internal static void Init(ManualLogSource logSource)
{
_logSource = logSource;
}
internal static void Debug(object data)
{
_logSource.LogDebug(data);
}
internal static void Error(object data)
{
_logSource.LogError(data);
}
internal static void Fatal(object data)
{
_logSource.LogFatal(data);
}
internal static void Info(object data)
{
_logSource.LogInfo(data);
}
internal static void Message(object data)
{
_logSource.LogMessage(data);
}
internal static void Warning(object data)
{
_logSource.LogWarning(data);
}
}
[BepInPlugin("not_score.ScrapMe", "ScrapMe", "0.1.0")]
public class ScrapMe : BaseUnityPlugin
{
internal class ConfigHolder
{
public readonly ConfigEntry<string> charNameTokens = ((BaseUnityPlugin)plugin).Config.Bind<string>("! Main", "Characters to Change", "", "Characters to look for, comma-separated. Must be as name tokens, i.e. COMMANDO_BODY_NAME.");
public readonly Dictionary<string, ConfigEntry<string>> itemBans = new Dictionary<string, ConfigEntry<string>>();
public void BindBody(string body)
{
if (!itemBans.ContainsKey(body))
{
itemBans[body] = ((BaseUnityPlugin)plugin).Config.Bind<string>("Characters", body + "_ItemBans", "", "Items to auto-scrap for " + body + ", comma-separated, using name tokens, i.e. ITEM_HEALINGPOTION_NAME.");
}
}
public void Load()
{
HashSet<string> hashSet = new HashSet<string>(from b in charNameTokens.Value.Split(",")
select b.Trim() into b
where !string.IsNullOrEmpty(b)
select b);
foreach (ConfigEntry<string> value2 in itemBans.Values)
{
if (!hashSet.Contains(((ConfigEntryBase)value2).Definition.Key))
{
((BaseUnityPlugin)plugin).Config.Remove(((ConfigEntryBase)value2).Definition);
plugin.userItemBans.Remove(((ConfigEntryBase)value2).Definition.Key);
}
}
foreach (string item in hashSet)
{
BindBody(item);
HashSet<string> value = new HashSet<string>(from b in itemBans[item].Value.Split(",")
select b.Trim() into b
where !string.IsNullOrEmpty(b)
select b);
plugin.userItemBans[item] = value;
}
}
public void Save()
{
}
}
internal static class RoR2Patches
{
[HarmonyPatch(typeof(GenericPickupController), "AttemptGrant")]
[HarmonyPrefix]
public static void ReplaceWithScrapIfBannedForChar(CharacterBody body, GenericPickupController __instance, bool __runOriginal)
{
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Invalid comparison between Unknown and I4
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_0186: Unknown result type (might be due to invalid IL or missing references)
//IL_0188: Unknown result type (might be due to invalid IL or missing references)
//IL_018a: Unknown result type (might be due to invalid IL or missing references)
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
//IL_01bb: Expected I4, but got Unknown
//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0209: Unknown result type (might be due to invalid IL or missing references)
//IL_0218: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Invalid comparison between Unknown and I4
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Invalid comparison between Unknown and I4
//IL_028f: Unknown result type (might be due to invalid IL or missing references)
//IL_0294: 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)
//IL_0153: Invalid comparison between Unknown and I4
if (!__runOriginal || (Object)(object)__instance == (Object)null || (Object)(object)body == (Object)null || body.baseNameToken == null)
{
return;
}
HashSet<string> hashSet = new HashSet<string>();
if (plugin.devItemBans.TryGetValue(body.baseNameToken, out var value) && value != null)
{
hashSet.UnionWith(value);
}
if (plugin.userItemBans.TryGetValue(body.baseNameToken, out var value2) && value2 != null)
{
hashSet.UnionWith(value2);
}
if (hashSet.Count == 0)
{
return;
}
UniquePickup pickup = __instance.pickup;
PickupDef pickupDef = PickupCatalog.GetPickupDef(pickup.pickupIndex);
if (pickupDef == null || pickupDef.nameToken == null)
{
return;
}
PickupDef val = null;
if (!hashSet.Contains(pickupDef.nameToken))
{
return;
}
if ((int)pickupDef.itemIndex == -1)
{
if (pickupDef.coinValue == 0 && (int)pickupDef.droneIndex == -1 && (int)pickupDef.artifactIndex == -1 && (int)pickupDef.equipmentIndex == -1)
{
Log.Error("Undefined behavior for pickup " + pickupDef.nameToken);
}
return;
}
ItemTier itemTier = pickupDef.itemTier;
ItemTier val2 = itemTier;
switch ((int)val2)
{
case 0:
case 1:
case 2:
case 4:
val = PickupCatalog.GetPickupDef(PickupCatalog.FindScrapIndexForItemTier(pickupDef.itemTier));
break;
case 3:
val = PickupCatalog.GetPickupDef(PickupCatalog.FindPickupIndex(ItemCatalog.FindItemIndex("Pearl")));
break;
case 6:
val = PickupCatalog.GetPickupDef(PickupCatalog.FindScrapIndexForItemTier((ItemTier)0));
break;
case 7:
val = PickupCatalog.GetPickupDef(PickupCatalog.FindScrapIndexForItemTier((ItemTier)1));
break;
case 8:
val = PickupCatalog.GetPickupDef(PickupCatalog.FindScrapIndexForItemTier((ItemTier)2));
break;
case 9:
val = PickupCatalog.GetPickupDef(PickupCatalog.FindScrapIndexForItemTier((ItemTier)4));
break;
default:
Log.Error("Failed to find appropriate replacement for item " + pickupDef.nameToken);
return;
}
if (val == null)
{
Log.Error("Replacement item for " + pickupDef.nameToken + " resolved null, not replacing");
return;
}
Log.Info("Replacing " + pickupDef.nameToken + " with " + val.nameToken);
__instance.pickup = new UniquePickup(val.pickupIndex);
}
}
public static ScrapMe plugin;
public const string PluginGUID = "not_score.ScrapMe";
public const string PluginAuthor = "not_score";
public const string PluginName = "ScrapMe";
public const string PluginVersion = "0.1.0";
internal ConfigHolder config;
internal Dictionary<string, HashSet<string>> devItemBans = new Dictionary<string, HashSet<string>>();
internal Dictionary<string, HashSet<string>> userItemBans = new Dictionary<string, HashSet<string>>();
internal void Awake()
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Expected O, but got Unknown
plugin = this;
Log.Init(((BaseUnityPlugin)this).Logger);
Harmony val = new Harmony("not_score.ScrapMe");
val.PatchAll(typeof(RoR2Patches));
config = new ConfigHolder();
config.Load();
}
public HashSet<string> GetBans(string bodyNameToken)
{
if (!devItemBans.ContainsKey(bodyNameToken))
{
devItemBans[bodyNameToken] = new HashSet<string>();
}
return devItemBans[bodyNameToken];
}
public void SetBans(string bodyNameToken, HashSet<string> bans)
{
devItemBans[bodyNameToken] = bans;
}
internal void Start()
{
}
}
}