Skip to content

Commit

Permalink
disable cloud packages
Browse files Browse the repository at this point in the history
  • Loading branch information
kianzarrin committed Jun 22, 2022
1 parent 93f6d8f commit 20b177e
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions LoadOrderIPatch/Patches/CMPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,32 +310,21 @@ public class CMPatch : IPatch {
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)
{
Expand Down

0 comments on commit 20b177e

Please sign in to comment.