using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using NightBloom.Services;
using ProjectM;
using ProjectM.CastleBuilding;
using ProjectM.Physics;
using ProjectM.Scripting;
using ProjectM.Shared;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
using VampireCommandFramework;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace NightBloom
{
internal static class Core
{
private static MonoBehaviour? _monoBehaviour;
private static bool _hasInitialized;
public static World Server { get; } = GetWorld("Server") ?? throw new Exception("No Server world — is this running on a dedicated server?");
public static EntityManager EntityManager { get; } = Server.EntityManager;
public static GenerateCastleSystem GenerateCastle { get; private set; } = null;
public static ServerScriptMapper ServerScriptMapper { get; private set; } = null;
public static ServerGameManager ServerGameManager => ServerScriptMapper.GetServerGameManager();
public static double ServerTime => ServerGameManager.ServerTime;
public static ManualLogSource Log => Plugin.Logger;
public static void InitializeAfterLoaded()
{
if (!_hasInitialized)
{
GenerateCastle = Server.GetOrCreateSystemManaged<GenerateCastleSystem>();
ServerScriptMapper = Server.GetExistingSystemManaged<ServerScriptMapper>();
NightBloomService.Start();
_hasInitialized = true;
Log.LogInfo((object)"[NightBloom] InitializeAfterLoaded completed.");
}
}
public static Coroutine StartCoroutine(IEnumerator routine)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
if ((Object)(object)_monoBehaviour == (Object)null)
{
GameObject val = new GameObject("NightBloom");
_monoBehaviour = (MonoBehaviour?)(object)val.AddComponent<IgnorePhysicsDebugSystem>();
Object.DontDestroyOnLoad((Object)val);
}
return _monoBehaviour.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(routine));
}
public static void StopCoroutine(Coroutine coroutine)
{
if ((Object)(object)_monoBehaviour != (Object)null)
{
_monoBehaviour.StopCoroutine(coroutine);
}
}
private static World? GetWorld(string name)
{
Enumerator<World> enumerator = World.s_AllWorlds.GetEnumerator();
while (enumerator.MoveNext())
{
if (enumerator.Current.Name == name)
{
return enumerator.Current;
}
}
return null;
}
}
internal static class ECSExtensions
{
public unsafe static T Read<T>(this Entity entity) where T : struct
{
//IL_000d: 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)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
ComponentType val = default(ComponentType);
((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
EntityManager entityManager = Core.EntityManager;
return Marshal.PtrToStructure<T>(new IntPtr(((EntityManager)(ref entityManager)).GetComponentDataRawRO(entity, val.TypeIndex)));
}
public unsafe static void Write<T>(this Entity entity, T value) where T : struct
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
ComponentType val = default(ComponentType);
((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
byte[] array = StructureToByteArray(value);
int num = Marshal.SizeOf<T>();
fixed (byte* ptr = array)
{
EntityManager entityManager = Core.EntityManager;
((EntityManager)(ref entityManager)).SetComponentDataRaw(entity, val.TypeIndex, (void*)ptr, num);
}
}
public static bool Has<T>(this Entity entity)
{
//IL_000d: 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)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
ComponentType val = default(ComponentType);
((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
EntityManager entityManager = Core.EntityManager;
return ((EntityManager)(ref entityManager)).HasComponent(entity, val);
}
public static DynamicBuffer<T> ReadBuffer<T>(this Entity entity) where T : struct
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
EntityManager entityManager = Core.Server.EntityManager;
return ((EntityManager)(ref entityManager)).GetBuffer<T>(entity, false);
}
private static byte[] StructureToByteArray<T>(T structure) where T : struct
{
int num = Marshal.SizeOf(structure);
byte[] array = new byte[num];
IntPtr intPtr = Marshal.AllocHGlobal(num);
Marshal.StructureToPtr(structure, intPtr, fDeleteOld: true);
Marshal.Copy(intPtr, array, 0, num);
Marshal.FreeHGlobal(intPtr);
return array;
}
}
internal static class KnownPrefabs
{
public static readonly Dictionary<string, int> All = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase)
{
{ "Bone", 1821405450 },
{ "GraveDust", -608131642 },
{ "SwordBone", -2085919458 },
{ "AxeBone", -1958888844 },
{ "MaceBone", 1588258447 },
{ "SpearBone", 2038011836 },
{ "ReaperBone", -152327780 },
{ "SlashersBone", -588909332 },
{ "SwordReinforcedBone", -796306296 },
{ "AxeReinforcedBone", -1391446205 },
{ "MaceReinforcedBone", -1998017941 },
{ "SpearReinforcedBone", 1244180446 },
{ "ReaperReinforcedBone", 1402953369 },
{ "SlashersReinforcedBone", 926722036 },
{ "SwordCopper", -2037272000 },
{ "AxeCopper", 518802008 },
{ "MaceCopper", -331345186 },
{ "SpearCopper", 1370755976 },
{ "ReaperCopper", 1522792650 },
{ "SlashersCopper", 1499160417 },
{ "SwordMercilessCopper", -1219959051 },
{ "AxeMercilessCopper", -491969324 },
{ "MaceMercilessCopper", 343324920 },
{ "SpearMercilessCopper", 790210443 },
{ "ReaperMercilessCopper", 1048518929 },
{ "SlashersMercilessCopper", -1042299347 },
{ "SwordIron", -903587404 },
{ "AxeIron", -1579575933 },
{ "MaceIron", -1714012261 },
{ "SpearIron", 1853029976 },
{ "ReaperIron", -2081286944 },
{ "SlashersIron", -314614708 },
{ "GreatSwordIron", -768054337 },
{ "TwinBladesIron", -1122389049 },
{ "ClawsIron", -1333849822 },
{ "WhipIron", -847062445 },
{ "SwordMercilessIron", -435501075 },
{ "AxeMercilessIron", 198951695 },
{ "MaceMercilessIron", -276593802 },
{ "SpearMercilessIron", 1065194820 },
{ "ReaperMercilessIron", 1778128946 },
{ "SlashersMercilessIron", 866934844 },
{ "GreatSwordMercilessIron", 82781195 },
{ "TwinBladesMercilessIron", -1651990235 },
{ "ClawsMercilessIron", 1748886117 },
{ "WhipMercilessIron", 1393113320 },
{ "SwordRareAncestral", 1637216050 },
{ "AxeRareAncestral", 1259464735 },
{ "MaceRareAncestral", 1177597629 },
{ "SpearRareAncestral", 2001389164 },
{ "ReaperRareAncestral", -922125625 },
{ "SlashersRareAncestral", 1930526079 },
{ "GreatSwordRareAncestral", 869276797 },
{ "TwinBladesRareAncestral", -1634108038 },
{ "ClawsRareAncestral", -2060572315 },
{ "WhipRareAncestral", 1705984031 },
{ "SwordDarkSilver", -1455388114 },
{ "AxeDarkSilver", -1130238142 },
{ "MaceDarkSilver", -184713893 },
{ "SpearDarkSilver", -352704566 },
{ "ReaperDarkSilver", 6711686 },
{ "SlashersDarkSilver", 633666898 },
{ "GreatSwordDarkSilver", 674704033 },
{ "TwinBladesDarkSilver", -1595292245 },
{ "ClawsDarkSilver", -1470260175 },
{ "WhipDarkSilver", -960205578 },
{ "SwordSanguine", -774462329 },
{ "AxeSanguine", -2044057823 },
{ "MaceSanguine", -126076280 },
{ "SpearSanguine", -850142339 },
{ "ReaperSanguine", -2053917766 },
{ "SlashersSanguine", 1322545846 },
{ "GreatSwordSanguine", 147836723 },
{ "TwinBladesSanguine", -297349982 },
{ "ClawsSanguine", -1777908217 },
{ "WhipSanguine", -655095317 },
{ "SwordEpicAncestral", 195858450 },
{ "AxeEpicAncestral", -102830349 },
{ "MaceEpicAncestral", 1994084762 },
{ "SpearEpicAncestral", -1931117134 },
{ "ReaperEpicAncestral", -105026635 },
{ "SlashersEpicAncestral", 821410795 },
{ "GreatSwordEpicAncestral", -1173681254 },
{ "TwinBladesEpicAncestral", 152014105 },
{ "ClawsEpicAncestral", -27238530 },
{ "WhipEpicAncestral", 429323760 },
{ "SwordShadowMatter", -1215982687 },
{ "AxeShadowMatter", 2100090213 },
{ "MaceShadowMatter", 160471982 },
{ "SpearShadowMatter", 1307774440 },
{ "ReaperShadowMatter", -465491217 },
{ "SlashersShadowMatter", 506082542 },
{ "GreatSwordShadowMatter", 1322254792 },
{ "TwinBladesShadowMatter", -699863795 },
{ "WhipShadowMatter", 567413754 }
};
public static readonly Dictionary<int, int> WeaponTiers = new Dictionary<int, int>
{
{ -2085919458, 1 },
{ -1958888844, 1 },
{ 1588258447, 1 },
{ 2038011836, 1 },
{ -152327780, 1 },
{ -588909332, 1 },
{ -796306296, 2 },
{ -1391446205, 2 },
{ -1998017941, 2 },
{ 1244180446, 2 },
{ 1402953369, 2 },
{ 926722036, 2 },
{ -2037272000, 3 },
{ 518802008, 3 },
{ -331345186, 3 },
{ 1370755976, 3 },
{ 1522792650, 3 },
{ 1499160417, 3 },
{ -1219959051, 4 },
{ -491969324, 4 },
{ 343324920, 4 },
{ 790210443, 4 },
{ 1048518929, 4 },
{ -1042299347, 4 },
{ -903587404, 5 },
{ -1579575933, 5 },
{ -1714012261, 5 },
{ 1853029976, 5 },
{ -2081286944, 5 },
{ -314614708, 5 },
{ -768054337, 5 },
{ -1122389049, 5 },
{ -1333849822, 5 },
{ -847062445, 5 },
{ -435501075, 6 },
{ 198951695, 6 },
{ -276593802, 6 },
{ 1065194820, 6 },
{ 1778128946, 6 },
{ 1887724512, 6 },
{ 866934844, 6 },
{ 82781195, 6 },
{ -1651990235, 6 },
{ 1748886117, 6 },
{ 1393113320, 6 },
{ 1637216050, 7 },
{ 1259464735, 7 },
{ 1177597629, 7 },
{ 2001389164, 7 },
{ -922125625, 7 },
{ 1930526079, 7 },
{ 869276797, 7 },
{ -1634108038, 7 },
{ -2060572315, 7 },
{ 1705984031, 7 },
{ -1455388114, 8 },
{ -1130238142, 8 },
{ -184713893, 8 },
{ -352704566, 8 },
{ 6711686, 8 },
{ 633666898, 8 },
{ 674704033, 8 },
{ -1595292245, 8 },
{ -1470260175, 8 },
{ -960205578, 8 },
{ -774462329, 9 },
{ -2044057823, 9 },
{ -126076280, 9 },
{ -850142339, 9 },
{ -2053917766, 9 },
{ 1322545846, 9 },
{ 147836723, 9 },
{ -297349982, 9 },
{ -1777908217, 9 },
{ -655095317, 9 },
{ 195858450, 10 },
{ -102830349, 10 },
{ 1994084762, 10 },
{ -1931117134, 10 },
{ -105026635, 10 },
{ 821410795, 10 },
{ -1173681254, 10 },
{ 152014105, 10 },
{ -27238530, 10 },
{ 429323760, 10 },
{ 2106567892, 10 },
{ 1239564213, 10 },
{ 675187526, 10 },
{ -1674680373, 10 },
{ -859437190, 10 },
{ -2068145306, 10 },
{ 1570363331, 10 },
{ 820408138, 10 },
{ 601169005, 10 },
{ -996999913, 10 },
{ -671246832, 10 },
{ -1215982687, 11 },
{ 2100090213, 11 },
{ 160471982, 11 },
{ 1307774440, 11 },
{ -465491217, 11 },
{ 506082542, 11 },
{ 1322254792, 11 },
{ -699863795, 11 },
{ 567413754, 11 }
};
public static readonly string[] TierNames = new string[12]
{
"", "Bone", "Reinforced Bone", "Copper", "Merciless Copper", "Iron", "Merciless Iron", "Rare Ancestral", "Dark Silver", "Sanguine",
"Epic Ancestral", "Shadow Matter"
};
public static int? Resolve(string nameOrGuid)
{
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
if (string.IsNullOrWhiteSpace(nameOrGuid))
{
return null;
}
string text = nameOrGuid.Trim();
if (int.TryParse(text, out var result))
{
return result;
}
if (All.TryGetValue(text, out var value))
{
return value;
}
ManualLogSource log = Core.Log;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(102, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[NightBloom] Unknown name in config: '");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'. Use a PrefabGUID integer or a known name (see documentation).");
}
log.LogWarning(val);
return null;
}
}
internal static class MyPluginInfo
{
public const string PLUGIN_GUID = "fumzou.NightBloom";
public const string PLUGIN_NAME = "NightBloom";
public const string PLUGIN_VERSION = "1.0.0";
}
internal static class NightBloomConfig
{
public static ConfigEntry<string> ControllerChestKeywords = null;
public static ConfigEntry<string> HarvestChestKeywords = null;
public static ConfigEntry<float> ConsumeIntervalSeconds = null;
public static ConfigEntry<float> ConsumeAmountPerInterval = null;
public static ConfigEntry<float> GrowthSpeedMultiplier = null;
public static ConfigEntry<string> FertilizerItems = null;
public static ConfigEntry<float> NoWeaponRadius = null;
public static ConfigEntry<float> ChestLinkRadius = null;
private static readonly ConfigEntry<float>[] _tierRadius = new ConfigEntry<float>[12];
private static readonly ConfigEntry<float>[] _tierDurability = new ConfigEntry<float>[12];
public static void Init(ConfigFile cfg)
{
ControllerChestKeywords = cfg.Bind<string>("1 - Chests", "ControllerChestKeywords", "fertilizer,fert", "Keywords used to detect the Fertilizer chest (not case-sensitive, separated by commas).\nThe Fertilizer chest must contain: one weapon (sets the harvest radius) + fertilizer items (Bone, GraveDust…).\n→ Simply rename a chest so its name contains one of these words.\n Example: name your chest 'Fertilizer' or 'Fert'");
HarvestChestKeywords = cfg.Bind<string>("1 - Chests", "HarvestChestKeywords", "harvest", "Keywords used to detect Harvest chests (not case-sensitive, separated by commas).\nHarvested plants are deposited into these chests automatically (nearest chest first).\n→ Rename any chest so its name contains one of these words.\n Example: name your chest 'Harvest'");
ConsumeIntervalSeconds = cfg.Bind<float>("2 - Consumption", "ConsumeIntervalSeconds", 1f, "How often (in seconds) the mod consumes fertilizer from the Fertilizer chest.\nCombine with ConsumeAmountPerInterval to control the consumption speed.\n→ 1.0 s + 1 item/interval = 1 item per second (default, balanced)\n→ 5.0 s + 1 item/interval = 1 item every 5 s (slow, resource-saving)\n→ 1.0 s + 5 items/interval = 5 items per second (fast, for large farms)");
ConsumeAmountPerInterval = cfg.Bind<float>("2 - Consumption", "ConsumeAmountPerInterval", 1f, "How many fertilizer credits are consumed per interval (see ConsumeIntervalSeconds).\nCredits required: 1 per plant harvested or accelerated each tick.\nItem values (configurable in FertilizerItems): Bone = 1 credit, GraveDust = 2 credits.");
GrowthSpeedMultiplier = cfg.Bind<float>("3 - Growth", "GrowthSpeedMultiplier", 2f, "How many times faster plants grow while the Fertilizer chest has fertilizer.\n→ 1.0 = normal speed (growth acceleration disabled)\n→ 2.0 = twice as fast (default)\n→ 5.0 = five times as fast");
FertilizerItems = cfg.Bind<string>("4 - Fertilizers", "FertilizerItems", "Bone:1.0,GraveDust:2.0", "Items accepted as fertilizer, written as 'Name:Power' pairs separated by commas.\nPower = number of credits that item provides when consumed.\nSupported names: Bone, GraveDust. For other items, use their PrefabGUID number.\nCheapest items (lowest power) are consumed first to preserve more powerful ones.\n→ Default: Bone = 1 credit, GraveDust = 2 credits\n→ Custom example: Bone:1.0,GraveDust:2.0,1234567890:3.0");
NoWeaponRadius = cfg.Bind<float>("5 - Radius", "NoWeaponRadius", 5f, "Harvest radius in meters when NO weapon is present in the Fertilizer chest.\nOnly plants within this distance from the chest are harvested or accelerated.");
ChestLinkRadius = cfg.Bind<float>("5 - Radius", "ChestLinkRadius", 45f, "Maximum distance in meters from the Fertilizer chest to search for Harvest chests.\nIncrease this value if your Harvest chests are far from the Fertilizer chest.");
float[] array = new float[12]
{
0f, 5f, 7f, 10f, 13f, 17f, 21f, 25f, 29f, 33f,
37f, 42f
};
float[] array2 = new float[12]
{
0f, 2f, 2f, 2f, 2f, 2f, 2f, 2f, 2f, 2f,
2f, 2f
};
for (int i = 1; i <= 11; i++)
{
string text = KnownPrefabs.TierNames[i];
string text2 = $"Tier{i:D2}_{text.Replace(" ", "")}";
string text3 = ((i == 1) ? "[Tier 01 – Bone] Harvest radius in meters.\nEach weapon tier has its own Radius and DurabilityLoss setting.\n Radius → how far the mod reaches when that weapon is in the Fertilizer chest.\n DurabilityLoss → durability removed from the weapon per plant harvested.\nThe mod always uses the highest-tier weapon found in the chest.\nTiers: 01=Bone 02=Reinforced Bone 03=Copper 04=Merciless Copper 05=Iron\n 06=Merciless Iron 07=Rare Ancestral 08=Dark Silver\n 09=Sanguine 10=Epic Ancestral 11=Shadow Matter" : $"[Tier {i:D2} – {text}] Harvest radius in meters.");
string text4 = ((i == 1) ? "[Tier 01 – Bone] Durability removed from the weapon per plant harvested." : $"[Tier {i:D2} – {text}] Durability removed per plant harvested.");
_tierRadius[i] = cfg.Bind<float>("6 - Per-Tier Weapon Settings", text2 + "_Radius", array[i], text3);
_tierDurability[i] = cfg.Bind<float>("6 - Per-Tier Weapon Settings", text2 + "_DurabilityLoss", array2[i], text4);
}
}
public static double GetCreditsPerSecond()
{
float num = Math.Max(0.05f, ConsumeIntervalSeconds.Value);
return Math.Max(0.01f, ConsumeAmountPerInterval.Value) / num;
}
public static double GetMaxBurst()
{
return Math.Max(0.01f, ConsumeAmountPerInterval.Value);
}
public static List<(int guid, float power)> GetFertilizerItems()
{
List<(int, float)> list = new List<(int, float)>();
string value = FertilizerItems.Value;
if (string.IsNullOrWhiteSpace(value))
{
return list;
}
string[] array = value.Split(',');
for (int i = 0; i < array.Length; i++)
{
string text = array[i].Trim();
int num = text.LastIndexOf(':');
if (num >= 0)
{
string nameOrGuid = text.Substring(0, num).Trim();
string s = text.Substring(num + 1).Trim();
int? num2 = KnownPrefabs.Resolve(nameOrGuid);
if (num2.HasValue && float.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out var result) && result > 0f)
{
list.Add((num2.Value, result));
}
}
}
return list;
}
public static float GetRadiusForTier(int tier)
{
if (tier < 1 || tier > 11)
{
return NoWeaponRadius.Value;
}
return _tierRadius[tier].Value;
}
public static float GetDurabilityLossForTier(int tier)
{
if (tier < 1 || tier > 11)
{
return 2f;
}
return Math.Max(0f, _tierDurability[tier].Value);
}
public static string[] GetControllerKeywords()
{
return SplitKeywords(ControllerChestKeywords.Value);
}
public static string[] GetHarvestKeywords()
{
return SplitKeywords(HarvestChestKeywords.Value);
}
private static string[] SplitKeywords(string raw)
{
if (string.IsNullOrWhiteSpace(raw))
{
return Array.Empty<string>();
}
string[] array = raw.Split(',');
string[] array2 = new string[array.Length];
for (int i = 0; i < array.Length; i++)
{
array2[i] = array[i].Trim().ToLowerInvariant();
}
return array2;
}
}
[BepInPlugin("fumzou.NightBloom", "NightBloom", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
internal static ManualLogSource Logger;
internal static Harmony Harmony;
internal static ConfigFile Cfg;
public override void Load()
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Expected O, but got Unknown
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Expected O, but got Unknown
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Expected O, but got Unknown
if (Application.productName != "VRisingServer")
{
((BasePlugin)this).Log.LogWarning((object)"NightBloom is a server-side mod. It will not run on a client.");
return;
}
Logger = ((BasePlugin)this).Log;
Cfg = ((BasePlugin)this).Config;
ManualLogSource log = ((BasePlugin)this).Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(10, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Loading ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("NightBloom");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" v");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
}
log.LogInfo(val);
NightBloomConfig.Init(((BasePlugin)this).Config);
Harmony = new Harmony("fumzou.NightBloom");
Harmony.PatchAll(Assembly.GetExecutingAssembly());
CommandRegistry.RegisterAll(Assembly.GetExecutingAssembly());
ManualLogSource log2 = ((BasePlugin)this).Log;
val = new BepInExInfoLogInterpolatedStringHandler(21, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("NightBloom");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded successfully.");
}
log2.LogInfo(val);
}
public override bool Unload()
{
CommandRegistry.UnregisterAssembly(Assembly.GetExecutingAssembly());
Harmony harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
return true;
}
}
}
namespace NightBloom.Services
{
internal static class NightBloomService
{
[CompilerGenerated]
private sealed class <TickLoop>d__10 : IEnumerator<object>, IEnumerator, IDisposable
{
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 <TickLoop>d__10(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Expected O, but got Unknown
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
int num = <>1__state;
if (num != 0)
{
if (num != 1)
{
return false;
}
<>1__state = -1;
try
{
Tick();
}
catch (Exception ex)
{
ManualLogSource log = Core.Log;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(25, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[NightBloom] Tick error: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
}
log.LogError(val);
}
}
else
{
<>1__state = -1;
}
<>2__current = (object)new WaitForSeconds(5f);
<>1__state = 1;
return true;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private static readonly PrefabGUID ExternalInventoryGuid = new PrefabGUID(1183666186);
private const float TickIntervalSeconds = 5f;
private const int MaxHarvestPerTick = 40;
private const int MaxFertilizePerTick = 50;
private static EntityQuery _storageQuery;
private static EntityQuery _farmObjectQuery;
private static EntityQuery _farmGrowthQuery;
private static Coroutine? _coroutine;
public static void Start()
{
BuildQueries();
_coroutine = Core.StartCoroutine(TickLoop());
Core.Log.LogInfo((object)"[NightBloom] Service started.");
}
public static void Stop()
{
if (_coroutine != null)
{
Core.StopCoroutine(_coroutine);
}
_coroutine = null;
}
[IteratorStateMachine(typeof(<TickLoop>d__10))]
private static IEnumerator TickLoop()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <TickLoop>d__10(0);
}
private static void BuildQueries()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: 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_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: 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_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: 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_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//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_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: 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_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
EntityManager entityManager = Core.EntityManager;
EntityQueryBuilder val = default(EntityQueryBuilder);
((EntityQueryBuilder)(ref val))..ctor(AllocatorHandle.op_Implicit((Allocator)2));
val = ((EntityQueryBuilder)(ref val)).AddAll(new ComponentType(Il2CppType.Of<PrefabGUID>(), (AccessMode)0));
val = ((EntityQueryBuilder)(ref val)).AddAll(new ComponentType(Il2CppType.Of<Translation>(), (AccessMode)0));
val = ((EntityQueryBuilder)(ref val)).AddAll(new ComponentType(Il2CppType.Of<InventoryRouteParent>(), (AccessMode)0));
val = ((EntityQueryBuilder)(ref val)).AddAll(new ComponentType(Il2CppType.Of<AttachedBuffer>(), (AccessMode)0));
EntityQueryBuilder val2 = ((EntityQueryBuilder)(ref val)).WithOptions((EntityQueryOptions)2);
_storageQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery(ref val2);
((EntityQueryBuilder)(ref val2)).Dispose();
EntityQueryBuilder val3 = default(EntityQueryBuilder);
((EntityQueryBuilder)(ref val3))..ctor(AllocatorHandle.op_Implicit((Allocator)2));
val3 = ((EntityQueryBuilder)(ref val3)).AddAll(new ComponentType(Il2CppType.Of<NetworkedSpawnChainChild>(), (AccessMode)0));
val3 = ((EntityQueryBuilder)(ref val3)).AddAll(new ComponentType(Il2CppType.Of<YieldResourcesOnDamageTaken>(), (AccessMode)0));
val3 = ((EntityQueryBuilder)(ref val3)).AddAll(new ComponentType(Il2CppType.Of<Translation>(), (AccessMode)0));
EntityQueryBuilder val4 = ((EntityQueryBuilder)(ref val3)).WithOptions((EntityQueryOptions)2);
_farmObjectQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery(ref val4);
((EntityQueryBuilder)(ref val4)).Dispose();
EntityQueryBuilder val5 = default(EntityQueryBuilder);
((EntityQueryBuilder)(ref val5))..ctor(AllocatorHandle.op_Implicit((Allocator)2));
val5 = ((EntityQueryBuilder)(ref val5)).AddAll(new ComponentType(Il2CppType.Of<AutoChainInstanceData>(), (AccessMode)0));
val5 = ((EntityQueryBuilder)(ref val5)).AddAll(new ComponentType(Il2CppType.Of<CastleHeartConnection>(), (AccessMode)0));
val5 = ((EntityQueryBuilder)(ref val5)).AddAll(new ComponentType(Il2CppType.Of<Translation>(), (AccessMode)0));
EntityQueryBuilder val6 = ((EntityQueryBuilder)(ref val5)).WithOptions((EntityQueryOptions)2);
_farmGrowthQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery(ref val6);
((EntityQueryBuilder)(ref val6)).Dispose();
}
private static void Tick()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: 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_0076: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_019a: Unknown result type (might be due to invalid IL or missing references)
//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
//IL_01e8: 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_020a: 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: Unknown result type (might be due to invalid IL or missing references)
//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_0223: 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)
//IL_0282: Unknown result type (might be due to invalid IL or missing references)
//IL_023f: 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_0296: Unknown result type (might be due to invalid IL or missing references)
//IL_0298: Unknown result type (might be due to invalid IL or missing references)
//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
NativeArray<Entity> allStorages = ((EntityQuery)(ref _storageQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
NativeArray<Entity> farmObjects = ((EntityQuery)(ref _farmObjectQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
NativeArray<Entity> farmGrowth = ((EntityQuery)(ref _farmGrowthQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
try
{
string[] controllerKeywords = NightBloomConfig.GetControllerKeywords();
string[] harvestKeywords = NightBloomConfig.GetHarvestKeywords();
List<(int, float)> fertilizerItems = NightBloomConfig.GetFertilizerItems();
float value = NightBloomConfig.ChestLinkRadius.Value;
List<Entity> list = new List<Entity>();
for (int i = 0; i < allStorages.Length; i++)
{
if (IsNamedChest(allStorages[i], controllerKeywords))
{
list.Add(allStorages[i]);
}
}
if (list.Count == 0)
{
return;
}
int num = 0;
int num2 = 0;
float num3 = 0f;
Dictionary<long, List<Entity>> dictionary = new Dictionary<long, List<Entity>>();
foreach (Entity item in list)
{
long territoryKey = GetTerritoryKey(item);
if (!dictionary.TryGetValue(territoryKey, out var value2))
{
value2 = (dictionary[territoryKey] = new List<Entity>());
}
value2.Add(item);
}
foreach (KeyValuePair<long, List<Entity>> item2 in dictionary)
{
if (item2.Value.Count > 1)
{
Core.Log.LogWarning((object)($"[NightBloom] {item2.Value.Count} Fertilizer chests in the same territory! " + "Only 1 is allowed per territory. Remove the duplicate(s) to re-enable the mod for this territory."));
continue;
}
Entity val = item2.Value[0];
if (!TryGetExternalInventory(val, out var inv) || GetTotalFertilizerCredits(inv, fertilizerItems) < 0.01f)
{
continue;
}
Translation val2 = val.Read<Translation>();
float2 xz = ((float3)(ref val2.Value)).xz;
Entity val3 = Entity.Null;
float radius = NightBloomConfig.NoWeaponRadius.Value;
int tier = 0;
if (TryFindBestTool(inv, out var bestWeapon, out var bestTier))
{
val3 = bestWeapon;
tier = bestTier;
radius = NightBloomConfig.GetRadiusForTier(tier);
}
int num4 = AccelerateGrowth(xz, radius, farmGrowth);
int num5 = 0;
if (val3 != Entity.Null)
{
List<Entity> linkedHarvestChests = GetLinkedHarvestChests(val, allStorages, harvestKeywords, value);
if (linkedHarvestChests.Count > 0)
{
int actionBudget = 40;
num5 = HarvestFarmObjects(xz, radius, linkedHarvestChests, farmObjects, ref actionBudget);
}
}
if (num4 > 0 || num5 > 0)
{
double creditsPerSecond = NightBloomConfig.GetCreditsPerSecond();
int creditsNeeded = (int)Math.Max(1.0, Math.Ceiling(creditsPerSecond * 5.0));
float num6 = ConsumeFertilizerCredits(inv, creditsNeeded, fertilizerItems);
num3 += num6;
}
if (val3 != Entity.Null && num5 > 0)
{
ConsumeDurability(val3, (float)num5 * NightBloomConfig.GetDurabilityLossForTier(tier));
}
num += num5;
num2 += num4;
}
}
finally
{
allStorages.Dispose();
farmObjects.Dispose();
farmGrowth.Dispose();
}
}
private static bool IsNamedChest(Entity chest, string[] keywords)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
string chestName = GetChestName(chest);
if (chestName.Length == 0)
{
return false;
}
string text = chestName.ToLowerInvariant();
foreach (string value in keywords)
{
if (text.Contains(value))
{
return true;
}
}
return false;
}
private static string GetChestName(Entity chest)
{
//IL_0000: 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)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
if (!chest.Has<NameableInteractable>())
{
return string.Empty;
}
NameableInteractable val = chest.Read<NameableInteractable>();
return ((object)(FixedString64Bytes)(ref val.Name)).ToString();
}
private static List<Entity> GetLinkedHarvestChests(Entity controller, NativeArray<Entity> allStorages, string[] harvestKw, float linkRadius)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//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_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: 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_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: 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_007d: Unknown result type (might be due to invalid IL or missing references)
List<Entity> list = new List<Entity>();
Translation val = controller.Read<Translation>();
float2 xz = ((float3)(ref val.Value)).xz;
bool flag = controller.Has<TeamReference>();
Entity val2 = (flag ? ModifiableEntity.op_Implicit(controller.Read<TeamReference>().Value) : Entity.Null);
for (int i = 0; i < allStorages.Length; i++)
{
Entity val3 = allStorages[i];
if (val3.Has<Translation>() && IsNamedChest(val3, harvestKw) && (!flag || !val3.Has<TeamReference>() || !(ModifiableEntity.op_Implicit(val3.Read<TeamReference>().Value) != val2)))
{
val = val3.Read<Translation>();
if (!(math.distance(xz, ((float3)(ref val.Value)).xz) > linkRadius))
{
list.Add(val3);
}
}
}
return list;
}
private static bool TryGetExternalInventory(Entity tileModel, out Entity inv)
{
//IL_0001: 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_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: 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_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_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_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: 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)
inv = Entity.Null;
EntityManager entityManager = Core.EntityManager;
DynamicBuffer<AttachedBuffer> val = default(DynamicBuffer<AttachedBuffer>);
if (!((EntityManager)(ref entityManager)).TryGetBuffer<AttachedBuffer>(tileModel, ref val))
{
return false;
}
for (int i = 0; i < val.Length; i++)
{
AttachedBuffer val2 = val[i];
int guidHash = ((PrefabGUID)(ref val2.PrefabGuid)).GuidHash;
PrefabGUID externalInventoryGuid = ExternalInventoryGuid;
if (guidHash == ((PrefabGUID)(ref externalInventoryGuid)).GuidHash && val2.Entity != Entity.Null)
{
inv = val2.Entity;
return true;
}
}
return false;
}
private static int GetItemCount(Entity inv, PrefabGUID itemGuid)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: 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_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
EntityManager entityManager = Core.EntityManager;
DynamicBuffer<InventoryBuffer> val = default(DynamicBuffer<InventoryBuffer>);
if (!((EntityManager)(ref entityManager)).TryGetBuffer<InventoryBuffer>(inv, ref val))
{
return 0;
}
int num = 0;
for (int i = 0; i < val.Length; i++)
{
if (val[i].Amount > 0)
{
InventoryBuffer val2 = val[i];
if (((PrefabGUID)(ref val2.ItemType)).GuidHash == ((PrefabGUID)(ref itemGuid)).GuidHash)
{
num += val[i].Amount;
}
}
}
return num;
}
private static void ConsumeItem(Entity inv, PrefabGUID itemGuid, int amount)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: 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)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: 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)
if (amount <= 0)
{
return;
}
EntityManager entityManager = Core.EntityManager;
DynamicBuffer<InventoryBuffer> val = default(DynamicBuffer<InventoryBuffer>);
if (!((EntityManager)(ref entityManager)).TryGetBuffer<InventoryBuffer>(inv, ref val))
{
return;
}
int num = amount;
for (int i = 0; i < val.Length; i++)
{
if (num <= 0)
{
break;
}
InventoryBuffer val2 = val[i];
if (val2.Amount <= 0 || ((PrefabGUID)(ref val2.ItemType)).GuidHash != ((PrefabGUID)(ref itemGuid)).GuidHash)
{
continue;
}
int num2 = Math.Min(val2.Amount, num);
val2.Amount -= num2;
num -= num2;
if (val2.Amount <= 0)
{
Entity entityOnServer = ((NetworkedEntity)(ref val2.ItemEntity)).GetEntityOnServer();
if (entityOnServer != Entity.Null)
{
DestroyUtility.Destroy(entityManager, entityOnServer, (DestroyDebugReason)0, string.Empty, 0);
}
val[i] = default(InventoryBuffer);
}
else
{
val[i] = val2;
}
}
}
private static float GetTotalFertilizerCredits(Entity inv, List<(int guid, float power)> fertilizers)
{
//IL_0024: 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)
float num = 0f;
foreach (var fertilizer in fertilizers)
{
int item = fertilizer.guid;
float item2 = fertilizer.power;
num += (float)GetItemCount(inv, new PrefabGUID(item)) * item2;
}
return num;
}
private static float ConsumeFertilizerCredits(Entity inv, int creditsNeeded, List<(int guid, float power)> fertilizers)
{
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
List<(int, float)> list = new List<(int, float)>(fertilizers);
list.Sort(((int guid, float power) a, (int guid, float power) b) => a.power.CompareTo(b.power));
float num = creditsNeeded;
float num2 = 0f;
foreach (var (num3, num4) in list)
{
if (num < 0.001f)
{
break;
}
int itemCount = GetItemCount(inv, new PrefabGUID(num3));
if (itemCount > 0)
{
int val = (int)Math.Ceiling(num / num4);
int num5 = Math.Min(itemCount, val);
ConsumeItem(inv, new PrefabGUID(num3), num5);
float num6 = (float)num5 * num4;
num2 += num6;
num -= num6;
}
}
return num2;
}
private static bool TryFindBestTool(Entity srcInv, out Entity bestWeapon, out int bestTier)
{
//IL_0001: 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_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: 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_0054: 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_0065: 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_0073: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: 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_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
bestWeapon = Entity.Null;
bestTier = 0;
EntityManager entityManager = Core.EntityManager;
DynamicBuffer<InventoryBuffer> val = default(DynamicBuffer<InventoryBuffer>);
if (!((EntityManager)(ref entityManager)).TryGetBuffer<InventoryBuffer>(srcInv, ref val))
{
return false;
}
float num = -1f;
for (int i = 0; i < val.Length; i++)
{
InventoryBuffer val2 = val[i];
if (val2.Amount <= 0)
{
continue;
}
Entity entityOnServer = ((NetworkedEntity)(ref val2.ItemEntity)).GetEntityOnServer();
if (!(entityOnServer == Entity.Null) && entityOnServer.Has<WeaponLevelSource>())
{
PrefabGUID val3 = entityOnServer.Read<PrefabGUID>();
int guidHash = ((PrefabGUID)(ref val3)).GuidHash;
if (!KnownPrefabs.WeaponTiers.TryGetValue(guidHash, out var value))
{
value = Mathf.Max(1, Mathf.RoundToInt(entityOnServer.Read<WeaponLevelSource>().Level));
}
float num2 = (entityOnServer.Has<Durability>() ? entityOnServer.Read<Durability>().Value : 0f);
if (!(num2 <= 0f) && (value > bestTier || (value == bestTier && num2 > num)))
{
bestTier = value;
num = num2;
bestWeapon = entityOnServer;
}
}
}
return bestWeapon != Entity.Null;
}
private static void ConsumeDurability(Entity weapon, float amount)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: 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)
//IL_0017: 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_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
if (!(amount <= 0f) && weapon.Has<Durability>())
{
Durability val = weapon.Read<Durability>();
val.Value = Math.Max(0f, val.Value - amount);
weapon.Write<Durability>(val);
}
}
private static int HarvestFarmObjects(float2 center, float radius, List<Entity> outputs, NativeArray<Entity> farmObjects, ref int actionBudget)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//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_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: 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_004e: 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_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: 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_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_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: 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_00c4: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: 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)
if (actionBudget <= 0)
{
return 0;
}
EntityManager entityManager = Core.EntityManager;
ServerGameManager serverGameManager = Core.ServerScriptMapper.GetServerGameManager();
int num = 0;
DynamicBuffer<YieldResourcesOnDamageTaken> val3 = default(DynamicBuffer<YieldResourcesOnDamageTaken>);
for (int i = 0; i < farmObjects.Length; i++)
{
if (actionBudget <= 0)
{
break;
}
if (num >= 40)
{
break;
}
Entity val = farmObjects[i];
if (val == Entity.Null || !val.Has<Translation>())
{
continue;
}
Translation val2 = val.Read<Translation>();
if (math.distance(center, ((float3)(ref val2.Value)).xz) > radius || !((EntityManager)(ref entityManager)).TryGetBuffer<YieldResourcesOnDamageTaken>(val, ref val3))
{
continue;
}
bool flag = false;
for (int j = 0; j < val3.Length; j++)
{
YieldResourcesOnDamageTaken val4 = val3[j];
int num2 = val4.Amount - val4.AmountTaken;
if (num2 > 0 && ((PrefabGUID)(ref val4.ItemType)).GuidHash != 0 && TryStoreInOutputs(serverGameManager, outputs, val4.ItemType, num2, val.Read<Translation>().Value) < num2)
{
flag = true;
}
}
if (flag)
{
DestroyUtility.Destroy(entityManager, val, (DestroyDebugReason)0, string.Empty, 0);
actionBudget--;
num++;
}
}
return num;
}
private static int TryStoreInOutputs(ServerGameManager sgm, List<Entity> outputs, PrefabGUID itemGuid, int amount, float3 origin)
{
//IL_000b: 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_0024: 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_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
int num = amount;
if (num <= 0)
{
return 0;
}
List<Entity> list = SortedByDistance(outputs, ((float3)(ref origin)).xz);
for (int i = 0; i < list.Count; i++)
{
if (num <= 0)
{
break;
}
try
{
AddItemResponse val = ((ServerGameManager)(ref sgm)).TryAddInventoryItem(list[i], itemGuid, num);
if (((AddItemResponse)(ref val)).Success)
{
num = math.max(0, val.RemainingAmount);
}
}
catch
{
}
}
return num;
}
private static int AccelerateGrowth(float2 center, float radius, NativeArray<Entity> farmGrowth)
{
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: 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_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
float num = Math.Max(1f, NightBloomConfig.GrowthSpeedMultiplier.Value);
double num2 = 5f * (num - 1f);
if (num2 <= 0.0)
{
return 0;
}
int num3 = 0;
double serverTime = Core.ServerTime;
for (int i = 0; i < farmGrowth.Length; i++)
{
if (num3 >= 50)
{
break;
}
Entity val = farmGrowth[i];
if (val == Entity.Null || !val.Has<Translation>())
{
continue;
}
Translation val2 = val.Read<Translation>();
if (math.distance(center, ((float3)(ref val2.Value)).xz) > radius)
{
continue;
}
AutoChainInstanceData val3 = val.Read<AutoChainInstanceData>();
double nextTransitionAttempt = val3.NextTransitionAttempt;
if (!(nextTransitionAttempt <= serverTime))
{
double num4 = Math.Max(serverTime + 0.1, nextTransitionAttempt - num2);
if (!(num4 >= nextTransitionAttempt))
{
val3.NextTransitionAttempt = num4;
val.Write<AutoChainInstanceData>(val3);
num3++;
}
}
}
return num3;
}
private static long GetTerritoryKey(Entity ctrl)
{
//IL_0000: 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_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: 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)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: 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_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//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_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: 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_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
if (ctrl.Has<CastleHeartConnection>())
{
CastleHeartConnection val = ctrl.Read<CastleHeartConnection>();
Entity entityOnServer = ((NetworkedEntity)(ref val.CastleHeartEntity)).GetEntityOnServer();
if (entityOnServer != Entity.Null)
{
return (long)(((ulong)(uint)entityOnServer.Index << 32) | (uint)entityOnServer.Version);
}
}
if (ctrl.Has<TeamReference>())
{
Entity val2 = ModifiableEntity.op_Implicit(ctrl.Read<TeamReference>().Value);
return (long)(((ulong)(uint)val2.Index << 32) | (uint)val2.Version);
}
return (long)(((ulong)(uint)ctrl.Index << 32) | (uint)ctrl.Version);
}
private static List<Entity> SortedByDistance(List<Entity> entities, float2 origin)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
List<Entity> list = new List<Entity>(entities);
list.Sort(delegate(Entity a, Entity b)
{
//IL_0001: 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_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: 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_0025: 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_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
float2 val = origin;
Translation val2 = a.Read<Translation>();
float num = math.distance(val, ((float3)(ref val2.Value)).xz);
float2 val3 = origin;
val2 = b.Read<Translation>();
float value = math.distance(val3, ((float3)(ref val2.Value)).xz);
return num.CompareTo(value);
});
return list;
}
public static List<string> GetStatus(Entity characterEntity)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: 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_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: 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_005f: 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)
//IL_0066: 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_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: 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_0093: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: 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_02f9: Unknown result type (might be due to invalid IL or missing references)
//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0307: Unknown result type (might be due to invalid IL or missing references)
//IL_0309: Unknown result type (might be due to invalid IL or missing references)
//IL_030e: Unknown result type (might be due to invalid IL or missing references)
//IL_0317: Unknown result type (might be due to invalid IL or missing references)
//IL_031c: Unknown result type (might be due to invalid IL or missing references)
//IL_0229: Unknown result type (might be due to invalid IL or missing references)
//IL_0239: Unknown result type (might be due to invalid IL or missing references)
//IL_023b: Unknown result type (might be due to invalid IL or missing references)
//IL_035f: Unknown result type (might be due to invalid IL or missing references)
//IL_0364: Unknown result type (might be due to invalid IL or missing references)
//IL_0366: Unknown result type (might be due to invalid IL or missing references)
//IL_036f: Unknown result type (might be due to invalid IL or missing references)
//IL_0371: Unknown result type (might be due to invalid IL or missing references)
//IL_0373: 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_0381: Unknown result type (might be due to invalid IL or missing references)
//IL_0401: Unknown result type (might be due to invalid IL or missing references)
//IL_0406: Unknown result type (might be due to invalid IL or missing references)
//IL_040b: Unknown result type (might be due to invalid IL or missing references)
//IL_0413: Unknown result type (might be due to invalid IL or missing references)
//IL_0418: Unknown result type (might be due to invalid IL or missing references)
//IL_041d: Unknown result type (might be due to invalid IL or missing references)
//IL_042e: Unknown result type (might be due to invalid IL or missing references)
//IL_0433: Unknown result type (might be due to invalid IL or missing references)
//IL_0435: Unknown result type (might be due to invalid IL or missing references)
//IL_0437: Unknown result type (might be due to invalid IL or missing references)
//IL_0443: Unknown result type (might be due to invalid IL or missing references)
//IL_044c: Unknown result type (might be due to invalid IL or missing references)
//IL_044e: Unknown result type (might be due to invalid IL or missing references)
//IL_0450: Unknown result type (might be due to invalid IL or missing references)
//IL_0455: Unknown result type (might be due to invalid IL or missing references)
//IL_045e: Unknown result type (might be due to invalid IL or missing references)
//IL_048c: Unknown result type (might be due to invalid IL or missing references)
//IL_0491: Unknown result type (might be due to invalid IL or missing references)
//IL_0493: Unknown result type (might be due to invalid IL or missing references)
//IL_0495: Unknown result type (might be due to invalid IL or missing references)
//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
//IL_04ac: Unknown result type (might be due to invalid IL or missing references)
//IL_04ae: Unknown result type (might be due to invalid IL or missing references)
//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
List<string> list = new List<string>();
if (!characterEntity.Has<Translation>())
{
list.Add("[NightBloom] Cannot determine your position.");
return list;
}
Translation val = characterEntity.Read<Translation>();
float2 xz = ((float3)(ref val.Value)).xz;
string[] controllerKeywords = NightBloomConfig.GetControllerKeywords();
string[] harvestKeywords = NightBloomConfig.GetHarvestKeywords();
List<(int, float)> fertilizerItems = NightBloomConfig.GetFertilizerItems();
float value = NightBloomConfig.ChestLinkRadius.Value;
NativeArray<Entity> allStorages = ((EntityQuery)(ref _storageQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
try
{
Entity val2 = Entity.Null;
float num = float.MaxValue;
for (int i = 0; i < allStorages.Length; i++)
{
Entity val3 = allStorages[i];
if (IsNamedChest(val3, controllerKeywords) && val3.Has<Translation>())
{
val = val3.Read<Translation>();
float num2 = math.distance(xz, ((float3)(ref val.Value)).xz);
if (num2 < num)
{
num = num2;
val2 = val3;
}
}
}
if (val2 == Entity.Null)
{
list.Add("[NightBloom] No Fertilizer chest found. Name a chest with keywords: " + string.Join(", ", controllerKeywords));
return list;
}
string chestName = GetChestName(val2);
list.Add($"[NightBloom] Fertilizer chest: '{chestName}' ({num:F0} m away)");
if (!TryGetExternalInventory(val2, out var inv))
{
list.Add(" → Inventory inaccessible.");
return list;
}
float totalFertilizerCredits = GetTotalFertilizerCredits(inv, fertilizerItems);
list.Add($" Credits: {totalFertilizerCredits:F1} | Rate: {NightBloomConfig.GetCreditsPerSecond():F2}/s");
string value4;
float num3;
if (TryFindBestTool(inv, out var bestWeapon, out var bestTier))
{
string value2 = ((bestTier >= 1 && bestTier <= 11) ? KnownPrefabs.TierNames[bestTier] : $"T{bestTier}");
float value3 = (bestWeapon.Has<Durability>() ? bestWeapon.Read<Durability>().Value : 0f);
value4 = $"{value2} (durability: {value3:F0})";
num3 = NightBloomConfig.GetRadiusForTier(bestTier);
}
else
{
value4 = "none";
num3 = NightBloomConfig.NoWeaponRadius.Value;
}
list.Add($" Tool: {value4} → radius: {num3:F0} m");
List<Entity> linkedHarvestChests = GetLinkedHarvestChests(val2, allStorages, harvestKeywords, value);
val = val2.Read<Translation>();
float2 xz2 = ((float3)(ref val.Value)).xz;
list.Add($" Harvest chests: {linkedHarvestChests.Count}");
foreach (Entity item in linkedHarvestChests)
{
string chestName2 = GetChestName(item);
val = item.Read<Translation>();
float value5 = math.distance(xz2, ((float3)(ref val.Value)).xz);
list.Add($" • '{chestName2}' ({value5:F0} m)");
}
NativeArray<Entity> val4 = ((EntityQuery)(ref _farmObjectQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
NativeArray<Entity> val5 = ((EntityQuery)(ref _farmGrowthQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
int num4 = 0;
int num5 = 0;
for (int j = 0; j < val4.Length; j++)
{
Entity val6 = val4[j];
if (!(val6 == Entity.Null) && val6.Has<Translation>())
{
val = val6.Read<Translation>();
if (math.distance(xz2, ((float3)(ref val.Value)).xz) <= num3)
{
num4++;
}
}
}
for (int k = 0; k < val5.Length; k++)
{
Entity val7 = val5[k];
if (!(val7 == Entity.Null) && val7.Has<Translation>())
{
val = val7.Read<Translation>();
if (math.distance(xz2, ((float3)(ref val.Value)).xz) <= num3)
{
num5++;
}
}
}
val4.Dispose();
val5.Dispose();
list.Add($" Plants in range: {num4} ready, {num5} growing");
list.Add($" Growth speed: {NightBloomConfig.GrowthSpeedMultiplier.Value:F1}x");
return list;
}
finally
{
allStorages.Dispose();
}
}
}
}
namespace NightBloom.Patches
{
[HarmonyPatch(typeof(SpawnTeamSystem_OnPersistenceLoad), "OnUpdate")]
internal static class InitializationPatch
{
[HarmonyPostfix]
public static void OneShot_AfterLoad_InitializationPatch()
{
Core.InitializeAfterLoaded();
MethodBase methodBase = AccessTools.Method(typeof(SpawnTeamSystem_OnPersistenceLoad), "OnUpdate", (Type[])null, (Type[])null);
MethodInfo methodInfo = AccessTools.Method(typeof(InitializationPatch), "OneShot_AfterLoad_InitializationPatch", (Type[])null, (Type[])null);
if (methodBase != null && methodInfo != null)
{
Plugin.Harmony.Unpatch(methodBase, methodInfo);
}
}
}
}
namespace NightBloom.Commands
{
[CommandGroup("nightbloom", "nb")]
internal class NightBloomCommands
{
[Command("info", null, null, "Show status of the nearest Fertilizer chest to your position.", null, false)]
public void Info(ChatCommandContext ctx)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
foreach (string item in NightBloomService.GetStatus(ctx.Event.SenderCharacterEntity))
{
ctx.Reply(item);
}
}
[Command("reload", null, null, "Reload NightBloom configuration from disk.", null, true)]
public void Reload(ChatCommandContext ctx)
{
Plugin.Cfg.Reload();
ctx.Reply("[NightBloom] Configuration reloaded from disk.");
}
}
}