1
0
mirror of synced 2024-12-01 02:27:22 +01:00

Support MTXT editing. Add file extensions to files inside PKG.

This commit is contained in:
KillzXGaming 2021-10-10 14:06:08 -04:00
parent 0f1ff1b45c
commit 08aae51016
2 changed files with 76 additions and 11 deletions

View File

@ -70,6 +70,24 @@ namespace FirstPlugin
file.FileDataStream = new SubStream(reader.BaseStream,
fileStartOffset, size);
string ext = ".bin";
if (size > 4)
{
using (reader.TemporarySeek(fileStartOffset, SeekOrigin.Begin)) {
string magic = reader.ReadString(4);
if (magic == "FWAV") ext = ".bfwav";
if (magic == "MTXT") ext = ".bctext";
if (magic == "MCAN") ext = ".mcamera";
if (magic == "MANM") ext = ".manim";
if (magic == "MSAS") ext = ".msas";
if (magic == "MMDL") ext = ".mmodel";
if (magic == "MSUR") ext = ".mmaterial";
if (magic == "MNAV") ext = ".mnavigation";
}
}
file.FileName += ext;
files.Add(file);
}
}

View File

@ -12,7 +12,7 @@ namespace FirstPlugin
{
public FileType FileType { get; set; } = FileType.Image;
public bool CanSave { get; set; }
public bool CanSave { get; set; } = true;
public string[] Description { get; set; } = new string[] { "MTXT" };
public string[] Extension { get; set; } = new string[] { "*.bctex" };
public string FileName { get; set; }
@ -44,6 +44,12 @@ namespace FirstPlugin
public bool DisplayIcons => false;
XTX TextureFile;
uint HeaderFlags;
ulong UnkData;
int TextureFlag;
public void Load(System.IO.Stream stream)
{
Text = this.FileName;
@ -51,23 +57,25 @@ namespace FirstPlugin
using (var reader = new FileReader(stream))
{
reader.ReadSignature(4, "MTXT");
reader.ReadBytes(4);
var comp = reader.ReadBytes((int)reader.BaseStream.Length - 8);
HeaderFlags = reader.ReadUInt32();
var comp = reader.ReadBytes((int)reader.BaseStream.Length - 8);
var decomp = STLibraryCompression.GZIP.Decompress(comp);
ReadTextureBinary(decomp);
}
}
private void ReadTextureBinary(byte[] data)
{
using (var reader = new FileReader(data))
{
//Note offsets are -8 relative due to decomp data and header being 8 bytes long
reader.ReadUInt64();
UnkData = reader.ReadUInt64();
uint w = reader.ReadUInt32(); //width
uint h = reader.ReadUInt32(); //height
reader.ReadUInt32(); //num mips
reader.ReadUInt32(); //unk (-1)
TextureFlag = reader.ReadInt32(); //unk (-1)
uint nameOffset = reader.ReadUInt32(); //name offset
reader.ReadUInt32();
var textureOffset = reader.ReadUInt32(); //texture xtx offset
@ -80,20 +88,59 @@ namespace FirstPlugin
}
var stream = new SubStream(reader.BaseStream, (long)textureOffset - 8, (long)textureSize);
XTX xtx = new XTX();
xtx.FileName = textureName;
xtx.Load(stream);
this.Tag = xtx;
foreach (STGenericTexture node in xtx.Nodes)
TextureFile = new XTX();
TextureFile.FileName = textureName;
TextureFile.Load(stream);
this.Tag = TextureFile;
foreach (STGenericTexture node in TextureFile.Nodes)
Nodes.Add(node);
TextureList = xtx.TextureList;
TextureList = TextureFile.TextureList;
}
}
public void Save(System.IO.Stream stream)
{
using (var writer = new FileWriter(stream))
{
writer.WriteSignature("MTXT");
writer.Write(HeaderFlags);
writer.Write(STLibraryCompression.GZIP.Compress(WriteTextureBinary()));
}
}
private byte[] WriteTextureBinary()
{
//Save XTX file binary
var binaryMem = new System.IO.MemoryStream();
TextureFile.Save(binaryMem);
var rawTextureFile = binaryMem.ToArray();
var mem = new System.IO.MemoryStream();
using (var writer = new FileWriter(mem))
{
//Write file header
writer.Write(UnkData);
writer.Write(TextureFile.TextureList[0].Width);
writer.Write(TextureFile.TextureList[0].Height);
writer.Write(TextureFile.TextureList[0].MipCount);
writer.Write(TextureFlag);
writer.Write(uint.MaxValue); //reserve name offset
writer.Write(0);
writer.Write(uint.MaxValue); //data offset
writer.Write(0);
writer.Write(rawTextureFile.Length); //data size
for (int i = 0; i < 19; i++)
writer.Write(0xFFFFFFFF);
//Write xtx file data
writer.WriteUint32Offset(32, -8);
writer.Write(rawTextureFile);
writer.WriteUint32Offset(24, -8);
writer.WriteString(Text);
}
return mem.ToArray();
}
public void Unload()