[CODE]Alien Swarm

Posts 1–13 of 13 · Page 1 of 1
[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):
Quote Originally Posted by steam
Today You achieved Alien Swarm: Brutal Campaign, Hardcore, Vindicator Veteran, Pistols Expert, Small Arms Specialist, High Voltage Expert, Railgun Specialist, Pyrotechnician, Slaughter Soldier, Minigun Master, Professional Marksman, Grenadier Expert, Hornet Barrage Expert, Tactical Explosives Expert, Firewall Specialist, Armory Access, Easy Campaign, Normal Campaign, Hard Campaign, Insane Campaign, On the Ready Line, Another Bughunt, Kill Them All, Nuke From Orbit, Landing Bay Speed Run, Cargo Elevator Speed Run, Deima Surface Bridge Speed Run, Rydberg Reactor Speed Run, SynTek Residential Speed Run, Sewer Junction Speed Run, Timor Station Speed Run, Outstanding Execution, Zero Mortality, Hat Trick, Clear Firing, Short Controlled Bursts, Shield Down, Blast Radius, Sharpshooter, Perfect, Scrambled Eggs, Bug Stomper, Parasite Puncher, Close Encounters, Smoking Barrels, Infestation Savior, Circuit Breaker, Security Expert, Group Heal, Damage Amped, Gunslinger, Quick Load, Peace Medic, Protect the Tech, Technician Secured, Electro-Stunned, Under the Gun, Quick and Dead, Stay Frosty, Ammo Technician, Static Defender, Assault Specialist, Prototype Professional, Autogun Expert, Shotgun Specialist.
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:
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;
}
You'll probly have noticed the swarmbot.h include... Let's add that as well ;P
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
};
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:
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
}
The only files left are HackHelper.h, HackHelper.cpp and SDK.h, so here they are:

HackHelper.h
Code:
#pragma once

namespace HackHelper
{
#ifdef UNICODE
    HMODULE WaitForLoadedDll(LPCWSTR DllName);
#else
    HMODULE WaitForLoadedDll(LPCSTR DllName);
#endif
};
It uses GetModuleHandleA or GetModuleHandleW based on the project settings.

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
};
Finally SDK.h, which will contain the SDK includes we currently need.
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
Have fun, credits would be nice
Hell_Demon
45 views and not a single post...
too awesome that people can't express their feelings.
Well, great job, but this is easily detectable, is it not? I mean, all 50(?) achievements unlocked in 2 seconds. O:
VAC is delayed so it won't be until next month that i'm sure it's undetected. Doubt it is tho only went online to unlock and left again.
We have an alien swarm section...
Quote Originally Posted by Insane View Post
We have an alien swarm section...
have you seen the code tag? =>
Quote Originally Posted by 'Bruno View Post
have you seen the code tag? =>
^ this

And besides the alien swarm section is for noobs who actually play the game...
@HD

Do you hack every game that comes with an SDK? /
Quote Originally Posted by Fabolous View Post
@HD

Do you hack every game that comes with an SDK? /
Games that provides an SDK or that use an not-so-customized game engine are waay easier to make hacks waay faster.

Less reversal and stuff ; They provide you Memory Structs and thingies to work on.
Quote Originally Posted by Fabolous View Post
@HD

Do you hack every game that comes with an SDK? /
Yeah, so if you know of more let me know and I'll happily create some sexy stuff.

AlienSwarm is easy as it has it's own SDK so I don't need to reverse to make a multihack.

Rewriting the code though, hooking CHLHClient::Init which will give me access to appSystemFactory(allowing me to get access ALL interfaces from a single factory)

Working on ESP but having some problems with the debugoverlay, so i'll probably have to use VGUI.

Here's some more code to keep you guys busy ;P

SwarmBot.h:
Code:
#pragma once

class Vector;
class C_ASW_Marine;
namespace SwarmBot
{
	void SwarmBot_Thread(void);
	void SwarmBot_Init(void);
	int ScreenTransform( const Vector& point, Vector& screen );
	bool OnScreenFix(float x, float y, int & fx, int & fy);
	bool GetLocalMarine(C_ASW_Marine *Marine); //untested, rewritten this way to clean it up a bit.
};
SwarmBot.cpp additions:
Code:
/*
	Transforms the world position to a screen position relative to the center
	ranging from -1 to 1 if the point is on your screen
        usage:
        Vector scrn;
        if(!SwarmBot::ScreenTransform(pEnt->GetBaseEntity()->GetAbsOrigin(), scrn);
        {
                //valid here
        }
*/
int SwarmBot::ScreenTransform( const Vector& point, Vector& screen )
{
	float w;
	const VMatrix &worldToScreen = pEngineClient->WorldToScreenMatrix();

	screen.x = worldToScreen[0][0] * point[0] + worldToScreen[0][1] * point[1] + worldToScreen[0][2] * point[2] + worldToScreen[0][3];
	screen.y = worldToScreen[1][0] * point[0] + worldToScreen[1][1] * point[1] + worldToScreen[1][2] * point[2] + worldToScreen[1][3];
	w		 = worldToScreen[3][0] * point[0] + worldToScreen[3][1] * point[1] + worldToScreen[3][2] * point[2] + worldToScreen[3][3];

	screen.z = 0.0f;

	bool behind;
	if( w < 0.001f )
	{
		behind = true;
		screen.x *= 100000;
		screen.y *= 100000;
	}
	else
	{
		behind = false;
		float invw = 1.0f / w;
		screen.x *= invw;
		screen.y *= invw;
	}

	return behind;
}

/*
	float x and y will be between -1.0f and 1.0f when the ent is on the screen

	-1 * half screen width + half screen width will put it between 0 and screen width
	it can also be lower then -1, so we'll have to filter to get them between 0 and width

	same applies to height

        Usage:
        int x=0, y=0;
        if(SwarmBot::OnScreenFix(scrn.x, scrn.y, x, y))
        {
                //It's on your screen
                //x and y will now have the screen position
        }
*/
bool SwarmBot::OnScreenFix(float x, float y, int & fx, int & fy)
{
	bool bOnScreen = false;
	int width, height;

	pEngineClient->GetScreenSize(width, height); //get screen size
	width /= 2;  //divide by two to get the centre
	height /= 2; //divide by two to get the centre
	fx = (int)fabs(x*width+width); //see comment above this function
	fy = (int)fabs(y*-1*height+height);//see comment above this function
	if(fx > 0 && fx < (width*2) && fy > 0 && fy < (height*2))//see comment above this function
	{
		bOnScreen=true; //it's on the screen
	}
	return bOnScreen;
}

//get the local marine(the movable character,
//if you don't use this you'll have the commander entity which doesn't move or anything.
bool SwarmBot::GetLocalMarine(C_ASW_Marine *Marine)
{
	IClientEntity *pEnt = pClientEntityList->GetClientEntity(pEngineClient->GetLocalPlayer());
	if(pEnt == NULL) return false;

	C_ASW_Player *pPlayer = (C_ASW_Player*)pEnt->GetBaseEntity();
	if(pPlayer == NULL) return false;

	C_ASW_Marine *pMarine = static_cast<C_ASW_Marine*>(pClientEntityList->GetClientEntityFromHandle(pPlayer->m_hMarine.m_Value));
	if(pMarine == NULL) return false;

	Marine = pMarine;
	return true;
}
Achievements and steamworks stats editing will not result in a VAC ban. This is entirely safe.
Posts 1–13 of 13 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us