Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public void Save(string filename)
{
bool be = ByteConverter.BigEndian;
ByteConverter.BigEndian = false;
List<byte> file = new List<byte>();
file.AddRange(ByteConverter.GetBytes(SAANIMVer));
Dictionary<string, uint> labels = new Dictionary<string, uint>();
byte[] anim = GetBytes(0x14, labels, out uint addr);
file.AddRange(ByteConverter.GetBytes(addr + 0x14));
file.Align(0x10);
file.AddRange(ByteConverter.GetBytes(ModelParts | (ShortRot ? int.MinValue : 0)));
file.Align(0x14);
file.AddRange(anim);
file.Align(4);
file.RemoveRange(0xC, 4);
file.InsertRange(0xC, ByteConverter.GetBytes(file.Count + 4));
if (labels.Count > 0)
{
List<byte> chunk = new List<byte>((labels.Count * 8) + 8);
int straddr = (labels.Count * 8) + 8;
List<byte> strbytes = new List<byte>();
foreach (KeyValuePair<string, uint> label in labels)
{
chunk.AddRange(ByteConverter.GetBytes(label.Value));
chunk.AddRange(ByteConverter.GetBytes(straddr + strbytes.Count));
strbytes.AddRange(Encoding.UTF8.GetBytes(label.Key));
strbytes.Add(0);
strbytes.Align(4);
}
chunk.AddRange(ByteConverter.GetBytes(-1L));
chunk.AddRange(strbytes);
file.AddRange(ByteConverter.GetBytes((uint)ChunkTypes.Label));
file.AddRange(ByteConverter.GetBytes(chunk.Count));
file.AddRange(chunk);
file.AddRange(ByteConverter.GetBytes((uint)ChunkTypes.End));
file.AddRange(new byte[4]);
}
File.WriteAllBytes(filename, file.ToArray());
ByteConverter.BigEndian = be;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.