OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
gsPlatform.h
1
3#ifndef __GSPLATFORM_H__
4#define __GSPLATFORM_H__
5
6// GameSpy platform definition and headers
7
8// Windows: _WIN32
9// Xbox: _WIN32 + _XBOX
10// Xbox360: _WIN32 + _XBOX + _X360
11// MacOSX: _MACOSX + _UNIX + __APPLE__
12// Linux: _LINUX + _UNIX
13// Nintendo DS: _NITRO
14// PSP: _PSP
15// PS3: _PS3
16
17// PlayStation2: _PS2
18// w/ EENET: EENET (set by developer project)
19// w/ INSOCK: INSOCK (set by developer project)
20// w/ SNSYSTEMS: SN_SYSTEMS (set by developer project)
21// Codewarrior: __MWERKS__
22
25// Set the platform define
26#if defined (__linux__) || defined(_LINUX) || defined(_MACOSX) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
27 #define _UNIX
28#elif __mips64
29 #ifndef _PS2
30 #define _PS2
31 #endif
32
33 // Make sure a network stack was defined
34 #if !defined(SN_SYSTEMS) && !defined(EENET) && !defined(INSOCK)
35 #error "PlayStation2 network stack was not defined!"
36 #endif
37#endif
38
39#if defined(_XBOX) || defined (_X360)
40#if _XBOX_VER >= 200
41 #define _X360
42#endif
43#endif
44
45// WIN32, set by OS headers
46// _XBOX, set by OS headers
47// __MWERKS__, set by compiler
48// _NITRO, set by OS headers
49
50
53// Include common OS headers
54#include <string.h>
55#include <stdlib.h>
56#include <stdio.h>
57#include <wchar.h>
58
59
60// XBOX/X360
61#if defined(_XBOX)
62 #include <Xtl.h>
63
64// WIN32
65#elif defined(_WIN32)
66 #define WIN32_LEAN_AND_MEAN
67 #include <windows.h>
68 #include <limits.h>
69 #include <time.h>
70
71 #if defined(GSI_WINSOCK2)
72 #include <winsock2.h>
73 #else
74 #include <winsock.h>
75 #endif
76
77 #if (_MSC_VER > 1300)
78 #define itoa(v, s, r) _itoa(v, s, r)
79 #endif
80// PS2
81#elif defined(_PS2)
82 // EENet headers must be included before common PS2 headers
83 #ifdef EENET
84 #include <libeenet.h>
85 #include <eenetctl.h>
86 #include <ifaddrs.h>
87 #include <sys/socket.h>
88 #include <sys/errno.h>
89 #include <netinet/in.h>
90 #include <arpa/inet.h>
91 #include <net/if.h>
92 #include <sys/select.h>
93 #include <malloc.h>
94
95 #endif // EENET
96
97 // Common PS2 headers
98 #include <eekernel.h>
99 #include <stdio.h>
100 #include <malloc.h>
101 #include <sifdev.h>
102 #include <sifrpc.h>
103 #include <sifcmd.h>
104 #include <ilink.h>
105 #include <ilsock.h>
106 #include <ilsocksf.h>
107 #include <limits.h>
108
109 #ifdef SN_SYSTEMS
110 // undefine socket defines from sys/types.h
111 // This is to workaround sony now automatically including sys/types.h
112 // and SNSystems having not produce a patch yet (they'll likely do the same since
113 // the SNSystems fd_set is a slightly different size than the sys/types.h.
114 #undef FD_CLR
115 #undef FD_ZERO
116 #undef FD_SET
117 #undef FD_ISSET
118 #undef FD_SETSIZE
119 #undef fd_set
120 #include "snskdefs.h"
121 #include "sntypes.h"
122 #include "snsocket.h"
123 #include "sneeutil.h"
124 #include "sntcutil.h"
125 #endif // SN_SYSTEMS
126
127 #ifdef INSOCK
128 #include "libinsck.h"
129 #include "libnet.h"
130 #include "sys/errno.h"
131 //#include "libmrpc.h"
132 #endif // INSOCK
133
134// LINUX and MACOSX
135#elif defined(_UNIX)
136 #include <unistd.h>
137 #include <sys/types.h>
138 #include <sys/socket.h>
139 #include <stdio.h>
140 #include <sys/types.h>
141 #include <sys/socket.h>
142 #include <sys/ioctl.h>
143 #include <netinet/in.h>
144
145 // MACOSX Warning!! netdb.h has it's own NOFILE define.
146 // GameSpy uses NOFILE to determine if an HD is available
147 #ifndef NOFILE
148 // Since GameSpy NOFILE is not defined, include netdb.h then undef NOFILE
149 #include <netdb.h>
150 #undef NOFILE
151 #else
152 // Otherwise leave NOFILE defined
153 #include <netdb.h>
154 #endif
155
156 #include <arpa/inet.h>
157 #include <errno.h>
158 #include <sys/time.h>
159 #include <limits.h>
160 //#include <sys/syslimits.h>
161 #include <netinet/tcp.h>
162
163 // ICMP ping support is unsupported on Linux/MacOSX due to needing super-user access for raw sockets
164 #define SB_NO_ICMP_SUPPORT
165
166// Nintendo DS
167#elif defined(_NITRO)
168 #include <nitro.h>
169 #define NINET_NWBASE_MD5_H_ // resolves md5 conflicts
170 #include <nitroWiFi.h>
171 #include <extras.h> // mwerks
172 #include <limits.h>
173
174 // Raw sockets are undefined on Nitro
175 #define SB_NO_ICMP_SUPPORT
176
177// Sony PSP
178#elif defined(_PSP)
179 #include <kernel.h>
180 #include <pspnet.h>
181 #include <pspnet_error.h>
182 #include <pspnet_inet.h>
183 #include <pspnet/sys/select.h>
184 #include <pspnet_resolver.h>
185 #include <pspnet_apctl.h>
186 #include <pspnet_ap_dialog_dummy.h>
187 #include <rtcsvc.h>
188 #include <errno.h>
189 #include <wlan.h>
190
191 #include <pspnet/sys/socket.h>
192 #include <pspnet/netinet/in.h>
193 #include <utility\utility_common.h>
194 #include <utility\utility_netconf.h>
195 #include <utility\utility_module.h>
196// PS3
197#elif defined(_PS3)
198#include <netex/errno.h>
199 #include <sys/process.h>
200 #include <sys/time.h>
201 #include <sys/types.h>
202 #include <sys/select.h>
203 #include <sys/socket.h>
204 #include <sys/sys_time.h>
205 #include <sys/timer.h>
206 #include <errno.h>
207 #include <netdb.h>
208 #include <netinet/in.h>
209 #include <arpa/inet.h>
210 #include <netex/net.h>
211 #include <netex/ifctl.h>
212// #include <netex/netset.h>
213 #include <limits.h>
214 #include <time.h>
215
216// Nintendo Wii
217#elif defined(_REVOLUTION)
218 #include <revolution.h>
219 #include <revolution/soex.h>
220 #include <revolution/ncd.h>
221 #include <limits.h>
222
223 // Raw sockets are undefined on Revolution
224 #define SB_NO_ICMP_SUPPORT
225
226// Unsupported platform or no platform defined!
227#else
228 #error "The GameSpy SDKs do not support this operating system"
229
230#endif //(platform switch)
231
232
233
234//---------- __cdecl fix for __fastcall conventions ----------
235#if defined(_WIN32)
236 #define GS_STATIC_CALLBACK __cdecl
237#else
238 #define GS_STATIC_CALLBACK
239#endif
240
241
242//---------- Handle Endianess ----------------------
243#if defined(_PS3) || defined(_REVOLUTION) || defined(_X360) //defined(_MACOSX)
244 #define GSI_BIG_ENDIAN
245#endif
246#ifndef GSI_BIG_ENDIAN
247 #define GSI_LITTLE_ENDIAN
248#endif
249
250
251
252#include <ctype.h>
253
254#if defined(_MACOSX)
255 #undef _T
256#endif
257
258#include <assert.h>
259
260#if defined(GS_NO_FILE) || defined(_PS2) || defined(_PS3) || defined(_NITRO) || defined(_PSP) || defined(_XBOX)
261 #define NOFILE
262#endif
263
264#if defined(_PSP) || defined(_NITRO)
265 #define GS_WIRELESS_DEVICE
266#endif
267
268#if !defined(GSI_DOMAIN_NAME)
269 #define GSI_DOMAIN_NAME "gamespy.com"
270#endif
271
272
275// Define GameSpy types
276
277// common base type defines, please refer to ranges below when porting
278typedef char gsi_i8;
279typedef unsigned char gsi_u8;
280typedef short gsi_i16;
281typedef unsigned short gsi_u16;
282typedef int gsi_i32;
283typedef unsigned int gsi_u32;
284typedef unsigned int gsi_time; // must be 32 bits
285
286// decprecated
287typedef gsi_i32 goa_int32; // 2003.Oct.04.JED - typename deprecated
288typedef gsi_u32 goa_uint32; // these types will be removed once all SDK's are updated
289
290typedef int gsi_bool;
291#define gsi_false ((gsi_bool)0)
292#define gsi_true ((gsi_bool)1)
293#define gsi_is_false(x) ((x) == gsi_false)
294#define gsi_is_true(x) ((x) != gsi_false)
295
296// Max integer size
297#if defined(_INTEGRAL_MAX_BITS) && !defined(GSI_MAX_INTEGRAL_BITS)
298 #define GSI_MAX_INTEGRAL_BITS _INTEGRAL_MAX_BITS
299#else
300 #define GSI_MAX_INTEGRAL_BITS 32
301#endif
302
303// Platform dependent types
304#ifdef _PS2
305 typedef signed long gsi_i64;
306 typedef unsigned long gsi_u64;
307#elif defined(_WIN32)
308 #if (!defined(_M_IX86) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64))
309 typedef __int64 gsi_i64;
310 typedef unsigned __int64 gsi_u64;
311 #endif
312#elif defined(_NITRO)
313 typedef s64 gsi_i64;
314 typedef u64 gsi_u64;
315#elif defined (_PSP)
316 typedef long long gsi_i64;
317 typedef unsigned long long gsi_u64;
318#elif defined (_PS3)
319 typedef int64_t gsi_i64;
320 typedef uint64_t gsi_u64;
321#elif defined (_REVOLUTION)
322 typedef signed long long gsi_i64;
323 typedef unsigned long long gsi_u64;
324#else /* _UNIX */
325 typedef long long gsi_i64;
326 typedef unsigned long long gsi_u64;
327#endif // 64 bit types
328
329#ifndef GSI_UNICODE
330 #define gsi_char char
331#else
332 #define gsi_char unsigned short
333#endif // goa_char
334
335
336// expected ranges for integer types
337#define GSI_MIN_I8 CHAR_MIN
338#define GSI_MAX_I8 CHAR_MAX
339#define GSI_MAX_U8 UCHAR_MAX
340
341#define GSI_MIN_I16 SHRT_MIN
342#define GSI_MAX_I16 SHRT_MAX
343#define GSI_MAX_U16 USHRT_MAX
344
345#define GSI_MIN_I32 INT_MIN
346#define GSI_MAX_I32 INT_MAX
347#define GSI_MAX_U32 UINT_MAX
348
349#if (GSI_MAX_INTEGRAL_BITS >= 64)
350#define GSI_MIN_I64 (-9223372036854775807 - 1)
351#define GSI_MAX_I64 9223372036854775807
352#define GSI_MAX_U64 0xffffffffffffffffui64
353#endif
354
355#ifdef __cplusplus
356extern "C" {
357#endif
358
361// Common platform string functions
362#undef _vftprintf
363#undef _ftprintf
364#undef _stprintf
365#undef _tprintf
366#undef _tcscpy
367#undef _tcsncpy
368#undef _tcscat
369#undef _tcslen
370#undef _tcschr
371#undef _tcscmp
372#undef _tfopen
373#undef _T
374#undef _tsnprintf
375
376#ifdef GSI_UNICODE
377 #define _vftprintf vfwprintf
378 #define _ftprintf fwprintf
379 #define _stprintf swprintf
380 #define _tprintf wprintf
381 #define _tcscpy wcscpy
382 #define _tcsncpy(d, s, l) wcsncpy((wchar_t *)d, (wchar_t *)s, l)
383 #define _tcscat wcscat
384 #define _tcslen wcslen
385 #define _tcschr wcschr
386 #define _tcscmp(s1, s2) wcscmp((wchar_t *)s1, (wchar_t *)s2)
387 #define _tfopen _wfopen
388 #define _T(a) L##a
389
390 #if defined(_WIN32) || defined(_PS2)
391 #define _tsnprintf _snwprintf
392 #else
393 #define _tsnprintf swprintf
394 #endif
395#else
396 #define _vftprintf vfprintf
397 #define _ftprintf fprintf
398 #define _stprintf sprintf
399 #define _tprintf printf
400 #define _tcscpy strcpy
401 #define _tcsncpy strncpy
402 #define _tcscat strcat
403 #define _tcslen strlen
404#if defined (_MSC_VER)
405#if (_MSC_VER < 1400)
406 #define _tcschr strchr
407#endif
408#else
409 #define _tcschr strchr
410#endif
411 #define _tcscmp strcmp
412 #define _tfopen fopen
413#ifndef _T
414 #define _T(a) a
415#endif
416
417 #if defined(_WIN32)
418 #define _tsnprintf _snprintf
419 #else
420 #define _tsnprintf snprintf
421 #endif
422#endif // GSI_UNICODE
423
424#if defined(_WIN32)
425 #define snprintf _snprintf
426#endif // _WIN32
427
428#if defined(_WIN32)
429 #define strcasecmp _stricmp
430 #define strncasecmp _strnicmp
431#endif
432
433#if !defined(_WIN32)
434 char *_strlwr(char *string);
435 char *_strupr(char *string);
436#endif
437
438char * goastrdup(const char *src);
439unsigned short * goawstrdup(const unsigned short *src);
440
441
442// ------ Cross Plat Alignment macros ------------
443/* ex use
444PRE_ALIGN(16) struct VECTOR
445{
446 float x,y,z,_unused;
447} POST_ALIGN(16);
448
449// another example when defining a variable:
450PRE_ALIGN(16);
451static char _mempool[MEMPOOL_SIZE] POST_ALIGN(16);
452
453*/
454#if defined _WIN32
455 #define PRE_ALIGN(x) __declspec(align(x)) // ignore Win32 directive
456 #define POST_ALIGN(x) // ignore
457#elif defined (_PS2) || defined (_PSP) || defined (_PS3)
458 #define PRE_ALIGN(x) // ignored this on psp/ps2
459 #define POST_ALIGN(x) __attribute__((aligned (x))) //
460#elif defined (_REVOLUTION)
461 #define PRE_ALIGN(x) // not needed
462 #define POST_ALIGN(x) __attribute__((aligned(32)))
463#else
464 // #warning "Platform not supported"
465 #define PRE_ALIGN(x) // ignore
466 #define POST_ALIGN(x) // ignore
467#endif
468
469#define DIM( x ) ( sizeof( x ) / sizeof((x)[ 0 ]))
470
471unsigned char * gsiFloatSwap(unsigned char buf[4], float);
472float gsiFloatUnswap(unsigned char buf[4]);
473extern gsi_u16 gsiByteOrderSwap16(gsi_u16);
474extern gsi_u32 gsiByteOrderSwap32(gsi_u32);
475extern gsi_u64 gsiByteOrderSwap64(gsi_u64);
476
477
478#ifdef __cplusplus
479}
480#endif
481
484#endif // __GSPLATFORM_H__
485