12#ifndef TT_INCLUDE__DEFINES_H
13#define TT_INCLUDE__DEFINES_H
19#if (WWCONFIG) || (TDBEDIT) || (W3DSHADER) || (W3DLIB_EXPORTS) || (W3DMESHMENDER) || (W3DDEPENDS) || (W3DMAPPER) || (ACHASH) || (PACKAGEEDITOR) || (FIXPLANES) || (MERGELOD) || (MIXCHECK) || (DDBEDIT) || (MAKEMIX) || (ALTMAT) || (W3DVIEWER)
23#pragma warning(disable: 4100)
24#pragma warning(disable: 4201)
25#pragma warning(disable: 4505)
26#pragma warning(disable: 6509)
30#pragma warning(disable:4251)
32#define WIN32_LEAN_AND_MEAN
33#define _WIN32_WINNT 0x0601
34#define _USE_MATH_DEFINES
38#define TT_INTERRUPT { __asm { __asm int 3 } }
39#elif defined(_M_AMD64)
40#define TT_INTERRUPT { __debugbreak(); }
44#define TT_RELEASE_ASSERT(expression) { __analysis_assume(expression); if (!(expression)) TT_INTERRUPT; }
48# define TT_ASSERT(expression) \
50 __analysis_assume(expression); \
55# define TT_ASSERT(expression) \
57 __analysis_assume(expression); \
63# define TT_ASSUME(x) TT_ASSERT(x)
64#elif defined(NDEBUG) && defined(_MSC_VER)
65# define TT_ASSUME(x) __assume(x)
72# define TT_UNREACHABLE TT_INTERRUPT
74# define TT_UNREACHABLE __assume(false);
77#define TT_UNIMPLEMENTED TT_INTERRUPT
78#define TT_UNTESTED TT_INTERRUPT
81#define TT_DEPRECATED(x) __declspec(deprecated(x))
84#if defined(NDEBUG) && defined(_MSC_VER)
85# define TT_INLINE __forceinline
87# define TT_INLINE inline
91template <
typename T,
size_t N>
92char ( &_ArraySizeHelper( T (&array)[N] ))[N];
94#define countof( array ) (sizeof( _ArraySizeHelper( array ) ))
99#define TT_NOOP(...) __VA_ARGS__
102#define UNK TT_DEPRECATED("Unknown type") uint32
103#define UNKB TT_DEPRECATED("Unknown type") uint8
104#define UNKADDRESS 0x00000000
110# define SHARED_API __declspec(dllexport)
112# define SHARED_API __declspec(dllimport)
116# define SCRIPTS_API __declspec(dllexport)
119# define SCRIPTS_API __declspec(dllimport)
125template <
typename T> T& ResolveGameReference(
const int client,
const int server,
const int leveledit)
127 if (Exe == 6) InitEngine();
128#pragma warning(suppress: 6011)
129 return *((T*)((Exe == 0) ? client : ((Exe == 1) ? server : ((Exe == 4) ? leveledit : 0))));
132template <
typename T, const
int size>
class RefArrayHelper
135 char _dummy[size *
sizeof(T)];
142 operator const T* ()
const
152 const T* operator & ()
const
159#define REF_DECL(type, name) type & name
160#define REF_ARR_DECL(type, name, size) RefArrayHelper<type, size> & name
163#define REF_DEF2(type, name, client, server) type & name = ResolveGameReference<type>(client, server, 0)
164#define REF_ARR_DEF2(type, name, size, client, server) RefArrayHelper<type, size> & name = ResolveGameReference<RefArrayHelper< type, size >> (client, server, 0)
167#define REF_DEF3(type, name, client, server, leveledit) type & name = ResolveGameReference<type>(client, server, leveledit)
168#define REF_ARR_DEF3(type, name, size, client, server, leveledit) RefArrayHelper<type, size> & name = ResolveGameReference<RefArrayHelper< type, size >> ( client, server, leveledit)
188void* HookupAT3(
void* a,
void* b,
void* c,
void* patch_start);
189#define RENEGADE_FUNCTION __declspec(naked)
191#define AT2(client, server) AT3(client, server, 0)
193#define AT3(client, server, leveledit) \
195 __asm AT3PatchStart: \
198 __asm push offset AT3PatchStart \
199 __asm push leveledit \
202 __asm call HookupAT3 \
217template<
int stackBufferLength,
typename Char>
class FormattedString;
219template<
int stackBufferLength>
class FormattedString<stackBufferLength, char>
224 char stackBuffer[stackBufferLength+1];
229 FormattedString(
const char* format, ...)
232 va_start(arguments, format);
233 length = vsnprintf(stackBuffer, stackBufferLength, format, arguments);
237 stackBuffer[length] =
'\0';
244 length = _vscprintf(format, arguments);
245 heapBuffer =
new char[length + 1];
246 vsprintf(heapBuffer, format, arguments);
257 const char* getValue()
const {
return value; }
258 const int getLength()
const {
return length; }
261template<
int stackBufferLength>
class FormattedString<stackBufferLength, wchar_t>
266 wchar_t stackBuffer[stackBufferLength+1];
268 const wchar_t* value;
271 FormattedString(
const wchar_t* format, ...)
274 va_start(arguments, format);
275 length = _vsnwprintf(stackBuffer, stackBufferLength, format, arguments);
279 stackBuffer[length] =
'\0';
286 length = _vscwprintf(format, arguments);
287 heapBuffer =
new wchar_t[length + 1];
288 _vsnwprintf(heapBuffer, length + 1, format, arguments);
299 const wchar_t* getValue()
const {
return value; }
300 const int getLength()
const {
return length; }
304#define TT_FORMAT(maxFormattedLength, format, ...) FormattedString<maxFormattedLength, char>(format, __VA_ARGS__).getValue()
305#define TT_FORMAT_WIDE(maxFormattedLength, format, ...) FormattedString<maxFormattedLength, wchar_t>(format, __VA_ARGS__).getValue()
310#define EXE_LEVELEDIT 4
311#define EXE_UNINITIALISED 6