Decompiled source of StarLevelSystem v0.8.1
plugins/StarLevelSystem.dll
Decompiled 18 hours 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.ComponentModel; 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.Serialization.Formatters.Binary; using System.Runtime.Versioning; using System.Security.Permissions; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using JetBrains.Annotations; using Jotunn; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using MonoMod.Utils; using SimpleJson; 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.8.1")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.8.1.0")] namespace StarLevelSystem { internal class ValConfig { [CompilerGenerated] private sealed class <OnClientReceiveColorConfigs>d__60 : 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__60(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__61 : 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__61(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__59 : 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__59(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 <OnClientReceiveModifiersConfigs>d__62 : 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 <OnClientReceiveModifiersConfigs>d__62(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; CreatureModifiersData.UpdateModifierConfig(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__58 : 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__58(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"); internal static string creatureModifierFilePath = Path.Combine(Paths.ConfigPath, "StarLevelSystem", "Modifiers.yaml"); private static CustomRPC LevelSettingsRPC; private static CustomRPC ColorSettingsRPC; private static CustomRPC CreatureLootSettingsRPC; private static CustomRPC ModifiersRPC; 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> EnableScalingFish; public static ConfigEntry<float> FishSizeScalePerLevel; public static ConfigEntry<bool> EnableTreeScaling; public static ConfigEntry<float> TreeSizeScalePerLevel; public static ConfigEntry<bool> RandomizeTameChildrenLevels; public static ConfigEntry<bool> SpawnMultiplicationAppliesToTames; public static ConfigEntry<int> MaxMajorModifiersPerCreature; public static ConfigEntry<int> MaxMinorModifiersPerCreature; public static ConfigEntry<float> ChanceMajorModifier; public static ConfigEntry<float> ChanceMinorModifier; public static ConfigEntry<bool> EnableBossModifiers; public static ConfigEntry<float> ChanceOfBossModifier; public static ConfigEntry<int> MaxBossModifiersPerBoss; 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 static ConfigEntry<int> NumberOfCacheUpdatesPerFrame; public static ConfigEntry<bool> OutputColorizationGeneratorsData; 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 //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown //IL_00ab: 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)); ModifiersRPC = NetworkManager.Instance.AddRPC("LSE_ModifiersRPC", new CoroutineHandler(OnServerRecieveConfigs), new CoroutineHandler(OnClientReceiveModifiersConfigs)); SynchronizationManager.Instance.AddInitialSynchronization(LevelSettingsRPC, (Func<ZPackage>)SendLevelsConfigs); SynchronizationManager.Instance.AddInitialSynchronization(ColorSettingsRPC, (Func<ZPackage>)SendColorsConfigs); SynchronizationManager.Instance.AddInitialSynchronization(CreatureLootSettingsRPC, (Func<ZPackage>)SendCreatureLootConfigs); SynchronizationManager.Instance.AddInitialSynchronization(ModifiersRPC, (Func<ZPackage>)SendModifierConfigs); } 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", 20, "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.", advanced: false, 0f, 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); RandomizeTameChildrenLevels = BindServerConfig("LevelSystems", "RandomizeTameLevels", value: false, "Randomly rolls bred creature levels, instead of inheriting from parent."); SpawnMultiplicationAppliesToTames = BindServerConfig("LevelSystems", "SpawnMultiplicationAppliesToTames", value: false, "Spawn multipliers set on creature or biome will apply to produced tames when enabled."); 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); EnableScalingFish = BindServerConfig("LevelSystem", "EnableScalingFish", value: true, "Enables star scaling for fish. This does potentially allow huge fish."); FishSizeScalePerLevel = BindServerConfig("LevelSystem", "FishSizeScalePerLevel", 0.1f, "The amount of size that fish gain per level 0.1 = 10% larger per level."); EnableTreeScaling = BindServerConfig("LevelSystem", "EnableTreeScaling", value: true, "Enables level scaling of trees. Make the trees bigger than reasonable? sure why not."); TreeSizeScalePerLevel = BindServerConfig("LevelSystem", "TreeSizeScalePerLevel", 0.1f, "The amount of size that trees gain per level 0.1 = 10% larger per level."); 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); MaxMajorModifiersPerCreature = BindServerConfig("Modifiers", "DefaultMajorModifiersPerCreature", 1, "The default number of major modifiers that a creature can have."); MaxMinorModifiersPerCreature = BindServerConfig("Modifiers", "MaxMinorModifiersPerCreature", 1, "The default number of minor modifiers that a creature can have."); ChanceMajorModifier = BindServerConfig("Modifiers", "ChanceMajorModifier", 0.15f, "The chance that a creature will have a major modifier (creatures can have BOTH major and minor modifiers).", advanced: false, 0f, 1f); ChanceMinorModifier = BindServerConfig("Modifiers", "ChanceMinorModifier", 0.25f, "The chance that a creature will have a minor modifier (creatures can have BOTH major and minor modifiers).", advanced: false, 0f, 1f); EnableBossModifiers = BindServerConfig("Modifiers", "EnableBossModifiers", value: true, "Wether or not bosses can spawn with modifiers."); ChanceOfBossModifier = BindServerConfig("Modifiers", "ChanceOfBossModifier", 0.75f, "The chance that a boss will have a modifier.", advanced: false, 0f, 1f); MaxBossModifiersPerBoss = BindServerConfig("Modifiers", "MaxBossModifiersPerBoss", 2, "The maximum number of modifiers that a boss can have."); NumberOfCacheUpdatesPerFrame = BindServerConfig("Misc", "NumberOfCacheUpdatesPerFrame", 10, "Number of cache updates to process when performing live updates", advanced: true, 1); OutputColorizationGeneratorsData = BindServerConfig("Misc", "OutputColorizationGeneratorsData", value: false, "Writes out color generators to a debug file. This can be useful if you want to hand pick color settings from generated values."); } internal void LoadYamlConfigs() { string[] files = Directory.GetFiles(GetSecondaryConfigDirectoryPath()); bool flag = false; bool flag2 = false; bool flag3 = false; bool flag4 = 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 (text.Contains("Modifiers.yaml")) { Logger.LogDebug("Found modifier configuration: " + text); creatureModifierFilePath = text; flag4 = true; } } if (!flag4) { Logger.LogDebug("Loot config missing, recreating."); using StreamWriter streamWriter = new StreamWriter(creatureModifierFilePath); string value = "#################################################\n# Star Level System Expanded - Creature loot configuration\n#################################################\n"; streamWriter.WriteLine(value); streamWriter.WriteLine(CreatureModifiersData.GetModifierDefaultConfig()); } if (!flag3) { Logger.LogDebug("Loot config missing, recreating."); using StreamWriter streamWriter2 = new StreamWriter(creatureLootFilePath); string value2 = "#################################################\n# Star Level System Expanded - Creature loot configuration\n#################################################\n"; streamWriter2.WriteLine(value2); streamWriter2.WriteLine(LootSystemData.YamlDefaultConfig()); } if (!flag) { Logger.LogDebug("Level config file missing, recreating."); using StreamWriter streamWriter3 = new StreamWriter(levelsFilePath); string value3 = "#################################################\n# Star Level System Expanded - Level Settings\n#################################################\n"; streamWriter3.WriteLine(value3); streamWriter3.WriteLine(LevelSystemData.YamlDefaultConfig()); } if (!flag2) { Logger.LogDebug("Color config file missing, recreating."); using StreamWriter streamWriter4 = new StreamWriter(colorsFilePath); string value4 = "#################################################\n# Star Level System Expanded - Creature Level Color Settings\n#################################################\n"; streamWriter4.WriteLine(value4); streamWriter4.WriteLine(Colorization.YamlDefaultConfig()); } SetupFileWatcher("ColorSettings.yaml"); SetupFileWatcher("LevelSettings.yaml"); SetupFileWatcher("Modifiers.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; case "Modifiers.yaml": Logger.LogDebug("Triggering Modifiers Settings update."); ModifiersRPC.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); } private static ZPackage SendModifierConfigs() { return SendFileAsZPackage(creatureModifierFilePath); } [IteratorStateMachine(typeof(<OnServerRecieveConfigs>d__58))] public static IEnumerator OnServerRecieveConfigs(long sender, ZPackage package) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <OnServerRecieveConfigs>d__58(0); } [IteratorStateMachine(typeof(<OnClientReceiveLevelConfigs>d__59))] private static IEnumerator OnClientReceiveLevelConfigs(long sender, ZPackage package) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <OnClientReceiveLevelConfigs>d__59(0) { package = package }; } [IteratorStateMachine(typeof(<OnClientReceiveColorConfigs>d__60))] private static IEnumerator OnClientReceiveColorConfigs(long sender, ZPackage package) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <OnClientReceiveColorConfigs>d__60(0) { package = package }; } [IteratorStateMachine(typeof(<OnClientReceiveCreatureLootConfigs>d__61))] private static IEnumerator OnClientReceiveCreatureLootConfigs(long sender, ZPackage package) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <OnClientReceiveCreatureLootConfigs>d__61(0) { package = package }; } [IteratorStateMachine(typeof(<OnClientReceiveModifiersConfigs>d__62))] private static IEnumerator OnClientReceiveModifiersConfigs(long sender, ZPackage package) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <OnClientReceiveModifiersConfigs>d__62(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.8.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] [BepInIncompatibility("org.bepinex.plugins.creaturelevelcontrol")] internal class StarLevelSystem : BaseUnityPlugin { public const string PluginGUID = "MidnightsFX.StarLevelSystem"; public const string PluginName = "StarLevelSystem"; public const string PluginVersion = "0.8.1"; public ValConfig cfg; public static CustomLocalization Localization = LocalizationManager.Instance.GetLocalization(); public static AssetBundle EmbeddedResourceBundle; 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(); EmbeddedResourceBundle = AssetUtils.LoadAssetBundleFromResources("StarLevelSystem.assets.starlevelsystems", typeof(StarLevelSystem).Assembly); HarmonyInstance = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "MidnightsFX.StarLevelSystem"); Colorization.Init(); LevelSystemData.Init(); LootSystemData.Init(); CreatureModifiersData.Init(); LocalizationLoader.AddLocalizations(); PrefabManager.OnVanillaPrefabsAvailable += CreatureModifiersData.LoadPrefabs; PrefabManager.OnVanillaPrefabsAvailable += LevelSystem.UpdateMaxLevel; PrefabManager.OnPrefabsRegistered += LootSystemData.AttachPrefabsWhenReady; TerminalCommands.AddCommands(); } } } namespace StarLevelSystem.modules { 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, CharacterColorGenerators = ColorizationData.defaultColorGenerators }; public static DataObjects.ColorDef defaultColorization = new DataObjects.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); foreach (KeyValuePair<int, DataObjects.ColorDef> item in defaultColorizationSettings.defaultLevelColorization) { if (!creatureColorizationSettings.defaultLevelColorization.Keys.Contains(item.Key)) { creatureColorizationSettings.defaultLevelColorization.Add(item.Key, item.Value); } } if (creatureColorizationSettings.CharacterColorGenerators != null) { Logger.LogInfo("Running color generators"); foreach (KeyValuePair<string, List<DataObjects.ColorRangeDef>> characterColorGenerator in creatureColorizationSettings.CharacterColorGenerators) { Logger.LogInfo("Building color range for " + characterColorGenerator.Key); foreach (DataObjects.ColorRangeDef item2 in characterColorGenerator.Value) { BuildAddColorRange(characterColorGenerator.Key, item2); } } if (ValConfig.OutputColorizationGeneratorsData.Value) { File.WriteAllText(Path.Combine(Paths.ConfigPath, "StarLevelSystem", "DebugGeneratedColorValues.yaml"), DataObjects.yamlserializer.Serialize((object)creatureColorizationSettings)); } } Logger.LogInfo("Updated ColorizationSettings."); Character[] array = Resources.FindObjectsOfTypeAll<Character>(); foreach (Character val in array) { if (val.m_level > 1) { DataObjects.CreatureDetailCache andSetDetailCache = CompositeLazyCache.GetAndSetDetailCache(val, update: true); ApplyColorizationWithoutLevelEffects(((Component)val).gameObject, andSetDetailCache.Colorization); } } } 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 DataObjects.ColorDef DetermineCharacterColorization(Character cgo, int level) { if ((Object)(object)cgo == (Object)null) { return null; } string prefabName = Utils.GetPrefabName(((Component)cgo).gameObject); if (creatureColorizationSettings.characterSpecificColorization.ContainsKey(prefabName) && creatureColorizationSettings.characterSpecificColorization[prefabName].ContainsKey(level - 1) && creatureColorizationSettings.characterSpecificColorization[prefabName].TryGetValue(level - 1, out var value)) { return value; } return GetDefaultColorization(level - 1); } internal static void ApplyColorizationWithoutLevelEffects(GameObject cgo, DataObjects.ColorDef colorization) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown //IL_0086: Unknown result type (might be due to invalid IL or missing references) LevelSetup val = colorization.toLevelEffect(); try { SkinnedMeshRenderer[] componentsInChildren = cgo.gameObject.GetComponentsInChildren<SkinnedMeshRenderer>(); foreach (SkinnedMeshRenderer val2 in componentsInChildren) { Material[] sharedMaterials = ((Renderer)val2).sharedMaterials; if (sharedMaterials.Length != 0) { 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)val2).sharedMaterials = sharedMaterials; } } } catch (Exception arg) { Logger.LogError($"Exception while colorizing {arg}"); } } internal static void BuildAddColorRange(string creatureKey, DataObjects.ColorRangeDef colorGen) { float num = Mathf.Abs(colorGen.EndColorDef.hue) + Mathf.Abs(colorGen.StartColorDef.hue); Mathf.Clamp(num, 0f, 2f); float num2 = Mathf.Abs(colorGen.EndColorDef.saturation) + Mathf.Abs(colorGen.StartColorDef.saturation); Mathf.Clamp(num2, 0f, 2f); float num3 = Mathf.Abs(colorGen.EndColorDef.value) + Mathf.Abs(colorGen.StartColorDef.value); Mathf.Clamp(num3, 0f, 2f); int num4 = colorGen.RangeEnd - colorGen.RangeStart; float num5 = num / (float)num4; float num6 = num2 / (float)num4; float num7 = num3 / (float)num4; int num8 = ((!(colorGen.StartColorDef.hue > colorGen.EndColorDef.hue)) ? 1 : (-1)); int num9 = ((!(colorGen.StartColorDef.saturation > colorGen.EndColorDef.saturation)) ? 1 : (-1)); int num10 = ((!(colorGen.StartColorDef.value > colorGen.EndColorDef.value)) ? 1 : (-1)); if (colorGen.CharacterSpecific && !creatureColorizationSettings.characterSpecificColorization.ContainsKey(creatureKey)) { creatureColorizationSettings.characterSpecificColorization.Add(creatureKey, new Dictionary<int, DataObjects.ColorDef>()); } int num11 = colorGen.RangeStart; int num12 = 0; while (num11 < colorGen.RangeEnd + 1) { DataObjects.ColorDef value = new DataObjects.ColorDef { hue = colorGen.StartColorDef.hue + num5 * (float)num12 * (float)num8, saturation = colorGen.StartColorDef.saturation + num6 * (float)num12 * (float)num9, value = colorGen.StartColorDef.value + num7 * (float)num12 * (float)num10, is_emissive = false }; if (colorGen.CharacterSpecific) { if (!creatureColorizationSettings.characterSpecificColorization.ContainsKey(creatureKey)) { creatureColorizationSettings.characterSpecificColorization.Add(creatureKey, new Dictionary<int, DataObjects.ColorDef>()); } if (creatureColorizationSettings.characterSpecificColorization[creatureKey].ContainsKey(num11)) { if (colorGen.OverwriteExisting) { creatureColorizationSettings.characterSpecificColorization[creatureKey][num11] = value; } } else { creatureColorizationSettings.characterSpecificColorization[creatureKey].Add(num11, value); } } else if (creatureColorizationSettings.defaultLevelColorization.ContainsKey(num11)) { if (colorGen.OverwriteExisting) { creatureColorizationSettings.defaultLevelColorization[num11] = value; } } else { creatureColorizationSettings.defaultLevelColorization.Add(num11, value); } num11++; num12++; } } 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 DataObjects.ColorDef GetDefaultColorization(int level) { if (creatureColorizationSettings.defaultLevelColorization.ContainsKey(level)) { return creatureColorizationSettings.defaultLevelColorization[level]; } return defaultColorization; } } internal static class Compatibility { } public static class CreatureModifiers { private static readonly List<DataObjects.NameSelectionStyle> prefixSelectors = new List<DataObjects.NameSelectionStyle> { DataObjects.NameSelectionStyle.RandomFirst, DataObjects.NameSelectionStyle.RandomBoth }; private static readonly List<DataObjects.NameSelectionStyle> suffixSelectors = new List<DataObjects.NameSelectionStyle> { DataObjects.NameSelectionStyle.RandomLast, DataObjects.NameSelectionStyle.RandomBoth }; public static Dictionary<CreatureModifiersData.ModifierNames, DataObjects.ModifierType> SetupBossModifiers(Character character, DataObjects.CreatureDetailCache cacheEntry, int max_mods, float chance) { Dictionary<CreatureModifiersData.ModifierNames, DataObjects.ModifierType> dictionary = new Dictionary<CreatureModifiersData.ModifierNames, DataObjects.ModifierType>(); foreach (CreatureModifiersData.ModifierNames item in SelectOrLoadModifiers(character, cacheEntry, max_mods, chance, DataObjects.ModifierType.Boss)) { if (item == CreatureModifiersData.ModifierNames.None) { continue; } if (!CreatureModifiersData.ActiveCreatureModifiers.BossModifiers.ContainsKey(item)) { Logger.LogWarning($"Major modifier {item} not found in CreatureModifiersData, skipping setup for {((Object)character).name}"); continue; } dictionary.Add(item, DataObjects.ModifierType.Boss); cacheEntry.Modifiers = dictionary; DataObjects.CreatureModifier creatureModifier = CreatureModifiersData.ActiveCreatureModifiers.BossModifiers[item]; creatureModifier.LoadAndSetGameObjects(); creatureModifier.SetupMethodCall(character, creatureModifier.Config, cacheEntry); SetupCreatureVFX(character, creatureModifier); if (creatureModifier.NamePrefixes != null && prefixSelectors.Contains(creatureModifier.namingConvention)) { cacheEntry.ModifierPrefixNames.Add(item, creatureModifier.NamePrefixes); } if (creatureModifier.NameSuffixes != null && suffixSelectors.Contains(creatureModifier.namingConvention)) { cacheEntry.ModifierSuffixNames.Add(item, creatureModifier.NameSuffixes); } } return dictionary; } public static Dictionary<CreatureModifiersData.ModifierNames, DataObjects.ModifierType> SetupModifiers(Character character, DataObjects.CreatureDetailCache cacheEntry, int num_major_mods, int num_minor_mods, float chanceMajor, float chanceMinor) { Dictionary<CreatureModifiersData.ModifierNames, DataObjects.ModifierType> dictionary = new Dictionary<CreatureModifiersData.ModifierNames, DataObjects.ModifierType>(); if (num_major_mods > 0) { foreach (CreatureModifiersData.ModifierNames item in SelectOrLoadModifiers(character, cacheEntry, num_major_mods, chanceMajor)) { if (item == CreatureModifiersData.ModifierNames.None) { continue; } if (!CreatureModifiersData.ActiveCreatureModifiers.MajorModifiers.ContainsKey(item)) { Logger.LogWarning($"Major modifier {item} not found in CreatureModifiersData, skipping setup for {((Object)character).name}"); continue; } dictionary.Add(item, DataObjects.ModifierType.Major); cacheEntry.Modifiers = dictionary; DataObjects.CreatureModifier creatureModifier = CreatureModifiersData.ActiveCreatureModifiers.MajorModifiers[item]; creatureModifier.SetupMethodCall(character, creatureModifier.Config, cacheEntry); SetupCreatureVFX(character, creatureModifier); if (creatureModifier.NamePrefixes != null && prefixSelectors.Contains(creatureModifier.namingConvention)) { cacheEntry.ModifierPrefixNames.Add(item, creatureModifier.NamePrefixes); } if (creatureModifier.NameSuffixes != null && suffixSelectors.Contains(creatureModifier.namingConvention)) { cacheEntry.ModifierSuffixNames.Add(item, creatureModifier.NameSuffixes); } } } if (num_minor_mods > 0) { foreach (CreatureModifiersData.ModifierNames item2 in SelectOrLoadModifiers(character, cacheEntry, num_minor_mods, chanceMinor, DataObjects.ModifierType.Minor)) { if (!CreatureModifiersData.ActiveCreatureModifiers.MinorModifiers.ContainsKey(item2)) { if (item2 != 0) { Logger.LogWarning($"Minor modifier {item2} not found in CreatureModifiersData, skipping setup for {((Object)character).name}"); } continue; } dictionary.Add(item2, DataObjects.ModifierType.Minor); cacheEntry.Modifiers = dictionary; DataObjects.CreatureModifier creatureModifier2 = CreatureModifiersData.ActiveCreatureModifiers.MinorModifiers[item2]; creatureModifier2.SetupMethodCall(character, creatureModifier2.Config, cacheEntry); SetupCreatureVFX(character, creatureModifier2); if (creatureModifier2.NamePrefixes != null && prefixSelectors.Contains(creatureModifier2.namingConvention)) { cacheEntry.ModifierPrefixNames.Add(item2, creatureModifier2.NamePrefixes); } if (creatureModifier2.NameSuffixes != null && suffixSelectors.Contains(creatureModifier2.namingConvention)) { cacheEntry.ModifierSuffixNames.Add(item2, creatureModifier2.NameSuffixes); } } } return dictionary; } internal static void SetupCreatureVFX(Character character, DataObjects.CreatureModifier cmodifier) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0163: 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) if (cmodifier.VisualEffect == null) { return; } GameObject val = CreatureModifiersData.LoadedModifierEffects[cmodifier.VisualEffect]; bool flag = Object.op_Implicit((Object)(object)((Component)character).transform.Find(((Object)val).name + "(Clone)")); string name = ((Object)character).name; ZDOID zDOID = character.GetZDOID(); Logger.LogDebug($"Setting up visual effect for {name} {((ZDOID)(ref zDOID)).ID} - {flag}"); if (!flag) { Logger.LogDebug("Adding visual effects for " + ((Object)character).name); GameObject val2 = Object.Instantiate<GameObject>(val, ((Component)character).transform); float height = character.GetHeight(); float num = height / 5f; float num2 = character.GetRadius() / 2f; switch (cmodifier.VisualEffectStyle) { case DataObjects.VisualEffectStyle.top: val2.transform.localPosition = new Vector3(0f, height, 0f); break; case DataObjects.VisualEffectStyle.bottom: val2.transform.localPosition = new Vector3(0f, 0f, 0f); break; case DataObjects.VisualEffectStyle.objectCenter: val2.transform.localPosition = new Vector3(0f, height / 2f, 0f); break; } val2.transform.localScale = new Vector3(val2.transform.localScale.x * num, val2.transform.localScale.y * num2, val2.transform.localScale.z * num); } } internal static string CheckOrBuildCreatureName(Character chara, DataObjects.CreatureDetailCache cacheEntry, bool useChache = true) { if (cacheEntry.CreatureDisabledInBiome || cacheEntry == null) { return Localization.instance.Localize(chara.m_name); } string @string = chara.m_nview.GetZDO().GetString("SLE_Name", ""); if (@string == "" || !useChache) { string text = ""; CreatureModifiersData.ModifierNames modifierNames = CreatureModifiersData.ModifierNames.None; if (cacheEntry.ModifierPrefixNames != null && cacheEntry.ModifierPrefixNames.Count > 0) { KeyValuePair<CreatureModifiersData.ModifierNames, List<string>> keyValuePair = Extensions.RandomEntry(cacheEntry.ModifierPrefixNames); modifierNames = keyValuePair.Key; text = keyValuePair.Value[Random.Range(0, keyValuePair.Value.Count - 1)]; } string text2 = ""; if (cacheEntry.ModifierSuffixNames != null && cacheEntry.ModifierSuffixNames.Count > 0) { KeyValuePair<CreatureModifiersData.ModifierNames, List<string>> keyValuePair2 = ((modifierNames == CreatureModifiersData.ModifierNames.None) ? Extensions.RandomEntry(cacheEntry.ModifierSuffixNames) : Extensions.RandomEntry(cacheEntry.ModifierSuffixNames, new List<CreatureModifiersData.ModifierNames> { modifierNames })); if (keyValuePair2.Value != null) { text2 = keyValuePair2.Value[Random.Range(0, keyValuePair2.Value.Count - 1)]; } } Tameable component = ((Component)chara).GetComponent<Tameable>(); string text3 = chara.m_name; if (Object.op_Implicit((Object)(object)component)) { text3 = component.GetHoverName(); } @string = text + " " + text3 + " " + text2; chara.m_nview.GetZDO().Set("SLE_Name", @string); Logger.LogDebug("Setting creature name for " + ((Object)chara).name + " to " + @string); return Localization.instance.Localize(@string.Trim()); } return Localization.instance.Localize(@string); } public static List<CreatureModifiersData.ModifierNames> SelectOrLoadModifiers(Character character, DataObjects.CreatureDetailCache cdc, int num_mods, float chanceForMod, DataObjects.ModifierType modType = DataObjects.ModifierType.Major) { //IL_0040: Unknown result type (might be due to invalid IL or missing references) DataObjects.ListModifierZNetProperty listModifierZNetProperty = new DataObjects.ListModifierZNetProperty($"SLS_{modType}_MODS", character.m_nview, new List<CreatureModifiersData.ModifierNames>()); List<CreatureModifiersData.ModifierNames> list = listModifierZNetProperty.Get(); if (list.Count > 0) { return list; } List<CreatureModifiersData.ModifierNames> list2 = SelectCreatureModifiers(Utils.GetPrefabName(((Component)character).gameObject), cdc.Biome, chanceForMod, num_mods, modType); listModifierZNetProperty.Set(list2); return list2; } public static List<CreatureModifiersData.ModifierNames> SelectCreatureModifiers(string creature, Biome biome, float chance, int num_mods, DataObjects.ModifierType type = DataObjects.ModifierType.Major) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) List<CreatureModifiersData.ModifierNames> selectedModifiers = new List<CreatureModifiersData.ModifierNames>(); List<DataObjects.ProbabilityEntry> probabilities = CreatureModifiersData.LazyCacheCreatureModifierSelect(creature, biome, type); if (probabilities.Count == 0) { return selectedModifiers; } num_mods.Times(delegate { if (chance < 1f) { if (Random.value < chance) { selectedModifiers.Add(RandomSelect.RandomSelectFromWeightedList(probabilities)); } } else { selectedModifiers.Add(RandomSelect.RandomSelectFromWeightedList(probabilities)); } }); if (selectedModifiers.Count == 0) { selectedModifiers.Add(CreatureModifiersData.ModifierNames.None); } return selectedModifiers; } public static void AddCreatureModifier(Character character, DataObjects.ModifierType modType, CreatureModifiersData.ModifierNames newModifier) { //IL_0164: Unknown result type (might be due to invalid IL or missing references) DataObjects.ListModifierZNetProperty listModifierZNetProperty = new DataObjects.ListModifierZNetProperty($"SLS_{modType}_MODS", character.m_nview, new List<CreatureModifiersData.ModifierNames>()); List<CreatureModifiersData.ModifierNames> list = listModifierZNetProperty.Get(); if (list.Count > 0 && list.Contains(newModifier)) { Logger.LogDebug($"{((Object)character).name} already has {newModifier}, skipping."); return; } list.Add(newModifier); listModifierZNetProperty.Set(list); Logger.LogDebug("Adding Modifier to ZDO."); DataObjects.CreatureDetailCache andSetDetailCache = CompositeLazyCache.GetAndSetDetailCache(character); DataObjects.CreatureModifier modifierDef = CreatureModifiersData.GetModifierDef(newModifier, modType); Logger.LogDebug("Setting up modifier."); modifierDef.SetupMethodCall(character, modifierDef.Config, andSetDetailCache); SetupCreatureVFX(character, modifierDef); Logger.LogDebug("Updating naming monikers."); if (modifierDef.NamePrefixes != null && prefixSelectors.Contains(modifierDef.namingConvention)) { Logger.LogDebug("Adding prefix names."); if (!andSetDetailCache.ModifierPrefixNames.ContainsKey(newModifier)) { andSetDetailCache.ModifierPrefixNames.Add(newModifier, modifierDef.NamePrefixes); } } if (modifierDef.NameSuffixes != null && suffixSelectors.Contains(modifierDef.namingConvention)) { Logger.LogDebug("Adding suffix names."); if (!andSetDetailCache.ModifierSuffixNames.ContainsKey(newModifier)) { andSetDetailCache.ModifierSuffixNames.Add(newModifier, modifierDef.NameSuffixes); } } Logger.LogDebug("Updating character cache entry."); andSetDetailCache.Modifiers.Add(newModifier, modType); CompositeLazyCache.UpdateCacheEntry(character, andSetDetailCache); Logger.LogDebug("Rebuilding Character UI"); CheckOrBuildCreatureName(character, andSetDetailCache, useChache: false); LevelUI.InvalidateCacheEntry(character.GetZDOID()); } } public static class LevelSystem { [HarmonyPatch(typeof(Fish), "Awake")] public static class RandomFishLevelExtension { public static void Postfix(Fish __instance) { //IL_00e3: 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) if (ValConfig.EnableScalingFish.Value && !((Object)(object)__instance.m_nview == (Object)null) && __instance.m_nview.GetZDO() != null) { int num = __instance.m_nview.GetZDO().GetInt("SLE_Fish", 0); if (num == 0) { SelectCreatureBiomeSettings(((Component)__instance).gameObject, out var creature_name, out var creature_settings, out var biome_settings, out var _); num = DetermineLevel(((Component)__instance).gameObject, creature_name, creature_settings, biome_settings); __instance.m_nview.GetZDO().Set("SLE_Fish", num); ((Component)__instance).GetComponent<ItemDrop>().SetQuality(num); ((Component)__instance).GetComponent<ItemDrop>().m_itemData.m_shared.m_maxQuality = num + 1; } if (num > 1) { float num2 = 1f + ValConfig.FishSizeScalePerLevel.Value * (float)num; ((Component)__instance).GetComponent<ItemDrop>().SetQuality(num); ((Component)__instance).GetComponent<ItemDrop>().m_itemData.m_shared.m_maxQuality = num + 1; Transform transform = ((Component)__instance).transform; transform.localScale *= num2; Physics.SyncTransforms(); } } } } [HarmonyPatch(typeof(TreeBase), "Awake")] public static class RandomTreeLevelExtension { public static void Postfix(TreeBase __instance) { //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0121: 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) if (!ValConfig.EnableTreeScaling.Value) { return; } int num = __instance.m_nview.GetZDO().GetInt("SLE_Tree", 0); if (num == 0) { SelectCreatureBiomeSettings(((Component)__instance).gameObject, out var creature_name, out var creature_settings, out var biome_settings, out var _); num = DetermineLevel(((Component)__instance).gameObject, creature_name, creature_settings, biome_settings); __instance.m_nview.GetZDO().Set("SLE_Tree", num); } if (num <= 1) { return; } float num2 = 1f + ValConfig.TreeSizeScalePerLevel.Value * (float)num; __instance.m_health += __instance.m_health * 0.1f * (float)num; Transform transform = ((Component)__instance).transform; transform.localScale *= num2; List<DropData> list = new List<DropData>(); foreach (DropData drop in __instance.m_dropWhenDestroyed.m_drops) { DropData item = default(DropData); item.m_stackMin = Mathf.RoundToInt((float)drop.m_stackMin * (ValConfig.PerLevelLootScale.Value * (float)num)); item.m_stackMax = Mathf.RoundToInt((float)drop.m_stackMax * (ValConfig.PerLevelLootScale.Value * (float)num)); item.m_item = drop.m_item; list.Add(item); } Physics.SyncTransforms(); } } [HarmonyPatch(typeof(TreeLog))] public static class SetTreeLogPassLevel { [HarmonyTranspiler] [HarmonyPatch("Destroy")] 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_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: 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_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Expected O, but got Unknown //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Expected O, but got Unknown //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Expected O, but got Unknown //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Expected O, but got Unknown //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null); val.MatchStartForward((CodeMatch[])(object)new CodeMatch[4] { new CodeMatch((OpCode?)OpCodes.Call, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Call, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(ZNetScene), "Destroy", (Type[])null, (Type[])null), (string)null) }).RemoveInstructions(4).MatchStartForward((CodeMatch[])(object)new CodeMatch[4] { new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(TreeLog), "m_subLogPrefab"), (string)null), new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)null, (string)null) }) .Advance(1) .RemoveInstructions(10) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[3] { new CodeInstruction(OpCodes.Ldloc_S, (object)(byte)10), new CodeInstruction(OpCodes.Ldloc_S, (object)(byte)11), Transpilers.EmitDelegate<Action<TreeLog, Transform, Quaternion>>((Action<TreeLog, Transform, Quaternion>)SetupTreeLog) }) .ThrowIfNotMatch("Unable to patch Tree Log Child Spawn Set Level.", Array.Empty<CodeMatch>()); return val.Instructions(); } [HarmonyPatch("Awake")] [HarmonyPostfix] private static void SetupAwakeLog(TreeLog __instance) { int @int = __instance.m_nview.GetZDO().GetInt("SLE_Tree", 1); UpdateDrops(__instance, @int); __instance.m_health += __instance.m_health * 0.1f * (float)@int; ImpactEffect component = ((Component)__instance).GetComponent<ImpactEffect>(); if (component != null) { ((DamageTypes)(ref component.m_damages)).Modify(1f + 0.1f * (float)@int); } } [HarmonyPatch("Destroy")] [HarmonyPostfix] internal static void RemoveTreeLogInst(TreeLog __instance) { Logger.LogDebug("Destroying Treelog"); ZNetScene.instance.Destroy(((Component)__instance).gameObject); } internal static void SetupTreeLog(TreeLog instance, Transform tform, Quaternion qt) { //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_0027: Unknown result type (might be due to invalid IL or missing references) GameObject obj = Object.Instantiate<GameObject>(instance.m_subLogPrefab, tform.position, qt); ZNetView component = obj.GetComponent<ZNetView>(); TreeLog component2 = obj.GetComponent<TreeLog>(); component.SetLocalScale(((Component)instance).transform.localScale); int num = 1; if (instance.m_nview.GetZDO() != null) { Logger.LogDebug("Checking stored Zvalue for tree level"); num = instance.m_nview.GetZDO().GetInt("SLE_Tree", 1); } Logger.LogDebug($"Got Tree level {num}"); UpdateDrops(component2, num); component2.m_health += component2.m_health * 0.1f * (float)num; ImpactEffect component3 = obj.GetComponent<ImpactEffect>(); if (component3 != null) { ((DamageTypes)(ref component3.m_damages)).Modify(1f + 0.1f * (float)num); } Logger.LogDebug($"Setting tree level {num}"); component.GetZDO().Set("SLE_Tree", num); ZNetScene.instance.Destroy(((Component)instance).gameObject); } internal static void UpdateDrops(TreeLog log, int level) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) if (log.m_dropWhenDestroyed == null || log.m_dropWhenDestroyed.m_drops == null || level == 1) { return; } List<DropData> list = new List<DropData>(); Logger.LogDebug($"Updating Drops for tree to: {level}"); foreach (DropData drop in log.m_dropWhenDestroyed.m_drops) { DropData item = default(DropData); item.m_stackMin = Mathf.RoundToInt((float)drop.m_stackMin * (ValConfig.PerLevelLootScale.Value * (float)level)); item.m_stackMax = Mathf.RoundToInt((float)drop.m_stackMax * (ValConfig.PerLevelLootScale.Value * (float)level)); item.m_item = drop.m_item; list.Add(item); } log.m_dropWhenDestroyed.m_drops = list; } } [HarmonyPatch(typeof(RandomFlyingBird), "Awake")] public static class RandomFlyingBirdExtension { public static void Postfix(RandomFlyingBird __instance) { //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0118: 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 (!ValConfig.EnableScalingBirds.Value) { return; } int num = __instance.m_nview.GetZDO().GetInt("SLE_Bird", 0); if (num == 0) { SelectCreatureBiomeSettings(((Component)__instance).gameObject, out var creature_name, out var creature_settings, out var biome_settings, out var _); num = DetermineLevel(((Component)__instance).gameObject, creature_name, creature_settings, biome_settings); __instance.m_nview.GetZDO().Set("SLE_Bird", num); } if (num <= 1) { return; } float num2 = 1f + ValConfig.BirdSizeScalePerLevel.Value * (float)num; 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 item = default(DropData); item.m_stackMin = Mathf.RoundToInt((float)drop.m_stackMin * (ValConfig.PerLevelLootScale.Value * (float)num)); item.m_stackMax = Mathf.RoundToInt((float)drop.m_stackMax * (ValConfig.PerLevelLootScale.Value * (float)num)); item.m_item = drop.m_item; list.Add(item); } component.m_dropWhenDestroyed.m_drops = list; } } [HarmonyPatch(typeof(Growup))] public static class SetGrowUpLevel { [HarmonyTranspiler] [HarmonyPatch("GrowUpdate")] 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_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null); val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(Character), "SetLevel", (Type[])null, (Type[])null), (string)null) }).RemoveInstructions(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate<Action<Character, int>>((Action<Character, int>)SetupGrownUp) }) .ThrowIfNotMatch("Unable to patch child grow up level set.", Array.Empty<CodeMatch>()); return val.Instructions(); } internal static void SetupGrownUp(Character grownup, int level) { ModificationExtensionSystem.CreatureSetup(grownup, refresh_cache: true, level); } } [HarmonyPatch(typeof(Procreation))] public static class SetChildLevel { [HarmonyTranspiler] [HarmonyPatch("Procreate")] 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_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: 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_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null); val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(Tameable), "IsTamed", (Type[])null, (Type[])null), (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(Character), "SetTamed", (Type[])null, (Type[])null), (string)null) }).RemoveInstructions(15).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[3] { new CodeInstruction(OpCodes.Ldloc, (object)(byte)6), new CodeInstruction(OpCodes.Ldarg_0, (object)null), Transpilers.EmitDelegate<Action<Character, Procreation>>((Action<Character, Procreation>)SetupChildCharacter) }) .ThrowIfNotMatch("Unable to patch child spawn level set.", Array.Empty<CodeMatch>()); return val.Instructions(); } internal static void SetupChildCharacter(Character chara, Procreation proc) { Logger.LogDebug("Setting child level for " + chara.m_name); if (!ValConfig.RandomizeTameChildrenLevels.Value) { int num = Mathf.Max(proc.m_character.GetLevel(), proc.m_minOffspringLevel); Logger.LogDebug($"character specific level {num} being used for child."); ModificationExtensionSystem.CreatureSetup(chara, refresh_cache: true, num); chara.SetTamed(true); } if (!ValConfig.SpawnMultiplicationAppliesToTames.Value && chara.m_nview.GetZDO() != null) { Logger.LogDebug("Disabling spawn multiplier for tamed child."); chara.m_nview.GetZDO().Set("SLS_DSpwnMlt", true); } } } [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 DetermineLevelSetAndRetrieve(Character character, ZDO cZDO, DataObjects.CreatureSpecificSetting creature_settings, DataObjects.BiomeSpecificSetting biome_settings, int leveloverride = 0) { //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)character == (Object)null || cZDO == null) { Logger.LogWarning("Creature null or nview null, cannot set level."); return 0; } if (leveloverride > 0) { cZDO.Set(ZDOVars.s_level, leveloverride, false); character.m_level = leveloverride; return leveloverride; } if (character.IsTamed()) { _ = ValConfig.RandomizeTameChildrenLevels.Value; } int @int = cZDO.GetInt(ZDOVars.s_level, 0); if (@int <= 0) { int maxLevel = ValConfig.MaxLevel.Value + 1; if (biome_settings != null && biome_settings.BiomeMaxLevelOverride != 0) { maxLevel = biome_settings.BiomeMaxLevelOverride; } if (creature_settings != null && creature_settings.CreatureMaxLevelOverride > -1) { maxLevel = creature_settings.CreatureMaxLevelOverride; } float roll = Random.Range(0f, 100f); float distance_from_center = Vector2.Distance(Vector2.op_Implicit(((Component)character).transform.position), center); float distance_influence = 1f; SortedDictionary<int, float> levelup_bonus = new SortedDictionary<int, float>(); SortedDictionary<int, float> defaultCreatureLevelUpChance = LevelSystemData.SLE_Level_Settings.DefaultCreatureLevelUpChance; if (biome_settings != null) { distance_influence = biome_settings.DistanceScaleModifier; } if (ValConfig.EnableDistanceLevelScalingBonus.Value && LevelSystemData.SLE_Level_Settings.DistanceLevelBonus != null) { levelup_bonus = SelectDistanceFromCenterLevelBonus(distance_from_center); } int num = (character.m_level = DetermineLevelRollResult(roll, maxLevel, defaultCreatureLevelUpChance, levelup_bonus, distance_influence)); cZDO.Set(ZDOVars.s_level, num, false); character.SetupMaxHealth(); return num; } return @int; } 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) && creature_settings.CustomCreatureLevelUpChance != null) { if (creature_settings.CreatureMaxLevelOverride > -1) { 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); } if (biome_settings != null) { if (biome_settings.BiomeMaxLevelOverride > 0) { 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); } internal 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) { 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 result = 0; foreach (KeyValuePair<int, float> item in creature_levelup_chance) { if (levelup_bonus.ContainsKey(item.Key)) { float num = (1f + levelup_bonus[item.Key]) * distance_influence; float num2 = item.Value * num; if (roll >= num2 || item.Key >= maxLevel) { result = item.Key; break; } } else if (roll >= item.Value || item.Key >= maxLevel) { result = item.Key; break; } } return result; } public static void UpdateMaxLevel() { foreach (GameObject item in from obj in Resources.FindObjectsOfTypeAll<GameObject>() where ((Object)obj).name.StartsWith("Fish") select obj) { if ((Object)(object)item.GetComponent<Fish>() != (Object)null) { item.GetComponent<ItemDrop>().m_itemData.m_shared.m_maxQuality = 999; } } } 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_0018: 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_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected I4, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) Vector3 position = creature.transform.position; creature_name = Utils.GetPrefabName(creature.gameObject); Biome val = Heightmap.FindBiome(position); creature_biome = (Biome)(int)val; biome_settings = null; if (LevelSystemData.SLE_Level_Settings.BiomeConfiguration != null) { DataObjects.BiomeSpecificSetting value; bool flag = LevelSystemData.SLE_Level_Settings.BiomeConfiguration.TryGetValue((Biome)895, out value); if (flag) { biome_settings = value; } DataObjects.BiomeSpecificSetting value2; bool flag2 = LevelSystemData.SLE_Level_Settings.BiomeConfiguration.TryGetValue(val, out value2); if (flag2 && flag) { biome_settings = Extensions.MergeBiomeConfigs(value2, value); } else if (flag2) { biome_settings = value2; } } creature_settings = null; if (LevelSystemData.SLE_Level_Settings.CreatureConfiguration != null && LevelSystemData.SLE_Level_Settings.CreatureConfiguration.TryGetValue(creature_name, out var value3)) { creature_settings = value3; } } } public class StarLevelHud { public bool isBoss { get; set; } public GameObject starlevel2 { get; set; } public Image starlevel2_front_image { get; set; } public Image starlevel2_back_image { get; set; } public GameObject starlevel3 { get; set; } public Image starlevel3_front_image { get; set; } public Image starlevel3_back_image { get; set; } public GameObject starlevel4 { get; set; } public Image starlevel4_front_image { get; set; } public Image starlevel4_back_image { get; set; } public GameObject starlevel5 { get; set; } public Image starlevel5_front_image { get; set; } public Image starlevel5_back_image { get; set; } public GameObject starlevel6 { get; set; } public Image starlevel6_front_image { get; set; } public Image starlevel6_back_image { get; set; } public GameObject starlevel_N { get; set; } public Image starlevelN_front_image { get; set; } public Image starlevelN_back_image { 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()) { return; } __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) { return; } RectTransform level = value.m_level2; if (level != null) { GameObject gameObject = ((Component)level).gameObject; if (gameObject != null) { gameObject.SetActive(false); } } RectTransform level2 = value.m_level3; if (level2 != null) { GameObject gameObject2 = ((Component)level2).gameObject; if (gameObject2 != null) { gameObject2.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(); } } [HarmonyPatch(typeof(Character), "GetHoverName")] public static class DisplayCreatureNameChanges { public static bool Prefix(Character __instance, ref string __result) { DataObjects.CreatureDetailCache andSetDetailCache = CompositeLazyCache.GetAndSetDetailCache(__instance); if (andSetDetailCache == null) { return true; } __result = CreatureModifiers.CheckOrBuildCreatureName(__instance, andSetDetailCache); return false; } } public static Dictionary<ZDOID, StarLevelHud> characterExtendedHuds = new Dictionary<ZDOID, StarLevelHud>(); private static GameObject star; public static void InvalidateCacheEntry(ZDOID zdo) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) if (characterExtendedHuds.ContainsKey(zdo)) { characterExtendedHuds.Remove(zdo); } } public static void UpdateHudforAllLevels(HudData ehud) { //IL_0037: 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) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Unknown result type (might be due to invalid IL or missing references) //IL_02cc: Unknown result type (might be due to invalid IL or missing references) //IL_03ac: Unknown result type (might be due to invalid IL or missing references) //IL_03de: Unknown result type (might be due to invalid IL or missing references) //IL_0484: Unknown result type (might be due to invalid IL or missing references) //IL_04b6: Unknown result type (might be due to invalid IL or missing references) //IL_055c: Unknown res