Example #1
0
        public static async void Postfix(EasyAssets __instance, Task __result)
        {
            await __result;

            string resourcesRoot = "/StreamingAssets/Windows/";
            Dictionary <string, IEasyBundle> dictionary = new Dictionary <string, IEasyBundle>();

            IEasyBundle[] easyBundles = Traverse.Create(__instance).Field("_bundles").GetValue <IEasyBundle[]>();

            if (easyBundles == null)
            {
                return;
            }

            foreach (IEasyBundle easyBundle in easyBundles)
            {
                dictionary.Add(Traverse.Create(easyBundle).Property("Key", null).GetValue <string>(), easyBundle);
            }

            foreach (Manifest manifest in BundlesUtil.Manifests)
            {
                string      entry = manifest.key.Split(new char[] { ':' })[0];
                string      path  = manifest.key.Split(new char[] { ':' })[1];
                IEasyBundle easyBundle;

                if (dictionary.TryGetValue(path, out easyBundle))
                {
                    string filepath = new DirectoryInfo(PatcherConstants.ExecutingAssemblyDirectory).Parent.ToString() + "/" + entry;
                    Traverse.Create(easyBundle).Field("_path").SetValue(filepath + resourcesRoot + path);
                }
            }
        }
 public static void Postfix(EasyAssets __instance, string key, ref string[] __result)
 {
     foreach (Manifest manifest in BundlesUtil.Manifests)
     {
         if (key == manifest.key.Split(new char[] { ':' })[1])
         {
             List <string> first = (__result == null) ? new List <string>() : __result.ToList();
             __result = first.Union(manifest.dependencyKeys).ToList().ToArray <string>();
         }
     }
 }
Example #3
0
        public static async Task Init(EasyAssets __instance, [CanBeNull] IBundleLock bundleLock, string defaultKey, string rootPath, string platformName, [CanBeNull] Func <string, bool> shouldExclude)
        {
            Traverse traverse = Traverse.Create(__instance);
            string   path     = rootPath.Replace("file:///", "").Replace("file://", "") + "/" + platformName + "/";

            AssetBundleCreateRequest manifestLoading = AssetBundle.LoadFromFileAsync(path + platformName);
            await manifestLoading.Await();

            AssetBundle        assetBundle  = manifestLoading.assetBundle;
            AssetBundleRequest assetLoading = assetBundle.LoadAllAssetsAsync();

            await assetLoading.Await();

            traverse.Field <AssetBundleManifest>("Manifest").Value = (AssetBundleManifest)assetLoading.allAssets[0];
            AssetBundleManifest manifest = traverse.Field <AssetBundleManifest>("Manifest").Value;

            //Add ModManifest
            List <string> result = manifest.GetAllAssetBundles().ToList <string>();
            List <string> resourcesModbundles = new List <string>();


            foreach (KeyValuePair <string, BundleInfo> kvp in Settings.bundles)
            {
                resourcesModbundles.Add(kvp.Key);
            }

            string[] bundleNames = result.Union(resourcesModbundles).ToList <string>().ToArray <string>();

            //string[] bundleNames = manifest.GetAllAssetBundles();
            traverse.Field(bundlesFieldName).SetValue(Array.CreateInstance(easyBundleType, bundleNames.Length));
            if (bundleLock == null)
            {
                bundleLock = new BundleLock(int.MaxValue);
            }

            IEasyBundle[] bundles   = traverse.Field(bundlesFieldName).GetValue <IEasyBundle[]>();
            var           startTime = Time.time;

            for (int i = 0; i < bundleNames.Length; i++)
            {
                bundles[i] = (IEasyBundle)Activator.CreateInstance(easyBundleType, new object[] { bundleNames[i], path, manifest, bundleLock });
                await JobScheduler.Yield();
            }

            var endTime = Time.time;

            UnityEngine.Debug.LogError(endTime - startTime);
            traverse.Field(bundlesFieldName).SetValue(bundles);
            traverse.Property <DependencyGraph>("System").Value = new DependencyGraph(bundles, defaultKey, shouldExclude);
        }
        public static bool Prefix(ref EasyAssets __instance, ref Task __result)
        {
            string text = File.ReadAllText(PatcherConstants.ExecutingAssemblyDirectory + "/manifest.json");

            string[] splittedPath = PatcherConstants.ExecutingAssemblyDirectory.Split(new char[] { '\\' });
            string   entry        = splittedPath[splittedPath.Length - 1];

            List <Manifest> manifests = JsonConvert.DeserializeObject <RootObject>(text).manifest;

            foreach (Manifest manifest in manifests)
            {
                manifest.key = entry + ":" + manifest.key;
                BundlesUtil.Manifests.Add(manifest);
            }

            __result = Task.CompletedTask;

            return(true);
        }
Example #5
0
 static bool PatchPrefix(EasyAssets __instance, [CanBeNull] IBundleLock bundleLock, string defaultKey, string rootPath, string platformName, [CanBeNull] Func <string, bool> shouldExclude, ref Task __result)
 {
     __result = Init(__instance, bundleLock, defaultKey, rootPath, platformName, shouldExclude);
     return(false);
 }