using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using FishNet.Object;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("HTFTest")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HTFTest")]
[assembly: AssemblyTitle("HTFTest")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[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 HTFTest
{
public enum GatherMode
{
All,
FishOnly,
ItemsOnly
}
[BepInPlugin("com.dan.htf.test", "HTF Test", "0.3.0")]
public class Plugin : BaseUnityPlugin
{
private ConfigEntry<KeyCode> _key;
private ConfigEntry<float> _distance;
private ConfigEntry<GatherMode> _mode;
private ConfigEntry<KeyCode> _cycleKey;
private ConfigEntry<KeyCode> _sellKey;
private void Awake()
{
_key = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "GatherKey", (KeyCode)289, "Teleport all loose items in front of you");
_distance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Distance", 3f, "Meters in front of the player");
_mode = ((BaseUnityPlugin)this).Config.Bind<GatherMode>("General", "Mode", GatherMode.All, "All, FishOnly (fish, dead ones included) or ItemsOnly (everything that is not a fish)");
_cycleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "CycleModeKey", (KeyCode)290, "Cycles the gather mode in-game");
_sellKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "SellFishKey", (KeyCode)291, "Sell every loose dead fish (host only)");
((BaseUnityPlugin)this).Logger.LogInfo((object)"HTF Test 0.3.0 loaded");
}
private void Update()
{
//IL_0006: 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_0078: Unknown result type (might be due to invalid IL or missing references)
if (Input.GetKeyDown(_cycleKey.Value))
{
_mode.Value = (GatherMode)((int)(_mode.Value + 1) % 3);
((BaseUnityPlugin)this).Logger.LogInfo((object)("Gather mode: " + _mode.Value));
}
if (Input.GetKeyDown(_sellKey.Value))
{
SellFish();
}
if (Input.GetKeyDown(_key.Value) && (Object)(object)Player.LocalPlayer != (Object)null)
{
((MonoBehaviour)this).StartCoroutine(Gather());
}
}
private void SellFish()
{
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Invalid comparison between Unknown and I4
if (!Object.op_Implicit((Object)(object)Server.Instance) || !((NetworkBehaviour)Server.Instance).IsServerInitialized)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"Selling only works as host");
return;
}
HashSet<Item> hashSet = new HashSet<Item>();
List<Item> list = new List<Item>();
foreach (Item value in ItemManager.Items.Values)
{
if (Object.op_Implicit((Object)(object)value) && hashSet.Add(value) && (int)value.Type == 1 && Object.op_Implicit((Object)(object)value.Creature) && value.Creature.IsDead && !Object.op_Implicit((Object)(object)value.Holder) && !Object.op_Implicit((Object)(object)value.SyncedHolder) && !value.IsInInventory && !Object.op_Implicit((Object)(object)value.AttachedRod) && !((NetworkBehaviour)value).IsDeinitializing && !value.IsDestroying)
{
list.Add(value);
}
}
int num = 0;
foreach (Item item in list)
{
num += item.TotalWorth;
MoneyManager.SellItem(item);
item.DestroyItem((byte)0, byte.MaxValue);
}
((BaseUnityPlugin)this).Logger.LogInfo((object)$"Sold {list.Count} fish for {num}");
}
private bool Matches(Item item)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Invalid comparison between Unknown and I4
bool flag = (int)item.Type == 1;
if (_mode.Value != GatherMode.All)
{
return _mode.Value == GatherMode.FishOnly == flag;
}
return true;
}
private IEnumerator Gather()
{
Transform transform = Player.LocalPlayer.Transform;
Vector3 target = transform.position + transform.forward * _distance.Value + Vector3.up;
List<Item> list = new List<Item>();
HashSet<Item> seen = new HashSet<Item>();
foreach (Item value in ItemManager.Items.Values)
{
if (Object.op_Implicit((Object)(object)value) && seen.Add(value) && (!Object.op_Implicit((Object)(object)value.Creature) || value.CanPickUp) && !Object.op_Implicit((Object)(object)value.Bird) && !Object.op_Implicit((Object)(object)value.DeadPlayer) && !Object.op_Implicit((Object)(object)value.SyncedHolder) && !value.IsInInventory && !Object.op_Implicit((Object)(object)value.AttachedRod) && Object.op_Implicit((Object)(object)value.RigidbodySync) && Matches(value))
{
list.Add(value);
}
}
foreach (Item item in list)
{
if (!item.RigidbodySync.IsSimulatedLocal)
{
Server.Instance.SetSyncedSimulator(item, ((NetworkBehaviour)Server.Instance).Owner);
}
}
float t = 0f;
while (t < 2f)
{
t += Time.deltaTime;
yield return null;
}
int num = 0;
int num2 = 0;
Vector3 val = default(Vector3);
foreach (Item item2 in list)
{
if (Object.op_Implicit((Object)(object)item2) && item2.RigidbodySync.IsSimulatedLocal)
{
((Vector3)(ref val))..ctor(((float)(num % 8) - 3.5f) * 0.6f, (float)(num / 64) * 0.6f, ((float)(num / 8 % 8) - 3.5f) * 0.6f);
item2.RigidbodySync.TeleportToPosRot(target + val, ((Component)item2).transform.rotation, (float[])null, (Quaternion[])null);
if (Object.op_Implicit((Object)(object)item2.Rig) && !item2.Rig.isKinematic)
{
item2.Rig.linearVelocity = Vector3.zero;
item2.Rig.angularVelocity = Vector3.zero;
}
num++;
num2++;
}
}
((BaseUnityPlugin)this).Logger.LogInfo((object)$"Gathered {num2}/{list.Count} items (registered {seen.Count}, not simulated locally {list.Count - num2})");
}
}
}