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 __DllMainCRTStartup@12'
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
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;
}
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
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)
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
Back to DllMain.cpp because we can now add some calls to our console!
After you check if m_pIGameConsole isnt NULL add the following lines:
Code: Select all
if (m_pIGameConsole->IsConsoleShown() == false)
m_pIGameConsole->Show();
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");
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)