Results 1 to 3 of 3

Thread: Sending Commands Into GameConsole and Reading Output.

  1. #1
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,603

    Default Sending Commands Into GameConsole and Reading Output.

    Hi,
    These are the functions I used to send and read from the console.
    Sending [UTF-16]:

    BOOL CALLBACK EnumChildSendCommandProc(HWND hwnd,LPARAM lParam);

    HWND MohaaConsole = FindWindowW(0, L"MOHAA Console"); //Find the console windows
    EnumChildWindows(MohaaConsole, EnumChildSendCommandProc, (LPARAM)"say This is a test cmd !");//loop through it's children.

    BOOL CALLBACK EnumChildSendCommandProc(HWND hwnd,LPARAM lParam) //Find the text editor for input.
    {
    wchar_t className[1024];
    GetClassNameW(hwnd,className,sizeof(className));
    if (wcscmp(className , L"Edit")) //If it's not a text editor we don't need it.
    {
    return true;
    }
    if (ES_READONLY & GetWindowLongW(hwnd,GWL_STYLE))
    {
    return true;
    }
    //At this point we found a text editor that isn't readonly.
    //Which is what we're searching for.
    SendMessageW(hwnd,WM_SETTEXT,0,lParam);//Send the command.
    SendMessageW(hwnd,WM_CHAR,VK_RETURN,0);//This is like pressing enter after you type something in the window.
    return false;
    }


    Sending [ANSI]:

    BOOL CALLBACK EnumChildSendCommandProc(HWND hwnd,LPARAM lParam);

    HWND MohaaConsole = FindWindowA(0, "MOHAA Console"); //Find the console windows
    EnumChildWindows(MohaaConsole, EnumChildSendCommandProc, (LPARAM)"say This is a test cmd !");//loop through it's children.

    BOOL CALLBACK EnumChildSendCommandProc(HWND hwnd,LPARAM lParam) //Find the text editor for input.
    {
    char className[1024];
    GetClassNameA(hwnd,className,sizeof(className));
    if (strcmp(className , "Edit")) //If it's not a text editor we don't need it.
    {
    return true;
    }
    if (ES_READONLY & GetWindowLongA(hwnd,GWL_STYLE))
    {
    return true;
    }
    //At this point we found a text editor that isn't readonly.
    //Which is what we're searching for.
    SendMessageA(hwnd,WM_SETTEXT,0,lParam); //Send the command.
    SendMessageA(hwnd,WM_CHAR,VK_RETURN,0); //This is like pressing enter after you type something in the window.
    return false;
    }


    Reading [UTF-16]:

    BOOL CALLBACK EnumChildSendCommandProc(HWND hwnd,LPARAM lParam);

    wchar_t buff[8192];

    HWND MohaaConsole = FindWindowW(0, L"MOHAA Console"); //Find the console windows
    EnumChildWindows(MohaaConsole, EnumChildSendCommandProc, (LPARAM)buff);//loop through it's children.
    MessageBoxW(NULL , buff , NULL , NULL);

    BOOL CALLBACK EnumChildSendCommandProc(HWND hwnd,LPARAM lParam) //find the text editor and read from it.
    {
    wchar_t className[1024];
    GetClassNameW(hwnd,className,1024);
    if (wcscmp(className , L"Edit"))//If it's not a text editor we don't need it.
    {
    return true;
    }
    if (ES_READONLY & GetWindowLongW(hwnd,GWL_STYLE)) //If it's read only then it's our guy.
    {
    SendMessageW(hwnd,WM_GETTEXT,8192,lParam);
    return false;
    }
    return true;
    }


    Reading [ANSI]:

    BOOL CALLBACK EnumChildSendCommandProc(HWND hwnd,LPARAM lParam);

    char buff[8192];

    HWND MohaaConsole = FindWindowA(0, "MOHAA Console"); //Find the console windows
    EnumChildWindows(MohaaConsole, EnumChildSendCommandProc, (LPARAM)buff);//loop through it's children.
    MessageBoxA(NULL , buff , NULL , NULL);

    BOOL CALLBACK EnumChildSendCommandProc(HWND hwnd,LPARAM lParam) //find the text editor and read from it.
    {
    char className[1024];
    GetClassNameA(hwnd,className,1024);
    if (strcmp(className , "Edit"))//If it's not a text editor we don't need it.
    {
    return true;
    }
    if (ES_READONLY & GetWindowLongA(hwnd,GWL_STYLE)) //If it's read only then it's our guy.
    {
    SendMessageA(hwnd,WM_GETTEXT,8192,lParam);
    return false;
    }

    return true;
    }



    The main concept is to Find the Console of MOHAA With FindWindow().
    Next loop through it's children (buttons , text editors, etc) and find the text editor that is involved for input/output.
    Then send a message to read from/write to that text editor.

    This works with MOHAA , BT , SH , and all the server versions.Just replace the "MOHAA Console" with "MOHAAS Console" or "MOHAAB Console".

    Hope it helps .
    Last edited by RyBack; June 6th, 2016 at 07:48 PM.

  2. #2
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    Careful on the buffer overflow.
    Thanks for the share though!

  3. #3
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,603

    Default

    It wouldn't overflow cuz WM_GETTEXT message's wParam is the maximum number of characters to be copied, including the terminating null character.
    How would it overflow ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •