public override byte[] Save() { int length = 20 + Items.Count * 4; Aligner.Align(ref length, 4); foreach (byte[] item in Items) { length += item.Length; Aligner.Align(ref length, 4); } byte[] data = new byte [length]; BitConv.ToInt32(data, 0, Magic); BitConv.ToInt32(data, 4, EID); BitConv.ToInt32(data, 8, Type); BitConv.ToInt32(data, 12, Items.Count); int offset = 20 + Items.Count * 4; Aligner.Align(ref offset, 4); BitConv.ToInt32(data, 16, offset); for (int i = 0; i < Items.Count; i++) { Items[i].CopyTo(data, offset); offset += Items[i].Length; Aligner.Align(ref offset, 4); BitConv.ToInt32(data, 20 + i * 4, offset); } return(data); }
public override UnprocessedChunk Unprocess(int chunkid) { byte[] data = new byte [Length]; BitConv.ToInt16(data, 0, Magic); BitConv.ToInt16(data, 2, Type); BitConv.ToInt32(data, 4, chunkid); BitConv.ToInt32(data, 8, entries.Count); // Checksum is here, but calculated later int offset = 20 + entries.Count * 4; for (int i = 0; i < entries.Count; i++) { UnprocessedEntry entry = entries[i].Unprocess(); byte[] entrydata = entry.Save(); offset += entry.HeaderLength; Aligner.Align(ref offset, Alignment); offset -= entry.HeaderLength; if (offset + entrydata.Length > Length) { throw new PackingException(); } BitConv.ToInt32(data, 16 + i * 4, offset); entrydata.CopyTo(data, offset); offset += entrydata.Length; } BitConv.ToInt32(data, 16 + entries.Count * 4, offset); int checksum = CalculateChecksum(data); BitConv.ToInt32(data, 12, checksum); return(new UnprocessedChunk(data)); }
public RIFF ToDLSRegion() { RIFF rgn = new RIFF("rgn "); byte[] rgnh = new byte [12]; BitConv.ToInt16(rgnh, 0, minimumnote); BitConv.ToInt16(rgnh, 2, maximumnote); BitConv.ToInt16(rgnh, 4, 0); BitConv.ToInt16(rgnh, 6, 127); BitConv.ToInt16(rgnh, 8, 0); BitConv.ToInt16(rgnh, 10, 0); rgn.Items.Add(new RIFFData("rgnh", rgnh)); byte[] wsmp = new byte [20 /* 36 */]; BitConv.ToInt32(wsmp, 0, 20); BitConv.ToInt16(wsmp, 4, centernote); BitConv.ToInt16(wsmp, 6, pitchshift); BitConv.ToInt32(wsmp, 8, volume - 64 << 16); BitConv.ToInt32(wsmp, 12, 0); BitConv.ToInt32(wsmp, 16, 0 /* 1 */); /*BitConv.ToInt32(wsmp,20,16); * BitConv.ToInt32(wsmp,24,0); * BitConv.ToInt32(wsmp,28,LOOPSTART); * BitConv.ToInt32(wsmp,28,LOOPLENGTH);*/ rgn.Items.Add(new RIFFData("wsmp", wsmp)); byte[] wlnk = new byte [12]; BitConv.ToInt16(wlnk, 0, 0); BitConv.ToInt16(wlnk, 2, 0); BitConv.ToInt32(wlnk, 4, 3); // ??? BitConv.ToInt32(wlnk, 8, wave - 1); rgn.Items.Add(new RIFFData("wlnk", wlnk)); return(rgn); }
public byte[] SaveA() { byte[] data = new byte [4]; int value = (vertexa << 8) | (vertexb << 20) | unknown1; BitConv.ToInt32(data, 0, value); return(data); }
public byte[] Save() { byte[] data = new byte [2592 + 32 * 16 * programs.Count]; BitConv.ToInt32(data, 0, Magic); BitConv.ToInt32(data, 4, isoldversion ? OldVersion : Version); BitConv.ToInt32(data, 8, 0); BitConv.ToInt32(data, 12, data.Length + vbsize * 16); BitConv.ToInt16(data, 16, -0x1112); int tonecount = 0; foreach (VHProgram program in programs.Values) { tonecount += program.Tones.Count; } BitConv.ToInt16(data, 18, (short)programs.Count); BitConv.ToInt16(data, 20, (short)tonecount); BitConv.ToInt16(data, 22, (short)waves.Count); data[24] = volume; data[25] = panning; data[26] = attribute1; data[27] = attribute2; BitConv.ToInt32(data, 28, -1); for (int i = 0; i < 128; i++) { if (programs.ContainsKey(i)) { programs[i].Save().CopyTo(data, 32 + 16 * i); } else { new VHProgram(isoldversion).Save().CopyTo(data, 32 + 16 * i); } } int ii = 0; foreach (KeyValuePair <int, VHProgram> kvp in programs) { VHProgram program = kvp.Value; for (int j = 0; j < 16; j++) { if (j < program.Tones.Count) { program.Tones[j].Save(kvp.Key).CopyTo(data, 2080 + 32 * 16 * ii + 32 * j); } else { new VHTone(isoldversion).Save(kvp.Key).CopyTo(data, 2080 + 32 * 16 * ii + 32 * j); } } ii++; } for (int i = 0; i < waves.Count; i++) { BitConv.ToInt16(data, 2080 + 32 * 16 * programs.Count + 2 + i * 2, (short)(waves[i] * 2)); } return(data); }
public byte[] Save() { byte[] data = new byte [8]; int worda = (vertexa << 8) | (vertexb << 20) | unknown2; int wordb = (vertexd << 8) | (vertexc << 20) | unknown3; BitConv.ToInt32(data, 0, worda); BitConv.ToInt32(data, 4, wordb); return(data); }
public override UnprocessedEntry Unprocess() { byte[] info = new byte [8]; byte[] data = samples.Save(); BitConv.ToInt32(info, 0, id); BitConv.ToInt32(info, 4, data.Length); byte[][] items = new byte [2][]; items[0] = info; items[1] = data; return(new UnprocessedEntry(items, EID, Type)); }
public override UnprocessedEntry Unprocess() { byte[][] items = new byte [3][]; items[0] = new byte [20]; BitConv.ToInt32(items[0], 0, SEP.SEQs.Count); BitConv.ToInt32(items[0], 4, vb0eid); BitConv.ToInt32(items[0], 8, vb1eid); BitConv.ToInt32(items[0], 12, vb2eid); BitConv.ToInt32(items[0], 16, vb3eid); items[1] = vh.Save(); items[2] = sep.Save(); return(new UnprocessedEntry(items, EID, Type)); }
public byte[] Save() { byte[] data = new byte [16]; data[0] = (byte)tones.Count; data[1] = volume; data[2] = priority; data[3] = mode; data[4] = panning; data[5] = isoldversion ? (byte)0x00 : (byte)0xFF; BitConv.ToInt16(data, 6, attribute); BitConv.ToInt32(data, 8, -1); BitConv.ToInt32(data, 12, -1); return(data); }
public byte[] Save() { int worda = 0; int wordb = 0; worda |= vertexa << 20; wordb |= vertexb << 8; wordb |= vertexc << 20; worda |= unknown1 << 8; worda |= unknown2; wordb |= unknown3; byte[] data = new byte [8]; BitConv.ToInt32(data, 0, worda); BitConv.ToInt32(data, 4, wordb); return(data); }
public static void ToInt32(Endianness endianness, byte[] str, int offset, int value) { switch (endianness) { case Endianness.LittleEndian: BitConv.ToInt32(str, offset, value); break; case Endianness.BigEndian: BEBitConv.ToInt32(str, offset, value); break; default: throw new ArgumentException("Endianness is invalid."); } }
public RIFF ToDLSInstrument(int programnumber, bool drumkit) { RIFF ins = new RIFF("ins "); byte[] insh = new byte [12]; BitConv.ToInt32(insh, 0, tones.Count); BitConv.ToInt32(insh, 4, drumkit ? (1 << 31) : 0); BitConv.ToInt32(insh, 8, programnumber); ins.Items.Add(new RIFFData("insh", insh)); RIFF lrgn = new RIFF("lrgn"); foreach (VHTone tone in tones) { lrgn.Items.Add(tone.ToDLSRegion()); } ins.Items.Add(lrgn); return(ins); }
public static RIFF ToWave(byte[] data, int samplerate) { if (data == null) { throw new ArgumentNullException("data"); } byte[] format = new byte [16]; BitConv.ToInt16(format, 0, 1); BitConv.ToInt16(format, 2, 1); BitConv.ToInt32(format, 4, samplerate); BitConv.ToInt32(format, 8, samplerate * 2); BitConv.ToInt16(format, 12, 2); BitConv.ToInt16(format, 14, 16); RIFF wave = new RIFF("WAVE"); wave.Items.Add(new RIFFData("fmt ", format)); wave.Items.Add(new RIFFData("data", data)); return(wave); }
public byte[] Save() { SortedDictionary <short, EntityProperty> properties = new SortedDictionary <short, EntityProperty>(extraproperties); foreach (KeyValuePair <short, FieldInfo> pair in propertyfields) { short id = pair.Key; FieldInfo field = pair.Value; EntityProperty property = EntityProperty.LoadFromField(field.GetValue(this)); if (property != null) { properties.Add(id, property); } } byte[] header = new byte [16 + 8 * properties.Count]; List <byte> result = new List <byte>(); int i = 0; int offset = header.Length - 12; foreach (KeyValuePair <short, EntityProperty> pair in properties) { EntityProperty property = pair.Value; BitConv.ToInt16(header, 16 + 8 * i + 0, pair.Key); unchecked { BitConv.ToInt16(header, 16 + 8 * i + 2, (short)offset); } header[16 + 8 * i + 4] = (byte)(property.Type | ((i == properties.Count - 1) ? 128 : 0) | (property.IsSparse ? 64 : 0) | (property.HasMetaValues ? 32 : 0)); header[16 + 8 * i + 5] = property.ElementSize; BitConv.ToInt16(header, 16 + 8 * i + 6, property.Unknown); byte[] propertydata = property.Save(); i++; offset += propertydata.Length; result.AddRange(propertydata); } BitConv.ToInt32(header, 0, offset + 12); BitConv.ToInt32(header, 4, 0); BitConv.ToInt32(header, 8, 0); BitConv.ToInt32(header, 12, properties.Count); result.InsertRange(0, header); return(result.ToArray()); }
public byte[] Save() { byte[] result = new byte [1312 + 8 * index.Count + extradata.Length]; for (int i = 0; i < 256; i++) { BitConv.ToInt32(result, i * 4, unknown1[i]); } BitConv.ToInt32(result, 1024, chunkcount); BitConv.ToInt32(result, 1028, index.Count); for (int i = 0; i < 70; i++) { BitConv.ToInt32(result, 1032 + i * 4, unknown2[i]); } for (int i = 0; i < index.Count; i++) { BitConv.ToInt32(result, 1312 + i * 8, index[i].ChunkID); BitConv.ToInt32(result, 1316 + i * 8, index[i].EntryID); } Array.Copy(extradata, 0, result, 1312 + index.Count * 8, extradata.Length); return(result); }
public override UnprocessedEntry Unprocess() { byte[][] items = new byte [3][]; items[0] = new byte [36]; BitConv.ToInt32(items[0], 0, SEP.SEQs.Count); BitConv.ToInt32(items[0], 4, vheid); BitConv.ToInt32(items[0], 8, vb0eid); BitConv.ToInt32(items[0], 12, vb1eid); BitConv.ToInt32(items[0], 16, vb2eid); BitConv.ToInt32(items[0], 20, vb3eid); BitConv.ToInt32(items[0], 24, vb4eid); BitConv.ToInt32(items[0], 28, vb5eid); BitConv.ToInt32(items[0], 32, vb6eid); if (vh != null) { items[1] = vh.Save(); } else { items[1] = new byte [0]; } items[2] = sep.Save(); return(new UnprocessedEntry(items, EID, Type)); }
public byte[] Save() { byte[] data = new byte [56 + vertices.Count * 6 + 2]; BitConv.ToInt32(data, 0, vertices.Count); BitConv.ToInt32(data, 4, modeleid); BitConv.ToInt32(data, 8, xoffset); BitConv.ToInt32(data, 12, yoffset); BitConv.ToInt32(data, 16, zoffset); BitConv.ToInt32(data, 20, x1); BitConv.ToInt32(data, 24, y1); BitConv.ToInt32(data, 28, z1); BitConv.ToInt32(data, 32, x2); BitConv.ToInt32(data, 36, y2); BitConv.ToInt32(data, 40, z2); BitConv.ToInt32(data, 44, xglobal); BitConv.ToInt32(data, 48, yglobal); BitConv.ToInt32(data, 52, zglobal); for (int i = 0; i < vertices.Count; i++) { vertices[i].Save().CopyTo(data, 56 + i * 6); } BitConv.ToInt16(data, 56 + vertices.Count * 6, unknown); return(data); }
protected override void SaveElement(byte[] data, int value) { BitConv.ToInt32(data, 0, value); }
public RIFF ToDLS() { RIFF dls = new RIFF("DLS "); byte[] colh = new byte [4]; BitConv.ToInt32(colh, 0, programs.Count * 2); dls.Items.Add(new RIFFData("colh", colh)); RIFF lins = new RIFF("lins"); for (int i = 0; i < 128; i++) { if (programs.ContainsKey(i)) { lins.Items.Add(programs[i].ToDLSInstrument(i, false)); lins.Items.Add(programs[i].ToDLSInstrument(i, true)); } } dls.Items.Add(lins); RIFF wvpl = new RIFF("wvpl"); foreach (SampleSet sampleset in waves) { List <byte> pcm = new List <byte>(); double s0 = 0.0; double s1 = 0.0; int loopstart = 0; for (int i = 0; i < sampleset.SampleLines.Count; i++) { SampleLine sampleline = sampleset.SampleLines[i]; pcm.AddRange(sampleline.ToPCM(ref s0, ref s1)); if ((sampleline.Flags & SampleLineFlags.LoopEnd) != 0) { break; } if ((sampleline.Flags & SampleLineFlags.LoopStart) != 0) { loopstart = i; } } /*for (int i = loopstart;i < sampleset.SampleLines.Count;i++) * { * SampleLine sampleline = sampleset.SampleLines[i]; * pcm.AddRange(sampleline.ToPCM(ref s0,ref s1)); * if ((sampleline.Flags & SampleLineFlags.LoopEnd) != 0) * { * break; * } * }*/ RIFF wave = WaveConv.ToWave(pcm.ToArray(), 44100); wave.Name = "wave"; wvpl.Items.Add(wave); } int waveoffset = 0; byte[] ptbl = new byte [8 + 4 * waves.Count]; BitConv.ToInt32(ptbl, 0, 8); BitConv.ToInt32(ptbl, 4, waves.Count); for (int i = 0; i < waves.Count; i++) { BitConv.ToInt32(ptbl, 8 + i * 4, waveoffset); waveoffset += wvpl.Items[i].Length; } dls.Items.Add(new RIFFData("ptbl", ptbl)); dls.Items.Add(wvpl); return(dls); }