public TROPUSR(string path_in) { this.path = path_in; BigEndianBinaryReader TROPUSRReader = null; if (path == null) { throw new Exception("Path cannot be null!"); } if (!path.EndsWith(@"\")) { path += @"\"; } if (!File.Exists(path + "TROPUSR.DAT")) { throw new Exception("Cannot find TROPUSR.DAT."); } try { TROPUSRReader = new BigEndianBinaryReader(new FileStream(path + "TROPUSR.DAT", FileMode.Open)); } catch (IOException) { throw new Exception("Cannot Open TROPUSR.DAT."); } header = TROPUSRReader.ReadBytes(Marshal.SizeOf(typeof(Header))).ToStruct <Header>(); if (header.Magic != 0x0000000100ad548f81) { throw new Exception("Not a vaild TROPUSR.DAT."); } typeRecordTable = new Dictionary <int, TypeRecord>(); for (int i = 0; i < header.UnknowCount; i++) { TypeRecord TypeRecordTmp = TROPUSRReader.ReadBytes(Marshal.SizeOf(typeof(TypeRecord))).ToStruct <TypeRecord>(); typeRecordTable.Add(TypeRecordTmp.ID, TypeRecordTmp); } do { // 1 unknow 2 account_id 3 trophy_id and hash(?) 4 trophy info // int type = TROPUSRReader.ReadInt32(); int blocksize = TROPUSRReader.ReadInt32(); int sequenceNumber = TROPUSRReader.ReadInt32(); // if have more than same type block, it will be used int unknow = TROPUSRReader.ReadInt32(); byte[] blockdata = TROPUSRReader.ReadBytes(blocksize); switch (type) { case 1: // unknow break; case 2: account_id = Encoding.UTF8.GetString(blockdata, 16, 16); break; case 3: trophy_id = Encoding.UTF8.GetString(blockdata, 0, 16).Trim('\0'); short u1 = BitConverter.ToInt16(blockdata, 16).ChangeEndian(); short u2 = BitConverter.ToInt16(blockdata, 18).ChangeEndian(); short u3 = BitConverter.ToInt16(blockdata, 20).ChangeEndian(); short u4 = BitConverter.ToInt16(blockdata, 22).ChangeEndian(); all_trophy_number = BitConverter.ToInt32(blockdata, 24).ChangeEndian(); int u5 = BitConverter.ToInt32(blockdata, 28).ChangeEndian(); AchievementRate[0] = BitConverter.ToUInt32(blockdata, 64); AchievementRate[1] = BitConverter.ToUInt32(blockdata, 68); AchievementRate[2] = BitConverter.ToUInt32(blockdata, 72); AchievementRate[3] = BitConverter.ToUInt32(blockdata, 76); break; case 4: trophyTypeTable.Add(blockdata.ToStruct <TrophyType>()); break; case 5: trophyListInfo = blockdata.ToStruct <TrophyListInfo>(); break; case 6: trophyTimeInfoTable.Add(blockdata.ToStruct <TrophyTimeInfo>()); break; case 7: // unknow unknowType7 = blockdata.ToStruct <UnknowType7>(); // Console.WriteLine("Unsupported block type. (Type{0})", type); break; case 8: // hash unknowHash = blockdata.SubArray(0, 20); break; case 9: // 通常寫著白金獎盃的一些數字,不明 // Console.WriteLine("Unsupported block type. (Type{0})", type); break; case 10: // i think it just a padding break; } } while (TROPUSRReader.BaseStream.Position < TROPUSRReader.BaseStream.Length); trophyListInfo.ListLastUpdateTime = DateTime.Now; TROPUSRReader.Close(); }
public TROPUSR(string path_in) { this.path = path_in; BigEndianBinaryReader TROPUSRReader = null; if (path == null) throw new Exception("Path cannot be null!"); if (!path.EndsWith(@"\")) path += @"\"; if (!File.Exists(path + "TROPUSR.DAT")) throw new Exception("Cannot find TROPUSR.DAT."); try { TROPUSRReader = new BigEndianBinaryReader(new FileStream(path + "TROPUSR.DAT", FileMode.Open)); } catch (IOException) { throw new Exception("Cannot Open TROPUSR.DAT."); } header = TROPUSRReader.ReadBytes(Marshal.SizeOf(typeof(Header))).ToStruct<Header>(); if (header.Magic != 0x0000000100ad548f81) throw new Exception("Not a vaild TROPUSR.DAT."); typeRecordTable = new Dictionary<int, TypeRecord>(); for (int i = 0; i < header.UnknowCount; i++) { TypeRecord TypeRecordTmp = TROPUSRReader.ReadBytes(Marshal.SizeOf(typeof(TypeRecord))).ToStruct<TypeRecord>(); typeRecordTable.Add(TypeRecordTmp.ID, TypeRecordTmp); } do { // 1 unknow 2 account_id 3 trophy_id and hash(?) 4 trophy info // int type = TROPUSRReader.ReadInt32(); int blocksize = TROPUSRReader.ReadInt32(); int sequenceNumber = TROPUSRReader.ReadInt32(); // if have more than same type block, it will be used int unknow = TROPUSRReader.ReadInt32(); byte[] blockdata = TROPUSRReader.ReadBytes(blocksize); switch (type) { case 1: // unknow break; case 2: account_id = Encoding.UTF8.GetString(blockdata, 16, 16); break; case 3: trophy_id = Encoding.UTF8.GetString(blockdata, 0, 16).Trim('\0'); short u1 = BitConverter.ToInt16(blockdata, 16).ChangeEndian(); short u2 = BitConverter.ToInt16(blockdata, 18).ChangeEndian(); short u3 = BitConverter.ToInt16(blockdata, 20).ChangeEndian(); short u4 = BitConverter.ToInt16(blockdata, 22).ChangeEndian(); all_trophy_number = BitConverter.ToInt32(blockdata, 24).ChangeEndian(); int u5 = BitConverter.ToInt32(blockdata, 28).ChangeEndian(); AchievementRate[0] = BitConverter.ToUInt32(blockdata, 64); AchievementRate[1] = BitConverter.ToUInt32(blockdata, 68); AchievementRate[2] = BitConverter.ToUInt32(blockdata, 72); AchievementRate[3] = BitConverter.ToUInt32(blockdata, 76); break; case 4: trophyTypeTable.Add(blockdata.ToStruct<TrophyType>()); break; case 5: trophyListInfo = blockdata.ToStruct<TrophyListInfo>(); break; case 6: trophyTimeInfoTable.Add(blockdata.ToStruct<TrophyTimeInfo>()); break; case 7:// unknow unknowType7 = blockdata.ToStruct<UnknowType7>(); // Console.WriteLine("Unsupported block type. (Type{0})", type); break; case 8: // hash unknowHash = blockdata.SubArray(0, 20); break; case 9: // 通常寫著白金獎盃的一些數字,不明 // Console.WriteLine("Unsupported block type. (Type{0})", type); break; case 10: // i think it just a padding break; } } while (TROPUSRReader.BaseStream.Position < TROPUSRReader.BaseStream.Length); trophyListInfo.ListLastUpdateTime = DateTime.Now; TROPUSRReader.Close(); }
public TROPUSR(string path) { if (path == null || path.Trim() == string.Empty) { throw new Exception("Path cannot be null!"); } string fileName = Path.Combine(path, TROPUSR_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 TROPUSRReader = new BigEndianBinaryReader(fileStream)) { header = TROPUSRReader.ReadBytes(Marshal.SizeOf(typeof(Header))).ToStruct <Header>(); if (header.Magic != 0x0000000100ad548f81) { throw new InvalidTrophyFileException(TROPUSR_FILE_NAME); } typeRecordTable = new Dictionary <int, TypeRecord>(); for (int i = 0; i < header.UnknowCount; i++) { TypeRecord TypeRecordTmp = TROPUSRReader.ReadBytes(Marshal.SizeOf(typeof(TypeRecord))).ToStruct <TypeRecord>(); typeRecordTable.Add(TypeRecordTmp.ID, TypeRecordTmp); } do { // 1 unknow 2 account_id 3 trophy_id and hash(?) 4 trophy info // int type = TROPUSRReader.ReadInt32(); int blocksize = TROPUSRReader.ReadInt32(); int sequenceNumber = TROPUSRReader.ReadInt32(); // if have more than same type block, it will be used int unknow = TROPUSRReader.ReadInt32(); byte[] blockdata = TROPUSRReader.ReadBytes(blocksize); switch (type) { case 1: // unknow break; case 2: account_id = blockdata.SubArray(16, 16); break; case 3: trophy_id = Encoding.UTF8.GetString(blockdata, 0, 16).Trim('\0'); short u1 = BitConverter.ToInt16(blockdata, 16).ChangeEndian(); short u2 = BitConverter.ToInt16(blockdata, 18).ChangeEndian(); short u3 = BitConverter.ToInt16(blockdata, 20).ChangeEndian(); short u4 = BitConverter.ToInt16(blockdata, 22).ChangeEndian(); all_trophy_number = BitConverter.ToInt32(blockdata, 24).ChangeEndian(); int u5 = BitConverter.ToInt32(blockdata, 28).ChangeEndian(); AchievementRate[0] = BitConverter.ToUInt32(blockdata, 64); AchievementRate[1] = BitConverter.ToUInt32(blockdata, 68); AchievementRate[2] = BitConverter.ToUInt32(blockdata, 72); AchievementRate[3] = BitConverter.ToUInt32(blockdata, 76); break; case 4: trophyTypeTable.Add(blockdata.ToStruct <TrophyType>()); break; case 5: trophyListInfo = blockdata.ToStruct <TrophyListInfo>(); break; case 6: trophyTimeInfoTable.Add(blockdata.ToStruct <TrophyTimeInfo>()); break; case 7:// unknow unknowType7 = blockdata.ToStruct <UnknowType7>(); // Console.WriteLine("Unsupported block type. (Type{0})", type); break; case 8: // hash unknowHash = blockdata.SubArray(0, 20); break; case 9: // 通常寫著白金獎盃的一些數字,不明 // Console.WriteLine("Unsupported block type. (Type{0})", type); break; case 10: // i think it just a padding break; } } while (TROPUSRReader.BaseStream.Position < TROPUSRReader.BaseStream.Length); trophyListInfo.ListLastUpdateTime = DateTime.Now; } }