Decompiled source of InsightHeim Season 03 v1.1.1
BepInEx/plugins/StarLevelSystem.dll
Decompiled a week ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Jotunn; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using StarLevelSystem.Data; using StarLevelSystem.common; using StarLevelSystem.modules; using UnityEngine; using UnityEngine.UI; using YamlDotNet.Serialization; using YamlDotNet.Serialization.NamingConventions; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("StarLevelSystem")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("StarLevelSystem")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")] [assembly: AssemblyFileVersion("0.0.8")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.8.0")] namespace StarLevelSystem { internal class ValConfig { [CompilerGenerated] private sealed class <OnClientReceiveColorConfigs>d__42 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public ZPackage package; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <OnClientReceiveColorConfigs>d__42(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { switch (<>1__state) { default: return false; case 0: <>1__state = -1; Colorization.UpdateYamlConfig(package.ReadString()); <>2__current = null; <>1__state = 1; return true; case 1: <>1__state = -1; return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [CompilerGenerated] private sealed class <OnClientReceiveCreatureLootConfigs>d__43 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public ZPackage package; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <OnClientReceiveCreatureLootConfigs>d__43(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { switch (<>1__state) { default: return false; case 0: <>1__state = -1; LootSystemData.UpdateYamlConfig(package.ReadString()); <>2__current = null; <>1__state = 1; return true; case 1: <>1__state = -1; return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [CompilerGenerated] private sealed class <OnClientReceiveLevelConfigs>d__41 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public ZPackage package; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <OnClientReceiveLevelConfigs>d__41(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { switch (<>1__state) { default: return false; case 0: <>1__state = -1; LevelSystemData.UpdateYamlConfig(package.ReadString()); <>2__current = null; <>1__state = 1; return true; case 1: <>1__state = -1; return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [CompilerGenerated] private sealed class <OnServerRecieveConfigs>d__40 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <OnServerRecieveConfigs>d__40(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { switch (<>1__state) { default: return false; case 0: <>1__state = -1; Logger.LogDebug("Server recieved config from client, rejecting due to being the server."); <>2__current = null; <>1__state = 1; return true; case 1: <>1__state = -1; return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } public static ConfigFile cfg; internal static string levelsFilePath = Path.Combine(Paths.ConfigPath, "StarLevelSystem", "LevelSettings.yaml"); internal static string colorsFilePath = Path.Combine(Paths.ConfigPath, "StarLevelSystem", "ColorSettings.yaml"); internal static string creatureLootFilePath = Path.Combine(Paths.ConfigPath, "StarLevelSystem", "CreatureLootSettings.yaml"); private static CustomRPC LevelSettingsRPC; private static CustomRPC ColorSettingsRPC; private static CustomRPC CreatureLootSettingsRPC; public static ConfigEntry<bool> EnableDebugMode; public static ConfigEntry<int> MaxLevel; public static ConfigEntry<bool> EnableCreatureScalingPerLevel; public static ConfigEntry<bool> EnableScalingInDungeons; public static ConfigEntry<float> PerLevelScaleBonus; public static ConfigEntry<float> PerLevelLootScale; public static ConfigEntry<int> LootDropsPerTick; public static ConfigEntry<string> LootDropCaluationType; public static ConfigEntry<float> EnemyHealthMultiplier; public static ConfigEntry<float> BossEnemyHealthMultiplier; public static ConfigEntry<float> EnemyHealthPerWorldLevel; public static ConfigEntry<float> EnemyDamageLevelMultiplier; public static ConfigEntry<float> BossEnemyDamageMultiplier; public static ConfigEntry<bool> EnableScalingBirds; public static ConfigEntry<float> BirdSizeScalePerLevel; public static ConfigEntry<bool> EnableDistanceLevelScalingBonus; public static ConfigEntry<bool> EnableMultiplayerEnemyHealthScaling; public static ConfigEntry<bool> EnableMultiplayerEnemyDamageScaling; public static ConfigEntry<int> MultiplayerScalingRequiredPlayersNearby; public static ConfigEntry<float> MultiplayerEnemyDamageModifier; public static ConfigEntry<float> MultiplayerEnemyHealthModifier; public ValConfig(ConfigFile cf) { cfg = cf; cfg.SaveOnConfigSet = true; CreateConfigValues(cf); } public void SetupConfigRPCs() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown //IL_0027: Expected O, but got Unknown //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Expected O, but got Unknown //IL_0053: Expected O, but got Unknown //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Expected O, but got Unknown //IL_007f: Expected O, but got Unknown LevelSettingsRPC = NetworkManager.Instance.AddRPC("LSE_LevelsRPC", new CoroutineHandler(OnServerRecieveConfigs), new CoroutineHandler(OnClientReceiveLevelConfigs)); ColorSettingsRPC = NetworkManager.Instance.AddRPC("LSE_ColorsRPC", new CoroutineHandler(OnServerRecieveConfigs), new CoroutineHandler(OnClientReceiveColorConfigs)); CreatureLootSettingsRPC = NetworkManager.Instance.AddRPC("LSE_CreatureLootRPC", new CoroutineHandler(OnServerRecieveConfigs), new CoroutineHandler(OnClientReceiveCreatureLootConfigs)); SynchronizationManager.Instance.AddInitialSynchronization(LevelSettingsRPC, (Func<ZPackage>)SendLevelsConfigs); SynchronizationManager.Instance.AddInitialSynchronization(ColorSettingsRPC, (Func<ZPackage>)SendColorsConfigs); SynchronizationManager.Instance.AddInitialSynchronization(CreatureLootSettingsRPC, (Func<ZPackage>)SendCreatureLootConfigs); } private void CreateConfigValues(ConfigFile Config) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown EnableDebugMode = Config.Bind<bool>("Client config", "EnableDebugMode", false, new ConfigDescription("Enables Debug logging.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdvanced = true } })); EnableDebugMode.SettingChanged += Logger.enableDebugLogging; Logger.CheckEnableDebugLogging(); MaxLevel = BindServerConfig("LevelSystem", "MaxLevel", 10, "The Maximum number of stars that a creature can have", advanced: false, 1, 100); EnableCreatureScalingPerLevel = BindServerConfig("LevelSystem", "EnableCreatureScalingPerLevel", value: true, "Enables started creatures to get larger for each star"); EnableDistanceLevelScalingBonus = BindServerConfig("LevelSystem", "EnableDistanceLevelScalingBonus", value: true, "Creatures further away from the center of the world have a higher chance to levelup, this is a bonus applied to existing creature/biome configuration."); PerLevelScaleBonus = BindServerConfig("LevelSystem", "PerLevelScaleBonus", 0.1f, "The additional size that a creature grows each star level.", advanced: true, 0f, 2f); PerLevelScaleBonus.SettingChanged += Colorization.StarLevelScaleChanged; EnableScalingInDungeons = BindServerConfig("LevelSystem", "EnableScalingInDungeons", value: false, "Enables scaling in dungeons, this can cause creatures to become stuck."); EnemyHealthMultiplier = BindServerConfig("LevelSystem", "EnemyHealthMultiplier", 1f, "The amount of health that each level gives a creature, vanilla is 1x. At 2x each creature has double the base health and gains twice as much per level.", advanced: false, 0.01f, 5f); EnemyHealthPerWorldLevel = BindServerConfig("LevelSystem", "EnemyHealthPerWorldLevel", 0.2f, "The percent amount of health that each world level gives a creature, vanilla is 2x (eg 200% more health each world level).", advanced: false, 0f, 2f); EnemyDamageLevelMultiplier = BindServerConfig("LevelSystem", "EnemyDamageLevelMultiplier", 0.1f, "The amount of damage that each level gives a creatures, vanilla is 0.5x (eg 50% more damage each level).", advanced: false, 0f, 2f); BossEnemyHealthMultiplier = BindServerConfig("LevelSystem", "BossEnemyHealthMultiplier", 0.3f, "The amount of health that each level gives a boss. 1 is 100% more health per level.", advanced: false, 0f, 5f); BossEnemyDamageMultiplier = BindServerConfig("LevelSystem", "BossEnemyDamageMultiplier", 0.02f, "The amount of damage that each level gives a boss. 1 is 100% more damage per level.", advanced: false, 0f, 5f); EnableScalingBirds = BindServerConfig("LevelSystem", "EnableScalingBirds", value: true, "Enables birds to scale with the level system. This will cause them to become larger and give more drops."); BirdSizeScalePerLevel = BindServerConfig("LevelSystem", "BirdSizeScalePerLevel", 0.1f, "The amount of size that birds gain per level. 0.1 = 10% larger per level.", advanced: true, 0f, 2f); MultiplayerEnemyDamageModifier = BindServerConfig("Multiplayer", "MultiplayerEnemyDamageModifier", 0.05f, "The additional amount of damage enemies will do to players, when there is a group of players together, per player. .2 = 20%", advanced: true, 0f, 2f); MultiplayerEnemyHealthModifier = BindServerConfig("Multiplayer", "MultiplayerEnemyHealthModifier", 0.2f, "The additional amount of health enemies gain when players are grouped together, per player. .3 = 30%", advanced: true, 0f, 2f); MultiplayerScalingRequiredPlayersNearby = BindServerConfig("Multiplayer", "MultiplayerScalingRequiredPlayersNearby", 3, "The number of players in a local area required to cause monsters to gain bonus health and/or damage.", advanced: true, 0, 10); EnableMultiplayerEnemyHealthScaling = BindServerConfig("Multiplayer", "EnableMultiplayerEnemyHealthScaling", value: true, "Wether or not creatures gain more health when players are grouped up."); EnableMultiplayerEnemyDamageScaling = BindServerConfig("Multiplayer", "EnableMultiplayerEnemyDamageScaling", value: false, "Wether or not creatures gain more damage when players are grouped up."); PerLevelLootScale = BindServerConfig("LootSystem", "PerLevelLootScale", 1f, "The amount of additional loot that a creature provides per each star level", advanced: false, 0f, 4f); LootDropCaluationType = BindServerConfig("LootSystem", "LootDropCaluationType", "PerLevel", "The type of loot calcuation to use. Per Level ", LootLevelsExpanded.AllowedLootFactors); LootDropCaluationType.SettingChanged += LootLevelsExpanded.LootFactorChanged; LootDropsPerTick = BindServerConfig("LootSystem", "LootDropsPerTick", 20, "The number of loot drops that are generated per tick, reducing this will reduce lag when massive amounts of loot is generated at once.", advanced: true, 1, 100); } internal void LoadYamlConfigs() { string[] files = Directory.GetFiles(GetSecondaryConfigDirectoryPath()); bool flag = false; bool flag2 = false; bool flag3 = false; string[] array = files; foreach (string text in array) { if (text.Contains("LevelSettings.yaml")) { Logger.LogDebug("Found level configuration: " + text); levelsFilePath = text; flag = true; } if (text.Contains("ColorSettings.yaml")) { Logger.LogDebug("Found color configuration: " + text); colorsFilePath = text; flag2 = true; } if (text.Contains("LootSettings.yaml")) { Logger.LogDebug("Found loot configuration: " + text); creatureLootFilePath = text; flag3 = true; } } if (!flag3) { Logger.LogDebug("Loot config missing, recreating."); using StreamWriter streamWriter = new StreamWriter(creatureLootFilePath); string value = "#################################################\r\n# Star Level System Expanded - Creature loot configuration\r\n#################################################\r\n"; streamWriter.WriteLine(value); streamWriter.WriteLine(LootSystemData.YamlDefaultConfig()); } if (!flag) { Logger.LogDebug("Level config file missing, recreating."); using StreamWriter streamWriter2 = new StreamWriter(levelsFilePath); string value2 = "#################################################\r\n# Star Level System Expanded - Level Settings\r\n#################################################\r\n"; streamWriter2.WriteLine(value2); streamWriter2.WriteLine(LevelSystemData.YamlDefaultConfig()); } if (!flag2) { Logger.LogDebug("Color config file missing, recreating."); using StreamWriter streamWriter3 = new StreamWriter(colorsFilePath); string value3 = "#################################################\r\n# Star Level System Expanded - Creature Level Color Settings\r\n#################################################\r\n"; streamWriter3.WriteLine(value3); streamWriter3.WriteLine(Colorization.YamlDefaultConfig()); } SetupFileWatcher("ColorSettings.yaml"); SetupFileWatcher("LevelSettings.yaml"); } private void SetupFileWatcher(string filtername) { FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(); fileSystemWatcher.Path = GetSecondaryConfigDirectoryPath(); fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite; fileSystemWatcher.Filter = filtername; fileSystemWatcher.Changed += UpdateConfigFileOnChange; fileSystemWatcher.Created += UpdateConfigFileOnChange; fileSystemWatcher.Renamed += UpdateConfigFileOnChange; fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject; fileSystemWatcher.EnableRaisingEvents = true; } private static void UpdateLevelsOnChange(object sender, FileSystemEventArgs e) { if (!SynchronizationManager.Instance.PlayerIsAdmin) { Logger.LogInfo("Player is not an admin, and not allowed to change local configuration. Ignoring."); } else if (File.Exists(e.FullPath)) { try { LevelSystemData.UpdateYamlConfig(File.ReadAllText(e.FullPath)); LevelSettingsRPC.SendPackage(ZNet.instance.m_peers, SendFileAsZPackage(e.FullPath)); } catch { Logger.LogWarning("Failed to update levels configuration"); } } } private static void UpdateColorsOnChange(object sender, FileSystemEventArgs e) { if (!SynchronizationManager.Instance.PlayerIsAdmin) { Logger.LogInfo("Player is not an admin, and not allowed to change local configuration. Ignoring."); } else if (File.Exists(e.FullPath)) { try { LevelSystemData.UpdateYamlConfig(File.ReadAllText(e.FullPath)); LevelSettingsRPC.SendPackage(ZNet.instance.m_peers, SendFileAsZPackage(e.FullPath)); } catch { Logger.LogWarning("Failed to update levels configuration"); } } } private static void UpdateConfigFileOnChange(object sender, FileSystemEventArgs e) { if (!SynchronizationManager.Instance.PlayerIsAdmin) { Logger.LogInfo("Player is not an admin, and not allowed to change local configuration. Ignoring."); } else if (File.Exists(e.FullPath)) { string yaml = File.ReadAllText(e.FullPath); FileInfo fileInfo = new FileInfo(e.FullPath); Logger.LogDebug("Filewatch changes from: (" + fileInfo.Name + ") " + fileInfo.FullName); switch (fileInfo.Name) { case "ColorSettings.yaml": Logger.LogDebug("Triggering Color Settings update."); Colorization.UpdateYamlConfig(yaml); ColorSettingsRPC.SendPackage(ZNet.instance.m_peers, SendFileAsZPackage(e.FullPath)); break; case "LevelSettings.yaml": Logger.LogDebug("Triggering Level Settings update."); LevelSystemData.UpdateYamlConfig(yaml); LevelSettingsRPC.SendPackage(ZNet.instance.m_peers, SendFileAsZPackage(e.FullPath)); break; case "CreatureLootSettings.yaml": Logger.LogDebug("Triggering Loot Settings update."); LootSystemData.UpdateYamlConfig(yaml); CreatureLootSettingsRPC.SendPackage(ZNet.instance.m_peers, SendFileAsZPackage(e.FullPath)); break; } } } private static ZPackage SendFileAsZPackage(string filepath) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Expected O, but got Unknown string text = File.ReadAllText(filepath); ZPackage val = new ZPackage(); val.Write(text); return val; } private static ZPackage SendLevelsConfigs() { return SendFileAsZPackage(levelsFilePath); } private static ZPackage SendCreatureLootConfigs() { return SendFileAsZPackage(creatureLootFilePath); } private static ZPackage SendColorsConfigs() { return SendFileAsZPackage(colorsFilePath); } [IteratorStateMachine(typeof(<OnServerRecieveConfigs>d__40))] public static IEnumerator OnServerRecieveConfigs(long sender, ZPackage package) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <OnServerRecieveConfigs>d__40(0); } [IteratorStateMachine(typeof(<OnClientReceiveLevelConfigs>d__41))] private static IEnumerator OnClientReceiveLevelConfigs(long sender, ZPackage package) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <OnClientReceiveLevelConfigs>d__41(0) { package = package }; } [IteratorStateMachine(typeof(<OnClientReceiveColorConfigs>d__42))] private static IEnumerator OnClientReceiveColorConfigs(long sender, ZPackage package) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <OnClientReceiveColorConfigs>d__42(0) { package = package }; } [IteratorStateMachine(typeof(<OnClientReceiveCreatureLootConfigs>d__43))] private static IEnumerator OnClientReceiveCreatureLootConfigs(long sender, ZPackage package) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <OnClientReceiveCreatureLootConfigs>d__43(0) { package = package }; } public static string GetSecondaryConfigDirectoryPath() { return Directory.CreateDirectory(Path.Combine(Paths.ConfigPath, "StarLevelSystem")).FullName; } public static ConfigEntry<bool> BindServerConfig(string catagory, string key, bool value, string description, AcceptableValueBase acceptableValues = null, bool advanced = false) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown return cfg.Bind<bool>(catagory, key, value, new ConfigDescription(description, acceptableValues, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, IsAdvanced = advanced } })); } public static ConfigEntry<int> BindServerConfig(string catagory, string key, int value, string description, bool advanced = false, int valmin = 0, int valmax = 150) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Expected O, but got Unknown //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown return cfg.Bind<int>(catagory, key, value, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<int>(valmin, valmax), new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, IsAdvanced = advanced } })); } public static ConfigEntry<float> BindServerConfig(string catagory, string key, float value, string description, bool advanced = false, float valmin = 0f, float valmax = 150f) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Expected O, but got Unknown //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown return cfg.Bind<float>(catagory, key, value, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<float>(valmin, valmax), new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, IsAdvanced = advanced } })); } public static ConfigEntry<string> BindServerConfig(string catagory, string key, string value, string description, AcceptableValueList<string> acceptableValues = null, bool advanced = false) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown return cfg.Bind<string>(catagory, key, value, new ConfigDescription(description, (AcceptableValueBase)(object)acceptableValues, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, IsAdvanced = advanced } })); } } internal class Logger { public static LogLevel Level = (LogLevel)16; public static void enableDebugLogging(object sender, EventArgs e) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) if (ValConfig.EnableDebugMode.Value) { Level = (LogLevel)32; } else { Level = (LogLevel)16; } } public static void CheckEnableDebugLogging() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) if (ValConfig.EnableDebugMode.Value) { Level = (LogLevel)32; } else { Level = (LogLevel)16; } } public static void LogDebug(string message) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Invalid comparison between Unknown and I4 if ((int)Level >= 32) { StarLevelSystem.Log.LogInfo((object)message); } } public static void LogInfo(string message) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Invalid comparison between Unknown and I4 if ((int)Level >= 16) { StarLevelSystem.Log.LogInfo((object)message); } } public static void LogWarning(string message) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Invalid comparison between Unknown and I4 if ((int)Level >= 4) { StarLevelSystem.Log.LogWarning((object)message); } } public static void LogError(string message) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Invalid comparison between Unknown and I4 if ((int)Level >= 2) { StarLevelSystem.Log.LogError((object)message); } } } [BepInPlugin("MidnightsFX.StarLevelSystem", "StarLevelSystem", "0.0.8")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] internal class StarLevelSystem : BaseUnityPlugin { public const string PluginGUID = "MidnightsFX.StarLevelSystem"; public const string PluginName = "StarLevelSystem"; public const string PluginVersion = "0.0.8"; public ValConfig cfg; public static CustomLocalization Localization = LocalizationManager.Instance.GetLocalization(); public static ManualLogSource Log; public static Harmony HarmonyInstance { get; private set; } public void Awake() { Log = ((BaseUnityPlugin)this).Logger; cfg = new ValConfig(((BaseUnityPlugin)this).Config); cfg.SetupConfigRPCs(); cfg.LoadYamlConfigs(); HarmonyInstance = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "MidnightsFX.StarLevelSystem"); Colorization.Init(); LevelSystemData.Init(); LootSystemData.Init(); PrefabManager.OnPrefabsRegistered += LootSystemData.AttachPrefabsWhenReady; CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new Commands.DumpLootTablesCommand()); } } } namespace StarLevelSystem.modules { public class ColorDef { public float hue { get; set; } public float saturation { get; set; } public float value { get; set; } public bool is_emissive { get; set; } public LevelSetup toLevelEffect() { //IL_0000: 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_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown return new LevelSetup { m_scale = 1f, m_hue = hue, m_saturation = saturation, m_value = value, m_setEmissiveColor = is_emissive, m_emissiveColor = new Color(hue, saturation, value) }; } } public static class Colorization { [HarmonyPatch(typeof(LevelEffects), "SetupLevelVisualization")] public static class PreventDefaultLevelSetup { public static bool Prefix() { return false; } } public static DataObjects.CreatureColorizationSettings creatureColorizationSettings = defaultColorizationSettings; private static DataObjects.CreatureColorizationSettings defaultColorizationSettings = new DataObjects.CreatureColorizationSettings { characterSpecificColorization = ColorizationData.characterColorizationData, defaultLevelColorization = ColorizationData.defaultColorizationData }; public static ColorDef defaultColorization = new ColorDef { hue = 0f, saturation = 0f, value = 0f, is_emissive = false }; public static void Init() { creatureColorizationSettings = defaultColorizationSettings; try { UpdateYamlConfig(File.ReadAllText(ValConfig.colorsFilePath)); } catch (Exception arg) { Logger.LogWarning((object)$"There was an error updating the Color Level values, defaults will be used. Exception: {arg}"); } } public static string YamlDefaultConfig() { return DataObjects.yamlserializer.Serialize((object)defaultColorizationSettings); } public static bool UpdateYamlConfig(string yaml) { try { creatureColorizationSettings = DataObjects.yamldeserializer.Deserialize<DataObjects.CreatureColorizationSettings>(yaml); creatureColorizationSettings.defaultLevelColorization = defaultColorizationSettings.defaultLevelColorization; Logger.LogInfo("Updated ColorizationSettings."); Character[] array = Resources.FindObjectsOfTypeAll<Character>(); foreach (Character val in array) { if (val.m_level > 1) { ApplyColorizationWithoutLevelEffects(val); } } } catch (Exception ex) { StarLevelSystem.Log.LogError((object)("Failed to parse ColorizationSettings YAML: " + ex.Message)); return false; } return true; } public static void ApplyLevelVisual(Character charc) { LevelEffects componentInChildren = ((Component)charc).gameObject.GetComponentInChildren<LevelEffects>(); if (!((Object)(object)componentInChildren == (Object)null) && componentInChildren.m_levelSetups != null && componentInChildren.m_levelSetups.Count > 0) { LevelSetup val = componentInChildren.m_levelSetups[Random.Range(0, componentInChildren.m_levelSetups.Count - 1)]; if ((Object)(object)val.m_enableObject != (Object)null) { val.m_enableObject.SetActive(true); } } } internal static void ApplyColorizationWithoutLevelEffects(Character cgo) { //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Expected O, but got Unknown //IL_010d: Unknown result type (might be due to invalid IL or missing references) int num = cgo.m_level - 1; LevelSetup val = GetDefaultColorization(num).toLevelEffect(); string prefabName = Utils.GetPrefabName(((Component)cgo).gameObject); Logger.LogDebug("Checking for character specific colorization " + prefabName); if (creatureColorizationSettings.characterSpecificColorization.ContainsKey(prefabName)) { if (creatureColorizationSettings.characterSpecificColorization[prefabName].TryGetValue(num, out var value)) { Logger.LogDebug($"Found character specific colorization for {prefabName} - {num}"); val = value.toLevelEffect(); } } else { Logger.LogDebug($"No character specific colorization for {prefabName} - {num}"); } try { SkinnedMeshRenderer[] componentsInChildren = ((Component)cgo).gameObject.GetComponentsInChildren<SkinnedMeshRenderer>(); foreach (SkinnedMeshRenderer obj in componentsInChildren) { Material[] sharedMaterials = ((Renderer)obj).sharedMaterials; sharedMaterials[0] = new Material(sharedMaterials[0]); sharedMaterials[0].SetFloat("_Hue", val.m_hue); sharedMaterials[0].SetFloat("_Saturation", val.m_saturation); sharedMaterials[0].SetFloat("_Value", val.m_value); if (val.m_setEmissiveColor) { sharedMaterials[0].SetColor("_EmissionColor", val.m_emissiveColor); } ((Renderer)obj).sharedMaterials = sharedMaterials; } } catch (Exception arg) { Logger.LogError($"Exception while colorizing {arg}"); } } internal static void StarLevelScaleChanged(object s, EventArgs e) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) Character[] array = Resources.FindObjectsOfTypeAll<Character>(); foreach (Character val in array) { ((Component)val).transform.localScale = Vector3.one; float num = 1f + ValConfig.PerLevelScaleBonus.Value * (float)(val.m_level - 1); Logger.LogDebug($"Setting {((Object)val).name} size {num}."); Transform transform = ((Component)val).transform; transform.localScale *= num; } Physics.SyncTransforms(); } internal static ColorDef GetDefaultColorization(int level) { if (creatureColorizationSettings.defaultLevelColorization.ContainsKey(level)) { return creatureColorizationSettings.defaultLevelColorization[level]; } return defaultColorization; } } internal class Commands { internal class DumpLootTablesCommand : ConsoleCommand { public override string Name => "SLS_Dump_LootTables"; public override string Help => "Writes all creature loot-tables to a debug file."; public override bool IsCheat => true; public override void Run(string[] args) { string path = Path.Combine(Paths.ConfigPath, "StarLevelSystem", "LootTablesDump.yaml"); Dictionary<string, List<DataObjects.ExtendedDrop>> dictionary = new Dictionary<string, List<DataObjects.ExtendedDrop>>(); foreach (CharacterDrop item2 in (from cdrop in Resources.FindObjectsOfTypeAll<CharacterDrop>() where !((Object)cdrop).name.EndsWith("(Clone)") select cdrop).ToList()) { Logger.LogDebug("Checking " + ((Object)item2).name + " for loot tables"); string name = ((Object)item2).name; if (dictionary.ContainsKey(name)) { continue; } Logger.LogDebug("checking " + name); List<DataObjects.ExtendedDrop> list = new List<DataObjects.ExtendedDrop>(); Logger.LogDebug($"drops {item2.m_drops.Count}"); foreach (Drop drop in item2.m_drops) { DataObjects.ExtendedDrop item = new DataObjects.ExtendedDrop { Drop = new DataObjects.Drop { prefab = ((Object)drop.m_prefab).name, min = drop.m_amountMin, max = drop.m_amountMax, chance = drop.m_chance, onePerPlayer = drop.m_onePerPlayer, levelMultiplier = drop.m_levelMultiplier, dontScale = drop.m_dontScale } }; list.Add(item); } dictionary.Add(name, list); Logger.LogDebug("Adding " + name + " loot-table"); } Logger.LogDebug("Serializing data"); string value = DataObjects.yamlserializer.Serialize((object)dictionary); Logger.LogDebug("Writing file to disk"); using StreamWriter streamWriter = new StreamWriter(path); streamWriter.WriteLine(value); } } } internal class LevelEffectsExtended { } public static class LevelSystem { public static class ExpandSpawnerTriggerLevel { [HarmonyPatch("Awake")] public static void Postfix(TriggerSpawner __instance) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: 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) Vector3 position = ((Component)__instance).transform.position; Vector3 val = default(Vector3); Biome key = default(Biome); BiomeArea val2 = default(BiomeArea); Heightmap val3 = default(Heightmap); ZoneSystem.instance.GetGroundData(ref position, ref val, ref key, ref val2, ref val3); LevelSystemData.SLE_Level_Settings.BiomeConfiguration.TryGetValue(key, out var value); if (value != null) { if (value.EnableBiomeLevelOverride) { __instance.m_maxLevel = value.BiomeMaxLevelOverride; } } else { __instance.m_maxLevel = ValConfig.MaxLevel.Value + 1; } } } public static class ExpandLevelupRoll { [HarmonyPatch(typeof(TriggerSpawner))] public static class SetupCreatureSpawnerLevelExtendedRoll { [HarmonyTranspiler] [HarmonyPatch("Spawn")] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Expected O, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Expected O, but got Unknown //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null); val.MatchStartForward((CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(TriggerSpawner), "m_minLevel"), (string)null), new CodeMatch((OpCode?)OpCodes.Stloc_S, (object)null, (string)null) }).RemoveInstructions(21).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[3] { new CodeInstruction(OpCodes.Ldloc_S, (object)(byte)5), Transpilers.EmitDelegate<Func<GameObject, int>>((Func<GameObject, int>)DetermineLevelInline), new CodeInstruction(OpCodes.Stloc_S, (object)(byte)8) }) .ThrowIfNotMatch("Unable to patch Creature Spawner set level.", Array.Empty<CodeMatch>()); return val.Instructions(); } } } public static class ExpandLevelupRollAreaSpawner { [HarmonyPatch(typeof(SpawnArea))] public static class SetupAreaSpawnerLevelExtendedRoll { [HarmonyTranspiler] [HarmonyPatch("SpawnOne")] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Expected O, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Expected O, but got Unknown //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Expected O, but got Unknown //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Expected O, but got Unknown //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null); val.MatchStartForward((CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Ldloc_2, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(SpawnData), "m_maxLevel"), (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_I4_1, (object)null, (string)null) }).RemoveInstructions(27).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[5] { new CodeInstruction(OpCodes.Ldloc_S, (object)(byte)4), Transpilers.EmitDelegate<Func<GameObject, int>>((Func<GameObject, int>)DetermineLevelInline), new CodeInstruction(OpCodes.Stloc_S, (object)(byte)8), new CodeInstruction(OpCodes.Ldloc_S, (object)(byte)5), new CodeInstruction(OpCodes.Ldloc_S, (object)(byte)8) }) .ThrowIfNotMatch("Unable to patch Area Spawner set level.", Array.Empty<CodeMatch>()); return val.Instructions(); } } } public static class ExpandLevelupRollSpawnSystem { [HarmonyPatch(typeof(SpawnSystem))] public static class SetupAreaSpawnerLevelExtendedRoll { [HarmonyTranspiler] [HarmonyPatch("Spawn")] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Expected O, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null); val.MatchStartForward((CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Ldarg_1, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(SpawnData), "m_levelUpMinCenterDistance"), (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)null, (string)null) }).Advance(1).RemoveInstructions(62) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2] { new CodeInstruction(OpCodes.Ldloc_0, (object)null), Transpilers.EmitDelegate<Action<SpawnData, GameObject>>((Action<SpawnData, GameObject>)DetermineApplyCreatureLevelOrUpgrade) }) .ThrowIfNotMatch("Unable to patch Spawn System set level.", Array.Empty<CodeMatch>()); return val.Instructions(); } } } public static class ExpandLevelupRollCreatureSpawner { [HarmonyPatch(typeof(CreatureSpawner), "Awake")] public static class PostfixLevelSetupCreatureSpawner { public static void Postfix(CreatureSpawner __instance) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: 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_003c: Unknown result type (might be due to invalid IL or missing references) Vector3 position = ((Component)__instance).transform.position; Vector3 val = default(Vector3); Biome key = default(Biome); BiomeArea val2 = default(BiomeArea); Heightmap val3 = default(Heightmap); ZoneSystem.instance.GetGroundData(ref position, ref val, ref key, ref val2, ref val3); try { if (LevelSystemData.SLE_Level_Settings.BiomeConfiguration.ContainsKey(key)) { DataObjects.BiomeSpecificSetting biomeSpecificSetting = LevelSystemData.SLE_Level_Settings.BiomeConfiguration[key]; if (biomeSpecificSetting.BiomeMaxLevelOverride != 0) { __instance.m_maxLevel = biomeSpecificSetting.BiomeMaxLevelOverride; } else { __instance.m_maxLevel = ValConfig.MaxLevel.Value + 1; } } else { __instance.m_maxLevel = ValConfig.MaxLevel.Value + 1; } } catch (Exception arg) { Logger.LogWarning($"Exception trying to set CreatureSpawner max level {arg}"); } } } [HarmonyPatch(typeof(CreatureSpawner))] public static class SetupCreatureSpawnerLevelExtendedRoll { [HarmonyTranspiler] [HarmonyPatch("Spawn")] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Expected O, but got Unknown //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null); val.MatchStartForward((CodeMatch[])(object)new CodeMatch[5] { new CodeMatch((OpCode?)OpCodes.Ldloc_3, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Stloc_S, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Call, (object)null, (string)null) }).Advance(6).RemoveInstructions(16) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[3] { new CodeInstruction(OpCodes.Ldloc_3, (object)null), Transpilers.EmitDelegate<Func<GameObject, int>>((Func<GameObject, int>)DetermineLevelInline), new CodeInstruction(OpCodes.Stloc_S, (object)(byte)11) }) .ThrowIfNotMatch("Unable to patch Creature Spawner set level.", Array.Empty<CodeMatch>()); return val.Instructions(); } } } [HarmonyPatch(typeof(Character), "GetMaxHealthBase")] public static class SetupMaxLevelHealthPatch { [HarmonyTranspiler] [HarmonyPatch("GetMaxHealthBase")] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Expected O, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null); val.MatchStartForward((CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(Character), "m_health"), (string)null), new CodeMatch((OpCode?)OpCodes.Stloc_0, (object)null, (string)null) }).Advance(1).RemoveInstructions(1) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate<Func<Character, float>>((Func<Character, float>)CharacterHealthMultiplier) }) .ThrowIfNotMatch("Unable to patch enemy base health and world level modifiers.", Array.Empty<CodeMatch>()); return val.Instructions(); } public static float CharacterHealthMultiplier(Character character) { if (character.IsPlayer()) { return 1f; } SelectCreatureBiomeSettings(((Component)character).gameObject, out var _, out var creature_settings, out var biome_settings, out var _); float num = 1f; float num2 = 1f; float value2; if (creature_settings != null && creature_settings.CreatureBaseValueModifiers != null && creature_settings.CreatureBaseValueModifiers.TryGetValue(DataObjects.CreatureBaseAttribute.BaseHealth, out var value)) { num = value; } else if (biome_settings != null && biome_settings.CreatureBaseValueModifiers != null && biome_settings.CreatureBaseValueModifiers.TryGetValue(DataObjects.CreatureBaseAttribute.BaseHealth, out value2)) { num = value2; } float value4; if (creature_settings != null && creature_settings.CreaturePerLevelValueModifiers != null && creature_settings.CreaturePerLevelValueModifiers.TryGetValue(DataObjects.CreaturePerLevelAttribute.HealthPerLevel, out var value3)) { num2 = value3; } else if (biome_settings != null && biome_settings.CreaturePerLevelValueModifiers != null && biome_settings.CreaturePerLevelValueModifiers.TryGetValue(DataObjects.CreaturePerLevelAttribute.HealthPerLevel, out value4)) { num2 = value4; } float num3 = Mathf.Pow(num2, (float)(character.m_level - 1)); float num4 = character.m_health * num * num3; Logger.LogDebug($"Setting {character.m_name} health {character.m_health} to {num4} using basehealth mod {num} and perlevel mod {num2} ({num3})"); if (character.IsBoss()) { if (num2 != 1f) { return num4 * num2; } return num4 * ValConfig.BossEnemyHealthMultiplier.Value; } if (num2 != 1f) { return num4 * num2; } return num4 * ValConfig.EnemyHealthMultiplier.Value; } } [HarmonyPatch(typeof(Attack), "GetLevelDamageFactor")] public static class SetupMaxLevelDamagePatch { public static void Postfix(Attack __instance, float __result) { __result = ((!((Object)(object)__instance.m_character != (Object)null) || !((Character)__instance.m_character).IsBoss()) ? (1f + (float)Mathf.Max(0, ((Character)__instance.m_character).GetLevel() - 1) * ValConfig.EnemyDamageLevelMultiplier.Value) : (1f + (float)Mathf.Max(0, ((Character)__instance.m_character).GetLevel() - 1) * ValConfig.BossEnemyDamageMultiplier.Value)); } } public static Vector2 center = new Vector2(0f, 0f); public static int DetermineLevelInline(GameObject creature) { SelectCreatureBiomeSettings(creature, out var creature_name, out var creature_settings, out var biome_settings, out var _); return DetermineLevel(creature, creature_name, creature_settings, biome_settings); } public static int DetermineLevel(GameObject creature, string creature_name, DataObjects.CreatureSpecificSetting creature_settings, DataObjects.BiomeSpecificSetting biome_settings) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)creature == (Object)null) { Logger.LogWarning("Creature is null, cannot determine level, set 1."); return 1; } float roll = Random.Range(0f, 100f); int maxLevel = ValConfig.MaxLevel.Value + 1; float distance_from_center = Vector2.Distance(Vector2.op_Implicit(creature.transform.position), center); SortedDictionary<int, float> levelup_bonus = new SortedDictionary<int, float>(); SortedDictionary<int, float> creature_levelup_chance = LevelSystemData.SLE_Level_Settings.DefaultCreatureLevelUpChance; if (ValConfig.EnableDistanceLevelScalingBonus.Value && LevelSystemData.SLE_Level_Settings.DistanceLevelBonus != null) { levelup_bonus = SelectDistanceFromCenterLevelBonus(distance_from_center); } float distance_influence = 1f; if (biome_settings != null) { distance_influence = biome_settings.DistanceScaleModifier; } if (LevelSystemData.SLE_Level_Settings.CreatureConfiguration.ContainsKey(creature_name)) { Logger.LogDebug("Creature specific config found for " + creature_name); if (creature_settings.CustomCreatureLevelUpChance != null) { if (creature_settings.EnableCreatureLevelOverride) { maxLevel = creature_settings.CreatureMaxLevelOverride; } if (creature_settings.CustomCreatureLevelUpChance != null) { creature_levelup_chance = creature_settings.CustomCreatureLevelUpChance; } return DetermineLevelRollResult(roll, maxLevel, creature_levelup_chance, levelup_bonus, distance_influence); } } else if (ValConfig.EnableDebugMode.Value) { Logger.LogDebug("Creature specific setting not found for " + creature_name + "."); } if (biome_settings != null) { if (biome_settings.EnableBiomeLevelOverride) { maxLevel = biome_settings.BiomeMaxLevelOverride; } if (biome_settings.CustomCreatureLevelUpChance != null) { creature_levelup_chance = biome_settings.CustomCreatureLevelUpChance; } return DetermineLevelRollResult(roll, maxLevel, creature_levelup_chance, levelup_bonus, distance_influence); } return DetermineLevelRollResult(roll, maxLevel, creature_levelup_chance, levelup_bonus, distance_influence); } private static SortedDictionary<int, float> SelectDistanceFromCenterLevelBonus(float distance_from_center) { SortedDictionary<int, float> result = new SortedDictionary<int, float>(); if (ValConfig.EnableDistanceLevelScalingBonus.Value && LevelSystemData.SLE_Level_Settings.DistanceLevelBonus != null) { foreach (KeyValuePair<int, SortedDictionary<int, float>> distanceLevelBonu in LevelSystemData.SLE_Level_Settings.DistanceLevelBonus) { if (distance_from_center <= (float)distanceLevelBonu.Key) { Logger.LogDebug($"Distance Level area: {distanceLevelBonu.Key}"); result = distanceLevelBonu.Value; break; } } } return result; } public static int DetermineLevelRollResult(float roll, int maxLevel, SortedDictionary<int, float> creature_levelup_chance, SortedDictionary<int, float> levelup_bonus, float distance_influence) { int num = 0; foreach (KeyValuePair<int, float> item in creature_levelup_chance) { Logger.LogDebug($"levelup k: {item.Key} v: {item.Value}"); if (levelup_bonus.ContainsKey(item.Key)) { float num2 = (1f + levelup_bonus[item.Key]) * distance_influence; float num3 = item.Value * num2; if (roll >= num3 || item.Key >= maxLevel) { num = item.Key; Logger.LogDebug($"Level Roll: {roll} >= {num3} = {item.Value} * {num2} | Selected Level: {num}"); break; } } else if (roll >= item.Value || item.Key >= maxLevel) { num = item.Key; Logger.LogDebug($"Level Roll: {roll} | Selected Level: {num}"); break; } } return num; } public static void DetermineApplyCreatureLevelOrUpgrade(SpawnData critter_def, GameObject creature) { SelectCreatureBiomeSettings(creature, out var creature_name, out var creature_settings, out var biome_settings, out var _); int num = DetermineLevel(creature, creature_name, creature_settings, biome_settings); if (num <= 1) { return; } Character component = creature.GetComponent<Character>(); if (component != null) { component.SetLevel(num); } if ((Object)(object)creature.GetComponent<Fish>() != (Object)null) { ItemDrop component2 = creature.GetComponent<ItemDrop>(); if (component2 != null) { component2.SetQuality(num); } } } public static void DetermineApplyLevelGeneric(GameObject creature, string creature_name, DataObjects.CreatureSpecificSetting creature_settings, DataObjects.BiomeSpecificSetting biome_settings) { int num = DetermineLevel(creature, creature_name, creature_settings, biome_settings); if (num <= 1) { return; } Character component = creature.GetComponent<Character>(); if (component != null) { component.SetLevel(num); } Humanoid component2 = creature.GetComponent<Humanoid>(); if ((Object)(object)component2 != (Object)null) { ((Character)component2).SetLevel(num); } if ((Object)(object)creature.GetComponent<Fish>() != (Object)null) { ItemDrop component3 = creature.GetComponent<ItemDrop>(); if (component3 != null) { component3.SetQuality(num); } } } public static void SelectCreatureBiomeSettings(GameObject creature, out string creature_name, out DataObjects.CreatureSpecificSetting creature_settings, out DataObjects.BiomeSpecificSetting biome_settings, out Biome creature_biome) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected I4, but got Unknown //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) Vector3 position = creature.transform.position; creature_name = ((Object)creature).name.Replace("(Clone)", ""); Vector3 val = default(Vector3); Biome val2 = default(Biome); BiomeArea val3 = default(BiomeArea); Heightmap val4 = default(Heightmap); ZoneSystem.instance.GetGroundData(ref position, ref val, ref val2, ref val3, ref val4); creature_biome = (Biome)(int)val2; Logger.LogDebug($"{creature_name} {val2} {position}"); if (LevelSystemData.SLE_Level_Settings.BiomeConfiguration.TryGetValue(val2, out var value)) { biome_settings = value; } else { biome_settings = null; } if (LevelSystemData.SLE_Level_Settings.CreatureConfiguration.TryGetValue(creature_name, out var value2)) { creature_settings = value2; } else { creature_settings = null; } } } public class StarLevelHud { public bool isBoss { get; set; } public GameObject starlevel2 { get; set; } public GameObject starlevel3 { get; set; } public GameObject starlevel4 { get; set; } public GameObject starlevel5 { get; set; } public GameObject starlevel6 { get; set; } public GameObject starlevel_N { get; set; } public Text starlevel_N_Text { get; set; } } public static class LevelUI { [HarmonyPatch(typeof(EnemyHud), "Awake")] public static class EnableLevelDisplay { public static void Postfix(EnemyHud __instance) { star = ((Component)__instance.m_baseHud.transform.Find("level_2/star")).gameObject; Object.Destroy((Object)(object)((Component)__instance.m_baseHud.transform.Find("level_3/star")).gameObject); StarLevelHudDisplay(star, __instance.m_baseHud.transform, __instance.m_baseHudBoss.transform); } private static void StarLevelHudDisplay(GameObject star, Transform basehud, Transform bosshud) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Expected O, but got Unknown //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Expected O, but got Unknown //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Expected O, but got Unknown //IL_0243: Unknown result type (might be due to invalid IL or missing references) //IL_0267: Unknown result type (might be due to invalid IL or missing references) //IL_0276: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_029b: Unknown result type (might be due to invalid IL or missing references) //IL_02a1: Unknown result type (might be due to invalid IL or missing references) SetupStar(star, 4, basehud); SetupStar(star, 5, basehud); SetupStar(star, 6, basehud); GameObject val = new GameObject("level_n"); val.transform.SetParent(basehud); GameObject obj = Object.Instantiate<GameObject>(star, val.transform); val.transform.localPosition = new Vector3(-42f, 19f, 0f); obj.transform.localPosition = new Vector3(0f, 0f, 0f); GameObject val2 = Object.Instantiate<GameObject>(new GameObject("level_n_name"), val.transform); val2.transform.SetParent(val.transform); val2.transform.localPosition = new Vector3(0f, 0f, 0f); GUIManager.Instance.CreateText("999", val2.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(185f, -13f), GUIManager.Instance.AveriaSerifBold, 14, GUIManager.Instance.ValheimYellow, true, Color.black, 350f, 40f, false); val.SetActive(false); SetupStar(star, 2, bosshud, boss: true); SetupStar(star, 3, bosshud, boss: true); SetupStar(star, 4, bosshud, boss: true); SetupStar(star, 5, bosshud, boss: true); SetupStar(star, 6, bosshud, boss: true); GameObject val3 = new GameObject("level_n"); val3.transform.SetParent(bosshud); GameObject obj2 = Object.Instantiate<GameObject>(star, val3.transform); obj2.GetComponent<RectTransform>().sizeDelta = new Vector2(20f, 20f); ((Component)obj2.transform.Find("star (1)")).gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(16f, 16f); val3.transform.localPosition = new Vector3(-17f, -6f, 0f); obj2.transform.localPosition = new Vector3(0f, 0f, 0f); GameObject val4 = Object.Instantiate<GameObject>(new GameObject("level_n_name"), val3.transform); val4.transform.SetParent(val3.transform); val4.transform.localPosition = new Vector3(0f, 0f, 0f); GUIManager.Instance.CreateText("999", val4.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(185f, -7f), GUIManager.Instance.AveriaSerifBold, 23, GUIManager.Instance.ValheimYellow, true, Color.black, 350f, 40f, false); val3.SetActive(false); } private static void SetupStar(GameObject star, int level, Transform parent_t, bool boss = false) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: 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_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_0264: Unknown result type (might be due to invalid IL or missing references) //IL_0206: Unknown result type (might be due to invalid IL or missing references) //IL_0225: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject($"level_{level}"); val.transform.SetParent(parent_t); GameObject val2 = Object.Instantiate<GameObject>(star, val.transform); if (boss) { RectTransform component = ((Component)val2.transform.Find("star (1)")).gameObject.GetComponent<RectTransform>(); RectTransform component2 = val2.GetComponent<RectTransform>(); component.sizeDelta = new Vector2(16f, 16f); component2.sizeDelta = new Vector2(20f, 20f); } val.SetActive(false); switch (level) { case 2: if (boss) { val.transform.localPosition = new Vector3(0f, -6f, 0f); } break; case 3: if (boss) { val.transform.localPosition = new Vector3(-20f, -6f, 0f); } break; case 4: if (boss) { val.transform.localPosition = new Vector3(20f, -6f, 0f); val2.transform.localPosition = new Vector3(0f, 0f, 0f); } else { val.transform.localPosition = new Vector3(-9f, 19f, 0f); val2.transform.localPosition = new Vector3(0f, 0f, 0f); } break; case 5: if (boss) { val.transform.localPosition = new Vector3(-40f, -6f, 0f); val2.transform.localPosition = new Vector3(0f, 0f, 0f); } else { val.transform.localPosition = new Vector3(7f, 19f, 0f); val2.transform.localPosition = new Vector3(0f, 0f, 0f); } break; case 6: if (boss) { val.transform.localPosition = new Vector3(40f, -6f, 0f); val2.transform.localPosition = new Vector3(0f, 0f, 0f); } else { val.transform.localPosition = new Vector3(23f, 19f, 0f); val2.transform.localPosition = new Vector3(0f, 0f, 0f); } break; } } } [HarmonyPatch(typeof(EnemyHud), "ShowHud")] public static class DisableVanillaStarsByDefault { public static void Postfix(EnemyHud __instance, Character c) { if (!((Object)(object)__instance == (Object)null) && !((Object)(object)c == (Object)null) && !c.IsBoss()) { __instance.m_huds.TryGetValue(c, out var value); if (value != null && !((Object)(object)value.m_level2 == (Object)null) && !((Object)(object)value.m_level3 == (Object)null)) { ((Component)value.m_level2).gameObject.SetActive(false); ((Component)value.m_level3).gameObject.SetActive(false); } } } } [HarmonyPatch(typeof(EnemyHud), "UpdateHuds")] public static class DestroyEnemyHud { [HarmonyTranspiler] [HarmonyPatch("UpdateHuds")] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Expected O, but got Unknown //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null); val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[5] { new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(EnemyHud), "m_huds"), (string)null), new CodeMatch((OpCode?)OpCodes.Ldloc_3, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Pop, (object)null, (string)null) }).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2] { new CodeInstruction(OpCodes.Ldloc_3, (object)null), Transpilers.EmitDelegate<Action<Character>>((Action<Character>)RemoveExtenedHudFromCache) }).ThrowIfNotMatch("Unable to patch Enemy Hud removal update, levels will not be displayed properly.", Array.Empty<CodeMatch>()); return val.Instructions(); } public static void RemoveExtenedHudFromCache(Character char3) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) characterExtendedHuds.Remove(char3.GetZDOID()); } } [HarmonyPatch(typeof(EnemyHud))] public static class SetupCreatureLevelDisplay { [HarmonyTranspiler] [HarmonyPatch("UpdateHuds")] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Expected O, but got Unknown //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Expected O, but got Unknown //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Expected O, but got Unknown //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Expected O, but got Unknown //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null); val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[8] { new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_I4_1, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Stloc_S, (object)null, (string)null) }).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2] { new CodeInstruction(OpCodes.Ldloc_S, (object)(byte)6), Transpilers.EmitDelegate<Action<HudData>>((Action<HudData>)UpdateHudforAllLevels) }).RemoveInstructions(23) .ThrowIfNotMatch("Unable to patch Enemy Hud update, levels will not be displayed properly.", Array.Empty<CodeMatch>()); return val.Instructions(); } } public static Dictionary<ZDOID, StarLevelHud> characterExtendedHuds = new Dictionary<ZDOID, StarLevelHud>(); private static GameObject star; public static void UpdateHudforAllLevels(HudData ehud) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) if (ehud == null || (Object)(object)ehud.m_character == (Object)null || ehud.m_character.IsPlayer()) { return; } int level = ehud.m_character.GetLevel(); ZDOID zDOID = ehud.m_character.GetZDOID(); if (zDOID == ZDOID.None) { return; } StarLevelHud starLevelHud = new StarLevelHud(); if (characterExtendedHuds.ContainsKey(zDOID)) { starLevelHud = characterExtendedHuds[zDOID]; } else { starLevelHud.isBoss = ehud.m_character.IsBoss(); starLevelHud.starlevel2 = ((Component)ehud.m_gui.transform.Find("level_2")).gameObject; starLevelHud.starlevel3 = ((Component)ehud.m_gui.transform.Find("level_3")).gameObject; starLevelHud.starlevel4 = ((Component)ehud.m_gui.transform.Find("level_4")).gameObject; starLevelHud.starlevel5 = ((Component)ehud.m_gui.transform.Find("level_5")).gameObject; starLevelHud.starlevel6 = ((Component)ehud.m_gui.transform.Find("level_6")).gameObject; starLevelHud.starlevel_N = ((Component)ehud.m_gui.transform.Find("level_n")).gameObject; starLevelHud.starlevel_N_Text = ((Component)ehud.m_gui.transform.Find("level_n/level_n_name(Clone)/Text")).gameObject.GetComponent<Text>(); if ((Object)(object)starLevelHud.starlevel2 == (Object)null || (Object)(object)starLevelHud.starlevel3 == (Object)null || (Object)(object)starLevelHud.starlevel4 == (Object)null || (Object)(object)starLevelHud.starlevel5 == (Object)null || (Object)(object)starLevelHud.starlevel6 == (Object)null || (Object)(object)starLevelHud.starlevel_N == (Object)null) { Logger.LogDebug("Unable to find all hud information for " + ((Object)ehud.m_character).name); return; } characterExtendedHuds.Add(zDOID, starLevelHud); } switch (level) { case 2: starLevelHud.starlevel2.SetActive(true); break; case 3: starLevelHud.starlevel2.SetActive(true); starLevelHud.starlevel3.SetActive(true); break; case 4: starLevelHud.starlevel2.SetActive(true); starLevelHud.starlevel3.SetActive(true); starLevelHud.starlevel4.SetActive(true); break; case 5: starLevelHud.starlevel2.SetActive(true); starLevelHud.starlevel3.SetActive(true); starLevelHud.starlevel4.SetActive(true); starLevelHud.starlevel5.SetActive(true); break; case 6: starLevelHud.starlevel2.SetActive(true); starLevelHud.starlevel3.SetActive(true); starLevelHud.starlevel4.SetActive(true); starLevelHud.starlevel5.SetActive(true); starLevelHud.starlevel6.SetActive(true); break; } if (level > 6) { starLevelHud.starlevel_N.SetActive(true); starLevelHud.starlevel_N_Text.text = (level - 1).ToString(); } } } public static class LootLevelsExpanded { public enum LootFactorType { PerLevel, Exponential } [HarmonyPatch(typeof(CharacterDrop), "GenerateDropList")] public static class ModifyLootPerLevelEffect { public static bool Prefix(ref List<KeyValuePair<GameObject, int>> __result, CharacterDrop __instance) { //IL_018d: Unknown result type (might be due to invalid IL or missing references) List<KeyValuePair<GameObject, int>> list = new List<KeyValuePair<GameObject, int>>(); int num = 1; SelectLootSettings(((Component)__instance).gameObject, out var creature_name, out var distance_bonus, out var _, out var charc); if ((Object)(object)charc != (Object)null) { num = charc.GetLevel(); } if (LootSystemData.SLS_Drop_Settings.characterSpecificLoot.ContainsKey(creature_name)) { Logger.LogDebug($"SLS Custom drop set for {creature_name} - level {num}"); foreach (DataObjects.ExtendedDrop item in LootSystemData.SLS_Drop_Settings.characterSpecificLoot[creature_name]) { if ((Object)(object)__instance.m_character != (Object)null) { Logger.LogDebug("Checking if drop is tame only or non-tame only."); if ((item.untamedOnlyDrop && __instance.m_character.IsTamed()) || (item.tamedOnlyDrop && !__instance.m_character.IsTamed())) { continue; } } float num2 = 1f; if (item.Drop.chance < 1f) { float value = Random.value; float num3 = item.Drop.chance; if (item.chanceScaleFactor > 0f) { num3 *= num2 * (float)num; } if (value > num3) { Logger.LogDebug($"Drop {item.Drop.prefab} failed random drop chance ({value} < {num3})."); continue; } } if (item.useChanceAsMultiplier) { num2 = item.Drop.chance * (float)num; Logger.LogDebug("Drop " + item.Drop.prefab + " modified by chance and creature level."); } if (item.scalePerNearbyPlayer) { num2 += (float)Player.GetPlayersInRangeXZ(((Component)__instance).transform.position, 500f); Logger.LogDebug("Drop " + item.Drop.prefab + " modified players in local area."); } int min = item.Drop.min; int max = item.Drop.max; int num4 = min; if (min != max) { num4 = ((!item.scalebyMaxLevel) ? Random.Range(min, max) : ((max - min) / ValConfig.MaxLevel.Value * num)); } if (item.doesNotScale) { Logger.LogDebug($"Drop {item.Drop.prefab} does not scale and will drop {num4}"); list.Add(new KeyValuePair<GameObject, int>(item.gameDrop.m_prefab, num4)); continue; } int num5 = num4; float num6 = item.amountScaleFactor * num2; if (num6 <= 0f) { num6 = 1f; } num5 = ((SelectedLootFactor != 0) ? ExponentLootPerLevel(num, num4, distance_bonus, num6) : multiplyLootPerLevel(num, num4, distance_bonus, num6)); Logger.LogDebug($"Drop {item.Drop.prefab} drops amount base {num4} x scale_mult {num2} x loot factor type {ValConfig.LootDropCaluationType.Value} = {num5}"); if (item.maxScaledAmount > 0 && num5 > item.maxScaledAmount) { num5 = item.maxScaledAmount; Logger.LogDebug($"Drop {item.Drop.prefab} capped to {num5}"); } Logger.LogDebug($"Drop {item.Drop.prefab} capped to {num5}"); if (item.gameDrop == null || (Object)(object)item.gameDrop.m_prefab == (Object)null) { Logger.LogDebug("Drop Prefab not yet cached, updating and caching."); item.SetupDrop(); } list.Add(new KeyValuePair<GameObject, int>(item.gameDrop.m_prefab, num5)); } __result = list; return false; } Logger.LogDebug($"SLS vanilla drop set for {creature_name} - level {num}"); foreach (Drop drop in __instance.m_drops) { if (drop.m_chance < 1f) { float value2 = Random.value; if (value2 > drop.m_chance) { Logger.LogDebug($"Drop {((Object)drop.m_prefab).name} failed random drop chance ({value2} < {drop.m_chance})."); continue; } Logger.LogDebug($"Drop {((Object)drop.m_prefab).name} succeeded random drop chance ({value2} < {drop.m_chance})."); } int num7 = drop.m_amountMin; if (drop.m_amountMin != drop.m_amountMax) { num7 = Random.Range(drop.m_amountMin, drop.m_amountMax); } if (drop.m_dontScale) { if (num7 > 0) { Logger.LogDebug($"Drop {((Object)drop.m_prefab).name} {num7}"); list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, num7)); } } else if (SelectedLootFactor == LootFactorType.PerLevel) { int num8 = multiplyLootPerLevel(num, num7, distance_bonus); if (num8 > 0) { Logger.LogDebug($"Drop {((Object)drop.m_prefab).name} {num8}"); list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, num8)); } } else { int num9 = ExponentLootPerLevel(num, num7, distance_bonus); if (num9 > 0) { Logger.LogDebug($"Drop {((Object)drop.m_prefab).name} {num9}"); list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, num9)); } } } __result = list; return false; } } [HarmonyPatch(typeof(CharacterDrop))] public static class DropItemsPerformancePatch { [HarmonyPatch("DropItems")] public static bool Prefix(CharacterDrop __instance, List<KeyValuePair<GameObject, int>> drops, Vector3 centerPos, float dropArea) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Player.m_localPlayer != (Object)null) { ((MonoBehaviour)Player.m_localPlayer).StartCoroutine(DropItemsAsync(drops, centerPos, dropArea)); } else { foreach (KeyValuePair<GameObject, int> drop in drops) { bool flag = false; int num = 0; GameObject key = drop.Key; int value = drop.Value; Logger.LogDebug($"Dropping {((Object)key).name} {value}"); for (int i = 0; i < value; i++) { GameObject obj = Object.Instantiate<GameObject>(key, centerPos, Quaternion.identity); ItemDrop component = obj.GetComponent<ItemDrop>(); if (!flag) { flag = true; if (Object.op_Implicit((Object)(object)component)) { num = component.m_itemData.m_shared.m_maxStackSize; } } if (component != null) { int num2 = value - i; if (num2 > 0) { if (value > num) { component.m_itemData.m_stack = num; i += num; } else { component.m_itemData.m_stack = num2; i += num2; } } component.m_itemData.m_worldLevel = (byte)Game.m_worldLevel; } Rigidbody component2 = obj.GetComponent<Rigidbody>(); if (Object.op_Implicit((Object)(object)component2)) { Vector3 insideUnitSphere = Random.insideUnitSphere; if (insideUnitSphere.y < 0f) { insideUnitSphere.y = 0f - insideUnitSphere.y; } component2.AddForce(insideUnitSphere * 5f, (ForceMode)2); } } } } return false; } } [CompilerGenerated] private sealed class <DropItemsAsync>d__8 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public List<KeyValuePair<GameObject, int>> drops; public Vector3 centerPos; private int <obj_spawns>5__2; private List<KeyValuePair<GameObject, int>>.Enumerator <>7__wrap2; private bool <set_stack_size>5__4; private int <max_stack_size>5__5; private GameObject <item>5__6; private int <amount>5__7; private int <i>5__8; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <DropItemsAsync>d__8(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { int num = <>1__state; if (num == -3 || num == 1) { try { } finally { <>m__Finally1(); } } <>7__wrap2 = default(List<KeyValuePair<GameObject, int>>.Enumerator); <item>5__6 = null; <>1__state = -2; } private bool MoveNext() { //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Expected O, but got Unknown //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_0201: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) try { int num = <>1__state; if (num != 0) { if (num != 1) { return false; } <>1__state = -3; goto IL_00eb; } <>1__state = -1; <obj_spawns>5__2 = 0; <>7__wrap2 = drops.GetEnumerator(); <>1__state = -3; goto IL_0236; IL_0236: if (<>7__wrap2.MoveNext()) { KeyValuePair<GameObject, int> current = <>7__wrap2.Current; <set_stack_size>5__4 = false; <max_stack_size>5__5 = 0; <item>5__6 = current.Key; <amount>5__7 = current.Value; Logger.LogDebug($"Dropping {((Object)<item>5__6).name} {<amount>5__7}"); <i>5__8 = 0; goto IL_021e; } <>m__Finally1(); <>7__wrap2 = default(List<KeyValuePair<GameObject, int>>.Enumerator); return false; IL_021e: if (<i>5__8 < <amount>5__7) { if (<obj_spawns>5__2 > 0 && <obj_spawns>5__2 % ValConfig.LootDropsPerTick.Value == 0) { <>2__current = (object)new WaitForSeconds(0.1f); <>1__state = 1; return true; } goto IL_00eb; } <item>5__6 = null; goto IL_0236; IL_00eb: GameObject obj = Object.Instantiate<GameObject>(<item>5__6, centerPos, Quaternion.identity); <obj_spawns>5__2++; ItemDrop component = obj.GetComponent<ItemDrop>(); if (!<set_stack_size>5__4) { <set_stack_size>5__4 = true; if (Object.op_Implicit((Object)(object)component)) { <max_stack_size>5__5 = component.m_itemData.m_shared.m_maxStackSize; } } if (component != null) { int num2 = <amount>5__7 - <i>5__8; if (num2 > 0) { if (<amount>5__7 > <max_stack_size>5__5) { component.m_itemData.m_stack = <max_stack_size>5__5; <i>5__8 += <max_stack_size>5__5; } else { component.m_itemData.m_stack = num2; <i>5__8 += num2; } } component.m_itemData.m_worldLevel = (byte)Game.m_worldLevel; } Rigidbody component2 = obj.GetComponent<Rigidbody>(); if (Object.op_Implicit((Object)(object)component2)) { Vector3 insideUnitSphere = Random.insideUnitSphere; if (insideUnitSphere.y < 0f) { insideUnitSphere.y = 0f - insideUnitSphere.y; } component2.AddForce(insideUnitSphere * 5f, (ForceMode)2); } <i>5__8++; goto IL_021e; } catch { //try-fault ((IDisposable)this).Dispose(); throw; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; ((IDisposable)<>7__wrap2).Dispose(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } public static LootFactorType SelectedLootFactor = LootFactorType.PerLevel; internal static readonly AcceptableValueList<string> AllowedLootFactors = new AcceptableValueList<string>(new string[2] { LootFactorType.PerLevel.ToString(), LootFactorType.Exponential.ToString() }); internal static void LootFactorChanged(object s, EventArgs e) { SelectedLootFactor = (LootFactorType)Enum.Parse(typeof(LootFactorType), ValConfig.LootDropCaluationType.Value); } private static int multiplyLootPerLevel(int level, int loot, DataObjects.DistanceLootModifier dmod, float scale_factor = 1f) { if (level == 1) { return loot; } float num = dmod.maxAmountScaleFactorBonus; if (num <= 0f) { num = 1f; } float num2 = dmod.minAmountScaleFactorBonus; if (num2 <= 0f) { num2 = 1f; } float num3 = ValConfig.PerLevelLootScale.Value * (float)level; int num4 = (int)(num3 * num2 * (float)loot * scale_factor); int num5 = (int)(num3 * num * (float)loot * scale_factor); Logger.LogDebug($"MLPL range: {num4}-{num5} using: loot_factor {num3} x {num2} or {num} x {loot} x {scale_factor}"); if (num4 == num5) { return num4; } return Random.Range(num4, num5); } private static int ExponentLootPerLevel(int level, int loot, DataObjects.DistanceLootModifier dmod, float scale_factor = 1f) { if (level == 1) { return loot; } float num = dmod.maxAmountScaleFactorBonus; if (num <= 0f) { num = 1f; } float num2 = dmod.minAmountScaleFactorBonus; if (num2 <= 0f) { num2 = 1f; } float num3 = Mathf.Pow(ValConfig.PerLevelLootScale.Value, (float)level); int num4 = (int)(num3 * num2 * (float)loot * scale_factor); int num5 = (int)(num3 * num * (float)loot * scale_factor); Logger.LogDebug($"ELPL range: {num4}-{num5} using: loot_factor {num3} x {num2} or {num} x {loot} x {scale_factor}"); if (num4 == num5) { return num4; } return Random.Range(num4, num5); } [IteratorStateMachine(typeof(<DropItemsAsync>d__8))] private static IEnumerator DropItemsAsync(List<KeyValuePair<GameObject, int>> drops, Vector3 centerPos, float dropArea) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <DropItemsAsync>d__8(0) { drops = drops, centerPos = centerPos }; } public static void SelectLootSettings(GameObject creature, out string creature_name, out DataObjects.DistanceLootModifier distance_bonus, out Biome creature_biome, out Character charc) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected I4, but got Unknown //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) Vector3 position = creature.transform.position; creature_name = ((Object)creature).name.Replace("(Clone)", ""); Vector3 val = default(Vector3); Biome val2 = default(Biome); BiomeArea val3 = default(BiomeArea); Heightmap val4 = default(Heightmap); ZoneSystem.instance.GetGroundData(ref position, ref val, ref val2, ref val3, ref val4); creature_biome = (Biome)(int)val2; float distance_from_center = Vector2.Distance(Vector2.op_Implicit(position), LevelSystem.center); distance_bonus = SelectDistanceFromCenterLootBonus(distance_from_center); charc = creature.GetComponent<Character>(); Logger.LogDebug($"{creature_name} {val2} {position}"); } private static DataObjects.DistanceLootModifier SelectDistanceFromCenterLootBonus(float distance_from_center) { DataObjects.DistanceLootModifier result = new DataObjects.DistanceLootModifier(); if (ValConfig.EnableDistanceLevelScalingBonus.Value && LootSystemData.SLS_Drop_Settings.DistanceLootModifier != null) { foreach (KeyValuePair<int, DataObjects.DistanceLootModifier> item in LootSystemData.SLS_Drop_Settings.DistanceLootModifier) { if (distance_from_center <= (float)item.Key) { Logger.LogDebug($"Distance Loot area: {item.Key}"); result = item.Value; break; } } } return result; } } internal class ModificationExtensionSystem { [HarmonyPatch(typeof(Character), "Awake")] public static class CreatureCharacterExtension { public static void Postfix(Character __instance) { SetupLevelColorSizeAndStats(__instance); } } [HarmonyPatch(typeof(Character), "SetLevel")] public static class ModifyCharacterVisualsToLevel { public static void Postfix(Character __instance) { SetupLevelColorSizeAndStats(__instance); } } [HarmonyPatch(typeof(Character), "Damage")] public static class CharacterDamageModificationApply { private static void Prefix(HitData hit, Character __instance) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) _ = hit.m_attacker; ZDO zDO = ZDOMan.instance.GetZDO(hit.m_attacker); if (zDO != null) { float @float = zDO.GetFloat("SLE_DMod", 1f); ((DamageTypes)(ref hit.m_damage)).Modify(@float); } } } [HarmonyPatch(typeof(RandomFlyingBird), "Awake")] public static class RandomFlyingBirdExtension { public static void Postfix(RandomFlyingBird __instance) { //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: 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) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) if (!ValConfig.EnableScalingBirds.Value) { return; } LevelSystem.SelectCreatureBiomeSettings(((Component)__instance).gameObject, out var creature_name, out var creature_settings, out var biome_settings, out var _); int num = LevelSystem.DetermineLevel(((Component)__instance).gameObject, creature_name, creature_settings, biome_settings); if (num <= 1) { return; } float num2 = 1f + ValConfig.BirdSizeScalePerLevel.Value * (float)num; Logger.LogDebug($"Setting bird size {num2}."); Transform transform = ((Component)__instance).transform; transform.localScale *= num2; Physics.SyncTransforms(); DropOnDestroyed component = ((Component)__instance).gameObject.GetComponent<DropOnDestroyed>(); List<DropData> list = new List<DropData>(); foreach (DropData drop in component.m_dropWhenDestroyed.m_drops) { DropData val = default(DropData); val.m_stackMin = Mathf.RoundToInt((float)drop.m_stackMin * (ValConfig.PerLevelLootScale.Value * (float)num)); val.m_stackMax = Mathf.RoundToInt((float)drop.m_stackMax * (ValConfig.PerLevelLootScale.Value * (float)num)); Logger.LogDebug($"Scaling drop {((Object)drop.m_item).name} from {drop.m_stackMin}-{drop.m_stackMax} to {val.m_stackMin}-{val.m_stackMax} for level {num}."); val.m_item = drop.m_item; list.Add(val); } component.m_dropWhenDestroyed.m_drops = list; } } [CompilerGenerated] private sealed class <DestroyCoroutine>d__4 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public float delay; public GameObject go; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <DestroyCoroutine>d__4(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitForSeconds(delay); <>1__state = 1; return true; case 1: <>1__state = -1; ZNetScene.instance.Destroy(go); return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [IteratorStateMachine(typeof(<DestroyCoroutine>d__4))] private static IEnumerator DestroyCoroutine(GameObject go, float delay = 0.2f) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <DestroyCoroutine>d__4(0) { go = go, delay = delay }; } private static void SetupLevelColorSizeAndStats(Character __instance) { //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) if (__instance.IsPlayer()) {