Alef/nocdkey – User

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
m (Text replacement - "\{\{( *)Important( *)\|" to "{{$1Feature$2|$2important$2|")
(42 intermediate revisions by 4 users not shown)
Line 1: Line 1:
'''nocdkey here doesn't mean you can play illegal copies with this plugin!'''<br>
{{Feature|important|"nocdkey" here doesn't mean you can play illegal copies with this plugin!}}
This plugin simulate what you usually can do just dropping your connection to the internet.
=== What is this? ===
This is a plugin to avoid the problems described [http://dev-heaven.net/issues/3445 here (#3445 at CIT)].


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.
=== Gamespy ===
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.
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>.


==How to run 2 ArmAs on the same PC==
=== ws2_32.dll ===
Need a crafted ''ws2_32.dll'', which returns ''WSAHOST_NOT_FOUND'' in ''gethostbyname()'' for ''armedass.master.gamespy.com'' or ''armedass.available.gamespy.com'' if -nokey is given on the server (-host) command line.
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, or in the <tt>beta</tt> folder if you run the beta, ArmA will use that instead of the Windows one. It is roughly the same like Armalib from Kegetys or JayArmA2lib, which uses <tt>dsound.dll</tt> to inject custom code in the ArmA process address space.<br>
I've modified a program found online (see the [[#Links|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 IP address given a name.<br>
==== How it works ====
When ArmA asks for host names in the domain <tt>gamespy.com</tt>, in order to check for duplicated CD keys, if the address it's found and valid, the check will happens. If ''not'', the server will get the message <tt>"No challenge value was received from the master server."</tt>. My <tt>ws2_32.dll</tt> let the latter happens, but only if you use <b><tt>-nocdkey</tt></b> together with <b><tt>-host</tt></b> on the command line.
==== Drawbacks ====
The DLL will intercept all of the network functions made by ArmA. 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 may add a delay equal to one memory fetch when it is not in cpu cache.
 
{{Feature|important|This should be something legally doable, because BI already provided the way to work without checking for duplicated CD keys both on dedicated server and in hosted server when Gamespy host is not reachable. No reverse-engineering work has been done on network packets nor for in-memory or on-disk executable images.}}
 
== Links ==
* Download available at [http://dev-heaven.net/projects/alef-projects/files dev-heaven.net]
* OFPEC beta [http://www.ofpec.com/forum/index.php?topic=32619.0 request]
* Xfire [http://www.xfire.com/video/4d907/ video] showing the procedure
* Original code: [http://www.codeguru.com/forum/archive/index.php/t-386875.html codeguru.com]
 
== Source ==
You get the full source in the distributed archive. This is the working code extracted from there:
<pre>
<pre>
Editor/Server:
struct hostent* FAR(__stdcall h_gethostbyname)(__in const char *name) {
\ArmA\arma.exe -window -nosplash -world=empty -nopause -host -nokey
    using namespace std;
 
    static const string gamespy("gamespy.com");
Client:
    static const wstring mhost(L"-host"), mnocdkey(L"-nocdkey");
\ArmA\arma.exe -window -nosplash -world=empty -nopause -connect=localhost
    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 == szArglist[i]);
                if (!nocdkey) nocdkey=(mnocdkey == szArglist[i]);
        }
        LocalFree(szArglist);
    }
    const string sname=name;
    if (host && nocdkey && name && (
        string::npos != sname.find( gamespy, sname.length() - gamespy.length())
    )) {
        p_WSASetLastError(WSAHOST_NOT_FOUND);
    } else {
        rc=p_gethostbyname(name);
    }
    return rc;
}
</pre>
</pre>
Will post on OFPEC for beta, if someone interested, and on BI forum.
Where ''p_'' is the original DLL function entry point and ''h_'' the overloaded one.

Revision as of 03:12, 7 February 2021

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

What is this?

This is a plugin to avoid the problems described here (#3445 at CIT).

Gamespy

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, or in the beta folder if you run the beta, ArmA will use that instead of the Windows one. It is roughly the same like Armalib from Kegetys or JayArmA2lib, 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 IP address given a name.

How it works

When ArmA asks for host names in the domain gamespy.com, in order to check for duplicated CD keys, if the address it's found and valid, the check will happens. If not, the server will get the message "No challenge value was received from the master server.". My ws2_32.dll let the latter happens, but only if you use -nocdkey together with -host on the command line.

Drawbacks

The DLL will intercept all of the network functions made by ArmA. 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 may add a delay equal to one memory fetch when it is not in cpu cache.

This should be something legally doable, because BI already provided the way to work without checking for duplicated CD keys both on dedicated server and in hosted server when Gamespy host is not reachable. No reverse-engineering work has been done on network packets nor for in-memory or on-disk executable images.

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 gamespy("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 == szArglist[i]); 
                if (!nocdkey) nocdkey=(mnocdkey == szArglist[i]);
        }
        LocalFree(szArglist);
    }
    const string sname=name;
    if (host && nocdkey && name && (
        string::npos != sname.find( gamespy, sname.length() - gamespy.length())
    )) {
        p_WSASetLastError(WSAHOST_NOT_FOUND);
    } else {
        rc=p_gethostbyname(name);
    }
    return rc;
}

Where p_ is the original DLL function entry point and h_ the overloaded one.