using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Text; using HarmonyLib; using MelonLoader; using MelonLoader.Preferences; using MelonLoader.Utils; using Microsoft.CodeAnalysis; using VehicleDeliverySlots; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(/*Could not decode attribute arguments.*/)] [assembly: AssemblyFileVersion("1.1.1.0")] [assembly: AssemblyInformationalVersion("1.1.1")] [assembly: MelonInfo(typeof(VehicleDeliverySlotsMod), "VehicleDeliverySlots", "1.1.1", "Daudr + Codex", "")] [assembly: MelonColor(1, 65, 170, 255)] [assembly: MelonGame("TVGS", "Schedule I")] [assembly: MelonOptionalDependencies(new string[] { "ModsApp" })] [assembly: AssemblyVersion("1.1.1.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : System.Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(/*Could not decode attribute arguments.*/)] internal sealed class NullableAttribute : System.Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(/*Could not decode attribute arguments.*/)] internal sealed class NullableContextAttribute : System.Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(/*Could not decode attribute arguments.*/)] internal sealed class RefSafetyRulesAttribute : System.Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace VehicleDeliverySlots { internal static class DeliveryManagerPatcher { private static Instance? _logger; internal static void Install(Harmony harmony, Instance logger) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Expected O, but got Unknown _logger = logger; System.Type type = FindType("Il2CppScheduleOne.Delivery.DeliveryManager"); if (type == (System.Type)null) { logger.Warning("Could not find Il2CppScheduleOne.Delivery.DeliveryManager. Delivery timer override was not patched."); return; } int num = 0; HarmonyMethod val = new HarmonyMethod(typeof(DeliveryManagerPatcher), "BeforeManagedDelivery", (System.Type[])null); HarmonyMethod val2 = new HarmonyMethod(typeof(DeliveryManagerPatcher), "BeforeReceiveDelivery", (System.Type[])null); MethodInfo[] array = Enumerable.ToArray(Enumerable.Where((System.Collections.Generic.IEnumerable)type.GetMethods((BindingFlags)54), (Func)((MethodInfo method) => ((MemberInfo)method).Name == "SendDelivery" && !((MethodBase)method).IsAbstract && !((MethodBase)method).ContainsGenericParameters))); foreach (MethodInfo val3 in array) { harmony.Patch((MethodBase)(object)val3, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); num++; } array = Enumerable.ToArray(Enumerable.Where((System.Collections.Generic.IEnumerable)type.GetMethods((BindingFlags)54), (Func)((MethodInfo method) => ((MemberInfo)method).Name == "ReceiveDelivery" && !((MethodBase)method).IsAbstract && !((MethodBase)method).ContainsGenericParameters))); foreach (MethodInfo val4 in array) { harmony.Patch((MethodBase)(object)val4, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); num++; } logger.Msg($"Patched {num} DeliveryManager method(s) for vehicle prep and optional delivery timer override."); } public static void BeforeManagedDelivery(object __instance, [HarmonyArgument("delivery")] object delivery) { if (Settings.Enabled.Value && delivery != null && _logger != null) { PrepareDeliveryVehicle(__instance, delivery); } } public static void BeforeReceiveDelivery(object __instance, [HarmonyArgument("delivery")] object delivery) { if (!Settings.Enabled.Value || delivery == null || _logger == null) { return; } PrepareDeliveryVehicle(__instance, delivery); if (Settings.DeliveryTimerOverrideEnabled.Value) { int deliveryTimerOverrideSecondsValue = Settings.DeliveryTimerOverrideSecondsValue; if (SetIntProperty(delivery, "TimeUntilArrival", deliveryTimerOverrideSecondsValue) && Settings.DiscoveryLogging.Value) { string stringProperty = GetStringProperty(delivery, "DeliveryID"); DiscoveryLog.Write($"Applied delivery timer override: {deliveryTimerOverrideSecondsValue}s for delivery ID: {stringProperty}"); } } } private static void PrepareDeliveryVehicle(object deliveryManager, object delivery) { if (_logger == null) { return; } int num = VehicleStorageExpander.Apply(delivery, _logger); string stringProperty = GetStringProperty(delivery, "StoreName"); if (!string.IsNullOrWhiteSpace(stringProperty) && stringProperty != "") { object propertyValue = GetPropertyValue(Invoke(deliveryManager, "GetShopInterface", stringProperty), "DeliveryVehicle"); if (propertyValue != null) { num += VehicleStorageExpander.Apply(propertyValue, _logger); } } if (Settings.DiscoveryLogging.Value) { string stringProperty2 = GetStringProperty(delivery, "DeliveryID"); DiscoveryLog.Write($"Prepared delivery vehicle for delivery ID={stringProperty2}, store={stringProperty}, changed={num}."); } } private static bool SetIntProperty(object instance, string propertyName, int value) { try { PropertyInfo property = instance.GetType().GetProperty(propertyName, (BindingFlags)52); if (property == (PropertyInfo)null || !property.CanWrite || property.PropertyType != typeof(int)) { return false; } property.SetValue(instance, (object)value); return true; } catch { return false; } } private static string GetStringProperty(object instance, string propertyName) { try { PropertyInfo property = instance.GetType().GetProperty(propertyName, (BindingFlags)52); return (((property != null) ? property.GetValue(instance) : null) as string) ?? ""; } catch { return ""; } } private static object? GetPropertyValue(object? instance, string propertyName) { if (instance == null) { return null; } try { PropertyInfo property = instance.GetType().GetProperty(propertyName, (BindingFlags)52); return (property != null) ? property.GetValue(instance) : null; } catch { return null; } } private static object? Invoke(object instance, string methodName, params object[] args) { MethodInfo[] methods = instance.GetType().GetMethods((BindingFlags)52); foreach (MethodInfo val in methods) { if (!(((MemberInfo)val).Name != methodName) && ((MethodBase)val).GetParameters().Length == args.Length) { try { return ((MethodBase)val).Invoke(instance, args); } catch { } } } return null; } private static System.Type? FindType(string fullName) { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly val in assemblies) { try { System.Type type = val.GetType(fullName, false); if (type != (System.Type)null) { return type; } } catch { } } return null; } } internal static class DeliveryQuantityPatcher { [CompilerGenerated] private sealed class d__20 : System.Collections.Generic.IEnumerable, System.Collections.IEnumerable, System.Collections.Generic.IEnumerator, System.IDisposable, System.Collections.IEnumerator { private int <>1__state; private object <>2__current; private int <>l__initialThreadId; private object candidate; public object <>3__candidate; object System.Collections.Generic.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object System.Collections.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__20(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void System.IDisposable.Dispose() { } private bool MoveNext() { object component; object component2; switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = candidate; <>1__state = 1; return true; case 1: { <>1__state = -1; object memberValue = GetMemberValue(candidate, "transform"); if (memberValue != null) { <>2__current = memberValue; <>1__state = 2; return true; } goto IL_007a; } case 2: <>1__state = -1; goto IL_007a; case 3: <>1__state = -1; goto IL_00a5; case 4: { <>1__state = -1; break; } IL_007a: component = GetComponent(candidate, "UnityEngine.RectTransform"); if (component != null) { <>2__current = component; <>1__state = 3; return true; } goto IL_00a5; IL_00a5: component2 = GetComponent(candidate, "UnityEngine.UI.LayoutElement"); if (component2 != null) { <>2__current = component2; <>1__state = 4; return true; } break; } return false; } bool System.Collections.IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void System.Collections.IEnumerator.Reset() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } [DebuggerHidden] System.Collections.Generic.IEnumerator System.Collections.Generic.IEnumerable.GetEnumerator() { d__20 d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; d__ = this; } else { d__ = new d__20(0); } d__.candidate = <>3__candidate; return d__; } [DebuggerHidden] System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return (System.Collections.IEnumerator)((System.Collections.Generic.IEnumerable)this).GetEnumerator(); } } [CompilerGenerated] private sealed class d__25 : System.Collections.Generic.IEnumerable, System.Collections.IEnumerable, System.Collections.Generic.IEnumerator, System.IDisposable, System.Collections.IEnumerator { private int <>1__state; private object <>2__current; private int <>l__initialThreadId; private object value; public object <>3__value; private System.Collections.IEnumerator <>7__wrap1; object System.Collections.Generic.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object System.Collections.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__25(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void System.IDisposable.Dispose() { int num = <>1__state; if (num == -3 || num == 1) { try { } finally { <>m__Finally1(); } } } private bool MoveNext() { try { switch (<>1__state) { default: return false; case 0: <>1__state = -1; if (value == null || value is string) { return false; } if (value is System.Collections.IEnumerable enumerable) { <>7__wrap1 = enumerable.GetEnumerator(); <>1__state = -3; goto IL_0091; } <>2__current = value; <>1__state = 2; return true; case 1: <>1__state = -3; goto IL_0091; case 2: { <>1__state = -1; return false; } IL_0091: while (<>7__wrap1.MoveNext()) { object current = <>7__wrap1.Current; if (current != null) { <>2__current = current; <>1__state = 1; return true; } } <>m__Finally1(); <>7__wrap1 = null; return false; } } catch { //try-fault ((System.IDisposable)this).Dispose(); throw; } } bool System.Collections.IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; if (<>7__wrap1 is System.IDisposable disposable) { disposable.Dispose(); } } [DebuggerHidden] void System.Collections.IEnumerator.Reset() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } [DebuggerHidden] System.Collections.Generic.IEnumerator System.Collections.Generic.IEnumerable.GetEnumerator() { d__25 d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; d__ = this; } else { d__ = new d__25(0); } d__.value = <>3__value; return d__; } [DebuggerHidden] System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return (System.Collections.IEnumerator)((System.Collections.Generic.IEnumerable)this).GetEnumerator(); } } [CompilerGenerated] private sealed class d__45 : System.Collections.Generic.IEnumerable, System.Collections.IEnumerable, System.Collections.Generic.IEnumerator, System.IDisposable, System.Collections.IEnumerator { private int <>1__state; private FieldInfo <>2__current; private int <>l__initialThreadId; private System.Type type; public System.Type <>3__type; private System.Type 5__2; private FieldInfo[] <>7__wrap2; private int <>7__wrap3; FieldInfo System.Collections.Generic.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object System.Collections.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__45(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void System.IDisposable.Dispose() { } private bool MoveNext() { int num = <>1__state; if (num != 0) { if (num != 1) { return false; } <>1__state = -1; <>7__wrap3++; goto IL_0074; } <>1__state = -1; 5__2 = type; goto IL_009c; IL_0074: if (<>7__wrap3 < <>7__wrap2.Length) { FieldInfo val = <>7__wrap2[<>7__wrap3]; <>2__current = val; <>1__state = 1; return true; } <>7__wrap2 = null; 5__2 = 5__2.BaseType; goto IL_009c; IL_009c: if (5__2 != (System.Type)null) { <>7__wrap2 = 5__2.GetFields((BindingFlags)54); <>7__wrap3 = 0; goto IL_0074; } 5__2 = null; return false; } bool System.Collections.IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void System.Collections.IEnumerator.Reset() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } [DebuggerHidden] System.Collections.Generic.IEnumerator System.Collections.Generic.IEnumerable.GetEnumerator() { d__45 d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; d__ = this; } else { d__ = new d__45(0); } d__.type = <>3__type; return d__; } [DebuggerHidden] System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return (System.Collections.IEnumerator)((System.Collections.Generic.IEnumerable)this).GetEnumerator(); } } [CompilerGenerated] private sealed class d__46 : System.Collections.Generic.IEnumerable, System.Collections.IEnumerable, System.Collections.Generic.IEnumerator, System.IDisposable, System.Collections.IEnumerator { private int <>1__state; private MethodInfo <>2__current; private int <>l__initialThreadId; private System.Type type; public System.Type <>3__type; private System.Type 5__2; private MethodInfo[] <>7__wrap2; private int <>7__wrap3; MethodInfo System.Collections.Generic.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object System.Collections.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__46(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void System.IDisposable.Dispose() { } private bool MoveNext() { int num = <>1__state; if (num != 0) { if (num != 1) { return false; } <>1__state = -1; <>7__wrap3++; goto IL_0074; } <>1__state = -1; 5__2 = type; goto IL_009c; IL_0074: if (<>7__wrap3 < <>7__wrap2.Length) { MethodInfo val = <>7__wrap2[<>7__wrap3]; <>2__current = val; <>1__state = 1; return true; } <>7__wrap2 = null; 5__2 = 5__2.BaseType; goto IL_009c; IL_009c: if (5__2 != (System.Type)null) { <>7__wrap2 = 5__2.GetMethods((BindingFlags)54); <>7__wrap3 = 0; goto IL_0074; } 5__2 = null; return false; } bool System.Collections.IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void System.Collections.IEnumerator.Reset() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } [DebuggerHidden] System.Collections.Generic.IEnumerator System.Collections.Generic.IEnumerable.GetEnumerator() { d__46 d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; d__ = this; } else { d__ = new d__46(0); } d__.type = <>3__type; return d__; } [DebuggerHidden] System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return (System.Collections.IEnumerator)((System.Collections.Generic.IEnumerable)this).GetEnumerator(); } } [CompilerGenerated] private sealed class d__44 : System.Collections.Generic.IEnumerable, System.Collections.IEnumerable, System.Collections.Generic.IEnumerator, System.IDisposable, System.Collections.IEnumerator { private int <>1__state; private PropertyInfo <>2__current; private int <>l__initialThreadId; private System.Type type; public System.Type <>3__type; private System.Type 5__2; private PropertyInfo[] <>7__wrap2; private int <>7__wrap3; PropertyInfo System.Collections.Generic.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object System.Collections.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__44(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void System.IDisposable.Dispose() { } private bool MoveNext() { int num = <>1__state; if (num != 0) { if (num != 1) { return false; } <>1__state = -1; <>7__wrap3++; goto IL_0074; } <>1__state = -1; 5__2 = type; goto IL_009c; IL_0074: if (<>7__wrap3 < <>7__wrap2.Length) { PropertyInfo val = <>7__wrap2[<>7__wrap3]; <>2__current = val; <>1__state = 1; return true; } <>7__wrap2 = null; 5__2 = 5__2.BaseType; goto IL_009c; IL_009c: if (5__2 != (System.Type)null) { <>7__wrap2 = 5__2.GetProperties((BindingFlags)54); <>7__wrap3 = 0; goto IL_0074; } 5__2 = null; return false; } bool System.Collections.IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void System.Collections.IEnumerator.Reset() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } [DebuggerHidden] System.Collections.Generic.IEnumerator System.Collections.Generic.IEnumerable.GetEnumerator() { d__44 d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; d__ = this; } else { d__ = new d__44(0); } d__.type = <>3__type; return d__; } [DebuggerHidden] System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return (System.Collections.IEnumerator)((System.Collections.Generic.IEnumerable)this).GetEnumerator(); } } [CompilerGenerated] private sealed class d__24 : System.Collections.Generic.IEnumerable, System.Collections.IEnumerable, System.Collections.Generic.IEnumerator, System.IDisposable, System.Collections.IEnumerator { private int <>1__state; private object <>2__current; private int <>l__initialThreadId; private string componentTypeName; public string <>3__componentTypeName; private object candidate; public object <>3__candidate; private System.Type 5__2; private object[] <>7__wrap2; private int <>7__wrap3; private object 5__5; private System.Collections.Generic.IEnumerator <>7__wrap5; private System.Collections.Generic.IEnumerator <>7__wrap6; object System.Collections.Generic.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object System.Collections.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__24(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void System.IDisposable.Dispose() { int num = <>1__state; if ((uint)(num - -4) > 1u && num != 1) { return; } try { if (num != -4 && num != 1) { return; } try { } finally { <>m__Finally2(); } } finally { <>m__Finally1(); } } private bool MoveNext() { try { int num = <>1__state; if (num != 0) { if (num != 1) { return false; } <>1__state = -4; goto IL_02cd; } <>1__state = -1; 5__2 = FindType(componentTypeName); if (5__2 == (System.Type)null) { return false; } object[] array = Enumerable.ToArray(Enumerable.Distinct(Enumerable.Cast((System.Collections.IEnumerable)Enumerable.Where((System.Collections.Generic.IEnumerable)new object[3] { candidate, GetMemberValue(candidate, "gameObject"), GetMemberValue(candidate, "transform") }, (Func)((object root) => root != null))), (IEqualityComparer)(object)ReferenceEqualityComparer.Instance)); <>7__wrap2 = array; <>7__wrap3 = 0; goto IL_0319; IL_0134: object value = null; MethodInfo current; ParameterInfo[] parameters = ((MethodBase)current).GetParameters(); try { if (((MethodBase)current).IsGenericMethodDefinition && parameters.Length == 0) { value = ((MethodBase)current.MakeGenericMethod(new System.Type[1] { 5__2 })).Invoke(5__5, (object[])null); } else if (((MethodBase)current).IsGenericMethodDefinition && parameters.Length == 1 && parameters[0].ParameterType == typeof(bool)) { value = ((MethodBase)current.MakeGenericMethod(new System.Type[1] { 5__2 })).Invoke(5__5, new object[1] { true }); } else if (!((MethodBase)current).IsGenericMethodDefinition && parameters.Length == 1 && parameters[0].ParameterType == typeof(System.Type)) { value = ((MethodBase)current).Invoke(5__5, new object[1] { 5__2 }); } else if (!((MethodBase)current).IsGenericMethodDefinition && parameters.Length == 2 && parameters[0].ParameterType == typeof(System.Type) && parameters[1].ParameterType == typeof(bool)) { value = ((MethodBase)current).Invoke(5__5, new object[2] { 5__2, true }); } } catch { } <>7__wrap6 = EnumerateObjects(value).GetEnumerator(); <>1__state = -4; goto IL_02cd; IL_0319: if (<>7__wrap3 < <>7__wrap2.Length) { 5__5 = <>7__wrap2[<>7__wrap3]; <>7__wrap5 = GetAllMethods(5__5.GetType()).GetEnumerator(); <>1__state = -3; goto IL_02e7; } <>7__wrap2 = null; return false; IL_02cd: if (((System.Collections.IEnumerator)<>7__wrap6).MoveNext()) { object current2 = <>7__wrap6.Current; <>2__current = current2; <>1__state = 1; return true; } <>m__Finally2(); <>7__wrap6 = null; goto IL_02e7; IL_02e7: while (((System.Collections.IEnumerator)<>7__wrap5).MoveNext()) { current = <>7__wrap5.Current; if (((MemberInfo)current).Name != "GetComponentsInChildren") { continue; } goto IL_0134; } <>m__Finally1(); <>7__wrap5 = null; 5__5 = null; <>7__wrap3++; goto IL_0319; } catch { //try-fault ((System.IDisposable)this).Dispose(); throw; } } bool System.Collections.IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; if (<>7__wrap5 != null) { ((System.IDisposable)<>7__wrap5).Dispose(); } } private void <>m__Finally2() { <>1__state = -3; if (<>7__wrap6 != null) { ((System.IDisposable)<>7__wrap6).Dispose(); } } [DebuggerHidden] void System.Collections.IEnumerator.Reset() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } [DebuggerHidden] System.Collections.Generic.IEnumerator System.Collections.Generic.IEnumerable.GetEnumerator() { d__24 d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; d__ = this; } else { d__ = new d__24(0); } d__.candidate = <>3__candidate; d__.componentTypeName = <>3__componentTypeName; return d__; } [DebuggerHidden] System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return (System.Collections.IEnumerator)((System.Collections.Generic.IEnumerable)this).GetEnumerator(); } } [CompilerGenerated] private sealed class d__18 : System.Collections.Generic.IEnumerable, System.Collections.IEnumerable, System.Collections.Generic.IEnumerator, System.IDisposable, System.Collections.IEnumerator { private int <>1__state; private object <>2__current; private int <>l__initialThreadId; private object input; public object <>3__input; private HashSet 5__2; private object[] <>7__wrap2; private int <>7__wrap3; private object 5__5; private string[] <>7__wrap5; private int <>7__wrap6; private System.Collections.Generic.IEnumerator <>7__wrap7; object System.Collections.Generic.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object System.Collections.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__18(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void System.IDisposable.Dispose() { int num = <>1__state; if (num == -3 || num == 3) { try { } finally { <>m__Finally1(); } } } private bool MoveNext() { try { switch (<>1__state) { default: return false; case 0: <>1__state = -1; 5__2 = new HashSet((IEqualityComparer)(object)ReferenceEqualityComparer.Instance); <>7__wrap2 = Enumerable.ToArray(GetQuantityVisualCandidates(input)); <>7__wrap3 = 0; goto IL_0280; case 1: <>1__state = -1; goto IL_00b1; case 2: <>1__state = -1; goto IL_0169; case 3: { <>1__state = -3; goto IL_0229; } IL_0280: if (<>7__wrap3 < <>7__wrap2.Length) { 5__5 = <>7__wrap2[<>7__wrap3]; if (HasTextSizingMember(5__5) && 5__2.Add(5__5)) { <>2__current = 5__5; <>1__state = 1; return true; } goto IL_00b1; } <>7__wrap2 = null; return false; IL_0229: while (((System.Collections.IEnumerator)<>7__wrap7).MoveNext()) { object current = <>7__wrap7.Current; if (5__2.Add(current)) { <>2__current = current; <>1__state = 3; return true; } } <>m__Finally1(); <>7__wrap7 = null; <>7__wrap6++; goto IL_0251; IL_0251: if (<>7__wrap6 < <>7__wrap5.Length) { string componentTypeName = <>7__wrap5[<>7__wrap6]; <>7__wrap7 = GetComponentsInChildren(5__5, componentTypeName).GetEnumerator(); <>1__state = -3; goto IL_0229; } <>7__wrap5 = null; 5__5 = null; <>7__wrap3++; goto IL_0280; IL_0169: <>7__wrap6++; goto IL_0177; IL_00b1: <>7__wrap5 = new string[10] { "textViewport", "TextViewport", "m_TextViewport", "_textViewport", "textComponent", "TextComponent", "m_TextComponent", "_textComponent", "placeholder", "m_Placeholder" }; <>7__wrap6 = 0; goto IL_0177; IL_0177: if (<>7__wrap6 < <>7__wrap5.Length) { string text = <>7__wrap5[<>7__wrap6]; object memberValue = GetMemberValue(5__5, text); if (memberValue != null && 5__2.Add(memberValue)) { <>2__current = memberValue; <>1__state = 2; return true; } goto IL_0169; } <>7__wrap5 = null; <>7__wrap5 = new string[3] { "TMPro.TMP_Text", "TMPro.TextMeshProUGUI", "UnityEngine.UI.Text" }; <>7__wrap6 = 0; goto IL_0251; } } catch { //try-fault ((System.IDisposable)this).Dispose(); throw; } } bool System.Collections.IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; if (<>7__wrap7 != null) { ((System.IDisposable)<>7__wrap7).Dispose(); } } [DebuggerHidden] void System.Collections.IEnumerator.Reset() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } [DebuggerHidden] System.Collections.Generic.IEnumerator System.Collections.Generic.IEnumerable.GetEnumerator() { d__18 d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; d__ = this; } else { d__ = new d__18(0); } d__.input = <>3__input; return d__; } [DebuggerHidden] System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return (System.Collections.IEnumerator)((System.Collections.Generic.IEnumerable)this).GetEnumerator(); } } [CompilerGenerated] private sealed class d__17 : System.Collections.Generic.IEnumerable, System.Collections.IEnumerable, System.Collections.Generic.IEnumerator, System.IDisposable, System.Collections.IEnumerator { private int <>1__state; private object <>2__current; private int <>l__initialThreadId; private object input; public object <>3__input; private System.Collections.Generic.IEnumerator <>7__wrap1; object System.Collections.Generic.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object System.Collections.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__17(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void System.IDisposable.Dispose() { switch (<>1__state) { case -3: case 1: try { break; } finally { <>m__Finally1(); } case -4: case 2: try { break; } finally { <>m__Finally2(); } case -2: case -1: case 0: break; } } private bool MoveNext() { try { object memberValue; switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>7__wrap1 = EnumerateLocalUiCandidates(input).GetEnumerator(); <>1__state = -3; goto IL_0070; case 1: <>1__state = -3; goto IL_0070; case 2: { <>1__state = -4; goto IL_00fa; } IL_0070: if (((System.Collections.IEnumerator)<>7__wrap1).MoveNext()) { object current = <>7__wrap1.Current; <>2__current = current; <>1__state = 1; return true; } <>m__Finally1(); <>7__wrap1 = null; memberValue = GetMemberValue(input, "InputField", "inputField", "_InputField_k__BackingField"); if (memberValue == null) { break; } <>7__wrap1 = EnumerateLocalUiCandidates(memberValue).GetEnumerator(); <>1__state = -4; goto IL_00fa; IL_00fa: if (((System.Collections.IEnumerator)<>7__wrap1).MoveNext()) { object current2 = <>7__wrap1.Current; <>2__current = current2; <>1__state = 2; return true; } <>m__Finally2(); <>7__wrap1 = null; break; } return false; } catch { //try-fault ((System.IDisposable)this).Dispose(); throw; } } bool System.Collections.IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; if (<>7__wrap1 != null) { ((System.IDisposable)<>7__wrap1).Dispose(); } } private void <>m__Finally2() { <>1__state = -1; if (<>7__wrap1 != null) { ((System.IDisposable)<>7__wrap1).Dispose(); } } [DebuggerHidden] void System.Collections.IEnumerator.Reset() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } [DebuggerHidden] System.Collections.Generic.IEnumerator System.Collections.Generic.IEnumerable.GetEnumerator() { d__17 d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; d__ = this; } else { d__ = new d__17(0); } d__.input = <>3__input; return d__; } [DebuggerHidden] System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return (System.Collections.IEnumerator)((System.Collections.Generic.IEnumerable)this).GetEnumerator(); } } private static Instance? _logger; private static bool _loggedInputPatch; internal static void Install(Harmony harmony, Instance logger) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Expected O, but got Unknown //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Expected O, but got Unknown //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Expected O, but got Unknown //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Expected O, but got Unknown //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Expected O, but got Unknown _logger = logger; int num = 0; System.Type type = FindType("Il2CppScheduleOne.UI.Phone.Delivery.DeliveryShop"); if (type != (System.Type)null) { HarmonyMethod postfix = new HarmonyMethod(typeof(DeliveryQuantityPatcher), "AfterDeliveryShopRefresh", (System.Type[])null); num += TryPatch(harmony, type, "Initialize", null, postfix); num += TryPatch(harmony, type, "Open", null, postfix); num += TryPatch(harmony, type, "RefreshShop", null, postfix); } else { logger.Warning("Could not find Il2CppScheduleOne.UI.Phone.Delivery.DeliveryShop. Delivery quantity shop limit was not patched."); } System.Type type2 = FindType("Il2CppScheduleOne.UI.Phone.Delivery.ListingEntry"); if (type2 != (System.Type)null) { HarmonyMethod postfix2 = new HarmonyMethod(typeof(DeliveryQuantityPatcher), "AfterListingEntryInitialize", (System.Type[])null); HarmonyMethod prefix = new HarmonyMethod(typeof(DeliveryQuantityPatcher), "BeforeSetQuantity", (System.Type[])null); HarmonyMethod prefix2 = new HarmonyMethod(typeof(DeliveryQuantityPatcher), "BeforeChangeQuantity", (System.Type[])null); HarmonyMethod prefix3 = new HarmonyMethod(typeof(DeliveryQuantityPatcher), "BeforeQuantityInputSubmitted", (System.Type[])null); HarmonyMethod prefix4 = new HarmonyMethod(typeof(DeliveryQuantityPatcher), "BeforeValidateInput", (System.Type[])null); num += TryPatch(harmony, type2, "Initialize", null, postfix2); num += TryPatch(harmony, type2, "SetQuantity", prefix, null); num += TryPatch(harmony, type2, "ChangeQuantity", prefix2, null); num += TryPatch(harmony, type2, "OnQuantityInputSubmitted", prefix3, null); num += TryPatch(harmony, type2, "_Initialize_b__16_0", prefix3, null); num += TryPatch(harmony, type2, "ValidateInput", prefix4, null); } else { logger.Warning("Could not find Il2CppScheduleOne.UI.Phone.Delivery.ListingEntry. Four-digit delivery quantity input was not patched."); } logger.Msg($"Patched {num} delivery quantity UI method(s)."); } public static void AfterDeliveryShopRefresh(object __instance) { if (Settings.Enabled.Value && __instance != null) { ApplyShopQuantityPreset(GetMemberValue(__instance, "MatchingShop", "_MatchingShop_k__BackingField")); } } public static void AfterListingEntryInitialize(object __instance) { if (Settings.Enabled.Value && __instance != null) { PrepareListingEntry(__instance); } } public static bool BeforeSetQuantity(object __instance, [HarmonyArgument(0)] int quantity, [HarmonyArgument(1)] bool notify) { if (!Settings.Enabled.Value || __instance == null) { return true; } PrepareListingEntry(__instance); SetQuantityDirect(__instance, ClampForListing(__instance, quantity), notify); return false; } public static bool BeforeChangeQuantity(object __instance, [HarmonyArgument(0)] int change) { if (!Settings.Enabled.Value || __instance == null) { return true; } PrepareListingEntry(__instance); int num = GetIntMember(__instance, "SelectedQuantity", "_SelectedQuantity_k__BackingField"); if (num < 0) { num = 0; } SetQuantityDirect(__instance, ClampForListing(__instance, num + change), notify: true); return false; } public static bool BeforeQuantityInputSubmitted(object __instance, [HarmonyArgument(0)] string value) { if (!Settings.Enabled.Value || __instance == null) { return true; } if (!TryParseQuantity(value, out var quantity)) { SetQuantityDirect(__instance, 0, notify: true); return false; } PrepareListingEntry(__instance); SetQuantityDirect(__instance, ClampForListing(__instance, quantity), notify: true); return false; } public static bool BeforeValidateInput(object __instance) { if (!Settings.Enabled.Value || __instance == null) { return true; } PrepareListingEntry(__instance); string quantityInputText = GetQuantityInputText(__instance); if (string.IsNullOrWhiteSpace(quantityInputText)) { return false; } string text = new string(Enumerable.ToArray(Enumerable.Where((System.Collections.Generic.IEnumerable)quantityInputText, (Func)char.IsDigit))); if (!string.Equals(quantityInputText, text, (StringComparison)4)) { SetQuantityInputText(__instance, text); } if (TryParseQuantity(text, out var quantity) && quantity > Settings.MaxOrderQuantityPerItemValue) { SetQuantityInputText(__instance, Settings.MaxOrderQuantityPerItemValue.ToString()); } return false; } private static int TryPatch(Harmony harmony, System.Type type, string methodName, HarmonyMethod? prefix, HarmonyMethod? postfix) { try { MethodInfo[] array = Enumerable.ToArray(Enumerable.Where((System.Collections.Generic.IEnumerable)type.GetMethods((BindingFlags)54), (Func)((MethodInfo method) => ((MemberInfo)method).Name == methodName && !((MethodBase)method).IsAbstract && !((MethodBase)method).ContainsGenericParameters))); int num = 0; MethodInfo[] array2 = array; foreach (MethodInfo val in array2) { harmony.Patch((MethodBase)(object)val, prefix, postfix, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); num++; if (Settings.DiscoveryLogging.Value) { DiscoveryLog.Write($"Patched {type.FullName}.{((MemberInfo)val).Name} for four-digit delivery quantities"); } } return num; } catch (System.Exception ex) { Instance? logger = _logger; if (logger != null) { logger.Warning($"Could not patch {type.FullName}.{methodName}: {ex.Message}"); } return 0; } } private static void PrepareListingEntry(object entry) { ApplyShopQuantityPreset(GetMemberValue(GetMemberValue(entry, "MatchingListing", "_MatchingListing_k__BackingField"), "Shop", "_Shop_k__BackingField")); object memberValue = GetMemberValue(entry, "QuantityInput"); if (memberValue != null) { int orderQuantityDigitCount = Settings.OrderQuantityDigitCount; SetInputCharacterLimit(memberValue, orderQuantityDigitCount); SetQuantityInputWidth(entry, memberValue); } } private static void ApplyShopQuantityPreset(object? shopInterface) { if (shopInterface == null) { return; } int maxOrderQuantityPerItemValue = Settings.MaxOrderQuantityPerItemValue; int intMember = GetIntMember(shopInterface, "MAX_ITEM_QUANTITY"); if (intMember != maxOrderQuantityPerItemValue) { SetMemberValue(shopInterface, "MAX_ITEM_QUANTITY", maxOrderQuantityPerItemValue); if (Settings.DiscoveryLogging.Value) { DiscoveryLog.Write($"Applied delivery shop quantity preset: MAX_ITEM_QUANTITY {intMember} -> {maxOrderQuantityPerItemValue}"); } } } private static int ClampForListing(object entry, int quantity) { int num = Settings.MaxOrderQuantityPerItemValue; object memberValue = GetMemberValue(entry, "MatchingListing", "_MatchingListing_k__BackingField"); if (memberValue != null && GetBoolMember(memberValue, "LimitedStock")) { int intMember = GetIntMember(memberValue, "CurrentStock", "_CurrentStock_k__BackingField"); if (intMember >= 0) { num = Math.Min(num, intMember); } } return Math.Clamp(quantity, 0, num); } private static void SetQuantityDirect(object entry, int quantity, bool notify) { SetMemberValue(entry, "SelectedQuantity", quantity); SetMemberValue(entry, "_SelectedQuantity_k__BackingField", quantity); SetQuantityInputText(entry, quantity.ToString()); if (notify) { InvokeQuantityChanged(entry, quantity); } if (Settings.DiscoveryLogging.Value) { string stringMember = GetStringMember(GetMemberValue(GetMemberValue(entry, "MatchingListing", "_MatchingListing_k__BackingField"), "Item"), "Name", "ID"); DiscoveryLog.Write($"Set delivery listing quantity: {stringMember} qty={quantity}"); } } private static void InvokeQuantityChanged(object entry, int quantity) { object memberValue = GetMemberValue(entry, "onQuantityChanged"); if (memberValue != null && !TryInvokeByName(memberValue, "Invoke", entry) && !TryInvokeByName(memberValue, "Invoke", quantity)) { TryInvokeByName(memberValue, "Invoke"); } } private static void SetInputCharacterLimit(object input, int characterLimit) { if (SetMemberValue(input, "characterLimit", characterLimit)) { LogInputPatchOnce(characterLimit); return; } object memberValue = GetMemberValue(input, "InputField", "inputField", "_InputField_k__BackingField"); if (memberValue != null && SetMemberValue(memberValue, "characterLimit", characterLimit)) { LogInputPatchOnce(characterLimit); } } private static void SetQuantityInputWidth(object entry, object input) { if (!Settings.FourDigitOrderQuantities.Value) { return; } System.Collections.Generic.IEnumerator enumerator = GetQuantityTextCandidates(input).GetEnumerator(); try { while (((System.Collections.IEnumerator)enumerator).MoveNext()) { object current = enumerator.Current; SetFontSize(current, 20f); EnableTextAutoSizing(current, 16f, 20f); DisableTextWrapping(current); } } finally { ((System.IDisposable)enumerator)?.Dispose(); } } [IteratorStateMachine(typeof(d__17))] private static System.Collections.Generic.IEnumerable GetQuantityVisualCandidates(object input) { System.Collections.Generic.IEnumerator enumerator = EnumerateLocalUiCandidates(input).GetEnumerator(); try { while (((System.Collections.IEnumerator)enumerator).MoveNext()) { yield return enumerator.Current; } } finally { ((System.IDisposable)enumerator)?.Dispose(); } object memberValue = GetMemberValue(input, "InputField", "inputField", "_InputField_k__BackingField"); if (memberValue == null) { yield break; } enumerator = EnumerateLocalUiCandidates(memberValue).GetEnumerator(); try { while (((System.Collections.IEnumerator)enumerator).MoveNext()) { yield return enumerator.Current; } } finally { ((System.IDisposable)enumerator)?.Dispose(); } } [IteratorStateMachine(typeof(d__18))] private static System.Collections.Generic.IEnumerable GetQuantityTextCandidates(object input) { HashSet seen = new HashSet((IEqualityComparer)(object)ReferenceEqualityComparer.Instance); object[] array = Enumerable.ToArray(GetQuantityVisualCandidates(input)); foreach (object owner in array) { if (HasTextSizingMember(owner) && seen.Add(owner)) { yield return owner; } string[] array2 = new string[10] { "textViewport", "TextViewport", "m_TextViewport", "_textViewport", "textComponent", "TextComponent", "m_TextComponent", "_textComponent", "placeholder", "m_Placeholder" }; foreach (string text in array2) { object memberValue = GetMemberValue(owner, text); if (memberValue != null && seen.Add(memberValue)) { yield return memberValue; } } array2 = new string[3] { "TMPro.TMP_Text", "TMPro.TextMeshProUGUI", "UnityEngine.UI.Text" }; foreach (string componentTypeName in array2) { System.Collections.Generic.IEnumerator enumerator = GetComponentsInChildren(owner, componentTypeName).GetEnumerator(); try { while (((System.Collections.IEnumerator)enumerator).MoveNext()) { object current = enumerator.Current; if (seen.Add(current)) { yield return current; } } } finally { ((System.IDisposable)enumerator)?.Dispose(); } } } } private static void EnableTextAutoSizing(object candidate, float minSize, float maxSize) { SetMemberValue(candidate, "enableAutoSizing", true); SetNumericMemberValue(candidate, "fontSizeMin", minSize); SetNumericMemberValue(candidate, "fontSizeMax", maxSize); SetMemberValue(candidate, "resizeTextForBestFit", true); SetNumericMemberValue(candidate, "resizeTextMinSize", minSize); SetNumericMemberValue(candidate, "resizeTextMaxSize", maxSize); } [IteratorStateMachine(typeof(d__20))] private static System.Collections.Generic.IEnumerable EnumerateLocalUiCandidates(object candidate) { yield return candidate; object memberValue = GetMemberValue(candidate, "transform"); if (memberValue != null) { yield return memberValue; } object component = GetComponent(candidate, "UnityEngine.RectTransform"); if (component != null) { yield return component; } object component2 = GetComponent(candidate, "UnityEngine.UI.LayoutElement"); if (component2 != null) { yield return component2; } } private static void SetFontSize(object candidate, float fontSize) { if (HasMember(candidate, "fontSize")) { float floatMember = GetFloatMember(candidate, "fontSize"); if (!(floatMember > 0f) || !(floatMember <= fontSize)) { SetNumericMemberValue(candidate, "fontSize", fontSize); } } } private static void DisableTextWrapping(object candidate) { SetMemberValue(candidate, "enableWordWrapping", false); } private static bool HasTextSizingMember(object candidate) { if (!HasMember(candidate, "fontSize") && !HasMember(candidate, "fontSizeMin")) { return HasMember(candidate, "resizeTextForBestFit"); } return true; } [IteratorStateMachine(typeof(d__24))] private static System.Collections.Generic.IEnumerable GetComponentsInChildren(object candidate, string componentTypeName) { System.Type componentType = FindType(componentTypeName); if (componentType == (System.Type)null) { yield break; } object[] array = Enumerable.ToArray(Enumerable.Distinct(Enumerable.Cast((System.Collections.IEnumerable)Enumerable.Where((System.Collections.Generic.IEnumerable)new object[3] { candidate, GetMemberValue(candidate, "gameObject"), GetMemberValue(candidate, "transform") }, (Func)((object obj2) => obj2 != null))), (IEqualityComparer)(object)ReferenceEqualityComparer.Instance)); object[] array2 = array; foreach (object root in array2) { System.Collections.Generic.IEnumerator enumerator = GetAllMethods(root.GetType()).GetEnumerator(); try { while (((System.Collections.IEnumerator)enumerator).MoveNext()) { MethodInfo current = enumerator.Current; if (((MemberInfo)current).Name != "GetComponentsInChildren") { continue; } object value = null; ParameterInfo[] parameters = ((MethodBase)current).GetParameters(); try { if (((MethodBase)current).IsGenericMethodDefinition && parameters.Length == 0) { value = ((MethodBase)current.MakeGenericMethod(new System.Type[1] { componentType })).Invoke(root, (object[])null); } else if (((MethodBase)current).IsGenericMethodDefinition && parameters.Length == 1 && parameters[0].ParameterType == typeof(bool)) { value = ((MethodBase)current.MakeGenericMethod(new System.Type[1] { componentType })).Invoke(root, new object[1] { true }); } else if (!((MethodBase)current).IsGenericMethodDefinition && parameters.Length == 1 && parameters[0].ParameterType == typeof(System.Type)) { value = ((MethodBase)current).Invoke(root, new object[1] { componentType }); } else if (!((MethodBase)current).IsGenericMethodDefinition && parameters.Length == 2 && parameters[0].ParameterType == typeof(System.Type) && parameters[1].ParameterType == typeof(bool)) { value = ((MethodBase)current).Invoke(root, new object[2] { componentType, true }); } } catch { } System.Collections.Generic.IEnumerator enumerator2 = EnumerateObjects(value).GetEnumerator(); try { while (((System.Collections.IEnumerator)enumerator2).MoveNext()) { yield return enumerator2.Current; } } finally { ((System.IDisposable)enumerator2)?.Dispose(); } } } finally { ((System.IDisposable)enumerator)?.Dispose(); } } } [IteratorStateMachine(typeof(d__25))] private static System.Collections.Generic.IEnumerable EnumerateObjects(object? value) { if (value == null || value is string) { yield break; } if (value is System.Collections.IEnumerable enumerable) { foreach (object item in enumerable) { if (item != null) { yield return item; } } } else { yield return value; } } private static object? GetComponent(object candidate, string componentTypeName) { System.Type type = FindType(componentTypeName); if (type == (System.Type)null) { return null; } object obj = GetMemberValue(candidate, "gameObject") ?? candidate; System.Collections.Generic.IEnumerator enumerator = GetAllMethods(obj.GetType()).GetEnumerator(); try { while (((System.Collections.IEnumerator)enumerator).MoveNext()) { MethodInfo current = enumerator.Current; if (((MemberInfo)current).Name != "GetComponent") { continue; } ParameterInfo[] parameters = ((MethodBase)current).GetParameters(); try { if (((MethodBase)current).IsGenericMethodDefinition && parameters.Length == 0) { return ((MethodBase)current.MakeGenericMethod(new System.Type[1] { type })).Invoke(obj, (object[])null); } if (!((MethodBase)current).IsGenericMethodDefinition && parameters.Length == 1 && parameters[0].ParameterType == typeof(System.Type)) { return ((MethodBase)current).Invoke(obj, new object[1] { type }); } } catch { } } } finally { ((System.IDisposable)enumerator)?.Dispose(); } return null; } private static float GetFloatMember(object? instance, params string[] memberNames) { object memberValue = GetMemberValue(instance, memberNames); if (!(memberValue is float result)) { if (!(memberValue is double num)) { if (memberValue is int num2) { return num2; } return 0f; } return (float)num; } return result; } private static bool HasMember(object instance, string memberName) { if (!Enumerable.Any(GetAllProperties(instance.GetType()), (Func)((PropertyInfo property) => string.Equals(((MemberInfo)property).Name, memberName, (StringComparison)4)))) { return Enumerable.Any(GetAllFields(instance.GetType()), (Func)((FieldInfo field) => string.Equals(((MemberInfo)field).Name, memberName, (StringComparison)4))); } return true; } private static string? GetQuantityInputText(object entry) { object memberValue = GetMemberValue(entry, "QuantityInput"); if (memberValue != null) { return GetInputText(memberValue); } return null; } private static string? GetInputText(object input) { if (GetMemberValue(input, "text", "Text") is string result) { return result; } object memberValue = GetMemberValue(input, "InputField", "inputField", "_InputField_k__BackingField"); if (memberValue == null) { return null; } return GetMemberValue(memberValue, "text", "Text") as string; } private static void SetQuantityInputText(object entry, string text) { object memberValue = GetMemberValue(entry, "QuantityInput"); if (memberValue != null) { SetInputText(memberValue, text); } } private static void SetInputText(object input, string text) { if (!TryInvokeByName(input, "SetTextWithoutNotify", text) && !SetMemberValue(input, "text", text) && !SetMemberValue(input, "Text", text)) { object memberValue = GetMemberValue(input, "InputField", "inputField", "_InputField_k__BackingField"); if (memberValue != null) { TryInvokeByName(memberValue, "SetTextWithoutNotify", text); SetMemberValue(memberValue, "text", text); SetMemberValue(memberValue, "Text", text); } } } private static bool TryParseQuantity(string? value, out int quantity) { quantity = 0; if (string.IsNullOrWhiteSpace(value)) { return false; } return int.TryParse(value.Trim(), ref quantity); } private static void LogInputPatchOnce(int characterLimit) { if (!_loggedInputPatch) { _loggedInputPatch = true; Instance? logger = _logger; if (logger != null) { logger.Msg($"Raised delivery quantity input limit to {characterLimit} digits."); } } } private static object? GetMemberValue(object? instance, params string[] memberNames) { if (instance == null) { return null; } System.Type type = instance.GetType(); foreach (string text in memberNames) { System.Collections.Generic.IEnumerator enumerator = GetAllProperties(type).GetEnumerator(); try { while (((System.Collections.IEnumerator)enumerator).MoveNext()) { PropertyInfo current = enumerator.Current; if (string.Equals(((MemberInfo)current).Name, text, (StringComparison)4) && current.GetIndexParameters().Length == 0) { try { return current.GetValue(instance); } catch { } } } } finally { ((System.IDisposable)enumerator)?.Dispose(); } System.Collections.Generic.IEnumerator enumerator2 = GetAllFields(type).GetEnumerator(); try { while (((System.Collections.IEnumerator)enumerator2).MoveNext()) { FieldInfo current2 = enumerator2.Current; if (string.Equals(((MemberInfo)current2).Name, text, (StringComparison)4)) { try { return current2.GetValue(instance); } catch { } } } } finally { ((System.IDisposable)enumerator2)?.Dispose(); } object obj3 = Invoke(instance, "get_" + text); if (obj3 != null) { return obj3; } } return null; } private static int GetIntMember(object? instance, params string[] memberNames) { object memberValue = GetMemberValue(instance, memberNames); if (!(memberValue is int result)) { if (!(memberValue is uint num)) { if (!(memberValue is short result2)) { if (!(memberValue is ushort result3)) { if (memberValue is byte result4) { return result4; } return -1; } return result3; } return result2; } return (num <= 2147483647) ? ((int)num) : (-1); } return result; } private static bool GetBoolMember(object? instance, params string[] memberNames) { object memberValue = GetMemberValue(instance, memberNames); bool flag = default(bool); int num; if (memberValue is bool) { flag = (bool)memberValue; num = 1; } else { num = 0; } return (byte)((uint)num & (flag ? 1u : 0u)) != 0; } private static string GetStringMember(object? instance, params string[] memberNames) { if (!(GetMemberValue(instance, memberNames) is string text) || string.IsNullOrWhiteSpace(text)) { return ""; } return text; } private static bool SetMemberValue(object instance, string memberName, object value) { System.Collections.Generic.IEnumerator enumerator = GetAllProperties(instance.GetType()).GetEnumerator(); try { while (((System.Collections.IEnumerator)enumerator).MoveNext()) { PropertyInfo current = enumerator.Current; if (string.Equals(((MemberInfo)current).Name, memberName, (StringComparison)4) && current.CanWrite) { try { current.SetValue(instance, value); return true; } catch { } } } } finally { ((System.IDisposable)enumerator)?.Dispose(); } try { FieldInfo field = instance.GetType().GetField(memberName, (BindingFlags)52); if (field != (FieldInfo)null) { field.SetValue(instance, value); return true; } } catch { } return TryInvokeByName(instance, "set_" + memberName, value); } private static bool SetNumericMemberValue(object instance, string memberName, float value) { System.Collections.Generic.IEnumerator enumerator = GetAllProperties(instance.GetType()).GetEnumerator(); try { while (((System.Collections.IEnumerator)enumerator).MoveNext()) { PropertyInfo current = enumerator.Current; if (string.Equals(((MemberInfo)current).Name, memberName, (StringComparison)4) && current.CanWrite && TryConvertNumber(value, current.PropertyType, out object converted)) { try { current.SetValue(instance, converted); return true; } catch { } } } } finally { ((System.IDisposable)enumerator)?.Dispose(); } System.Collections.Generic.IEnumerator enumerator2 = GetAllFields(instance.GetType()).GetEnumerator(); try { while (((System.Collections.IEnumerator)enumerator2).MoveNext()) { FieldInfo current2 = enumerator2.Current; if (string.Equals(((MemberInfo)current2).Name, memberName, (StringComparison)4) && TryConvertNumber(value, current2.FieldType, out object converted2)) { try { current2.SetValue(instance, converted2); return true; } catch { } } } } finally { ((System.IDisposable)enumerator2)?.Dispose(); } if (!TryInvokeByName(instance, "set_" + memberName, value)) { return TryInvokeByName(instance, "set_" + memberName, (int)MathF.Round(value)); } return true; } private static bool TryConvertNumber(float value, System.Type targetType, out object converted) { targetType = Nullable.GetUnderlyingType(targetType) ?? targetType; if (targetType == typeof(float)) { converted = value; return true; } if (targetType == typeof(double)) { converted = (double)value; return true; } if (targetType == typeof(decimal)) { converted = (decimal)value; return true; } if (targetType == typeof(int)) { converted = (int)MathF.Round(value); return true; } if (targetType == typeof(uint)) { converted = (uint)Math.Max(0, (int)MathF.Round(value)); return true; } if (targetType == typeof(short)) { converted = (short)MathF.Round(value); return true; } if (targetType == typeof(ushort)) { converted = (ushort)Math.Max(0, (int)MathF.Round(value)); return true; } if (targetType == typeof(byte)) { converted = (byte)Math.Clamp((int)MathF.Round(value), 0, 255); return true; } converted = value; return false; } private static object? Invoke(object instance, string methodName, params object[] args) { System.Collections.Generic.IEnumerator enumerator = GetAllMethods(instance.GetType()).GetEnumerator(); try { while (((System.Collections.IEnumerator)enumerator).MoveNext()) { MethodInfo current = enumerator.Current; if (string.Equals(((MemberInfo)current).Name, methodName, (StringComparison)4) && ((MethodBase)current).GetParameters().Length == args.Length) { try { return ((MethodBase)current).Invoke(instance, args); } catch { } } } } finally { ((System.IDisposable)enumerator)?.Dispose(); } return null; } private static bool TryInvokeByName(object instance, string methodName, params object[] args) { System.Collections.Generic.IEnumerator enumerator = GetAllMethods(instance.GetType()).GetEnumerator(); try { while (((System.Collections.IEnumerator)enumerator).MoveNext()) { MethodInfo current = enumerator.Current; if (string.Equals(((MemberInfo)current).Name, methodName, (StringComparison)4) && ((MethodBase)current).GetParameters().Length == args.Length) { try { ((MethodBase)current).Invoke(instance, args); return true; } catch { } } } } finally { ((System.IDisposable)enumerator)?.Dispose(); } return false; } [IteratorStateMachine(typeof(d__44))] private static System.Collections.Generic.IEnumerable GetAllProperties(System.Type type) { System.Type current = type; while (current != (System.Type)null) { PropertyInfo[] properties = current.GetProperties((BindingFlags)54); for (int i = 0; i < properties.Length; i++) { yield return properties[i]; } current = current.BaseType; } } [IteratorStateMachine(typeof(d__45))] private static System.Collections.Generic.IEnumerable GetAllFields(System.Type type) { System.Type current = type; while (current != (System.Type)null) { FieldInfo[] fields = current.GetFields((BindingFlags)54); for (int i = 0; i < fields.Length; i++) { yield return fields[i]; } current = current.BaseType; } } [IteratorStateMachine(typeof(d__46))] private static System.Collections.Generic.IEnumerable GetAllMethods(System.Type type) { System.Type current = type; while (current != (System.Type)null) { MethodInfo[] methods = current.GetMethods((BindingFlags)54); for (int i = 0; i < methods.Length; i++) { yield return methods[i]; } current = current.BaseType; } } private static System.Type? FindType(string fullName) { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly val in assemblies) { try { System.Type type = val.GetType(fullName, false); if (type != (System.Type)null) { return type; } } catch { } } return null; } } internal static class DeliveryShopPatcher { private readonly record struct StackInfo(int StackLimit, string Source) { public static StackInfo Unknown => new StackInfo(-1, "unknown"); [CompilerGenerated] public override string ToString() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown StringBuilder val = new StringBuilder(); val.Append("StackInfo"); val.Append(" { "); if (PrintMembers(val)) { val.Append(' '); } val.Append('}'); return ((object)val).ToString(); } [CompilerGenerated] private bool PrintMembers(StringBuilder builder) { builder.Append("StackLimit = "); builder.Append(((object)StackLimit/*cast due to .constrained prefix*/).ToString()); builder.Append(", Source = "); builder.Append((object)Source); return true; } } [CompilerGenerated] private sealed class d__13 : System.Collections.Generic.IEnumerable, System.Collections.IEnumerable, System.Collections.Generic.IEnumerator, System.IDisposable, System.Collections.IEnumerator { private int <>1__state; private FieldInfo <>2__current; private int <>l__initialThreadId; private System.Type type; public System.Type <>3__type; private System.Type 5__2; private FieldInfo[] <>7__wrap2; private int <>7__wrap3; FieldInfo System.Collections.Generic.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object System.Collections.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__13(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void System.IDisposable.Dispose() { } private bool MoveNext() { int num = <>1__state; if (num != 0) { if (num != 1) { return false; } <>1__state = -1; <>7__wrap3++; goto IL_0074; } <>1__state = -1; 5__2 = type; goto IL_009c; IL_0074: if (<>7__wrap3 < <>7__wrap2.Length) { FieldInfo val = <>7__wrap2[<>7__wrap3]; <>2__current = val; <>1__state = 1; return true; } <>7__wrap2 = null; 5__2 = 5__2.BaseType; goto IL_009c; IL_009c: if (5__2 != (System.Type)null) { <>7__wrap2 = 5__2.GetFields((BindingFlags)54); <>7__wrap3 = 0; goto IL_0074; } 5__2 = null; return false; } bool System.Collections.IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void System.Collections.IEnumerator.Reset() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } [DebuggerHidden] System.Collections.Generic.IEnumerator System.Collections.Generic.IEnumerable.GetEnumerator() { d__13 d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; d__ = this; } else { d__ = new d__13(0); } d__.type = <>3__type; return d__; } [DebuggerHidden] System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return (System.Collections.IEnumerator)((System.Collections.Generic.IEnumerable)this).GetEnumerator(); } } [CompilerGenerated] private sealed class d__14 : System.Collections.Generic.IEnumerable, System.Collections.IEnumerable, System.Collections.Generic.IEnumerator, System.IDisposable, System.Collections.IEnumerator { private int <>1__state; private MethodInfo <>2__current; private int <>l__initialThreadId; private System.Type type; public System.Type <>3__type; private System.Type 5__2; private MethodInfo[] <>7__wrap2; private int <>7__wrap3; MethodInfo System.Collections.Generic.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object System.Collections.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__14(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void System.IDisposable.Dispose() { } private bool MoveNext() { int num = <>1__state; if (num != 0) { if (num != 1) { return false; } <>1__state = -1; <>7__wrap3++; goto IL_0074; } <>1__state = -1; 5__2 = type; goto IL_009c; IL_0074: if (<>7__wrap3 < <>7__wrap2.Length) { MethodInfo val = <>7__wrap2[<>7__wrap3]; <>2__current = val; <>1__state = 1; return true; } <>7__wrap2 = null; 5__2 = 5__2.BaseType; goto IL_009c; IL_009c: if (5__2 != (System.Type)null) { <>7__wrap2 = 5__2.GetMethods((BindingFlags)54); <>7__wrap3 = 0; goto IL_0074; } 5__2 = null; return false; } bool System.Collections.IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void System.Collections.IEnumerator.Reset() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } [DebuggerHidden] System.Collections.Generic.IEnumerator System.Collections.Generic.IEnumerable.GetEnumerator() { d__14 d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; d__ = this; } else { d__ = new d__14(0); } d__.type = <>3__type; return d__; } [DebuggerHidden] System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return (System.Collections.IEnumerator)((System.Collections.Generic.IEnumerable)this).GetEnumerator(); } } [CompilerGenerated] private sealed class d__12 : System.Collections.Generic.IEnumerable, System.Collections.IEnumerable, System.Collections.Generic.IEnumerator, System.IDisposable, System.Collections.IEnumerator { private int <>1__state; private PropertyInfo <>2__current; private int <>l__initialThreadId; private System.Type type; public System.Type <>3__type; private System.Type 5__2; private PropertyInfo[] <>7__wrap2; private int <>7__wrap3; PropertyInfo System.Collections.Generic.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object System.Collections.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__12(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void System.IDisposable.Dispose() { } private bool MoveNext() { int num = <>1__state; if (num != 0) { if (num != 1) { return false; } <>1__state = -1; <>7__wrap3++; goto IL_0074; } <>1__state = -1; 5__2 = type; goto IL_009c; IL_0074: if (<>7__wrap3 < <>7__wrap2.Length) { PropertyInfo val = <>7__wrap2[<>7__wrap3]; <>2__current = val; <>1__state = 1; return true; } <>7__wrap2 = null; 5__2 = 5__2.BaseType; goto IL_009c; IL_009c: if (5__2 != (System.Type)null) { <>7__wrap2 = 5__2.GetProperties((BindingFlags)54); <>7__wrap3 = 0; goto IL_0074; } 5__2 = null; return false; } bool System.Collections.IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void System.Collections.IEnumerator.Reset() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } [DebuggerHidden] System.Collections.Generic.IEnumerator System.Collections.Generic.IEnumerable.GetEnumerator() { d__12 d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; d__ = this; } else { d__ = new d__12(0); } d__.type = <>3__type; return d__; } [DebuggerHidden] System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return (System.Collections.IEnumerator)((System.Collections.Generic.IEnumerable)this).GetEnumerator(); } } private static Instance? _logger; private static bool _warnedAboutEstimationFailure; internal static void Install(Harmony harmony, Instance logger) { //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown _logger = logger; System.Type type = FindType("Il2CppScheduleOne.UI.Phone.Delivery.DeliveryShop"); if (type == (System.Type)null) { logger.Warning("Could not find Il2CppScheduleOne.UI.Phone.Delivery.DeliveryShop. Order-size validation was not patched."); return; } MethodInfo method = type.GetMethod("WillCartFitInVehicle", (BindingFlags)54); if (method == (MethodInfo)null) { logger.Warning("Could not find DeliveryShop.WillCartFitInVehicle(). Order-size validation was not patched."); return; } harmony.Patch((MethodBase)(object)method, (HarmonyMethod)null, new HarmonyMethod(typeof(DeliveryShopPatcher), "WillCartFitInVehiclePostfix", (System.Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); logger.Msg("Patched DeliveryShop.WillCartFitInVehicle for modded delivery trunk capacity."); } public static void WillCartFitInVehiclePostfix(object __instance, ref bool __result) { if ((!Settings.Enabled.Value || __instance == null) | __result) { return; } int num = EstimateCartSlots(__instance); if (num <= 0) { if (!_warnedAboutEstimationFailure) { _warnedAboutEstimationFailure = true; Instance? logger = _logger; if (logger != null) { logger.Warning("Could not estimate delivery cart slot usage. Keeping original order-size validation result."); } } return; } int targetSlotsValue = Settings.TargetSlotsValue; if (num > targetSlotsValue) { if (Settings.DiscoveryLogging.Value) { DiscoveryLog.Write($"Delivery cart still too large: {num} stack slots needed, target is {targetSlotsValue}."); } return; } __result = true; if (Settings.DiscoveryLogging.Value) { DiscoveryLog.Write($"Allowed delivery order using modded capacity: {num}/{targetSlotsValue} stack slots."); } } private static int EstimateCartSlots(object deliveryShop) { object memberValue = GetMemberValue(deliveryShop, "listingEntries"); if (memberValue == null) { if (Settings.DiscoveryLogging.Value) { DiscoveryLog.Write("Could not read DeliveryShop.listingEntries."); } return -1; } int listCount = GetListCount(memberValue); if (listCount < 0) { if (Settings.DiscoveryLogging.Value) { DiscoveryLog.Write("Could not read listingEntries.Count from " + memberValue.GetType().FullName + "."); } return -1; } int num = 0; for (int i = 0; i < listCount; i++) { object listItem = GetListItem(memberValue, i); if (listItem == null) { continue; } int intMember = GetIntMember(listItem, "SelectedQuantity", "_SelectedQuantity_k__BackingField"); if (intMember <= 0) { continue; } object memberValue2 = GetMemberValue(listItem, "MatchingListing", "_MatchingListing_k__BackingField"); object obj = ((memberValue2 == null) ? null : GetMemberValue(memberValue2, "Item")); StackInfo stackCapacity = GetStackCapacity(obj); int stackLimit = stackCapacity.StackLimit; if (stackLimit <= 0) { if (Settings.DiscoveryLogging.Value) { string text = memberValue2?.GetType().FullName ?? ""; string text2 = obj?.GetType().FullName ?? ""; DiscoveryLog.Write($"Could not resolve stack limit for cart entry index={i}, quantity={intMember}, listingType={text}, itemType={text2}."); } return -1; } num += (int)Math.Ceiling((double)intMember / (double)stackLimit); if (Settings.DiscoveryLogging.Value) { string stringMember = GetStringMember(obj, "Name", "ID"); DiscoveryLog.Write($"Cart item: {stringMember} qty={intMember}, stack={stackLimit}, slots={(int)Math.Ceiling((double)intMember / (double)stackLimit)}, stackSource={stackCapacity.Source}"); } } return num; } private static StackInfo GetStackCapacity(object? itemDefinition) { if (itemDefinition == null) { return StackInfo.Unknown; } try { List val = new List(); int intMember = GetIntMember(itemDefinition, "StackLimit"); if (intMember > 0) { val.Add(new StackInfo(intMember, "definition.StackLimit")); } int intMember2 = GetIntMember(itemDefinition, "DefaultStackLimit"); if (intMember2 > 0) { val.Add(new StackInfo(intMember2, "definition.DefaultStackLimit")); } object obj = Invoke(itemDefinition, "GetDefaultInstance", 1); if (obj != null) { int intMember3 = GetIntMember(obj, "StackLimit"); if (intMember3 > 0) { val.Add(new StackInfo(intMember3, "instance.StackLimit")); } System.Type type = FindType("Il2CppScheduleOne.ItemFramework.ItemSlot"); object obj2 = ((type == (System.Type)null) ? null : Activator.CreateInstance(type)); if (obj2 != null && Invoke(obj2, "GetCapacityForItem", obj, true) is int num && num > 0) { val.Add(new StackInfo(num, "emptySlot.GetCapacityForItem")); } } return (val.Count == 0) ? StackInfo.Unknown : Enumerable.First((System.Collections.Generic.IEnumerable)Enumerable.OrderBy((System.Collections.Generic.IEnumerable)val, (Func)((StackInfo candidate) => candidate.StackLimit))); } catch { return StackInfo.Unknown; } } private static int GetListCount(object list) { if (list is System.Collections.ICollection collection) { return collection.Count; } return GetIntMember(list, "Count"); } private static object? GetListItem(object list, int index) { if (list is System.Collections.IList list2 && index >= 0 && index < ((System.Collections.ICollection)list2).Count) { return list2[index]; } System.Collections.Generic.IEnumerator enumerator = GetAllProperties(list.GetType()).GetEnumerator(); try { while (((System.Collections.IEnumerator)enumerator).MoveNext()) { PropertyInfo current = enumerator.Current; ParameterInfo[] indexParameters = current.GetIndexParameters(); if (indexParameters.Length == 1 && !(indexParameters[0].ParameterType != typeof(int))) { try { return current.GetValue(list, new object[1] { index }); } catch { } } } } finally { ((System.IDisposable)enumerator)?.Dispose(); } object obj2 = Invoke(list, "get_Item", index); if (obj2 != null) { return obj2; } if (list is System.Collections.IEnumerable enumerable) { int num = 0; foreach (object item in enumerable) { if (num == index) { return item; } num++; } } return null; } private static object? GetMemberValue(object? instance, params string[] memberNames) { if (instance == null) { return null; } System.Type type = instance.GetType(); foreach (string text in memberNames) { System.Collections.Generic.IEnumerator enumerator = GetAllProperties(type).GetEnumerator(); try { while (((System.Collections.IEnumerator)enumerator).MoveNext()) { PropertyInfo current = enumerator.Current; if (string.Equals(((MemberInfo)current).Name, text, (StringComparison)4) && current.GetIndexParameters().Length == 0) { try { return current.GetValue(instance); } catch { } } } } finally { ((System.IDisposable)enumerator)?.Dispose(); } System.Collections.Generic.IEnumerator enumerator2 = GetAllFields(type).GetEnumerator(); try { while (((System.Collections.IEnumerator)enumerator2).MoveNext()) { FieldInfo current2 = enumerator2.Current; if (string.Equals(((MemberInfo)current2).Name, text, (StringComparison)4)) { try { return current2.GetValue(instance); } catch { } } } } finally { ((System.IDisposable)enumerator2)?.Dispose(); } object obj3 = Invoke(instance, "get_" + text); if (obj3 != null) { return obj3; } } return null; } private static int GetIntMember(object? instance, params string[] memberNames) { object memberValue = GetMemberValue(instance, memberNames); if (!(memberValue is int result)) { if (!(memberValue is uint num)) { if (!(memberValue is short result2)) { if (!(memberValue is ushort result3)) { if (memberValue is byte result4) { return result4; } return -1; } return result3; } return result2; } return (num <= 2147483647) ? ((int)num) : (-1); } return result; } private static string GetStringMember(object? instance, params string[] memberNames) { if (GetMemberValue(instance, memberNames) is string text && !string.IsNullOrWhiteSpace(text)) { return text; } return ""; } private static object? Invoke(object instance, string methodName, params object[] args) { System.Collections.Generic.IEnumerator enumerator = GetAllMethods(instance.GetType()).GetEnumerator(); try { while (((System.Collections.IEnumerator)enumerator).MoveNext()) { MethodInfo current = enumerator.Current; if (string.Equals(((MemberInfo)current).Name, methodName, (StringComparison)4) && ((MethodBase)current).GetParameters().Length == args.Length) { try { return ((MethodBase)current).Invoke(instance, args); } catch { } } } } finally { ((System.IDisposable)enumerator)?.Dispose(); } return null; } [IteratorStateMachine(typeof(d__12))] private static System.Collections.Generic.IEnumerable GetAllProperties(System.Type type) { System.Type current = type; while (current != (System.Type)null) { PropertyInfo[] properties = current.GetProperties((BindingFlags)54); for (int i = 0; i < properties.Length; i++) { yield return properties[i]; } current = current.BaseType; } } [IteratorStateMachine(typeof(d__13))] private static System.Collections.Generic.IEnumerable GetAllFields(System.Type type) { System.Type current = type; while (current != (System.Type)null) { FieldInfo[] fields = current.GetFields((BindingFlags)54); for (int i = 0; i < fields.Length; i++) { yield return fields[i]; } current = current.BaseType; } } [IteratorStateMachine(typeof(d__14))] private static System.Collections.Generic.IEnumerable GetAllMethods(System.Type type) { System.Type current = type; while (current != (System.Type)null) { MethodInfo[] methods = current.GetMethods((BindingFlags)54); for (int i = 0; i < methods.Length; i++) { yield return methods[i]; } current = current.BaseType; } } private static System.Type? FindType(string fullName) { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly val in assemblies) { try { System.Type type = val.GetType(fullName, false); if (type != (System.Type)null) { return type; } } catch { } } return null; } } internal static class DeliveryVehiclePatcher { private static Instance? _logger; internal static void Install(Harmony harmony, Instance logger) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Expected O, but got Unknown //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Expected O, but got Unknown _logger = logger; System.Type type = FindType("Il2CppScheduleOne.Delivery.DeliveryVehicle"); if (type == (System.Type)null) { logger.Warning("Could not find Il2CppScheduleOne.Delivery.DeliveryVehicle. No trunk patch was installed."); return; } HarmonyMethod prefix = new HarmonyMethod(typeof(DeliveryVehiclePatcher), "BeforeDeliveryVehicleReady", (System.Type[])null); HarmonyMethod postfix = new HarmonyMethod(typeof(DeliveryVehiclePatcher), "AfterDeliveryVehicleReady", (System.Type[])null); HarmonyMethod prefix2 = new HarmonyMethod(typeof(DeliveryVehiclePatcher), "BeforeItemsAddedToDeliveryVehicle", (System.Type[])null); int num = 0; num += TryPatch(harmony, type, "Activate", prefix, postfix); System.Type type2 = FindType("Il2CppScheduleOne.Delivery.DeliveryInstance"); if (type2 == (System.Type)null) { logger.Warning("Could not find Il2CppScheduleOne.Delivery.DeliveryInstance. Delivery item insertion was not patched."); } else { num += TryPatch(harmony, type2, "AddItemsToDeliveryVehicle", prefix2, null); } logger.Msg($"Patched {num} delivery vehicle/item insertion method(s)."); } private static int TryPatch(Harmony harmony, System.Type type, string methodName, HarmonyMethod? prefix, HarmonyMethod? postfix) { try { MethodInfo[] array = Enumerable.ToArray(Enumerable.Where((System.Collections.Generic.IEnumerable)type.GetMethods((BindingFlags)54), (Func)((MethodInfo method) => ((MemberInfo)method).Name == methodName && !((MethodBase)method).IsAbstract && !((MethodBase)method).ContainsGenericParameters))); int num = 0; MethodInfo[] array2 = array; foreach (MethodInfo val in array2) { harmony.Patch((MethodBase)(object)val, prefix, postfix, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); num++; if (Settings.DiscoveryLogging.Value) { DiscoveryLog.Write("Patched " + type.FullName + "." + ((MemberInfo)val).Name); } } return num; } catch (System.Exception ex) { Instance? logger = _logger; if (logger != null) { logger.Warning($"Could not patch {type.FullName}.{methodName}: {ex.Message}"); } return 0; } } public static void BeforeDeliveryVehicleReady(object __instance) { Expand(__instance); } public static void AfterDeliveryVehicleReady(object __instance) { Expand(__instance); } public static void BeforeItemsAddedToDeliveryVehicle(object __instance) { Expand(__instance); } private static void Expand(object __instance) { if (Settings.Enabled.Value && __instance != null && _logger != null) { VehicleStorageExpander.Apply(__instance, _logger); } } private static System.Type? FindType(string fullName) { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly val in assemblies) { try { System.Type type = val.GetType(fullName, false); if (type != (System.Type)null) { return type; } } catch { } } return null; } } internal static class DiscoveryLog { private static readonly object Sync = new object(); internal static void Write(string line) { try { string text = Path.Combine(string.IsNullOrWhiteSpace(MelonEnvironment.UserDataDirectory) ? Path.Combine(Environment.CurrentDirectory, "UserData") : MelonEnvironment.UserDataDirectory, "VehicleDeliverySlots"); Directory.CreateDirectory(text); string text2 = Path.Combine(text, "discovery.log"); lock (Sync) { File.AppendAllText(text2, $"[{System.DateTime.Now:HH:mm:ss}] {line}{Environment.NewLine}", Encoding.UTF8); } } catch { } } } public static class BuildInfo { public const string Name = "VehicleDeliverySlots"; public const string Author = "Daudr + Codex"; public const string Version = "1.1.1"; public const string DownloadLink = ""; } public sealed class VehicleDeliverySlotsMod : MelonMod { public override void OnInitializeMelon() { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown //IL_004a: Expected O, but got Unknown Settings.Register(); Harmony val = new Harmony("daudr.schedulei.vehicle-delivery-slots"); DeliveryVehiclePatcher.Install(val, ((MelonBase)this).LoggerInstance); DeliveryManagerPatcher.Install(val, ((MelonBase)this).LoggerInstance); DeliveryShopPatcher.Install(val, ((MelonBase)this).LoggerInstance); StorageMenuPatcher.Install(val, ((MelonBase)this).LoggerInstance); DeliveryQuantityPatcher.Install(val, ((MelonBase)this).LoggerInstance); ((MelonBase)this).LoggerInstance.Msg($"Initialized. TargetSlots={Settings.TargetSlotsValue}."); } } internal sealed class ReferenceEqualityComparer : IEqualityComparer { internal static readonly ReferenceEqualityComparer Instance = new ReferenceEqualityComparer(); private ReferenceEqualityComparer() { } public bool Equals(object? x, object? y) { return x == y; } public int GetHashCode(object obj) { return RuntimeHelpers.GetHashCode(obj); } } internal static class Settings { internal const int VanillaTrunkSlots = 16; internal const int DefaultTargetSlots = 24; internal const int MaxTargetSlots = 64; [field: CompilerGenerated] internal static MelonPreferences_Entry Enabled { [CompilerGenerated] get; [CompilerGenerated] private set; } [field: CompilerGenerated] internal static MelonPreferences_Entry TargetSlots { [CompilerGenerated] get; [CompilerGenerated] private set; } [field: CompilerGenerated] internal static MelonPreferences_Entry DiscoveryLogging { [CompilerGenerated] get; [CompilerGenerated] private set; } [field: CompilerGenerated] internal static MelonPreferences_Entry DeliveryTimerOverrideEnabled { [CompilerGenerated] get; [CompilerGenerated] private set; } [field: CompilerGenerated] internal static MelonPreferences_Entry DeliveryTimerOverrideSeconds { [CompilerGenerated] get; [CompilerGenerated] private set; } [field: CompilerGenerated] internal static MelonPreferences_Entry FourDigitOrderQuantities { [CompilerGenerated] get; [CompilerGenerated] private set; } internal static int TargetSlotsValue => Math.Clamp((TargetSlots.Value <= 16) ? 24 : TargetSlots.Value, 17, 64); internal static int DeliveryTimerOverrideSecondsValue => Math.Clamp(DeliveryTimerOverrideSeconds.Value, 1, 600); internal static int MaxOrderQuantityPerItemValue { get { if (!FourDigitOrderQuantities.Value) { return 999; } return 9999; } } internal static int OrderQuantityDigitCount { get { if (!FourDigitOrderQuantities.Value) { return 3; } return 4; } } internal static void Register() { MelonPreferences_Category obj = MelonPreferences.CreateCategory("VehicleDeliverySlots", "Vehicle Delivery Slots"); MelonPreferences_Category val = MelonPreferences.CreateCategory("VehicleDeliverySlots.Timer", "Delivery Timer Override"); MelonPreferences_Category val2 = MelonPreferences.CreateCategory("VehicleDeliverySlots.OrderQuantities", "Delivery Order Quantities"); Enabled = obj.CreateEntry("Enabled", true, "Enabled", "Master toggle. When disabled, no delivery slot or capacity values are changed.", false, false, (ValueValidator)null, (string)null); TargetSlots = obj.CreateEntry("TargetSlots", 24, "Target slots", "Target number of vehicle trunk slots. Vanilla is 16; values from old builds at or below 16 are treated as 24.", false, false, (ValueValidator)null, (string)null); if (TargetSlots.Value <= 16) { TargetSlots.Value = 24; } DiscoveryLogging = obj.CreateEntry("DiscoveryLogging", false, "Discovery logging", "Writes a small troubleshooting log to UserData/VehicleDeliverySlots.", false, false, (ValueValidator)null, (string)null); DeliveryTimerOverrideEnabled = val.CreateEntry("DeliveryTimerOverrideEnabled", true, "Delivery timer override", "Optional built-in delivery arrival timer override. Disable other delivery timer mods when this is enabled.", false, false, (ValueValidator)null, (string)null); DeliveryTimerOverrideSeconds = val.CreateEntry("DeliveryTimerOverrideSeconds", 1, "Delivery timer seconds", "Delivery arrival time used when DeliveryTimerOverrideEnabled is on.", false, false, (ValueValidator)null, (string)null); FourDigitOrderQuantities = val2.CreateEntry("FourDigitOrderQuantities", true, "Four-digit order quantities", "When enabled, delivery item quantities use a 4-digit cap of 9999. Disable for the vanilla 3-digit cap of 999.", false, false, (ValueValidator)null, (string)null); } } internal static class StorageMenuPatcher { private static Instance? _logger; private static bool _loggedCapacityExpansion; private static bool _loggedLayoutFallback; internal static void Install(Harmony harmony, Instance logger) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Expected O, but got Unknown //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Expected O, but got Unknown //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Expected O, but got Unknown _logger = logger; System.Type type = FindType("Il2CppScheduleOne.UI.StorageMenu"); if (type == (System.Type)null) { logger.Warning("Could not find Il2CppScheduleOne.UI.StorageMenu. Large trunk grid layout was not patched."); return; } int num = 0; HarmonyMethod postfix = new HarmonyMethod(typeof(StorageMenuPatcher), "AfterAwake", (System.Type[])null); HarmonyMethod prefix = new HarmonyMethod(typeof(StorageMenuPatcher), "BeforeOpen", (System.Type[])null); HarmonyMethod postfix2 = new HarmonyMethod(typeof(StorageMenuPatcher), "AfterOpen", (System.Type[])null); HarmonyMethod postfix3 = new HarmonyMethod(typeof(StorageMenuPatcher), "AfterClose", (System.Type[])null); num += TryPatch(harmony, type, "Awake", null, postfix); num += TryPatch(harmony, type, "Open", prefix, postfix2); num += TryPatch(harmony, type, "Close", null, postfix3); num += TryPatch(harmony, type, "CloseMenu", null, postfix3); logger.Msg($"Patched {num} storage menu UI method(s) for large delivery trunk grids."); } public static void AfterAwake(object __instance) { if (Settings.Enabled.Value && __instance != null) { EnsureSlotUiCapacity(__instance, 64); } } public static void BeforeOpen(object __instance) { if (Settings.Enabled.Value && __instance != null) { EnsureSlotUiCapacity(__instance, 64); } } public static void AfterOpen(object __instance) { if (Settings.Enabled.Value && __instance != null) { EnsureSlotUiCapacity(__instance, 64); ApplyManagedGrid(__instance); } } public static void AfterClose(object __instance) { if (__instance != null) { ResetContainer(__instance); } } private static int TryPatch(Harmony harmony, System.Type type, string methodName, HarmonyMethod? prefix, HarmonyMethod? postfix) { try { MethodInfo[] array = Enumerable.ToArray(Enumerable.Where((System.Collections.Generic.IEnumerable)type.GetMethods((BindingFlags)54), (Func)((MethodInfo method) => ((MemberInfo)method).Name == methodName && !((MethodBase)method).IsAbstract && !((MethodBase)method).ContainsGenericParameters))); int num = 0; MethodInfo[] array2 = array; foreach (MethodInfo val in array2) { harmony.Patch((MethodBase)(object)val, prefix, postfix, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); num++; if (Settings.DiscoveryLogging.Value) { DiscoveryLog.Write($"Patched {type.FullName}.{((MemberInfo)val).Name} for storage menu grid layout"); } } return num; } catch (System.Exception ex) { Instance? logger = _logger; if (logger != null) { logger.Warning($"Could not patch {type.FullName}.{methodName}: {ex.Message}"); } return 0; } } private static void ApplyManagedGrid(object menu) { if (!VehicleStorageExpander.TryGetManagedRowCount(GetPropertyValue(menu, "OpenedStorageEntity") ?? GetPropertyValue(menu, "_OpenedStorageEntity_k__BackingField"), out var rows)) { return; } object propertyValue = GetPropertyValue(menu, "SlotGridLayout"); if (propertyValue != null && SetIntMember(propertyValue, "constraintCount", rows)) { ApplyVerticalLayout(menu, propertyValue, rows); if (Settings.DiscoveryLogging.Value) { DiscoveryLog.Write($"Applied delivery trunk storage grid rows={rows}, targetSlots={Settings.TargetSlotsValue}"); } } } private static void ApplyVerticalLayout(object menu, object grid, int rows) { float num = GetVectorComponent(GetPropertyValue(grid, "cellSize"), "y") + GetVectorComponent(GetPropertyValue(grid, "spacing"), "y"); if (num <= 0f) { if (!_loggedLayoutFallback) { _loggedLayoutFallback = true; Instance? logger = _logger; if (logger != null) { logger.Warning("Could not read storage grid row height. Using fallback large-trunk layout spacing."); } } num = 90f; } object rectTransformLike = GetRectTransformLike(GetPropertyValue(menu, "CloseButton")); if (rectTransformLike != null) { float num2 = GetVectorComponent(GetPropertyValue(rectTransformLike, "sizeDelta"), "y"); if (num2 <= 0f) { num2 = 50f; } object obj = CreateVector("UnityEngine.Vector2", 0f, (float)(-rows) * num - num2); if (obj != null) { SetMemberValue(rectTransformLike, "anchoredPosition", obj); } } object propertyValue = GetPropertyValue(menu, "Container"); if (propertyValue != null) { float num3 = ((rows > 4) ? ((float)(rows - 4) * num) : 0f); object obj2 = CreateVector("UnityEngine.Vector3", 0f, num3, 0f); if (obj2 != null) { SetMemberValue(propertyValue, "localPosition", obj2); } } } private static void ResetContainer(object menu) { object propertyValue = GetPropertyValue(menu, "Container"); if (propertyValue != null) { object obj = CreateVector("UnityEngine.Vector3", default(float), default(float), default(float)); if (obj != null) { SetMemberValue(propertyValue, "localPosition", obj); } } } private static void EnsureSlotUiCapacity(object menu, int desiredCapacity) { try { object obj = GetPropertyValue(menu, "SlotsUIs") ?? GetPropertyValue(menu, "_SlotsUIs_k__BackingField"); if (obj == null) { return; } int intMember = GetIntMember(obj, "Length"); if (intMember >= desiredCapacity || intMember <= 0) { return; } object propertyValue = GetPropertyValue(menu, "SlotContainer"); object arrayItem = GetArrayItem(obj, 0); object propertyValue2 = GetPropertyValue(arrayItem, "gameObject"); if (propertyValue == null || arrayItem == null || propertyValue2 == null) { return; } object obj2 = CreateIl2CppReferenceArray(obj.GetType(), desiredCapacity); if (obj2 == null) { return; } for (int i = 0; i < intMember; i++) { object arrayItem2 = GetArrayItem(obj, i); if (arrayItem2 != null) { SetArrayItem(obj2, i, arrayItem2); } } for (int j = intMember; j < desiredCapacity; j++) { object obj3 = InstantiateUnityObject(propertyValue2, propertyValue); if (obj3 == null) { return; } string stringMember = GetStringMember(propertyValue2, "name"); if (!string.IsNullOrWhiteSpace(stringMember)) { SetMemberValue(obj3, "name", $"{stringMember} ({j})"); } InvokeByName(obj3, "SetActive", true); object component = GetComponent(obj3, arrayItem.GetType()); if (component == null) { return; } SetArrayItem(obj2, j, component); } SetMemberValue(menu, "SlotsUIs", obj2); SetMemberValue(menu, "_SlotsUIs_k__BackingField", obj2); if (!_loggedCapacityExpansion) { _loggedCapacityExpansion = true; Instance? logger = _logger; if (logger != null) { logger.Msg($"Expanded storage menu UI slot pool: {intMember} -> {desiredCapacity}"); } } } catch (System.Exception ex) { if (Settings.DiscoveryLogging.Value) { DiscoveryLog.Write("Could not expand storage menu UI slot pool: " + ((MemberInfo)ex.GetType()).Name + ": " + ex.Message); } } } private static object? CreateIl2CppReferenceArray(System.Type arrayType, int desiredCapacity) { ConstructorInfo[] constructors = arrayType.GetConstructors((BindingFlags)52); foreach (ConstructorInfo val in constructors) { ParameterInfo[] parameters = ((MethodBase)val).GetParameters(); if (parameters.Length != 1) { continue; } System.Type parameterType = parameters[0].ParameterType; object obj = ((parameterType == typeof(long)) ? ((object)(long)desiredCapacity) : ((parameterType == typeof(int)) ? ((object)desiredCapacity) : ((parameterType == typeof(uint)) ? ((object)(uint)desiredCapacity) : null))); if (obj != null) { try { return val.Invoke(new object[1] { obj }); } catch { } } } return null; } private static object? InstantiateUnityObject(object source, object parent) { System.Type type = FindType("UnityEngine.Object"); if (type == (System.Type)null) { return null; } MethodInfo[] methods = type.GetMethods((BindingFlags)24); foreach (MethodInfo val in methods) { if (((MemberInfo)val).Name != "Instantiate" || ((MethodBase)val).ContainsGenericParameters) { continue; } ParameterInfo[] parameters = ((MethodBase)val).GetParameters(); if (parameters.Length == 2 && parameters[0].ParameterType.IsAssignableFrom(source.GetType()) && parameters[1].ParameterType.IsAssignableFrom(parent.GetType())) { try { return ((MethodBase)val).Invoke((object)null, new object[2] { source, parent }); } catch { } } } return null; } private static object? GetComponent(object gameObject, System.Type componentType) { MethodInfo[] methods = gameObject.GetType().GetMethods((BindingFlags)20); foreach (MethodInfo val in methods) { if (!(((MemberInfo)val).Name != "GetComponent") && ((MethodBase)val).IsGenericMethodDefinition && ((MethodBase)val).GetParameters().Length == 0) { try { return ((MethodBase)val.MakeGenericMethod(new System.Type[1] { componentType })).Invoke(gameObject, (object[])null); } catch { } } } return null; } private static object? GetArrayItem(object? array, int index) { if (array == null) { return null; } MethodInfo[] methods = array.GetType().GetMethods((BindingFlags)52); foreach (MethodInfo val in methods) { if (!(((MemberInfo)val).Name != "get_Item") && ((MethodBase)val).GetParameters().Length == 1) { try { return ((MethodBase)val).Invoke(array, new object[1] { index }); } catch { } } } return null; } private static void SetArrayItem(object array, int index, object value) { MethodInfo[] methods = array.GetType().GetMethods((BindingFlags)52); foreach (MethodInfo val in methods) { if (!(((MemberInfo)val).Name != "set_Item") && ((MethodBase)val).GetParameters().Length == 2) { try { ((MethodBase)val).Invoke(array, new object[2] { index, value }); break; } catch { } } } } private static object? GetRectTransformLike(object? candidate) { if (candidate == null) { return null; } if (HasMember(candidate, "anchoredPosition")) { return candidate; } return GetPropertyValue(candidate, "transform"); } private static bool SetIntMember(object instance, string memberName, int value) { if (!SetMemberValue(instance, memberName, value)) { return TryInvokeByName(instance, "set_" + memberName, value); } return true; } private static int GetIntMember(object? instance, string memberName) { object obj = GetPropertyValue(instance, memberName) ?? GetFieldValue(instance, memberName); if (obj is int) { return (int)obj; } return -1; } private static string GetStringMember(object? instance, string memberName) { return ((GetPropertyValue(instance, memberName) ?? GetFieldValue(instance, memberName)) as string) ?? string.Empty; } private static float GetVectorComponent(object? vector, string componentName) { object obj = GetPropertyValue(vector, componentName) ?? GetFieldValue(vector, componentName); if (!(obj is float result)) { if (!(obj is double num)) { if (obj is int num2) { return num2; } return 0f; } return (float)num; } return result; } private static object? CreateVector(string fullName, params float[] values) { System.Type type = FindType(fullName); if (type == (System.Type)null) { return null; } try { return Activator.CreateInstance(type, Enumerable.ToArray(Enumerable.Cast((System.Collections.IEnumerable)(object)values))); } catch { return null; } } private static bool HasMember(object instance, string memberName) { if (!(instance.GetType().GetProperty(memberName, (BindingFlags)52) != (PropertyInfo)null)) { return instance.GetType().GetField(memberName, (BindingFlags)52) != (FieldInfo)null; } return true; } private static object? GetPropertyValue(object? instance, string propertyName) { if (instance == null) { return null; } try { PropertyInfo property = instance.GetType().GetProperty(propertyName, (BindingFlags)52); return (property != null) ? property.GetValue(instance) : null; } catch { return null; } } private static object? GetFieldValue(object? instance, string fieldName) { if (instance == null) { return null; } try { FieldInfo field = instance.GetType().GetField(fieldName, (BindingFlags)52); return (field != null) ? field.GetValue(instance) : null; } catch { return null; } } private static bool SetMemberValue(object instance, string memberName, object value) { try { PropertyInfo property = instance.GetType().GetProperty(memberName, (BindingFlags)52); if (property != null && property.CanWrite) { property.SetValue(instance, value); return true; } } catch { } try { FieldInfo field = instance.GetType().GetField(memberName, (BindingFlags)52); if (field != (FieldInfo)null) { field.SetValue(instance, value); return true; } } catch { } return false; } private static object? InvokeByName(object instance, string methodName, params object[] args) { MethodInfo[] methods = instance.GetType().GetMethods((BindingFlags)52); foreach (MethodInfo val in methods) { if (!(((MemberInfo)val).Name != methodName) && ((MethodBase)val).GetParameters().Length == args.Length) { try { return ((MethodBase)val).Invoke(instance, args); } catch { } } } return null; } private static bool TryInvokeByName(object instance, string methodName, params object[] args) { MethodInfo[] methods = instance.GetType().GetMethods((BindingFlags)52); foreach (MethodInfo val in methods) { if (!(((MemberInfo)val).Name != methodName) && ((MethodBase)val).GetParameters().Length == args.Length) { try { ((MethodBase)val).Invoke(instance, args); return true; } catch { } } } return false; } private static System.Type? FindType(string fullName) { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly val in assemblies) { try { System.Type type = val.GetType(fullName, false); if (type != (System.Type)null) { return type; } } catch { } } return null; } } internal static class VehicleStorageExpander { private static readonly HashSet LoggedStorages = new HashSet(); private static readonly HashSet LoggedTrimmedStorages = new HashSet(); private static readonly Dictionary ManagedStorageRows = new Dictionary(); internal static int Apply(object candidate, Instance logger) { if (candidate == null) { return 0; } string text = candidate.GetType().FullName ?? ((MemberInfo)candidate.GetType()).Name; if (text == "Il2CppScheduleOne.Delivery.DeliveryVehicle") { object obj = GetPropertyValue(candidate, "Vehicle") ?? GetPropertyValue(candidate, "_Vehicle_k__BackingField"); if (obj != null) { return ExpandLandVehicle(obj, logger, "delivery vehicle"); } return 0; } if (text == "Il2CppScheduleOne.Delivery.DeliveryInstance") { return ExpandDeliveryInstance(candidate, logger); } return 0; } private static int ExpandDeliveryInstance(object deliveryInstance, Instance logger) { int num = 0; object obj = GetPropertyValue(deliveryInstance, "ActiveVehicle") ?? GetPropertyValue(deliveryInstance, "_ActiveVehicle_k__BackingField"); if (obj != null) { num += Apply(obj, logger); } object propertyValue = GetPropertyValue(deliveryInstance, "LoadingDock"); if (propertyValue != null) { num += ExpandLoadingDockOccupant(propertyValue, "DynamicOccupant", "_DynamicOccupant_k__BackingField", logger); num += ExpandLoadingDockOccupant(propertyValue, "StaticOccupant", "_StaticOccupant_k__BackingField", logger); } return num; } private static int ExpandLoadingDockOccupant(object loadingDock, string propertyName, string backingPropertyName, Instance logger) { object obj = GetPropertyValue(loadingDock, propertyName) ?? GetPropertyValue(loadingDock, backingPropertyName); if (obj != null) { return ExpandLandVehicle(obj, logger, "delivery loading dock occupant"); } return 0; } private static int ExpandLandVehicle(object landVehicle, Instance logger, string source) { object propertyValue = GetPropertyValue(landVehicle, "Storage"); if (propertyValue == null) { return 0; } return ExpandStorageEntity(propertyValue, logger, source); } private static int ExpandStorageEntity(object storageEntity, Instance logger, string source) { int num = 0; int targetSlotsValue = Settings.TargetSlotsValue; num += SetIntPropertyIfLower(storageEntity, "MAX_SLOTS", targetSlotsValue); num += SetIntPropertyIfLower(storageEntity, "SlotCount", targetSlotsValue); int num2 = CalculateDisplayRows(targetSlotsValue); num += SetIntPropertyIfDifferent(storageEntity, "DisplayRowCount", num2); RememberManagedStorage(storageEntity, num2); object obj = GetPropertyValue(storageEntity, "ItemSlots") ?? GetPropertyValue(storageEntity, "_ItemSlots_k__BackingField"); if (obj == null) { return num; } int intProperty = GetIntProperty(obj, "Count"); if (intProperty < 0) { return num; } if (intProperty > targetSlotsValue) { int num3 = intProperty; int num4 = TrimEmptyOverflowSlots(obj, targetSlotsValue); if (num4 > 0) { num += num4; SetPropertyValue(storageEntity, "ItemSlots", obj); SetPropertyValue(storageEntity, "_ItemSlots_k__BackingField", obj); LogStorageTrim(storageEntity, source, num3, num3 - num4, targetSlotsValue, logger); } intProperty = GetIntProperty(obj, "Count"); } if (intProperty >= targetSlotsValue) { return num; } System.Type type = FindType("Il2CppScheduleOne.ItemFramework.ItemSlot"); if (type == (System.Type)null) { return num; } MethodInfo method = obj.GetType().GetMethod("Add", (BindingFlags)20); if (method == (MethodInfo)null) { return num; } for (int i = intProperty; i < targetSlotsValue; i++) { object obj2 = Activator.CreateInstance(type); if (obj2 == null) { break; } InvokeIfExists(obj2, "SetSlotOwner", storageEntity); ((MethodBase)method).Invoke(obj, new object[1] { obj2 }); num++; } SetPropertyValue(storageEntity, "ItemSlots", obj); SetPropertyValue(storageEntity, "_ItemSlots_k__BackingField", obj); if (intProperty < targetSlotsValue) { LogStorageExpansion(storageEntity, source, intProperty, targetSlotsValue, logger); } return num; } internal static bool TryGetManagedRowCount(object? storageEntity, out int rows) { rows = 0; if (storageEntity == null) { return false; } int hashCode = ReferenceEqualityComparer.Instance.GetHashCode(storageEntity); if (ManagedStorageRows.TryGetValue(hashCode, ref rows)) { return rows > 0; } return false; } internal static int CalculateDisplayRows(int slots) { if (slots <= 0) { return 1; } if (slots <= 24) { return Math.Max(1, (int)Math.Ceiling((double)slots / 12.0)); } if (slots <= 80) { return Math.Max(1, (int)Math.Ceiling((double)slots / 10.0)); } return Math.Max(1, (int)Math.Ceiling((double)slots / 16.0)); } private static void RememberManagedStorage(object storageEntity, int rows) { int hashCode = ReferenceEqualityComparer.Instance.GetHashCode(storageEntity); ManagedStorageRows[hashCode] = rows; } private static int TrimEmptyOverflowSlots(object itemSlots, int target) { int intProperty = GetIntProperty(itemSlots, "Count"); if (intProperty <= target) { return 0; } MethodInfo method = itemSlots.GetType().GetMethod("RemoveAt", (BindingFlags)20); if (method == (MethodInfo)null) { return 0; } for (int i = target; i < intProperty; i++) { object listItem = GetListItem(itemSlots, i); if (listItem == null || !IsSlotEmpty(listItem)) { return 0; } } int num = 0; for (int num2 = intProperty - 1; num2 >= target; num2--) { try { ((MethodBase)method).Invoke(itemSlots, new object[1] { num2 }); num++; } catch { break; } } return num; } private static object? GetListItem(object list, int index) { try { MethodInfo val = Enumerable.FirstOrDefault((System.Collections.Generic.IEnumerable)list.GetType().GetMethods((BindingFlags)52), (Func)((MethodInfo candidate) => ((MemberInfo)candidate).Name == "get_Item" && ((MethodBase)candidate).GetParameters().Length == 1)); if (val != (MethodInfo)null) { return ((MethodBase)val).Invoke(list, new object[1] { index }); } } catch { } PropertyInfo[] properties = list.GetType().GetProperties((BindingFlags)52); foreach (PropertyInfo val2 in properties) { ParameterInfo[] indexParameters = val2.GetIndexParameters(); if (indexParameters.Length == 1 && !(indexParameters[0].ParameterType != typeof(int))) { try { return val2.GetValue(list, new object[1] { index }); } catch { } } } return null; } private static bool IsSlotEmpty(object slot) { int intProperty = GetIntProperty(slot, "Quantity"); object obj = GetPropertyValue(slot, "ItemInstance") ?? GetPropertyValue(slot, "_ItemInstance_k__BackingField"); if (intProperty <= 0) { return obj == null; } return false; } private static int SetIntPropertyIfLower(object instance, string propertyName, int target) { try { PropertyInfo property = instance.GetType().GetProperty(propertyName, (BindingFlags)52); if (property == (PropertyInfo)null || !property.CanRead || !property.CanWrite || property.PropertyType != typeof(int)) { return 0; } if ((int)property.GetValue(instance) >= target) { return 0; } property.SetValue(instance, (object)target); return 1; } catch { return 0; } } private static int SetIntPropertyIfDifferent(object instance, string propertyName, int target) { try { PropertyInfo property = instance.GetType().GetProperty(propertyName, (BindingFlags)52); if (property == (PropertyInfo)null || !property.CanRead || !property.CanWrite || property.PropertyType != typeof(int)) { return 0; } if ((int)property.GetValue(instance) == target) { return 0; } property.SetValue(instance, (object)target); return 1; } catch { return 0; } } private static object? GetPropertyValue(object instance, string propertyName) { try { PropertyInfo property = instance.GetType().GetProperty(propertyName, (BindingFlags)52); return (property != null) ? property.GetValue(instance) : null; } catch { return null; } } private static void SetPropertyValue(object instance, string propertyName, object value) { try { PropertyInfo property = instance.GetType().GetProperty(propertyName, (BindingFlags)52); if (property != null && property.CanWrite) { property.SetValue(instance, value); } } catch { } } private static int GetIntProperty(object instance, string propertyName) { try { PropertyInfo property = instance.GetType().GetProperty(propertyName, (BindingFlags)52); return (((property != null) ? property.GetValue(instance) : null) is int num) ? num : (-1); } catch { return -1; } } private static string GetStringProperty(object instance, string propertyName) { try { PropertyInfo property = instance.GetType().GetProperty(propertyName, (BindingFlags)52); return (((property != null) ? property.GetValue(instance) : null) as string) ?? string.Empty; } catch { return string.Empty; } } private static void InvokeIfExists(object instance, string methodName, params object[] args) { try { MethodInfo method = instance.GetType().GetMethod(methodName, (BindingFlags)52); if (method != null) { ((MethodBase)method).Invoke(instance, args); } } catch { } } private static System.Type? FindType(string fullName) { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly val in assemblies) { try { System.Type type = val.GetType(fullName, false); if (type != (System.Type)null) { return type; } } catch { } } return null; } private static void LogStorageExpansion(object storageEntity, string source, int oldCount, int target, Instance logger) { int hashCode = ReferenceEqualityComparer.Instance.GetHashCode(storageEntity); if (LoggedStorages.Add(hashCode)) { logger.Msg($"Expanded {source} trunk storage slots: {oldCount} -> {target}"); if (Settings.DiscoveryLogging.Value) { DiscoveryLog.Write($"Expanded {source} {storageEntity.GetType().FullName}: {oldCount} -> {target}"); } } } private static void LogStorageTrim(object storageEntity, string source, int oldCount, int newCount, int target, Instance logger) { int hashCode = ReferenceEqualityComparer.Instance.GetHashCode(storageEntity); if (LoggedTrimmedStorages.Add(hashCode)) { logger.Msg($"Trimmed empty overflow slots for {source}: {oldCount} -> {newCount} (target {target})"); if (Settings.DiscoveryLogging.Value) { DiscoveryLog.Write($"Trimmed empty overflow slots for {source} {storageEntity.GetType().FullName}: {oldCount} -> {newCount} (target {target})"); } } } } }