Alef/nocdkey – User

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 3: Line 3:
A fast way to setup MP missions is to run two ArmA games on the same computer. Let's call the first ''Editor'' and the second ''Client''.
A fast way to setup MP missions is to run two ArmA games on the same computer. Let's call the first ''Editor'' and the second ''Client''.
''Editor'' run the mission editor, selected clicking on ''Multiplayer -> New -> Edit/New''.
''Editor'' run the mission editor, selected clicking on ''Multiplayer -> New -> Edit/New''.
Client can now join it selecting Multiplayer -> LAN or Remote wiht IP 127.0.0.1. It will see Editor in edit mode.
''Client'' can now join it selecting ''Multiplayer -> LAN'' or ''Remote'' wiht IP ''127.0.0.1''. It will see ''Editor'' in edit mode.
As Editor click on preview to run the mission, a PBO is create on the fly (__cur_mp.pbo) for Client to be available.
As ''Editor'' clicks on ''Preview'' to run the mission, a PBO named <tt>__cur_mp.pbo</tt> is create on the fly for ''Client'' to be downloaded.
Both now enter the usual lobby and choose the slot they want. They play the mission, and when they leave back to the lobby, they can choose to run it again or go back. Editor in this case to the mission editor, Client to the multiplayer screen or 'Wait for host'.
Both now enter the usual lobby and choose the slot they want. They play the mission, and when they leave back to the lobby, they can choose to run it again or go back. ''Editor'' in this case to the mission editor, ''Client'' to the multiplayer or ''Wait for host'' screen.


In order to avoid to click the menus, command line arguments are available.
In order to avoid to click the menus, command line arguments are available.
For Editor<pre>
For ''Editor''<pre>
\ArmA\arma.exe  -host
\ArmA\arma.exe  -host
</pre>
</pre>
For Client<pre>
For ''Client''<pre>
\ArmA\arma.exe -connect=localhost
\ArmA\arma.exe -connect=localhost
</pre>
</pre>
It is suggested to add<pre>
I like to suggest adding<pre>
-window -nosplash -world=empty -nopause
-window -nosplash -world=empty -nopause
</pre>to speed up things and run safe from alt-tabbing.
</pre>to speed up things and run safe from alt-tabbing.


===Problems===
===Problems===
All of this above should works if ArmA doesn't check for duplicated CD keys. You maybe know that there is an option in server.cfg called kickduplicate, which if set to 0 allows the same CD key to join a MP game. The problem is that server.cfg, or better, the file you provide with -config, is read only if you run ArmA with -server or the dedicated <tt>arma_server.exe</tt> or <tt>server</tt> on Linux.
All of this above should works if ArmA doesn't check for duplicated CD keys, and you have a single operative system user and a single installation of ArmA. You maybe know that there is an option in [[server.cfg]] called [[server.cfg#Server_Options|kickduplicate]], which if set to 0 allows the same CD key to join a MP game. The problem is that server.cfg, or better, the file you provide with [[-config]], is only read if you run ArmA with [[ArmA:_Startup_Parameters#Network_Options|-server]] or the dedicated <tt>[[ArmA:_Dedicated_Server|arma_server.exe]]</tt> or <tt>server</tt> on [[ArmA:_Dedicated_Server#Linux_2|Linux]].
Because this check is done on the gamespy Internet service, if you drop your internet connection, everything works. But this could be a problem, because in editing you usually want to search some forums or other online resources.
Because this check is done online at gamespy, if you drop your internet connection, the check isn't done. But this could be a problem, because while editing or testing, you usually want to search some forums or other online resources.


===Solution===
===Solution===
The CD key check will be skipped at least if the name for the gamespy servers are not found, or resolved. It doesn't simply mean you can force a different IP, like 127.0.0.1, editing it in <tt>c:\windows\system32\drivers\etc\hosts</tt>.
The CD key check will be skipped at least if the name for the gamespy servers are not found, or resolved. It doesn't simply mean you can force a different IP, like ''127.0.0.1'', editing your <tt>c:\windows\system32\drivers\etc\hosts</tt>.


===ws2_32.dll===
===ws2_32.dll===
To connect to the Internet, like all the other programs on Windows, ArmA uses a DLL called <tt>ws2_32.dll</tt>, that is a file installed in <tt>c:\windows\system32</tt>. If you put another file with the same name in the ArmA installation directory, ArmA will use that instead of the Windows one. It is like the Armalib from Kegetys, which uses <tt>dsound.dll</tt> to inject custom code in the ArmA process address space. Or, worse, like some viruses/trojan/cheaters do.
To connect to the Internet, like all the other programs on Windows, ArmA uses a DLL called <tt>ws2_32.dll</tt>, that is a file installed in <tt>c:\windows\system32</tt>. If you put another file with the same name in the ArmA installation directory, ArmA will use that instead of the Windows one. It is the same like Armalib from Kegetys, which uses <tt>dsound.dll</tt> to inject custom code in the ArmA process address space.
I've modified a program found online (see the References below), that intercept the functions ArmA does to connect other computers. One of these functions is <tt>gethostbyname</tt>, which usually is used to obtain an internet address given a name, like www.ofpec.com returns 85.17.58.182. Now, if ArmA asks for hosts in <tt>gamespy.com</tt> domain, to check for duplicated CD keys, if the address it's found and valid, the check will happens. This function is enables only if you use <tt>-host</tt> and <tt>-nocdkey</tt>.
I've modified a program found online (see the [[#Links]] below), that intercept the functions ArmA does to connect other computers. One of these functions is <tt>[http://msdn.microsoft.com/en-us/library/ms738524(VS.85).aspx gethostbyname]</tt>, which is used to obtain an internet address given a name, like ''www.ofpec.com'' returns ''85.17.58.182''. Now, if ArmA asks for hosts in <tt>gamespy.com</tt> domain, to check for duplicated CD keys, if the address it's found and valid, the check will happens. This function is enables only if you use <tt>-host</tt> and <tt>-nocdkey</tt>. The server will get the message "No challenge value was received from the master server." when attempting to check for duplicated CD keys.
The DLL will intercept all of the network functions. All of them, apart the one above, add an overhead for this to work. This overhead consists of a single <tt>jmp</tt> instruction without stack management, which I suppose should at least be long as a single CPU cycle. So if you run a 3GHz CPU, the added delay should be 0,33 ns ([http://en.wikipedia.org/wiki/Nanosecond nanosecond], a billionth of second).
The DLL will intercept all of the network functions. All of them, apart the one above, add an overhead for this to work. This overhead consists of a single <tt>jmp</tt> instruction without stack management (nacked), which I suppose should at least be long as a single CPU cycle, or less. So if you run a 3GHz CPU, the added delay should be 0,33 ns ([http://en.wikipedia.org/wiki/Nanosecond nanosecond], a billionth of second).
 
==Legal==
'''I suppose''' this is something legally doable, because BI already provided the way to work without checking for duplicated CD keys. If BI doesn't want this, I'll remove any reference to this work and notify the reachable forums and mirrors.


==Links==
==Links==
[http://www.ofpec.com/forum/index.php?topic=32619.0 OFPEC beta]
* OFPEC beta [http://www.ofpec.com/forum/index.php?topic=32619.0 request]
[http://www.xfire.com/video/4d907/ Xfire video]
* Xfire [http://www.xfire.com/video/4d907/ video] showing a procure.
This is a file called ''ws2_32.dll'' to put in the same ''arma.exe'' directory, and get enabled using ''-nocdkey'' and ''-host'' arguments on the command line.
It will intercept the host name resolution for gamespy service, returning a "not found" answer. This is the same effect you can obtain disconnecting the network cable.


Need a crafted ''ws2_32.dll'', which returns ''WSAHOST_NOT_FOUND'' in ''gethostbyname()'' for ''armedass.master.gamespy.com'' or ''armedass.available.gamespy.com'' if -nocdkey is given on the server (-host) command line.
==Source==
<pre>
You get the full source in the distributed archive. This is the working code extracted from there:
Editor/Server:
\ArmA\arma.exe -window -nosplash -world=empty -nopause -host -nokey
 
Client:
\ArmA\arma.exe -window -nosplash -world=empty -nopause -connect=localhost
</pre>
 
The server will get the message "No challenge value was received from the master server."
 
Will post on OFPEC for beta, if someone interested, and on BI forum.
==How it works?==
<pre>
<pre>
struct hostent* FAR(__stdcall h_gethostbyname)(__in const char *name) {
struct hostent* FAR(__stdcall h_gethostbyname)(__in const char *name) {
Line 75: Line 65:
}
}
</pre>
</pre>
 
This was possible thanks to
References:
[http://forum.koaxia.com/index.php?PHPSESSID=8c74b13cfe75e2b293e4825c7e7985e5&topic=3099.0 this] and [http://www.codeguru.com/forum/archive/index.php/t-386875.html this].
http://forum.koaxia.com/index.php?PHPSESSID=8c74b13cfe75e2b293e4825c7e7985e5&topic=3099.0
http://www.codeguru.com/forum/archive/index.php/t-386875.html

Revision as of 15:55, 8 December 2008

nocdkey here doesn't mean you can play illegal copies with this plugin!

How to run 2 ArmA on the same PC

A fast way to setup MP missions is to run two ArmA games on the same computer. Let's call the first Editor and the second Client. Editor run the mission editor, selected clicking on Multiplayer -> New -> Edit/New. Client can now join it selecting Multiplayer -> LAN or Remote wiht IP 127.0.0.1. It will see Editor in edit mode. As Editor clicks on Preview to run the mission, a PBO named __cur_mp.pbo is create on the fly for Client to be downloaded. Both now enter the usual lobby and choose the slot they want. They play the mission, and when they leave back to the lobby, they can choose to run it again or go back. Editor in this case to the mission editor, Client to the multiplayer or Wait for host screen.

In order to avoid to click the menus, command line arguments are available.

For Editor

\ArmA\arma.exe  -host

For Client

\ArmA\arma.exe -connect=localhost

I like to suggest adding

-window -nosplash -world=empty -nopause

to speed up things and run safe from alt-tabbing.

Problems

All of this above should works if ArmA doesn't check for duplicated CD keys, and you have a single operative system user and a single installation of ArmA. You maybe know that there is an option in server.cfg called kickduplicate, which if set to 0 allows the same CD key to join a MP game. The problem is that server.cfg, or better, the file you provide with -config, is only read if you run ArmA with -server or the dedicated arma_server.exe or server on Linux. Because this check is done online at gamespy, if you drop your internet connection, the check isn't done. But this could be a problem, because while editing or testing, you usually want to search some forums or other online resources.

Solution

The CD key check will be skipped at least if the name for the gamespy servers are not found, or resolved. It doesn't simply mean you can force a different IP, like 127.0.0.1, editing your c:\windows\system32\drivers\etc\hosts.

ws2_32.dll

To connect to the Internet, like all the other programs on Windows, ArmA uses a DLL called ws2_32.dll, that is a file installed in c:\windows\system32. If you put another file with the same name in the ArmA installation directory, ArmA will use that instead of the Windows one. It is the same like Armalib from Kegetys, which uses dsound.dll to inject custom code in the ArmA process address space. I've modified a program found online (see the #Links below), that intercept the functions ArmA does to connect other computers. One of these functions is gethostbyname, which is used to obtain an internet address given a name, like www.ofpec.com returns 85.17.58.182. Now, if ArmA asks for hosts in gamespy.com domain, to check for duplicated CD keys, if the address it's found and valid, the check will happens. This function is enables only if you use -host and -nocdkey. The server will get the message "No challenge value was received from the master server." when attempting to check for duplicated CD keys. The DLL will intercept all of the network functions. All of them, apart the one above, add an overhead for this to work. This overhead consists of a single jmp instruction without stack management (nacked), which I suppose should at least be long as a single CPU cycle, or less. So if you run a 3GHz CPU, the added delay should be 0,33 ns (nanosecond, a billionth of second).

Legal

I suppose this is something legally doable, because BI already provided the way to work without checking for duplicated CD keys. If BI doesn't want this, I'll remove any reference to this work and notify the reachable forums and mirrors.

Links

Source

You get the full source in the distributed archive. This is the working code extracted from there:

struct hostent* FAR(__stdcall h_gethostbyname)(__in const char *name) {
    using namespace std;
    static const string master("armedass.master.gamespy.com"), available("armedass.available.gamespy.com");
    static const wstring mhost(L"-host"), mnocdkey(L"-nocdkey");
    static bool host=false, nocdkey=false, argschecked=false;
    struct hostent* FAR rc = 0;
    if (!argschecked) {
	argschecked=true;
	LPWSTR *szArglist;
	int nArgs;
	szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
	if( NULL != szArglist ) for(int i=0; i<nArgs ; ++i) {
		if (!host)    host=(mhost.compare(szArglist[i]) == 0); 
		if (!nocdkey) nocdkey=(mnocdkey.compare(szArglist[i]) == 0);
	}
	LocalFree(szArglist);
    }
    if (host && nocdkey && name && (master.compare(name) == 0 || available.compare(name) == 0) ) {
	p_WSASetLastError(WSAHOST_NOT_FOUND);
    } else {
	rc=p_gethostbyname(name);
    }
    return rc;
}

This was possible thanks to this and this.