Example #1
0
        public static bool TryLoadCareer(string json, Assembly assembly, string gameData, out InstalledContentPack pack)
        {
            try
            {
                var metadata = JsonSerializer.Deserialize <ContentPackMetadata>(json, new JsonSerializerOptions
                {
                    IncludeFields = true
                });

                pack             = new InstalledContentPack();
                pack.Name        = metadata.Name;
                pack.Author      = metadata.Author;
                pack.Description = metadata.Description;

                pack._dataReader = () =>
                                   assembly.GetManifestResourceStream(gameData);

                return(true);
            }
            catch (Exception ex)
            {
                EntryPoint.CurrentApp.Logger.Log("Cannot load career mode data.");
                EntryPoint.CurrentApp.Logger.LogException(ex);
            }

            pack = null;
            return(false);
        }
Example #2
0
        public static InstalledContentPack FromPak(GraphicsProcessor gpu, string pakPath)
        {
            var pakFile = PakUtils.OpenPak(pakPath);
            var fs      = FileSystem.FromPak(pakFile);

            try
            {
                if (!fs.FileExists("/meta"))
                {
                    throw new InvalidOperationException("Missing metadata file.");
                }

                if (!fs.FileExists("/meta.icon"))
                {
                    throw new InvalidOperationException("Missing world icon.");
                }

                if (!fs.FileExists("/meta.boot"))
                {
                    throw new InvalidOperationException("Missing boot logo.");
                }

                if (!fs.FileExists("/wallpaper"))
                {
                    throw new InvalidOperationException("Missing wallpaper.");
                }

                using var metaStream = fs.OpenFile("/meta");
                using var reader     = new BinaryReader(metaStream, Encoding.UTF8);

                var name        = reader.ReadString();
                var author      = reader.ReadString();
                var description = reader.ReadString();

                var icon      = Texture2D.FromPak(gpu, fs.OpenFile("/meta.icon"));
                var wallpaper = Texture2D.FromPak(gpu, fs.OpenFile("/wallpaper"));
                var boot      = Texture2D.FromPak(gpu, fs.OpenFile("/meta.boot"));

                var pack = new InstalledContentPack();
                pack.Name        = name;
                pack.Description = description;
                pack.Author      = author;
                pack.Icon        = icon;
                pack.Backdrop    = wallpaper;
                pack.BootLogo    = boot;
                pack._dataReader = () => File.OpenRead(pakPath);

                return(pack);
            }
            catch (Exception ex)
            {
                pakFile.Dispose();
                throw new InvalidOperationException("Bad world pak", ex);
            }

            pakFile.Dispose();
            return(null);
        }