public TROPTRNS(string path_in) { this.path = path_in; BinaryReader TROPTRNSReader = null; try { if (path == null) { throw new Exception("Path cannot be null!"); } if (!path.EndsWith(@"\")) { path += @"\"; } if (!File.Exists(path + "TROPTRNS.DAT")) { throw new Exception("Cannot find TROPTRNS.DAT."); } try { TROPTRNSReader = new BinaryReader(new FileStream(path + "TROPTRNS.DAT", FileMode.Open)); } catch (IOException) { throw new Exception("Cannot Open TROPTRNS.DAT."); } header = TROPTRNSReader.ReadBytes(Marshal.SizeOf(typeof(Header))).ToStruct <Header>(); if (header.Magic != 0x0000000100ad548f81) { TROPTRNSReader.Close(); throw new Exception("Not a vaild TROPTRNS.DAT."); } typeRecordTable = new Dictionary <int, TypeRecord>(); for (int i = 0; i < header.UnknowCount; i++) { TypeRecord TypeRecordTmp = TROPTRNSReader.ReadBytes(Marshal.SizeOf(typeof(TypeRecord))).ToStruct <TypeRecord>(); typeRecordTable.Add(TypeRecordTmp.ID, TypeRecordTmp); } // Type 2 TypeRecord account_id_Record = typeRecordTable[2]; TROPTRNSReader.BaseStream.Position = account_id_Record.Offset + 32; // 空行 account_id = Encoding.UTF8.GetString(TROPTRNSReader.ReadBytes(16)); // Type 3 TypeRecord trophy_id_Record = typeRecordTable[3]; TROPTRNSReader.BaseStream.Position = trophy_id_Record.Offset + 16; // 空行 trophy_id = Encoding.UTF8.GetString(TROPTRNSReader.ReadBytes(16)).Trim('\0'); u1 = TROPTRNSReader.ReadInt32(); // always 00000090 AllGetTrophysCount = TROPTRNSReader.ReadInt32(); AllSyncPSNTrophyCount = TROPTRNSReader.ReadInt32(); // Type 4 TypeRecord TrophyInfoRecord = typeRecordTable[4]; TROPTRNSReader.BaseStream.Position = TrophyInfoRecord.Offset; // 空行 int type = TROPTRNSReader.ReadInt32(); int blocksize = TROPTRNSReader.ReadInt32(); int sequenceNumber = TROPTRNSReader.ReadInt32(); // if have more than same type block, it will be used int unknow = TROPTRNSReader.ReadInt32(); byte[] blockdata = TROPTRNSReader.ReadBytes(blocksize); trophyInitTime = blockdata.ToStruct <TrophyInitTime>(); for (int i = 0; i < (AllGetTrophysCount - 1); i++) { TROPTRNSReader.BaseStream.Position += 16; TrophyInfo ti = TROPTRNSReader.ReadBytes(blocksize).ToStruct <TrophyInfo>(); trophyInfoTable.Add(ti); } } finally { if (TROPTRNSReader != null) { TROPTRNSReader.Close(); } } }
public TROPTRNS(string path) { if (path == null || path.Trim() == string.Empty) { throw new Exception("Path cannot be null!"); } string fileName = Path.Combine(path, TROPTRNS_FILE_NAME); if (!File.Exists(fileName)) { throw new FileNotFoundException("File not found", fileName); } this.path = path; using (var fileStream = new FileStream(fileName, FileMode.Open)) using (var TROPTRNSReader = new BigEndianBinaryReader(fileStream)) { header = TROPTRNSReader.ReadBytes(Marshal.SizeOf(typeof(Header))).ToStruct <Header>(); if (header.Magic != 0x0000000100ad548f81) { throw new InvalidTrophyFileException(TROPTRNS_FILE_NAME); } typeRecordTable = new Dictionary <int, TypeRecord>(); for (int i = 0; i < header.UnknowCount; i++) { TypeRecord TypeRecordTmp = TROPTRNSReader.ReadBytes(Marshal.SizeOf(typeof(TypeRecord))).ToStruct <TypeRecord>(); typeRecordTable.Add(TypeRecordTmp.ID, TypeRecordTmp); } // Type 2 TypeRecord account_id_Record = typeRecordTable[2]; TROPTRNSReader.BaseStream.Position = account_id_Record.Offset + 32; // 空行 account_id = TROPTRNSReader.ReadBytes(16); // Type 3 TypeRecord trophy_id_Record = typeRecordTable[3]; TROPTRNSReader.BaseStream.Position = trophy_id_Record.Offset + 16; // 空行 trophy_id = Encoding.UTF8.GetString(TROPTRNSReader.ReadBytes(16)).Trim('\0'); u1 = TROPTRNSReader.ReadInt32(); // always 00000090 AllGetTrophysCount = TROPTRNSReader.ReadInt32(); AllSyncPSNTrophyCount = TROPTRNSReader.ReadInt32(); // Type 4 TypeRecord TrophyInfoRecord = typeRecordTable[4]; TROPTRNSReader.BaseStream.Position = TrophyInfoRecord.Offset; // 空行 int type = TROPTRNSReader.ReadInt32(); int blocksize = TROPTRNSReader.ReadInt32(); int sequenceNumber = TROPTRNSReader.ReadInt32(); // if have more than same type block, it will be used int unknow = TROPTRNSReader.ReadInt32(); byte[] blockdata = TROPTRNSReader.ReadBytes(blocksize); trophyInitTime = blockdata.ToStruct <TrophyInitTime>(); for (int i = 0; i < (AllGetTrophysCount - 1); i++) { TROPTRNSReader.BaseStream.Position += 16; TrophyInfo ti = TROPTRNSReader.ReadBytes(blocksize).ToStruct <TrophyInfo>(); trophyInfoTable.Add(ti); } } }
public TROPTRNS(string path_in) { this.path = path_in; BigEndianBinaryReader TROPTRNSReader = null; try { if (path == null) throw new Exception("Path cannot be null!"); if (!path.EndsWith(@"\")) path += @"\"; if (!File.Exists(path + "TROPTRNS.DAT")) throw new Exception("Cannot find TROPTRNS.DAT."); try { TROPTRNSReader = new BigEndianBinaryReader(new FileStream(path + "TROPTRNS.DAT", FileMode.Open)); } catch (IOException) { throw new Exception("Cannot Open TROPTRNS.DAT."); } header = TROPTRNSReader.ReadBytes(Marshal.SizeOf(typeof(Header))).ToStruct<Header>(); if (header.Magic != 0x0000000100ad548f81) { TROPTRNSReader.Close(); throw new Exception("Not a vaild TROPTRNS.DAT."); } typeRecordTable = new Dictionary<int, TypeRecord>(); for (int i = 0; i < header.UnknowCount; i++) { TypeRecord TypeRecordTmp = TROPTRNSReader.ReadBytes(Marshal.SizeOf(typeof(TypeRecord))).ToStruct<TypeRecord>(); typeRecordTable.Add(TypeRecordTmp.ID, TypeRecordTmp); } // Type 2 TypeRecord account_id_Record = typeRecordTable[2]; TROPTRNSReader.BaseStream.Position = account_id_Record.Offset + 32; // 空行 account_id = Encoding.UTF8.GetString(TROPTRNSReader.ReadBytes(16)); // Type 3 TypeRecord trophy_id_Record = typeRecordTable[3]; TROPTRNSReader.BaseStream.Position = trophy_id_Record.Offset + 16; // 空行 trophy_id = Encoding.UTF8.GetString(TROPTRNSReader.ReadBytes(16)).Trim('\0'); u1 = TROPTRNSReader.ReadInt32(); // always 00000090 AllGetTrophysCount = TROPTRNSReader.ReadInt32(); AllSyncPSNTrophyCount = TROPTRNSReader.ReadInt32(); // Type 4 TypeRecord TrophyInfoRecord = typeRecordTable[4]; TROPTRNSReader.BaseStream.Position = TrophyInfoRecord.Offset; // 空行 int type = TROPTRNSReader.ReadInt32(); int blocksize = TROPTRNSReader.ReadInt32(); int sequenceNumber = TROPTRNSReader.ReadInt32(); // if have more than same type block, it will be used int unknow = TROPTRNSReader.ReadInt32(); byte[] blockdata = TROPTRNSReader.ReadBytes(blocksize); trophyInitTime = blockdata.ToStruct<TrophyInitTime>(); for (int i = 0; i < (AllGetTrophysCount - 1); i++) { TROPTRNSReader.BaseStream.Position += 16; TrophyInfo ti = TROPTRNSReader.ReadBytes(blocksize).ToStruct<TrophyInfo>(); trophyInfoTable.Add(ti); } } finally { if (TROPTRNSReader != null) TROPTRNSReader.Close(); } }