Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0x19 MessageBox #15

Closed
RElesgoe opened this issue May 6, 2014 · 13 comments
Closed

0x19 MessageBox #15

RElesgoe opened this issue May 6, 2014 · 13 comments

Comments

@RElesgoe
Copy link
Member

RElesgoe commented May 6, 2014

image
Successful implementation of packet 0x19 for MessageBox

//packet.h
t_server_messagebox         server_messagebox;
//packet.cpp
case SERVER_MESSAGEBOX:
    return "SERVER_MESSAGEBOX";
//bnetprotocol.h
#define SERVER_MESSAGEBOX 0x19ff
    typedef struct
    {
        t_bnet_header h;
        bn_int        style;
        /* Text */
        /* Caption */
    } PACKED_ATTR() t_server_messagebox;
#define SERVER_MESSAGEBOX_OK    0x00000000
#define SERVER_MESSAGEBOX_OK_CANCEL 0x00000001
//Example code:
t_packet *rpacket;

if ((rpacket = packet_create(packet_class_bnet)))
{
    packet_set_size(rpacket, sizeof(t_server_messagebox));
    packet_set_type(rpacket, SERVER_MESSAGEBOX);
    bn_int_set(&rpacket->u.server_messagebox.style, SERVER_MESSAGEBOX_OK);
    packet_append_string(rpacket, "Text");
    packet_append_string(rpacket, "");
    conn_push_outqueue(c, rpacket);
    packet_del_ref(rpacket);
}

return 0;

In bn_int_set(&rpacket->u.server_messagebox.style, SERVER_MESSAGEBOX_OK);
SERVER_MESSAGEBOX_OK creates an Ok button while SERVER_MESSAGEBOX_OK_CANCEL creates an Ok and Cancel button for the client.
image
There is no purpose in having both Ok and Cancel buttons because the server will not know which button the user has pressed(and from my testing, you can ignore the messagebox and click other buttons such as Join and Create) so I've hardcoded SERVER_MESSAGEBOX_OK as the value.

@RElesgoe RElesgoe changed the title Messagebox 0x19 MessageBox May 6, 2014
This was referenced May 6, 2014
@HarpyWar
Copy link
Member

HarpyWar commented May 6, 2014

Great!
MessageBox is modal in full screen mode, and user can't interact with other elements while message is visible. But it's broken in window mode of Starcraft.

@RElesgoe
Copy link
Member Author

RElesgoe commented May 6, 2014

Can you check if you can see the Caption field in WC3 and D2. I don't believe that SC supports the Caption field considering that there's no space for it

@carlbennett
Copy link
Collaborator

In regards to the 0x19 SID_MESSAGEBOX packet, I believe I can be of some help here. It is indeed true that the packet structure mimics that of the WinAPI MessageBox (http://msdn.microsoft.com/en-us/library/windows/desktop/ms645505(v=vs.85).aspx) and therefore can be passed directly to it.

The way Starcraft works, at least as far as I remember, is it will pass the packet directly to the WinAPI MessageBox function. It will then catch any MessageBox message sent in the message queue (read: http://msdn.microsoft.com/en-us/library/windows/desktop/ms632590(v=vs.85).aspx) and pass it to its own handler. Its handler will present that modal that @HarpyWar talked about. However, in catching this MessageBox message itself rather than letting Windows handle it, it also means it's responsible for what gets displayed to the user and how. One of the things that it ignores is that Caption field, and it won't relay button clicks back to Battle.net either.

If I still remember correctly, Battle.net will simply send Battle.net as the caption, regardless of the message Text field and its style.

Also, windowed mode was never official from Blizzard, so it's likely that the windowed mode hack you're using isn't handling native Windows modal dialogs properly (that is what it is after all, just with a different user design).

Here's some more reading on the WM_INITDIALOG which I am not sure if Starcraft uses or not, but it's useful to know: http://msdn.microsoft.com/en-us/library/windows/desktop/ms645428(v=vs.85).aspx

@RElesgoe
Copy link
Member Author

Ok the code is ready to be committed now

@RElesgoe
Copy link
Member Author

I have an idea, maybe wrap this messagebox code inside a function, something like MessageBox(caption, text);
The caption parameter will actually be part of the message but with a newline appended after it so that it'll always be at the top of the message.

@HarpyWar
Copy link
Member

@Jailout2000, thanks for the research. It appears that all other games have a similar messagebox implementation - there is also no caption.

@xboi209, I will add your code soon, after merge with a code from another branch. Now it is not very convenient to switch between branches for me.
Caption does not really provide useful information in this case. The command will be complicated, like /msgbox caption "text"; user can do the same thing using \n symbol: /msgbox caption\n\ntext.

@HarpyWar
Copy link
Member

It works fine in Starcraft, Diablo 1, Warcraft 2.

But it doesn't work in Warcraft 3 and Diablo 2 :(.
Nothing happens with message style "OK". User connection immediately destroyed in Warcraft 3 when a message style is "OKCANCEL".
It seems somebody tried and can't get it working too http://forum.valhallalegends.com/index.php/topic,18242.msg184928.html

@HarpyWar
Copy link
Member

I have done a lot of testing and have found next patterns for message box.

  1. Simple messagebox shows when text in bounds of a small window.
    For example: wwwwwwwwwwwwwwwwww(19) and aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(30) will show a simple messagebox. But if we add one more symbol for each then it will show messagebox with a caption.
    simple 2014-05-24 20 41 06
    complex 2014-05-24 20 38 51
  2. Message box with a caption shows when text in bounds of a large window.
    For example: aaaaaaaaaaaaaaaaaaaaaaaaawwadwwadawdawdawdwadawdaa(50) and iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii(115). One more symbol will show normal message box from Windows (!!!).
    max_width
    max_width 2
  3. There are all options work with uType of Windows messagebox http://msdn.microsoft.com/en-us/library/windows/desktop/ms645505(v=vs.85).aspx. This parameter can be a combination of flags.
    For example: 0x00000100 | 0x00000003 | 0x00000020 applies flags MB_DEFBUTTON2, MB_YESNOCANCEL and MB_ICONQUESTION
    2014-05-24 20 43 25
  4. Starcraft Battle.net interface has a chatbox that is always on top if active. Because of that any messagebox from the server is hidden when user clicks on a chatbox area (initially @xboi209 talked about).
    click to view animation
    I'm not sure, but may be there is a special flag that makes it real modal, like messagebox from "Whisper" button?
  5. We can send a lot of Windows messageboxes and they will spawn many times.
    But internal messagebox in game is replaced by the latest.

@HarpyWar
Copy link
Member

I have add command /alert <messagebox>. There is additional line *************************** and author at the end of the text to extend messagebox to large version with a caption.

Even if user loses focus he can return it by click on visible part of the caption.
2014-05-24 19 39 20
2014-05-24 20 51 22

@RElesgoe
Copy link
Member Author

Nice job, earlier I expected text to just cut off if there were too many.

@dotabattle
Copy link

what is the program used by HarpyWar in this SS ?

@RElesgoe
Copy link
Member Author

StarCraft: Brood War

@HarpyWar HarpyWar added this to the PvPGN 2.0 milestone Jul 16, 2014
RElesgoe added a commit that referenced this issue Aug 24, 2016
@xpeh-owns
Copy link

The way Starcraft works, at least as far as I remember, is it will pass the packet directly to the WinAPI MessageBox function.
There was a bug in windows in which messagebox with certaing parameters caused bluescreen :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants