/// <summary> /// Decodes a .par file to it's ini contents /// </summary> /// <param name="parEncryptedFile"></param> /// <returns></returns> public static DuplicatingIni DecodePAR(byte[] parEncryptedFile) { int PARFileKeyPosition = 0; byte[] PARFileContentToProcess; char[] PARFileXORedContent = new char[parEncryptedFile.Length]; byte[] PARFileKeyByteArray = Encoding.UTF8.GetBytes(parEncKey); if (parEncryptedFile[0] != 0x2A || //Magic? CRC? parEncryptedFile[1] != 0x02 || parEncryptedFile[2] != 0x11 || parEncryptedFile[3] != 0x3C) { PARFileContentToProcess = parEncryptedFile.Skip(4).ToArray(); } else { PARFileContentToProcess = parEncryptedFile; } for (int i = 0; i < PARFileContentToProcess.Length; i++) { PARFileXORedContent[i] = (char)(PARFileContentToProcess[i] ^ PARFileKeyByteArray[PARFileKeyPosition]); PARFileKeyPosition = ((PARFileKeyPosition + 1) % PARFileKeyByteArray.Length); } var decPar = new string(PARFileXORedContent); return(DuplicatingIni.ParseIni(decPar)); }
public ME2Coalesced(string file) { Inputfile = file; using FileStream fs = new FileStream(file, FileMode.Open); int unknownInt = fs.ReadInt32(); if (unknownInt != 0x1E) { throw new Exception("First 4 bytes were not 0x1E (was " + unknownInt.ToString("X8") + ").This does not appear to be a Coalesced file."); } while (fs.Position < fs.Length) { long pos = fs.Position; string filename = fs.ReadUnrealString(); string contents = fs.ReadUnrealString(); Inis[filename] = DuplicatingIni.ParseIni(contents); } }