using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Pigeon.Movement;
using Steamworks;
using Steamworks.Data;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("fuck")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("fuck")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("1E1FC42D-9EB7-40D8-AC17-4EF63F280E96")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = "")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace fuck;
[MycoMod(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.fuck.upgradetrademod", "Upgrade Trade", "1.0.0")]
public class TradeMod : BaseUnityPlugin
{
public class InputHandler : MonoBehaviour
{
private InputActionMap actionMap;
private InputAction f1Action;
private void Awake()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
actionMap = new InputActionMap("testMod");
f1Action = InputActionSetupExtensions.AddAction(actionMap, "grantUpgrade", (InputActionType)0, (string)null, (string)null, (string)null, (string)null, (string)null);
InputActionSetupExtensions.AddBinding(f1Action, "<Keyboard>/F1", (string)null, (string)null, (string)null);
f1Action.performed += delegate
{
TradeHandler.ActivateTradeAttempt();
};
actionMap.Enable();
}
}
public static ManualLogSource Log;
private static GameObject listenerObject;
private static Harmony harmony;
public static GearUpgradeUI LastSelectedUpgradeUI;
public static bool awaitingConfirmation;
public static bool awaitingTarget;
public static bool pauseUpdates;
public static string[] claimed;
public static UpgradeInstance selection;
public static Lobby LastCreatedLobby;
public static int targetPlayerIndex;
public static ulong targetSteamId;
private void Awake()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
listenerObject = new GameObject("ModInputListener");
listenerObject.AddComponent<InputHandler>();
Object.DontDestroyOnLoad((Object)(object)listenerObject);
harmony = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
harmony.PatchAll(typeof(GearDetailsWindowPatch));
harmony.PatchAll(typeof(ChatMessagePatch));
harmony.PatchAll(typeof(LobbyConstructorPatch));
}
private void OnDisable()
{
if ((Object)(object)listenerObject != (Object)null)
{
Object.Destroy((Object)(object)listenerObject);
}
}
}
public static class TradeHandler
{
public static void ActivateTradeAttempt()
{
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: 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)
TradeMod.Log.LogInfo((object)"Trade keybind pressed, running setup.");
if ((Object)(object)TradeMod.LastSelectedUpgradeUI != (Object)null && !TradeMod.pauseUpdates)
{
UpgradeInstance upgrade = ((HoverInfoUpgrade)TradeMod.LastSelectedUpgradeUI).Upgrade;
TradeMod.selection = upgrade;
TradeMod.awaitingConfirmation = true;
StringBuilder stringBuilder = new StringBuilder();
int num = 1;
foreach (Friend member in ((Lobby)(ref TradeMod.LastCreatedLobby)).Members)
{
Friend current = member;
stringBuilder.Append($"\n{num}: {((Friend)(ref current)).Name}");
num++;
}
PlayerLook.Instance.AddTextChatMessage(" ", GameManager.GetPlayer(Online.GetPlayerID()));
PlayerLook.Instance.AddTextChatMessage("Trading upgrade: <color=#" + ColorUtility.ToHtmlStringRGB(TradeMod.selection.Upgrade.Color) + "> " + TradeMod.selection.Upgrade.APIName, GameManager.GetPlayer(Online.GetPlayerID()));
PlayerLook.Instance.AddTextChatMessage(stringBuilder.ToString().Replace("\r", ""), GameManager.GetPlayer(Online.GetPlayerID()));
PlayerLook.Instance.AddTextChatMessage("To confirm the trade, type: '/trade (id)', where (id) is the number before their username above", GameManager.GetPlayer(Online.GetPlayerID()));
TradeMod.awaitingTarget = true;
TradeMod.pauseUpdates = true;
TradeMod.Log.LogInfo((object)"Trade now in progress");
}
else if ((Object)(object)TradeMod.LastSelectedUpgradeUI == (Object)null)
{
TradeMod.pauseUpdates = false;
TradeMod.awaitingTarget = false;
TradeMod.awaitingConfirmation = false;
TradeMod.LastSelectedUpgradeUI = null;
TradeMod.selection = null;
PlayerLook.Instance.AddTextChatMessage("No upgrade was held at the time the keybind was pressed.", GameManager.GetPlayer(Online.GetPlayerID()));
TradeMod.Log.LogWarning((object)"No upgrade was detected, likely that the upgrade wasn't in the right state (being held) at the time the keybind was pressed, dont forget /fix is a thing if it is truly broken");
}
else
{
TradeMod.pauseUpdates = false;
TradeMod.awaitingTarget = false;
TradeMod.awaitingConfirmation = false;
TradeMod.LastSelectedUpgradeUI = null;
TradeMod.selection = null;
PlayerLook.Instance.AddTextChatMessage("Trade Cancelled", GameManager.GetPlayer(Online.GetPlayerID()));
TradeMod.Log.LogWarning((object)"Trade keybind pressed mid trade, cancelling it");
}
}
}
public static class LobbyConstructorPatch
{
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyPatch(new Type[] { typeof(SteamId) })]
[HarmonyPostfix]
private static void Postfix(ref Lobby __instance)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
if (((Lobby)(ref __instance)).Id.Value != 0)
{
TradeMod.LastCreatedLobby = __instance;
}
}
}
public static class GearDetailsWindowPatch
{
[HarmonyPatch(typeof(GearDetailsWindow))]
private static class SetterPatch
{
[HarmonyTargetMethod]
public static MethodBase TargetMethod()
{
return AccessTools.PropertySetter(typeof(GearDetailsWindow), "SelectedUpgrade");
}
[HarmonyPrefix]
private static void SetSelectedUpgradePrefix(GearUpgradeUI value)
{
if ((Object)(object)value != (Object)null)
{
TradeMod.LastSelectedUpgradeUI = value;
}
}
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyPostfix]
private static void GetSelectedUpgradePostfix(GearUpgradeUI __result)
{
if ((Object)(object)__result != (Object)null)
{
TradeMod.LastSelectedUpgradeUI = __result;
}
}
}
public static class ChatMessagePatch
{
public struct TradeData
{
public string GearName;
public string UpgradeName;
public int Seed;
public ulong targetSteamId;
public long UnixTimestamp;
}
private const string Separator = "|";
public static string GetTradeDataString(string GearAPIName, string UpgradeAPIName, string seed, ulong TargetSteamId)
{
return $"</color>{GearAPIName}|{UpgradeAPIName}|{seed}|{TargetSteamId}";
}
public static bool IsTradeDataValid(string tradeMessage)
{
return !tradeMessage.StartsWith("</color><");
}
public static TradeData GetTradeDataFromString(string tradeMessage)
{
TradeData result = default(TradeData);
tradeMessage = tradeMessage.Replace("</color>", "");
string[] array = tradeMessage.Split(new char[1] { '|' });
result.GearName = array[0];
result.UpgradeName = array[1];
result.Seed = int.Parse(array[2]);
result.targetSteamId = ulong.Parse(array[3]);
return result;
}
public static string GetConfirmNumber(ulong steamID)
{
string text = steamID.ToString("x");
return (text.Length >= 6) ? text.Substring(text.Length - 6) : text.PadLeft(6, '0');
}
[HarmonyPatch(typeof(PlayerLook), "AddTextChatMessage")]
[HarmonyPrefix]
private static bool Prefix(string message)
{
//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_0163: Expected O, but got Unknown
//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_0206: Unknown result type (might be due to invalid IL or missing references)
//IL_0401: Unknown result type (might be due to invalid IL or missing references)
//IL_0403: Unknown result type (might be due to invalid IL or missing references)
//IL_049e: Unknown result type (might be due to invalid IL or missing references)
//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
//IL_05a5: Unknown result type (might be due to invalid IL or missing references)
//IL_05aa: Unknown result type (might be due to invalid IL or missing references)
//IL_0640: Unknown result type (might be due to invalid IL or missing references)
if (message.StartsWith("</color>") && IsTradeDataValid(message))
{
TradeData tradeDataFromString = GetTradeDataFromString(message);
if (tradeDataFromString.targetSteamId != Online.GetPlayerID())
{
TradeMod.Log.LogInfo((object)"Observed trade in chat, you were not marked as the target");
return false;
}
int num = 0;
IUpgradable val = null;
foreach (KeyValuePair<int, GearData> item in PlayerData.Instance.collectedGear)
{
if (item.Value.IsUnlocked && item.Value.Gear.Info.APIName == tradeDataFromString.GearName)
{
num = item.Key;
val = item.Value.Gear;
}
}
if (num == 0 || val == null)
{
TradeMod.Log.LogWarning((object)("You do not own the required gear " + tradeDataFromString.GearName));
return false;
}
GearInfo info = val.Info;
foreach (Upgrade upgrade in info.Upgrades)
{
if (upgrade.APIName == tradeDataFromString.UpgradeName)
{
UpgradeInstance val2 = new UpgradeInstance(upgrade, val);
val2.Seed = tradeDataFromString.Seed;
PlayerData.CollectInstance(val2, (UnlockFlags)0);
val2.Unlock(false);
}
}
TradeMod.Log.LogInfo((object)"successfully traded mod");
string text = "</color><color=#" + GetConfirmNumber(Online.GetPlayerID()) + ">";
PlayerLook.Instance.AddTextChatMessage(text, GameManager.GetPlayer(Online.GetPlayerID()));
FixedString512Bytes val3 = default(FixedString512Bytes);
((FixedString512Bytes)(ref val3))..ctor(text);
GameManager.Instance.SendTextChatMessage512_Rpc(val3, ((NetworkBehaviour)Player.LocalPlayer).OwnerClientId);
GameManager.Instance.SendTextChatMessage512_Rpc(val3, Online.GetPlayerID());
return true;
}
if (message.StartsWith("</color><color=") && TradeMod.pauseUpdates && message.Contains("</color><color=#" + GetConfirmNumber(TradeMod.targetSteamId) + ">"))
{
TradeMod.Log.LogInfo((object)"received confirmation that a traded upgrade was obtained, cleaning up existing copy");
TradeMod.selection.Unequip(TradeMod.selection.Gear);
TradeMod.selection.Destroy();
TradeMod.selection = null;
TradeMod.LastSelectedUpgradeUI = null;
TradeMod.awaitingConfirmation = false;
TradeMod.awaitingTarget = false;
TradeMod.targetSteamId = 0uL;
TradeMod.pauseUpdates = false;
}
if (TradeMod.pauseUpdates && message.StartsWith("/fix"))
{
TradeMod.pauseUpdates = false;
TradeMod.awaitingTarget = false;
TradeMod.awaitingConfirmation = false;
TradeMod.LastSelectedUpgradeUI = null;
TradeMod.selection = null;
PlayerLook.Instance.AddTextChatMessage(" ", GameManager.GetPlayer(Online.GetPlayerID()));
PlayerLook.Instance.AddTextChatMessage("Unstuck trades", GameManager.GetPlayer(Online.GetPlayerID()));
TradeMod.Log.LogWarning((object)"Cancelled any trades in progress");
return false;
}
if (TradeMod.awaitingConfirmation && !TradeMod.awaitingTarget)
{
if (message == "yes")
{
if (TradeMod.selection == null)
{
TradeMod.Log.LogError((object)"UpgradeInstance selection is null, this should NEVER happen");
}
UpgradeInstance selection = TradeMod.selection;
if (selection != null)
{
TradeMod.awaitingTarget = false;
PlayerLook.Instance.AddTextChatMessage("Trade Confirmed", GameManager.GetPlayer(Online.GetPlayerID()));
int targetPlayerIndex = TradeMod.targetPlayerIndex;
ulong targetSteamId = 0uL;
int num2 = 1;
foreach (Friend member in ((Lobby)(ref TradeMod.LastCreatedLobby)).Members)
{
if (num2 == targetPlayerIndex)
{
targetSteamId = SteamId.op_Implicit(member.Id);
}
num2++;
}
TradeMod.targetSteamId = targetSteamId;
string tradeDataString = GetTradeDataString(selection.Gear.Info.APIName, selection.Upgrade.APIName, selection.Seed.ToString(), targetSteamId);
TradeMod.Log.LogInfo((object)tradeDataString);
PlayerLook.Instance.AddTextChatMessage(tradeDataString, GameManager.GetPlayer(Online.GetPlayerID()));
FixedString512Bytes val4 = default(FixedString512Bytes);
((FixedString512Bytes)(ref val4))..ctor(tradeDataString);
GameManager.Instance.SendTextChatMessage512_Rpc(val4, ((NetworkBehaviour)Player.LocalPlayer).OwnerClientId);
GameManager.Instance.SendTextChatMessage512_Rpc(val4, Online.GetPlayerID());
return false;
}
TradeMod.pauseUpdates = true;
}
TradeMod.awaitingConfirmation = false;
return false;
}
if (TradeMod.awaitingTarget)
{
if (string.IsNullOrEmpty(message) || !message.StartsWith("/trade "))
{
TradeMod.pauseUpdates = false;
TradeMod.awaitingTarget = false;
TradeMod.awaitingConfirmation = false;
PlayerLook.Instance.AddTextChatMessage("Trade Cancelled", GameManager.GetPlayer(Online.GetPlayerID()));
TradeMod.Log.LogInfo((object)"Aborting trade, user may not be interested in continuing trade.");
return true;
}
string s = message.Substring("/trade ".Length).Trim();
if (int.TryParse(s, out var result))
{
TradeMod.targetPlayerIndex = result;
TradeMod.awaitingTarget = false;
string text2 = null;
int num3 = 1;
foreach (Friend member2 in ((Lobby)(ref TradeMod.LastCreatedLobby)).Members)
{
Friend current4 = member2;
if (num3 == result)
{
text2 = ((Friend)(ref current4)).Name;
}
num3++;
}
if (text2 == null)
{
PlayerLook.Instance.AddTextChatMessage("Target player wasn't found, sorry.", GameManager.GetPlayer(Online.GetPlayerID()));
TradeMod.Log.LogWarning((object)"Aborting trade, no target user found");
return false;
}
PlayerLook.Instance.AddTextChatMessage("Type 'yes' to confirm trading <color=#" + ColorUtility.ToHtmlStringRGB(TradeMod.selection.Upgrade.Color) + "> " + TradeMod.selection.Upgrade.APIName + " </color> to " + text2, GameManager.GetPlayer(Online.GetPlayerID()));
TradeMod.Log.LogInfo((object)"Awaiting Confirmation to proceed with trade");
TradeMod.awaitingConfirmation = true;
return false;
}
if (message.StartsWith("/trade "))
{
PlayerLook.Instance.AddTextChatMessage("Target player wasn't found, sorry.", GameManager.GetPlayer(Online.GetPlayerID()));
}
TradeMod.Log.LogWarning((object)"Aborting trade, no target user found");
return false;
}
return true;
}
}