Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of BloodMoon v0.8.4
BloodMoon.dll
Decompiled 3 weeks agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyVersion("0.0.0.0")] namespace BloodMoon; [BepInPlugin("com.burks.bloodmoon", "Blood Moon", "0.8.3")] public class BloodMoonPlugin : BaseUnityPlugin { public const string GUID = "com.burks.bloodmoon"; public const string NAME = "Blood Moon"; public const string VERSION = "0.8.3"; public static ManualLogSource Log; public static ConfigEntry<int> IntervalDays; public static ConfigEntry<int> MaxNearby; public static ConfigEntry<int> GroupMin; public static ConfigEntry<int> GroupMax; public static ConfigEntry<bool> SpawnMonsters; public static ConfigEntry<bool> BlockSleep; public static ConfigEntry<bool> RedSky; public static ConfigEntry<bool> HuntPlayers; public static ConfigEntry<bool> MusicOn; public static ConfigEntry<bool> MusicInDungeons; public static ConfigEntry<bool> ShelterSafe; public static ConfigEntry<float> MusicVolume; public static ConfigEntry<float> Intensity; public static ConfigEntry<float> Chance; public static ConfigEntry<float> BruteChance; public static ConfigEntry<float> CountdownX; public static ConfigEntry<float> CountdownY; public static ConfigEntry<bool> ShowCountdown; public static ConfigEntry<float> SpawnInterval; public static ConfigEntry<float> OneStarChance; public static ConfigEntry<float> TwoStarChance; public static ConfigEntry<float> RedStrength; public static ConfigEntry<float> ToughBias; public static ConfigEntry<string> Exclude; public static ConfigEntry<bool> FollowBosses; public static ConfigEntry<float> NewestShare; public static ConfigEntry<float> BigChance; public static ConfigEntry<int> MaxBig; public static ConfigEntry<string> BigList; public static ConfigEntry<bool> BigStars; public static ConfigEntry<bool> BigHealthBar; public static ConfigEntry<float> HuntRange; public static ConfigEntry<float> NextWaveWhenLeft; public static ConfigEntry<bool> ScaleWithPlayers; public static ConfigEntry<float> SoloStrength; public static ConfigEntry<int> FullAtPlayers; public static ConfigEntry<float> PlayerRange; public static ConfigEntry<int> BigMinPlayers; private bool _headless; private float _nextState; private float _nextSpawn; private int _phase = -1; private void Awake() { //IL_05ca: Unknown result type (might be due to invalid IL or missing references) //IL_05d0: Invalid comparison between Unknown and I4 //IL_05f5: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; IntervalDays = ((BaseUnityPlugin)this).Config.Bind<int>("Schedule", "IntervalDays", 7, "A blood moon rises on the night of every day that divides by this number (7 = days 7, 14, 21 ...)."); Chance = ((BaseUnityPlugin)this).Config.Bind<float>("Schedule", "Chance", 0.5f, "Chance (0-1) that a blood moon actually rises on a scheduled day. 1 = always. Every player must use the same value, or they will disagree about which nights are blood moons."); SpawnMonsters = ((BaseUnityPlugin)this).Config.Bind<bool>("Danger", "SpawnMonsters", true, "Extra monsters from the biome you are in keep appearing around you all night."); SpawnInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Danger", "SpawnIntervalSeconds", 25f, "Seconds between waves around each player."); MaxNearby = ((BaseUnityPlugin)this).Config.Bind<int>("Danger", "MaxNearbyMonsters", 10, "No new wave while this many monsters are already within 60 m of you."); GroupMin = ((BaseUnityPlugin)this).Config.Bind<int>("Danger", "GroupSizeMin", 1, "Smallest wave."); GroupMax = ((BaseUnityPlugin)this).Config.Bind<int>("Danger", "GroupSizeMax", 3, "Largest wave."); OneStarChance = ((BaseUnityPlugin)this).Config.Bind<float>("Danger", "OneStarChance", 0.3f, "Chance (0-1) that a blood moon monster is one-star."); TwoStarChance = ((BaseUnityPlugin)this).Config.Bind<float>("Danger", "TwoStarChance", 0.1f, "Chance (0-1) that a blood moon monster is two-star."); ToughBias = ((BaseUnityPlugin)this).Config.Bind<float>("Danger", "TougherMonsterBias", 0.6f, "0 = every monster of the biome is equally likely, 1 = strongly favour the biome's toughest monsters."); Exclude = ((BaseUnityPlugin)this).Config.Bind<string>("Danger", "ExcludeCreatures", "", "Comma-separated creature prefab names that never appear in a wave. The log names every wave, so copy names from there."); HuntPlayers = ((BaseUnityPlugin)this).Config.Bind<bool>("Danger", "MonstersHuntYou", true, "Blood moon monsters know where you are and come for you, like raid monsters."); BlockSleep = ((BaseUnityPlugin)this).Config.Bind<bool>("Danger", "BlockSleep", true, "Nobody with the mod can sleep through a blood moon."); Intensity = ((BaseUnityPlugin)this).Config.Bind<float>("Danger", "Intensity", 1.6f, "Overall danger multiplier on top of the settings above: waves come this much faster, this many more monsters may be around you at once, and starred monsters are this much more likely. 1 = the 0.3.0 behaviour."); ShelterSafe = ((BaseUnityPlugin)this).Config.Bind<bool>("Danger", "ShelterIsSafe", true, "While you are under a roof (the game's Shelter status), no waves come for you and blood moon monsters stop hunting you."); BruteChance = ((BaseUnityPlugin)this).Config.Bind<float>("Danger", "BruteChance", 0.5f, "Chance (0-1) that a group of greydwarfs brings a brute along. Brutes picked as a wave of their own (Black Forest) are scaled by the same amount. 1 = the 0.5 behaviour."); FollowBosses = ((BaseUnityPlugin)this).Config.Bind<bool>("Progression", "FollowBosses", true, "Waves come from every biome your world has unlocked by beating its boss (Eikthyr unlocks Black Forest creatures, The Elder the Swamp, Bonemass the Mountains, Moder the Plains, Yagluth the Mistlands, The Queen the Ashlands), wherever you are standing. Meadows creatures are always in. false = only creatures native to the biome around you (the 0.6.0 behaviour)."); NewestShare = ((BaseUnityPlugin)this).Config.Bind<float>("Progression", "NewestBiomeShare", 0.1f, "Chance (0-1) that a wave comes from the newest biome you have unlocked. The rest come from the earlier unlocked biomes: the most recent of those gets the biggest share and each one before it less (weights n, n-1, ... 1)."); if (Mathf.Approximately(NewestShare.Value, 0.5f) || Mathf.Approximately(NewestShare.Value, 0.25f)) { NewestShare.Value = 0.1f; } BigChance = ((BaseUnityPlugin)this).Config.Bind<float>("Progression", "BigMonsterChance", 0.5f, "Chance (0-1) that a blood moon brings one big monster (see BigMonsters) for you, some time during the night. At most one per blood moon. Every player gets announced. Not changed by Intensity."); if (Mathf.Approximately(BigChance.Value, 0.1f)) { BigChance.Value = 0.5f; } MaxBig = ((BaseUnityPlugin)this).Config.Bind<int>("Progression", "MaxBigMonsters", 1, "No new big monster while this many big monsters are already within 150 m of you (or the last one the blood moon sent you is still alive). 0 = no big monsters."); BigList = ((BaseUnityPlugin)this).Config.Bind<string>("Progression", "BigMonsters", "BlackForest:Troll, BlackForest:Bjorn, BlackForest:Unbjorn, Swamp:Abomination, Mountain:StoneGolem, Plains:GoblinBrute, Plains:Lox, Mistlands:SeekerBrute, Mistlands:Gjall, AshLands:FallenValkyrie, AshLands:Morgen, DeepNorth:TrollFrost", "The hardest creature(s) of each biome, as Biome:PrefabName, comma-separated. They only ever come alone, through BigMonsterChance, and only once their biome is unlocked. Biomes: Meadows, BlackForest, Swamp, Mountain, Plains, Mistlands, AshLands, DeepNorth."); if (BigList.Value == "BlackForest:Troll, BlackForest:Bjorn, Swamp:Abomination, Mountain:StoneGolem, Plains:GoblinBrute, Plains:Lox, Mistlands:SeekerBrute, Mistlands:Gjall, AshLands:FallenValkyrie, AshLands:Morgen, DeepNorth:TrollFrost" || BigList.Value == "BlackForest:Troll, Swamp:Abomination, Mountain:StoneGolem, Plains:GoblinBrute, Plains:Lox, Mistlands:SeekerBrute, Mistlands:Gjall, AshLands:FallenValkyrie, AshLands:Morgen" || BigList.Value == "BlackForest:Troll, Swamp:Abomination, Mountain:StoneGolem, Plains:GoblinBrute, Plains:Lox, Mistlands:SeekerBrute, Mistlands:Gjall, AshLands:FallenValkyrie, AshLands:Morgen, DeepNorth:TrollFrost") { BigList.Value = "BlackForest:Troll, BlackForest:Bjorn, BlackForest:Unbjorn, Swamp:Abomination, Mountain:StoneGolem, Plains:GoblinBrute, Plains:Lox, Mistlands:SeekerBrute, Mistlands:Gjall, AshLands:FallenValkyrie, AshLands:Morgen, DeepNorth:TrollFrost"; } ScaleWithPlayers = ((BaseUnityPlugin)this).Config.Bind<bool>("Players", "ScaleWithPlayers", true, "Blood moon strength depends on how many players are near you: waves come slower, fewer monsters can be around you and stars are rarer when there are fewer of you."); SoloStrength = ((BaseUnityPlugin)this).Config.Bind<float>("Players", "SoloStrength", 0.5f, "Blood moon strength when you are alone (0.5 = 50%). It rises evenly with each nearby player to 100% at FullStrengthPlayers."); FullAtPlayers = ((BaseUnityPlugin)this).Config.Bind<int>("Players", "FullStrengthPlayers", 4, "Nearby players (yourself included) needed for 100% strength."); PlayerRange = ((BaseUnityPlugin)this).Config.Bind<float>("Players", "NearbyRange", 100f, "Players within this many metres of you count as nearby."); BigMinPlayers = ((BaseUnityPlugin)this).Config.Bind<int>("Players", "BigMonsterMinPlayers", 2, "A big monster only comes when at least this many players are nearby (yourself included). If it is due while you are alone, it waits until someone joins you."); HuntRange = ((BaseUnityPlugin)this).Config.Bind<float>("Danger", "HuntRange", 200f, "Blood moon monsters go for the closest player within this many metres, even one they cannot see, instead of fighting other monsters or wandering."); NextWaveWhenLeft = ((BaseUnityPlugin)this).Config.Bind<float>("Danger", "NextWaveWhenLeft", 0.1f, "When this share (0-1) or less of your last wave is still alive, the next wave comes right away instead of waiting for SpawnIntervalSeconds. 0.1 = 10%; for groups of 1-3 that means once they are all dead. -1 = off."); BigHealthBar = ((BaseUnityPlugin)this).Config.Bind<bool>("Progression", "BigMonsterHealthBar", true, "Big monsters get a boss health bar at the top of the screen (for every player with the mod)."); BigStars = ((BaseUnityPlugin)this).Config.Bind<bool>("Progression", "BigMonstersCanHaveStars", false, "Big monsters can be one- or two-star like the rest. false = always zero-star."); ShowCountdown = ((BaseUnityPlugin)this).Config.Bind<bool>("Look", "ShowCountdown", true, "Show the days left until the next blood moon beside the minimap."); CountdownX = ((BaseUnityPlugin)this).Config.Bind<float>("Look", "CountdownOffsetX", 0f, "Move the countdown left (negative) or right (positive), in pixels at 1080p."); CountdownY = ((BaseUnityPlugin)this).Config.Bind<float>("Look", "CountdownOffsetY", 0f, "Move the countdown up (negative) or down (positive), in pixels at 1080p."); RedSky = ((BaseUnityPlugin)this).Config.Bind<bool>("Look", "RedSky", true, "Tint the night red."); RedStrength = ((BaseUnityPlugin)this).Config.Bind<float>("Look", "RedSkyStrength", 0.65f, "How strong the red tint is (0-1)."); MusicOn = ((BaseUnityPlugin)this).Config.Bind<bool>("Music", "Music", true, "Play the blood moon track once when the blood moon rises, then keep the music silent for the rest of the night. The track is the audio file (.ogg, .wav or .mp3) next to BloodMoon.dll; a file named bloodmoon.* wins if there are several."); MusicInDungeons = ((BaseUnityPlugin)this).Config.Bind<bool>("Music", "MusicInDungeons", true, "Keep the track playing inside dungeons and other interiors."); MusicVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Music", "MusicVolume", 1f, "Track volume (0-1), on top of the game's own music volume slider."); _headless = (int)SystemInfo.graphicsDeviceType == 4; if (_headless) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Headless server detected; Blood Moon runs on the players' games, nothing to do here."); return; } new Harmony("com.burks.bloodmoon").PatchAll(Assembly.GetExecutingAssembly()); if (MusicOn.Value) { ((MonoBehaviour)this).StartCoroutine(Music.Load(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location))); } ((BaseUnityPlugin)this).Logger.LogInfo((object)"Blood Moon 0.8.3 loaded."); } private void OnGUI() { if (_headless) { return; } try { Countdown.Draw(); } catch (Exception ex) { if (!Countdown.Failed) { Countdown.Failed = true; Log.LogWarning((object)("Countdown display failed: " + ex.Message)); } } } private void Update() { if (_headless) { return; } float unscaledTime = Time.unscaledTime; if (unscaledTime >= _nextState) { _nextState = unscaledTime + 1f; try { UpdateState(); } catch (Exception ex) { Log.LogWarning((object)("State check failed: " + ex.Message)); _nextState = unscaledTime + 30f; } } if (unscaledTime < _nextSpawn && Moon.Active && Spawner.WaveCleared()) { _nextSpawn = unscaledTime; } if (unscaledTime >= _nextSpawn) { _nextSpawn = unscaledTime + Mathf.Clamp(SpawnInterval.Value / Spawner.Intensity, 3f, 600f); try { Spawner.Wave(); } catch (Exception ex2) { Log.LogWarning((object)("Wave failed: " + ex2)); _nextSpawn = unscaledTime + 60f; } } Sky.Fade(Time.unscaledDeltaTime); Music.Tick(Time.unscaledDeltaTime); } private void UpdateState() { if ((Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)EnvMan.instance == (Object)null) { _phase = -1; return; } Commands.Register(); Spawner.UpdateShelter(); int num = (Moon.Active ? 2 : (Moon.Tonight ? 1 : 0)); if (num == _phase) { return; } int phase = _phase; _phase = num; switch (num) { case 1: Say("A blood moon will rise tonight."); break; case 2: Say(BlockSleep.Value ? "The blood moon rises. There will be no sleep tonight." : "The blood moon rises."); try { foreach (string item in Spawner.Describe()) { Log.LogInfo((object)item); } } catch (Exception ex) { Log.LogWarning((object)("Could not list blood moon creatures: " + ex.Message)); } break; default: if (phase == 2) { Say("The blood moon fades."); } break; } Moon.Clock(out var day, out var f); ManualLogSource log = Log; string[] array = new string[6] { "Day ", day.ToString(), " (", Mathf.RoundToInt(f * 100f).ToString(), "% of the day): ", null }; array[5] = (string)(num switch { 1 => "blood moon tonight", 2 => "blood moon is up", _ => "no blood moon", }); log.LogInfo((object)string.Concat(array)); } private static void Say(string text) { if ((Object)(object)MessageHud.instance != (Object)null) { MessageHud.instance.ShowMessage((MessageType)2, text, 0, (Sprite)null, false, true); } } } public static class Moon { public static bool Forced; public static int ForcedRuns; private static int _latchedNight = int.MinValue; public static bool Active { get { if (Forced) { return true; } if (!Clock(out var day, out var f)) { return false; } int num = ((f >= 0.5f) ? day : (day - 1)); if ((f >= 0.85f && IsBloodDay(day)) || (f <= 0.15f && IsBloodDay(day - 1))) { _latchedNight = num; return true; } if (_latchedNight == num) { if (!(f > 0.84f)) { return f < 0.16f; } return true; } return false; } } public static bool Tonight { get { if (Forced) { return false; } if (!Clock(out var day, out var f)) { return false; } if (f > 0.15f && f < 0.85f) { return IsBloodDay(day); } return false; } } public static int NightKey() { if (Forced) { return -1 - ForcedRuns; } Clock(out var day, out var f); if (!(f >= 0.5f)) { return day - 1; } return day; } public static void ClearLatch() { _latchedNight = int.MinValue; } public static bool IsBloodDay(int day) { int num = Mathf.Max(1, BloodMoonPlugin.IntervalDays.Value); if (day <= 0 || day % num != 0) { return false; } float num2 = Mathf.Clamp01(BloodMoonPlugin.Chance.Value); if (num2 >= 1f) { return true; } ulong num3 = (ulong)(day * -7046029254386353131L); try { if ((Object)(object)ZNet.instance != (Object)null) { num3 ^= (ulong)ZNet.instance.GetWorldUID(); } } catch (Exception) { } num3 ^= num3 >> 33; num3 *= 18397679294719823053uL; num3 ^= num3 >> 33; num3 *= 14181476777654086739uL; num3 ^= num3 >> 33; return num3 % 10000 < (ulong)Mathf.RoundToInt(num2 * 10000f); } public static bool Clock(out int day, out float f) { day = 0; f = 0.5f; EnvMan instance = EnvMan.instance; if ((Object)(object)instance == (Object)null || (Object)(object)ZNet.instance == (Object)null) { return false; } double num = Math.Max(1L, instance.m_dayLengthSec); double timeSeconds = ZNet.instance.GetTimeSeconds(); day = (int)(timeSeconds / num); f = (float)((timeSeconds - (double)day * num) / num); return true; } } public static class Spawner { public class Entry { public GameObject Prefab; public string Name; public float GroundOffset; public float Weight = 1f; public int Tier; public bool Relaxed; public bool Big; } public class Pools { public readonly List<Entry> Regular = new List<Entry>(); public readonly List<Entry> Big = new List<Entry>(); public readonly List<int> Unlocked = new List<int>(); public int Newest = -1; public bool Follow; } public static readonly Biome[] Order; public static readonly string[] BossKey; public static readonly string[] BossName; public static readonly string[] BiomeName; private static readonly HashSet<string> NeverOnLand; private static readonly HashSet<string> _exclude; private static string _excludeRaw; private static readonly Dictionary<string, int> _big; private static string _bigRaw; private static readonly HashSet<string> _missingWarned; private static readonly List<MonsterAI> _mine; private static readonly List<Character> _mineBig; private static readonly HashSet<Character> _seen; private static readonly List<int> _tiers; private static readonly Pools _pools; public static readonly int WaveKey; private static readonly List<Character> _wave; private static int _waveSize; private static float _waveAt; private static readonly MethodInfo WakeM; private static bool _safe; private static int _bigNight; private static bool _bigDue; private static float _bigAt; private static int _players; private static float _playersAt; public static float Intensity => Mathf.Clamp(BloodMoonPlugin.Intensity.Value, 0.25f, 5f) * PlayerScale; public static int NearbyPlayers { get { //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) if (Time.time - _playersAt < 1f) { return _players; } _playersAt = Time.time; Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return _players = 1; } float num = Mathf.Max(1f, BloodMoonPlugin.PlayerRange.Value); int num2 = 0; foreach (Player allPlayer in Player.GetAllPlayers()) { if (!((Object)(object)allPlayer != (Object)null) || ((Character)allPlayer).IsDead()) { continue; } if (!((Object)(object)allPlayer == (Object)(object)localPlayer)) { Vector3 val = ((Component)allPlayer).transform.position - ((Component)localPlayer).transform.position; if (!(((Vector3)(ref val)).sqrMagnitude <= num * num)) { continue; } } num2++; } return _players = Mathf.Max(1, num2); } } public static float PlayerScale { get { if (!BloodMoonPlugin.ScaleWithPlayers.Value) { return 1f; } float num = Mathf.Clamp(BloodMoonPlugin.SoloStrength.Value, 0.05f, 1f); int num2 = Mathf.Max(2, BloodMoonPlugin.FullAtPlayers.Value); return Mathf.Clamp(num + (1f - num) * (float)(NearbyPlayers - 1) / (float)(num2 - 1), num, 1f); } } public static void MarkWave(Character c) { try { ZNetView component = ((Component)c).GetComponent<ZNetView>(); if ((Object)(object)component != (Object)null && component.IsValid()) { component.GetZDO().Set(WaveKey, true); } } catch (Exception) { } } public static bool WaveCleared() { float value = BloodMoonPlugin.NextWaveWhenLeft.Value; if (_waveSize <= 0 || value < 0f || Time.time - _waveAt < 3f) { return false; } int num = 0; foreach (Character item in _wave) { if ((Object)(object)item != (Object)null && !item.IsDead()) { num++; } } if (num > Mathf.FloorToInt((float)_waveSize * Mathf.Clamp01(value) + 0.0001f)) { return false; } _waveSize = 0; _wave.Clear(); return true; } private static int Bits(int v) { uint num = (uint)v; int num2 = 0; while (num != 0) { num2 += (int)(num & 1); num >>= 1; } return num2; } public static int TierOf(Biome b) { //IL_0004: 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) for (int i = 0; i < Order.Length; i++) { if ((b & Order[i]) != 0) { return i; } } return -1; } private static int TierOfName(string s) { string text = s.Replace(" ", "").ToLowerInvariant(); if (text == "mountains") { text = "mountain"; } for (int i = 0; i < Order.Length; i++) { if (text == ((object)Unsafe.As<Biome, Biome>(ref Order[i])/*cast due to .constrained prefix*/).ToString().ToLowerInvariant() || text == BiomeName[i].Replace(" ", "").ToLowerInvariant()) { return i; } } return -2; } public static bool Unlocked(int tier) { if (tier == 0) { return true; } try { return (Object)(object)ZoneSystem.instance != (Object)null && ZoneSystem.instance.GetGlobalKey(BossKey[tier]); } catch { return false; } } public static string PrefabName(GameObject go) { string text = ((Object)go).name; int num = text.IndexOf('('); if (num > 0) { text = text.Substring(0, num); } return text.Trim(); } private static void RefreshConfig() { string[] array; if (_excludeRaw != BloodMoonPlugin.Exclude.Value) { _excludeRaw = BloodMoonPlugin.Exclude.Value; _exclude.Clear(); array = (_excludeRaw ?? "").Split(','); foreach (string text in array) { if (text.Trim().Length > 0) { _exclude.Add(text.Trim()); } } } if (!(_bigRaw != BloodMoonPlugin.BigList.Value)) { return; } _bigRaw = BloodMoonPlugin.BigList.Value; _big.Clear(); array = (_bigRaw ?? "").Split(','); for (int i = 0; i < array.Length; i++) { string text2 = array[i].Trim(); if (text2.Length == 0) { continue; } int num = text2.IndexOf(':'); int num2 = -1; string text3 = text2; if (num >= 0) { num2 = TierOfName(text2.Substring(0, num)); text3 = text2.Substring(num + 1).Trim(); if (num2 == -2) { BloodMoonPlugin.Log.LogWarning((object)("BigMonsters: unknown biome in '" + text2 + "', using the creature's own biome.")); num2 = -1; } } if (text3.Length > 0) { _big[text3] = num2; } } } private static bool Hostile(GameObject prefab, out Character c) { //IL_0039: 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_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected I4, but got Unknown c = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<Character>() : null); if ((Object)(object)c == (Object)null || (Object)(object)prefab.GetComponent<MonsterAI>() == (Object)null || c.IsBoss()) { return false; } Faction faction = c.m_faction; switch ((int)faction) { case 0: case 1: case 6: case 8: case 10: case 11: case 12: return false; default: if (!NeverOnLand.Contains(((Object)prefab).name)) { return !_exclude.Contains(((Object)prefab).name); } return false; } } public static void Build(Pools p, bool follow, Biome spotBiome, float alt, float dist) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Expected I4, but got Unknown //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Invalid comparison between Unknown and I4 //IL_01d4: Unknown result type (might be due to invalid IL or missing references) p.Regular.Clear(); p.Big.Clear(); p.Unlocked.Clear(); p.Newest = -1; p.Follow = follow; RefreshConfig(); int num = TierOf(spotBiome); if (follow) { for (int i = 0; i < Order.Length; i++) { if (Unlocked(i)) { p.Unlocked.Add(i); } } } else { if (num < 0) { return; } p.Unlocked.Add(num); } SpawnSystem val = Object.FindFirstObjectByType<SpawnSystem>(); if ((Object)(object)val == (Object)null || val.m_spawnLists == null || (Object)(object)ZoneSystem.instance == (Object)null) { return; } float num2 = Mathf.Clamp01(BloodMoonPlugin.ToughBias.Value); Dictionary<string, Entry> dictionary = new Dictionary<string, Entry>(StringComparer.OrdinalIgnoreCase); Dictionary<string, float> dictionary2 = new Dictionary<string, float>(StringComparer.OrdinalIgnoreCase); Dictionary<string, int> dictionary3 = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase); foreach (SpawnSystemList spawnList in val.m_spawnLists) { if ((Object)(object)spawnList == (Object)null || spawnList.m_spawners == null) { continue; } foreach (SpawnData spawner in spawnList.m_spawners) { if (spawner == null || !spawner.m_enabled || (Object)(object)spawner.m_prefab == (Object)null || !spawner.m_spawnAtNight || (spawner.m_inLava && !spawner.m_outsideLava) || (!string.IsNullOrEmpty(spawner.m_requiredGlobalKey) && !ZoneSystem.instance.GetGlobalKey(spawner.m_requiredGlobalKey)) || Bits((int)spawner.m_biome) > 2 || !string.IsNullOrEmpty(spawner.m_requiredPersistentEvent)) { continue; } bool flag = spawner.m_requiredEnvironments != null && spawner.m_requiredEnvironments.Count > 0; int num3; if (follow) { num3 = TierOf(spawner.m_biome); if (num3 < 0 || !p.Unlocked.Contains(num3) || spawner.m_maxAltitude <= 0f) { continue; } } else { if ((spawner.m_biome & spotBiome) == 0 || flag || alt < spawner.m_minAltitude || alt > spawner.m_maxAltitude || (spawner.m_minDistanceFromCenter > 0f && dist < spawner.m_minDistanceFromCenter) || (spawner.m_maxDistanceFromCenter > 0f && dist > spawner.m_maxDistanceFromCenter)) { continue; } num3 = num; } if (!Hostile(spawner.m_prefab, out var c)) { continue; } string name = ((Object)spawner.m_prefab).name; if (_big.ContainsKey(name)) { if (!dictionary2.ContainsKey(name)) { dictionary2[name] = spawner.m_groundOffset; } if (!dictionary3.TryGetValue(name, out var value) || num3 < value) { dictionary3[name] = num3; } continue; } if (dictionary.TryGetValue(name, out var value2)) { if (num3 < value2.Tier || (value2.Relaxed && !flag && num3 == value2.Tier)) { value2.Tier = num3; value2.Relaxed = flag; value2.GroundOffset = spawner.m_groundOffset; } continue; } float num4 = Mathf.Pow(Mathf.Max(1f, c.m_health), num2); if (name == "Greydwarf_Elite") { num4 *= Mathf.Clamp01(BloodMoonPlugin.BruteChance.Value); } dictionary[name] = new Entry { Prefab = spawner.m_prefab, Name = name, GroundOffset = spawner.m_groundOffset, Weight = num4, Tier = num3, Relaxed = flag }; } } HashSet<int> hashSet = new HashSet<int>(); foreach (Entry value5 in dictionary.Values) { if (!value5.Relaxed) { hashSet.Add(value5.Tier); } } foreach (Entry value6 in dictionary.Values) { if (!value6.Relaxed || !hashSet.Contains(value6.Tier)) { p.Regular.Add(value6); if (value6.Tier > p.Newest) { p.Newest = value6.Tier; } } } p.Regular.Sort((Entry a, Entry b) => (a.Tier == b.Tier) ? string.CompareOrdinal(a.Name, b.Name) : a.Tier.CompareTo(b.Tier)); if ((Object)(object)ZNetScene.instance == (Object)null) { return; } foreach (KeyValuePair<string, int> item in _big) { int value3 = item.Value; if (value3 < 0 && !dictionary3.TryGetValue(item.Key, out value3)) { continue; } if (!follow) { value3 = ((value3 == num) ? num : (-1)); } if (value3 < 0 || !p.Unlocked.Contains(value3)) { continue; } GameObject prefab = ZNetScene.instance.GetPrefab(item.Key); Character c2; if ((Object)(object)prefab == (Object)null) { if (_missingWarned.Add(item.Key)) { BloodMoonPlugin.Log.LogWarning((object)("BigMonsters: no creature called '" + item.Key + "' in this game, skipped.")); } } else if (Hostile(prefab, out c2)) { float value4; float groundOffset = (dictionary2.TryGetValue(item.Key, out value4) ? value4 : (c2.m_flying ? 8f : 0f)); p.Big.Add(new Entry { Prefab = prefab, Name = ((Object)prefab).name, GroundOffset = groundOffset, Weight = 1f, Tier = value3, Big = true }); } } p.Big.Sort((Entry a, Entry b) => (a.Tier == b.Tier) ? string.CompareOrdinal(a.Name, b.Name) : a.Tier.CompareTo(b.Tier)); } public static Entry Pick(List<Entry> list, int newest, bool weighted, out bool fromNewest, float share, bool falloff) { fromNewest = false; _tiers.Clear(); foreach (Entry item in list) { if ((!weighted || item.Weight > 0f) && !_tiers.Contains(item.Tier)) { _tiers.Add(item.Tier); } } if (_tiers.Count == 0) { return null; } int num; if (_tiers.Contains(newest) && (_tiers.Count == 1 || Random.value < Mathf.Clamp01(share))) { num = newest; fromNewest = true; } else { _tiers.Remove(newest); if (falloff) { _tiers.Sort(); float num2 = 0f; for (int i = 0; i < _tiers.Count; i++) { num2 += (float)(i + 1); } float num3 = Random.value * num2; num = _tiers[_tiers.Count - 1]; for (int j = 0; j < _tiers.Count; j++) { num3 -= (float)(j + 1); if (num3 <= 0f) { num = _tiers[j]; break; } } } else { num = _tiers[Random.Range(0, _tiers.Count)]; } } float num4 = 0f; foreach (Entry item2 in list) { if (item2.Tier == num) { num4 += (weighted ? item2.Weight : 1f); } } float num5 = Random.value * num4; Entry result = null; foreach (Entry item3 in list) { if (item3.Tier != num) { continue; } float num6 = (weighted ? item3.Weight : 1f); if (!(num6 <= 0f)) { result = item3; num5 -= num6; if (num5 <= 0f) { break; } } } return result; } public static int BigCount(Vector3 pos) { //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: 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) _mineBig.RemoveAll((Character c) => (Object)(object)c == (Object)null || c.IsDead()); _seen.Clear(); int num = 0; foreach (Character item in _mineBig) { _seen.Add(item); num++; } foreach (Character allCharacter in Character.GetAllCharacters()) { if (!((Object)(object)allCharacter == (Object)null) && !_seen.Contains(allCharacter) && !allCharacter.IsPlayer() && !allCharacter.IsDead() && !allCharacter.IsTamed()) { Vector3 val = ((Component)allCharacter).transform.position - pos; if (!(((Vector3)(ref val)).sqrMagnitude > 22500f) && _big.ContainsKey(PrefabName(((Component)allCharacter).gameObject))) { num++; } } } return num; } public static bool Sheltered() { Player localPlayer = Player.m_localPlayer; if (BloodMoonPlugin.ShelterSafe.Value && (Object)(object)localPlayer != (Object)null) { return localPlayer.InShelter(); } return false; } public static void UpdateShelter() { bool flag = Sheltered(); _mine.RemoveAll((MonsterAI a) => (Object)(object)a == (Object)null); if (flag == _safe) { return; } _safe = flag; bool huntPlayer = !flag && BloodMoonPlugin.HuntPlayers.Value && Moon.Active; foreach (MonsterAI item in _mine) { try { ((BaseAI)item).SetHuntPlayer(huntPlayer); } catch (Exception) { } } } private static string Names(List<Entry> list, int tier) { List<string> list2 = new List<string>(); foreach (Entry item in list) { if (item.Tier == tier && (!(item.Weight <= 0f) || item.Big)) { list2.Add(item.Name); } } return string.Join(", ", list2.ToArray()); } public static List<string> Describe() { List<string> list = new List<string>(); if (!BloodMoonPlugin.FollowBosses.Value) { list.Add("FollowBosses is off: waves use the creatures native to the biome around you."); return list; } RefreshConfig(); Build(_pools, follow: true, (Biome)0, 0f, 0f); List<string> list2 = new List<string>(); for (int i = 1; i < Order.Length; i++) { if (Unlocked(i)) { list2.Add(BossName[i]); } } list.Add("Players near you: " + NearbyPlayers + " -> blood moon strength " + Mathf.RoundToInt(PlayerScale * 100f) + "%" + ((NearbyPlayers < BloodMoonPlugin.BigMinPlayers.Value) ? (" (big monsters need " + BloodMoonPlugin.BigMinPlayers.Value + " players)") : "") + "."); list.Add("Bosses beaten: " + ((list2.Count > 0) ? string.Join(", ", list2.ToArray()) : "none") + "."); if (_pools.Newest < 0) { list.Add("No creatures found for the blood moon (are you in a world?)."); return list; } bool flag = false; foreach (Entry item in _pools.Regular) { if (item.Tier != _pools.Newest && item.Weight > 0f) { flag = true; } } int num = (flag ? Mathf.RoundToInt(Mathf.Clamp01(BloodMoonPlugin.NewestShare.Value) * 100f) : 100); list.Add("Newest biome " + BiomeName[_pools.Newest] + " (" + num + "% of waves): " + Names(_pools.Regular, _pools.Newest)); List<int> list3 = new List<int>(); foreach (int item2 in _pools.Unlocked) { if (item2 != _pools.Newest && Names(_pools.Regular, item2).Length > 0) { list3.Add(item2); } } list3.Sort(); float num2 = (float)(list3.Count * (list3.Count + 1)) / 2f; for (int num3 = list3.Count - 1; num3 >= 0; num3--) { float num4 = (100f - (float)num) * (float)(num3 + 1) / num2; list.Add("Earlier " + BiomeName[list3[num3]] + " (" + num4.ToString("0.#") + "%): " + Names(_pools.Regular, list3[num3])); } List<string> list4 = new List<string>(); foreach (Entry item3 in _pools.Big) { list4.Add(item3.Name + " (" + BiomeName[item3.Tier] + ")"); } list.Add("Big monster (" + Mathf.RoundToInt(Mathf.Clamp01(BloodMoonPlugin.BigChance.Value) * 100f) + "% chance per blood moon, at most one): " + ((list4.Count > 0) ? string.Join(", ", list4.ToArray()) : "none yet")); return list; } public unsafe static string Wave(string forceBig = null) { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_065c: Unknown result type (might be due to invalid IL or missing references) //IL_0681: Unknown result type (might be due to invalid IL or missing references) //IL_0686: Unknown result type (might be due to invalid IL or missing references) //IL_068b: Unknown result type (might be due to invalid IL or missing references) //IL_0692: Unknown result type (might be due to invalid IL or missing references) //IL_06cd: Unknown result type (might be due to invalid IL or missing references) //IL_06e8: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_0398: Unknown result type (might be due to invalid IL or missing references) //IL_0405: Unknown result type (might be due to invalid IL or missing references) //IL_0419: Unknown result type (might be due to invalid IL or missing references) //IL_0420: Unknown result type (might be due to invalid IL or missing references) //IL_0425: Unknown result type (might be due to invalid IL or missing references) //IL_042a: Unknown result type (might be due to invalid IL or missing references) //IL_0431: Unknown result type (might be due to invalid IL or missing references) //IL_0442: Unknown result type (might be due to invalid IL or missing references) //IL_0466: Unknown result type (might be due to invalid IL or missing references) //IL_0485: Unknown result type (might be due to invalid IL or missing references) //IL_049d: Unknown result type (might be due to invalid IL or missing references) //IL_049f: Unknown result type (might be due to invalid IL or missing references) //IL_04a4: Unknown result type (might be due to invalid IL or missing references) //IL_04b0: Unknown result type (might be due to invalid IL or missing references) //IL_04b7: Unknown result type (might be due to invalid IL or missing references) //IL_04be: Unknown result type (might be due to invalid IL or missing references) //IL_04c5: Unknown result type (might be due to invalid IL or missing references) //IL_04ca: Unknown result type (might be due to invalid IL or missing references) bool flag = forceBig != null; if (!flag && (Sheltered() || !BloodMoonPlugin.SpawnMonsters.Value || !Moon.Active)) { return null; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead() || ((Character)localPlayer).IsTeleporting() || ((Character)localPlayer).InInterior() || (Object)(object)ZoneSystem.instance == (Object)null || (Object)(object)ZNetScene.instance == (Object)null) { return "You need to be alive and outside."; } Vector3 position = ((Component)localPlayer).transform.position; int num = 0; foreach (Character allCharacter in Character.GetAllCharacters()) { if (!((Object)(object)allCharacter == (Object)null) && !allCharacter.IsPlayer() && !allCharacter.IsDead() && !allCharacter.IsTamed()) { Vector3 val = ((Component)allCharacter).transform.position - position; if (!(((Vector3)(ref val)).sqrMagnitude > 3600f) && (Object)(object)((Component)allCharacter).GetComponent<MonsterAI>() != (Object)null) { num++; } } } if (!flag && num >= Mathf.RoundToInt((float)BloodMoonPlugin.MaxNearby.Value * Intensity)) { return null; } RefreshConfig(); bool value = BloodMoonPlugin.FollowBosses.Value; if (value) { Build(_pools, follow: true, (Biome)0, 0f, 0f); if (!flag && _pools.Regular.Count == 0 && _pools.Big.Count == 0) { return null; } } Entry entry = null; if (flag) { if (!value) { Build(_pools, follow: true, (Biome)0, 0f, 0f); } if (forceBig.Length > 0) { foreach (Entry item in _pools.Big) { if (string.Equals(item.Name, forceBig, StringComparison.OrdinalIgnoreCase)) { entry = item; } } if (entry == null) { GameObject prefab = ZNetScene.instance.GetPrefab(forceBig); Character val2 = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<Character>() : null); if ((Object)(object)val2 == (Object)null || (Object)(object)prefab.GetComponent<MonsterAI>() == (Object)null) { return "No creature called '" + forceBig + "'. Use the name from BigMonsters, e.g. Troll."; } entry = new Entry { Prefab = prefab, Name = ((Object)prefab).name, GroundOffset = (val2.m_flying ? 8f : 0f), Tier = 0, Big = true }; } } else { entry = Pick(_pools.Big, _pools.Newest, weighted: false, out var _, 0.5f, falloff: false); if (entry == null) { return "No big monster unlocked yet (beat Eikthyr first), or name one: bloodmoon big Troll"; } } } int num2 = Moon.NightKey(); if (num2 != _bigNight) { _bigNight = num2; _bigDue = BloodMoonPlugin.MaxBig.Value > 0 && Random.value < Mathf.Clamp01(BloodMoonPlugin.BigChance.Value); _bigAt = Time.time + (Moon.Forced ? Random.Range(10f, 30f) : Random.Range(45f, 240f)); BloodMoonPlugin.Log.LogInfo((object)(_bigDue ? ("A big monster will come for you this blood moon, in about " + Mathf.RoundToInt(_bigAt - Time.time) + " s.") : "No big monster for you this blood moon.")); } bool flag2 = flag || (_bigDue && Time.time >= _bigAt && NearbyPlayers >= Mathf.Max(1, BloodMoonPlugin.BigMinPlayers.Value) && BigCount(position) < Mathf.Max(1, BloodMoonPlugin.MaxBig.Value)); float waterLevel = ZoneSystem.instance.m_waterLevel; float num5 = default(float); float num10 = default(float); for (int i = 0; i < 30; i++) { float num3 = Random.Range(0f, (float)Math.PI * 2f); float num4 = ((i < 10) ? Random.Range(22f, 40f) : Random.Range(40f, 90f)); Vector3 val3 = position + new Vector3(Mathf.Cos(num3), 0f, Mathf.Sin(num3)) * num4; if (!ZNetScene.instance.IsAreaReady(val3) || !ZoneSystem.instance.GetSolidHeight(val3, ref num5, 1000) || num5 < waterLevel + 0.3f || Mathf.Abs(num5 - position.y) > 30f) { continue; } val3.y = num5; if ((Object)(object)EffectArea.IsPointInsideArea(val3, (Type)4, 3f) != (Object)null) { continue; } Biome val4 = Heightmap.FindBiome(val3); if (!value) { Pools pools = _pools; Biome spotBiome = val4; float alt = num5 - waterLevel; Vector2 val5 = new Vector2(val3.x, val3.z); Build(pools, follow: false, spotBiome, alt, ((Vector2)(ref val5)).magnitude); } Entry entry2 = null; bool fromNewest2 = false; bool flag3 = false; if (entry != null) { entry2 = entry; flag3 = true; } else if (flag2 && _pools.Big.Count > 0) { entry2 = Pick(_pools.Big, _pools.Newest, weighted: false, out fromNewest2, 0.5f, falloff: false); flag3 = entry2 != null; } if (entry2 == null) { entry2 = Pick(_pools.Regular, _pools.Newest, weighted: true, out fromNewest2, BloodMoonPlugin.NewestShare.Value, falloff: true); } if (entry2 == null) { continue; } int num6 = Mathf.Max(1, BloodMoonPlugin.GroupMin.Value); int num7 = Mathf.Max(num6, BloodMoonPlugin.GroupMax.Value); int num8 = Random.Range(num6, num7 + 1); Character component = entry2.Prefab.GetComponent<Character>(); if (flag3 || ((Object)(object)component != (Object)null && component.m_health >= 400f)) { num8 = 1; } GameObject val6 = null; if (!flag3 && entry2.Name == "Greydwarf" && !_exclude.Contains("Greydwarf_Elite") && Random.value < Mathf.Clamp01(BloodMoonPlugin.BruteChance.Value)) { val6 = ZNetScene.instance.GetPrefab("Greydwarf_Elite"); if ((Object)(object)val6 != (Object)null && (Object)(object)val6.GetComponent<MonsterAI>() == (Object)null) { val6 = null; } } int num9 = 0; if (!flag) { _wave.Clear(); _waveSize = 0; } for (int j = 0; j < num8 + (((Object)(object)val6 != (Object)null) ? 1 : 0); j++) { GameObject val7 = ((j < num8) ? entry2.Prefab : val6); Vector3 val8 = val3 + new Vector3(Random.Range(-3f, 3f), 0f, Random.Range(-3f, 3f)); if (!ZoneSystem.instance.GetSolidHeight(val8, ref num10, 1000) || num10 < waterLevel + 0.3f) { continue; } val8.y = num10 + 0.5f + entry2.GroundOffset; GameObject obj = Object.Instantiate<GameObject>(val7, val8, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f)); Character component2 = obj.GetComponent<Character>(); if ((Object)(object)component2 != (Object)null && (!flag3 || BloodMoonPlugin.BigStars.Value)) { float value2 = Random.value; float num11 = Mathf.Clamp01(BloodMoonPlugin.TwoStarChance.Value * Intensity); float num12 = Mathf.Clamp01(BloodMoonPlugin.OneStarChance.Value * Intensity); if (value2 < num11) { component2.SetLevel(3); } else if (value2 < num11 + num12) { component2.SetLevel(2); } } MonsterAI component3 = obj.GetComponent<MonsterAI>(); if ((Object)(object)component3 != (Object)null) { try { if (((BaseAI)component3).IsSleeping() && WakeM != null) { WakeM.Invoke(component3, null); } } catch (Exception) { } component3.SetDespawnInDay(true); if (BloodMoonPlugin.HuntPlayers.Value) { ((BaseAI)component3).SetHuntPlayer(true); } _mine.Add(component3); } if ((Object)(object)component2 != (Object)null) { MarkWave(component2); if (!flag) { _wave.Add(component2); } } if (flag3 && (Object)(object)component2 != (Object)null) { _mineBig.Add(component2); BigHud.Mark(component2); } num9++; } if (num9 > 0 && !flag) { _waveSize = _wave.Count; _waveAt = Time.time; } if (num9 > 0) { string text = ((!value) ? (" in " + ((object)(*(Biome*)(&val4))/*cast due to .constrained prefix*/).ToString()) : (fromNewest2 ? (" (newest biome, " + BiomeName[entry2.Tier] + ")") : (" (earlier biome, " + BiomeName[entry2.Tier] + ")"))); if (flag3) { BloodMoonPlugin.Log.LogInfo((object)("Big monster: " + entry2.Name + text + ".")); if (!flag) { _bigDue = false; } try { string text2 = (((Object)(object)component != (Object)null) ? component.m_name : entry2.Name); string text3 = "A " + text2 + " has come for " + localPlayer.GetPlayerName() + "!"; if ((Object)(object)MessageHud.instance != (Object)null && ZRoutedRpc.instance != null) { MessageHud.instance.MessageAll((MessageType)2, text3); } } catch (Exception) { } } else { BloodMoonPlugin.Log.LogInfo((object)("Wave: " + num9 + " x " + entry2.Name + (((Object)(object)val6 != (Object)null) ? " (one of them a brute)" : "") + text + ".")); } } if (!flag) { return null; } if (num9 <= 0) { return "Could not place it, try again."; } return "Spawned " + entry2.Name + " near you."; } if (!flag) { return null; } return "No open ground 22-90 m from you to spawn it (not in water or inside a base). Try somewhere else."; } static Spawner() { Biome[] array = new Biome[8]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); Order = (Biome[])(object)array; BossKey = new string[8] { "", "defeated_eikthyr", "defeated_gdking", "defeated_bonemass", "defeated_dragon", "defeated_goblinking", "defeated_queen", "defeated_fader" }; BossName = new string[8] { "", "Eikthyr", "The Elder", "Bonemass", "Moder", "Yagluth", "The Queen", "Fader" }; BiomeName = new string[8] { "Meadows", "Black Forest", "Swamp", "Mountains", "Plains", "Mistlands", "Ashlands", "Deep North" }; NeverOnLand = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Leech", "Leech_cave", "Serpent", "BonemawSerpent" }; _exclude = new HashSet<string>(StringComparer.OrdinalIgnoreCase); _big = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase); _missingWarned = new HashSet<string>(StringComparer.OrdinalIgnoreCase); _mine = new List<MonsterAI>(); _mineBig = new List<Character>(); _seen = new HashSet<Character>(); _tiers = new List<int>(); _pools = new Pools(); WaveKey = StringExtensionMethods.GetStableHashCode("burks_bloodmoon_wave"); _wave = new List<Character>(); WakeM = AccessTools.Method(typeof(MonsterAI), "Wakeup", (Type[])null, (Type[])null); _bigNight = int.MinValue; _players = 1; _playersAt = -10f; } } [HarmonyPatch(typeof(EnvMan), "SetEnv")] public static class Sky { private static float _k; private static readonly int SunFog = Shader.PropertyToID("_SunFogColor"); private static readonly int Sun = Shader.PropertyToID("_SunColor"); private static readonly int Ambient = Shader.PropertyToID("_AmbientColor"); public static void Fade(float dt) { bool flag = false; try { flag = BloodMoonPlugin.RedSky.Value && (Object)(object)Player.m_localPlayer != (Object)null && Moon.Active && !((Character)Player.m_localPlayer).InInterior(); } catch { flag = false; } _k = Mathf.MoveTowards(_k, flag ? 1f : 0f, dt / 6f); } private static Color Tint(Color c, float amount) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: 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_0044: 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_0050: 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) float num = Mathf.Max(c.r, Mathf.Max(c.g, c.b)); Color val = default(Color); ((Color)(ref val))..ctor(Mathf.Min(1.5f, num * 1.5f + 0.1f), num * 0.12f, num * 0.1f, c.a); return Color.Lerp(c, val, amount); } [HarmonyPostfix] public static void Postfix(EnvMan __instance) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0092: 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_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) if (_k <= 0.001f) { return; } try { float amount = _k * Mathf.Clamp01(BloodMoonPlugin.RedStrength.Value); RenderSettings.ambientLight = Tint(RenderSettings.ambientLight, amount); RenderSettings.fogColor = Tint(RenderSettings.fogColor, amount); if ((Object)(object)__instance.m_dirLight != (Object)null) { __instance.m_dirLight.color = Tint(__instance.m_dirLight.color, amount); } Shader.SetGlobalColor(SunFog, Tint(Shader.GetGlobalColor(SunFog), amount)); Shader.SetGlobalColor(Sun, Tint(Shader.GetGlobalColor(Sun), amount)); Shader.SetGlobalColor(Ambient, Tint(Shader.GetGlobalColor(Ambient), amount)); } catch { } } } [HarmonyPatch(typeof(EnvMan), "CanSleep")] public static class SleepPatch { [HarmonyPostfix] public static void Postfix(ref bool __result) { try { if (__result && BloodMoonPlugin.BlockSleep.Value && Moon.Active) { __result = false; } } catch { } } } public static class Commands { private static bool _done; private static bool _madeNight; public static void Register() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_002e: Unknown result type (might be due to invalid IL or missing references) if (_done) { return; } _done = true; try { new ConsoleCommand("bloodmoon", "start | stop | status | big [name] - test the blood moon on your own game; status lists which creatures it can send, big spawns a big monster now", new ConsoleEvent(Run), false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); } catch (Exception ex) { BloodMoonPlugin.Log.LogWarning((object)("Could not add the 'bloodmoon' console command: " + ex.Message)); } } private static void Run(ConsoleEventArgs args) { switch ((args.Args.Length > 1) ? args.Args[1].ToLowerInvariant() : "status") { case "start": { if (!Moon.Forced) { Moon.ForcedRuns++; } Moon.Forced = true; bool flag = false; if ((Object)(object)EnvMan.instance != (Object)null && !EnvMan.instance.m_debugTimeOfDay) { Moon.Clock(out var _, out var f); if (f > 0.15f && f < 0.85f) { EnvMan.instance.m_debugTimeOfDay = true; EnvMan.instance.m_debugTime = 0f; _madeNight = true; flag = true; } } args.Context.AddString("Blood moon forced on (your game only)" + (flag ? ", and it is midnight for you until you stop it" : "") + ". 'bloodmoon stop' ends it."); return; } case "big": { string forceBig = ((args.Args.Length > 2) ? args.Args[2] : ""); args.Context.AddString(Spawner.Wave(forceBig) ?? "Nothing spawned."); return; } case "stop": Moon.Forced = false; Moon.ClearLatch(); if (_madeNight && (Object)(object)EnvMan.instance != (Object)null) { EnvMan.instance.m_debugTimeOfDay = false; } _madeNight = false; args.Context.AddString("Forced blood moon ended; the clock is back to the real time."); return; } int num = Mathf.Max(1, BloodMoonPlugin.IntervalDays.Value); Moon.Clock(out var day2, out var f2); int num2 = (day2 / num + 1) * num; if (day2 > 0 && day2 % num == 0 && !Moon.Active && f2 < 0.85f) { num2 = day2; } args.Context.AddString("Day " + day2 + ". Blood moon " + (Moon.Active ? "is up now" : ("next on the night of day " + num2)) + " (every " + num + " days)."); try { foreach (string item in Spawner.Describe()) { args.Context.AddString(item); } } catch (Exception ex) { args.Context.AddString("Could not list blood moon creatures: " + ex.Message); } } } [HarmonyPatch(typeof(MusicMan), "UpdateCurrentMusic")] public static class Music { public const string Name = "bloodmoon"; private static AudioClip _clip; private static readonly MethodInfo StopM = AccessTools.Method(typeof(MusicMan), "StopMusic", (Type[])null, (Type[])null); private static readonly MethodInfo CurrentM = AccessTools.Method(typeof(MusicMan), "GetCurrentMusic", (Type[])null, (Type[])null); private static AudioSource _src; private static bool _played; private static bool _warned; private static float _vol; public static IEnumerator Load(string dir) { string file = null; try { string[] files = Directory.GetFiles(dir); foreach (string text in files) { string text2 = Path.GetExtension(text).ToLowerInvariant(); if ((!(text2 != ".ogg") || !(text2 != ".wav") || !(text2 != ".mp3")) && (file == null || Path.GetFileNameWithoutExtension(text).ToLowerInvariant() == "bloodmoon")) { file = text; } } } catch (Exception ex) { BloodMoonPlugin.Log.LogWarning((object)("Could not look for a music file: " + ex.Message)); } if (file == null) { BloodMoonPlugin.Log.LogInfo((object)"No music file (.ogg, .wav, .mp3) next to BloodMoon.dll; blood moons will be silent."); yield break; } string text3 = Path.GetExtension(file).ToLowerInvariant(); AudioType val = (AudioType)((text3 == ".ogg") ? 14 : ((text3 == ".wav") ? 20 : 13)); UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip(new Uri(file).AbsoluteUri, val); try { yield return req.SendWebRequest(); AudioClip val2 = null; try { if (string.IsNullOrEmpty(req.error)) { val2 = DownloadHandlerAudioClip.GetContent(req); } } catch (Exception ex2) { BloodMoonPlugin.Log.LogWarning((object)("Music file could not be decoded: " + ex2.Message)); } if ((Object)(object)val2 == (Object)null || val2.length <= 0f) { BloodMoonPlugin.Log.LogWarning((object)("Could not load music file " + Path.GetFileName(file) + ": " + req.error)); yield break; } ((Object)val2).name = "bloodmoon"; _clip = val2; BloodMoonPlugin.Log.LogInfo((object)("Music loaded: " + Path.GetFileName(file) + " (" + Mathf.RoundToInt(val2.length) + " s).")); } finally { ((IDisposable)req)?.Dispose(); } } private static bool Wanted() { Player localPlayer = Player.m_localPlayer; if ((Object)(object)_clip == (Object)null || !BloodMoonPlugin.MusicOn.Value || (Object)(object)localPlayer == (Object)null || !Moon.Active) { return false; } if (!BloodMoonPlugin.MusicInDungeons.Value) { return !((Character)localPlayer).InInterior(); } return true; } public static void Tick(float dt) { //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Expected O, but got Unknown try { if ((Object)(object)_clip == (Object)null) { return; } if (!((Object)(object)Player.m_localPlayer != (Object)null) || !Moon.Active) { _played = false; } bool flag = Wanted(); if (flag && !_played) { _played = true; if ((Object)(object)_src == (Object)null) { GameObject val = new GameObject("BloodMoonMusic"); Object.DontDestroyOnLoad((Object)val); _src = val.AddComponent<AudioSource>(); _src.spatialBlend = 0f; _src.loop = false; _src.playOnAwake = false; _src.bypassReverbZones = true; _src.priority = 0; } _src.clip = _clip; _vol = 0f; _src.volume = 0f; _src.Play(); BloodMoonPlugin.Log.LogInfo((object)"Blood moon track playing."); } if (!((Object)(object)_src == (Object)null) && _src.isPlaying) { _vol = Mathf.MoveTowards(_vol, flag ? 1f : 0f, dt / 2f); _src.volume = _vol * Mathf.Clamp01(BloodMoonPlugin.MusicVolume.Value) * Mathf.Clamp01(MusicMan.m_masterMusicVolume); if (!flag && _vol <= 0f) { _src.Stop(); } } } catch (Exception ex) { if (!_warned) { _warned = true; BloodMoonPlugin.Log.LogWarning((object)("Music failed: " + ex)); } } } [HarmonyPrefix] public static bool Prefix(MusicMan __instance) { try { if (!Wanted()) { return true; } if (!string.IsNullOrEmpty(CurrentM.Invoke(__instance, null) as string)) { StopM.Invoke(__instance, null); } return false; } catch (Exception) { return true; } } } public static class Countdown { public static bool Failed; private static GUIStyle _style; private static Font _font; private static bool _fontSearched; private static Texture2D _moon; private static string _text = ""; private static bool _red; private static float _next; private static void Refresh() { if (Time.unscaledTime < _next) { return; } _next = Time.unscaledTime + 1f; _text = ""; _red = false; if (Moon.Active) { _text = "Blood moon"; _red = true; } else { if (!Moon.Clock(out var day, out var _)) { return; } if (Moon.Tonight) { _text = "Blood moon tonight"; _red = true; return; } for (int i = day + 1; i < day + 400; i++) { if (Moon.IsBloodDay(i)) { int num = i - day; _text = "Blood moon in " + num + ((num == 1) ? " day" : " days"); break; } } } } private static Texture2D MoonIcon() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_00a7: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false); for (int i = 0; i < 32; i++) { for (int j = 0; j < 32; j++) { float num = (float)j + 0.5f - 16f; float num2 = (float)i + 0.5f - 16f; float num3 = Mathf.Sqrt(num * num + num2 * num2) / 16f; float num4 = Mathf.Clamp01((1f - num3) * 8f); float num5 = Mathf.Lerp(1f, 0.7f, Mathf.Clamp01((num + num2) / 32f + 0.5f)); val.SetPixel(j, i, new Color(0.85f * num5, 0.12f * num5, 0.1f * num5, num4)); } } val.Apply(); return val; } public static void Draw() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Invalid comparison between Unknown and I4 //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Invalid comparison between Unknown and I4 //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: 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_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Expected O, but got Unknown //IL_0279: Unknown result type (might be due to invalid IL or missing references) //IL_0283: Expected O, but got Unknown //IL_027e: Unknown result type (might be due to invalid IL or missing references) //IL_02bb: Unknown result type (might be due to invalid IL or missing references) //IL_02c0: Unknown result type (might be due to invalid IL or missing references) //IL_02c5: Unknown result type (might be due to invalid IL or missing references) //IL_02db: Unknown result type (might be due to invalid IL or missing references) //IL_0313: Unknown result type (might be due to invalid IL or missing references) //IL_035d: Unknown result type (might be due to invalid IL or missing references) //IL_0342: Unknown result type (might be due to invalid IL or missing references) //IL_0367: Unknown result type (might be due to invalid IL or missing references) //IL_0378: Unknown result type (might be due to invalid IL or missing references) //IL_038c: Unknown result type (might be due to invalid IL or missing references) if ((int)Event.current.type != 7 || !BloodMoonPlugin.ShowCountdown.Value || (Object)(object)Player.m_localPlayer == (Object)null || Failed) { return; } Minimap instance = Minimap.instance; if ((Object)(object)instance == (Object)null || (int)instance.m_mode != 1 || (Object)(object)instance.m_mapImageSmall == (Object)null || Hud.IsUserHidden() || !((Component)instance.m_mapImageSmall).gameObject.activeInHierarchy) { return; } Refresh(); if (_text.Length == 0) { return; } RectTransform rectTransform = ((Graphic)instance.m_mapImageSmall).rectTransform; Vector3[] array = (Vector3[])(object)new Vector3[4]; rectTransform.GetWorldCorners(array); Canvas componentInParent = ((Component)rectTransform).GetComponentInParent<Canvas>(); Vector2 val = RectTransformUtility.WorldToScreenPoint(((Object)(object)componentInParent != (Object)null && (int)componentInParent.renderMode != 0) ? componentInParent.worldCamera : null, array[1]); float x = val.x; float num = (float)Screen.height - val.y; float num2 = Mathf.Max(0.6f, (float)Screen.height / 1080f); if (!_fontSearched) { _fontSearched = true; Font[] array2 = Resources.FindObjectsOfTypeAll<Font>(); foreach (Font val2 in array2) { if ((Object)(object)val2 != (Object)null && ((Object)val2).name.IndexOf("Averia", StringComparison.OrdinalIgnoreCase) >= 0) { _font = val2; if (((Object)val2).name.IndexOf("Bold", StringComparison.OrdinalIgnoreCase) >= 0) { break; } } } } if (_style == null) { _style = new GUIStyle(GUI.skin.label); _style.alignment = (TextAnchor)5; _style.fontStyle = (FontStyle)(!((Object)(object)_font != (Object)null)); if ((Object)(object)_font != (Object)null) { _style.font = _font; } _style.clipping = (TextClipping)0; _style.wordWrap = false; } if ((Object)(object)_moon == (Object)null) { _moon = MoonIcon(); } _style.fontSize = Mathf.RoundToInt(17f * num2); float num3 = 24f * num2; float num4 = 15f * num2; float num5 = 6f * num2; float num6 = x - 10f * num2 + BloodMoonPlugin.CountdownX.Value * num2; float num7 = num - num3 - 2f * num2 + BloodMoonPlugin.CountdownY.Value * num2; if (num7 < 2f * num2) { num7 = num + 2f * num2; } float x2 = _style.CalcSize(new GUIContent(_text)).x; Rect val3 = default(Rect); ((Rect)(ref val3))..ctor(num6 - x2, num7, x2, num3); Rect val4 = new Rect(((Rect)(ref val3)).x - num5 - num4, num7 + (num3 - num4) / 2f, num4, num4); Color color = GUI.color; GUI.color = new Color(0f, 0f, 0f, 0.75f); GUI.Label(new Rect(((Rect)(ref val3)).x + 1.5f * num2, ((Rect)(ref val3)).y + 1.5f * num2, ((Rect)(ref val3)).width, ((Rect)(ref val3)).height), _text, _style); GUI.color = (_red ? new Color(1f, 0.42f, 0.36f, 1f) : new Color(0.95f, 0.9f, 0.82f, 1f)); GUI.Label(val3, _text, _style); GUI.color = Color.white; GUI.DrawTexture(val4, (Texture)(object)_moon); GUI.color = color; } } [HarmonyPatch(typeof(EnemyHud), "LateUpdate")] public static class BigHud { private static readonly int Key = StringExtensionMethods.GetStableHashCode("burks_bloodmoon_big"); private static readonly List<Character> _marked = new List<Character>(); private static readonly List<Character> _on = new List<Character>(); private static float _next; public static void Mark(Character c) { try { ZNetView component = ((Component)c).GetComponent<ZNetView>(); if ((Object)(object)component != (Object)null && component.IsValid()) { component.GetZDO().Set(Key, true); } } catch (Exception) { } } private static void Refresh() { if (Time.time < _next) { return; } _next = Time.time + 1f; _marked.Clear(); foreach (Character allCharacter in Character.GetAllCharacters()) { if (!((Object)(object)allCharacter == (Object)null) && !allCharacter.m_boss && !allCharacter.IsPlayer() && !allCharacter.IsDead()) { ZNetView component = ((Component)allCharacter).GetComponent<ZNetView>(); if ((Object)(object)component != (Object)null && component.IsValid() && component.GetZDO().GetBool(Key, false)) { _marked.Add(allCharacter); } } } } private static void Prefix() { _on.Clear(); if (!BloodMoonPlugin.BigHealthBar.Value) { return; } try { Refresh(); foreach (Character item in _marked) { if ((Object)(object)item != (Object)null && !item.m_boss) { item.m_boss = true; _on.Add(item); } } } catch (Exception) { } } private static Exception Finalizer(Exception __exception) { foreach (Character item in _on) { if ((Object)(object)item != (Object)null) { item.m_boss = false; } } _on.Clear(); return __exception; } } [HarmonyPatch(typeof(BaseAI), "FindEnemy")] public static class HuntPatch { private static readonly FieldRef<BaseAI, ZNetView> NView = AccessTools.FieldRefAccess<BaseAI, ZNetView>("m_nview"); private static void Postfix(BaseAI __instance, ref Character __result) { //IL_0065: Unknown result type (might be due to invalid IL or missing references) try { if (((Object)(object)__result != (Object)null && __result.IsPlayer()) || !BloodMoonPlugin.HuntPlayers.Value || !(__instance is MonsterAI)) { return; } ZNetView val = NView.Invoke(__instance); if (!((Object)(object)val == (Object)null) && val.IsValid() && val.GetZDO().GetBool(Spawner.WaveKey, false)) { Player closestPlayer = Player.GetClosestPlayer(((Component)__instance).transform.position, Mathf.Max(10f, BloodMoonPlugin.HuntRange.Value)); if ((Object)(object)closestPlayer != (Object)null && !((Character)closestPlayer).InGhostMode() && !closestPlayer.InDebugFlyMode() && !((Character)closestPlayer).IsDead()) { __result = (Character)(object)closestPlayer; } } } catch (Exception) { } } }