Esempio n. 1
0
        private void LoadTexture(SLPack pack, Dictionary <string, object> dict, string dirPath, string texFile, bool addGlobal)
        {
            var texture = pack.LoadTexture2D(dirPath, texFile, false, false);

            var name = Path.GetFileNameWithoutExtension(texFile);

            // add to the Texture2D dict for this pack
            if (pack.Texture2D.ContainsKey(name))
            {
                SL.LogWarning("Trying to load two textures with the same name into the same SLPack: " + name);
                return;
            }

            pack.Texture2D.Add(name, texture);

            dict.Add(Path.Combine(dirPath, texFile), texture);

            if (addGlobal)
            {
                // add to the global Tex replacements dict
                if (CustomTextures.Textures.ContainsKey(name))
                {
                    SL.Log("Custom Texture2Ds: A Texture already exists in the global list called " + name + "! Overwriting with this one...");
                    CustomTextures.Textures[name] = texture;
                }
                else
                {
                    CustomTextures.Textures.Add(name, texture);
                }
            }
        }
        public override Dictionary <string, object> LoadContent(SLPack pack, bool isHotReload)
        {
            var dir = pack.GetPathForCategory <PackBundleCategory>();

            if (!Directory.Exists(dir))
            {
                return(null);
            }

            foreach (var bundlePath in Directory.GetFiles(dir))
            {
                try
                {
                    SL.Log("Loading Pack AssetBundle: " + bundlePath);

                    var assetbundle = AssetBundle.LoadFromFile(bundlePath);

                    var bundlePack = new SLPackBundle(Path.GetFileName(bundlePath), pack, assetbundle);

                    pack.PackBundles.Add(bundlePack.Name, bundlePack);

                    s_loadedBundles.Add(bundlePath, bundlePack);

                    //SL.Log($"Added bundle '{bundlePack.Name}' to pack '{pack.Name}' (Bundle count: {pack.PackBundles.Count})");
                }
                catch (Exception ex)
                {
                    SL.LogWarning("Exception loading Pack Bundle: " + bundlePath);
                    SL.LogInnerException(ex);
                }
            }

            return(null);
        }
Esempio n. 3
0
        internal void RefreshLoadedSLPacks()
        {
            m_slPackDropdown.options.Clear();
            m_slPackDropdownLabel.text = "Choose an SLPack...";

            m_slPackDropdown.options.Add(new Dropdown.OptionData
            {
                text = "No SLPack selected"
            });

            for (int i = 0; i < SL.s_packs.Count; i++)
            {
                var pack = SL.s_packs.ElementAt(i).Value;
                m_slPackDropdown.options.Add(new Dropdown.OptionData
                {
                    text = pack.Name
                });
            }

            m_slPackDropdown.value = 1;
            m_slPackDropdown.value = 0;

            m_currentPack = null;
            m_scrollObj.gameObject.SetActive(false);
            m_generateObj.gameObject.SetActive(false);
        }
Esempio n. 4
0
        public override Dictionary <string, object> LoadContent(SLPack pack, bool isHotReload)
        {
            var dict = new Dictionary <string, object>();

            var dirPath = pack.GetPathForCategory <Texture2DCategory>();

            if (!pack.DirectoryExists(dirPath))
            {
                return(dict);
            }

            foreach (var texPath in pack.GetFiles(dirPath, ".png"))
            {
                LoadTexture(pack, dict, dirPath, texPath, true);
            }

            var localDir = dirPath + @"\Local";

            if (Directory.Exists(localDir))
            {
                foreach (var localTex in pack.GetFiles(localDir, ".png"))
                {
                    LoadTexture(pack, dict, localDir, localTex, false);
                }
            }

            return(dict);
        }
        public override Dictionary <string, object> LoadContent(SLPack pack, bool isHotReload)
        {
            var dict = new Dictionary <string, object>();

            var dirPath = pack.GetPathForCategory <AudioClipCategory>();

            if (!pack.DirectoryExists(dirPath))
            {
                return(dict);
            }

            foreach (var clipPath in pack.GetFiles(dirPath, ".wav"))
            {
                //SL.Log($"Loading audio clip from '{clipPath}'");

                pack.LoadAudioClip(dirPath,
                                   Path.GetFileName(clipPath),
                                   (AudioClip clip) =>
                {
                    if (clip)
                    {
                        dict.Add(clipPath, clip);
                    }
                }
                                   );
            }

            return(dict);
        }
        private void DeserializePack(SLPack pack, List <ContentTemplate> list)
        {
            try
            {
                var dict = new Dictionary <string, object>();

                var dirPath = pack.GetPathForCategory(this.GetType());

                if (!pack.DirectoryExists(dirPath))
                {
                    return;
                }

                // load root directory templates
                foreach (var filepath in pack.GetFiles(dirPath, ".xml"))
                {
                    DeserializeTemplate(dirPath, filepath);
                }

                // load one-subfolder templates
                foreach (var subDir in pack.GetDirectories(dirPath))
                {
                    foreach (var filepath in pack.GetFiles(subDir, ".xml"))
                    {
                        DeserializeTemplate(subDir, filepath, subDir);
                    }
                }

                AddToSLPackDictionary(pack, dict);

                void DeserializeTemplate(string directory, string filepath, string subfolder = null)
                {
                    //SL.Log($@"Deserializing template from '{directory}\{filepath}'");

                    var template = pack.ReadXmlDocument <T>(directory, Path.GetFileName(filepath));

                    dict.Add(filepath, template);
                    list.Add(template);

                    template.SerializedSLPackName = pack.Name;
                    template.SerializedFilename   = Path.GetFileNameWithoutExtension(filepath);

                    if (!string.IsNullOrEmpty(subfolder))
                    {
                        template.SerializedSubfolderName = Path.GetFileName(subfolder);
                    }
                }
            }
            catch (Exception ex)
            {
                SL.LogWarning("Exception loading " + this.FolderName + " from '" + pack.Name + "'");
                SL.LogInnerException(ex);
            }
        }
        public ReflectionInspector Inspect(object obj, SLPack pack, CacheObjectBase parentMember = null)
        {
            //UnityEngine.Object unityObj = obj as UnityEngine.Object;

            if (obj.IsNullOrDestroyed(false))
            {
                return(null);
            }

            // check if currently inspecting this object
            foreach (InspectorBase tab in m_currentInspectors)
            {
                if (ReferenceEquals(obj, tab.Target))
                {
                    SetInspectorTab(tab);
                    return(null);
                }
            }

            ReflectionInspector inspector;

            if (obj is ContentTemplate)
            {
                inspector = new TemplateInspector(obj, pack);
            }
            else if (obj is SL_Material)
            {
                inspector = new MaterialInspector(obj);
            }
            else
            {
                inspector = new ReflectionInspector(obj);
            }

            inspector.ParentMember = parentMember;
            inspector.Init();

            if (inspector is TemplateInspector tInspector)
            {
                tInspector.UpdateFullPathText();
            }

            m_currentInspectors.Add(inspector);
            SetInspectorTab(inspector);

            return(inspector);
        }
        public override Dictionary <string, object> LoadContent(SLPack pack, bool isHotReload)
        {
            var dict = new Dictionary <string, object>();

            // AssetBundle does not use hot reload at the moment.
            if (isHotReload)
            {
                return(dict);
            }

            var dirPath = pack.GetPathForCategory <AssetBundleCategory>();

            if (!pack.DirectoryExists(dirPath))
            {
                return(dict);
            }

            var fileQuery = pack.GetFiles(dirPath)
                            .Where(x => !x.EndsWith(".meta") &&
                                   !x.EndsWith(".manifest"));

            foreach (var bundlePath in fileQuery)
            {
                try
                {
                    string name = Path.GetFileName(bundlePath);

                    if (pack.LoadAssetBundle(dirPath, name) is AssetBundle bundle)
                    {
                        pack.AssetBundles.Add(name, bundle);

                        dict.Add(bundlePath, bundle);
                        SL.Log("Loaded assetbundle " + name);
                    }
                    else
                    {
                        throw new Exception($"Unknown error (Bundle '{Path.GetFileName(bundlePath)}' was null)");
                    }
                }
                catch (Exception e)
                {
                    SL.LogError("Error loading asset bundle! Message: " + e.Message + "\r\nStack: " + e.StackTrace);
                }
            }

            return(dict);
        }
        public SLPackBundle(string name, SLPack parentPack, AssetBundle bundle)
        {
            this.Name = $"{parentPack.Name}.{name}";

            if (SL.s_bundlePacks.ContainsKey(Name))
            {
                SL.LogWarning("Two SLPackBundles with duplicate name: " + Name + ", not loading!");
                return;
            }

            SL.s_bundlePacks.Add(Name, this);

            this.ParentSLPack   = parentPack;
            this.RefAssetBundle = bundle;

            CachePaths();
        }
Esempio n. 10
0
        internal void SetSLPackFromDowndown(int val)
        {
            if (val < 1 || val > SL.s_packs.Count)
            {
                m_scrollObj.gameObject.SetActive(false);
                m_generateObj.gameObject.SetActive(false);
                return;
            }

            m_currentPack = SL.s_packs.ElementAt(val - 1).Value;
            //m_slPackLabel.text = $"<b>Inspecting:</b> {m_currentPack.Name}";

            m_scrollObj.gameObject.SetActive(true);
            m_generateObj.gameObject.SetActive(true);

            RefreshSLPackContentList();
        }
Esempio n. 11
0
        private void CreatePack()
        {
            RefreshLoadedSLPacks();

            var name = m_createInput.text;

            var safename = Serializer.ReplaceInvalidChars(name);

            if (string.IsNullOrEmpty(safename))
            {
                return;
            }

            if (name != safename)
            {
                SL.LogWarning("SLPack name contains invalid path characters! Try '" + safename + "'");
                return;
            }

            if (SL.GetSLPack(name) != null)
            {
                SL.LogWarning("Cannot make an SLPack with this name as one already exists!");
                return;
            }

            var slPack = new SLPack
            {
                Name = name
            };

            Directory.CreateDirectory(Paths.PluginPath + $@"\{name}");
            SL.s_packs.Add(name, slPack);

            RefreshLoadedSLPacks();

            for (int i = 0; i < m_slPackDropdown.options.Count; i++)
            {
                var opt = m_slPackDropdown.options[i];
                if (opt.text == name)
                {
                    m_slPackDropdown.value = i;
                    break;
                }
            }
        }
Esempio n. 12
0
        protected void AddToSLPackDictionary(SLPack pack, Dictionary <string, object> dict)
        {
            var ctgType = this.GetType();

            if (!pack.LoadedContent.ContainsKey(ctgType))
            {
                pack.LoadedContent.Add(ctgType, dict);
            }
            else
            {
                foreach (var entry in dict)
                {
                    if (!pack.LoadedContent[ctgType].ContainsKey(entry.Key))
                    {
                        pack.LoadedContent[ctgType].Add(entry.Key, entry.Value);
                    }
                }
            }
        }
        private static List <SLPack> LoadBaseSLPacks()
        {
            var packs = new List <SLPack>();

            // 'BepInEx\plugins\...' packs:
            foreach (var dir in Directory.GetDirectories(Paths.PluginPath))
            {
                if (!Directory.Exists($@"{dir}\SideLoader"))
                {
                    continue;
                }

                string name;
                string manifestPath = Path.Combine(dir, "SideLoader", "manifest.txt");
                if (File.Exists(manifestPath))
                {
                    name = File.ReadAllText(manifestPath).Trim();
                }
                else
                {
                    name = Path.GetFileName(dir);
                }

                AddSLPack(name, false, Path.GetFileName(dir));
            }

            // LEGACY 'Mods\SideLoader\...' packs:
            if (Directory.Exists(SL.LEGACY_SL_FOLDER))
            {
                foreach (var dir in Directory.GetDirectories(SL.LEGACY_SL_FOLDER))
                {
                    if (dir.Contains("_INTERNAL") || dir.Contains("_SAVEDATA") || dir.Contains("_GENERATED"))
                    {
                        continue;
                    }

                    //AddSLPack(Path.GetFileName(dir), true);

                    string name;
                    string manifestPath = Path.Combine(dir, "manifest.txt");
                    if (File.Exists(manifestPath))
                    {
                        name = File.ReadAllText(manifestPath).Trim();
                    }
                    else
                    {
                        name = Path.GetFileName(dir);
                    }

                    AddSLPack(name, true, Path.GetFileName(dir));
                }
            }

            void AddSLPack(string name, bool isLegacyFolder = false, string actualFolderName = null)
            {
                if (SL.s_packs.ContainsKey(name))
                {
                    SL.LogWarning("Trying to load the same SLPack name twice? Name: " + name);
                    return;
                }

                var pack = new SLPack
                {
                    Name               = name,
                    IsInLegacyFolder   = isLegacyFolder,
                    s_actualFolderName = actualFolderName,
                };

                packs.Add(pack);
                SL.s_packs.Add(name, pack);

                SL.Log($"Found SLPack '{name}'");
            }

            return(packs);
        }
 public TemplateInspector(object target, SLPack pack) : base(target)
 {
     Template = target as ContentTemplate;
     RefPack = pack;
 }
 public abstract Dictionary <string, object> LoadContent(SLPack pack, bool isHotReload);