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
2023-03-03 18:52:31 +00:00

50 lines
1.6 KiB
C#

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) ?? new string[0];
if (BundleManager.Bundles.TryGetValue(key, out BundleInfo bundle))
{
dependencyKeys = (dependencyKeys.Length > 0) ? dependencyKeys.Union(bundle.DependencyKeys).ToArray() : bundle.DependencyKeys;
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
};
}
}
}