using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FindItemsForQuotaBepin5.Networking;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("FindItemsForQuotaBepin5")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FindItemsForQuotaBepin5")]
[assembly: AssemblyTitle("FindItemsForQuotaBepin5")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace FindItemsForQuotaBepin5
{
internal class FindItemsForQuotaBepin5Config
{
private readonly ConfigFile Config;
public Dictionary<string, ConfigEntry<bool>> Filter;
private readonly List<string> GeneralItems;
private readonly List<string> SpecialItems;
public FindItemsForQuotaBepin5Config(ConfigFile File)
{
Config = File;
GeneralItems = new List<string>(new <>z__ReadOnlyArray<string>(new string[21]
{
"PerfumeBottle", "LaserPointer", "FancyLamp", "RedSodaCan", "FancyGlass", "MagnifyingGlass", "Dentures", "Mug", "Painting", "TragedyMask",
"RobotToy", "FancyRing", "HandBell", "Hairdryer", "Magic7Ball", "ComedyMask", "OldPhone", "Airhorn", "ToyCube", "BinFullOfBottles",
"Hairbrush"
}));
SpecialItems = new List<string>(new <>z__ReadOnlyArray<string>(new string[8] { "PickleJar", "LungApparatusTurnedOff", "GoldBar", "RedLocustHive", "ShotgunItem", "RubberDucky", "CashRegisterItem", "KnifeItem" }));
base..ctor();
}
public void RegisterOptions()
{
Filter = new Dictionary<string, ConfigEntry<bool>>();
foreach (string generalItem in GeneralItems)
{
Filter.Add(generalItem, Config.Bind<bool>("Filter", generalItem, false, "Decides if the mod should filter (until no longer possible) this item."));
}
foreach (string specialItem in SpecialItems)
{
Filter.Add(specialItem, Config.Bind<bool>("Filter", specialItem, true, "Decides if the mod should filter (until no longer possible) this item."));
}
}
}
[BepInPlugin("Rbmukthegreat.FindItemsForQuotaMod", "Find Items For Quota Mod", "1.2.3")]
public class Plugin : BaseUnityPlugin
{
private const string modGUID = "Rbmukthegreat.FindItemsForQuotaMod";
private const string modName = "Find Items For Quota Mod";
private const string modVersion = "1.2.3";
internal static FindItemsForQuotaBepin5Config ConfigInstance;
private readonly Harmony harmony = new Harmony("Rbmukthegreat.FindItemsForQuotaMod");
internal static ManualLogSource Log;
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin FindItemsForQuotaBepin5 is loaded!");
((BaseUnityPlugin)this).Logger.LogInfo((object)"Current version: 1.0.0");
ConfigInstance = new FindItemsForQuotaBepin5Config(((BaseUnityPlugin)this).Config);
ConfigInstance.RegisterOptions();
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
}
internal class Przydatek
{
public static List<int> PrzydatekFast(List<int> a, int B)
{
int num = a.Count();
if (num == 0)
{
return null;
}
Random r = new Random(Guid.NewGuid().GetHashCode());
List<int> result = new List<int>(new int[num]);
int num2 = B;
for (int i = 0; i < 40; i++)
{
int delta_curr = B;
List<int> x = new List<int>(new int[num]);
foreach (int item in from y in Enumerable.Range(0, num)
orderby r.Next()
select y)
{
if (a[item] <= delta_curr)
{
x[item] = 1;
delta_curr -= a[item];
}
}
List<int> list = (from index in x.Select((int value, int index) => (value == 1) ? index : (-1))
where index != -1
select index).ToList();
foreach (int item2 in from y in Enumerable.Range(0, list.Count())
orderby r.Next()
select y)
{
int index2 = list[item2];
if (delta_curr == 0)
{
break;
}
IEnumerable<(int, int)> enumerable = from valueIndexPair in a.Select((int al, int l) => (x[l] == 0 && 0 < al - a[index2] && al - a[index2] <= delta_curr) ? (al, l) : (0, -1))
where valueIndexPair.Item2 != -1
select valueIndexPair;
if (enumerable.Any())
{
int index3 = MaxIndex(enumerable);
delta_curr -= a[index3] - a[index2];
x[index3] = 1;
x[index2] = 0;
}
}
if (delta_curr < num2)
{
result = x;
num2 = delta_curr;
}
if (num2 == 0)
{
break;
}
}
return result;
}
private static int MaxIndex(IEnumerable<(int, int)> T)
{
int num = int.MinValue;
int result = -1;
foreach (var (num2, num3) in T)
{
if (num2 > num)
{
num = num2;
result = num3;
}
}
return result;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "FindItemsForQuotaBepin5";
public const string PLUGIN_NAME = "FindItemsForQuotaBepin5";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace FindItemsForQuotaBepin5.Patches
{
[HarmonyPatch]
internal class FindItemsForQuotaPatcher
{
private static readonly ManualLogSource Log = Plugin.Log;
private static GameObject _ship;
private static int Credits;
private static int ProfitQuota => TimeOfDay.Instance.profitQuota;
private static int QuotaFulfilled => TimeOfDay.Instance.quotaFulfilled;
private static SelectableLevel CurrentLevel => StartOfRound.Instance?.currentLevel;
private static PlayerControllerB Player => StartOfRound.Instance?.localPlayerController;
private static bool ShipLanded => StartOfRound.Instance.shipHasLanded;
[HarmonyPatch(typeof(Terminal), "Start")]
[HarmonyPostfix]
private static void UpdateCreditsStart(int ___groupCredits)
{
Credits = ___groupCredits;
}
[HarmonyPatch(typeof(Terminal), "BuyItemsServerRpc")]
[HarmonyPostfix]
private static void UpdateCreditsAfterPurchase(int ___groupCredits)
{
Credits = ___groupCredits;
}
[HarmonyPatch(typeof(HUDManager), "AddTextToChatOnServer")]
[HarmonyPostfix]
private static void GetText(string chatMessage)
{
Log.LogMessage((object)chatMessage);
string[] array = chatMessage.Split(new char[1] { ' ' });
if (array.Length >= 2)
{
if (array[0] == ".find" && int.TryParse(array[1], out var result))
{
FindItems(null, result);
}
else if (array[0] == ".find" && (array[1].ToLower() == "rend" || array[1].ToLower() == "art"))
{
FindItems(array[1], 0);
}
}
}
[HarmonyPatch(typeof(StartOfRound), "openingDoorsSequence")]
[HarmonyPostfix]
private static void LogShipLanded()
{
((MonoBehaviour)GameNetworkManager.Instance).StartCoroutine(LogShipLandedCoroutine());
}
private static IEnumerator LogShipLandedCoroutine()
{
yield return (object)new WaitForSeconds(21.05f);
Log.LogMessage((object)"Ship has landed!");
}
private static void FindItems(string moon, int target)
{
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)CurrentLevel))
{
Log.LogMessage((object)"Scene hasn't loaded yet!");
return;
}
if (!ShipLanded)
{
Log.LogMessage((object)"Ship hasn't landed yet!");
return;
}
if (CurrentLevel.levelID != 3)
{
Log.LogMessage((object)"Not at company building!");
return;
}
int num = CalculateMoneyNeeded(moon, target);
Log.LogMessage((object)$"Money needed: {num}");
List<GrabbableObject> loot2 = GetLoot(num);
Vector3 position = default(Vector3);
((Vector3)(ref position))..ctor(-27.95f, -2.62f, -31.36f);
((Component)Player).transform.position = position;
List<int> subset = Przydatek.PrzydatekFast(loot2.Select((GrabbableObject loot) => loot.scrapValue).ToList(), num);
Log.LogMessage((object)$"Total items being sold: {subset.Sum()}");
loot2 = loot2.Where((GrabbableObject loot, int index) => subset[index] == 1).ToList();
TeleportObjects(loot2);
}
private static List<GrabbableObject> GetLoot(int moneyNeeded)
{
if (!Object.op_Implicit((Object)(object)_ship))
{
_ship = GameObject.Find("/Environment/HangarShip");
}
string Clone = "(Clone)";
List<GrabbableObject> list = (from obj in _ship.GetComponentsInChildren<GrabbableObject>()
where obj.itemProperties.isScrap && !(obj is RagdollGrabbableObject) && ((Object)obj).name.Substring(0, ((Object)obj).name.Count() - Clone.Count()) != "GiftBox"
select obj).ToList();
List<GrabbableObject> list2 = list.Where((GrabbableObject loot) => IsItemAllowed(((Object)loot).name.Substring(0, ((Object)loot).name.Count() - Clone.Count()), Plugin.ConfigInstance.Filter)).ToList();
if (list2.Select((GrabbableObject loot) => loot.scrapValue).Sum() > moneyNeeded)
{
list = list2;
}
return list;
}
private static int CalculateMoneyNeeded(string moon, int totalNeeded)
{
if (moon != null)
{
int num = ((moon == "rend") ? 550 : 1500);
return Mathf.Max(NeedToSell(num - Credits), ProfitQuota - QuotaFulfilled);
}
return (NeedToSell(totalNeeded) < totalNeeded) ? NeedToSell(totalNeeded) : totalNeeded;
}
private static int NeedToSell(int target)
{
int num = 15;
return Mathf.CeilToInt(1f / 6f * (float)(5 * (target + num) + ProfitQuota - QuotaFulfilled));
}
private static bool IsItemAllowed(string item, Dictionary<string, ConfigEntry<bool>> Filter)
{
ConfigEntry<bool> value;
return !Filter.TryGetValue(item, out value) || !value.Value;
}
private static void TeleportObjects(List<GrabbableObject> loot)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
foreach (GrabbableObject item in loot)
{
DropItemAt(item, ((Component)Player).transform.position);
}
int num = loot.Select((GrabbableObject loot) => loot.scrapValue).Sum();
Log.LogMessage((object)$"Total sold: {num}");
}
private static void DropItemAt(GrabbableObject item, Vector3 position)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
NetworkFunctions.NetworkingObjectManager.MakeObjectFallClientRpc(NetworkObjectReference.op_Implicit(((NetworkBehaviour)item).NetworkObject), position, Quaternion.identity);
}
}
}
namespace FindItemsForQuotaBepin5.Networking
{
internal class NetworkFunctions
{
public class NetworkingObjectManager : NetworkBehaviour
{
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static HandleNamedMessageDelegate <>9__3_0;
internal void <NetworkManagerInit>b__3_0(ulong senderClientId, FastBufferReader reader)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
if (senderClientId != Player.playerClientId)
{
NetworkObjectReference val = default(NetworkObjectReference);
((FastBufferReader)(ref reader)).ReadValueSafe<NetworkObjectReference>(ref val, default(ForNetworkSerializable));
Vector3 placementPosition = default(Vector3);
((FastBufferReader)(ref reader)).ReadValueSafe(ref placementPosition);
Quaternion placementRotation = default(Quaternion);
((FastBufferReader)(ref reader)).ReadValueSafe(ref placementRotation);
NetworkObject val2 = default(NetworkObject);
if (((NetworkObjectReference)(ref val)).TryGet(ref val2, (NetworkManager)null))
{
GrabbableObject component = ((Component)val2).GetComponent<GrabbableObject>();
MakeObjectFall(component, placementPosition, placementRotation);
}
}
}
}
public static void MakeObjectFall(GrabbableObject obj, Vector3 placementPosition, Quaternion placementRotation)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
((Component)obj).gameObject.transform.SetPositionAndRotation(placementPosition, placementRotation);
obj.hasHitGround = false;
obj.startFallingPosition = placementPosition;
obj.floorYRot = -1;
if ((Object)(object)((Component)obj).transform.parent != (Object)null)
{
obj.startFallingPosition = ((Component)obj).transform.parent.InverseTransformPoint(obj.startFallingPosition);
}
obj.FallToGround(false);
obj.floorYRot = -1;
}
[ClientRpc]
public static void MakeObjectFallClientRpc(NetworkObjectReference obj, Vector3 placementPosition, Quaternion placementRotation)
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: 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)
NetworkManager singleton = NetworkManager.Singleton;
if (singleton == null || !singleton.IsListening)
{
return;
}
FastBufferWriter val = default(FastBufferWriter);
((FastBufferWriter)(ref val))..ctor(256, (Allocator)2, -1);
((FastBufferWriter)(ref val)).WriteValueSafe<NetworkObjectReference>(ref obj, default(ForNetworkSerializable));
((FastBufferWriter)(ref val)).WriteValueSafe(ref placementPosition);
((FastBufferWriter)(ref val)).WriteValueSafe(ref placementRotation);
NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("MakeObjectFall", val, (NetworkDelivery)2);
NetworkObject val2 = default(NetworkObject);
if (((NetworkObjectReference)(ref obj)).TryGet(ref val2, (NetworkManager)null))
{
GrabbableObject obj2 = default(GrabbableObject);
if (((Component)val2).TryGetComponent<GrabbableObject>(ref obj2))
{
MakeObjectFall(obj2, placementPosition, placementRotation);
}
else
{
Log.LogError((object)"Failed to get grabbable object ref from network object - ClientRpc");
}
}
}
[ServerRpc]
public static void MakeObjectFallServerRpc(NetworkObjectReference obj, Vector3 placementPosition, Quaternion placementRotation)
{
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: 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_0070: Invalid comparison between Unknown and I4
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
NetworkManager singleton = NetworkManager.Singleton;
if ((Object)(object)singleton == (Object)null)
{
Log.LogError((object)"Network Manager == null");
return;
}
if (!singleton.IsListening)
{
Log.LogError((object)"Network Manager not listening");
return;
}
if (((NetworkBehaviour)Player).OwnerClientId != singleton.LocalClientId)
{
if ((int)singleton.LogLevel <= 1)
{
Log.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
}
return;
}
FastBufferWriter val = default(FastBufferWriter);
((FastBufferWriter)(ref val))..ctor(256, (Allocator)2, -1);
((FastBufferWriter)(ref val)).WriteValueSafe<NetworkObjectReference>(ref obj, default(ForNetworkSerializable));
((FastBufferWriter)(ref val)).WriteValueSafe(ref placementPosition);
((FastBufferWriter)(ref val)).WriteValueSafe(ref placementRotation);
NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("MakeObjectFall", val, (NetworkDelivery)2);
NetworkObject val2 = default(NetworkObject);
if (((NetworkObjectReference)(ref obj)).TryGet(ref val2, (NetworkManager)null))
{
GrabbableObject obj2 = default(GrabbableObject);
if (((Component)val2).TryGetComponent<GrabbableObject>(ref obj2))
{
MakeObjectFall(obj2, placementPosition, placementRotation);
}
else
{
Log.LogError((object)"Failed to get grabbable object ref from network object - ServerRpc");
}
}
}
public static void NetworkManagerInit()
{
//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_003f: Expected O, but got Unknown
Log.LogMessage((object)"Registering named message");
CustomMessagingManager customMessagingManager = NetworkManager.Singleton.CustomMessagingManager;
object obj = <>c.<>9__3_0;
if (obj == null)
{
HandleNamedMessageDelegate val = delegate(ulong senderClientId, FastBufferReader reader)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
if (senderClientId != Player.playerClientId)
{
NetworkObjectReference val2 = default(NetworkObjectReference);
((FastBufferReader)(ref reader)).ReadValueSafe<NetworkObjectReference>(ref val2, default(ForNetworkSerializable));
Vector3 placementPosition = default(Vector3);
((FastBufferReader)(ref reader)).ReadValueSafe(ref placementPosition);
Quaternion placementRotation = default(Quaternion);
((FastBufferReader)(ref reader)).ReadValueSafe(ref placementRotation);
NetworkObject val3 = default(NetworkObject);
if (((NetworkObjectReference)(ref val2)).TryGet(ref val3, (NetworkManager)null))
{
GrabbableObject component = ((Component)val3).GetComponent<GrabbableObject>();
MakeObjectFall(component, placementPosition, placementRotation);
}
}
};
<>c.<>9__3_0 = val;
obj = (object)val;
}
customMessagingManager.RegisterNamedMessageHandler("MakeObjectFall", (HandleNamedMessageDelegate)obj);
}
[ClientRpc]
public static void RunClientRpc(NetworkObjectReference obj, Vector3 placementPosition, Quaternion placementRotation)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
MakeObjectFallServerRpc(obj, placementPosition, placementRotation);
}
}
private static readonly ManualLogSource Log = Plugin.Log;
private static PlayerControllerB Player => StartOfRound.Instance?.localPlayerController;
}
}
internal sealed class <>z__ReadOnlyArray<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>
{
int ICollection.Count => _items.Length;
bool ICollection.IsSynchronized => false;
object ICollection.SyncRoot => this;
object IList.this[int index]
{
get
{
return _items[index];
}
set
{
throw new NotSupportedException();
}
}
bool IList.IsFixedSize => true;
bool IList.IsReadOnly => true;
int IReadOnlyCollection<T>.Count => _items.Length;
T IReadOnlyList<T>.this[int index] => _items[index];
int ICollection<T>.Count => _items.Length;
bool ICollection<T>.IsReadOnly => true;
T IList<T>.this[int index]
{
get
{
return _items[index];
}
set
{
throw new NotSupportedException();
}
}
public <>z__ReadOnlyArray(T[] items)
{
_items = items;
}
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable)_items).GetEnumerator();
}
void ICollection.CopyTo(Array array, int index)
{
((ICollection)_items).CopyTo(array, index);
}
int IList.Add(object value)
{
throw new NotSupportedException();
}
void IList.Clear()
{
throw new NotSupportedException();
}
bool IList.Contains(object value)
{
return ((IList)_items).Contains(value);
}
int IList.IndexOf(object value)
{
return ((IList)_items).IndexOf(value);
}
void IList.Insert(int index, object value)
{
throw new NotSupportedException();
}
void IList.Remove(object value)
{
throw new NotSupportedException();
}
void IList.RemoveAt(int index)
{
throw new NotSupportedException();
}
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
return ((IEnumerable<T>)_items).GetEnumerator();
}
void ICollection<T>.Add(T item)
{
throw new NotSupportedException();
}
void ICollection<T>.Clear()
{
throw new NotSupportedException();
}
bool ICollection<T>.Contains(T item)
{
return ((ICollection<T>)_items).Contains(item);
}
void ICollection<T>.CopyTo(T[] array, int arrayIndex)
{
((ICollection<T>)_items).CopyTo(array, arrayIndex);
}
bool ICollection<T>.Remove(T item)
{
throw new NotSupportedException();
}
int IList<T>.IndexOf(T item)
{
return ((IList<T>)_items).IndexOf(item);
}
void IList<T>.Insert(int index, T item)
{
throw new NotSupportedException();
}
void IList<T>.RemoveAt(int index)
{
throw new NotSupportedException();
}
}