private void p1_Load(object sender, EventArgs e) { p3D = new Direct3D(); alDeleter.Add(p3D); device = new Device(p3D, 0, DeviceType.Hardware, p1.Handle, CreateFlags.HardwareVertexProcessing, new[] { PP }); alDeleter.Add(device); device.SetRenderState(RenderState.Lighting, false); device.SetRenderState(RenderState.ZEnable, true); device.SetRenderState(RenderState.AlphaTestEnable, true); device.SetRenderState(RenderState.AlphaRef, 2); device.SetRenderState(RenderState.AlphaFunc, Compare.GreaterEqual); device.SetRenderState(RenderState.AlphaBlendEnable, true); device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha); device.SetRenderState(RenderState.SourceBlendAlpha, Blend.SourceAlpha); device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha); device.SetRenderState(RenderState.DestinationBlendAlpha, Blend.InverseSourceAlpha); device.SetRenderState(RenderState.CullMode, Cull.Counterclockwise); device.SetRenderState(RenderState.FogColor, p1.BackColor.ToArgb()); device.SetRenderState(RenderState.FogStart, 5f); device.SetRenderState(RenderState.FogEnd, 30000f); device.SetRenderState(RenderState.FogDensity, 0.0001f); device.SetRenderState(RenderState.FogVertexMode, FogMode.Exponential); p1.MouseWheel += p1_MouseWheel; var list = new List <CustomVertex.PositionColoredTextured>(); foreach (DC current in aldc) { var toolStripButton = new ToolStripButton("Show " + current.name); toolStripButton.DisplayStyle = ToolStripItemDisplayStyle.Text; toolStripButton.CheckOnClick = true; toolStripButton.Tag = current.dcId; toolStripButton.Checked = true; toolStripButton.CheckedChanged += tsiIfRender_CheckedChanged; toolStrip1.Items.Insert(toolStrip1.Items.IndexOf(tsbShowColl), toolStripButton); } alci.Clear(); altex.Clear(); var array = new int[4]; int num = 0; foreach (DC current2 in aldc) { int count = altex.Count; Bitmap[] pics = current2.o7.pics; for (int i = 0; i < pics.Length; i++) { Bitmap bitmap = pics[i]; var memoryStream = new MemoryStream(); bitmap.Save(memoryStream, ImageFormat.Png); memoryStream.Position = 0L; Texture item; altex.Add(item = Texture.FromStream(device, memoryStream)); alDeleter.Add(item); } if (current2.o4Mdlx != null) { using ( SortedDictionary <int, Parse4Mdlx.Model> .Enumerator enumerator3 = current2.o4Mdlx.dictModel.GetEnumerator()) { while (enumerator3.MoveNext()) { KeyValuePair <int, Parse4Mdlx.Model> current3 = enumerator3.Current; var cI = new CI(); int count2 = list.Count; Parse4Mdlx.Model value = current3.Value; list.AddRange(value.alv); var list2 = new List <uint>(); for (int j = 0; j < value.alv.Count; j++) { list2.Add((uint)(count2 + j)); } cI.ali = list2.ToArray(); cI.texi = count + current3.Key; cI.vifi = 0; alci.Add(cI); } goto IL_75D; } } goto IL_3C9; IL_75D: alalci.Add(alci.ToArray()); alci.Clear(); continue; IL_3C9: if (current2.o4Map != null) { for (int k = 0; k < current2.o4Map.alvifpkt.Count; k++) { Vifpli vifpli = current2.o4Map.alvifpkt[k]; byte[] vifpkt = vifpli.vifpkt; var vu = new VU1Mem(); var parseVIF = new ParseVIF1(vu); parseVIF.Parse(new MemoryStream(vifpkt, false), 0); foreach (var current4 in parseVIF.almsmem) { var cI2 = new CI(); var memoryStream2 = new MemoryStream(current4, false); var binaryReader = new BinaryReader(memoryStream2); binaryReader.ReadInt32(); binaryReader.ReadInt32(); binaryReader.ReadInt32(); binaryReader.ReadInt32(); int num2 = binaryReader.ReadInt32(); int num3 = binaryReader.ReadInt32(); binaryReader.ReadInt32(); binaryReader.ReadInt32(); binaryReader.ReadInt32(); int num4 = binaryReader.ReadInt32(); binaryReader.ReadInt32(); binaryReader.ReadInt32(); binaryReader.ReadInt32(); int num5 = binaryReader.ReadInt32(); var list3 = new List <uint>(); int count3 = list.Count; for (int l = 0; l < num2; l++) { memoryStream2.Position = 16 * (num3 + l); int num6 = binaryReader.ReadInt16(); binaryReader.ReadInt16(); int num7 = binaryReader.ReadInt16(); binaryReader.ReadInt16(); int num8 = binaryReader.ReadInt16(); binaryReader.ReadInt16(); int num9 = binaryReader.ReadInt16(); binaryReader.ReadInt16(); memoryStream2.Position = 16 * (num5 + num8); Vector3 v; v.X = -binaryReader.ReadSingle(); v.Y = binaryReader.ReadSingle(); v.Z = binaryReader.ReadSingle(); memoryStream2.Position = 16 * (num4 + l); int num10 = (byte)binaryReader.ReadUInt32(); int num11 = (byte)binaryReader.ReadUInt32(); int num12 = (byte)binaryReader.ReadUInt32(); int num13 = (byte)binaryReader.ReadUInt32(); if (num4 == 0) { num10 = 255; num11 = 255; num12 = 255; num13 = 255; } array[num & 3] = count3 + l; num++; if (num9 != 0 && num9 != 16) { if (num9 == 32) { list3.Add(Convert.ToUInt32(array[num - 1 & 3])); list3.Add(Convert.ToUInt32(array[num - 2 & 3])); list3.Add(Convert.ToUInt32(array[num - 3 & 3])); } else { if (num9 == 48) { list3.Add(Convert.ToUInt32(array[num - 1 & 3])); list3.Add(Convert.ToUInt32(array[num - 3 & 3])); list3.Add(Convert.ToUInt32(array[num - 2 & 3])); } } } Color color = Color.FromArgb(lm.al[num13], lm.al[num10], lm.al[num11], lm.al[num12]); var item2 = new CustomVertex.PositionColoredTextured(v, color.ToArgb(), num6 / 16f / 256f, num7 / 16f / 256f); list.Add(item2); } cI2.ali = list3.ToArray(); cI2.texi = count + vifpli.texi; cI2.vifi = k; alci.Add(cI2); } } } goto IL_75D; } if (alalci.Count != 0) { alci.Clear(); alci.AddRange(alalci[0]); } if (list.Count == 0) { list.Add(default(CustomVertex.PositionColoredTextured)); } vb = new VertexBuffer(device, (cntVerts = list.Count) * CustomVertex.PositionColoredTextured.Size, Usage.Points, CustomVertex.PositionColoredTextured.Format, Pool.Managed); alDeleter.Add(vb); DataStream dataStream = vb.Lock(0, 0, LockFlags.None); try { foreach (CustomVertex.PositionColoredTextured current5 in list) { dataStream.Write(current5); } } finally { vb.Unlock(); } lCntVert.Text = cntVerts.ToString("#,##0"); int num14 = 0; alib.Clear(); int num15 = 0; foreach (var current6 in alalci) { CI[] array2 = current6; for (int i = 0; i < array2.Length; i++) { CI cI3 = array2[i]; if (cI3.ali.Length != 0) { var indexBuffer = new IndexBuffer(device, 4 * cI3.ali.Length, Usage.None, Pool.Managed, false); num14 += cI3.ali.Length; alDeleter.Add(indexBuffer); DataStream dataStream2 = indexBuffer.Lock(0, 0, LockFlags.None); try { uint[] ali = cI3.ali; for (int m = 0; m < ali.Length; m++) { uint value2 = ali[m]; dataStream2.Write(value2); } } finally { indexBuffer.Unlock(); } var rIB = new RIB(); rIB.ib = indexBuffer; rIB.cnt = cI3.ali.Length; rIB.texi = cI3.texi; rIB.vifi = cI3.vifi; rIB.name = aldc[num15].name; rIB.dcId = aldc[num15].dcId; alib.Add(rIB); } else { var rIB2 = new RIB(); rIB2.ib = null; rIB2.cnt = 0; rIB2.texi = cI3.texi; rIB2.vifi = cI3.vifi; rIB2.name = aldc[num15].name; rIB2.dcId = aldc[num15].dcId; alib.Add(rIB2); } } num15++; } lCntTris.Text = (num14 / 3).ToString("#,##0"); foreach (Co2 current7 in coll.alCo2) { alpf.Add(putb.Add(current7)); } if (putb.alv.Count != 0) { pvi = new Putvi(putb, device); } Console.Write(""); }
/// <summary> /// Function that parse MDLX files /// </summary> /// <param name="entbin">byte array of the file</param> public Parse4Mdlx(byte[] entbin) { mdlx = new Mdlxfst(new MemoryStream(entbin, false)); float scale = 1f; using (List <T31> .Enumerator enumerator = mdlx.alt31.GetEnumerator()) { if (enumerator.MoveNext()) { T31 current = enumerator.Current; AxBone[] array = current.t21.alaxb.ToArray(); var array2 = new Matrix[array.Length]; var array3 = new Vector3[array2.Length]; var array4 = new Quaternion[array2.Length]; for (int i = 0; i < array2.Length; i++) { AxBone axBone = array[i]; int parent = axBone.parent; Quaternion quaternion; Vector3 left; if (parent < 0) { quaternion = Quaternion.Identity; left = Vector3.Zero; } else { quaternion = array4[parent]; left = array3[parent]; } Vector3 right = Vector3.TransformCoordinate(new Vector3(axBone.x3, axBone.y3, axBone.z3), Matrix.RotationQuaternion(quaternion)); array3[i] = left + right; Quaternion left2 = Quaternion.Identity; if (axBone.x2 != 0f) { left2 *= Quaternion.RotationAxis(new Vector3(1f, 0f, 0f), axBone.x2); } if (axBone.y2 != 0f) { left2 *= Quaternion.RotationAxis(new Vector3(0f, 1f, 0f), axBone.y2); } if (axBone.z2 != 0f) { left2 *= Quaternion.RotationAxis(new Vector3(0f, 0f, 1f), axBone.z2); } array4[i] = left2 * quaternion; } for (int j = 0; j < array2.Length; j++) { Matrix matrix = Matrix.RotationQuaternion(array4[j]); matrix *= Matrix.Translation(array3[j]); array2[j] = matrix; } var list = new List <Body1e>(); Matrix identity = Matrix.Identity; foreach (T13vif current2 in current.al13) { var vU1Mem = new VU1Mem(); int tops = 64; int top = 544; new ParseVIF1(vU1Mem).Parse(new MemoryStream(current2.bin, false), tops); Body1e item = SimaVU1e.Sima(vU1Mem, array2, tops, top, current2.texi, current2.alaxi, identity); list.Add(item); } var ffMesh = new ffMesh(); int num = 0; int num2 = 0; var array5 = new ff1[4]; int num3 = 0; int[] array6 = { 1, 3, 2 }; foreach (Body1e current3 in list) { for (int k = 0; k < current3.alvi.Length; k++) { var ff = new ff1(num + current3.alvi[k], num2 + k); array5[num3] = ff; num3 = (num3 + 1 & 3); int num4 = current3.alfl[k]; if (num4 == 32 || num4 == 0) { var item2 = new ff3(current3.t, array5[num3 - array6[0] & 3], array5[num3 - array6[1] & 3], array5[num3 - array6[2] & 3]); ffMesh.al3.Add(item2); } if (num4 == 48 || num4 == 0) { var item3 = new ff3(current3.t, array5[num3 - array6[0] & 3], array5[num3 - array6[2] & 3], array5[num3 - array6[1] & 3]); ffMesh.al3.Add(item3); } } for (int l = 0; l < current3.alvertraw.Length; l++) { if (current3.alalni[l] == null) { ffMesh.alpos.Add(Vector3.Zero); ffMesh.almtxuse.Add(new MJ1[0]); } else { if (current3.alalni[l].Length == 1) { MJ1 mJ = current3.alalni[l][0]; mJ.factor = 1f; Vector3 item4 = Vector3.TransformCoordinate(VCUt.V4To3(current3.alvertraw[mJ.vertexIndex]), array2[mJ.matrixIndex]); ffMesh.alpos.Add(item4); } else { Vector3 vector = Vector3.Zero; MJ1[] array7 = current3.alalni[l]; for (int m = 0; m < array7.Length; m++) { MJ1 mJ2 = array7[m]; vector += VCUt.V4To3(Vector4.Transform(current3.alvertraw[mJ2.vertexIndex], array2[mJ2.matrixIndex])); } ffMesh.alpos.Add(vector); } ffMesh.almtxuse.Add(current3.alalni[l]); } } for (int n = 0; n < current3.aluv.Length; n++) { Vector2 item5 = current3.aluv[n]; item5.Y = 1f - item5.Y; ffMesh.alst.Add(item5); } num += current3.alvertraw.Length; num2 += current3.aluv.Length; } int count = ffMesh.al3.Count; for (int num5 = 0; num5 < count; num5++) { ff3 ff2 = ffMesh.al3[num5]; Model model; if (!dictModel.TryGetValue(ff2.texi, out model)) { model = (dictModel[ff2.texi] = new Model()); } for (int num6 = 0; num6 < ff2.al1.Length; num6++) { ff1 ff3 = ff2.al1[num6]; Vector3 v = ffMesh.alpos[ff3.vi] * scale; Vector2 vector2 = ffMesh.alst[ff3.ti]; model.alv.Add(new CustomVertex.PositionColoredTextured(v, -1, vector2.X, 1f - vector2.Y)); } } } } }
public static Body1e Sima(VU1Mem vu1mem, Matrix[] Ma, int tops, int top2, int tsel, int[] alaxi, Matrix Mv) { var memoryStream = new MemoryStream(vu1mem.vumem, true); var binaryReader = new BinaryReader(memoryStream); memoryStream.Position = 16 * tops; int num = binaryReader.ReadInt32(); if (num != 1 && num != 2) { throw new ProtInvalidTypeException(); } binaryReader.ReadInt32(); binaryReader.ReadInt32(); binaryReader.ReadInt32(); int num2 = binaryReader.ReadInt32(); int num3 = binaryReader.ReadInt32(); int num4 = binaryReader.ReadInt32(); binaryReader.ReadInt32(); if (num == 1) { binaryReader.ReadInt32(); } if (num == 1) { binaryReader.ReadInt32(); } int num5 = (num == 1) ? binaryReader.ReadInt32() : 0; int num6 = (num == 1) ? binaryReader.ReadInt32() : 0; int num7 = binaryReader.ReadInt32(); int num8 = binaryReader.ReadInt32(); binaryReader.ReadInt32(); int num9 = binaryReader.ReadInt32(); memoryStream.Position = 16 * (tops + num4); var array = new int[num9]; for (int i = 0; i < array.Length; i++) { array[i] = binaryReader.ReadInt32(); } var body1e = new Body1e(); body1e.t = tsel; body1e.alvertraw = new Vector4[num7]; body1e.avail = (num5 == 0 && num == 1); body1e.alalni = new MJ1[num7][]; var array2 = new MJ1[num7]; int num10 = 0; memoryStream.Position = 16 * (tops + num8); for (int j = 0; j < array.Length; j++) { int num11 = array[j]; int k = 0; while (k < num11) { float x = binaryReader.ReadSingle(); float y = binaryReader.ReadSingle(); float z = binaryReader.ReadSingle(); float num12 = binaryReader.ReadSingle(); var vector = new Vector4(x, y, z, num12); body1e.alvertraw[num10] = Vector4.Transform(vector, Mv); body1e.alalni[num10] = new[] { array2[num10] = new MJ1(alaxi[j], num10, num12) }; k++; num10++; } } body1e.aluv = new Vector2[num2]; body1e.alvi = new int[num2]; body1e.alfl = new int[num2]; int num13 = 2147483647; int num14 = -2147483648; memoryStream.Position = 16 * (tops + num3); for (int l = 0; l < num2; l++) { int num15 = binaryReader.ReadUInt16() / 16; binaryReader.ReadUInt16(); int num16 = binaryReader.ReadUInt16() / 16; binaryReader.ReadUInt16(); body1e.aluv[l] = new Vector2(num15 / 256f, num16 / 256f); int val = body1e.alvi[l] = binaryReader.ReadUInt16(); binaryReader.ReadUInt16(); body1e.alfl[l] = binaryReader.ReadUInt16(); binaryReader.ReadUInt16(); num13 = Math.Min(num13, val); num14 = Math.Max(num14, val); } if (num5 != 0) { memoryStream.Position = 16 * (tops + num6); int num17 = binaryReader.ReadInt32(); int num18 = binaryReader.ReadInt32(); int num19 = binaryReader.ReadInt32(); int num20 = binaryReader.ReadInt32(); int num21 = 0; if (num5 >= 5) { num21 = binaryReader.ReadInt32(); binaryReader.ReadInt32(); binaryReader.ReadInt32(); binaryReader.ReadInt32(); } var array3 = new MJ1[num7][]; int m; for (m = 0; m < num17; m++) { int num22 = binaryReader.ReadInt32(); array3[m] = new[] { array2[num22] }; } if (num5 >= 2) { memoryStream.Position = (memoryStream.Position + 15L & -16L); int n = 0; while (n < num18) { int num23 = binaryReader.ReadInt32(); int num24 = binaryReader.ReadInt32(); array3[m] = new[] { array2[num23], array2[num24] }; n++; m++; } } if (num5 >= 3) { memoryStream.Position = (memoryStream.Position + 15L & -16L); int num25 = 0; while (num25 < num19) { int num26 = binaryReader.ReadInt32(); int num27 = binaryReader.ReadInt32(); int num28 = binaryReader.ReadInt32(); array3[m] = new[] { array2[num26], array2[num27], array2[num28] }; num25++; m++; } } if (num5 >= 4) { memoryStream.Position = (memoryStream.Position + 15L & -16L); int num29 = 0; while (num29 < num20) { int num30 = binaryReader.ReadInt32(); int num31 = binaryReader.ReadInt32(); int num32 = binaryReader.ReadInt32(); int num33 = binaryReader.ReadInt32(); array3[m] = new[] { array2[num30], array2[num31], array2[num32], array2[num33] }; num29++; m++; } } if (num5 >= 5) { memoryStream.Position = (memoryStream.Position + 15L & -16L); int num34 = 0; while (num34 < num21) { int num35 = binaryReader.ReadInt32(); int num36 = binaryReader.ReadInt32(); int num37 = binaryReader.ReadInt32(); int num38 = binaryReader.ReadInt32(); int num39 = binaryReader.ReadInt32(); array3[m] = new[] { array2[num35], array2[num36], array2[num37], array2[num38], array2[num39] }; num34++; m++; } } for (int num40 = num13; num40 <= num14; num40++) { } body1e.alalni = array3; } return(body1e); }
public static Body1 Sima(VU1Mem vu1mem, Matrix[] Ma, int tops, int top2, int tsel, int[] alaxi, Matrix Mv) { var memoryStream = new MemoryStream(vu1mem.vumem, true); var binaryReader = new BinaryReader(memoryStream); memoryStream.Position = 16 * tops; int num = binaryReader.ReadInt32(); if (num != 1 && num != 2) { throw new ProtInvalidTypeException(); } binaryReader.ReadInt32(); binaryReader.ReadInt32(); binaryReader.ReadInt32(); int num2 = binaryReader.ReadInt32(); int num3 = binaryReader.ReadInt32(); int num4 = binaryReader.ReadInt32(); binaryReader.ReadInt32(); if (num == 1) { binaryReader.ReadInt32(); } if (num == 1) { binaryReader.ReadInt32(); } int num5 = (num == 1) ? binaryReader.ReadInt32() : 0; int num6 = (num == 1) ? binaryReader.ReadInt32() : 0; int num7 = binaryReader.ReadInt32(); int num8 = binaryReader.ReadInt32(); binaryReader.ReadInt32(); int num9 = binaryReader.ReadInt32(); memoryStream.Position = 16 * (tops + num4); var array = new int[num9]; for (int i = 0; i < array.Length; i++) { array[i] = binaryReader.ReadInt32(); } var body = new Body1(); body.t = tsel; body.alvert = new Vector3[num7]; body.avail = (num5 == 0 && num == 1); var array2 = new Vector3[num7]; int num10 = 0; memoryStream.Position = 16 * (tops + num8); for (int j = 0; j < array.Length; j++) { Matrix transformation = Ma[alaxi[j]] * Mv; int num11 = array[j]; int k = 0; while (k < num11) { float x = binaryReader.ReadSingle(); float y = binaryReader.ReadSingle(); float z = binaryReader.ReadSingle(); float w = binaryReader.ReadSingle(); var coordinate = new Vector3(x, y, z); Vector3 vector = Vector3.TransformCoordinate(coordinate, transformation); body.alvert[num10] = vector; var vector2 = new Vector4(x, y, z, w); Vector4 vector3 = Vector4.Transform(vector2, transformation); array2[num10] = new Vector3(vector3.X, vector3.Y, vector3.Z); k++; num10++; } } body.aluv = new Vector2[num2]; body.alvi = new int[num2]; body.alfl = new int[num2]; memoryStream.Position = 16 * (tops + num3); for (int l = 0; l < num2; l++) { int num12 = binaryReader.ReadUInt16() / 16; binaryReader.ReadUInt16(); int num13 = binaryReader.ReadUInt16() / 16; binaryReader.ReadUInt16(); body.aluv[l] = new Vector2(num12 / 256f, num13 / 256f); body.alvi[l] = binaryReader.ReadUInt16(); binaryReader.ReadUInt16(); body.alfl[l] = binaryReader.ReadUInt16(); binaryReader.ReadUInt16(); } if (num5 != 0) { memoryStream.Position = 16 * (tops + num6); int num14 = binaryReader.ReadInt32(); int num15 = binaryReader.ReadInt32(); int num16 = binaryReader.ReadInt32(); int num17 = binaryReader.ReadInt32(); int num18 = 0; if (num5 >= 5) { num18 = binaryReader.ReadInt32(); binaryReader.ReadInt32(); binaryReader.ReadInt32(); binaryReader.ReadInt32(); } var array3 = new Vector3[num7]; int m; for (m = 0; m < num14; m++) { int num19 = binaryReader.ReadInt32(); array3[m] = body.alvert[num19]; } if (num5 >= 2) { memoryStream.Position = (memoryStream.Position + 15L & -16L); int n = 0; while (n < num15) { int num20 = binaryReader.ReadInt32(); int num21 = binaryReader.ReadInt32(); array3[m] = array2[num20] + array2[num21]; n++; m++; } } if (num5 >= 3) { memoryStream.Position = (memoryStream.Position + 15L & -16L); int num22 = 0; while (num22 < num16) { int num23 = binaryReader.ReadInt32(); int num24 = binaryReader.ReadInt32(); int num25 = binaryReader.ReadInt32(); array3[m] = array2[num23] + array2[num24] + array2[num25]; num22++; m++; } } if (num5 >= 4) { memoryStream.Position = (memoryStream.Position + 15L & -16L); int num26 = 0; while (num26 < num17) { int num27 = binaryReader.ReadInt32(); int num28 = binaryReader.ReadInt32(); int num29 = binaryReader.ReadInt32(); int num30 = binaryReader.ReadInt32(); array3[m] = array2[num27] + array2[num28] + array2[num29] + array2[num30]; num26++; m++; } } if (num5 >= 5) { memoryStream.Position = (memoryStream.Position + 15L & -16L); int num31 = 0; while (num31 < num18) { int num32 = binaryReader.ReadInt32(); int num33 = binaryReader.ReadInt32(); int num34 = binaryReader.ReadInt32(); int num35 = binaryReader.ReadInt32(); int num36 = binaryReader.ReadInt32(); array3[m] = array2[num32] + array2[num33] + array2[num34] + array2[num35] + array2[num36]; num31++; m++; } } body.alvert = array3; } return(body); }