AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   Counter-Strike SDK (https://forums.alliedmods.net/showthread.php?t=123097)

Arkshine 04-02-2010 11:02

Counter-Strike SDK
 
Counter-Strike SDK
- last updated : 2 apr 2010


The purpose is obviously not to provide a full working and compilable project
but only showing the content of some functions to know more on some CS specificities,
understanding the flow of some features, extracting useful datas thus creating better plugins
which should be more finely, intelligently, and efficiently coded.

So, from now I'm starting to release there as many function as I can gradually as time passes.
If people want to help, they are welcomed, though you should be aware it requires a lot of times.

As side notes I don't know much C/C++ so there will be probably some typos and sometimes
you will see pawn syntax. Unless it must be fixed, don't bother me with details.

I've started recently, don't expect to see all the functions at once.
I will try to keep one post by class, so I can explain things if need,
like the offsets related to the function, or from where is called such function.

Credits to HLSDK and HL2SDK.

EDIT: Now the project has been moved at : https://github.com/Arkshine/CSSDK
EDIT2: Another project by s1lentq, more complete at: https://github.com/s1lentq/ReGameDLL_CS. Consider checking this one instead.


Arkshine 04-02-2010 11:09

Re: Counter-Strike SDK
 
* snip *

Seta00 04-02-2010 11:10

Re: Counter-Strike SDK
 
Nice job!

EDIT: In player.cpp, lines 231 and 241, you're assigning instead of comparing:
Quote:

Originally Posted by player.cpp
if ( g_pGameRules->m_bCTCantBuy && m_iTeam = TEAM_CT )
...
if ( g_pGameRules->m_bTCantBuy && m_iTeam = TEAM_TERRORIST )


Arkshine 04-02-2010 11:16

Re: Counter-Strike SDK
 
*snip*

Arkshine 04-02-2010 11:18

Re: Counter-Strike SDK
 
Thanks, it will be fixed for the next version.

Arkshine 04-02-2010 11:22

Re: Counter-Strike SDK
 
*snip*

Asd' 04-02-2010 11:24

Re: Counter-Strike SDK
 
Arkshine, Nice job.
Regards.

Arkshine 04-02-2010 11:27

Re: Counter-Strike SDK
 
*snip*

Arkshine 04-02-2010 11:33

Re: Counter-Strike SDK
 
*snip*

Arkshine 04-02-2010 11:37

Re: Counter-Strike SDK
 
*snip*

xPaw 04-02-2010 11:49

Re: Counter-Strike SDK
 
Woop, god like!

valve doesn't give us source codes? We arkshine can make own! :mrgreen:

edit:
Quote:

BOOL CBasePlayer::NeedsArmor()
{
return !m_iKevelar || pev->armorvalue < 50;
}

Seta00 04-02-2010 11:54

Re: Counter-Strike SDK
 
In weapon_awp.cpp, line 153:
Quote:

Originally Posted by weapon_awp.cpp
void CAWP::AUGFire

should be:
Quote:

Originally Posted by weapon_awp.cpp
void CAWP::AWPFire

----------------------

In multiplay_gamerules.cpp, lines 238, 245, 252 and 259, you're using sprintf incorrectly (I'm not sure what you meant, but it was probably a ClientPrint)
In the same file, line 268, there's an incomplete statement:
Quote:

Originally Posted by multiplay_gamerules.cpp:268
m_ =


joropito 04-02-2010 13:22

Re: Counter-Strike SDK
 
I think Arkshine went crazy doing this :P

Good job, very useful.

Arkshine 04-02-2010 13:44

Re: Counter-Strike SDK
 
Well, you may right because there is still so much to post. :mrgreen:

@seta00 : Thanks, it's fixed. About sprintf, it's actually ALERT().

Arkshine 04-02-2010 14:11

Re: Counter-Strike SDK
 
*snip*

joropito 04-02-2010 14:16

Re: Counter-Strike SDK
 
Arkshine, your anchor tag is not working between pages

Arkshine 04-02-2010 14:17

Re: Counter-Strike SDK
 
*snip*

Arkshine 04-02-2010 14:21

Re: Counter-Strike SDK
 
Quote:

Originally Posted by joropito (Post 1136620)
Arkshine, your anchor tag is not working between pages

Damn. It sucks putting directly the link, it will open each time a tab/windows. But no choice if I keep to release there. :/

xPaw 04-02-2010 15:34

Re: Counter-Strike SDK
 
You should create some small page atleast on wiki

Arkshine 04-02-2010 15:51

Re: Counter-Strike SDK
 
Later. When there will too much data I will migrate all on the wiki. But right now it's only the beginning and I prefer sharing here, seeing feedbacks, adjusting the contents etc..

Dr.G 04-02-2010 17:13

Re: Counter-Strike SDK
 
are there any m_CollisionGroup like offset in HL1 ? Iam thinkin a NoBlock plugin like this for HL1 -> http://forums.alliedmods.net/showthread.php?p=746250

Seta00 04-02-2010 17:47

Re: Counter-Strike SDK
 
Quote:

Originally Posted by Arkshine (Post 1136715)
now it's only the beginning

:shock::shock::shock:

By the way, how exactly are you doing this?

Arkshine 04-02-2010 18:04

Re: Counter-Strike SDK
 
IDA pro + HLSDK + a lot of times ( because you need to check, recheck, searching, guessing, switching between linux/windows IDA output etc.. IDA is a motherfucker sometimes you have to be careful :/ )


@Dr.G : No idea right now.

Exolent[jNr] 04-02-2010 20:03

Re: Counter-Strike SDK
 
This is amazing! :D

joropito 04-02-2010 21:53

Re: Counter-Strike SDK
 
I need this :)

Quote:

Originally Posted by Arkshine (Post 1136475)
[*]CBaseSpectator


Immortal_BLG 04-02-2010 22:14

Re: Counter-Strike SDK
 
Maybe useful for somebody....

List of game events for TheBots, TheTutor, ... OnEvent() function

Code:

enum GameEventType_t
{
        GameEventType_PLAYER_ATTACK = 1u,                                // tell bots the player is attack (argumens: 1 = attacker, 2 = NULL)
        GameEventType_PLAYER_ATTACK_WITHOUT_CLIP_AMMO,        // tell bots the player is attack without clip ammo (argumens: 1 = attacker, 2 = NULL)
        GameEventType_PLAYER_RELOAD_WEAPON,                                // tell bots the player is reloading his weapon (argumens: 1 = reloader, 2 = NULL)

        GameEventType_GRENADE_EXPLODED,                                        // tell bots the HE grenade is exploded (argumens: 1 = grenade thrower, 2 = NULL)
        GameEventType_FLASHBANG_EXPLODED,                                // tell bots the flashbang grenade is exploded (argumens: 1 = grenade thrower, 2 = explosion origin)
        GameEventType_SMOKE_GRENADE_EXPLODED,                        // tell bots the smoke grenade is exploded (argumens: 1 = grenade thrower, 2 = NULL)

        GameEventType_PLAYER_FLASHED = 9u,                                // tell bots the player is flashed (argumens: 1 = flashed player, 2 = NULL)
        GameEventType_PLAYER_RUNNING,                                        // tell bots the player is running (argumens: 1 = runner, 2 = NULL)
        GameEventType_PLAYER_JUMPED,                                        // tell bots the player is jumped (argumens: 1 = jumper, 2 = NULL)
        GameEventType_PLAYER_KILLED,                                        // tell bots the player is killed (argumens: 1 = victim, 2 = killer)
        GameEventType_PLAYER_FELL_WITH_DAMAGE,                        // tell bots the player is fell with some damage (argumens: 1 = felled player, 2 = NULL)
        GameEventType_PLAYER_TAKE_DAMAGE,                                // tell bots the player is take damage (argumens: 1 = victim, 2 = attacker)
        GameEventType_PLAYER_INJURED_HOSTAGE,                        // tell bots the player has injured a hostage (argumens: 1 = hostage, 2 = injurer)
        GameEventType_PLAYER_KILLED_HOSTAGE,                        // tell bots the player has killed a hostage (argumens: 1 = hostage, 2 = killer)

        GameEventType_DOOR_MOVING,                                                // tell bots the door is moving (argumens: 1 = door, 2 = NULL)

        GameEventType_GLASS_BREAK,                                                // tell bots the glass has break (argumens: 1 = glass, 2 = NULL)
        GameEventType_WOOD_BREAK,                                                // tell bots the wood has break (argumens: 1 = wood, 2 = NULL)
        GameEventType_METAL_BREAK,                                                // tell bots the metal/computer has break (argumens: 1 = metal/computer, 2 = NULL)
        GameEventType_FLESH_BREAK,                                                // tell bots the flesh has break (argumens: 1 = flesh, 2 = NULL)
        GameEventType_CONCRETE_BREAK,                                        // tell bots the concrete has break (argumens: 1 = concrete, 2 = NULL)

        GameEventType_BOMB_PLANTED,                                                // tell bots the bomb has been planted (argumens: 1 = planter, 2 = NULL)
        GameEventType_BOMB_DROPPED,                                                // tell bots the bomb has been dropped (argumens: 1 = NULL, 2 = NULL)
        GameEventType_BOMB_PICKUP,                                                // let the bots hear the bomb pickup (argumens: 1 = player that pickup c4, 2 = NULL)
        GameEventType_BOMB_BEEP,                                                // let the bots hear the bomb beeping (argumens: 1 = c4, 2 = NULL)
        GameEventType_BOMB_DEFUSING,                                        // tell the bots someone has started defusing (argumens: 1 = defuser, 2 = NULL)
        GameEventType_BOMB_DEFUSE_ABORTED,                                // tell the bots someone has aborted defusing (argumens: 1 = NULL, 2 = NULL)
        GameEventType_BOMB_DEFUSED,                                                // tell the bots the bomb is defused (argumens: 1 = defuser, 2 = NULL)
        GameEventType_BOMB_EXPLODED,                                        // let the bots hear the bomb exploding (argumens: 1 = NULL, 2 = NULL)

        GameEventType_HOSTAGE_USED,                                                // tell bots the hostage is used (argumens: 1 = user, 2 = NULL)
        GameEventType_HOSTAGE_RESCUED,                                        // tell bots the hostage is rescued (argumens: 1 = rescuer (Classes::BasePlayer *), 2 = hostage (Classes::Hostage *))
        GameEventType_ALL_HOSTAGES_RESCUED,                                // tell bots the all hostages are rescued (argumens: 1 = NULL, 2 = NULL)

        GameEventType_VIP_ESCAPED,                                                // tell bots the VIP is escaped (argumens: 1 = NULL, 2 = NULL)
        GameEventType_VIP_ASSASSINATED,                                        // tell bots the VIP is assassinated (argumens: 1 = NULL, 2 = NULL)

        GameEventType_TERRORISTS_WIN,                                        // tell bots the terrorists won the round (argumens: 1 = NULL, 2 = NULL)
        GameEventType_CTS_WIN,                                                        // tell bots the CTs won the round (argumens: 1 = NULL, 2 = NULL)

        GameEventType_ROUND_DRAW,                                                // tell bots the round was a draw (argumens: 1 = NULL, 2 = NULL)

        GameEventType_ROUND_START = 41u,                                // tell bots the round was started (when freeze period is expired) (argumens: 1 = NULL, 2 = NULL)
        GameEventType_PLAYER_SPAWN,                                                // tell bots the player is spawned (argumens: 1 = spawned player, 2 = NULL)
        GameEventType_ROUND_RESTART = 44u,                                // tell bots the round was restarted (argumens: 1 = NULL, 2 = NULL)
        GameEventType_PLAYER_START_OBSERVER = 46u,                // tell bots the player is sart observer (argumens: 1 = observer player, 2 = NULL)
        GameEventType_BUY_MENU_OPEN = 53u,                                // tell bots the buy menu is opened (argumens: 1 = NULL, 2 = NULL)

        // Radio commands.... (argumens: 1 = radio command sender, 2 = NULL)
                GameEventType_RADIO_Cover_me = 65u,
                GameEventType_RADIO_You_take_the_point,
                GameEventType_RADIO_Hold_this_position,
                GameEventType_RADIO_Regroup_team,
                GameEventType_RADIO_Follow_me,
                GameEventType_RADIO_Taking_fire,

                GameEventType_RADIO_Go_go_go = 72u,
                GameEventType_RADIO_Team_fall_back,
                GameEventType_RADIO_Stick_together_team,
                GameEventType_RADIO_Get_in_position_and_wait,
                GameEventType_RADIO_Storm_the_front,
                GameEventType_RADIO_Report_in_team,

                GameEventType_RADIO_Affirmative = 79u,
                GameEventType_RADIO_Enemy_spotted,
                GameEventType_RADIO_Need_backup,
                GameEventType_RADIO_Sector_clear,
                GameEventType_RADIO_In_position,
                GameEventType_RADIO_Reporting_in,
                GameEventType_RADIO_Get_out_of_there,
                GameEventType_RADIO_Negative,
                GameEventType_RADIO_Enemy_down,

        GameEventType_GAME_RESET = 89u,                                        // tell bots the game is reset (argumens: 1 = NULL, 2 = NULL)
        GameEventType_PLAYER_SWITCH_TEAM,                                // tell bots the player is switch his team (also called from ClientPutInServer()) (argumens: 1 = switcher, 2 = NULL)
        GameEventType_PLAYER_SHOOT_AT_WALL,                                // tell bots the player is shoot at wall (argumens: 1 = shooter, 2 = shoot trace end position)
        GameEventType_GAME_COMMENCING,                                        // tell bots the game is commencing (argumens: 1 = NULL, 2 = NULL)
        GameEventType_PLAYER_SWITCH_WEAPON_ZOOM,                // tell bots the player is switch weapon zoom (argumens: 1 = zoom switcher, 2 = NULL)
        GameEventType_HOSTAGE_TALKING                                        // tell bots the hostage is talking (argumens: 1 = listener, 2 = NULL)
};


Arkshine 04-03-2010 06:04

Re: Counter-Strike SDK
 
Quote:

Originally Posted by joropito (Post 1137140)
I need this :)

Actually it's the same as HLSDK, just checked.

What you need would be probably :

CBasePlayer::Observer_CheckProperties()
CBasePlayer::Observer_CheckTarget()
CBasePlayer::Observer_FindNextPlayer()
CBasePlayer::Observer_HandleButtons()
CBasePlayer::Observer_IsValidTarget()
CBasePlayer::Observer_SetMode()

What do you search ?


Quote:

List of game events for TheBots, TheTutor, ... OnEvent() function
Thanks, I will update the code.

wrecked_ 04-03-2010 10:45

Re: Counter-Strike SDK
 
Fabulous work, Arkshine.

joropito 04-03-2010 11:12

Re: Counter-Strike SDK
 
Quote:

Originally Posted by Arkshine (Post 1137438)
Actually it's the same as HLSDK, just checked.

What you need would be probably :

CBasePlayer::Observer_CheckProperties()
CBasePlayer::Observer_CheckTarget()
CBasePlayer::Observer_FindNextPlayer()
CBasePlayer::Observer_HandleButtons()
CBasePlayer::Observer_IsValidTarget()
CBasePlayer::Observer_SetMode()

What do you search ?

I think I need HandleButtons.

I wonder if Observer stands for spectator player or just hltv.
I need spectator.

Arkshine 04-03-2010 11:53

Re: Counter-Strike SDK
 
Something like :

Code:
void CBasePlayer::Observer_HandleButtons() {     if ( m_flNextObserverInput <= gpGlobals->time )     {         int mode;                 if ( m_afButtonPressed & IN_JUMP )         {             switch ( pev->iuser1 )             {                 case 1, 2 : mode = 4;                 case 3    : mode = 5;                 case 4    : mode = 3;                 case 5    : mode = 6;                 default   : mode = m_fObserverAutoDirector ? 1 : 2;             }                       Observer_SetMode( mode );         }                 if ( m_afButtonPressed & IN_ATTACK )         {             Observer_FindNextPlayer( 0, 0 );         }           else if ( m_afButtonPressed & IN_ATTACK2 )         {             Observer_FindNextPlayer( 1, 0 );         }                 m_flNextObserverInput = gpGlobals->time + 0.2;     } }

I don't know how to name the offsets. You ask now you have to give names. :mrgreen:

joropito 04-03-2010 12:13

Re: Counter-Strike SDK
 
Thanks.

FYI and from hlsdk:

m_flOffsetPlayer100 -> m_flNextObserverInput
I found observer.cpp only on ricochet & dmc

Arkshine 04-03-2010 12:32

Re: Counter-Strike SDK
 
Nice catch. :mrgreen:

Will take a look too.

ConnorMcLeod 04-04-2010 01:49

Re: Counter-Strike SDK
 
Code:

        else if ( m_afButtonPressed & IN_FORWARD )
Shoud rather be IN_ATTACK2

Observer_FindNextPlayer( 1, 0 )
First param could be something like Next/Previous, and i think that 2nd param could be about allowed players, like team specific param.

Arkshine 04-04-2010 05:25

Re: Counter-Strike SDK
 
It's weird because I see for both linux/window IDA output "& 8" ; but it makes sens it should be IN_ATTACK2. ( EDIT : Ah I think I know why )

About the last param, the type is a string, it seems to be an optional param to search directly a player by its name. Looking at the function I see a check done in a loop with this param and m_hObserverTarget->pev->netname.

Anyway it should look now like :

Code:
#define OBS_NONE          0 #define OBS_CHASE_LOCKED  1 #define OBS_CHASE_FREE    2 #define OBS_ROAMING       3         #define OBS_IN_EYE        4 #define OBS_MAP_FREE      5 #define OBS_MAP_CHASE     6 void CBasePlayer::Observer_HandleButtons() {     if ( m_flNextObserverInput > gpGlobals->time )     {         return;     }     if ( m_afButtonPressed & IN_JUMP )     {         int mode;                 switch ( pev->iuser1 )         {             case OBS_CHASE_LOCKED :             case OBS_CHASE_FREE   : mode = OBS_IN_EYE;             case OBS_IN_EYE       : mode = OBS_ROAMING;             case OBS_ROAMING      : mode = OBS_MAP_FREE;             case OBS_MAP_FREE     : mode = OBS_MAP_CHASE;             default               : mode = m_fObserverAutoDirector ? OBS_CHASE_LOCKED : OBS_CHASE_FREE;         }               Observer_SetMode( mode );     }         if ( m_afButtonPressed & IN_ATTACK )     {         Observer_FindNextPlayer( FALSE );     }     else if ( m_afButtonPressed & IN_ATTACK2 )     {         Observer_FindNextPlayer( TRUE );     }         m_flNextObserverInput = gpGlobals->time + 0.2; }

joropito 04-04-2010 11:13

Re: Counter-Strike SDK
 
From cl_dll/hud_spectator.cpp
PHP Code:

FindNextPlayer( (ButtonPressed IN_ATTACK2) ? true:false ); 

I wonder if you, Arkshine, are getting only assembler code with IDA or something else that can help to move it to C.

It was hard to my to understand the structure of the decompiled code.

Arkshine 04-04-2010 11:36

Re: Counter-Strike SDK
 
For sure, we can reduce the code like that. I know there are some functions which are taken from the Client and modified on the server like StudioEstimateGait().

I'm not enough crazy to try to decompile from the disassembled code !! :mrgreen: I don't have the knowledge to start ( even though I've read severals asm tutorials ). I'm using a decompiler provided with IDA which greatly help by given a nearly C output. Even with that, it takes a lot of time to understand because the output is often weird and you have to read carefully, following the goto, thinking if the structure is right, filtering between virtual functions, entities data, etc., switching between windows/linux decompiled binary because the output differs and you can have an output more pertinent than the other. For example CBasePlayer::Killed() takes me ~2h ( without counting the time to search what does some things ), though I have to finish one part yet. So, you can imagine without decompiled code it would take so much more time. :)

By the way, I'm thinking to actually try to reproduce a decent SDK with header and such, so I could use Doxygen to generate a documentation system like we can see for metamod. This way it would be better to see the relations and references. I wanted to do that manually but the forum or the wiki suck as hell. I think it's a more appropriate solution instead of posting like I do.

EXteRmiNaToR 04-04-2010 11:56

Re: Counter-Strike SDK
 
Quote:

Originally Posted by Arkshine (Post 1139078)
By the way, I'm thinking to actually try to reproduce a decent SDK with header and such, so I could use Doxygen to generate a documentation system like we can see for metamod. This way it would be better to see the relations and references. I wanted to do that manually but the forum or the wiki suck as hell. I think it's a more appropriate solution instead of posting like I do.

It's the best that way!:)

joropito 04-04-2010 12:12

Re: Counter-Strike SDK
 
Another way is to start a Google Code project and put all together in SVN to you can upload updates with revision control.
You have code parsing and you can search inside the SVN too so it's very useful.

Arkshine 04-04-2010 12:23

Re: Counter-Strike SDK
 
In waiting to have more file and a good structure to use Doxygen, I could use for sure a Google Code project so people could help more easily, especially people knowing very well C/C++ who could fix easily typos/errors and such. Thanks for the suggestions.

Seta00 04-04-2010 15:04

Re: Counter-Strike SDK
 
Quote:

Originally Posted by Arkshine (Post 1139132)
In waiting to have more file and a good structure to use Doxygen, I could use for sure a Google Code project so people could help more easily, especially people knowing very well C/C++ who could fix easily typos/errors and such. Thanks for the suggestions.

I support this completely.
By the way:
Quote:

Originally Posted by multiplayer_gamerules.cpp:310
m_iNumEscapers = 0

missing a semicolon.


All times are GMT -4. The time now is 00:08.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.