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 ScaleInCart v1.2.3
ScaleInCart.dll
Decompiled 2 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using REPOLib; using REPOLib.Modules; using ScaleInCart.Classes; using ScaleInCart.Enums; using ScaleInCart.Structs; 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("ScaleInCart")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ScaleInCart")] [assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("5e12a72d-c200-488d-940a-653d1003d96e")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] namespace ScaleInCart { [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInPlugin("bulletbot.scaleincart", "ScaleInCart", "1.2.3")] internal class Plugin : BaseUnityPlugin { public static class REPOLib { public const string modGUID = "REPOLib"; public static bool IsLoaded() { return Chainloader.PluginInfos.ContainsKey("REPOLib"); } public static void OnAwake() { BundleLoader.OnAllBundlesLoaded += delegate { foreach (PrefabRef registeredValuable in Valuables.RegisteredValuables) { ValuableObject component = registeredValuable.Prefab.GetComponent<ValuableObject>(); if ((Object)(object)component != (Object)null) { instance.SetupValuableObject(component, isModded: true); } } instance.LogMessages(); }; } } private const string modGUID = "bulletbot.scaleincart"; private const string modName = "ScaleInCart"; private const string modVer = "1.2.3"; public static Plugin instance; public ManualLogSource logger; private readonly Harmony harmony = new Harmony("bulletbot.scaleincart"); public Dictionary<PhysGrabCart, List<PhysGrabObject>> grabObjectsInCarts; public Dictionary<PhysGrabObject, PhysGrabObjectData> grabObjectDatas; public List<Vector2> massScaleFactorsList; public List<Vector2> customScaleCurvesList; public ConfigEntry<bool> printCartNames; public ConfigEntry<bool> printValuables; public ConfigEntry<bool> scaleEverything; public ConfigEntry<string> excludeCartNames; public ConfigEntry<bool> revertBackToOriginalScale; private ConfigEntry<ScaleCurveType> scaleCurveType; private ConfigEntry<ScaleCurveDirection> scaleCurveDirection; private ConfigEntry<string> customScaleCurves; public ConfigEntry<float> scaleSpeed; public ConfigEntry<float> scaleDelay; public ConfigEntry<bool> scaleMass; public ConfigEntry<float> defaultScale; public ConfigEntry<bool> useMassScaling; public ConfigEntry<string> massScaleFactors; public ConfigEntry<float> massScaleDefaultScale; public Dictionary<string, ValuableConfig> valuableConfigs; public int vanillaCount; public int moddedCount = -1; public static string GetBaseName(string name) { return name.Replace("(Clone)", ""); } public static float GetEffectiveUniformScale(Vector3 vectorScale) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) return Mathf.Pow(vectorScale.x * vectorScale.y * vectorScale.z, 1f / 3f); } public static float EvaluateScaleCurve(float progress) { //IL_0723: Unknown result type (might be due to invalid IL or missing references) //IL_075f: Unknown result type (might be due to invalid IL or missing references) //IL_073f: Unknown result type (might be due to invalid IL or missing references) //IL_0779: Unknown result type (might be due to invalid IL or missing references) //IL_0796: Unknown result type (might be due to invalid IL or missing references) //IL_079b: Unknown result type (might be due to invalid IL or missing references) //IL_07a3: Unknown result type (might be due to invalid IL or missing references) //IL_07a8: Unknown result type (might be due to invalid IL or missing references) //IL_07ab: Unknown result type (might be due to invalid IL or missing references) //IL_07b5: Unknown result type (might be due to invalid IL or missing references) //IL_0826: Unknown result type (might be due to invalid IL or missing references) //IL_07cc: Unknown result type (might be due to invalid IL or missing references) //IL_07d4: Unknown result type (might be due to invalid IL or missing references) //IL_07db: Unknown result type (might be due to invalid IL or missing references) //IL_07e6: Unknown result type (might be due to invalid IL or missing references) //IL_07ed: Unknown result type (might be due to invalid IL or missing references) progress = Mathf.Clamp01(progress); float num = progress; switch (instance.scaleCurveType.Value) { case ScaleCurveType.SmoothStep: num = progress * progress * (3f - 2f * progress); break; case ScaleCurveType.QuadIn: num = progress * progress; break; case ScaleCurveType.QuadOut: num = 1f - (1f - progress) * (1f - progress); break; case ScaleCurveType.QuadInOut: num = ((progress < 0.5f) ? (2f * progress * progress) : (1f - Mathf.Pow(-2f * progress + 2f, 2f) / 2f)); break; case ScaleCurveType.CubicIn: num = progress * progress * progress; break; case ScaleCurveType.CubicOut: { float num8 = 1f - progress; num = 1f - num8 * num8 * num8; break; } case ScaleCurveType.CubicInOut: num = ((progress < 0.5f) ? (4f * progress * progress * progress) : (1f - Mathf.Pow(-2f * progress + 2f, 3f) / 2f)); break; case ScaleCurveType.QuartIn: num = progress * progress * progress * progress; break; case ScaleCurveType.QuartOut: { float num4 = 1f - progress; num = 1f - num4 * num4 * num4 * num4; break; } case ScaleCurveType.QuartInOut: num = ((progress < 0.5f) ? (8f * Mathf.Pow(progress, 4f)) : (1f - Mathf.Pow(-2f * progress + 2f, 4f) / 2f)); break; case ScaleCurveType.QuintIn: num = Mathf.Pow(progress, 5f); break; case ScaleCurveType.QuintOut: { float num7 = 1f - progress; num = 1f - Mathf.Pow(num7, 5f); break; } case ScaleCurveType.QuintInOut: num = ((progress < 0.5f) ? (16f * Mathf.Pow(progress, 5f)) : (1f - Mathf.Pow(-2f * progress + 2f, 5f) / 2f)); break; case ScaleCurveType.SineIn: num = 1f - Mathf.Cos(progress * (float)Math.PI / 2f); break; case ScaleCurveType.SineOut: num = Mathf.Sin(progress * (float)Math.PI / 2f); break; case ScaleCurveType.SineInOut: num = (0f - (Mathf.Cos((float)Math.PI * progress) - 1f)) / 2f; break; case ScaleCurveType.ExpoIn: num = ((progress != 0f) ? Mathf.Pow(2f, 10f * (progress - 1f)) : 0f); break; case ScaleCurveType.ExpoOut: num = ((progress != 1f) ? (1f - Mathf.Pow(2f, -10f * progress)) : 1f); break; case ScaleCurveType.ExpoInOut: num = ((progress != 0f) ? ((progress != 1f) ? ((progress < 0.5f) ? (Mathf.Pow(2f, 20f * progress - 10f) / 2f) : ((2f - Mathf.Pow(2f, -20f * progress + 10f)) / 2f)) : 1f) : 0f); break; case ScaleCurveType.CircIn: num = 1f - Mathf.Sqrt(1f - progress * progress); break; case ScaleCurveType.CircOut: { float num6 = progress - 1f; num = Mathf.Sqrt(1f - num6 * num6); break; } case ScaleCurveType.CircInOut: num = ((progress < 0.5f) ? ((1f - Mathf.Sqrt(1f - 4f * progress * progress)) / 2f) : ((Mathf.Sqrt(1f - Mathf.Pow(-2f * progress + 2f, 2f)) + 1f) / 2f)); break; case ScaleCurveType.BackIn: num = 2.70158f * progress * progress * progress - 1.70158f * progress * progress; break; case ScaleCurveType.BackOut: { float num5 = progress - 1f; num = 1f + 2.70158f * num5 * num5 * num5 + 1.70158f * num5 * num5; break; } case ScaleCurveType.BackInOut: num = ((progress < 0.5f) ? (Mathf.Pow(2f * progress, 2f) * (7.189819f * progress - 2.5949094f) / 2f) : ((Mathf.Pow(2f * progress - 2f, 2f) * (3.5949094f * (progress * 2f - 2f) + 2.5949094f) + 2f) / 2f)); break; case ScaleCurveType.ElasticIn: num = ((progress != 0f) ? ((progress != 1f) ? ((0f - Mathf.Pow(2f, 10f * progress - 10f)) * Mathf.Sin((progress * 10f - 10.75f) * ((float)Math.PI * 2f / 3f))) : 1f) : 0f); break; case ScaleCurveType.ElasticOut: num = ((progress != 0f) ? ((progress != 1f) ? (Mathf.Pow(2f, -10f * progress) * Mathf.Sin((progress * 10f - 0.75f) * ((float)Math.PI * 2f / 3f)) + 1f) : 1f) : 0f); break; case ScaleCurveType.ElasticInOut: num = ((progress != 0f) ? ((progress != 1f) ? ((progress < 0.5f) ? ((0f - Mathf.Pow(2f, 20f * progress - 10f) * Mathf.Sin((20f * progress - 11.125f) * ((float)Math.PI * 4f / 9f))) / 2f) : (Mathf.Pow(2f, -20f * progress + 10f) * Mathf.Sin((20f * progress - 11.125f) * ((float)Math.PI * 4f / 9f)) / 2f + 1f)) : 1f) : 0f); break; case ScaleCurveType.BounceIn: num = 1f - Bounce(1f - progress); break; case ScaleCurveType.BounceOut: num = Bounce(progress); break; case ScaleCurveType.BounceInOut: num = ((progress < 0.5f) ? ((1f - Bounce(1f - 2f * progress)) / 2f) : ((1f + Bounce(2f * progress - 1f)) / 2f)); break; case ScaleCurveType.Custom: { List<Vector2> list = instance.customScaleCurvesList; if (list.Count == 0) { num = progress; break; } if (list.Count == 1 || progress <= list[0].x) { num = list[0].y; break; } int num2 = list.Count - 1; if (progress >= list[num2].x) { num = list[num2].y; break; } bool flag = false; for (int i = 0; i < num2; i++) { Vector2 val = list[i]; Vector2 val2 = list[i + 1]; if (progress >= val.x && progress <= val2.x) { float num3 = (progress - val.x) / (val2.x - val.x); num = Mathf.Lerp(val.y, val2.y, num3); flag = true; break; } } if (!flag) { num = list[num2].y; } break; } } return Mathf.Clamp01(num); static float Bounce(float t) { if (t < 0.36363637f) { return 7.5625f * t * t; } if (t < 0.72727275f) { t -= 0.54545456f; return 7.5625f * t * t + 0.75f; } if (t < 0.90909094f) { t -= 0.8181818f; return 7.5625f * t * t + 0.9375f; } t -= 21f / 22f; return 7.5625f * t * t + 63f / 64f; } } public static float GetCurveDirection(float targetProgress, float value) { value = Mathf.Clamp01(value); return instance.scaleCurveDirection.Value switch { ScaleCurveDirection.SameBothWays => (targetProgress == 1f) ? value : (1f - value), ScaleCurveDirection.SameBothWaysFlipped => (targetProgress == 1f) ? (1f - value) : value, _ => value, }; } public static float GetCurveTime(float targetProgress, float progress) { progress = Mathf.Clamp01(progress); float curveDirection = GetCurveDirection(targetProgress, progress); float value = EvaluateScaleCurve(curveDirection); float curveDirection2 = GetCurveDirection(targetProgress, value); return Mathf.Clamp01(curveDirection2); } public static float FindProgressForTime(float targetProgress, float desiredTime) { desiredTime = Mathf.Clamp01(desiredTime); float num = 0f; float num2 = 1f; for (int i = 0; i < 10; i++) { float num3 = 0.5f * (num + num2); float curveTime = GetCurveTime(targetProgress, num3); if (curveTime < desiredTime) { num = num3; } else { num2 = num3; } } return 0.5f * (num + num2); } private void SetupValuableObject(ValuableObject valuableObject, bool isModded = false) { string name = ((Object)valuableObject).name; if (valuableConfigs.ContainsKey(name)) { return; } string text = (isModded ? "Modded " : "") + "Valuable Scaling (" + name + ")"; ValuableConfig valuableConfig = new ValuableConfig(); valuableConfig.generateConfig = ((BaseUnityPlugin)this).Config.Bind<bool>(text, "Generate Config", false, "If enabled, this will generate config for this valuable. (Note: Restarting the game is required.)"); if (valuableConfig.generateConfig.Value) { valuableConfig.useValuableScale = ((BaseUnityPlugin)this).Config.Bind<bool>(text, "Use Valuable Scale", false, "If enabled, this will force the valuable scale to be used no matter what the \"Use Mass Scaling\" and \"Default Scale\" value would be."); valuableConfig.valuableScale = ((BaseUnityPlugin)this).Config.Bind<float>(text, "Valuable Scale", 1f, "Determines the scale factor for this valuable."); valuableConfig.useValuableMassScale = ((BaseUnityPlugin)this).Config.Bind<bool>(text, "Use Valuable Mass Scale", false, "If enabled, this will force the valuable mass scale to be used no matter what the \"Scale Mass\" value would be."); valuableConfig.valuableMassScale = ((BaseUnityPlugin)this).Config.Bind<float>(text, "Valuable Mass Scale", 1f, "Determines the mass scale factor for this valuable."); } valuableConfigs[name] = valuableConfig; if (isModded) { if (moddedCount == -1) { moddedCount = 0; } moddedCount++; } else { vanillaCount++; } } public void LogMessages() { logger.LogMessage((object)$"Found {massScaleFactorsList.Count} mass scale factors."); logger.LogMessage((object)$"Found {customScaleCurvesList.Count} custom scale curves."); logger.LogMessage((object)$"Found {vanillaCount} vanilla valuables."); if (moddedCount != -1) { logger.LogMessage((object)$"Found {moddedCount} modded valuables."); } logger.LogMessage((object)$"Found {valuableConfigs.Count} valuables in total."); } private void Awake() { //IL_0329: Unknown result type (might be due to invalid IL or missing references) //IL_04c2: Unknown result type (might be due to invalid IL or missing references) instance = this; logger = Logger.CreateLogSource("ScaleInCart"); grabObjectsInCarts = new Dictionary<PhysGrabCart, List<PhysGrabObject>>(); grabObjectDatas = new Dictionary<PhysGrabObject, PhysGrabObjectData>(); massScaleFactorsList = new List<Vector2>(); customScaleCurvesList = new List<Vector2>(); string text = "! Debugging !"; printCartNames = ((BaseUnityPlugin)this).Config.Bind<bool>(text, "Print Cart Names", false, "If enabled, the cart names will be printed to the console. (Note: Prints at the start of the level.)"); printValuables = ((BaseUnityPlugin)this).Config.Bind<bool>(text, "Print Valuables", false, "If enabled, the valuables data will be printed to the console. (Note: Prints while grabbing the valuable.)"); string text2 = "! General !"; scaleEverything = ((BaseUnityPlugin)this).Config.Bind<bool>(text2, "Scale Everything", false, "If enabled, every grabbable object will be scaled.\nIf disabled, only valuables will be scaled."); excludeCartNames = ((BaseUnityPlugin)this).Config.Bind<string>(text2, "Exclude Cart Names", "", "Exclude specific carts from scaling their items by listing their names, separated by commas."); revertBackToOriginalScale = ((BaseUnityPlugin)this).Config.Bind<bool>(text2, "Revert Back To Original Scale", true, "If enabled, valuables will revert to their original scale when not in the cart.\nIf disabled, valuables will remain at their modified scale."); string text3 = "! Scaling - General !"; scaleCurveType = ((BaseUnityPlugin)this).Config.Bind<ScaleCurveType>(text3, "Scale Curve Type", ScaleCurveType.Linear, "Determines how valuables scale based on the curving style."); customScaleCurves = ((BaseUnityPlugin)this).Config.Bind<string>(text3, "Custom Scale Curves", "0.0=0.0, 0.3=1.0, 0.5=0.5, 0.7=1.0, 1.0=1.0", "Curve values based on specific time points. Used when \"Scale Curve Type\" is set to Custom.\nFormat: \"time=value\", separated by commas."); scaleCurveDirection = ((BaseUnityPlugin)this).Config.Bind<ScaleCurveDirection>(text3, "Scale Curve Direction", ScaleCurveDirection.SameBothWays, "Determines how the scale curve behaves during scaling."); scaleSpeed = ((BaseUnityPlugin)this).Config.Bind<float>(text3, "Scale Speed", 0.45f, "Determines how quickly valuables scale over time. Higher values make them scale faster."); scaleDelay = ((BaseUnityPlugin)this).Config.Bind<float>(text3, "Scale Delay", 0f, "The initial delay in seconds before valuables begin scaling."); scaleMass = ((BaseUnityPlugin)this).Config.Bind<bool>(text3, "Scale Mass", true, "If enabled, valuables will scale their mass.\nIf disabled, valuables will not scale their mass."); defaultScale = ((BaseUnityPlugin)this).Config.Bind<float>(text3, "Default Scale", 0.8f, "Default scale factor for valuables when \"Use Mass Scaling\" is disabled."); string text4 = "! Scaling - Mass !"; useMassScaling = ((BaseUnityPlugin)this).Config.Bind<bool>(text4, "Use Mass Scaling", true, "If enabled, valuables will scale based on their mass.\nIf disabled, valuables will scale based on their valuable scale or default scale setting."); massScaleFactors = ((BaseUnityPlugin)this).Config.Bind<string>(text4, "Scale Factors", "1.0=0.75, 1.5=0.7, 2.0=0.65, 2.5=0.6, 3.0=0.55, 3.5=0.5, 4.0=0.45, 4.5=0.4, 5.0=0.35", "Scale factors based on minimum mass thresholds.\nFormat: \"mass=scale\", separated by commas."); massScaleDefaultScale = ((BaseUnityPlugin)this).Config.Bind<float>(text4, "Default Scale", 0.8f, "Default scale factor for valuables if no mass threshold is met."); try { string[] array = massScaleFactors.Value.Split(new char[1] { ',' }); foreach (string text5 in array) { string[] array2 = (from x in text5.Split(new char[1] { '=' }) select x.Trim()).ToArray(); if (array2.Length == 2) { float mass = float.Parse(array2[0], CultureInfo.InvariantCulture); if (massScaleFactorsList.Any((Vector2 x) => Mathf.Approximately(x.x, mass))) { logger.LogWarning((object)$"Duplicate found for mass \"{mass}\"."); continue; } float num = float.Parse(array2[1], CultureInfo.InvariantCulture); massScaleFactorsList.Add(new Vector2(mass, num)); } } massScaleFactorsList.Sort((Vector2 a, Vector2 b) => b.x.CompareTo(a.x)); string[] array3 = customScaleCurves.Value.Split(new char[1] { ',' }); foreach (string text6 in array3) { string[] array4 = (from x in text6.Split(new char[1] { '=' }) select x.Trim()).ToArray(); if (array4.Length != 2) { continue; } float num2 = float.Parse(array4[0], CultureInfo.InvariantCulture); bool flag = num2 < 0f || num2 > 1f; float time = Mathf.Clamp01(num2); if (customScaleCurvesList.Any((Vector2 x) => Mathf.Approximately(x.x, time))) { if (flag) { logger.LogWarning((object)$"Duplicate found for time \"{time}\" after clamping from \"{num2}\"."); } else { logger.LogWarning((object)$"Duplicate found for time \"{time}\"."); } } else { float num3 = float.Parse(array4[1], CultureInfo.InvariantCulture); customScaleCurvesList.Add(new Vector2(time, num3)); } } customScaleCurvesList.Sort((Vector2 a, Vector2 b) => a.x.CompareTo(b.x)); } catch (Exception ex) { logger.LogError((object)("Error parsing mass scale factors or custom curve: " + ex.Message)); logger.LogError((object)"Failed to start ScaleInCart."); return; } valuableConfigs = new Dictionary<string, ValuableConfig>(); ValuableObject[] array5 = Resources.LoadAll<ValuableObject>("Valuables/"); foreach (ValuableObject valuableObject in array5) { SetupValuableObject(valuableObject); } harmony.PatchAll(); logger.LogMessage((object)"ScaleInCart has started."); if (REPOLib.IsLoaded()) { REPOLib.OnAwake(); } else { LogMessages(); } } } } namespace ScaleInCart.Structs { public readonly struct PhysGrabObjectScaleData { public readonly float? objectScale; public readonly float? massScale; public PhysGrabObjectScaleData(float? scale, float? massScale) { objectScale = scale; this.massScale = massScale; } } } namespace ScaleInCart.Patches { [HarmonyPatch(typeof(RunManager))] internal class RunManagerPatch { [HarmonyPatch("ChangeLevel")] [HarmonyPrefix] private static void ChangeLevel() { Plugin.instance.grabObjectsInCarts.Clear(); Plugin.instance.grabObjectDatas.Clear(); } } [HarmonyPatch(typeof(PhysGrabObject))] internal class PhysGrabObjectPatch { public const float scaleProgressThreshold = 0.0001f; [HarmonyPatch("Start")] [HarmonyPostfix] private static void Start(PhysGrabObject __instance) { Plugin.instance.grabObjectDatas[__instance] = new PhysGrabObjectData(__instance); } [HarmonyPatch("ResetMass")] [HarmonyPostfix] private static void ResetMass(PhysGrabObject __instance) { Plugin.instance.grabObjectDatas[__instance].originalMass = __instance.massOriginal; } [HarmonyPatch("Update")] [HarmonyPostfix] private static void Update(PhysGrabObject __instance, bool ___isValuable) { //IL_02ef: Unknown result type (might be due to invalid IL or missing references) //IL_02f4: Unknown result type (might be due to invalid IL or missing references) //IL_02f6: Unknown result type (might be due to invalid IL or missing references) //IL_02ff: Unknown result type (might be due to invalid IL or missing references) //IL_0304: Unknown result type (might be due to invalid IL or missing references) //IL_0328: 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_03f3: Unknown result type (might be due to invalid IL or missing references) //IL_03f7: Unknown result type (might be due to invalid IL or missing references) //IL_0398: Unknown result type (might be due to invalid IL or missing references) //IL_0394: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.rb == (Object)null || (Object)(object)((Component)__instance).GetComponentInChildren<MeshRenderer>() == (Object)null || __instance.rb.isKinematic) { return; } ItemEquippable component = ((Component)__instance).GetComponent<ItemEquippable>(); if (((Object)(object)component != (Object)null && component.IsEquipped()) || (!Plugin.instance.scaleEverything.Value && !___isValuable) || !Plugin.instance.grabObjectDatas.TryGetValue(__instance, out var value)) { return; } PhysGrabObjectScaleData scaleData = value.GetScaleData(); float? objectScale = scaleData.objectScale; if (!objectScale.HasValue) { return; } bool shouldScale = true; bool flag = Plugin.instance.grabObjectsInCarts.Any(delegate(KeyValuePair<PhysGrabCart, List<PhysGrabObject>> x) { if (!x.Value.Contains(__instance)) { return false; } shouldScale = !(from y in Plugin.instance.excludeCartNames.Value.Split(new char[1] { ',' }) select y.Trim()).Any((string y) => y.Contains(Plugin.GetBaseName(((Object)x.Key).name))); return true; }); if (!shouldScale) { return; } bool value2 = Plugin.instance.revertBackToOriginalScale.Value; bool valueOrDefault = value.lastIsInCart.GetValueOrDefault(flag); bool flag2 = valueOrDefault != flag; if (!value.lastIsInCart.HasValue) { value.lastIsInCart = flag; value.scaleProgress = (flag ? 1f : 0f); } else if (flag2) { value.lastIsInCart = flag; if (value2) { float scaleProgress = value.scaleProgress; if (scaleProgress <= 0.0001f || scaleProgress >= 0.9999f) { value.scaleProgress = (flag ? 0f : 1f); } else { value.scaleProgress = Plugin.FindProgressForTime(flag ? 1f : 0f, Plugin.GetCurveTime(valueOrDefault ? 1f : 0f, scaleProgress)); } } } float num = (flag ? 1f : ((!value2) ? (-1f) : 0f)); float value3 = Plugin.instance.scaleDelay.Value; if (value3 > 0f && num >= 0f) { float time = Time.time; float num2 = value.lastTime.GetValueOrDefault(time); if (flag2) { num2 = time + value3; value.lastTime = num2; } if (time < num2) { num = -2f; } else { value.lastTime = time; } } value.targetProgress = num; if (num < 0f) { return; } Vector3 originalScale = value.originalScale; Vector3 val = originalScale * objectScale.Value; float originalMass = value.originalMass; float num3 = originalMass * scaleData.massScale.Value; value.scaleProgress = Mathf.MoveTowards(value.scaleProgress, num, Plugin.GetEffectiveUniformScale(originalScale) * Mathf.Max(0f, Plugin.instance.scaleSpeed.Value) * Time.deltaTime); if (Mathf.Abs(value.scaleProgress - num) <= 0.0001f) { value.scaleProgress = num; ((Component)__instance).transform.localScale = ((num == 1f) ? val : originalScale); if (Plugin.instance.scaleMass.Value) { __instance.rb.mass = ((num == 1f) ? num3 : originalMass); } } else { float curveTime = Plugin.GetCurveTime(num, value.scaleProgress); ((Component)__instance).transform.localScale = Vector3.Lerp(originalScale, val, curveTime); if (Plugin.instance.scaleMass.Value) { __instance.rb.mass = Mathf.Lerp(originalMass, num3, curveTime); } } } [HarmonyPatch("GrabStarted")] [HarmonyPostfix] private static void GrabStarted(PhysGrabObject __instance, bool ___grabbedLocal, bool ___isValuable) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) if (!___grabbedLocal || !___isValuable || !Plugin.instance.printValuables.Value || !Plugin.instance.grabObjectDatas.TryGetValue(__instance, out var value)) { return; } PhysGrabObjectScaleData scaleData = value.GetScaleData(); float effectiveUniformScale = Plugin.GetEffectiveUniformScale(value.originalScale); float effectiveUniformScale2 = Plugin.GetEffectiveUniformScale(((Component)__instance).transform.localScale); float? num = null; float? objectScale = scaleData.objectScale; if (objectScale.HasValue) { num = effectiveUniformScale * objectScale.Value; } float originalMass = value.originalMass; float mass = __instance.rb.mass; float? num2 = null; float? massScale = scaleData.massScale; if (massScale.HasValue) { num2 = originalMass * massScale.Value; } string arg = null; float targetProgress = value.targetProgress; float num3 = targetProgress; float num4 = num3; if (num4 != 1f) { if (num4 != 0f) { if (num4 != -1f) { if (num4 == -2f) { arg = "Delayed"; } } else { arg = "None"; } } else { arg = "Out"; } } else { arg = "In"; } float scaleProgress = value.scaleProgress; float num5 = ((targetProgress >= 0f) ? Plugin.GetCurveTime(targetProgress, scaleProgress) : Plugin.EvaluateScaleCurve(scaleProgress)); string text = "---- Valuable: \"" + value.name + "\" ----"; Plugin.instance.logger.LogMessage((object)("\n" + text + "\nOriginal Scale: " + effectiveUniformScale.ToString(CultureInfo.InvariantCulture) + "\nCurrent Scale: " + effectiveUniformScale2.ToString(CultureInfo.InvariantCulture) + "\nTarget Scale: " + (num.HasValue ? num.Value.ToString(CultureInfo.InvariantCulture) : "Unknown") + "\nScale Multiplier: " + (objectScale.HasValue ? objectScale.Value.ToString(CultureInfo.InvariantCulture) : "Unknown") + "\nOriginal Mass: " + originalMass.ToString(CultureInfo.InvariantCulture) + "\nCurrent Mass: " + mass.ToString(CultureInfo.InvariantCulture) + "\nTarget Mass: " + (num2.HasValue ? num2.Value.ToString(CultureInfo.InvariantCulture) : "Unknown") + "\nMass Scale Multiplier: " + (massScale.HasValue ? massScale.Value.ToString(CultureInfo.InvariantCulture) : "Unknown") + "\nRaw Progress: " + scaleProgress.ToString(CultureInfo.InvariantCulture) + "\n" + $"Target Progress: {arg} ({targetProgress})\n" + "Curved Time: " + num5.ToString(CultureInfo.InvariantCulture) + "\n" + new string('-', text.Length))); } } [HarmonyPatch(typeof(PhysGrabCart))] internal class PhysGrabCartPatch { [HarmonyPatch("Start")] [HarmonyPostfix] private static void Start(PhysGrabCart __instance, List<PhysGrabObject> ___itemsInCart) { Plugin.instance.grabObjectsInCarts[__instance] = ___itemsInCart; if (Plugin.instance.printCartNames.Value) { Plugin.instance.logger.LogMessage((object)("Cart Name: \"" + Plugin.GetBaseName(((Object)__instance).name) + "\"")); } } } } namespace ScaleInCart.Enums { internal enum ScaleCurveDirection { SameBothWays, SameBothWaysFlipped, ForwardThenReverse } internal enum ScaleCurveType { Linear, SmoothStep, QuadIn, QuadOut, QuadInOut, CubicIn, CubicOut, CubicInOut, QuartIn, QuartOut, QuartInOut, QuintIn, QuintOut, QuintInOut, SineIn, SineOut, SineInOut, ExpoIn, ExpoOut, ExpoInOut, CircIn, CircOut, CircInOut, BackIn, BackOut, BackInOut, ElasticIn, ElasticOut, ElasticInOut, BounceIn, BounceOut, BounceInOut, Custom } } namespace ScaleInCart.Classes { internal class PhysGrabObjectData { public readonly string name; public readonly Vector3 originalScale; public float originalMass; public float scaleProgress; public float targetProgress; public float? lastTime; public bool? lastIsInCart; public PhysGrabObjectData(PhysGrabObject grabObject) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) name = Plugin.GetBaseName(((Object)grabObject).name); originalScale = ((Component)grabObject).transform.localScale; originalMass = grabObject.massOriginal; targetProgress = -1f; } public PhysGrabObjectScaleData GetScaleData() { float? num = null; float? massScale = null; if (Plugin.instance.valuableConfigs.TryGetValue(name, out var value) && value.generateConfig.Value) { num = (value.useValuableScale.Value ? new float?(value.valuableScale.Value) : ((!Plugin.instance.useMassScaling.Value) ? new float?(Plugin.instance.defaultScale.Value) : new float?(GetScaleByOriginalMass()))); if (value.useValuableMassScale.Value) { massScale = value.valuableMassScale.Value; } } else { num = (Plugin.instance.useMassScaling.Value ? GetScaleByOriginalMass() : Plugin.instance.defaultScale.Value); } if (!massScale.HasValue) { massScale = num; } if (num.HasValue) { num = Mathf.Max(0f, num.Value); } if (massScale.HasValue) { massScale = Mathf.Max(0f, massScale.Value); } return new PhysGrabObjectScaleData(num, massScale); float GetScaleByOriginalMass() { //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) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) foreach (Vector2 massScaleFactors in Plugin.instance.massScaleFactorsList) { if (originalMass >= massScaleFactors.x) { return massScaleFactors.y; } } return Plugin.instance.massScaleDefaultScale.Value; } } } internal class ValuableConfig { public ConfigEntry<bool> generateConfig; public ConfigEntry<bool> useValuableScale; public ConfigEntry<float> valuableScale; public ConfigEntry<bool> useValuableMassScale; public ConfigEntry<float> valuableMassScale; } }