Exemplo n.º 1
0
        protected static ResourcePackManifest GetManifest(IFilesystem archive, ResourcePackType type)
        {
            if (type == ResourcePackType.Java)
            {
                var entry = archive.GetEntry("pack.mcmeta");
                if (entry != null)
                {
                    ResourcePackInfo info;
                    using (TextReader reader = new StreamReader(entry.Open()))
                    {
                        ResourcePackInfoWrapper wrap = MCJsonConvert.DeserializeObject <ResourcePackInfoWrapper>(reader.ReadToEnd());
                        info = wrap.pack;
                    }

                    try
                    {
                        var imgEntry = archive.GetEntry("pack.png");
                        if (imgEntry != null)
                        {
                            // Bitmap bmp = new Bitmap(imgEntry.Open());
                            using (var stream = imgEntry.Open())
                            {
                                var bmp = Image.Load <Rgba32>(stream.ReadToSpan(entry.Length));
                                return(new ResourcePackManifest(bmp, "", info.Description));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Warn(ex, $"Could not read resourcepack logo: {archive.ToString()}");
                    }

                    return(new ResourcePackManifest("", info.Description));
                }
                else
                {
                    throw new InvalidResourcePackException();
                }
            }
            else if (type == ResourcePackType.Bedrock)
            {
            }

            return(null);
        }
Exemplo n.º 2
0
        public Stream GetStream(string path)
        {
            var entry = _archive.GetEntry(path);

            if (entry == null)
            {
                throw new FileNotFoundException();
            }

            return(entry.Open());
        }
Exemplo n.º 3
0
        public static ResourcePack LoadFromArchive(IFilesystem archive)
        {
            ResourcePack pack = new ResourcePack();

            if (archive.GetEntry("pack.mcmeta") != null)
            {
                pack.Type = ResourcePackType.Java;
            }
            else if (archive.GetEntry("manifest.json") != null)
            {
                pack.Type = ResourcePackType.Bedrock;
            }
            else
            {
                throw new InvalidResourcePackException();
            }

            pack.Info = GetManifest(archive, pack.Type);

            return(pack);
        }
Exemplo n.º 4
0
        public static ResourcePackManifest GetManifest(IFilesystem archive)
        {
            //if (archive.GetEntry("pack.mcmeta") != null)

            var entry = archive.GetEntry("pack.mcmeta");

            if (entry != null)
            {
                ResourcePackInfo info;

                using (TextReader reader = new StreamReader(entry.Open()))
                {
                    ResourcePackInfoWrapper wrap =
                        MCJsonConvert.DeserializeObject <ResourcePackInfoWrapper>(reader.ReadToEnd());

                    info = wrap.pack;
                }

                try
                {
                    var imgEntry = archive.GetEntry("pack.png");

                    if (imgEntry != null && imgEntry.Length > 0)
                    {
                        // Bitmap bmp = new Bitmap(imgEntry.Open());
                        using (var stream = imgEntry.Open())
                        {
                            //var data = stream.ReadToSpan(entry.Length);

                            var bmp = Image.Load(stream).CloneAs <Rgba32>();

                            return(new ResourcePackManifest(bmp, "", info.Description, ResourcePackType.Java));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Warn(ex, $"Could not read resourcepack logo: {archive.ToString()}");
                }

                return(new ResourcePackManifest("", info.Description, ResourcePackType.Java));
            }

            entry = archive.GetEntry("manifest.json");

            if (entry != null)
            {
                //Load bedrock meta
                McPackManifest info;

                using (TextReader reader = new StreamReader(entry.Open()))
                {
                    info =
                        MCJsonConvert.DeserializeObject <McPackManifest>(reader.ReadToEnd());

                    //info = new ResourcePackInfo() {Description = wrap.Header.Description};
                    //info = wrap.pack;
                }

                try
                {
                    var imgEntry = archive.GetEntry("pack_icon.png");

                    if (imgEntry != null && imgEntry.Length > 0)
                    {
                        // Bitmap bmp = new Bitmap(imgEntry.Open());
                        using (var stream = imgEntry.Open())
                        {
                            //var data = stream.ReadToSpan(entry.Length);

                            var bmp = Image.Load(stream).CloneAs <Rgba32>();

                            return(new ResourcePackManifest(bmp, info.Header.Name, info.Header.Description, ResourcePackType.Bedrock));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Warn(ex, $"Could not read resourcepack logo: {archive.ToString()}");
                }

                return(new ResourcePackManifest(info.Header.Name, info.Header.Description, ResourcePackType.Bedrock));
            }


            return(null);
        }
Exemplo n.º 5
0
        private void Load(IFilesystem archive)
        {
            var manifestEntry = archive.GetEntry("manifest.json");
            var contentEntry  = archive.GetEntry("content.zipe");

            if (manifestEntry == null)
            {
                throw new InvalidMCPackException("No manifest found!");
            }

            Manifest = MCJsonConvert.DeserializeObject <McPackManifest>(manifestEntry.ReadAsString());

            if (contentEntry == null)
            {
                throw new InvalidMCPackException($"No content found for MCPack: {Manifest.Header.Name}");
            }

            List <MCPackModule> modules = new List <MCPackModule>();

            foreach (var module in Manifest.Modules)
            {
                switch (module.Type.ToLower())
                {
                case "skin_pack":
                    try
                    {
                        MCSkinPack skinPack = new MCSkinPack(contentEntry);
                        modules.Add(skinPack);
                    }
                    catch
                    {
                    }
                    break;
                }
            }

            List <MCPackModule> toRemove = new List <MCPackModule>();

            foreach (var module in modules)
            {
                bool loaded = false;
                try
                {
                    loaded = module.Load();
                    loaded = true;
                }
                catch (Exception ex)
                {
                    Log.Error(ex, $"Failed to load MCPack module: {module.Name} from {Manifest.Header.Name}: {ex}");
                    //toRemove.Add(module);
                }

                if (!loaded)
                {
                    Log.Warn($"Failed to load MCPack module \'{module.Name}\' from {Manifest.Header.Name}.");
                    toRemove.Add(module);
                }
            }

            foreach (var rm in toRemove)
            {
                modules.Remove(rm);
            }

            Modules = modules.ToArray();
        }