Exemple #1
0
        private void Start()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();

            if (HighLogic.LoadedScene == GameScenes.LOADING && !loaded)
            {
                Log("Version: " + assembly.GetName().Version);
                loaded    = true;
                _MainTex  = Shader.PropertyToID("_MainTex");
                _BumpMap  = Shader.PropertyToID("_BumpMap");
                _Emissive = Shader.PropertyToID("_Emissive");

                moduleNode = new ConfigNode("MODULE");
                moduleNode.SetValue("name", typeof(TextureUnloaderPartModule).Name, true);

                Type gdType = typeof(GameDatabase);
                List <DatabaseLoader <GameDatabase.TextureInfo> > textureLoaders =
                    (from fld in gdType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
                     where fld.FieldType == typeof(List <DatabaseLoader <GameDatabase.TextureInfo> >)
                     select(List <DatabaseLoader <GameDatabase.TextureInfo> >) fld.GetValue(GameDatabase.Instance)).FirstOrDefault();

                DatabaseLoaderAttrib loaderAttrib = (DatabaseLoaderAttrib)Attribute.GetCustomAttribute(typeof(DatabaseLoaderTexture_DTL), typeof(DatabaseLoaderAttrib));
                foreach (var textureLoader in textureLoaders)
                {
                    if (textureLoader.GetType().Name != "DatabaseLoaderTexture_DTL")
                    {
                        Log("Disabling " + textureLoader.GetType().Name);
                        textureLoader.extensions.RemoveAll(i => loaderAttrib.extensions.Contains(i));
                        Log(textureLoader.GetType().Name + " now has extensions: " + String.Join(", ", textureLoader.extensions.ToArray()));
                    }
                }
            }

            //unload any materials added by mods.
            if (HighLogic.LoadedScene == GameScenes.SPACECENTER && !unloaded)
            {
                foreach (AvailablePart ap in PartLoader.LoadedPartsList)
                {
                    if (ap.partUrl != null && ap.partUrl != "")
                    {
                        Part part = ap.partPrefab;
                        TextureUnloaderPartModule module = (TextureUnloaderPartModule)part.FindModuleImplementing <TextureUnloaderPartModule>();
                        module.Unload(true);
                    }
                }
                unloaded = true;
            }

            System.GC.Collect();
            Resources.UnloadUnusedAssets();
        }
Exemple #2
0
 public static void loadDictionary()
 {
     if (!xrefed)
     {
         DatabaseLoaderAttrib loaderAttrib = (DatabaseLoaderAttrib)Attribute.GetCustomAttribute(typeof(DatabaseLoaderTexture_DTL), typeof(DatabaseLoaderAttrib));
         foreach (UrlDir.UrlConfig config in GameDatabase.Instance.root.AllConfigs.ToArray())
         {
             ConfigNode[] models = config.config.GetNodes("MODEL");
             if ((config.type == "PART" || config.type == "INTERNAL") && models != null)
             {
                 foreach (ConfigNode model in models)
                 {
                     int    i            = 0;
                     string modelUrl     = model.GetValue("model");
                     String modelCapture = @"(.*/)([^/\\]+)$";
                     if (Regex.IsMatch(modelUrl, modelCapture))
                     {
                         modelUrl = Regex.Match(modelUrl, modelCapture).Groups[1].Value;
                         string value = model.GetValue("texture", i);
                         while (value != null)
                         {
                             String capture = @"(.*[^\s])\s*,\s*(.*[^\s])";
                             if (Regex.IsMatch(value, capture))
                             {
                                 Match  match    = Regex.Match(value, capture);
                                 string realUrl  = match.Groups[2].Value;
                                 string dummyUrl = modelUrl + match.Groups[1].Value;
                                 Loader.Log("stashing " + dummyUrl + " -> " + realUrl);
                                 if (texMapDictionary.ContainsKey(dummyUrl) && texMapDictionary[dummyUrl] != realUrl)
                                 {
                                     Loader.Log("Dummy has multiple refs!");
                                 }
                                 else
                                 {
                                     texMapDictionary[dummyUrl] = realUrl;
                                 }
                             }
                             i++;
                             value = model.GetValue("texture", i);
                         }
                     }
                 }
             }
         }
         xrefed = true;
     }
 }
Exemple #3
0
        private static UrlDir.UrlFile getReplacementFile(string urlReplace)
        {
            Loader.Log("mapping to " + urlReplace);
            DatabaseLoaderAttrib loaderAttrib = (DatabaseLoaderAttrib)Attribute.GetCustomAttribute(typeof(DatabaseLoaderTexture_DTL), typeof(DatabaseLoaderAttrib));
            string fileBase = UrlDir.ApplicationRootPath + "GameData/" + urlReplace;

            foreach (String ext in loaderAttrib.extensions)
            {
                string file = fileBase + "." + ext;
                if (File.Exists(file))
                {
                    Loader.Log("Getting replacement from " + file);
                    return(new UrlDir.UrlFile(GameDatabase.Instance.root, new FileInfo(file)));
                }
            }
            return(null);
        }
Exemple #4
0
        private void Start()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();

            if (HighLogic.LoadedScene == GameScenes.LOADING && !loaded)
            {
                Log("Version: " + assembly.GetName().Version);
                loaded    = true;
                _MainTex  = Shader.PropertyToID("_MainTex");
                _BumpMap  = Shader.PropertyToID("_BumpMap");
                _Emissive = Shader.PropertyToID("_Emissive");

                moduleNode = new ConfigNode("MODULE");
                moduleNode.SetValue("name", typeof(TextureUnloaderPartModule).Name, true);

                Type gdType = typeof(GameDatabase);
                List <DatabaseLoader <GameDatabase.TextureInfo> > textureLoaders =
                    (from fld in gdType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
                     where fld.FieldType == typeof(List <DatabaseLoader <GameDatabase.TextureInfo> >)
                     select(List <DatabaseLoader <GameDatabase.TextureInfo> >) fld.GetValue(GameDatabase.Instance)).FirstOrDefault();

                DatabaseLoaderTexture_DTL textureLoaderDTL = (DatabaseLoaderTexture_DTL)textureLoaders.First(t => t.GetType() == typeof(DatabaseLoaderTexture_DTL));

                DatabaseLoaderAttrib loaderAttrib = (DatabaseLoaderAttrib)Attribute.GetCustomAttribute(typeof(DatabaseLoaderTexture_DTL), typeof(DatabaseLoaderAttrib));
                foreach (var textureLoader in textureLoaders)
                {
                    if (textureLoader.GetType() != typeof(DatabaseLoaderTexture_DTL))
                    {
                        Log("Disabling " + textureLoader.GetType().Name);
                        textureLoaderDTL.setLoader(textureLoader);
                        textureLoader.extensions.RemoveAll(i => loaderAttrib.extensions.Contains(i));
                        Log(textureLoader.GetType().Name + " now has extensions: " + String.Join(", ", textureLoader.extensions.ToArray()));
                    }
                    else
                    {
                        ((DatabaseLoaderTexture_DTL)textureLoader).fixExtensions(loaderAttrib.extensions.ToList());
                    }
                }


                /*
                 * List<LoadingSystem> list = LoadingScreen.Instance.loaders;
                 *
                 * if (list != null)
                 * {
                 *
                 *  GameObject aGameObject = new GameObject("ModuleManager");
                 *  TexPatchLoader loader = aGameObject.AddComponent<TexPatchLoader>();
                 *  int index = list.FindIndex(l => l.GetType() == typeof(PartLoader));
                 *  list.Insert(index, loader);
                 *  //list.Insert(2, loader);
                 * }
                 */
            }

            //unload any materials added by mods.
            if (HighLogic.LoadedScene == GameScenes.SPACECENTER && !unloaded)
            {
                foreach (AvailablePart ap in PartLoader.LoadedPartsList)
                {
                    Part part = ap.partPrefab;
                    if (part != null)
                    {
                        TextureUnloaderPartModule module = (TextureUnloaderPartModule)part.FindModuleImplementing <TextureUnloaderPartModule>();
                        if (module != null)
                        {
                            module.Unload(true);
                        }
                    }
                }
                unloaded = true;
            }

            System.GC.Collect();
            //Resources.UnloadUnusedAssets();
        }