author | nemo |
Wed, 28 Oct 2015 10:01:31 -0400 | |
changeset 11255 | 66796cd627d8 |
parent 8440 | ea4d6a7a2937 |
permissions | -rw-r--r-- |
2920 | 1 |
/* This file is NOT open source. See "license.txt" to read the full license provided with the Xfire SDK. */ |
2830 | 2 |
|
3 |
#define WIN32_LEAN_AND_MEAN |
|
4 |
#include <windows.h> |
|
5 |
#include <tlhelp32.h> |
|
6 |
||
7 |
#include "xfiregameclient.h" |
|
8 |
||
9 |
static HMODULE g_toucan_dll = NULL; |
|
10 |
static void HelperInit(); |
|
11 |
static HMODULE HelperGetToucanDLL(); |
|
12 |
||
13 |
typedef int (*XfireSetCustomGameDataAFunction)(int , const char **, const char **); |
|
14 |
typedef int (*XfireSetCustomGameDataWFunction)(int , const wchar_t **, const wchar_t **); |
|
15 |
typedef int (*XfireSetCustomGameDataUTF8Function)(int , const char **, const char **); |
|
16 |
||
17 |
static XfireSetCustomGameDataAFunction ptr_XfireSetCustomGameDataA = NULL; |
|
18 |
static XfireSetCustomGameDataWFunction ptr_XfireSetCustomGameDataW = NULL; |
|
19 |
static XfireSetCustomGameDataUTF8Function ptr_XfireSetCustomGameDataUTF8 = NULL; |
|
20 |
||
21 |
/* make sure we are going to call the ANSI version */ |
|
22 |
#ifdef MODULEENTRY32 |
|
23 |
#undef MODULEENTRY32 |
|
24 |
#endif |
|
25 |
||
26 |
#ifdef Module32First |
|
27 |
#undef Module32First |
|
28 |
#endif |
|
29 |
||
30 |
#ifdef Module32Next |
|
31 |
#undef Module32Next |
|
3697 | 32 |
#endif |
2830 | 33 |
|
34 |
||
35 |
int XfireIsLoaded() |
|
36 |
{ |
|
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
37 |
HelperInit(); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
38 |
if (ptr_XfireSetCustomGameDataA && |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
39 |
ptr_XfireSetCustomGameDataW && |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
40 |
ptr_XfireSetCustomGameDataUTF8) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
41 |
return 1; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
42 |
return 0; |
2830 | 43 |
} |
44 |
||
45 |
int XfireSetCustomGameDataA(int num_keys, const char **keys, const char **values) |
|
46 |
{ |
|
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
47 |
HelperInit(); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
48 |
if (ptr_XfireSetCustomGameDataA) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
49 |
return ptr_XfireSetCustomGameDataA(num_keys, keys, values); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
50 |
return 1; |
2830 | 51 |
} |
52 |
||
53 |
int XfireSetCustomGameDataW(int num_keys, const wchar_t **keys, const wchar_t **values) |
|
54 |
{ |
|
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
55 |
HelperInit(); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
56 |
if (ptr_XfireSetCustomGameDataW) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
57 |
return ptr_XfireSetCustomGameDataW(num_keys, keys, values); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
58 |
return 1; |
2830 | 59 |
} |
60 |
||
61 |
int XfireSetCustomGameDataUTF8(int num_keys, const char **keys, const char **values) |
|
62 |
{ |
|
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
63 |
HelperInit(); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
64 |
if (ptr_XfireSetCustomGameDataUTF8) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
65 |
return ptr_XfireSetCustomGameDataUTF8(num_keys, keys, values); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
66 |
return 1; |
2830 | 67 |
} |
68 |
||
69 |
/* ------------------------------------------------------------------------- */ |
|
70 |
static void HelperInit() |
|
71 |
{ |
|
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
72 |
if (!ptr_XfireSetCustomGameDataA || |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
73 |
!ptr_XfireSetCustomGameDataW || |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
74 |
!ptr_XfireSetCustomGameDataUTF8) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
75 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
76 |
HMODULE toucan_dll = HelperGetToucanDLL(); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
77 |
if (toucan_dll) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
78 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
79 |
ptr_XfireSetCustomGameDataA = (XfireSetCustomGameDataAFunction)::GetProcAddress(toucan_dll, "ToucanSendGameClientDataA_V1"); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
80 |
ptr_XfireSetCustomGameDataW = (XfireSetCustomGameDataWFunction)::GetProcAddress(toucan_dll, "ToucanSendGameClientDataW_V1"); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
81 |
ptr_XfireSetCustomGameDataUTF8 = (XfireSetCustomGameDataUTF8Function)::GetProcAddress(toucan_dll, "ToucanSendGameClientDataUTF8_V1"); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
82 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
83 |
} |
2830 | 84 |
} |
85 |
||
86 |
||
87 |
static HMODULE HelperGetToucanDLL() |
|
88 |
{ |
|
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
89 |
if (g_toucan_dll) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
90 |
return g_toucan_dll; |
2830 | 91 |
|
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
92 |
/* |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
93 |
** We need to enumerate the DLLs loaded to find toucan dll. |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
94 |
** This is done because the toucan dll changes with each update. |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
95 |
** The toucan dll has the following format. "xfire_toucan_{BUILD_NUMBER}.dll" |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
96 |
** We simply try to find a dll w/ the prefix "xfire_toucan" |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
97 |
*/ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
98 |
HANDLE snapshot_handle = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId()); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
99 |
if (snapshot_handle != INVALID_HANDLE_VALUE) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
100 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
101 |
MODULEENTRY32 module_entry; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
102 |
module_entry.dwSize = sizeof(MODULEENTRY32); |
2830 | 103 |
|
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
104 |
BOOL result = Module32First(snapshot_handle, &module_entry); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
105 |
char module_name[] = "xfire_toucan"; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
106 |
DWORD module_name_len = sizeof(module_name)-1; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
107 |
while (result) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
108 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
109 |
if (CompareStringA(LOCALE_USER_DEFAULT, NORM_IGNORECASE, module_entry.szModule, module_name_len, module_name, module_name_len) == CSTR_EQUAL) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
110 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
111 |
g_toucan_dll = module_entry.hModule; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
112 |
break; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
113 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
114 |
result = Module32Next(snapshot_handle, &module_entry); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
115 |
} |
2830 | 116 |
|
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
117 |
CloseHandle(snapshot_handle); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
118 |
} |
2830 | 119 |
|
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
120 |
return g_toucan_dll; |
2920 | 121 |
} |