private void AssetBundleLoadingHook(IAssetBundleLoadingContext context) { if (context.Parameters.LoadType != AssetBundleLoadType.LoadFromFile) { return; } var path = context.Parameters.Path; if (path == null) { return; } var abdataIndex = path.IndexOf("/abdata/"); if (abdataIndex == -1) { return; } string bundle = path.Substring(abdataIndex).Replace("/abdata/", ""); if (!File.Exists(path)) { if (BundleManager.Bundles.TryGetValue(bundle, out List <LazyCustom <AssetBundle> > lazyList)) { context.Bundle = lazyList[0].Instance; context.Bundle.name = bundle; context.Complete(); } else { //Create a placeholder asset bundle for png files without a matching asset bundle if (IsPngFolderOnly(bundle)) { context.Bundle = AssetBundleHelper.CreateEmptyAssetBundle(); context.Bundle.name = bundle; context.Complete(); } //Placeholder for .csv excel data else if (Lists.ExternalExcelData.ContainsKey(bundle)) { context.Bundle = AssetBundleHelper.CreateEmptyAssetBundle(); context.Bundle.name = bundle; context.Complete(); } } } else { var ab = AssetBundle.LoadFromFile(context.Parameters.Path, context.Parameters.Crc, context.Parameters.Offset); if (ab != null) { context.Bundle = ab; context.Bundle.name = bundle; context.Complete(); } } }
public void AssetBundleLoading(IAssetBundleLoadingContext context) { if (!File.Exists(context.Parameters.Path)) { // the game is trying to load a path that does not exist, lets redirect to our own resources // obtain different resource path var normalizedPath = context.GetNormalizedPath(); var modFolderPath = Path.Combine("mods", normalizedPath); // if the path exists, let's load that instead if (File.Exists(modFolderPath)) { if (context is AsyncAssetBundleLoadingContext asyncContext) { var request = AssetBundle.LoadFromFileAsync(modFolderPath); asyncContext.Request = request; } else { var bundle = AssetBundle.LoadFromFile(modFolderPath); context.Bundle = bundle; } context.Complete( skipRemainingPrefixes: true, skipOriginalCall: true); } } }
private void AssetBundleLoadingHook(IAssetBundleLoadingContext context) { var normalized = context.GetNormalizedPath(); if (normalized.Contains(@"abdata\")) { if (!context.Parameters.Path.Contains(modFolder) && bundleAbdata.TryGetValue(normalized.Substring(@"abdata\"), out var newPath)) { context.Parameters.Path = newPath; } } }