internal static R_MythicPackageData Pack(string current_file) { /* * * [4] - Data Block/File (sizeof: 12+Lenght bytes) * * WORD -> flag compressed ( 0008 ) * * WORD -> offset ( 0003 ) * * QWORD -> FileTime * * BYTE(Lenght) 0xd88 -> compressed data * * ...this is repeated until all Files from FileIndexes are processed */ FileStream reading = new FileStream(current_file, FileMode.Open); int usize = (int)reading.Length; //Stream Size int csize = usize; //Compressed Size REF byte[] sourceData = new byte[usize]; //Stream to be compressed byte[] destData = new byte[csize]; //Stream compressed bool compressed = true; //Must say if datas are TO BE compressed or not. R_MythicPackageData final = new R_MythicPackageData(); using (BinaryReader reader = new BinaryReader(reading)) { reader.Read(sourceData, 0, usize); } if (sourceData.Length <= 10)//If file length is less than 10 bytes we do not compress it. { compressed = false; } if (compressed) { ZLibError error = Zlib.Zlib.Compress(destData, ref csize, sourceData, usize); if (error != ZLibError.Okay) throw new Exception(String.Format("Error Compressing: {0}", error)); } else { csize = usize; destData = sourceData; } final.Flag = 3; //Is this fixed? final.DataOffset = 8; //And this? final.DateTime = System.DateTime.Now.ToFileTime(); //To check byte[] compressedData = new byte[csize]; for (int i = 0; i < csize; i++) { compressedData[i] = destData[i]; } final.Data = compressedData; //Ok final.Compressed = compressed; //Ok final.C_size = csize; //Ok final.U_size = usize; //Ok return final; }
internal static R_MythicPackageData Empty() { R_MythicPackageData d = new R_MythicPackageData(); d.Flag = 0; d.Data = BitConverter.GetBytes(0); d.DataOffset = 0; d.DateTime = 0; return(d); }
internal static R_MythicPackageIndex Pack(string current_file, ref bool error) { /*- Create index for each data (sizeof: 34bytes ) * QWORD 0x34 -> Offset to start of Data Block of this file * DWORD 0x3c -> Length of Data Block header (usually 0x0C) * DWORD 0x40 -> Lenght of compressed data * DWORD 0x44 -> Size of decompressed file * QWORD 0x48 -> Filehash * DWORD 0x50 -> Adler32 CRC of Data in littleEndian ( flag offset data ) * WORD 0x54 -> Compressed Flag */ R_MythicPackageData datas = new R_MythicPackageData(); R_MythicPackageIndex final = new R_MythicPackageIndex(); datas = R_MythicPackageData.Pack(current_file); //Pack current file datas string toHash = ""; //Initialized "" to prevent error in hashing /*error = false; //Actually we does not want to get out of the cycle * //We are looking fo Build folder, that is the root. * int inde = current_file.IndexOf("build\\"); * if (inde != -1) //if found * toHash = current_file.Substring(Form1.FolderName.Length+1); * toHash = toHash.Replace("\\", "/"); * //toHash = current_file.Substring(inde, current_file.Length - inde); * else * { * MessageBox.Show("NO BUILD FOLDER FOUND!"); * error = true;//We are going out from cycle * }*/ toHash = current_file.Substring(Form1.FolderName.Length + 1); toHash = toHash.Replace("\\", "/"); bool compr = datas.Compressed; //Are datas compressed? final.DataBlockOffset = 0; //Offset to start of Data Block of this file final.HeadLength = 0x0C; //Is this fixed? final.CompressedSize = datas.C_size; //Ok final.DecompressedSize = datas.U_size; //Ok long hash = 0; Form1.Dictionary.TryGetValue(toHash, out hash); final.FileHash = hash; //FileHash To Check final.CRC = final.find_CRC(datas); //See find_CRC final.Flag = compr ? (short)0x1 : (short)0x0; //Flag Compressed data To check final.DataBlock = datas; //Tocheck if (final.CRC == 0) { MessageBox.Show("Unable to find CRC!"); error = true; //We are going out from cycle } return(final); }
internal static R_MythicPackageIndex Pack(string current_file, ref bool error) { /*- Create index for each data (sizeof: 34bytes ) * QWORD 0x34 -> Offset to start of Data Block of this file * DWORD 0x3c -> Length of Data Block header (usually 0x0C) * DWORD 0x40 -> Lenght of compressed data * DWORD 0x44 -> Size of decompressed file * QWORD 0x48 -> Filehash * DWORD 0x50 -> Adler32 CRC of Data in littleEndian ( flag offset data ) * WORD 0x54 -> Compressed Flag */ R_MythicPackageData datas = new R_MythicPackageData(); R_MythicPackageIndex final = new R_MythicPackageIndex(); datas = R_MythicPackageData.Pack(current_file); //Pack current file datas string toHash = ""; //Initialized "" to prevent error in hashing /*error = false; //Actually we does not want to get out of the cycle //We are looking fo Build folder, that is the root. int inde = current_file.IndexOf("build\\"); if (inde != -1) //if found toHash = current_file.Substring(Form1.FolderName.Length+1); toHash = toHash.Replace("\\", "/"); //toHash = current_file.Substring(inde, current_file.Length - inde); else { MessageBox.Show("NO BUILD FOLDER FOUND!"); error = true;//We are going out from cycle }*/ toHash = current_file.Substring(Form1.FolderName.Length+1); toHash = toHash.Replace("\\", "/"); bool compr = datas.Compressed; //Are datas compressed? final.DataBlockOffset = 0; //Offset to start of Data Block of this file final.HeadLength = 0x0C; //Is this fixed? final.CompressedSize = datas.C_size; //Ok final.DecompressedSize = datas.U_size; //Ok long hash = 0; Form1.Dictionary.TryGetValue(toHash, out hash); final.FileHash = hash; //FileHash To Check final.CRC = final.find_CRC(datas); //See find_CRC final.Flag = compr ? (short)0x1 : (short)0x0; //Flag Compressed data To check final.DataBlock = datas; //Tocheck if (final.CRC == 0) { MessageBox.Show("Unable to find CRC!"); error = true; //We are going out from cycle } return final; }
internal uint find_CRC(R_MythicPackageData data) { AdlerChecksum crc = new AdlerChecksum(); byte[] tocheck = new byte[BitConverter.GetBytes(data.Flag).Length + BitConverter.GetBytes(data.DataOffset).Length + data.Data.Length]; BitConverter.GetBytes(data.Flag).CopyTo(tocheck, 0); //tocheck position in array BitConverter.GetBytes(data.DataOffset).CopyTo(tocheck, BitConverter.GetBytes(data.Flag).Length); //tocheck position in array data.Data.CopyTo(tocheck, BitConverter.GetBytes(data.Flag).Length + BitConverter.GetBytes(data.DataOffset).Length); if (crc.MakeForBuff(tocheck)) { return(crc.ChecksumValue); } else { return(0); //this will be Error } }
internal static R_MythicPackageData Empty() { R_MythicPackageData d = new R_MythicPackageData(); d.Flag = 0; d.Data = BitConverter.GetBytes(0) ; d.DataOffset = 0; d.DateTime = 0; return d; }
internal uint find_CRC(R_MythicPackageData data) { AdlerChecksum crc = new AdlerChecksum(); byte[] tocheck = new byte[ BitConverter.GetBytes(data.Flag).Length + BitConverter.GetBytes(data.DataOffset).Length + data.Data.Length]; BitConverter.GetBytes(data.Flag).CopyTo(tocheck, 0); //tocheck position in array BitConverter.GetBytes(data.DataOffset).CopyTo(tocheck, BitConverter.GetBytes(data.Flag).Length); //tocheck position in array data.Data.CopyTo(tocheck, BitConverter.GetBytes(data.Flag).Length + BitConverter.GetBytes(data.DataOffset).Length); if(crc.MakeForBuff(tocheck)) return crc.ChecksumValue; else return 0; //this will be Error }
internal static R_MythicPackageData Pack(string current_file) { /* * * [4] - Data Block/File (sizeof: 12+Lenght bytes) * * WORD -> flag compressed ( 0008 ) * * WORD -> offset ( 0003 ) * * QWORD -> FileTime * * BYTE(Lenght) 0xd88 -> compressed data * * ...this is repeated until all Files from FileIndexes are processed */ FileStream reading = new FileStream(current_file, FileMode.Open); int usize = (int)reading.Length; //Stream Size int csize = usize; //Compressed Size REF byte[] sourceData = new byte[usize]; //Stream to be compressed byte[] destData = new byte[csize]; //Stream compressed bool compressed = true; //Must say if datas are TO BE compressed or not. R_MythicPackageData final = new R_MythicPackageData(); using (BinaryReader reader = new BinaryReader(reading)) { reader.Read(sourceData, 0, usize); } if (sourceData.Length <= 10)//If file length is less than 10 bytes we do not compress it. { compressed = false; } if (compressed) { ZLibError error = Zlib.Zlib.Compress(destData, ref csize, sourceData, usize); if (error != ZLibError.Okay) { throw new Exception(String.Format("Error Compressing: {0}", error)); } } else { csize = usize; destData = sourceData; } final.Flag = 3; //Is this fixed? final.DataOffset = 8; //And this? final.DateTime = System.DateTime.Now.ToFileTime(); //To check byte[] compressedData = new byte[csize]; for (int i = 0; i < csize; i++) { compressedData[i] = destData[i]; } final.Data = compressedData; //Ok final.Compressed = compressed; //Ok final.C_size = csize; //Ok final.U_size = usize; //Ok return(final); }