Exemplo n.º 1
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);
        }
Exemplo n.º 2
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...");
            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 (!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);

            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);
        }
Exemplo n.º 3
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);
        }