[HOW TO]Make a CSS/HL2 clienthook

Talk about game mods and editors, no game hacking here (cheat engine..etc)

[HOW TO]Make a CSS/HL2 clienthook

Postby TeamRetox » Sat Jun 06, 2009 4:21 pm

Installing the Source Code:
1. Open up Steam then go to the Tools tab and launch Source SDK.
2. Make sure that Engine Version is "Half Life2: episode 1" and Current Game is "Counter Strike source"(or HL2 as game).
3. Select Create a Mod and select Source code only.
4. Select a non excisting path(or an empty one, I used 'C:/CSSHack').
5. After the files finish copying you can close out of the Source SDK window and go to the folder where you installed the SDK.
6. Open up the Game_HL2-2005.sln in Visual Studio 2003/2005.

Setting up the enviroment:
1. Delete "Server (HL2)" project from the solution as we dont need it.
2. Build the solution, if you get any errors post them here and I will try to help out.
3. Run Clean Solution because none of the intermediate objects created in step 2 will be used in our DLL so they're worthless to us.
4. Remove the Tool Framework folder from the project.
5. Open the Source Files folder in the project, select all of its contents, and Remove them from the project. We don't need the CPP files(only the headers)
6. From the MP3 folder, remove the mp3player.cpp from the project.
7. Open the Client (HL2) project's properties and go to Custom Build Steps under Configuration Properties. Clear out the three properties that are filled in.
8. Still in the Configuration Properties, go to the Linker tab and replace Output File with $(OutDir)/CSSHack.dll as to not confuse ourselves, since CSS uses its own Client.dll.
9. In C/C++ -> Precompiled Headers, turn off Precompiled Headers (Not Using Precompiled Headers)
10. Close out of the properties sheet and go to Build-> Rebuild Solution.

If you did the above steps succesfully you should get the following error:
'1>LINK : error LNK2001: unresolved external symbol [email protected]'
If you don't get that error you've done something wrong.

Creating the base:
You need to create two files in the source folder now(sharedheaders.h and dllmain.cpp)

SharedHeaders.h:
Code: Select all
#ifndef __SHAREDHEADERS_H
#define __SHAREDHEADERS_H

#include <windows.h>

#endif


DllMain.cpp:
Code: Select all
#include "SharedHeaders.h"

HMODULE DLLModule;

DWORD MainThread ( LPVOID lpArgs )
{
    HMODULE hClient = NULL;

    // Wait for the process to load its client.dll
    for ( ; hClient == NULL ; Sleep(100) )
        hClient = GetModuleHandle("client.dll");

    MessageBox(0, "wh00t we did it!!", "CSSHack", MB_OK);

    // We're done, wait a few seconds then exit :)
    // We free our library now so we can run our 'hack' more then once without restarting
    Sleep(5000);
    FreeLibraryAndExitThread(DLLModule, 0);
}


BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpReserved )
{
    if( dwReason == 1 )
    {
        DLLModule = hinstDLL;
        DWORD dwThreadID;
        CreateThread( NULL, NULL, (LPTHREAD_START_ROUTINE)MainThread, NULL, NULL, &dwThreadID);
    }

    return TRUE;
}


That's the base of our CSS hook.
Since it doesn't have any functionality we're gonna add that now :)

Writing to the game's console
Create a new header in our source folder named IGameConsole.h:
Code: Select all
#ifndef __IGAMECONSOLE_H
#define __IGAMECONSOLE_H

class IGameConsole : public IBaseInterface
{
public:
    virtual void Show() = 0;
    virtual void Initialize() = 0;
    virtual void Hide() = 0;
    virtual void Clear() = 0;
    virtual bool IsConsoleShown() = 0;

    // Unknown functions in the interface.
    virtual void UnknownA() = 0;
    virtual void UnknownB() = 0;
};

#define GAMECONSOLE_INTERFACE_VERSION "GameConsole003"

#endif


Now that we have our interface class we can start by getting a pointer to the games console.
Open up DllMain.cpp and find the ::MessageBox line and replace it with the following code:
Code: Select all
CreateInterfaceFn IGCCreateInterface = (CreateInterfaceFn)GetProcAddress(GetModuleHandle("gameui.dll"), "CreateInterface");

    IGameConsole *m_pIGameConsole = (IGameConsole *)IGCCreateInterface(GAMECONSOLE_INTERFACE_VERSION, NULL);
    if (m_pIGameConsole == NULL)
        MessageBox(0, "Error: m_pIGameConsole is null!", "Error", MB_OK)


Since we're using new functions we'll need to add some lines to our sharedheaders.h(replace the old one with this):
Code: Select all
#ifndef __SHAREDHEADERS_H
#define __SHAREDHEADERS_H

#include <windows.h>
#include "tier0/dbg.h"
#undef CreateThread
#include "interface.h"

#include "IGameConsole.h"

#endif


If you get problems with MessageBox add #undef MessageBox under the undef CreateThread line.
Back to DllMain.cpp because we can now add some calls to our console! :D

After you check if m_pIGameConsole isnt NULL add the following lines:
Code: Select all
if (m_pIGameConsole->IsConsoleShown() == false)
        m_pIGameConsole->Show();


The above code checks if the console is open, and if it isnt it will be opened. This is a way to check if your DLL loaded, and there might occur problems when writing to the console if it hasn't been showed before.

Lets write something to the console now :) After the line that opens it add this:
Code: Select all
ConMsg("RAWR :D Our hook loaded succesfully!!!\n");


That was all for this tutorial, if you have any problems feel free to ask about it.
If you want to add more functionallity to your hack search on google for tutorials on e.g. HudUpdate hooks(which is pretty easy as its almost the same as we did for our console)
TeamRetox
Allie
Allie
 
Posts: 222
Joined: Sat Jun 06, 2009 3:48 pm

Re: [HOW TO]Make a CSS/HL2 clienthook

Postby Sethioz » Sun Jun 07, 2009 4:11 am

never knew about it, is this the way they use on MPC to make those multihacks ?
I assume it is not VAC proof ?
User avatar
Sethioz
Admin
Admin
 
Posts: 4757
Joined: Fri Jul 27, 2007 5:11 pm
Location: unknown

Re: [HOW TO]Make a CSS/HL2 clienthook

Postby TeamRetox » Mon Jun 15, 2009 3:21 pm

Yep, this is how they do it(kind of, they hook more stuff because this is just a basic example).

I've been using this code(expanded and on some parts a bit different) for 3 months now and I haven't got banned yet.
TeamRetox
Allie
Allie
 
Posts: 222
Joined: Sat Jun 06, 2009 3:48 pm

Re: [HOW TO]Make a CSS/HL2 clienthook

Postby Sethioz » Mon Jun 15, 2009 5:13 pm

still quite good example, i haven't tried any of that myself (not a big fan of online css and hl2), but i was searching this like 2 years ago and found no tutorials at all.


About VAC:
i think that VAC does not ban such hooks when its custom made.
i dont think that VAC detects .dll based hacks directly, because there is no telling if you add your own .dll or not. it only bans if you modify the current game files or if its known hack/mod in public, which VAC team has access to so they can put signature into VAC.
however i got banned for nothing in SvenCoop. account i used...i only played svencoop for whole year with it and one day banned..
2 things that came into my mind are fraps and zonealarm's program control (steam acted wierd and i blocked access to my system, think it was vac scan and then it banned me cuz it couldnt scan or something).
User avatar
Sethioz
Admin
Admin
 
Posts: 4757
Joined: Fri Jul 27, 2007 5:11 pm
Location: unknown


Return to Game - Modding / Editing

Who is online

Users browsing this forum: No registered users and 1 guest

cron