Decompiled source of ItemCensorer v1.0.0

plugins/SillyItemCensor.dll

Decompiled 10 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using On.RoR2;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("SillyItemCensor")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SillyItemCensor")]
[assembly: AssemblyTitle("SillyItemCensor")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace SillyItemCensor;

[BepInPlugin("com.TheTimeSweeper.SillyItemCensor", "SillyItemCensor", "0.1.0")]
public class SillyItemCensorPlugin : BaseUnityPlugin
{
	private static string itemList;

	private string[] censoredItems;

	private Mesh cubeMesh;

	private AssetBundle bundle;

	private Dictionary<string, Sprite> cachedSprites = new Dictionary<string, Sprite>();

	private void Awake()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		ItemCatalog.SetItemDefs += new hook_SetItemDefs(ItemCatalog_SetItemDefs);
		cubeMesh = Addressables.LoadAssetAsync<Mesh>((object)"Decalicious/DecalCube.asset").WaitForCompletion();
		bundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "itemcensorer"));
		ReadConfig();
	}

	private string getItemTierSpriteName(ItemTier tier)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Expected I4, but got Unknown
		ItemTier val = tier;
		ItemTier val2 = val;
		switch ((int)val2)
		{
		case 0:
		case 1:
		case 2:
		case 3:
		case 4:
			return ((object)(ItemTier)(ref tier)).ToString().ToLowerInvariant();
		case 6:
		case 7:
		case 8:
		case 9:
			return "void";
		default:
			return "consumed";
		case 10:
			return "default";
		}
	}

	private Sprite getIconSprite(ItemTier tier)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		string itemTierSpriteName = getItemTierSpriteName(tier);
		if (cachedSprites.ContainsKey(itemTierSpriteName))
		{
			return cachedSprites[itemTierSpriteName];
		}
		return cachedSprites[itemTierSpriteName] = bundle.LoadAsset<Sprite>(itemTierSpriteName);
	}

	private void ReadConfig()
	{
		itemList = ((BaseUnityPlugin)this).Config.Bind<string>("Hello", "CensoredItemsList", "Syringe", "List of Items to be censored, comma separated").Value;
		censoredItems = itemList.Replace(", ", ",").Split(new char[1] { ',' });
	}

	private void ItemCatalog_SetItemDefs(orig_SetItemDefs orig, ItemDef[] newItemDefs)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		foreach (ItemDef val in newItemDefs)
		{
			if (!ItemIsCensored(val))
			{
				continue;
			}
			val.pickupIconSprite = getIconSprite(val.tier);
			if (!((Object)(object)val.pickupModelPrefab == (Object)null))
			{
				SkinnedMeshRenderer[] componentsInChildren = val.pickupModelPrefab.GetComponentsInChildren<SkinnedMeshRenderer>();
				for (int j = 0; j < componentsInChildren.Length; j++)
				{
					componentsInChildren[j].sharedMesh = cubeMesh;
				}
				MeshFilter[] componentsInChildren2 = val.pickupModelPrefab.GetComponentsInChildren<MeshFilter>();
				for (int k = 0; k < componentsInChildren2.Length; k++)
				{
					componentsInChildren2[k].mesh = cubeMesh;
				}
			}
		}
		orig.Invoke(newItemDefs);
	}

	private bool ItemIsCensored(ItemDef itemDef)
	{
		for (int i = 0; i < censoredItems.Length; i++)
		{
			bool flag = false;
			string text = censoredItems[i].ToLowerInvariant();
			if (((Object)itemDef).name.ToLowerInvariant().Contains(text))
			{
				flag = true;
			}
			string text2 = Language.GetString(itemDef.nameToken, "en").ToLowerInvariant();
			if (text2.Contains(text))
			{
				flag = true;
			}
			if (text2.Replace(" ", "").Contains(text.Replace(" ", "")))
			{
				flag = true;
			}
			if (flag)
			{
				((BaseUnityPlugin)this).Logger.LogMessage((object)("Found item for entry " + censoredItems[i] + ", censoring " + ((Object)itemDef).name));
				return true;
			}
		}
		return false;
	}
}