public static void QueueSearch(int pid, SearchSpecial special, ushort species, SearchMetagames meta, byte country, byte region) { switch (special) { case SearchSpecial.Latest30: Console.WriteLine("Searching for latest 30 videos."); break; case SearchSpecial.TopLinkBattles: Console.WriteLine("Searching for top link battles."); break; case SearchSpecial.TopSubwayBattles: Console.WriteLine("Searching for top Subway battles."); break; default: { Console.Write("Searching for "); if (species != 0xffff) { Console.Write("species {0}, ", species); } if (meta != SearchMetagames.None) { Console.Write("{0}, ", meta); } if (country != 0xff) { Console.Write("country {0}, ", region); } if (region != 0xff) { Console.Write("region {0}", region); } } break; } byte[] data = new byte[0x15c]; MemoryStream request = new MemoryStream(data); request.Write(new byte[4], 0, 4); // length goes here, see end request.Write(new byte[] { 0xf1, 0x55, 0x00, 0x00 }, 0, 4); // request type, sanity 0000 request.Write(BitConverter.GetBytes(pid), 0, 4); // pid, hopefully this doesn't ban me request.Write(new byte[] { 0x14, 0x02 }, 0, 2); WriteBase64shit(request); request.Write(new byte[0xda], 0, 0xda); request.Write(BitConverter.GetBytes((uint)special), 0, 4); request.Write(BitConverter.GetBytes(species), 0, 2); request.Write(BitConverter.GetBytes((uint)meta), 0, 4); request.WriteByte(country); request.WriteByte(region); request.Write(new byte[] { 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0, 16); request.Flush(); PutLength(data); byte[] response = Conversation(data); if (special != SearchSpecial.Latest30) { using (MySqlConnection db = CreateConnection()) { db.Open(); db.ExecuteNonQuery("INSERT INTO BattleVideoSearchHistory5 (Metagame, Species, " + "Country, Region, Special) VALUES (@metagame, @species, @country, @region, @special)", new MySqlParameter("@metagame", (int)meta), new MySqlParameter("@species", (int)species), new MySqlParameter("@country", (int)country), new MySqlParameter("@region", (int)region), new MySqlParameter("@special", (int)special)); db.Close(); } } QueueSearchResults(response); }
public static bool RunSearch(int pid) { Random rand = new Random(); SearchMetagames[] metagames = (SearchMetagames[])Enum.GetValues(typeof(SearchMetagames)); int metaCount = metagames.Length - 1;// remove None from the list int metaIndex = rand.Next(1, metaCount + 1); SearchMetagames metagame = metagames[metaIndex]; ushort species = (ushort)rand.Next(0, 649); byte country = 0xff; byte region = 0xff; using (MySqlConnection db = CreateConnection()) { db.Open(); if ((long)db.ExecuteScalar( "SELECT Count(*) FROM BattleVideoSearchHistory5 WHERE Metagame = @metagame " + "AND Species = @species AND Country = @country AND Region = @region AND Special = 0", new MySqlParameter("@metagame", (int)metagame), new MySqlParameter("@species", (int)species), new MySqlParameter("@country", (int)country), new MySqlParameter("@region", (int)region)) == 0) { // exact match QueueSearch(pid, SearchSpecial.None, species, metagame, country, region); return(true); } DataTable dt; dt = db.ExecuteDataTable("SELECT DISTINCT Metagame, Species, Country, Region " + "FROM BattleVideoSearchHistory5 WHERE Metagame = @metagame AND Special = 0 ORDER BY Species", new MySqlParameter("@metagame", (int)metagame)); if (dt.Rows.Count < 649) { int prevSpecies = 1; foreach (DataRow row in dt.Rows) { if ((int)row["Species"] != prevSpecies) { QueueSearch(pid, SearchSpecial.None, (ushort)(prevSpecies), metagame, country, region); return(true); } prevSpecies++; } } dt = db.ExecuteDataTable("SELECT DISTINCT Metagame, Species, Country, Region " + "FROM BattleVideoSearchHistory5 WHERE Species = @species AND Special = 0 ORDER BY Metagame", new MySqlParameter("@species", (int)species)); if (dt.Rows.Count < metaCount) { int prevMeta = 1; foreach (DataRow row in dt.Rows) { if ((int)row["Metagame"] != (int)metagames[prevMeta]) { QueueSearch(pid, SearchSpecial.None, species, metagames[prevMeta], country, region); return(true); } prevMeta++; } } dt = db.ExecuteDataTable("SELECT DISTINCT Metagame, Species, Country, Region " + "FROM BattleVideoSearchHistory5 WHERE Special = 0 ORDER BY Metagame, Species"); if (dt.Rows.Count < 649 * metaCount) { int prevSpecies = 1; int prevMeta = 1; foreach (DataRow row in dt.Rows) { if ((int)row["Species"] != prevSpecies || (int)row["Metagame"] != (int)metagames[prevMeta]) { QueueSearch(pid, SearchSpecial.None, (ushort)(prevSpecies), metagames[prevMeta], country, region); return(true); } prevSpecies++; if (prevSpecies > 649) { prevSpecies = 1; prevMeta++; } } } } return(false); }
public static void QueueSearch(int pid, ushort species, SearchMetagames meta, byte country, byte region) { bool hasSearch = species == 0xffff && meta == SearchMetagames.Latest30 && country == 0xff && region == 0xff; if (hasSearch) Console.WriteLine("Searching for latest 30 videos."); else { Console.Write("Searching for "); if (species != 0xffff) Console.Write("species {0}, ", species); if (meta != SearchMetagames.Latest30) Console.Write("{0}, ", meta); if (country != 0xff) Console.Write("country {0}, ", region); if (region != 0xff) Console.Write("region {0}", region); } byte[] data = new byte[0x15c]; MemoryStream request = new MemoryStream(data); request.Write(new byte[4], 0, 4); // length goes here, see end request.Write(new byte[] { 0xd9, 0xc4, 0x00, 0x00 }, 0, 4); // request type, sanity 0000 request.Write(BitConverter.GetBytes(pid), 0, 4); // pid, hopefully this doesn't ban me request.Write(new byte[] { 0x0c, 0x02 }, 0, 2); // there is some random bytes contained in this sometimes. Could be trainer profile // related, I don't know... request.Write(new byte[0x132], 0, 0x132); request.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }, 0, 4); request.Write(BitConverter.GetBytes(species), 0, 2); request.WriteByte((byte)meta); request.WriteByte(country); request.WriteByte(region); request.Write(new byte[] { 0x00, 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0xf6, 0x1b, 0x02, 0x0c, 0x03, 0x00, 0x00 }, 0, 19); request.Flush(); Encrypt(data, 0xc9); PutLength(data); byte[] response = Conversation(data); if (!hasSearch) { using (MySqlConnection db = CreateConnection()) { db.Open(); db.ExecuteNonQuery("INSERT INTO BattleVideoSearchHistory (Metagame, Species, " + "Country, Region) VALUES (@metagame, @species, @country, @region)", new MySqlParameter("@metagame", (int)meta), new MySqlParameter("@species", (int)species), new MySqlParameter("@country", (int)country), new MySqlParameter("@region", (int)region)); db.Close(); } } QueueSearchResults(response); }
public static void QueueSearch(int pid, SearchSpecial special, ushort species, SearchMetagames meta, byte country, byte region) { switch (special) { case SearchSpecial.Latest30: Console.WriteLine("Searching for latest 30 videos."); break; case SearchSpecial.TopLinkBattles: Console.WriteLine("Searching for top link battles."); break; case SearchSpecial.TopSubwayBattles: Console.WriteLine("Searching for top Subway battles."); break; default: { Console.Write("Searching for "); if (species != 0xffff) Console.Write("species {0}, ", species); if (meta != SearchMetagames.None) Console.Write("{0}, ", meta); if (country != 0xff) Console.Write("country {0}, ", region); if (region != 0xff) Console.Write("region {0}", region); } break; } byte[] data = new byte[0x15c]; MemoryStream request = new MemoryStream(data); request.Write(new byte[4], 0, 4); // length goes here, see end request.Write(new byte[] { 0xf1, 0x55, 0x00, 0x00 }, 0, 4); // request type, sanity 0000 request.Write(BitConverter.GetBytes(pid), 0, 4); // pid, hopefully this doesn't ban me request.Write(new byte[] { 0x14, 0x02 }, 0, 2); WriteBase64shit(request); request.Write(new byte[0xda], 0, 0xda); request.Write(BitConverter.GetBytes((uint)special), 0, 4); request.Write(BitConverter.GetBytes(species), 0, 2); request.Write(BitConverter.GetBytes((uint)meta), 0, 4); request.WriteByte(country); request.WriteByte(region); request.Write(new byte[] { 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0, 16); request.Flush(); PutLength(data); byte[] response = Conversation(data); if (special != SearchSpecial.Latest30) { using (MySqlConnection db = CreateConnection()) { db.Open(); db.ExecuteNonQuery("INSERT INTO BattleVideoSearchHistory5 (Metagame, Species, " + "Country, Region, Special) VALUES (@metagame, @species, @country, @region, @special)", new MySqlParameter("@metagame", (int)meta), new MySqlParameter("@species", (int)species), new MySqlParameter("@country", (int)country), new MySqlParameter("@region", (int)region), new MySqlParameter("@special", (int)special)); db.Close(); } } QueueSearchResults(response); }
public static void QueueSearch(int pid, ushort species, SearchMetagames meta, byte country, byte region) { bool hasSearch = species == 0xffff && meta == SearchMetagames.Latest30 && country == 0xff && region == 0xff; if (hasSearch) { Console.WriteLine("Searching for latest 30 videos."); } else { Console.Write("Searching for "); if (species != 0xffff) { Console.Write("species {0}, ", species); } if (meta != SearchMetagames.Latest30) { Console.Write("{0}, ", meta); } if (country != 0xff) { Console.Write("country {0}, ", region); } if (region != 0xff) { Console.Write("region {0}", region); } } byte[] data = new byte[0x15c]; MemoryStream request = new MemoryStream(data); request.Write(new byte[4], 0, 4); // length goes here, see end request.Write(new byte[] { 0xd9, 0xc4, 0x00, 0x00 }, 0, 4); // request type, sanity 0000 request.Write(BitConverter.GetBytes(pid), 0, 4); // pid, hopefully this doesn't ban me request.Write(new byte[] { 0x0c, 0x02 }, 0, 2); // there is some random bytes contained in this sometimes. Could be trainer profile // related, I don't know... request.Write(new byte[0x132], 0, 0x132); request.Write(new byte[] { 0x00, 0x00, 0x00, 0x00 }, 0, 4); request.Write(BitConverter.GetBytes(species), 0, 2); request.WriteByte((byte)meta); request.WriteByte(country); request.WriteByte(region); request.Write(new byte[] { 0x00, 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0xf6, 0x1b, 0x02, 0x0c, 0x03, 0x00, 0x00 }, 0, 19); request.Flush(); Encrypt(data, 0xc9); PutLength(data); byte[] response = Conversation(data); if (!hasSearch) { using (MySqlConnection db = CreateConnection()) { db.Open(); db.ExecuteNonQuery("INSERT INTO BattleVideoSearchHistory (Metagame, Species, " + "Country, Region) VALUES (@metagame, @species, @country, @region)", new MySqlParameter("@metagame", (int)meta), new MySqlParameter("@species", (int)species), new MySqlParameter("@country", (int)country), new MySqlParameter("@region", (int)region)); db.Close(); } } QueueSearchResults(response); }