private void saveToolStripMenuItem_Click(object sender, EventArgs e) { lblStatus.Text = "Writing data into pakstream..."; strgStatusStrip.Refresh(); string[,] stringData = new string[strgDGR.Rows.Count, 11]; for (int rows = 0; rows < strgDGR.Rows.Count; rows++) { for (int col = 0; col < 11; col++) { stringData[rows, col] = strgDGR.Rows[rows].Cells[col].Value.ToString(); } } if (stringData.Length < 12) { byte[] headerData = new byte[] { 0x87, 0x65, 0x43, 0x21, //Magic 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x01, //HeaderData 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //Name data unused 0x45, 0x4E, 0x47, 0x4C, 0x4A, 0x41, 0x50, 0x4E, 0x47, 0x45, 0x52, 0x4D, 0x46, 0x52, 0x45, 0x4E, 0x53, 0x50, 0x41, 0x4E, 0x49, 0x54, 0x41, 0x4C, 0x55, 0x4B, 0x45, 0x4E, 0x4B, 0x4F, 0x52, 0x45, 0x4E, 0x41, 0x46, 0x52, 0x4E, 0x41, 0x53, 0x50 //Language Table }; int bufferSize = 64; byte[][][] pointerTable = new byte[11][][]; byte[][][] stringSection = new byte[11][][]; // Write stringdata to byte array's for (int i = 1; i < stringData.Length; i++) { stringSection[i] = new byte[2][]; stringSection[i][0] = fixByteString(System.Text.Encoding.UTF8.GetBytes(stringData[0, i])); stringSection[i][1] = BitConverter.GetBytes(Endian.SwapEndian32(stringSection[i][0].Length)); bufferSize += stringSection[i][0].Length + 4; } int pointerCounter = Endian.SwapEndian32(stringSection[1][0].Length); // write pointertable array for (int i = 1; i < stringData.Length; i++) { pointerTable[i] = new byte[2][]; pointerTable[i][0] = BitConverter.GetBytes(Endian.SwapEndian32(stringSection[i][0].Length)); if (i == 1) { pointerCounter = 0; } else { pointerCounter += stringSection[i - 1][0].Length + 4; } pointerTable[i][1] = BitConverter.GetBytes(Endian.SwapEndian32(pointerCounter)); bufferSize += 8; } byte[] strgFile = new byte[bufferSize]; int offsetCounter = 0; //making final file Buffer.BlockCopy(headerData, 0, strgFile, offsetCounter, headerData.Length); offsetCounter += headerData.Length; for (int i = 1; i < 11; i++) { Buffer.BlockCopy(pointerTable[i][0], 0, strgFile, offsetCounter, 4); offsetCounter += 4; Buffer.BlockCopy(pointerTable[i][1], 0, strgFile, offsetCounter, 4); offsetCounter += 4; } for (int i = 1; i < 11; i++) { Buffer.BlockCopy(stringSection[i][1], 0, strgFile, offsetCounter, 4); offsetCounter += 4; Buffer.BlockCopy(stringSection[i][0], 0, strgFile, offsetCounter, stringSection[i][0].Length); offsetCounter += stringSection[i][0].Length; } Form1 formClass = new Form1(); ZlibCompression compress = new ZlibCompression(); MemoryStream strgFileStr = new MemoryStream(strgFile); BinaryReader strgFileBin = new BinaryReader(strgFileStr); finalCompressedStrg = compress.Compress(strgFileBin); formClass.replaceFile(finalCompressedStrg); formClass.renewFloatingData(); formClass.loadRSHDData(); lblStatus.Text = "File Saved"; strgStatusStrip.Refresh(); ///////////////// // For testing // ///////////////// /* * SaveFileDialog saveFileDialog1 = new SaveFileDialog(); * saveFileDialog1.Filter = "STRG file|*.STRG"; * if (saveFileDialog1.ShowDialog() == DialogResult.OK) * { * File.WriteAllBytes(saveFileDialog1.FileName, strgFile); * }*/ } }