.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Bot Coding (http://forums.bots-united.com/forumdisplay.php?f=24)
-   -   new CS update screws up intercepting chat messages!? (http://forums.bots-united.com/showthread.php?t=1978)

stefanhendriks 15-06-2004 11:48

new CS update screws up intercepting chat messages!?
 
Hey guys,

I upgraded my CS version today on STEAM. Ran my bot, everything is fine. I say something to my bot... and BAM. it crashes

Code:

void BotClient_CS_SayText(void *p, int bot_index)
{
static unsigned char ucEntIndex;
static int state = 0; // current state machine state
if (state == 0)
{
ucEntIndex = *(unsigned char *)p;
}
else if (state == 1)
{
cBot *pBot=&bots[bot_index];
if(ENTINDEX(pBot->pEdict) != ucEntIndex)
{
char sentence[80];
char chSentence[80];
char netname[30];
memset (sentence, 0, sizeof (sentence));
memset (chSentence, 0, sizeof (chSentence));
memset (netname, 0, sizeof (netname));
 
strcpy(sentence,(char *)p);
// remove first part of sentence.
int length = strlen (sentence) - strlen (strstr (sentence, " : "));
 
int tc=0;
int c;
for (c=length; c < 80; c++)
{
        chSentence[tc] = sentence[c];
        tc++;
}
//strncpy (chSentence, (char *)sentence[length], 80-length);
//strcpy(netname, STRING(pBot->pEdict->v.netname));
//strcpy(netname, sentence, strlen(strstr(sentence, " : "));
 
int nc=0;
c=2;
if (strstr(sentence, "*DEAD*"))
        c+= 6;
 
if (counterstrike == 0)
        c=1;
for (c; c < length; c++)
{
        netname[nc] = sentence[c];
        nc++;
}
ChatEngine.set_sentence(netname, chSentence);
state = -1;
}
}
state++;
}

this is the code i used, and it worked fine.

Even when my bots are not supposed to chat, and i type a message there is something going horribly wrong.

I am not sure WHERE it crashes as all i get is a 'read' error and no specific indications from CS/HL.EXE

edit:
i have sent cliffe a mail about this, i hope he responds at all... and if he does, with something that can help us out.

minorgod 15-06-2004 22:51

Re: new CS update screws up intercepting chat messages!?
 
Glad it's not just me! I'm getting the exact same behavior with the latest CVS update. I'm getting a segfault whenever I try to chat. I have no clue why, but I thought it might be a Linux-only problem. Guess it could be steam, but I didn't notice the problem until I updated and recompiled from the latest CVS. I was going to try a rollback, but I didn't save the previous version.

stefanhendriks 16-06-2004 11:02

Re: new CS update screws up intercepting chat messages!?
 
well, as soon asi disable catching this message in my code, everything runs fine. So its definatly something wrong there.

Also Cheating-Death does not work with this CS anymore (ver 4.22.0), so i guess they DID change something.. i still have no word of Cliffe. Dammit

Whistler 16-06-2004 11:08

Re: new CS update screws up intercepting chat messages!?
 
perhaps it's because of strcpy(). try using strncpy() instead.

stefanhendriks 16-06-2004 11:17

Re: new CS update screws up intercepting chat messages!?
 
Whistler, i can try that, but i don't think it will work. As i said, the code *worked* already, until the new CS update came around.

Too bad i threw out that engine interception stuff of Botman to figure out how engine messages are build up. Now i have to regrab that code or something. I think they have changed the chat message handler, perhaps a state more or less.

Perhaps you are right and something is wrong with my code, although it worked perfectly before. Anyway, gtg check it out.

Pierre-Marie Baty 16-06-2004 14:10

Re: new CS update screws up intercepting chat messages!?
 
Message interception still seem to work fine here with my bot...
I'd advise to rewrite this function in a cleaner way anyway. And don't start reading the message at the first character, since the first character has always been a non-printable formatting character (color code).

stefanhendriks 16-06-2004 15:28

Re: new CS update screws up intercepting chat messages!?
 
@PMB;

I have added lots of debug lines, and guess what. The format HAS changed. Instead of sending the actual chat string when state = 1. I now get a string saying for "WHO" it is...

ie, in CS 1.5 my debug lines say:
Quote:

------State=0------
Passed
------State=1------
Dunno
Passed memset
Copied string
Length check of sentence:'Dumb : hello
'
Going to find : in the sentence...Found!
------END state=1------

and in CS 1.6, the same situation, same chat sentence, says:
Quote:

------State=0------
Passed
------State=1------
Dunno
Passed memset
Copied string
Length check of sentence:'#Cstrike_Chat_All'
Going to find : in the sentence...Not found!
------END state=1------
------State=0------
Passed
------State=1------
Dunno
Passed memset
Copied string
Length check of sentence:'hello
'
Going to find : in the sentence...Not found!
------END state=1------
Notice that in CS 1.6 the chat message gets sent TWICE?

So yes, you are correct in CS 1.5 and former CS 1.6 (former=before 14th june) you could do this. I bet they DID change in CS 1.6 the format... perhaps in 4 or maybe 5 states.. something like:

state=0 remains same
state=1 for who?
state=2 sentence
state=3 netname who sent message?

i gtg figure this out soon.

EDIT:
what crashed my code was that strstr did NOT find ":" in the new sentence of CS 1.6, therefor returning NULL to strlen, which caused a crash...

stefanhendriks 16-06-2004 16:06

Re: new CS update screws up intercepting chat messages!?
 
I had to reimplement the engine debugging stuff, but eventually i got what i wanted:

Quote:

ENGINE: pfnMessageBegin(), dest=1, msg_type=76
ENGINE: pfnWriteByte() - '1'
ENGINE: pfnWriteByte() - '#Cstrike_Chat_All'
ENGINE: pfnWriteByte() - ''
ENGINE: pfnWriteByte() - 'hello everybody
'
ENGINE: pfnMessageEnd()
I guess its all you need:
1 is entity index
2 some flag, so ya know to who and what, etc
3 don't know
4 the actual sentence

stefanhendriks 16-06-2004 16:27

Re: new CS update screws up intercepting chat messages!?
 
okay, i have fixed my bug. Here is my code now:

Code:

void BotClient_CS_SayText(void *p, int bot_index)
{
 static unsigned char ucEntIndex;
 static int state = 0;  // current state machine state
 // Different Counter-Strike versions mean different
 // handling of this "SayText" thingy.
 if (counterstrike==0)
 {
  if (state == 0)
  {
  ucEntIndex = *(unsigned char *)p;
  }
  else if (state == 1)
  { 
  cBot *pBot=&bots[bot_index];
 
  if (ENTINDEX(pBot->pEdict) != ucEntIndex)
  {
        log("Dunno\n");
        char sentence[80];
        char chSentence[80];
        char netname[30]; 
        memset (sentence, 0, sizeof (sentence));
        memset (chSentence, 0, sizeof (chSentence));
        memset (netname, 0, sizeof (netname));
               
        strcpy(sentence,(char *)p);
                 
        int length=0;
        // FIXED: In any case that this might return NULL, do not crash the server
        if (strstr (sentence, " : "))
        length = strlen (sentence) - strlen (strstr (sentence, " : "));
       
        int tc=0,c;
        for (c=length; c < 80; c++)
        {
        chSentence[tc] = sentence[c];
        tc++;
        }
        edict_t *pPlayer = INDEXENT (ucEntIndex);
        strcpy(netname, STRING(pPlayer->v.netname));
        ChatEngine.set_sentence(netname, chSentence);
        state = -1;
  }
  }
 }
 else if (counterstrike==1)
 {
  // CS 1.6
  if (state == 0)
  {
  // who sent this message?
  ucEntIndex = *(unsigned char *)p;
  }
  // to who?
  else if (state == 1)
  {
  // here must be some team check so we do not let bots
  // of the other team react to this somehow..
 
  }
  // don't know?
  else if (state == 2)
  {
  // do nothing here
  }
  // the actual sentence
  else if (state == 3)
  {
  // sentence
  char sentence[80];
  char netname[30]; 
       
  // init
  memset (sentence, 0, sizeof (sentence));
  memset (netname, 0, sizeof (netname));
 
  // copy in memory
  strcpy(sentence,(char *)p);
  // copy netname
  edict_t *pPlayer = INDEXENT (ucEntIndex);
  strcpy(netname, STRING(pPlayer->v.netname));
 
  // and give chatengine something to do
  ChatEngine.set_sentence(netname, sentence);
  state=-1;
  }
 }
 state++;
}

note, it still needs to be optimized so that bots do NOT hear you when you are talking on team messages and such, but that should not be a real problem. Its just a bit of comparing strings "#Cstrike_Chat_All" and such. I might post an update of my source when that works too ;)

Pierre-Marie Baty 16-06-2004 20:07

Re: new CS update screws up intercepting chat messages!?
 
Thanks for the fix! It simplified this part of my code a LOT. :)


All times are GMT +2. The time now is 12:47.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.