From 5db746ee64705d6e4b0bf2c2396b254d1790b2ef Mon Sep 17 00:00:00 2001 From: Greg Edwards Date: Sat, 13 Mar 2021 00:40:18 -0500 Subject: [PATCH] Added replay responses for trainer rankings. --- GlobalTerminalService/GTServer4.cs | 271 ++++++++++++++++++++++++++--- library/Support/StreamExtender.cs | 7 + 2 files changed, 249 insertions(+), 29 deletions(-) diff --git a/GlobalTerminalService/GTServer4.cs b/GlobalTerminalService/GTServer4.cs index b7a89d0d..37bb5f69 100644 --- a/GlobalTerminalService/GTServer4.cs +++ b/GlobalTerminalService/GTServer4.cs @@ -126,6 +126,7 @@ namespace PkmnFoundations.GlobalTerminalService response.Write(BitConverter.GetBytes(result.PID), 0, 4); response.Write(BitConverter.GetBytes((int)result.Label), 0, 4); response.Write(BitConverter.GetBytes(result.SerialNumber), 0, 8); + // xxx: this may throw if there's database corruption response.Write(result.Data, 0, 0x21c); } logEntry.AppendFormat("Retrieved {0} boxes.", results.Length); @@ -335,14 +336,249 @@ namespace PkmnFoundations.GlobalTerminalService #region Trainer Rankings case RequestTypes4.TrainerRankingsHead: - logEntry.AppendLine("Not supported."); - response.Write(new byte[] { 0x02, 0x00 }, 0, 2); - break; + { + if (data.Length != 0x140) + { + logEntry.AppendLine("Length did not validate."); + type = EventLogEntryType.FailureAudit; + response.Write(new byte[] { 0x02, 0x00 }, 0, 2); + break; + } + + logEntry.AppendLine("Replayed response."); + response.Write(new byte[] { 0x00, 0x00 }, 0, 2); + + // Response format seems to be a list of the three record categories currently being collected. + // 0x01: Hall of fame entries + // 0x28: Completed GTS trades + // 0x43: Facilities challenged at battle frontier + // The purpose of 0x1c is unclear to me. + response.Write(new byte[] { 0x01, 0x28, 0x43, 0x1c }, 0, 4); + + } break; case RequestTypes4.TrainerRankingsSearch: - logEntry.AppendLine("Not supported."); - response.Write(new byte[] { 0x02, 0x00 }, 0, 2); - break; + { + if (data.Length != 0x164) + { + logEntry.AppendLine("Length did not validate."); + type = EventLogEntryType.FailureAudit; + response.Write(new byte[] { 0x02, 0x00 }, 0, 2); + break; + } + + // The request is important. It contains the player's records for the above three chosen categories. + // It also (presumably) conveys which teams the player is a part of. + // (Trainer Class, Birth Month, Favourite Pokémon) + + // The response is biig and contains all the records for both this week and last week. + // This week lacks numbers because they're still growing and to make it a surprise. + + logEntry.AppendLine("Replayed response."); + response.Write(new byte[] { 0x00, 0x00 }, 0, 2); + + response.WriteBytes(new byte[] { + 0x1c, 0x00, 0x00, 0x00, 0x02, 0x07, 0x06, 0x00, + 0x04, 0x01, 0x05, 0x03, 0x0c, 0x09, 0x0f, 0x0e, + 0x0d, 0x08, 0x0a, 0x0b, 0x89, 0xe9, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x8a, 0x66, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x8f, 0x04, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xb1, 0xe0, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x31, 0xa4, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xf5, 0xa0, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xa8, 0x9d, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x71, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xd6, 0x51, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xc9, 0x46, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x17, 0x2a, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xb2, 0x26, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x58, 0x22, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x20, 0x21, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x99, 0x1e, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x6b, 0x12, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x09, 0x05, 0x0c, + 0x07, 0x04, 0x08, 0x0a, 0x02, 0x03, 0x06, 0x0b, + 0xd3, 0x16, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xf0, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xa4, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x17, 0xea, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x90, 0xcd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x86, 0xb6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x6e, 0xb5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xdf, 0xad, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xde, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7b, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x46, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x89, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x9d, 0x00, 0xc0, 0x01, 0xf9, 0x00, 0x5e, 0x01, + 0xf8, 0x00, 0x06, 0x00, 0x95, 0x01, 0xa0, 0x00, + 0x97, 0x00, 0x95, 0x00, 0xbd, 0x01, 0x7f, 0x01, + 0x5f, 0x00, 0xd8, 0x01, 0x88, 0x01, 0x94, 0x00, + 0xed, 0x01, 0x19, 0x00, 0x93, 0x00, 0x96, 0x00, + 0xb6, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x95, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x61, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xb1, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0b, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xd3, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xa4, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xee, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x22, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x1f, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x27, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x3a, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x6f, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x5e, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x41, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x33, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xeb, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xdf, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x4c, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2b, 0x00, 0x00, 0x00, 0x07, 0x03, 0x0f, 0x02, + 0x05, 0x0e, 0x04, 0x01, 0x09, 0x00, 0x0a, 0x0c, + 0x06, 0x0d, 0x0b, 0x08, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0c, 0x08, 0x0b, 0x09, + 0x01, 0x07, 0x03, 0x04, 0x06, 0x0a, 0x05, 0x02, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xf8, 0x00, 0xbd, 0x00, 0x8d, 0x00, 0x71, 0x01, + 0x8e, 0x01, 0x98, 0x00, 0xa2, 0x00, 0x7e, 0x00, + 0x42, 0x01, 0x55, 0x01, 0x48, 0x01, 0xa7, 0x01, + 0x53, 0x00, 0x4f, 0x01, 0xa6, 0x00, 0xd7, 0x00, + 0xcc, 0x01, 0x48, 0x00, 0xf3, 0x00, 0x94, 0x01, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x4a, 0x00, 0x00, 0x00, 0x02, 0x06, 0x07, 0x05, + 0x00, 0x03, 0x04, 0x01, 0x08, 0x09, 0x0e, 0x0c, + 0x0d, 0x0a, 0x0b, 0x0f, 0x5e, 0x76, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x8f, 0x39, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x16, 0x28, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x8e, 0x1e, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x4a, 0x13, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xb6, 0x0c, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x33, 0x0b, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xfe, 0x0a, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xaa, 0x0a, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x2b, 0x04, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xb8, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x63, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x14, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xad, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x01, 0x09, + 0x0a, 0x05, 0x03, 0x0b, 0x07, 0x08, 0x0c, 0x06, + 0x64, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xd7, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x24, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7a, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x5a, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xfc, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xf3, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x9f, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x3a, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x82, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xbb, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xa6, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xf9, 0x00, 0x79, 0x00, 0x9d, 0x00, 0x80, 0x01, + 0xa0, 0x00, 0x9b, 0x01, 0x95, 0x01, 0x70, 0x01, + 0xc0, 0x01, 0xd0, 0x01, 0x7f, 0x01, 0x94, 0x01, + 0x95, 0x00, 0xbd, 0x01, 0x7d, 0x01, 0xe6, 0x01, + 0x94, 0x00, 0x92, 0x00, 0xd2, 0x01, 0x01, 0x00, + 0xf5, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xec, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x85, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x1d, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x38, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x1a, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x27, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xd4, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xb7, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x87, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x87, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x6e, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x67, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xd4, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xb2, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x9d, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x97, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xcd, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xb4, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x80, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x04, 0x06, 0x0f, + 0x03, 0x05, 0x07, 0x00, 0x08, 0x09, 0x01, 0x0c, + 0x0e, 0x0b, 0x0d, 0x0a, 0x03, 0x06, 0x01, 0x04, + 0x0a, 0x05, 0x08, 0x0c, 0x09, 0x0b, 0x02, 0x07, + 0x8e, 0x00, 0x7c, 0x01, 0x75, 0x01, 0x8e, 0x01, + 0x9d, 0x00, 0xe4, 0x01, 0x04, 0x01, 0x80, 0x01, + 0xfe, 0x00, 0xaf, 0x00, 0xe3, 0x01, 0x88, 0x01, + 0xe7, 0x01, 0x82, 0x00, 0x5e, 0x01, 0xeb, 0x01, + 0xe5, 0x00, 0xe8, 0x01, 0x93, 0x00, 0x96, 0x00, + 0x28, 0x00, 0x00, 0x00, 0x03, 0x07, 0x00, 0x0c, + 0x04, 0x02, 0x05, 0x06, 0x0b, 0x01, 0x0f, 0x0d, + 0x08, 0x09, 0x0e, 0x0a, 0x0a, 0x07, 0x0c, 0x06, + 0x01, 0x02, 0x08, 0x03, 0x05, 0x09, 0x0b, 0x04, + 0x88, 0x01, 0x8f, 0x00, 0x7c, 0x01, 0x8e, 0x01, + 0xea, 0x00, 0x01, 0x01, 0xa4, 0x01, 0xe6, 0x01, + 0x5e, 0x01, 0xc0, 0x01, 0x8e, 0x00, 0x9a, 0x00, + 0xe7, 0x01, 0xbd, 0x01, 0xfe, 0x00, 0x82, 0x00, + 0xbb, 0x00, 0x04, 0x01, 0xb0, 0x00, 0x9d, 0x00, + 0x43, 0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x04, + 0x03, 0x08, 0x07, 0x05, 0x0f, 0x01, 0x0c, 0x09, + 0x0b, 0x0e, 0x0d, 0x0a, 0x0a, 0x05, 0x04, 0x07, + 0x01, 0x03, 0x0b, 0x0c, 0x09, 0x06, 0x08, 0x02, + 0x8e, 0x01, 0x75, 0x01, 0x82, 0x00, 0x80, 0x01, + 0xaf, 0x00, 0xeb, 0x01, 0xe7, 0x01, 0x5e, 0x01, + 0x9a, 0x00, 0x8f, 0x00, 0x9d, 0x00, 0xe8, 0x01, + 0x8e, 0x00, 0x7c, 0x01, 0x7d, 0x01, 0xe5, 0x00, + 0x88, 0x01, 0x1a, 0x00, 0xfe, 0x00, 0xf9, 0x00 + }); + + } break; #endregion default: @@ -378,29 +614,6 @@ namespace PkmnFoundations.GlobalTerminalService message[x] ^= m_pad[(x + padOffset) & 0xff]; } - private byte Byte6(RequestTypes4 type) - { - switch (type) - { - case RequestTypes4.BoxUpload: - case RequestTypes4.BoxSearch: - return 0x52; - case RequestTypes4.DressupUpload: - case RequestTypes4.DressupSearch: - return 0x4e; - case RequestTypes4.BattleVideoUpload: - case RequestTypes4.BattleVideoSearch: - case RequestTypes4.BattleVideoWatch: - case RequestTypes4.BattleVideoSaved: - return 0x59; - case RequestTypes4.TrainerRankingsHead: - case RequestTypes4.TrainerRankingsSearch: - return 0x55; - default: - return 0x00; - } - } - public override string Title { get diff --git a/library/Support/StreamExtender.cs b/library/Support/StreamExtender.cs index 05e529de..5c0552db 100644 --- a/library/Support/StreamExtender.cs +++ b/library/Support/StreamExtender.cs @@ -60,5 +60,12 @@ namespace PkmnFoundations.Support while ((lastProgress = src.Read(buffer, 0, BUFFER_LENGTH)) > 0) dest.Write(buffer, 0, lastProgress); } + + public static void WriteBytes(this Stream s, byte[] buffer) + { + // Lack of a Stream.Write overload that just writes the whole array + // seems like a huge omission to me. + s.Write(buffer, 0, buffer.Length); + } } }