• Welcome to Valhalla Legends Archive.
 

Question about sockets..

Started by iago, August 01, 2003, 07:12 AM

Previous topic - Next topic

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?
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


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.
QuoteAnyone attempting to generate random numbers by deterministic means is, of course, living in a state of sin
John Vo

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.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Adron

Quote from: iago on August 01, 2003, 07:12 AM
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?

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.



Skywing

#4
Quote from: Adron on August 01, 2003, 09:25 AM
Quote from: iago on August 01, 2003, 07:12 AM
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?

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.



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.

iago

Quote from: Adron on August 01, 2003, 09:25 AM
Quote from: iago on August 01, 2003, 07:12 AM
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?

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.

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!
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


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 :)
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


UserLoser

#7
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.

__asm
{
    push 0
    ret
}

iago

Quote from: UserLoser on August 01, 2003, 10:07 PM
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.

__asm
{
    push 0
    ret
}


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.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Skywing

#9
Quote from: iago on August 01, 2003, 09:38 PM
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 :)
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.

TheMinistered

#10
You could try making a Proxy/Stub DLL for winsock and see if you can do anything with that.