Adding Voice Support to Quake2


 

Posted by [QBS]Quadrant (81.86.96.*) at 5:13 PM, 12/30/2002:

Hi i put this tutorial together awhile ago after adding voice support to RvR Tournament i just thought i would share this feature with you all.

To use voice support you will need Roger Wilco installed on your machine.
The way this code modification works is it will kick in your Roger wilco when you connect to the server & it will add you to the correct team channels & stuff. Hope you find this helpful.

ok so lets create two new files voice_com.c voice_com.h and add them to our project

lets start with voice_com.c please copy & paste the below code into this new file.

<C&NBSP;CODE>
#include "..\g_local.h"

#include <windows.h>//[QBS]VOICE

BOOL SendCommandToRogerWilco( const char* cmd )
{
  HKEY    hKey = 0;
  char    commandLine[MAX_PATH];
  DWORD    len = MAX_PATH;
  UINT    r = 0;

  if( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
    "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\roger.exe",
    0, KEY_QUERY_VALUE, &hKey ) != ERROR_SUCCESS )
  {
    return FALSE;
  }
  if( RegQueryValueEx( hKey, NULL, NULL, NULL, commandLine, &len ) != ERROR_SUCCESS )
  {
    RegCloseKey(hKey);
    return FALSE;
  }
  RegCloseKey(hKey);

  strcat( commandLine, " " );
  strcat( commandLine, cmd );

  /*
   * Replace the SW_SHOWMINNOACTIVE if you want Roger Wilco
   * to pop to the front; SHOWMINNOACTIVE will keep it hidden
   * (minimized and not active)
   */
  r = WinExec( commandLine, SW_SHOWMINNOACTIVE );
  if( r < 31 ) return FALSE;  // Error of some sort.

  return TRUE;  // Sent OK.
}

//==

BOOL DetuneRogerWilco(const char *channel_name)
{
  char cmd[512];

  if (!(*channel_name))
    channel_name = "";

  sprintf(cmd, "/leave %s", channel_name);

  return SendCommandToRogerWilco(cmd);
}

//==

BOOL CreateRogerWilcoChannel(const char *channel_name, const char *passwd)
{
  char cmd[512];

  if (!(*channel_name))
    channel_name = "DEFAULT";

  sprintf(cmd, "/create %s %s", channel_name, passwd);

  return SendCommandToRogerWilco(cmd);
}

//==

BOOL JoinRogerWilcoChannel(const char *host_ip, const char *channel_name, const char *passwd)
{
  char cmd[512];

  if (!stricmp(channel_name, "DEFAULT"))
    channel_name = "";
  sprintf(cmd, "/join1 %s/%s %s", host_ip, channel_name, passwd);

  return SendCommandToRogerWilco(cmd);
}

//==

/* 
   full-screen apps that want to ensure that Roger Wilco's window never pops up
   over their initialized full-screenb graphics screen should call this prior to 
   opening their main window or switching into a full-screen mode.  
 
   This gives Roger Wilco a chance to make sure that it has opened its window and
   gotten onto the desktop, and ensures that any graphics mode switches and window opens
   that the integrating app performs will not be un-done by Roger Wilco

*/
BOOL StartRogerWilco()
{
  // if you wanted to verify that they had installed Roger Wilco, you could do this here
  // by looking under HKEY_LOCAL_MACHINE for 
  // Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\roger.exe

  BOOL retval = SendCommandToRogerWilco("");
  Sleep(2000);

  // if you wanted to verify the version of Roger Wilco they are using, you could examine
  // HKEY_CURRENT_USER for "Software\\Resounding\\Roger Wilco\\version_name

  return retval;
}

//==

ok that the end of us adding code to that file so next lets create the header file for the above so lets add the below code to voice_com.h

#include <windows.h>//[QBS]VOICE
BOOL SendCommandToRogerWilco( const char* cmd );
BOOL DetuneRogerWilco(const char *channel_name);
BOOL CreateRogerWilcoChannel(const char *channel_name, const char *passwd);
BOOL JoinRogerWilcoChannel(const char *host_ip, const char *channel_name, const char *passwd);
BOOL StartRogerWilco();


OK thats both files done next lets intergrate these new functions into the Gamex86.dll

First we will need to start roger wilco up

in file g_save.c

at the start of function InitGame

just below line   gi.dprintf ("==== InitGame ====\n");

lets add this new piece of code 

//[QBS]s VOICE
  gi.dprintf ("==== Init Voice Server ====\n");
  StartRogerWilco();
  CreateRogerWilcoChannel("my_channel",0);// decide on a channel name for the server
  JoinRogerWilcoChannel(0,"my_channel",0);
  SendCommandToRogerWilco("/vox");
  SendCommandToRogerWilco("/clicks on");
  gi.dprintf ("==== Voice Server Ready ====\n");
//[QBS]e

ok you can now close g_save.c we have finished with that file now.
ok we now have it so that when you run a server now it will start up roger wilco and create a channel called my_channel we now need to get it to join players to the chat channel when they connect to the server etc you can even get it to join a player to specific channels for each team you decide.. ok lets go next bit..
 
in file p_client.c function ClientConnect

at the very bottom just before the last return true.

lets start the clients roger wilco up and get the to connect to the quake2 servers roger wilco and the correct channel

mmmm here i guess you could move the second line of the below to where in your code you are choosing the player class or team etc you could have it connect to the correct channel for there team then etc ??? other wise the below would be fine if its one channel for everyone..

//[QBS]s VOICE   client
  StartRogerWilco();
  JoinRogerWilcoChannel("127.0.0.1","rvr",0);//mmm need to get server ip here
//[QBS]e

then last thing in g_main.c the server needs to close down the roger wilco when its no longer needed by the server we do this in ShutdownGame

just below gi.dprintf ("==== ShutdownGame ====\n");

lets add code to close down roger wilco

//[QBS]s VOICE
  gi.dprintf ("==== Voice Server Shutdown ====\n");
  SendCommandToRogerWilco("/shutdown");
//[QBS]e


That should be most of what you need to add voice support to your mod, you just need to add code that server side loads a cvar with the server ip or something then get it to put that ip value into the line when it logs the player into a channel other wise its not going to know the ip of the server running the rogerwilco or if you want the roger wilco server to be running on another ip to the quake2 server you could hardcode the ip thats what ive done with mine hense the code not being there to grab ip from server..

ok bye for now hope someone at least finds this of interest</C&NBSP;CODE>

 


Link: QuadEngine 2001 2D\3D Engine