Previous Blog Next Blog
Prev/Next Blog
by date

X-Fire Integration continued

X-Fire Integration continued
Name:James Thompson 
Date Posted:May 29, 2006
Rating:2.0 out of 5
Public:YES
Comments:YES
RSS Feed:GarageGames Blog feedor Subscribe with .
Profile Page:View profile page for James Thompson

Blog post
X-Fire is now working in my game (at least I think it is, I have no way of testing it right now)

I can get it to compile and start missions, so I think its all good ;)

Code says it all so here goes (once I have tested it this will go up as a resource):

New File (game/net/xfire.cc)

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <tlhelp32.h>

#include "xfire.h"

static HMODULE g_toucan_dll = NULL;
static void HelperInit();
static HMODULE HelperGetToucanDLL();

typedef int (*XfireSetCustomGameDataWFunction)(int , const wchar_t **, const wchar_t **);

static XfireSetCustomGameDataWFunction ptr_XfireSetCustomGameDataW = NULL;

/* make sure we are going to call the ANSI version */
#ifdef MODULEENTRY32
#undef MODULEENTRY32
#endif

#ifdef Module32First
#undef Module32First
#endif

#ifdef Module32Next
#undef Module32Next
#endif


int XfireIsLoaded()
{
HelperInit();
if (ptr_XfireSetCustomGameDataW)
return 1;
return 0;
}

int XfireSetCustomGameDataW(int num_keys, const wchar_t **keys, const wchar_t **values)
{
HelperInit();
if (ptr_XfireSetCustomGameDataW)
return ptr_XfireSetCustomGameDataW(num_keys, keys, values);
return 1;
}

/* ------------------------------------------------------------------------- */
static void HelperInit()
{
if (!ptr_XfireSetCustomGameDataW)
{
HMODULE toucan_dll = HelperGetToucanDLL();
if (toucan_dll)
{
ptr_XfireSetCustomGameDataW = (XfireSetCustomGameDataWFunction)::GetProcAddress(toucan_dll, "ToucanSendGameClientDataW_V1");
}
}
}


static HMODULE HelperGetToucanDLL()
{
if (g_toucan_dll)
return g_toucan_dll;

/*
** We need to enumerate the DLLs loaded to find toucan dll.
** This is done because the toucan dll changes with each update.
** The toucan dll has the following format. "xfire_toucan_{BUILD_NUMBER}.dll"
** We simply try to find a dll w/ the prefix "xfire_toucan"
*/
HANDLE snapshot_handle = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId());
if (snapshot_handle != INVALID_HANDLE_VALUE)
{
MODULEENTRY32 module_entry;
module_entry.dwSize = sizeof(MODULEENTRY32);

BOOL result = Module32First(snapshot_handle, &module_entry);
char module_name[] = "xfire_toucan";
DWORD module_name_len = sizeof(module_name)-1;
while (result)
{
if (CompareStringA(LOCALE_USER_DEFAULT, NORM_IGNORECASE, module_entry.szModule, module_name_len, module_name, module_name_len) == CSTR_EQUAL)
{
g_toucan_dll = module_entry.hModule;
break;
}
result = Module32Next(snapshot_handle, &module_entry);
}

CloseHandle(snapshot_handle);
}

return g_toucan_dll;
}

That contains some unessesary stuff i think

New File (game/net/xfire.h)

#ifndef __XFIREGAMECLIENT_H__
#define __XFIREGAMECLIENT_H__

#ifdef __cplusplus
extern "C" {
#endif

/*
** XfireIsLoaded()
**
** returns 1 if application can talk to Xfire, 0 otherwise
*/
int XfireIsLoaded();

/*
** XfireSetCustomGameDataA()
**
** UNICODE version to tell xfire of custom game data
*/
int XfireSetCustomGameDataW(int num_keys, const wchar_t **keys, const wchar_t **values);

#define XfireSetCustomGameData XfireSetCustomGameDataW

#ifdef __cplusplus
}
#endif

#endif /* __XFIREGAMECLIENT_H__ */


That probably has some unnecessary stuff too

Now In player.cc

   //-----------------------------------------------------
// X-Fire
//-----------------------------------------------------
#include "game/net/xfire.h"
//-----------------------------------------------------
// X-Fire
//-----------------------------------------------------



// Anchor point compression
const F32 sAnchorMaxDistance = 32;

//-----------------------------------------------------
// X-Fire
//-----------------------------------------------------
const char *key[100],*value[100];
//-----------------------------------------------------
// X-Fire
//-----------------------------------------------------



bool Player::onAdd()
{
//-----------------------------------------------------
// X-Fire
//-----------------------------------------------------
key[0] = "Status";
value[0] = "Playing";
//-----------------------------------------------------
// X-Fire
//-----------------------------------------------------



Theres a lot more, but that is the basic idea, like I said when I have it all together and i've tested it I will submit it as a resource

Recent Blog Posts
List:11/04/06 - DOM, SG and future resources
10/01/06 - Progress on various things
09/02/06 - DawnOfMen & me
07/01/06 - DawnOfMen Alpha Progress
06/25/06 - DawnOfMen Alpha Release
06/18/06 - RSS
06/05/06 - DawnOfMen 0.8
05/29/06 - X-Fire Integration continued

Submit ResourceSubmit your own resources!

James Thompson   (May 29, 2006 at 18:54 GMT)
Thinking about it I don't need the
ifdef unicode
stuff, it will be defined in 1.4

Updated blog to take out non-unicode stuff

Could you please tell me how bad my coding is and what (if anything) I've done wrong
Edited on May 29, 2006 19:06 GMT

Joseph Euan   (May 29, 2006 at 19:14 GMT)
Have you got you're game showing up on the xfire list?

James Thompson   (May 29, 2006 at 19:16 GMT)
Yes
Edited on May 29, 2006 22:03 GMT

Mincetro   (May 30, 2006 at 09:42 GMT)
Nice work...
I'll try this out sometime
DHL:I should have this ;)
Edited on May 30, 2006 09:43 GMT

James Thompson   (May 30, 2006 at 10:24 GMT)
Er this isnt the complete list of changes nor will your game show up in xfire, it is a starter to get you going

You must be a member and be logged in to either append comments or rate this resource.