Initial commit

This commit is contained in:
Yukai Li 2021-02-16 01:04:29 -07:00
commit 0f86b0434b
38 changed files with 2370 additions and 0 deletions

View file

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace LibDgf.Aqualead.Texture
{
public struct AlPoint
{
public short X;
public short Y;
}
}

View file

@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace LibDgf.Aqualead.Texture
{
public class AlTexture
{
public AlTextureFlags Flags { get; set; }
public List<AlTextureEntry> ChildTextures { get; set; } = new List<AlTextureEntry>();
public short Width { get; set; }
public short Height { get; set; }
public uint IndirectReference { get; set; }
public byte[] ImageData { get; set; }
public void Read(BinaryReader br)
{
var baseOffset = br.BaseStream.Position;
if (new string(br.ReadChars(4)) != "ALTX")
throw new InvalidDataException("Not an Aqualead texture.");
bool isMultitexture = br.ReadBoolean();
Flags = (AlTextureFlags)br.ReadByte();
ushort numTextures = br.ReadUInt16();
uint imgOffset = br.ReadUInt32();
ushort[] entryOffsets = new ushort[numTextures];
for (int i = 0; i < numTextures; ++i)
{
entryOffsets[i] = br.ReadUInt16();
}
ChildTextures.Clear();
uint entryOffset = 0;
for (int i = 0; i < numTextures; ++i)
{
entryOffset += entryOffsets[i];
br.BaseStream.Seek(baseOffset + entryOffset, SeekOrigin.Begin);
AlTextureEntry entry = new AlTextureEntry();
entry.Read(br, isMultitexture);
ChildTextures.Add(entry);
}
if ((Flags & AlTextureFlags.IsSpecial) != 0)
{
if ((Flags & AlTextureFlags.IsIndirect) != 0)
{
IndirectReference = br.ReadUInt32();
return;
}
else if ((Flags & AlTextureFlags.IsOverrideDimensions) != 0)
{
Width = br.ReadInt16();
Height = br.ReadInt16();
}
}
br.BaseStream.Seek(baseOffset + imgOffset, SeekOrigin.Begin);
ImageData = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position));
}
}
}

View file

@ -0,0 +1,53 @@
using GMWare.IO;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace LibDgf.Aqualead.Texture
{
public class AlTextureEntry
{
public uint Id { get; set; }
public AlTextureEntryFlags Flags { get; set; }
public string Name { get; set; }
public List<AlXYWH> Bounds { get; set; } = new List<AlXYWH>();
public AlPoint CenterPoint { get; set; }
public void Read(BinaryReader br, bool isMultiTexture)
{
var baseOffset = br.BaseStream.Position;
Id = br.ReadUInt32();
ushort mipsCount = br.ReadUInt16();
Flags = (AlTextureEntryFlags)br.ReadByte();
br.ReadByte(); // Alignment
if (!isMultiTexture) return;
for (int i = 0; i < mipsCount; ++i)
{
Bounds.Add(new AlXYWH
{
X = br.ReadInt16(),
Y = br.ReadInt16(),
W = br.ReadUInt16(),
H = br.ReadUInt16()
});
}
if ((Flags & AlTextureEntryFlags.IsHasCenterPoint) != 0)
{
CenterPoint = new AlPoint
{
X = br.ReadInt16(),
Y = br.ReadInt16()
};
}
if ((Flags & AlTextureEntryFlags.IsHasName) != 0)
{
br.BaseStream.Seek(baseOffset - 0x20, SeekOrigin.Begin);
Name = StringReadingHelper.ReadNullTerminatedStringFromFixedSizeBlock(br, 0x20, Encoding.UTF8);
}
}
}
}

View file

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace LibDgf.Aqualead.Texture
{
[Flags]
public enum AlTextureEntryFlags : byte
{
IsHasName = 1 << 0,
IsHasCenterPoint = 1 << 1,
IsFiltered = 1 << 2
}
}

View file

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace LibDgf.Aqualead.Texture
{
[Flags]
public enum AlTextureFlags : byte
{
IsSpecial = 1 << 1,
IsIndirect = 1 << 2,
IsOverrideDimensions = 1 << 3
}
}

View file

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace LibDgf.Aqualead.Texture
{
public struct AlXYWH
{
public short X;
public short Y;
public ushort W;
public ushort H;
}
}