private byte[] serializeForDynamicType(params object[] vals) { BEBinaryWriter elt = new BEBinaryWriter(); foreach (var p in vals) { if (p is int) { elt.WriteUInt16((ushort)(0x8000 | 'i')); elt.WriteUInt16((ushort)4); elt.WriteInt32((int)p); elt.WriteByte((byte)0); } else if (p is String) { elt.WriteUInt16((ushort)(0x8000 | 's')); elt.WriteString(p as string); elt.WriteByte((byte)0); } else { throw new InvalidOperationException(); } } var ret = new byte[elt.Length]; Buffer.BlockCopy(elt.GetBuffer(), 0, ret, 0, (int)elt.Length); return(ret); }
private byte[] serializeForDynamicType(params object[] vals) { var elt = new BEBinaryWriter(); foreach (object p in vals) { if (p is int) { elt.WriteUInt16(0x8000 | 'i'); elt.WriteUInt16(4); elt.WriteInt32((int) p); elt.WriteByte(0); } else if (p is String) { elt.WriteUInt16(0x8000 | 's'); elt.WriteString(p as string); elt.WriteByte(0); } else { throw new InvalidOperationException(); } } var ret = new byte[elt.Length]; Buffer.BlockCopy(elt.GetBuffer(), 0, ret, 0, (int) elt.Length); return ret; }
public void Save(string Path) { if (Materials.Count == 0) { return; } using (BEBinaryWriter bw = new BEBinaryWriter(new FileStream(Path, FileMode.Create))) { bw.WriteInt32(18); bw.WriteInt32(8); bw.WriteInt32(5); bw.WriteInt32(2); foreach (MATMaterial M in Materials) { bw.Write(new byte[] { 0, 0, 0, 60 }); bw.WriteInt32(68 + M.Name.Length); bw.Write(M.DiffuseColour); bw.WriteSingle(M.AmbientLighting); bw.WriteSingle(M.DirectionalLighting); bw.WriteSingle(M.SpecularLighting); bw.WriteSingle(M.SpecularPower); bw.WriteInt32(M.Flags); bw.WriteSingle(M.UVMatrix.M11); bw.WriteSingle(M.UVMatrix.M12); bw.WriteSingle(M.UVMatrix.M21); bw.WriteSingle(M.UVMatrix.M22); bw.WriteSingle(M.UVMatrix.M31); bw.WriteSingle(M.UVMatrix.M32); bw.Write(new byte[] { 10, 31, 0, 0 }); //Unknown, seems to be a constant bw.Write(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }); //13 bytes of nothing please! bw.Write(M.Name.ToCharArray()); bw.WriteByte(0); if (M.HasTexture) { bw.Write(new byte[] { 0, 0, 0, 28 }); bw.WriteInt32(M.Texture.Length + 1); bw.Write(M.Texture.ToCharArray()); bw.WriteByte(0); } bw.Write(0); bw.Write(0); } } }
public void Save(string path) { using (FileStream fs = new FileStream(path, FileMode.Create)) using (BEBinaryWriter bw = new BEBinaryWriter(fs, Encoding.Default)) { int length; bw.WriteInt32(0x12); // Magic Number bw.WriteInt32(0x8); // bw.WriteInt32(0x1); // bw.WriteInt32(0x2); // foreach (ACTNode A in Sections) { bw.WriteInt32((int)A.Section); switch (A.Section) { case Section.Name: length = A.Identifier.Length + 3; bw.WriteInt32(length); bw.WriteByte((byte)A.ActorType); bw.WriteByte((byte)A.RenderStyle); bw.Write(A.Identifier.ToCharArray()); bw.WriteByte(0); break; case Section.Matrix: bw.WriteInt32(48); bw.WriteSingle(A.Transform.M11); bw.WriteSingle(A.Transform.M12); bw.WriteSingle(A.Transform.M13); bw.WriteSingle(A.Transform.M21); bw.WriteSingle(A.Transform.M22); bw.WriteSingle(A.Transform.M23); bw.WriteSingle(A.Transform.M31); bw.WriteSingle(A.Transform.M32); bw.WriteSingle(A.Transform.M33); bw.WriteSingle(A.Transform.M41); bw.WriteSingle(A.Transform.M42); bw.WriteSingle(A.Transform.M43); break; case Section.Section37: case Section.SubLevelBegin: case Section.SubLevelEnd: bw.WriteInt32(0); break; case Section.Model: bw.WriteInt32(A.Model.Length + 1); bw.Write(A.Model.ToCharArray()); bw.WriteByte(0); break; } } bw.WriteInt32(0); bw.WriteInt32(0); } }
public void Save(string path) { using (FileStream fs = new FileStream(path, FileMode.Create)) using (BEBinaryWriter bw = new BEBinaryWriter(fs)) { int matListLength; string name; //output header bw.WriteInt32(0x12); bw.WriteInt32(0x8); bw.WriteInt32(0xface); bw.WriteInt32(0x2); for (int i = 0; i < DatMeshes.Count; i++) { DatMesh dm = DatMeshes[i]; matListLength = 0; for (int j = 0; j < dm.Mesh.Materials.Count; j++) { matListLength += dm.Mesh.Materials[j].Length + 1; } name = dm.Name; //Console.WriteLine(name + " : " + dm.Mesh.Verts.Count); //begin name section bw.WriteInt32(54); bw.WriteInt32(name.Length + 3); bw.WriteByte(0); bw.WriteByte(0); bw.Write(name.ToCharArray()); bw.WriteByte(0); //end name section //begin vertex data bw.WriteInt32(23); bw.WriteInt32((dm.Mesh.Verts.Count * 12) + 4); bw.WriteInt32(dm.Mesh.Verts.Count); for (int j = 0; j < dm.Mesh.Verts.Count; j++) { bw.WriteSingle(dm.Mesh.Verts[j].X); bw.WriteSingle(dm.Mesh.Verts[j].Y); bw.WriteSingle(dm.Mesh.Verts[j].Z); } //end vertex data //begin uv data (00 00 00 18) bw.WriteInt32(24); bw.WriteInt32((dm.Mesh.UVs.Count * 8) + 4); bw.WriteInt32(dm.Mesh.UVs.Count); for (int j = 0; j < dm.Mesh.UVs.Count; j++) { bw.WriteSingle(dm.Mesh.UVs[j].X); bw.WriteSingle(dm.Mesh.UVs[j].Y); } //end uv data //begin face data (00 00 00 35) bw.WriteInt32(53); bw.WriteInt32((dm.Mesh.Faces.Count * 9) + 4); bw.WriteInt32(dm.Mesh.Faces.Count); for (int j = 0; j < dm.Mesh.Faces.Count; j++) { bw.WriteInt16(dm.Mesh.Faces[j].V1); bw.WriteInt16(dm.Mesh.Faces[j].V2); bw.WriteInt16(dm.Mesh.Faces[j].V3); bw.WriteByte(0); // smoothing groups 9 - 16 bw.WriteByte(1); // smoothing groups 1 - 8 bw.WriteByte(0); // number of edges, 0 and 3 = tri. 4 = quad. } //end face data //begin material list bw.WriteInt32(22); bw.WriteInt32(matListLength + 4); bw.WriteInt32(dm.Mesh.Materials.Count); for (int j = 0; j < dm.Mesh.Materials.Count; j++) { bw.Write(dm.Mesh.Materials[j].ToCharArray()); bw.WriteByte(0); } //end material list //begin face textures bw.WriteInt32(26); bw.WriteInt32((dm.Mesh.Faces.Count * 2) + 4); bw.WriteInt32(dm.Mesh.Faces.Count); bw.WriteInt32(2); for (int j = 0; j < dm.Mesh.Faces.Count; j++) { bw.WriteInt16(dm.Mesh.Faces[j].MaterialID + 1); } //end face textures bw.WriteInt32(0); bw.WriteInt32(0); } } }
public void Save(string path) { using (FileStream fs = new FileStream(path, FileMode.Create)) using (BEBinaryWriter bw = new BEBinaryWriter(fs)) { bw.WriteInt32(0x12); bw.WriteInt32(0x8); bw.WriteInt32(0x2); bw.WriteInt32(0x2); foreach (PIXIE pixie in Pixies) { bw.WriteInt32(0x3); bw.WriteInt32(12 + pixie.Name.Length); bw.WriteByte((byte)pixie.Format); bw.WriteInt16(pixie.RowSize); bw.WriteInt16(pixie.Width); bw.WriteInt16(pixie.Height); bw.WriteInt16(pixie.HalfWidth); bw.WriteInt16(pixie.HalfHeight); bw.WriteString(pixie.Name.ToUpper()); bw.WriteByte(0); bw.WriteInt32(0x21); bw.WriteInt32(8 + (pixie.RowSize * pixie.Height)); bw.WriteInt32(pixie.PixelCount); bw.WriteInt32(pixie.PixelSize); bw.Write(pixie.Data); bw.WriteInt32(0x0); bw.WriteInt32(0); } } }