diff --git a/regamedll/common/crc.h b/regamedll/common/crc.h index 5d098ccf..1a56b405 100644 --- a/regamedll/common/crc.h +++ b/regamedll/common/crc.h @@ -13,12 +13,9 @@ * ****/ -#ifndef CRC_H -#define CRC_H -#ifdef _WIN32 #pragma once -#endif +// MD5 Hash typedef struct { unsigned int buf[4]; @@ -26,6 +23,31 @@ typedef struct unsigned char in[64]; } MD5Context_t; -typedef uint32_t CRC32_t; +typedef unsigned int CRC32_t; -#endif // CRC_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +void CRC32_Init(CRC32_t *pulCRC); +CRC32_t CRC32_Final(CRC32_t pulCRC); +void CRC32_ProcessByte(CRC32_t *pulCRC, unsigned char ch); +void CRC32_ProcessBuffer(CRC32_t *pulCRC, void *pBuffer, int nBuffer); +BOOL CRC_File(CRC32_t *crcvalue, char *pszFileName); + +#ifdef __cplusplus +} +#endif + +byte COM_BlockSequenceCRCByte(byte *base, int length, int sequence); +int CRC_MapFile(CRC32_t *crcvalue, char *pszFileName); + +void MD5Init(MD5Context_t *ctx); +void MD5Update(MD5Context_t *ctx, const unsigned char *buf, unsigned int len); +void MD5Final(unsigned char digest[16], MD5Context_t *ctx); +void MD5Transform(unsigned int buf[4], const unsigned int in[16]); + +BOOL MD5_Hash_File(unsigned char digest[16], char *pszFileName, BOOL bUsefopen, BOOL bSeed, unsigned int seed[4]); +char *MD5_Print(unsigned char hash[16]); diff --git a/regamedll/common/mathlib.h b/regamedll/common/mathlib.h index 931897a6..45ea7b20 100644 --- a/regamedll/common/mathlib.h +++ b/regamedll/common/mathlib.h @@ -69,13 +69,13 @@ typedef union DLONG_u #endif template -T min(T a, T b) { return (a < b) ? a : b; } +const T& min(const T& a, const T& b) { return (a < b) ? a : b; } template -T max(T a, T b) { return (a > b) ? a : b; } +const T& max(const T& a, const T& b) { return (a > b) ? a : b; } template -T clamp(T a, T min, T max) { return (a > max) ? max : (a < min) ? min : a; } +const T& clamp(const T& a, const T& min, const T& max) { return (a > max) ? max : (a < min) ? min : a; } #else // __cplusplus diff --git a/regamedll/dlls/util.h b/regamedll/dlls/util.h index 39ff4076..9a36aa34 100644 --- a/regamedll/dlls/util.h +++ b/regamedll/dlls/util.h @@ -79,7 +79,7 @@ extern globalvars_t *gpGlobals; #define STRING(offset) ((const char *)(gpGlobals->pStringBase + (unsigned int)(offset))) -#define MAKE_STRING(str) ((uint64_t)(str) - (uint64_t)(STRING(0))) +#define MAKE_STRING(str) ((uint64)(str) - (uint64)(STRING(0))) // Dot products for view cone checking diff --git a/regamedll/engine/studio.h b/regamedll/engine/studio.h index d67d92c4..a84ceb76 100644 --- a/regamedll/engine/studio.h +++ b/regamedll/engine/studio.h @@ -155,7 +155,7 @@ typedef struct { char label[32]; // textual name char name[64]; // file name - int32_t unused1; // cache index pointer + int32 unused1; // cache index pointer int unused2; // hack for group 0 } mstudioseqgroup_t; diff --git a/regamedll/extra/cssdk/common/mathlib.h b/regamedll/extra/cssdk/common/mathlib.h index 336c1f09..d1dbdc9e 100644 --- a/regamedll/extra/cssdk/common/mathlib.h +++ b/regamedll/extra/cssdk/common/mathlib.h @@ -69,13 +69,13 @@ typedef union DLONG_u #endif template -T min(T a, T b) { return (a < b) ? a : b; } +const T& min(const T& a, const T& b) { return (a < b) ? a : b; } template -T max(T a, T b) { return (a > b) ? a : b; } +const T& max(const T& a, const T& b) { return (a > b) ? a : b; } template -T clamp(T a, T min, T max) { return (a > max) ? max : (a < min) ? min : a; } +const T& clamp(const T& a, const T& min, const T& max) { return (a > max) ? max : (a < min) ? min : a; } #else // __cplusplus diff --git a/regamedll/extra/cssdk/dlls/platform.h b/regamedll/extra/cssdk/dlls/platform.h deleted file mode 100644 index fd9a3046..00000000 --- a/regamedll/extra/cssdk/dlls/platform.h +++ /dev/null @@ -1,651 +0,0 @@ -//=========== (C) Copyright 1999 Valve, L.L.C. All rights reserved. =========== -// -// The copyright to the contents herein is the property of Valve, L.L.C. -// The contents may be used and/or copied only with the written permission of -// Valve, L.L.C., or in accordance with the terms and conditions stipulated in -// the agreement/contract under which the contents have been supplied. -// -// $Header: $ -// $NoKeywords: $ -// -// Extremely low-level platform-specific stuff -//============================================================================= - - -#ifndef PLATFORM_H -#define PLATFORM_H - -#ifdef _WIN32 -#pragma once -#endif - -#include "osconfig.h" - -// need this for _alloca -#include - -// need this for memset -#include - -// for when we care about how many bits we use -typedef signed char int8; -typedef signed short int16; - -#ifdef _WIN32 -#ifdef _MSC_VER -typedef signed __int64 int64; -#endif -#elif defined __linux__ -typedef long long int64; -#endif - -typedef unsigned char uint8; -typedef unsigned short uint16; -#ifdef _WIN32 -#ifdef _MSC_VER -typedef unsigned __int64 uint64; -#endif -#elif defined __linux__ -typedef unsigned long long uint64; -#endif - - -typedef float float32; -typedef double float64; - -// for when we don't care about how many bits we use -typedef unsigned int uint; - -// This can be used to ensure the size of pointers to members when declaring -// a pointer type for a class that has only been forward declared -#ifdef _MSC_VER -#define SINGLE_INHERITANCE __single_inheritance -#define MULTIPLE_INHERITANCE __multiple_inheritance -#else -#define SINGLE_INHERITANCE -#define MULTIPLE_INHERITANCE -#endif - -/* -FIXME: Enable this when we no longer fear change =) - -// need these for the limits -#include -#include - -// Maximum and minimum representable values -#define INT8_MAX SCHAR_MAX -#define INT16_MAX SHRT_MAX -#define INT32_MAX LONG_MAX -#define INT64_MAX (((int64)~0) >> 1) - -#define INT8_MIN SCHAR_MIN -#define INT16_MIN SHRT_MIN -#define INT32_MIN LONG_MIN -#define INT64_MIN (((int64)1) << 63) - -#define UINT8_MAX ((uint8)~0) -#define UINT16_MAX ((uint16)~0) -#define UINT32_MAX ((uint32_t)~0) -#define UINT64_MAX ((uint64)~0) - -#define UINT8_MIN 0 -#define UINT16_MIN 0 -#define UINT32_MIN 0 -#define UINT64_MIN 0 - -#ifndef UINT_MIN -#define UINT_MIN UINT32_MIN -#endif - -#define FLOAT32_MAX FLT_MAX -#define FLOAT64_MAX DBL_MAX - -#define FLOAT32_MIN FLT_MIN -#define FLOAT64_MIN DBL_MIN -*/ - -// portability / compiler settings -#if defined(_WIN32) && !defined(WINDED) - -#if defined(_M_IX86) -#define __i386__ 1 -#endif - -#elif __linux__ -typedef void * HINSTANCE; -#define _MAX_PATH PATH_MAX -#endif // defined(_WIN32) && !defined(WINDED) - - -// Defines MAX_PATH -#ifndef MAX_PATH -#define MAX_PATH 260 -#endif - -// Used to step into the debugger -#define DebuggerBreak() __asm { int 3 } - -// C functions for external declarations that call the appropriate C++ methods -#ifndef EXPORT -#ifdef _WIN32 -#define EXPORT _declspec( dllexport ) -#else -#define EXPORT /* */ -#endif -#endif - -#if defined __i386__ && !defined __linux__ -#define id386 1 -#else -#define id386 0 -#endif // __i386__ - -#ifdef _WIN32 -// Used for dll exporting and importing -#define DLL_EXPORT extern "C" __declspec( dllexport ) -#define DLL_IMPORT extern "C" __declspec( dllimport ) - -// Can't use extern "C" when DLL exporting a class -#define DLL_CLASS_EXPORT __declspec( dllexport ) -#define DLL_CLASS_IMPORT __declspec( dllimport ) - -// Can't use extern "C" when DLL exporting a global -#define DLL_GLOBAL_EXPORT extern __declspec( dllexport ) -#define DLL_GLOBAL_IMPORT extern __declspec( dllimport ) -#elif defined __linux__ - -// Used for dll exporting and importing -#define DLL_EXPORT extern "C" -#define DLL_IMPORT extern "C" - -// Can't use extern "C" when DLL exporting a class -#define DLL_CLASS_EXPORT -#define DLL_CLASS_IMPORT - -// Can't use extern "C" when DLL exporting a global -#define DLL_GLOBAL_EXPORT extern -#define DLL_GLOBAL_IMPORT extern - -#else -#error "Unsupported Platform." -#endif - -// Used for standard calling conventions -#ifdef _WIN32 -#define FASTCALL __fastcall -#define FORCEINLINE __forceinline -#else -#define FASTCALL -#define FORCEINLINE inline -#endif - -// Force a function call site -not- to inlined. (useful for profiling) -#define DONT_INLINE(a) (((int)(a)+1)?(a):(a)) - -// Pass hints to the compiler to prevent it from generating unnessecary / stupid code -// in certain situations. Several compilers other than MSVC also have an equivilent -// construct. -// -// Essentially the 'Hint' is that the condition specified is assumed to be true at -// that point in the compilation. If '0' is passed, then the compiler assumes that -// any subsequent code in the same 'basic block' is unreachable, and thus usually -// removed. -#ifdef _MSC_VER -#define HINT(THE_HINT) __assume((THE_HINT)) -#else -#define HINT(THE_HINT) 0 -#endif - -// Marks the codepath from here until the next branch entry point as unreachable, -// and asserts if any attempt is made to execute it. -#define UNREACHABLE() { Assert(0); HINT(0); } - -// In cases where no default is present or appropriate, this causes MSVC to generate -// as little code as possible, and throw an assertion in debug. -#define NO_DEFAULT default: UNREACHABLE(); - -#ifdef _WIN32 -// Alloca defined for this platform -#define stackalloc( _size ) _alloca( _size ) -#define stackfree( _p ) 0 -#elif __linux__ -// Alloca defined for this platform -#define stackalloc( _size ) alloca( _size ) -#define stackfree( _p ) 0 -#endif - -#ifdef _WIN32 -// Remove warnings from warning level 4. -#pragma warning(disable : 4514) // warning C4514: 'acosl' : unreferenced inline function has been removed -#pragma warning(disable : 4100) // warning C4100: 'hwnd' : unreferenced formal parameter -#pragma warning(disable : 4127) // warning C4127: conditional expression is constant -#pragma warning(disable : 4512) // warning C4512: 'InFileRIFF' : assignment operator could not be generated -#pragma warning(disable : 4611) // warning C4611: interaction between '_setjmp' and C++ object destruction is non-portable -#pragma warning(disable : 4706) // warning C4706: assignment within conditional expression -#pragma warning(disable : 4710) // warning C4710: function 'x' not inlined -#pragma warning(disable : 4702) // warning C4702: unreachable code -#pragma warning(disable : 4505) // unreferenced local function has been removed -#pragma warning(disable : 4239) // nonstandard extension used : 'argument' ( conversion from class Vector to class Vector& ) -#pragma warning(disable : 4097) // typedef-name 'BaseClass' used as synonym for class-name 'CFlexCycler::CBaseFlex' -#pragma warning(disable : 4324) // Padding was added at the end of a structure -#pragma warning(disable : 4244) // type conversion warning. -#pragma warning(disable : 4305) // truncation from 'const double ' to 'float ' -#pragma warning(disable : 4786) // Disable warnings about long symbol names - -#if _MSC_VER >= 1300 -#pragma warning(disable : 4511) // Disable warnings about private copy constructors -#endif -#endif -//----------------------------------------------------------------------------- -// Purpose: Standard functions for handling endian-ness -//----------------------------------------------------------------------------- - -//------------------------------------- -// Basic swaps -//------------------------------------- - -template -inline T WordSwapC(T w) -{ - uint16 temp; - - temp = ((*((uint16 *)&w) & 0xff00) >> 8); - temp |= ((*((uint16 *)&w) & 0x00ff) << 8); - - return *((T*)&temp); -} - -template -inline T DWordSwapC(T dw) -{ - uint32_t temp; - - temp = *((uint32_t *)&dw) >> 24; - temp |= ((*((uint32_t *)&dw) & 0x00FF0000) >> 8); - temp |= ((*((uint32_t *)&dw) & 0x0000FF00) << 8); - temp |= ((*((uint32_t *)&dw) & 0x000000FF) << 24); - - return *((T*)&temp); -} - -//------------------------------------- -// Fast swaps -//------------------------------------- - -#ifdef _MSC_VER - -#define WordSwap WordSwapAsm -#define DWordSwap DWordSwapAsm - -#pragma warning(push) -#pragma warning (disable:4035) // no return value - -template -inline T WordSwapAsm(T w) -{ - __asm - { - mov ax, w - xchg al, ah - } -} - -template -inline T DWordSwapAsm(T dw) -{ - __asm - { - mov eax, dw - bswap eax - } -} - -#pragma warning(pop) - -// The assembly implementation is not compatible with floats -template <> -inline float DWordSwapAsm(float f) -{ - return DWordSwapC(f); -} - -#else - -#define WordSwap WordSwapC -#define DWordSwap DWordSwapC - -#endif - -//------------------------------------- -// The typically used methods. -//------------------------------------- - -#if defined(__i386__) -#define VALVE_LITTLE_ENDIAN 1 -#endif - -#ifdef _SGI_SOURCE -#define VALVE_BIG_ENDIAN 1 -#endif - -#if defined(VALVE_LITTLE_ENDIAN) - -#define Valve_BigShort( val ) WordSwap( val ) -#define Valve_BigWord( val ) WordSwap( val ) -#define Valve_BigLong( val ) DWordSwap( val ) -#define Valve_BigDWord( val ) DWordSwap( val ) -#define Valve_BigFloat( val ) DWordSwap( val ) -#define Valve_LittleShort( val ) ( val ) -#define Valve_LittleWord( val ) ( val ) -#define Valve_LittleLong( val ) ( val ) -#define Valve_LittleDWord( val ) ( val ) -#define Valve_LittleFloat( val ) ( val ) - -#elif defined(BIG_ENDIAN) - -#define Valve_BigShort( val ) ( val ) -#define Valve_BigWord( val ) ( val ) -#define Valve_BigLong( val ) ( val ) -#define Valve_BigDWord( val ) ( val ) -#define Valve_BigFloat( val ) ( val ) -#define Valve_LittleShort( val ) WordSwap( val ) -#define Valve_LittleWord( val ) WordSwap( val ) -#define Valve_LittleLong( val ) DWordSwap( val ) -#define Valve_LittleDWord( val ) DWordSwap( val ) -#define Valve_LittleFloat( val ) DWordSwap( val ) - -#else - -// @Note (toml 05-02-02): this technique expects the compiler to -// optimize the expression and eliminate the other path. On any new -// platform/compiler this should be tested. -inline short BigShort(short val) { int test = 1; return (*(char *)&test == 1) ? WordSwap(val) : val; } -inline uint16 BigWord(uint16 val) { int test = 1; return (*(char *)&test == 1) ? WordSwap(val) : val; } -inline long BigLong(long val) { int test = 1; return (*(char *)&test == 1) ? DWordSwap(val) : val; } -inline uint32_t BigDWord(uint32_t val) { int test = 1; return (*(char *)&test == 1) ? DWordSwap(val) : val; } -inline float BigFloat(float val) { int test = 1; return (*(char *)&test == 1) ? DWordSwap(val) : val; } -inline short LittleShort(short val) { int test = 1; return (*(char *)&test == 1) ? val : WordSwap(val); } -inline uint16 LittleWord(uint16 val) { int test = 1; return (*(char *)&test == 1) ? val : WordSwap(val); } -inline long LittleLong(long val) { int test = 1; return (*(char *)&test == 1) ? val : DWordSwap(val); } -inline uint32_t LittleDWord(uint32_t val) { int test = 1; return (*(char *)&test == 1) ? val : DWordSwap(val); } -inline float LittleFloat(float val) { int test = 1; return (*(char *)&test == 1) ? val : DWordSwap(val); } - -#endif - - - -#ifdef TIER0_DLL_EXPORT -#define PLATFORM_INTERFACE DLL_EXPORT -#define PLATFORM_OVERLOAD DLL_GLOBAL_EXPORT -#else -#define PLATFORM_INTERFACE DLL_IMPORT -#define PLATFORM_OVERLOAD DLL_GLOBAL_IMPORT -#endif - -/* -PLATFORM_INTERFACE double Plat_FloatTime(); // Returns time in seconds since the module was loaded. -PLATFORM_INTERFACE unsigned long Plat_MSTime(); // Time in milliseconds. - -// b/w compatibility -#define Sys_FloatTime Plat_FloatTime -*/ - -// Processor Information: -struct CPUInformation -{ - int m_Size; // Size of this structure, for forward compatability. - - bool m_bRDTSC : 1, // Is RDTSC supported? - m_bCMOV : 1, // Is CMOV supported? - m_bFCMOV : 1, // Is FCMOV supported? - m_bSSE : 1, // Is SSE supported? - m_bSSE2 : 1, // Is SSE2 Supported? - m_b3DNow : 1, // Is 3DNow! Supported? - m_bMMX : 1, // Is MMX supported? - m_bHT : 1; // Is HyperThreading supported? - - unsigned char m_nLogicalProcessors, // Number op logical processors. - m_nPhysicalProcessors; // Number of physical processors - - int64 m_Speed; // In cycles per second. - - char* m_szProcessorID; // Processor vendor Identification. -}; - -PLATFORM_INTERFACE const CPUInformation& GetCPUInformation(); - - -//----------------------------------------------------------------------------- -// Thread related functions -//----------------------------------------------------------------------------- -// Registers the current thread with Tier0's thread management system. -// This should be called on every thread created in the game. -PLATFORM_INTERFACE unsigned long Plat_RegisterThread(const char *pName = "Source Thread"); - -// Registers the current thread as the primary thread. -PLATFORM_INTERFACE unsigned long Plat_RegisterPrimaryThread(); - -// VC-specific. Sets the thread's name so it has a friendly name in the debugger. -// This should generally only be handled by Plat_RegisterThread and Plat_RegisterPrimaryThread -PLATFORM_INTERFACE void Plat_SetThreadName(unsigned long dwThreadID, const char *pName); - -// These would be private if it were possible to export private variables from a .DLL. -// They need to be variables because they are checked by inline functions at performance -// critical places. -PLATFORM_INTERFACE unsigned long Plat_PrimaryThreadID; - -// Returns the ID of the currently executing thread. -PLATFORM_INTERFACE unsigned long Plat_GetCurrentThreadID(); - -// Returns the ID of the primary thread. -inline unsigned long Plat_GetPrimaryThreadID() -{ - return Plat_PrimaryThreadID; -} - -// Returns true if the current thread is the primary thread. -inline bool Plat_IsPrimaryThread() -{ - //return true; - return (Plat_GetPrimaryThreadID() == Plat_GetCurrentThreadID()); -} - -//----------------------------------------------------------------------------- -// Security related functions -//----------------------------------------------------------------------------- -// Ensure that the hardware key's drivers have been installed. -PLATFORM_INTERFACE bool Plat_VerifyHardwareKeyDriver(); - -// Ok, so this isn't a very secure way to verify the hardware key for now. It -// is primarially depending on the fact that all the binaries have been wrapped -// with the secure wrapper provided by the hardware keys vendor. -PLATFORM_INTERFACE bool Plat_VerifyHardwareKey(); - -// The same as above, but notifies user with a message box when the key isn't in -// and gives him an opportunity to correct the situation. -PLATFORM_INTERFACE bool Plat_VerifyHardwareKeyPrompt(); - -// Can be called in real time, doesn't perform the verify every frame. Mainly just -// here to allow the game to drop out quickly when the key is removed, rather than -// allowing the wrapper to pop up it's own blocking dialog, which the engine doesn't -// like much. -PLATFORM_INTERFACE bool Plat_FastVerifyHardwareKey(); - - - -//----------------------------------------------------------------------------- -// Include additional dependant header components. -//----------------------------------------------------------------------------- -//#include "tier0/fasttimer.h" - - -//----------------------------------------------------------------------------- -// Just logs file and line to simple.log -//----------------------------------------------------------------------------- -void* Plat_SimpleLog(const char* file, int line); - -//#define Plat_dynamic_cast Plat_SimpleLog(__FILE__,__LINE__),dynamic_cast - -//----------------------------------------------------------------------------- -// Methods to invoke the constructor, copy constructor, and destructor -//----------------------------------------------------------------------------- - -template -inline void Construct(T* pMemory) -{ - new(pMemory)T; -} - -template -inline void CopyConstruct(T* pMemory, T const& src) -{ - new(pMemory)T(src); -} - -template -inline void Destruct(T* pMemory) -{ - pMemory->~T(); - -#ifdef _DEBUG - memset(pMemory, 0xDD, sizeof(T)); -#endif -} - - -// -// GET_OUTER() -// -// A platform-independent way for a contained class to get a pointer to its -// owner. If you know a class is exclusively used in the context of some -// "outer" class, this is a much more space efficient way to get at the outer -// class than having the inner class store a pointer to it. -// -// class COuter -// { -// class CInner // Note: this does not need to be a nested class to work -// { -// void PrintAddressOfOuter() -// { -// printf( "Outer is at 0x%x\n", GET_OUTER( COuter, m_Inner ) ); -// } -// }; -// -// CInner m_Inner; -// friend class CInner; -// }; - -#define GET_OUTER( OuterType, OuterMember ) \ - ( ( OuterType * ) ( (char *)this - offsetof( OuterType, OuterMember ) ) ) - - -/* TEMPLATE_FUNCTION_TABLE() - -(Note added to platform.h so platforms that correctly support templated -functions can handle portions as templated functions rather than wrapped -functions) - -Helps automate the process of creating an array of function -templates that are all specialized by a single integer. -This sort of thing is often useful in optimization work. - -For example, using TEMPLATE_FUNCTION_TABLE, this: - -TEMPLATE_FUNCTION_TABLE(int, Function, ( int blah, int blah ), 10) -{ -return argument * argument; -} - -is equivilent to the following: - -(NOTE: the function has to be wrapped in a class due to code -generation bugs involved with directly specializing a function -based on a constant.) - -template -class FunctionWrapper -{ -public: -int Function( int blah, int blah ) -{ -return argument*argument; -} -} - -typedef int (*FunctionType)( int blah, int blah ); - -class FunctionName -{ -public: -enum { count = 10 }; -FunctionType functions[10]; -}; - -FunctionType FunctionName::functions[] = -{ -FunctionWrapper<0>::Function, -FunctionWrapper<1>::Function, -FunctionWrapper<2>::Function, -FunctionWrapper<3>::Function, -FunctionWrapper<4>::Function, -FunctionWrapper<5>::Function, -FunctionWrapper<6>::Function, -FunctionWrapper<7>::Function, -FunctionWrapper<8>::Function, -FunctionWrapper<9>::Function -}; -*/ - -bool vtune(bool resume); - - -#define TEMPLATE_FUNCTION_TABLE(RETURN_TYPE, NAME, ARGS, COUNT) \ - \ -typedef RETURN_TYPE (FASTCALL *__Type_##NAME) ARGS; \ - \ -template \ -struct __Function_##NAME \ -{ \ - static RETURN_TYPE FASTCALL Run ARGS; \ -}; \ - \ -template \ -struct __MetaLooper_##NAME : __MetaLooper_##NAME \ -{ \ - __Type_##NAME func; \ - inline __MetaLooper_##NAME() { func = __Function_##NAME::Run; } \ -}; \ - \ -template<> \ -struct __MetaLooper_##NAME<0> \ -{ \ - __Type_##NAME func; \ - inline __MetaLooper_##NAME() { func = __Function_##NAME<0>::Run; } \ -}; \ - \ -class NAME \ -{ \ -private: \ - static const __MetaLooper_##NAME m; \ -public: \ - enum { count = COUNT }; \ - static const __Type_##NAME* functions; \ -}; \ -const __MetaLooper_##NAME NAME::m; \ -const __Type_##NAME* NAME::functions = (__Type_##NAME*)&m; \ -template \ -RETURN_TYPE FASTCALL __Function_##NAME::Run ARGS - - -#define LOOP_INTERCHANGE(BOOLEAN, CODE)\ - if( (BOOLEAN) )\ - {\ - CODE;\ - } else\ - {\ - CODE;\ - } - - -#endif /* PLATFORM_H */ \ No newline at end of file diff --git a/regamedll/extra/cssdk/dlls/util.h b/regamedll/extra/cssdk/dlls/util.h index f5482ee0..e0d1d304 100644 --- a/regamedll/extra/cssdk/dlls/util.h +++ b/regamedll/extra/cssdk/dlls/util.h @@ -44,7 +44,7 @@ extern globalvars_t *gpGlobals; // Use this instead of ALLOC_STRING on constant strings #define STRING(offset) ((const char *)(gpGlobals->pStringBase + (unsigned int)(offset))) -#define MAKE_STRING(str) ((uint64_t)(str) - (uint64_t)(STRING(0))) +#define MAKE_STRING(str) ((uint64)(str) - (uint64)(STRING(0))) // Dot products for view cone checking #define VIEW_FIELD_FULL -1.0 // +-180 degrees diff --git a/regamedll/extra/cssdk/public/asmlib.h b/regamedll/extra/cssdk/public/asmlib.h deleted file mode 100644 index c1bc9af8..00000000 --- a/regamedll/extra/cssdk/public/asmlib.h +++ /dev/null @@ -1,123 +0,0 @@ -/*************************** asmlib.h *************************************** -* Author: Agner Fog -* Date created: 2003-12-12 -* Last modified: 2013-10-04 -* Project: asmlib.zip -* Source URL: www.agner.org/optimize -* -* Description: -* Header file for the asmlib function library. -* This library is available in many versions for different platforms. -* See asmlib-instructions.pdf for details. -* -* (c) Copyright 2003 - 2013 by Agner Fog. -* GNU General Public License http://www.gnu.org/licenses/gpl.html -*****************************************************************************/ - - -#ifndef ASMLIB_H -#define ASMLIB_H - - -/*********************************************************************** -Define compiler-specific types and directives -***********************************************************************/ - -// Define type size_t -#ifndef _SIZE_T_DEFINED -#include "stddef.h" -#endif - -// Define integer types with known size: int32_t, uint32_t, int64_t, uint64_t. -// If this doesn't work then insert compiler-specific definitions here: -#if defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1600) - // Compilers supporting C99 or C++0x have stdint.h defining these integer types - #include - #define INT64_SUPPORTED // Remove this if the compiler doesn't support 64-bit integers -#elif defined(_MSC_VER) - // Older Microsoft compilers have their own definition - typedef signed __int16 int16_t; - typedef unsigned __int16 uint16_t; - typedef signed __int32 int32_t; - typedef unsigned __int32 uint32_t; - typedef signed __int64 int64_t; - typedef unsigned __int64 uint64_t; - #define INT64_SUPPORTED // Remove this if the compiler doesn't support 64-bit integers -#else - // This works with most compilers - typedef signed short int int16_t; - typedef unsigned short int uint16_t; - typedef signed int int32_t; - typedef unsigned int uint32_t; - typedef long long int64_t; - typedef unsigned long long uint64_t; - #define INT64_SUPPORTED // Remove this if the compiler doesn't support 64-bit integers -#endif - - -// Turn off name mangling -#ifdef __cplusplus -extern "C" { -#endif - -/*********************************************************************** -Function prototypes, memory and string functions -***********************************************************************/ -void * A_memcpy (void * dest, const void * src, size_t count); // Copy count bytes from src to dest -void * A_memmove(void * dest, const void * src, size_t count); // Same as memcpy, allows overlap between src and dest -void * A_memset (void * dest, int c, size_t count); // Set count bytes in dest to (char)c -int A_memcmp (const void * buf1, const void * buf2, size_t num); // Compares two blocks of memory -size_t GetMemcpyCacheLimit(void); // Data blocks bigger than this will be copied uncached by memcpy and memmove -void SetMemcpyCacheLimit(size_t); // Change limit in GetMemcpyCacheLimit -size_t GetMemsetCacheLimit(void); // Data blocks bigger than this will be stored uncached by memset -void SetMemsetCacheLimit(size_t); // Change limit in GetMemsetCacheLimit -char * A_strcat (char * dest, const char * src); // Concatenate strings dest and src. Store result in dest -char * A_strcpy (char * dest, const char * src); // Copy string src to dest -size_t A_strlen (const char * str); // Get length of zero-terminated string -int A_strcmp (const char * a, const char * b); // Compare strings. Case sensitive -int A_stricmp (const char *string1, const char *string2); // Compare strings. Case insensitive for A-Z only -char * A_strstr (char * haystack, const char * needle); // Search for substring in string -void A_strtolower(char * string); // Convert string to lower case for A-Z only -void A_strtoupper(char * string); // Convert string to upper case for a-z only -size_t A_substring(char * dest, const char * source, size_t pos, size_t len); // Copy a substring for source into dest -size_t A_strspn (const char * str, const char * set); // Find span of characters that belong to set -size_t A_strcspn(const char * str, const char * set); // Find span of characters that don't belong to set -size_t strCountInSet(const char * str, const char * set); // Count characters that belong to set -size_t strcount_UTF8(const char * str); // Counts the number of characters in a UTF-8 encoded string - - -/*********************************************************************** -Function prototypes, miscellaneous functions -***********************************************************************/ -uint32_t A_popcount(uint32_t x); // Count 1-bits in 32-bit integer -int RoundD (double x); // Round to nearest or even -int RoundF (float x); // Round to nearest or even -int InstructionSet(void); // Tell which instruction set is supported -char * ProcessorName(void); // ASCIIZ text describing microprocessor -void CpuType(int * vendor, int * family, int * model); // Get CPU vendor, family and model -size_t DataCacheSize(int level); // Get size of data cache -void A_DebugBreak(void); // Makes a debug breakpoint -#ifdef INT64_SUPPORTED - uint64_t ReadTSC(void); // Read microprocessor internal clock (64 bits) -#else - uint32_t ReadTSC(void); // Read microprocessor internal clock (only 32 bits supported by compiler) -#endif -void cpuid_ex (int abcd[4], int eax, int ecx); // call CPUID instruction -static inline void cpuid_abcd (int abcd[4], int eax) { - cpuid_ex(abcd, eax, 0);} - -#ifdef __cplusplus -} // end of extern "C" - -// Define overloaded versions if compiling as C++ - -static inline int Round (double x) { // Overload name Round - return RoundD(x);} -static inline int Round (float x) { // Overload name Round - return RoundF(x);} -static inline const char * A_strstr(const char * haystack, const char * needle) { - return A_strstr((char*)haystack, needle);} // Overload A_strstr with const char * version - -#endif // __cplusplus - -#endif // ASMLIB_H diff --git a/regamedll/extra/cssdk/public/basetypes.h b/regamedll/extra/cssdk/public/basetypes.h index 04df63b2..68d56780 100644 --- a/regamedll/extra/cssdk/public/basetypes.h +++ b/regamedll/extra/cssdk/public/basetypes.h @@ -17,7 +17,7 @@ // For backward compatibilty only... -//#include "tier0/platform.h" +#include "tier0/platform.h" // stdio.h #ifndef NULL @@ -44,30 +44,19 @@ #define PAD_NUMBER(number, boundary) \ ( ((number) + ((boundary)-1)) / (boundary) ) * (boundary) +#ifndef MATHLIB_H // In case this ever changes #define M_PI 3.14159265358979323846 -// #ifndef min -// #define min(a,b) (((a) < (b)) ? (a) : (b)) -// #endif - -// #ifndef max -// #define max(a,b) (((a) > (b)) ? (a) : (b)) -// #endif - -#ifdef __cplusplus -template -inline T clamp2(T const &val, T const &minVal, T const &maxVal) //renamed to clamp2 to avoid conflicts with clamp defined in mathlib -{ - if (val < minVal) - return minVal; - else if (val > maxVal) - return maxVal; - else - return val; -} +#ifndef min +#define min(a,b) (((a) < (b)) ? (a) : (b)) #endif +#ifndef max +#define max(a,b) (((a) > (b)) ? (a) : (b)) +#endif +#endif // MATHLIB_H + #ifndef FALSE #define FALSE 0 #define TRUE (!FALSE) @@ -81,7 +70,7 @@ typedef unsigned char BYTE; typedef unsigned char byte; typedef unsigned short word; -//#include "string_t.h" +#include "string_t.h" typedef float vec_t; diff --git a/regamedll/hookers/memory.cpp b/regamedll/hookers/memory.cpp index 2a7b031c..ecbc6ffc 100644 --- a/regamedll/hookers/memory.cpp +++ b/regamedll/hookers/memory.cpp @@ -300,8 +300,8 @@ size_t HIDDEN FindSymbol(Module *module, const char* symbolName, int index) Elf32_Shdr *sections, *shstrtab_hdr, *symtab_hdr, *strtab_hdr; Elf32_Sym *symtab; const char *shstrtab, *strtab; - uint16_t section_count; - uint32_t symbol_count; + uint16 section_count; + uint32 symbol_count; size_t address; // If index > 0 then we shouldn't use dlsym, cos it will give wrong result @@ -345,7 +345,7 @@ size_t HIDDEN FindSymbol(Module *module, const char* symbolName, int index) shstrtab = (const char *)(map_base + shstrtab_hdr->sh_offset); // Iterate sections while looking for ELF symbol table and string table - for (uint16_t i = 0; i < section_count; i++) + for (uint16 i = 0; i < section_count; i++) { Elf32_Shdr &hdr = sections[i]; const char *section_name = shstrtab + hdr.sh_name; @@ -379,7 +379,7 @@ size_t HIDDEN FindSymbol(Module *module, const char* symbolName, int index) // Iterate symbol table int match = 1; - for (uint32_t i = 0; i < symbol_count; i++) + for (uint32 i = 0; i < symbol_count; i++) { Elf32_Sym &sym = symtab[i]; unsigned char sym_type = ELF32_ST_TYPE(sym.st_info); @@ -457,7 +457,7 @@ void ProcessModuleData(Module *module) return; } - module->codeSection.start = (uint32_t)module->base + CodeSection->VirtualAddress; + module->codeSection.start = (uint32)module->base + CodeSection->VirtualAddress; module->codeSection.size = CodeSection->Misc.VirtualSize; module->codeSection.end = module->codeSection.start + module->codeSection.size; module->codeSection.next = NULL; @@ -516,7 +516,7 @@ size_t HIDDEN ConvertHexString(const char *srcHexString, unsigned char *outBuffe unsigned char *out = outBuffer; unsigned char *end = outBuffer + bufferSize; bool low = false; - uint8_t byte = 0; + uint8 byte = 0; while (*in && out < end) { if (*in >= '0' && *in <= '9') { byte |= *in - '0'; } @@ -648,7 +648,7 @@ size_t HIDDEN MemoryFindBackward(size_t start, size_t end, const unsigned char * return NULL; } -size_t HIDDEN MemoryFindRefForwardPrefix8(size_t start, size_t end, size_t refAddress, uint8_t prefixValue, bool relative) +size_t HIDDEN MemoryFindRefForwardPrefix8(size_t start, size_t end, size_t refAddress, uint8 prefixValue, bool relative) { // Ensure start is lower than the end if (start > end) @@ -684,21 +684,21 @@ size_t HIDDEN MemoryFindRefForwardPrefix8(size_t start, size_t end, size_t refAd } // Replaces double word on specified address with a new dword, returns old dword -uint32_t HIDDEN HookDWord(size_t addr, uint32_t newDWord) +uint32 HIDDEN HookDWord(size_t addr, uint32 newDWord) { - uint32_t origDWord = *(size_t *)addr; - EnablePageWrite(addr, sizeof(uint32_t)); + uint32 origDWord = *(size_t *)addr; + EnablePageWrite(addr, sizeof(uint32)); *(size_t *)addr = newDWord; - RestorePageProtection(addr, sizeof(uint32_t)); + RestorePageProtection(addr, sizeof(uint32)); return origDWord; } // Exchanges bytes between memory address and bytes array -void HIDDEN ExchangeMemoryBytes(size_t origAddr, size_t dataAddr, uint32_t size) +void HIDDEN ExchangeMemoryBytes(size_t origAddr, size_t dataAddr, uint32 size) { EnablePageWrite(origAddr, size); unsigned char data[MAX_PATTERN]; - int32_t iSize = size; + int32 iSize = size; while (iSize > 0) { size_t s = iSize <= MAX_PATTERN ? iSize : MAX_PATTERN; @@ -798,9 +798,9 @@ bool HIDDEN FindDataRef(Module *module, AddressRef *ref) } #ifdef _WIN32 -void FindAllCalls(Section* section, CFuncAddr** calls, uint32_t findRefsTo) +void FindAllCalls(Section* section, CFuncAddr** calls, uint32 findRefsTo) { - uint32_t coderef_addr = section->start; + uint32 coderef_addr = section->start; coderef_addr = MemoryFindRefForwardPrefix8(coderef_addr, section->end, findRefsTo, 0xE8, true); while (coderef_addr) { CFuncAddr* cfa = new CFuncAddr(coderef_addr); diff --git a/regamedll/hookers/memory.h b/regamedll/hookers/memory.h index 8a93ecea..e415ed7c 100644 --- a/regamedll/hookers/memory.h +++ b/regamedll/hookers/memory.h @@ -96,7 +96,7 @@ struct AddressRef class CFuncAddr { public: - uint32_t Addr; + uint32 Addr; CFuncAddr *Next; void *operator new(size_t size){ @@ -107,7 +107,7 @@ public: free(cPoint); } - CFuncAddr(uint32_t addr) { + CFuncAddr(uint32 addr) { Addr = addr; Next = NULL; } @@ -128,10 +128,10 @@ void ProcessModuleData(Module *module); size_t ConvertHexString(const char *srcHexString, unsigned char *outBuffer, size_t bufferSize); size_t MemoryFindForward(size_t start, size_t end, const unsigned char *pattern, const unsigned char *mask, size_t len); size_t MemoryFindBackward(size_t start, size_t end, const unsigned char *pattern, const unsigned char *mask, size_t len); -size_t MemoryFindRefForwardPrefix8(size_t start, size_t end, size_t refAddress, uint8_t prefixValue, bool relative); +size_t MemoryFindRefForwardPrefix8(size_t start, size_t end, size_t refAddress, uint8 prefixValue, bool relative); -uint32_t HookDWord(size_t addr, uint32_t newDWord); -void ExchangeMemoryBytes(size_t origAddr, size_t dataAddr, uint32_t size); +uint32 HookDWord(size_t addr, uint32 newDWord); +void ExchangeMemoryBytes(size_t origAddr, size_t dataAddr, uint32 size); bool GetAddress(Module *module, Address *addr, size_t baseOffset); bool HookFunction(Module *module, FunctionHook *hook); @@ -139,7 +139,7 @@ void HookFunctionCall(void* hookWhat, void* hookAddr); bool HIDDEN FindDataRef(Module *module, AddressRef *ref); #ifdef WIN32 -void FindAllCalls(Section* section, CFuncAddr** calls, uint32_t findRefsTo); +void FindAllCalls(Section* section, CFuncAddr** calls, uint32 findRefsTo); #endif #if defined(HOOK_GAMEDLL) && defined(_WIN32) && !defined(REGAMEDLL_UNIT_TESTS) diff --git a/regamedll/public/asmlib.h b/regamedll/public/asmlib.h deleted file mode 100644 index c1bc9af8..00000000 --- a/regamedll/public/asmlib.h +++ /dev/null @@ -1,123 +0,0 @@ -/*************************** asmlib.h *************************************** -* Author: Agner Fog -* Date created: 2003-12-12 -* Last modified: 2013-10-04 -* Project: asmlib.zip -* Source URL: www.agner.org/optimize -* -* Description: -* Header file for the asmlib function library. -* This library is available in many versions for different platforms. -* See asmlib-instructions.pdf for details. -* -* (c) Copyright 2003 - 2013 by Agner Fog. -* GNU General Public License http://www.gnu.org/licenses/gpl.html -*****************************************************************************/ - - -#ifndef ASMLIB_H -#define ASMLIB_H - - -/*********************************************************************** -Define compiler-specific types and directives -***********************************************************************/ - -// Define type size_t -#ifndef _SIZE_T_DEFINED -#include "stddef.h" -#endif - -// Define integer types with known size: int32_t, uint32_t, int64_t, uint64_t. -// If this doesn't work then insert compiler-specific definitions here: -#if defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1600) - // Compilers supporting C99 or C++0x have stdint.h defining these integer types - #include - #define INT64_SUPPORTED // Remove this if the compiler doesn't support 64-bit integers -#elif defined(_MSC_VER) - // Older Microsoft compilers have their own definition - typedef signed __int16 int16_t; - typedef unsigned __int16 uint16_t; - typedef signed __int32 int32_t; - typedef unsigned __int32 uint32_t; - typedef signed __int64 int64_t; - typedef unsigned __int64 uint64_t; - #define INT64_SUPPORTED // Remove this if the compiler doesn't support 64-bit integers -#else - // This works with most compilers - typedef signed short int int16_t; - typedef unsigned short int uint16_t; - typedef signed int int32_t; - typedef unsigned int uint32_t; - typedef long long int64_t; - typedef unsigned long long uint64_t; - #define INT64_SUPPORTED // Remove this if the compiler doesn't support 64-bit integers -#endif - - -// Turn off name mangling -#ifdef __cplusplus -extern "C" { -#endif - -/*********************************************************************** -Function prototypes, memory and string functions -***********************************************************************/ -void * A_memcpy (void * dest, const void * src, size_t count); // Copy count bytes from src to dest -void * A_memmove(void * dest, const void * src, size_t count); // Same as memcpy, allows overlap between src and dest -void * A_memset (void * dest, int c, size_t count); // Set count bytes in dest to (char)c -int A_memcmp (const void * buf1, const void * buf2, size_t num); // Compares two blocks of memory -size_t GetMemcpyCacheLimit(void); // Data blocks bigger than this will be copied uncached by memcpy and memmove -void SetMemcpyCacheLimit(size_t); // Change limit in GetMemcpyCacheLimit -size_t GetMemsetCacheLimit(void); // Data blocks bigger than this will be stored uncached by memset -void SetMemsetCacheLimit(size_t); // Change limit in GetMemsetCacheLimit -char * A_strcat (char * dest, const char * src); // Concatenate strings dest and src. Store result in dest -char * A_strcpy (char * dest, const char * src); // Copy string src to dest -size_t A_strlen (const char * str); // Get length of zero-terminated string -int A_strcmp (const char * a, const char * b); // Compare strings. Case sensitive -int A_stricmp (const char *string1, const char *string2); // Compare strings. Case insensitive for A-Z only -char * A_strstr (char * haystack, const char * needle); // Search for substring in string -void A_strtolower(char * string); // Convert string to lower case for A-Z only -void A_strtoupper(char * string); // Convert string to upper case for a-z only -size_t A_substring(char * dest, const char * source, size_t pos, size_t len); // Copy a substring for source into dest -size_t A_strspn (const char * str, const char * set); // Find span of characters that belong to set -size_t A_strcspn(const char * str, const char * set); // Find span of characters that don't belong to set -size_t strCountInSet(const char * str, const char * set); // Count characters that belong to set -size_t strcount_UTF8(const char * str); // Counts the number of characters in a UTF-8 encoded string - - -/*********************************************************************** -Function prototypes, miscellaneous functions -***********************************************************************/ -uint32_t A_popcount(uint32_t x); // Count 1-bits in 32-bit integer -int RoundD (double x); // Round to nearest or even -int RoundF (float x); // Round to nearest or even -int InstructionSet(void); // Tell which instruction set is supported -char * ProcessorName(void); // ASCIIZ text describing microprocessor -void CpuType(int * vendor, int * family, int * model); // Get CPU vendor, family and model -size_t DataCacheSize(int level); // Get size of data cache -void A_DebugBreak(void); // Makes a debug breakpoint -#ifdef INT64_SUPPORTED - uint64_t ReadTSC(void); // Read microprocessor internal clock (64 bits) -#else - uint32_t ReadTSC(void); // Read microprocessor internal clock (only 32 bits supported by compiler) -#endif -void cpuid_ex (int abcd[4], int eax, int ecx); // call CPUID instruction -static inline void cpuid_abcd (int abcd[4], int eax) { - cpuid_ex(abcd, eax, 0);} - -#ifdef __cplusplus -} // end of extern "C" - -// Define overloaded versions if compiling as C++ - -static inline int Round (double x) { // Overload name Round - return RoundD(x);} -static inline int Round (float x) { // Overload name Round - return RoundF(x);} -static inline const char * A_strstr(const char * haystack, const char * needle) { - return A_strstr((char*)haystack, needle);} // Overload A_strstr with const char * version - -#endif // __cplusplus - -#endif // ASMLIB_H diff --git a/regamedll/public/basetypes.h b/regamedll/public/basetypes.h index 44ba3ffb..dfdcdbbc 100644 --- a/regamedll/public/basetypes.h +++ b/regamedll/public/basetypes.h @@ -17,7 +17,7 @@ // For backward compatibilty only... -//#include "tier0/platform.h" +#include "tier0/platform.h" // stdio.h #ifndef NULL @@ -44,30 +44,19 @@ #define PAD_NUMBER(number, boundary) \ ( ((number) + ((boundary)-1)) / (boundary) ) * (boundary) +#ifndef MATHLIB_H // In case this ever changes #define M_PI 3.14159265358979323846 -// #ifndef min -// #define min(a,b) (((a) < (b)) ? (a) : (b)) -// #endif - -// #ifndef max -// #define max(a,b) (((a) > (b)) ? (a) : (b)) -// #endif - -#ifdef __cplusplus -template -inline T clamp2(T const &val, T const &minVal, T const &maxVal) //renamed to clamp2 to avoid conflicts with clamp defined in mathlib -{ - if (val < minVal) - return minVal; - else if (val > maxVal) - return maxVal; - else - return val; -} +#ifndef min +#define min(a,b) (((a) < (b)) ? (a) : (b)) #endif +#ifndef max +#define max(a,b) (((a) > (b)) ? (a) : (b)) +#endif +#endif // MATHLIB_H + #ifndef FALSE #define FALSE 0 #define TRUE (!FALSE) @@ -81,7 +70,7 @@ typedef unsigned char BYTE; typedef unsigned char byte; typedef unsigned short word; -//#include "string_t.h" +#include "string_t.h" typedef float vec_t; diff --git a/regamedll/public/regamedll/platform.h b/regamedll/public/regamedll/platform.h deleted file mode 100644 index fd9a3046..00000000 --- a/regamedll/public/regamedll/platform.h +++ /dev/null @@ -1,651 +0,0 @@ -//=========== (C) Copyright 1999 Valve, L.L.C. All rights reserved. =========== -// -// The copyright to the contents herein is the property of Valve, L.L.C. -// The contents may be used and/or copied only with the written permission of -// Valve, L.L.C., or in accordance with the terms and conditions stipulated in -// the agreement/contract under which the contents have been supplied. -// -// $Header: $ -// $NoKeywords: $ -// -// Extremely low-level platform-specific stuff -//============================================================================= - - -#ifndef PLATFORM_H -#define PLATFORM_H - -#ifdef _WIN32 -#pragma once -#endif - -#include "osconfig.h" - -// need this for _alloca -#include - -// need this for memset -#include - -// for when we care about how many bits we use -typedef signed char int8; -typedef signed short int16; - -#ifdef _WIN32 -#ifdef _MSC_VER -typedef signed __int64 int64; -#endif -#elif defined __linux__ -typedef long long int64; -#endif - -typedef unsigned char uint8; -typedef unsigned short uint16; -#ifdef _WIN32 -#ifdef _MSC_VER -typedef unsigned __int64 uint64; -#endif -#elif defined __linux__ -typedef unsigned long long uint64; -#endif - - -typedef float float32; -typedef double float64; - -// for when we don't care about how many bits we use -typedef unsigned int uint; - -// This can be used to ensure the size of pointers to members when declaring -// a pointer type for a class that has only been forward declared -#ifdef _MSC_VER -#define SINGLE_INHERITANCE __single_inheritance -#define MULTIPLE_INHERITANCE __multiple_inheritance -#else -#define SINGLE_INHERITANCE -#define MULTIPLE_INHERITANCE -#endif - -/* -FIXME: Enable this when we no longer fear change =) - -// need these for the limits -#include -#include - -// Maximum and minimum representable values -#define INT8_MAX SCHAR_MAX -#define INT16_MAX SHRT_MAX -#define INT32_MAX LONG_MAX -#define INT64_MAX (((int64)~0) >> 1) - -#define INT8_MIN SCHAR_MIN -#define INT16_MIN SHRT_MIN -#define INT32_MIN LONG_MIN -#define INT64_MIN (((int64)1) << 63) - -#define UINT8_MAX ((uint8)~0) -#define UINT16_MAX ((uint16)~0) -#define UINT32_MAX ((uint32_t)~0) -#define UINT64_MAX ((uint64)~0) - -#define UINT8_MIN 0 -#define UINT16_MIN 0 -#define UINT32_MIN 0 -#define UINT64_MIN 0 - -#ifndef UINT_MIN -#define UINT_MIN UINT32_MIN -#endif - -#define FLOAT32_MAX FLT_MAX -#define FLOAT64_MAX DBL_MAX - -#define FLOAT32_MIN FLT_MIN -#define FLOAT64_MIN DBL_MIN -*/ - -// portability / compiler settings -#if defined(_WIN32) && !defined(WINDED) - -#if defined(_M_IX86) -#define __i386__ 1 -#endif - -#elif __linux__ -typedef void * HINSTANCE; -#define _MAX_PATH PATH_MAX -#endif // defined(_WIN32) && !defined(WINDED) - - -// Defines MAX_PATH -#ifndef MAX_PATH -#define MAX_PATH 260 -#endif - -// Used to step into the debugger -#define DebuggerBreak() __asm { int 3 } - -// C functions for external declarations that call the appropriate C++ methods -#ifndef EXPORT -#ifdef _WIN32 -#define EXPORT _declspec( dllexport ) -#else -#define EXPORT /* */ -#endif -#endif - -#if defined __i386__ && !defined __linux__ -#define id386 1 -#else -#define id386 0 -#endif // __i386__ - -#ifdef _WIN32 -// Used for dll exporting and importing -#define DLL_EXPORT extern "C" __declspec( dllexport ) -#define DLL_IMPORT extern "C" __declspec( dllimport ) - -// Can't use extern "C" when DLL exporting a class -#define DLL_CLASS_EXPORT __declspec( dllexport ) -#define DLL_CLASS_IMPORT __declspec( dllimport ) - -// Can't use extern "C" when DLL exporting a global -#define DLL_GLOBAL_EXPORT extern __declspec( dllexport ) -#define DLL_GLOBAL_IMPORT extern __declspec( dllimport ) -#elif defined __linux__ - -// Used for dll exporting and importing -#define DLL_EXPORT extern "C" -#define DLL_IMPORT extern "C" - -// Can't use extern "C" when DLL exporting a class -#define DLL_CLASS_EXPORT -#define DLL_CLASS_IMPORT - -// Can't use extern "C" when DLL exporting a global -#define DLL_GLOBAL_EXPORT extern -#define DLL_GLOBAL_IMPORT extern - -#else -#error "Unsupported Platform." -#endif - -// Used for standard calling conventions -#ifdef _WIN32 -#define FASTCALL __fastcall -#define FORCEINLINE __forceinline -#else -#define FASTCALL -#define FORCEINLINE inline -#endif - -// Force a function call site -not- to inlined. (useful for profiling) -#define DONT_INLINE(a) (((int)(a)+1)?(a):(a)) - -// Pass hints to the compiler to prevent it from generating unnessecary / stupid code -// in certain situations. Several compilers other than MSVC also have an equivilent -// construct. -// -// Essentially the 'Hint' is that the condition specified is assumed to be true at -// that point in the compilation. If '0' is passed, then the compiler assumes that -// any subsequent code in the same 'basic block' is unreachable, and thus usually -// removed. -#ifdef _MSC_VER -#define HINT(THE_HINT) __assume((THE_HINT)) -#else -#define HINT(THE_HINT) 0 -#endif - -// Marks the codepath from here until the next branch entry point as unreachable, -// and asserts if any attempt is made to execute it. -#define UNREACHABLE() { Assert(0); HINT(0); } - -// In cases where no default is present or appropriate, this causes MSVC to generate -// as little code as possible, and throw an assertion in debug. -#define NO_DEFAULT default: UNREACHABLE(); - -#ifdef _WIN32 -// Alloca defined for this platform -#define stackalloc( _size ) _alloca( _size ) -#define stackfree( _p ) 0 -#elif __linux__ -// Alloca defined for this platform -#define stackalloc( _size ) alloca( _size ) -#define stackfree( _p ) 0 -#endif - -#ifdef _WIN32 -// Remove warnings from warning level 4. -#pragma warning(disable : 4514) // warning C4514: 'acosl' : unreferenced inline function has been removed -#pragma warning(disable : 4100) // warning C4100: 'hwnd' : unreferenced formal parameter -#pragma warning(disable : 4127) // warning C4127: conditional expression is constant -#pragma warning(disable : 4512) // warning C4512: 'InFileRIFF' : assignment operator could not be generated -#pragma warning(disable : 4611) // warning C4611: interaction between '_setjmp' and C++ object destruction is non-portable -#pragma warning(disable : 4706) // warning C4706: assignment within conditional expression -#pragma warning(disable : 4710) // warning C4710: function 'x' not inlined -#pragma warning(disable : 4702) // warning C4702: unreachable code -#pragma warning(disable : 4505) // unreferenced local function has been removed -#pragma warning(disable : 4239) // nonstandard extension used : 'argument' ( conversion from class Vector to class Vector& ) -#pragma warning(disable : 4097) // typedef-name 'BaseClass' used as synonym for class-name 'CFlexCycler::CBaseFlex' -#pragma warning(disable : 4324) // Padding was added at the end of a structure -#pragma warning(disable : 4244) // type conversion warning. -#pragma warning(disable : 4305) // truncation from 'const double ' to 'float ' -#pragma warning(disable : 4786) // Disable warnings about long symbol names - -#if _MSC_VER >= 1300 -#pragma warning(disable : 4511) // Disable warnings about private copy constructors -#endif -#endif -//----------------------------------------------------------------------------- -// Purpose: Standard functions for handling endian-ness -//----------------------------------------------------------------------------- - -//------------------------------------- -// Basic swaps -//------------------------------------- - -template -inline T WordSwapC(T w) -{ - uint16 temp; - - temp = ((*((uint16 *)&w) & 0xff00) >> 8); - temp |= ((*((uint16 *)&w) & 0x00ff) << 8); - - return *((T*)&temp); -} - -template -inline T DWordSwapC(T dw) -{ - uint32_t temp; - - temp = *((uint32_t *)&dw) >> 24; - temp |= ((*((uint32_t *)&dw) & 0x00FF0000) >> 8); - temp |= ((*((uint32_t *)&dw) & 0x0000FF00) << 8); - temp |= ((*((uint32_t *)&dw) & 0x000000FF) << 24); - - return *((T*)&temp); -} - -//------------------------------------- -// Fast swaps -//------------------------------------- - -#ifdef _MSC_VER - -#define WordSwap WordSwapAsm -#define DWordSwap DWordSwapAsm - -#pragma warning(push) -#pragma warning (disable:4035) // no return value - -template -inline T WordSwapAsm(T w) -{ - __asm - { - mov ax, w - xchg al, ah - } -} - -template -inline T DWordSwapAsm(T dw) -{ - __asm - { - mov eax, dw - bswap eax - } -} - -#pragma warning(pop) - -// The assembly implementation is not compatible with floats -template <> -inline float DWordSwapAsm(float f) -{ - return DWordSwapC(f); -} - -#else - -#define WordSwap WordSwapC -#define DWordSwap DWordSwapC - -#endif - -//------------------------------------- -// The typically used methods. -//------------------------------------- - -#if defined(__i386__) -#define VALVE_LITTLE_ENDIAN 1 -#endif - -#ifdef _SGI_SOURCE -#define VALVE_BIG_ENDIAN 1 -#endif - -#if defined(VALVE_LITTLE_ENDIAN) - -#define Valve_BigShort( val ) WordSwap( val ) -#define Valve_BigWord( val ) WordSwap( val ) -#define Valve_BigLong( val ) DWordSwap( val ) -#define Valve_BigDWord( val ) DWordSwap( val ) -#define Valve_BigFloat( val ) DWordSwap( val ) -#define Valve_LittleShort( val ) ( val ) -#define Valve_LittleWord( val ) ( val ) -#define Valve_LittleLong( val ) ( val ) -#define Valve_LittleDWord( val ) ( val ) -#define Valve_LittleFloat( val ) ( val ) - -#elif defined(BIG_ENDIAN) - -#define Valve_BigShort( val ) ( val ) -#define Valve_BigWord( val ) ( val ) -#define Valve_BigLong( val ) ( val ) -#define Valve_BigDWord( val ) ( val ) -#define Valve_BigFloat( val ) ( val ) -#define Valve_LittleShort( val ) WordSwap( val ) -#define Valve_LittleWord( val ) WordSwap( val ) -#define Valve_LittleLong( val ) DWordSwap( val ) -#define Valve_LittleDWord( val ) DWordSwap( val ) -#define Valve_LittleFloat( val ) DWordSwap( val ) - -#else - -// @Note (toml 05-02-02): this technique expects the compiler to -// optimize the expression and eliminate the other path. On any new -// platform/compiler this should be tested. -inline short BigShort(short val) { int test = 1; return (*(char *)&test == 1) ? WordSwap(val) : val; } -inline uint16 BigWord(uint16 val) { int test = 1; return (*(char *)&test == 1) ? WordSwap(val) : val; } -inline long BigLong(long val) { int test = 1; return (*(char *)&test == 1) ? DWordSwap(val) : val; } -inline uint32_t BigDWord(uint32_t val) { int test = 1; return (*(char *)&test == 1) ? DWordSwap(val) : val; } -inline float BigFloat(float val) { int test = 1; return (*(char *)&test == 1) ? DWordSwap(val) : val; } -inline short LittleShort(short val) { int test = 1; return (*(char *)&test == 1) ? val : WordSwap(val); } -inline uint16 LittleWord(uint16 val) { int test = 1; return (*(char *)&test == 1) ? val : WordSwap(val); } -inline long LittleLong(long val) { int test = 1; return (*(char *)&test == 1) ? val : DWordSwap(val); } -inline uint32_t LittleDWord(uint32_t val) { int test = 1; return (*(char *)&test == 1) ? val : DWordSwap(val); } -inline float LittleFloat(float val) { int test = 1; return (*(char *)&test == 1) ? val : DWordSwap(val); } - -#endif - - - -#ifdef TIER0_DLL_EXPORT -#define PLATFORM_INTERFACE DLL_EXPORT -#define PLATFORM_OVERLOAD DLL_GLOBAL_EXPORT -#else -#define PLATFORM_INTERFACE DLL_IMPORT -#define PLATFORM_OVERLOAD DLL_GLOBAL_IMPORT -#endif - -/* -PLATFORM_INTERFACE double Plat_FloatTime(); // Returns time in seconds since the module was loaded. -PLATFORM_INTERFACE unsigned long Plat_MSTime(); // Time in milliseconds. - -// b/w compatibility -#define Sys_FloatTime Plat_FloatTime -*/ - -// Processor Information: -struct CPUInformation -{ - int m_Size; // Size of this structure, for forward compatability. - - bool m_bRDTSC : 1, // Is RDTSC supported? - m_bCMOV : 1, // Is CMOV supported? - m_bFCMOV : 1, // Is FCMOV supported? - m_bSSE : 1, // Is SSE supported? - m_bSSE2 : 1, // Is SSE2 Supported? - m_b3DNow : 1, // Is 3DNow! Supported? - m_bMMX : 1, // Is MMX supported? - m_bHT : 1; // Is HyperThreading supported? - - unsigned char m_nLogicalProcessors, // Number op logical processors. - m_nPhysicalProcessors; // Number of physical processors - - int64 m_Speed; // In cycles per second. - - char* m_szProcessorID; // Processor vendor Identification. -}; - -PLATFORM_INTERFACE const CPUInformation& GetCPUInformation(); - - -//----------------------------------------------------------------------------- -// Thread related functions -//----------------------------------------------------------------------------- -// Registers the current thread with Tier0's thread management system. -// This should be called on every thread created in the game. -PLATFORM_INTERFACE unsigned long Plat_RegisterThread(const char *pName = "Source Thread"); - -// Registers the current thread as the primary thread. -PLATFORM_INTERFACE unsigned long Plat_RegisterPrimaryThread(); - -// VC-specific. Sets the thread's name so it has a friendly name in the debugger. -// This should generally only be handled by Plat_RegisterThread and Plat_RegisterPrimaryThread -PLATFORM_INTERFACE void Plat_SetThreadName(unsigned long dwThreadID, const char *pName); - -// These would be private if it were possible to export private variables from a .DLL. -// They need to be variables because they are checked by inline functions at performance -// critical places. -PLATFORM_INTERFACE unsigned long Plat_PrimaryThreadID; - -// Returns the ID of the currently executing thread. -PLATFORM_INTERFACE unsigned long Plat_GetCurrentThreadID(); - -// Returns the ID of the primary thread. -inline unsigned long Plat_GetPrimaryThreadID() -{ - return Plat_PrimaryThreadID; -} - -// Returns true if the current thread is the primary thread. -inline bool Plat_IsPrimaryThread() -{ - //return true; - return (Plat_GetPrimaryThreadID() == Plat_GetCurrentThreadID()); -} - -//----------------------------------------------------------------------------- -// Security related functions -//----------------------------------------------------------------------------- -// Ensure that the hardware key's drivers have been installed. -PLATFORM_INTERFACE bool Plat_VerifyHardwareKeyDriver(); - -// Ok, so this isn't a very secure way to verify the hardware key for now. It -// is primarially depending on the fact that all the binaries have been wrapped -// with the secure wrapper provided by the hardware keys vendor. -PLATFORM_INTERFACE bool Plat_VerifyHardwareKey(); - -// The same as above, but notifies user with a message box when the key isn't in -// and gives him an opportunity to correct the situation. -PLATFORM_INTERFACE bool Plat_VerifyHardwareKeyPrompt(); - -// Can be called in real time, doesn't perform the verify every frame. Mainly just -// here to allow the game to drop out quickly when the key is removed, rather than -// allowing the wrapper to pop up it's own blocking dialog, which the engine doesn't -// like much. -PLATFORM_INTERFACE bool Plat_FastVerifyHardwareKey(); - - - -//----------------------------------------------------------------------------- -// Include additional dependant header components. -//----------------------------------------------------------------------------- -//#include "tier0/fasttimer.h" - - -//----------------------------------------------------------------------------- -// Just logs file and line to simple.log -//----------------------------------------------------------------------------- -void* Plat_SimpleLog(const char* file, int line); - -//#define Plat_dynamic_cast Plat_SimpleLog(__FILE__,__LINE__),dynamic_cast - -//----------------------------------------------------------------------------- -// Methods to invoke the constructor, copy constructor, and destructor -//----------------------------------------------------------------------------- - -template -inline void Construct(T* pMemory) -{ - new(pMemory)T; -} - -template -inline void CopyConstruct(T* pMemory, T const& src) -{ - new(pMemory)T(src); -} - -template -inline void Destruct(T* pMemory) -{ - pMemory->~T(); - -#ifdef _DEBUG - memset(pMemory, 0xDD, sizeof(T)); -#endif -} - - -// -// GET_OUTER() -// -// A platform-independent way for a contained class to get a pointer to its -// owner. If you know a class is exclusively used in the context of some -// "outer" class, this is a much more space efficient way to get at the outer -// class than having the inner class store a pointer to it. -// -// class COuter -// { -// class CInner // Note: this does not need to be a nested class to work -// { -// void PrintAddressOfOuter() -// { -// printf( "Outer is at 0x%x\n", GET_OUTER( COuter, m_Inner ) ); -// } -// }; -// -// CInner m_Inner; -// friend class CInner; -// }; - -#define GET_OUTER( OuterType, OuterMember ) \ - ( ( OuterType * ) ( (char *)this - offsetof( OuterType, OuterMember ) ) ) - - -/* TEMPLATE_FUNCTION_TABLE() - -(Note added to platform.h so platforms that correctly support templated -functions can handle portions as templated functions rather than wrapped -functions) - -Helps automate the process of creating an array of function -templates that are all specialized by a single integer. -This sort of thing is often useful in optimization work. - -For example, using TEMPLATE_FUNCTION_TABLE, this: - -TEMPLATE_FUNCTION_TABLE(int, Function, ( int blah, int blah ), 10) -{ -return argument * argument; -} - -is equivilent to the following: - -(NOTE: the function has to be wrapped in a class due to code -generation bugs involved with directly specializing a function -based on a constant.) - -template -class FunctionWrapper -{ -public: -int Function( int blah, int blah ) -{ -return argument*argument; -} -} - -typedef int (*FunctionType)( int blah, int blah ); - -class FunctionName -{ -public: -enum { count = 10 }; -FunctionType functions[10]; -}; - -FunctionType FunctionName::functions[] = -{ -FunctionWrapper<0>::Function, -FunctionWrapper<1>::Function, -FunctionWrapper<2>::Function, -FunctionWrapper<3>::Function, -FunctionWrapper<4>::Function, -FunctionWrapper<5>::Function, -FunctionWrapper<6>::Function, -FunctionWrapper<7>::Function, -FunctionWrapper<8>::Function, -FunctionWrapper<9>::Function -}; -*/ - -bool vtune(bool resume); - - -#define TEMPLATE_FUNCTION_TABLE(RETURN_TYPE, NAME, ARGS, COUNT) \ - \ -typedef RETURN_TYPE (FASTCALL *__Type_##NAME) ARGS; \ - \ -template \ -struct __Function_##NAME \ -{ \ - static RETURN_TYPE FASTCALL Run ARGS; \ -}; \ - \ -template \ -struct __MetaLooper_##NAME : __MetaLooper_##NAME \ -{ \ - __Type_##NAME func; \ - inline __MetaLooper_##NAME() { func = __Function_##NAME::Run; } \ -}; \ - \ -template<> \ -struct __MetaLooper_##NAME<0> \ -{ \ - __Type_##NAME func; \ - inline __MetaLooper_##NAME() { func = __Function_##NAME<0>::Run; } \ -}; \ - \ -class NAME \ -{ \ -private: \ - static const __MetaLooper_##NAME m; \ -public: \ - enum { count = COUNT }; \ - static const __Type_##NAME* functions; \ -}; \ -const __MetaLooper_##NAME NAME::m; \ -const __Type_##NAME* NAME::functions = (__Type_##NAME*)&m; \ -template \ -RETURN_TYPE FASTCALL __Function_##NAME::Run ARGS - - -#define LOOP_INTERCHANGE(BOOLEAN, CODE)\ - if( (BOOLEAN) )\ - {\ - CODE;\ - } else\ - {\ - CODE;\ - } - - -#endif /* PLATFORM_H */ \ No newline at end of file diff --git a/regamedll/regamedll/platform.h b/regamedll/regamedll/platform.h index b99e47d6..b4af38ec 100644 --- a/regamedll/regamedll/platform.h +++ b/regamedll/regamedll/platform.h @@ -9,4 +9,4 @@ extern void regamedll_log(const char *fmt, ...); extern void __declspec(noreturn) regamedll_syserror(const char *fmt, ...); -#endif // PLATFORM_GAMEDLL_H \ No newline at end of file +#endif // PLATFORM_GAMEDLL_H diff --git a/regamedll/regamedll/precompiled.h b/regamedll/regamedll/precompiled.h index 2566643e..529bd206 100644 --- a/regamedll/regamedll/precompiled.h +++ b/regamedll/regamedll/precompiled.h @@ -6,7 +6,6 @@ #include "basetypes.h" #include "archtypes.h" -#include "asmlib.h" #include "sse_mathfun.h" #include "MemPool.h"