Skip to content

Commit

Permalink
Updated for USUM.
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveCookTU committed Dec 30, 2017
1 parent 40f12c1 commit e12ef1e
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 41 deletions.
33 changes: 28 additions & 5 deletions Ledybot/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ public partial class MainForm : Form
public LogDelegate delLastLog;
public string lastlog = "";
public int pid = 0;
public int game = 0;
public PKHeX dumpedPKHeX = new PKHeX();

public uint boxOff = 0x330D9838;
public uint wcOff = 0x331397E4;
public uint partyOff = 0x34195E10;
private uint eggOff = 0x3313EDD8;
public uint boxOff;
public uint wcOff;

public uint partyOff;
private uint eggOff;

private bool botWorking = false;
private bool botStop = false;
Expand Down Expand Up @@ -96,7 +98,28 @@ public void getGame(object sender, EventArgs e)
pid = Convert.ToInt32("0x" + splitlog.Substring(0, 8), 16);
Program.helper.pid = pid;
Program.scriptHelper.write(0x3E14C0, BitConverter.GetBytes(0xE3A01000), pid);
game = 0;
MessageBox.Show("Connection Successful!");

boxOff = 0x330D9838;
wcOff = 0x331397E4;
partyOff = 0x34195E10;
eggOff = 0x3313EDD8;

} else if(log.Contains("momiji"))
{
string splitlog = log.Substring(log.IndexOf(", pname: momiji") - 8, log.Length - log.IndexOf(", pname: momiji"));
pid = Convert.ToInt32("0x" + splitlog.Substring(0, 8), 16);
Program.helper.pid = pid;
Program.scriptHelper.write(0x3F341C, BitConverter.GetBytes(0xE3A01000), pid);
Program.scriptHelper.write(0x3F3420, BitConverter.GetBytes(0xE3A01000), pid);
game = 1;
MessageBox.Show("Connection Successful!");

boxOff = 0x33015AB0;
wcOff = 0x33075BF4;
partyOff = 0x33F7FA44;
eggOff = 0x3307B1E8;
}
}

Expand Down Expand Up @@ -196,7 +219,7 @@ private async void btn_Start_Click(object sender, EventArgs e)
{
tradeDirection = 2;
}
GTSBot7 = new GTSBot7(pid, combo_pkmnList.SelectedIndex + 1, combo_gender.SelectedIndex, combo_levelrange.SelectedIndex ,cb_Blacklist.Checked, cb_Reddit.Checked, tradeDirection, tb_waittime.Text, tb_consoleName.Text, cb_UseLedySync.Checked, tb_LedySyncIP.Text, tb_LedySyncPort.Text);
GTSBot7 = new GTSBot7(pid, combo_pkmnList.SelectedIndex + 1, combo_gender.SelectedIndex, combo_levelrange.SelectedIndex ,cb_Blacklist.Checked, cb_Reddit.Checked, tradeDirection, tb_waittime.Text, tb_consoleName.Text, cb_UseLedySync.Checked, tb_LedySyncIP.Text, tb_LedySyncPort.Text, game);
Task<int> Bot = GTSBot7.RunBot();
int result = await Bot;
if (botStop)
Expand Down
120 changes: 88 additions & 32 deletions Ledybot/GTSBot7.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GTSBot7
{

//private System.IO.StreamWriter file = new StreamWriter(@"C:\Temp\ledylog.txt");

public enum gtsbotstates { botstart, startsearch, pressSeek, openpokemonwanted, openwhatpokemon, typepokemon, presssearch, startfind, findfromend, findfromstart, trade, research, botexit, updatecomments, quicksearch, panic };

private TcpClient client = new TcpClient();
Expand All @@ -28,30 +28,31 @@ public enum gtsbotstates { botstart, startsearch, pressSeek, openpokemonwanted,
private const int SEARCHDIRECTION_FROMBACKFIRSTPAGEONLY = 1;
private const int SEARCHDIRECTION_FROMFRONT = 2;

private uint addr_PageSize = 0x32A6A1A4; //How many entries are on the current GTS page
private uint addr_PageEndStartRecord = 0x32A6A68C; //This address holds the address to the last block in the entry-block-list
private uint addr_PageStartStartRecord = 0x32A6A690; //This address holds the address to the first block in the entry block-list
private uint addr_PageCurrentView = 0x305ea384; //Current selected entry in the list
private uint addr_PageStartingIndex = 0x32A6A190; //To determine on which page we are, 0 = first page, 100 = second page, etc
private uint addr_ListOfAllPageEntries = 0x32A6A7C4; //Startingaddress of all up to 100 trade entries of the current page
private uint addr_PageSize; //How many entries are on the current GTS page
private uint addr_PageEndStartRecord; //This address holds the address to the last block in the entry-block-list
private uint addr_PageStartStartRecord; //This address holds the address to the first block in the entry block-list
private uint addr_PageCurrentView; //Current selected entry in the list
private uint addr_PageStartingIndex; //To determine on which page we are, 0 = first page, 100 = second page, etc
private uint addr_ListOfAllPageEntries; //Startingaddress of all up to 100 trade entries of the current page

private uint addr_box1slot1; //To inject the pokemon into box1slot1

private uint addr_box1slot1 = 0x330d9838; //To inject the pokemon into box1slot1
private uint addr_SearchPokemonNameField = 0x301118D4; //Holds the currently typed in name in the "search pokemon" window
//private uint addr_SearchPokemonNameField = 0x301118D4; //Holds the currently typed in name in the "search pokemon" window

private uint addr_currentScreen = 0x00674802; //Hopefully a address to tell us in what screen we are (roughly)
private uint addr_currentScreen; //Hopefully a address to tell us in what screen we are (roughly)

private uint addr_pokemonToFind = 0x32A6A180;
private uint addr_pokemonToFindGender = 0x32A6A184;
private uint addr_pokemonToFindLevel = 0x32A6A188;
private uint addr_pokemonToFind;
private uint addr_pokemonToFindGender;
private uint addr_pokemonToFindLevel;

private int val_PlazaScreen = 0x00;
private int val_Quit_SeekScreen = 0x3F2B;
private int val_SearchScreen = 0x4128; //also in the box during selecting etc
private int val_WhatPkmnScreen = 0x4160;
private int val_GTSListScreen = 0x4180;
private int val_BoxScreen = 0x4120;
private int val_system = 0x41A8; //during error, saving, early sending
private int val_duringTrade = 0x3FD5; //trade is split in several steps, sometimes even 0x00
private int val_PlazaScreen;
private int val_Quit_SeekScreen;
private int val_SearchScreen; //also in the box during selecting etc
private int val_WhatPkmnScreen;
private int val_GTSListScreen;
private int val_BoxScreen;
private int val_system; //during error, saving, early sending
private int val_duringTrade; //trade is split in several steps, sometimes even 0x00

private int iPokemonToFind = 0;
private int iPokemonToFindGender = 0;
Expand Down Expand Up @@ -98,7 +99,7 @@ private Boolean canThisTrade(byte[] principal, string consoleName, string traine
NetworkStream clientStream = client.GetStream();
byte[] buffer = new byte[4096];
byte[] messageID = { 0x00 };
string szmessage = consoleName + '\t' + trainerName + '\t' + country + '\t' + region + '\t' + pokemon + '\t' + page + "\t" + index +"\t";
string szmessage = consoleName + '\t' + trainerName + '\t' + country + '\t' + region + '\t' + pokemon + '\t' + page + "\t" + index + "\t";
byte[] toSend = Encoding.UTF8.GetBytes(szmessage);

buffer = messageID.Concat(principal).Concat(toSend).ToArray();
Expand All @@ -109,7 +110,7 @@ private Boolean canThisTrade(byte[] principal, string consoleName, string traine
{
//blocks until a client sends a message
int bytesRead = clientStream.Read(message, 0, 4096);
if(message[0] == 0x02)
if (message[0] == 0x02)
{
Program.f1.banlist.Add(szFC);
}
Expand All @@ -122,7 +123,7 @@ private Boolean canThisTrade(byte[] principal, string consoleName, string traine
}
}

public GTSBot7(int iP, int iPtF, int iPtFGender, int iPtFLevel, bool bBlacklist, bool bReddit, int iSearchDirection, string waittime, string consoleName, bool useLedySync, string ledySyncIp, string ledySyncPort)
public GTSBot7(int iP, int iPtF, int iPtFGender, int iPtFLevel, bool bBlacklist, bool bReddit, int iSearchDirection, string waittime, string consoleName, bool useLedySync, string ledySyncIp, string ledySyncPort, int game)
{
this.iPokemonToFind = iPtF;
this.iPokemonToFindGender = iPtFGender;
Expand All @@ -140,6 +141,60 @@ public GTSBot7(int iP, int iPtF, int iPtFGender, int iPtFLevel, bool bBlacklist,
client.Connect(serverEndPoint);
}
this.consoleName = consoleName;

if (game == 0)
{
addr_PageSize = 0x32A6A1A4; //How many entries are on the current GTS page
addr_PageEndStartRecord = 0x32A6A68C; //This address holds the address to the last block in the entry-block-list
addr_PageStartStartRecord = 0x32A6A690; //This address holds the address to the first block in the entry block-list
addr_PageCurrentView = 0x305ea384; //Current selected entry in the list
addr_PageStartingIndex = 0x32A6A190; //To determine on which page we are, 0 = first page, 100 = second page, etc
addr_ListOfAllPageEntries = 0x32A6A7C4; //Startingaddress of all up to 100 trade entries of the current page

addr_box1slot1 = 0x330D9838; //To inject the pokemon into box1slot1

addr_currentScreen = 0x00674802; //Hopefully a address to tell us in what screen we are (roughly)

addr_pokemonToFind = 0x32A6A180;
addr_pokemonToFindGender = 0x32A6A184;
addr_pokemonToFindLevel = 0x32A6A188;

val_PlazaScreen = 0x00;
val_Quit_SeekScreen = 0x3F2B;
val_SearchScreen = 0x4128; //also in the box during selecting etc
val_WhatPkmnScreen = 0x4160;
val_GTSListScreen = 0x4180;
val_BoxScreen = 0x4120;
val_system = 0x41A8; //during error, saving, early sending
val_duringTrade = 0x3FD5; //trade is split in several steps, sometimes even 0x00
}
else if (game == 1)
{
addr_PageSize = 0x329921A4;
addr_PageEndStartRecord = 0x3299268C;
addr_PageStartStartRecord = 0x32992690;
addr_PageCurrentView = 0x305CD9F4;
addr_PageStartingIndex = 0x32992190;
addr_ListOfAllPageEntries = 0x329927C4;

addr_box1slot1 = 0x33015AB0;

addr_currentScreen = 0x006A610A;

addr_pokemonToFind = 0x32992180;
addr_pokemonToFindGender = 0x32992184;
addr_pokemonToFindLevel = 0x32992188;

val_PlazaScreen = 0x00;
val_Quit_SeekScreen = 0x3F2B;
val_SearchScreen = 0x412A;
val_WhatPkmnScreen = 0x1040;
val_GTSListScreen = 0x4180;
val_BoxScreen = 0x4120;
val_system = 0x1C848;
val_duringTrade = 0x3FD5;
}

}

public async Task<int> RunBot()
Expand All @@ -158,7 +213,7 @@ public async Task<int> RunBot()
int panicAttempts = 0;
while (!botstop)
{
if(botState != (int)gtsbotstates.panic)
if (botState != (int)gtsbotstates.panic)
{
panicAttempts = 0;
}
Expand Down Expand Up @@ -281,7 +336,8 @@ public async Task<int> RunBot()
if (searchDirection == SEARCHDIRECTION_FROMBACK || searchDirection == SEARCHDIRECTION_FROMBACKFIRSTPAGEONLY)
{
await Program.helper.waitNTRread(addr_PageEndStartRecord);
}else
}
else
{
await Program.helper.waitNTRread(addr_PageStartStartRecord);
}
Expand Down Expand Up @@ -342,7 +398,7 @@ public async Task<int> RunBot()
string subregion = "-";
Program.f1.regions.TryGetValue(subRegionIndex, out subregion);
int ipage = Convert.ToInt32(Math.Floor(startIndex / 100.0)) + 1;
if (useLedySync && !Program.f1.banlist.Contains(szFC) && canThisTrade(principal, consoleName, szTrainerName, country, subregion, Program.PKTable.Species7[dexnumber - 1], szFC, ipage +"", (i-1)+""))
if (useLedySync && !Program.f1.banlist.Contains(szFC) && canThisTrade(principal, consoleName, szTrainerName, country, subregion, Program.PKTable.Species7[dexnumber - 1], szFC, ipage + "", (i - 1) + ""))
{
Program.f1.ChangeStatus("Found a pokemon to trade");
tradeIndex = i - 1;
Expand Down Expand Up @@ -565,7 +621,7 @@ public async Task<int> RunBot()
//still in GTS list screen
//write index we want to trade
int page = Convert.ToInt32(Math.Floor(startIndex / 100.0)) + 1;
Program.f1.ChangeStatus("Trading pokemon on page "+ page + " index " + tradeIndex +"");
Program.f1.ChangeStatus("Trading pokemon on page " + page + " index " + tradeIndex + "");
waitTaskbool = Program.helper.waitNTRwrite(addr_PageCurrentView, BitConverter.GetBytes(tradeIndex), iPID);
if (await waitTaskbool)
{
Expand Down Expand Up @@ -596,12 +652,12 @@ public async Task<int> RunBot()
{
details.Item6.Add(BitConverter.ToInt32(principal, 0));
}
Program.f1.AppendListViewItem(szTrainerName, szNickname, country, subregion, Program.PKTable.Species7[dexnumber - 1], szFC, page+"", tradeIndex + "");
Program.f1.AppendListViewItem(szTrainerName, szNickname, country, subregion, Program.PKTable.Species7[dexnumber - 1], szFC, page + "", tradeIndex + "");
//Inject the Pokemon to box1slot1
Program.scriptHelper.write(addr_box1slot1, cloneshort, iPID);
//spam a to trade pokemon
Program.helper.quickbuton(Program.PKTable.keyA, commandtime);
await Task.Delay(commandtime + delaytime + 2500 +o3dswaittime);
await Task.Delay(commandtime + delaytime + 2500 + o3dswaittime);
Program.helper.quickbuton(Program.PKTable.keyA, commandtime);
await Task.Delay(commandtime + delaytime);
Program.helper.quickbuton(Program.PKTable.keyA, commandtime);
Expand Down Expand Up @@ -779,7 +835,7 @@ public async Task<int> RunBot()
}
else
{
if(panicAttempts == 0)
if (panicAttempts == 0)
{
panicAttempts++;
botState = (int)gtsbotstates.panic;
Expand All @@ -797,7 +853,7 @@ public async Task<int> RunBot()
break;
}
}
if(this.serverEndPoint != null)
if (this.serverEndPoint != null)
{
client.Close();
}
Expand Down
5 changes: 2 additions & 3 deletions Ledybot/Ledybot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@
<ApplicationIcon>165Ledyba.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
Expand Down
2 changes: 1 addition & 1 deletion Ledybot/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" />
</packages>

5 comments on commit e12ef1e

@Bappsack
Copy link
Contributor

@Bappsack Bappsack commented on e12ef1e Dec 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

holy moly u was quick, can u tell me to find the block data for Start,End & Total?
and u forgot the EggOff for the Eggbot.

@SteveCookTU
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did? And I dumped one page of results, looked at the pointer of the "previous" list entry of the first block in the list and the pointer of the "next" list entry of the last block and it points to the index which has the start and end to be able to start the cycle over again.

@Bappsack
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i mean in the actuall EggBot.cs, for the Button "Egg always available".
Thats pretty neat, i got lost on the hex editor lmao.

@SteveCookTU
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take it as a compliment haha, I have an eye for patterns. If you know pokeCalcNTR, I was the one to discover the key to the whole plugin just build scrolling through it. Found something a script couldn't find.

@Bappsack
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome dude, one last Question, what re u using for collecting addresses? im using a simple CTRPF plugin lmao.
oh, i sended u a friend request on Discord.

Please sign in to comment.