public Triangle(byte[] file, int address) : this() { Indexes[0] = ByteConverter.ToUInt16(file, address); Indexes[1] = ByteConverter.ToUInt16(file, address + 2); Indexes[2] = ByteConverter.ToUInt16(file, address + 4); }
public Animation(byte[] file, int address, uint imageBase, int nummodels, Dictionary <int, string> labels) { if (labels.ContainsKey(address)) { Name = labels[address]; } else { Name = "animation_" + address.ToString("X8"); } Int32 ptr = address; Frames = ByteConverter.ToInt32(file, ptr + 4); AnimFlags animtype = (AnimFlags)ByteConverter.ToUInt16(file, ptr + 8); int framesize = (ByteConverter.ToUInt16(file, ptr + 10) & 0xF) * 8; ptr = (int)(ByteConverter.ToUInt32(file, ptr) - imageBase); for (int i = 0; i < nummodels; i++) { Models.Add(i, new AnimModelData(file, ptr + (i * framesize), imageBase, animtype)); if (Models[i].Position.Count == 0 & Models[i].Rotation.Count == 0 & Models[i].Scale.Count == 0) { Models.Remove(i); } } ModelParts = nummodels; }
public Quad(byte[] file, int address) : this() { Indexes[0] = ByteConverter.ToUInt16(file, address); Indexes[1] = ByteConverter.ToUInt16(file, address + 2); Indexes[2] = ByteConverter.ToUInt16(file, address + 4); Indexes[3] = ByteConverter.ToUInt16(file, address + 6); }
public Strip(byte[] file, int address) { Indexes = new ushort[ByteConverter.ToUInt16(file, address) & 0x7FFF]; Reversed = (ByteConverter.ToUInt16(file, address) & 0x8000) == 0x8000; address += 2; for (int i = 0; i < Indexes.Length; i++) { Indexes[i] = ByteConverter.ToUInt16(file, address); address += 2; } }
public PolyChunkVolume(byte[] file, int address) { Header = ByteConverter.ToUInt16(file, address); address += sizeof(ushort); Size = ByteConverter.ToUInt16(file, address); address += sizeof(ushort); Header2 = ByteConverter.ToUInt16(file, address); address += sizeof(ushort); Polys = new List <Poly>(PolyCount); for (int i = 0; i < PolyCount; i++) { Poly str = Poly.CreatePoly(Type, file, address, UserFlags); Polys.Add(str); address += str.Size; } }
public PolyChunkStrip(byte[] file, int address) { Header = ByteConverter.ToUInt16(file, address); address += sizeof(ushort); Size = ByteConverter.ToUInt16(file, address); address += sizeof(ushort); Header2 = ByteConverter.ToUInt16(file, address); address += sizeof(ushort); int stripCount = Header2 & 0x3FFF; Strips = new List <Strip>(stripCount); for (int i = 0; i < stripCount; i++) { Strip str = new Strip(file, address, Type, UserFlags); Strips.Add(str); address += str.Size; } }
public PolyChunkMaterialBump(byte[] file, int address) { Header = ByteConverter.ToUInt16(file, address); address += sizeof(ushort); Size = ByteConverter.ToUInt16(file, address); address += sizeof(ushort); DX = ByteConverter.ToUInt16(file, address); address += sizeof(ushort); DY = ByteConverter.ToUInt16(file, address); address += sizeof(ushort); DZ = ByteConverter.ToUInt16(file, address); address += sizeof(ushort); UX = ByteConverter.ToUInt16(file, address); address += sizeof(ushort); UY = ByteConverter.ToUInt16(file, address); address += sizeof(ushort); UZ = ByteConverter.ToUInt16(file, address); address += sizeof(ushort); }
public Triangle(byte[] file, int address, byte userFlags) : this() { Indexes[0] = ByteConverter.ToUInt16(file, address); Indexes[1] = ByteConverter.ToUInt16(file, address + 2); Indexes[2] = ByteConverter.ToUInt16(file, address + 4); if (userFlags > 0) { UserFlags1 = ByteConverter.ToUInt16(file, address + 6); if (userFlags > 1) { UserFlags2 = ByteConverter.ToUInt16(file, address + 8); if (userFlags > 2) { UserFlags3 = ByteConverter.ToUInt16(file, address + 10); } } } }
public static Color FromBytes(byte[] file, int address, ColorType type) { switch (type) { case ColorType.ARGB8888_32: return(Color.FromArgb(ByteConverter.ToInt32(file, address))); case ColorType.XRGB8888_32: return(Color.FromArgb(unchecked ((int)(ByteConverter.ToUInt32(file, address) | 0xFF000000u)))); case ColorType.ARGB8888_16: return(Color.FromArgb((ByteConverter.ToUInt16(file, address + 2) << 16) | ByteConverter.ToUInt16(file, address))); case ColorType.XRGB8888_16: return(Color.FromArgb(unchecked ((int)((uint)((ByteConverter.ToUInt16(file, address + 2) << 16) | ByteConverter.ToUInt16(file, address)) | 0xFF000000u)))); case ColorType.ARGB4444: ushort value = ByteConverter.ToUInt16(file, address); int a = value >> 12; int r = (value >> 8) & 0xF; int g = (value >> 4) & 0xF; int b = value & 0xF; return(Color.FromArgb( a | (a << 4), r | (r << 4), g | (g << 4), b | (b << 4) )); case ColorType.RGB565: value = ByteConverter.ToUInt16(file, address); r = value >> 11; g = (value >> 5) & 0x3F; b = value & 0x1F; return(Color.FromArgb( r << 3 | r >> 2, g << 2 | g >> 4, b << 3 | b >> 2 )); } throw new ArgumentOutOfRangeException("type"); }
public Strip(byte[] file, int address, byte userFlags) { Indexes = new ushort[ByteConverter.ToUInt16(file, address) & 0x7FFF]; Reversed = (ByteConverter.ToUInt16(file, address) & 0x8000) == 0x8000; if (userFlags > 0) { UserFlags1 = new ushort[Indexes.Length - 2]; } if (userFlags > 1) { UserFlags2 = new ushort[Indexes.Length - 2]; } if (userFlags > 2) { UserFlags3 = new ushort[Indexes.Length - 2]; } address += 2; for (int i = 0; i < Indexes.Length; i++) { Indexes[i] = ByteConverter.ToUInt16(file, address); address += 2; if (i > 1) { if (userFlags > 0) { UserFlags1[i - 2] = ByteConverter.ToUInt16(file, address); address += 2; if (userFlags > 1) { UserFlags2[i - 2] = ByteConverter.ToUInt16(file, address); address += 2; if (userFlags > 2) { UserFlags3[i - 2] = ByteConverter.ToUInt16(file, address); address += 2; } } } } } }
public byte[] GetBytes() { VertexChunk next = null; int vertlimit; int vertcount = Vertices.Count; switch (Type) { case ChunkType.Vertex_VertexSH: vertlimit = 65535 / 4; if (Vertices.Count > vertlimit) { next = new VertexChunk(Type) { Vertices = Vertices.Skip(vertlimit).ToList() }; vertcount = vertlimit; } break; case ChunkType.Vertex_VertexNormalSH: vertlimit = 65535 / 8; if (Vertices.Count > vertlimit) { next = new VertexChunk(Type) { Vertices = Vertices.Skip(vertlimit).ToList(), Normals = Normals.Skip(vertlimit).ToList() }; vertcount = vertlimit; } break; case ChunkType.Vertex_Vertex: vertlimit = 65535 / 3; if (Vertices.Count > vertlimit) { next = new VertexChunk(Type) { Vertices = Vertices.Skip(vertlimit).ToList() }; vertcount = vertlimit; } break; case ChunkType.Vertex_VertexDiffuse8: vertlimit = 65535 / 4; if (Vertices.Count > vertlimit) { next = new VertexChunk(Type) { Vertices = Vertices.Skip(vertlimit).ToList(), Diffuse = Diffuse.Skip(vertlimit).ToList() }; vertcount = vertlimit; } break; case ChunkType.Vertex_VertexUserFlags: vertlimit = 65535 / 4; if (Vertices.Count > vertlimit) { next = new VertexChunk(Type) { Vertices = Vertices.Skip(vertlimit).ToList(), UserFlags = UserFlags.Skip(vertlimit).ToList() }; vertcount = vertlimit; } break; case ChunkType.Vertex_VertexNinjaFlags: vertlimit = 65535 / 4; if (Vertices.Count > vertlimit) { next = new VertexChunk(Type) { Vertices = Vertices.Skip(vertlimit).ToList(), NinjaFlags = NinjaFlags.Skip(vertlimit).ToList() }; vertcount = vertlimit; } break; case ChunkType.Vertex_VertexDiffuseSpecular5: case ChunkType.Vertex_VertexDiffuseSpecular4: vertlimit = 65535 / 4; if (Vertices.Count > vertlimit) { next = new VertexChunk(Type) { Vertices = Vertices.Skip(vertlimit).ToList(), Diffuse = Diffuse.Skip(vertlimit).ToList(), Specular = Specular.Skip(vertlimit).ToList() }; vertcount = vertlimit; } break; case ChunkType.Vertex_VertexNormal: vertlimit = 65535 / 6; if (Vertices.Count > vertlimit) { next = new VertexChunk(Type) { Vertices = Vertices.Skip(vertlimit).ToList(), Normals = Normals.Skip(vertlimit).ToList() }; vertcount = vertlimit; } break; case ChunkType.Vertex_VertexNormalDiffuse8: vertlimit = 65535 / 7; if (Vertices.Count > vertlimit) { next = new VertexChunk(Type) { Vertices = Vertices.Skip(vertlimit).ToList(), Normals = Normals.Skip(vertlimit).ToList(), Diffuse = Diffuse.Skip(vertlimit).ToList() }; vertcount = vertlimit; } break; case ChunkType.Vertex_VertexNormalUserFlags: vertlimit = 65535 / 7; if (Vertices.Count > vertlimit) { next = new VertexChunk(Type) { Vertices = Vertices.Skip(vertlimit).ToList(), Normals = Normals.Skip(vertlimit).ToList(), UserFlags = UserFlags.Skip(vertlimit).ToList() }; vertcount = vertlimit; } break; case ChunkType.Vertex_VertexNormalNinjaFlags: vertlimit = 65535 / 7; if (Vertices.Count > vertlimit) { next = new VertexChunk(Type) { Vertices = Vertices.Skip(vertlimit).ToList(), Normals = Normals.Skip(vertlimit).ToList(), NinjaFlags = NinjaFlags.Skip(vertlimit).ToList() }; vertcount = vertlimit; } break; case ChunkType.Vertex_VertexNormalDiffuseSpecular5: case ChunkType.Vertex_VertexNormalDiffuseSpecular4: vertlimit = 65535 / 7; if (Vertices.Count > vertlimit) { next = new VertexChunk(Type) { Vertices = Vertices.Skip(vertlimit).ToList(), Normals = Normals.Skip(vertlimit).ToList(), Diffuse = Diffuse.Skip(vertlimit).ToList(), Specular = Specular.Skip(vertlimit).ToList() }; vertcount = vertlimit; } break; case ChunkType.End: break; default: throw new NotSupportedException("Unsupported chunk type " + Type + "."); } SetVertCount(vertcount); switch (Type) { case ChunkType.Vertex_Vertex: Size = (ushort)(vertcount * 3 + 1); break; case ChunkType.Vertex_VertexSH: case ChunkType.Vertex_VertexDiffuse8: case ChunkType.Vertex_VertexUserFlags: case ChunkType.Vertex_VertexNinjaFlags: case ChunkType.Vertex_VertexDiffuseSpecular5: case ChunkType.Vertex_VertexDiffuseSpecular4: Size = (ushort)(vertcount * 4 + 1); break; case ChunkType.Vertex_VertexNormal: Size = (ushort)(vertcount * 6 + 1); break; case ChunkType.Vertex_VertexNormalDiffuse8: case ChunkType.Vertex_VertexNormalUserFlags: case ChunkType.Vertex_VertexNormalNinjaFlags: case ChunkType.Vertex_VertexNormalDiffuseSpecular5: case ChunkType.Vertex_VertexNormalDiffuseSpecular4: Size = (ushort)(vertcount * 7 + 1); break; case ChunkType.Vertex_VertexNormalSH: Size = (ushort)(vertcount * 8 + 1); break; } List <byte> result = new List <byte>((Size * 4) + 4); result.AddRange(ByteConverter.GetBytes(Header1)); result.AddRange(ByteConverter.GetBytes(Header2)); for (int i = 0; i < vertcount; i++) { switch (Type) { case ChunkType.Vertex_VertexSH: result.AddRange(Vertices[i].GetBytes()); result.AddRange(ByteConverter.GetBytes(1.0f)); break; case ChunkType.Vertex_VertexNormalSH: result.AddRange(Vertices[i].GetBytes()); result.AddRange(ByteConverter.GetBytes(1.0f)); result.AddRange(Normals[i].GetBytes()); result.AddRange(ByteConverter.GetBytes(1.0f)); break; case ChunkType.Vertex_Vertex: result.AddRange(Vertices[i].GetBytes()); break; case ChunkType.Vertex_VertexDiffuse8: result.AddRange(Vertices[i].GetBytes()); result.AddRange(VColor.GetBytes(Diffuse[i], ColorType.ARGB8888_32)); break; case ChunkType.Vertex_VertexUserFlags: result.AddRange(Vertices[i].GetBytes()); result.AddRange(ByteConverter.GetBytes(UserFlags[i])); break; case ChunkType.Vertex_VertexNinjaFlags: result.AddRange(Vertices[i].GetBytes()); result.AddRange(ByteConverter.GetBytes(NinjaFlags[i])); break; case ChunkType.Vertex_VertexDiffuseSpecular5: result.AddRange(Vertices[i].GetBytes()); result.AddRange(ByteConverter.GetBytes( ByteConverter.ToUInt16(VColor.GetBytes(Diffuse[i], ColorType.RGB565), 0) | (ByteConverter.ToUInt16(VColor.GetBytes(Specular[i], ColorType.RGB565), 0) << 16))); break; case ChunkType.Vertex_VertexDiffuseSpecular4: result.AddRange(Vertices[i].GetBytes()); result.AddRange(ByteConverter.GetBytes( ByteConverter.ToUInt16(VColor.GetBytes(Diffuse[i], ColorType.ARGB4444), 0) | (ByteConverter.ToUInt16(VColor.GetBytes(Specular[i], ColorType.RGB565), 0) << 16))); break; case ChunkType.Vertex_VertexNormal: result.AddRange(Vertices[i].GetBytes()); result.AddRange(Normals[i].GetBytes()); break; case ChunkType.Vertex_VertexNormalDiffuse8: result.AddRange(Vertices[i].GetBytes()); result.AddRange(Normals[i].GetBytes()); result.AddRange(VColor.GetBytes(Diffuse[i], ColorType.ARGB8888_32)); break; case ChunkType.Vertex_VertexNormalUserFlags: result.AddRange(Vertices[i].GetBytes()); result.AddRange(Normals[i].GetBytes()); result.AddRange(ByteConverter.GetBytes(UserFlags[i])); break; case ChunkType.Vertex_VertexNormalNinjaFlags: result.AddRange(Vertices[i].GetBytes()); result.AddRange(Normals[i].GetBytes()); result.AddRange(ByteConverter.GetBytes(NinjaFlags[i])); break; case ChunkType.Vertex_VertexNormalDiffuseSpecular5: result.AddRange(Vertices[i].GetBytes()); result.AddRange(Normals[i].GetBytes()); result.AddRange(ByteConverter.GetBytes( ByteConverter.ToUInt16(VColor.GetBytes(Diffuse[i], ColorType.RGB565), 0) | (ByteConverter.ToUInt16(VColor.GetBytes(Specular[i], ColorType.RGB565), 0) << 16))); break; case ChunkType.Vertex_VertexNormalDiffuseSpecular4: result.AddRange(Vertices[i].GetBytes()); result.AddRange(Normals[i].GetBytes()); result.AddRange(ByteConverter.GetBytes( ByteConverter.ToUInt16(VColor.GetBytes(Diffuse[i], ColorType.ARGB4444), 0) | (ByteConverter.ToUInt16(VColor.GetBytes(Specular[i], ColorType.RGB565), 0) << 16))); break; } } if (next != null) { result.AddRange(next.GetBytes()); } return(result.ToArray()); }
public PolyChunkEnd(byte[] file, int address) { Header = ByteConverter.ToUInt16(file, address); }
public PolyChunkMaterial(byte[] file, int address) { Header = ByteConverter.ToUInt16(file, address); address += sizeof(ushort); Size = ByteConverter.ToUInt16(file, address); address += sizeof(ushort); switch (Type) { case ChunkType.Material_Diffuse: case ChunkType.Material_DiffuseAmbient: case ChunkType.Material_DiffuseSpecular: case ChunkType.Material_DiffuseAmbientSpecular: case ChunkType.Material_Diffuse2: case ChunkType.Material_DiffuseAmbient2: case ChunkType.Material_DiffuseSpecular2: case ChunkType.Material_DiffuseAmbientSpecular2: Diffuse = VColor.FromBytes(file, address, ColorType.ARGB8888_16); address += VColor.Size(ColorType.ARGB8888_16); break; } switch (Type) { case ChunkType.Material_Ambient: case ChunkType.Material_DiffuseAmbient: case ChunkType.Material_AmbientSpecular: case ChunkType.Material_DiffuseAmbientSpecular: case ChunkType.Material_Ambient2: case ChunkType.Material_DiffuseAmbient2: case ChunkType.Material_AmbientSpecular2: case ChunkType.Material_DiffuseAmbientSpecular2: Ambient = VColor.FromBytes(file, address, ColorType.XRGB8888_16); address += VColor.Size(ColorType.XRGB8888_16); break; } switch (Type) { case ChunkType.Material_Specular: case ChunkType.Material_DiffuseSpecular: case ChunkType.Material_AmbientSpecular: case ChunkType.Material_DiffuseAmbientSpecular: case ChunkType.Material_Specular2: case ChunkType.Material_DiffuseSpecular2: case ChunkType.Material_AmbientSpecular2: case ChunkType.Material_DiffuseAmbientSpecular2: Specular = VColor.FromBytes(file, address, ColorType.XRGB8888_16); SpecularExponent = (byte)(ByteConverter.ToUInt16(file, address + 2) >> 8); address += VColor.Size(ColorType.XRGB8888_16); break; } switch (Type) { case ChunkType.Material_Diffuse2: case ChunkType.Material_Ambient2: case ChunkType.Material_DiffuseAmbient2: case ChunkType.Material_Specular2: case ChunkType.Material_DiffuseSpecular2: case ChunkType.Material_AmbientSpecular2: case ChunkType.Material_DiffuseAmbientSpecular2: Second = true; break; } }
public NJS_MESHSET(byte[] file, int address, uint imageBase, Dictionary <int, string> labels) { MaterialID = ByteConverter.ToUInt16(file, address); PolyType = (Basic_PolyType)(MaterialID >> 0xE); MaterialID &= 0x3FFF; Poly[] polys = new Poly[ByteConverter.ToInt16(file, address + 2)]; int tmpaddr = (int)(ByteConverter.ToUInt32(file, address + 4) - imageBase); if (labels.ContainsKey(tmpaddr)) { PolyName = labels[tmpaddr]; } else { PolyName = "poly_" + tmpaddr.ToString("X8"); } int striptotal = 0; for (int i = 0; i < polys.Length; i++) { polys[i] = SAModel.Poly.CreatePoly(PolyType, file, tmpaddr); striptotal += polys[i].Indexes.Length; tmpaddr += polys[i].Size; } Poly = new ReadOnlyCollection <Poly>(polys); PAttr = ByteConverter.ToInt32(file, address + 8); tmpaddr = ByteConverter.ToInt32(file, address + 0xC); if (tmpaddr != 0) { tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase); if (labels.ContainsKey(tmpaddr)) { PolyNormalName = labels[tmpaddr]; } else { PolyNormalName = "polynormal_" + tmpaddr.ToString("X8"); } PolyNormal = new Vertex[polys.Length]; for (int i = 0; i < polys.Length; i++) { PolyNormal[i] = new Vertex(file, tmpaddr); tmpaddr += Vertex.Size; } } else { PolyNormalName = "polynormal_" + Extensions.GenerateIdentifier(); } tmpaddr = ByteConverter.ToInt32(file, address + 0x10); if (tmpaddr != 0) { tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase); if (labels.ContainsKey(tmpaddr)) { VColorName = labels[tmpaddr]; } else { VColorName = "vcolor_" + tmpaddr.ToString("X8"); } VColor = new Color[striptotal]; for (int i = 0; i < striptotal; i++) { VColor[i] = SAModel.VColor.FromBytes(file, tmpaddr); tmpaddr += SAModel.VColor.Size(ColorType.ARGB8888_32); } } else { VColorName = "vcolor_" + Extensions.GenerateIdentifier(); } tmpaddr = ByteConverter.ToInt32(file, address + 0x14); if (tmpaddr != 0) { tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase); if (labels.ContainsKey(tmpaddr)) { UVName = labels[tmpaddr]; } else { UVName = "uv_" + tmpaddr.ToString("X8"); } UV = new UV[striptotal]; for (int i = 0; i < striptotal; i++) { UV[i] = new UV(file, tmpaddr); tmpaddr += SAModel.UV.Size; } } else { UVName = "uv_" + Extensions.GenerateIdentifier(); } }
public static PolyChunk Load(byte[] file, int address) { ChunkType type = (ChunkType)(ByteConverter.ToUInt16(file, address) & 0xFF); switch (type) { case ChunkType.Null: return(new PolyChunkNull(file, address)); case ChunkType.Bits_BlendAlpha: return(new PolyChunkBitsBlendAlpha(file, address)); case ChunkType.Bits_MipmapDAdjust: return(new PolyChunkBitsMipmapDAdjust(file, address)); case ChunkType.Bits_SpecularExponent: return(new PolyChunkBitsSpecularExponent(file, address)); case ChunkType.Bits_CachePolygonList: return(new PolyChunkBitsCachePolygonList(file, address)); case ChunkType.Bits_DrawPolygonList: return(new PolyChunkBitsDrawPolygonList(file, address)); case ChunkType.Tiny_TextureID: case ChunkType.Tiny_TextureID2: return(new PolyChunkTinyTextureID(file, address)); case ChunkType.Material_Diffuse: case ChunkType.Material_Ambient: case ChunkType.Material_DiffuseAmbient: case ChunkType.Material_Specular: case ChunkType.Material_DiffuseSpecular: case ChunkType.Material_AmbientSpecular: case ChunkType.Material_DiffuseAmbientSpecular: case ChunkType.Material_Diffuse2: case ChunkType.Material_Ambient2: case ChunkType.Material_DiffuseAmbient2: case ChunkType.Material_Specular2: case ChunkType.Material_DiffuseSpecular2: case ChunkType.Material_AmbientSpecular2: case ChunkType.Material_DiffuseAmbientSpecular2: return(new PolyChunkMaterial(file, address)); case ChunkType.Material_Bump: return(new PolyChunkMaterialBump(file, address)); case ChunkType.Volume_Polygon3: case ChunkType.Volume_Polygon4: case ChunkType.Volume_Strip: return(new PolyChunkVolume(file, address)); case ChunkType.Strip_Strip: case ChunkType.Strip_StripUVN: case ChunkType.Strip_StripUVH: case ChunkType.Strip_StripColor: case ChunkType.Strip_StripUVNColor: case ChunkType.Strip_StripUVHColor: case ChunkType.Strip_Strip2: case ChunkType.Strip_StripUVN2: case ChunkType.Strip_StripUVH2: return(new PolyChunkStrip(file, address)); case ChunkType.End: return(new PolyChunkEnd(file, address)); default: throw new NotSupportedException("Unsupported chunk type " + type + " at " + address.ToString("X8") + "."); } }
public PolyChunkTinyTextureID(byte[] file, int address) { Header = ByteConverter.ToUInt16(file, address); Second = Type == ChunkType.Tiny_TextureID2; Data = ByteConverter.ToUInt16(file, address + 2); }
public PolyChunkBitsDrawPolygonList(byte[] file, int address) { Header = ByteConverter.ToUInt16(file, address); }
public PolyChunkBitsSpecularExponent(byte[] file, int address) { Header = ByteConverter.ToUInt16(file, address); }
public PolyChunkBitsMipmapDAdjust(byte[] file, int address) { Header = ByteConverter.ToUInt16(file, address); }
public static Color FromBytes(byte[] file, int address, ColorType type) { switch (type) { case ColorType.ARGB8888_32: if (address > file.Length - 4) { return(Color.FromArgb(0, 0, 0, 0)); } if (ByteConverter.BigEndian) { //"Reverse" is for the order used in SADX Gamecube if (ByteConverter.Reverse) { return(Color.FromArgb(file[address + 3], file[address], file[address + 1], file[address + 2])); } else { return(Color.FromArgb(file[address], file[address + 1], file[address + 2], file[address + 3])); } } else { return(Color.FromArgb(file[address + 3], file[address + 2], file[address + 1], file[address])); } case ColorType.XRGB8888_32: return(Color.FromArgb(unchecked ((int)(ByteConverter.ToUInt32(file, address) | 0xFF000000u)))); case ColorType.ARGB8888_16: return(Color.FromArgb((ByteConverter.ToUInt16(file, address + 2) << 16) | ByteConverter.ToUInt16(file, address))); case ColorType.XRGB8888_16: return(Color.FromArgb(unchecked ((int)((uint)((ByteConverter.ToUInt16(file, address + 2) << 16) | ByteConverter.ToUInt16(file, address)) | 0xFF000000u)))); case ColorType.ARGB4444: ushort value = ByteConverter.ToUInt16(file, address); int a = value >> 12; int r = (value >> 8) & 0xF; int g = (value >> 4) & 0xF; int b = value & 0xF; return(Color.FromArgb( a | (a << 4), r | (r << 4), g | (g << 4), b | (b << 4) )); case ColorType.RGB565: value = ByteConverter.ToUInt16(file, address); r = value >> 11; g = (value >> 5) & 0x3F; b = value & 0x1F; return(Color.FromArgb( r << 3 | r >> 2, g << 2 | g >> 4, b << 3 | b >> 2 )); } throw new ArgumentOutOfRangeException("type"); }
public Strip(byte[] file, int address, ChunkType type, byte userFlags) { Indexes = new ushort[Math.Abs(ByteConverter.ToInt16(file, address))]; Reversed = (ByteConverter.ToUInt16(file, address) & 0x8000) == 0x8000; address += 2; switch (type) { case ChunkType.Strip_StripUVN: case ChunkType.Strip_StripUVH: case ChunkType.Strip_StripUVN2: case ChunkType.Strip_StripUVH2: UVs = new UV[Indexes.Length]; break; case ChunkType.Strip_StripColor: VColors = new Color[Indexes.Length]; break; case ChunkType.Strip_StripUVNColor: case ChunkType.Strip_StripUVHColor: UVs = new UV[Indexes.Length]; VColors = new Color[Indexes.Length]; break; } if (userFlags > 0) { UserFlags1 = new ushort[Indexes.Length - 2]; } if (userFlags > 1) { UserFlags2 = new ushort[Indexes.Length - 2]; } if (userFlags > 2) { UserFlags3 = new ushort[Indexes.Length - 2]; } for (int i = 0; i < Indexes.Length; i++) { Indexes[i] = ByteConverter.ToUInt16(file, address); address += 2; switch (type) { case ChunkType.Strip_StripUVN: case ChunkType.Strip_StripUVNColor: case ChunkType.Strip_StripUVN2: UVs[i] = new UV(file, address, false); address += UV.Size; break; case ChunkType.Strip_StripUVH: case ChunkType.Strip_StripUVHColor: case ChunkType.Strip_StripUVH2: UVs[i] = new UV(file, address, true); address += UV.Size; break; } switch (type) { case ChunkType.Strip_StripColor: case ChunkType.Strip_StripUVNColor: case ChunkType.Strip_StripUVHColor: VColors[i] = VColor.FromBytes(file, address, ColorType.ARGB8888_16); address += VColor.Size(ColorType.ARGB8888_16); break; } if (i > 1) { if (userFlags > 0) { UserFlags1[i - 2] = ByteConverter.ToUInt16(file, address); address += 2; if (userFlags > 1) { UserFlags2[i - 2] = ByteConverter.ToUInt16(file, address); address += 2; if (userFlags > 2) { UserFlags3[i - 2] = ByteConverter.ToUInt16(file, address); address += 2; } } } } } }
public byte[] GetBytes() { List <byte> result = new List <byte>((Size * 4) + 4); result.AddRange(ByteConverter.GetBytes(Header1)); result.AddRange(ByteConverter.GetBytes(Header2)); for (int i = 0; i < VertexCount; i++) { switch (Type) { case ChunkType.Vertex_VertexSH: result.AddRange(Vertices[i].GetBytes()); result.AddRange(ByteConverter.GetBytes(1.0f)); break; case ChunkType.Vertex_VertexNormalSH: result.AddRange(Vertices[i].GetBytes()); result.AddRange(ByteConverter.GetBytes(1.0f)); result.AddRange(Normals[i].GetBytes()); result.AddRange(ByteConverter.GetBytes(1.0f)); break; case ChunkType.Vertex_Vertex: result.AddRange(Vertices[i].GetBytes()); break; case ChunkType.Vertex_VertexDiffuse8: result.AddRange(Vertices[i].GetBytes()); result.AddRange(VColor.GetBytes(Diffuse[i], ColorType.ARGB8888_32)); break; case ChunkType.Vertex_VertexUserFlags: result.AddRange(Vertices[i].GetBytes()); result.AddRange(ByteConverter.GetBytes(UserFlags[i])); break; case ChunkType.Vertex_VertexNinjaFlags: result.AddRange(Vertices[i].GetBytes()); result.AddRange(ByteConverter.GetBytes(NinjaFlags[i])); break; case ChunkType.Vertex_VertexDiffuseSpecular5: result.AddRange(Vertices[i].GetBytes()); result.AddRange(ByteConverter.GetBytes( ByteConverter.ToUInt16(VColor.GetBytes(Diffuse[i], ColorType.RGB565), 0) | (ByteConverter.ToUInt16(VColor.GetBytes(Specular[i], ColorType.RGB565), 0) << 16))); break; case ChunkType.Vertex_VertexDiffuseSpecular4: result.AddRange(Vertices[i].GetBytes()); result.AddRange(ByteConverter.GetBytes( ByteConverter.ToUInt16(VColor.GetBytes(Diffuse[i], ColorType.ARGB4444), 0) | (ByteConverter.ToUInt16(VColor.GetBytes(Specular[i], ColorType.RGB565), 0) << 16))); break; case ChunkType.Vertex_VertexNormal: result.AddRange(Vertices[i].GetBytes()); result.AddRange(Normals[i].GetBytes()); break; case ChunkType.Vertex_VertexNormalDiffuse8: result.AddRange(Vertices[i].GetBytes()); result.AddRange(Normals[i].GetBytes()); result.AddRange(VColor.GetBytes(Diffuse[i], ColorType.ARGB8888_32)); break; case ChunkType.Vertex_VertexNormalUserFlags: result.AddRange(Vertices[i].GetBytes()); result.AddRange(Normals[i].GetBytes()); result.AddRange(ByteConverter.GetBytes(UserFlags[i])); break; case ChunkType.Vertex_VertexNormalNinjaFlags: result.AddRange(Vertices[i].GetBytes()); result.AddRange(Normals[i].GetBytes()); result.AddRange(ByteConverter.GetBytes(NinjaFlags[i])); break; case ChunkType.Vertex_VertexNormalDiffuseSpecular5: result.AddRange(Vertices[i].GetBytes()); result.AddRange(Normals[i].GetBytes()); result.AddRange(ByteConverter.GetBytes( ByteConverter.ToUInt16(VColor.GetBytes(Diffuse[i], ColorType.RGB565), 0) | (ByteConverter.ToUInt16(VColor.GetBytes(Specular[i], ColorType.RGB565), 0) << 16))); break; case ChunkType.Vertex_VertexNormalDiffuseSpecular4: result.AddRange(Vertices[i].GetBytes()); result.AddRange(Normals[i].GetBytes()); result.AddRange(ByteConverter.GetBytes( ByteConverter.ToUInt16(VColor.GetBytes(Diffuse[i], ColorType.ARGB4444), 0) | (ByteConverter.ToUInt16(VColor.GetBytes(Specular[i], ColorType.RGB565), 0) << 16))); break; default: throw new NotSupportedException("Unsupported chunk type " + Type + "."); } } return(result.ToArray()); }
public PolyChunkBitsBlendAlpha(byte[] file, int address) { Header = ByteConverter.ToUInt16(file, address); }