Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of ShrinkHaulSimple v0.1.1
plugins/ShrinkHaulSimple.dll
Decompiled 2 days agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using Photon.Pun; using ScalerCore; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("0.0.0.0")] namespace ShrinkHaulSimple; [BepInPlugin("cn_xc.ShrinkHaulSimple", "缩物搬运", "0.1.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { internal static ManualLogSource Log; private static ConfigEntry<bool> _cartEnabled; private static ConfigEntry<bool> _extractionEnabled; private const float ExtractionRadius = 2.5f; private const float CartExtraShrink = 0.7f; private const float CartPadding = 0f; private static ConfigEntry<bool> _hostOnly; private static ConfigEntry<bool> _verbose; private static ConfigEntry<float> _fTiny; private static ConfigEntry<float> _fSmall; private static ConfigEntry<float> _fMedium; private static ConfigEntry<float> _fBig; private static ConfigEntry<float> _fWide; private static ConfigEntry<float> _fTall; private static ConfigEntry<float> _fVeryTall; private static float _nextScanAt; private static readonly HashSet<int> _ours = new HashSet<int>(); private static FieldInfo _inCartObjectsField; private static FieldInfo _cartObjectPgoField; internal static void LogInfo(string m) { if (Log != null) { Log.LogInfo((object)m); } } internal static void Verbose(string m) { if (Log != null) { Log.LogDebug((object)m); } } private void Awake() { Log = ((BaseUnityPlugin)this).Logger; _cartEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("触发范围", "推车缩小", true, "贵重品放进推车(PhysGrabCart)时缩小。"); _extractionEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("触发范围", "提取点缩小", true, "贵重品进入提取点范围时缩小(ShrinkCart 之类的模组没有这个功能)。"); _fTiny = ((BaseUnityPlugin)this).Config.Bind<float>("体型倍率", "微小 Tiny", 0.8f, RangeDesc("已经很小的物品,轻微缩小。")); _fSmall = ((BaseUnityPlugin)this).Config.Bind<float>("体型倍率", "小 Small", 0.7f, RangeDesc("小件物品。")); _fMedium = ((BaseUnityPlugin)this).Config.Bind<float>("体型倍率", "中 Medium", 0.5f, RangeDesc("中等体积。")); _fBig = ((BaseUnityPlugin)this).Config.Bind<float>("体型倍率", "大 Big", 0.4f, RangeDesc("大件,需要明显缩小才放得下。")); _fWide = ((BaseUnityPlugin)this).Config.Bind<float>("体型倍率", "宽 Wide", 0.4f, RangeDesc("特别宽,横向占地大。")); _fTall = ((BaseUnityPlugin)this).Config.Bind<float>("体型倍率", "高 Tall", 0.4f, RangeDesc("比较高。")); _fVeryTall = ((BaseUnityPlugin)this).Config.Bind<float>("体型倍率", "超高 VeryTall", 0.3f, RangeDesc("最高的一档。")); _hostOnly = ((BaseUnityPlugin)this).Config.Bind<bool>("通用", "仅房主执行", true, "推荐开启:缩放由 ScalerCore 同步,房主执行即可,避免多人重复缩放。"); _verbose = ((BaseUnityPlugin)this).Config.Bind<bool>("通用", "详细日志", false, "输出每次缩放/恢复的明细(含体型与倍率)。"); LogInfo("缩物搬运 v0.1.1 已加载(依赖 ScalerCore)。"); } private static ConfigDescription RangeDesc(string desc) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown return new ConfigDescription(desc + " 1.0 = 不缩小。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()); } private void Update() { try { if (!(Time.unscaledTime < _nextScanAt)) { _nextScanAt = Time.unscaledTime + 0.25f; if (!_hostOnly.Value || !PhotonNetwork.InRoom || PhotonNetwork.IsMasterClient) { Scan(); } } } catch (Exception ex) { Verbose("扫描异常:" + ex.Message); } } private static void CollectInCartIds(HashSet<int> ids) { try { if (_inCartObjectsField == null) { _inCartObjectsField = typeof(PhysGrabInCart).GetField("inCartObjects", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); } if (_inCartObjectsField == null) { return; } PhysGrabInCart[] array = Object.FindObjectsByType<PhysGrabInCart>((FindObjectsSortMode)0); foreach (PhysGrabInCart val in array) { if ((Object)(object)val == (Object)null || !(_inCartObjectsField.GetValue(val) is IList list)) { continue; } for (int j = 0; j < list.Count; j++) { object obj = list[j]; if (obj == null) { continue; } if (_cartObjectPgoField == null) { _cartObjectPgoField = obj.GetType().GetField("physGrabObject", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); } PhysGrabObject val2 = (PhysGrabObject)((_cartObjectPgoField != null) ? /*isinst with value type is only supported in some contexts*/: null); if (!((Object)(object)val2 == (Object)null)) { ValuableObject val3 = ((Component)val2).GetComponent<ValuableObject>(); if ((Object)(object)val3 == (Object)null) { val3 = ((Component)val2).GetComponentInParent<ValuableObject>(); } if ((Object)(object)val3 != (Object)null) { ids.Add(((Object)((Component)val3).gameObject).GetInstanceID()); } } } } } catch (Exception ex) { Verbose("读取推车内容失败:" + ex.Message); } } private static float FactorFor(Type t) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected I4, but got Unknown return (int)t switch { 0 => _fTiny.Value, 1 => _fSmall.Value, 2 => _fMedium.Value, 3 => _fBig.Value, 4 => _fWide.Value, 5 => _fTall.Value, 6 => _fVeryTall.Value, _ => 0.5f, }; } private static void Scan() { //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_0064: 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_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_0212: Unknown result type (might be due to invalid IL or missing references) ValuableObject[] array = Object.FindObjectsByType<ValuableObject>((FindObjectsSortMode)0); if (array == null || array.Length == 0) { return; } HashSet<int> hashSet = new HashSet<int>(); List<Bounds> list = new List<Bounds>(); if (_cartEnabled.Value) { CollectInCartIds(hashSet); PhysGrabCart[] array2 = Object.FindObjectsByType<PhysGrabCart>((FindObjectsSortMode)0); if (array2 != null) { foreach (PhysGrabCart val in array2) { if (!((Object)(object)val == (Object)null)) { Collider componentInChildren = ((Component)val).GetComponentInChildren<Collider>(); if (!((Object)(object)componentInChildren == (Object)null)) { Bounds bounds = componentInChildren.bounds; ((Bounds)(ref bounds)).Expand(0f); list.Add(bounds); } } } } } List<Vector3> list2 = new List<Vector3>(); if (_extractionEnabled.Value) { ExtractionPoint[] array3 = Object.FindObjectsByType<ExtractionPoint>((FindObjectsSortMode)0); if (array3 != null) { for (int j = 0; j < array3.Length; j++) { if (!((Object)(object)array3[j] == (Object)null)) { list2.Add(((Component)array3[j]).transform.position); } } } } float num = 2.5f; foreach (ValuableObject val2 in array) { if ((Object)(object)val2 == (Object)null) { continue; } GameObject gameObject = ((Component)val2).gameObject; int instanceID = ((Object)gameObject).GetInstanceID(); bool flag = hashSet.Contains(instanceID); Vector3 position = ((Component)val2).transform.position; for (int l = 0; l < list.Count; l++) { if (flag) { break; } Bounds val3 = list[l]; if (((Bounds)(ref val3)).Contains(position)) { flag = true; } } bool flag2 = false; for (int m = 0; m < list2.Count; m++) { if (flag2) { break; } if (Vector3.Distance(position, list2[m]) <= num) { flag2 = true; } } float num2 = FactorFor(val2.volumeType); if (flag) { num2 *= 0.7f; } num2 = Mathf.Clamp(num2, 0.05f, 1f); bool num3 = (flag || flag2) && num2 < 0.99f; bool flag3 = ScaleManager.IsScaled(gameObject); bool flag4 = _ours.Contains(instanceID); if (num3) { if (flag3) { continue; } ScaleOptions val4 = ScaleOptions.Default; val4.Factor = num2; val4.Duration = 0f; if (ScaleManager.ApplyIfNotScaled(gameObject, val4)) { _ours.Add(instanceID); if (_verbose.Value) { LogInfo("[缩小] " + ((Object)val2).name + " 体型=" + ((object)Unsafe.As<Type, Type>(ref val2.volumeType)/*cast due to .constrained prefix*/).ToString() + " → x" + num2 + (flag ? "(推车)" : "") + (flag2 ? "(提取点)" : "")); } } } else if (flag3 && flag4) { ScaleManager.Restore(gameObject); _ours.Remove(instanceID); if (_verbose.Value) { LogInfo("[恢复] " + ((Object)val2).name); } } } } }