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
Dev 336ad97bc8 Revert "Revert "Improve async bundles (!123)""
This reverts commit 64296e3e62e92cc1b4a77f91384e579008872d95.
2024-05-12 23:22:37 +01:00

56 lines
1.8 KiB
C#

using System;
using System.IO;
using System.Linq;
using System.Reflection;
using Diz.DependencyManager;
using UnityEngine.Build.Pipeline;
using Aki.Custom.Models;
using Aki.Custom.Utils;
using Aki.Reflection.Patching;
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 filepath = rootPath + key;
var dependencies = manifest.GetDirectDependencies(key) ?? Array.Empty<string>();
if (BundleManager.Bundles.TryGetValue(key, out BundleItem bundle))
{
// server bundle
dependencies = (dependencies.Length > 0)
? dependencies.Union(bundle.Dependencies).ToArray()
: bundle.Dependencies;
// set path to either cache (HTTP) or mod (local)
filepath = BundleManager.GetBundleFilePath(bundle);
}
_ = new EasyBundleHelper(__instance)
{
Key = key,
Path = filepath,
KeyWithoutExtension = Path.GetFileNameWithoutExtension(key),
DependencyKeys = dependencies,
LoadState = new BindableState<ELoadState>(ELoadState.Unloaded, null),
BundleLock = bundleLock
};
}
}
}