/// <summary> /// Return bitmap of the PAX file /// <param name="si">MemoryStream of the PAX file/param> /// </summary> public static PicPAX GetPAX(MemoryStream si) { si.Position = 0; BinaryReader br = new BinaryReader(si); if (si.ReadByte() != 0x50) throw new NotSupportedException("!PAX"); if (si.ReadByte() != 0x41) throw new NotSupportedException("!PAX"); if (si.ReadByte() != 0x58) throw new NotSupportedException("!PAX"); if (si.ReadByte() != 0x5F) throw new NotSupportedException("!PAX"); si.Position = 0xC; int v0c = br.ReadInt32(); // off-to-tbl82 si.Position = v0c; int test82 = br.ReadInt32(); if (test82 != 0x82) throw new NotSupportedException("!82"); si.Position = v0c + 0xC; int cx = br.ReadInt32(); PicPAX pp = new PicPAX(); for (int x = 0; x < cx; x++) { si.Position = v0c + 16 + 32*x; int off96 = (v0c + br.ReadInt32()); si.Position = off96; int test96 = br.ReadInt32(); if (test96 != 0x96) throw new NotSupportedException("!96"); int cnt1 = br.ReadInt32(); List<int> aloff1 = new List<int>(); // dmac tag off? for (int t = 0; t < cnt1; t++) aloff1.Add(off96 + br.ReadInt32()); int cnt2 = br.ReadInt32(); List<int> aloff2 = new List<int>(); // tex off? for (int t = 0; t < cnt2; t++) aloff2.Add(off96 + br.ReadInt32()); int cnt3 = br.ReadInt32(); List<int> aloff3 = new List<int>(); // ? for (int t = 0; t < cnt3; t++) aloff3.Add(off96 + br.ReadInt32()); int cnt4 = br.ReadInt32(); List<int> aloff4 = new List<int>(); // ? for (int t = 0; t < cnt4; t++) aloff4.Add(off96 + br.ReadInt32()); int cnt5 = br.ReadInt32(); List<int> aloff5 = new List<int>(); // ? for (int t = 0; t < cnt5; t++) aloff5.Add(off96 + br.ReadInt32()); R or = new R(); pp.alr.Add(or); for (int t = 0; t < aloff2.Count; t++) { int offt2 = aloff2[t]; si.Position = offt2; br.ReadInt32(); // @0 br.ReadInt16(); // @4 int fmt = br.ReadInt16(); // @6 br.ReadInt32(); // @8 int tcx = br.ReadInt16(); // @12 int tcy = br.ReadInt16(); // @14 if (fmt == 0x13) { si.Position = offt2 + 32; byte[] pic = br.ReadBytes(tcx*tcy); byte[] pal = br.ReadBytes(1024); or.pics.Add(BUt.Make8(pic, pal, tcx, tcy, t + 1)); } } for (int t = 0; t < aloff3.Count; t++) { int offt3 = aloff3[t]; si.Position = offt3 + 0x14; St3 o3 = new St3(); or.als3.Add(o3); o3.cnt1 = br.ReadInt16(); // @0x14 o3.cnt2 = br.ReadInt16(); // @0x16 Debug.Assert(o3.cnt1 == o3.cnt2); for (int s = 0; s < o3.cnt1; s++) { si.Position = offt3 + 0x20 + 8*s; int off3r = br.ReadUInt16(); St3r o3r = new St3r(); o3.al3r.Add(o3r); si.Position = offt3 + 0x10 + off3r; o3r.v0 = br.ReadUInt16(); // @0x00 o3r.v2 = br.ReadUInt16(); // @0x02 o3r.v4 = br.ReadUInt16(); // @0x04 si.Position = offt3 + 0x10 + off3r + 0x20; for (int w = 0; w < o3r.v2; w++) { STXYC v0 = new STXYC(); STXYC v1 = new STXYC(); v0.x = br.ReadInt16(); v0.y = br.ReadInt16(); v1.x = br.ReadInt16(); v1.y = br.ReadInt16(); v0.s = br.ReadInt16(); v0.t = br.ReadInt16(); v1.s = br.ReadInt16(); v1.t = br.ReadInt16(); o3r.alv.Add(v0); o3r.alv.Add(v1); } for (int w = 0; w < o3r.v2; w++) { STXYC vv = o3r.alv[w]; int vR = br.ReadByte(); int vG = br.ReadByte(); int vB = br.ReadByte(); int vA = br.ReadByte(); vv.clr = Color.FromArgb(vA, vR, vG, vB); o3r.alv[w] = vv; br.ReadInt32(); } } } } return pp; }
/// <summary> /// Function that will parse PAX files /// </summary> /// <param name="si">MemoryStream of the file</param> /// <returns>The picture</returns> public static PicPAX ReadPAX(MemoryStream si) { si.Position = 0L; var binaryReader = new BinaryReader(si); if (si.ReadByte() != 80) { throw new NotSupportedException("!PAX"); } if (si.ReadByte() != 65) { throw new NotSupportedException("!PAX"); } if (si.ReadByte() != 88) { throw new NotSupportedException("!PAX"); } if (si.ReadByte() != 95) { throw new NotSupportedException("!PAX"); } si.Position = 12L; int num = binaryReader.ReadInt32(); si.Position = num; int num2 = binaryReader.ReadInt32(); if (num2 != 130) { throw new NotSupportedException("!82"); } si.Position = num + 12; int num3 = binaryReader.ReadInt32(); var picPAX = new PicPAX(); for (int i = 0; i < num3; i++) { si.Position = num + 16 + 32 * i; int num4 = num + binaryReader.ReadInt32(); si.Position = num4; int num5 = binaryReader.ReadInt32(); if (num5 != 150) { throw new NotSupportedException("!96"); } int num6 = binaryReader.ReadInt32(); var list = new List <int>(); for (int j = 0; j < num6; j++) { list.Add(num4 + binaryReader.ReadInt32()); } int num7 = binaryReader.ReadInt32(); var list2 = new List <int>(); for (int k = 0; k < num7; k++) { list2.Add(num4 + binaryReader.ReadInt32()); } int num8 = binaryReader.ReadInt32(); var list3 = new List <int>(); for (int l = 0; l < num8; l++) { list3.Add(num4 + binaryReader.ReadInt32()); } int num9 = binaryReader.ReadInt32(); var list4 = new List <int>(); for (int m = 0; m < num9; m++) { list4.Add(num4 + binaryReader.ReadInt32()); } int num10 = binaryReader.ReadInt32(); var list5 = new List <int>(); for (int n = 0; n < num10; n++) { list5.Add(num4 + binaryReader.ReadInt32()); } var r = new R(); picPAX.alr.Add(r); for (int num11 = 0; num11 < list2.Count; num11++) { int num12 = list2[num11]; si.Position = num12; binaryReader.ReadInt32(); binaryReader.ReadInt16(); int num13 = binaryReader.ReadInt16(); binaryReader.ReadInt32(); int num14 = binaryReader.ReadInt16(); int num15 = binaryReader.ReadInt16(); if (num13 == 19) { si.Position = num12 + 32; byte[] pic = binaryReader.ReadBytes(num14 * num15); byte[] pal = binaryReader.ReadBytes(1024); r.pics.Add(BUt.Make8(pic, pal, num14, num15)); } } for (int num16 = 0; num16 < list3.Count; num16++) { int num17 = list3[num16]; si.Position = num17 + 20; var st = new St3(); r.als3.Add(st); st.cnt1 = binaryReader.ReadInt16(); st.cnt2 = binaryReader.ReadInt16(); for (int num18 = 0; num18 < st.cnt1; num18++) { si.Position = num17 + 32 + 8 * num18; int num19 = binaryReader.ReadUInt16(); var st3r = new St3r(); st.al3r.Add(st3r); si.Position = num17 + 16 + num19; st3r.v0 = binaryReader.ReadUInt16(); st3r.v2 = binaryReader.ReadUInt16(); st3r.v4 = binaryReader.ReadUInt16(); si.Position = num17 + 16 + num19 + 32; for (int num20 = 0; num20 < st3r.v2; num20++) { STXYC item = default(STXYC); STXYC item2 = default(STXYC); item.x = binaryReader.ReadInt16(); item.y = binaryReader.ReadInt16(); item2.x = binaryReader.ReadInt16(); item2.y = binaryReader.ReadInt16(); item.s = binaryReader.ReadInt16(); item.t = binaryReader.ReadInt16(); item2.s = binaryReader.ReadInt16(); item2.t = binaryReader.ReadInt16(); st3r.alv.Add(item); st3r.alv.Add(item2); } for (int num21 = 0; num21 < st3r.v2; num21++) { STXYC value = st3r.alv[num21]; int red = binaryReader.ReadByte(); int green = binaryReader.ReadByte(); int blue = binaryReader.ReadByte(); int alpha = binaryReader.ReadByte(); value.clr = Color.FromArgb(alpha, red, green, blue); st3r.alv[num21] = value; binaryReader.ReadInt32(); } } } } return(picPAX); }