Пример #1
0
        public static bool LoaderConstructor(object __instance, string key, string rootPath, AssetBundleManifest manifest, GInterface251 bundleLock, ref string ___string_1, ref string ___string_0, ref Task ___task_0, ref GInterface251 ___ginterface251_0)
        {
            SetPropertyValue(__instance, key, "Key");
            ___string_1 = rootPath + key;
            ___string_0 = Path.GetFileNameWithoutExtension(key);
            if (manifest != null)
            {
                SetPropertyValue(__instance, manifest.GetDirectDependencies(key), "DependencyKeys");
            }
            SetPropertyValue(__instance, new GClass2166 <ELoadState>(ELoadState.Unloaded), "LoadState");
            ___task_0          = null;
            ___ginterface251_0 = bundleLock;

            return(false);
        }
Пример #2
0
        public static bool LoaderPrefix(object __instance, GInterface251 ___ginterface251_0, bool ___bool_0, ref Task ___task_0, ref string ___string_1, string ___string_0, ref Task __result)
        {
            try
            {
                if (!File.Exists(___string_1) && CachedBundles.ContainsKey(___string_1))
                {
                    ___string_1 = CachedBundles[___string_1];
                }

                ___task_0 = LoadTarkovBundle(__instance, ___ginterface251_0, ___bool_0, ___string_1, ___string_0);
                __result  = ___task_0;
            }
            catch (Exception e)
            {
                MelonLogger.Log(e.ToString());
            }

            return(false);
        }
Пример #3
0
        private static async Task LoadTarkovBundle(object instance, GInterface251 gInterface239, bool bool_0, string bundleFilePath, string bundleVirtualPath)
        {
            var key = GetPropertyValue(instance, "Key").ToString();
            var loadStateInstance = _loadState.GetValue(instance);

            while (gInterface239.IsLocked)
            {
                if (!bool_0)
                {
                    _taskField.SetValue(instance, null);
                    return;
                }

                await Delay(100);
            }

            if (!bool_0)
            {
                _taskField.SetValue(instance, null);
                return;
            }

            gInterface239.Lock();

            if (ModdedAssets.ContainsKey(key))
            {
                MelonLogger.Log($"Patching bundle {key} with modded assets...");

                //AssetBundle assetBundle;
                var request = AssetBundle.LoadFromFileAsync(ModdedBundlePaths[key]);
                if (request == null)
                {
                    MelonLogger.LogError("Error: could not load bundle: " + key);
                    _loadStateProperty.SetValue(loadStateInstance, ELoadState.Failed);
                    gInterface239.Unlock();
                    _taskField.SetValue(instance, null);
                    return;
                }

                while (!request.isDone && request.progress < 1)
                {
                    SetPropertyValue(instance, request.progress * 0.5f, "Progress");
                    await Delay(100);
                }

                var assetBundle = request.assetBundle;

                if (assetBundle == null)
                {
                    MelonLogger.LogError("Error: could not load bundle: " + key +
                                         " at path " + bundleFilePath);
                    _loadStateProperty.SetValue(loadStateInstance, ELoadState.Failed);
                    gInterface239.Unlock();
                    SetPropertyValue(instance, 0f, "Progress");
                    _taskField.SetValue(instance, null);
                    return;
                }

                SetPropertyValue(instance, 0.5f, "Progress");

                var assetsRequest = assetBundle.LoadAllAssetsAsync();
                while (!assetsRequest.isDone && assetsRequest.progress < 1)
                {
                    await Delay(100);
                }
                var assetsList = assetsRequest.allAssets;

                SetPropertyValue(instance, 0.9f, "Progress");

                var sameName = assetsList.Where(x => x.name == bundleVirtualPath);
                if (sameName.Any())
                {
                    SetPropertyValue(instance, sameName.First(), "SameNameAsset");
                }


                SetPropertyValue(instance, assetsList.ToArray(), "Assets");
                _loadStateProperty.SetValue(loadStateInstance, ELoadState.Loaded);
                gInterface239.Unlock();
                SetPropertyValue(instance, 1f, "Progress");
                _taskField.SetValue(instance, null);
                _bundleField.SetValue(instance, assetBundle);
            }
            else
            {
                var request = AssetBundle.LoadFromFileAsync(bundleFilePath);
                if (request == null)
                {
                    MelonLogger.LogError("Error: could not load bundle: " + key);
                    _loadStateProperty.SetValue(loadStateInstance, ELoadState.Failed);
                    gInterface239.Unlock();
                    _taskField.SetValue(instance, null);
                    return;
                }

                while (!request.isDone && request.progress < 1)
                {
                    SetPropertyValue(instance, request.progress * 0.5f, "Progress");
                    await Delay(100);
                }

                var assetBundle = request.assetBundle;

                if (assetBundle == null)
                {
                    MelonLogger.LogError("Error: could not load bundle: " + key +
                                         " at path " + bundleFilePath);
                    _loadStateProperty.SetValue(loadStateInstance, ELoadState.Failed);
                    gInterface239.Unlock();
                    SetPropertyValue(instance, 0f, "Progress");
                    _taskField.SetValue(instance, null);
                    return;
                }

                SetPropertyValue(instance, 0.5f, "Progress");
                var assetBundleRequest = assetBundle.LoadAllAssetsAsync();
                while (!assetBundleRequest.isDone && assetBundleRequest.progress < 1)
                {
                    SetPropertyValue(instance, 0.5f + assetBundleRequest.progress * 0.4f, "Progress");
                    await Delay(100);
                }

                SetPropertyValue(instance, assetBundleRequest.allAssets, "Assets");

                foreach (var asset in assetBundleRequest.allAssets)
                {
                    if (asset.name != bundleVirtualPath)
                    {
                        continue;
                    }
                    SetPropertyValue(instance, asset, "SameNameAsset");
                    _taskField.SetValue(instance, null);
                    break;
                }

                _loadStateProperty.SetValue(loadStateInstance, ELoadState.Loaded);
                gInterface239.Unlock();
                SetPropertyValue(instance, 1f, "Progress");
                _taskField.SetValue(instance, null);
                _bundleField.SetValue(instance, assetBundle);
            }
        }