using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using On;
using SeedTotem.Utils;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SeedTotem")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SeedTotem")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.1.3")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.3.0")]
[module: UnverifiableCode]
public static class PoissonDiscSampling
{
public static List<Vector2> GeneratePoints(float radius, Vector2 sampleRegionSize, int numSamplesBeforeRejection = 30)
{
//IL_000e: 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_003b: 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_0063: 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_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_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_00bd: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
float num = radius / Mathf.Sqrt(2f);
int[,] array = new int[Mathf.CeilToInt(sampleRegionSize.x / num), Mathf.CeilToInt(sampleRegionSize.y / num)];
List<Vector2> list = new List<Vector2>();
List<Vector2> list2 = new List<Vector2>();
list2.Add(sampleRegionSize / 2f);
Vector2 val2 = default(Vector2);
while (list2.Count > 0)
{
int index = Random.Range(0, list2.Count);
Vector2 val = list2[index];
bool flag = false;
for (int i = 0; i < numSamplesBeforeRejection; i++)
{
float num2 = Random.value * (float)Math.PI * 2f;
((Vector2)(ref val2))..ctor(Mathf.Sin(num2), Mathf.Cos(num2));
Vector2 val3 = val + val2 * Random.Range(radius, 2f * radius);
if (IsValid(val3, sampleRegionSize, num, radius, list, array))
{
list.Add(val3);
list2.Add(val3);
array[(int)(val3.x / num), (int)(val3.y / num)] = list.Count;
flag = true;
break;
}
}
if (!flag)
{
list2.RemoveAt(index);
}
}
return list;
}
private static bool IsValid(Vector2 candidate, Vector2 sampleRegionSize, float cellSize, float radius, List<Vector2> points, int[,] grid)
{
//IL_0001: 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_0014: 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_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: 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_002f: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
if (candidate.x >= 0f && candidate.x < sampleRegionSize.x && candidate.y >= 0f && candidate.y < sampleRegionSize.y)
{
int num = (int)(candidate.x / cellSize);
int num2 = (int)(candidate.y / cellSize);
int num3 = Mathf.Max(0, num - 2);
int num4 = Mathf.Min(num + 2, grid.GetLength(0) - 1);
int num5 = Mathf.Max(0, num2 - 2);
int num6 = Mathf.Min(num2 + 2, grid.GetLength(1) - 1);
for (int i = num3; i <= num4; i++)
{
for (int j = num5; j <= num6; j++)
{
int num7 = grid[i, j] - 1;
if (num7 != -1)
{
Vector2 val = candidate - points[num7];
float sqrMagnitude = ((Vector2)(ref val)).sqrMagnitude;
if (sqrMagnitude < radius * radius)
{
return false;
}
}
}
}
return true;
}
return false;
}
}
namespace SeedTotem
{
public class SeedQueue : IEquatable<SeedQueue>
{
public class Entry : IEquatable<Entry>
{
public string Name { get; internal set; }
public int Amount { get; internal set; }
public Entry(string name, int amount)
{
Name = name;
Amount = amount;
}
public bool Equals(Entry other)
{
return other != null && Name == other.Name && Amount == other.Amount;
}
public override int GetHashCode()
{
int num = 221287967;
num = num * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Name);
return num * -1521134295 + Amount.GetHashCode();
}
public override bool Equals(object obj)
{
return Equals(obj as Entry);
}
public override string ToString()
{
return $"Name: {Name}, Amount: {Amount}";
}
public static bool operator ==(Entry left, Entry right)
{
return left?.Equals(right) ?? ((object)right == null);
}
public static bool operator !=(Entry left, Entry right)
{
return !(left == right);
}
}
private readonly Queue<Entry> queue = new Queue<Entry>();
public int Count => queue.Sum((Entry entry) => entry.Amount);
public SeedQueue()
{
}
public SeedQueue(ZPackage package)
{
int num = package.ReadInt();
for (int i = 0; i < num; i++)
{
queue.Enqueue(new Entry(package.ReadString(), package.ReadInt()));
}
}
public void AddSeed(string name, int amount)
{
if (queue.Any())
{
Entry entry = queue.Last();
if (entry.Name == name)
{
entry.Amount += amount;
return;
}
}
queue.Enqueue(new Entry(name, amount));
}
public bool Equals(SeedQueue other)
{
if (queue.Count != other.queue.Count)
{
return false;
}
for (int i = 0; i < queue.Count; i++)
{
if (!queue.ElementAt(i).Equals(other.queue.ElementAt(i)))
{
return false;
}
}
return true;
}
public override bool Equals(object obj)
{
return Equals(obj as SeedQueue);
}
public override int GetHashCode()
{
return 1833020792 + EqualityComparer<Queue<Entry>>.Default.GetHashCode(queue);
}
public string Peek()
{
return (queue.Count == 0) ? null : queue.Peek().Name;
}
public string Dequeue()
{
if (queue.Count == 0)
{
return null;
}
Entry entry = queue.Peek();
entry.Amount--;
if (entry.Amount <= 0)
{
queue.Dequeue();
}
return entry.Name;
}
public List<Entry> Restrict(string newRestrict)
{
Dictionary<string, int> dictionary = new Dictionary<string, int>();
foreach (Entry item in queue)
{
if (dictionary.TryGetValue(item.Name, out var value))
{
dictionary[item.Name] = value + item.Amount;
}
else
{
dictionary[item.Name] = item.Amount;
}
}
queue.Clear();
if (dictionary.TryGetValue(newRestrict, out var value2))
{
queue.Enqueue(new Entry(newRestrict, value2));
dictionary.Remove(newRestrict);
}
return dictionary.Select((KeyValuePair<string, int> kv) => new Entry(kv.Key, kv.Value)).ToList();
}
public void RemoveSeed()
{
if (queue.Any())
{
Entry entry = queue.Peek();
entry.Amount--;
if (entry.Amount <= 0)
{
queue.Dequeue();
}
}
}
public ZPackage ToZPackage()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
ZPackage val = new ZPackage();
val.Write(queue.Count);
foreach (Entry item in queue)
{
val.Write(item.Name);
val.Write(item.Amount);
}
return val;
}
public static bool operator ==(SeedQueue left, SeedQueue right)
{
return left?.Equals(right) ?? ((object)right == null);
}
public static bool operator !=(SeedQueue left, SeedQueue right)
{
return !(left == right);
}
}
internal class SeedTotem : MonoBehaviour, Interactable, Hoverable
{
internal enum FieldShape
{
Circle,
Rectangle
}
public class ItemConversion
{
public ItemDrop seedDrop;
public Piece plantPiece;
public Plant plant;
public override string ToString()
{
return seedDrop.m_itemData.m_shared.m_name + " -> " + plant.m_name;
}
}
public enum PlacementStatus
{
Init,
Planting,
NoRoom,
WrongBiome
}
private const string ZDO_queued = "queued";
private const string ZDO_total = "total";
private const string ZDO_restrict = "restrict";
private const string messageSeedGenericPlural = "$message_seed_totem_seed_generic_plural";
private const string messageSeedGenericSingular = "$message_seed_totem_seed_generic";
private const string messageAll = "$message_seed_totem_all";
internal static ConfigEntry<KeyboardShortcut> configRadiusDecrementButton;
internal static ConfigEntry<KeyboardShortcut> configRadiusIncrementButton;
internal static ConfigEntry<KeyboardShortcut> configWidthDecrementButton;
internal static ConfigEntry<KeyboardShortcut> configWidthIncrementButton;
internal static ConfigEntry<KeyboardShortcut> configLengthDecrementButton;
internal static ConfigEntry<KeyboardShortcut> configLengthIncrementButton;
internal static ConfigEntry<float> configFlareSize;
internal static ConfigEntry<Color> configFlareColor;
internal static ConfigEntry<Color> configLightColor;
internal static ConfigEntry<float> configLightIntensity;
internal static ConfigEntry<Color> configGlowColor;
internal static ConfigEntry<bool> configShowQueue;
internal static ConfigEntry<float> configDefaultRadius;
internal static ConfigEntry<float> configDispersionTime;
internal static ConfigEntry<float> configMargin;
internal static ConfigEntry<int> configDispersionCount;
internal static ConfigEntry<int> configMaxRetries;
internal static ConfigEntry<bool> configHarvestOnHit;
internal static ConfigEntry<bool> configCheckCultivated;
internal static ConfigEntry<bool> configCheckBiome;
internal static ConfigEntry<int> configMaxSeeds;
internal static ConfigEntry<float> configMaxRadius;
internal static ConfigEntry<bool> configAdminOnlyRadius;
public static Dictionary<string, ItemConversion> seedPrefabMap = new Dictionary<string, ItemConversion>();
private ZNetView m_nview;
private Piece m_piece;
internal CircleProjector m_areaMarker;
internal RectangleProjector m_rectangleProjector;
private Animator m_animator;
internal GameObject m_enabledEffect;
internal MeshRenderer m_model;
internal MeshRenderer m_gearLeft;
internal MeshRenderer m_gearRight;
public static EffectList m_disperseEffects = new EffectList();
private static int m_spaceMask;
internal FieldShape m_shape = FieldShape.Circle;
private static bool scanningCultivator = false;
private string m_hoverText = "";
private float m_holdRepeatInterval = 1f;
private float m_lastUseTime;
internal static ConfigEntry<float> configRadiusChange;
public void Awake()
{
if (m_spaceMask == 0)
{
m_spaceMask = LayerMask.GetMask(new string[5] { "Default", "static_solid", "Default_small", "piece", "piece_nonsolid" });
}
ScanCultivator();
m_nview = ((Component)this).GetComponent<ZNetView>();
m_piece = ((Component)this).GetComponent<Piece>();
WearNTear component = ((Component)this).GetComponent<WearNTear>();
component.m_onDestroyed = (Action)Delegate.Combine(component.m_onDestroyed, new Action(OnDestroyed));
m_nview.Register<string, int>("AddSeed", (Action<long, string, int>)RPC_AddSeed);
m_nview.Register<string>("Restrict", (Action<long, string>)RPC_Restrict);
m_nview.Register<float>("SetRadius", (Action<long, float>)RPC_SetRadius);
m_nview.Register<float>("SetLength", (Action<long, float>)RPC_SetLength);
m_nview.Register<float>("SetWidth", (Action<long, float>)RPC_SetWidth);
if (((Object)this).name.StartsWith("piece_seed_totem_auto_field"))
{
m_shape = FieldShape.Rectangle;
m_rectangleProjector = ((Component)((Component)this).transform.Find("AreaMarker")).GetComponent<RectangleProjector>();
m_animator = ((Component)this).GetComponent<Animator>();
m_gearLeft = ((Component)((Component)this).transform.Find("new/pivot_left/gear_left")).GetComponent<MeshRenderer>();
m_gearRight = ((Component)((Component)this).transform.Find("new/pivot_right/gear_right")).GetComponent<MeshRenderer>();
}
if (!Object.op_Implicit((Object)(object)m_enabledEffect))
{
m_enabledEffect = ((Component)((Component)this).transform.Find("WayEffect")).gameObject;
}
if (!Object.op_Implicit((Object)(object)m_model))
{
m_model = ((Component)((Component)this).transform.Find("new/default")).GetComponent<MeshRenderer>();
}
if (!Object.op_Implicit((Object)(object)m_areaMarker))
{
Transform obj = ((Component)this).transform.Find("AreaMarker");
m_areaMarker = ((obj != null) ? ((Component)obj).GetComponent<CircleProjector>() : null);
}
((MonoBehaviour)this).InvokeRepeating("UpdateSeedTotem", 1f, 1f);
((MonoBehaviour)this).InvokeRepeating("DisperseSeeds", 1f, configDispersionTime.Value);
UpdateVisuals();
}
public void Start()
{
if (!Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid())
{
UpdateMaterials(active: true);
ShowAreaMarker(0f);
return;
}
UpdateMaterials(active: false);
HideMarker();
if (m_nview.IsOwner())
{
CountTotal();
}
}
public static void ScanCultivator()
{
if (scanningCultivator)
{
return;
}
scanningCultivator = true;
PieceTable pieceTable = PieceManager.Instance.GetPieceTable("_CultivatorPieceTable");
foreach (GameObject piece in pieceTable.m_pieces)
{
Plant component = piece.GetComponent<Plant>();
if (!Object.op_Implicit((Object)(object)component))
{
continue;
}
Piece component2 = piece.GetComponent<Piece>();
Requirement[] resources = component2.m_resources;
if (resources.Length > 1)
{
Logger.LogWarning((object)(" Multiple seeds required for " + component.m_name + "? Skipping"));
continue;
}
Requirement val = resources[0];
ItemDrop resItem = val.m_resItem;
if (!seedPrefabMap.ContainsKey(resItem.m_itemData.m_shared.m_name))
{
Logger.LogDebug((object)("Looking for Prefab of " + resItem.m_itemData.m_shared.m_name + " -> " + ((Object)((Component)resItem).gameObject).name));
ItemConversion itemConversion = new ItemConversion
{
seedDrop = val.m_resItem,
plantPiece = component2,
plant = component
};
Logger.LogDebug((object)("Registering seed type: " + itemConversion));
seedPrefabMap.Add(resItem.m_itemData.m_shared.m_name, itemConversion);
}
}
scanningCultivator = false;
}
internal static void OnDamage(orig_Damage orig, WearNTear self, HitData hit)
{
SeedTotem seedTotem = default(SeedTotem);
if (hit.GetTotalDamage() > 0f && ((Component)self).TryGetComponent<SeedTotem>(ref seedTotem))
{
SeedTotem seedTotem2 = seedTotem;
Character attacker = hit.GetAttacker();
seedTotem2.OnDamaged((Player)(object)((attacker is Player) ? attacker : null));
}
else
{
orig.Invoke(self, hit);
}
}
private void OnDamaged(Player player)
{
//IL_004e: 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_0098: 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_00db: Unknown result type (might be due to invalid IL or missing references)
if (!configHarvestOnHit.Value)
{
return;
}
if ((Object)(object)player == (Object)null)
{
Logger.LogWarning((object)"Not sure who hit us? Credit the local player");
player = Player.m_localPlayer;
}
FieldShape shape = m_shape;
FieldShape fieldShape = shape;
Collider[] array = ((fieldShape != 0 && fieldShape == FieldShape.Rectangle) ? Physics.OverlapBox(((Component)this).transform.TransformPoint(new Vector3(0f, 0f, -1f - GetLength() / 2f)), new Vector3(GetWidth() / 2f + configMargin.Value, 10f, GetLength() / 2f + configMargin.Value), ((Component)this).transform.rotation, m_spaceMask) : Physics.OverlapSphere(((Component)this).transform.position, GetRadius() + configMargin.Value, m_spaceMask));
for (int i = 0; i < array.Length; i++)
{
Pickable component = ((Component)array[i]).GetComponent<Pickable>();
if (Object.op_Implicit((Object)(object)component))
{
component.Interact((Humanoid)(object)player, false, false);
}
}
}
internal void CopyPrivateArea(PrivateArea privateArea)
{
m_areaMarker = privateArea.m_areaMarker;
((Component)m_areaMarker).gameObject.SetActive(false);
m_enabledEffect = privateArea.m_enabledEffect;
m_model = privateArea.m_model;
UpdateVisuals();
}
public void UpdateVisuals()
{
//IL_000c: 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_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_0076: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Expected O, but got Unknown
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: 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_00e4: 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)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: 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_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
//IL_0191: Unknown result type (might be due to invalid IL or missing references)
//IL_0196: 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_019b: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: 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_02aa: Unknown result type (might be due to invalid IL or missing references)
//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0301: Unknown result type (might be due to invalid IL or missing references)
//IL_030a: Unknown result type (might be due to invalid IL or missing references)
//IL_030f: Unknown result type (might be due to invalid IL or missing references)
//IL_0326: Unknown result type (might be due to invalid IL or missing references)
Vector3 position = ((Component)this).transform.position;
Logger.LogDebug((object)("Updating color of SeedTotem at " + ((object)(Vector3)(ref position)).ToString()));
Material[] materials = ((Renderer)m_model).materials;
Color value = configGlowColor.Value;
Material[] array = materials;
foreach (Material val in array)
{
string value2 = "Guardstone_OdenGlow_mat";
if (((Object)val).name.StartsWith(value2))
{
val.SetColor("_EmissionColor", value);
}
}
EffectData[] effectPrefabs = m_disperseEffects.m_effectPrefabs;
foreach (EffectData val2 in effectPrefabs)
{
ParticleSystem component = val2.m_prefab.GetComponent<ParticleSystem>();
ColorOverLifetimeModule colorOverLifetime = component.colorOverLifetime;
Gradient val3 = new Gradient();
val3.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
{
new GradientColorKey(value, 0f),
new GradientColorKey(Color.clear, 0.6f)
}, (GradientAlphaKey[])(object)new GradientAlphaKey[2]
{
new GradientAlphaKey(1f, 0f),
new GradientAlphaKey(0f, 0.6f)
});
((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val3);
}
GameObject gameObject = ((Component)m_enabledEffect.transform.Find("sparcs")).gameObject;
ParticleSystem component2 = gameObject.GetComponent<ParticleSystem>();
ShapeModule shape = component2.shape;
Vector3 scale = ((ShapeModule)(ref shape)).scale;
scale.y = 0.5f;
MainModule main = component2.main;
((MainModule)(ref main)).startColor = new MinMaxGradient(value, value * 0.2f);
GameObject gameObject2 = ((Component)m_enabledEffect.transform.Find("Point light")).gameObject;
Light component3 = gameObject2.GetComponent<Light>();
component3.color = configLightColor.Value;
component3.intensity = configLightIntensity.Value;
if (m_shape == FieldShape.Circle)
{
float radius = GetRadius();
m_areaMarker.m_radius = radius;
m_areaMarker.m_nrOfSegments = Mathf.CeilToInt(m_areaMarker.m_radius * 4f);
scale.x = radius;
scale.z = radius;
component3.range = radius;
}
else if (Object.op_Implicit((Object)(object)m_rectangleProjector))
{
float length = GetLength();
m_rectangleProjector.m_length = length;
((Component)m_rectangleProjector).transform.localPosition = new Vector3(0f, 0f, -1f - length / 2f);
m_rectangleProjector.m_width = GetWidth();
m_rectangleProjector.RefreshStuff(force: true);
}
GameObject gameObject3 = ((Component)m_enabledEffect.transform.Find("flare")).gameObject;
ParticleSystem component4 = gameObject3.GetComponent<ParticleSystem>();
MainModule main2 = component4.main;
((MainModule)(ref main2)).startColor = new MinMaxGradient(configFlareColor.Value);
((MainModule)(ref main2)).startSize = new MinMaxCurve(configFlareSize.Value);
}
public void UpdateSeedTotem()
{
if (m_nview.IsValid())
{
bool active = IsEnabled();
UpdateMaterials(active);
UpdateHoverText();
}
}
private void UpdateMaterials(bool active)
{
m_enabledEffect.SetActive(active);
if (Object.op_Implicit((Object)(object)m_animator))
{
((Behaviour)m_animator).enabled = active;
SetEmission(((Renderer)m_gearLeft).materials, active);
SetEmission(((Renderer)m_gearRight).materials, active);
}
SetEmission(((Renderer)m_model).materials, active);
}
private static void SetEmission(Material[] materials, bool active)
{
foreach (Material val in materials)
{
if (active)
{
val.EnableKeyword("_EMISSION");
}
else
{
val.DisableKeyword("_EMISSION");
}
}
}
private bool IsEnabled()
{
return GetQueueSize() > 0;
}
public string GetHoverName()
{
return m_piece.m_name;
}
public string GetHoverText()
{
//IL_007a: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
//IL_0167: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
//IL_0204: Unknown result type (might be due to invalid IL or missing references)
//IL_0209: Unknown result type (might be due to invalid IL or missing references)
if (!m_nview.IsValid() || (Object)(object)Player.m_localPlayer == (Object)null)
{
return "";
}
ShowAreaMarker();
if (!configAdminOnlyRadius.Value || SynchronizationManager.Instance.PlayerIsAdmin)
{
KeyboardShortcut value;
switch (m_shape)
{
case FieldShape.Circle:
value = configRadiusIncrementButton.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
m_nview.InvokeRPC("SetRadius", new object[1] { GetRadius() + configRadiusChange.Value });
break;
}
value = configRadiusDecrementButton.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
m_nview.InvokeRPC("SetRadius", new object[1] { GetRadius() - configRadiusChange.Value });
}
break;
case FieldShape.Rectangle:
value = configLengthIncrementButton.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
m_nview.InvokeRPC("SetLength", new object[1] { GetLength() + configRadiusChange.Value });
break;
}
value = configLengthDecrementButton.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
m_nview.InvokeRPC("SetLength", new object[1] { GetLength() - configRadiusChange.Value });
break;
}
value = configWidthIncrementButton.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
m_nview.InvokeRPC("SetWidth", new object[1] { GetWidth() + configRadiusChange.Value });
break;
}
value = configWidthDecrementButton.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
m_nview.InvokeRPC("SetWidth", new object[1] { GetWidth() - configRadiusChange.Value });
}
break;
}
}
return Localization.instance.Localize(m_hoverText);
}
private float GetRadius()
{
if (!Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid())
{
return configDefaultRadius.Value;
}
return m_nview.GetZDO().GetFloat("radius", configDefaultRadius.Value);
}
private float GetWidth()
{
if (!Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid())
{
return configDefaultRadius.Value;
}
return m_nview.GetZDO().GetFloat("width", configDefaultRadius.Value);
}
private float GetLength()
{
if (!Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid())
{
return configDefaultRadius.Value;
}
return m_nview.GetZDO().GetFloat("length", configDefaultRadius.Value);
}
public void ShowAreaMarker(float timeout = 0.5f)
{
switch (m_shape)
{
case FieldShape.Circle:
((Component)m_areaMarker).gameObject.SetActive(true);
break;
case FieldShape.Rectangle:
((Component)m_rectangleProjector).gameObject.SetActive(true);
break;
}
((MonoBehaviour)this).CancelInvoke("HideMarker");
if (timeout > 0f)
{
((MonoBehaviour)this).Invoke("HideMarker", timeout);
}
}
public void HideMarker()
{
switch (m_shape)
{
case FieldShape.Circle:
((Component)m_areaMarker).gameObject.SetActive(false);
break;
case FieldShape.Rectangle:
((Component)m_rectangleProjector).gameObject.SetActive(false);
break;
}
}
private void UpdateHoverText()
{
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_0152: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
StringBuilder stringBuilder = new StringBuilder(GetHoverName() + " (" + GetTotalSeedCount());
if (configMaxSeeds.Value > 0)
{
stringBuilder.Append("/" + configMaxSeeds.Value);
}
stringBuilder.Append(")\n");
string restrict = GetRestrict();
string text = "$message_seed_totem_seed_generic";
string text2 = "$message_seed_totem_seed_generic_plural";
if (restrict != "")
{
text = restrict;
text2 = restrict;
}
if (restrict != "")
{
stringBuilder.Append("<color=grey>$message_seed_totem_restricted_to</color> <color=green>" + restrict + "</color>\n");
}
stringBuilder.Append("[<color=yellow><b>$KEY_Use</b></color>] $piece_smelter_add " + text + "\n");
stringBuilder.Append("[$message_seed_totem_hold <color=yellow><b>$KEY_Use</b></color>] $piece_smelter_add $message_seed_totem_all " + text2 + "\n");
stringBuilder.Append("[<color=yellow><b>1-8</b></color>] $message_seed_totem_restrict\n");
if (!configAdminOnlyRadius.Value || SynchronizationManager.Instance.PlayerIsAdmin)
{
switch (m_shape)
{
case FieldShape.Circle:
stringBuilder.Append($"[<color=yellow>{configRadiusIncrementButton.Value}</color>/<color=yellow>{configRadiusDecrementButton.Value}</color>] $hud_seed_totem_change_radius\n");
break;
case FieldShape.Rectangle:
stringBuilder.Append($"[<color=yellow>{configWidthIncrementButton.Value}</color>/<color=yellow>{configWidthDecrementButton.Value}</color>] $hud_seed_totem_change_width\n");
stringBuilder.Append($"[<color=yellow>{configLengthIncrementButton.Value}</color>/<color=yellow>{configLengthDecrementButton.Value}</color>] $hud_seed_totem_change_length\n");
break;
}
}
if (configShowQueue.Value)
{
stringBuilder.Append("\n");
for (int i = 0; i < GetQueueSize(); i++)
{
string queuedSeed = GetQueuedSeed(i);
int queuedSeedCount = GetQueuedSeedCount(i);
PlacementStatus queuedStatus = GetQueuedStatus(i);
stringBuilder.Append(queuedSeedCount + " " + queuedSeed);
switch (queuedStatus)
{
case PlacementStatus.NoRoom:
stringBuilder.Append("[<color=green>$message_seed_totem_status_looking_for_space</color>]");
break;
case PlacementStatus.Planting:
stringBuilder.Append("[<color=green>$message_seed_totem_status_planting</color>]");
break;
case PlacementStatus.WrongBiome:
stringBuilder.Append("[<color=red>$message_seed_totem_status_wrong_biome</color>]");
break;
}
stringBuilder.Append("\n");
}
}
m_hoverText = stringBuilder.ToString();
}
private int GetTotalSeedCount()
{
return m_nview.GetZDO().GetInt("total", 0);
}
private void DropSeeds(string seedName, int amount)
{
//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_00d0: 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_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: 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_0106: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: 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)
if (seedName == null)
{
return;
}
Logger.LogDebug((object)("Dropping instances of " + seedName));
if (!seedPrefabMap.ContainsKey(seedName))
{
Logger.LogWarning((object)("Skipping unknown key " + seedName));
return;
}
ItemDrop seedDrop = seedPrefabMap[seedName].seedDrop;
GameObject gameObject = ((Component)seedDrop).gameObject;
if ((Object)(object)gameObject == (Object)null)
{
Logger.LogWarning((object)("No seed found for " + seedName));
return;
}
int num = amount;
int maxStackSize = seedDrop.m_itemData.m_shared.m_maxStackSize;
Logger.LogDebug((object)("Dropping " + num + " in stacks of " + maxStackSize));
do
{
Vector3 val = ((Component)this).transform.position + Vector3.up + Random.insideUnitSphere * 0.3f;
Quaternion val2 = Quaternion.Euler(0f, (float)Random.Range(0, 360), 0f);
ItemDrop component = Object.Instantiate<GameObject>(gameObject, val, val2).GetComponent<ItemDrop>();
int num2 = ((num > maxStackSize) ? maxStackSize : num);
if (amount != 0)
{
component.m_itemData.m_stack = num2;
}
num -= num2;
Logger.LogDebug((object)("Dropped " + num2 + ", " + num + " left to go"));
}
while (num > 0);
}
private void DropAllSeeds()
{
while (GetQueueSize() > 0)
{
string queuedSeed = GetQueuedSeed();
int queuedSeedCount = GetQueuedSeedCount();
DropSeeds(queuedSeed, queuedSeedCount);
ShiftQueueDown();
}
}
public string FindSeed(string restrict, Inventory inventory)
{
if (restrict == "")
{
foreach (string key in seedPrefabMap.Keys)
{
Logger.LogDebug((object)("Looking for seed " + key));
if (inventory.HaveItem(key, true))
{
Logger.LogDebug((object)"Found seed!");
return key;
}
}
}
else
{
Logger.LogDebug((object)("Looking for seed " + restrict));
if (inventory.HaveItem(restrict, true))
{
Logger.LogDebug((object)"Found seed!");
return restrict;
}
}
return null;
}
public bool Interact(Humanoid user, bool hold, bool alt)
{
if (((Character)Player.m_localPlayer).InPlaceMode())
{
return false;
}
if (hold)
{
if (m_holdRepeatInterval <= 0f)
{
return false;
}
if (Time.time - m_lastUseTime < m_holdRepeatInterval)
{
return false;
}
m_lastUseTime = Time.time;
return AddAllSeeds(user);
}
m_lastUseTime = Time.time;
string restrict = GetRestrict();
string text = FindSeed(restrict, user.GetInventory());
if (text == null)
{
string text2 = ((!(restrict == "")) ? restrict : "$message_seed_totem_seed_generic_plural");
((Character)user).Message((MessageType)2, "$msg_donthaveany " + text2, 0, (Sprite)null);
return false;
}
if (configMaxSeeds.Value > 0)
{
int totalSeedCount = GetTotalSeedCount();
if (totalSeedCount >= configMaxSeeds.Value)
{
((Character)user).Message((MessageType)2, "$msg_itsfull", 0, (Sprite)null);
return false;
}
}
user.GetInventory().RemoveItem(text, 1, -1, true);
m_nview.InvokeRPC("AddSeed", new object[2] { text, 1 });
((Character)user).Message((MessageType)2, "$msg_added " + text, 0, (Sprite)null);
return true;
}
private bool AddAllSeeds(Humanoid user)
{
string restrict = GetRestrict();
StringBuilder stringBuilder = new StringBuilder();
bool flag = false;
foreach (string key in seedPrefabMap.Keys)
{
if (restrict != "" && restrict != key)
{
continue;
}
Logger.LogDebug((object)("Looking for seed " + key));
int num = user.GetInventory().CountItems(key, -1, true);
if (configMaxSeeds.Value > 0)
{
int totalSeedCount = GetTotalSeedCount();
int num2 = configMaxSeeds.Value - totalSeedCount;
if (num2 < 0)
{
if (flag)
{
return true;
}
((Character)user).Message((MessageType)2, "$msg_itsfull", 0, (Sprite)null);
return false;
}
num = Math.Min(num2, num);
}
if (num > 0)
{
m_nview.InvokeRPC("AddSeed", new object[2] { key, num });
user.GetInventory().RemoveItem(key, num, -1, true);
if (stringBuilder.Length > 0)
{
stringBuilder.Append("\n");
}
stringBuilder.Append("$msg_added " + num + " " + key);
}
}
string text = stringBuilder.ToString();
if (text.Length > 0)
{
((Character)user).Message((MessageType)2, stringBuilder.ToString(), 0, (Sprite)null);
return true;
}
string text2 = ((!(restrict == "")) ? restrict : "$message_seed_totem_seed_generic_plural");
((Character)user).Message((MessageType)2, "$msg_donthaveany " + text2, 0, (Sprite)null);
return false;
}
public bool UseItem(Humanoid user, ItemData item)
{
if (Object.op_Implicit((Object)(object)item.m_shared.m_buildPieces))
{
return false;
}
if (((Character)Player.m_localPlayer).InPlaceMode())
{
return false;
}
string text = GetSeedName(item);
if (text == null)
{
return false;
}
if (!seedPrefabMap.ContainsKey(text))
{
if (!(GetRestrict() != ""))
{
((Character)user).Message((MessageType)2, "$message_seed_totem_not_a_seed", 0, (Sprite)null);
return false;
}
text = "";
((Character)user).Message((MessageType)2, "$message_seed_totem_unrestricted", 0, (Sprite)null);
}
Logger.LogDebug((object)("Restricting to " + text));
m_nview.InvokeRPC("Restrict", new object[1] { text });
return true;
}
private string GetSeedName(ItemData item)
{
return item.m_shared.m_name;
}
private PlacementStatus TryPlacePlant(ItemConversion conversion, int maxRetries)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_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_00b2: 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_00a3: 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_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: 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_01cc: Unknown result type (might be due to invalid IL or missing references)
int num = 0;
Vector3 val2 = default(Vector3);
PlacementStatus result;
do
{
num++;
FieldShape shape = m_shape;
FieldShape fieldShape = shape;
Vector3 val;
if (fieldShape == FieldShape.Circle || fieldShape != FieldShape.Rectangle)
{
float radius = GetRadius();
val = ((Component)this).transform.position + Vector3.up + Random.onUnitSphere * radius;
}
else
{
float width = GetWidth();
((Vector3)(ref val2))..ctor(width * Random.Range(0f, 1f) - width / 2f, 0f, -1f - GetLength() * Random.Range(0f, 1f));
val = ((Component)this).transform.TransformPoint(val2);
}
float groundHeight = ZoneSystem.instance.GetGroundHeight(val);
val.y = groundHeight;
if ((int)conversion.plant.m_biome != 0 && configCheckBiome.Value && !IsCorrectBiome(val, conversion.plant.m_biome))
{
result = PlacementStatus.WrongBiome;
continue;
}
if (conversion.plant.m_needCultivatedGround && configCheckCultivated.Value && !IsCultivated(val))
{
result = PlacementStatus.NoRoom;
continue;
}
if (!HasGrowSpace(val, conversion.plant.m_growRadius))
{
result = PlacementStatus.NoRoom;
continue;
}
string? obj = ((object)conversion.plantPiece)?.ToString();
Vector3 val3 = val;
Logger.LogDebug((object)("Placing new plant " + obj + " at " + ((object)(Vector3)(ref val3)).ToString()));
Quaternion val4 = Quaternion.Euler(0f, (float)Random.Range(0, 360), 0f);
GameObject val5 = Object.Instantiate<GameObject>(((Component)conversion.plantPiece).gameObject, val, val4);
conversion.plantPiece.m_placeEffect.Create(val, val4, val5.transform, 1f, -1);
RemoveOneSeed();
return PlacementStatus.Planting;
}
while (num <= maxRetries);
Logger.LogDebug((object)("Max retries reached, result " + result));
return result;
}
private bool IsCorrectBiome(Vector3 p, Biome biome)
{
//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_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Invalid comparison between Unknown and I4
Heightmap val = Heightmap.FindHeightmap(p);
return Object.op_Implicit((Object)(object)val) && (val.GetBiome(p, 0.02f, false) & biome) > 0;
}
private bool IsCultivated(Vector3 p)
{
//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)
Heightmap val = Heightmap.FindHeightmap(p);
return Object.op_Implicit((Object)(object)val) && val.IsCultivated(p);
}
private void DumpQueueDetails()
{
StringBuilder stringBuilder = new StringBuilder("QueueDetails:");
for (int i = 0; i < GetQueueSize(); i++)
{
string queuedSeed = GetQueuedSeed(i);
int queuedSeedCount = GetQueuedSeedCount(i);
PlacementStatus queuedStatus = GetQueuedStatus(i);
stringBuilder.AppendLine("Position " + i + " -> " + queuedSeed + " -> " + queuedSeedCount + " -> " + queuedStatus);
}
Logger.LogWarning((object)stringBuilder.ToString());
}
internal void DisperseSeeds()
{
//IL_0168: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsOwner() || !m_nview.IsValid() || (Object)(object)Player.m_localPlayer == (Object)null)
{
return;
}
bool flag = false;
int num = 0;
int value = configMaxRetries.Value;
while (GetQueueSize() > 0)
{
string queuedSeed = GetQueuedSeed();
int queuedSeedCount = GetQueuedSeedCount();
if (!seedPrefabMap.ContainsKey(queuedSeed))
{
Logger.LogWarning((object)("Key '" + queuedSeed + "' not found in seedPrefabMap"));
DumpQueueDetails();
Logger.LogWarning((object)"Shifting queue to remove invalid entry");
ShiftQueueDown();
return;
}
ItemConversion conversion = seedPrefabMap[queuedSeed];
PlacementStatus placementStatus = TryPlacePlant(conversion, value);
SetStatus(placementStatus);
switch (placementStatus)
{
case PlacementStatus.Planting:
num++;
flag = true;
goto IL_0129;
case PlacementStatus.WrongBiome:
Logger.LogDebug((object)("Wrong biome deteced, moving " + queuedSeed + " to end of queue"));
MoveToEndOfQueue(queuedSeed, queuedSeedCount, placementStatus);
break;
default:
goto IL_0129;
case PlacementStatus.NoRoom:
break;
}
break;
IL_0129:
if (num >= configDispersionCount.Value)
{
break;
}
}
if (flag)
{
m_disperseEffects.Create(((Component)this).transform.position, Quaternion.Euler(0f, (float)Random.Range(0, 360), 0f), ((Component)this).transform, GetRadius() / 5f, -1);
}
}
private void MoveToEndOfQueue(string currentSeed, int currentCount, PlacementStatus status)
{
Logger.LogDebug((object)("Moving " + currentSeed + " to end of queue"));
DumpQueueDetails();
ShiftQueueDown();
QueueSeed(currentSeed, currentCount, status);
Logger.LogDebug((object)"After move");
DumpQueueDetails();
}
private bool HasGrowSpace(Vector3 position, float m_growRadius)
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
if (m_spaceMask == 0)
{
m_spaceMask = LayerMask.GetMask(new string[5] { "Default", "static_solid", "Default_small", "piece", "piece_nonsolid" });
}
Collider[] array = Physics.OverlapSphere(position, m_growRadius + configMargin.Value, m_spaceMask);
for (int i = 0; i < array.Length; i++)
{
Plant component = ((Component)array[i]).GetComponent<Plant>();
if (!Object.op_Implicit((Object)(object)component) || (Object)(object)component != (Object)(object)this)
{
return false;
}
}
return true;
}
public void OnDestroyed()
{
Logger.LogInfo((object)"SeedTotem destroyed, dropping all seeds");
DropAllSeeds();
((MonoBehaviour)this).CancelInvoke("UpdateSeedTotem");
}
private int GetCurrentCount(string seedName)
{
return m_nview.GetZDO().GetInt(seedName, 0);
}
private int GetQueueSize()
{
return m_nview.GetZDO().GetInt("queued", 0);
}
private string GetQueuedSeed(int queuePosition = 0)
{
if (GetQueueSize() == 0)
{
return null;
}
return m_nview.GetZDO().GetString("item" + queuePosition, (string)null);
}
private void SetStatus(PlacementStatus status)
{
m_nview.GetZDO().Set("item0status", (int)status);
}
private PlacementStatus GetQueuedStatus(int queuePosition = 0)
{
if (GetQueueSize() == 0)
{
return PlacementStatus.Init;
}
return (PlacementStatus)m_nview.GetZDO().GetInt("item" + queuePosition + "status", 0);
}
private int GetQueuedSeedCount(int queuePosition = 0)
{
if (GetQueueSize() == 0)
{
return 0;
}
return m_nview.GetZDO().GetInt("item" + queuePosition + "count", 0);
}
private void SetQueueSeedCount(int queuePosition, int count)
{
m_nview.GetZDO().Set("item" + queuePosition + "count", count);
}
private void RemoveOneSeed()
{
Logger.LogDebug((object)"--Removing 1 seed--");
int queueSize = GetQueueSize();
if (queueSize <= 0)
{
Logger.LogWarning((object)"Tried to remove a seed when none are queued");
DumpQueueDetails();
return;
}
int queuedSeedCount = GetQueuedSeedCount();
Logger.LogDebug((object)("Current count " + queuedSeedCount));
if (queuedSeedCount > 1)
{
SetQueueSeedCount(0, queuedSeedCount - 1);
}
else
{
ShiftQueueDown();
}
SetTotalSeedCount(GetTotalSeedCount() - 1);
}
private void ShiftQueueDown()
{
int queueSize = GetQueueSize();
if (queueSize == 0)
{
Logger.LogError((object)"Invalid ShiftQueueDown, queue is empty");
DumpQueueDetails();
return;
}
for (int i = 0; i < queueSize; i++)
{
string @string = m_nview.GetZDO().GetString("item" + (i + 1), "");
m_nview.GetZDO().Set("item" + i, @string);
int @int = m_nview.GetZDO().GetInt("item" + (i + 1) + "count", 0);
m_nview.GetZDO().Set("item" + i + "count", @int);
int int2 = m_nview.GetZDO().GetInt("item" + (i + 1) + "status", 0);
m_nview.GetZDO().Set("item" + i + "status", int2);
}
queueSize--;
m_nview.GetZDO().Set("queued", queueSize);
}
private void QueueSeed(string name, int amount = 1, PlacementStatus status = PlacementStatus.Init)
{
int queueSize = GetQueueSize();
string queuedSeed = GetQueuedSeed(queueSize - 1);
if (queuedSeed == name)
{
SetQueueSeedCount(queueSize - 1, GetQueuedSeedCount(queueSize - 1) + amount);
}
else
{
m_nview.GetZDO().Set("item" + queueSize, name);
m_nview.GetZDO().Set("item" + queueSize + "count", amount);
m_nview.GetZDO().Set("item" + queueSize + "status", (int)status);
m_nview.GetZDO().Set("queued", queueSize + 1);
}
SetTotalSeedCount(GetTotalSeedCount() + amount);
}
private void SetTotalSeedCount(int amount)
{
m_nview.GetZDO().Set("total", amount);
}
private void RPC_SetRadius(long sender, float newRadius)
{
if (m_nview.IsOwner())
{
newRadius = Mathf.Clamp(newRadius, 2f, configMaxRadius.Value);
Logger.LogInfo((object)$"Updating radius to {newRadius}");
m_nview.GetZDO().Set("radius", newRadius);
}
UpdateVisuals();
}
private void RPC_SetWidth(long sender, float newWidth)
{
if (m_nview.IsOwner())
{
newWidth = Mathf.Clamp(newWidth, 2f, configMaxRadius.Value);
Logger.LogInfo((object)$"Updating width to {newWidth}");
m_nview.GetZDO().Set("width", newWidth);
}
UpdateVisuals();
}
private void RPC_SetLength(long sender, float newLength)
{
if (m_nview.IsOwner())
{
newLength = Mathf.Clamp(newLength, 2f, configMaxRadius.Value);
Logger.LogInfo((object)$"Updating length to {newLength}");
m_nview.GetZDO().Set("length", newLength);
}
UpdateVisuals();
}
private void RPC_DropSeeds(long sender)
{
if (m_nview.IsOwner())
{
DropAllSeeds();
}
}
private void RPC_AddSeed(long sender, string seedName, int amount)
{
if (m_nview.IsOwner())
{
QueueSeed(seedName, amount);
}
}
private void RPC_Restrict(long sender, string restrict)
{
if (!m_nview.IsOwner())
{
return;
}
SetRestrict(restrict);
int queueSize = GetQueueSize();
int num = 0;
for (int i = 0; i < queueSize; i++)
{
string queuedSeed = GetQueuedSeed();
int queuedSeedCount = GetQueuedSeedCount();
if (queuedSeed != restrict)
{
DropSeeds(queuedSeed, queuedSeedCount);
ShiftQueueDown();
}
else
{
num += queuedSeedCount;
MoveToEndOfQueue(queuedSeed, queuedSeedCount, GetQueuedStatus());
}
}
SetTotalSeedCount(num);
Logger.LogDebug((object)("Restricted to " + restrict));
}
private void CountTotal()
{
int queueSize = GetQueueSize();
int num = 0;
for (int i = 0; i < queueSize; i++)
{
num += GetQueuedSeedCount();
}
SetTotalSeedCount(num);
}
private void SetRestrict(string seedName)
{
m_nview.GetZDO().Set("restrict", seedName);
}
public string GetRestrict()
{
return m_nview.GetZDO().GetString("restrict", "");
}
internal static void SettingsUpdated()
{
SeedTotem[] array = Object.FindObjectsOfType<SeedTotem>();
foreach (SeedTotem seedTotem in array)
{
seedTotem.UpdateVisuals();
((MonoBehaviour)seedTotem).CancelInvoke("DisperseSeeds");
((MonoBehaviour)seedTotem).InvokeRepeating("DisperseSeeds", 1f, configDispersionTime.Value);
}
}
public DestructibleType GetDestructibleType()
{
//IL_0002: 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)
return (DestructibleType)1;
}
}
[BepInPlugin("0zzerod.SeedTotem", "Seed Totem", "0.1.3")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
internal class SeedTotemMod : BaseUnityPlugin
{
public enum PieceLocation
{
Hammer,
Cultivator
}
public const string PluginGUID = "0zzerod.SeedTotem";
public const string PluginName = "Seed Totem";
public const string PluginVersion = "0.1.3";
public ConfigEntry<int> nexusID;
private SeedTotemPrefabConfig seedTotemPrefabConfig;
private Harmony harmony;
public void Awake()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Expected O, but got Unknown
harmony = new Harmony("0zzerod.SeedTotem");
harmony.PatchAll();
WearNTear.Damage += new hook_Damage(SeedTotem.OnDamage);
CreateConfiguration();
PrefabManager.OnVanillaPrefabsAvailable += AddCustomPrefabs;
SeedTotem.configGlowColor.SettingChanged += SettingsChanged;
SeedTotem.configLightColor.SettingChanged += SettingsChanged;
SeedTotem.configLightIntensity.SettingChanged += SettingsChanged;
SeedTotem.configFlareColor.SettingChanged += SettingsChanged;
SeedTotem.configFlareSize.SettingChanged += SettingsChanged;
SeedTotemPrefabConfig.configLocation.SettingChanged += UpdatePieceLocation;
PieceManager.OnPiecesRegistered += OnPiecesRegistered;
}
private void CreateConfiguration()
{
//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_0040: Expected O, but got Unknown
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: 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_0093: Expected O, but got Unknown
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Expected O, but got Unknown
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Expected O, but got Unknown
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: Expected O, but got Unknown
//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_0113: Expected O, but got Unknown
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Expected O, but got Unknown
//IL_0141: Unknown result type (might be due to invalid IL or missing references)
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Expected O, but got Unknown
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Expected O, but got Unknown
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
//IL_018b: Expected O, but got Unknown
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Expected O, but got Unknown
//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: Expected O, but got Unknown
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_01d1: Expected O, but got Unknown
//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0203: Expected O, but got Unknown
//IL_0203: Unknown result type (might be due to invalid IL or missing references)
//IL_020d: Expected O, but got Unknown
//IL_0231: Unknown result type (might be due to invalid IL or missing references)
//IL_0236: Unknown result type (might be due to invalid IL or missing references)
//IL_023f: Expected O, but got Unknown
//IL_023f: Unknown result type (might be due to invalid IL or missing references)
//IL_0249: Expected O, but got Unknown
//IL_026d: Unknown result type (might be due to invalid IL or missing references)
//IL_0272: Unknown result type (might be due to invalid IL or missing references)
//IL_027b: Expected O, but got Unknown
//IL_027b: Unknown result type (might be due to invalid IL or missing references)
//IL_0285: Expected O, but got Unknown
//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
//IL_02bb: Expected O, but got Unknown
//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
//IL_02c5: Expected O, but got Unknown
//IL_02ed: 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_02fb: Expected O, but got Unknown
//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0305: Expected O, but got Unknown
//IL_0329: Unknown result type (might be due to invalid IL or missing references)
//IL_032e: Unknown result type (might be due to invalid IL or missing references)
//IL_0337: Expected O, but got Unknown
//IL_0337: Unknown result type (might be due to invalid IL or missing references)
//IL_0341: Expected O, but got Unknown
//IL_0362: Unknown result type (might be due to invalid IL or missing references)
//IL_036c: Expected O, but got Unknown
//IL_0395: Unknown result type (might be due to invalid IL or missing references)
//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
//IL_03af: Expected O, but got Unknown
//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
//IL_03f2: Expected O, but got Unknown
//IL_0417: Unknown result type (might be due to invalid IL or missing references)
//IL_0421: Expected O, but got Unknown
//IL_044a: Unknown result type (might be due to invalid IL or missing references)
//IL_045a: Unknown result type (might be due to invalid IL or missing references)
//IL_0464: Expected O, but got Unknown
//IL_0489: Unknown result type (might be due to invalid IL or missing references)
//IL_0493: Expected O, but got Unknown
//IL_04b8: Unknown result type (might be due to invalid IL or missing references)
//IL_04c2: Expected O, but got Unknown
//IL_04e1: Unknown result type (might be due to invalid IL or missing references)
//IL_050b: Unknown result type (might be due to invalid IL or missing references)
//IL_0535: Unknown result type (might be due to invalid IL or missing references)
//IL_055f: Unknown result type (might be due to invalid IL or missing references)
//IL_0589: Unknown result type (might be due to invalid IL or missing references)
//IL_05b3: Unknown result type (might be due to invalid IL or missing references)
//IL_05f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0600: Expected O, but got Unknown
SeedTotem.configMaxRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Server", "Max Dispersion Radius", 20f, new ConfigDescription("Max dispersion radius of the Seed totem.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 64f), new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true
} }));
SeedTotem.configDefaultRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Server", "Default Dispersion Radius", 5f, new ConfigDescription("Default dispersion radius of the Seed totem.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, SeedTotem.configMaxRadius.Value), new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true
} }));
SeedTotem.configDispersionTime = ((BaseUnityPlugin)this).Config.Bind<float>("Server", "Dispersion time", 10f, new ConfigDescription("Time (in seconds) between each dispersion (low values can cause lag)", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true
} }));
SeedTotem.configMargin = ((BaseUnityPlugin)this).Config.Bind<float>("Server", "Space requirement margin", 0.1f, new ConfigDescription("Extra distance to make sure plants have enough space", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true
} }));
SeedTotem.configDispersionCount = ((BaseUnityPlugin)this).Config.Bind<int>("Server", "Dispersion count", 5, new ConfigDescription("Maximum number of plants to place when dispersing (high values can cause lag)", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true
} }));
SeedTotem.configMaxRetries = ((BaseUnityPlugin)this).Config.Bind<int>("Server", "Max retries", 8, new ConfigDescription("Maximum number of placement tests on each dispersion (high values can cause lag)", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true
} }));
SeedTotem.configHarvestOnHit = ((BaseUnityPlugin)this).Config.Bind<bool>("Server", "Harvest on hit", true, new ConfigDescription("Should the Seed totem send out a wave to pick all pickables in radius when hit?", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true
} }));
SeedTotem.configAdminOnlyRadius = ((BaseUnityPlugin)this).Config.Bind<bool>("Server", "Only admin can change radius", true, new ConfigDescription("Should only admins be able to change the radius of individual Seed totems?", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true
} }));
SeedTotem.configCheckCultivated = ((BaseUnityPlugin)this).Config.Bind<bool>("Server", "Check for cultivated ground", true, new ConfigDescription("Should the Seed totem also check for cultivated land?", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true
} }));
SeedTotem.configCheckBiome = ((BaseUnityPlugin)this).Config.Bind<bool>("Server", "Check for correct biome", true, new ConfigDescription("Should the Seed totem also check for the correct biome?", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true
} }));
SeedTotemPrefabConfig.configRecipe = ((BaseUnityPlugin)this).Config.Bind<string>("Server", "Seed totem requirements", "FineWood:5,GreydwarfEye:5,SurtlingCore:1,AncientSeed:1", new ConfigDescription("Requirements to build the Seed totem", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true
} }));
AutoFieldPrefabConfig.configRecipe = ((BaseUnityPlugin)this).Config.Bind<string>("Server", "Advanced seed totem requirements", "FineWood:10,GreydwarfEye:10,SurtlingCore:2,AncientSeed:1", new ConfigDescription("Requirements to build the Advanced seed totem", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true
} }));
SeedTotem.configMaxSeeds = ((BaseUnityPlugin)this).Config.Bind<int>("Server", "Max seeds in totem (0 is no limit)", 0, new ConfigDescription("Maximum number of seeds in each totem, 0 is no limit", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
{
IsAdminOnly = true
} }));
SeedTotem.configShowQueue = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "Show queue", true, new ConfigDescription("Show the current queue on hover", (AcceptableValueBase)null, Array.Empty<object>()));
SeedTotem.configGlowColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Graphical", "Glow lines color", new Color(0f, 0.8f, 0f, 1f), new ConfigDescription("Color of the glowing lines on the Seed totem", (AcceptableValueBase)null, Array.Empty<object>()));
SeedTotem.configLightColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Graphical", "Glow light color", new Color(0f, 0.8f, 0f, 0.05f), new ConfigDescription("Color of the light from the Seed totem", (AcceptableValueBase)null, Array.Empty<object>()));
SeedTotem.configLightIntensity = ((BaseUnityPlugin)this).Config.Bind<float>("Graphical", "Glow light intensity", 3f, new ConfigDescription("Intensity of the light flare from the Seed totem", (AcceptableValueBase)null, Array.Empty<object>()));
SeedTotem.configFlareColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Graphical", "Glow flare color", new Color(0f, 0.8f, 0f, 0.1f), new ConfigDescription("Color of the light flare from the Seed totem", (AcceptableValueBase)null, Array.Empty<object>()));
SeedTotem.configFlareSize = ((BaseUnityPlugin)this).Config.Bind<float>("Graphical", "Glow flare size", 3f, new ConfigDescription("Size of the light flare from the Seed totem", (AcceptableValueBase)null, Array.Empty<object>()));
SeedTotem.configRadiusChange = ((BaseUnityPlugin)this).Config.Bind<float>("Input", "Radius size change for each keypress", 1f, new ConfigDescription("How much the radius will change for each keypress", (AcceptableValueBase)null, Array.Empty<object>()));
SeedTotem.configRadiusIncrementButton = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Input", "Increment seed totem radius", new KeyboardShortcut((KeyCode)270, Array.Empty<KeyCode>()), (ConfigDescription)null);
SeedTotem.configRadiusDecrementButton = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Input", "Decrement seed totem radius", new KeyboardShortcut((KeyCode)269, Array.Empty<KeyCode>()), (ConfigDescription)null);
SeedTotem.configWidthIncrementButton = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Input", "Increment seed totem width", new KeyboardShortcut((KeyCode)275, Array.Empty<KeyCode>()), (ConfigDescription)null);
SeedTotem.configWidthDecrementButton = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Input", "Decrement seed totem width", new KeyboardShortcut((KeyCode)276, Array.Empty<KeyCode>()), (ConfigDescription)null);
SeedTotem.configLengthIncrementButton = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Input", "Increment seed totem length", new KeyboardShortcut((KeyCode)273, Array.Empty<KeyCode>()), (ConfigDescription)null);
SeedTotem.configLengthDecrementButton = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Input", "Decrement seed totem length", new KeyboardShortcut((KeyCode)274, Array.Empty<KeyCode>()), (ConfigDescription)null);
nexusID = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 876, new ConfigDescription("Nexus mod ID for updates", (AcceptableValueBase)(object)new AcceptableValueList<int>(new int[1] { 876 }), Array.Empty<object>()));
SeedTotemPrefabConfig.configLocation = ((BaseUnityPlugin)this).Config.Bind<PieceLocation>("UI", "Build menu", PieceLocation.Hammer, "In which build menu is the Seed totem located");
}
private void OnPiecesRegistered()
{
seedTotemPrefabConfig.UpdatePieceLocation();
}
public void OnDestroy()
{
Harmony obj = harmony;
if (obj != null)
{
obj.UnpatchSelf();
}
}
private void AddCustomPrefabs()
{
AssetBundle val = AssetUtils.LoadAssetBundleFromResources("seedtotem", typeof(SeedTotemMod).Assembly);
try
{
seedTotemPrefabConfig = new SeedTotemPrefabConfig();
GameObject prefab = PrefabManager.Instance.CreateClonedPrefab("SeedTotem", "guard_stone");
seedTotemPrefabConfig.UpdateCopiedPrefab(val, prefab);
AutoFieldPrefabConfig autoFieldPrefabConfig = new AutoFieldPrefabConfig();
autoFieldPrefabConfig.UpdateCopiedPrefab(val);
}
catch (Exception arg)
{
Logger.LogError((object)$"Error while adding cloned item: {arg}");
}
finally
{
PrefabManager.OnVanillaPrefabsAvailable -= AddCustomPrefabs;
if (val != null)
{
val.Unload(false);
}
}
}
private void UpdatePieceLocation(object sender, EventArgs e)
{
seedTotemPrefabConfig.UpdatePieceLocation();
}
private void SettingsChanged(object sender, EventArgs e)
{
SeedTotem.SettingsUpdated();
}
public static string GetAssetPath(string assetName, bool isDirectory = false)
{
string text = Path.Combine(Paths.PluginPath, "SeedTotem", assetName);
if (isDirectory)
{
if (!Directory.Exists(text))
{
Assembly assembly = typeof(SeedTotemMod).Assembly;
text = Path.Combine(Path.GetDirectoryName(assembly.Location), assetName);
if (!Directory.Exists(text))
{
Logger.LogWarning((object)("Could not find directory (" + assetName + ")."));
return null;
}
}
return text;
}
if (!File.Exists(text))
{
Assembly assembly2 = typeof(SeedTotemMod).Assembly;
text = Path.Combine(Path.GetDirectoryName(assembly2.Location), assetName);
if (!File.Exists(text))
{
Logger.LogWarning((object)("Could not find asset (" + assetName + ")."));
return null;
}
}
return text;
}
private void Update()
{
if (Input.GetKeyDown((KeyCode)290))
{
Logger.LogInfo((object)"Right here");
}
}
}
internal class AutoFieldPrefabConfig
{
private const string localizationName = "seed_totem";
public const string ravenTopic = "$tutorial_seed_totem_topic";
public const string ravenText = "$tutorial_seed_totem_text";
public const string ravenLabel = "$tutorial_seed_totem_label";
public const string requirementsFile = "seed-totem-custom-requirements.json";
public const string prefabName = "piece_seed_totem_auto_field";
internal static ConfigEntry<SeedTotemMod.PieceLocation> configLocation;
internal static ConfigEntry<string> configRecipe;
private GameObject currentPiece;
private static RequirementConfig[] ParseRequirements()
{
//IL_0050: 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_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Expected O, but got Unknown
string[] array = configRecipe.Value.Split(new char[1] { ',' });
RequirementConfig[] array2 = (RequirementConfig[])(object)new RequirementConfig[array.Length];
int num = 0;
string[] array3 = array;
foreach (string text in array3)
{
string[] array4 = text.Split(new char[1] { ':' });
array2[num++] = new RequirementConfig
{
Item = array4[0],
Amount = int.Parse(array4[1]),
Recover = true
};
}
return array2;
}
public void UpdateCopiedPrefab(AssetBundle assetBundle)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Expected O, but got Unknown
//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_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: 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_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Expected O, but got Unknown
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Expected O, but got Unknown
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: 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_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Expected O, but got Unknown
//IL_0170: Unknown result type (might be due to invalid IL or missing references)
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
//IL_0199: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_01f6: Expected O, but got Unknown
//IL_0221: Unknown result type (might be due to invalid IL or missing references)
//IL_023d: Unknown result type (might be due to invalid IL or missing references)
//IL_024a: 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)
GameObject val = assetBundle.LoadAsset<GameObject>("piece_seed_totem_auto_field");
Sprite autoFieldIcon = assetBundle.LoadAsset<Sprite>("auto_field_icon");
KitbashManager instance = KitbashManager.Instance;
KitbashConfig val2 = new KitbashConfig();
val2.Layer = "piece";
val2.FixReferences = true;
List<KitbashSourceConfig> list = new List<KitbashSourceConfig>
{
new KitbashSourceConfig
{
Name = "default",
TargetParentPath = "new",
SourcePrefab = "guard_stone",
SourcePath = "new/default",
Scale = Vector3.one * 0.6f
}
};
KitbashSourceConfig val3 = new KitbashSourceConfig();
val3.Name = "hopper";
val3.TargetParentPath = "new";
val3.Position = new Vector3(0.29f, 1.12f, 1.26f);
val3.Rotation = Quaternion.Euler(177.7f, -258.918f, -89.55298f);
val3.Scale = Vector3.one;
val3.SourcePrefab = "piece_spinningwheel";
val3.SourcePath = "SpinningWheel_Destruction/SpinningWheel_Destruction_SpinningWheel_Broken.016";
val3.Materials = new string[1] { "SpinningWheel_mat" };
list.Add(val3);
val3 = new KitbashSourceConfig();
val3.Name = "gear_left";
val3.TargetParentPath = "new/pivot_left";
val3.Position = new Vector3(-0.383f, 0.8181f, -0.8028001f);
val3.Rotation = Quaternion.Euler(0f, -90.00001f, -90.91601f);
val3.Scale = Vector3.one * 0.68285f;
val3.SourcePrefab = "piece_artisanstation";
val3.SourcePath = "ArtisanTable_Destruction/ArtisanTable_Destruction.007_ArtisanTable.019";
val3.Materials = new string[2] { "ArtisanTable_Mat", "TearChanal_mat" };
list.Add(val3);
val3 = new KitbashSourceConfig();
val3.Name = "gear_right";
val3.TargetParentPath = "new/pivot_right";
val3.Position = new Vector3(-0.47695f, 0.5057697f, -0.7557001f);
val3.Rotation = Quaternion.Euler(0f, -90.00001f, -90.91601f);
val3.Scale = Vector3.one * 0.68285f;
val3.SourcePrefab = "piece_artisanstation";
val3.SourcePath = "ArtisanTable_Destruction/ArtisanTable_Destruction.006_ArtisanTable.018";
val3.Materials = new string[2] { "ArtisanTable_Mat", "TearChanal_mat" };
list.Add(val3);
val2.KitbashSources = list;
KitbashObject autoFieldKitbash = instance.AddKitbash(val, val2);
KitbashObject obj = autoFieldKitbash;
obj.OnKitbashApplied = (Action)Delegate.Combine(obj.OnKitbashApplied, (Action)delegate
{
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Expected O, but got Unknown
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Expected O, but got Unknown
SeedTotem seedTotem = autoFieldKitbash.Prefab.AddComponent<SeedTotem>();
seedTotem.m_shape = SeedTotem.FieldShape.Rectangle;
GameObject prefab = PrefabManager.Instance.GetPrefab("guard_stone");
GameObject val4 = Object.Instantiate<GameObject>(((Component)prefab.transform.Find("WayEffect")).gameObject, autoFieldKitbash.Prefab.transform);
((Object)val4).name = "WayEffect";
seedTotem.m_enabledEffect = val4;
seedTotem.m_model = ((Component)((Component)seedTotem).transform.Find("new/default")).GetComponent<MeshRenderer>();
seedTotem.UpdateVisuals();
seedTotem.m_enabledEffect = val4;
RectangleProjector rectangleProjector = ((Component)autoFieldKitbash.Prefab.transform.Find("AreaMarker")).gameObject.AddComponent<RectangleProjector>();
seedTotem.m_rectangleProjector = rectangleProjector;
PieceManager.Instance.AddPiece(new CustomPiece(autoFieldKitbash.Prefab, true, new PieceConfig
{
PieceTable = "Hammer",
CraftingStation = "piece_artisanstation",
Requirements = ParseRequirements(),
Icon = autoFieldIcon
}));
});
}
internal void UpdatePieceLocation()
{
Logger.LogDebug((object)("Moving Seed totem to " + configLocation.Value));
foreach (SeedTotemMod.PieceLocation value in Enum.GetValues(typeof(SeedTotemMod.PieceLocation)))
{
currentPiece = RemovePieceFromPieceTable(value, "piece_seed_totem_auto_field");
if ((Object)(object)currentPiece != (Object)null)
{
break;
}
}
if (configLocation.Value == SeedTotemMod.PieceLocation.Cultivator)
{
GetPieceTable(configLocation.Value).m_pieces.Insert(2, currentPiece);
}
else
{
GetPieceTable(configLocation.Value).m_pieces.Add(currentPiece);
}
if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
{
Player.m_localPlayer.AddKnownPiece(currentPiece.GetComponent<Piece>());
}
}
private PieceTable GetPieceTable(SeedTotemMod.PieceLocation location)
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
string text = $"_{location}PieceTable";
Object[] array = Resources.FindObjectsOfTypeAll(typeof(PieceTable));
for (int i = 0; i < array.Length; i++)
{
PieceTable val = (PieceTable)array[i];
string name = ((Object)((Component)val).gameObject).name;
if (text == name)
{
return val;
}
}
return null;
}
private GameObject RemovePieceFromPieceTable(SeedTotemMod.PieceLocation location, string pieceName)
{
Logger.LogDebug((object)("Removing " + pieceName + " from " + location));
PieceTable pieceTable = GetPieceTable(location);
int num = pieceTable.m_pieces.FindIndex((GameObject piece) => ((Object)piece).name == pieceName);
if (num >= 0)
{
Logger.LogDebug((object)("Found Piece " + pieceName + " at position " + num));
GameObject result = pieceTable.m_pieces[num];
pieceTable.m_pieces.RemoveAt(num);
return result;
}
return null;
}
}
internal class SeedTotemPrefabConfig
{
public const string prefabName = "SeedTotem";
private const string localizationName = "seed_totem";
public const string ravenTopic = "$tutorial_seed_totem_topic";
public const string ravenText = "$tutorial_seed_totem_text";
public const string ravenLabel = "$tutorial_seed_totem_label";
public const string requirementsFile = "seed-totem-custom-requirements.json";
internal static ConfigEntry<SeedTotemMod.PieceLocation> configLocation;
internal static ConfigEntry<string> configRecipe;
private GameObject currentPiece;
private GameObject Prefab;
private static RequirementConfig[] ParseRequirements()
{
//IL_0050: 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_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Expected O, but got Unknown
string[] array = configRecipe.Value.Split(new char[1] { ',' });
RequirementConfig[] array2 = (RequirementConfig[])(object)new RequirementConfig[array.Length];
int num = 0;
string[] array3 = array;
foreach (string text in array3)
{
string[] array4 = text.Split(new char[1] { ':' });
array2[num++] = new RequirementConfig
{
Item = array4[0],
Amount = int.Parse(array4[1]),
Recover = true
};
}
return array2;
}
public void UpdateCopiedPrefab(AssetBundle assetBundle, GameObject prefab)
{
Prefab = prefab;
Piece component = Prefab.GetComponent<Piece>();
component.m_name = "$piece_seed_totem_name";
component.m_description = "$piece_seed_totem_description";
component.m_clipGround = true;
component.m_groundPiece = true;
component.m_groundOnly = true;
component.m_noInWater = true;
GuidePoint[] componentsInChildren = Prefab.GetComponentsInChildren<GuidePoint>();
foreach (GuidePoint val in componentsInChildren)
{
val.m_text.m_key = "seed_totem";
val.m_text.m_topic = "$tutorial_seed_totem_topic";
val.m_text.m_text = "$tutorial_seed_totem_text";
val.m_text.m_label = "$tutorial_seed_totem_label";
}
SeedTotem seedTotem = Prefab.AddComponent<SeedTotem>();
PrivateArea component2 = Prefab.GetComponent<PrivateArea>();
if ((Object)(object)component2 != (Object)null)
{
Logger.LogDebug((object)"Converting PrivateArea to SeedTotem");
seedTotem.CopyPrivateArea(component2);
Logger.LogDebug((object)("Destroying redundant PrivateArea: " + (object)component2));
Object.DestroyImmediate((Object)(object)component2);
}
RegisterPiece(assetBundle);
}
internal void RegisterPiece(AssetBundle assetBundle)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: 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_006b: Expected O, but got Unknown
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Expected O, but got Unknown
Logger.LogInfo((object)"Registering Seed Totem Piece");
PieceManager.Instance.AddPiece(new CustomPiece(Prefab, false, new PieceConfig
{
PieceTable = configLocation.Value.ToString(),
Icon = assetBundle.LoadAsset<Sprite>("seed_totem_icon"),
Description = "$piece_seed_totem_description",
Requirements = ParseRequirements()
}));
}
internal void UpdatePieceLocation()
{
Logger.LogInfo((object)("Moving Seed Totem to " + configLocation.Value));
foreach (SeedTotemMod.PieceLocation value in Enum.GetValues(typeof(SeedTotemMod.PieceLocation)))
{
currentPiece = RemovePieceFromPieceTable(value, "SeedTotem");
if ((Object)(object)currentPiece != (Object)null)
{
break;
}
}
if (configLocation.Value == SeedTotemMod.PieceLocation.Cultivator)
{
GetPieceTable(configLocation.Value).m_pieces.Insert(2, currentPiece);
}
else
{
GetPieceTable(configLocation.Value).m_pieces.Add(currentPiece);
}
if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
{
Player.m_localPlayer.AddKnownPiece(currentPiece.GetComponent<Piece>());
}
}
private PieceTable GetPieceTable(SeedTotemMod.PieceLocation location)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Expected O, but got Unknown
string text = $"_{location}PieceTable";
Object[] array = Resources.FindObjectsOfTypeAll(typeof(PieceTable));
Object[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
PieceTable val = (PieceTable)array2[i];
if (text == ((Object)((Component)val).gameObject).name)
{
return val;
}
}
return null;
}
private GameObject RemovePieceFromPieceTable(SeedTotemMod.PieceLocation location, string pieceName)
{
Logger.LogDebug((object)("Removing " + pieceName + " from " + location));
PieceTable pieceTable = GetPieceTable(location);
int num = pieceTable.m_pieces.FindIndex((GameObject piece) => ((Object)piece).name == pieceName);
if (num >= 0)
{
Logger.LogDebug((object)("Found Piece " + pieceName + " at position " + num));
GameObject result = pieceTable.m_pieces[num];
pieceTable.m_pieces.RemoveAt(num);
return result;
}
return null;
}
}
}
namespace SeedTotem.Utils
{
internal class RectangleProjector : MonoBehaviour
{
public float cubesSpeed = 1f;
public float m_length = 2f;
public float m_width = 2f;
private static GameObject _segment;
private GameObject rootCube;
private float cubesThickness = 0.15f;
private float cubesHeight = 0.1f;
private float cubesLength = 1f;
private int cubesPerWidth;
private int cubesPerLength;
private float updatesPerSecond = 60f;
private float cubesLength100;
private float cubesWidth100;
private float sideLengthHalved;
private float sideWidthHalved;
internal bool isRunning = false;
private Transform parentNorth;
private Transform parentEast;
private Transform parentSouth;
private Transform parentWest;
private List<Transform> cubesNorth = new List<Transform>();
private List<Transform> cubesEast = new List<Transform>();
private List<Transform> cubesSouth = new List<Transform>();
private List<Transform> cubesWest = new List<Transform>();
private static GameObject SelectionSegment
{
get
{
if (!Object.op_Implicit((Object)(object)_segment))
{
GameObject prefab = PrefabManager.Instance.GetPrefab("piece_workbench");
_segment = Object.Instantiate<GameObject>(prefab.GetComponentInChildren<CircleProjector>().m_prefab);
_segment.SetActive(true);
}
return _segment;
}
}
public void Start()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
//IL_0048: 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_0090: Unknown result type (might be due to invalid IL or missing references)
rootCube = new GameObject("cube");
GameObject val = Object.Instantiate<GameObject>(SelectionSegment);
val.transform.SetParent(rootCube.transform);
val.transform.localScale = new Vector3(1f, 1f, 1f);
val.transform.localPosition = new Vector3(0f, 0f, -0.5f);
rootCube.transform.localScale = new Vector3(cubesThickness, cubesHeight, cubesLength);
rootCube.SetActive(true);
RefreshStuff();
StartProjecting();
}
private void OnEnable()
{
if (!isRunning && !((Object)(object)parentNorth == (Object)null))
{
isRunning = true;
StartMarchingCubes();
}
}
private void StartMarchingCubes()
{
((MonoBehaviour)this).StartCoroutine(AnimateElements(parentNorth, cubesNorth, length: false));
((MonoBehaviour)this).StartCoroutine(AnimateElements(parentEast, cubesEast, length: true));
((MonoBehaviour)this).StartCoroutine(AnimateElements(parentSouth, cubesSouth, length: false));
((MonoBehaviour)this).StartCoroutine(AnimateElements(parentWest, cubesWest, length: true));
}
private void OnDisable()
{
isRunning = false;
}
public void StartProjecting()
{
if (!isRunning)
{
isRunning = true;
parentNorth = CreateElements(0, cubesNorth);
parentEast = CreateElements(90, cubesEast);
parentSouth = CreateElements(180, cubesSouth);
parentWest = CreateElements(270, cubesWest);
StartMarchingCubes();
}
}
public void StopProjecting()
{
if (isRunning)
{
isRunning = false;
((MonoBehaviour)this).StopAllCoroutines();
Object.Destroy((Object)(object)((Component)parentNorth).gameObject);
Object.Destroy((Object)(object)((Component)parentEast).gameObject);
Object.Destroy((Object)(object)((Component)parentSouth).gameObject);
Object.Destroy((Object)(object)((Component)parentWest).gameObject);
cubesNorth.Clear();
cubesEast.Clear();
cubesSouth.Clear();
cubesWest.Clear();
}
}
internal void RefreshStuff(bool force = false)
{
cubesPerLength = Mathf.FloorToInt(m_length / 2f);
cubesPerWidth = Mathf.FloorToInt(m_width / 2f);
cubesLength100 = m_length / (float)cubesPerLength;
cubesWidth100 = m_width / (float)cubesPerWidth;
sideLengthHalved = m_length / 2f;
sideWidthHalved = m_width / 2f;
if (isRunning && (force || cubesPerLength + 1 != cubesNorth.Count || cubesPerWidth + 1 != cubesEast.Count))
{
StopProjecting();
StartProjecting();
}
}
private Transform CreateElements(int rotation, List<Transform> cubes)
{
//IL_0008: 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_0036: 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_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_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
Transform transform = new GameObject(rotation.ToString()).transform;
((Component)transform).transform.position = ((Component)this).transform.position;
((Component)transform).transform.rotation = ((Component)this).transform.rotation;
((Component)transform).transform.RotateAround(((Component)this).transform.position, Vector3.up, (float)rotation);
transform.SetParent(((Component)this).transform);
int num = ((rotation % 180 == 0) ? cubesPerLength : cubesPerWidth);
for (int i = 0; i < num + 1; i++)
{
cubes.Add(Object.Instantiate<GameObject>(rootCube, ((Component)this).transform.position, Quaternion.identity, transform).transform);
}
Transform transform2 = new GameObject("Start").transform;
Transform transform3 = new GameObject("End").transform;
transform2.SetParent(transform);
transform3.SetParent(transform);
for (int j = 0; j < cubes.Count; j++)
{
cubes[j].forward = transform.right;
}
return transform;
}
private IEnumerator AnimateElements(Transform cubeParent, List<Transform> cubes, bool length)
{
Transform a = cubeParent.Find("Start");
Transform b = cubeParent.Find("End");
int cubesPerSide = (length ? cubesPerLength : cubesPerWidth);
float sideLength = (length ? m_length : m_width);
float halfSideLength = (length ? sideLengthHalved : sideWidthHalved);
float halfSideWidth = (length ? sideWidthHalved : sideLengthHalved);
float cubes2 = (length ? cubesLength100 : cubesWidth100);
while (true)
{
RefreshStuff();
a.position = cubeParent.forward * (halfSideWidth - cubesThickness / 2f) - cubeParent.right * halfSideLength + cubeParent.position;
b.position = cubeParent.forward * (halfSideWidth - cubesThickness / 2f) + cubeParent.right * halfSideLength + cubeParent.position;
Vector3 dir = b.position - a.position;
for (int i = 0; i < cubes.Count; i++)
{
Transform cube = cubes[i];
((Component)cube).gameObject.SetActive(true);
float pos = (Time.time * cubesSpeed + sideLength / (float)cubesPerSide * (float)i) % (sideLength + cubes2);
if (pos < cubesLength)
{
cube.position = ((Vector3)(ref dir)).normalized * pos + a.position;
cube.localScale = new Vector3(cube.localScale.x, cube.localScale.y, cubesLength - (cubesLength - pos));
}
else if (pos >= sideLength && pos <= sideLength + cubesLength)
{
cube.position = ((Vector3)(ref dir)).normalized * sideLength + a.position;
cube.localScale = new Vector3(cube.localScale.x, cube.localScale.y, cubesLength - (pos - sideLength));
}
else if (pos >= sideLength && pos >= sideLength + cubesLength)
{
((Component)cube).gameObject.SetActive(false);
}
else
{
cube.position = ((Vector3)(ref dir)).normalized * pos + a.position;
cube.localScale = new Vector3(cube.localScale.x, cube.localScale.y, cubesLength);
}
}
yield return (object)new WaitForSecondsRealtime(1f / updatesPerSecond);
dir = default(Vector3);
}
}
}
}