Valhalla Legends Forums Archive | General Programming | Question about sockets..

AuthorMessageTime
iago
Ok, here's a quick background:
I was playing diablo ii, it crashed (well, locked up) during a combat, and I got killed.

Now there are 3 solutions to stop this from happening again:
1. Be smart, stop playing on hardcore (har!)
2. Suffer (Like no good CS student should do)
3. Fix it..? Read on....

Now, I was wondering if it's possible to access a socket that another program has open. I would like to be able to send an emergency "Exit Game" if this ever happens again. Is it possible send data on another process's TCP socket?
August 1, 2003, 12:12 PM
j0k3r
You play hardcore? Useast? Nice let's play sometime... Never stop playing hardcore, if your not gunna play hardcore don't bother playing >_< Softcore is messed up too bad.

Diablo 2 doesn't crash regularly unless you have a horrible computer (my p1 200mhz ran it fine)... Just try reinstalling. If that doesn't work then try whatever someone else recommends with your socket idea.
August 1, 2003, 12:43 PM
iago
It only happened once, it was probably a horrible fluke.

And I tend to just play with a single friend, at his house, nobody else. I don't like having more than two people in the game, it just bothers me.
August 1, 2003, 1:40 PM
Adron
[quote author=iago link=board=5;threadid=2164;start=0#msg16688 date=1059739926]
Now, I was wondering if it's possible to access a socket that another program has open. I would like to be able to send an emergency "Exit Game" if this ever happens again. Is it possible send data on another process's TCP socket?
[/quote]

Look at duplicating the socket (handle) into your other process. DuplicateHandleEx or something like that. It might be easier though to write something that loads inside D2 to do this. Otherwise I'm not sure how you'll detect a hung game?

One idea would be an event that is set on every frame displayed and a thread waiting for it with a 1 second or so timeout to verify that the game is working right.. If event stops being set, that thread can take some action to save you.


August 1, 2003, 2:25 PM
Skywing
[quote author=Adron link=board=5;threadid=2164;start=0#msg16700 date=1059747912]
[quote author=iago link=board=5;threadid=2164;start=0#msg16688 date=1059739926]
Now, I was wondering if it's possible to access a socket that another program has open. I would like to be able to send an emergency "Exit Game" if this ever happens again. Is it possible send data on another process's TCP socket?
[/quote]

Look at duplicating the socket (handle) into your other process. DuplicateHandleEx or something like that. It might be easier though to write something that loads inside D2 to do this. Otherwise I'm not sure how you'll detect a hung game?

One idea would be an event that is set on every frame displayed and a thread waiting for it with a 1 second or so timeout to verify that the game is working right.. If event stops being set, that thread can take some action to save you.



[/quote]
Winsock provides a special function for this - WSADuplicateSocket. I think you need to use this instead of DuplicateHandle(Ex) because Winsock maintains some state information about socket handles in user mode. At least, I'm sure that it maintains it's own list of socket handles (which is why if you CloseHandle on a socket, WSACleanup will break, since it tries to operate on a closed handle which it didn't know was closed).

You might be able to use SendMessageTimeout with WM_NULL or something similar to detect a lockup, if it involves freezing the message loop.
August 1, 2003, 7:04 PM
iago
[quote author=Adron link=board=5;threadid=2164;start=0#msg16700 date=1059747912]
[quote author=iago link=board=5;threadid=2164;start=0#msg16688 date=1059739926]
Now, I was wondering if it's possible to access a socket that another program has open. I would like to be able to send an emergency "Exit Game" if this ever happens again. Is it possible send data on another process's TCP socket?
[/quote]

Look at duplicating the socket (handle) into your other process. DuplicateHandleEx or something like that. It might be easier though to write something that loads inside D2 to do this. Otherwise I'm not sure how you'll detect a hung game?

One idea would be an event that is set on every frame displayed and a thread waiting for it with a 1 second or so timeout to verify that the game is working right.. If event stops being set, that thread can take some action to save you.
[/quote]

I already to this for low health, so it wouldn't be too difficult...

Both of those ideas sound like they have potential, I'll have to put some more thought into it after work.

Thanks!
August 2, 2003, 2:27 AM
iago
Hmm, if the process crashes, or if ExitProcess() is called, would I have a chance to recover before the process closes? Does dll_main get called with dwReason = DLL_PROCESS_DETACH before the process shuts down? I could test it myself, but it's easier to ask since I have to go to work right away :)
August 2, 2003, 2:38 AM
UserLoser
What about D2HackIt? Since that attaches it's self to Diablo's process, I believe you can send packets using it. Out of D2HackIt's source code, there's a command .crash, which immediately exit's D2. I don't know if this has any use to you at all, but here's the code for it. :P Also I don't know any ASM either.
[code]
__asm
{
push 0
ret
}
[/code]
August 2, 2003, 3:07 AM
iago
[quote author=UserLoser link=board=5;threadid=2164;start=0#msg16768 date=1059793646]
What about D2HackIt? Since that attaches it's self to Diablo's process, I believe you can send packets using it. Out of D2HackIt's source code, there's a command .crash, which immediately exit's D2. I don't know if this has any use to you at all, but here's the code for it. :P Also I don't know any ASM either.
[code]
__asm
{
push 0
ret
}
[/code]
[/quote]

Thanks, but I wrote my own plugin which lets me send packets to either the realm or chat server, and that's a really dumb way to crash.

I would have done this:
__asm
{
int 03
ret
}

that would crash immediately, and if it's being debugged it would be caught and you could debug/resume the program without screwing up the stack.
August 2, 2003, 3:24 AM
Skywing
[quote author=iago link=board=5;threadid=2164;start=0#msg16764 date=1059791935]
Hmm, if the process crashes, or if ExitProcess() is called, would I have a chance to recover before the process closes? Does dll_main get called with dwReason = DLL_PROCESS_DETACH before the process shuts down? I could test it myself, but it's easier to ask since I have to go to work right away :)
[/quote]
DLL callouts are only processed during normal termination. If it crashes or otherwise gets NtTerminateProcess'd, you won't have a chance to clean up (unless, of course, you're a kernel mode driver). I'd recommend waiting on the process handle in a different process, as this will guarantee that it'll work even if D2 crashes.
August 2, 2003, 11:27 PM
TheMinistered
You could try making a Proxy/Stub DLL for winsock and see if you can do anything with that.
August 3, 2003, 5:09 PM

Search