[CODE]Alien Swarm
Well, it's been some time since I last contributed anything useful to this section so I figured I'd continue working on Alien Swarm(free game on steam).
So, for today there shall be this(I'll be posting more soon enough):
Originally Posted by steam
All achievements unlocked! 
(note: you'll need to join a multiplayer server in order for the achievements to unlock)
So, what should you do?
1. Install the alien swarm SDK and click Create a mod
2. Extract it to some easy to find place(C:\AssMod for me)
3. Open up 'modname/src/game/client/swarm_sdk_client.sln'
4. delete all folders from the project except for 'link libraries'
5. add two new folders: 'source files' and 'header files'
6. now go to 'modname/src' folder, control + f and delete all .cpp files.
7. Coding starts!
First off we add the usual DLL stuff, so add this to your main.cpp:
You'll probly have noticed the swarmbot.h include... Let's add that as well ;P
Now you're probably wondering why I'm using a namespace, don't worry, just a personal preference.
Thats all in the .h, so lets add swarmbot.cpp as well:
The only files left are HackHelper.h, HackHelper.cpp and SDK.h, so here they are:
HackHelper.h
It uses GetModuleHandleA or GetModuleHandleW based on the project settings.
HackHelper.cpp
Finally SDK.h, which will contain the SDK includes we currently need.
Have fun, credits would be nice 
Hell_Demon
So, for today there shall be this(I'll be posting more soon enough):

(note: you'll need to join a multiplayer server in order for the achievements to unlock)
So, what should you do?
1. Install the alien swarm SDK and click Create a mod
2. Extract it to some easy to find place(C:\AssMod for me)
3. Open up 'modname/src/game/client/swarm_sdk_client.sln'
4. delete all folders from the project except for 'link libraries'
5. add two new folders: 'source files' and 'header files'
6. now go to 'modname/src' folder, control + f and delete all .cpp files.
7. Coding starts!
First off we add the usual DLL stuff, so add this to your main.cpp:
Code:
/* Includes */
#include <windows.h>
#include "swarmbot.h"
/* DLL entry point */
BOOL APIENTRY DllMain(HMODULE hDll, DWORD dwReason, LPVOID lpReserved)
{
switch(dwReason)
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hDll); //disable future calls to this module
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)SwarmBot::SwarmBot_Thread, 0, 0, 0); //create a thread to our control function.
break;
}
return true;
}
Code:
#pragma once
#include "SDK.h"
namespace SwarmBot
{
void SwarmBot_Thread(void); //we run this as thread
void SwarmBot_Init(void); //gives us access to the interfaces we want
};
Thats all in the .h, so lets add swarmbot.cpp as well:
Code:
#include <windows.h>
#include <stdio.h> //sprintf
#include "swarmbot.h"
#include "hackhelper.h" //contains the HackHelper::WaitForLoadedDll
#include "SDK.h" //SDK functions
bool bInitialized;
IBaseClientDLL *pBaseClientDLL = NULL;
IVEngineClient *pEngineClient = NULL;
IClientEntityList *pClientEntityList = NULL;
void SwarmBot::SwarmBot_Thread(void)
{
SwarmBot_Init(); //get access to the interfaces
while(1)
{
if(GetAsyncKeyState(VK_NUMPAD1)&1) //the lazy way of checking keys ;)
{
IAchievementMgr *pAchievements = pEngineClient->GetAchievementMgr(); //get a pointer to the achievement manager
for(int i=0; i<pAchievements->GetAchievementCount(); i++) //loop through all achievements
{
IAchievement *pAchievement = pAchievements->GetAchievementByIndex(i, 0); //get the achievement by index
pAchievements->AwardAchievement(pAchievement->GetAchievementID(), 0); //award the achievement by ID
char msg[256]=""; //blank message
sprintf(msg, "echo \"Unlocked: %s\"", pAchievement->GetName()); //format the message "echo Unlocked: achievement name here"
pEngineClient->ClientCmd(msg); //execute the echo command, which will print out the message specified in the console.
}
}
Sleep(100);
}
}
void SwarmBot::SwarmBot_Init(void)
{
//Wait for the needed modules to load and get their handles
HMODULE hClient = HackHelper::WaitForLoadedDll("client.dll"); //get a handle to client.dll
HMODULE hEngine = HackHelper::WaitForLoadedDll("engine.dll"); //get a handle to engine.dll
//Get a pointer to the CreateInterface functions
CreateInterfaceFn CIBaseClient = (CreateInterfaceFn)GetProcAddress(hClient, "CreateInterface");
CreateInterfaceFn CIEngineClient = (CreateInterfaceFn)GetProcAddress(hEngine, "CreateInterface");
//Get access to the client interfaces
pBaseClientDLL = (IBaseClientDLL *)CIBaseClient(CLIENT_DLL_INTERFACE_VERSION, 0);
pClientEntityList = (IClientEntityList*)CIBaseClient(VCLIENTENTITYLIST_INTERFACE_VERSION, 0);
//Get access to the engine interfaces
pEngineClient = (IVEngineClient *)CIEngineClient(VENGINE_CLIENT_INTERFACE_VERSION, 0);
bInitialized = true; //not used but left in for future use
}
HackHelper.h
Code:
#pragma once
namespace HackHelper
{
#ifdef UNICODE
HMODULE WaitForLoadedDll(LPCWSTR DllName);
#else
HMODULE WaitForLoadedDll(LPCSTR DllName);
#endif
};
HackHelper.cpp
Code:
#include <windows.h>
#include "hackhelper.h"
namespace HackHelper
{
#ifdef UNICODE
HMODULE WaitForLoadedDll(LPCWSTR DllName)
{
HMODULE hRet = NULL;
while(!(hRet = GetModuleHandleW(DllName)))
{
Sleep(25);
}
return hRet;
}
#else
HMODULE WaitForLoadedDll(LPCSTR DllName)
{
HMODULE hRet = NULL;
while(!(hRet = GetModuleHandleA(DllName)))
{
Sleep(50);
}
return hRet;
}
#endif // !UNICODE
};
Code:
#pragma once #include "cdll_int.h" //engine interface stuff #include "interfaces/interfaces.h" //interface stuff #include "client_class.h" //player class is in here #include "icliententitylist.h" //client entity interface #include "icliententity.h" //client entity interface #include "iachievementmgr.h" //achievement manager

Hell_Demon



