using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
using REPOLib.Modules;
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("REPO_ItemCloset")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("微软中国")]
[assembly: AssemblyProduct("REPO_ItemCloset")]
[assembly: AssemblyCopyright("Copyright © 微软中国 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("aaf399cc-df2b-4e1b-ab2e-4bc61964471a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace REPO_ItemCloset;
[BepInPlugin("com.XiaohaoMod.REPO.MaxItemAmout", "REPO.MaxItemAmout", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
public class ItemConfigManager
{
public static readonly Dictionary<string, string> ChineseNameMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
{ "Item Cart Medium", "中型运输车" },
{ "Item Cart Small", "便携式运输车" },
{ "Item Drone Battery", "充电无人机" },
{ "Item Drone Feather", "羽翼无人机" },
{ "Item Drone Indestructible", "无敌无人机" },
{ "Item Drone Torque", "扭矩无人机" },
{ "Item Drone Zero Gravity", "零重力无人机" },
{ "Item Drone Heal", "医疗无人机" },
{ "Item Extraction Tracker", "撤离点定位器" },
{ "Item Valuable Tracker", "贵重品探测器" },
{ "Item Grenade Duct Taped", "胶带加固手雷" },
{ "Item Grenade Explosive", "高爆手雷" },
{ "Item Grenade Human", "人肉炸弹" },
{ "Item Grenade Shockwave", "冲击波手雷" },
{ "Item Grenade Stun", "眩晕手雷" },
{ "Item Gun Handgun", "标准手枪" },
{ "Item Gun Shotgun", "霰弹枪" },
{ "Item Gun Tranq", "麻醉手枪" },
{ "Item Health Pack Large", "大型医疗包" },
{ "Item Health Pack Medium", "中型医疗包" },
{ "Item Health Pack Small", "小型医疗包" },
{ "Item Melee Baseball Bat", "球棒" },
{ "Item Melee Frying Pan", "平底锅" },
{ "Item Melee Inflatable Hammer", "充气锤" },
{ "Item Melee Sledge Hammer", "工程大锤" },
{ "Item Melee Sword", "战术短剑" },
{ "Item Mine Explosive", "爆炸地雷" },
{ "Item Mine Shockwave", "冲击地雷" },
{ "Item Mine Stun", "眩晕地雷" },
{ "Item Orb Zero Gravity", "无重力球" },
{ "Item Power Crystal", "能量水晶" },
{ "Item Rubber Duck", "橡皮鸭" },
{ "Item Upgrade Map Player Count", "地图升级" },
{ "Item Upgrade Player Energy", "耐力升级" },
{ "Item Upgrade Player Extra Jump", "多段跳升级" },
{ "Item Upgrade Player Grab Range", "抓取范围升级" },
{ "Item Upgrade Player Grab Strength", "力量升级" },
{ "Item Upgrade Player Health", "最大生命值升级" },
{ "Item Upgrade Player Sprint Speed", "冲刺速度升级" },
{ "Item Upgrade Player Tumble Launch", "翻滚升级" }
};
public static Dictionary<string, ConfigEntry<int>> itemMaxAmountConfigs = new Dictionary<string, ConfigEntry<int>>();
public static bool LoadConfig = false;
private const string CONFIG_CATEGORY = "Item Settings";
private static readonly char[] InvalidChars = new char[7] { ' ', '\t', '\n', '[', ']', '\\', '/' };
public static void InitializeItemConfigs()
{
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Expected O, but got Unknown
itemMaxAmountConfigs.Clear();
if (StatsManager.instance?.itemDictionary == null)
{
logger.LogError((object)"物品字典未初始化!");
return;
}
foreach (KeyValuePair<string, Item> item in StatsManager.instance.itemDictionary)
{
string key = item.Key;
Item value = item.Value;
if ((Object)(object)value == (Object)null || string.IsNullOrEmpty(key))
{
logger.LogWarning((object)("发现无效物品条目: " + key));
continue;
}
string value2;
string text = (ChineseNameMap.TryGetValue(key, out value2) ? value2 : value.itemName);
ConfigDescription val = new ConfigDescription(text + " 最大数量 ", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 150), Array.Empty<object>());
ConfigEntry<int> val2 = ((BaseUnityPlugin)instance).Config.Bind<int>("Item Settings", SanitizeConfigKey(value.itemName), value.maxAmount, val);
itemMaxAmountConfigs[key] = val2;
value.maxAmount = val2.Value;
}
logger.LogInfo((object)$"已为 {itemMaxAmountConfigs.Count} 个物品生成配置");
LoadConfig = true;
}
public static void UpdateConfigs()
{
foreach (KeyValuePair<string, Item> item in StatsManager.instance.itemDictionary)
{
if (!itemMaxAmountConfigs.ContainsKey(item.Key))
{
InitializeItemConfigs();
break;
}
}
}
public static string SanitizeConfigKey(string input)
{
string text = input.Trim();
text = text.Replace(' ', '_');
char[] invalidChars = InvalidChars;
foreach (char c in invalidChars)
{
text = text.Replace(c.ToString(), "");
}
return text;
}
}
public const string version = "1.0.1";
public static Plugin instance;
public static ManualLogSource logger;
public static GameObject ClosetPrefab;
private void Awake()
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Expected O, but got Unknown
logger = ((BaseUnityPlugin)this).Logger;
instance = this;
logger.LogInfo((object)"MaxItemAmout 1.0.1 is loaded!");
new Harmony("XiaohaiMod.REPO.MaxItemAmout").PatchAll();
LoadAB();
((BaseUnityPlugin)this).Config.Bind<float>("申明", "本MOD由傀鹏&&小海开发,仅供学习交流使用,禁止用于商业用途,版本号:1.0.1", 1f, new ConfigDescription("Its just Mod info", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), Array.Empty<object>()));
}
private void LoadAB()
{
string location = Assembly.GetExecutingAssembly().Location;
string directoryName = Path.GetDirectoryName(location);
string text = Path.Combine(directoryName, "itemcloset");
AssetBundle val = AssetBundle.LoadFromFile(text);
ClosetPrefab = val.LoadAsset<GameObject>("StorageCloset.prefab");
if ((Object)(object)ClosetPrefab == (Object)null)
{
Debug.LogError((object)"加载预制体 ClosetPrefab.prefab 失败");
}
else
{
NetworkPrefabs.RegisterNetworkPrefab(ClosetPrefab);
}
}
public void LoadItemConfigs()
{
ItemConfigManager.InitializeItemConfigs();
((BaseUnityPlugin)this).Config.ConfigReloaded += delegate
{
foreach (KeyValuePair<string, ConfigEntry<int>> itemMaxAmountConfig in ItemConfigManager.itemMaxAmountConfigs)
{
if (StatsManager.instance.itemDictionary.TryGetValue(itemMaxAmountConfig.Key, out var value))
{
value.maxAmount = itemMaxAmountConfig.Value.Value;
}
}
};
}
}
internal static class Patch
{
[HarmonyPatch(typeof(PunManager))]
private static class PunManagerPatch
{
[HarmonyPrefix]
[HarmonyPatch("TruckPopulateItemVolumes")]
private static bool TruckPopulateItemVolumesPatch(PunManager __instance)
{
ItemManager.instance.spawnedItems.Clear();
if (SemiFunc.IsNotMasterClient())
{
return false;
}
List<ItemVolume> list = new List<ItemVolume>(__instance.itemManager.itemVolumes);
List<Item> list2 = new List<Item>(__instance.itemManager.purchasedItems);
List<ItemVolume> list3 = new List<ItemVolume>();
foreach (ItemVolume item2 in list)
{
if (((Object)((Component)((Component)item2).transform.parent).gameObject).name == "StorageCloset")
{
list3.Add(item2);
list.Remove(item2);
}
}
ItemVolume val = list[0];
while (list.Count > 0 && list2.Count > 0)
{
bool flag = false;
for (int i = 0; i < list2.Count; i++)
{
Item item = list2[i];
ItemVolume val2;
if (list3.Count > 0)
{
val2 = list3.Find((ItemVolume v) => v.itemVolume == item.itemVolume);
list3.Remove(val2);
}
else
{
val2 = list.Find((ItemVolume v) => v.itemVolume == item.itemVolume);
list.Remove(val2);
}
if (Object.op_Implicit((Object)(object)val2))
{
__instance.SpawnItem(item, val2);
list2.RemoveAt(i);
flag = true;
break;
}
}
if (!flag)
{
break;
}
}
if (list2.Count > 0 && (Object)(object)val != (Object)null)
{
foreach (Item item3 in list2)
{
list2.Remove(item3);
__instance.SpawnItem(item3, val);
}
}
foreach (ItemVolume itemVolume in __instance.itemManager.itemVolumes)
{
Object.Destroy((Object)(object)((Component)itemVolume).gameObject);
}
return false;
}
}
[HarmonyPatch(typeof(LevelGenerator))]
private static class LevelGeneratorPatch
{
[HarmonyPrefix]
[HarmonyPatch("ItemSetup")]
private static void ItemSetupPatch(LevelGenerator __instance)
{
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Expected O, but got Unknown
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
if (!ShouldRunCustomLogic())
{
return;
}
StartRoom val = Object.FindObjectOfType<StartRoom>();
if ((Object)(object)val != (Object)null)
{
Transform val2 = ((Component)val).transform.Find("Truck Run/cctv");
if ((Object)(object)val2 == (Object)null)
{
Plugin.logger.LogError((object)"未找到 cctv 对象");
return;
}
Vector3 val3 = default(Vector3);
((Vector3)(ref val3))..ctor(val2.position.x, val2.position.y - 1.5f, val2.position.z);
GameObject val4 = new GameObject();
if (GameManager.instance.gameMode == 0)
{
val4 = Object.Instantiate<GameObject>(Plugin.ClosetPrefab, val3, Quaternion.Euler(90f, 0f, 0f));
}
else
{
val4 = PhotonNetwork.InstantiateRoomObject(((Object)Plugin.ClosetPrefab).name, val3, Quaternion.Euler(90f, 0f, 0f), (byte)0, (object[])null);
}
}
else
{
Plugin.logger.LogError((object)"未找到 StartRoom 对象");
}
}
[HarmonyPatch("GenerateDone")]
[HarmonyPostfix]
private static void AfterLevelGenerated(LevelGenerator __instance)
{
if (Plugin.ItemConfigManager.LoadConfig)
{
return;
}
if (StatsManager.instance.itemDictionary != null && StatsManager.instance.itemDictionary.Count > 0)
{
foreach (KeyValuePair<string, Item> item in StatsManager.instance.itemDictionary)
{
string key = item.Key;
Item value = item.Value;
if ((Object)(object)value != (Object)null)
{
Plugin.logger.LogInfo((object)$"Item Key: {key}, itemName: {value.itemName},MaxAmount:{value.maxAmount}");
}
}
Plugin.instance.LoadItemConfigs();
}
else
{
Plugin.logger.LogWarning((object)"itemDictionary 为空或未初始化");
}
}
private static bool ShouldRunCustomLogic()
{
RunManager instance = RunManager.instance;
return (Object)(object)instance != (Object)null && (Object)(object)instance.levelCurrent != (Object)(object)instance.levelTutorial && (Object)(object)instance.levelCurrent != (Object)(object)instance.levelShop && (Object)(object)instance.levelCurrent != (Object)(object)instance.levelLobbyMenu;
}
}
[HarmonyPatch(typeof(PlayerAvatar))]
public static class PlayerAvatarPatch
{
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void UpdatePatch(PlayerAvatar __instance)
{
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
if (Input.GetKeyDown((KeyCode)286) && __instance.isLocal)
{
ValuableObject component = AssetManager.instance.surplusValuableSmall.GetComponent<ValuableObject>();
Value val = ScriptableObject.CreateInstance<Value>();
val.valueMin = 888888f;
val.valueMax = 999999f;
component.valuePreset = val;
Vector3 position = ((Component)__instance).transform.position;
ExtractionPoint val2 = SemiFunc.ExtractionPointGetNearest(position) ?? SemiFunc.ExtractionPointGetNearestNotActivated(position);
if ((Object)(object)val2 != (Object)null)
{
__instance.SpawnRPC(((Component)val2).transform.position, ((Component)__instance).transform.rotation);
Object.Instantiate<GameObject>(AssetManager.instance.surplusValuableSmall, ((Component)val2).transform.position, Quaternion.identity);
}
}
}
}
}