0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
modules/project/Aki.Custom/Patches/EasyBundlePatch.cs
Merijn Hendriks 245f21c3d8 Improve bundle documentation (!101)
Most of this code was (re-)written in 0.12.9, almost 3 years ago.
Current understanding of how it worked was limited, so I went back and broke it until I understood it properly.

I added comments where I could and slightly altered the logic of `GetManifestJson` to make it easier to read.

Regarding removal of `GetManifestBundle`: you can't. While `Windows.json` contains most of the bundle info, some info (like `Doge`) resides outside of this. Removing `GetManifestBundle` results in the game failing to load.

Reviewed-on: SPT-AKI/Modules#101
Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
Co-committed-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
2024-03-25 09:53:20 +00:00

56 lines
1.8 KiB
C#

using System;
using Aki.Reflection.Patching;
using Diz.DependencyManager;
using UnityEngine.Build.Pipeline;
using System.IO;
using System.Linq;
using System.Reflection;
using Aki.Custom.Models;
using Aki.Custom.Utils;
namespace Aki.Custom.Patches
{
public class EasyBundlePatch : ModulePatch
{
static EasyBundlePatch()
{
_ = nameof(IEasyBundle.SameNameAsset);
_ = nameof(IBundleLock.IsLocked);
_ = nameof(BindableState<ELoadState>.Bind);
}
protected override MethodBase GetTargetMethod()
{
return EasyBundleHelper.Type.GetConstructors()[0];
}
[PatchPostfix]
private static void PatchPostfix(object __instance, string key, string rootPath, CompatibilityAssetBundleManifest manifest, IBundleLock bundleLock)
{
var path = rootPath + key;
var dependencyKeys = manifest.GetDirectDependencies(key) ?? Array.Empty<string>();
if (BundleManager.Bundles.TryGetValue(key, out BundleInfo bundle))
{
// server bundle
dependencyKeys = (dependencyKeys.Length > 0)
? dependencyKeys.Union(bundle.DependencyKeys).ToArray()
: bundle.DependencyKeys;
// set path to either cachedpath (HTTP) or modpath (local)
path = bundle.Path;
}
_ = new EasyBundleHelper(__instance)
{
Key = key,
Path = path,
KeyWithoutExtension = Path.GetFileNameWithoutExtension(key),
DependencyKeys = dependencyKeys,
LoadState = new BindableState<ELoadState>(ELoadState.Unloaded, null),
BundleLock = bundleLock
};
}
}
}