/// <summary> /// Load a material from a file buffer, with labels. /// </summary> /// <param name="file">byte array representing file</param> /// <param name="address">address of this material within 'file' byte array.</param> /// <param name="labels"></param> public NJS_MATERIAL(byte[] file, int address, Dictionary <int, string> labels) { if (ByteConverter.BigEndian) { //"Reverse" is for the order used in SADX Gamecube if (ByteConverter.Reverse) { DiffuseColor = Color.FromArgb(file[address + 3], file[address], file[address + 1], file[address + 2]); SpecularColor = Color.FromArgb(file[address + 7], file[address + 4], file[address + 5], file[address + 6]); } else { DiffuseColor = Color.FromArgb(file[address], file[address + 1], file[address + 2], file[address + 3]); SpecularColor = Color.FromArgb(file[address + 4], file[address + 5], file[address + 6], file[address + 7]); } } else { DiffuseColor = Color.FromArgb(file[address + 3], file[address + 2], file[address + 1], file[address]); SpecularColor = Color.FromArgb(file[address + 7], file[address + 6], file[address + 5], file[address + 4]); } Exponent = ByteConverter.ToSingle(file, address + 8); TextureID = ByteConverter.ToInt32(file, address + 0xC); Flags = ByteConverter.ToUInt32(file, address + 0x10); }
public GeoAnimData(byte[] file, int address, uint imageBase, LandTableFormat format, Dictionary <int, string> labels, Dictionary <int, Attach> attaches) { ModelFormat mfmt = 0; switch (format) { case LandTableFormat.SA1: mfmt = ModelFormat.Basic; break; case LandTableFormat.SADX: mfmt = ModelFormat.BasicDX; break; case LandTableFormat.SA2: mfmt = ModelFormat.Chunk; break; } AnimationFrame = ByteConverter.ToSingle(file, address); AnimationSpeed = ByteConverter.ToSingle(file, address + 4); MaxFrame = ByteConverter.ToSingle(file, address + 8); Model = new NJS_OBJECT(file, (int)(ByteConverter.ToUInt32(file, address + 0xC) - imageBase), imageBase, mfmt, labels, attaches); int actionaddr = (int)(ByteConverter.ToUInt32(file, address + 0x10) - imageBase); TexlistPointer = ByteConverter.ToUInt32(file, address + 0x14); NJS_ACTION action = new NJS_ACTION(file, actionaddr, imageBase, mfmt, labels, attaches); Animation = action.Animation; }
public Vertex(byte[] file, int address) { if (address > file.Length - 12) { X = 0; Y = 0; Z = 0; } else { X = ByteConverter.ToSingle(file, address); Y = ByteConverter.ToSingle(file, address + 4); Z = ByteConverter.ToSingle(file, address + 8); } }
public UV(byte[] file, int address, bool UVH, bool chunk = false, bool xj = false) { if (xj) { U = ByteConverter.ToSingle(file, address); V = ByteConverter.ToSingle(file, address + 4); } //"Reverse" is for the order used in SADX Gamecube else if (ByteConverter.Reverse || !ByteConverter.BigEndian || chunk) { U = ByteConverter.ToInt16(file, address) / (UVH ? 1023f : 255f); V = ByteConverter.ToInt16(file, address + 2) / (UVH ? 1023f : 255f); } else { V = ByteConverter.ToInt16(file, address) / (UVH ? 1023f : 255f); U = ByteConverter.ToInt16(file, address + 2) / (UVH ? 1023f : 255f); } }
public BoundingSphere(byte[] file, int address) { Center = new Vertex(file, address); Radius = ByteConverter.ToSingle(file, address + Vertex.Size); }
public LandTable(byte[] file, int address, uint imageBase, LandTableFormat format, Dictionary <int, string> labels) { Format = format; if (labels.ContainsKey(address)) { Name = labels[address]; } else { Name = "landtable_" + address.ToString("X8"); } short colcnt = ByteConverter.ToInt16(file, address); Dictionary <int, Attach> attaches = new Dictionary <int, Attach>(); switch (format) { case LandTableFormat.SA1: case LandTableFormat.SADX: short anicnt = ByteConverter.ToInt16(file, address + 2); Attributes = (SA1LandtableAttributes)ByteConverter.ToInt16(file, address + 4); Flags = ByteConverter.ToInt16(file, address + 6); FarClipping = ByteConverter.ToSingle(file, address + 8); COL = new List <COL>(); int tmpaddr = ByteConverter.ToInt32(file, address + 0xC); if (tmpaddr != 0) { tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase); if (labels.ContainsKey(tmpaddr)) { COLName = labels[tmpaddr]; } else { COLName = "collist_" + tmpaddr.ToString("X8"); } for (int i = 0; i < colcnt; i++) { COL.Add(new COL(file, tmpaddr, imageBase, format, labels, attaches)); tmpaddr += SAModel.COL.Size(format); } } else { COLName = "collist_" + Extensions.GenerateIdentifier(); } Anim = new List <GeoAnimData>(); tmpaddr = ByteConverter.ToInt32(file, address + 0x10); if (tmpaddr != 0) { tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase); if (labels.ContainsKey(tmpaddr)) { AnimName = labels[tmpaddr]; } else { AnimName = "animlist_" + tmpaddr.ToString("X8"); } for (int i = 0; i < anicnt; i++) { Anim.Add(new GeoAnimData(file, tmpaddr, imageBase, format, labels, attaches)); tmpaddr += GeoAnimData.Size; } } else { AnimName = "animlist_" + Extensions.GenerateIdentifier(); } tmpaddr = ByteConverter.ToInt32(file, address + 0x14); if (tmpaddr != 0) { tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase); TextureFileName = file.GetCString(tmpaddr, Encoding.ASCII); } TextureList = ByteConverter.ToUInt32(file, address + 0x18); BinaryFilename = ByteConverter.ToInt32(file, address + 0x1C); BinaryLoadFunction = ByteConverter.ToInt32(file, address + 0x20); break; case LandTableFormat.SA2: case LandTableFormat.SA2B: short cnkcnt = ByteConverter.ToInt16(file, address + 2); FarClipping = ByteConverter.ToSingle(file, address + 0xC); COL = new List <COL>(); tmpaddr = ByteConverter.ToInt32(file, address + 0x10); if (tmpaddr != 0) { tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase); if (labels.ContainsKey(tmpaddr)) { COLName = labels[tmpaddr]; } else { COLName = "collist_" + tmpaddr.ToString("X8"); } for (int i = 0; i < colcnt; i++) { COL.Add(new COL(file, tmpaddr, imageBase, format, labels, cnkcnt < 0 ? null : (bool?)(i >= cnkcnt), attaches)); tmpaddr += SAModel.COL.Size(format); } } else { COLName = "collist_" + Extensions.GenerateIdentifier(); } Anim = new List <GeoAnimData>(); AnimName = "animlist_" + Extensions.GenerateIdentifier(); tmpaddr = ByteConverter.ToInt32(file, address + 0x18); if (tmpaddr != 0) { tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase); TextureFileName = file.GetCString(tmpaddr, Encoding.ASCII); } TextureList = ByteConverter.ToUInt32(file, address + 0x1C); break; } Metadata = new Dictionary <uint, byte[]>(); }
public COL(byte[] file, int address, uint imageBase, LandTableFormat format, Dictionary <int, string> labels, bool?forceBasic, Dictionary <int, Attach> attaches) { Bounds = new BoundingSphere(file, address); ModelFormat mfmt = 0; switch (format) { case LandTableFormat.SA1: mfmt = ModelFormat.Basic; break; case LandTableFormat.SADX: mfmt = ModelFormat.BasicDX; break; case LandTableFormat.SA2: if (forceBasic.HasValue && forceBasic.Value) { mfmt = ModelFormat.Basic; } else { mfmt = ModelFormat.Chunk; } break; case LandTableFormat.SA2B: if (forceBasic.HasValue && forceBasic.Value) { mfmt = ModelFormat.Basic; } else { mfmt = ModelFormat.GC; } break; } switch (format) { case LandTableFormat.SA1: case LandTableFormat.SADX: WidthY = ByteConverter.ToSingle(file, address + 0x10); WidthZ = ByteConverter.ToSingle(file, address + 0x14); uint tmpaddr = ByteConverter.ToUInt32(file, address + 0x18) - imageBase; Model = new NJS_OBJECT(file, (int)tmpaddr, imageBase, mfmt, labels, attaches); BlockBits = ByteConverter.ToUInt32(file, address + 0x1C); Flags = ByteConverter.ToInt32(file, address + 0x20); break; case LandTableFormat.SA2: case LandTableFormat.SA2B: Flags = ByteConverter.ToInt32(file, address + 0x1C); if (!forceBasic.HasValue && Flags >= 0) { mfmt = ModelFormat.Basic; } tmpaddr = ByteConverter.ToUInt32(file, address + 0x10) - imageBase; Model = new NJS_OBJECT(file, (int)tmpaddr, imageBase, mfmt, labels, attaches); WidthZ = ByteConverter.ToInt32(file, address + 0x14); BlockBits = ByteConverter.ToUInt32(file, address + 0x18); break; } }