diff --git a/pkmnFoundations.sln b/pkmnFoundations.sln index 30e92c43..a36bcb4e 100644 --- a/pkmnFoundations.sln +++ b/pkmnFoundations.sln @@ -23,7 +23,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bvRestorer4", "bvRestorer4\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bvRestorer5", "bvRestorer5\bvRestorer5.csproj", "{9F2A0A44-B90E-4B30-8DFF-2B5E273F5BEC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "towerRestorer4", "towerRestorer4\towerRestorer4.csproj", "{750A0BFD-7258-4B32-A4F9-60EEEB0BA64A}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "towerRestorer", "towerRestorer4\towerRestorer.csproj", "{750A0BFD-7258-4B32-A4F9-60EEEB0BA64A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/towerRestorer4/Program.cs b/towerRestorer4/Program.cs index fbd9c643..e094363f 100644 --- a/towerRestorer4/Program.cs +++ b/towerRestorer4/Program.cs @@ -8,7 +8,7 @@ using PkmnFoundations.Data; using PkmnFoundations.Structures; using PkmnFoundations.Support; -namespace towerRestorer4 +namespace towerRestorer { class Program { @@ -20,7 +20,7 @@ namespace towerRestorer4 Console.WriteLine("Attempts to insert files in "); Console.WriteLine("into the database in app configuration."); Console.WriteLine("Only inserts files whose names match the naming pattern:"); - Console.WriteLine("g4_pid*_rank*_room*"); + Console.WriteLine("g*_pid*_rank*_room*"); Console.WriteLine("Rank and room number are taken from the filename."); return; } @@ -56,7 +56,7 @@ namespace towerRestorer4 byte rank, room; if (split.Length != 4 || - split[0] != "g4" || + (split[0] != "g4" && split[0] != "g5") || split[2].Substring(0, 4) != "rank" || !Byte.TryParse(split[2].Substring(4), out rank) || split[3].Substring(0, 4) != "room" || @@ -68,62 +68,129 @@ namespace towerRestorer4 continue; } + int gen = Convert.ToInt32(split[0].Substring(1)); + rank--; room--; - FileStream fs = File.OpenRead(s); - if (fs.Length != 0xa38) + switch (gen) { - Console.WriteLine("{0}: file size is wrong, skipped.", filename); - failureCount++; - continue; + case 4: + { + continue; + FileStream fs = File.OpenRead(s); + if (fs.Length != 0xa38) + { + Console.WriteLine("{0}: file size is wrong, skipped.", filename); + failureCount++; + continue; + } + + byte[] data = new byte[0xa38]; + fs.ReadBlock(data, 0, 0xa38); + fs.Close(); + + // battletower/download.asp response: 2616 bytes + // 00-63b: BattleTowerRecord objects x7 + // 63c-a37: BattleTowerTrainerProfile objects x30 + for (int x = 0; x < 7; x++) + { + try + { + BattleTowerRecord4 record = new BattleTowerRecord4(data, 0xe4 * x); + record.PID = 0; + record.Rank = rank; + record.RoomNum = room; + record.BattlesWon = 7; + db.BattleTowerUpdateRecord4(record); + opponentSuccessCount++; + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + opponentFailureCount++; + } + } + + for (int x = 0; x < 30; x++) + { + try + { + BattleTowerProfile4 profile = new BattleTowerProfile4(data, 0x63c + 0x22 * x); + BattleTowerRecord4 record = new BattleTowerRecord4(); + record.Profile = profile; + record.PID = 0; + record.Rank = rank; + record.RoomNum = room; + db.BattleTowerAddLeader4(record); + leaderSuccessCount++; + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + leaderFailureCount++; + } + } + } break; + + case 5: + { + FileStream fs = File.OpenRead(s); + if (fs.Length != 0xab4) + { + Console.WriteLine("{0}: file size is wrong, skipped.", filename); + failureCount++; + continue; + } + + byte[] data = new byte[0xab4]; + fs.ReadBlock(data, 0, 0xab4); + fs.Close(); + + //web/battletower/download.asp response: 2700 bytes + //00-68f: BattleSubwayRecord objects x7 + //690-a8b: BattleSubwayTrainerProfile objects x30 + for (int x = 0; x < 7; x++) + { + try + { + BattleSubwayRecord5 record = new BattleSubwayRecord5(data, 0xf0 * x); + record.PID = 0; + record.Rank = rank; + record.RoomNum = room; + record.BattlesWon = 7; + db.BattleSubwayUpdateRecord5(record); + opponentSuccessCount++; + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + opponentFailureCount++; + } + } + + for (int x = 0; x < 30; x++) + { + try + { + BattleSubwayProfile5 profile = new BattleSubwayProfile5(data, 0x690 + 0x22 * x); + BattleSubwayRecord5 record = new BattleSubwayRecord5(); + record.Profile = profile; + record.PID = 0; + record.Rank = rank; + record.RoomNum = room; + db.BattleSubwayAddLeader5(record); + leaderSuccessCount++; + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + leaderFailureCount++; + } + } + } break; } - byte[] data = new byte[0xa38]; - fs.ReadBlock(data, 0, 0xa38); - fs.Close(); - - // battletower/download.asp response: 2616 bytes - // 00-63b: BattleTowerRecord objects x7 - // 63c-a37: BattleTowerTrainerProfile objects x30 - for (int x = 0; x < 7; x++) - { - try - { - BattleTowerRecord4 record = new BattleTowerRecord4(data, 0xe4 * x); - record.PID = 0; - record.Rank = rank; - record.RoomNum = room; - record.BattlesWon = 7; - db.BattleTowerUpdateRecord4(record); - opponentSuccessCount++; - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - opponentFailureCount++; - } - } - - for (int x = 0; x < 30; x++) - { - try - { - BattleTowerProfile4 profile = new BattleTowerProfile4(data, 0x63c + 0x22 * x); - BattleTowerRecord4 record = new BattleTowerRecord4(); - record.Profile = profile; - record.PID = 0; - record.Rank = rank; - record.RoomNum = room; - db.BattleTowerAddLeader4(record); - leaderSuccessCount++; - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - leaderFailureCount++; - } - } Console.WriteLine("{0} complete", s); } diff --git a/towerRestorer4/towerRestorer4.csproj b/towerRestorer4/towerRestorer.csproj similarity index 96% rename from towerRestorer4/towerRestorer4.csproj rename to towerRestorer4/towerRestorer.csproj index af20be13..8d7d2921 100644 --- a/towerRestorer4/towerRestorer4.csproj +++ b/towerRestorer4/towerRestorer.csproj @@ -7,8 +7,8 @@ {750A0BFD-7258-4B32-A4F9-60EEEB0BA64A} Exe Properties - towerRestorer4 - towerRestorer4 + towerRestorer + towerRestorer v4.5 512