.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > SDK Programming discussions > Half-Life 2 SDK
Half-Life 2 SDK For developments focused around the Half-Life 2 engine Half-Life 2

Reply
 
Thread Tools
Re: I don't like this!
Old
  (#11)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: I don't like this! - 27-12-2004

i mailed Alfred about bots and such;

he replied!

Quote:
> So basicly:

> 1) Any news on Bots with HL2DM? (crash on fakeclient creation)

I haven't managed to look at this yes (Christmas and all).

> 2) Any hints for us bot creators about any update functions or

> something alike

We are working on a document describing to how implement bots in Mods, you could use that information also.

>3) Any other hints on future things we can expect?

> (ie, we certainly hope we *can* create bots on Source... Though i

>have seen some frustrated members on forums talking about 'its

> impossible'.. )

>

You can make bots, its just not trivial from plugins. We are working out now how best to support plugins.




Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: I don't like this!
Old
  (#12)
botman
Super Moderator
 
Status: Offline
Posts: 280
Join Date: Jan 2004
Location: Plano, TX
Default Re: I don't like this! - 28-12-2004

Well, as far as his answer to #2...

bot.h file...

Code:
   //=============================================================================//
    //
    // bot.h - bot header file (Copyright 2004, Jeffrey "botman" Broome)
    //
    //=============================================================================//
    
    #ifndef BOT_H
    #define BOT_H
    
    typedef struct
    {
    	CSDKPlayer*	pPlayer;
    } bot_t;
    
    #endif // BOT_H
bot.cpp file...

Code:
   //=============================================================================//
    //
    // bot.cpp - bot source code file (Copyright 2004, Jeffrey "botman" Broome)
    //
    //=============================================================================//
    
    #include "cbase.h"
    #include "entitylist.h"
    #include "mapentities_shared.h"
    //#include "isaverestore.h"
    //#include "eventqueue.h"
    //#include "entityinput.h"
    //#include "entityoutput.h"
    //#include "mempool.h"
    //#include "vstdlib/strtools.h"
    //#include "engine/IVEngineCache.h"
    
    //#include "tier0/vprof.h"
    
    #include "client.h"
    #include "sdk_player.h"
    #include "movehelper_server.h"
    #include "in_buttons.h"
    #include "bot.h"
    
    // memdbgon must be the last include file in a .cpp file!!!
    #include "tier0/memdbgon.h"
    
    // private data for each bot
    static bot_t gBots[32];
    
    
    void BotThink(CSDKPlayer* pBot);
    
    
    CSDKPlayer* CreateBot(const char* name)
    {
    	edict_t *pEdict = engine->CreateFakeClient( name );
    
    	if (!pEdict)
    	{
    		Msg("CreateBot: ERROR - Counldn't create a bot!!!\n");
    		return NULL;
    	}
    
    //	ClientPutInServer(pEdict, name);  // you don't need this for bots in Source
    
    	CSDKPlayer *pPlayer = ((CSDKPlayer *)CBaseEntity::Instance( pEdict ));
    	pPlayer->ClearFlags();
    	pPlayer->AddFlag( FL_CLIENT | FL_FAKECLIENT );
    
    	bot_t *pBot = &gBots[ engine->IndexOfEdict(pEdict) - 1 ];
    
    	// initialize any private bot data here...
    	pBot->pPlayer = pPlayer;
    
    	Msg("CreateBot: bot was added successfully to server\n");
    
    	return pPlayer;
    }
    
    void AddBot( void )
    {
    	Msg("AddBot: Adding a bot...\n");
    
    	CreateBot("Player");  // create a bot named "Player"
    }
    
    ConCommand addbot( "addbot", AddBot, "add a bot to the game." );
    
    
    // called by GameStartFrame() at the start of every frame, let's the bots Think...
    void BotStartFrame(void)
    {
    	for ( int i = 1; i <= gpGlobals->maxClients; i++ )
    	{
    		CSDKPlayer *pPlayer = ToSDKPlayer( UTIL_PlayerByIndex( i ) );
    
 		if ((pPlayer != NULL) && (pPlayer->GetFlags() & FL_FAKECLIENT))
    		{
    			BotThink( pPlayer );
    		}
    	}
    }
    
    // see CBasePlayer::RunNullCommand() for example of PlayerRunCommand()...
    void BotRunPlayerMove(CSDKPlayer* pPlayer)
    {
    	CUserCmd cmd;
    
    	// Store off the globals.. they're gonna get whacked
    	float flOldFrametime = gpGlobals->frametime;
    	float flOldCurtime = gpGlobals->curtime;
    
    	pPlayer->pl.fixangle = FIXANGLE_NONE;
    	cmd.viewangles = pPlayer->EyeAngles();
    
    	float flTimeBase = gpGlobals->curtime;
    	pPlayer->SetTimeBase( flTimeBase );
    
    	cmd.forwardmove = 200.0f;
    	cmd.sidemove = 0;
    	cmd.upmove = 0;
    	cmd.buttons = IN_JUMP;
    	cmd.impulse = 0;
    
    	if ( pPlayer->IsDead() ) // respawn dead players
    	{
    		if (RandomInt(0,1))
    			cmd.buttons = 0;
    		else
    			cmd.buttons = IN_ATTACK;
    	}
    
    	MoveHelperServer()->SetHost( pPlayer );
    	pPlayer->PlayerRunCommand( &cmd, MoveHelperServer() );
    
    	// save off the last good usercmd
    	pPlayer->SetLastUserCommand( cmd );
    
    	// Restore the globals..
    	gpGlobals->frametime = flOldFrametime;
    	gpGlobals->curtime = flOldCurtime;
    }
    
    void BotThink(CSDKPlayer* pPlayer)
    {
    	bot_t *pBot = &gBots[ engine->IndexOfEdict(pPlayer->edict()) - 1 ];
    
    	pPlayer->AddFlag( FL_FAKECLIENT );  // make sure this is set every frame
    
    	BotRunPlayerMove(pPlayer);
    }
You can just drop those 2 files into the 'dlls' folder of your Half-Life2 MOD (mine's called "MyMod"), so it would be MyMod\src\dlls\bot.h and MyMod\src\dlls\bot.cpp. Add bot.cpp to the list of source files in the Solution Explorer, build the DLLs and you can spawn a bot using "addbot" in the console.

EDIT: Opps, you also have to add...

void BotStartFrame(void);

...after line 38 of sdk_client.cpp in the dlls\sdk folder and add this...

BotStartFrame();

...at the very end of the "void GameStartFrame( void )" function in that same file (sdk_client.cpp).

botman

Last edited by botman; 28-12-2004 at 01:27..
  
Reply With Quote
Re: I don't like this!
Old
  (#13)
dub
Member
 
dub's Avatar
 
Status: Offline
Posts: 89
Join Date: Aug 2004
Location: UK
Default Re: I don't like this! - 28-12-2004

nice work botman.
P.S any news from valve about the plugin interface for bots from first impressions it seems like all the engine functions will need to be written into the plugin for a working bot.
  
Reply With Quote
Re: I don't like this!
Old
  (#14)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: I don't like this! - 28-12-2004

i just hope that valve will make a better answer then botman has, although its very nice to see how you can just use 2 files for a bot in your mod. I don't think this 'sollution' will be very fruitful.

*Edit:
Actually reading the response from nr 3, i don't think we should expect real support for bots @ plugins soon. Though, it would be great if they would make it easier for us (or even, possible).


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me

Last edited by stefanhendriks; 28-12-2004 at 19:01..
  
Reply With Quote
Re: I don't like this!
Old
  (#15)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: I don't like this! - 28-12-2004

I have mailed Alfred again; with some sort of request if he *might* have a chance to give us some more info, or some hope about any developments for bots in plugins...

Quote:
Alfred,
Thank you for your reply; i already got response on it from Bots-United members. Basicly put we are a bit concerned about bot support. I understand that bot support is a good thing, especially via documentation or alike. However, what would be most ideal is to be able to code bots, seperated from the mod source. Botman already gave us an example of 2 files you can simply put in your mod and voila, you have bots. This is not exactly what we are looking for.

I understand that bot support is not trivial for plugins right now; though i'd think the functionalities for other plugins also require some access to certain variables (cBaseEntity/Player, etc) which is hard (or impossible) at this moment. For bots itself we only need some kind of updating function, so we can pass through the results of the think routine.

A good source i can give (about this subject and our concerns) is: http://forums.bots-united.com/showth...0987#post30987
Thanks again,
===============================================
Stefan Hendriks
FunDynamic & RealBot
http://www.fundynamic.nl
http://realbot.bots-united.com
http://www.bots-united.com
===============================================


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: I don't like this!
Old
  (#16)
sfx1999
Member
 
sfx1999's Avatar
 
Status: Offline
Posts: 534
Join Date: Jan 2004
Location: Pittsburgh, PA, USA
Default Re: I don't like this! - 28-12-2004

Are you sure you can't hook it anymore? What if you hooked the interfaces, and allowed new interfaces to still go through?


sfx1999.postcount++
  
Reply With Quote
Re: I don't like this!
Old
  (#17)
botman
Super Moderator
 
Status: Offline
Posts: 280
Join Date: Jan 2004
Location: Plano, TX
Default Re: I don't like this! - 28-12-2004

You can still hook "CreateInterface" if you want to (at least until the next Steam update wipes out your custom server.dll file).

Once you have hooked "CreateInterface", you can intercept requests from the game DLL code (old server.dll) to the engine. These requests will all be wanting engine interface function pointers. If you simply return the engine interface function pointers to the game DLL code, the game DLL code will bypass your hook DLL (because the function pointers point to the engine code). You will have to substitute YOUR version of these function pointers for the engine's function pointers and pass those back to the game DLL code so that the game DLL code will call your version of the functions. This is the same as it was in Half-Life1, where you had to recreate all of the engine functions and pass the game DLL code your version of those engine functions).

This is where the difficult part comes. You have to maintain a list of ALL possible versions of the engines interface function definitions (i.e. if the engine has gone through 5 different versions of the IGameEventManager interface function, your hook code would need to support all of those versions to be compatible with different MODs). If you only wanted focus on a single MOD (say CS), you would only need to support whichever version that MOD required (updating as necessary when the MOD updates or the engine updates).

Even after doing this, you STILL don't have access to player origins and angles, because this information isn't stored in the Half-Life2 engine like it was in Half-Life1. This data is now stored in the CBaseEntity class (which you don't have access to without doing some mucking around with pointers to PrivateData).

Like I said before, if the engine is handling collisions, then some of this data is passed from the game DLL code to the engine (the origin for example), but rotation (angles) is not used in player collisions (since HL1 and HL2 use axis-aligned bounding boxes for player collision). So even if the game DLL code is telling the engine what the origin of players is, the game DLL code might not be telling the engine what the rotation (angles) currently is (since the engine doesn't need this).

Other clients, obviously DO need this, so somewhere the CBaseEntity data has to be replicated from the server game DLL to all client. Perhaps intercepting this mechanism will allow you to get at the data you need.

botman
  
Reply With Quote
Re: I don't like this!
Old
  (#18)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: I don't like this! - 29-12-2004

sounds like a big project to come , just to get bots working for HL2 as 'we' want it.

I got an answer from Alfred:

Quote:
Okay, I have found the bug in HL2MP that causes fakeclients to crash. The next HL2MP release should contain a fix (I don't have an ETA, sometime in January).

We are still working on the document describing how to make bots work (it will answer your runcommand question).

- Alfred

i sincerely hope that the document he is talking about, is sufficient for us.


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: I don't like this!
Old
  (#19)
cannonfodder
Member
 
Status: Offline
Posts: 8
Join Date: Dec 2004
Default Re: I don't like this! - 30-12-2004

I have been looking at the same sort of issue for other reasons and I'm not sure why you would need to hook the game DLL.

There must be something obvious I'm missing but when you call createfakeclient it gives you an edict and through that edict I would think you can access the csdkplayer info.

The problem I see is that to access it you need to understand the csdkplayer class which means you need the class definition for this which pretty much then requires the entire game.dll to be compiled into your server plugin. And even this isn't enough since you now need to go through the the game.dll code you added and make sure any local calls to interface functions in this code use the real interface functions into the real game.dll (since the engine won't call yours).

So am I totally off base here ?? I can't believe Valve would make it this hard, but I can't see how you can do anything without full access to the csdkplayer class.
  
Reply With Quote
Re: I don't like this!
Old
  (#20)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: I don't like this! - 30-12-2004

the problem also is, to run the command to make players move, which are game dll specific. So even if you could gain acces, you should somehow find a way to run this function.

I saw a 'hack' about this, so you can acces cBaseEntity or something, but its ugly as hell.


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com