Exemple #1
0
 public static LoadedContentItem <T> LoadItem(VirtualFile file)
 {
     try
     {
         if (typeof(T) == typeof(string))
         {
             return(new LoadedContentItem <T>(file, (T)(object)file.ReadAllText()));
         }
         if (typeof(T) == typeof(Texture2D))
         {
             return(new LoadedContentItem <T>(file, (T)(object)LoadTexture(file)));
         }
         if (typeof(T) == typeof(AudioClip))
         {
             if (Prefs.LogVerbose)
             {
                 DeepProfiler.Start("Loading file " + file);
             }
             IDisposable extraDisposable = null;
             T           val;
             try
             {
                 string uri = GenFilePaths.SafeURIForUnityWWWFromPath(file.FullPath);
                 using UnityWebRequest unityWebRequest = UnityWebRequestMultimedia.GetAudioClip(uri, GetAudioTypeFromURI(uri));
                 unityWebRequest.SendWebRequest();
                 while (!unityWebRequest.isDone)
                 {
                     Thread.Sleep(1);
                 }
                 if (unityWebRequest.error != null)
                 {
                     throw new InvalidOperationException(unityWebRequest.error);
                 }
                 val = (T)(object)DownloadHandlerAudioClip.GetContent(unityWebRequest);
             }
             finally
             {
                 if (Prefs.LogVerbose)
                 {
                     DeepProfiler.End();
                 }
             }
             UnityEngine.Object @object = val as UnityEngine.Object;
             if (@object != null)
             {
                 @object.name = Path.GetFileNameWithoutExtension(file.Name);
             }
             return(new LoadedContentItem <T>(file, val, extraDisposable));
         }
     }
     catch (Exception ex)
     {
         Log.Error(string.Concat("Exception loading ", typeof(T), " from file.\nabsFilePath: ", file.FullPath, "\nException: ", ex.ToString()));
     }
     if (typeof(T) == typeof(Texture2D))
     {
         return((LoadedContentItem <T>)(object) new LoadedContentItem <Texture2D>(file, BaseContent.BadTex));
     }
     return(null);
 }
Exemple #2
0
        private void Init()
        {
            this.meta = DirectXmlLoader.ItemFromXmlFile <ModMetaData.ModMetaDataInternal>(string.Concat(new object[]
            {
                this.RootDir.FullName,
                Path.DirectorySeparatorChar,
                "About",
                Path.DirectorySeparatorChar,
                "About.xml"
            }), true);
            if (this.meta.name.NullOrEmpty())
            {
                if (this.OnSteamWorkshop)
                {
                    this.meta.name = "Workshop mod " + this.Identifier;
                }
                else
                {
                    this.meta.name = this.Identifier;
                }
            }
            if (!this.IsCoreMod && !this.OnSteamWorkshop && !VersionControl.IsWellFormattedVersionString(this.meta.targetVersion))
            {
                Log.ErrorOnce(string.Concat(new string[]
                {
                    "Mod ",
                    this.meta.name,
                    " has incorrectly formatted target version '",
                    this.meta.targetVersion,
                    "'. For the current version, write: <targetVersion>",
                    VersionControl.CurrentVersionString,
                    "</targetVersion>"
                }), this.Identifier.GetHashCode(), false);
            }
            LongEventHandler.ExecuteWhenFinished(delegate
            {
                string url = GenFilePaths.SafeURIForUnityWWWFromPath(this.PreviewImagePath);
                using (WWW www = new WWW(url))
                {
                    www.threadPriority = UnityEngine.ThreadPriority.High;
                    while (!www.isDone)
                    {
                        Thread.Sleep(1);
                    }
                    if (www.error == null)
                    {
                        this.previewImage = www.textureNonReadable;
                    }
                }
            });
            string publishedFileIdPath = this.PublishedFileIdPath;

            if (File.Exists(this.PublishedFileIdPath))
            {
                string s = File.ReadAllText(publishedFileIdPath);
                this.publishedFileIdInt = new PublishedFileId_t(ulong.Parse(s));
            }
        }
Exemple #3
0
        private void <Init> m__0()
        {
            string url = GenFilePaths.SafeURIForUnityWWWFromPath(this.PreviewImagePath);

            using (WWW www = new WWW(url))
            {
                www.threadPriority = UnityEngine.ThreadPriority.High;
                while (!www.isDone)
                {
                    Thread.Sleep(1);
                }
                if (www.error == null)
                {
                    this.previewImage = www.textureNonReadable;
                }
            }
        }
Exemple #4
0
        private void Init()
        {
            meta = DirectXmlLoader.ItemFromXmlFile <ModMetaDataInternal>(RootDir.FullName + Path.DirectorySeparatorChar + "About" + Path.DirectorySeparatorChar + "About.xml");
            if (meta.name.NullOrEmpty())
            {
                if (OnSteamWorkshop)
                {
                    meta.name = "Workshop mod " + Identifier;
                }
                else
                {
                    meta.name = Identifier;
                }
            }
            if (!IsCoreMod && !OnSteamWorkshop && !VersionControl.IsWellFormattedVersionString(meta.targetVersion))
            {
                Log.ErrorOnce("Mod " + meta.name + " has incorrectly formatted target version '" + meta.targetVersion + "'. For the current version, write: <targetVersion>" + VersionControl.CurrentVersionString + "</targetVersion>", Identifier.GetHashCode());
            }
            LongEventHandler.ExecuteWhenFinished(delegate
            {
                string url = GenFilePaths.SafeURIForUnityWWWFromPath(PreviewImagePath);
                using (WWW wWW = new WWW(url))
                {
                    wWW.threadPriority = UnityEngine.ThreadPriority.High;
                    while (!wWW.isDone)
                    {
                        Thread.Sleep(1);
                    }
                    if (wWW.error == null)
                    {
                        previewImage = wWW.textureNonReadable;
                    }
                }
            });
            string publishedFileIdPath = PublishedFileIdPath;

            if (File.Exists(PublishedFileIdPath))
            {
                string s = File.ReadAllText(publishedFileIdPath);
                publishedFileIdInt = new PublishedFileId_t(ulong.Parse(s));
            }
        }