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 KALI Grid Planting v0.1.2
BepInEx/plugins/KALI_Grid_Planting/FinallyGridPlanting.dll
Decompiled 19 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using ServersideQoL; using ServersideQoL.Processors; using ServersideQoL.Utilities; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("FinallyGridPlanting")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.1.2.0")] [assembly: AssemblyInformationalVersion("0.1.2")] [assembly: AssemblyProduct("FinallyGridPlanting")] [assembly: AssemblyTitle("FinallyGridPlanting")] [assembly: AssemblyVersion("0.1.2.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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] [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] [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 FinallyGridPlanting { [BepInPlugin("local.finally.gridplanting", "Finally Grid Planting", "0.1.2")] [BepInDependency("ArgusMagnus.ServersideQoL", "2.5.1")] public sealed class GridPlugin : ServersideQoLPluginBase<GridPlugin, GridConfig> { [HarmonyPatch(typeof(ZDOMan), "RPC_ZDOData")] private static class PlacementObserver { private static void Prefix(ZRpc rpc, ZPackage pkg, out List<ZDOID>? __state) { //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Expected O, but got Unknown //IL_006d: 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_0084: Expected O, but got Unknown //IL_0085: 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_00ab: 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_00d9: Unknown result type (might be due to invalid IL or missing references) __state = null; if (!GridPayments.Ready || !((ConfigBase)ConfigBase<GridConfig>.Instance).Enabled.Value || !ZNet.instance.IsServer() || !ZNet.instance.GetPeers().Any((ZNetPeer p) => p.m_rpc == rpc && p.IsReady())) { return; } try { ZPackage val = new ZPackage(pkg.GetArray()); int num = val.ReadInt(); for (int num2 = 0; num2 < num; num2++) { val.ReadZDOID(); } ZPackage val2 = new ZPackage(); while (true) { ZDOID val3 = val.ReadZDOID(); if (!((ZDOID)(ref val3)).IsNone()) { val.ReadUShort(); val.ReadUInt(); val.ReadLong(); val.ReadVector3(); val.ReadPackage(ref val2); if (ZDOMan.instance.GetZDO(val3) == null) { (__state ?? (__state = new List<ZDOID>())).Add(val3); } continue; } break; } } catch { __state = null; } } private static void Postfix(ZRpc rpc, List<ZDOID>? __state) { //IL_003c: 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_0047: Unknown result type (might be due to invalid IL or missing references) if (__state == null) { return; } ZNetPeer val = ((IEnumerable<ZNetPeer>)ZNet.instance.GetPeers()).FirstOrDefault((Func<ZNetPeer, bool>)((ZNetPeer p) => p.m_rpc == rpc)); if (val == null) { return; } foreach (ZDOID item in __state) { ZDO zDO = ZDOMan.instance.GetZDO(item); if (zDO != null && ((ZDOID)(ref zDO.m_uid)).UserID == val.m_uid && zDO.GetOwner() == val.m_uid) { Processor.Instance<GridPayments>().Observe(zDO, val.m_uid); } } } } private float nextTick; protected override GridConfig CreateConfigSingleton(ConfigFile cfg, Logger logger) { return new GridConfig(cfg, logger); } protected override void RegisterProcessors(IProcessorCollection processors) { processors.Add<GridPayments>(); } private void Awake() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) new Harmony("local.finally.gridplanting").PatchAll(typeof(GridPlugin).Assembly); } private void Update() { if (!GridPayments.Ready || Time.realtimeSinceStartup < nextTick || (Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer()) { return; } nextTick = Time.realtimeSinceStartup + 0.1f; try { Processor.Instance<GridPayments>().Tick(); } catch (Exception ex) { ServersideQoLPluginBaseCore<GridPlugin, GridConfig>.Logger.LogError((object)("Grid planting transaction retained for retry: " + ex)); } } } public sealed class GridConfig : ConfigBase<GridConfig> { public override ConfigEntry<bool> Enabled { get; } public GridConfig(ConfigFile cfg, Logger logger) : base(cfg, logger) { Enabled = cfg.Bind<bool>("GridPlanting", "Enabled", true, "Fill valid spots around newly planted ground crops, up to a 3x3 grid. Consume one seed per extra plant. Trees, vines and grass are unchanged."); } } [Processor("c184c3d7-e780-4446-9403-678f40d01ed0")] [DependsOn<ContainerRegistryProcessor>] [DependsOn<PlayerRegistryProcessor>] public sealed class GridPayments : Processor<ProcessorPrefabInfo<Container>> { private sealed class Flight { public long Owner; public float Sent; public bool Started; public bool FenceSent; } private static readonly HashSet<string> Crops = new HashSet<string>(StringComparer.Ordinal) { "sapling_barley", "sapling_carrot", "sapling_flax", "sapling_jotunpuffs", "sapling_Kale", "sapling_magecap", "sapling_oat", "sapling_onion", "sapling_poteitr", "sapling_seedcarrot", "sapling_seedkale", "sapling_seedonion", "sapling_seedturnip", "sapling_turnip" }; private static readonly ServerVar<int> Phase = ServersideQoLPluginBaseCore<GridPlugin, GridConfig>.RegisterServerVar<int>("Phase"); private static readonly ServerVar<long> Player = ServersideQoLPluginBaseCore<GridPlugin, GridConfig>.RegisterServerVar<long>("Player"); private static readonly ServerVar<int> Seed = ServersideQoLPluginBaseCore<GridPlugin, GridConfig>.RegisterServerVar<int>("Seed"); private static readonly ServerVar<int> Prefill = ServersideQoLPluginBaseCore<GridPlugin, GridConfig>.RegisterServerVar<int>("Prefill"); private static readonly ServerVar<int> Crop = ServersideQoLPluginBaseCore<GridPlugin, GridConfig>.RegisterServerVar<int>("Crop"); private static readonly ServerVar<ZDOID> Original = ServersideQoLPluginBaseCore<GridPlugin, GridConfig>.RegisterServerVar<ZDOID>("Original"); private static readonly ServerVar<Vector3[]> Targets = ServersideQoLPluginBaseCore<GridPlugin, GridConfig>.RegisterServerVar<Vector3[]>("Targets"); private static readonly ServerVar<Quaternion> Rotation = ServersideQoLPluginBaseCore<GridPlugin, GridConfig>.RegisterServerVar<Quaternion>("Rotation"); private static readonly ServerVar<long> PlantTime = ServersideQoLPluginBaseCore<GridPlugin, GridConfig>.RegisterServerVar<long>("PlantTime"); private static readonly ServerVar<int> Completed = ServersideQoLPluginBaseCore<GridPlugin, GridConfig>.RegisterServerVar<int>("Completed"); private readonly Queue<(ZDOID Id, long Peer, Quaternion? Heading)> pending = new Queue<(ZDOID, long, Quaternion?)>(); private readonly Dictionary<ServersideQoLZDO, Flight> flights = new Dictionary<ServersideQoLZDO, Flight>(); public static bool Ready { get; private set; } public IReadOnlyCollection<ServersideQoLZDO> Transactions => ((Processor)this).PlacedObjects; public static bool IsCrop(string prefab) { return Crops.Contains(prefab); } protected override void Initialize() { Ready = true; ((Processor)this).Logger.LogInfo((object)"Grid planting ready: 14 ground-crop/seed variants only. Trees, vines, grass and existing plants are unchanged."); } protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList<Peer> peers, ProcessorPrefabInfo<Container> info) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) if (!((Processor)this).PlacedObjects.Contains(zdo)) { return (ProcessResult)2; } return ((Processor)this).ScheduleReprocessing(0.2f); } public void Observe(ZDO plant, long owner) { //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: 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 (!((ConfigBase)ConfigBase<GridConfig>.Instance).Enabled.Value) { return; } GameObject prefab = ZNetScene.instance.GetPrefab(plant.GetPrefab()); if (IsCrop(((prefab != null) ? ((Object)prefab).name : null) ?? "")) { long num = ZNet.instance.GetTime().Ticks - plant.GetLong(ZDOVars.s_plantTime, 0L); if (num >= -50000000 && num <= 150000000 && plant.GetLong(ZDOVars.s_creator, 0L) != 0L) { PlayerState stateForPeerID = Processor.Instance<PlayerRegistryProcessor>().GetStateForPeerID(owner); Quaternion? item = ((stateForPeerID == null) ? ((Quaternion?)null) : new Quaternion?(PlacementRotation(stateForPeerID.ZDO.ZDO.GetPosition(), stateForPeerID.ZDO.ZDO.GetRotation(), plant.GetPosition()))); pending.Enqueue((plant.m_uid, owner, item)); } } } public static Quaternion PlacementRotation(Vector3 playerPosition, Quaternion playerRotation, Vector3 placement) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: 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_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_0044: 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_0038: Unknown result type (might be due to invalid IL or missing references) Vector3 val = placement - playerPosition; val.y = 0f; if (!(((Vector3)(ref val)).sqrMagnitude > 0.0001f)) { return Quaternion.Euler(0f, ((Quaternion)(ref playerRotation)).eulerAngles.y, 0f); } return Quaternion.LookRotation(val, Vector3.up); } public void Tick() { //IL_002b: 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_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) int count = pending.Count; for (int i = 0; i < count; i++) { (ZDOID, long, Quaternion?) item = pending.Dequeue(); ZDO zDO = ZDOMan.instance.GetZDO(item.Item1); PlayerState state = Processor.Instance<PlayerRegistryProcessor>().GetStateForPeerID(item.Item2); if (zDO == null) { continue; } if (state == null) { if (ZNet.instance.GetTime().Ticks - zDO.GetLong(ZDOVars.s_plantTime, 0L) < 150000000) { pending.Enqueue(item); } continue; } long num = zDO.GetLong(ZDOVars.s_creator, 0L); PlayerID playerID = state.PlayerID; if (num != ((PlayerID)(ref playerID)).Value) { continue; } if (((Processor)this).PlacedObjects.Any(delegate(ServersideQoLZDO z) { //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) long num3 = Player.Get(z, 0L); PlayerID playerID2 = state.PlayerID; return num3 == ((PlayerID)(ref playerID2)).Value && Phase.Get(z, 0) == 1; })) { pending.Enqueue(item); continue; } Quaternion value = (Quaternion)(((??)item.Item3) ?? PlacementRotation(state.ZDO.ZDO.GetPosition(), state.ZDO.ZDO.GetRotation(), zDO.GetPosition())); if (TryPlan(zDO, out Vector3[] positions, out ItemDrop seed, value)) { StartCollection(zDO, state, positions, seed, value); } } ServersideQoLZDO[] array = ((Processor)this).PlacedObjects.ToArray(); foreach (ServersideQoLZDO helper in array) { Advance(helper); } } public bool TryPlan(ZDO original, out Vector3[] positions, out ItemDrop seed, Quaternion? heading = null) { //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_012c: 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_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0173: 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_017c: 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_0377: Unknown result type (might be due to invalid IL or missing references) //IL_028a: Unknown result type (might be due to invalid IL or missing references) //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_0297: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_029c: Unknown result type (might be due to invalid IL or missing references) //IL_02a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_02b6: Unknown result type (might be due to invalid IL or missing references) //IL_02c7: Unknown result type (might be due to invalid IL or missing references) //IL_02cb: Invalid comparison between Unknown and I4 //IL_02e7: Unknown result type (might be due to invalid IL or missing references) //IL_02f2: Unknown result type (might be due to invalid IL or missing references) //IL_02d5: Unknown result type (might be due to invalid IL or missing references) //IL_02d8: Invalid comparison between Unknown and I4 //IL_02da: Unknown result type (might be due to invalid IL or missing references) //IL_02de: Invalid comparison between Unknown and I4 //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Expected O, but got Unknown //IL_0324: Unknown result type (might be due to invalid IL or missing references) positions = Array.Empty<Vector3>(); seed = null; GameObject prefab = ZNetScene.instance.GetPrefab(original.GetPrefab()); if ((Object)(object)prefab == (Object)null || !IsCrop(((Object)prefab).name)) { return false; } Plant component = prefab.GetComponent<Plant>(); Piece component2 = prefab.GetComponent<Piece>(); if ((Object)(object)component == (Object)null || component.m_attachDistance > 0f || component2.m_resources.Length != 1 || component2.m_resources[0].m_amount != 1) { return false; } seed = component2.m_resources[0].m_resItem; if ((Object)(object)seed == (Object)null || seed.m_itemData.m_shared.m_maxStackSize <= 8) { return false; } Vector3 position = original.GetPosition(); float num = Mathf.Max(1.2f, component.m_growRadius * 2f + 0.2f); List<ZDO> list = new List<ZDO>(); ZDOMan.instance.FindSectorObjects(ZoneSystem.GetZone(position), new SimulationDistance(1, 0, false), list, (List<ZDO>)null); HashSet<Heightmap> hashSet = new HashSet<Heightmap>(); List<Vector3> list2 = new List<Vector3>(); Quaternion? val = heading; Quaternion val2; if (!val.HasValue) { Quaternion rotation = original.GetRotation(); val2 = Quaternion.Euler(0f, ((Quaternion)(ref rotation)).eulerAngles.y, 0f); } else { val2 = val.GetValueOrDefault(); } Quaternion val3 = val2; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (i == 0 && j == 0) { continue; } Vector3 val4 = position + val3 * new Vector3((float)i * num, 0f, (float)j * num); Heightmap hm = Processor.GetHeightmap(val4); if (hashSet.Add(hm)) { TerrainComp val5 = TerrainComp.FindTerrainCompiler(((Component)hm).transform.position); if ((Object)(object)val5 == (Object)null) { ZDO val6 = ((IEnumerable<ZDO>)list).FirstOrDefault((Func<ZDO, bool>)delegate(ZDO z) { //IL_0001: 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_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) Vector3 val8 = z.GetPosition() - ((Component)hm).transform.position; if (((Vector3)(ref val8)).sqrMagnitude < 1f) { GameObject prefab3 = ZNetScene.instance.GetPrefab(z.GetPrefab()); return (Object)(object)((prefab3 != null) ? prefab3.GetComponent<TerrainComp>() : null) != (Object)null; } return false; }); if (val6 != null) { ZNetView obj = ZNetScene.instance.FindInstance(val6); GameObject val7 = ((obj != null) ? ((Component)obj).gameObject : null); if ((Object)(object)val7 == (Object)null) { val7 = (GameObject)AccessTools.Method(typeof(ZNetScene), "CreateObject", (Type[])null, (Type[])null).Invoke(ZNetScene.instance, new object[1] { val6 }); } val5 = ((val7 != null) ? val7.GetComponent<TerrainComp>() : null); } } if ((Object)(object)val5 != (Object)null) { AccessTools.Method(typeof(TerrainComp), "CheckLoad", (Type[])null, (Type[])null).Invoke(val5, null); } if (hm.HaveQueuedRebuild()) { hm.Regenerate(); } } Biome biome = hm.GetBiome(val4, 0.02f, false); if ((biome & component.m_biome) != 0 && (!component.m_needCultivatedGround || hm.IsCultivated(val4)) && (component.m_tolerateHeat || (int)biome != 32) && (component.m_tolerateCold || ((int)biome != 4 && (int)biome != 64))) { float height = Extensions.GetHeight(hm, val4); if (!(Mathf.Abs(height - position.y) > 1.5f) && !(height < ZoneSystem.instance.m_waterLevel)) { val4.y = height + 0.05f; list2.Add(val4); } } } } foreach (ZDO other in list) { if (other.m_uid == original.m_uid) { continue; } GameObject prefab2 = ZNetScene.instance.GetPrefab(other.GetPrefab()); if ((Object)(object)prefab2 == (Object)null) { continue; } Plant component3 = prefab2.GetComponent<Plant>(); Pickable component4 = prefab2.GetComponent<Pickable>(); if (!((Object)(object)component3 == (Object)null) || !((Object)(object)component4 == (Object)null)) { float radius = Mathf.Max(component.m_growRadius, component3?.m_growRadius ?? 0.5f) + 0.15f; list2.RemoveAll((Vector3 pos) => Vector3.Distance(pos, other.GetPosition()) < radius); } } positions = list2.ToArray(); return positions.Length != 0; } public ServersideQoLZDO StartCollection(ZDO original, PlayerState player, Vector3[] positions, ItemDrop seed, Quaternion? heading = null) { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0060: 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_0098: 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_00c2: Unknown result type (might be due to invalid IL or missing references) if (positions.Length < 1 || positions.Length > 8) { throw new ArgumentException("One to eight extra positions required"); } Container component = ZNetScene.instance.GetPrefab(Prefabs.PrivateChest).GetComponent<Container>(); int num = seed.m_itemData.m_shared.m_maxStackSize * component.m_width * component.m_height - positions.Length; Vector3 position = original.GetPosition(); GameObject gameObject = ((Component)seed).gameObject; PlayerID playerID = player.PlayerID; ServersideQoLZDO val = Helper(position, gameObject, num, ((PlayerID)(ref playerID)).Value, 1); Prefill.Set(val, num); Crop.Set(val, original.GetPrefab()); Original.Set(val, original.m_uid); Targets.Set(val, positions); Rotation.Set(val, (Quaternion)(((??)heading) ?? original.GetRotation())); PlantTime.Set(val, original.GetLong(ZDOVars.s_plantTime, 0L)); return val; } private ServersideQoLZDO Helper(Vector3 position, GameObject seed, int amount, long player, int phase) { //IL_0001: 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_0012: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) ServersideQoLZDO val = ((Processor)this).PlacePiece(new Vector3(position.x, -1000f, position.z), Prefabs.PrivateChest, 0f, (CreatorMarkers)2); val.ZDO.Set(ZDOVars.s_addedDefaultItems, true); Phase.Set(val, phase); Player.Set(val, player); Seed.Set(val, StringExtensionMethods.GetStableHashCode(((Object)seed).name)); IInventory inventory = Processor.Instance<ContainerRegistryProcessor>().GetState(val).GetInventory(); int maxStackSize = seed.GetComponent<ItemDrop>().m_itemData.m_shared.m_maxStackSize; int num = inventory.Inventory.GetWidth() * inventory.Inventory.GetHeight(); int num2 = ((phase == 1) ? (maxStackSize * num - amount) : 0); if (phase == 1 && (num2 < 1 || num2 > 8)) { throw new ArgumentException("Invalid seed collection capacity"); } int num3 = 0; while (amount > 0 && num3 < num) { ItemData val2 = seed.GetComponent<ItemDrop>().m_itemData.Clone(); val2.m_dropPrefab = seed; val2.m_stack = ((phase == 1 && num3 == 0) ? (maxStackSize - num2) : Math.Min(maxStackSize, amount)); val2.m_gridPos = new Vector2i(num3 % inventory.Inventory.GetWidth(), num3 / inventory.Inventory.GetWidth()); inventory.Items.Add(val2); amount -= val2.m_stack; num3++; } if (amount != 0) { throw new InvalidOperationException("Seed payment exceeds collector capacity"); } inventory.Save(); return val; } public void Advance(ServersideQoLZDO helper) { //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Expected O, but got Unknown //IL_02b8: Unknown result type (might be due to invalid IL or missing references) //IL_02d0: Unknown result type (might be due to invalid IL or missing references) //IL_02d5: 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_02e1: Unknown result type (might be due to invalid IL or missing references) //IL_02e3: Unknown result type (might be due to invalid IL or missing references) //IL_02e8: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_01fe: Unknown result type (might be due to invalid IL or missing references) //IL_0201: Unknown result type (might be due to invalid IL or missing references) //IL_0206: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Unknown result type (might be due to invalid IL or missing references) //IL_0248: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_0254: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_025b: Unknown result type (might be due to invalid IL or missing references) if (!((Processor)this).PlacedObjects.Contains(helper)) { return; } PlayerState state = ((IEnumerable<PlayerState>)Processor.Instance<PlayerRegistryProcessor>().PlayerStates).FirstOrDefault((Func<PlayerState, bool>)delegate(PlayerState p) { //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) PlayerID playerID = p.PlayerID; return ((PlayerID)(ref playerID)).Value == Player.Get(helper, 0L); }); ZNetPeer val = ((state == null) ? null : ((IEnumerable<ZNetPeer>)ZNet.instance.GetPeers()).FirstOrDefault((Func<ZNetPeer, bool>)((ZNetPeer p) => p.m_uid == state.Owner && p.IsReady()))); if (state == null || val == null) { return; } if (!flights.TryGetValue(helper, out Flight value)) { value = (flights[helper] = new Flight()); } ZDOVars vars; PlayerID val2; if (value.Started && value.FenceSent && helper.ZDO.GetOwner() == ZDOMan.GetSessionID()) { Settle(helper, state); } else if (!value.Started || value.Owner != state.Owner) { helper.ZDO.SetPosition(new Vector3(state.ZDO.ZDO.GetPosition().x, -1000f, state.ZDO.ZDO.GetPosition().z)); helper.ZDO.SetOwner(state.Owner); Processor.ForceSend(new Peer(val), helper); value.Owner = state.Owner; value.Sent = Time.realtimeSinceStartup; value.Started = true; value.FenceSent = false; } else if (!value.FenceSent && Time.realtimeSinceStartup - value.Sent >= 0.3f) { ZDORpc rPC; ContainerRpc container; if (Phase.Get(helper, 0) == 1) { rPC = helper.RPC; container = ((ZDORpc)(ref rPC)).Container; ((ContainerRpc)(ref container)).StackResponse(true); } else { rPC = helper.RPC; container = ((ZDORpc)(ref rPC)).Container; ((ContainerRpc)(ref container)).TakeAllResponse(true); } ZRoutedRpc instance = ZRoutedRpc.instance; long owner = state.Owner; ZDOID uid = helper.ZDO.m_uid; object[] array = new object[1]; vars = helper.Vars; val2 = default(PlayerID); val2 = ((ZDOVars)(ref vars)).GetCreator(val2); array[0] = ((PlayerID)(ref val2)).Value; instance.InvokeRoutedRPC(owner, uid, "RPC_RequestOpen", array); value.FenceSent = true; value.Sent = Time.realtimeSinceStartup; } else if (value.FenceSent && Time.realtimeSinceStartup - value.Sent > 5f) { ZRoutedRpc instance2 = ZRoutedRpc.instance; long owner2 = state.Owner; ZDOID uid2 = helper.ZDO.m_uid; object[] array2 = new object[1]; vars = helper.Vars; val2 = default(PlayerID); val2 = ((ZDOVars)(ref vars)).GetCreator(val2); array2[0] = ((PlayerID)(ref val2)).Value; instance2.InvokeRoutedRPC(owner2, uid2, "RPC_RequestOpen", array2); value.Sent = Time.realtimeSinceStartup; } } public void Settle(ServersideQoLZDO helper, PlayerState player) { //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_034e: Unknown result type (might be due to invalid IL or missing references) if (!((Processor)this).PlacedObjects.Contains(helper) || helper.ZDO.GetOwner() != ZDOMan.GetSessionID()) { return; } int num = Processor.Instance<ContainerRegistryProcessor>().GetState(helper).GetInventory() .Items.Where((ItemData i) => StringExtensionMethods.GetStableHashCode(((Object)i.m_dropPrefab).name) == Seed.Get(helper, 0)).Sum((ItemData i) => i.m_stack); if (Phase.Get(helper, 0) == 2) { if (num == 0) { Finish(helper); } else { flights.Remove(helper); } return; } int num2 = Math.Max(0, num - Prefill.Get(helper, 0)); ZDO zDO = ZDOMan.instance.GetZDO(Original.Get(helper, default(ZDOID))); Vector3[] validTargets = Array.Empty<Vector3>(); if (zDO != null) { TryPlan(zDO, out validTargets, out ItemDrop _, Rotation.Get(helper, default(Quaternion))); } int num3 = Completed.Get(helper, 0); Vector3[] source = Targets.Get(helper, (Vector3[])null) ?? throw new InvalidOperationException("Missing saved grid targets"); Vector3[] array = source.Take(num3).Concat(from pos in source.Skip(num3) where validTargets.Any(delegate(Vector3 valid) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: 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) Vector3 val = valid - pos; return ((Vector3)(ref val)).sqrMagnitude < 0.0001f; }) select pos).ToArray(); Targets.Set(helper, array); for (int num4 = num3; num4 < Math.Min(num2, array.Length); num4++) { ServersideQoLZDO obj = Processor.Spawn(Crop.Get(helper, 0), array[num4], Rotation.Get(helper, default(Quaternion)), 0L); obj.ZDO.Set(ZDOVars.s_creator, Player.Get(helper, 0L)); obj.ZDO.Set(ZDOVars.s_plantTime, PlantTime.Get(helper, 0L)); obj.ZDO.Set("FinallyGridOriginal", Original.Get(helper, default(ZDOID))); num3 = num4 + 1; Completed.Set(helper, num3); } if (num3 > 0) { ((Processor)this).Logger.LogInfo((object)("Planted " + num3 + " extra crops for " + player.PlayerName + "; consumed " + num3 + " extra " + ((Object)ObjectDB.instance.GetItemPrefab(Seed.Get(helper, 0))).name)); RPC.ShowMessage(player.Owner, (MessageType)1, "Planted " + num3 + " extra."); } int num5 = Math.Max(0, num2 - num3); if (num5 > 0) { Helper(player.ZDO.ZDO.GetPosition(), ObjectDB.instance.GetItemPrefab(Seed.Get(helper, 0)), num5, Player.Get(helper, 0L), 2); RPC.ShowMessage(player.Owner, (MessageType)1, "Returning " + num5 + " unused seeds."); } Finish(helper); } private void Finish(ServersideQoLZDO helper) { flights.Remove(helper); ((Processor)this).TryDestroyObject(helper); } } }