Decompiled source of RandomWeightAndValueMod v1.3.9

plugins/RandomWeightAndValueMod.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Photon.Pun;
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("RandomWeightAndValueMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RandomWeightAndValueMod")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("1b4cbb3b-6247-407a-9e71-2e7a4b5f5d75")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RandomWeightAndValueMod;

[BepInPlugin("dyxc666.RandomWeightAndValueMod", "随机贵重物品的价格及重量", "1.3.9")]
[BepInProcess("REPO.exe")]
[BepInDependency("nickklmao.repoconfig", "1.2.3")]
public class RandomWeightAndValueMod : BaseUnityPlugin
{
	private readonly Harmony harmony = new Harmony("dyxc666.RandomWeightAndValueMod");

	public static ConfigEntry<bool> EnableValueRandomization;

	public static ConfigEntry<bool> EnableWeightRandomization;

	public static ConfigEntry<float> MinWeight;

	public static ConfigEntry<float> MaxWeight;

	public static ConfigEntry<float> MinValueMultiplier;

	public static ConfigEntry<float> MaxValueMultiplier;

	public static ConfigEntry<bool> ForceRefreshUI;

	public static ConfigEntry<bool> EnableVerboseLogging;

	public static ConfigEntry<string> BlacklistKeywords;

	public static ConfigEntry<string> WhitelistKeywords;

	public static ConfigEntry<bool> EnableWhitelistMode;

	public static ConfigEntry<bool> EnableBlacklistMode;

	public static ConfigEntry<bool> ExcludeHighValueItems;

	public static ConfigEntry<float> HighValueThreshold;

	public static ConfigEntry<bool> CashBagRandomizationToggle;

	public static ConfigEntry<bool> EnableNetworkSync;

	public static ConfigEntry<bool> EnableNetworkDebug;

	private static List<string> blacklistKeywordsList = new List<string>();

	private static List<string> whitelistKeywordsList = new List<string>();

	public static HashSet<int> modifiedItemIDs = new HashSet<int>();

	private void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"=========================================");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"随机贵重物品的价格及重量模组 v1.3.6 已加载");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"作者: dyxc666");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"修复版本: 修复了重复随机化和关键词处理问题");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"=========================================");
		CreateConfigEntries();
		BlacklistKeywords.SettingChanged += delegate
		{
			UpdateKeywordLists();
		};
		WhitelistKeywords.SettingChanged += delegate
		{
			UpdateKeywordLists();
		};
		UpdateKeywordLists();
		try
		{
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"✅ 模组初始化成功");
			((BaseUnityPlugin)this).Logger.LogInfo((object)("\ud83d\udccb 黑名单关键词: " + ((blacklistKeywordsList.Count > 0) ? string.Join(", ", blacklistKeywordsList) : "无")));
			((BaseUnityPlugin)this).Logger.LogInfo((object)("\ud83d\udccb 白名单关键词: " + ((whitelistKeywordsList.Count > 0) ? string.Join(", ", whitelistKeywordsList) : "无")));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"⚙\ufe0f 当前功能状态:");
			((BaseUnityPlugin)this).Logger.LogInfo((object)("   重量随机化: " + (EnableWeightRandomization.Value ? "✅" : "❌")));
			((BaseUnityPlugin)this).Logger.LogInfo((object)("   价格随机化: " + (EnableValueRandomization.Value ? "✅" : "❌")));
			((BaseUnityPlugin)this).Logger.LogInfo((object)("   现金袋保护: " + (CashBagRandomizationToggle.Value ? "❌ 已禁用" : "✅ 已启用")));
			((BaseUnityPlugin)this).Logger.LogInfo((object)("   网络同步: " + (EnableNetworkSync.Value ? "✅ 已启用" : "❌ 已禁用")));
			if (EnableNetworkSync.Value)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"\ud83c\udf10 网络同步功能已启用");
				((BaseUnityPlugin)this).Logger.LogInfo((object)"   确保所有玩家都安装此模组以获得最佳体验");
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"\ud83d\udca1 提示: 配置选项可以在游戏设置菜单的Mods选项中修改");
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("❌ 模组初始化失败: " + ex.Message));
			((BaseUnityPlugin)this).Logger.LogError((object)("详细错误: " + ex.StackTrace));
		}
	}

	private void CreateConfigEntries()
	{
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Expected O, but got Unknown
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Expected O, but got Unknown
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Expected O, but got Unknown
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0215: Expected O, but got Unknown
		EnableValueRandomization = ((BaseUnityPlugin)this).Config.Bind<bool>("基础设置", "随机化物品价格", true, "是否随机化贵重物品的价格");
		EnableWeightRandomization = ((BaseUnityPlugin)this).Config.Bind<bool>("基础设置", "随机化物品重量", true, "是否随机化贵重物品的重量");
		MinWeight = ((BaseUnityPlugin)this).Config.Bind<float>("重量设置", "最小重量倍率", 0.5f, new ConfigDescription("最小重量倍率 (0.5 = 原重的50%)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 5f), Array.Empty<object>()));
		MaxWeight = ((BaseUnityPlugin)this).Config.Bind<float>("重量设置", "最大重量倍率", 3f, new ConfigDescription("最大重量倍率 (3.0 = 原重的300%)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 10f), Array.Empty<object>()));
		MinValueMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("价格设置", "最小价格倍率", 0.8f, new ConfigDescription("价格的最小倍率 (0.8 = 原价的80%)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 5f), Array.Empty<object>()));
		MaxValueMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("价格设置", "最大价格倍率", 2.5f, new ConfigDescription("价格的最大倍率 (2.5 = 原价的250%)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 10f), Array.Empty<object>()));
		EnableBlacklistMode = ((BaseUnityPlugin)this).Config.Bind<bool>("黑白名单", "启用黑名单模式", true, "启用黑名单,匹配的物品将不被随机化");
		BlacklistKeywords = ((BaseUnityPlugin)this).Config.Bind<string>("黑白名单", "黑名单关键词", "keycard,microfilm,document", "逗号分隔的关键词列表,匹配这些关键词的物品将不被随机化(留空表示无黑名单)");
		EnableWhitelistMode = ((BaseUnityPlugin)this).Config.Bind<bool>("黑白名单", "启用白名单模式", false, "启用白名单,只有匹配白名单的物品才会被随机化 (黑名单优先)");
		WhitelistKeywords = ((BaseUnityPlugin)this).Config.Bind<string>("黑白名单", "白名单关键词", "", "逗号分隔的关键词列表,只有匹配这些关键词的物品才会被随机化(留空表示所有物品)");
		ExcludeHighValueItems = ((BaseUnityPlugin)this).Config.Bind<bool>("特殊排除规则", "排除高价物品", false, "不随机化价格超过阈值的物品");
		HighValueThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("特殊排除规则", "高价物品阈值", 50000f, new ConfigDescription("价格超过此值的物品不随机化 (如果启用排除高额物品)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1000f, 1000000f), Array.Empty<object>()));
		CashBagRandomizationToggle = ((BaseUnityPlugin)this).Config.Bind<bool>("特殊排除规则", "现金袋随机化", false, "如果为true,则现金袋也会被随机化");
		EnableNetworkSync = ((BaseUnityPlugin)this).Config.Bind<bool>("网络设置", "启用网络同步", true, "启用多人游戏网络同步 (需要所有玩家安装此模组)");
		EnableNetworkDebug = ((BaseUnityPlugin)this).Config.Bind<bool>("网络设置", "网络调试日志", false, "输出网络同步的详细日志");
		ForceRefreshUI = ((BaseUnityPlugin)this).Config.Bind<bool>("调试设置", "强制刷新UI", true, "尝试强制刷新UI显示");
		EnableVerboseLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("调试设置", "详细日志输出", false, "输出每个物品修改前后的具体数值");
	}

	private void UpdateKeywordLists()
	{
		try
		{
			if (!string.IsNullOrWhiteSpace(WhitelistKeywords.Value))
			{
				string[] source = BlacklistKeywords.Value.Split(new char[3] { ',', ';', '|' }, StringSplitOptions.RemoveEmptyEntries);
				blacklistKeywordsList = (from k in source
					select k.Trim().ToLower() into k
					where !string.IsNullOrEmpty(k)
					select k).Distinct().ToList();
			}
			else
			{
				blacklistKeywordsList = new List<string>();
			}
			if (!string.IsNullOrWhiteSpace(WhitelistKeywords.Value))
			{
				string[] source2 = WhitelistKeywords.Value.Split(new char[3] { ',', ';', '|' }, StringSplitOptions.RemoveEmptyEntries);
				whitelistKeywordsList = (from k in source2
					select k.Trim().ToLower() into k
					where !string.IsNullOrEmpty(k)
					select k).Distinct().ToList();
			}
			else
			{
				whitelistKeywordsList = new List<string>();
			}
			if (EnableVerboseLogging.Value)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("\ud83d\udcdd 黑名单关键词已更新: " + ((blacklistKeywordsList.Count > 0) ? string.Join(", ", blacklistKeywordsList) : "无")));
				((BaseUnityPlugin)this).Logger.LogInfo((object)("\ud83d\udcdd 白名单关键词已更新: " + ((whitelistKeywordsList.Count > 0) ? string.Join(", ", whitelistKeywordsList) : "无")));
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("更新关键词列表时出错: " + ex.Message));
		}
	}

	public static bool ShouldItemBeRandomized(GameObject obj, ValuableObject vo)
	{
		try
		{
			if (!((Object)obj).name.EndsWith("(Clone)"))
			{
				if (EnableVerboseLogging.Value)
				{
					Debug.Log((object)("[RWVM] \ud83c\udfed 跳过原型物品: " + ((Object)obj).name));
				}
				return false;
			}
			string itemName = ((Object)obj).name.ToLower();
			if (IsCashBag(itemName))
			{
				if (CashBagRandomizationToggle.Value)
				{
					if (EnableVerboseLogging.Value)
					{
						Debug.Log((object)("[RWVM] \ud83c\udfb2 现金袋随机化开关开启,对现金袋进行随机化: " + ((Object)obj).name));
					}
					return true;
				}
				if (EnableVerboseLogging.Value)
				{
					Debug.Log((object)("[RWVM] \ud83d\udcb0 现金袋随机化开关关闭,跳过随机化: " + ((Object)obj).name));
				}
				return false;
			}
			if (CheckSpecialExclusionRules(obj, vo))
			{
				if (EnableVerboseLogging.Value)
				{
					Debug.Log((object)("[RWVM] \ud83d\udd12 特殊规则排除: " + ((Object)obj).name));
				}
				return false;
			}
			if (EnableBlacklistMode.Value && CheckBlacklist(itemName))
			{
				if (EnableVerboseLogging.Value)
				{
					Debug.Log((object)("[RWVM] \ud83d\udeab 黑名单排除: " + ((Object)obj).name));
				}
				return false;
			}
			if (EnableWhitelistMode.Value && !CheckWhitelist(itemName))
			{
				if (EnableVerboseLogging.Value)
				{
					Debug.Log((object)("[RWVM] \ud83d\udccb 白名单未匹配: " + ((Object)obj).name));
				}
				return false;
			}
			if (!EnableWeightRandomization.Value && !EnableValueRandomization.Value)
			{
				if (EnableVerboseLogging.Value)
				{
					Debug.Log((object)"[RWVM] ⚙\ufe0f 通用设置关闭了所有修改功能");
				}
				return false;
			}
			return true;
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[RWVM] 检查物品时出错: " + ex.Message));
			return false;
		}
	}

	private static bool IsCashBag(string itemName)
	{
		return itemName.Contains("surplus") || itemName.Contains("cash") || (itemName.Contains("bag") && itemName.Contains("money"));
	}

	private static bool CheckSpecialExclusionRules(GameObject obj, ValuableObject vo)
	{
		string text = ((Object)obj).name.ToLower();
		if (ExcludeHighValueItems.Value)
		{
			float itemPrice = GetItemPrice(vo);
			if (itemPrice >= HighValueThreshold.Value)
			{
				if (EnableVerboseLogging.Value)
				{
					Debug.Log((object)$"[RWVM] \ud83d\udc8e 排除高额物品: {((Object)obj).name} (价格: {itemPrice:F0})");
				}
				return true;
			}
		}
		return false;
	}

	private static bool CheckBlacklist(string itemName)
	{
		if (blacklistKeywordsList.Count == 0)
		{
			return false;
		}
		foreach (string blacklistKeywords in blacklistKeywordsList)
		{
			if (itemName.Contains(blacklistKeywords))
			{
				return true;
			}
		}
		return false;
	}

	private static bool CheckWhitelist(string itemName)
	{
		if (whitelistKeywordsList.Count == 0)
		{
			return true;
		}
		foreach (string whitelistKeywords in whitelistKeywordsList)
		{
			if (itemName.Contains(whitelistKeywords))
			{
				return true;
			}
		}
		return false;
	}

	private static float GetItemPrice(ValuableObject vo)
	{
		try
		{
			FieldInfo field = typeof(ValuableObject).GetField("dollarValueCurrent", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				return (float)field.GetValue(vo);
			}
		}
		catch
		{
		}
		return 0f;
	}
}
public static class ItemModifier
{
	private static FieldInfo _dollarValueCurrentField;

	private static FieldInfo _dollarValueOriginalField;

	private static FieldInfo _rigidBodyMassField;

	static ItemModifier()
	{
		try
		{
			_dollarValueCurrentField = typeof(ValuableObject).GetField("dollarValueCurrent", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			_dollarValueOriginalField = typeof(ValuableObject).GetField("dollarValueOriginal", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			_rigidBodyMassField = typeof(ValuableObject).GetField("rigidBodyMass", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[RWVM] 初始化反射字段缓存时出错: " + ex.Message));
		}
	}

	public static bool ModifyItemAttributes(PhysGrabObject pgo, ValuableObject vo, float newWeight, float newPrice)
	{
		try
		{
			float originalWeight = GetOriginalWeight(pgo, vo);
			float itemPrice = GetItemPrice(vo);
			bool flag = false;
			bool flag2 = false;
			if (RandomWeightAndValueMod.EnableWeightRandomization.Value && originalWeight > 0f)
			{
				flag = ModifyItemWeight(pgo, vo, newWeight);
			}
			else if (RandomWeightAndValueMod.EnableWeightRandomization.Value && originalWeight <= 0f)
			{
				Debug.LogWarning((object)("[RWVM] ⚠\ufe0f 物品重量为0或未找到重量值,跳过重量修改: " + ((Object)((Component)pgo).gameObject).name));
			}
			if (RandomWeightAndValueMod.EnableValueRandomization.Value && itemPrice > 0f)
			{
				flag2 = ModifyItemPrice(vo, newPrice);
				if (RandomWeightAndValueMod.ForceRefreshUI.Value)
				{
					TryRefreshUIDisplay(vo);
				}
			}
			else if (RandomWeightAndValueMod.EnableValueRandomization.Value && itemPrice <= 0f)
			{
				Debug.LogWarning((object)("[RWVM] ⚠\ufe0f 物品价格为0或未找到价格值,跳过价格修改: " + ((Object)((Component)pgo).gameObject).name));
			}
			if (RandomWeightAndValueMod.EnableVerboseLogging.Value && (flag || flag2))
			{
				string text = "[RWVM] " + ((Object)((Component)pgo).gameObject).name + ": ";
				if (flag && originalWeight > 0f)
				{
					float num = ((originalWeight > 0f) ? (newWeight / originalWeight) : 0f);
					text += $"重量 {originalWeight:F2}→{newWeight:F2}kg (x{num:F2}) ";
				}
				if (flag2 && itemPrice > 0f)
				{
					float num2 = newPrice / itemPrice;
					text += $"价格 ${itemPrice:F0}→${newPrice:F0}(x{num2:F2})";
					if (num2 > 2f)
					{
						text += " \ud83d\udcb0";
					}
					else if (num2 > 1.5f)
					{
						text += " \ud83d\udcc8";
					}
					else if (num2 < 0.9f)
					{
						text += " \ud83d\udcc9";
					}
					else if (num2 < 1f)
					{
						text += " \ud83d\udd3b";
					}
				}
				Debug.Log((object)text);
			}
			return flag || flag2;
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[RWVM] 修改物品属性时出错: " + ex.Message));
			return false;
		}
	}

	public static float GetOriginalWeight(PhysGrabObject pgo, ValuableObject vo)
	{
		try
		{
			if ((Object)(object)pgo != (Object)null && pgo.massOriginal > 0f)
			{
				return pgo.massOriginal;
			}
			if ((Object)(object)pgo != (Object)null && (Object)(object)pgo.rb != (Object)null && pgo.rb.mass > 0f)
			{
				return pgo.rb.mass;
			}
			if (_rigidBodyMassField != null)
			{
				float num = (float)_rigidBodyMassField.GetValue(vo);
				if (num > 0f)
				{
					return num;
				}
			}
			return 0f;
		}
		catch
		{
			return 0f;
		}
	}

	private static bool ModifyItemWeight(PhysGrabObject pgo, ValuableObject vo, float newWeight)
	{
		try
		{
			newWeight = Mathf.Clamp(newWeight, 0.01f, 1000f);
			if ((Object)(object)pgo != (Object)null)
			{
				pgo.massOriginal = newWeight;
				if ((Object)(object)pgo.rb != (Object)null)
				{
					pgo.rb.mass = newWeight;
				}
				if (_rigidBodyMassField != null && _rigidBodyMassField.FieldType == typeof(float))
				{
					_rigidBodyMassField.SetValue(vo, newWeight);
				}
				if ((Object)(object)pgo.rb != (Object)null)
				{
					pgo.rb.ResetCenterOfMass();
					pgo.rb.ResetInertiaTensor();
					pgo.rb.WakeUp();
				}
				return true;
			}
			return false;
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[RWVM] 修改物品重量失败: " + ex.Message));
			return false;
		}
	}

	private static bool ModifyItemPrice(ValuableObject vo, float newPrice)
	{
		try
		{
			newPrice = Mathf.Clamp(newPrice, 1f, 1000000f);
			if (_dollarValueCurrentField != null)
			{
				_dollarValueCurrentField.SetValue(vo, newPrice);
			}
			if (_dollarValueOriginalField != null)
			{
				_dollarValueOriginalField.SetValue(vo, newPrice);
			}
			return true;
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[RWVM] 修改物品价格失败: " + ex.Message));
			return false;
		}
	}

	private static void TryRefreshUIDisplay(ValuableObject valuableItem)
	{
		try
		{
			((Component)valuableItem).BroadcastMessage("OnValueChanged", (SendMessageOptions)1);
			((Component)valuableItem).BroadcastMessage("OnWeightChanged", (SendMessageOptions)1);
		}
		catch
		{
		}
	}

	public static float GetItemPrice(ValuableObject vo)
	{
		try
		{
			if (_dollarValueCurrentField != null)
			{
				return (float)_dollarValueCurrentField.GetValue(vo);
			}
		}
		catch
		{
		}
		return 0f;
	}

	public static float GenerateDeterministicRandomNumber(int seed, float minValue, float maxValue)
	{
		Random.InitState(seed);
		return Random.Range(minValue, maxValue);
	}
}
[HarmonyPatch(typeof(PhysGrabObject), "GrabStarted")]
public static class GrabItemPatch
{
	private static void Postfix(PhysGrabObject __instance)
	{
		try
		{
			ValuableObject component = ((Component)__instance).GetComponent<ValuableObject>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			int instanceID = ((Object)((Component)__instance).gameObject).GetInstanceID();
			if (RandomWeightAndValueMod.modifiedItemIDs.Contains(instanceID))
			{
				if (RandomWeightAndValueMod.EnableVerboseLogging.Value)
				{
					Debug.Log((object)$"[RWVM] ⏭\ufe0f 物品已处理过,跳过: {((Object)((Component)__instance).gameObject).name} (ID: {instanceID})");
				}
				return;
			}
			if (!RandomWeightAndValueMod.ShouldItemBeRandomized(((Component)__instance).gameObject, component))
			{
				RandomWeightAndValueMod.modifiedItemIDs.Add(instanceID);
				return;
			}
			float originalWeight = ItemModifier.GetOriginalWeight(__instance, component);
			float itemPrice = ItemModifier.GetItemPrice(component);
			float newWeight = originalWeight;
			float newPrice = itemPrice;
			bool flag = RandomWeightAndValueMod.EnableWeightRandomization.Value && originalWeight > 0f;
			bool flag2 = RandomWeightAndValueMod.EnableValueRandomization.Value && itemPrice > 0f;
			if (!flag && !flag2)
			{
				RandomWeightAndValueMod.modifiedItemIDs.Add(instanceID);
				return;
			}
			if (flag)
			{
				float num = GenerateRandomWeightMultiplier(((Component)__instance).gameObject);
				newWeight = originalWeight * num;
			}
			if (flag2)
			{
				float num2 = GenerateRandomPriceMultiplier(((Component)__instance).gameObject);
				newPrice = itemPrice * num2;
				newPrice = Mathf.Max(1f, newPrice);
			}
			if (ItemModifier.ModifyItemAttributes(__instance, component, newWeight, newPrice))
			{
				RandomWeightAndValueMod.modifiedItemIDs.Add(instanceID);
				if (RandomWeightAndValueMod.EnableNetworkSync.Value)
				{
					HandleNetworkSync(((Component)__instance).gameObject, newWeight, newPrice);
				}
				Debug.Log((object)("[RWVM] ✅ 成功随机化: " + ((Object)((Component)__instance).gameObject).name));
			}
			else
			{
				Debug.LogError((object)("[RWVM] ❌ 随机化失败: " + ((Object)((Component)__instance).gameObject).name));
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[RWVM] 抓取物品补丁错误: " + ex.Message));
		}
	}

	private static void HandleNetworkSync(GameObject itemObject, float newWeight, float newPrice)
	{
		try
		{
			ItemRandomizationNetworkSync itemRandomizationNetworkSync = default(ItemRandomizationNetworkSync);
			if (itemObject.TryGetComponent<ItemRandomizationNetworkSync>(ref itemRandomizationNetworkSync))
			{
				itemRandomizationNetworkSync.BroadcastRandomization(newWeight, newPrice);
				if (RandomWeightAndValueMod.EnableNetworkDebug.Value)
				{
					Debug.Log((object)("[RWVM-Patch] 网络同步调用成功: " + ((Object)itemObject).name));
				}
			}
			else
			{
				Debug.LogWarning((object)("[RWVM-Patch] 物品缺少网络同步组件: " + ((Object)itemObject).name));
				ItemRandomizationNetworkSync.EnsureNetworkComponent(itemObject);
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[RWVM-Patch] 网络同步处理失败: " + ex.Message));
		}
	}

	private static float GenerateRandomWeightMultiplier(GameObject obj)
	{
		float value = RandomWeightAndValueMod.MinWeight.Value;
		float value2 = RandomWeightAndValueMod.MaxWeight.Value;
		int seed = ((Object)obj).GetInstanceID() + Time.frameCount;
		return ItemModifier.GenerateDeterministicRandomNumber(seed, value, value2);
	}

	private static float GenerateRandomPriceMultiplier(GameObject obj)
	{
		float value = RandomWeightAndValueMod.MinValueMultiplier.Value;
		float value2 = RandomWeightAndValueMod.MaxValueMultiplier.Value;
		int seed = ((Object)obj).GetInstanceID() + Time.frameCount + 1000;
		return ItemModifier.GenerateDeterministicRandomNumber(seed, value, value2);
	}
}
[HarmonyPatch(typeof(ValuableObject), "Start")]
public static class AddNetworkSyncComponentPatch
{
	private static void Postfix(ValuableObject __instance)
	{
		try
		{
			if (!((Object)(object)__instance == (Object)null))
			{
				ItemRandomizationNetworkSync.EnsureNetworkComponent(((Component)__instance).gameObject);
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[RWVM] 添加网络同步组件失败: " + ex.Message));
		}
	}
}
[HarmonyPatch(typeof(PhysGrabObject), "GrabEnded")]
public static class ReleaseItemPatch
{
	private static void Postfix(PhysGrabObject __instance)
	{
	}
}
public class ItemRandomizationNetworkSync : MonoBehaviourPun
{
	private bool hasBeenSynced = false;

	private float syncedWeight = -1f;

	private float syncedPrice = -1f;

	private int itemInstanceID = 0;

	private ValuableObject vo;

	private PhysGrabObject pgo;

	private void Awake()
	{
		vo = ((Component)this).GetComponent<ValuableObject>();
		pgo = ((Component)this).GetComponent<PhysGrabObject>();
		itemInstanceID = ((Object)((Component)this).gameObject).GetInstanceID();
	}

	[PunRPC]
	public void SyncItemRandomization(int viewID, float weight, float price)
	{
		if (viewID != ((MonoBehaviourPun)this).photonView.ViewID)
		{
			if (RandomWeightAndValueMod.EnableNetworkDebug.Value)
			{
				Debug.Log((object)$"[RWVM-NS] 视图ID不匹配: 收到{viewID}, 当前{((MonoBehaviourPun)this).photonView.ViewID}");
			}
		}
		else if (hasBeenSynced)
		{
			if (RandomWeightAndValueMod.EnableNetworkDebug.Value)
			{
				Debug.Log((object)("[RWVM-NS] 物品已同步过,跳过: " + ((Object)((Component)this).gameObject).name));
			}
		}
		else
		{
			syncedWeight = weight;
			syncedPrice = price;
			hasBeenSynced = true;
			ApplySyncedRandomization();
		}
	}

	private void ApplySyncedRandomization()
	{
		if ((Object)(object)vo == (Object)null || (Object)(object)pgo == (Object)null)
		{
			Debug.LogWarning((object)("[RWVM-NS] 找不到物品组件: " + ((Object)((Component)this).gameObject).name));
		}
		else if (RandomWeightAndValueMod.modifiedItemIDs.Contains(itemInstanceID))
		{
			if (RandomWeightAndValueMod.EnableNetworkDebug.Value)
			{
				Debug.Log((object)("[RWVM-NS] 物品已处理过,跳过: " + ((Object)((Component)this).gameObject).name));
			}
		}
		else if (!RandomWeightAndValueMod.ShouldItemBeRandomized(((Component)this).gameObject, vo))
		{
			RandomWeightAndValueMod.modifiedItemIDs.Add(itemInstanceID);
		}
		else if (ItemModifier.ModifyItemAttributes(pgo, vo, syncedWeight, syncedPrice))
		{
			RandomWeightAndValueMod.modifiedItemIDs.Add(itemInstanceID);
			if (RandomWeightAndValueMod.EnableNetworkDebug.Value)
			{
				Debug.Log((object)("[RWVM-NS] 客户端成功应用随机化: " + ((Object)((Component)this).gameObject).name));
				Debug.Log((object)$"[RWVM-NS]   重量: {syncedWeight:F2} kg");
				Debug.Log((object)$"[RWVM-NS]   价格: ${syncedPrice:F0}");
			}
		}
		else
		{
			Debug.LogError((object)("[RWVM-NS] 客户端应用随机化失败: " + ((Object)((Component)this).gameObject).name));
		}
	}

	public void BroadcastRandomization(float weight, float price)
	{
		if (!((MonoBehaviourPun)this).photonView.IsMine)
		{
			Debug.LogWarning((object)("[RWVM-NS] 不是物品所有者,无法广播: " + ((Object)((Component)this).gameObject).name));
			return;
		}
		if (!RandomWeightAndValueMod.EnableNetworkSync.Value)
		{
			if (RandomWeightAndValueMod.EnableNetworkDebug.Value)
			{
				Debug.Log((object)("[RWVM-NS] 网络同步已禁用,跳过广播: " + ((Object)((Component)this).gameObject).name));
			}
			return;
		}
		try
		{
			((MonoBehaviourPun)this).photonView.RPC("SyncItemRandomization", (RpcTarget)1, new object[3]
			{
				((MonoBehaviourPun)this).photonView.ViewID,
				weight,
				price
			});
			hasBeenSynced = true;
			if (RandomWeightAndValueMod.EnableNetworkDebug.Value)
			{
				Debug.Log((object)("[RWVM-NS] 主机广播随机化: " + ((Object)((Component)this).gameObject).name));
				Debug.Log((object)"[RWVM-NS]   发送给: 所有客户端");
				Debug.Log((object)$"[RWVM-NS]   视图ID: {((MonoBehaviourPun)this).photonView.ViewID}");
				Debug.Log((object)$"[RWVM-NS]   重量: {weight:F2} kg");
				Debug.Log((object)$"[RWVM-NS]   价格: ${price:F0}");
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[RWVM-NS] 广播随机化时出错: " + ex.Message));
		}
	}

	public static void EnsureNetworkComponent(GameObject obj)
	{
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)obj == (Object)null || !RandomWeightAndValueMod.EnableNetworkSync.Value)
		{
			return;
		}
		ValuableObject component = obj.GetComponent<ValuableObject>();
		ItemRandomizationNetworkSync itemRandomizationNetworkSync = default(ItemRandomizationNetworkSync);
		if (!((Object)(object)component == (Object)null) && RandomWeightAndValueMod.ShouldItemBeRandomized(obj, component) && !obj.TryGetComponent<ItemRandomizationNetworkSync>(ref itemRandomizationNetworkSync))
		{
			PhotonView val = default(PhotonView);
			if (!obj.TryGetComponent<PhotonView>(ref val))
			{
				val = obj.AddComponent<PhotonView>();
				val.OwnershipTransfer = (OwnershipOption)1;
				val.Synchronization = (ViewSynchronization)3;
			}
			obj.AddComponent<ItemRandomizationNetworkSync>();
			if (RandomWeightAndValueMod.EnableNetworkDebug.Value)
			{
				Debug.Log((object)("[RWVM-NS] 已添加网络同步组件: " + ((Object)obj).name));
			}
		}
	}
}