using System;
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 BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using ItemSeller.Patches;
using Microsoft.CodeAnalysis;
using REPOLib.Modules;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ItemSeller")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ItemSeller")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f6d01380-ae72-46c1-999b-efd8e0c25027")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace ItemSeller
{
[BepInPlugin("OldBody.ItemSeller", "REPO ItemEquippable Seller", "1.0.0")]
public class ItemSeller : BaseUnityPlugin
{
private const string modGUID = "OldBody.ItemSeller";
private const string modName = "REPO ItemEquippable Seller";
private const string modVersion = "1.0.0";
private readonly Harmony harmony = new Harmony("OldBody.ItemSeller");
private static ItemSeller Instance;
private static HashSet<string> convertedItems = new HashSet<string>();
private void Awake()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
if ((Object)Instance == (Object)null)
{
Instance = this;
}
ConfigManager.Initialize(((BaseUnityPlugin)this).Config);
harmony.PatchAll(typeof(ItemSeller));
harmony.PatchAll(typeof(ShopManagerPatch));
harmony.PatchAll(typeof(PlayerControllerPatch));
harmony.PatchAll(typeof(PhysGrabCartPatch));
}
public static void AddConvertedItem(string itemName)
{
convertedItems.Add(itemName);
}
public static void RemoveConvertedItemsFromSave()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
if (convertedItems.Count == 0)
{
return;
}
try
{
ES3Settings val = new ES3Settings((EncryptionType)1, "Why would you want to cheat?... :o It's no fun. :') :'D");
string path = Path.Combine(Application.persistentDataPath, "saves");
if (!Directory.Exists(path))
{
return;
}
string[] array = (from f in Directory.GetFiles(path, "*.es3", SearchOption.AllDirectories)
where !Path.GetFileName(f).Contains("BACKUP")
orderby File.GetLastWriteTime(f) descending
select f).ToArray();
if (array.Length == 0)
{
return;
}
string path2 = array[0];
if (!File.Exists(path2))
{
return;
}
val.path = path2;
if (!ES3.KeyExists("dictionaryOfDictionaries", val))
{
return;
}
Dictionary<string, Dictionary<string, int>> dictionary = ES3.Load<Dictionary<string, Dictionary<string, int>>>("dictionaryOfDictionaries", val);
if (dictionary == null || !dictionary.TryGetValue("itemsPurchased", out var value) || !dictionary.TryGetValue("itemsPurchasedTotal", out var value2))
{
return;
}
foreach (string convertedItem in convertedItems)
{
string key = convertedItem.Replace("(Clone)", "").Trim();
if (value.ContainsKey(key) && value2.ContainsKey(key))
{
int num = value[key];
int num2 = value2[key];
value[key] = Math.Max(0, num - 1);
value2[key] = Math.Max(0, num2 - 1);
}
}
dictionary["itemsPurchased"] = value;
dictionary["itemsPurchasedTotal"] = value2;
ES3.Save<Dictionary<string, Dictionary<string, int>>>("dictionaryOfDictionaries", dictionary, val);
}
catch (Exception)
{
}
}
}
}
namespace ItemSeller.Patches
{
internal class ConfigManager
{
public static ConfigEntry<string> reviveKey;
public static void Initialize(ConfigFile cfg)
{
reviveKey = cfg.Bind<string>("Controls", "ReviveKey", "h", "The key used to trigger a pack item to sell.");
}
}
[HarmonyPatch(typeof(PhysGrabCart))]
internal class PhysGrabCartPatch
{
private static GameObject uiObject;
private static TextMeshProUGUI textMesh;
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void InitializeUI()
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Expected O, but got Unknown
//IL_00ce: 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_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)uiObject == (Object)null)
{
uiObject = new GameObject("ItemSellerUI");
Canvas val = uiObject.AddComponent<Canvas>();
val.renderMode = (RenderMode)0;
val.sortingOrder = 100;
CanvasScaler val2 = uiObject.AddComponent<CanvasScaler>();
val2.uiScaleMode = (ScaleMode)1;
val2.referenceResolution = new Vector2(1920f, 1080f);
GameObject val3 = new GameObject("Text");
val3.transform.SetParent(uiObject.transform, false);
textMesh = val3.AddComponent<TextMeshProUGUI>();
((TMP_Text)textMesh).fontSize = 24f;
((TMP_Text)textMesh).alignment = (TextAlignmentOptions)1028;
((Graphic)textMesh).color = new Color(1f, 1f, 0f, 1f);
RectTransform component = val3.GetComponent<RectTransform>();
component.anchorMin = new Vector2(1f, 0f);
component.anchorMax = new Vector2(1f, 0f);
component.pivot = new Vector2(1f, 0f);
component.anchoredPosition = new Vector2(-20f, 20f);
component.sizeDelta = new Vector2(400f, 50f);
Object.DontDestroyOnLoad((Object)(object)uiObject);
}
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void displayText()
{
if (!SemiFunc.RunIsShop() && PlayerControllerPatch.isGrab)
{
string value = ConfigManager.reviveKey.Value;
TextMeshProUGUI obj = textMesh;
if (obj != null)
{
((TMP_Text)obj).SetText($"Press [{value}] to pack the ItemEquippable for {PlayerControllerPatch.itemPrice} $$$", true);
}
}
else
{
TextMeshProUGUI obj2 = textMesh;
if (obj2 != null)
{
((TMP_Text)obj2).SetText("", true);
}
}
}
}
[HarmonyPatch(typeof(PlayerController))]
internal class PlayerControllerPatch
{
private class ItemCacheData
{
public int Price { get; set; }
public float BatteryLife { get; set; }
}
public static MonoBehaviour grabItem;
public static bool isGrab;
public static int itemPrice = 0;
public static float itemBatteryLife;
public static string itemName;
private static Dictionary<string, ItemCacheData> itemPriceCache = new Dictionary<string, ItemCacheData>();
private static readonly string[] supportedItemTypes = new string[14]
{
"drone", "Upgrade Player", "power crystal", "grenade", "melee", "health pack", "gun", "Valuable Tracker", "Extraction Tracker", "mine",
"cart small", "duck bucket", "cart cannon", "cart laser"
};
public static int GetItemPrice(string itemId, MonoBehaviour equippable)
{
ItemAttributes component = ((Component)equippable).GetComponent<ItemAttributes>();
if ((Object)(object)component == (Object)null)
{
return 0;
}
component.GetValue();
int value = component.value;
float num = 0.98f;
float num2 = -1f;
ItemBattery component2 = ((Component)equippable).GetComponent<ItemBattery>();
if ((Object)(object)component2 != (Object)null)
{
num2 = component2.batteryLife;
if (num2 > 0f)
{
num = num2 / 100f;
if (num > 0.98f)
{
num = 0.98f;
}
}
else
{
num = 0.1f;
}
}
if (itemPriceCache.TryGetValue(itemId, out ItemCacheData value2))
{
if (Mathf.Abs(value2.BatteryLife - num2) > 0.01f)
{
int num3 = (int)((float)value * num * 1000f);
if (num2 < value2.BatteryLife && num3 > value2.Price)
{
return value2.Price;
}
value2.Price = num3;
value2.BatteryLife = num2;
return num3;
}
return value2.Price;
}
int num4 = (int)((float)value * num * 1000f);
itemPriceCache[itemId] = new ItemCacheData
{
Price = num4,
BatteryLife = num2
};
return num4;
}
public static void ResetPriceCache()
{
itemPriceCache.Clear();
}
[HarmonyPatch("FixedUpdate")]
[HarmonyPostfix]
private static void PlayerGrabItemPatch(PlayerController __instance)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Expected O, but got Unknown
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Expected O, but got Unknown
if (SemiFunc.RunIsShop() || (Object)__instance == (Object)null)
{
return;
}
if (__instance.physGrabActive && (Object)__instance.physGrabObject != (Object)null)
{
MonoBehaviour component = __instance.physGrabObject.GetComponent<MonoBehaviour>();
if (!((Object)component != (Object)null))
{
return;
}
MonoBehaviour equippable = __instance.physGrabObject.GetComponent<MonoBehaviour>();
if (!((Object)(object)equippable != (Object)null) || !supportedItemTypes.Any((string type) => ((Object)equippable).name.StartsWith("Item " + type, StringComparison.OrdinalIgnoreCase)))
{
return;
}
if (((Object)equippable).name.StartsWith("Item health pack", StringComparison.OrdinalIgnoreCase))
{
ItemHealthPack component2 = ((Component)equippable).GetComponent<ItemHealthPack>();
if ((Object)(object)component2 != (Object)null && component2.used)
{
return;
}
}
grabItem = equippable;
itemName = ((Object)equippable).name;
if (((Object)equippable).name.StartsWith("Item Grenade Human", StringComparison.OrdinalIgnoreCase))
{
itemPrice = 1500;
}
else if (((Object)equippable).name.StartsWith("Item Grenade", StringComparison.OrdinalIgnoreCase) || ((Object)equippable).name.StartsWith("Item Mine", StringComparison.OrdinalIgnoreCase))
{
itemPrice = 2000;
}
else
{
itemPrice = GetItemPrice(itemName, equippable);
}
isGrab = true;
}
else
{
isGrab = false;
}
}
}
internal class ReviveManager : MonoBehaviour
{
private void Update()
{
//IL_0017: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: 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_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
InputControl val = ((InputControl)Keyboard.current)[ConfigManager.reviveKey.Value];
if (!((ButtonControl)val).wasPressedThisFrame)
{
return;
}
bool isGrab = PlayerControllerPatch.isGrab;
int itemPrice = PlayerControllerPatch.itemPrice;
if (!isGrab)
{
return;
}
if ((Object)(object)PlayerControllerPatch.grabItem != (Object)null)
{
if (((Object)PlayerControllerPatch.grabItem).name.StartsWith("Item health pack", StringComparison.OrdinalIgnoreCase))
{
ItemHealthPack component = ((Component)PlayerControllerPatch.grabItem).GetComponent<ItemHealthPack>();
if ((Object)(object)component != (Object)null && component.used)
{
return;
}
}
Object.Destroy((Object)(object)((Component)PlayerControllerPatch.grabItem).gameObject);
PlayerControllerPatch.grabItem = null;
}
ValuableObject val2 = default(ValuableObject);
if (Valuables.TryGetValuableThatContainsName("money", ref val2))
{
ItemSeller.AddConvertedItem(PlayerControllerPatch.itemName);
Vector3 val3 = ((Component)PlayerAvatar.instance).transform.position + new Vector3(0f, 1f, 0f) + ((Component)PlayerAvatar.instance).transform.forward * 1f;
val2.valuePreset.valueMax = itemPrice;
val2.valuePreset.valueMin = itemPrice;
Valuables.SpawnValuable(val2, val3, Quaternion.identity);
}
}
}
[HarmonyPatch(typeof(ShopManager))]
internal class ShopManagerPatch
{
[HarmonyPatch("Awake")]
[HarmonyPostfix]
private static void keyboardListener(ShopManager __instance)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Expected O, but got Unknown
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected O, but got Unknown
if (!((Object)__instance == (Object)null) && (Object)((Component)__instance).gameObject.GetComponent<ReviveManager>() == (Object)null)
{
((Component)__instance).gameObject.AddComponent<ReviveManager>();
}
}
[HarmonyPatch("Awake")]
[HarmonyPostfix]
private static void ResetCacheOnShopEnter(ShopManager __instance)
{
if (SemiFunc.RunIsShop())
{
PlayerControllerPatch.ResetPriceCache();
ItemSeller.RemoveConvertedItemsFromSave();
}
}
}
}