Some mods may be broken due to the recent Alloyed Collective update.
Decompiled source of ArtifactOfPrestige v1.3.4
ArtifactOfPrestige.dll
Decompiled 2 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; 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.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using Microsoft.CodeAnalysis; using Newtonsoft.Json; using On.RoR2; using ProperSave; using R2API; using R2API.Networking; using R2API.Networking.Interfaces; using RiskOfOptions; using RiskOfOptions.OptionConfigs; using RiskOfOptions.Options; using RoR2; using UnityEngine; using UnityEngine.Networking; [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.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("ArtifactOfPrestige")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+34492bbd733e4fad78b7f6aacc013379ea79a352")] [assembly: AssemblyProduct("ArtifactOfPrestige")] [assembly: AssemblyTitle("ArtifactOfPrestige")] [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 ArtifactOfPrestige { internal class Artifact : ArtifactBase { public static ConfigEntry<int> TimesToPrintMessageOnStart; public Color pink = new Color(0.8f, 0.13f, 0.6f, 1f); public override string ArtifactName => "Artifact of Prestige"; public override string ArtifactLangTokenName => "ARTIFACT_OF_PRESTIGE"; public override string ArtifactDescription => "At least one Shrine of the Mountain spawns every stage. Shrine of the Mountain effects are permanent."; public override Sprite ArtifactEnabledIcon => Assets.mainAssetBundle.LoadAsset<Sprite>("enabled.png"); public override Sprite ArtifactDisabledIcon => Assets.mainAssetBundle.LoadAsset<Sprite>("disabled.png"); public override void Init(ConfigFile config) { CreateLang(); CreateArtifact(); Hooks(); } public override void Hooks() { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Expected O, but got Unknown //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Expected O, but got Unknown //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Expected O, but got Unknown Run.onRunStartGlobal += ResetValues; Stage.onStageStartGlobal += SetValues; ShrineBossBehavior.AddShrineStack += new hook_AddShrineStack(UpdateValues); SceneDirector.PopulateScene += new hook_PopulateScene(SpawnShrine); ShrineBossBehavior.Start += new hook_Start(AllowShrineAfterTeleporter); TeleporterInteraction.onTeleporterChargedGlobal += HideLocalIndicators; ShrineBossBehavior.Start += new hook_Start(ShrineMat); TeleporterInteraction.Awake += new hook_Awake(TPMat); if (ProperSaveCompatibility.enabled) { ProperSaveCompatibility.AddEvent(SavePrestigeSettings); } } private void SavePrestigeSettings(Dictionary<string, object> dict) { if (base.ArtifactEnabled) { string value = JsonConvert.SerializeObject((object)new ArtifactOfPrestige_ProperSaveObj()); dict.Add("ArtifactOfPrestigeObj", value); } } private void LoadProperSave() { if (ProperSaveCompatibility.enabled && base.ArtifactEnabled && ProperSaveCompatibility.IsLoading) { string moddedData = ProperSaveCompatibility.GetModdedData("ArtifactOfPrestigeObj"); ArtifactOfPrestige_ProperSaveObj artifactOfPrestige_ProperSaveObj = JsonConvert.DeserializeObject<ArtifactOfPrestige_ProperSaveObj>(moddedData); ArtifactOfPrestige.bonusRewardCount = artifactOfPrestige_ProperSaveObj.bonusRewardCount; ArtifactOfPrestige.shrineBonusStacks = artifactOfPrestige_ProperSaveObj.shrineBonusStacks; ArtifactOfPrestige.NetworkshowExtraBossesIndicator = artifactOfPrestige_ProperSaveObj.NetworkshowExtraBossesIndicator; } } private void UpdateValues(orig_AddShrineStack orig, ShrineBossBehavior self, Interactor interactor) { ArtifactOfPrestige.bonusRewardCount++; ArtifactOfPrestige.NetworkshowExtraBossesIndicator = true; NetMessageExtensions.Send((INetMessage)(object)new SyncAddIndicator(base.ArtifactEnabled), (NetworkDestination)1); orig.Invoke(self, interactor); } private void SetValues(Stage stage) { ArtifactOfPrestige.localIndicators = new List<GameObject>(); ArtifactOfPrestige.offset = 0; if (ArtifactOfPrestige.stackOutsidePrestige.Value && !base.ArtifactEnabled) { ArtifactOfPrestige.shrineBonusStacks = 0; } TeleporterInteraction instance = TeleporterInteraction.instance; if (instance == null || !Object.op_Implicit((Object)(object)instance) || !base.ArtifactEnabled) { return; } TeleporterInteraction instance2 = TeleporterInteraction.instance; if (NetworkServer.active) { instance2.bossGroup.bonusRewardCount = ArtifactOfPrestige.bonusRewardCount; instance2.shrineBonusStacks = ArtifactOfPrestige.shrineBonusStacks; instance2.NetworkshowExtraBossesIndicator = ArtifactOfPrestige.NetworkshowExtraBossesIndicator; } if (ArtifactOfPrestige.shrineBonusStacks > 1 && ArtifactOfPrestige.stackingIndicators.Value) { for (int i = 0; i < ArtifactOfPrestige.shrineBonusStacks - 1; i++) { LocalAddIndicator(); } } } private void ShrineMat(orig_Start orig, ShrineBossBehavior self) { //IL_0056: Unknown result type (might be due to invalid IL or missing references) if ((base.ArtifactEnabled && ArtifactOfPrestige.colouredIndicators.Value) || ArtifactOfPrestige.colouredOutsidePrestige.Value) { MeshRenderer component = ((Component)((Component)self).gameObject.transform.Find("Symbol")).GetComponent<MeshRenderer>(); Material[] materials = ((Renderer)component).materials; materials[0].SetColor("_TintColor", ArtifactOfPrestige.indicatorColor.Value); ((Renderer)component).materials = materials; } orig.Invoke(self); } private void TPMat(orig_Awake orig, TeleporterInteraction self) { //IL_004f: Unknown result type (might be due to invalid IL or missing references) orig.Invoke(self); if ((base.ArtifactEnabled && ArtifactOfPrestige.colouredIndicators.Value) || ArtifactOfPrestige.colouredOutsidePrestige.Value) { MeshRenderer component = self.bossShrineIndicator.GetComponent<MeshRenderer>(); Material[] materials = ((Renderer)component).materials; materials[0].SetColor("_TintColor", ArtifactOfPrestige.indicatorColor.Value); ((Renderer)component).materials = materials; } } private void ResetValues(Run run) { if (base.ArtifactEnabled || ArtifactOfPrestige.stackOutsidePrestige.Value) { ArtifactOfPrestige.ResetValues(); } LoadProperSave(); } private void SpawnShrine(orig_PopulateScene orig, SceneDirector self) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Expected O, but got Unknown //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown if (base.ArtifactEnabled && SceneInfo.instance.countsAsStage && Object.op_Implicit((Object)(object)self.teleporterSpawnCard)) { Xoroshiro128Plus val = new Xoroshiro128Plus(self.rng.nextUlong); DirectorCore.instance.TrySpawnObject(new DirectorSpawnRequest(LegacyResourcesAPI.Load<SpawnCard>("SpawnCards/InteractableSpawnCard/iscShrineBoss"), new DirectorPlacementRule { placementMode = (PlacementMode)4 }, val)); } orig.Invoke(self); } private void HideLocalIndicators(TeleporterInteraction teleporterInteraction) { if (!base.ArtifactEnabled && !ArtifactOfPrestige.stackOutsidePrestige.Value) { return; } foreach (GameObject localIndicator in ArtifactOfPrestige.localIndicators) { localIndicator.SetActive(false); } } private void LocalAddIndicator() { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) TeleporterInteraction instance = TeleporterInteraction.instance; GameObject bossShrineIndicator = instance.bossShrineIndicator; GameObject val = Object.Instantiate<GameObject>(bossShrineIndicator); val.transform.parent = ((Component)instance).gameObject.transform; val.transform.position = bossShrineIndicator.transform.position + new Vector3(0f, (float)(ArtifactOfPrestige.offset + 2), 0f); ArtifactOfPrestige.offset += 2; val.SetActive(true); ArtifactOfPrestige.localIndicators.Add(val); } private void AllowShrineAfterTeleporter(orig_Start orig, ShrineBossBehavior self) { orig.Invoke(self); self.purchaseInteraction.setUnavailableOnTeleporterActivated = !base.ArtifactEnabled; } } public abstract class ArtifactBase { public ArtifactDef ArtifactDef; public abstract string ArtifactName { get; } public abstract string ArtifactLangTokenName { get; } public abstract string ArtifactDescription { get; } public abstract Sprite ArtifactEnabledIcon { get; } public abstract Sprite ArtifactDisabledIcon { get; } public bool ArtifactEnabled => RunArtifactManager.instance.IsArtifactEnabled(ArtifactDef); public abstract void Init(ConfigFile config); protected void CreateLang() { LanguageAPI.Add("ARTIFACT_" + ArtifactLangTokenName + "_NAME", ArtifactName); LanguageAPI.Add("ARTIFACT_" + ArtifactLangTokenName + "_DESCRIPTION", ArtifactDescription); } protected void CreateArtifact() { ArtifactDef = ScriptableObject.CreateInstance<ArtifactDef>(); ArtifactDef.cachedName = "ARTIFACT_" + ArtifactLangTokenName; ArtifactDef.nameToken = "ARTIFACT_" + ArtifactLangTokenName + "_NAME"; ArtifactDef.descriptionToken = "ARTIFACT_" + ArtifactLangTokenName + "_DESCRIPTION"; ArtifactDef.smallIconSelectedSprite = ArtifactEnabledIcon; ArtifactDef.smallIconDeselectedSprite = ArtifactDisabledIcon; ContentAddition.AddArtifactDef(ArtifactDef); } public abstract void Hooks(); } [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInPlugin("Miyowi.ArtifactOfPrestige", "ArtifactOfPrestige", "1.3.4")] public class ArtifactOfPrestige : BaseUnityPlugin { public static ArtifactOfPrestige instance; internal static GameObject CentralNetworkObject; private static GameObject _centralNetworkObjectSpawned; public const string PluginGUID = "Miyowi.ArtifactOfPrestige"; public const string PluginAuthor = "Miyowi"; public const string PluginName = "ArtifactOfPrestige"; public const string PluginVersion = "1.3.4"; public static PluginInfo pluginInfo; public List<ArtifactBase> Artifacts = new List<ArtifactBase>(); public static int bonusRewardCount = 0; public static int shrineBonusStacks = 0; public static int offset = 0; public static bool NetworkshowExtraBossesIndicator = false; public static List<GameObject> localIndicators = new List<GameObject>(); public static ConfigEntry<bool> stackingIndicators { get; set; } public static ConfigEntry<bool> colouredIndicators { get; set; } public static ConfigEntry<Color> indicatorColor { get; set; } public static ConfigEntry<bool> stackOutsidePrestige { get; set; } public static ConfigEntry<bool> colouredOutsidePrestige { get; set; } public void Awake() { //IL_0090: Unknown result type (might be due to invalid IL or missing references) instance = this; pluginInfo = ((BaseUnityPlugin)this).Info; Log.Init(((BaseUnityPlugin)this).Logger); Assets.PopulateAssets(); NetworkingAPI.RegisterMessageType<SyncAddIndicator>(); stackingIndicators = ((BaseUnityPlugin)this).Config.Bind<bool>("Artifact of Prestige", "Stacking Indicators", true, "When more than one Shrine of the Mountain is activated, Shrine of the Mountain indicators stack above each other on the teleporter."); colouredIndicators = ((BaseUnityPlugin)this).Config.Bind<bool>("Artifact of Prestige", "Coloured Indicator", true, "Shrine of the Mountain indicators are coloured differently to normal."); indicatorColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Artifact of Prestige", "Indicator Colour", new Color(0.8f, 0.13f, 0.6f, 1f), "If 'Coloured Indicator' is enabled, the colour that indicators are changed to."); stackOutsidePrestige = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Stacking Indicators Outside Prestige", false, "Stacking Shrine of the Mountain indicators occurs in regular runs. Overrides 'Stacking Indicators'."); colouredOutsidePrestige = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Coloured Indicators Outside Prestige", false, "Shrine of the Mountain indicators are coloured to the value set by 'Indicator Colour' in regular runs. Overrides 'Coloured Indicator'."); if (RiskOfOptionsCompatibility.enabled) { RiskOfOptionsCompatibility.OptionsInit(); } IEnumerable<Type> enumerable = from type in Assembly.GetExecutingAssembly().GetTypes() where !type.IsAbstract && type.IsSubclassOf(typeof(ArtifactBase)) select type; foreach (Type item in enumerable) { ArtifactBase artifactBase = (ArtifactBase)Activator.CreateInstance(item); if (ValidateArtifact(artifactBase, Artifacts)) { artifactBase.Init(((BaseUnityPlugin)this).Config); } } } public static void CheckNetworkObject() { if (NetworkServer.active && !Object.op_Implicit((Object)(object)_centralNetworkObjectSpawned)) { _centralNetworkObjectSpawned = Object.Instantiate<GameObject>(CentralNetworkObject); NetworkServer.Spawn(_centralNetworkObjectSpawned); } } public static void ResetValues() { localIndicators = new List<GameObject>(); bonusRewardCount = 0; shrineBonusStacks = 0; offset = 0; NetworkshowExtraBossesIndicator = false; } public bool ValidateArtifact(ArtifactBase artifact, List<ArtifactBase> artifactList) { bool value = ((BaseUnityPlugin)this).Config.Bind<bool>("Artifact: " + artifact.ArtifactName, "Enable Artifact?", true, "Should this artifact appear for selection?").Value; if (value) { artifactList.Add(artifact); } return value; } } public static class Assets { public static AssetBundle mainAssetBundle = null; internal static string assetBundleName = "artifactofprestigeicons"; internal static string assemblyDir => Path.GetDirectoryName(ArtifactOfPrestige.pluginInfo.Location); public static void PopulateAssets() { mainAssetBundle = AssetBundle.LoadFromFile(Path.Combine(assemblyDir, assetBundleName)); } } public static class RiskOfOptionsCompatibility { private static bool? _enabled; public static bool enabled { get { if (!_enabled.HasValue) { _enabled = Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"); } return _enabled.Value; } } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] public static void OptionsInit() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Expected O, but got Unknown ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ArtifactOfPrestige.stackingIndicators)); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ArtifactOfPrestige.colouredIndicators)); ModSettingsManager.AddOption((BaseOption)new ColorOption(ArtifactOfPrestige.indicatorColor, new ColorOptionConfig())); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ArtifactOfPrestige.stackOutsidePrestige)); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ArtifactOfPrestige.colouredOutsidePrestige)); ModSettingsManager.SetModDescription("Allows customisation of how the artifact affects Shrine of the Mountain visuals, or to enable the visuals even without the artifact because it's kinda cool I think."); Sprite modIcon = Assets.mainAssetBundle.LoadAsset<Sprite>("icon.png"); ModSettingsManager.SetModIcon(modIcon); } } public static class ProperSaveCompatibility { private static bool? _enabled; public static bool enabled { get { if (!_enabled.HasValue) { _enabled = Chainloader.PluginInfos.ContainsKey("com.KingEnderBrine.ProperSave"); } return _enabled.Value; } } public static bool IsLoading { [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] get { return Loading.IsLoading; } } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] public static void AddEvent(Action<Dictionary<string, object>> action) { SaveFile.OnGatherSaveData += action; } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] public static string GetModdedData(string name) { return Loading.CurrentSave.GetModdedData<string>(name); } } public class ArtifactOfPrestige_ProperSaveObj { public int bonusRewardCount; public int shrineBonusStacks; public bool NetworkshowExtraBossesIndicator; public ArtifactOfPrestige_ProperSaveObj() { bonusRewardCount = ArtifactOfPrestige.bonusRewardCount; shrineBonusStacks = ArtifactOfPrestige.shrineBonusStacks; NetworkshowExtraBossesIndicator = ArtifactOfPrestige.NetworkshowExtraBossesIndicator; } } 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); } } public class SyncAddIndicator : INetMessage, ISerializableObject { private bool artifactEnabled; public SyncAddIndicator() { } public SyncAddIndicator(bool artifactEnabled) { this.artifactEnabled = artifactEnabled; } public void Serialize(NetworkWriter writer) { writer.Write(artifactEnabled); } public void Deserialize(NetworkReader reader) { artifactEnabled = reader.ReadBoolean(); } public void OnReceived() { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Invalid comparison between Unknown and I4 //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) if ((artifactEnabled && ArtifactOfPrestige.stackingIndicators.Value) || ArtifactOfPrestige.stackOutsidePrestige.Value) { ArtifactOfPrestige.shrineBonusStacks++; } TeleporterInteraction instance = TeleporterInteraction.instance; if (instance != null && (int)instance.activationState <= 1 && ArtifactOfPrestige.shrineBonusStacks > 1 && ArtifactOfPrestige.stackingIndicators.Value) { TeleporterInteraction instance2 = TeleporterInteraction.instance; GameObject bossShrineIndicator = instance2.bossShrineIndicator; GameObject val = Object.Instantiate<GameObject>(bossShrineIndicator); val.transform.parent = ((Component)instance2).gameObject.transform; val.transform.position = bossShrineIndicator.transform.position + new Vector3(0f, (float)(ArtifactOfPrestige.offset + 2), 0f); ArtifactOfPrestige.offset += 2; val.SetActive(true); ArtifactOfPrestige.localIndicators.Add(val); } } } }