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.Bootstrap; using BepInEx.Logging; using Microsoft.CodeAnalysis; using RunConfigAPI.Capabilities; using RunConfigAPI.Common; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("dev.kirsho.RunConfigAPI")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("dev.kirsho.RunConfigAPI")] [assembly: AssemblyTitle("RunConfigAPI")] [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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [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 BepInEx { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [Conditional("CodeGeneration")] internal sealed class BepInAutoPluginAttribute : Attribute { public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null) { } } } namespace BepInEx.Preloader.Core.Patching { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [Conditional("CodeGeneration")] internal sealed class PatcherAutoPluginAttribute : Attribute { public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null) { } } } namespace RunConfigAPI { public static class CapabilityRegistry { private static readonly Dictionary _capabilities = new Dictionary(); public static void Register(string guid, IConfigCapability capability) { if (_capabilities.ContainsKey(guid)) { Plugin.Logger.LogWarning((object)("Overriding capabilities for " + guid)); } _capabilities[guid] = capability; } public static IEnumerable GetAll() where T : IConfigCapability { return _capabilities.Values.OfType(); } public static T GetSingle() where T : IConfigCapability { return GetAll().FirstOrDefault(); } } public interface IPriority { int GetPriority(); } public enum Priority { First = 100, VeryHigh = 200, High = 400, HigherThanNormal = 500, Normal = 600, LowerThanNormal = 700, Low = 800, VeryLow = 900, Last = 1000 } [BepInPlugin("dev.kirsho.RunConfigAPI", "RunConfigAPI", "1.0.0")] public class Plugin : BaseUnityPlugin { public const string Id = "dev.kirsho.RunConfigAPI"; internal static ManualLogSource Logger { get; private set; } public static string Name => "RunConfigAPI"; public static string Version => "1.0.0"; private void Awake() { Logger = ((BaseUnityPlugin)this).Logger; RegisterCapabilitiesAutomatically(); Logger.LogInfo((object)("Plugin " + Name + " is loaded!")); } private static void RegisterCapabilitiesAutomatically() { foreach (PluginInfo value in Chainloader.PluginInfos.Values) { if (value.Instance is IConfigCapability capability) { CapabilityRegistry.Register(value.Metadata.GUID, capability); Logger.LogDebug((object)$"Registered {value.Metadata.Name} v{value.Metadata.Version} to registry"); } } } } public static class RunCapabilityApplier { public static void Apply(RunConfig config) { List list = (from x in CapabilityRegistry.GetAll() orderby (x as IPriority)?.GetPriority() ?? 600 select x).ToList(); foreach (IApplyLifecycle item in list) { try { item.BeforeApply(config); } catch (Exception ex) { Plugin.Logger.LogError((object)("BeforeApply failed: " + ex.Message)); } } ApplyTerrainConfig(config); ApplyLootConfig(config); foreach (IApplyLifecycle item2 in list) { try { item2.AfterApply(config); } catch (Exception ex2) { Plugin.Logger.LogError((object)("AfterApply failed: " + ex2.Message)); } } } private static void ApplyTerrainConfig(RunConfig config) { List list = (from x in CapabilityRegistry.GetAll() orderby (x as IPriority)?.GetPriority() ?? 600 select x).ToList(); if (list.Count < 1) { Plugin.Logger.LogWarning((object)"No terrain capability mod is running, proceeding with usual settings."); return; } if (list.Count > 1) { Plugin.Logger.LogWarning((object)"Multiple terrain capability mods are running, applying one with the highest priority"); } ITerrainCapability terrainCapability = list[0]; terrainCapability.SetTerrainSeed(config.Seed); foreach (KeyValuePair item in config.BiomeInformation) { terrainCapability.SetBiomeInfo(item.Key, item.Value); } } private static void ApplyLootConfig(RunConfig config) { List list = (from x in CapabilityRegistry.GetAll() orderby (x as IPriority)?.GetPriority() ?? 600 select x).ToList(); if (list.Count < 1) { Plugin.Logger.LogWarning((object)"No loot capability mod is running, proceeding with usual settings."); return; } if (list.Count > 1) { Plugin.Logger.LogWarning((object)"Multiple loot capability mods are running, applying one with the highest priority"); } ILootCapability lootCapability = list[0]; lootCapability.SetLootSeed(config.Seed); } } public class RunConfig { public int Seed; public Dictionary BiomeInformation = new Dictionary(); } } namespace RunConfigAPI.Common { public class BiomeInfo { public string Name = string.Empty; public string Variant = string.Empty; public BiomeType GetBiomeType() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return TypeFromName(Name); } public static BiomeType TypeFromName(string name) { return (BiomeType)(name switch { "Shore" => 0, "Tropics" => 1, "Alpine" => 2, "Volcano" => 3, "Peak" => 5, "Mesa" => 6, "Roots" => 7, _ => throw new ArgumentException("Unsupported Biome name"), }); } } public enum ShoreVariants { Default, SnakeBeach, RedBeach, BlueBeach, JellyHell, BlackSand } public enum TropicsVariants { Default, Lava, Pillars, Thorny, Bombs, Ivy, SkyJungle } public enum RootsVariants { Default, CaveMania, DeepWater, BombBeetle, DeepWoods, Clearcut } public enum AlpineVariants { Default, Lava, Spiky, GeyserHell } public enum MesaVariants { NoVariant, CactusForest, TumblerHell, TornadoHell, ScorpionsHell, CacusHell, DynamiteHell } } namespace RunConfigAPI.Capabilities { public interface IApplyLifecycle : IConfigCapability { void BeforeApply(RunConfig config) { } void AfterApply(RunConfig config) { } } public interface IConfigCapability { } public interface ILootCapability : IConfigCapability { void SetLootSeed(int seed); } public interface ITerrainCapability : IConfigCapability { void SetTerrainSeed(int seed); void SetBiomeInfo(string section, BiomeInfo info); } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }