public IEnumerator StartAssetLoad(FileSystemInfo handle, LoadOrderType loadOrder, bool allowUnload) { FileInfo file = handle.ConsumeFile(); string bundleID = file.FullName.Replace(file.Name, "") + " : " + file.Name; return(LoadAssetsFromPathAsync(file.FullName, bundleID, "", new string[] { }, loadOrder, allowUnload).TryCatch(e => { OtherLogger.LogError("Failed to load mod (" + bundleID + ")"); OtherLogger.LogError(e.ToString()); LoaderStatus.UpdateProgress(bundleID, 1); LoaderStatus.RemoveActiveLoader(bundleID, true); })); }
public IEnumerator RegisterAssetLoadLate(string bundlePath, string bundleName, LoadOrderType loadOrder) { //In order to get this bundle to load later, we want to replace the file path for the already loaded FVRObject string bundleID = bundlePath.Replace(bundleName, "") + " : " + bundleName.Replace("late_", ""); OtherLoader.ManagedBundles[bundleID] = bundlePath; LoaderStatus.TrackLoader(bundleID, loadOrder); AnvilCallbackBase anvilCallbackBase; if (AnvilManager.m_bundles.TryGetValue(bundleID, out anvilCallbackBase)) { AnvilManager.m_bundles.m_lookup.Remove(bundleID); AnvilManager.m_bundles.m_loading.Remove(anvilCallbackBase); if (OtherLoader.LogLoading.Value) { OtherLogger.Log("Registered asset bundle to load later (" + bundlePath + ")", OtherLogger.LogType.General); OtherLogger.Log("This bundle will replace the data bundle (" + bundleID + ")", OtherLogger.LogType.Loading); } else { OtherLogger.Log("Registered asset bundle to load later (" + bundleName + ")", OtherLogger.LogType.General); OtherLogger.Log("This bundle will replace the data bundle (" + LoaderUtils.GetBundleNameFromUniqueID(bundleID) + ")", OtherLogger.LogType.Loading); } } else { OtherLogger.LogError("Tried to register bundle to load later, but pre-bundle had not yet been loaded! (" + bundleID + ")"); } yield return(null); }
private IEnumerator LoadAssetsFromPathAsync(string path, string bundleID, string guid, string[] dependancies, LoadOrderType loadOrder, bool allowUnload, IEnumerator afterLoad = null) { //Start tracking this bundle and then wait a frame for everything else to be tracked LoaderStatus.TrackLoader(bundleID, loadOrder); yield return(null); //If there are many active loaders at once, we should wait our turn bool overTime = false; while (!LoaderStatus.CanOrderedModLoad(bundleID)) { if (!overTime && Time.time - LoaderStatus.LastLoadEventTime > 30) { OtherLogger.Log("Bundle has been waiting a long time to load! (" + bundleID + ")", OtherLogger.LogType.General); LoaderStatus.PrintWaitingBundles(bundleID); overTime = true; } yield return(null); } //Begin the loading process LoaderStatus.AddActiveLoader(bundleID); if (OtherLoader.LogLoading.Value) { OtherLogger.Log("Beginning async loading of asset bundle (" + bundleID + ")", OtherLogger.LogType.General); } //Load the bundle and apply it's contents float time = Time.time; LoaderStatus.UpdateProgress(bundleID, UnityEngine.Random.Range(.1f, .3f)); AnvilCallback <AssetBundle> bundle = LoaderUtils.LoadAssetBundle(path); yield return(bundle); LoaderStatus.UpdateProgress(bundleID, 0.9f); yield return(ApplyLoadedAssetBundleAsync(bundle, bundleID).TryCatch(e => { OtherLogger.LogError("Failed to load mod (" + bundleID + ")"); OtherLogger.LogError(e.ToString()); LoaderStatus.UpdateProgress(bundleID, 1); LoaderStatus.RemoveActiveLoader(bundleID, true); })); //Log that the bundle is loaded if (OtherLoader.LogLoading.Value) { OtherLogger.Log($"[{(Time.time - time).ToString("0.000")} s] Completed loading bundle ({bundleID})", OtherLogger.LogType.General); } else { OtherLogger.Log($"[{(Time.time - time).ToString("0.000")} s] Completed loading bundle ({LoaderUtils.GetBundleNameFromUniqueID(bundleID)})", OtherLogger.LogType.General); } if (allowUnload && OtherLoader.OptimizeMemory.Value) { OtherLogger.Log("Unloading asset bundle (Optimize Memory is true)", OtherLogger.LogType.Loading); bundle.Result.Unload(false); } else { AnvilManager.m_bundles.Add(bundleID, bundle); } OtherLoader.ManagedBundles.Add(bundleID, path); LoaderStatus.UpdateProgress(bundleID, 1); LoaderStatus.RemoveActiveLoader(bundleID, !(OtherLoader.OptimizeMemory.Value && allowUnload)); if (afterLoad != null) { yield return(afterLoad); } }
public IEnumerator RegisterAssetLoadLate(FileSystemInfo handle, LoadOrderType loadOrder) { FileInfo file = handle.ConsumeFile(); return(RegisterAssetLoadLate(file.FullName, file.Name, loadOrder)); }
public IEnumerator StartAssetLoadDirect(string folderPath, string bundleName, string guid, string[] dependancies, LoadOrderType loadOrder, bool allowUnload) { OtherLogger.Log("Direct Loading Bundle (" + bundleName + ")", OtherLogger.LogType.General); string bundlePath = Path.Combine(folderPath, bundleName); string lateName = "late_" + bundleName; string latePath = Path.Combine(folderPath, lateName); string bundleID = bundlePath.Replace(bundleName, "") + " : " + bundleName; IEnumerator afterLoad = null; if (File.Exists(latePath)) { afterLoad = RegisterAssetLoadLate(latePath, lateName, loadOrder); } return(LoadAssetsFromPathAsync(bundlePath, bundleID, guid, dependancies, loadOrder, allowUnload, afterLoad).TryCatch(e => { OtherLogger.LogError("Failed to load mod (" + bundleID + ")"); OtherLogger.LogError(e.ToString()); LoaderStatus.UpdateProgress(bundleID, 1); LoaderStatus.RemoveActiveLoader(bundleID, true); })); }
public RequireAttribute(string requirement, LoadOrderType order) { Requirement = requirement; Order = order; }
public BundleInfo(string BundleID, LoadOrderType LoadOrderType) { this.BundleID = BundleID; this.LoadOrderType = LoadOrderType; Status = BundleStatus.Waiting; }
public void AddToLoadOrder(string bundleID, LoadOrderType loadOrderType) { BundleInfo bundleInfo = new BundleInfo(bundleID, loadOrderType); //If this is replacing an already loaded bundle (load late), remove the old instances //Also, update the new bundle info to be marked as unloaded if (bundleInfoDic.ContainsKey(bundleID)) { BundleInfo oldInfo = bundleInfoDic[bundleID]; bundleInfoDic.Remove(bundleID); loadFirst.Remove(oldInfo); loadUnordered.Remove(oldInfo); loadLast.Remove(oldInfo); bundleInfo.Status = BundleStatus.Unloaded; bundleInfo.LoadOrderType = oldInfo.LoadOrderType; if (oldInfo.Status != BundleStatus.Loaded && oldInfo.Status != BundleStatus.Unloaded) { OtherLogger.LogError("Tracking a late bundle, but the data bundle isn't already loaded! Data bundle status: " + oldInfo.Status); } } //If this is a new bundle, we should decide if it is able to start being loaded immediately else { if (loadOrderType == LoadOrderType.LoadFirst) { if (loadFirst.Count == 0 || loadFirst.All(o => o.Status == BundleStatus.Loaded || o.Status == BundleStatus.Unloaded)) { bundleInfo.Status = BundleStatus.CanLoad; } //When adding load first bundles, there must never be unordered or load last bundles already added if (loadUnordered.Count != 0 || loadLast.Count != 0) { OtherLogger.LogError($"Mod is set to load first, but it looks like unordered or load last mods are already loading! BundleID ({bundleID})"); loadUnordered.ForEach(o => OtherLogger.LogError($"Load Unordered BundleID ({o.BundleID})")); loadLast.ForEach(o => OtherLogger.LogError($"Load Last BundleID ({o.BundleID})")); } } if (loadOrderType == LoadOrderType.LoadUnordered) { if (loadFirst.Count == 0 || loadFirst.All(o => o.Status == BundleStatus.Loaded || o.Status == BundleStatus.Unloaded)) { bundleInfo.Status = BundleStatus.CanLoad; } //When adding load unordered bundles, there must never be load last bundles already added if (loadLast.Count != 0) { OtherLogger.LogError($"Mod is set to load unordered, but it looks like load last mods are already loading! BundleID ({bundleID})"); loadLast.ForEach(o => OtherLogger.LogError($"Load Last BundleID ({o.BundleID})")); } } if (loadOrderType == LoadOrderType.LoadLast) { if ((loadFirst.Count == 0 && loadUnordered.Count == 0 && loadLast.Count == 0) || (loadFirst.All(o => o.Status == BundleStatus.Loaded || o.Status == BundleStatus.Unloaded) && loadUnordered.All(o => o.Status == BundleStatus.Loaded || o.Status == BundleStatus.Unloaded) && loadLast.All(o => o.Status == BundleStatus.Loaded || o.Status == BundleStatus.Unloaded))) { bundleInfo.Status = BundleStatus.CanLoad; } } } bundleInfoDic.Add(bundleID, bundleInfo); if (loadOrderType == LoadOrderType.LoadFirst) { loadFirst.Add(bundleInfo); } else if (loadOrderType == LoadOrderType.LoadLast) { loadLast.Add(bundleInfo); } else if (loadOrderType == LoadOrderType.LoadUnordered) { loadUnordered.Add(bundleInfo); } }