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 BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Pigeon.Movement;
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("KeepContraband")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("KeepContraband")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7240bf33-4d43-4910-8be2-2ec6e3e763f4")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace KeepContraband;
[BepInPlugin("wastak.mycopunk.keepcontraband", "Keep Contraband", "1.0.0")]
public sealed class Plugin : BaseUnityPlugin
{
public const string PluginGuid = "wastak.mycopunk.keepcontraband";
public const string PluginName = "Keep Contraband";
public const string PluginVersion = "1.0.0";
internal static ManualLogSource Log;
private Harmony _harmony;
private void Awake()
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Keep Contraband 1.0.0: starting patch setup.");
_harmony = new Harmony("wastak.mycopunk.keepcontraband");
try
{
_harmony.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Keep Contraband 1.0.0 loaded.");
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)"Keep Contraband: PatchAll failed.");
((BaseUnityPlugin)this).Logger.LogError((object)ex);
}
}
private void OnDestroy()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
}
internal static class ContrabandUtility
{
internal static bool IsPermanentContraband(UpgradeInstance instance)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Invalid comparison between Unknown and I4
return instance != null && (Object)(object)instance.Upgrade != (Object)null && (int)instance.Upgrade.Rarity == 5 && !instance.RemoveAfterMission && !instance.RemoveOnQuit;
}
internal static bool IsInsideOuroboros()
{
try
{
return ((MissionData)(ref MissionManager.CurrentMission)).Mission is OuroMission;
}
catch
{
return false;
}
}
}
internal static class ContrabandVisibility
{
internal sealed class UpgradeState
{
internal Upgrade Definition;
internal Rarity OriginalRarity;
internal UpgradeFlags OriginalFlags;
}
private static readonly FieldInfo RarityField = AccessTools.Field(typeof(Upgrade), "<Rarity>k__BackingField");
private static readonly FieldInfo FlagsField = AccessTools.Field(typeof(Upgrade), "<Flags>k__BackingField");
internal static UpgradeState TemporarilyAllow(UpgradeInstance instance)
{
//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_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: 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_0097: 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_009f: Unknown result type (might be due to invalid IL or missing references)
if (!ContrabandUtility.IsPermanentContraband(instance))
{
return null;
}
Upgrade upgrade = instance.Upgrade;
if (RarityField == null || FlagsField == null)
{
Plugin.Log.LogError((object)"[Inventory] Could not find Upgrade backing fields.");
return null;
}
UpgradeState upgradeState = new UpgradeState
{
Definition = upgrade,
OriginalRarity = upgrade.Rarity,
OriginalFlags = upgrade.Flags
};
RarityField.SetValue(upgrade, (object)(Rarity)4);
UpgradeFlags val = (UpgradeFlags)(upgradeState.OriginalFlags & -32769);
FlagsField.SetValue(upgrade, val);
return upgradeState;
}
internal static void Restore(UpgradeState state)
{
//IL_0036: 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)
if (state != null && !((Object)(object)state.Definition == (Object)null))
{
if (RarityField != null)
{
RarityField.SetValue(state.Definition, state.OriginalRarity);
}
if (FlagsField != null)
{
FlagsField.SetValue(state.Definition, state.OriginalFlags);
}
}
}
internal static List<UpgradeState> TemporarilyAllowAll(IUpgradable gear)
{
List<UpgradeState> list = new List<UpgradeState>();
if (gear == null)
{
return list;
}
List<UpgradeInfo> allUpgrades = PlayerData.GetAllUpgrades(gear, true);
if (allUpgrades == null)
{
return list;
}
HashSet<Upgrade> hashSet = new HashSet<Upgrade>();
foreach (UpgradeInfo item in allUpgrades)
{
if (item == null || item.Instances == null)
{
continue;
}
foreach (UpgradeInstance instance in item.Instances)
{
if (!ContrabandUtility.IsPermanentContraband(instance))
{
continue;
}
Upgrade upgrade = instance.Upgrade;
if (!hashSet.Contains(upgrade))
{
UpgradeState upgradeState = TemporarilyAllow(instance);
if (upgradeState != null)
{
hashSet.Add(upgrade);
list.Add(upgradeState);
}
}
}
}
return list;
}
internal static void RestoreAll(List<UpgradeState> states)
{
if (states != null)
{
for (int num = states.Count - 1; num >= 0; num--)
{
Restore(states[num]);
}
}
}
}
internal static class ContrabandInventoryRefresh
{
private static readonly MethodInfo SetupUpgradesMethod = AccessTools.Method(typeof(GearDetailsWindow), "SetupUpgrades", new Type[3]
{
typeof(IUpgradable),
typeof(bool),
typeof(bool)
}, (Type[])null);
private static bool _isRefreshing;
private static bool _loggedMissingMethod;
internal static void Refresh(GearDetailsWindow window)
{
if (_isRefreshing || (Object)(object)window == (Object)null || window.UpgradablePrefab == null)
{
return;
}
if (SetupUpgradesMethod == null)
{
if (!_loggedMissingMethod)
{
_loggedMissingMethod = true;
Plugin.Log.LogError((object)"[Refresh] Could not find GearDetailsWindow.SetupUpgrades.");
}
return;
}
_isRefreshing = true;
try
{
SetupUpgradesMethod.Invoke(window, new object[3] { window.UpgradablePrefab, window.InSkinMode, false });
window.OnUpgradesChanged();
Plugin.Log.LogInfo((object)"[Refresh] Inventory updated after Contraband equipment change.");
}
catch (TargetInvocationException ex)
{
Exception ex2 = ex.InnerException ?? ex;
Plugin.Log.LogError((object)"[Refresh] Failed to rebuild inventory.");
Plugin.Log.LogError((object)ex2);
}
catch (Exception ex3)
{
Plugin.Log.LogError((object)"[Refresh] Failed to rebuild inventory.");
Plugin.Log.LogError((object)ex3);
}
finally
{
_isRefreshing = false;
}
}
}
internal static class MultiversalThievery
{
private const int UpgradeNumberID = 185736;
internal static bool IsMultiversalThievery(UpgradeInstance instance)
{
if (instance == null || (Object)(object)instance.Upgrade == (Object)null)
{
return false;
}
Upgrade upgrade = instance.Upgrade;
return !upgrade.IsModded && upgrade.NumberID == 185736;
}
internal static int GetEquippedCount(IUpgradable gear)
{
if (gear == null)
{
return 0;
}
int num = 0;
EquippedUpgradeEnumerator val = default(EquippedUpgradeEnumerator);
((EquippedUpgradeEnumerator)(ref val))..ctor(gear, true);
while (((EquippedUpgradeEnumerator)(ref val)).MoveNext())
{
if (IsMultiversalThievery(((EquippedUpgradeEnumerator)(ref val)).Upgrade))
{
num++;
}
}
return num;
}
internal static IUpgradable GetEquippedGear(int index)
{
Player localPlayer = Player.LocalPlayer;
if ((Object)(object)localPlayer == (Object)null)
{
return null;
}
try
{
return (IUpgradable)(index switch
{
0 => ((IUpgradable)localPlayer.Gear[0]).Prefab,
1 => ((IUpgradable)localPlayer.Gear[1]).Prefab,
2 => ((IUpgradable)localPlayer.Gear[3]).Prefab,
_ => localPlayer.Character,
});
}
catch
{
return null;
}
}
internal static void ModifyGridWidth(GearData data, ref int width)
{
if (data == null || data.Gear == null || (Object)(object)Player.LocalPlayer == (Object)null || ContrabandUtility.IsInsideOuroboros())
{
return;
}
IUpgradable gear = data.Gear;
int equippedCount = GetEquippedCount(gear);
width += equippedCount * 3;
for (int i = 0; i < 4; i++)
{
IUpgradable equippedGear = GetEquippedGear(i);
if (equippedGear != null && equippedGear != gear)
{
width -= GetEquippedCount(equippedGear);
}
}
if (width < 0)
{
width = 0;
}
}
}
internal static class ContrabandWorldDrops
{
private sealed class Candidate
{
internal IUpgradable Gear;
internal Upgrade Upgrade;
}
private const float ExoticReplacementChance = 0.05f;
private const int CosmicMicrowaveNumberId = 849084;
private const int VariantGenerationAttempts = 32;
private static readonly List<Candidate> Candidates = new List<Candidate>();
private static readonly HashSet<IUpgradable> CheckedCandidateGear = new HashSet<IUpgradable>();
private static readonly HashSet<IUpgradable> CheckedInventoryGear = new HashSet<IUpgradable>();
private static readonly HashSet<int> BlockedContrabandNumberIds = new HashSet<int>();
private static readonly HashSet<string> OwnedVariantKeys = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
private static readonly FieldInfo SeedField = AccessTools.Field(typeof(UpgradeInstance), "<Seed>k__BackingField");
internal static UpgradeInstance TryReplaceExotic(UpgradeInstance originalInstance)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Invalid comparison between Unknown and I4
if (originalInstance == null || (Object)(object)originalInstance.Upgrade == (Object)null)
{
return originalInstance;
}
Upgrade upgrade = originalInstance.Upgrade;
if ((int)upgrade.Rarity != 3)
{
return originalInstance;
}
if (Random.value >= 0.05f)
{
return originalInstance;
}
UpgradeInstance val = CreateRandomContraband();
if (val == null)
{
return originalInstance;
}
return val;
}
private static UpgradeInstance CreateRandomContraband()
{
Candidates.Clear();
CheckedCandidateGear.Clear();
CheckedInventoryGear.Clear();
BlockedContrabandNumberIds.Clear();
OwnedVariantKeys.Clear();
Player localPlayer = Player.LocalPlayer;
if ((Object)(object)localPlayer == (Object)null)
{
Plugin.Log.LogWarning((object)"[World Drops] Local player is unavailable.");
return null;
}
try
{
IGear obj = localPlayer.Gear[0];
CollectPermanentContraband((obj != null) ? ((IUpgradable)obj).Prefab : null);
IGear obj2 = localPlayer.Gear[1];
CollectPermanentContraband((obj2 != null) ? ((IUpgradable)obj2).Prefab : null);
IGear obj3 = localPlayer.Gear[3];
CollectPermanentContraband((obj3 != null) ? ((IUpgradable)obj3).Prefab : null);
CollectPermanentContraband((IUpgradable)(object)localPlayer.Character);
CollectPermanentContraband((IUpgradable)(object)Global.Instance);
IGear obj4 = localPlayer.Gear[0];
AddCandidateGear((obj4 != null) ? ((IUpgradable)obj4).Prefab : null);
IGear obj5 = localPlayer.Gear[1];
AddCandidateGear((obj5 != null) ? ((IUpgradable)obj5).Prefab : null);
IGear obj6 = localPlayer.Gear[3];
AddCandidateGear((obj6 != null) ? ((IUpgradable)obj6).Prefab : null);
AddCandidateGear((IUpgradable)(object)localPlayer.Character);
AddCandidateGear((IUpgradable)(object)Global.Instance);
}
catch (Exception ex)
{
Plugin.Log.LogError((object)"[World Drops] Failed while scanning the player's Contraband inventory.");
Plugin.Log.LogError((object)ex);
return null;
}
while (Candidates.Count > 0)
{
int index = Random.Range(0, Candidates.Count);
Candidate candidate = Candidates[index];
UpgradeInstance val = CreateUniqueInstance(candidate);
if (val != null)
{
return val;
}
Candidates.RemoveAt(index);
}
return null;
}
private static UpgradeInstance CreateUniqueInstance(Candidate candidate)
{
if (candidate == null || candidate.Gear == null || (Object)(object)candidate.Upgrade == (Object)null)
{
return null;
}
if (!IsVariantContraband(candidate.Upgrade))
{
return PlayerData.CreateUpgradeInstance(candidate.Gear, candidate.Upgrade, true);
}
for (int i = 1; i <= 32; i++)
{
UpgradeInstance val = PlayerData.CreateUpgradeInstance(candidate.Gear, candidate.Upgrade, false);
if (val == null)
{
continue;
}
string element;
string uniquenessKey = GetUniquenessKey(val, out element);
if (string.IsNullOrEmpty(uniquenessKey))
{
Plugin.Log.LogWarning((object)"[World Drops] Could not calculate a variant key for Cosmic Microwave. The whole NumberID is treated as blocked.");
BlockedContrabandNumberIds.Add(candidate.Upgrade.NumberID);
return null;
}
if (OwnedVariantKeys.Contains(uniquenessKey))
{
Plugin.Log.LogInfo((object)("[World Drops] Generated duplicate Cosmic Microwave variant: Element=" + element + ", Key=" + uniquenessKey + ", " + $"Attempt={i}/" + $"{32}."));
continue;
}
UpgradeInstance val2 = PlayerData.CreateUpgradeInstance(candidate.Gear, candidate.Upgrade, true);
if (val2 == null)
{
return null;
}
if (!TryCopySeed(val, val2))
{
Plugin.Log.LogError((object)"[World Drops] Failed to preserve the preview Seed for Cosmic Microwave.");
return null;
}
string element2;
string uniquenessKey2 = GetUniquenessKey(val2, out element2);
if (string.IsNullOrEmpty(uniquenessKey2) || OwnedVariantKeys.Contains(uniquenessKey2))
{
Plugin.Log.LogError((object)"[World Drops] Cosmic Microwave variant changed or became duplicate after copying its Seed.");
return null;
}
return val2;
}
return null;
}
private static bool TryCopySeed(UpgradeInstance source, UpgradeInstance destination)
{
if (source == null || destination == null || SeedField == null)
{
return false;
}
try
{
SeedField.SetValue(destination, source.Seed);
return destination.Seed == source.Seed;
}
catch (Exception ex)
{
Plugin.Log.LogError((object)"[World Drops] Failed to copy UpgradeInstance Seed.");
Plugin.Log.LogError((object)ex);
return false;
}
}
private static void CollectPermanentContraband(IUpgradable gear)
{
if (gear == null || !CheckedInventoryGear.Add(gear))
{
return;
}
List<UpgradeInfo> allUpgrades = PlayerData.GetAllUpgrades(gear, true);
if (allUpgrades == null)
{
return;
}
foreach (UpgradeInfo item in allUpgrades)
{
if (item == null || item.Instances == null)
{
continue;
}
foreach (UpgradeInstance instance in item.Instances)
{
if (!ContrabandUtility.IsPermanentContraband(instance))
{
continue;
}
Upgrade upgrade = instance.Upgrade;
if ((Object)(object)upgrade == (Object)null)
{
continue;
}
if (!IsVariantContraband(upgrade))
{
BlockedContrabandNumberIds.Add(upgrade.NumberID);
continue;
}
string element;
string uniquenessKey = GetUniquenessKey(instance, out element);
if (string.IsNullOrEmpty(uniquenessKey))
{
BlockedContrabandNumberIds.Add(upgrade.NumberID);
Plugin.Log.LogWarning((object)("[World Drops] Existing Cosmic Microwave element could not be determined. NumberID " + $"{upgrade.NumberID} was blocked."));
}
else if (OwnedVariantKeys.Add(uniquenessKey))
{
Plugin.Log.LogInfo((object)("[World Drops] Owned Cosmic Microwave variant: Element=" + element + ", Key=" + uniquenessKey + ", " + $"Instance={instance.InstanceID}."));
}
}
}
}
private static void AddCandidateGear(IUpgradable gear)
{
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Invalid comparison between Unknown and I4
//IL_00b2: 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)
if (gear == null || !CheckedCandidateGear.Add(gear) || (Object)(object)gear.Info == (Object)null || gear.Info.Upgrades == null)
{
return;
}
for (int i = 0; i < gear.Info.Upgrades.Count; i++)
{
Upgrade val = gear.Info.Upgrades[i];
if (!((Object)(object)val == (Object)null) && (int)val.Rarity == 5 && !val.IsSkin())
{
UpgradeInfo upgradeInfo = PlayerData.GetUpgradeInfo(gear, val);
if (upgradeInfo != null && upgradeInfo.IsUnlockable && !BlockedContrabandNumberIds.Contains(val.NumberID) && ((val.Flags & 0x40) == 0 || GameManager.players.Count > 1))
{
Candidates.Add(new Candidate
{
Gear = gear,
Upgrade = val
});
}
}
}
}
private static bool IsVariantContraband(Upgrade upgrade)
{
//IL_0047: 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)
if ((Object)(object)upgrade == (Object)null)
{
return false;
}
if (upgrade.NumberID == 849084)
{
return true;
}
if (string.Equals(upgrade.APIName, "Elementalist", StringComparison.OrdinalIgnoreCase))
{
return true;
}
try
{
Enumerator properties = upgrade.GetProperties();
while (((Enumerator)(ref properties)).MoveNext())
{
object current = ((Enumerator)(ref properties)).Current;
if (current != null && string.Equals(current.GetType().Name, "UpgradeProperty_Player_Elementalist", StringComparison.Ordinal))
{
return true;
}
}
}
catch
{
}
return false;
}
private static string GetUniquenessKey(UpgradeInstance instance, out string element)
{
element = null;
if (instance == null || (Object)(object)instance.Upgrade == (Object)null)
{
return null;
}
Upgrade upgrade = instance.Upgrade;
if (!IsVariantContraband(upgrade))
{
return upgrade.NumberID.ToString();
}
element = TryGetElement(instance);
if (string.IsNullOrWhiteSpace(element))
{
return null;
}
return upgrade.NumberID + "|" + element.Trim();
}
private static string TryGetElement(UpgradeInstance instance)
{
try
{
string statList = instance.Upgrade.GetStatList(instance.Seed, instance);
if (string.IsNullOrWhiteSpace(statList))
{
return null;
}
string text = RemoveRichTextTags(statList);
string[] array = text.Split(new char[2] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
string[] array2 = array;
foreach (string text2 in array2)
{
string text3 = text2.Trim();
int num = text3.IndexOf(':');
if (num >= 0 && num < text3.Length - 1)
{
string text4 = text3.Substring(num + 1).Trim();
if (!string.IsNullOrEmpty(text4) && !char.IsDigit(text4[0]) && text4[0] != '+' && text4[0] != '-')
{
return text4;
}
}
}
}
catch (Exception ex)
{
Plugin.Log.LogError((object)"[World Drops] Failed to calculate Cosmic Microwave element.");
Plugin.Log.LogError((object)ex);
}
return null;
}
private static string RemoveRichTextTags(string text)
{
if (string.IsNullOrEmpty(text))
{
return text;
}
char[] array = new char[text.Length];
int num = 0;
bool flag = false;
foreach (char c in text)
{
if (c == '<')
{
flag = true;
}
else if (c == '>' && flag)
{
flag = false;
}
else if (!flag)
{
array[num] = c;
num++;
}
}
return new string(array, 0, num);
}
}
[HarmonyPatch]
internal static class ExoticWorldDropReplacementPatch
{
private static MethodBase TargetMethod()
{
return AccessTools.Method(typeof(PlayerData), "RentRandomUpgrade", new Type[1] { typeof(UpgradeFilterParams) }, (Type[])null);
}
private static void Postfix(ref UpgradeInstance __result)
{
if (!ContrabandUtility.IsInsideOuroboros())
{
__result = ContrabandWorldDrops.TryReplaceExotic(__result);
}
}
}
[HarmonyPatch]
internal static class IsValidUpgradePatch
{
private static MethodBase TargetMethod()
{
return AccessTools.Method(typeof(OuroBuyWindow), "IsValidUpgrade", new Type[3]
{
typeof(IUpgradable),
typeof(UpgradeInstance),
typeof(bool).MakeByRefType()
}, (Type[])null);
}
private static void Postfix(UpgradeInstance upgrade, ref bool excludeFromPool, ref bool __result)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Invalid comparison between Unknown and I4
if (upgrade != null)
{
Upgrade upgrade2 = upgrade.Upgrade;
if (!((Object)(object)upgrade2 == (Object)null) && (int)upgrade2.Rarity == 5 && upgrade.RemoveAfterMission && upgrade.HasBeenSeen && upgrade.CanCleanse)
{
excludeFromPool = false;
__result = true;
}
}
}
}
[HarmonyPatch]
internal static class GearDetailsWindowAddUpgradePatch
{
private static MethodBase TargetMethod()
{
return AccessTools.Method(typeof(GearDetailsWindow), "AddUpgrade", new Type[2]
{
typeof(UpgradeInstance),
typeof(int).MakeByRefType()
}, (Type[])null);
}
private static void Prefix(UpgradeInstance upgrade, out ContrabandVisibility.UpgradeState __state)
{
__state = ContrabandVisibility.TemporarilyAllow(upgrade);
}
private static void Postfix(ContrabandVisibility.UpgradeState __state)
{
ContrabandVisibility.Restore(__state);
}
private static Exception Finalizer(Exception __exception, ContrabandVisibility.UpgradeState __state)
{
ContrabandVisibility.Restore(__state);
return __exception;
}
}
[HarmonyPatch]
internal static class UpgradeSelectPopupSetupPatch
{
private static MethodBase TargetMethod()
{
return AccessTools.Method(typeof(UpgradeSelectPopup), "SetupUpgrades", new Type[1] { typeof(IUpgradable) }, (Type[])null);
}
private static void Prefix(IUpgradable gear, out List<ContrabandVisibility.UpgradeState> __state)
{
__state = ContrabandVisibility.TemporarilyAllowAll(gear);
}
private static void Postfix(List<ContrabandVisibility.UpgradeState> __state)
{
ContrabandVisibility.RestoreAll(__state);
}
private static Exception Finalizer(Exception __exception, List<ContrabandVisibility.UpgradeState> __state)
{
ContrabandVisibility.RestoreAll(__state);
return __exception;
}
}
[HarmonyPatch]
internal static class GearDataModifyGridSizePatch
{
private static MethodBase TargetMethod()
{
return AccessTools.Method(typeof(GearData), "ModifyGridSize", new Type[3]
{
typeof(int),
typeof(int).MakeByRefType(),
typeof(int).MakeByRefType()
}, (Type[])null);
}
private static void Postfix(GearData __instance, ref int width)
{
MultiversalThievery.ModifyGridWidth(__instance, ref width);
}
}
[HarmonyPatch]
internal static class GearDetailsWindowEquipRefreshPatch
{
private static MethodBase TargetMethod()
{
return AccessTools.Method(typeof(GearDetailsWindow), "EquipUpgrade", new Type[3]
{
typeof(UpgradeEquipCell),
typeof(UpgradeInstance),
typeof(byte)
}, (Type[])null);
}
private static void Postfix(GearDetailsWindow __instance, UpgradeInstance upgrade, bool __result)
{
if (__result && ContrabandUtility.IsPermanentContraband(upgrade))
{
ContrabandInventoryRefresh.Refresh(__instance);
}
}
}
[HarmonyPatch]
internal static class GearDetailsWindowUnequipRefreshPatch
{
private static MethodBase TargetMethod()
{
return AccessTools.Method(typeof(GearDetailsWindow), "UnequipUpgrade", new Type[1] { typeof(UpgradeInstance) }, (Type[])null);
}
private static void Prefix(GearDetailsWindow __instance, UpgradeInstance upgrade, out bool __state)
{
__state = (Object)(object)__instance != (Object)null && __instance.UpgradablePrefab != null && ContrabandUtility.IsPermanentContraband(upgrade) && upgrade.IsEquipped(__instance.UpgradablePrefab);
}
private static void Postfix(GearDetailsWindow __instance, bool __state)
{
if (__state)
{
ContrabandInventoryRefresh.Refresh(__instance);
}
}
}
[HarmonyPatch(typeof(PlayerData), "OnUpgradeCollected")]
internal static class ContrabandCollectedPatch
{
private static void Postfix(UpgradeInstance instance)
{
if (ContrabandUtility.IsPermanentContraband(instance))
{
Plugin.Log.LogInfo((object)("[Contraband Collected] " + $"Instance={instance.InstanceID}, " + $"NumberID={instance.Upgrade.NumberID}, " + "Upgrade=" + ((Object)instance.Upgrade).name + ", RemoveAfterMission=" + $"{instance.RemoveAfterMission}, " + $"RemoveOnQuit={instance.RemoveOnQuit}"));
}
}
}
internal static class ContrabandDescriptionCleaner
{
internal const int FakeIdBiologicalsOnlyNumberId = 310014;
internal const int InterimManagerNumberId = 816438;
private const string FakeIdObsoleteDescription = "Collecting this upgrade rerolls all existing upgrades but doesn't change their patterns.";
private const string InterimManagerObsoleteDescription = "Collecting this upgrade randomizes your employee and rerolls all existing employee upgrades, but doesn't change their patterns.";
internal static string Clean(Upgrade upgrade, string description)
{
if ((Object)(object)upgrade == (Object)null || string.IsNullOrEmpty(description) || ContrabandUtility.IsInsideOuroboros())
{
return description;
}
string oldValue;
switch (upgrade.NumberID)
{
case 310014:
oldValue = "Collecting this upgrade rerolls all existing upgrades but doesn't change their patterns.";
break;
case 816438:
oldValue = "Collecting this upgrade randomizes your employee and rerolls all existing employee upgrades, but doesn't change their patterns.";
break;
default:
return description;
}
string text = description.Replace(oldValue, string.Empty);
while (text.Contains("\n\n\n"))
{
text = text.Replace("\n\n\n", "\n\n");
}
return text.Trim();
}
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
internal static class UpgradeDescriptionPatch
{
private static void Postfix(Upgrade __instance, ref string __result)
{
__result = ContrabandDescriptionCleaner.Clean(__instance, __result);
}
}