dnjswjd777 (04-21-2011),falzarex (02-23-2010),HaxAttaxxx (05-28-2012),jz3 (10-26-2015),kibbles18 (12-17-2010),magicb0y (07-01-2012),mookamoka3 (02-14-2011),Void (02-22-2010),why06 (02-22-2010),|-|3|_][({}PT3R12 (02-22-2010)
Hai guys, I'll be teaching you how to make a source engine hook(CS: Source, National Bloodsports, Hidden: Source)
The game I'll be using for this tutorial is Hidden: Source
The same can be applied to the orange box, altho orange box games have some extra protections on stuff like CUserCMD.
Installing the Source SDK
Go to the Tools tab in steam and right click -> install 'Source SDK' if you don't already have it.
Installing the code
Launch the source SDK and make sure you've set up the engine version matches the game you're going to code for.
Now that you've set up the correct engine version click 'Create a Mod' and click 'Source code only'.
Install it into an empty folder so it is easily accesible.
After it's finished copying you can close the SDK.
Finally open up the Game_HL2-2005.sln in Visual Studio 2005.
Setting up the project
Since we'll be coding for the client only, we won't need the server part of the SDK, so delete the server folder from the project.
We won't be using the .cpp files either since we will write our own, so remove all of them from the project(Yes, I know its alot of work :P)
Open up the project's settings, go to the Custom Build Steps under the submenu Configuration Properties and clear out the 3 properties.
Don't close the settings just yet, first go to the Linker tab and replace output dir with $(OutDir)/MyLeetVIPHax.dll.
Under the C/C++ submenu, turn off precompiled headers.
Note: You can delete the headers from the project aslong as you make sure they aren't removed from your harddrive. I removed these to make things easier to manage.
Lets get started!
Create main.cpp and SDK.h.
SDK.h will contain all the header's we're going to use, main.cpp will the file where we do our hooking.
Open up SDK.h and add the following code:
And open up main.cpp and add the following:Code:#pragma once #include <windows.h>
Now this in itself doesn't do a whole lot, besides waiting for your target to load up client.dll.Code:#include "SDK.h" void MainThread(void) { HMODULE hClient = NULL; // Wait for the process to load its client.dll, which we'll use for fun. while(hClient == NULL) { hClient = GetModuleHandle("client.dll"); Sleep(100); } } BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpReserved ) { if( dwReason == DLL_PROCESS_ATTACH ) { CreateThread( NULL, NULL, (LPTHREAD_START_ROUTINE)MainThread, NULL, NULL, NULL); } return TRUE; }
Doing some usefull stuff
Since the above doesn't do a whole lot of usefull stuff, lets do something usefull like writing to the game's console =D
Normally if you would do this from scratch you'd have to open up your target game and search for console related strings.
You'd find a CreateInterface call in 'gameui.dll' with a "GameConsole003", which is the interface version the game is requesting.
The CreateInterface call returns a pointer to a class, and if you check out that pointer you'll see a vtable with 7 functions.
By watching calls you can then figure out which does what, and by looking at the disassembly you could see how many arguments the function takes etc.
Now, here's the console class(create a new file called IGameConsole.h):
The class IGameConsole is an extention of IBaseInterface, which is located in interface.hCode:#pragma once class IGameConsole : public IBaseInterface { public: virtual void Show() = 0; virtual void Init() = 0; virtual void Hide() = 0; virtual void Clear() = 0; virtual bool IsShown() = 0; // ??? virtual void UnknownA() = 0; virtual void UnknownB() = 0; }; #define GAMECONSOLE_INTERFACE_VERSION "GameConsole003"
Now, we haven't hooked the console yet, we'll need the following code to do that.
Place this at the top:
And place this in MainThread:Code:IGameConsole *g_pIGameConsole=NULL;
To use CreateInterface we'll have to include interface.h and to use our console class, we'll have to include IGameConsole.h.Code:CreateInterfaceFn ConCreateInterface = (CreateInterfaceFn)GetProcAddress(GetModuleHandle("gameui.dll"), "CreateInterface"); g_pIGameConsole = (IGameConsole *)ConCreateInterface(GAMECONSOLE_INTERFACE_VERSION, NULL); if (g_pIGameConsole == NULL) return; if (g_pIGameConsole->IsConsoleShown() == false) { g_pIGameConsole->Show(); ConMsg(0, "Our hook has been loaded :D\n"); }
We'll also need to include tier0/dbg.h, because we used ConMsg.
Here's the new SDK.h
Notice the #undef CreateThread? We'll need to do that because tier0/dbg.h makes some weird defines that conflict with what we want to do ;(Code:#pragma once #include <windows.h> #include "tier0/dbg.h" #undef CreateThread #include "interface.h" #include "IGameConsole.h"
That will be it for now(tired), I'll write up some stuff about hooking CInput and using CUserCMD for fun stuff like spinbots
Ah we-a blaze the fyah, make it bun dem!
dnjswjd777 (04-21-2011),falzarex (02-23-2010),HaxAttaxxx (05-28-2012),jz3 (10-26-2015),kibbles18 (12-17-2010),magicb0y (07-01-2012),mookamoka3 (02-14-2011),Void (02-22-2010),why06 (02-22-2010),|-|3|_][({}PT3R12 (02-22-2010)
Finally! I've been waiting for this forever! wo_Ot! Thanks HD. I will read the whole thing and write a 1 paragraph summary to be turned in Tuesday for 20% of my grade. \___*____*___/
Will add to tut list soon :P
EDIT: Read, so this first part is about hooking the console. Neat trick
Last edited by why06; 02-22-2010 at 12:29 PM.
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
dat be it :l... pardon crappy vid.
[YOUTUBE]<object width="425" height="344"><param name="movie" value="https://www.youtube.com/v/S9YJxwxZsQI&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="https://www.youtube.com/v/S9YJxwxZsQI&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>[/YOUTUBE]
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
added to list.
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
Just asking but is it true that all game engines have their own consoles?
Originally Posted by falzarex aka myself
This is an epic fail resume
Hello VBfags.
A 'member' of the almighty C++ section will soon join you, he is 13 year old, has the IQ and typing skills of a VBfag, so I thought he would fit in here nicely.
A few reasons why he should be in this section instead of the C++ section:
1) He has the IQ of a VBfag.
2) He has no sense of grammer/spelling at all.
3) He thinks he is pro(like most of the people in here)
4) He thinks copy pasting is fun(exactly what you guys do)
5) He loves it up the ass(he will keep you VBfags nice and warm)
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
Ahh u just need to kno wad game engine the game is built on then u can determine the way of hooking it
like unreal engine 3?
combat arms lithtech engine?
cryengine? Etcetc
Originally Posted by falzarex aka myself
This is an epic fail resume
Hello VBfags.
A 'member' of the almighty C++ section will soon join you, he is 13 year old, has the IQ and typing skills of a VBfag, so I thought he would fit in here nicely.
A few reasons why he should be in this section instead of the C++ section:
1) He has the IQ of a VBfag.
2) He has no sense of grammer/spelling at all.
3) He thinks he is pro(like most of the people in here)
4) He thinks copy pasting is fun(exactly what you guys do)
5) He loves it up the ass(he will keep you VBfags nice and warm)
ye
¹³³7 POST TOO SHORT ¹³³7
Ah we-a blaze the fyah, make it bun dem!