From 20b177e2f19e834ecac02ca30ade55253e8105b1 Mon Sep 17 00:00:00 2001 From: kianzzarrin Date: Thu, 23 Jun 2022 00:11:22 +0300 Subject: [PATCH] disable cloud packages --- LoadOrderIPatch/Patches/CMPatch.cs | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/LoadOrderIPatch/Patches/CMPatch.cs b/LoadOrderIPatch/Patches/CMPatch.cs index be41dca..2f2c3f6 100644 --- a/LoadOrderIPatch/Patches/CMPatch.cs +++ b/LoadOrderIPatch/Patches/CMPatch.cs @@ -310,32 +310,21 @@ public static void LogExceptionInLOM(Exception ex) { public void LoadCloudPackagesPatch(AssemblyDefinition CM) { Log.Called(); var module = CM.MainModule; - var mTarget = module.GetMethod("ColossalFramework.PlatformServices.Cloud.GetEnumerator"); + var mTarget = module.GetMethod("ColossalFramework.Packaging.PackageManager.LoadCloudPackages"); ILProcessor ilProcessor = mTarget.Body.GetILProcessor(); var instructions = mTarget.Body.Instructions; - var ret = instructions.Last(); - - var mGetCloudEnumerator = typeof(CMPatch).GetMethod(nameof(GetCloudEnumerator)); - var callGetCloudEnumerator = Instruction.Create(OpCodes.Call, module.ImportReference(mGetCloudEnumerator)); - - // if GetCloudEnumerator returned non-null, return it. - // otherwise continue with the main code. - var returnIfTrue = Instruction.Create(OpCodes.Brtrue_S, ret); + var last = instructions.Last(); - ilProcessor.Prefix( - callGetCloudEnumerator, - returnIfTrue); + var mIsCloudEnabled = typeof(CMPatch).GetMethod(nameof(IsCloudEnabled)); + var callIsCloudEnabled = Instruction.Create(OpCodes.Call, module.ImportReference(mIsCloudEnabled)); + var skipIfFalse = Instruction.Create(OpCodes.Brfalse, last); + ilProcessor.Prefix(callIsCloudEnabled, skipIfFalse); Log.Successful(); } - public static IEnumerator GetCloudEnumerator() { - if(ColossalFramework.PlatformServices.PlatformService.cloud.enabled) { - return null; // fall back to default behavior. - } else { - return new object[0].GetEnumerator(); // no cloud objects - } - } + public static bool IsCloudEnabled() => + ColossalFramework.PlatformServices.PlatformService.cloud?.enabled ?? false; public AssemblyDefinition NoCustomAssetsPatch(AssemblyDefinition CM) {