示例#1
0
 public static IEnumerable <T> GetAllInFolder(string folderPath)
 {
     if (!UnityData.IsInMainThread)
     {
         Log.Error("Tried to get all resources in a folder \"" + folderPath + "\" from a different thread. All resources must be loaded in the main thread.", false);
     }
     else
     {
         foreach (ModContentPack mod in LoadedModManager.RunningMods)
         {
             foreach (T item in mod.GetContentHolder <T>().GetAllUnderPath(folderPath))
             {
                 yield return(item);
             }
         }
         T[] items = null;
         if (typeof(T) == typeof(Texture2D))
         {
             items = (T[])Resources.LoadAll <Texture2D>(GenFilePaths.ContentPath <Texture2D>() + folderPath);
         }
         if (typeof(T) == typeof(AudioClip))
         {
             items = (T[])Resources.LoadAll <AudioClip>(GenFilePaths.ContentPath <AudioClip>() + folderPath);
         }
         if (items != null)
         {
             T[] array = items;
             for (int i = 0; i < array.Length; i++)
             {
                 T item2 = array[i];
                 yield return(item2);
             }
         }
     }
 }
示例#2
0
        public static IEnumerable <LoadedContentItem <T> > LoadAllForMod(ModContentPack mod)
        {
            string        contentDirPath = Path.Combine(mod.RootDir, GenFilePaths.ContentPath <T>());
            DirectoryInfo contentDir     = new DirectoryInfo(contentDirPath);

            if (contentDir.Exists)
            {
                DeepProfiler.Start("Loading assets of type " + typeof(T) + " for mod " + mod);
                FileInfo[] files = contentDir.GetFiles("*.*", SearchOption.AllDirectories);
                foreach (FileInfo file in files)
                {
                    if (IsAcceptableExtension(file.Extension))
                    {
                        LoadedContentItem <T> loadedItem = LoadItem(file.FullName, contentDirPath);
                        if (loadedItem != null)
                        {
                            yield return(loadedItem);

                            /*Error: Unable to find new state assignment for yield return*/;
                        }
                    }
                }
                DeepProfiler.End();
            }
        }
示例#3
0
 public void ReloadAll()
 {
     foreach (Pair <string, LoadedContentItem <T> > item in ModContentLoader <T> .LoadAllForMod(mod))
     {
         string first = item.First;
         first = first.Replace('\\', '/');
         string text = GenFilePaths.ContentPath <T>();
         if (first.StartsWith(text))
         {
             first = first.Substring(text.Length);
         }
         if (first.EndsWith(Path.GetExtension(first)))
         {
             first = first.Substring(0, first.Length - Path.GetExtension(first).Length);
         }
         if (contentList.ContainsKey(first))
         {
             Log.Warning("Tried to load duplicate " + typeof(T) + " with path: " + item.Second.internalFile + " and internal path: " + first);
         }
         else
         {
             contentList.Add(first, item.Second.contentItem);
             if (item.Second.extraDisposable != null)
             {
                 extraDisposables.Add(item.Second.extraDisposable);
             }
         }
     }
 }
        public static IEnumerable <LoadedContentItem <T> > LoadAllForMod(ModContentPack mod)
        {
            string        contentDirPath = Path.Combine(mod.RootDir, GenFilePaths.ContentPath <T>());
            DirectoryInfo contentDir     = new DirectoryInfo(contentDirPath);

            if (contentDir.Exists)
            {
                DeepProfiler.Start(string.Concat(new object[]
                {
                    "Loading assets of type ",
                    typeof(T),
                    " for mod ",
                    mod
                }));
                FileInfo[] files = contentDir.GetFiles("*.*", SearchOption.AllDirectories);
                for (int i = 0; i < files.Length; i++)
                {
                    FileInfo file = files[i];
                    if (ModContentLoader <T> .IsAcceptableExtension(file.Extension))
                    {
                        LoadedContentItem <T> loadedItem = ModContentLoader <T> .LoadItem(file.FullName, contentDirPath);

                        if (loadedItem != null)
                        {
                            yield return(loadedItem);
                        }
                    }
                }
                DeepProfiler.End();
            }
        }
示例#5
0
        public static T Get(string itemPath, bool reportFailure = true)
        {
            T result;

            if (!UnityData.IsInMainThread)
            {
                Log.Error("Tried to get a resource \"" + itemPath + "\" from a different thread. All resources must be loaded in the main thread.", false);
                result = (T)((object)null);
            }
            else
            {
                T t = (T)((object)null);
                List <ModContentPack> runningModsListForReading = LoadedModManager.RunningModsListForReading;
                for (int i = runningModsListForReading.Count - 1; i >= 0; i--)
                {
                    t = runningModsListForReading[i].GetContentHolder <T>().Get(itemPath);
                    if (t != null)
                    {
                        return(t);
                    }
                }
                if (typeof(T) == typeof(Texture2D))
                {
                    t = (T)((object)Resources.Load <Texture2D>(GenFilePaths.ContentPath <Texture2D>() + itemPath));
                }
                if (typeof(T) == typeof(AudioClip))
                {
                    t = (T)((object)Resources.Load <AudioClip>(GenFilePaths.ContentPath <AudioClip>() + itemPath));
                }
                if (t != null)
                {
                    result = t;
                }
                else
                {
                    if (reportFailure)
                    {
                        Log.Error(string.Concat(new object[]
                        {
                            "Could not load ",
                            typeof(T),
                            " at ",
                            itemPath,
                            " in any active mod or in base resources."
                        }), false);
                    }
                    result = (T)((object)null);
                }
            }
            return(result);
        }
示例#6
0
        private static void LoadedFilesForMod()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            foreach (ModContentPack item in LoadedModManager.RunningModsListForReading)
            {
                ModContentPack mod = item;
                list.Add(new DebugMenuOption(mod.Name, DebugMenuOptionMode.Action, delegate
                {
                    ModMetaData metaData = ModLister.GetModWithIdentifier(mod.PackageId);
                    if (metaData.loadFolders != null && metaData.loadFolders.DefinedVersions().Count != 0)
                    {
                        Find.WindowStack.Add(new Dialog_DebugOptionListLister(from ver in metaData.loadFolders.DefinedVersions()
                                                                              select new DebugMenuOption(ver, DebugMenuOptionMode.Action, delegate
                        {
                            ShowTable((from f in metaData.loadFolders.FoldersForVersion(ver)
                                       select Path.Combine(mod.RootDir, f.folderName)).Reverse().ToList());
                        })));
                    }
                    else
                    {
                        ShowTable(null);
                    }
                }));
                void ShowTable(List <string> loadFolders)
                {
                    List <Pair <string, string> > list2 = new List <Pair <string, string> >();

                    list2.AddRange(from f in DirectXmlLoader.XmlAssetsInModFolder(mod, "Defs/", loadFolders)
                                   select new Pair <string, string>(f.FullFilePath, "-"));
                    list2.AddRange(from f in DirectXmlLoader.XmlAssetsInModFolder(mod, "Patches/", loadFolders)
                                   select new Pair <string, string>(f.FullFilePath, "-"));
                    list2.AddRange(from f in ModContentPack.GetAllFilesForMod(mod, GenFilePaths.ContentPath <Texture2D>(), ModContentLoader <Texture2D> .IsAcceptableExtension, loadFolders)
                                   select new Pair <string, string>(f.Value.FullName, f.Key));
                    list2.AddRange(from f in ModContentPack.GetAllFilesForMod(mod, GenFilePaths.ContentPath <AudioClip>(), ModContentLoader <AudioClip> .IsAcceptableExtension, loadFolders)
                                   select new Pair <string, string>(f.Value.FullName, f.Key));
                    list2.AddRange(from f in ModContentPack.GetAllFilesForMod(mod, GenFilePaths.ContentPath <string>(), ModContentLoader <string> .IsAcceptableExtension, loadFolders)
                                   select new Pair <string, string>(f.Value.FullName, f.Key));
                    list2.AddRange(from f in ModContentPack.GetAllFilesForModPreserveOrder(mod, "Assemblies/", (string e) => e.ToLower() == ".dll", loadFolders)
                                   select new Pair <string, string>(f.Item2.FullName, f.Item1));
                    DebugTables.MakeTablesDialog(list2, new List <TableDataGetter <Pair <string, string> > >
                    {
                        new TableDataGetter <Pair <string, string> >("full path", (Pair <string, string> f) => f.First),
                        new TableDataGetter <Pair <string, string> >("internal path", (Pair <string, string> f) => f.Second)
                    }.ToArray());
                }
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
示例#7
0
        public static IEnumerable <T> GetAllInFolder(string folderPath)
        {
            if (!UnityData.IsInMainThread)
            {
                Log.Error("Tried to get all resources in a folder \"" + folderPath + "\" from a different thread. All resources must be loaded in the main thread.");
            }
            else
            {
                foreach (ModContentPack runningMod in LoadedModManager.RunningMods)
                {
                    using (IEnumerator <T> enumerator2 = runningMod.GetContentHolder <T>().GetAllUnderPath(folderPath).GetEnumerator())
                    {
                        if (enumerator2.MoveNext())
                        {
                            T item2 = enumerator2.Current;
                            yield return(item2);

                            /*Error: Unable to find new state assignment for yield return*/;
                        }
                    }
                }
                T[] items = null;
                if (typeof(T) == typeof(Texture2D))
                {
                    items = (T[])Resources.LoadAll <Texture2D>(GenFilePaths.ContentPath <Texture2D>() + folderPath);
                }
                if (typeof(T) == typeof(AudioClip))
                {
                    items = (T[])Resources.LoadAll <AudioClip>(GenFilePaths.ContentPath <AudioClip>() + folderPath);
                }
                if (items != null)
                {
                    T[] array = items;
                    int num   = 0;
                    if (num < array.Length)
                    {
                        T item = array[num];
                        yield return(item);

                        /*Error: Unable to find new state assignment for yield return*/;
                    }
                }
            }
            yield break;
IL_024a:
            /*Error near IL_024b: Unexpected return in MoveNext()*/;
        }
示例#8
0
        public static T Get(string itemPath, bool reportFailure = true)
        {
            if (!UnityData.IsInMainThread)
            {
                Log.Error("Tried to get a resource \"" + itemPath + "\" from a different thread. All resources must be loaded in the main thread.");
                return((T)null);
            }
            T val = (T)null;
            List <ModContentPack> runningModsListForReading = LoadedModManager.RunningModsListForReading;

            for (int num = runningModsListForReading.Count - 1; num >= 0; num--)
            {
                val = runningModsListForReading[num].GetContentHolder <T>().Get(itemPath);
                if (val != null)
                {
                    return(val);
                }
            }
            if (typeof(T) == typeof(Texture2D))
            {
                val = (T)(object)Resources.Load <Texture2D>(GenFilePaths.ContentPath <Texture2D>() + itemPath);
            }
            if (typeof(T) == typeof(AudioClip))
            {
                val = (T)(object)Resources.Load <AudioClip>(GenFilePaths.ContentPath <AudioClip>() + itemPath);
            }
            if (val != null)
            {
                return(val);
            }
            if (reportFailure)
            {
                Log.Error("Could not load " + typeof(T) + " at " + itemPath + " in any active mod or in base resources.");
            }
            return((T)null);
        }
示例#9
0
        public static T Get(string itemPath, bool reportFailure = true)
        {
            if (!UnityData.IsInMainThread)
            {
                Log.Error("Tried to get a resource \"" + itemPath + "\" from a different thread. All resources must be loaded in the main thread.");
                return(null);
            }
            T val = null;
            List <ModContentPack> runningModsListForReading = LoadedModManager.RunningModsListForReading;

            for (int num = runningModsListForReading.Count - 1; num >= 0; num--)
            {
                val = runningModsListForReading[num].GetContentHolder <T>().Get(itemPath);
                if (val != null)
                {
                    return(val);
                }
            }
            if (typeof(T) == typeof(Texture2D))
            {
                val = (T)(object)Resources.Load <Texture2D>(GenFilePaths.ContentPath <Texture2D>() + itemPath);
            }
            if (typeof(T) == typeof(AudioClip))
            {
                val = (T)(object)Resources.Load <AudioClip>(GenFilePaths.ContentPath <AudioClip>() + itemPath);
            }
            if (val != null)
            {
                return(val);
            }
            for (int num2 = runningModsListForReading.Count - 1; num2 >= 0; num2--)
            {
                for (int i = 0; i < runningModsListForReading[num2].assetBundles.loadedAssetBundles.Count; i++)
                {
                    AssetBundle assetBundle = runningModsListForReading[num2].assetBundles.loadedAssetBundles[i];
                    string      path        = Path.Combine("Assets", "Data");
                    path = Path.Combine(path, runningModsListForReading[num2].FolderName);
                    if (typeof(T) == typeof(Texture2D))
                    {
                        string str = Path.Combine(Path.Combine(path, GenFilePaths.ContentPath <Texture2D>()), itemPath);
                        for (int j = 0; j < ModAssetBundlesHandler.TextureExtensions.Length; j++)
                        {
                            val = (T)(object)assetBundle.LoadAsset <Texture2D>(str + ModAssetBundlesHandler.TextureExtensions[j]);
                            if (val != null)
                            {
                                return(val);
                            }
                        }
                    }
                    if (!(typeof(T) == typeof(AudioClip)))
                    {
                        continue;
                    }
                    string str2 = Path.Combine(Path.Combine(path, GenFilePaths.ContentPath <AudioClip>()), itemPath);
                    for (int k = 0; k < ModAssetBundlesHandler.AudioClipExtensions.Length; k++)
                    {
                        val = (T)(object)assetBundle.LoadAsset <AudioClip>(str2 + ModAssetBundlesHandler.AudioClipExtensions[k]);
                        if (val != null)
                        {
                            return(val);
                        }
                    }
                }
            }
            if (reportFailure)
            {
                Log.Error(string.Concat("Could not load ", typeof(T), " at ", itemPath, " in any active mod or in base resources."));
            }
            return(null);
        }
示例#10
0
        public static IEnumerable <T> GetAllInFolder(string folderPath)
        {
            if (!UnityData.IsInMainThread)
            {
                Log.Error("Tried to get all resources in a folder \"" + folderPath + "\" from a different thread. All resources must be loaded in the main thread.");
                yield break;
            }
            foreach (ModContentPack runningMod in LoadedModManager.RunningMods)
            {
                foreach (T item in runningMod.GetContentHolder <T>().GetAllUnderPath(folderPath))
                {
                    yield return(item);
                }
            }
            T[] array = null;
            if (typeof(T) == typeof(Texture2D))
            {
                array = (T[])(object)Resources.LoadAll <Texture2D>(GenFilePaths.ContentPath <Texture2D>() + folderPath);
            }
            if (typeof(T) == typeof(AudioClip))
            {
                array = (T[])(object)Resources.LoadAll <AudioClip>(GenFilePaths.ContentPath <AudioClip>() + folderPath);
            }
            if (array != null)
            {
                T[] array2 = array;
                for (int j = 0; j < array2.Length; j++)
                {
                    yield return(array2[j]);
                }
            }
            List <ModContentPack> mods = LoadedModManager.RunningModsListForReading;

            for (int j = mods.Count - 1; j >= 0; j--)
            {
                for (int i = 0; i < mods[j].assetBundles.loadedAssetBundles.Count; i++)
                {
                    AssetBundle assetBundle   = mods[j].assetBundles.loadedAssetBundles[i];
                    string      dirForBundle2 = Path.Combine("Assets", "Data");
                    dirForBundle2 = Path.Combine(dirForBundle2, mods[j].FolderName);
                    if (typeof(T) == typeof(Texture2D))
                    {
                        string fullPath = Path.Combine(Path.Combine(dirForBundle2, GenFilePaths.ContentPath <Texture2D>()).Replace('\\', '/'), folderPath).ToLower();
                        IEnumerable <string> enumerable = from p in mods[j].AllAssetNamesInBundle(i)
                                                          where p.StartsWith(fullPath)
                                                          select p;
                        foreach (string item2 in enumerable)
                        {
                            if (ModAssetBundlesHandler.TextureExtensions.Contains(Path.GetExtension(item2)))
                            {
                                yield return((T)(object)assetBundle.LoadAsset <Texture2D>(item2));
                            }
                        }
                    }
                    if (!(typeof(T) == typeof(AudioClip)))
                    {
                        continue;
                    }
                    string fullPath2 = Path.Combine(Path.Combine(dirForBundle2, GenFilePaths.ContentPath <AudioClip>()).Replace('\\', '/'), folderPath).ToLower();
                    IEnumerable <string> enumerable2 = from p in mods[j].AllAssetNamesInBundle(i)
                                                       where p.StartsWith(fullPath2)
                                                       select p;
                    foreach (string item3 in enumerable2)
                    {
                        if (ModAssetBundlesHandler.AudioClipExtensions.Contains(Path.GetExtension(item3)))
                        {
                            yield return((T)(object)assetBundle.LoadAsset <AudioClip>(item3));
                        }
                    }
                }
            }
        }
示例#11
0
        public static IEnumerable <Pair <string, LoadedContentItem <T> > > LoadAllForMod(ModContentPack mod)
        {
            DeepProfiler.Start(string.Concat("Loading assets of type ", typeof(T), " for mod ", mod));
            Dictionary <string, FileInfo> allFilesForMod = ModContentPack.GetAllFilesForMod(mod, GenFilePaths.ContentPath <T>(), IsAcceptableExtension);

            foreach (KeyValuePair <string, FileInfo> item in allFilesForMod)
            {
                LoadedContentItem <T> loadedContentItem = LoadItem((FilesystemFile)item.Value);
                if (loadedContentItem != null)
                {
                    yield return(new Pair <string, LoadedContentItem <T> >(item.Key, loadedContentItem));
                }
            }
            DeepProfiler.End();
        }