Ejemplo n.º 1
0
        void AddToTree(FullAssetInfo asset)
        {
            if (asset.Filename == null)
            {
                return;
            }
            var      parts = asset.Filename.Split('\\');
            TreeNode node  = _rootNode;

            foreach (var dir in parts.Take(parts.Length - 1)) // Ensure parent nodes exist
            {
                if (!node.Nodes.ContainsKey(dir))
                {
                    node.Nodes.Add(dir, dir);
                }
                node = node.Nodes[dir];
            }

            string key  = Path.GetFileNameWithoutExtension(parts.Last());
            string name = string.IsNullOrEmpty(asset.Name)
                ? key
                : $"{asset.Name} ({asset.Id})";

            if (!node.Nodes.ContainsKey(key))
            {
                var newNode = node.Nodes.Add(key, name);
                newNode.Tag      = asset;
                newNode.NodeFont = asset.PaletteHints?.Count == 0 ? _boldFont : _defaultFont;
                _nodes[asset]    = newNode;
            }
        }
Ejemplo n.º 2
0
        IAssetViewer GetViewerForAsset(FullAssetInfo asset)
        {
            if (asset == null)
            {
                return(null);
            }

            switch (asset.Format)
            {
            case FileFormat.Unknown:
                break;

            case FileFormat.AmorphousSprite:
            case FileFormat.FixedSizeSprite:
            case FileFormat.HeaderPerSubImageSprite:
            case FileFormat.SingleHeaderSprite:
            case FileFormat.Font:
            case FileFormat.InterlacedBitmap:
            case FileFormat.Slab:
                return(_imageViewer);

            case FileFormat.StringTable:
            case FileFormat.SystemText:
            case FileFormat.Script:
            case FileFormat.ItemNames:
                return(_textViewer);

            case FileFormat.AudioSample:
            case FileFormat.SampleLibrary:
            case FileFormat.Song:
                return(_soundPlayer);

            case FileFormat.Palette:
            case FileFormat.PaletteCommon:
                break;

            case FileFormat.FlicVideo:
                break;

            case FileFormat.MapData:
            case FileFormat.Tileset:
            case FileFormat.CharacterData:
            case FileFormat.SpellData:
            case FileFormat.LabyrinthData:
            case FileFormat.ItemData:
                break;

            case FileFormat.BlockList:
            case FileFormat.EventSet:
            case FileFormat.PlayerInventory:
            case FileFormat.ChestInventory:
            case FileFormat.MerchantInventory:
            case FileFormat.MonsterGroup:
            case FileFormat.TranslationTable:
                break;
            }

            return(null);
        }
Ejemplo n.º 3
0
 AlbionSprite LoadSprite(string filename, FullAssetInfo conf)
 {
     using (var stream = File.OpenRead(filename))
         using (var br = new BinaryReader(stream))
         {
             return((AlbionSprite)GetLoader(conf).Load(br, stream.Length, filename, conf));
         }
 }
Ejemplo n.º 4
0
        IAssetLoader GetLoader(FullAssetInfo conf)
        {
            switch (conf.Parent.Format)
            {
            case FileFormat.AmorphousSprite: return(new AmorphousSpriteLoader());

            case FileFormat.MapData:
            case FileFormat.FixedSizeSprite: return(new FixedSizeSpriteLoader());

            case FileFormat.SingleHeaderSprite:
            case FileFormat.HeaderPerSubImageSprite: return(new HeaderBasedSpriteLoader());

            default: throw new NotImplementedException();
            }
        }
Ejemplo n.º 5
0
 static IAssetLoader GetLoader(FullAssetInfo conf) =>
 (conf.Parent.Format) switch
 {
Ejemplo n.º 6
0
 AlbionSprite LoadSprite(string filename, FullAssetInfo conf)
 {
     using var stream = File.OpenRead(Path.Combine(_core.BaseExportDirectory, filename));
     using var br     = new BinaryReader(stream);
     return((AlbionSprite)GetLoader(conf).Load(br, stream.Length, new AssetKey(AssetType.Picture), conf));
 }
Ejemplo n.º 7
0
        void AddToTree(string location, FullXldInfo xld)
        {
            var      parts = location.Split('\\');
            TreeNode node  = _rootNode;

            foreach (var dir in parts.Take(parts.Length - 1)) // Ensure parent nodes exist
            {
                if (!node.Nodes.ContainsKey(dir))
                {
                    node.Nodes.Add(dir, dir);
                }
                node = node.Nodes[dir];
            }

            string key = parts.Last();

            if (!key.EndsWith(".bin"))
            {
                return;
            }
            key = key.Substring(0, key.Length - 4);
            int number = int.Parse(key);

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

            FullAssetInfo asset = xld.Assets[number];

            string name = string.IsNullOrEmpty(asset.Name)
                ? key
                : $"{asset.Name} ({number})";

            if (!node.Nodes.ContainsKey(key))
            {
                var newNode = node.Nodes.Add(key, name);
                newNode.Tag      = asset;
                newNode.NodeFont = (asset.PaletteHints?.Count == 0) ? _boldFont : _defaultFont;
                _nodes[asset]    = newNode;
            }
        }

        (string, FullXldInfo) CurrentXld
        {
            get
            {
                if (fileTree.SelectedNode == null)
                {
                    return(null, null);
                }

                var node = fileTree.SelectedNode;
                if (int.TryParse(fileTree.SelectedNode.Name, out _))
                {
                    node = fileTree.SelectedNode.Parent;
                }

                string filename = "";
                while (node != _rootNode)
                {
                    filename = node.Name + "\\" + filename;
                    node     = node.Parent;
                }

                filename = filename.TrimEnd('\\');
                var fullXldPath = Path.GetFullPath(Path.Combine(Path.Combine(_generalConfig.BasePath, _generalConfig.ExportedXldPath), filename));
                return(_config.Xlds.ContainsKey(filename)
                    ? (fullXldPath, _config.Xlds[filename])
                    : (null, null));
            }
        }

        (string, FullAssetInfo) CurrentObject
        {
            get
            {
                if (!int.TryParse(fileTree.SelectedNode?.Name, out int number))
                {
                    return(null, null);
                }

                var(xldFilename, xld) = CurrentXld;
                if (xld == null || !xld.Assets.ContainsKey(number))
                {
                    return(null, null);
                }

                var filename = $"{xldFilename}\\{number:00}.bin";
                return(filename, xld.Assets[number]);
            }
        }

        void SyncSelectedPalettes()
        {
            var(filename, asset) = CurrentObject;
            if (asset == null)
            {
                return;
            }

            if (asset.PaletteHints == null)
            {
                asset.PaletteHints = new List <int>();
            }

            for (int index = 0; index < chkListPalettes.Items.Count; index++)
            {
                var item = (AlbionPalette)chkListPalettes.Items[index];
                chkListPalettes.SetItemChecked(index, asset.PaletteHints.Contains(item.Id));
            }

            if (!chkListPalettes.GetItemChecked(chkListPalettes.SelectedIndex) && chkListPalettes.CheckedIndices.Count > 0)
            {
                chkListPalettes.SelectedIndex = chkListPalettes.CheckedIndices[0];
            }
        }

        void FileTree_AfterSelect(object sender, TreeViewEventArgs e)
        {
            var(filename, asset) = CurrentObject;
            if (asset == null)
            {
                return;
            }
            SyncSelectedPalettes();

            trackWidth.Value = asset.EffectiveWidth == 0 ? 1 : asset.EffectiveWidth;
            trackFrame.Value = 0;
            textName.Text    = asset.Name;
            Render();

            if (_logicalSprite != null)
            {
                trackFrameCount.Value = _logicalSprite.Frames.Count;
                if (asset.Parent.Format == FileFormat.FixedSizeSprite &&
                    asset.Height != null &&
                    _logicalSprite.Frames[0].Height != asset.Height)
                {
                    asset.Height = _logicalSprite.Frames[0].Height;
                }
            }
        }

        #region Width
        void TrackWidth_ValueChanged(object sender, EventArgs e)
        {
            var(filename, asset) = CurrentObject;
            if (asset == null)
            {
                return;
            }

            if (!asset.Parent.Width.HasValue &&
                asset.Parent.Format == FileFormat.FixedSizeSprite &&
                asset.Width != trackWidth.Value)
            {
                asset.Width    = trackWidth.Value;
                _logicalSprite = null; // Force sprite reload
                _visualSprite  = null;
                Render();
            }

            if (sender != numWidth && (int)numWidth.Value != trackWidth.Value)
            {
                numWidth.Value = trackWidth.Value;
            }
        }

        void TrackWidth_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == Keys.Left && trackWidth.Value != 0)
            {
                trackWidth.Value = (int)(trackWidth.Value / (e.Shift ? 1.5 : 2.0));
                e.Handled        = true;
            }

            if (e.Control && e.KeyCode == Keys.Right)
            {
                var newValue = (int)(trackWidth.Value * (e.Shift ? 1.5 : 2.0));
                if (newValue > trackWidth.Maximum)
                {
                    newValue = trackWidth.Maximum;
                }
                trackWidth.Value = newValue;
                e.Handled        = true;
            }
        }

        void NumWidth_ValueChanged(object sender, EventArgs e)
        {
            if (sender != trackWidth && trackWidth.Value != (int)numWidth.Value)
            {
                trackWidth.Value = (int)numWidth.Value;
            }
        }

        void NumWidth_Enter(object sender, EventArgs e)
        {
            numWidth.Select(0, numWidth.Text.Length);
        }

        #endregion

        void TextName_TextChanged(object sender, EventArgs e)
        {
            var(filename, asset) = CurrentObject;
            if (asset != null)
            {
                asset.Name = textName.Text;
            }
        }

        void TrackFrameCount_ValueChanged(object sender, EventArgs e)
        {
            var(filename, asset) = CurrentObject;
            if (_logicalSprite != null && asset != null)
            {
                int?newHeight =
                    trackFrameCount.Value <= 1
                        ? (int?)null
                        : _logicalSprite.Height / trackFrameCount.Value;

                if (!asset.Parent.Height.HasValue &&
                    asset.Parent.Format == FileFormat.FixedSizeSprite &&
                    asset.Height != newHeight)
                {
                    asset.Height   = newHeight;
                    _logicalSprite = null; // Force sprite reload
                    _visualSprite  = null;
                    Render();
                }
            }

            if (sender != numFrameCount && (int)numFrameCount.Value != trackFrameCount.Value)
            {
                numFrameCount.Value = trackFrameCount.Value;
            }
        }

        void NumFrameCount_ValueChanged(object sender, EventArgs e)
        {
            if (sender != trackFrameCount && trackFrameCount.Value != (int)numFrameCount.Value)
            {
                trackFrameCount.Value = (int)numFrameCount.Value;
            }
        }

        void TrackFrame_ValueChanged(object sender, EventArgs e)
        {
            Render();
            if (sender != numFrame && (int)numFrame.Value != trackFrame.Value)
            {
                numFrame.Value = trackFrame.Value;
            }
        }

        void NumFrame_ValueChanged(object sender, EventArgs e)
        {
            if (sender != trackFrame && trackFrame.Value != (int)numFrame.Value)
            {
                trackFrame.Value = (int)numFrame.Value;
            }
        }

        void BtnSave_Click(object sender, EventArgs e)
        {
            SaveClicked?.Invoke(this, EventArgs.Empty);
        }

        void ChkListPalettes_SelectedIndexChanged(object sender, EventArgs e)
        {
            Render();
        }

        void ChkAnimate_CheckedChanged(object sender, EventArgs e)
        {
            if (chkAnimate.Checked)
            {
                _timer.Start();
            }
            else
            {
                _timer.Stop();
            }
        }

        void FileTree_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == Keys.X && _logicalSprite != null)
            {
                trackWidth.Value = _logicalSprite.Frames[0].Height;
            }

            var(_, asset) = CurrentObject;
            if (e.Control && e.KeyCode == Keys.C && asset != null)
            {
                _savedPalettes = asset.PaletteHints.ToList();
            }

            if (e.Control && e.KeyCode == Keys.V && asset != null && _savedPalettes != null)
            {
                asset.PaletteHints.Clear();
                foreach (var palette in _savedPalettes)
                {
                    asset.PaletteHints.Add(palette);
                }
                SyncSelectedPalettes();
            }
        }

        void ChkListPalettes_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            var(_, asset) = CurrentObject;
            if (asset == null)
            {
                return;
            }

            var palette = (AlbionPalette)chkListPalettes.Items[e.Index];

            if (e.NewValue == CheckState.Checked)
            {
                if (!asset.PaletteHints.Contains(palette.Id))
                {
                    asset.PaletteHints.Add(palette.Id);
                }
            }
            else
            {
                asset.PaletteHints.Remove(palette.Id);
            }

            _nodes[asset].NodeFont = asset.PaletteHints?.Count == 0 ? _boldFont : _defaultFont;
        }
    }
Ejemplo n.º 8
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);
                    }
            }
        }
Ejemplo n.º 9
0
 public SelectedAssetChangedArgs(FullXldInfo selectedXld, FullAssetInfo selectedObject)
 {
     SelectedXld    = selectedXld;
     SelectedObject = selectedObject;
 }
Ejemplo n.º 10
0
 public AssetChangedArgs(FullAssetInfo asset)
 {
     Asset = asset;
 }
Ejemplo n.º 11
0
 public void TriggerAssetChanged(FullAssetInfo asset) => AssetChanged?.Invoke(this, new AssetChangedArgs(asset));