예제 #1
0
        void MainFrm_Load(object sender, EventArgs e)
        {
            _rootNode = fileTree.Nodes.Add("Files");
            var exportedDir = Path.GetFullPath(Path.Combine(_generalConfig.BasePath, _generalConfig.ExportedXldPath));
            var files       = Directory.EnumerateFiles(exportedDir, "*.*", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                var absDir      = Path.GetDirectoryName(file);
                var relativeDir = absDir.Substring(exportedDir.Length).TrimStart('\\').Replace("\\", "/");
                if (relativeDir.Length == 0)
                {
                    continue;
                }

                if (!_config.Xlds.ContainsKey(relativeDir))
                {
                    _config.Xlds.Add(relativeDir, new FullXldInfo());
                }

                var relative = file.Substring(exportedDir.Length + 1);
                var xld      = _config.Xlds[relativeDir];
                AddToTree(relative, xld);
            }

            var commonPalette = File.ReadAllBytes(Path.Combine(_generalConfig.BasePath, _generalConfig.XldPath, "PALETTE.000"));

            var palettesPath = Path.Combine(exportedDir, "PALETTE0.XLD");

            files = Directory.EnumerateFiles(palettesPath, "*.*", SearchOption.AllDirectories);
            foreach (var file in files)
            {
                var a             = file.Substring(palettesPath.Length + 1, 2);
                int paletteNumber = int.Parse(a);
                var assetConfig   = _config.Xlds["PALETTE0.XLD"].Assets[paletteNumber];
                var paletteName   = assetConfig.Name;
                if (string.IsNullOrEmpty(paletteName))
                {
                    paletteName = file.Substring(exportedDir.Length + 1);
                }

                using (var stream = File.Open(file, FileMode.Open))
                    using (var br = new BinaryReader(stream))
                    {
                        var palette = new AlbionPalette(br, (int)br.BaseStream.Length, paletteName, paletteNumber);
                        palette.SetCommonPalette(commonPalette);
                        chkListPalettes.Items.Add(palette);
                    }
            }

            chkListPalettes.SelectedIndex = 0;
            _rootNode.Expand();
            _timer.Start();
        }
예제 #2
0
        public ReverserCore(GeneralConfig generalConfig, FullAssetConfig config)
        {
            GeneralConfig = generalConfig;
            Config        = config;

            BaseExportDirectory = Path.GetFullPath(Path.Combine(GeneralConfig.BasePath, GeneralConfig.ExportedXldPath));
            var files = Directory.EnumerateFiles(BaseExportDirectory, "*.*", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                var absDir      = Path.GetDirectoryName(file) ?? "";
                var relativeDir = absDir.Substring(BaseExportDirectory.Length).TrimStart('\\').Replace("\\", "/");
                if (relativeDir.Length == 0)
                {
                    continue;
                }

                if (!Config.Xlds.ContainsKey(relativeDir))
                {
                    Config.Xlds.Add(relativeDir, new FullXldInfo());
                }

                var xld = Config.Xlds[relativeDir];
                if (!Xlds.ContainsKey(relativeDir))
                {
                    Xlds.Add(relativeDir, xld);
                }

                var    relative = file.Substring(BaseExportDirectory.Length + 1);
                var    parts    = relative.Split('\\');
                string key      = parts.Last();
                key = Path.GetFileNameWithoutExtension(key);
                if (!int.TryParse(key, out var number))
                {
                    continue;
                }

                if (!xld.Assets.ContainsKey(number))
                {
                    xld.Assets[number] = new FullAssetInfo();
                }

                FullAssetInfo asset = xld.Assets[number];
                asset.Filename = relative;
            }

            var commonPalette = File.ReadAllBytes(Path.Combine(GeneralConfig.BasePath, GeneralConfig.XldPath, "PALETTE.000"));

            var palettesPath = Path.Combine(BaseExportDirectory, "PALETTE0.XLD");

            files = Directory.EnumerateFiles(palettesPath, "*.*", SearchOption.AllDirectories);
            foreach (var file in files)
            {
                var    a             = file.Substring(palettesPath.Length + 1, 2);
                ushort paletteNumber = ushort.Parse(a);
                var    assetConfig   = Config.Xlds["PALETTE0.XLD"].Assets[paletteNumber];
                var    paletteName   = assetConfig.Name;
                if (string.IsNullOrEmpty(paletteName))
                {
                    paletteName = file.Substring(BaseExportDirectory.Length + 1);
                }

                using (var stream = File.Open(file, FileMode.Open))
                    using (var br = new BinaryReader(stream))
                    {
                        var palette = new AlbionPalette(br, (int)br.BaseStream.Length, new AssetKey(AssetType.Palette, paletteNumber), paletteNumber);
                        palette.SetCommonPalette(commonPalette);
                        Palettes.Add(palette);
                    }
            }
        }