diff --git a/README.md b/README.md index 62d670e..edb544e 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ On Windows:
gradlew --max-workers=1 clean buildRelease
* For faster building without unit tests use this:exclamation:
gradlew --max-workers=1 clean buildFixes
+NOTE: You can also use `Visual Studio` to build, just select from the solution configurations list `Release Swds` or `Debug Swds`
On Linux (ICC):
./gradlew --max-workers=1 clean buildRelease
diff --git a/dep/bzip2/msvc/bzip2.vcxproj b/dep/bzip2/msvc/bzip2.vcxproj index 650c842..57a808f 100644 --- a/dep/bzip2/msvc/bzip2.vcxproj +++ b/dep/bzip2/msvc/bzip2.vcxproj @@ -5,6 +5,10 @@ Debug Win32 + + Release Swds + Win32 + Release Win32 @@ -33,6 +37,15 @@ true Unicode + + StaticLibrary + false + v120 + v140 + v141 + true + Unicode + @@ -42,6 +55,9 @@ + + + @@ -78,6 +94,25 @@ true + + + Level3 + Use + MaxSpeed + true + true + _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + $(ProjectDir)..\include\ + MultiThreaded + bzlib_private.h + + + Windows + true + true + true + + @@ -91,6 +126,7 @@ Create Create + Create diff --git a/dep/cppunitlite/msvc/cppunitlite.vcxproj b/dep/cppunitlite/msvc/cppunitlite.vcxproj index a9518db..4d2c96b 100644 --- a/dep/cppunitlite/msvc/cppunitlite.vcxproj +++ b/dep/cppunitlite/msvc/cppunitlite.vcxproj @@ -5,6 +5,10 @@ Debug Win32 + + Release Swds + Win32 + Release Win32 @@ -49,6 +53,15 @@ true MultiByte + + StaticLibrary + false + v120 + v140 + v141 + true + MultiByte + @@ -58,6 +71,9 @@ + + + @@ -96,6 +112,26 @@ true + + + Level3 + + + MaxSpeed + true + true + WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_LIB;%(PreprocessorDefinitions) + MultiThreaded + $(ProjectDir)..\include\ + false + + + Windows + true + true + true + + diff --git a/msvc/ReHLDS.sln b/msvc/ReHLDS.sln index 242f435..e5ede79 100644 --- a/msvc/ReHLDS.sln +++ b/msvc/ReHLDS.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.30501.0 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ReHLDS", "..\rehlds\msvc\ReHLDS.vcxproj", "{70A2B904-B7DB-4C48-8DE0-AF567360D572}" ProjectSection(ProjectDependencies) = postProject @@ -47,6 +47,7 @@ Global Debug|Win32 = Debug|Win32 Release Play|Win32 = Release Play|Win32 Release Swds Play|Win32 = Release Swds Play|Win32 + Release Swds|Win32 = Release Swds|Win32 Release|Win32 = Release|Win32 Test Fixes|Win32 = Test Fixes|Win32 Tests|Win32 = Tests|Win32 @@ -66,6 +67,8 @@ Global {70A2B904-B7DB-4C48-8DE0-AF567360D572}.Release Play|Win32.Build.0 = Release Play|Win32 {70A2B904-B7DB-4C48-8DE0-AF567360D572}.Release Swds Play|Win32.ActiveCfg = Release Swds Play|Win32 {70A2B904-B7DB-4C48-8DE0-AF567360D572}.Release Swds Play|Win32.Build.0 = Release Swds Play|Win32 + {70A2B904-B7DB-4C48-8DE0-AF567360D572}.Release Swds|Win32.ActiveCfg = Release Swds|Win32 + {70A2B904-B7DB-4C48-8DE0-AF567360D572}.Release Swds|Win32.Build.0 = Release Swds|Win32 {70A2B904-B7DB-4C48-8DE0-AF567360D572}.Release|Win32.ActiveCfg = Release|Win32 {70A2B904-B7DB-4C48-8DE0-AF567360D572}.Release|Win32.Build.0 = Release|Win32 {70A2B904-B7DB-4C48-8DE0-AF567360D572}.Test Fixes|Win32.ActiveCfg = Test Fixes|Win32 @@ -86,6 +89,8 @@ Global {CEB94F7C-E459-4673-AABB-36E2074396C0}.Release Play|Win32.Build.0 = Release|Win32 {CEB94F7C-E459-4673-AABB-36E2074396C0}.Release Swds Play|Win32.ActiveCfg = Release|Win32 {CEB94F7C-E459-4673-AABB-36E2074396C0}.Release Swds Play|Win32.Build.0 = Release|Win32 + {CEB94F7C-E459-4673-AABB-36E2074396C0}.Release Swds|Win32.ActiveCfg = Release|Win32 + {CEB94F7C-E459-4673-AABB-36E2074396C0}.Release Swds|Win32.Build.0 = Release|Win32 {CEB94F7C-E459-4673-AABB-36E2074396C0}.Release|Win32.ActiveCfg = Release|Win32 {CEB94F7C-E459-4673-AABB-36E2074396C0}.Release|Win32.Build.0 = Release|Win32 {CEB94F7C-E459-4673-AABB-36E2074396C0}.Test Fixes|Win32.ActiveCfg = Release|Win32 @@ -106,6 +111,8 @@ Global {792DF067-9904-4579-99B9-46C17277ADE3}.Release Play|Win32.Build.0 = Release|Win32 {792DF067-9904-4579-99B9-46C17277ADE3}.Release Swds Play|Win32.ActiveCfg = Release|Win32 {792DF067-9904-4579-99B9-46C17277ADE3}.Release Swds Play|Win32.Build.0 = Release|Win32 + {792DF067-9904-4579-99B9-46C17277ADE3}.Release Swds|Win32.ActiveCfg = Release|Win32 + {792DF067-9904-4579-99B9-46C17277ADE3}.Release Swds|Win32.Build.0 = Release|Win32 {792DF067-9904-4579-99B9-46C17277ADE3}.Release|Win32.ActiveCfg = Release|Win32 {792DF067-9904-4579-99B9-46C17277ADE3}.Release|Win32.Build.0 = Release|Win32 {792DF067-9904-4579-99B9-46C17277ADE3}.Test Fixes|Win32.ActiveCfg = Release|Win32 @@ -126,6 +133,8 @@ Global {D49883F3-5C5C-4B9F-B9C7-B31518F228D4}.Release Play|Win32.Build.0 = Release|Win32 {D49883F3-5C5C-4B9F-B9C7-B31518F228D4}.Release Swds Play|Win32.ActiveCfg = Release|Win32 {D49883F3-5C5C-4B9F-B9C7-B31518F228D4}.Release Swds Play|Win32.Build.0 = Release|Win32 + {D49883F3-5C5C-4B9F-B9C7-B31518F228D4}.Release Swds|Win32.ActiveCfg = Release|Win32 + {D49883F3-5C5C-4B9F-B9C7-B31518F228D4}.Release Swds|Win32.Build.0 = Release|Win32 {D49883F3-5C5C-4B9F-B9C7-B31518F228D4}.Release|Win32.ActiveCfg = Release|Win32 {D49883F3-5C5C-4B9F-B9C7-B31518F228D4}.Release|Win32.Build.0 = Release|Win32 {D49883F3-5C5C-4B9F-B9C7-B31518F228D4}.Test Fixes|Win32.ActiveCfg = Release|Win32 @@ -146,6 +155,8 @@ Global {D5CAB879-D54F-456F-8592-31D549CFD1D8}.Release Play|Win32.Build.0 = Release|Win32 {D5CAB879-D54F-456F-8592-31D549CFD1D8}.Release Swds Play|Win32.ActiveCfg = Release|Win32 {D5CAB879-D54F-456F-8592-31D549CFD1D8}.Release Swds Play|Win32.Build.0 = Release|Win32 + {D5CAB879-D54F-456F-8592-31D549CFD1D8}.Release Swds|Win32.ActiveCfg = Release|Win32 + {D5CAB879-D54F-456F-8592-31D549CFD1D8}.Release Swds|Win32.Build.0 = Release|Win32 {D5CAB879-D54F-456F-8592-31D549CFD1D8}.Release|Win32.ActiveCfg = Release|Win32 {D5CAB879-D54F-456F-8592-31D549CFD1D8}.Release|Win32.Build.0 = Release|Win32 {D5CAB879-D54F-456F-8592-31D549CFD1D8}.Test Fixes|Win32.ActiveCfg = Release|Win32 @@ -166,6 +177,8 @@ Global {52F752EA-73D1-422D-B805-17EF1FB20E09}.Release Play|Win32.Build.0 = Release|Win32 {52F752EA-73D1-422D-B805-17EF1FB20E09}.Release Swds Play|Win32.ActiveCfg = Release|Win32 {52F752EA-73D1-422D-B805-17EF1FB20E09}.Release Swds Play|Win32.Build.0 = Release|Win32 + {52F752EA-73D1-422D-B805-17EF1FB20E09}.Release Swds|Win32.ActiveCfg = Release|Win32 + {52F752EA-73D1-422D-B805-17EF1FB20E09}.Release Swds|Win32.Build.0 = Release|Win32 {52F752EA-73D1-422D-B805-17EF1FB20E09}.Release|Win32.ActiveCfg = Release|Win32 {52F752EA-73D1-422D-B805-17EF1FB20E09}.Release|Win32.Build.0 = Release|Win32 {52F752EA-73D1-422D-B805-17EF1FB20E09}.Test Fixes|Win32.ActiveCfg = Release|Win32 @@ -186,6 +199,8 @@ Global {05292761-0847-4A68-BA10-9D384DC0D3EE}.Release Play|Win32.Build.0 = Release|Win32 {05292761-0847-4A68-BA10-9D384DC0D3EE}.Release Swds Play|Win32.ActiveCfg = Release|Win32 {05292761-0847-4A68-BA10-9D384DC0D3EE}.Release Swds Play|Win32.Build.0 = Release|Win32 + {05292761-0847-4A68-BA10-9D384DC0D3EE}.Release Swds|Win32.ActiveCfg = Release|Win32 + {05292761-0847-4A68-BA10-9D384DC0D3EE}.Release Swds|Win32.Build.0 = Release|Win32 {05292761-0847-4A68-BA10-9D384DC0D3EE}.Release|Win32.ActiveCfg = Release|Win32 {05292761-0847-4A68-BA10-9D384DC0D3EE}.Release|Win32.Build.0 = Release|Win32 {05292761-0847-4A68-BA10-9D384DC0D3EE}.Test Fixes|Win32.ActiveCfg = Release|Win32 @@ -206,6 +221,8 @@ Global {04D0594C-57F5-4277-AF1B-EAE90AED0C3C}.Release Play|Win32.Build.0 = Release|Win32 {04D0594C-57F5-4277-AF1B-EAE90AED0C3C}.Release Swds Play|Win32.ActiveCfg = Release|Win32 {04D0594C-57F5-4277-AF1B-EAE90AED0C3C}.Release Swds Play|Win32.Build.0 = Release|Win32 + {04D0594C-57F5-4277-AF1B-EAE90AED0C3C}.Release Swds|Win32.ActiveCfg = Release|Win32 + {04D0594C-57F5-4277-AF1B-EAE90AED0C3C}.Release Swds|Win32.Build.0 = Release|Win32 {04D0594C-57F5-4277-AF1B-EAE90AED0C3C}.Release|Win32.ActiveCfg = Release|Win32 {04D0594C-57F5-4277-AF1B-EAE90AED0C3C}.Release|Win32.Build.0 = Release|Win32 {04D0594C-57F5-4277-AF1B-EAE90AED0C3C}.Test Fixes|Win32.ActiveCfg = Release|Win32 @@ -226,6 +243,8 @@ Global {ADDFF069-D39D-4A1B-87C9-85A62B980547}.Release Play|Win32.Build.0 = Release|Win32 {ADDFF069-D39D-4A1B-87C9-85A62B980547}.Release Swds Play|Win32.ActiveCfg = Release|Win32 {ADDFF069-D39D-4A1B-87C9-85A62B980547}.Release Swds Play|Win32.Build.0 = Release|Win32 + {ADDFF069-D39D-4A1B-87C9-85A62B980547}.Release Swds|Win32.ActiveCfg = Release|Win32 + {ADDFF069-D39D-4A1B-87C9-85A62B980547}.Release Swds|Win32.Build.0 = Release|Win32 {ADDFF069-D39D-4A1B-87C9-85A62B980547}.Release|Win32.ActiveCfg = Release|Win32 {ADDFF069-D39D-4A1B-87C9-85A62B980547}.Release|Win32.Build.0 = Release|Win32 {ADDFF069-D39D-4A1B-87C9-85A62B980547}.Test Fixes|Win32.ActiveCfg = Release|Win32 diff --git a/rehlds/HLTV/Console/msvc/Console.vcxproj b/rehlds/HLTV/Console/msvc/Console.vcxproj index 001b45b..8661108 100644 --- a/rehlds/HLTV/Console/msvc/Console.vcxproj +++ b/rehlds/HLTV/Console/msvc/Console.vcxproj @@ -5,6 +5,10 @@ Debug Win32 + + Release Swds + Win32 + Release Win32 @@ -29,46 +33,57 @@ Use Use + Use Use Use + Use Use Use + Use Use Use + Use Use Use + Use Use Use + Use Use + Use Use Use Use + Use Create + Create Create Use + Use Use Use + Use Use @@ -103,6 +118,15 @@ true MultiByte + + Application + false + v120_xp + v140_xp + v141_xp + true + MultiByte + @@ -114,6 +138,9 @@ + + + true @@ -123,6 +150,10 @@ false hltv + + false + hltv + Use @@ -148,8 +179,8 @@ echo Empty Action Force build to run Pre-Build event - git.always.run - git.always.run + build.always.run + build.always.run @@ -180,8 +211,40 @@ echo Empty Action Force build to run Pre-Build event - git.always.run - git.always.run + build.always.run + build.always.run + + + + + Level3 + Use + Disabled + true + true + HLTV;WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + $(ProjectDir)\..\src;$(ProjectDir)\..\..\;$(ProjectDir)\..\..\..\;$(ProjectDir)\..\..\..\common;$(ProjectDir)\..\..\..\engine;$(ProjectDir)\..\..\..\public;$(ProjectDir)\..\..\..\public\rehlds;%(AdditionalIncludeDirectories) + precompiled.h + MultiThreaded + + + Windows + true + true + true + user32.lib;%(AdditionalDependencies) + + + IF EXIST "$(ProjectDir)PostBuild.bat" (CALL "$(ProjectDir)PostBuild.bat" "$(TargetDir)" "$(TargetName)" "$(TargetExt)" "$(ProjectDir)") + + + Automatic deployment script + + + echo Empty Action + Force build to run Pre-Build event + build.always.run + build.always.run diff --git a/rehlds/HLTV/Console/src/System.cpp b/rehlds/HLTV/Console/src/System.cpp index 6cc4957..07eb3db 100644 --- a/rehlds/HLTV/Console/src/System.cpp +++ b/rehlds/HLTV/Console/src/System.cpp @@ -143,7 +143,7 @@ bool System::RegisterCommand(char *name, ISystemModule *module, int commandID) cmd = (command_t *)malloc(sizeof(command_t)); - strcopy(cmd->name, name); + Q_strlcpy(cmd->name, name); cmd->module = module; cmd->commandID = commandID; @@ -355,7 +355,7 @@ bool System::Init(IBaseSystem *system, int serial, char *name) SetName("system"); } - strcopy(m_BaseDir, GetBaseDir()); + Q_strlcpy(m_BaseDir, GetBaseDir()); m_Developer = CheckParam("-dev") ? true : false; if (!m_Console.Init(this)) @@ -480,7 +480,7 @@ void System::StopVGUI() void System::SetName(char *newName) { - strcopy(m_Name, newName); + Q_strlcpy(m_Name, newName); } void System::RunFrame(double time) @@ -776,7 +776,7 @@ void System::CMD_Quit(char *cmdLine) void System::OpenLogFile(char *filename) { CloseLogFile(); - strcopy(m_LogFileName, filename); + Q_strlcpy(m_LogFileName, filename); m_LogFile = m_FileSystem->Open(m_LogFileName, "wt"); if (!m_LogFile) @@ -866,7 +866,7 @@ void System::ExecuteCommandLine() } memset(string, 0, sizeof(string)); - strcopy(string, token + 1); + Q_strlcpy(string, token + 1); // next iteration token = m_Parameters.GetToken(++i); @@ -942,7 +942,7 @@ void System::CMD_UnloadModule(char *cmdLine) System::library_t *System::GetLibrary(char *name) { char fixedname[MAX_PATH]; - strcopy(fixedname, name); + Q_strlcpy(fixedname, name); COM_FixSlashes(fixedname); library_t *lib = (library_t *)m_Libraries.GetFirst(); @@ -1033,7 +1033,7 @@ Panel *System::GetPanel() void System::SetStatusLine(char *text) { - strcopy(m_StatusLine, text); + Q_strlcpy(m_StatusLine, text); } void System::ShowConsole(bool visible) diff --git a/rehlds/HLTV/Console/src/precompiled.h b/rehlds/HLTV/Console/src/precompiled.h index 19ee736..828c1ff 100644 --- a/rehlds/HLTV/Console/src/precompiled.h +++ b/rehlds/HLTV/Console/src/precompiled.h @@ -1,9 +1,8 @@ #pragma once -#include "osconfig.h" -#include "archtypes.h" -#include "mathlib.h" +#include "basetypes.h" #include "FileSystem.h" +#include "strtools.h" #include #include diff --git a/rehlds/HLTV/Core/msvc/Core.vcxproj b/rehlds/HLTV/Core/msvc/Core.vcxproj index 67419f3..aca1150 100644 --- a/rehlds/HLTV/Core/msvc/Core.vcxproj +++ b/rehlds/HLTV/Core/msvc/Core.vcxproj @@ -5,6 +5,10 @@ Debug Win32 + + Release Swds + Win32 + Release Win32 @@ -34,6 +38,15 @@ true MultiByte + + DynamicLibrary + false + v120_xp + v140_xp + v141_xp + true + MultiByte + @@ -45,6 +58,9 @@ + + + true @@ -53,6 +69,9 @@ false + + false + Use @@ -81,15 +100,9 @@ echo Empty Action - - Force build to run Pre-Build event - - - git.always.run - - - git.always.run + build.always.run + build.always.run @@ -122,15 +135,44 @@ echo Empty Action - - Force build to run Pre-Build event + build.always.run + build.always.run + + + + Level3 + Use + MaxSpeed + true + true + HLTV;WIN32;NDEBUG;_WINDOWS;_USRDLL;CORE_MODULE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + + $(ProjectDir)\..\src;$(ProjectDir)\..\..\;$(ProjectDir)\..\..\..\;$(ProjectDir)\..\..\..\common;$(ProjectDir)\..\..\..\engine;$(ProjectDir)\..\..\..\public;$(ProjectDir)\..\..\..\public\rehlds;$(ProjectDir)\..\..\..\pm_shared;$(ProjectDir)\..\..\..\..\dep\bzip2\include;%(AdditionalIncludeDirectories) + precompiled.h + MultiThreaded + true + + + Windows + true + true + true + psapi.lib;ws2_32.lib;%(AdditionalDependencies) + + + IF EXIST "$(ProjectDir)PostBuild.bat" (CALL "$(ProjectDir)PostBuild.bat" "$(TargetDir)" "$(TargetName)" "$(TargetExt)" "$(ProjectDir)") + + + Automatic deployment script + - git.always.run - - - git.always.run + echo Empty Action + Force build to run Pre-Build event + build.always.run + build.always.run @@ -142,14 +184,17 @@ true true + true true true + true true true + true @@ -167,44 +212,58 @@ Use precompiled.h Use + Use precompiled.h + precompiled.h Use precompiled.h Use + Use precompiled.h + precompiled.h Use precompiled.h Use + Use precompiled.h + precompiled.h Use precompiled.h Use + Use precompiled.h + precompiled.h Create precompiled.h Create + Create precompiled.h + precompiled.h Use precompiled.h Use + Use precompiled.h + precompiled.h Use precompiled.h Use + Use precompiled.h + precompiled.h @@ -216,10 +275,12 @@ true true + true true true + true diff --git a/rehlds/HLTV/Core/src/BSPModel.cpp b/rehlds/HLTV/Core/src/BSPModel.cpp index 57ad2e4..5bf4328 100644 --- a/rehlds/HLTV/Core/src/BSPModel.cpp +++ b/rehlds/HLTV/Core/src/BSPModel.cpp @@ -705,7 +705,7 @@ bool BSPModel::LoadFromBuffer(unsigned int *buffer, int length, const char *name int i; Clear(); - strcopy(m_model.name, name); + Q_strlcpy(m_model.name, name); m_System->DPrintf("Loading model: %s (%i kB)\n", name, length / 1024); m_model.needload = NL_PRESENT; diff --git a/rehlds/HLTV/Core/src/Delta.cpp b/rehlds/HLTV/Core/src/Delta.cpp index 3ff95ae..7fc1e2d 100644 --- a/rehlds/HLTV/Core/src/Delta.cpp +++ b/rehlds/HLTV/Core/src/Delta.cpp @@ -1192,7 +1192,7 @@ bool Delta::ParseField(int count, delta_definition_t *pdefinition, delta_link_t return false; } - strcopy(pField->delta->fieldName, com_token); + Q_strlcpy(pField->delta->fieldName, com_token); pField->delta->fieldOffset = FindOffset(count, pdefinition, com_token); *pstream = COM_Parse(*pstream); @@ -1399,7 +1399,7 @@ bool Delta::ParseDescription(char *name, delta_t **ppdesc, char *pstream) if (_stricmp(com_token, "none")) { - strcopy(source, com_token); + Q_strlcpy(source, com_token); // Parse custom encoder function name pstream = COM_Parse(pstream); @@ -1408,7 +1408,7 @@ bool Delta::ParseDescription(char *name, delta_t **ppdesc, char *pstream) return false; } - strcopy(encoder, com_token); + Q_strlcpy(encoder, com_token); } // Parse fields @@ -1439,7 +1439,7 @@ bool Delta::ParseDescription(char *name, delta_t **ppdesc, char *pstream) if (encoder[0]) { - strcopy((*ppdesc)->conditionalencodename, encoder); + Q_strlcpy((*ppdesc)->conditionalencodename, encoder); (*ppdesc)->conditionalencodename[sizeof((*ppdesc)->conditionalencodename) - 1] = '\0'; (*ppdesc)->conditionalencode = nullptr; } diff --git a/rehlds/HLTV/Core/src/Network.cpp b/rehlds/HLTV/Core/src/Network.cpp index cd94db7..81b67d0 100644 --- a/rehlds/HLTV/Core/src/Network.cpp +++ b/rehlds/HLTV/Core/src/Network.cpp @@ -281,7 +281,7 @@ bool Network::ResolveAddress(char *string, NetAddress *address) ((sockaddr_in *)&sadr)->sin_family = AF_INET; ((sockaddr_in *)&sadr)->sin_port = 0; - strcopy(copy, string); + Q_strlcpy(copy, string); // Parse port char *colon = copy; @@ -384,7 +384,7 @@ char *Network::GetErrorText(int code) void Network::SetName(char *newName) { - strcopy(m_Name, newName); + Q_strlcpy(m_Name, newName); } void Network::UpdateStats() diff --git a/rehlds/HLTV/Core/src/Server.cpp b/rehlds/HLTV/Core/src/Server.cpp index 553b7c6..d166e0e 100644 --- a/rehlds/HLTV/Core/src/Server.cpp +++ b/rehlds/HLTV/Core/src/Server.cpp @@ -148,8 +148,8 @@ bool Server::Init(IBaseSystem *system, int serial, char *name) m_ClientData.Clear(); m_DemoData.Clear(); - strcopy(m_CDKey, "2123437429222"); - strcopy(m_HostName, "Unkown Host"); + Q_strlcpy(m_CDKey, "2123437429222"); + Q_strlcpy(m_HostName, "Unkown Host"); memset(m_SeqNrMap, 0, sizeof(m_SeqNrMap)); m_validSequence = 0; @@ -612,7 +612,7 @@ void Server::SendConnectPacket() return; } - strcopy(buffer, MD5_GetCDKeyHash(m_CDKey)); + Q_strlcpy(buffer, MD5_GetCDKeyHash(m_CDKey)); } protinfo.SetValueForKey("prot", COM_VarArgs("%i", m_AuthProtocol)); @@ -787,9 +787,9 @@ void Server::ParseServerinfo() char levelname[MAX_PATH]; int gametype = m_Instream->ReadByte(); - strcopy(gamedir, m_Instream->ReadString()); - strcopy(m_HostName, m_Instream->ReadString()); - strcopy(levelname, m_Instream->ReadString()); + Q_strlcpy(gamedir, m_Instream->ReadString()); + Q_strlcpy(m_HostName, m_Instream->ReadString()); + Q_strlcpy(levelname, m_Instream->ReadString()); m_Instream->SkipString(); @@ -853,7 +853,7 @@ void Server::ParseMoveVars() movevars.skyvec_y = m_Instream->ReadFloat(); movevars.skyvec_z = m_Instream->ReadFloat(); - strcopy(movevars.skyName, m_Instream->ReadString()); + Q_strlcpy(movevars.skyName, m_Instream->ReadString()); m_World->SetMoveVars(&movevars); } @@ -1096,7 +1096,7 @@ void Server::ParseResourceList() resource.type = (resourcetype_t)m_Instream->ReadBits(4); - strcopy(resource.szFileName, m_Instream->ReadBitString()); + Q_strlcpy(resource.szFileName, m_Instream->ReadBitString()); resource.nIndex = m_Instream->ReadBits(12); resource.nDownloadSize = m_Instream->ReadBits(24); @@ -1348,7 +1348,7 @@ void Server::ParseSignonNum() SendStringCommand(COM_VarArgs("VModEnable %d", m_IsVoiceBlocking ? 0 : 1)); char string[128]; - strcopy(string, "vban"); + Q_strlcpy(string, "vban"); for (int i = 0; i < MAX_CLIENTS; i++) { strcat(string, " 0"); @@ -1373,7 +1373,7 @@ void Server::ParseCustomization() resource_t *resource = (resource_t *)Mem_ZeroMalloc(sizeof(resource_t)); resource->type = (resourcetype_t)m_Instream->ReadByte(); - strcopy(resource->szFileName, m_Instream->ReadString()); + Q_strlcpy(resource->szFileName, m_Instream->ReadString()); resource->nIndex = m_Instream->ReadShort(); resource->nDownloadSize = m_Instream->ReadLong(); @@ -1477,7 +1477,7 @@ bool Server::ParseUserMessage(int cmd) SendStringCommand(cmdString); char string[128]; - strcopy(string, "vban"); + Q_strlcpy(string, "vban"); for (int i = 0; i < MAX_CLIENTS; i++) { strcat(string, " 0"); @@ -1869,11 +1869,11 @@ void Server::ParseInfo(BitBuffer *stream, bool detailed) { serverinfo_t si; - strcopy(si.address, m_ServerChannel.GetTargetAddress()->ToBaseString()); - strcopy(si.name, stream->ReadString()); - strcopy(si.map, stream->ReadString()); - strcopy(si.gamedir, stream->ReadString()); - strcopy(si.description, stream->ReadString()); + Q_strlcpy(si.address, m_ServerChannel.GetTargetAddress()->ToBaseString()); + Q_strlcpy(si.name, stream->ReadString()); + Q_strlcpy(si.map, stream->ReadString()); + Q_strlcpy(si.gamedir, stream->ReadString()); + Q_strlcpy(si.description, stream->ReadString()); si.activePlayers = stream->ReadByte(); si.maxPlayers = stream->ReadByte(); @@ -1888,9 +1888,9 @@ void Server::ParseInfo(BitBuffer *stream, bool detailed) if (si.mod) { - strcopy(si.url_info, stream->ReadString()); - strcopy(si.url_dl, stream->ReadString()); - strcopy(si.hlversion, stream->ReadString()); + Q_strlcpy(si.url_info, stream->ReadString()); + Q_strlcpy(si.url_dl, stream->ReadString()); + Q_strlcpy(si.hlversion, stream->ReadString()); si.ver = stream->ReadLong(); si.size = stream->ReadLong(); @@ -2211,7 +2211,7 @@ void Server::ParseResourceLocation() { char *url = m_Instream->ReadString(); if (url) { - strcopy(g_DownloadURL, url); + Q_strlcpy(g_DownloadURL, url); } } @@ -2313,7 +2313,7 @@ char *Server::GetCmdName(int cmd) void Server::SetName(char *newName) { - strcopy(m_Name, newName); + Q_strlcpy(m_Name, newName); } void Server::ProcessEntityUpdate() diff --git a/rehlds/HLTV/Core/src/World.cpp b/rehlds/HLTV/Core/src/World.cpp index 5dc353a..3cb4dbc 100644 --- a/rehlds/HLTV/Core/src/World.cpp +++ b/rehlds/HLTV/Core/src/World.cpp @@ -48,7 +48,7 @@ bool World::Init(IBaseSystem *system, int serial, char *name) m_ServerInfo.SetMaxSize(MAX_SERVERINFO_STRING); memset(m_HostName, 0, sizeof(m_HostName)); - strcopy(m_ServerName, "Unnamed HLTV"); + Q_strlcpy(m_ServerName, "Unnamed HLTV"); m_Frames.Init(); m_FramesByTime.Init(); @@ -179,7 +179,7 @@ bool World::AddUserMessage(int msgNumber, int size, char *name) umsg.iSize = -1; } - strcopy(umsg.szName, name); + Q_strlcpy(umsg.szName, name); bool bFound = false; for (UserMsg *pList = m_ClientUserMsgs; pList; pList = pList->next) @@ -223,9 +223,9 @@ void World::UpdatePlayer(int playerNum, int userId, char *infostring, char *hash m_System->DPrintf("Player update(%i:%s)\n", playerNum, player->name); infostr.RemovePrefixedKeys('_'); - strcopy(player->userinfo, infostr.GetString()); - strcopy(player->name, infostr.ValueForKey("name")); - strcopy(player->model, infostr.ValueForKey("model")); + Q_strlcpy(player->userinfo, infostr.GetString()); + Q_strlcpy(player->name, infostr.ValueForKey("name")); + Q_strlcpy(player->model, infostr.ValueForKey("model")); player->topcolor = atoi(infostr.ValueForKey("topcolor")); player->bottomcolor = atoi(infostr.ValueForKey("bottomcolor")); @@ -333,7 +333,7 @@ void World::SetHostName(char *name) return; } - strcopy(m_HostName, name); + Q_strlcpy(m_HostName, name); } void World::ClearLightStyles() @@ -353,7 +353,7 @@ void World::AddLightStyle(int index, char *style) m_System->Printf("WARNING! World::SetLightStyle: style too long (%i).\n", length); } - strcopy(m_Lightstyles[index], style); + Q_strlcpy(m_Lightstyles[index], style); } void World::NewGame(int newServerCount) @@ -1698,7 +1698,7 @@ void World::WriteNewData(BitBuffer *stream) void World::SetName(char *newName) { - strcopy(m_Name, newName); + Q_strlcpy(m_Name, newName); } float World::GetBufferedGameTime() @@ -1855,8 +1855,8 @@ void World::SetServerInfo(int protocol, CRC32_t nserverCRC, unsigned char *nclie m_PlayerNum = nplayernum; m_GameType = ngametype; - strcopy(m_GameDir, ngamedir); - strcopy(m_LevelName, nlevelname); + Q_strlcpy(m_GameDir, ngamedir); + Q_strlcpy(m_LevelName, nlevelname); _snprintf(m_ServerName, sizeof(m_ServerName), "%s:%i", nservername, m_PlayerNum); } @@ -1909,7 +1909,7 @@ void World::ParseDeltaDescription(BitBuffer *stream) } char szDesc[256]; - strcopy(szDesc, s); + Q_strlcpy(szDesc, s); m_System->DPrintf("Reading delta description for: %s.\n", s); delta_t **ppdelta = m_Delta.LookupRegistration(szDesc); @@ -1967,7 +1967,7 @@ bool World::GetPlayerInfoString(int playerNum, InfoString *infoString) void World::SetExtraInfo(char *nclientfallback, int nallowCheats) { - strcopy(m_ClientFallback, nclientfallback); + Q_strlcpy(m_ClientFallback, nclientfallback); m_AllowCheats = nallowCheats ? true : false; } @@ -2253,14 +2253,14 @@ void World::RearrangeFrame(frame_t *frame, int seqNrOffset, float timeOffset) void World::UpdateServerInfo() { - strcopy(m_DetailedServerInfo.address, ""); - strcopy(m_DetailedServerInfo.name, GetHostName()); + Q_strlcpy(m_DetailedServerInfo.address, ""); + Q_strlcpy(m_DetailedServerInfo.name, GetHostName()); COM_FileBase(m_LevelName, m_DetailedServerInfo.map); m_DetailedServerInfo.map[sizeof(m_DetailedServerInfo.map) - 1] = '\0'; - strcopy(m_DetailedServerInfo.gamedir, m_GameDir); - strcopy(m_DetailedServerInfo.description, "HLTV"); + Q_strlcpy(m_DetailedServerInfo.gamedir, m_GameDir); + Q_strlcpy(m_DetailedServerInfo.description, "HLTV"); m_DetailedServerInfo.activePlayers = m_PlayerNum; m_DetailedServerInfo.maxPlayers = m_Maxclients; diff --git a/rehlds/HLTV/Core/src/precompiled.h b/rehlds/HLTV/Core/src/precompiled.h index b17cb08..c331350 100644 --- a/rehlds/HLTV/Core/src/precompiled.h +++ b/rehlds/HLTV/Core/src/precompiled.h @@ -1,9 +1,8 @@ #pragma once #include "basetypes.h" -#include "archtypes.h" -#include "mathlib.h" #include "FileSystem.h" +#include "strtools.h" #include "interface.h" #include "IBaseSystem.h" diff --git a/rehlds/HLTV/DemoPlayer/msvc/DemoPlayer.vcxproj b/rehlds/HLTV/DemoPlayer/msvc/DemoPlayer.vcxproj index 53446f3..022084d 100644 --- a/rehlds/HLTV/DemoPlayer/msvc/DemoPlayer.vcxproj +++ b/rehlds/HLTV/DemoPlayer/msvc/DemoPlayer.vcxproj @@ -5,6 +5,10 @@ Debug Win32 + + Release Swds + Win32 + Release Win32 @@ -18,10 +22,12 @@ true + true true true + true true @@ -33,6 +39,7 @@ Create Create + Create @@ -44,6 +51,7 @@ true + true true @@ -79,6 +87,15 @@ true MultiByte + + DynamicLibrary + false + v120_xp + v140_xp + v141_xp + true + MultiByte + @@ -90,6 +107,9 @@ + + + true @@ -97,6 +117,9 @@ false + + false + Use @@ -120,15 +143,9 @@ echo Empty Action - - Force build to run Pre-Build event - - - git.always.run - - - git.always.run + build.always.run + build.always.run @@ -160,15 +177,43 @@ echo Empty Action - - Force build to run Pre-Build event + build.always.run + build.always.run + + + + Level3 + Use + MaxSpeed + true + true + HOOK_HLTV;HLTV;WIN32;NDEBUG;_WINDOWS;_USRDLL;DEMOPLAYER_MODULE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitiHOOons) + precompiled.h + $(ProjectDir)\..\src;$(ProjectDir)\..\..\;$(ProjectDir)\..\..\..\;$(ProjectDir)\..\..\..\common;$(ProjectDir)\..\..\..\engine;$(ProjectDir)\..\..\..\public;$(ProjectDir)\..\..\..\public\rehlds;$(ProjectDir)\..\..\..\pm_shared;%(AdditionalIncludeDirectories) + MultiThreaded + true + + + Windows + true + true + true + psapi.lib;%(AdditionalDependencies) + false + + + IF EXIST "$(ProjectDir)PostBuild.bat" (CALL "$(ProjectDir)PostBuild.bat" "$(TargetDir)" "$(TargetName)" "$(TargetExt)" "$(ProjectDir)") + + + Automatic deployment script + - git.always.run - - - git.always.run + echo Empty Action + Force build to run Pre-Build event + build.always.run + build.always.run diff --git a/rehlds/HLTV/DemoPlayer/src/DemoPlayer.cpp b/rehlds/HLTV/DemoPlayer/src/DemoPlayer.cpp index 3d1e16c..b194e5e 100644 --- a/rehlds/HLTV/DemoPlayer/src/DemoPlayer.cpp +++ b/rehlds/HLTV/DemoPlayer/src/DemoPlayer.cpp @@ -752,7 +752,7 @@ void DemoPlayer::ReadNetchanState(int *incoming_sequence, int *incoming_acknowle void DemoPlayer::SetName(char *newName) { - strcopy(m_Name, newName); + Q_strlcpy(m_Name, newName); } void DemoPlayer::RunClocks() @@ -887,7 +887,7 @@ bool DemoPlayer::LoadGame(char *filename) return false; } - strcopy(m_DemoFileName, filename); + Q_strlcpy(m_DemoFileName, filename); m_World->SetBufferSize(-1); m_Outgoing_sequence = 0; diff --git a/rehlds/HLTV/DemoPlayer/src/precompiled.h b/rehlds/HLTV/DemoPlayer/src/precompiled.h index 7f1d66c..440fa0e 100644 --- a/rehlds/HLTV/DemoPlayer/src/precompiled.h +++ b/rehlds/HLTV/DemoPlayer/src/precompiled.h @@ -1,7 +1,7 @@ #pragma once -#include "archtypes.h" -#include "maintypes.h" +#include "basetypes.h" +#include "strtools.h" #include "TokenLine.h" #include "interface.h" diff --git a/rehlds/HLTV/Director/msvc/Director.vcxproj b/rehlds/HLTV/Director/msvc/Director.vcxproj index d8f1620..efb8178 100644 --- a/rehlds/HLTV/Director/msvc/Director.vcxproj +++ b/rehlds/HLTV/Director/msvc/Director.vcxproj @@ -5,6 +5,10 @@ Debug Win32 + + Release Swds + Win32 + Release Win32 @@ -34,6 +38,15 @@ true MultiByte + + DynamicLibrary + false + v120_xp + v140_xp + v141_xp + true + MultiByte + @@ -45,6 +58,9 @@ + + + true @@ -52,6 +68,9 @@ false + + false + Use @@ -76,11 +95,9 @@ echo Empty Action - - Force build to run Pre-Build event - git.always.run - git.always.run + build.always.run + build.always.run @@ -105,11 +122,42 @@ echo Empty Action - - Force build to run Pre-Build event - git.always.run - git.always.run + build.always.run + build.always.run + + + IF EXIST "$(ProjectDir)PostBuild.bat" (CALL "$(ProjectDir)PostBuild.bat" "$(TargetDir)" "$(TargetName)" "$(TargetExt)" "$(ProjectDir)") + + + Automatic deployment script + + + + + Level3 + Use + MaxSpeed + true + true + HLTV;WIN32;NDEBUG;_WINDOWS;_USRDLL;DIRECTOR_MODULE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + $(ProjectDir)\..\..\;$(ProjectDir)\..\src;$(ProjectDir)\..\..\..\common;$(ProjectDir)\..\..\..\engine;$(ProjectDir)\..\..\..\public;$(ProjectDir)\..\..\..\public\rehlds;$(ProjectDir)\..\..\..\pm_shared;%(AdditionalIncludeDirectories) + precompiled.h + MultiThreaded + true + + + Windows + true + true + true + %(AdditionalDependencies) + + + echo Empty Action + Force build to run Pre-Build event + build.always.run + build.always.run IF EXIST "$(ProjectDir)PostBuild.bat" (CALL "$(ProjectDir)PostBuild.bat" "$(TargetDir)" "$(TargetName)" "$(TargetExt)" "$(ProjectDir)") @@ -134,6 +182,7 @@ Create Create + Create diff --git a/rehlds/HLTV/Director/src/precompiled.h b/rehlds/HLTV/Director/src/precompiled.h index d191f95..16b9049 100644 --- a/rehlds/HLTV/Director/src/precompiled.h +++ b/rehlds/HLTV/Director/src/precompiled.h @@ -1,9 +1,8 @@ #pragma once -#include "osconfig.h" -#include "archtypes.h" -#include "mathlib.h" +#include "basetypes.h" #include "FileSystem.h" +#include "strtools.h" #include "TokenLine.h" #include "interface.h" diff --git a/rehlds/HLTV/Proxy/msvc/Proxy.vcxproj b/rehlds/HLTV/Proxy/msvc/Proxy.vcxproj index d0bb6ea..822b067 100644 --- a/rehlds/HLTV/Proxy/msvc/Proxy.vcxproj +++ b/rehlds/HLTV/Proxy/msvc/Proxy.vcxproj @@ -5,6 +5,10 @@ Debug Win32 + + Release Swds + Win32 + Release Win32 @@ -16,195 +20,264 @@ + + + + + + + + true true + true true true + true Use + Use Use + + Use + Use Use + + + + + + Use + Use Use + + Use + Use Use + + Use + Use Use + + Use + Use Use + + Use + Use Use + + Use + Use Use + + Use + Use Use + + Use + Use Use + + + + + + Use + Use Use + + Use + Use Use + + + + Create Create + Create Use + Use Use + + Use + Use Use + + Use + Use Use + + Use + Use Use + + @@ -216,6 +289,7 @@ true true + true @@ -269,6 +343,15 @@ true MultiByte + + DynamicLibrary + false + v120_xp + v140_xp + v141_xp + true + MultiByte + @@ -280,6 +363,9 @@ + + + true @@ -289,6 +375,10 @@ false proxy + + false + proxy + Use @@ -309,14 +399,10 @@ $(ProjectDir)../../../lib - Force build to run Pre-Build event - - - git.always.run - - - git.always.run echo Empty Action + Force build to run Pre-Build event + build.always.run + build.always.run IF EXIST "$(ProjectDir)PostBuild.bat" (CALL "$(ProjectDir)PostBuild.bat" "$(TargetDir)" "$(TargetName)" "$(TargetExt)" "$(ProjectDir)") @@ -357,15 +443,52 @@ echo Empty Action - - Force build to run Pre-Build event + build.always.run + build.always.run + + IF EXIST "$(ProjectDir)PostBuild.bat" (CALL "$(ProjectDir)PostBuild.bat" "$(TargetDir)" "$(TargetName)" "$(TargetExt)" "$(ProjectDir)") + + + Automatic deployment script + + + + + Level3 + Use + MaxSpeed + true + true + HLTV;WIN32;NDEBUG;_WINDOWS;_USRDLL;PROXY_MODULE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + $(ProjectDir)\..\src;$(ProjectDir)\..\..\;$(ProjectDir)\..\..\..\;$(ProjectDir)\..\..\Director\src;$(ProjectDir)\..\..\..\common;$(ProjectDir)\..\..\..\engine;$(ProjectDir)\..\..\..\public;$(ProjectDir)\..\..\..\public\rehlds;$(ProjectDir)\..\..\..\pm_shared;$(ProjectDir)\..\..\..\..\dep\bzip2\include;%(AdditionalIncludeDirectories) + precompiled.h + MultiThreaded + true + false + + + Windows + true + true + true + psapi.lib;ws2_32.lib;steam_api.lib;%(AdditionalDependencies) + $(ProjectDir)../../../lib + + + + + + + + + - git.always.run - - - git.always.run + echo Empty Action + Force build to run Pre-Build event + build.always.run + build.always.run IF EXIST "$(ProjectDir)PostBuild.bat" (CALL "$(ProjectDir)PostBuild.bat" "$(TargetDir)" "$(TargetName)" "$(TargetExt)" "$(ProjectDir)") diff --git a/rehlds/HLTV/Proxy/src/DemoClient.cpp b/rehlds/HLTV/Proxy/src/DemoClient.cpp index 210bb20..8ebc1fa 100644 --- a/rehlds/HLTV/Proxy/src/DemoClient.cpp +++ b/rehlds/HLTV/Proxy/src/DemoClient.cpp @@ -297,7 +297,7 @@ void DemoClient::SetWorld(IWorld *world) void DemoClient::SetFileName(char *fileName) { - strcopy(m_BaseFileName, fileName); + Q_strlcpy(m_BaseFileName, fileName); } DemoFile *DemoClient::GetDemoFile() diff --git a/rehlds/HLTV/Proxy/src/Master.cpp b/rehlds/HLTV/Proxy/src/Master.cpp index 7e01221..a51496e 100644 --- a/rehlds/HLTV/Proxy/src/Master.cpp +++ b/rehlds/HLTV/Proxy/src/Master.cpp @@ -163,7 +163,7 @@ void Master::RunFrame(double time) COM_FileBase(world->GetLevelName(), mapName); char szHostName[MAX_PATH]; - strcopy(szHostName, world->GetHostName()); + Q_strlcpy(szHostName, world->GetHostName()); int slots, proxies, spectators; m_Proxy->GetStatistics(proxies, slots, spectators); diff --git a/rehlds/HLTV/Proxy/src/Proxy.cpp b/rehlds/HLTV/Proxy/src/Proxy.cpp index eb5cfe9..fd8b3f9 100644 --- a/rehlds/HLTV/Proxy/src/Proxy.cpp +++ b/rehlds/HLTV/Proxy/src/Proxy.cpp @@ -236,7 +236,7 @@ bool Proxy::Init(IBaseSystem *system, int serial, char *name) "" // text }; - strcopy(m_OffLineText, "Game is delayed. Please try again later."); + Q_strlcpy(m_OffLineText, "Game is delayed. Please try again later."); m_System->SetTitle("HLTV - offline"); m_System->ExecuteFile("hltv.cfg"); @@ -624,7 +624,7 @@ void Proxy::UpdateStatusLine() char text[128]; char activeTime[32]; - strcopy(activeTime, COM_FormatTime((float)m_World->GetTime())); + Q_strlcpy(activeTime, COM_FormatTime((float)m_World->GetTime())); m_Network->GetFlowStats(&in, &out); m_CurrentLoss = m_Server->GetPacketLoss(); @@ -684,7 +684,7 @@ void Proxy::CMD_Status(char *cmdLine) if (m_World->IsActive()) { char activeTime[32]; - strcopy(activeTime, COM_FormatTime((float)m_World->GetTime())); + Q_strlcpy(activeTime, COM_FormatTime((float)m_World->GetTime())); const char *mapname = m_World->GetLevelName() + sizeof("maps/") - 1; // skip 'maps/' m_System->Printf("Game Time %s, Mod \"%s\", Map \"%s\", Players %i\n", activeTime, m_World->GetGameDir(), mapname, m_World->GetNumPlayers()); @@ -970,7 +970,7 @@ void Proxy::CMD_Name(char *cmdLine) return; } - strcopy(name, params.GetToken(1)); + Q_strlcpy(name, params.GetToken(1)); m_Server->SetPlayerName(name); } @@ -983,7 +983,7 @@ void Proxy::CMD_Msg(char *cmdLine) return; } - strcopy(m_LocalMessage.text, params.GetToken(1)); + Q_strlcpy(m_LocalMessage.text, params.GetToken(1)); if (params.CountToken() == 6) { @@ -1223,7 +1223,7 @@ void Proxy::CMD_LoopCmd(char *cmdLine) lcmd->interval = seconds; lcmd->lastTime = 0; - strcopy(lcmd->command, cmds); + Q_strlcpy(lcmd->command, cmds); } void Proxy::CMD_RconAddress(char *cmdLine) @@ -1251,7 +1251,7 @@ void Proxy::CMD_RconPassword(char *cmdLine) return; } - strcopy(m_RconPassword, params.GetToken(1)); + Q_strlcpy(m_RconPassword, params.GetToken(1)); } void Proxy::CMD_Rcon(char *cmdLine) @@ -1277,7 +1277,7 @@ void Proxy::CMD_Rcon(char *cmdLine) return; } - strcopy(m_LastRconCommand, params.GetRestOfLine(1)); + Q_strlcpy(m_LastRconCommand, params.GetRestOfLine(1)); m_Socket->OutOfBandPrintf(&m_RconAddress, "challenge rcon\n"); } @@ -1372,7 +1372,7 @@ void Proxy::CMD_ProxyPassword(char *cmdLine) return; } - strcopy(m_ProxyPassword, params.GetToken(1)); + Q_strlcpy(m_ProxyPassword, params.GetToken(1)); } void Proxy::NewServerConnection() @@ -1849,7 +1849,7 @@ void Proxy::CMD_OffLineText(char *cmdLine) return; } - strcopy(m_OffLineText, params.GetToken(1)); + Q_strlcpy(m_OffLineText, params.GetToken(1)); COM_RemoveEvilChars(m_OffLineText); } @@ -1931,7 +1931,7 @@ void Proxy::CMD_SpectatorPassword(char *cmdLine) return; } - strcopy(m_SpectatorPassword, params.GetToken(1)); + Q_strlcpy(m_SpectatorPassword, params.GetToken(1)); } void Proxy::CMD_DispatchMode(char *cmdLine) @@ -2017,7 +2017,7 @@ resource_t *Proxy::LoadResourceFromFile(char *fileName, resourcetype_t type) { resource_t *newresource = (resource_t *)Mem_ZeroMalloc(sizeof(resource_t)); - strcopy(newresource->szFileName, fileName); + Q_strlcpy(newresource->szFileName, fileName); newresource->type = type; newresource->data = m_System->LoadFile(newresource->szFileName, &newresource->nDownloadSize); @@ -2064,7 +2064,7 @@ resource_t *Proxy::AddResource(char *fileName, resourcetype_t type, char *asFile if (resource) { if (asFileName) { - strcopy(resource->szFileName, asFileName); + Q_strlcpy(resource->szFileName, asFileName); } m_Resources.Add(resource); @@ -2105,7 +2105,7 @@ void Proxy::CMD_SignOnCommands(char *cmdLine) return; } - strcopy(m_SignonCommands, params.GetToken(1)); + Q_strlcpy(m_SignonCommands, params.GetToken(1)); } void Proxy::CMD_AdminPassword(char *cmdLine) @@ -2122,7 +2122,7 @@ void Proxy::CMD_AdminPassword(char *cmdLine) return; } - strcopy(m_AdminPassword, params.GetToken(1)); + Q_strlcpy(m_AdminPassword, params.GetToken(1)); } void Proxy::CMD_LocalMsg(char *cmdLine) @@ -2134,7 +2134,7 @@ void Proxy::CMD_LocalMsg(char *cmdLine) return; } - strcopy(m_LocalMessage.text, params.GetToken(1)); + Q_strlcpy(m_LocalMessage.text, params.GetToken(1)); if (params.CountToken() == 6) { @@ -2155,7 +2155,7 @@ void Proxy::ChatCommentator(char *nick, char *text) { BitBuffer buffer(144); - strcopy(m_CommentatorMessage.text, text); + Q_strlcpy(m_CommentatorMessage.text, text); COM_RemoveEvilChars(m_CommentatorMessage.text); WriteHUDMsg(&m_CommentatorMessage, &buffer); @@ -2754,7 +2754,7 @@ void Proxy::UpdateInfoMessages() void Proxy::SetName(char *newName) { - strcopy(m_Name, newName); + Q_strlcpy(m_Name, newName); } const char *Proxy::GetDescription() diff --git a/rehlds/HLTV/Proxy/src/Status.cpp b/rehlds/HLTV/Proxy/src/Status.cpp index 4bf605a..c6e3537 100644 --- a/rehlds/HLTV/Proxy/src/Status.cpp +++ b/rehlds/HLTV/Proxy/src/Status.cpp @@ -137,7 +137,7 @@ void Status::SendStatusUpdate() void Status::SetName(char *newName) { - strcopy(m_Name, newName); + Q_strlcpy(m_Name, newName); } char *Status::GetType() diff --git a/rehlds/HLTV/Proxy/src/precompiled.h b/rehlds/HLTV/Proxy/src/precompiled.h index d722eb0..a3065cf 100644 --- a/rehlds/HLTV/Proxy/src/precompiled.h +++ b/rehlds/HLTV/Proxy/src/precompiled.h @@ -1,9 +1,8 @@ #pragma once #include "basetypes.h" -#include "archtypes.h" -#include "mathlib.h" #include "FileSystem.h" +#include "strtools.h" #include "interface.h" #include "IBaseSystem.h" diff --git a/rehlds/HLTV/common/BaseClient.cpp b/rehlds/HLTV/common/BaseClient.cpp index a1b9c1c..f0fcbc9 100644 --- a/rehlds/HLTV/common/BaseClient.cpp +++ b/rehlds/HLTV/common/BaseClient.cpp @@ -35,7 +35,7 @@ bool BaseClient::Init(IBaseSystem *system, int serial, char *name) } if (!name) { - strcopy(m_Name, CLIENT_INTERFACE_VERSION); + Q_strlcpy(m_Name, CLIENT_INTERFACE_VERSION); } SetState(CLIENT_INITIALIZING); @@ -386,7 +386,7 @@ void BaseClient::UpdateUserInfo(char *userinfostring) m_Userinfo.SetString(userinfostring); } - strcopy(buffer, m_Userinfo.ValueForKey("name")); + Q_strlcpy(buffer, m_Userinfo.ValueForKey("name")); SetName(buffer); m_ClientType = atoi(m_Userinfo.ValueForKey("*hltv")); @@ -648,7 +648,7 @@ void BaseClient::SetName(char *newName) strcpy(temp, "unnamed"); } - strcopy(m_ClientName, temp); + Q_strlcpy(m_ClientName, temp); m_Userinfo.SetValueForKey("name", m_ClientName); } diff --git a/rehlds/HLTV/common/DemoFile.cpp b/rehlds/HLTV/common/DemoFile.cpp index b7117e9..15d69c0 100644 --- a/rehlds/HLTV/common/DemoFile.cpp +++ b/rehlds/HLTV/common/DemoFile.cpp @@ -251,7 +251,7 @@ bool DemoFile::StartRecording(char *newName) CloseFile(); } - strcopy(m_FileName, newName); + Q_strlcpy(m_FileName, newName); m_FileHandle = m_FileSystem->Open(m_FileName, "wb"); if (!m_FileHandle) { @@ -332,8 +332,8 @@ bool DemoFile::LoadDemo(char *demoname) CloseFile(); - strcopy(m_FileName, demoname); - _strlwr(m_FileName); + Q_strlcpy(m_FileName, demoname); + Q_strlwr(m_FileName); if (!strstr(m_FileName, ".dem")) { strcat(m_FileName, ".dem"); @@ -384,11 +384,11 @@ bool DemoFile::LoadDemo(char *demoname) m_Continuous = true; memset(&m_ServerInfo, 0, sizeof(m_ServerInfo)); - strcopy(m_ServerInfo.address, m_DemoChannel->m_remote_address.ToBaseString()); - strcopy(m_ServerInfo.name, m_FileName); - strcopy(m_ServerInfo.map, m_demoHeader.szMapName); - strcopy(m_ServerInfo.gamedir, m_demoHeader.szDllDir); - strcopy(m_ServerInfo.description, "Demo Playback"); + Q_strlcpy(m_ServerInfo.address, m_DemoChannel->m_remote_address.ToBaseString()); + Q_strlcpy(m_ServerInfo.name, m_FileName); + Q_strlcpy(m_ServerInfo.map, m_demoHeader.szMapName); + Q_strlcpy(m_ServerInfo.gamedir, m_demoHeader.szDllDir); + Q_strlcpy(m_ServerInfo.description, "Demo Playback"); m_ServerInfo.activePlayers = 0; m_ServerInfo.maxPlayers = MAX_CLIENTS; diff --git a/rehlds/HLTV/common/NetChannel.cpp b/rehlds/HLTV/common/NetChannel.cpp index 820c45f..61c997f 100644 --- a/rehlds/HLTV/common/NetChannel.cpp +++ b/rehlds/HLTV/common/NetChannel.cpp @@ -1262,7 +1262,7 @@ bool NetChannel::CopyFileFragments() } filecontent.Reset(); - strcopy(filename, filecontent.ReadString()); + Q_strlcpy(filename, filecontent.ReadString()); if (!strlen(filename)) { m_System->Printf("File fragment received with no filename\n"); diff --git a/rehlds/build.gradle b/rehlds/build.gradle index 9761936..9cd8b09 100644 --- a/rehlds/build.gradle +++ b/rehlds/build.gradle @@ -153,14 +153,16 @@ void setupToolchain(NativeBinarySpec b) { pchSourceSet: 'rehlds_pch' ) } - cfg.compilerOptions.languageStandard = 'c++0x' + cfg.compilerOptions.languageStandard = 'c++11' cfg.defines([ '_stricmp': 'strcasecmp', '_strnicmp': 'strncasecmp', '_strdup': 'strdup', '_unlink': 'unlink', '_vsnprintf': 'vsnprintf', - ]) + '_vsnwprintf' : 'vswprintf', + ]); + if (useGcc) { // Produce code optimized for the most common IA32/AMD64/EM64T processors. // As new processors are deployed in the marketplace, the behavior of this option will change. @@ -183,7 +185,7 @@ void setupToolchain(NativeBinarySpec b) { } if (rehldsFixes) { - cfg.singleDefines 'REHLDS_FIXES', 'REHLDS_CHECKS' + cfg.singleDefines 'REHLDS_FIXES', 'REHLDS_CHECKS', 'HAVE_OPT_STRTOOLS' } ToolchainConfigUtils.apply(project, cfg, b) diff --git a/rehlds/common/BaseSystemModule.cpp b/rehlds/common/BaseSystemModule.cpp index c344d7c..7081b33 100644 --- a/rehlds/common/BaseSystemModule.cpp +++ b/rehlds/common/BaseSystemModule.cpp @@ -28,7 +28,6 @@ #include "precompiled.h" - BaseSystemModule::BaseSystemModule() { m_System = nullptr; @@ -87,7 +86,7 @@ bool BaseSystemModule::Init(IBaseSystem *system, int serial, char *name) m_SystemTime = 0; if (name) { - strcopy(m_Name, name); + Q_strlcpy(m_Name, name); } return true; diff --git a/rehlds/common/TokenLine.cpp b/rehlds/common/TokenLine.cpp index df8643a..f893b09 100644 --- a/rehlds/common/TokenLine.cpp +++ b/rehlds/common/TokenLine.cpp @@ -30,8 +30,8 @@ bool TokenLine::SetLine(const char *newLine) return false; } - strcopy(m_fullLine, newLine); - strcopy(m_tokenBuffer, newLine); + Q_strlcpy(m_fullLine, newLine); + Q_strlcpy(m_tokenBuffer, newLine); // parse tokens char *charPointer = m_tokenBuffer; diff --git a/rehlds/dedicated/msvc/dedicated.vcxproj b/rehlds/dedicated/msvc/dedicated.vcxproj index fa3d31b..5b57385 100644 --- a/rehlds/dedicated/msvc/dedicated.vcxproj +++ b/rehlds/dedicated/msvc/dedicated.vcxproj @@ -5,6 +5,10 @@ Debug Win32 + + Release Swds + Win32 + Release Win32 @@ -35,6 +39,15 @@ true MultiByte + + Application + false + v120_xp + v140_xp + v141_xp + true + MultiByte + @@ -44,6 +57,9 @@ + + + true @@ -53,6 +69,10 @@ false hlds + + false + hlds + Use @@ -83,15 +103,9 @@ echo Empty Action - - Force build to run Pre-Build event - - - git.always.run - - - git.always.run + build.always.run + build.always.run @@ -134,13 +148,54 @@ echo Empty Action - - - subversion.always.run - - - subversion.always.run Force build to run Pre-Build event + build.always.run + build.always.run + + + + + Level3 + Use + Full + true + true + WIN32;LAUNCHER_FIXES;NDEBUG;DEDICATED;_CRT_SECURE_NO_WARNINGS;USE_BREAKPAD_HANDLER;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + $(ProjectDir)..\src;$(ProjectDir)..\..\;$(ProjectDir)..\..\common;$(ProjectDir)..\..\engine;$(ProjectDir)..\..\public;$(ProjectDir)..\..\public\rehlds;%(AdditionalIncludeDirectories) + MultiThreaded + false + StreamingSIMDExtensions2 + + + AnySuitable + true + true + precompiled.h + + + Windows + true + true + true + ws2_32.lib;winmm.lib;%(AdditionalDependencies) + + + IF EXIST "$(ProjectDir)PreBuild.bat" (CALL "$(ProjectDir)PreBuild.bat" "$(ProjectDir)..\version\" "$(ProjectDir)..\") + + + Setup version from Git revision + + + IF EXIST "$(ProjectDir)PostBuild.bat" (CALL "$(ProjectDir)PostBuild.bat" "$(TargetDir)" "$(TargetName)" "$(TargetExt)" "$(ProjectDir)") + + + Automatic deployment script + + + echo Empty Action + Force build to run Pre-Build event + build.always.run + build.always.run @@ -150,6 +205,7 @@ true true + true @@ -170,6 +226,7 @@ true true + true @@ -178,12 +235,14 @@ Create Create + Create true true + true diff --git a/rehlds/dedicated/src/precompiled.h b/rehlds/dedicated/src/precompiled.h index bd9ecee..21128b8 100644 --- a/rehlds/dedicated/src/precompiled.h +++ b/rehlds/dedicated/src/precompiled.h @@ -1,9 +1,8 @@ #pragma once -#include "osconfig.h" -#include "archtypes.h" -#include "mathlib.h" +#include "basetypes.h" #include "FileSystem.h" +#include "strtools.h" #include "common.h" #include "mem.h" diff --git a/rehlds/engine/SystemWrapper.cpp b/rehlds/engine/SystemWrapper.cpp index c39e9c0..83aa088 100644 --- a/rehlds/engine/SystemWrapper.cpp +++ b/rehlds/engine/SystemWrapper.cpp @@ -235,7 +235,7 @@ void SystemWrapper::CMD_UnloadModule(char *cmdLine) SystemWrapper::library_t *SystemWrapper::GetLibrary(char *name) { char fixedname[MAX_PATH]; - strcopy(fixedname, name); + Q_strlcpy(fixedname, name); COM_FixSlashes(fixedname); library_t *lib = (library_t *)m_Libraries.GetFirst(); @@ -364,7 +364,7 @@ bool SystemWrapper::RegisterCommand(char *name, ISystemModule *module, int comma cmd = (command_t *)Mem_ZeroMalloc(sizeof(command_t)); - strcopy(cmd->name, name); + Q_strlcpy(cmd->name, name); cmd->module = module; cmd->commandID = commandID; diff --git a/rehlds/engine/common.cpp b/rehlds/engine/common.cpp index b5c852a..62946da 100644 --- a/rehlds/engine/common.cpp +++ b/rehlds/engine/common.cpp @@ -38,61 +38,6 @@ char *Info_Serverinfo(void) return serverinfo; } -#ifdef Q_functions - -NOBODY void Q_memset(void *dest, int fill, int count); -NOBODY void Q_memcpy(void *dest, const void *src, int count); -NOBODY int Q_memcmp(void *m1, void *m2, int count); - -void Q_strcpy(char *dest, const char *src) -{ - char *c; - const char *s; - - s = src; - for (c = dest; s; *c++ = *s++) - { - if (!c) - break; - if (!*s) - break; - } - *c = 0; -} - -NOBODY void Q_strncpy(char *dest, const char *src, int count); - -int Q_strlen(const char *str) -{ - int result = 0; - if (str) - { - if (*str) - { - while (str[result++ + 1]); - } - } - return result; -} - - -NOBODY char *Q_strrchr(char *s, char c); -NOBODY void Q_strcat(char *dest, char *src); -NOBODY int Q_strcmp(const char *s1, const char *s2); -NOBODY int Q_strncmp(const char *s1, const char *s2, int count); -NOBODY int Q_strncasecmp(const char *s1, const char *s2, int n); -NOBODY int Q_strcasecmp(const char *s1, const char *s2); -NOBODY int Q_stricmp(const char *s1, const char *s2); -NOBODY int Q_strnicmp(const char *s1, const char *s2, int n); -NOBODY int Q_atoi(const char *str); -NOBODY float Q_atof(const char *str); -NOBODY char *Q_strlwr(char *src); -NOBODY int Q_FileNameCmp(char *file1, char *file2); -NOBODY char *Q_strstr(const char *s1, const char *search); -NOBODY uint64 Q_strtoull(char *str); - -#endif // Q_functions - #ifndef COM_Functions_region unsigned char COM_Nibble(char c) diff --git a/rehlds/engine/common.h b/rehlds/engine/common.h index 1df658b..0e453a9 100644 --- a/rehlds/engine/common.h +++ b/rehlds/engine/common.h @@ -123,123 +123,6 @@ extern cache_user_t *loadcache; extern unsigned char *loadbuf; extern int loadsize; - -//#define Q_functions -#ifndef Q_functions - -#ifndef _WIN32 -#define _strlwr(p) for (int i = 0; p[i] != 0; i++) p[i] = tolower(p[i]); -#endif - -#if defined(REHLDS_OPT_PEDANTIC) || defined(REHLDS_FIXES) -#define Q_memset A_memset -#define Q_memcpy A_memcpy -#define Q_memmove A_memmove -#define Q_strlen A_strlen -#define Q_memcmp A_memcmp -#define Q_strcpy A_strcpy -#define Q_strncpy strncpy -#define Q_strrchr strrchr -#define Q_strcat A_strcat -#define Q_strncat strncat -#define Q_strcmp A_strcmp -#define Q_strncmp strncmp -//#define Q_strcasecmp _stricmp // Use Q_stricmp -//#define Q_strncasecmp _strnicmp // Use Q_strnicmp -#define Q_stricmp A_stricmp -#define Q_strnicmp _strnicmp -#define Q_strstr A_strstr -#define Q_strchr strchr -#define Q_strlwr A_strtolower -#define Q_sprintf sprintf -#define Q_snprintf _snprintf -#define Q_atoi atoi -#define Q_atof atof -#define Q_sqrt M_sqrt -#define Q_min M_min -#define Q_max M_max -#define Q_clamp M_clamp -//#define Q_strtoull strtoull -//#define Q_FileNameCmp FileNameCmp -#define Q_vsnprintf _vsnprintf -#else -#define Q_memset memset -#define Q_memcpy memcpy -#define Q_memmove memmove -#define Q_strlen strlen -#define Q_memcmp memcmp -#define Q_strcpy strcpy -#define Q_strncpy strncpy -#define Q_strrchr strrchr -#define Q_strcat strcat -#define Q_strncat strncat -#define Q_strcmp strcmp -#define Q_strncmp strncmp -//#define Q_strcasecmp _stricmp // Use Q_stricmp -//#define Q_strncasecmp _strnicmp // Use Q_strnicmp -#define Q_stricmp _stricmp -#define Q_strnicmp _strnicmp -#define Q_strstr strstr -#define Q_strchr strchr -#define Q_strlwr _strlwr -#define Q_sprintf sprintf -#define Q_snprintf _snprintf -#define Q_atoi atoi -#define Q_atof atof -#define Q_sqrt sqrt -#define Q_min min -#define Q_max max -#define Q_clamp clamp -//#define Q_strtoull strtoull -//#define Q_FileNameCmp FileNameCmp -#define Q_vsnprintf _vsnprintf -#endif // defined(REHLDS_OPT_PEDANTIC) || defined(REHLDS_FIXES) - -#else // Q_functions - -void Q_strcpy(char *dest, const char *src); -int Q_strlen(const char *str); -NOBODY void Q_memset(void *dest, int fill, int count); -NOBODY void Q_memcpy(void *dest, const void *src, int count); -NOBODY int Q_memcmp(void *m1, void *m2, int count); -NOBODY void Q_strncpy(char *dest, const char *src, int count); -NOBODY char *Q_strrchr(char *s, char c); -NOBODY void Q_strcat(char *dest, char *src); -NOBODY int Q_strcmp(const char *s1, const char *s2); -NOBODY int Q_strncmp(const char *s1, const char *s2, int count); -NOBODY int Q_strncasecmp(const char *s1, const char *s2, int n); -NOBODY int Q_strcasecmp(const char *s1, const char *s2); -NOBODY int Q_stricmp(const char *s1, const char *s2); -NOBODY int Q_strnicmp(const char *s1, const char *s2, int n); -NOBODY int Q_atoi(const char *str); -NOBODY float Q_atof(const char *str); -NOBODY char *Q_strlwr(char *src); -NOBODY int Q_FileNameCmp(char *file1, char *file2); -NOBODY char *Q_strstr(const char *s1, const char *search); -NOBODY uint64 Q_strtoull(char *str); - -#endif // Q_functions - -template -char *strcopy(char (&dest)[N], const char *src) { - Q_strncpy(dest, src, N - 1); - dest[N - 1] = '\0'; - return dest; -} - -inline char *strncopy(char *dest, const char *src, size_t n) { - Q_strncpy(dest, src, n - 1); - dest[n - 1] = '\0'; - return dest; -} - -// strcpy that works correctly with overlapping src and dst buffers -inline char *strcpy_safe(char *dst, char *src) { - int len = Q_strlen(src); - Q_memmove(dst, src, len + 1); - return dst; -} - int build_number(void); char *Info_Serverinfo(void); diff --git a/rehlds/engine/net.h b/rehlds/engine/net.h index b340a5a..c21e305 100644 --- a/rehlds/engine/net.h +++ b/rehlds/engine/net.h @@ -125,11 +125,6 @@ const int NET_MAX_PAYLOAD = 65536; // } #define HEADER_BYTES (8 + MAX_STREAMS * 9) -// Pad a number so it lies on an N byte boundary. -// So PAD_NUMBER(0,4) is 0 and PAD_NUMBER(1,4) is 4 -#define PAD_NUMBER(number, boundary) \ - (((number) + ((boundary) - 1)) / (boundary)) * (boundary) - // Pad this to next higher 16 byte boundary // This is the largest packet that can come in/out over the wire, before processing the header // bytes will be stripped by the networking channel layer diff --git a/rehlds/hookers/engine/hooklist.cpp b/rehlds/hookers/engine/hooklist.cpp index 718d33c..7ff8e8e 100644 --- a/rehlds/hookers/engine/hooklist.cpp +++ b/rehlds/hookers/engine/hooklist.cpp @@ -130,14 +130,12 @@ FunctionHook g_FunctionHooks[] = #ifndef Common_MSG_region -#ifdef Q_functions - //HOOK_DEF(0x, Q_memset), //HOOK_DEF(0x, Q_memcpy), //HOOK_DEF(0x, Q_memcmp), - HOOK_DEF(0x01D28AF0, Q_strcpy), + //HOOK_DEF(0x01D28AF0, Q_strcpy), //HOOK_DEF(0x, Q_strncpy), - HOOK_DEF(0x01D28B50, Q_strlen), + //HOOK_DEF(0x01D28B50, Q_strlen), //HOOK_DEF(0x, Q_strrchr), //HOOK_DEF(0x, Q_strcat), //HOOK_DEF(0x, Q_strcmp), @@ -153,8 +151,6 @@ FunctionHook g_FunctionHooks[] = //HOOK_DEF(0x, Q_strstr), //HOOK_DEF(0x, Q_strtoull), -#endif // Q_functions - HOOK_DEF(0x01D29290, MSG_WriteChar), HOOK_DEF(0x01D292B0, MSG_WriteByte), HOOK_DEF(0x01D292D0, MSG_WriteShort), diff --git a/rehlds/public/iosutil.h b/rehlds/hookers/iosutil.h similarity index 94% rename from rehlds/public/iosutil.h rename to rehlds/hookers/iosutil.h index 36c7de7..34e56d8 100644 --- a/rehlds/public/iosutil.h +++ b/rehlds/hookers/iosutil.h @@ -1,21 +1,21 @@ -#pragma once - -#include - -class IosFlagSaver { -public: - explicit IosFlagSaver(std::ostream& _ios) : - ios(_ios), - f(_ios.flags()) { - } - ~IosFlagSaver() { - ios.flags(f); - } - - IosFlagSaver(const IosFlagSaver &rhs) = delete; - IosFlagSaver& operator= (const IosFlagSaver& rhs) = delete; - -private: - std::ostream& ios; - std::ios::fmtflags f; -}; +#pragma once + +#include + +class IosFlagSaver { +public: + explicit IosFlagSaver(std::ostream& _ios) : + ios(_ios), + f(_ios.flags()) { + } + ~IosFlagSaver() { + ios.flags(f); + } + + IosFlagSaver(const IosFlagSaver &rhs) = delete; + IosFlagSaver& operator= (const IosFlagSaver& rhs) = delete; + +private: + std::ostream& ios; + std::ios::fmtflags f; +}; diff --git a/rehlds/hookers/rehlds_debug.h b/rehlds/hookers/rehlds_debug.h index 7680dca..9964d3b 100644 --- a/rehlds/hookers/rehlds_debug.h +++ b/rehlds/hookers/rehlds_debug.h @@ -4,7 +4,7 @@ #include "maintypes.h" #include "memory.h" #include "model.h" - +#include "iosutil.h" #ifdef _WIN32 diff --git a/rehlds/msvc/ReHLDS.vcxproj b/rehlds/msvc/ReHLDS.vcxproj index 3f06db7..d0d7359 100644 --- a/rehlds/msvc/ReHLDS.vcxproj +++ b/rehlds/msvc/ReHLDS.vcxproj @@ -29,6 +29,10 @@ Release Swds Play Win32 + + Release Swds + Win32 + Release Win32 @@ -110,11 +114,13 @@ true true true + true true true true + true true @@ -136,6 +142,7 @@ true true true + true true true @@ -147,6 +154,7 @@ true true true + true true true true @@ -161,24 +169,12 @@ true true true + true true true - - true - true - true - true - true - true - true - true - true - true - - @@ -200,9 +196,11 @@ Create Create Create + Create precompiled.h precompiled.h precompiled.h + precompiled.h Create Create precompiled.h @@ -225,6 +223,7 @@ true true true + true true @@ -235,6 +234,7 @@ true true true + true true @@ -245,6 +245,7 @@ true true true + true true @@ -255,6 +256,7 @@ true true true + true true @@ -265,6 +267,7 @@ true true true + true @@ -279,6 +282,7 @@ true true true + true true @@ -289,6 +293,7 @@ true true true + true true @@ -299,6 +304,7 @@ true true true + true true @@ -309,6 +315,7 @@ true true true + true @@ -477,7 +484,6 @@ - @@ -530,11 +536,8 @@ + - - - - @@ -675,6 +678,15 @@ true MultiByte + + DynamicLibrary + false + v120_xp + v140_xp + v141_xp + true + MultiByte + @@ -708,6 +720,9 @@ + + + filesystem_stdio @@ -739,6 +754,9 @@ swds + + swds + IF EXIST "$(ProjectDir)PreBuild.bat" (CALL "$(ProjectDir)PreBuild.bat" "$(ProjectDir)..\version\" "$(ProjectDir)..\") @@ -749,7 +767,7 @@ Level3 Disabled true - REHLDS_OPT_PEDANTIC;REHLDS_SELF;HOOK_ENGINE;REHLDS_FIXES;REHLDS_CHECKS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions) + REHLDS_OPT_PEDANTIC;REHLDS_SELF;HOOK_ENGINE;REHLDS_FIXES;REHLDS_CHECKS;HAVE_OPT_STRTOOLS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions) Precise /arch:IA32 %(AdditionalOptions) MultiThreadedDebug @@ -773,8 +791,8 @@ echo Empty Action Force build to run Pre-Build event - subversion.always.run - subversion.always.run + build.always.run + build.always.run @@ -787,7 +805,7 @@ Level3 Disabled true - REHLDS_FLIGHT_REC;REHLDS_OPT_PEDANTIC;REHLDS_FIXES;REHLDS_SELF;REHLDS_CHECKS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions) + REHLDS_FLIGHT_REC;REHLDS_OPT_PEDANTIC;REHLDS_FIXES;REHLDS_SELF;REHLDS_CHECKS;HAVE_OPT_STRTOOLS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions) Precise /arch:IA32 %(AdditionalOptions) MultiThreadedDebug @@ -810,8 +828,8 @@ echo Empty Action Force build to run Pre-Build event - subversion.always.run - subversion.always.run + build.always.run + build.always.run @@ -846,8 +864,8 @@ echo Empty Action Force build to run Pre-Build event - subversion.always.run - subversion.always.run + build.always.run + build.always.run @@ -860,7 +878,7 @@ Level3 Disabled true - REHLDS_FLIGHT_REC;REHLDS_OPT_PEDANTIC;REHLDS_SELF;REHLDS_CHECKS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions) + REHLDS_FLIGHT_REC;REHLDS_OPT_PEDANTIC;REHLDS_SELF;REHLDS_CHECKS;HAVE_OPT_STRTOOLS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions) Precise /arch:IA32 %(AdditionalOptions) MultiThreadedDebug @@ -885,8 +903,8 @@ echo Empty Action Force build to run Pre-Build event - subversion.always.run - subversion.always.run + build.always.run + build.always.run @@ -921,8 +939,8 @@ echo Empty Action Force build to run Pre-Build event - subversion.always.run - subversion.always.run + build.always.run + build.always.run @@ -935,7 +953,7 @@ Level3 Disabled true - REHLDS_FLIGHT_REC;REHLDS_OPT_PEDANTIC;REHLDS_SELF;REHLDS_UNIT_TESTS;_BUILD_FROM_IDE;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions) + REHLDS_FLIGHT_REC;REHLDS_OPT_PEDANTIC;HAVE_OPT_STRTOOLS;REHLDS_SELF;REHLDS_UNIT_TESTS;_BUILD_FROM_IDE;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions) MultiThreadedDebug Use precompiled.h @@ -957,8 +975,8 @@ echo Empty Action Force build to run Pre-Build event - subversion.always.run - subversion.always.run + build.always.run + build.always.run @@ -971,7 +989,7 @@ Level3 Disabled true - REHLDS_FLIGHT_REC;REHLDS_OPT_PEDANTIC;REHLDS_FIXES;REHLDS_SELF;REHLDS_UNIT_TESTS;_BUILD_FROM_IDE;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions) + REHLDS_FLIGHT_REC;REHLDS_OPT_PEDANTIC;REHLDS_FIXES;HAVE_OPT_STRTOOLS;REHLDS_SELF;REHLDS_UNIT_TESTS;_BUILD_FROM_IDE;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions) MultiThreadedDebug Use precompiled.h @@ -992,8 +1010,8 @@ echo Empty Action Force build to run Pre-Build event - subversion.always.run - subversion.always.run + build.always.run + build.always.run @@ -1008,7 +1026,7 @@ true true true - REHLDS_OPT_PEDANTIC;REHLDS_SELF;HOOK_ENGINE;REHLDS_CHECKS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + REHLDS_OPT_PEDANTIC;REHLDS_SELF;HOOK_ENGINE;REHLDS_CHECKS;HAVE_OPT_STRTOOLS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreaded /arch:IA32 %(AdditionalOptions) Use @@ -1031,8 +1049,8 @@ echo Empty Action Force build to run Pre-Build event - subversion.always.run - subversion.always.run + build.always.run + build.always.run @@ -1071,8 +1089,8 @@ echo Empty Action Force build to run Pre-Build event - subversion.always.run - subversion.always.run + build.always.run + build.always.run @@ -1087,7 +1105,7 @@ true true true - REHLDS_FLIGHT_REC;REHLDS_OPT_PEDANTIC;REHLDS_SELF;REHLDS_CHECKS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + REHLDS_FLIGHT_REC;REHLDS_OPT_PEDANTIC;REHLDS_SELF;REHLDS_CHECKS;HAVE_OPT_STRTOOLS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreaded /arch:IA32 %(AdditionalOptions) Use @@ -1115,8 +1133,52 @@ echo Empty Action Force build to run Pre-Build event - subversion.always.run - subversion.always.run + build.always.run + build.always.run + + + + + IF EXIST "$(ProjectDir)PreBuild.bat" (CALL "$(ProjectDir)PreBuild.bat" "$(ProjectDir)..\version\" "$(ProjectDir)..\") + Setup version from Git revision + + + $(ProjectDir)\..\;$(ProjectDir)\..\hookers\;$(ProjectDir)\..\metamod\include\;$(ProjectDir)\..\public\rehlds\;$(ProjectDir)\..\common;$(ProjectDir)\..\engine;$(ProjectDir)\..\public;$(ProjectDir)\..\pm_shared;$(ProjectDir)\..\rehlds\;$(ProjectDir)\..\testsuite\;$(VCInstallDir)UnitTest\include;$(SolutionDir)..\dep\bzip2\include\;$(SolutionDir)..\dep\cppunitlite\include\;%(AdditionalIncludeDirectories) + Level3 + MaxSpeed + true + true + true + REHLDS_FLIGHT_REC;REHLDS_FIXES;REHLDS_OPT_PEDANTIC;REHLDS_SELF;REHLDS_CHECKS;HAVE_OPT_STRTOOLS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + MultiThreaded + /arch:IA32 %(AdditionalOptions) + Use + precompiled.h + + + true + true + true + psapi.lib;ws2_32.lib;$(ProjectDir)../lib/steam_api.lib;$(ProjectDir)../lib/libacof32.lib;%(AdditionalDependencies) + + + + + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + false + + + 0x4970000 + + + IF EXIST "$(ProjectDir)PostBuild_swds.bat" (CALL "$(ProjectDir)PostBuild_swds.bat" "$(TargetDir)" "$(TargetName)" "$(TargetExt)" "$(ProjectDir)") + Automatic deployment script + + + echo Empty Action + Force build to run Pre-Build event + build.always.run + build.always.run diff --git a/rehlds/msvc/ReHLDS.vcxproj.filters b/rehlds/msvc/ReHLDS.vcxproj.filters index 606ce65..1f6d429 100644 --- a/rehlds/msvc/ReHLDS.vcxproj.filters +++ b/rehlds/msvc/ReHLDS.vcxproj.filters @@ -215,12 +215,6 @@ public - - public\tier0 - - - public\tier0 - engine @@ -772,9 +766,6 @@ public - - public - public @@ -784,18 +775,6 @@ public - - public\tier0 - - - public\tier0 - - - public\tier0 - - - public\tier0 - public @@ -1057,9 +1036,6 @@ public\rehlds - - public - unittests @@ -1099,6 +1075,12 @@ engine\common + + hookers + + + public + diff --git a/rehlds/public/basetypes.h b/rehlds/public/basetypes.h index 8929655..f47aabd 100644 --- a/rehlds/public/basetypes.h +++ b/rehlds/public/basetypes.h @@ -1,9 +1,30 @@ -//========= Copyright 1996-2001, Valve LLC, All rights reserved. ============ -// -// Purpose: -// -// $NoKeywords: $ -//============================================================================= +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ #ifndef BASETYPES_H #define BASETYPES_H @@ -12,9 +33,10 @@ #endif #include "osconfig.h" -#include "protected_things.h" #include "commonmacros.h" +#include "archtypes.h" +#include "mathlib.h" // For backward compatibilty only... #include "tier0/platform.h" @@ -24,45 +46,16 @@ #define NULL 0 #endif - -#define ExecuteNTimes( nTimes, x ) \ - { \ - static int __executeCount=0;\ - if ( __executeCount < nTimes )\ - { \ - x; \ - ++__executeCount; \ - } \ - } - - -#define ExecuteOnce( x ) ExecuteNTimes( 1, x ) - - // Pad a number so it lies on an N byte boundary. // So PAD_NUMBER(0,4) is 0 and PAD_NUMBER(1,4) is 4 #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 -#endif // MATHLIB_H + (((number) + ((boundary) - 1)) / (boundary)) * (boundary) #ifndef FALSE #define FALSE 0 #define TRUE (!FALSE) #endif - typedef int BOOL; typedef int qboolean; typedef unsigned long ULONG; @@ -72,216 +65,14 @@ typedef unsigned short word; typedef float vec_t; - -// FIXME: this should move -#ifndef __cplusplus -#define true TRUE -#define false FALSE -#endif - -//----------------------------------------------------------------------------- -// look for NANs, infinities, and underflows. -// This assumes the ANSI/IEEE 754-1985 standard -//----------------------------------------------------------------------------- - -#ifdef __cplusplus - -inline unsigned long& FloatBits(vec_t& f) -{ - return *reinterpret_cast(&f); -} - -inline unsigned long const& FloatBits(vec_t const& f) -{ - return *reinterpret_cast(&f); -} - -inline vec_t BitsToFloat(unsigned long i) -{ - return *reinterpret_cast(&i); -} - -inline bool IsFinite(vec_t f) -{ - return ((FloatBits(f) & 0x7F800000) != 0x7F800000); -} - -inline unsigned long FloatAbsBits(vec_t f) -{ - return FloatBits(f) & 0x7FFFFFFF; -} - -inline float FloatMakeNegative(vec_t f) -{ - return BitsToFloat(FloatBits(f) | 0x80000000); -} - -#if defined( WIN32 ) - -//#include -// Just use prototype from math.h -#ifdef __cplusplus -extern "C" -{ -#endif - double __cdecl fabs(double); -#ifdef __cplusplus -} -#endif - -// In win32 try to use the intrinsic fabs so the optimizer can do it's thing inline in the code -#pragma intrinsic( fabs ) -// Also, alias float make positive to use fabs, too -// NOTE: Is there a perf issue with double<->float conversion? -inline float FloatMakePositive(vec_t f) -{ - return fabs(f); -} -#else -inline float FloatMakePositive(vec_t f) -{ - return BitsToFloat(FloatBits(f) & 0x7FFFFFFF); -} -#endif - -inline float FloatNegate(vec_t f) -{ - return BitsToFloat(FloatBits(f) ^ 0x80000000); -} - - -#define FLOAT32_NAN_BITS (unsigned long)0x7FC00000 // not a number! -#define FLOAT32_NAN BitsToFloat( FLOAT32_NAN_BITS ) - -#define VEC_T_NAN FLOAT32_NAN - -#endif - -// FIXME: why are these here? Hardly anyone actually needs them. -struct valve_color24 -{ - byte r, g, b; -}; - -typedef struct valve_color32_s -{ - bool operator!=(const struct valve_color32_s &other) const; - - byte r, g, b, a; -} valve_color32; - -inline bool valve_color32::operator!=(const valve_color32 &other) const -{ - return r != other.r || g != other.g || b != other.b || a != other.a; -} - -struct valve_colorRGBExp32 -{ - byte r, g, b; - signed char exponent; -}; - -struct valve_colorVec -{ - unsigned r, g, b, a; -}; - - #ifndef UNUSED #define UNUSED(x) (x = x) // for pesky compiler / lint warnings #endif -#ifdef __cplusplus - struct vrect_t { - int x, y, width, height; - vrect_t *pnext; + int x, y, width, height; + vrect_t *pnext; }; -#endif - - -//----------------------------------------------------------------------------- -// MaterialRect_t struct - used for DrawDebugText -//----------------------------------------------------------------------------- -struct Rect_t -{ - int x, y; - int width, height; -}; - - -//----------------------------------------------------------------------------- -// Declares a type-safe handle type; you can't assign one handle to the next -//----------------------------------------------------------------------------- - -// 32-bit pointer handles. - -// Typesafe 8-bit and 16-bit handles. -template< class HandleType > -class CBaseIntHandle -{ -public: - - inline bool operator==(const CBaseIntHandle &other) { return m_Handle == other.m_Handle; } - inline bool operator!=(const CBaseIntHandle &other) { return m_Handle != other.m_Handle; } - - // Only the code that doles out these handles should use these functions. - // Everyone else should treat them as a transparent type. - inline HandleType GetHandleValue() { return m_Handle; } - inline void SetHandleValue(HandleType val) { m_Handle = val; } - - typedef HandleType HANDLE_TYPE; - -protected: - - HandleType m_Handle; -}; - -template< class DummyType > -class CIntHandle16 : public CBaseIntHandle < unsigned short > -{ -public: - inline CIntHandle16() {} - - static inline CIntHandle16 MakeHandle(HANDLE_TYPE val) - { - return CIntHandle16(val); - } - -protected: - inline CIntHandle16(HANDLE_TYPE val) - { - m_Handle = val; - } -}; - - -template< class DummyType > -class CIntHandle32 : public CBaseIntHandle < unsigned long > -{ -public: - inline CIntHandle32() {} - - static inline CIntHandle32 MakeHandle(HANDLE_TYPE val) - { - return CIntHandle32(val); - } - -protected: - inline CIntHandle32(HANDLE_TYPE val) - { - m_Handle = val; - } -}; - - -// NOTE: This macro is the same as windows uses; so don't change the guts of it -#define DECLARE_HANDLE_16BIT(name) typedef CIntHandle16< struct name##__handle * > name; -#define DECLARE_HANDLE_32BIT(name) typedef CIntHandle32< struct name##__handle * > name; - -#define DECLARE_POINTER_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name -#define FORWARD_DECLARE_HANDLE(name) typedef struct name##__ *name - #endif // BASETYPES_H diff --git a/rehlds/public/protected_things.h b/rehlds/public/protected_things.h deleted file mode 100644 index ab10bbb..0000000 --- a/rehlds/public/protected_things.h +++ /dev/null @@ -1,187 +0,0 @@ -//========= Copyright © 1996-2002, Valve LLC, All rights reserved. ============ -// -// Purpose: -// -// $NoKeywords: $ -//============================================================================= - -#ifndef PROTECTED_THINGS_H -#define PROTECTED_THINGS_H -#ifdef _WIN32 -#pragma once -#endif - - -// This header tries to prevent people from using potentially dangerous functions -// (like the notorious non-null-terminating strncpy) and functions that will break -// VCR mode (like time, input, registry, etc). -// -// This header should be included by ALL of our source code. - -// Eventually, ALL of these should be protected, but one man can only accomplish so much in -// one day AND work on features too! -#if defined( PROTECT_STRING_FUNCTIONS ) -#if defined( strncpy ) -#undef strncpy -#endif -#define strncpy strncpy__HEY_YOU__USE_VSTDLIB - - -#if defined( _snprintf ) -#undef _snprintf -#endif -#define _snprintf snprintf__HEY_YOU__USE_VSTDLIB - - -#if defined( sprintf ) -#undef sprintf -#endif -#define sprintf sprintf__HEY_YOU__USE_VSTDLIB - - -#if defined( _vsnprintf ) -#undef _vsnprintf -#endif -#define _vsnprintf vsnprintf__HEY_YOU__USE_VSTDLIB - - -#if defined( strcat ) -#undef strcat -#endif -#define strcat strcat__HEY_YOU__USE_VSTDLIB -#endif - - -#if defined( PROTECT_FILEIO_FUNCTIONS ) -#if defined( fopen ) -#undef fopen -#endif -#define fopen fopen_USE_FILESYSTEM_INSTEAD -#endif - - -#if defined( PROTECTED_THINGS_ENABLE ) - -#if defined( GetTickCount ) -#undef GetTickCount -#endif -#define GetTickCount GetTickCount__HEY_YOU__USE_PLATFORM_LIB - - -#if defined( timeGetTime ) -#undef timeGetTime -#endif -#define timeGetTime timeGetTime__HEY_YOU__USE_PLATFORM_LIB - - -#if defined( clock ) -#undef clock -#endif -#define time time__HEY_YOU__USE_PLATFORM_LIB - - -#if defined( recvfrom ) -#undef recvfrom -#endif -#define recvfrom recvfrom__HEY_YOU__USE_PLATFORM_LIB - - -#if defined( GetCursorPos ) -#undef GetCursorPos -#endif -#define GetCursorPos GetCursorPos__HEY_YOU__USE_PLATFORM_LIB - - -#if defined( ScreenToClient ) -#undef ScreenToClient -#endif -#define ScreenToClient ScreenToClient__HEY_YOU__USE_PLATFORM_LIB - - -#if defined( GetCommandLine ) -#undef GetCommandLine -#endif -#define GetCommandLine GetCommandLine__HEY_YOU__USE_PLATFORM_LIB - - -#if defined( RegOpenKeyEx ) -#undef RegOpenKeyEx -#endif -#define RegOpenKeyEx RegOpenKeyEx__HEY_YOU__USE_PLATFORM_LIB - - -#if defined( RegOpenKey ) -#undef RegOpenKey -#endif -#define RegOpenKey RegOpenKey__HEY_YOU__USE_PLATFORM_LIB - - -#if defined( RegSetValueEx ) -#undef RegSetValueEx -#endif -#define RegSetValueEx RegSetValueEx__HEY_YOU__USE_PLATFORM_LIB - - -#if defined( RegSetValue ) -#undef RegSetValue -#endif -#define RegSetValue RegSetValue__HEY_YOU__USE_PLATFORM_LIB - - -#if defined( RegQueryValueEx ) -#undef RegQueryValueEx -#endif -#define RegQueryValueEx RegQueryValueEx__HEY_YOU__USE_PLATFORM_LIB - - -#if defined( RegQueryValue ) -#undef RegQueryValue -#endif -#define RegQueryValue RegQueryValue__HEY_YOU__USE_PLATFORM_LIB - - -#if defined( RegCreateKeyEx ) -#undef RegCreateKeyEx -#endif -#define RegCreateKeyEx RegCreateKeyEx__HEY_YOU__USE_PLATFORM_LIB - - -#if defined( RegCreateKey ) -#undef RegCreateKey -#endif -#define RegCreateKey RegCreateKey__HEY_YOU__USE_PLATFORM_LIB - - -#if defined( RegCloseKey ) -#undef RegCloseKey -#endif -#define RegCloseKey RegCloseKey__HEY_YOU__USE_PLATFORM_LIB - - -#if defined( GetNumberOfConsoleInputEvents ) -#undef GetNumberOfConsoleInputEvents -#endif -#define GetNumberOfConsoleInputEvents GetNumberOfConsoleInputEvents__HEY_YOU__USE_PLATFORM_LIB - - -#if defined( ReadConsoleInput ) -#undef ReadConsoleInput -#endif -#define ReadConsoleInput ReadConsoleInput__HEY_YOU__USE_PLATFORM_LIB - - -#if defined( GetAsyncKeyState ) -#undef GetAsyncKeyState -#endif -#define GetAsyncKeyState GetAsyncKeyState__HEY_YOU__USE_PLATFORM_LIB - - -#if defined( GetKeyState ) -#undef GetKeyState -#endif -#define GetKeyState GetKeyState__HEY_YOU__USE_PLATFORM_LIB - -#endif - - -#endif // PROTECTED_THINGS_H diff --git a/rehlds/public/rehlds/osconfig.h b/rehlds/public/rehlds/osconfig.h index f2810b6..db7a0f5 100644 --- a/rehlds/public/rehlds/osconfig.h +++ b/rehlds/public/rehlds/osconfig.h @@ -103,8 +103,10 @@ #ifndef CDECL #define CDECL __cdecl #endif + #define FASTCALL __fastcall #define STDCALL __stdcall #define HIDDEN + #define FORCEINLINE __forceinline #define NOINLINE __declspec(noinline) #define ALIGN16 __declspec(align(16)) #define NORETURN __declspec(noreturn) @@ -147,9 +149,11 @@ typedef unsigned short WORD; typedef unsigned int UNINT32; + #define FASTCALL #define CDECL __attribute__ ((cdecl)) #define STDCALL __attribute__ ((stdcall)) #define HIDDEN __attribute__((visibility("hidden"))) + #define FORCEINLINE inline #define NOINLINE __attribute__((noinline)) #define ALIGN16 __attribute__((aligned(16))) #define NORETURN __attribute__((noreturn)) diff --git a/rehlds/public/strtools.h b/rehlds/public/strtools.h new file mode 100644 index 0000000..e856681 --- /dev/null +++ b/rehlds/public/strtools.h @@ -0,0 +1,199 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ + +#pragma once + +#ifdef _WIN32 +const char CORRECT_PATH_SEPARATOR = '\\'; +const char INCORRECT_PATH_SEPARATOR = '/'; +#else +const char CORRECT_PATH_SEPARATOR = '/'; +const char INCORRECT_PATH_SEPARATOR = '\\'; +#endif + +#if !defined(_WIN32) +inline char *_strupr(char *start) +{ + char *str = start; + while (str && *str) + { + *str = (char)toupper(*str); + str++; + } + + return start; +} + +inline char *_strlwr(char *start) +{ + char *str = start; + while (str && *str) + { + *str = (char)tolower(*str); + str++; + } + + return start; +} +#endif + +#if defined(ASMLIB_H) && defined(HAVE_OPT_STRTOOLS) + #define Q_memset A_memset + #define Q_memcpy A_memcpy + #define Q_memcmp A_memcmp + #define Q_memmove A_memmove + #define Q_strlen A_strlen + #define Q_strcpy A_strcpy + #define Q_strncpy strncpy + #define Q_strcat A_strcat + #define Q_strncat strncat + #define Q_strcmp A_strcmp + #define Q_strncmp strncmp + #define Q_strdup _strdup + #define Q_stricmp A_stricmp + #define Q_strnicmp _strnicmp + #define Q_strstr A_strstr + #define Q_strchr strchr + #define Q_strrchr strrchr + #define Q_strlwr A_strtolower + #define Q_strupr A_strtoupper + #define Q_sprintf sprintf + #define Q_snprintf _snprintf + #define Q_vsnprintf _vsnprintf + #define Q_vsnwprintf _vsnwprintf + #define Q_atoi atoi + #define Q_atof atof + #define Q_sqrt M_sqrt + #define Q_min M_min + #define Q_max M_max + #define Q_clamp M_clamp + #define Q_abs abs + #define Q_fabs fabs + #define Q_tan tan + #define Q_atan atan + #define Q_atan2 atan2 + #define Q_acos acos + #define Q_cos cos + #define Q_sin sin + #define Q_pow pow + #define Q_fmod fmod +#else + #define Q_memset memset + #define Q_memcpy memcpy + #define Q_memcmp memcmp + #define Q_memmove memmove + #define Q_strlen strlen + #define Q_strcpy strcpy + #define Q_strncpy strncpy + #define Q_strcat strcat + #define Q_strncat strncat + #define Q_strcmp strcmp + #define Q_strncmp strncmp + #define Q_strdup _strdup + #define Q_stricmp _stricmp + #define Q_strnicmp _strnicmp + #define Q_strstr strstr + #define Q_strchr strchr + #define Q_strrchr strrchr + #define Q_strlwr _strlwr + #define Q_strupr _strupr + #define Q_sprintf sprintf + #define Q_snprintf _snprintf + #define Q_vsnprintf _vsnprintf + #define Q_vsnwprintf _vsnwprintf + #define Q_atoi atoi + #define Q_atof atof + #define Q_sqrt sqrt + #define Q_min min + #define Q_max max + #define Q_clamp clamp + #define Q_abs abs + #define Q_fabs fabs + #define Q_tan tan + #define Q_atan atan + #define Q_atan2 atan2 + #define Q_acos acos + #define Q_cos cos + #define Q_sin sin + #define Q_pow pow + #define Q_fmod fmod +#endif // #if defined(ASMLIB_H) && defined(HAVE_OPT_STRTOOLS) + +template +char *Q_strlcpy(char (&dest)[N], const char *src) { + Q_strncpy(dest, src, N - 1); + dest[N - 1] = '\0'; + return dest; +} + +inline char *Q_strnlcpy(char *dest, const char *src, size_t n) { + Q_strncpy(dest, src, n - 1); + dest[n - 1] = '\0'; + return dest; +} + +template +size_t Q_strlcat(char (&dest)[N], const char *src) +{ + size_t dstlen = Q_strlen(dest); + size_t size = N - dstlen + 1; + + if (!size) { + return dstlen; + } + + size_t srclen = Q_strlen(src); + if (srclen > size) + srclen = size; + + Q_memcpy(dst + dstlen, src, srclen); + dst[dstlen + srclen] = '\0'; + + return dstlen + srclen; +} + +// Force slashes of either type to be = separator character +inline void Q_FixSlashes(char *pname, char separator = CORRECT_PATH_SEPARATOR) +{ + while (*pname) + { + if (*pname == INCORRECT_PATH_SEPARATOR || *pname == CORRECT_PATH_SEPARATOR) + { + *pname = separator; + } + + pname++; + } +} + +// strcpy that works correctly with overlapping src and dst buffers +inline char *strcpy_safe(char *dst, char *src) { + int len = Q_strlen(src); + Q_memmove(dst, src, len + 1); + return dst; +} diff --git a/rehlds/public/tier0/dbg.h b/rehlds/public/tier0/dbg.h index 23e836e..df088d6 100644 --- a/rehlds/public/tier0/dbg.h +++ b/rehlds/public/tier0/dbg.h @@ -19,9 +19,8 @@ #pragma once #endif -#include "osconfig.h" #include "basetypes.h" -#include "tier0/platform.h" + #include #include #include diff --git a/rehlds/public/tier0/mem.h b/rehlds/public/tier0/mem.h deleted file mode 100644 index 5171ffe..0000000 --- a/rehlds/public/tier0/mem.h +++ /dev/null @@ -1,37 +0,0 @@ -//========= Copyright © 1996-2001, Valve LLC, All rights reserved. ============ -// -// Purpose: Memory allocation! -// -// $NoKeywords: $ -//============================================================================= - -#ifndef TIER0_MEM_H -#define TIER0_MEM_H - -#ifdef _WIN32 -#pragma once -#endif - -#include "osconfig.h" -#include -#include "tier0/platform.h" - -#ifdef TIER0_DLL_EXPORT -# define MEM_INTERFACE DLL_EXPORT -#else -# define MEM_INTERFACE DLL_IMPORT -#endif - - -//----------------------------------------------------------------------------- -// DLL-exported methods for particular kinds of memory -//----------------------------------------------------------------------------- -MEM_INTERFACE void *MemAllocScratch(int nMemSize); -MEM_INTERFACE void MemFreeScratch(); - -#ifdef __linux__ -MEM_INTERFACE void ZeroMemory(void *mem, size_t length); -#endif - - -#endif /* TIER0_MEM_H */ diff --git a/rehlds/public/tier0/memalloc.h b/rehlds/public/tier0/memalloc.h deleted file mode 100644 index 165d6d1..0000000 --- a/rehlds/public/tier0/memalloc.h +++ /dev/null @@ -1,77 +0,0 @@ -//========= Copyright © 1996-2001, Valve LLC, All rights reserved. ============ -// -// Purpose: This header should never be used directly from leaf code!!! -// Instead, just add the file memoverride.cpp into your project and all this -// will automagically be used -// -// $NoKeywords: $ -//============================================================================= - -#ifndef TIER0_MEMALLOC_H -#define TIER0_MEMALLOC_H - -#ifdef _WIN32 -#pragma once -#endif - -#include "osconfig.h" -#include -#include "tier0/mem.h" - -struct _CrtMemState; - -//----------------------------------------------------------------------------- -// NOTE! This should never be called directly from leaf code -// Just use new,delete,malloc,free etc. They will call into this eventually -//----------------------------------------------------------------------------- -class IMemAlloc -{ -public: - // Release versions - virtual void *Alloc(size_t nSize) = 0; - virtual void *Realloc(void *pMem, size_t nSize) = 0; - virtual void Free(void *pMem) = 0; - virtual void *Expand(void *pMem, size_t nSize) = 0; - - // Debug versions - virtual void *Alloc(size_t nSize, const char *pFileName, int nLine) = 0; - virtual void *Realloc(void *pMem, size_t nSize, const char *pFileName, int nLine) = 0; - virtual void Free(void *pMem, const char *pFileName, int nLine) = 0; - virtual void *Expand(void *pMem, size_t nSize, const char *pFileName, int nLine) = 0; - - // Returns size of a particular allocation - virtual size_t GetSize(void *pMem) = 0; - - // Force file + line information for an allocation - virtual void PushAllocDbgInfo(const char *pFileName, int nLine) = 0; - virtual void PopAllocDbgInfo() = 0; - - // FIXME: Remove when we have our own allocator - // these methods of the Crt debug code is used in our codebase currently - virtual long CrtSetBreakAlloc(long lNewBreakAlloc) = 0; - virtual int CrtSetReportMode(int nReportType, int nReportMode) = 0; - virtual int CrtIsValidHeapPointer(const void *pMem) = 0; - virtual int CrtCheckMemory(void) = 0; - virtual int CrtSetDbgFlag(int nNewFlag) = 0; - virtual void CrtMemCheckpoint(_CrtMemState *pState) = 0; - - // FIXME: Make a better stats interface - virtual void DumpStats() = 0; - - // FIXME: Remove when we have our own allocator - virtual void* CrtSetReportFile(int nRptType, void* hFile) = 0; - virtual void* CrtSetReportHook(void* pfnNewHook) = 0; - virtual int CrtDbgReport(int nRptType, const char * szFile, - int nLine, const char * szModule, const char * pMsg) = 0; - - virtual int heapchk() = 0; -}; - - -//----------------------------------------------------------------------------- -// Singleton interface -//----------------------------------------------------------------------------- -IMemAlloc *g_pMemAlloc; - - -#endif /* TIER0_MEMALLOC_H */ diff --git a/rehlds/public/tier0/memdbgoff.h b/rehlds/public/tier0/memdbgoff.h deleted file mode 100644 index 7abf9e8..0000000 --- a/rehlds/public/tier0/memdbgoff.h +++ /dev/null @@ -1,21 +0,0 @@ -//========= Copyright © 1996-2003, Valve LLC, All rights reserved. ============ -// -// Purpose: This header, which must be the final line of a .h file, -// causes all crt methods to stop using debugging versions of the memory allocators. -// NOTE: Use memdbgon.h to re-enable memory debugging. -// -// $NoKeywords: $ -//============================================================================= - -#ifdef MEM_DEBUG_ON - -#undef malloc -#undef realloc -#undef calloc -#undef free -#undef _expand -#undef _msize -#undef new -#undef MEM_DEBUG_ON - -#endif diff --git a/rehlds/public/tier0/memdbgon.h b/rehlds/public/tier0/memdbgon.h deleted file mode 100644 index 3090b8f..0000000 --- a/rehlds/public/tier0/memdbgon.h +++ /dev/null @@ -1,93 +0,0 @@ -//========= Copyright © 1996-2003, Valve LLC, All rights reserved. ============ -// -// Purpose: This header, which must be the final include in a .cpp (or .h) file, -// causes all crt methods to use debugging versions of the memory allocators. -// NOTE: Use memdbgoff.h to disable memory debugging. -// -// $NoKeywords: $ -//============================================================================= - -// SPECIAL NOTE! This file must *not* use include guards; we need to be able -// to include this potentially multiple times (since we can deactivate debugging -// by including memdbgoff.h) - -// SPECIAL NOTE #2: This must be the final include in a .cpp or .h file!!! -#include "osconfig.h" - -#ifdef _DEBUG - -#include -#include -#include -#include - -#include "tier0/memdbgoff.h" - -#define MEM_DEBUG_ON 1 - -#undef malloc -#undef realloc -#undef calloc -#undef _expand -#undef free -#undef _msize - -#define malloc(s) _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__) -#define calloc(c, s) _calloc_dbg(c, s, _NORMAL_BLOCK, __FILE__, __LINE__) -#define realloc(p, s) _realloc_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__) -#define free(p) _free_dbg(p, _NORMAL_BLOCK) -#define _msize(p) _msize_dbg(p, _NORMAL_BLOCK) -#define _expand(p, s) _expand_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__) - - -#if defined(__AFX_H__) && defined(DEBUG_NEW) -#define new DEBUG_NEW -#else -#undef new -#define MEMALL_DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) -#define new MEMALL_DEBUG_NEW -#endif - -#undef _strdup -#undef strdup -#undef _wcsdup -#undef wcsup - -#define _strdup(s) strdup_dbg(s, __FILE__, __LINE__) -#define strdup(s) strdup_dbg(s, __FILE__, __LINE__) -#define _wcsdup(s) wcsdup_dbg(s, __FILE__, __LINE__) -#define wcsdup(s) wcsdup_dbg(s, __FILE__, __LINE__) - -// Make sure we don't define strdup twice -#ifndef MEM_DBG_DEFINED_STRDUP -#define MEM_DBG_DEFINED_STRDUP 1 - -inline char *strdup_dbg(const char *pString, const char *pFileName, unsigned nLine) -{ - char *pMemory; - - if (!pString) - return NULL; - - if ((pMemory = (char *)_malloc_dbg(strlen(pString) + 1, _NORMAL_BLOCK, pFileName, nLine)) != NULL) - return strcpy(pMemory, pString); - - return NULL; -} - -inline wchar_t *wcsdup_dbg(const wchar_t *pString, const char *pFileName, unsigned nLine) -{ - wchar_t *pMemory; - - if (!pString) - return NULL; - - if ((pMemory = (wchar_t *)_malloc_dbg((wcslen(pString) + 1) * sizeof(wchar_t), _NORMAL_BLOCK, pFileName, nLine)) != NULL) - return wcscpy(pMemory, pString); - - return NULL; -} - -#endif // DBMEM_DEFINED_STRDUP - -#endif // _DEBUG diff --git a/rehlds/public/tier0/platform.h b/rehlds/public/tier0/platform.h index 40fd908..92f8319 100644 --- a/rehlds/public/tier0/platform.h +++ b/rehlds/public/tier0/platform.h @@ -1,102 +1,40 @@ -//=========== (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 -//============================================================================= +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ - -#ifndef PLATFORM_H -#define PLATFORM_H - -#ifdef _WIN32 #pragma once -#endif #include "osconfig.h" -// need this for _alloca -#include - -// need this for memset -#include +#include // need this for _alloca +#include // need this for memset #include "archtypes.h" -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)~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 @@ -108,92 +46,42 @@ typedef void * HINSTANCE; // C functions for external declarations that call the appropriate C++ methods #ifndef EXPORT #ifdef _WIN32 -#define EXPORT _declspec( dllexport ) -#else +#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 ) +#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 ) +#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 ) +#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" +#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 +#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 +#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 @@ -216,274 +104,22 @@ typedef void * HINSTANCE; #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 temp; - - temp = *((uint32 *)&dw) >> 24; - temp |= ((*((uint32 *)&dw) & 0x00FF0000) >> 8); - temp |= ((*((uint32 *)&dw) & 0x0000FF00) << 8); - temp |= ((*((uint32 *)&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 BigDWord(uint32 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 LittleDWord(uint32 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) +inline void Construct(T *pMemory) { - new(pMemory)T; + new(pMemory) T; } template -inline void CopyConstruct(T* pMemory, T const& src) +inline void CopyConstruct(T *pMemory, T const &src) { - new(pMemory)T(src); + new(pMemory) T(src); } template -inline void Destruct(T* pMemory) +inline void Destruct(T *pMemory) { pMemory->~T(); @@ -491,140 +127,3 @@ inline void Destruct(T* pMemory) 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 */ diff --git a/rehlds/public/tier0/platform_linux.cpp b/rehlds/public/tier0/platform_linux.cpp deleted file mode 100644 index ed150dc..0000000 --- a/rehlds/public/tier0/platform_linux.cpp +++ /dev/null @@ -1,59 +0,0 @@ -//========= Copyright © 1996-2002, Valve LLC, All rights reserved. ============ -// -// Purpose: -// -// $NoKeywords: $ -//============================================================================= - -#include "precompiled.h" - -double Plat_FloatTime() -{ - struct timeval tp; - static int secbase = 0; - - gettimeofday(&tp, NULL); - - if (!secbase) - { - secbase = tp.tv_sec; - return (tp.tv_usec / 1000000.0); - } - - return ((tp.tv_sec - secbase) + tp.tv_usec / 1000000.0); -} - -unsigned long Plat_MSTime() -{ - struct timeval tp; - static int secbase = 0; - - gettimeofday(&tp, NULL); - - if (!secbase) - { - secbase = tp.tv_sec; - return (tp.tv_usec / 1000000.0); - } - - return (unsigned long)((tp.tv_sec - secbase) + tp.tv_usec / 1000000.0); - -} - - - -bool vtune(bool resume) -{ - return true; -} - - -// -------------------------------------------------------------------------------------------------- // -// Memory stuff. -// -------------------------------------------------------------------------------------------------- // - - -void Plat_SetThreadName(unsigned long dwThreadID, const char *pName) -{ - Assert("Plat_SetThreadName not implemented"); -} diff --git a/rehlds/public/tier0/platform_win32.cpp b/rehlds/public/tier0/platform_win32.cpp deleted file mode 100644 index 26b53a5..0000000 --- a/rehlds/public/tier0/platform_win32.cpp +++ /dev/null @@ -1,95 +0,0 @@ -//========= Copyright © 1996-2002, Valve LLC, All rights reserved. ============ -// -// Purpose: -// -// $NoKeywords: $ -//============================================================================= - -#include "precompiled.h" - -static LARGE_INTEGER g_PerformanceFrequency; -static LARGE_INTEGER g_MSPerformanceFrequency; -static LARGE_INTEGER g_ClockStart; -static HINSTANCE g_pVTuneDLL; - -static void InitTime() -{ - if (!g_PerformanceFrequency.QuadPart) - { - QueryPerformanceFrequency(&g_PerformanceFrequency); - g_MSPerformanceFrequency.QuadPart = g_PerformanceFrequency.QuadPart / 1000; - QueryPerformanceCounter(&g_ClockStart); - } -} - -double Plat_FloatTime() -{ - InitTime(); - - LARGE_INTEGER CurrentTime; - - QueryPerformanceCounter(&CurrentTime); - - double fRawSeconds = (double)(CurrentTime.QuadPart - g_ClockStart.QuadPart) / (double)(g_PerformanceFrequency.QuadPart); - - return fRawSeconds; -} - -unsigned long Plat_MSTime() -{ - InitTime(); - - LARGE_INTEGER CurrentTime; - - QueryPerformanceCounter(&CurrentTime); - - return (unsigned long)((CurrentTime.QuadPart - g_ClockStart.QuadPart) / g_MSPerformanceFrequency.QuadPart); -} - -void free_vtune() -{ - FreeLibrary(g_pVTuneDLL); -} - -bool vtune(bool resume) -{ - static bool bInitialized = false; - static void(__cdecl *VTResume)(void) = NULL; - static void(__cdecl *VTPause) (void) = NULL; - - // Grab the Pause and Resume function pointers from the VTune DLL the first time through: - if (!bInitialized) - { - bInitialized = true; - - g_pVTuneDLL = LoadLibrary("vtuneapi.dll"); - - if (g_pVTuneDLL) - { - VTResume = (void(__cdecl *)())GetProcAddress(g_pVTuneDLL, "VTResume"); - VTPause = (void(__cdecl *)())GetProcAddress(g_pVTuneDLL, "VTPause"); - atexit(free_vtune); - } - } - - // Call the appropriate function, as indicated by the argument: - if (resume && VTResume) - { - VTResume(); - return true; - - } - else if (!resume && VTPause) - { - VTPause(); - return true; - } - - return false; - -} - - -// -------------------------------------------------------------------------------------------------- // -// Memory stuff. -// -------------------------------------------------------------------------------------------------- // diff --git a/rehlds/public/utllinkedlist.h b/rehlds/public/utllinkedlist.h index 05f8799..4ce917b 100644 --- a/rehlds/public/utllinkedlist.h +++ b/rehlds/public/utllinkedlist.h @@ -18,7 +18,6 @@ #pragma once #endif -#include "osconfig.h" #include "basetypes.h" #include "utlmemory.h" #include "tier0/dbg.h" diff --git a/rehlds/public/utlmap.h b/rehlds/public/utlmap.h new file mode 100644 index 0000000..4433f26 --- /dev/null +++ b/rehlds/public/utlmap.h @@ -0,0 +1,261 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ + +#pragma once + +#include "tier0/dbg.h" +#include "utlrbtree.h" + +// Purpose: An associative container. Pretty much identical to std::map. +// This is a useful macro to iterate from start to end in order in a map +#define FOR_EACH_MAP(mapName, iteratorName)\ + for (int iteratorName = (mapName).FirstInorder(); (mapName).IsUtlMap && iteratorName != (mapName).InvalidIndex(); iteratorName = (mapName).NextInorder(iteratorName)) + +// faster iteration, but in an unspecified order +#define FOR_EACH_MAP_FAST(mapName, iteratorName)\ + for (int iteratorName = 0; (mapName).IsUtlMap && iteratorName < (mapName).MaxElement(); ++iteratorName) if (!(mapName).IsValidIndex(iteratorName)) continue; else + +struct base_utlmap_t +{ +public: + // This enum exists so that FOR_EACH_MAP and FOR_EACH_MAP_FAST cannot accidentally + // be used on a type that is not a CUtlMap. If the code compiles then all is well. + // The check for IsUtlMap being true should be free. + // Using an enum rather than a static const bool ensures that this trick works even + // with optimizations disabled on gcc. + enum CompileTimeCheck + { + IsUtlMap = 1 + }; +}; + +template +class CUtlMap: public base_utlmap_t +{ +public: + typedef K KeyType_t; + typedef T ElemType_t; + typedef I IndexType_t; + + // Less func typedef + // Returns true if the first parameter is "less" than the second + typedef bool (*LessFunc_t)(const KeyType_t &, const KeyType_t &); + + // constructor, destructor + // Left at growSize = 0, the memory will first allocate 1 element and double in size + // at each increment. + // LessFunc_t is required, but may be set after the constructor using SetLessFunc() below + CUtlMap(int growSize = 0, int initSize = 0, LessFunc_t lessfunc = 0) + : m_Tree(growSize, initSize, CKeyLess(lessfunc)) + { + if (!lessfunc) { + SetLessFunc(DefLessFunc(K)); + } + } + + CUtlMap(LessFunc_t lessfunc) + : m_Tree(CKeyLess(lessfunc)) + { + if (!lessfunc) { + SetLessFunc(DefLessFunc(K)); + } + } + + void EnsureCapacity(int num) { m_Tree.EnsureCapacity(num); } + + // gets particular elements + ElemType_t & Element(IndexType_t i) { return m_Tree.Element(i).elem; } + const ElemType_t & Element(IndexType_t i) const { return m_Tree.Element(i).elem; } + ElemType_t & operator[](IndexType_t i) { return m_Tree.Element(i).elem; } + const ElemType_t & operator[](IndexType_t i) const { return m_Tree.Element(i).elem; } + KeyType_t & Key(IndexType_t i) { return m_Tree.Element(i).key; } + const KeyType_t & Key(IndexType_t i) const { return m_Tree.Element(i).key; } + + + // Num elements + unsigned int Count() const { return m_Tree.Count(); } + + // Max "size" of the vector + IndexType_t MaxElement() const { return m_Tree.MaxElement(); } + + // Checks if a node is valid and in the map + bool IsValidIndex(IndexType_t i) const { return m_Tree.IsValidIndex(i); } + + // Checks if the map as a whole is valid + bool IsValid() const { return m_Tree.IsValid(); } + + // Invalid index + static IndexType_t InvalidIndex() { return CTree::InvalidIndex(); } + + // Sets the less func + void SetLessFunc(LessFunc_t func) + { + m_Tree.SetLessFunc(CKeyLess(func)); + } + + // Insert method (inserts in order) + IndexType_t Insert(const KeyType_t &key, const ElemType_t &insert) + { + Node_t node; + node.key = key; + node.elem = insert; + return m_Tree.Insert(node); + } + + IndexType_t Insert(const KeyType_t &key) + { + Node_t node; + node.key = key; + return m_Tree.Insert(node); + } + + // Find method + IndexType_t Find(const KeyType_t &key) const + { + Node_t dummyNode; + dummyNode.key = key; + return m_Tree.Find(dummyNode); + } + + // Remove methods + void RemoveAt(IndexType_t i) { m_Tree.RemoveAt(i); } + bool Remove(const KeyType_t &key) + { + Node_t dummyNode; + dummyNode.key = key; + return m_Tree.Remove(dummyNode); + } + + void RemoveAll() { m_Tree.RemoveAll(); } + void Purge() { m_Tree.Purge(); } + + // Purges the list and calls delete on each element in it. + void PurgeAndDeleteElements(); + + // Iteration + IndexType_t FirstInorder() const { return m_Tree.FirstInorder(); } + IndexType_t NextInorder(IndexType_t i) const { return m_Tree.NextInorder(i); } + IndexType_t PrevInorder(IndexType_t i) const { return m_Tree.PrevInorder(i); } + IndexType_t LastInorder() const { return m_Tree.LastInorder(); } + + // If you change the search key, this can be used to reinsert the + // element into the map. + void Reinsert(const KeyType_t &key, IndexType_t i) + { + m_Tree[i].key = key; + m_Tree.Reinsert(i); + } + + IndexType_t InsertOrReplace(const KeyType_t &key, const ElemType_t &insert) + { + IndexType_t i = Find(key); + if (i != InvalidIndex()) + { + Element(i) = insert; + return i; + } + + return Insert(key, insert); + } + + void Swap(CUtlMap &that) + { + m_Tree.Swap(that.m_Tree); + } + + struct Node_t + { + Node_t() + { + } + + Node_t(const Node_t &from) + : key(from.key), + elem(from.elem) + { + } + + KeyType_t key; + ElemType_t elem; + }; + + class CKeyLess + { + public: + CKeyLess(LessFunc_t lessFunc) : m_LessFunc(lessFunc) {} + + bool operator!() const + { + return !m_LessFunc; + } + + bool operator()(const Node_t &left, const Node_t &right) const + { + return m_LessFunc(left.key, right.key); + } + + LessFunc_t m_LessFunc; + }; + + typedef CUtlRBTree CTree; + + CTree *AccessTree() { return &m_Tree; } + +protected: + CTree m_Tree; +}; + +// Purges the list and calls delete on each element in it. +template +inline void CUtlMap::PurgeAndDeleteElements() +{ + for (I i = 0; i < MaxElement(); ++i) + { + if (!IsValidIndex(i)) + continue; + + delete Element(i); + } + + Purge(); +} + +// This is horrible and slow and meant to be used only when you're dealing with really +// non-time/memory-critical code and desperately want to copy a whole map element-by-element +// for whatever reason. +template +void DeepCopyMap(const CUtlMap &pmapIn, CUtlMap *out_pmapOut) +{ + Assert(out_pmapOut); + + out_pmapOut->Purge(); + FOR_EACH_MAP_FAST(pmapIn, i) + { + out_pmapOut->Insert(pmapIn.Key(i), pmapIn.Element(i)); + } +} diff --git a/rehlds/public/utlmemory.h b/rehlds/public/utlmemory.h index 8c61d1c..5f76e30 100644 --- a/rehlds/public/utlmemory.h +++ b/rehlds/public/utlmemory.h @@ -1,59 +1,90 @@ -//=========== (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: $ -// -// A growable memory class. -//============================================================================= +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ -#ifndef UTLMEMORY_H -#define UTLMEMORY_H - -#ifdef _WIN32 #pragma once -#endif #include "osconfig.h" #include "tier0/dbg.h" #include -#include "tier0/platform.h" #pragma warning (disable:4100) #pragma warning (disable:4514) -//----------------------------------------------------------------------------- // The CUtlMemory class: // A growable memory class which doubles in size by default. -//----------------------------------------------------------------------------- -template< class T > +template class CUtlMemory { public: // constructor, destructor CUtlMemory(int nGrowSize = 0, int nInitSize = 0); - CUtlMemory(T* pMemory, int numElements); + CUtlMemory(T *pMemory, int numElements); ~CUtlMemory(); + // Set the size by which the memory grows + void Init(int nGrowSize = 0, int nInitSize = 0); + + class Iterator_t + { + public: + Iterator_t(I i) : m_index(i) {} + I m_index; + + bool operator==(const Iterator_t it) const { return m_index == it.m_index; } + bool operator!=(const Iterator_t it) const { return m_index != it.m_index; } + }; + + Iterator_t First() const { return Iterator_t(IsIdxValid(0) ? 0 : InvalidIndex()); } + Iterator_t Next(const Iterator_t &it) const { return Iterator_t(IsIdxValid(it.index + 1) ? it.index + 1 : InvalidIndex()); } + I GetIndex(const Iterator_t &it) const { return it.index; } + bool IsIdxAfter(I i, const Iterator_t &it) const { return i > it.index; } + bool IsValidIterator(const Iterator_t &it) const { return IsIdxValid(it.index); } + Iterator_t InvalidIterator() const { return Iterator_t(InvalidIndex()); } + // element access - T& operator[](int i); - T const& operator[](int i) const; - T& Element(int i); - T const& Element(int i) const; + T& Element(I i); + T const& Element(I i) const; + T& operator[](I i); + T const& operator[](I i) const; // Can we use this index? - bool IsIdxValid(int i) const; + bool IsIdxValid(I i) const; + + // Specify the invalid ('null') index that we'll only return on failure + static const I INVALID_INDEX = (I)-1; // For use with COMPILE_TIME_ASSERT + static I InvalidIndex() { return INVALID_INDEX; } // Gets the base address (can change when adding elements!) - T* Base(); - T const* Base() const; + T *Base(); + T const *Base() const; // Attaches the buffer to external memory.... - void SetExternalBuffer(T* pMemory, int numElements); + void SetExternalBuffer(T *pMemory, int numElements); // Size int NumAllocated() const; @@ -80,46 +111,54 @@ private: EXTERNAL_BUFFER_MARKER = -1, }; - T* m_pMemory; + T *m_pMemory; int m_nAllocationCount; int m_nGrowSize; }; - -//----------------------------------------------------------------------------- // constructor, destructor -//----------------------------------------------------------------------------- -template< class T > -CUtlMemory::CUtlMemory(int nGrowSize, int nInitAllocationCount) : m_pMemory(0), -m_nAllocationCount(nInitAllocationCount), m_nGrowSize(nGrowSize) +template +CUtlMemory::CUtlMemory(int nGrowSize, int nInitSize) : m_pMemory(0), +m_nAllocationCount(nInitSize), m_nGrowSize(nGrowSize) { Assert((nGrowSize >= 0) && (nGrowSize != EXTERNAL_BUFFER_MARKER)); if (m_nAllocationCount) { - m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T)); + m_pMemory = (T *)malloc(m_nAllocationCount * sizeof(T)); } } -template< class T > -CUtlMemory::CUtlMemory(T* pMemory, int numElements) : m_pMemory(pMemory), +template +CUtlMemory::CUtlMemory(T *pMemory, int numElements) : m_pMemory(pMemory), m_nAllocationCount(numElements) { // Special marker indicating externally supplied memory m_nGrowSize = EXTERNAL_BUFFER_MARKER; } -template< class T > -CUtlMemory::~CUtlMemory() +template +CUtlMemory::~CUtlMemory() { Purge(); } +template +void CUtlMemory::Init(int nGrowSize, int nInitSize) +{ + Purge(); + + m_nGrowSize = nGrowSize; + m_nAllocationCount = nInitSize; + Assert(nGrowSize >= 0); + if (m_nAllocationCount) + { + m_pMemory = (T *)malloc(m_nAllocationCount * sizeof(T)); + } +} -//----------------------------------------------------------------------------- // Attaches the buffer to external memory.... -//----------------------------------------------------------------------------- -template< class T > -void CUtlMemory::SetExternalBuffer(T* pMemory, int numElements) +template +void CUtlMemory::SetExternalBuffer(T *pMemory, int numElements) { // Blow away any existing allocated memory Purge(); @@ -131,110 +170,91 @@ void CUtlMemory::SetExternalBuffer(T* pMemory, int numElements) m_nGrowSize = EXTERNAL_BUFFER_MARKER; } - -//----------------------------------------------------------------------------- // element access -//----------------------------------------------------------------------------- -template< class T > -inline T& CUtlMemory::operator[](int i) +template +inline T& CUtlMemory::operator[](I i) { Assert(IsIdxValid(i)); return m_pMemory[i]; } -template< class T > -inline T const& CUtlMemory::operator[](int i) const +template +inline T const& CUtlMemory::operator[](I i) const { Assert(IsIdxValid(i)); return m_pMemory[i]; } -template< class T > -inline T& CUtlMemory::Element(int i) +template +inline T& CUtlMemory::Element(I i) { Assert(IsIdxValid(i)); return m_pMemory[i]; } -template< class T > -inline T const& CUtlMemory::Element(int i) const +template +inline T const& CUtlMemory::Element(I i) const { Assert(IsIdxValid(i)); return m_pMemory[i]; } - -//----------------------------------------------------------------------------- // is the memory externally allocated? -//----------------------------------------------------------------------------- -template< class T > -bool CUtlMemory::IsExternallyAllocated() const +template +bool CUtlMemory::IsExternallyAllocated() const { return m_nGrowSize == EXTERNAL_BUFFER_MARKER; } - -template< class T > -void CUtlMemory::SetGrowSize(int nSize) +template +void CUtlMemory::SetGrowSize(int nSize) { Assert((nSize >= 0) && (nSize != EXTERNAL_BUFFER_MARKER)); m_nGrowSize = nSize; } - -//----------------------------------------------------------------------------- // Gets the base address (can change when adding elements!) -//----------------------------------------------------------------------------- -template< class T > -inline T* CUtlMemory::Base() +template +inline T *CUtlMemory::Base() { return m_pMemory; } -template< class T > -inline T const* CUtlMemory::Base() const +template +inline T const *CUtlMemory::Base() const { return m_pMemory; } - -//----------------------------------------------------------------------------- // Size -//----------------------------------------------------------------------------- -template< class T > -inline int CUtlMemory::NumAllocated() const +template +inline int CUtlMemory::NumAllocated() const { return m_nAllocationCount; } -template< class T > -inline int CUtlMemory::Count() const +template +inline int CUtlMemory::Count() const { return m_nAllocationCount; } - -//----------------------------------------------------------------------------- // Is element index valid? -//----------------------------------------------------------------------------- -template< class T > -inline bool CUtlMemory::IsIdxValid(int i) const +template +inline bool CUtlMemory::IsIdxValid(I i) const { - return (i >= 0) && (i < m_nAllocationCount); + return (((int)i) >= 0) && (((int) i) < m_nAllocationCount); } - -//----------------------------------------------------------------------------- // Grows the memory -//----------------------------------------------------------------------------- -template< class T > -void CUtlMemory::Grow(int num) +template +void CUtlMemory::Grow(int num) { Assert(num > 0); if (IsExternallyAllocated()) { - // Can't grow a buffer whose memory was externally allocated + // Can't grow a buffer whose memory was externally allocated Assert(0); return; } @@ -265,27 +285,24 @@ void CUtlMemory::Grow(int num) if (m_pMemory) { - m_pMemory = (T*)realloc(m_pMemory, m_nAllocationCount * sizeof(T)); + m_pMemory = (T *)realloc(m_pMemory, m_nAllocationCount * sizeof(T)); } else { - m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T)); + m_pMemory = (T *)malloc(m_nAllocationCount * sizeof(T)); } } - -//----------------------------------------------------------------------------- // Makes sure we've got at least this much memory -//----------------------------------------------------------------------------- -template< class T > -inline void CUtlMemory::EnsureCapacity(int num) +template +inline void CUtlMemory::EnsureCapacity(int num) { if (m_nAllocationCount >= num) return; if (IsExternallyAllocated()) { - // Can't grow a buffer whose memory was externally allocated + // Can't grow a buffer whose memory was externally allocated Assert(0); return; } @@ -293,31 +310,25 @@ inline void CUtlMemory::EnsureCapacity(int num) m_nAllocationCount = num; if (m_pMemory) { - m_pMemory = (T*)realloc(m_pMemory, m_nAllocationCount * sizeof(T)); + m_pMemory = (T *)realloc(m_pMemory, m_nAllocationCount * sizeof(T)); } else { - m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T)); + m_pMemory = (T *)malloc(m_nAllocationCount * sizeof(T)); } } - -//----------------------------------------------------------------------------- // Memory deallocation -//----------------------------------------------------------------------------- -template< class T > -void CUtlMemory::Purge() +template +void CUtlMemory::Purge() { if (!IsExternallyAllocated()) { if (m_pMemory) { - free((void*)m_pMemory); + free((void *)m_pMemory); m_pMemory = 0; } m_nAllocationCount = 0; } } - - -#endif // UTLSTORAGE_H diff --git a/rehlds/rehlds/precompiled.h b/rehlds/rehlds/precompiled.h index 5c19610..182cdee 100644 --- a/rehlds/rehlds/precompiled.h +++ b/rehlds/rehlds/precompiled.h @@ -16,19 +16,20 @@ #include "ed_strpool.h" #include "memory.h" +#include "strtools.h" // Hook stuff #include "hookers/engine/hooklist.h" +// Valve libs stuff +#include "tier0/platform.h" +#include "tier0/dbg.h" + #include "engine.h" #include "platform.h" #include "RehldsRuntimeConfig.h" #include "rehlds_debug.h" -// Valve libs stuff -#include "tier0/platform.h" -#include "tier0/dbg.h" - #include "interface.h" #include "iregistry.h"