BOOL OOG_CreateCharacter(char* szCharacter, int type, bool hardcore, bool ladder) { if(OOG_GetLocation() != OOG_CHAR_SELECT || strlen(szCharacter) > 15 || type > 6 || type < 0) return FALSE; // click the create character button Control* ctrl = findControl(CONTROL_BUTTON, (char*)NULL, -1, 33, 528, 168, 60); if(ctrl) clickControl(ctrl); // TODO: replace with real time checking code int i = 0; while((OOG_GetLocation() != OOG_CHARACTER_CREATE) && i++ < 30) Sleep(100); int locs[7][5] = { {100, 337, 80, 330, 4011}, // amazon {626, 353, 600, 300, 4010}, // sorceress {301, 333, 300, 330, 4009}, // necromancer {521, 339, 500, 330, 4008}, // paladin {400, 330, 390, 330, 4007}, // barbarian {720, 370, 700, 370, 4012}, // druid {232, 364, 200, 300, 4013}, // assassin }; ctrl = findControl(CONTROL_IMAGE, (char*)NULL, -1, locs[type][0], locs[type][1], 88, 184); if(ctrl) { clickControl(ctrl, locs[type][2], locs[type][3]); Sleep(500); clickControl(ctrl, locs[type][2], locs[type][3]); } // verify that the correct type got selected ctrl = findControl(CONTROL_TEXTBOX, (char*)NULL, -1, 0, 180, 800, 100); wchar_t* name = D2LANG_GetLocaleText((WORD)locs[type][4]); if(_wcsicmp(name, ctrl->pFirstText->wText[0]) != 0) return FALSE; // something bad happened? // set the name // ctrl = findControl(); // still need to find the name editbox, set the name, and click the various // checkboxes and the ok button return FALSE; }
bool OOG_JoinGame(const char* name, const char* pass) { if(ClientState() != ClientStateMenu) return FALSE; // reject name/password combinations over 15 characters if(strlen(name) > 15 || strlen(pass) > 15) return FALSE; Control* pControl = NULL; // Battle.net/open lobby/chat area if(!(OOG_GetLocation() == OOG_LOBBY || OOG_GetLocation() == OOG_CHAT || OOG_GetLocation() == OOG_JOIN)) return FALSE; // JOIN button if (OOG_GetLocation() != OOG_JOIN) { pControl = findControl(CONTROL_BUTTON, (char *)NULL, -1, 652,469,120,20); if(!pControl || !clickControl(pControl)) return FALSE; Sleep(100); } if(OOG_GetLocation() == OOG_JOIN) { // Game name edit box if(name) SetControlText(findControl(1, (char *)NULL, -1, 432,148,155,20), name); else return FALSE; // Password edit box if(pass) SetControlText(findControl(1, (char *)NULL, -1, 606,148,155,20), pass); else return FALSE; // Join Game Button pControl = findControl(CONTROL_BUTTON, (char *)NULL, -1, 594,433,172,32); if(!pControl || !clickControl(pControl)) return FALSE; } return TRUE; }
bool OOG_CreateGame(const wchar_t* name, const wchar_t* pass, int difficulty) { if (ClientState() != ClientStateMenu) return FALSE; // reject name/password combinations over 15 characters if (!name || !pass || wcslen(name) > 15 || wcslen(pass) > 15) return FALSE; Control* pControl = NULL; // Battle.net/open game creation OOG_Location loc = OOG_GetLocation(); if (!(loc == OOG_LOBBY || loc == OOG_CHAT || loc == OOG_DIFFICULTY || loc == OOG_CREATE)) return FALSE; if (loc == OOG_DIFFICULTY) { // just click the difficulty button Control *normal = findControl(CONTROL_BUTTON, (const wchar_t*)NULL, -1, 264, 297, 272, 35), *nightmare = findControl(CONTROL_BUTTON, (const wchar_t*)NULL, -1, 264, 340, 272, 35), *hell = findControl(CONTROL_BUTTON, (const wchar_t*)NULL, -1, 264, 383, 272, 35); switch (difficulty) { case 0: // normal button if (normal->dwDisabled != 0x0d || !clickControl(normal)) return FALSE; break; case 1: // nightmare button if (nightmare->dwDisabled != 0x0d || !clickControl(nightmare)) return FALSE; break; case 2: // hell button if (hell->dwDisabled != 0x0d || !clickControl(hell)) return FALSE; break; case 3: // hardest difficulty available if (hell->dwDisabled != 0x0d) { if (!clickControl(hell)) return FALSE; } else if (nightmare->dwDisabled != 0x0d) { if (!clickControl(nightmare)) return FALSE; } else if (normal->dwDisabled != 0x0d) { if (!clickControl(normal)) return FALSE; } break; default: return FALSE; } } else { // Create button if (loc != OOG_CREATE) { pControl = findControl(CONTROL_BUTTON, (const wchar_t*)NULL, -1, 533, 469, 120, 20); if (!pControl || !clickControl(pControl)) return FALSE; Sleep(100); } if (OOG_GetLocation() == OOG_CREATE) { // Game name edit box if (name) SetControlText(findControl(1, (const wchar_t*)NULL, -1, 432, 162, 158, 20), name); else return FALSE; Sleep(100); // Password edit box if (pass) SetControlText(findControl(1, (const wchar_t*)NULL, -1, 432, 217, 158, 20), pass); else return FALSE; Sleep(100); Control *normal = findControl(CONTROL_BUTTON, (const wchar_t*)NULL, -1, 430, 381, 16, 16), *nightmare = findControl(CONTROL_BUTTON, (const wchar_t*)NULL, -1, 555, 381, 16, 16), *hell = findControl(CONTROL_BUTTON, (const wchar_t*)NULL, -1, 698, 381, 16, 16); switch (difficulty) { case 0: // normal button if (normal->dwDisabled == 0x4 || !clickControl(normal)) return FALSE; break; case 1: // nightmare button if (nightmare->dwDisabled == 0x4 || !clickControl(nightmare)) return FALSE; break; case 2: // hell button if (hell->dwDisabled == 0x4 || !clickControl(hell)) return FALSE; break; case 3: // hardest difficulty available if (hell->dwDisabled != 0x4) { if (!clickControl(hell)) return FALSE; } else if (nightmare->dwDisabled != 0x4) { if (!clickControl(nightmare)) return FALSE; } else if (normal->dwDisabled != 0x4) { if (!clickControl(normal)) return FALSE; } break; default: return FALSE; } // Create Game Button pControl = findControl(CONTROL_BUTTON, (const wchar_t*)NULL, -1, 594, 433, 172, 32); if (!pControl || !clickControl(pControl)) return FALSE; } } return TRUE; }
DWORD Profile::login(char** error) { bool loginComplete = FALSE, skippedToBnet = TRUE; int location = 0; char* errorMsg = ""; Control* pControl = NULL; unsigned int timeout = 0; /* clickedOnce is needed because, when in OOG_OTHER_MULTIPLAYER the clickControl () is done twice and the second time it is failing because the button is not there anymore. */ int clickedOnce = false; Vars.bBlockKeys = Vars.bBlockMouse = TRUE; while(!loginComplete) { location = OOG_GetLocation(); switch(location) { case OOG_D2SPLASH: clickControl(*p_D2WIN_FirstControl); break; case OOG_CHAR_SELECT: if (!OOG_SelectCharacter(charname)) errorMsg = "Invalid character name"; break; case OOG_MAIN_MENU: if(type == PROFILETYPE_SINGLEPLAYER) if(!clickControl(findControl(6, (char *)NULL, -1, 264,324,272,35))) errorMsg = "Failed to click the Single button?"; if(type == PROFILETYPE_BATTLENET) { OOG_SelectGateway(gateway, 256); if(!clickControl(findControl(6, (char *)NULL, -1, 264, 366, 272, 35))) errorMsg = "Failed to click the 'Battle.net' button?"; } if(isOtherMP(type)) { if(!clickControl(findControl(6, (char *)NULL, -1, 264, 433, 272, 35))) errorMsg = "Failed to click the 'Other Multiplayer' button?"; else skippedToBnet = FALSE; } break; case OOG_LOGIN: if((type == PROFILETYPE_SINGLEPLAYER || isOtherMP(type)) && skippedToBnet) { if(!clickControl(findControl(6, "EXIT", -1,33,572,128,35))) errorMsg = "Failed to click the exit button?"; break; } pControl = findControl(1, (char *)NULL, -1, 322, 342, 162, 19); if(pControl) SetControlText(pControl, username); else errorMsg = "Failed to set the 'Username' text-edit box."; // Password text-edit box pControl = findControl(1, (char *)NULL, -1, 322, 396, 162, 19); if(pControl) SetControlText(pControl, password); else errorMsg = "Failed to set the 'Password' text-edit box."; pControl = findControl(6, (char *)NULL, -1, 264, 484, 272, 35); if(pControl) if(!clickControl(pControl)) errorMsg ="Failed to click the 'Log in' button?"; timeout++; break; case OOG_DIFFICULTY: switch(diff) { case 0: // normal button if(!clickControl(findControl(6, (char *)NULL, -1, 264, 297, 272, 35))) errorMsg ="Failed to click the 'Normal Difficulty' button?"; break; case 1: // nightmare button if(!clickControl(findControl(6, (char *)NULL, -1, 264, 340, 272, 35))) errorMsg = "Failed to click the 'Nightmare Difficulty' button?"; break; case 2: // hell button if(!clickControl(findControl(6, (char *)NULL, -1, 264, 383, 272, 35))) errorMsg = "Failed to click the 'Hell Difficulty' button?"; break; default: errorMsg = "Invalid single player difficulty level specified!"; break; } case OOG_OTHER_MULTIPLAYER: // Open Battle.net if (type == PROFILETYPE_OPEN_BATTLENET) if(!clickControl(findControl(6, (char *)NULL, -1, 264, 310, 272, 35))) errorMsg = "Failed to click the 'Open Battle.net' button?"; // TCP/IP Game if (isTcpIp(type)) if(!clickControl(findControl(6, (char *)NULL, -1, 264,350,272,35)) && !clickedOnce) errorMsg = "Failed to click the 'TCP/IP Game' button?"; else clickedOnce = true; break; case OOG_TCP_IP: if (type == PROFILETYPE_TCPIP_HOST) if(!clickControl(findControl(6, (char *)NULL, -1,265,206,272,35))) errorMsg = "Failed to click the 'Host Game' button?"; if (type == PROFILETYPE_TCPIP_JOIN) if(!clickControl(findControl(6, (char *)NULL, -1,265,264,272,35))) errorMsg = "Failed to click the 'Join Game' button?"; break; case OOG_ENTER_IP_ADDRESS: if (_strcmpi(ip, "")) { pControl = findControl(1, (char *)NULL, -1, 300, 268, -1, -1); if(pControl) { SetControlText(pControl, ip); // Click the OK button if(!clickControl(findControl(6, (char *)NULL, -1, 421, 337, 96, 32))) { errorMsg = "Failed to click the OK button"; } } else errorMsg = "Failed to find the 'Host IP Address' text-edit box."; } else errorMsg = "Could not get the IP address from the profile in the d2bs.ini file."; break; case OOG_MAIN_MENU_CONNECTING: case OOG_CHARACTER_SELECT_PLEASE_WAIT: case OOG_PLEASE_WAIT: case OOG_GATEWAY: case OOG_CHARACTER_SELECT_NO_CHARS: case OOG_CONNECTING: case OOG_NONE: timeout++; break; case OOG_LOBBY: case OOG_INLINE: case OOG_CHAT: case OOG_CREATE: case OOG_JOIN: case OOG_LADDER: case OOG_CHANNEL: case OOG_GAME_EXIST: case OOG_GAME_DOES_NOT_EXIST: loginComplete=TRUE; break; case OOG_UNABLE_TO_CONNECT: errorMsg = "Unable to connect"; break; case OOG_CDKEY_IN_USE: errorMsg = "CD-Key in use"; break; case OOG_LOGIN_ERROR: errorMsg = "Bad account or password"; break; case OOG_REALM_DOWN: errorMsg = "Realm Down"; break; default: errorMsg = "Unhandled login location"; break; } if(_strcmpi(errorMsg, "")) { Vars.bBlockKeys = Vars.bBlockMouse = FALSE; *error = errorMsg; return 2; } if((timeout*100) > maxLoginTime) { Vars.bBlockKeys = Vars.bBlockMouse = FALSE; *error = "login time out"; return 1; } if(ClientState() == ClientStateInGame) loginComplete = TRUE; Sleep(100); } Vars.bBlockKeys = Vars.bBlockMouse = FALSE; return 0; }