Decompiled source of TrophyDropChance v1.0.1

TrophyDropChance.dll

Decompiled a year ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("TrophyDropChance")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TrophyDropChance")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
namespace TrophyDropChance;

public static class Configs
{
	public class Trophy
	{
		public ConfigEntry<int> ConfigEntry;

		public Drop CharacterDrop;

		public GameObject Prefab;
	}

	public static ConfigFile Config;

	public static List<Trophy> Trophies;

	public static ConfigEntry<bool> LockConfigs;

	public static ConfigurationManagerAttributes IsAdminOnly = new ConfigurationManagerAttributes
	{
		IsAdminOnly = true
	};

	public static void SetupConfigs(ConfigFile config)
	{
		Config = config;
		Trophies = new List<Trophy>();
		LockConfigs = config.Bind<bool>("General", "Lock Configs", false, "Lock the configs, so that the settings are only changed by administrators and synchronized with players.");
		config.SettingChanged += Config_SettingChanged;
	}

	public static ConfigurationManagerAttributes ConfigAttributes()
	{
		return LockConfigs.Value ? IsAdminOnly : null;
	}

	private static void Config_SettingChanged(object sender, SettingChangedEventArgs e)
	{
		TrophyDropChance.UpdateTrophies();
	}
}
[BepInPlugin("TrophyDropChance", "TrophyDropChance", "1.0.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
internal class TrophyDropChance : BaseUnityPlugin
{
	[HarmonyPatch(typeof(ZNetScene), "Awake")]
	public static class ZNetScene_Awake_Patch
	{
		public static void Postfix(ZNetScene __instance)
		{
			CreateTrophies(__instance);
		}
	}

	[HarmonyPatch(typeof(ZNetScene), "OnDestroy")]
	public static class ZNetScene_OnDestroy_Patch
	{
		public static void Postfix(ZNetScene __instance)
		{
			Configs.Trophies.Clear();
		}
	}

	public const string PluginGUID = "TrophyDropChance";

	public const string PluginName = "TrophyDropChance";

	public const string PluginVersion = "1.0.1";

	private static Harmony harmony;

	private void Awake()
	{
		Configs.SetupConfigs(((BaseUnityPlugin)this).Config);
		harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "TrophyDropChance");
	}

	private void OnDestroy()
	{
		Harmony obj = harmony;
		if (obj != null)
		{
			obj.UnpatchSelf();
		}
	}

	private static void CreateTrophies(ZNetScene scene)
	{
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Invalid comparison between Unknown and I4
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Expected O, but got Unknown
		CharacterDrop val = default(CharacterDrop);
		ItemDrop val2 = default(ItemDrop);
		foreach (GameObject prefab in scene.m_prefabs)
		{
			if (!prefab.TryGetComponent<CharacterDrop>(ref val))
			{
				continue;
			}
			foreach (Drop drop in val.m_drops)
			{
				if (drop.m_prefab.TryGetComponent<ItemDrop>(ref val2) && (int)val2.m_itemData.m_shared.m_itemType == 13)
				{
					Configs.Trophy trophy = new Configs.Trophy();
					trophy.ConfigEntry = Configs.Config.Bind<int>("Trophies (drop in percentage)", ((Object)((Component)val2).gameObject).name, Mathf.RoundToInt(drop.m_chance * 100f), new ConfigDescription("Chance, in percentage, to drop the given trophy.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), new object[1] { Configs.LockConfigs }));
					trophy.CharacterDrop = drop;
					trophy.Prefab = prefab;
					Configs.Trophy item = trophy;
					Configs.Trophies.Add(item);
				}
			}
		}
		UpdateTrophies();
	}

	public static void UpdateTrophies()
	{
		if (!((Object)(object)ZNetScene.instance != (Object)null))
		{
			return;
		}
		foreach (Configs.Trophy trophy in Configs.Trophies)
		{
			trophy.CharacterDrop.m_chance = (float)trophy.ConfigEntry.Value / 100f;
		}
	}
}