Some mods may be broken due to the recent Alloyed Collective update.
Decompiled source of AWUChestReward v1.0.2
plugins\AWUChestReward\AWUChestReward.dll
Decompiled 12 months agousing System; using System.Collections; 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 BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using Microsoft.CodeAnalysis; using On.RoR2; using RiskOfOptions; using RiskOfOptions.OptionConfigs; using RiskOfOptions.Options; using RoR2; using RoR2.Hologram; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.Networking; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("AWUChestReward")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+2a76aa911092640961e5cd20176be1f1a43272c5")] [assembly: AssemblyProduct("AWUChestReward")] [assembly: AssemblyTitle("AWUChestReward")] [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 AWUChestReward { [BepInPlugin("Judgy.AWUChestReward", "AWUChestReward", "1.0.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class AWUChestRewardPlugin : BaseUnityPlugin { public const string PluginGUID = "Judgy.AWUChestReward"; public const string PluginAuthor = "Judgy"; public const string PluginName = "AWUChestReward"; public const string PluginVersion = "1.0.2"; private readonly GameObject _chestPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/GoldChest/GoldChest.prefab").WaitForCompletion(); private readonly GameObject _fxPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/LightningStrikeOnHit/SimpleLightningStrikeImpact.prefab").WaitForCompletion(); private float _diffCoefficientStageStart; private GameObject _holderGO; private bool _spawnInProgress; public static string PluginDirectory { get; private set; } public void Awake() { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown PluginDirectory = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); Log.Init(((BaseUnityPlugin)this).Logger); AWUConfig.Init(((BaseUnityPlugin)this).Config); BossGroup.DropRewards += new hook_DropRewards(BossGroup_DropRewards); Stage.Start += new hook_Start(Stage_Start); } private IEnumerator Stage_Start(orig_Start orig, Stage self) { if (Object.op_Implicit((Object)(object)Run.instance)) { _diffCoefficientStageStart = Run.instance.difficultyCoefficient; _holderGO = null; } return orig.Invoke(self); } private void BossGroup_DropRewards(orig_DropRewards orig, BossGroup self) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) if (AWUConfig.Enabled.Value && ((Object)self).name == "SuperRoboBallEncounter") { Scene activeScene = SceneManager.GetActiveScene(); if (((Scene)(ref activeScene)).name == "shipgraveyard") { ((MonoBehaviour)this).StartCoroutine(SpawnCustomRewards()); return; } } orig.Invoke(self); } private IEnumerator SpawnCustomRewards() { if (!NetworkServer.active || !Object.op_Implicit((Object)(object)Run.instance) || Object.op_Implicit((Object)(object)_holderGO) || _spawnInProgress) { yield break; } _spawnInProgress = true; _holderGO = new GameObject("HOLDER: AWU Chests"); _holderGO.transform.position = new Vector3(34.699f, -3.1f, -39.428f); _holderGO.transform.eulerAngles = new Vector3(2.6f, 0f, 0f); int chestCount = 1; if (AWUConfig.ScaleWithPlayerCount.Value) { chestCount = Run.instance.participatingPlayerCount; } float anglePerChest = 360f / (float)chestCount; Vector3 posOffset = new Vector3(4.888f, 0f, -4.892f); int chestCost = ComputeChestCost(); for (int i = 0; i < chestCount; i++) { yield return (object)new WaitForSeconds(0.75f); float num = anglePerChest * (float)i; GameObject val = Object.Instantiate<GameObject>(_chestPrefab, _holderGO.transform); val.transform.localPosition = Quaternion.AngleAxis(num, Vector3.up) * posOffset; val.transform.localEulerAngles = new Vector3(0f, (135f + num) % 360f, 0f); NetworkServer.Spawn(val); val.GetComponent<PurchaseInteraction>().Networkcost = chestCost; if (chestCost == 0) { ((Behaviour)val.GetComponent<HologramProjector>()).enabled = false; } EffectData val2 = new EffectData { origin = val.transform.position }; EffectManager.SpawnEffect(_fxPrefab, val2, true); } _spawnInProgress = false; } private int ComputeChestCost() { return AWUConfig.ChestCostScalingMode.Value switch { AWUConfig.ScalingMode.None => AWUConfig.ChestCost.Value, AWUConfig.ScalingMode.StageStart => Run.instance.GetDifficultyScaledCost(AWUConfig.ChestCost.Value, _diffCoefficientStageStart), AWUConfig.ScalingMode.OnKill => Run.instance.GetDifficultyScaledCost(AWUConfig.ChestCost.Value, Run.instance.difficultyCoefficient), _ => throw new NotImplementedException("ChestCostScalingMode Unknown Value"), }; } } public class AWUConfig { public enum ScalingMode { None, StageStart, OnKill } public static ConfigEntry<bool> Enabled; public static ConfigEntry<int> ChestCost; public static ConfigEntry<ScalingMode> ChestCostScalingMode; public static ConfigEntry<bool> ScaleWithPlayerCount; public static void Init(ConfigFile config) { Enabled = config.Bind<bool>("Configuration", "Enabled", true, "True: mod is enabled and AWU will summon a chest on death.\nFalse: mod is disabled and default behaviour is restored."); ChestCost = config.Bind<int>("Chest Cost", "Base Cost", 0, "Cost of the chest. \nDefault Legendary chest cost is 400.\n0 is free."); ChestCostScalingMode = config.Bind<ScalingMode>("Chest Cost", "Scaling Mode", ScalingMode.StageStart, "Defines how the cost of chest scales :\n- None: Cost doesn't scale at all.\n- StageStart: Cost scales with the difficulty at the start of the stage.\n- OnKill: Cost scales with the difficulty at the time AWU is killed."); ScaleWithPlayerCount = config.Bind<bool>("Multiplayer", "Scale With Player Count", true, "True: spawns one chest for each player.\nFalse: spawns only one chest disregarding the amount of players."); if (RiskOfOptionsCompatibility.Enabled) { RiskOfOptionsCompatibility.AddConfig(); } } } 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); } } internal class RiskOfOptionsCompatibility { private static bool? _enabled; public static bool Enabled { get { bool valueOrDefault = _enabled.GetValueOrDefault(); if (!_enabled.HasValue) { valueOrDefault = Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"); _enabled = valueOrDefault; } return _enabled.Value; } } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] public static void AddConfig() { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Expected O, but got Unknown ModSettingsManager.SetModIcon(LoadIcon()); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(AWUConfig.Enabled)); ModSettingsManager.AddOption((BaseOption)new IntSliderOption(AWUConfig.ChestCost, new IntSliderConfig { min = 0, max = 1000 })); ModSettingsManager.AddOption((BaseOption)new ChoiceOption((ConfigEntryBase)(object)AWUConfig.ChestCostScalingMode)); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(AWUConfig.ScaleWithPlayerCount)); } private static Sprite LoadIcon() { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Expected O, but got Unknown string text = FindIconFilePath(); if (text == null) { return null; } Texture2D val = new Texture2D(256, 256); ImageConversion.LoadImage(val, File.ReadAllBytes(text)); return Sprite.Create(val, new Rect(0f, 0f, 256f, 256f), new Vector2(0f, 0f)); } private static string FindIconFilePath() { DirectoryInfo directoryInfo = new DirectoryInfo(AWUChestRewardPlugin.PluginDirectory); do { FileInfo[] files = directoryInfo.GetFiles("icon.png", SearchOption.TopDirectoryOnly); if (files != null && files.Length != 0) { return files[0].FullName; } directoryInfo = directoryInfo.Parent; } while (directoryInfo != null && !string.Equals(directoryInfo.Name, "plugins", StringComparison.OrdinalIgnoreCase)); return null; } } }