Ejemplo n.º 1
0
        private void LoadTextures(GraphicsDevice device, IProgressReceiver progressReceiver,
                                  McResourcePack resourcePack, bool isFirst)
        {
            progressReceiver.UpdateProgress(0, $"Loading textures: {resourcePack.Manifest?.Name ?? "Unknown"}");

            if (!isFirst)
            {
                Atlas.LoadResourcePackOnTop(device,
                                            ActiveResourcePacks.First().TexturesAsBitmaps.Where(x => x.Key.StartsWith("block")).ToArray(),
                                            resourcePack.TexturesAsBitmaps.Where(x => x.Key.StartsWith("block")).ToArray(),
                                            resourcePack.TextureMetas,
                                            progressReceiver);
            }
            else
            {
                Atlas.GenerateAtlas(device, resourcePack.TexturesAsBitmaps.Where(x => x.Key.StartsWith("block")).ToArray(),
                                    resourcePack.TextureMetas,
                                    progressReceiver);


                //Atlas.Atlas.Save("atlas.png", ImageFormat.Png);
            }

            //  if (!isFirst)
            {
                progressReceiver.UpdateProgress(0, $"Loading UI textures: {resourcePack.Manifest?.Name ?? "Unknown"}");
                Alex.GuiRenderer.LoadResourcePackTextures(resourcePack, progressReceiver);
            }
        }
Ejemplo n.º 2
0
        public Microsoft.Xna.Framework.Color GetFoliageColor(float temp, float rain, int elevation)
        {
            foreach (var resourcePack in ActiveResourcePacks.Reverse())
            {
                if (resourcePack.TryGetFoliageColor(temp, rain, elevation, out var color))
                {
                    return(color);
                }
            }

            return(new Microsoft.Xna.Framework.Color(94, 157, 52));
        }
Ejemplo n.º 3
0
        public bool TryGetBlockModel(ResourceLocation key, out ResourcePackModelBase model)
        {
            model = null;
            foreach (var resourcePack in ActiveResourcePacks.Reverse())
            {
                if (resourcePack.BlockModels.TryGetValue(key, out model))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 4
0
        public bool TryGetBlockState(string location, out BlockStateResource resource)
        {
            resource = null;
            foreach (var resourcePack in ActiveResourcePacks.Reverse())
            {
                if (resourcePack.TryGetBlockState(location, out resource))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 5
0
        public bool TryGetBitmap(ResourceLocation location, out Image <Rgba32> bitmap)
        {
            bitmap = null;
            foreach (var resourcePack in ActiveResourcePacks.Reverse())
            {
                if (resourcePack.TryGetBitmap(location, out var f))
                {
                    bitmap = f;
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 6
0
        private void LoadTextures(GraphicsDevice device, IProgressReceiver progressReceiver,
                                  McResourcePack resourcePack, bool isFirst)
        {
            progressReceiver.UpdateProgress(0, $"Loading textures: {resourcePack.Manifest?.Name ?? "Unknown"}");

            if (!isFirst)
            {
                Atlas.LoadResourcePackOnTop(device,
                                            ActiveResourcePacks.First(),
                                            resourcePack,
                                            progressReceiver);
            }
            else
            {
                Atlas.LoadResourcePack(device, resourcePack, progressReceiver);
            }

            //  if (!isFirst)
            {
                progressReceiver.UpdateProgress(0, $"Loading UI textures: {resourcePack.Manifest?.Name ?? "Unknown"}");
                Alex.GuiRenderer.LoadResourcePackTextures(resourcePack, progressReceiver);
            }
        }
Ejemplo n.º 7
0
        private void LoadResourcePacks(GraphicsDevice device, IProgressReceiver progress, string[] resourcePacks)
        {
            var countBefore = ActiveResourcePacks.Count;

            var first = ActiveResourcePacks.First.Value;

            ActiveResourcePacks.Clear();

            ActiveResourcePacks.AddFirst(first);

            if (_hasInit)
            {
                PreloadCallback?.Invoke(first.FontBitmap, McResourcePack.BitmapFontCharacters.ToList());
                Atlas.Reset();
            }

            foreach (string file in resourcePacks)
            {
                try
                {
                    string resourcePackPath = Path.Combine(ResourcePackDirectory.FullName, file);
                    if (File.Exists(resourcePackPath))
                    {
                        Log.Info($"Loading resourcepack {file}...");

                        using (FileStream stream = new FileStream(resourcePackPath, FileMode.Open))
                        {
                            var pack = LoadResourcePack(progress, stream, true, null);
                            if (pack.Manifest != null && string.IsNullOrWhiteSpace(pack.Manifest.Name))
                            {
                                pack.Manifest.Name = Path.GetFileNameWithoutExtension(file);
                            }
                            ActiveResourcePacks.AddLast(pack);
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Warn(e, $"Could not load resourcepack {file}: {e.ToString()}");
                }
            }

            bool isFirst = true;

            foreach (var resourcePack in ActiveResourcePacks)
            {
                Alex.GuiRenderer.LoadLanguages(resourcePack, progress);

                LoadTextures(device, progress, resourcePack, isFirst);

                if (isFirst)
                {
                    isFirst = false;
                }
            }

            isFirst = true;
            foreach (var resourcePack in ActiveResourcePacks)
            {
                LoadModels(progress, resourcePack, !isFirst, isFirst);
                if (isFirst)
                {         //Only load models for vanilla until above we fix blockstate replacement issues.
                    isFirst = false;
                    break;
                }
            }

            Alex.GuiRenderer.SetLanguage(Options.AlexOptions.MiscelaneousOptions.Language.Value);

            var f = ActiveResourcePacks.LastOrDefault(x => x.FontBitmap != null);

            if (f != null)
            {
                PreloadCallback?.Invoke(f.FontBitmap, McResourcePack.BitmapFontCharacters.ToList());
            }
        }
Ejemplo n.º 8
0
        public bool CheckResources(GraphicsDevice device, IProgressReceiver progressReceiver, McResourcePack.McResourcePackPreloadCallback preloadCallback)
        {
            PreloadCallback = preloadCallback;
            byte[] defaultResources;
            byte[] defaultBedrock;

            if (!CheckRequiredPaths(progressReceiver, out defaultResources, out defaultBedrock))
            {
                return(false);
            }

            Log.Info($"Loading registries...");
            progressReceiver?.UpdateProgress(0, "Loading registries...");
            Registries = JsonConvert.DeserializeObject <Registries>(ReadStringResource("Alex.Resources.registries.json"));
            progressReceiver?.UpdateProgress(100, "Loading registries...");

            Log.Info($"Loading vanilla resources...");
            using (MemoryStream stream = new MemoryStream(defaultResources))
            {
                var vanilla = LoadResourcePack(progressReceiver, stream, false, preloadCallback);
                vanilla.Manifest.Name = "Vanilla";

                ActiveResourcePacks.AddFirst(vanilla);
            }

            var bedrockPath = Path.Combine("assets", "bedrock");

            DirectoryInfo directory;

            if (!Storage.TryGetDirectory(bedrockPath, out directory))
            {
                Log.Warn($"The bedrock resources required to play this game are not set-up correctly!");
                Console.ReadLine();
                Environment.Exit(1);
                return(false);
            }

            /*if (!directories.Any(x => x.Name.Equals("models")))
             * {
             *                  Log.Warn($"Please make sure to extract the MC:Bedrock resource pack into \"{directory.FullName}\"");
             *  Console.ReadLine();
             *  Environment.Exit(1);
             *                  return false;
             * }*/

            if (directory.GetFileSystemInfos().Length == 0)
            {
                Log.Info($"Extracting required resources...");
                progressReceiver?.UpdateProgress(50, "Extracting resources...");

                byte[] zipped = defaultBedrock;    //ReadResource("Alex.Resources.resources.zip");
                using (MemoryStream ms = new MemoryStream(zipped))
                {
                    using (ZipArchive archive = new ZipArchive(ms, ZipArchiveMode.Read))
                    {
                        archive.ExtractToDirectory(directory.FullName);
                    }
                }
            }

            var directories = directory.GetDirectories();

            /*  if (!directories.Any(x => x.Name.Equals("definitions")))
             * {
             *                    Log.Warn($"The required definition files are not found. Any questions can be asked on Discord.");
             *    Console.ReadLine();
             *                    Environment.Exit(1);
             *    return false;
             * }*/
            //report(ResourcePack.AsciiFont);

            Log.Info($"Loading bedrock resources...");
            BedrockResourcePack = new BedrockResourcePack(directory);

            EntityFactory.LoadModels(this, device, true, progressReceiver);


            Log.Info($"Loading known entity data...");
            EntityFactory.Load(this, progressReceiver);

            Storage.TryGetDirectory(Path.Combine("assets", "resourcepacks"), out DirectoryInfo root);
            ResourcePackDirectory = root;

            LoadRegistries(progressReceiver);

            LoadResourcePacks(device, progressReceiver, Options.AlexOptions.ResourceOptions.LoadedResourcesPacks.Value);

            ItemFactory.Init(RegistryManager, this, ResourcePack, progressReceiver);

            if (Storage.TryGetDirectory(Path.Combine("assets", "bedrockpacks"), out DirectoryInfo info))
            {
                SkinPackDirectory = info;
                LoadBedrockPacks(progressReceiver, info);
            }
            else
            {
                if (Storage.TryCreateDirectory(Path.Combine("assets", "bedrockpacks")))
                {
                    if (Storage.TryGetDirectory(Path.Combine("assets", "bedrockpacks"), out var dirInfo))
                    {
                        SkinPackDirectory = dirInfo;
                    }
                }
            }

            Options.AlexOptions.ResourceOptions.LoadedResourcesPacks.Bind(ResourcePacksChanged);
            _hasInit = true;

            return(true);
        }
Ejemplo n.º 9
0
        public bool CheckResources(GraphicsDevice device, IProgressReceiver progressReceiver, McResourcePack.McResourcePackPreloadCallback preloadCallback)
        {
            LoadHWID();

            PreloadCallback = preloadCallback;

            Log.Info($"Loading registries...");
            progressReceiver?.UpdateProgress(0, "Loading registries...");
            Registries = JsonConvert.DeserializeObject <Registries>(ReadStringResource("Alex.Resources.registries.json"));
            progressReceiver?.UpdateProgress(100, "Loading registries...");

            string defaultResources;
            string defaultBedrock;

            if (!CheckJavaAssets(progressReceiver, out defaultResources))
            {
                return(false);
            }

            if (!CheckBedrockAssets(progressReceiver, out defaultBedrock))
            {
                return(false);
            }

            progressReceiver?.UpdateProgress(0, "Loading vanilla resources...");

            var vanilla = LoadResourcePack(progressReceiver, new RealFileSystem(defaultResources), preloadCallback);

            vanilla.Manifest.Name = "Vanilla";

            ActiveResourcePacks.AddFirst(vanilla);

            Alex.AudioEngine.Initialize(vanilla);

            // Log.Info($"Loading bedrock resources...");

            progressReceiver?.UpdateProgress(0, "Loading bedrock resources...");

            using (RealFileSystem fileSystem = new RealFileSystem(defaultBedrock))
            {
                BedrockResourcePack = new BedrockResourcePack(
                    fileSystem, (percentage, file) => { progressReceiver?.UpdateProgress(percentage, null, file); });

                int modelCount = EntityFactory.LoadModels(BedrockResourcePack, device, true, progressReceiver);

                Log.Info($"Imported {modelCount} entity models...");
            }

            //Log.Info($"Loading known entity data...");
            EntityFactory.Load(this, progressReceiver);

            Storage.TryGetDirectory(Path.Combine("assets", "resourcepacks"), out DirectoryInfo root);
            ResourcePackDirectory = root;

            LoadRegistries(progressReceiver);

            LoadResourcePacks(
                device, progressReceiver, Options.AlexOptions.ResourceOptions.LoadedResourcesPacks.Value);

            ItemFactory.Init(RegistryManager, this, ResourcePack, progressReceiver);

            BlockEntityFactory.LoadResources(device, ResourcePack);

            if (Storage.TryGetDirectory(Path.Combine("assets", "bedrockpacks"), out DirectoryInfo info))
            {
                SkinPackDirectory = info;
                LoadBedrockPacks(progressReceiver, info);
            }
            else
            {
                if (Storage.TryCreateDirectory(Path.Combine("assets", "bedrockpacks")))
                {
                    if (Storage.TryGetDirectory(Path.Combine("assets", "bedrockpacks"), out var dirInfo))
                    {
                        SkinPackDirectory = dirInfo;
                    }
                }
            }

            BlockMapper.Init(progressReceiver);

            Options.AlexOptions.ResourceOptions.LoadedResourcesPacks.Bind(ResourcePacksChanged);
            _hasInit = true;

            return(true);
        }
Ejemplo n.º 10
0
        public bool CheckResources(GraphicsDevice device, IProgressReceiver progressReceiver, McResourcePack.McResourcePackPreloadCallback preloadCallback)
        {
            LoadHWID();

            PreloadCallback = preloadCallback;

            Log.Info($"Loading registries...");
            progressReceiver?.UpdateProgress(0, "Loading registries...");
            Registries = JsonConvert.DeserializeObject <Registries>(ReadStringResource("Alex.Resources.registries.json"));
            progressReceiver?.UpdateProgress(100, "Loading registries...");

            byte[] defaultResources;
            byte[] defaultBedrock;

            if (!CheckJavaAssets(progressReceiver, out defaultResources))
            {
                return(false);
            }

            Log.Info($"Loading vanilla resources...");

            progressReceiver?.UpdateProgress(0, "Loading vanilla resources...");
            using (MemoryStream stream = new MemoryStream(defaultResources))
            {
                var vanilla = LoadResourcePack(progressReceiver, stream, false, preloadCallback);
                vanilla.Manifest.Name = "Vanilla";

                ActiveResourcePacks.AddFirst(vanilla);
            }

            if (!CheckBedrockAssets(progressReceiver, out defaultBedrock))
            {
                return(false);
            }

            var bedrockPath = Path.Combine("assets", "bedrock");

            DirectoryInfo directory;

            if (!Storage.TryGetDirectory(bedrockPath, out directory) && !Storage.TryCreateDirectory(bedrockPath))
            {
                Log.Warn($"The bedrock resources required to play this game are not set-up correctly!");
                Console.ReadLine();
                Environment.Exit(1);
                return(false);
            }

            if (directory.GetFileSystemInfos().Length == 0)
            {
                Log.Info($"Extracting required resources...");
                progressReceiver?.UpdateProgress(50, "Extracting resources...");

                byte[] zipped = defaultBedrock;    //ReadResource("Alex.Resources.resources.zip");
                using (MemoryStream ms = new MemoryStream(zipped))
                {
                    using (ZipArchive archive = new ZipArchive(ms, ZipArchiveMode.Read))
                    {
                        archive.ExtractToDirectory(directory.FullName);
                    }
                }
            }

            Log.Info($"Loading bedrock resources...");

            progressReceiver?.UpdateProgress(0, "Loading bedrock resources...");
            BedrockResourcePack = new BedrockResourcePack(directory, (percentage, file) =>
            {
                progressReceiver?.UpdateProgress(percentage, null, file);
            });

            EntityFactory.LoadModels(this, device, true, progressReceiver);


            Log.Info($"Loading known entity data...");
            EntityFactory.Load(this, progressReceiver);

            Storage.TryGetDirectory(Path.Combine("assets", "resourcepacks"), out DirectoryInfo root);
            ResourcePackDirectory = root;

            LoadRegistries(progressReceiver);

            LoadResourcePacks(device, progressReceiver, Options.AlexOptions.ResourceOptions.LoadedResourcesPacks.Value);

            ItemFactory.Init(RegistryManager, this, ResourcePack, progressReceiver);

            BlockEntityFactory.LoadResources(device, ResourcePack);

            if (Storage.TryGetDirectory(Path.Combine("assets", "bedrockpacks"), out DirectoryInfo info))
            {
                SkinPackDirectory = info;
                LoadBedrockPacks(progressReceiver, info);
            }
            else
            {
                if (Storage.TryCreateDirectory(Path.Combine("assets", "bedrockpacks")))
                {
                    if (Storage.TryGetDirectory(Path.Combine("assets", "bedrockpacks"), out var dirInfo))
                    {
                        SkinPackDirectory = dirInfo;
                    }
                }
            }

            Options.AlexOptions.ResourceOptions.LoadedResourcesPacks.Bind(ResourcePacksChanged);
            _hasInit = true;

            return(true);
        }
Ejemplo n.º 11
0
        private void LoadResourcePacks(GraphicsDevice device, IProgressReceiver progress, string[] resourcePacks)
        {
            var countBefore = ActiveResourcePacks.Count;

            var first  = ActiveResourcePacks.First.Value;
            var before = ActiveResourcePacks.ToArray();

            foreach (var item in before.Skip(1))
            {
                item.Dispose();
            }

            ActiveResourcePacks.Clear();

            ActiveResourcePacks.AddFirst(first);

            if (_hasInit)
            {
                PreloadCallback?.Invoke(first.FontBitmap, McResourcePack.BitmapFontCharacters.ToList());
                Atlas.Reset();
            }

            foreach (string file in resourcePacks)
            {
                try
                {
                    string resourcePackPath = Path.Combine(ResourcePackDirectory.FullName, file);
                    if (File.Exists(resourcePackPath))
                    {
                        //Log.Info($"Loading resourcepack {file}...");

                        //using (FileStream stream = new FileStream(resourcePackPath, FileMode.Open))
                        {
                            // using (ZipFileSystem zipFileSystem = )
                            {
                                var pack = LoadResourcePack(progress, new ZipFileSystem(new FileStream(resourcePackPath, FileMode.Open), Path.GetFileNameWithoutExtension(resourcePackPath)), null);

                                if (pack is McResourcePack javaPack)
                                {
                                    if (pack.Info != null && string.IsNullOrWhiteSpace(pack.Info.Name))
                                    {
                                        pack.Info.Name = Path.GetFileNameWithoutExtension(file);
                                    }

                                    ActiveResourcePacks.AddLast(javaPack);
                                }
                                else if (pack is BedrockResourcePack bedrockPack)
                                {
                                    ActiveBedrockResourcePacks.AddLast(bedrockPack);
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Warn(e, $"Could not load resourcepack {file}: {e.ToString()}");
                }
            }

            var  active  = ActiveResourcePacks.ToArray();
            bool isFirst = true;

            foreach (var resourcePack in active)
            {
                Alex.GuiRenderer.LoadLanguages(resourcePack, progress);

                LoadModels(progress, resourcePack, !isFirst, isFirst);
                if (isFirst)
                {         //Only load models for vanilla until above we fix blockstate replacement issues.
                    isFirst = false;
                    // break;
                }
            }

            Stopwatch sw = Stopwatch.StartNew();

            MeasureProfiler.StartCollectingData();
            var imported = BlockFactory.LoadBlockstates(RegistryManager, this, false, false, progress);

            MeasureProfiler.SaveData();

            MeasureProfiler.StopCollectingData();

            Log.Info($"Imported {imported} blockstates from resourcepack in {sw.ElapsedMilliseconds}ms!");

            var textures = new Dictionary <ResourceLocation, AtlasGenerator.ImageEntry>();

            for (var index = 0; index < active.Length; index++)
            {
                var resourcePack = active[index];

                progress?.UpdateProgress(0, $"Loading textures: {resourcePack.Info?.Name ?? "Unknown"}");

                Atlas.LoadResourcePackOnTop(device,
                                            textures,
                                            resourcePack,
                                            progress, index == active.Length - 1);
                //LoadTextures(device, progress, resourcePack, ref textures, index == active.Length - 1);
            }

            foreach (var resourcePack in ActiveBedrockResourcePacks)
            {
                LoadEntityModels(resourcePack, progress);
                int modelCount = EntityFactory.LoadModels(resourcePack, this, device, true, progress);

                Log.Info($"Imported {modelCount} entity models...");
            }

            progress?.UpdateProgress(0, $"Loading UI textures...");
            Alex.GuiRenderer.LoadResourcePackTextures(this, progress);

            progress?.UpdateProgress(50, "Loading language...");
            if (!Alex.GuiRenderer.SetLanguage(Options.AlexOptions.MiscelaneousOptions.Language.Value))
            {
                Alex.GuiRenderer.SetLanguage(CultureInfo.InstalledUICulture.Name);
            }

            progress?.UpdateProgress(100, "Loading language...");

            var f = ActiveResourcePacks.LastOrDefault(x => x.FontBitmap != null);

            if (f != null)
            {
                PreloadCallback?.Invoke(f.FontBitmap, McResourcePack.BitmapFontCharacters.ToList());
            }
        }
Ejemplo n.º 12
0
        public bool Asynchronous => true; //ActiveResourcePacks.All(x => x.Asynchronous);

        public bool CheckResources(GraphicsDevice device, IProgressReceiver progressReceiver, McResourcePack.McResourcePackPreloadCallback preloadCallback)
        {
            LoadHWID();

            PreloadCallback = preloadCallback;

            Log.Info($"Loading registries...");
            progressReceiver?.UpdateProgress(0, "Loading registries...");
            Registries = JsonConvert.DeserializeObject <Registries>(ReadStringResource("Alex.Resources.registries.json"));
            progressReceiver?.UpdateProgress(100, "Loading registries...");

            string defaultResources;
            string defaultBedrock;

            if (!CheckJavaAssets(progressReceiver, out defaultResources))
            {
                return(false);
            }

            if (!CheckBedrockAssets(progressReceiver, out defaultBedrock))
            {
                return(false);
            }

            progressReceiver?.UpdateProgress(0, "Loading vanilla resources...");

            var vanilla = LoadResourcePack(progressReceiver, new DiskFileSystem(defaultResources), preloadCallback);

            if (vanilla.Info != null)
            {
                vanilla.Info.Name = "Vanilla";
            }

            ActiveResourcePacks.AddFirst((McResourcePack)vanilla);

            Alex.AudioEngine.Initialize((McResourcePack)vanilla);

            // Log.Info($"Loading bedrock resources...");

            progressReceiver?.UpdateProgress(0, "Loading bedrock resources...");

            var vanillaBedrock = LoadResourcePack(progressReceiver, new DiskFileSystem(defaultBedrock));

            ActiveBedrockResourcePacks.AddFirst((BedrockResourcePack)vanillaBedrock);
            //Log.Info($"Loading known entity data...");

            Storage.TryGetDirectory(Path.Combine("assets", "resourcepacks"), out DirectoryInfo root);
            ResourcePackDirectory = root;

            LoadRegistries(progressReceiver);

            LoadResourcePacks(
                device, progressReceiver, Options.AlexOptions.ResourceOptions.LoadedResourcesPacks.Value);

            EntityFactory.Load(this, progressReceiver);

            ItemFactory.Init(RegistryManager, this, progressReceiver);

            BlockEntityFactory.LoadResources(device, this);

            if (Storage.TryGetDirectory(Path.Combine("assets", "bedrockpacks"), out DirectoryInfo info))
            {
                SkinPackDirectory = info;
                LoadBedrockPacks(progressReceiver, info);
            }
            else
            {
                if (Storage.TryCreateDirectory(Path.Combine("assets", "bedrockpacks")))
                {
                    if (Storage.TryGetDirectory(Path.Combine("assets", "bedrockpacks"), out var dirInfo))
                    {
                        SkinPackDirectory = dirInfo;
                    }
                }
            }

            BlockMapper.Init(progressReceiver);

            Options.AlexOptions.ResourceOptions.LoadedResourcesPacks.Bind(ResourcePacksChanged);
            _hasInit = true;

            var data = ReadResource("Alex.Resources.nethergames.png");

            NethergamesLogo = TextureUtils.BitmapToTexture2D(Alex.GraphicsDevice, Image.Load(data));

            return(true);
        }