diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 0000000..ec82c82
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,183 @@
+name: C/C++ CI
+
+on:
+ push:
+ branches: [master]
+ pull_request:
+ types: [opened, reopened, synchronize]
+ release:
+ types: [published]
+
+jobs:
+ windows:
+ name: 'Windows'
+ runs-on: windows-latest
+ env:
+ solution: 'msvc/ReHLDS.sln'
+ buildPlatform: 'Win32'
+ buildConfiguration: 'Release'
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v2
+ - name: Setup Nuget
+ uses: nuget/setup-nuget@v1
+ with:
+ nuget-api-key: ${{ secrets.NuGetAPIKey }}
+ nuget-version: '5.x'
+ - run: nuget restore '${{ env.solution }}'
+
+ - name: Setup MSBuild
+ uses: microsoft/setup-msbuild@v1.0.2
+ with:
+ vs-version: '16.8'
+
+ - name: Build ReHLDS
+ run:
+ msbuild ${{ env.solution }} /t:Clean,Build -p:Configuration="${{ env.buildConfiguration }}" /p:Platform=${{ env.buildPlatform }} /p:PlatformToolset=v140_xp /p:XPDeprecationWarning=false
+
+ - name: Move files
+ run: |
+ mkdir publish\debug
+ mkdir publish\bin\win32\valve\dlls
+ move msvc\${{ env.buildConfiguration }}\hlds.exe publish\bin\win32\hlds.exe
+ move msvc\${{ env.buildConfiguration }}\hltv.exe publish\bin\win32\hltv.exe
+ move msvc\${{ env.buildConfiguration }}\swds.dll publish\bin\win32\swds.dll
+ move msvc\${{ env.buildConfiguration }}\core.dll publish\bin\win32\core.dll
+ move msvc\${{ env.buildConfiguration }}\proxy.dll publish\bin\win32\proxy.dll
+ move msvc\${{ env.buildConfiguration }}\demoplayer.dll publish\bin\win32\demoplayer.dll
+ move msvc\${{ env.buildConfiguration }}\filesystem_stdio.dll publish\bin\win32\filesystem_stdio.dll
+ move msvc\${{ env.buildConfiguration }}\director.dll publish\bin\win32\valve\dlls\director.dll
+ move msvc\${{ env.buildConfiguration }}\hlds.pdb publish\debug\hlds.pdb
+ move msvc\${{ env.buildConfiguration }}\hltv.pdb publish\debug\hltv.pdb
+ move msvc\${{ env.buildConfiguration }}\swds.pdb publish\debug\swds.pdb
+ move msvc\${{ env.buildConfiguration }}\core.pdb publish\debug\core.pdb
+ move msvc\${{ env.buildConfiguration }}\proxy.pdb publish\debug\proxy.pdb
+ move msvc\${{ env.buildConfiguration }}\demoplayer.pdb publish\debug\demoplayer.pdb
+ move msvc\${{ env.buildConfiguration }}\filesystem_stdio.pdb publish\debug\filesystem_stdio.pdb
+ move msvc\${{ env.buildConfiguration }}\director.pdb publish\debug\director.pdb
+
+ - name: Deploy artifacts
+ uses: actions/upload-artifact@v2
+ with:
+ name: win32
+ path: publish/*
+
+ linux:
+ name: 'Linux'
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+
+ - name: Check dependencies
+ run: |
+ sudo dpkg --add-architecture i386
+ sudo apt-get update
+ sudo apt-get install -y gcc-multilib g++-multilib
+ sudo apt-get install -y build-essential
+ sudo apt-get install -y libc6-dev libc6-dev-i386
+ sudo apt-get install -y p7zip-full
+
+ - name: Build
+ run: |
+ mkdir build
+ cd build
+ cmake ../
+ make
+
+ - name: Prepare HLSDK
+ run: |
+ mkdir -p publish/hlsdk
+ rsync -a rehlds/common/ publish/hlsdk/common/
+ rsync -a rehlds/dlls/ publish/hlsdk/dlls/
+ rsync -a rehlds/pm_shared/ publish/hlsdk/pm_shared/
+ rsync -a rehlds/public/ publish/hlsdk/public/ --exclude rehlds/
+ rsync -a rehlds/public/rehlds/ publish/hlsdk/engine
+
+ - name: Move files
+ run: |
+ mkdir -p publish/bin/linux32/valve/dlls
+ mv build/rehlds/engine_i486.so publish/bin/linux32/engine_i486.so
+ mv rehlds/version/appversion.h publish/appversion.h
+ mv build/rehlds/dedicated/hlds_linux publish/bin/linux32/hlds_linux
+ mv build/rehlds/HLTV/Console/hltv publish/bin/linux32/hltv
+ mv build/rehlds/HLTV/Core/core.so publish/bin/linux32/core.so
+ mv build/rehlds/HLTV/Proxy/proxy.so publish/bin/linux32/proxy.so
+ mv build/rehlds/HLTV/DemoPlayer/demoplayer.so publish/bin/linux32/demoplayer.so
+ mv build/rehlds/HLTV/Director/director.so publish/bin/linux32/valve/dlls/director.so
+ mv build/rehlds/filesystem/FileSystem_Stdio/filesystem_stdio.so publish/bin/linux32/filesystem_stdio.so
+
+ - name: Deploy artifacts
+ uses: actions/upload-artifact@v2
+ id: upload-job
+ with:
+ name: linux32
+ path: publish/*
+
+ - name: Cleanup temporary artifacts
+ if: success() && steps.upload-job.outcome == 'success'
+ run: |
+ rm -rf hlsdk
+ rm -f appversion.h
+
+ publish:
+ needs: [windows, linux]
+ name: 'Publish'
+ runs-on: ubuntu-latest
+ steps:
+ - name: Deploying linux artifacts
+ uses: actions/download-artifact@v2
+ with:
+ name: linux32
+
+ - name: Deploying windows artifacts
+ uses: actions/download-artifact@v2
+ with:
+ name: win32
+
+ - name: Reading appversion.h
+ run: |
+ if [ -e appversion.h ]; then
+ APP_VERSION=$(cat appversion.h | grep -wi '#define APP_VERSION_STRD' | sed -e 's/#define APP_VERSION_STRD[ \t\r\n\v\f]\+\(.*\)/\1/i' -e 's/\r//g')
+ if [ $? -ne 0 ]; then
+ APP_VERSION=""
+ else
+ # Remove quotes
+ APP_VERSION=$(echo $APP_VERSION | xargs)
+ echo "APP_VERSION=${APP_VERSION}" >> $GITHUB_ENV
+ fi
+ fi
+ rm -f appversion.h
+
+ - name: Packaging bin/dbg
+ id: packaging-job
+ if: |
+ github.event_name == 'release' &&
+ github.event.action == 'published' &&
+ startsWith(github.ref, 'refs/tags/')
+ run: |
+ 7z a -tzip rehlds-bin-${{ env.APP_VERSION }}.zip bin/ hlsdk/
+ 7z a -t7z -m0=lzma2 -mx=9 -mfb=64 -aoa rehlds-dbg-${{ env.APP_VERSION }}.7z debug/
+
+ - name: Publish artifacts
+ uses: softprops/action-gh-release@v1
+ id: publish-job
+ if: |
+ startsWith(github.ref, 'refs/tags/') &&
+ steps.packaging-job.outcome == 'success'
+ with:
+ files: |
+ *.zip
+ *.7z
+ env:
+ GITHUB_TOKEN: ${{ secrets.API_TOKEN }}
+
+ - name: Cleanup temporary artifacts
+ if: success() && steps.publish-job.outcome == 'success'
+ run: |
+ rm -rf bin debug hlsdk
+ rm -f *.7z *.zip appversion.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..2046105
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,11 @@
+cmake_minimum_required(VERSION 3.1)
+project(rehlds CXX)
+
+if (WIN32)
+ message(FATAL_ERROR "CMakeLists.txt Windows platform isn't supported yet. Use msvc/ReHLDS.sln instead it!")
+endif()
+
+add_subdirectory(rehlds)
+add_subdirectory(rehlds/dedicated)
+add_subdirectory(rehlds/filesystem)
+add_subdirectory(rehlds/HLTV)
diff --git a/README.md b/README.md
index 0a1e3d7..b2a1e90 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,4 @@
-# Rehlds [![Build Status](http://teamcity.rehlds.org/app/rest/builds/buildType:(id:Rehlds_Publish)/statusIcon)](http://teamcity.rehlds.org/viewType.html?buildTypeId=Rehlds_Publish&guest=1) [![Download](https://camo.githubusercontent.com/65c70643ec7b40eea50971003624c2fb04d8d375/687474703a2f2f7265686c64732e6f72672f76657273696f6e2f7265686c64732e737667)](http://teamcity.rehlds.org/guestAuth/downloadArtifacts.html?buildTypeId=Rehlds_Publish&buildId=lastSuccessful)
-
+# ReHLDS [![C/C++ CI](https://github.com/dreamstalker/rehlds/actions/workflows/build.yml/badge.svg)](https://github.com/dreamstalker/rehlds/actions/workflows/build.yml) [![Download](https://camo.githubusercontent.com/7ab483250adb4037b26e9575331218ee51108190d0938b7836d32f1209ccf907/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f647265616d7374616c6b65722f7265686c64732e737667)](https://github.com/dreamstalker/rehlds/releases/latest) [![Downloads](https://camo.githubusercontent.com/d37654956d99bb9fb7a348fdac39b214d6ae14a7cfb9f96bf873c6b46cdf9ef6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f646f776e6c6f6164732f647265616d7374616c6b65722f7265686c64732f746f74616c3f636f6c6f723d696d706f7274616e74)]() [![Percentage of issues still open](http://isitmaintained.com/badge/open/dreamstalker/rehlds.svg)](http://isitmaintained.com/project/dreamstalker/rehlds "Percentage of issues still open") [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
Reverse-engineered (and bugfixed) HLDS
## What is this?
@@ -7,7 +6,7 @@ ReHLDS is a result of reverse engineering of original HLDS (build 6152/6153) usi
Along with reverse engineering, a lot of defects and (potential) bugs were found and fixed
-You can try play on one of the servers that using rehlds: http://www.gametracker.com/search/?search_by=server_variable&search_by2=sv_version
+You can try play on one of the servers that using rehlds: [Game Tracker](http://www.gametracker.com/search/?search_by=server_variable&search_by2=sv_version)
## Goals of the project
@@ -19,7 +18,7 @@ You can try play on one of the servers that using rehlds: http://www.gametracker
Rehlds is fully compatible with latest official HLDS downloaded by steamcmd. All you have to do is to download rehlds binaries and replace original swds.dll/engine_i486.so. For windows you can also copy a swds.pdb file with a debug information.
Warning! Rehlds is not compatible with an old 5xxx or below platforms downloaded by hldsupdatetool.
-Compiled binaries are available here: http://nexus.rehlds.org/nexus/content/repositories/rehlds-dev/rehlds/rehlds/
+Compiled binaries are available here: [Artifact releases](https://github.com/dreamstalker/rehlds/releases)
Rehlds binaries require SSE, SSE2 and SSE3 instruction sets to run and can benefit from SSE4.1 and SSE4.2.
diff --git a/dep/bzip2/CMakeLists.txt b/dep/bzip2/CMakeLists.txt
new file mode 100644
index 0000000..74f4b99
--- /dev/null
+++ b/dep/bzip2/CMakeLists.txt
@@ -0,0 +1,21 @@
+cmake_minimum_required(VERSION 3.1)
+project(bzip2 C)
+
+set(BZIP2_SRCS
+ "src/blocksort.c"
+ "src/bzlib.c"
+ "src/compress.c"
+ "src/crctable.c"
+ "src/decompress.c"
+ "src/huffman.c"
+ "src/precompiled.c"
+ "src/randtable.c"
+ "src/bzlib_private.h"
+)
+
+include_directories(
+ "include"
+)
+
+add_library(bzip2 STATIC ${BZIP2_SRCS})
+set_target_properties(bzip2 PROPERTIES COMPILE_FLAGS "-m32" POSITION_INDEPENDENT_CODE ON)
diff --git a/dep/bzip2/msvc/bzip2.vcxproj b/dep/bzip2/msvc/bzip2.vcxproj
index 55fab7d..d11db95 100644
--- a/dep/bzip2/msvc/bzip2.vcxproj
+++ b/dep/bzip2/msvc/bzip2.vcxproj
@@ -5,10 +5,6 @@
Debug
Win32
-
- Release Swds
- Win32
-
Release
Win32
@@ -39,16 +35,6 @@
true
Unicode
-
- StaticLibrary
- false
- v120
- v140
- v141
- v142
- true
- Unicode
-
@@ -58,9 +44,6 @@
-
-
-
@@ -97,25 +80,6 @@
true
-
-
- Level3
- Use
- MaxSpeed
- true
- true
- _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)
- $(ProjectDir)..\include\
- MultiThreaded
- bzlib_private.h
-
-
- Windows
- true
- true
- true
-
-
@@ -129,7 +93,6 @@
Create
Create
- Create
diff --git a/dep/cppunitlite/msvc/cppunitlite.vcxproj b/dep/cppunitlite/msvc/cppunitlite.vcxproj
index b44933d..09143e8 100644
--- a/dep/cppunitlite/msvc/cppunitlite.vcxproj
+++ b/dep/cppunitlite/msvc/cppunitlite.vcxproj
@@ -5,10 +5,6 @@
Debug
Win32
-
- Release Swds
- Win32
-
Release
Win32
@@ -55,16 +51,6 @@
true
MultiByte
-
- StaticLibrary
- false
- v120
- v140
- v141
- v142
- true
- MultiByte
-
@@ -74,9 +60,6 @@
-
-
-
@@ -115,26 +98,6 @@
true
-
-
- Level3
-
-
- MaxSpeed
- true
- true
- WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_LIB;%(PreprocessorDefinitions)
- MultiThreaded
- $(ProjectDir)..\include\
- false
-
-
- Windows
- true
- true
- true
-
-
diff --git a/rehlds/CMakeLists.txt b/rehlds/CMakeLists.txt
new file mode 100644
index 0000000..16543a9
--- /dev/null
+++ b/rehlds/CMakeLists.txt
@@ -0,0 +1,148 @@
+cmake_minimum_required(VERSION 3.1)
+project(engine CXX)
+
+option(DEBUG "Build with debug information." OFF)
+option(USE_INTEL_COMPILER "Use the Intel compiler." OFF)
+option(USE_CLANG_COMPILER "Use the Clang compiler." OFF)
+option(USE_STATIC_LIBSTDC "Enables static linking libstdc++." OFF)
+
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+if (USE_INTEL_COMPILER)
+ set(CMAKE_C_COMPILER "/opt/intel/bin/icc")
+ set(CMAKE_CXX_COMPILER "/opt/intel/bin/icpc")
+elseif (USE_CLANG_COMPILER)
+ set(CMAKE_C_COMPILER "/usr/bin/clang")
+ set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
+endif()
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-rtti -fno-exceptions")
+
+# Remove noxref code and data
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections")
+
+if (DEBUG)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O3 -ggdb")
+else()
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O3")
+endif()
+
+if (USE_INTEL_COMPILER)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp")
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel -no-intel-extensions")
+
+ if (NOT DEBUG)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ipo")
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_CXX_FLAGS} -ipo")
+ endif()
+else()
+ # 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.
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=generic -msse3\
+ -fpermissive\
+ -Wno-unknown-pragmas -Wno-invalid-offsetof\
+ -Wno-unused-variable -Wno-unused-result -Wno-unused-function -Wno-delete-non-virtual-dtor\
+ -Wno-write-strings -Wno-format\
+ -Wno-sign-compare -Wno-strict-aliasing -Wno-ignored-attributes")
+
+ if (NOT USE_CLANG_COMPILER)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-stringop-truncation -Wno-format-truncation -Wno-unused-but-set-variable -Wno-class-memaccess")
+ endif()
+endif()
+
+if (NOT DEBUG AND USE_STATIC_LIBSTDC)
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-gc-sections -Wl,--version-script=\"${PROJECT_SOURCE_DIR}/../version_script.lds\"")
+endif()
+
+if (USE_STATIC_LIBSTDC)
+ add_definitions(-DBUILD_STATIC_LIBSTDC)
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc -static-libstdc++")
+endif()
+
+set(PROJECT_SRC_DIR
+ "${PROJECT_SOURCE_DIR}"
+ "${PROJECT_SOURCE_DIR}/engine"
+ "${PROJECT_SOURCE_DIR}/common"
+ "${PROJECT_SOURCE_DIR}/pm_shared"
+ "${PROJECT_SOURCE_DIR}/rehlds"
+ "${PROJECT_SOURCE_DIR}/testsuite"
+)
+
+set(PROJECT_BZIP2_DIR
+ "${PROJECT_SOURCE_DIR}/../dep/bzip2/include"
+)
+
+set(PROJECT_PUBLIC_DIR
+ "${PROJECT_SOURCE_DIR}/public"
+ "${PROJECT_SOURCE_DIR}/public/rehlds"
+)
+
+file(GLOB ENGINE_SRCS
+ "engine/*.cpp"
+ "rehlds/*.cpp"
+ "version/*.cpp"
+)
+
+list(REMOVE_ITEM ENGINE_SRCS EXCLUDE
+ "${PROJECT_SOURCE_DIR}/rehlds/precompiled.cpp"
+ "${PROJECT_SOURCE_DIR}/rehlds/RehldsRuntimeConfig.cpp"
+ "${PROJECT_SOURCE_DIR}/rehlds/structSizeCheck.cpp"
+)
+
+file(GLOB COMMON_SRCS
+ "common/BaseSystemModule.cpp"
+ "common/ObjectList.cpp"
+ "common/TokenLine.cpp"
+)
+
+file(GLOB PUBLIC_SRCS
+ "public/tier0/dbg.cpp"
+ "public/registry.cpp"
+ "public/steamid.cpp"
+ "public/utlbuffer.cpp"
+)
+
+include_directories(
+ ${PROJECT_SRC_DIR}
+ ${PROJECT_BZIP2_DIR}
+ ${PROJECT_PUBLIC_DIR}
+)
+
+link_directories(${PROJECT_SOURCE_DIR}/lib/linux32)
+
+add_definitions(
+ -DSWDS
+ -DREHLDS_JIT
+ -DREHLDS_SSE
+ -DREHLDS_FIXES
+ -DREHLDS_CHECKS
+ -DREHLDS_API
+ -DREHLDS_SELF
+ -DREHLDS_OPT_PEDANTIC
+ -DHAVE_OPT_STRTOOLS
+ -DUSE_BREAKPAD_HANDLER
+ -D_LINUX
+ -DLINUX
+ -D_GLIBCXX_USE_CXX11_ABI=0
+ -D_stricmp=strcasecmp
+ -D_strnicmp=strncasecmp
+ -D_strdup=strdup
+ -D_unlink=unlink
+ -D_vsnprintf=vsnprintf
+ -D_vsnwprintf=vswprintf
+)
+
+if (NOT TARGET bzip2)
+ add_subdirectory(../dep/bzip2 lib)
+endif()
+
+if (NOT TARGET appversion)
+ add_custom_target(appversion DEPENDS COMMAND "${PROJECT_SOURCE_DIR}/version/appversion.sh" "${PROJECT_SOURCE_DIR}")
+endif()
+
+add_library(engine SHARED ${appversion.sh} ${ENGINE_SRCS} ${COMMON_SRCS} ${PUBLIC_SRCS})
+set_property(TARGET engine PROPERTY LIBRARY_OUTPUT_NAME engine_i486)
+set_target_properties(engine PROPERTIES PREFIX "" COMPILE_FLAGS "-m32" LINK_FLAGS "-m32" POSITION_INDEPENDENT_CODE ON)
+target_link_libraries(engine dl rt m aelf32 bzip2 steam_api)
+add_dependencies(engine appversion)
diff --git a/rehlds/HLTV/CMakeLists.txt b/rehlds/HLTV/CMakeLists.txt
new file mode 100644
index 0000000..abfaf71
--- /dev/null
+++ b/rehlds/HLTV/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.1)
+project(HLTV CXX)
+
+add_subdirectory(Console)
+add_subdirectory(Core)
+add_subdirectory(Proxy)
+add_subdirectory(DemoPlayer)
+add_subdirectory(Director)
diff --git a/rehlds/HLTV/Console/CMakeLists.txt b/rehlds/HLTV/Console/CMakeLists.txt
new file mode 100644
index 0000000..2d85a32
--- /dev/null
+++ b/rehlds/HLTV/Console/CMakeLists.txt
@@ -0,0 +1,100 @@
+cmake_minimum_required(VERSION 3.1)
+project(hltv CXX)
+
+option(DEBUG "Build with debug information." OFF)
+option(USE_INTEL_COMPILER "Use the Intel compiler." OFF)
+option(USE_CLANG_COMPILER "Use the Clang compiler." OFF)
+
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+if (USE_INTEL_COMPILER)
+ set(CMAKE_C_COMPILER "/opt/intel/bin/icc")
+ set(CMAKE_CXX_COMPILER "/opt/intel/bin/icpc")
+elseif (USE_CLANG_COMPILER)
+ set(CMAKE_C_COMPILER "/usr/bin/clang")
+ set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
+endif()
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions")
+
+if (DEBUG)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O3 -ggdb")
+else()
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O3")
+endif()
+
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -no-pie")
+
+if (USE_INTEL_COMPILER)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp")
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-intel -no-intel-extensions")
+
+ if (NOT DEBUG)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ipo")
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_CXX_FLAGS} -ipo")
+ endif()
+else()
+ # 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.
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=generic -msse3 -flto\
+ -fpermissive\
+ -Wno-unused-result -Wno-unknown-pragmas -Wno-write-strings")
+endif()
+
+set(PROJECT_SRC_DIR
+ "${PROJECT_SOURCE_DIR}/src"
+ "${PROJECT_SOURCE_DIR}/../"
+)
+
+set(PROJECT_PUBLIC_DIR
+ "${PROJECT_SOURCE_DIR}/../.."
+ "${PROJECT_SOURCE_DIR}/../../engine"
+ "${PROJECT_SOURCE_DIR}/../../common"
+ "${PROJECT_SOURCE_DIR}/../../public"
+ "${PROJECT_SOURCE_DIR}/../../public/rehlds"
+)
+
+set(HLTV_SRCS
+ "src/System.cpp"
+ "src/public_amalgamation.cpp"
+)
+
+set(COMMON_SRCS
+ "../../common/BaseSystemModule.cpp"
+ "../../common/TokenLine.cpp"
+ "../../common/ObjectList.cpp"
+ "../../common/textconsole.cpp"
+ "../../common/TextConsoleUnix.cpp"
+ "../../common/minidump.cpp"
+ "../../HLTV/common/random.cpp"
+ "../../HLTV/common/common.cpp"
+ "../../engine/mem.cpp"
+)
+
+include_directories(
+ ${PROJECT_SRC_DIR}
+ ${PROJECT_PUBLIC_DIR}
+)
+
+add_definitions(
+ -DLAUNCHER_FIXES
+ -D_CONSOLE
+ -D_LINUX
+ -DLINUX
+ -D_GLIBCXX_USE_CXX11_ABI=0
+ -D_stricmp=strcasecmp
+ -D_strnicmp=strncasecmp
+ -D_strdup=strdup
+ -D_vsnprintf=vsnprintf
+ -D_snprintf=snprintf
+)
+
+if (NOT TARGET appversion)
+ add_custom_target(appversion DEPENDS COMMAND "${PROJECT_SOURCE_DIR}/../../version/appversion.sh" "${PROJECT_SOURCE_DIR}/../..")
+endif()
+
+add_executable(hltv ${appversion.sh} ${HLTV_SRCS} ${COMMON_SRCS})
+target_link_libraries(hltv dl)
+set_target_properties(hltv PROPERTIES PREFIX "" COMPILE_FLAGS "-m32" LINK_FLAGS "-m32" POSITION_INDEPENDENT_CODE ON)
+add_dependencies(hltv appversion)
diff --git a/rehlds/HLTV/Console/msvc/Console.vcxproj b/rehlds/HLTV/Console/msvc/Console.vcxproj
index cdeb0e3..3ecc3b6 100644
--- a/rehlds/HLTV/Console/msvc/Console.vcxproj
+++ b/rehlds/HLTV/Console/msvc/Console.vcxproj
@@ -5,10 +5,6 @@
Debug
Win32
-
- Release Swds
- Win32
-
Release
Win32
@@ -34,62 +30,50 @@
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
@@ -125,16 +109,6 @@
true
MultiByte
-
- Application
- false
- v120_xp
- v140_xp
- v141_xp
- v142
- true
- MultiByte
-
@@ -146,9 +120,6 @@
-
-
-
true
@@ -158,10 +129,6 @@
false
hltv
-
- false
- hltv
-
Use
@@ -190,6 +157,10 @@
build.always.run
build.always.run
+
+ IF EXIST "$(ProjectDir)PreBuild.bat" (CALL "$(ProjectDir)PreBuild.bat" "$(ProjectDir)..\..\..\version\" "$(ProjectDir)..\..\..\")
+ Setup version from Git revision
+
@@ -222,38 +193,10 @@
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
-
+
+ IF EXIST "$(ProjectDir)PreBuild.bat" (CALL "$(ProjectDir)PreBuild.bat" "$(ProjectDir)..\..\..\version\" "$(ProjectDir)..\..\..\")
+ Setup version from Git revision
+
diff --git a/rehlds/HLTV/Console/msvc/PreBuild.bat b/rehlds/HLTV/Console/msvc/PreBuild.bat
new file mode 100644
index 0000000..c9f7989
--- /dev/null
+++ b/rehlds/HLTV/Console/msvc/PreBuild.bat
@@ -0,0 +1,220 @@
+@setlocal enableextensions enabledelayedexpansion
+@echo on
+::
+:: Pre-build auto-versioning script
+::
+
+set srcdir=%~1
+set repodir=%~2
+
+set old_version=
+set version_major=0
+set version_minor=0
+set version_maintenance=0
+set version_modifed=
+
+set commitSHA=
+set commitURL=
+set commitCount=0
+set branch_name=master
+
+for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set "dt=%%a"
+set "YYYY=%dt:~0,4%"
+set "MM=%dt:~4,2%"
+set "DD=%dt:~6,2%"
+set "hour=%dt:~8,2%"
+set "min=%dt:~10,2%"
+set "sec=%dt:~12,2%"
+
+::
+:: Remove leading zero from MM (e.g 09 > 9)
+::
+for /f "tokens=* delims=0" %%I in ("%MM%") do set MM=%%I
+
+::
+:: Index into array to get month name
+::
+for /f "tokens=%MM%" %%I in ("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec") do set "month=%%I"
+
+::
+:: Check for git.exe presence
+::
+CALL git.exe describe >NUL 2>&1
+set errlvl="%ERRORLEVEL%"
+
+::
+:: Read old appversion.h, if present
+::
+IF EXIST "%srcdir%\appversion.h" (
+ FOR /F "usebackq tokens=1,2,3" %%i in ("%srcdir%\appversion.h") do (
+ IF %%i==#define (
+ IF %%j==APP_VERSION (
+ :: Remove quotes
+ set v=%%k
+ set old_version=!v:"=!
+ )
+ )
+ )
+)
+
+IF %errlvl% == "1" (
+ echo can't locate git.exe - auto-versioning step won't be performed
+
+ :: if we haven't appversion.h, we need to create it
+ IF NOT "%old_version%" == "" (
+ set commitCount=0
+ )
+)
+
+::
+:: Read major, minor and maintenance version components from Version.h
+::
+IF EXIST "%srcdir%\version.h" (
+ FOR /F "usebackq tokens=1,2,3" %%i in ("%srcdir%\version.h") do (
+ IF %%i==#define (
+ IF %%j==VERSION_MAJOR set version_major=%%k
+ IF %%j==VERSION_MINOR set version_minor=%%k
+ IF %%j==VERSION_MAINTENANCE set version_maintenance=%%k
+ )
+ )
+) ELSE (
+ FOR /F "usebackq tokens=1,2,3,* delims==" %%i in ("%repodir%..\gradle.properties") do (
+ IF NOT [%%j] == [] (
+ IF %%i==majorVersion set version_major=%%j
+ IF %%i==minorVersion set version_minor=%%j
+ IF %%i==maintenanceVersion set version_maintenance=%%j
+ )
+ )
+)
+
+::
+:: Read revision and release date from it
+::
+IF NOT %errlvl% == "1" (
+ :: Get current branch
+ FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-parse --abbrev-ref HEAD"') DO (
+ set branch_name=%%i
+ )
+
+ FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-list --count !branch_name!"') DO (
+ IF NOT [%%i] == [] (
+ set commitCount=%%i
+ )
+ )
+)
+
+::
+:: Get remote url repository
+::
+IF NOT %errlvl% == "1" (
+
+ set branch_remote=origin
+ :: Get remote name by current branch
+ FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." config branch.!branch_name!.remote"') DO (
+ set branch_remote=%%i
+ )
+ :: Get remote url
+ FOR /F "tokens=2 delims=@" %%i IN ('"git -C "%repodir%\." config remote.!branch_remote!.url"') DO (
+ set commitURL=%%i
+ )
+ :: Get commit id
+ FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-parse --verify HEAD"') DO (
+ set shafull=%%i
+ set commitSHA=!shafull:~0,+7!
+ )
+
+ IF [!commitURL!] == [] (
+
+ FOR /F "tokens=1" %%i IN ('"git -C "%repodir%\." config remote.!branch_remote!.url"') DO (
+ set commitURL=%%i
+ )
+
+ :: strip .git
+ if "x!commitURL:~-4!"=="x.git" (
+ set commitURL=!commitURL:~0,-4!
+ )
+
+ :: append extra string
+ If NOT "!commitURL!"=="!commitURL:bitbucket.org=!" (
+ set commitURL=!commitURL!/commits/
+ ) ELSE (
+ set commitURL=!commitURL!/commit/
+ )
+
+ ) ELSE (
+ :: strip .git
+ if "x!commitURL:~-4!"=="x.git" (
+ set commitURL=!commitURL:~0,-4!
+ )
+ :: replace : to /
+ set commitURL=!commitURL::=/!
+
+ :: append extra string
+ If NOT "!commitURL!"=="!commitURL:bitbucket.org=!" (
+ set commitURL=https://!commitURL!/commits/
+ ) ELSE (
+ set commitURL=https://!commitURL!/commit/
+ )
+ )
+)
+
+::
+:: Detect local modifications
+::
+set localChanged=0
+IF NOT %errlvl% == "1" (
+ FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." ls-files -m"') DO (
+ set localChanged=1
+ )
+)
+
+IF [%localChanged%]==[1] (
+ set version_modifed=+m
+)
+
+::
+:: Now form full version string like 1.0.0.1
+::
+
+set new_version=%version_major%.%version_minor%.%version_maintenance%.%commitCount%-dev%version_modifed%
+
+::
+:: Update appversion.h if version has changed or modifications/mixed revisions detected
+::
+IF NOT "%new_version%"=="%old_version%" goto _update
+goto _exit
+
+:_update
+echo Updating appversion.h, new version is "%new_version%", the old one was %old_version%
+
+echo #ifndef __APPVERSION_H__>"%srcdir%\appversion.h"
+echo #define __APPVERSION_H__>>"%srcdir%\appversion.h"
+echo.>>"%srcdir%\appversion.h"
+echo // >>"%srcdir%\appversion.h"
+echo // This file is generated automatically.>>"%srcdir%\appversion.h"
+echo // Don't edit it.>>"%srcdir%\appversion.h"
+echo // >>"%srcdir%\appversion.h"
+echo.>>"%srcdir%\appversion.h"
+echo // Version defines>>"%srcdir%\appversion.h"
+echo #define APP_VERSION "%new_version%">>"%srcdir%\appversion.h"
+
+echo.>>"%srcdir%\appversion.h"
+echo #define APP_COMMIT_DATE "%month% %DD% %YYYY%">>"%srcdir%\appversion.h"
+echo #define APP_COMMIT_TIME "%hour%:%min%:%sec%">>"%srcdir%\appversion.h"
+
+echo.>>"%srcdir%\appversion.h"
+echo #define APP_COMMIT_SHA "%commitSHA%">>"%srcdir%\appversion.h"
+echo #define APP_COMMIT_URL "%commitURL%">>"%srcdir%\appversion.h"
+echo.>>"%srcdir%\appversion.h"
+
+echo #endif //__APPVERSION_H__>>"%srcdir%\appversion.h"
+echo.>>"%srcdir%\appversion.h"
+
+::
+:: Do update of version.cpp file last modify time to force it recompile
+::
+copy /b "%srcdir%\version.cpp"+,, "%srcdir%\version.cpp"
+endlocal
+
+:_exit
+exit /B 0
diff --git a/rehlds/HLTV/Console/src/System.cpp b/rehlds/HLTV/Console/src/System.cpp
index 54db254..982d292 100644
--- a/rehlds/HLTV/Console/src/System.cpp
+++ b/rehlds/HLTV/Console/src/System.cpp
@@ -48,7 +48,7 @@ char *System::GetBaseDir()
return COM_GetBaseDir();
}
-void Sys_Printf(char *fmt, ...)
+void Sys_Printf(const char *fmt, ...)
{
// Dump text to debugging console.
va_list argptr;
@@ -151,49 +151,56 @@ bool System::RegisterCommand(char *name, ISystemModule *module, int commandID)
return true;
}
-void System::ExecuteString(char *commands)
+void System::ExecuteString(const char *commands)
{
if (!commands || !commands[0])
return;
- int size = 0;
- char singleCmd[256] = "";
- bool quotes = false;
- char *p = singleCmd;
- char *c = commands;
+ // Remove format characters to block format string attacks
+ COM_RemoveEvilChars(const_cast(commands));
- COM_RemoveEvilChars(c);
- while (true)
+ bool bInQuote = false;
+
+ char *pszDest;
+ char singleCmd[256] = {0};
+
+ const char *pszSource = commands;
+ while (*pszSource)
{
- *p = *c;
+ // Parse out single commands and execute them
+ pszDest = singleCmd;
- if (++size >= sizeof(singleCmd))
+ unsigned int i;
+ for (i = 0; i < ARRAYSIZE(singleCmd); i++)
{
- DPrintf("WARNING! System::ExecuteString: Command token too long.\n");
- break;
+ char c = *pszSource++;
+
+ *pszDest++ = c;
+
+ if (c == '"')
+ {
+ bInQuote = !bInQuote;
+ }
+ else if (c == ';' && !bInQuote)
+ {
+ // End of command and not in a quoted string
+ break;
+ }
}
- if (*c == '"')
- quotes = !quotes;
-
- if ((*c != ';' || quotes) && *c)
+ if (i >= ARRAYSIZE(singleCmd))
{
- ++p;
- }
- else
- {
- *p = '\0';
-
- char *cmd = singleCmd;
- while (*cmd == ' ') { cmd++; }
-
- DispatchCommand(cmd);
- p = singleCmd;
- size = 0;
+ Printf("WARNING! System::ExecuteString: Command token too long.\n");
+ return;
}
- if (!*c++)
- break;
+ *pszDest = '\0';
+
+ char *pszCmd = singleCmd;
+ while (*pszCmd == ' ')
+ pszCmd++; // skip leading whitespaces
+
+ DispatchCommand(pszCmd);
}
}
@@ -887,7 +894,7 @@ void System::UpdateTime()
m_SystemTime = m_Counter.GetCurTime();
}
-char *System::GetInput()
+const char *System::GetInput()
{
return m_Console.GetLine();
}
diff --git a/rehlds/HLTV/Console/src/System.h b/rehlds/HLTV/Console/src/System.h
index 7d3c560..01ab9e3 100644
--- a/rehlds/HLTV/Console/src/System.h
+++ b/rehlds/HLTV/Console/src/System.h
@@ -57,7 +57,7 @@ public:
Panel *GetPanel();
bool RegisterCommand(char *name, ISystemModule *module, int commandID);
void GetCommandMatches(char *string, ObjectList *pMatchList);
- void ExecuteString(char *commands);
+ void ExecuteString(const char *commands);
void ExecuteFile(char *filename);
void Errorf(char *fmt, ...);
char *CheckParam(char *param);
@@ -102,7 +102,7 @@ protected:
bool DispatchCommand(char *command);
void ExecuteCommandLine();
void UpdateTime();
- char *GetInput();
+ const char *GetInput();
bool StartVGUI();
void StopVGUI();
void SetName(char *newName);
@@ -183,4 +183,4 @@ private:
extern System gSystem;
-void Sys_Printf(char *fmt, ...);
+void Sys_Printf(const char *fmt, ...);
diff --git a/rehlds/HLTV/Core/CMakeLists.txt b/rehlds/HLTV/Core/CMakeLists.txt
new file mode 100644
index 0000000..032b673
--- /dev/null
+++ b/rehlds/HLTV/Core/CMakeLists.txt
@@ -0,0 +1,121 @@
+cmake_minimum_required(VERSION 3.1)
+project(core CXX)
+
+option(DEBUG "Build with debug information." OFF)
+option(USE_INTEL_COMPILER "Use the Intel compiler." OFF)
+option(USE_CLANG_COMPILER "Use the Clang compiler." OFF)
+
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+if (USE_INTEL_COMPILER)
+ set(CMAKE_C_COMPILER "/opt/intel/bin/icc")
+ set(CMAKE_CXX_COMPILER "/opt/intel/bin/icpc")
+elseif (USE_CLANG_COMPILER)
+ set(CMAKE_C_COMPILER "/usr/bin/clang")
+ set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
+endif()
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions")
+
+if (DEBUG)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O3 -ggdb")
+else()
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O3")
+endif()
+
+if (USE_INTEL_COMPILER)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp")
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel -no-intel-extensions")
+
+ if (NOT DEBUG)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ipo")
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_CXX_FLAGS} -ipo")
+ endif()
+else()
+ # 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.
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=generic -msse3 -flto\
+ -fpermissive\
+ -Wno-unused-result -Wno-unknown-pragmas -Wno-unused-variable\
+ -Wno-sign-compare -Wno-write-strings -Wno-strict-aliasing")
+
+ if (USE_CLANG_COMPILER)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-private-field")
+ endif()
+endif()
+
+set(PROJECT_SRC_DIR
+ "${PROJECT_SOURCE_DIR}/src"
+ "${PROJECT_SOURCE_DIR}/../"
+)
+
+set(PROJECT_BZIP2_DIR
+ "${PROJECT_SOURCE_DIR}/../../../dep/bzip2/include"
+)
+
+set(PROJECT_PUBLIC_DIR
+ "${PROJECT_SOURCE_DIR}/../.."
+ "${PROJECT_SOURCE_DIR}/../../engine"
+ "${PROJECT_SOURCE_DIR}/../../common"
+ "${PROJECT_SOURCE_DIR}/../../pm_shared"
+ "${PROJECT_SOURCE_DIR}/../../public"
+ "${PROJECT_SOURCE_DIR}/../../public/rehlds"
+)
+
+set(CORE_SRCS
+ "src/BSPModel.cpp"
+ "src/Delta.cpp"
+ "src/NetSocket.cpp"
+ "src/Network.cpp"
+ "src/Server.cpp"
+ "src/World.cpp"
+ "src/public_amalgamation.cpp"
+)
+
+set(COMMON_SRCS
+ "../../common/BaseSystemModule.cpp"
+ "../../common/ObjectDictionary.cpp"
+ "../../common/ObjectList.cpp"
+ "../../common/TokenLine.cpp"
+ "../../HLTV/common/BitBuffer.cpp"
+ "../../HLTV/common/byteorder.cpp"
+ "../../HLTV/common/common.cpp"
+ "../../HLTV/common/DemoFile.cpp"
+ "../../HLTV/common/DirectorCmd.cpp"
+ "../../HLTV/common/InfoString.cpp"
+ "../../HLTV/common/mathlib.cpp"
+ "../../HLTV/common/md5.cpp"
+ "../../HLTV/common/munge.cpp"
+ "../../HLTV/common/NetAddress.cpp"
+ "../../HLTV/common/NetChannel.cpp"
+ "../../HLTV/common/random.cpp"
+ "../../engine/mem.cpp"
+)
+
+include_directories(
+ ${PROJECT_SRC_DIR}
+ ${PROJECT_BZIP2_DIR}
+ ${PROJECT_PUBLIC_DIR}
+)
+
+add_definitions(
+ -DHLTV
+ -DHLTV_FIXES
+ -D_LINUX
+ -DLINUX
+ -D_GLIBCXX_USE_CXX11_ABI=0
+ -D_stricmp=strcasecmp
+ -D_strnicmp=strncasecmp
+ -D_strdup=strdup
+ -D_vsnprintf=vsnprintf
+ -D_snprintf=snprintf
+)
+
+if (NOT TARGET bzip2)
+ add_subdirectory(../../../dep/bzip2 lib)
+endif()
+
+add_library(core SHARED ${CORE_SRCS} ${COMMON_SRCS})
+target_link_libraries(core dl bzip2)
+set_target_properties(core PROPERTIES PREFIX "" COMPILE_FLAGS "-m32" LINK_FLAGS "-m32" POSITION_INDEPENDENT_CODE ON)
diff --git a/rehlds/HLTV/Core/msvc/Core.vcxproj b/rehlds/HLTV/Core/msvc/Core.vcxproj
index 21d4a79..0ae9902 100644
--- a/rehlds/HLTV/Core/msvc/Core.vcxproj
+++ b/rehlds/HLTV/Core/msvc/Core.vcxproj
@@ -5,10 +5,6 @@
Debug
Win32
-
- Release Swds
- Win32
-
Release
Win32
@@ -39,16 +35,6 @@
true
MultiByte
-
- DynamicLibrary
- false
- v120_xp
- v140_xp
- v141_xp
- v142
- true
- MultiByte
-
@@ -60,9 +46,6 @@
-
-
-
true
@@ -71,9 +54,6 @@
false
-
- false
-
Use
@@ -142,41 +122,6 @@
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
-
-
- echo Empty Action
- Force build to run Pre-Build event
- build.always.run
- build.always.run
-
-
@@ -186,17 +131,14 @@
true
true
- true
true
true
- true
true
true
- true
@@ -214,58 +156,44 @@
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
@@ -277,12 +205,10 @@
true
true
- true
true
true
- true
diff --git a/rehlds/HLTV/Core/src/Delta.cpp b/rehlds/HLTV/Core/src/Delta.cpp
index a1e5d75..54b96c2 100644
--- a/rehlds/HLTV/Core/src/Delta.cpp
+++ b/rehlds/HLTV/Core/src/Delta.cpp
@@ -42,13 +42,13 @@ delta_t *Delta::m_CustomentityDelta = nullptr;
delta_description_t Delta::m_MetaDescription[] =
{
- { DT_INTEGER, DELTA_D_DEF(fieldType), 1, 32, 1.0, 1.0, 0, 0, 0 },
- { DT_STRING, DELTA_D_DEF(fieldName), 1, 1, 1.0, 1.0, 0, 0, 0 },
- { DT_INTEGER, DELTA_D_DEF(fieldOffset), 1, 16, 1.0, 1.0, 0, 0, 0 },
- { DT_INTEGER, DELTA_D_DEF(fieldSize), 1, 8, 1.0, 1.0, 0, 0, 0 },
- { DT_INTEGER, DELTA_D_DEF(significant_bits), 1, 8, 1.0, 1.0, 0, 0, 0 },
- { DT_FLOAT, DELTA_D_DEF(premultiply), 1, 32, 4000.0, 1.0, 0, 0, 0 },
- { DT_FLOAT, DELTA_D_DEF(postmultiply), 1, 32, 4000.0, 1.0, 0, 0, 0 },
+ { DT_INTEGER, DELTA_D_DEF(fieldType), 1, 32, 1.0, 1.0, 0, {0, 0} },
+ { DT_STRING, DELTA_D_DEF(fieldName), 1, 1, 1.0, 1.0, 0, {0, 0} },
+ { DT_INTEGER, DELTA_D_DEF(fieldOffset), 1, 16, 1.0, 1.0, 0, {0, 0} },
+ { DT_INTEGER, DELTA_D_DEF(fieldSize), 1, 8, 1.0, 1.0, 0, {0, 0} },
+ { DT_INTEGER, DELTA_D_DEF(significant_bits), 1, 8, 1.0, 1.0, 0, {0, 0} },
+ { DT_FLOAT, DELTA_D_DEF(premultiply), 1, 32, 4000.0, 1.0, 0, {0, 0} },
+ { DT_FLOAT, DELTA_D_DEF(postmultiply), 1, 32, 4000.0, 1.0, 0, {0, 0} },
};
delta_t Delta::m_MetaDelta[] =
@@ -453,7 +453,7 @@ void Delta::MarkSendFields(unsigned char *from, unsigned char *to, delta_t *pFie
st2 = (char *)&to[pTest->fieldOffset];
// Not sure why it is case insensitive, but it looks so
- if (!(!*st1 && !*st2 || *st1 && *st2 && !Q_stricmp(st1, st2))) {
+ if (!((!*st1 && !*st2) || (*st1 && *st2 && !Q_stricmp(st1, st2)))) {
pTest->flags |= FDT_MARK;
}
break;
@@ -972,7 +972,7 @@ int Delta::TestDelta(unsigned char *from, unsigned char *to, delta_t *pFields)
st2 = (char *)&to[pTest->fieldOffset];
// Not sure why it is case insensitive, but it looks so
- if (!(!*st1 && !*st2 || *st1 && *st2 && !Q_stricmp(st1, st2)))
+ if (!((!*st1 && !*st2) || (*st1 && *st2 && !Q_stricmp(st1, st2))))
{
different = true;
length = Q_strlen(st2) * 8;
diff --git a/rehlds/HLTV/Core/src/World.cpp b/rehlds/HLTV/Core/src/World.cpp
index 8fb764f..5d8f1fd 100644
--- a/rehlds/HLTV/Core/src/World.cpp
+++ b/rehlds/HLTV/Core/src/World.cpp
@@ -1208,11 +1208,12 @@ void World::ClearEntityCache()
{
if (m_DeltaCache)
{
- for (int i = 0; i < m_MaxCacheIndex; i++) {
+ for (int i = 0; i < m_MaxCacheIndex; i++)
+ {
+ m_DeltaCache[i].seqNr = 0;
+ m_DeltaCache[i].deltaNr = 0;
m_DeltaCache[i].buffer.Free();
}
-
- Q_memset(m_DeltaCache, 0, sizeof(deltaCache_t) * m_MaxCacheIndex);
}
if (m_FrameCache) {
diff --git a/rehlds/HLTV/DemoPlayer/CMakeLists.txt b/rehlds/HLTV/DemoPlayer/CMakeLists.txt
new file mode 100644
index 0000000..17d85c3
--- /dev/null
+++ b/rehlds/HLTV/DemoPlayer/CMakeLists.txt
@@ -0,0 +1,96 @@
+cmake_minimum_required(VERSION 3.1)
+project(demoplayer CXX)
+
+option(DEBUG "Build with debug information." OFF)
+option(USE_INTEL_COMPILER "Use the Intel compiler." OFF)
+option(USE_CLANG_COMPILER "Use the Clang compiler." OFF)
+
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+if (USE_INTEL_COMPILER)
+ set(CMAKE_C_COMPILER "/opt/intel/bin/icc")
+ set(CMAKE_CXX_COMPILER "/opt/intel/bin/icpc")
+elseif (USE_CLANG_COMPILER)
+ set(CMAKE_C_COMPILER "/usr/bin/clang")
+ set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
+endif()
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions")
+
+if (DEBUG)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O3 -ggdb")
+else()
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O3")
+endif()
+
+if (USE_INTEL_COMPILER)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp")
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel -no-intel-extensions")
+
+ if (NOT DEBUG)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ipo")
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_CXX_FLAGS} -ipo")
+ endif()
+else()
+ # 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.
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=generic -msse3 -flto\
+ -fpermissive\
+ -Wno-unused-result -Wno-unknown-pragmas\
+ -Wno-sign-compare -Wno-write-strings -Wno-strict-aliasing")
+endif()
+
+set(PROJECT_SRC_DIR
+ "${PROJECT_SOURCE_DIR}/src"
+ "${PROJECT_SOURCE_DIR}/../"
+)
+
+set(PROJECT_PUBLIC_DIR
+ "${PROJECT_SOURCE_DIR}/../.."
+ "${PROJECT_SOURCE_DIR}/../../engine"
+ "${PROJECT_SOURCE_DIR}/../../common"
+ "${PROJECT_SOURCE_DIR}/../../pm_shared"
+ "${PROJECT_SOURCE_DIR}/../../public"
+ "${PROJECT_SOURCE_DIR}/../../public/rehlds"
+)
+
+set(DEMOPLAYER_SRCS
+ "src/DemoPlayer.cpp"
+ "src/public_amalgamation.cpp"
+)
+
+set(COMMON_SRCS
+ "../../common/BaseSystemModule.cpp"
+ "../../common/ObjectDictionary.cpp"
+ "../../common/ObjectList.cpp"
+ "../../common/TokenLine.cpp"
+ "../../HLTV/common/BitBuffer.cpp"
+ "../../HLTV/common/byteorder.cpp"
+ "../../HLTV/common/common.cpp"
+ "../../HLTV/common/DirectorCmd.cpp"
+ "../../HLTV/common/mathlib.cpp"
+ "../../engine/mem.cpp"
+)
+
+include_directories(
+ ${PROJECT_SRC_DIR}
+ ${PROJECT_PUBLIC_DIR}
+)
+
+add_definitions(
+ -DHLTV
+ -DHLTV_FIXES
+ -D_LINUX
+ -DLINUX
+ -D_GLIBCXX_USE_CXX11_ABI=0
+ -D_stricmp=strcasecmp
+ -D_strnicmp=strncasecmp
+ -D_strdup=strdup
+ -D_vsnprintf=vsnprintf
+ -D_snprintf=snprintf
+)
+
+add_library(demoplayer SHARED ${DEMOPLAYER_SRCS} ${COMMON_SRCS})
+target_link_libraries(demoplayer dl)
+set_target_properties(demoplayer PROPERTIES PREFIX "" COMPILE_FLAGS "-m32" LINK_FLAGS "-m32" POSITION_INDEPENDENT_CODE ON)
diff --git a/rehlds/HLTV/DemoPlayer/msvc/DemoPlayer.vcxproj b/rehlds/HLTV/DemoPlayer/msvc/DemoPlayer.vcxproj
index 515fd01..45a7a94 100644
--- a/rehlds/HLTV/DemoPlayer/msvc/DemoPlayer.vcxproj
+++ b/rehlds/HLTV/DemoPlayer/msvc/DemoPlayer.vcxproj
@@ -5,10 +5,6 @@
Debug
Win32
-
- Release Swds
- Win32
-
Release
Win32
@@ -22,12 +18,10 @@
true
- true
true
true
- true
true
@@ -39,7 +33,6 @@
Create
Create
- Create
@@ -51,7 +44,6 @@
true
- true
true
@@ -88,16 +80,6 @@
true
MultiByte
-
- DynamicLibrary
- false
- v120_xp
- v140_xp
- v141_xp
- v142
- true
- MultiByte
-
@@ -109,9 +91,6 @@
-
-
-
true
@@ -119,9 +98,6 @@
false
-
- false
-
Use
@@ -184,40 +160,6 @@
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
-
-
- echo Empty Action
- Force build to run Pre-Build event
- build.always.run
- build.always.run
-
-
diff --git a/rehlds/HLTV/Director/CMakeLists.txt b/rehlds/HLTV/Director/CMakeLists.txt
new file mode 100644
index 0000000..7667adb
--- /dev/null
+++ b/rehlds/HLTV/Director/CMakeLists.txt
@@ -0,0 +1,103 @@
+cmake_minimum_required(VERSION 3.1)
+project(director CXX)
+
+option(DEBUG "Build with debug information." OFF)
+option(USE_INTEL_COMPILER "Use the Intel compiler." OFF)
+option(USE_CLANG_COMPILER "Use the Clang compiler." OFF)
+
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+if (USE_INTEL_COMPILER)
+ set(CMAKE_C_COMPILER "/opt/intel/bin/icc")
+ set(CMAKE_CXX_COMPILER "/opt/intel/bin/icpc")
+elseif (USE_CLANG_COMPILER)
+ set(CMAKE_C_COMPILER "/usr/bin/clang")
+ set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
+endif()
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions")
+
+if (DEBUG)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O3 -ggdb")
+else()
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O3")
+endif()
+
+if (USE_INTEL_COMPILER)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp")
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel -no-intel-extensions")
+
+ if (NOT DEBUG)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ipo")
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_CXX_FLAGS} -ipo")
+ endif()
+else()
+ # 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.
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=generic -msse3 -flto\
+ -fpermissive\
+ -Wno-unused-result -Wno-unknown-pragmas\
+ -Wno-write-strings -Wno-strict-aliasing")
+endif()
+
+set(PROJECT_SRC_DIR
+ "${PROJECT_SOURCE_DIR}/src"
+ "${PROJECT_SOURCE_DIR}/../"
+)
+
+set(PROJECT_PUBLIC_DIR
+ "${PROJECT_SOURCE_DIR}/../.."
+ "${PROJECT_SOURCE_DIR}/../../engine"
+ "${PROJECT_SOURCE_DIR}/../../common"
+ "${PROJECT_SOURCE_DIR}/../../pm_shared"
+ "${PROJECT_SOURCE_DIR}/../../public"
+ "${PROJECT_SOURCE_DIR}/../../public/rehlds"
+)
+
+set(DIRECTOR_SRCS
+ "src/Director.cpp"
+ "src/public_amalgamation.cpp"
+)
+
+set(COMMON_SRCS
+ "../../common/BaseSystemModule.cpp"
+ "../../common/ObjectDictionary.cpp"
+ "../../common/ObjectList.cpp"
+ "../../common/TokenLine.cpp"
+ "../../HLTV/common/BitBuffer.cpp"
+ "../../HLTV/common/byteorder.cpp"
+ "../../HLTV/common/common.cpp"
+ "../../HLTV/common/DirectorCmd.cpp"
+ "../../HLTV/common/mathlib.cpp"
+ "../../HLTV/common/random.cpp"
+ "../../engine/mem.cpp"
+)
+
+include_directories(
+ ${PROJECT_SRC_DIR}
+ ${PROJECT_PUBLIC_DIR}
+)
+
+add_definitions(
+ -DHLTV
+ -DHLTV_FIXES
+ -DDIRECTOR_MODULE
+ -D_LINUX
+ -DLINUX
+ -D_GLIBCXX_USE_CXX11_ABI=0
+ -D_stricmp=strcasecmp
+ -D_strnicmp=strncasecmp
+ -D_strdup=strdup
+ -D_vsnprintf=vsnprintf
+ -D_snprintf=snprintf
+)
+
+if (NOT TARGET appversion)
+ add_custom_target(appversion DEPENDS COMMAND "${PROJECT_SOURCE_DIR}/../../version/appversion.sh" "${PROJECT_SOURCE_DIR}/../..")
+endif()
+
+add_library(director SHARED ${appversion.sh} ${DIRECTOR_SRCS} ${COMMON_SRCS})
+target_link_libraries(director dl)
+set_target_properties(director PROPERTIES PREFIX "" COMPILE_FLAGS "-m32" LINK_FLAGS "-m32" POSITION_INDEPENDENT_CODE ON)
+add_dependencies(director appversion)
diff --git a/rehlds/HLTV/Director/msvc/Director.vcxproj b/rehlds/HLTV/Director/msvc/Director.vcxproj
index 76cf66d..3f8a675 100644
--- a/rehlds/HLTV/Director/msvc/Director.vcxproj
+++ b/rehlds/HLTV/Director/msvc/Director.vcxproj
@@ -5,10 +5,6 @@
Debug
Win32
-
- Release Swds
- Win32
-
Release
Win32
@@ -39,16 +35,6 @@
true
MultiByte
-
- DynamicLibrary
- false
- v120_xp
- v140_xp
- v141_xp
- v142
- true
- MultiByte
-
@@ -60,9 +46,6 @@
-
-
-
true
@@ -70,9 +53,6 @@
false
-
- false
-
Use
@@ -135,39 +115,6 @@
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)")
-
-
- Automatic deployment script
-
-
@@ -184,7 +131,6 @@
Create
Create
- Create
diff --git a/rehlds/HLTV/Proxy/CMakeLists.txt b/rehlds/HLTV/Proxy/CMakeLists.txt
new file mode 100644
index 0000000..3365aee
--- /dev/null
+++ b/rehlds/HLTV/Proxy/CMakeLists.txt
@@ -0,0 +1,126 @@
+cmake_minimum_required(VERSION 3.1)
+project(proxy CXX)
+
+option(DEBUG "Build with debug information." OFF)
+option(USE_INTEL_COMPILER "Use the Intel compiler." OFF)
+option(USE_CLANG_COMPILER "Use the Clang compiler." OFF)
+
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+if (USE_INTEL_COMPILER)
+ set(CMAKE_C_COMPILER "/opt/intel/bin/icc")
+ set(CMAKE_CXX_COMPILER "/opt/intel/bin/icpc")
+elseif (USE_CLANG_COMPILER)
+ set(CMAKE_C_COMPILER "/usr/bin/clang")
+ set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
+endif()
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions")
+
+if (DEBUG)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O3 -ggdb")
+else()
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O3")
+endif()
+
+if (USE_INTEL_COMPILER)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp")
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel -no-intel-extensions")
+
+ if (NOT DEBUG)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ipo")
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_CXX_FLAGS} -ipo")
+ endif()
+else()
+ # 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.
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=generic -msse3 -flto\
+ -fpermissive\
+ -Wno-unused-result -Wno-unknown-pragmas -Wno-unused-variable\
+ -Wno-write-strings -Wno-strict-aliasing")
+
+ if (USE_CLANG_COMPILER)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-private-field")
+ endif()
+endif()
+
+set(PROJECT_SRC_DIR
+ "${PROJECT_SOURCE_DIR}/src"
+ "${PROJECT_SOURCE_DIR}/../"
+ "${PROJECT_SOURCE_DIR}/../Director/src"
+)
+
+set(PROJECT_BZIP2_DIR
+ "${PROJECT_SOURCE_DIR}/../../../dep/bzip2/include"
+)
+
+set(PROJECT_PUBLIC_DIR
+ "${PROJECT_SOURCE_DIR}/../.."
+ "${PROJECT_SOURCE_DIR}/../../engine"
+ "${PROJECT_SOURCE_DIR}/../../common"
+ "${PROJECT_SOURCE_DIR}/../../pm_shared"
+ "${PROJECT_SOURCE_DIR}/../../public"
+ "${PROJECT_SOURCE_DIR}/../../public/rehlds"
+)
+
+set(PROXY_SRCS
+ "src/Proxy.cpp"
+ "src/Status.cpp"
+ "src/Master.cpp"
+ "src/ProxyClient.cpp"
+ "src/DemoClient.cpp"
+ "src/FakeClient.cpp"
+ "src/public_amalgamation.cpp"
+ "../Director/src/Director.cpp"
+)
+
+set(COMMON_SRCS
+ "../../common/BaseSystemModule.cpp"
+ "../../common/ObjectDictionary.cpp"
+ "../../common/ObjectList.cpp"
+ "../../common/TokenLine.cpp"
+ "../../HLTV/common/BaseClient.cpp"
+ "../../HLTV/common/BitBuffer.cpp"
+ "../../HLTV/common/byteorder.cpp"
+ "../../HLTV/common/common.cpp"
+ "../../HLTV/common/DemoFile.cpp"
+ "../../HLTV/common/DirectorCmd.cpp"
+ "../../HLTV/common/InfoString.cpp"
+ "../../HLTV/common/mathlib.cpp"
+ "../../HLTV/common/md5.cpp"
+ "../../HLTV/common/munge.cpp"
+ "../../HLTV/common/NetAddress.cpp"
+ "../../HLTV/common/NetChannel.cpp"
+ "../../HLTV/common/random.cpp"
+ "../../engine/mem.cpp"
+)
+
+include_directories(
+ ${PROJECT_SRC_DIR}
+ ${PROJECT_BZIP2_DIR}
+ ${PROJECT_PUBLIC_DIR}
+)
+
+link_directories(${PROJECT_SOURCE_DIR}/../../lib/linux32)
+
+add_definitions(
+ -DHLTV
+ -DHLTV_FIXES
+ -D_LINUX
+ -DLINUX
+ -D_GLIBCXX_USE_CXX11_ABI=0
+ -D_stricmp=strcasecmp
+ -D_strnicmp=strncasecmp
+ -D_strdup=strdup
+ -D_vsnprintf=vsnprintf
+ -D_snprintf=snprintf
+)
+
+if (NOT TARGET bzip2)
+ add_subdirectory(../../../dep/bzip2 lib)
+endif()
+
+add_library(proxy SHARED ${PROXY_SRCS} ${COMMON_SRCS})
+target_link_libraries(proxy dl bzip2 steam_api)
+set_target_properties(proxy PROPERTIES PREFIX "" COMPILE_FLAGS "-m32" LINK_FLAGS "-m32" POSITION_INDEPENDENT_CODE ON)
diff --git a/rehlds/HLTV/Proxy/msvc/Proxy.vcxproj b/rehlds/HLTV/Proxy/msvc/Proxy.vcxproj
index a5324d2..44bb4d8 100644
--- a/rehlds/HLTV/Proxy/msvc/Proxy.vcxproj
+++ b/rehlds/HLTV/Proxy/msvc/Proxy.vcxproj
@@ -5,10 +5,6 @@
Debug
Win32
-
- Release Swds
- Win32
-
Release
Win32
@@ -20,264 +16,195 @@
-
-
-
-
-
-
-
-
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
-
-
@@ -289,7 +216,6 @@
true
true
- true
@@ -344,16 +270,6 @@
true
MultiByte
-
- DynamicLibrary
- false
- v120_xp
- v140_xp
- v141_xp
- v142
- true
- MultiByte
-
@@ -365,9 +281,6 @@
-
-
-
true
@@ -377,10 +290,6 @@
false
proxy
-
- false
- proxy
-
Use
@@ -456,49 +365,6 @@
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
-
-
-
-
-
-
-
-
-
-
- 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
-
-
diff --git a/rehlds/HLTV/Proxy/src/Proxy.cpp b/rehlds/HLTV/Proxy/src/Proxy.cpp
index ce850e9..c4d4aa6 100644
--- a/rehlds/HLTV/Proxy/src/Proxy.cpp
+++ b/rehlds/HLTV/Proxy/src/Proxy.cpp
@@ -210,7 +210,13 @@ bool Proxy::Init(IBaseSystem *system, int serial, char *name)
Q_memset(m_LastRconCommand, 0, sizeof(m_LastRconCommand));
Q_memset(m_OffLineText, 0, sizeof(m_OffLineText));
Q_memset(m_SignonCommands, 0, sizeof(m_SignonCommands));
- Q_memset(m_Challenges, 0, sizeof(m_Challenges));
+
+ for (int i = 0; i < MAX_CHALLENGES; i++)
+ {
+ m_Challenges[i].adr.Clear();
+ m_Challenges[i].challenge = 0;
+ m_Challenges[i].time = 0.0f;
+ }
m_LoopCommands.Init();
m_BannList.Init();
@@ -836,10 +842,10 @@ void Proxy::Broadcast(byte *data, int length, int groupType, bool isReliable)
while (client)
{
if (client->IsActive()
- && ((groupType & GROUP_CLIENT) && client->GetClientType() == TYPE_CLIENT)
- || ((groupType & GROUP_PROXY) && client->GetClientType() == TYPE_PROXY)
- || ((groupType & GROUP_VOICE) && client->IsHearingVoices())
- || ((groupType & GROUP_CHAT) && client->HasChatEnabled()))
+ && (((groupType & GROUP_CLIENT) && client->GetClientType() == TYPE_CLIENT)
+ || ((groupType & GROUP_PROXY) && client->GetClientType() == TYPE_PROXY)
+ || ((groupType & GROUP_VOICE) && client->IsHearingVoices())
+ || ((groupType & GROUP_CHAT) && client->HasChatEnabled())))
{
client->Send(data, length, isReliable);
}
@@ -966,7 +972,7 @@ void Proxy::CMD_Name(char *cmdLine)
}
char name[MAX_NAME];
- int len = Q_strlen(params.GetToken(1));
+ unsigned int len = Q_strlen(params.GetToken(1));
if (len > sizeof(name) - 1) {
m_System->Printf("Invalid name length.\n");
return;
diff --git a/rehlds/HLTV/common/BitBuffer.cpp b/rehlds/HLTV/common/BitBuffer.cpp
index f730896..89bf0fc 100644
--- a/rehlds/HLTV/common/BitBuffer.cpp
+++ b/rehlds/HLTV/common/BitBuffer.cpp
@@ -67,15 +67,15 @@ const uint32 INVBITTABLE[] =
0xFFFFFFFF,
};
-BitBuffer::BitBuffer() : m_Data(nullptr),
+BitBuffer::BitBuffer() :
+ m_Overflowed(false),
+ m_Data(nullptr),
m_CurByte(nullptr),
m_CurBit(0),
m_MaxSize(0),
- m_Overflowed(false),
m_LittleEndian(false),
m_OwnData(false)
{
- ;
}
BitBuffer::BitBuffer(void *newData, unsigned int size)
@@ -345,7 +345,8 @@ void BitBuffer::WriteBuf(BitBuffer *buf, int length)
char *BitBuffer::ReadString()
{
- int c = 0, l = 0;
+ int c = 0;
+ unsigned int l = 0;
static char string[8192];
while ((c = ReadChar(), c) && c != -1 && l < sizeof(string) - 1) {
@@ -358,7 +359,8 @@ char *BitBuffer::ReadString()
char *BitBuffer::ReadStringLine()
{
- int c = 0, l = 0;
+ int c = 0;
+ unsigned int l = 0;
static char string[2048];
while ((c = ReadChar(), c) && c != '\n' && c != -1 && l < sizeof(string) - 1) {
diff --git a/rehlds/HLTV/common/DemoFile.cpp b/rehlds/HLTV/common/DemoFile.cpp
index f3ddbee..d955248 100644
--- a/rehlds/HLTV/common/DemoFile.cpp
+++ b/rehlds/HLTV/common/DemoFile.cpp
@@ -29,10 +29,10 @@
#include "precompiled.h"
DemoFile::DemoFile() :
- m_FileSystem(nullptr),
m_FileHandle(FILESYSTEM_INVALID_HANDLE),
m_DemoChannel(nullptr),
- m_Entries(nullptr)
+ m_Entries(nullptr),
+ m_FileSystem(nullptr)
{
Reset();
}
@@ -545,6 +545,8 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
case DemoCmd::PayLoad:
demoData->WriteLong(msglen);
break;
+ default:
+ break;
}
demoData->WriteBuf(msgbuf, msglen);
diff --git a/rehlds/HLTV/common/InfoString.cpp b/rehlds/HLTV/common/InfoString.cpp
index 070206e..9e0bc03 100644
--- a/rehlds/HLTV/common/InfoString.cpp
+++ b/rehlds/HLTV/common/InfoString.cpp
@@ -28,8 +28,9 @@
#include "precompiled.h"
-InfoString::InfoString(char *string, unsigned int maxSize)
- : m_String(nullptr), m_MaxSize(0)
+InfoString::InfoString(char *string, unsigned int maxSize) :
+ m_MaxSize(0),
+ m_String(nullptr)
{
unsigned int len = Q_strlen(string) + 1;
if (len < maxSize) {
@@ -40,19 +41,22 @@ InfoString::InfoString(char *string, unsigned int maxSize)
SetString(string);
}
-InfoString::InfoString()
- : m_String(nullptr), m_MaxSize(0)
+InfoString::InfoString() :
+ m_MaxSize(0),
+ m_String(nullptr)
{
}
-InfoString::InfoString(unsigned int maxSize)
- : m_String(nullptr), m_MaxSize(0)
+InfoString::InfoString(unsigned int maxSize) :
+ m_MaxSize(0),
+ m_String(nullptr)
{
SetMaxSize(maxSize);
}
-InfoString::InfoString(char *string)
- : m_String(nullptr), m_MaxSize(0)
+InfoString::InfoString(char *string) :
+ m_MaxSize(0),
+ m_String(nullptr)
{
unsigned int len = Q_strlen(string) + 1;
if (len < MAX_INFO_LEN) {
diff --git a/rehlds/HLTV/common/NetAddress.cpp b/rehlds/HLTV/common/NetAddress.cpp
index 2ee99c0..089af9d 100644
--- a/rehlds/HLTV/common/NetAddress.cpp
+++ b/rehlds/HLTV/common/NetAddress.cpp
@@ -28,9 +28,11 @@
#include "precompiled.h"
-NetAddress::NetAddress() :
- m_Port(0), m_IP(), m_String()
+NetAddress::NetAddress()
{
+ m_Port = 0;
+ Q_memset(m_IP, 0, sizeof(m_IP));
+ Q_memset(m_String, 0, sizeof(m_String));
}
void NetAddress::SetPort(int16 port)
diff --git a/rehlds/HLTV/common/common.cpp b/rehlds/HLTV/common/common.cpp
index 84916cf..0da0ef4 100644
--- a/rehlds/HLTV/common/common.cpp
+++ b/rehlds/HLTV/common/common.cpp
@@ -220,7 +220,7 @@ char *COM_FileExtension(char *in)
#else // #ifdef HLTV_FIXES
static char exten[MAX_PATH];
char *c, *d = nullptr;
- int i;
+ unsigned int i;
// Search for the first dot after the last path separator
c = in;
@@ -537,7 +537,7 @@ void NORETURN HLTV_SysError(const char *fmt, ...)
fprintf(fl, "%s\n", string);
fclose(fl);
- int *null = 0;
+ volatile int *null = 0;
*null = 0;
exit(-1);
}
diff --git a/rehlds/common/IBaseSystem.h b/rehlds/common/IBaseSystem.h
index 9f50fe3..9b0f687 100644
--- a/rehlds/common/IBaseSystem.h
+++ b/rehlds/common/IBaseSystem.h
@@ -74,7 +74,7 @@ public:
virtual bool RegisterCommand(char *name, ISystemModule *module, int commandID) = 0;
virtual void GetCommandMatches(char *string, ObjectList *pMatchList) = 0;
- virtual void ExecuteString(char *commands) = 0;
+ virtual void ExecuteString(const char *commands) = 0;
virtual void ExecuteFile(char *filename) = 0;
virtual void Errorf(char *fmt, ...) = 0;
diff --git a/rehlds/common/TextConsoleUnix.cpp b/rehlds/common/TextConsoleUnix.cpp
index 32671ae..90af60c 100644
--- a/rehlds/common/TextConsoleUnix.cpp
+++ b/rehlds/common/TextConsoleUnix.cpp
@@ -133,7 +133,7 @@ int CTextConsoleUnix::kbhit()
return select(STDIN_FILENO + 1, &rfds, NULL, NULL, &tv) != -1 && FD_ISSET(STDIN_FILENO, &rfds);
}
-char *CTextConsoleUnix::GetLine()
+const char *CTextConsoleUnix::GetLine()
{
// early return for 99.999% case :)
if (!kbhit())
@@ -273,7 +273,7 @@ char *CTextConsoleUnix::GetLine()
return NULL;
}
-void CTextConsoleUnix::PrintRaw(char *pszMsg, int nChars)
+void CTextConsoleUnix::PrintRaw(const char *pszMsg, int nChars)
{
if (nChars == 0)
{
@@ -288,7 +288,7 @@ void CTextConsoleUnix::PrintRaw(char *pszMsg, int nChars)
}
}
-void CTextConsoleUnix::Echo(char *pszMsg, int nChars)
+void CTextConsoleUnix::Echo(const char *pszMsg, int nChars)
{
if (nChars == 0)
{
diff --git a/rehlds/common/TextConsoleUnix.h b/rehlds/common/TextConsoleUnix.h
index b40cbc4..bc14575 100644
--- a/rehlds/common/TextConsoleUnix.h
+++ b/rehlds/common/TextConsoleUnix.h
@@ -44,9 +44,9 @@ public:
bool Init(IBaseSystem *system = nullptr);
void ShutDown();
- void PrintRaw(char *pszMsg, int nChars = 0);
- void Echo(char *pszMsg, int nChars = 0);
- char *GetLine();
+ void PrintRaw(const char *pszMsg, int nChars = 0);
+ void Echo(const char *pszMsg, int nChars = 0);
+ const char *GetLine();
int GetWidth();
private:
diff --git a/rehlds/common/TextConsoleWin32.cpp b/rehlds/common/TextConsoleWin32.cpp
index aeaefb3..1ac38f3 100644
--- a/rehlds/common/TextConsoleWin32.cpp
+++ b/rehlds/common/TextConsoleWin32.cpp
@@ -111,7 +111,7 @@ void CTextConsoleWin32::SetVisible(bool visible)
m_ConsoleVisible = visible;
}
-char *CTextConsoleWin32::GetLine()
+const char *CTextConsoleWin32::GetLine()
{
while (true)
{
@@ -203,7 +203,7 @@ char *CTextConsoleWin32::GetLine()
return nullptr;
}
-void CTextConsoleWin32::PrintRaw(char *pszMsg, int nChars)
+void CTextConsoleWin32::PrintRaw(const char *pszMsg, int nChars)
{
#ifdef LAUNCHER_FIXES
char outputStr[2048];
@@ -225,7 +225,7 @@ void CTextConsoleWin32::PrintRaw(char *pszMsg, int nChars)
#endif
}
-void CTextConsoleWin32::Echo(char *pszMsg, int nChars)
+void CTextConsoleWin32::Echo(const char *pszMsg, int nChars)
{
PrintRaw(pszMsg, nChars);
}
@@ -245,7 +245,7 @@ int CTextConsoleWin32::GetWidth()
return nWidth;
}
-void CTextConsoleWin32::SetStatusLine(char *pszStatus)
+void CTextConsoleWin32::SetStatusLine(const char *pszStatus)
{
Q_strncpy(statusline, pszStatus, sizeof(statusline) - 1);
statusline[sizeof(statusline) - 2] = '\0';
@@ -269,7 +269,7 @@ void CTextConsoleWin32::UpdateStatus()
WriteConsoleOutputCharacter(houtput, statusline, 80, coord, &dwWritten);
}
-void CTextConsoleWin32::SetTitle(char *pszTitle)
+void CTextConsoleWin32::SetTitle(const char *pszTitle)
{
SetConsoleTitle(pszTitle);
}
diff --git a/rehlds/common/TextConsoleWin32.h b/rehlds/common/TextConsoleWin32.h
index 656110e..70ba857 100644
--- a/rehlds/common/TextConsoleWin32.h
+++ b/rehlds/common/TextConsoleWin32.h
@@ -39,13 +39,13 @@ public:
bool Init(IBaseSystem *system = nullptr);
void ShutDown();
- void SetTitle(char *pszTitle);
- void SetStatusLine(char *pszStatus);
+ void SetTitle(const char *pszTitle);
+ void SetStatusLine(const char *pszStatus);
void UpdateStatus();
- void PrintRaw(char * pszMsz, int nChars = 0);
- void Echo(char * pszMsz, int nChars = 0);
- char *GetLine();
+ void PrintRaw(const char *pszMsz, int nChars = 0);
+ void Echo(const char *pszMsz, int nChars = 0);
+ const char *GetLine();
int GetWidth();
void SetVisible(bool visible);
diff --git a/rehlds/common/commandline.cpp b/rehlds/common/commandline.cpp
index 9be292c..4fc4970 100644
--- a/rehlds/common/commandline.cpp
+++ b/rehlds/common/commandline.cpp
@@ -61,7 +61,6 @@ char *CopyString(const char *src)
void CCommandLine::CreateCmdLine(int argc, const char *argv[])
{
char cmdline[4096] = "";
- const int MAX_CHARS = sizeof(cmdline) - 1;
for (int i = 0; i < argc; ++i)
{
@@ -88,7 +87,10 @@ void CCommandLine::LoadParametersFromFile(const char *&pSrc, char *&pDst, int ma
// Suck out the file name
char szFileName[ MAX_PATH ];
char *pOut;
+
+#if 0
char *pDestStart = pDst;
+#endif
// Skip the @ sign
pSrc++;
@@ -342,7 +344,7 @@ const char *CCommandLine::CheckParm(const char *psz, char **ppszValue) const
sz[i] = p2[i];
i++;
- } while (i < sizeof(sz));
+ } while ((unsigned)i < sizeof(sz));
sz[i] = '\0';
*ppszValue = sz;
diff --git a/rehlds/common/stdc++compat.cpp b/rehlds/common/stdc++compat.cpp
index 6177fee..363e440 100644
--- a/rehlds/common/stdc++compat.cpp
+++ b/rehlds/common/stdc++compat.cpp
@@ -1,6 +1,6 @@
#include
-#if !defined(_WIN32)
+#if !defined(_WIN32) && !defined(BUILD_STATIC_LIBSTDC) // if build with static libstdc++ then ignore
void NORETURN Sys_Error(const char *error, ...);
// This file adds the necessary compatibility tricks to avoid symbols with
diff --git a/rehlds/common/textconsole.cpp b/rehlds/common/textconsole.cpp
index 45d13d7..b996eec 100644
--- a/rehlds/common/textconsole.cpp
+++ b/rehlds/common/textconsole.cpp
@@ -74,7 +74,7 @@ void CTextConsole::ShutDown()
;
}
-void CTextConsole::Print(char *pszMsg)
+void CTextConsole::Print(const char *pszMsg)
{
if (m_nConsoleTextLen)
{
@@ -264,7 +264,7 @@ void CTextConsole::ReceiveStandardChar(const char ch)
int nCount;
// If the line buffer is maxed out, ignore this char
- if (m_nConsoleTextLen >= (sizeof(m_szConsoleText) - 2))
+ if ((unsigned)m_nConsoleTextLen >= (sizeof(m_szConsoleText) - 2))
{
return;
}
diff --git a/rehlds/common/textconsole.h b/rehlds/common/textconsole.h
index 9d1b67e..d9d673b 100644
--- a/rehlds/common/textconsole.h
+++ b/rehlds/common/textconsole.h
@@ -39,16 +39,16 @@ public:
virtual bool Init(IBaseSystem *system = nullptr);
virtual void ShutDown();
- virtual void Print(char *pszMsg);
+ virtual void Print(const char *pszMsg);
- virtual void SetTitle(char *pszTitle) {}
- virtual void SetStatusLine(char *pszStatus) {}
+ virtual void SetTitle(const char *pszTitle) {}
+ virtual void SetStatusLine(const char *pszStatus) {}
virtual void UpdateStatus() {}
// Must be provided by children
- virtual void PrintRaw(char *pszMsg, int nChars = 0) = 0;
- virtual void Echo(char *pszMsg, int nChars = 0) = 0;
- virtual char *GetLine() = 0;
+ virtual void PrintRaw(const char *pszMsg, int nChars = 0) = 0;
+ virtual void Echo(const char *pszMsg, int nChars = 0) = 0;
+ virtual const char *GetLine() = 0;
virtual int GetWidth() = 0;
virtual void SetVisible(bool visible);
@@ -92,4 +92,4 @@ protected:
#include "TextConsoleUnix.h"
#endif // defined(_WIN32)
-void Sys_Printf(char *fmt, ...);
+void Sys_Printf(const char *fmt, ...);
diff --git a/rehlds/dedicated/CMakeLists.txt b/rehlds/dedicated/CMakeLists.txt
new file mode 100644
index 0000000..0f53ac5
--- /dev/null
+++ b/rehlds/dedicated/CMakeLists.txt
@@ -0,0 +1,95 @@
+cmake_minimum_required(VERSION 3.1)
+project(hlds CXX)
+
+option(DEBUG "Build with debug information." OFF)
+option(USE_INTEL_COMPILER "Use the Intel compiler." OFF)
+option(USE_CLANG_COMPILER "Use the Clang compiler." OFF)
+
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+if (USE_INTEL_COMPILER)
+ set(CMAKE_C_COMPILER "/opt/intel/bin/icc")
+ set(CMAKE_CXX_COMPILER "/opt/intel/bin/icpc")
+elseif (USE_CLANG_COMPILER)
+ set(CMAKE_C_COMPILER "/usr/bin/clang")
+ set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
+endif()
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions")
+
+if (DEBUG)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O3 -ggdb")
+else()
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O3")
+endif()
+
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -no-pie")
+
+if (USE_INTEL_COMPILER)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp")
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-intel -no-intel-extensions")
+
+ if (NOT DEBUG)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ipo")
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_CXX_FLAGS} -ipo")
+ endif()
+else()
+ # 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.
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=generic -msse3 -flto\
+ -fpermissive\
+ -Wno-unused-result")
+endif()
+
+set(PROJECT_SRC_DIR
+ "${PROJECT_SOURCE_DIR}/src"
+ "${PROJECT_SOURCE_DIR}/../"
+)
+
+set(PROJECT_PUBLIC_DIR
+ "${PROJECT_SOURCE_DIR}/../engine"
+ "${PROJECT_SOURCE_DIR}/../common"
+ "${PROJECT_SOURCE_DIR}/../public"
+ "${PROJECT_SOURCE_DIR}/../public/rehlds"
+)
+
+set(DEDICATED_SRCS
+ "src/dbg.cpp"
+ "src/dedicated_exports.cpp"
+ "src/public_amalgamation.cpp"
+ "src/sys_ded.cpp"
+ "src/sys_linux.cpp"
+ "src/vgui/vguihelpers.cpp"
+)
+
+set(COMMON_SRCS
+ "../common/textconsole.cpp"
+ "../common/TextConsoleUnix.cpp"
+ "../common/SteamAppStartUp.cpp"
+ "../common/ObjectList.cpp"
+ "../common/commandline.cpp"
+ "../common/minidump.cpp"
+ "../engine/mem.cpp"
+)
+
+include_directories(
+ ${PROJECT_SRC_DIR}
+ ${PROJECT_PUBLIC_DIR}
+)
+
+add_definitions(
+ -DLAUNCHER_FIXES
+ -D_CONSOLE
+ -D_LINUX
+ -DLINUX
+ -D_GLIBCXX_USE_CXX11_ABI=0
+ -D_stricmp=strcasecmp
+ -D_strnicmp=strncasecmp
+ -D_strdup=strdup
+ -D_vsnprintf=vsnprintf
+)
+
+add_executable(hlds ${DEDICATED_SRCS} ${COMMON_SRCS})
+target_link_libraries(hlds dl)
+set_target_properties(hlds PROPERTIES OUTPUT_NAME hlds_linux PREFIX "" COMPILE_FLAGS "-m32" LINK_FLAGS "-m32" POSITION_INDEPENDENT_CODE ON)
diff --git a/rehlds/dedicated/msvc/dedicated.vcxproj b/rehlds/dedicated/msvc/dedicated.vcxproj
index 96c4544..a05bc81 100644
--- a/rehlds/dedicated/msvc/dedicated.vcxproj
+++ b/rehlds/dedicated/msvc/dedicated.vcxproj
@@ -5,10 +5,6 @@
Debug
Win32
-
- Release Swds
- Win32
-
Release
Win32
@@ -40,16 +36,6 @@
true
MultiByte
-
- Application
- false
- v120_xp
- v140_xp
- v141_xp
- v142
- true
- MultiByte
-
@@ -59,9 +45,6 @@
-
-
-
true
@@ -71,10 +54,6 @@
false
hlds
-
- false
- hlds
-
Use
@@ -155,51 +134,6 @@
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
-
-
@@ -208,7 +142,6 @@
true
true
- true
@@ -230,7 +163,6 @@
true
true
- true
@@ -239,14 +171,12 @@
Create
Create
- Create
true
true
- true
diff --git a/rehlds/dedicated/src/dedicated_exports.cpp b/rehlds/dedicated/src/dedicated_exports.cpp
index f248d9c..060e007 100644
--- a/rehlds/dedicated/src/dedicated_exports.cpp
+++ b/rehlds/dedicated/src/dedicated_exports.cpp
@@ -30,12 +30,12 @@
class CDedicatedExports: public IDedicatedExports {
public:
- EXT_FUNC void Sys_Printf(char *text);
+ EXT_FUNC void Sys_Printf(const char *text);
};
EXPOSE_SINGLE_INTERFACE(CDedicatedExports, IDedicatedExports, VENGINE_DEDICATEDEXPORTS_API_VERSION);
-void CDedicatedExports::Sys_Printf(char *text)
+void CDedicatedExports::Sys_Printf(const char *text)
{
::Sys_Printf_Safe(text);
}
diff --git a/rehlds/dedicated/src/isys.h b/rehlds/dedicated/src/isys.h
index e973916..fc4a0fe 100644
--- a/rehlds/dedicated/src/isys.h
+++ b/rehlds/dedicated/src/isys.h
@@ -36,18 +36,18 @@ public:
virtual bool GetExecutableName(char *out) = 0;
virtual void ErrorMessage(int level, const char *msg) = 0;
- virtual void WriteStatusText(char *szText) = 0;
+ virtual void WriteStatusText(const char *szText) = 0;
virtual void UpdateStatus(int force) = 0;
- virtual long LoadLibrary(char *lib) = 0;
+ virtual long LoadLibrary(const char *lib) = 0;
virtual void FreeLibrary(long library) = 0;
virtual bool CreateConsoleWindow(void) = 0;
virtual void DestroyConsoleWindow(void) = 0;
- virtual void ConsoleOutput(char *string) = 0;
- virtual char *ConsoleInput(void) = 0;
- virtual void Printf(char *fmt, ...) = 0;
+ virtual void ConsoleOutput(const char *string) = 0;
+ virtual const char *ConsoleInput(void) = 0;
+ virtual void Printf(const char *fmt, ...) = 0;
};
extern ISys *sys;
diff --git a/rehlds/dedicated/src/sys_ded.cpp b/rehlds/dedicated/src/sys_ded.cpp
index df0cfea..eae9147 100644
--- a/rehlds/dedicated/src/sys_ded.cpp
+++ b/rehlds/dedicated/src/sys_ded.cpp
@@ -40,7 +40,7 @@ CSysModule *g_pFileSystemModule = nullptr;
CreateInterfaceFn g_FilesystemFactoryFn;
-void Sys_Printf_Safe(char *text)
+void Sys_Printf_Safe(const char *text)
{
if (sys)
{
@@ -48,7 +48,7 @@ void Sys_Printf_Safe(char *text)
}
}
-void Sys_Printf(char *fmt, ...)
+void Sys_Printf(const char *fmt, ...)
{
// Dump text to debugging console.
va_list argptr;
@@ -76,7 +76,7 @@ void ProcessConsoleInput()
if (!engineAPI)
return;
- char *inputLine = console.GetLine();
+ const char *inputLine = console.GetLine();
if (inputLine)
{
char szBuf[256];
@@ -85,7 +85,7 @@ void ProcessConsoleInput()
}
}
-char *UTIL_GetBaseDir()
+const char *UTIL_GetBaseDir()
{
return ".";
}
diff --git a/rehlds/dedicated/src/sys_ded.h b/rehlds/dedicated/src/sys_ded.h
index 17603e9..b0912f8 100644
--- a/rehlds/dedicated/src/sys_ded.h
+++ b/rehlds/dedicated/src/sys_ded.h
@@ -38,5 +38,5 @@ extern CreateInterfaceFn g_FilesystemFactoryFn;
int RunEngine();
int StartServer(char* cmdline);
-void Sys_Printf_Safe(char *text);
-void Sys_Printf(char *fmt, ...);
+void Sys_Printf_Safe(const char *text);
+void Sys_Printf(const char *fmt, ...);
diff --git a/rehlds/dedicated/src/sys_linux.cpp b/rehlds/dedicated/src/sys_linux.cpp
index 5a0cf11..814eb18 100644
--- a/rehlds/dedicated/src/sys_linux.cpp
+++ b/rehlds/dedicated/src/sys_linux.cpp
@@ -37,18 +37,18 @@ public:
bool GetExecutableName(char *out) override;
NORETURN void ErrorMessage(int level, const char *msg) override;
- void WriteStatusText(char *szText) override;
+ void WriteStatusText(const char *szText) override;
void UpdateStatus(int force) override;
- long LoadLibrary(char *lib) override;
+ long LoadLibrary(const char *lib) override;
void FreeLibrary(long library) override;
bool CreateConsoleWindow() override;
void DestroyConsoleWindow() override;
- void ConsoleOutput(char *string) override;
- char *ConsoleInput() override;
- void Printf(char *fmt, ...) override;
+ void ConsoleOutput(const char *string) override;
+ const char *ConsoleInput() override;
+ void Printf(const char *fmt, ...) override;
};
CSys g_Sys;
@@ -206,7 +206,7 @@ void CSys::ErrorMessage(int level, const char *msg)
exit(-1);
}
-void CSys::WriteStatusText(char *szText)
+void CSys::WriteStatusText(const char *szText)
{
}
@@ -214,7 +214,7 @@ void CSys::UpdateStatus(int force)
{
}
-long CSys::LoadLibrary(char *lib)
+long CSys::LoadLibrary(const char *lib)
{
char cwd[1024];
char absolute_lib[1024];
@@ -258,18 +258,18 @@ void CSys::DestroyConsoleWindow()
}
// Print text to the dedicated console
-void CSys::ConsoleOutput(char *string)
+void CSys::ConsoleOutput(const char *string)
{
printf("%s", string);
fflush(stdout);
}
-char *CSys::ConsoleInput()
+const char *CSys::ConsoleInput()
{
return console.GetLine();
}
-void CSys::Printf(char *fmt, ...)
+void CSys::Printf(const char *fmt, ...)
{
// Dump text to debugging console.
va_list argptr;
diff --git a/rehlds/dedicated/src/sys_window.cpp b/rehlds/dedicated/src/sys_window.cpp
index f8e614d..02661d7 100644
--- a/rehlds/dedicated/src/sys_window.cpp
+++ b/rehlds/dedicated/src/sys_window.cpp
@@ -37,18 +37,18 @@ public:
bool GetExecutableName(char *out) override;
void ErrorMessage(int level, const char *msg) override;
- void WriteStatusText(char *szText) override;
+ void WriteStatusText(const char *szText) override;
void UpdateStatus(int force) override;
- long LoadLibrary(char *lib) override;
+ long LoadLibrary(const char *lib) override;
void FreeLibrary(long library) override;
bool CreateConsoleWindow() override;
void DestroyConsoleWindow() override;
- void ConsoleOutput(char *string) override;
- char *ConsoleInput() override;
- void Printf(char *fmt, ...) override;
+ void ConsoleOutput(const char *string) override;
+ const char *ConsoleInput() override;
+ void Printf(const char *fmt, ...) override;
};
CSys g_Sys;
@@ -93,7 +93,7 @@ void CSys::ErrorMessage(int level, const char *msg)
PostQuitMessage(0);
}
-void CSys::WriteStatusText(char *szText)
+void CSys::WriteStatusText(const char *szText)
{
SetConsoleTitle(szText);
}
@@ -125,7 +125,7 @@ void CSys::UpdateStatus(int force)
console.UpdateStatus();
}
-long CSys::LoadLibrary(char *lib)
+long CSys::LoadLibrary(const char *lib)
{
void *hDll = ::LoadLibrary(lib);
return (long)hDll;
@@ -160,7 +160,7 @@ void CSys::DestroyConsoleWindow()
DeinitConProc();
}
-void CSys::ConsoleOutput(char *string)
+void CSys::ConsoleOutput(const char *string)
{
if (g_bVGui)
{
@@ -172,12 +172,12 @@ void CSys::ConsoleOutput(char *string)
}
}
-char *CSys::ConsoleInput()
+const char *CSys::ConsoleInput()
{
return console.GetLine();
}
-void CSys::Printf(char *fmt, ...)
+void CSys::Printf(const char *fmt, ...)
{
// Dump text to debugging console.
va_list argptr;
diff --git a/rehlds/engine/SystemWrapper.cpp b/rehlds/engine/SystemWrapper.cpp
index 83aa088..ba3ca9c 100644
--- a/rehlds/engine/SystemWrapper.cpp
+++ b/rehlds/engine/SystemWrapper.cpp
@@ -54,7 +54,7 @@ BOOL SystemWrapper_LoadModule(char *interfacename, char *library, char *instance
return FALSE;
}
-void SystemWrapper_ExecuteString(char *command)
+void SystemWrapper_ExecuteString(const char *command)
{
gSystemWrapper.ExecuteString(command);
}
@@ -234,7 +234,7 @@ void SystemWrapper::CMD_UnloadModule(char *cmdLine)
SystemWrapper::library_t *SystemWrapper::GetLibrary(char *name)
{
- char fixedname[MAX_PATH];
+ char fixedname[MAX_PATH-4]; // reserve for extension so/dll
Q_strlcpy(fixedname, name);
COM_FixSlashes(fixedname);
@@ -550,49 +550,56 @@ bool SystemWrapper::RemoveModule(ISystemModule *module)
return false;
}
-void SystemWrapper::ExecuteString(char *commands)
+void SystemWrapper::ExecuteString(const char *commands)
{
if (!commands || !commands[0])
return;
- int size = 0;
- char singleCmd[256] = "";
- bool quotes = false;
- char *p = singleCmd;
- char *c = commands;
+ // Remove format characters to block format string attacks
+ COM_RemoveEvilChars(const_cast(commands));
- COM_RemoveEvilChars(c);
- while (true)
+ bool bInQuote = false;
+
+ char *pszDest;
+ char singleCmd[256] = {0};
+
+ const char *pszSource = commands;
+ while (*pszSource)
{
- *p = *c;
+ // Parse out single commands and execute them
+ pszDest = singleCmd;
- if (++size >= sizeof(singleCmd))
+ unsigned int i;
+ for (i = 0; i < ARRAYSIZE(singleCmd); i++)
{
- DPrintf("WARNING! System::ExecuteString: Command token too long.\n");
- break;
+ char c = *pszSource++;
+
+ *pszDest++ = c;
+
+ if (c == '"')
+ {
+ bInQuote = !bInQuote;
+ }
+ else if (c == ';' && !bInQuote)
+ {
+ // End of command and not in a quoted string
+ break;
+ }
}
- if (*c == '"')
- quotes = !quotes;
-
- if ((*c != ';' || quotes) && *c)
+ if (i >= ARRAYSIZE(singleCmd))
{
- ++p;
- }
- else
- {
- *p = '\0';
-
- char *cmd = singleCmd;
- while (*cmd == ' ') { cmd++; }
-
- DispatchCommand(cmd);
- p = singleCmd;
- size = 0;
+ Printf("WARNING! System::ExecuteString: Command token too long.\n");
+ return;
}
- if (!*c++)
- break;
+ *pszDest = '\0';
+
+ char *pszCmd = singleCmd;
+ while (*pszCmd == ' ')
+ pszCmd++; // skip leading whitespaces
+
+ DispatchCommand(pszCmd);
}
}
@@ -699,7 +706,7 @@ void EngineWrapper::DemoUpdateClientData(client_data_t *cdat)
void EngineWrapper::CL_QueueEvent(int flags, int index, float delay, event_args_t *pargs)
{
#ifndef SWDS
- CL_QueueEvent(flags, index, delay, pargs);
+ ::CL_QueueEvent(flags, index, delay, pargs);
#endif // SWDS
}
@@ -713,14 +720,14 @@ void EngineWrapper::HudWeaponAnim(int iAnim, int body)
void EngineWrapper::CL_DemoPlaySound(int channel, char *sample, float attenuation, float volume, int flags, int pitch)
{
#ifndef SWDS
- CL_DemoPlaySound(channel, sample, attenuation, volume, flags, pitch);
+ ::CL_DemoPlaySound(channel, sample, attenuation, volume, flags, pitch);
#endif // SWDS
}
void EngineWrapper::ClientDLL_ReadDemoBuffer(int size, unsigned char *buffer)
{
#ifndef SWDS
- ClientDLL_ReadDemoBuffer();
+ ::ClientDLL_ReadDemoBuffer();
#endif // SWDS
}
@@ -741,7 +748,7 @@ char *EngineWrapper::GetStatusLine()
void EngineWrapper::Cbuf_AddText(char *text)
{
- Cbuf_AddText(text);
+ ::Cbuf_AddText(text);
}
#ifdef REHLDS_FIXES
diff --git a/rehlds/engine/SystemWrapper.h b/rehlds/engine/SystemWrapper.h
index 9cbcb7c..fd5c5fc 100644
--- a/rehlds/engine/SystemWrapper.h
+++ b/rehlds/engine/SystemWrapper.h
@@ -93,7 +93,7 @@ public:
EXT_FUNC Panel *GetPanel();
EXT_FUNC bool RegisterCommand(char *name, ISystemModule *module, int commandID);
EXT_FUNC void GetCommandMatches(char *string, ObjectList *pMatchList);
- EXT_FUNC void ExecuteString(char *commands);
+ EXT_FUNC void ExecuteString(const char *commands);
EXT_FUNC void ExecuteFile(char *filename);
EXT_FUNC void Errorf(char *fmt, ...);
EXT_FUNC char *CheckParam(char *param);
@@ -146,7 +146,7 @@ void SystemWrapper_Init();
void SystemWrapper_ShutDown();
void SystemWrapper_RunFrame(double time);
BOOL SystemWrapper_LoadModule(char *interfacename, char *library, char *instancename = nullptr);
-void SystemWrapper_ExecuteString(char *command);
+void SystemWrapper_ExecuteString(const char *command);
void SystemWrapper_CommandForwarder();
int COM_BuildNumber();
diff --git a/rehlds/engine/common.cpp b/rehlds/engine/common.cpp
index 4384158..b9d1210 100644
--- a/rehlds/engine/common.cpp
+++ b/rehlds/engine/common.cpp
@@ -2393,7 +2393,7 @@ void EXT_FUNC COM_GetGameDir(char *szGameDir)
{
if (szGameDir)
{
- Q_snprintf(szGameDir, MAX_PATH - 1 , "%s", com_gamedir);
+ Q_snprintf(szGameDir, MAX_PATH, "%s", com_gamedir);
}
}
diff --git a/rehlds/engine/cvar.cpp b/rehlds/engine/cvar.cpp
index 37d18ed..9285fa2 100644
--- a/rehlds/engine/cvar.cpp
+++ b/rehlds/engine/cvar.cpp
@@ -430,11 +430,9 @@ NOXREF void Cvar_RemoveHudCvars(void)
const char *Cvar_IsMultipleTokens(const char *varname)
{
static char firstToken[516];
- int tokens;
char *name;
firstToken[0] = 0;
- tokens = 0;
name = (char *)varname;
name = COM_Parse(name);
diff --git a/rehlds/engine/decals.cpp b/rehlds/engine/decals.cpp
index ff382ea..975d7f9 100644
--- a/rehlds/engine/decals.cpp
+++ b/rehlds/engine/decals.cpp
@@ -538,15 +538,17 @@ void Decal_Init(void)
for (i = 0; i < ARRAYSIZE(pszPathID); i++)
{
hfile = FS_OpenPathID("decals.wad", "rb", pszPathID[i]);
-#ifdef REHLDS_FIXES
+
if (!hfile)
+ {
+#ifdef REHLDS_FIXES
if (found || i < ARRAYSIZE(pszPathID) - 1)
continue;
- else
#else
- if (i == 0 && !hfile)
+ if (i == 0)
#endif
- Sys_Error("%s: Couldn't find '%s' in \"%s\" search path\n", __func__, "decals.wad", pszPathID[i]);
+ Sys_Error("%s: Couldn't find '%s' in \"%s\" search path\n", __func__, "decals.wad", pszPathID[i]);
+ }
#ifdef REHLDS_FIXES
found = true;
diff --git a/rehlds/engine/delta.cpp b/rehlds/engine/delta.cpp
index 6f81baf..5a63b08 100644
--- a/rehlds/engine/delta.cpp
+++ b/rehlds/engine/delta.cpp
@@ -82,13 +82,13 @@ static delta_definition_t g_DeltaDataDefinition[] =
static delta_description_t g_MetaDescription[] =
{
- { DT_INTEGER, DELTA_D_DEF(fieldType), 1, 32, 1.0, 1.0, 0, 0, 0 },
- { DT_STRING, DELTA_D_DEF(fieldName), 1, 1, 1.0, 1.0, 0, 0, 0 },
- { DT_INTEGER, DELTA_D_DEF(fieldOffset), 1, 16, 1.0, 1.0, 0, 0, 0 },
- { DT_INTEGER, DELTA_D_DEF(fieldSize), 1, 8, 1.0, 1.0, 0, 0, 0 },
- { DT_INTEGER, DELTA_D_DEF(significant_bits), 1, 8, 1.0, 1.0, 0, 0, 0 },
- { DT_FLOAT, DELTA_D_DEF(premultiply), 1, 32, 4000.0, 1.0, 0, 0, 0 },
- { DT_FLOAT, DELTA_D_DEF(postmultiply), 1, 32, 4000.0, 1.0, 0, 0, 0 },
+ { DT_INTEGER, DELTA_D_DEF(fieldType), 1, 32, 1.0, 1.0, 0, {0, 0} },
+ { DT_STRING, DELTA_D_DEF(fieldName), 1, 1, 1.0, 1.0, 0, {0, 0} },
+ { DT_INTEGER, DELTA_D_DEF(fieldOffset), 1, 16, 1.0, 1.0, 0, {0, 0} },
+ { DT_INTEGER, DELTA_D_DEF(fieldSize), 1, 8, 1.0, 1.0, 0, {0, 0} },
+ { DT_INTEGER, DELTA_D_DEF(significant_bits), 1, 8, 1.0, 1.0, 0, {0, 0} },
+ { DT_FLOAT, DELTA_D_DEF(premultiply), 1, 32, 4000.0, 1.0, 0, {0, 0} },
+ { DT_FLOAT, DELTA_D_DEF(postmultiply), 1, 32, 4000.0, 1.0, 0, {0, 0} },
};
delta_t g_MetaDelta[] =
@@ -463,7 +463,7 @@ int DELTA_TestDelta(unsigned char *from, unsigned char *to, delta_t *pFields)
case DT_STRING:
st1 = (char*)&from[pTest->fieldOffset];
st2 = (char*)&to[pTest->fieldOffset];
- if (!(!*st1 && !*st2 || *st1 && *st2 && !Q_stricmp(st1, st2))) // Not sure why it is case insensitive, but it looks so
+ if (!((!*st1 && !*st2) || (*st1 && *st2 && !Q_stricmp(st1, st2)))) // Not sure why it is case insensitive, but it looks so
{
#ifndef REHLDS_FIXES
pTest->flags |= FDT_MARK;
@@ -558,7 +558,7 @@ void DELTA_MarkSendFields(unsigned char *from, unsigned char *to, delta_t *pFiel
case DT_STRING:
st1 = (char*)&from[pTest->fieldOffset];
st2 = (char*)&to[pTest->fieldOffset];
- if (!(!*st1 && !*st2 || *st1 && *st2 && !Q_stricmp(st1, st2))) // Not sure why it is case insensitive, but it looks so
+ if (!((!*st1 && !*st2) || (*st1 && *st2 && !Q_stricmp(st1, st2)))) // Not sure why it is case insensitive, but it looks so
pTest->flags |= FDT_MARK;
break;
default:
@@ -1239,7 +1239,7 @@ qboolean DELTA_ParseField(int count, delta_definition_t *pdefinition, delta_link
Sys_Error("%s: Expecting fieldname\n", __func__);
}
- Q_strncpy(pField->delta->fieldName, com_token, 31);
+ Q_strlcpy(pField->delta->fieldName, com_token);
pField->delta->fieldName[31] = 0;
pField->delta->fieldOffset = DELTA_FindOffset(count, pdefinition, com_token);
@@ -1454,8 +1454,7 @@ qboolean DELTA_ParseDescription(char *name, delta_t **ppdesc, char *pstream)
}
if (Q_stricmp(com_token, "none"))
{
- Q_strncpy(source, com_token, sizeof(source)-1);
- source[sizeof(source)-1] = 0;
+ Q_strlcpy(source, com_token);
// Parse custom encoder function name
pstream = COM_Parse(pstream);
@@ -1464,8 +1463,7 @@ qboolean DELTA_ParseDescription(char *name, delta_t **ppdesc, char *pstream)
Sys_Error("%s: Expecting encoder\n", __func__);
}
- Q_strncpy(encoder, com_token, sizeof(encoder)-1);
- encoder[sizeof(encoder)-1] = 0;
+ Q_strlcpy(encoder, com_token);
}
// Parse fields
@@ -1496,7 +1494,7 @@ qboolean DELTA_ParseDescription(char *name, delta_t **ppdesc, char *pstream)
if (encoder[0] != 0)
{
- Q_strncpy((*ppdesc)->conditionalencodename, encoder, sizeof((*ppdesc)->conditionalencodename) - 1);
+ Q_strlcpy((*ppdesc)->conditionalencodename, encoder);
(*ppdesc)->conditionalencodename[sizeof((*ppdesc)->conditionalencodename) - 1] = 0;
(*ppdesc)->conditionalencode = 0;
}
diff --git a/rehlds/engine/filesystem.cpp b/rehlds/engine/filesystem.cpp
index 7d01f81..12c4a5a 100644
--- a/rehlds/engine/filesystem.cpp
+++ b/rehlds/engine/filesystem.cpp
@@ -241,7 +241,7 @@ void CheckLiblistForFallbackDir(const char *pGameDir, bool bLanguage, const char
if (bLanguage && pLanguage)
{
- char baseDir[4096];
+ char baseDir[MAX_PATH];
char *tempPtr;
Q_snprintf(szTemp, 511, "%s/%s_%s", GetBaseDirectory(), szFallback, pLanguage);
@@ -283,7 +283,7 @@ void CheckLiblistForFallbackDir(const char *pGameDir, bool bLanguage, const char
if (Q_stricmp(szFallback, "valve"))
{
- const int BufLen = 128;
+ const int BufLen = 256;
char *szFileName = new char[BufLen];
Q_snprintf(szFileName, BufLen - 1, "Resource/%s_%%language%%.txt", szFallback);
@@ -298,7 +298,7 @@ void CheckLiblistForFallbackDir(const char *pGameDir, bool bLanguage, const char
int FileSystem_SetGameDirectory(const char *pDefaultDir, const char *pGameDir)
{
char temp[512];
- char language[256];
+ char language[128];
const char *pchLang;
g_pFileSystem->RemoveAllSearchPaths();
@@ -474,7 +474,7 @@ int FileSystem_AddFallbackGameDir(const char *pGameDir)
return 1;
}
-int FileSystem_Init(char *basedir, void *voidfilesystemFactory)
+int FileSystem_Init(const char *basedir, void *voidfilesystemFactory)
{
#ifdef REHLDS_CHECKS
Q_strncpy(s_pBaseDir, basedir, ARRAYSIZE(s_pBaseDir));
diff --git a/rehlds/engine/filesystem_.h b/rehlds/engine/filesystem_.h
index 198cf5b..f171400 100644
--- a/rehlds/engine/filesystem_.h
+++ b/rehlds/engine/filesystem_.h
@@ -52,5 +52,5 @@ int Host_GetVideoLevel(void);
void CheckLiblistForFallbackDir(const char *pGameDir, bool bLanguage, const char *pLanguage, bool bLowViolenceBuild_);
int FileSystem_SetGameDirectory(const char *pDefaultDir, const char *pGameDir);
int FileSystem_AddFallbackGameDir(const char *pGameDir);
-int FileSystem_Init(char *basedir, void *voidfilesystemFactory);
+int FileSystem_Init(const char *basedir, void *voidfilesystemFactory);
void FileSystem_Shutdown(void);
diff --git a/rehlds/engine/host.cpp b/rehlds/engine/host.cpp
index e6e2bf9..f30cfad 100644
--- a/rehlds/engine/host.cpp
+++ b/rehlds/engine/host.cpp
@@ -1041,7 +1041,7 @@ void Host_Version(void)
gpszVersionString[sizeof(gpszVersionString) - 1] = 0;
if (COM_CheckParm("-steam"))
{
- char szSteamVersionId[32];
+ char szSteamVersionId[16];
FS_GetInterfaceVersion(szSteamVersionId, sizeof(szSteamVersionId) - 1);
Q_snprintf(gpszVersionString, sizeof(gpszVersionString), "%s/%s", &com_token[Q_strlen("PatchVersion=")], szSteamVersionId);
gpszVersionString[sizeof(gpszVersionString) - 1] = 0;
diff --git a/rehlds/engine/host_cmd.cpp b/rehlds/engine/host_cmd.cpp
index 9cac571..d76815c 100644
--- a/rehlds/engine/host_cmd.cpp
+++ b/rehlds/engine/host_cmd.cpp
@@ -377,7 +377,7 @@ void Host_UpdateStats(void)
fscanf(pFile, "%d %s %c %d %d %d %d %d %lu %lu \t\t\t%lu %lu %lu %ld %ld %ld %ld %ld %ld %lu \t\t\t%lu %ld %lu %lu %lu %lu %lu %lu %lu %lu \t\t\t%lu %lu %lu %lu %lu %lu",
&dummy,
statFile,
- &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy,
+ (char *)&dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy,
&ctime,
&stime,
&dummy, &dummy, &dummy, &dummy, &dummy,
@@ -423,7 +423,12 @@ void GetStatsString(char *buf, int bufSize)
for (int i = 0; i < g_psvs.maxclients; i++)
{
host_client = &g_psvs.clients[i];
- if (!host_client->active && !host_client->connected && !host_client->spawned || host_client->fakeclient)
+
+ // Fake clients are ignored
+ if (host_client->fakeclient)
+ continue;
+
+ if (!host_client->active && !host_client->connected && !host_client->spawned)
continue;
players++;
diff --git a/rehlds/engine/iengine.h b/rehlds/engine/iengine.h
index 10b30f4..eaa5243 100644
--- a/rehlds/engine/iengine.h
+++ b/rehlds/engine/iengine.h
@@ -42,7 +42,7 @@ public:
virtual ~IEngine() {}
- virtual bool Load(bool dedicated, char *basedir, char *cmdline) = 0;
+ virtual bool Load(bool dedicated, const char *basedir, const char *cmdline) = 0;
virtual void Unload() = 0;
virtual void SetState(int iState) = 0;
virtual int GetState() = 0;
diff --git a/rehlds/engine/mathlib_sse.cpp b/rehlds/engine/mathlib_sse.cpp
index e99d85a..9342d01 100644
--- a/rehlds/engine/mathlib_sse.cpp
+++ b/rehlds/engine/mathlib_sse.cpp
@@ -48,10 +48,10 @@ const avec4_t deg2rad =
const aivec4_t negmask[4] =
{
- 0x80000000,
- 0x80000000,
- 0x80000000,
- 0x80000000
+ {0x80000000},
+ {0x80000000},
+ {0x80000000},
+ {0x80000000}
};
const aivec4_t negmask_1001 =
diff --git a/rehlds/engine/model.cpp b/rehlds/engine/model.cpp
index 11b3214..4c29ecc 100644
--- a/rehlds/engine/model.cpp
+++ b/rehlds/engine/model.cpp
@@ -152,7 +152,7 @@ model_t *Mod_FindName(qboolean trackCRC, const char *name)
if (mod->needload == NL_UNREFERENCED)
{
- if (!avail || mod->type != mod_alias && mod->type != mod_studio)
+ if (!avail || (mod->type != mod_alias && mod->type != mod_studio))
avail = mod;
}
}
@@ -1329,7 +1329,7 @@ void EXT_FUNC Mod_LoadBrushModel_internal(model_t *mod, void *buffer)
if (i < mod->numsubmodels - 1)
{
- char name[10];
+ char name[12];
Q_snprintf(name, ARRAYSIZE(name), "*%i", i + 1);
loadmodel = Mod_FindName(0, name);
diff --git a/rehlds/engine/net_chan.cpp b/rehlds/engine/net_chan.cpp
index 957676a..88c5bae 100644
--- a/rehlds/engine/net_chan.cpp
+++ b/rehlds/engine/net_chan.cpp
@@ -412,7 +412,7 @@ void Netchan_Transmit(netchan_t *chan, int length, byte *data)
// If it's not in-memory, then we'll need to copy it in frame the file handle.
if (pbuf->isfile && !pbuf->isbuffer) {
- char compressedfilename[MAX_PATH];
+ char compressedfilename[MAX_PATH+5]; // room for extension string
FileHandle_t hfile;
if (pbuf->iscompressed)
{
diff --git a/rehlds/engine/net_ws.cpp b/rehlds/engine/net_ws.cpp
index 76da8d5..219b73a 100644
--- a/rehlds/engine/net_ws.cpp
+++ b/rehlds/engine/net_ws.cpp
@@ -873,7 +873,7 @@ qboolean NET_QueuePacket(netsrc_t sock)
for (int protocol = 0; protocol < 1; protocol++)
#endif // _WIN32
{
- SOCKET net_socket;
+ SOCKET net_socket = INV_SOCK;
if (protocol == 0)
net_socket = ip_sockets[sock];
diff --git a/rehlds/engine/pr_cmds.cpp b/rehlds/engine/pr_cmds.cpp
index be18e51..c56eaec 100644
--- a/rehlds/engine/pr_cmds.cpp
+++ b/rehlds/engine/pr_cmds.cpp
@@ -384,7 +384,7 @@ void EXT_FUNC TraceSphere(const float *v1, const float *v2, int fNoMonsters, flo
void EXT_FUNC TraceModel(const float *v1, const float *v2, int hullNumber, edict_t *pent, TraceResult *ptr)
{
- int oldMovetype, oldSolid;
+ int oldMovetype = MOVETYPE_NONE, oldSolid = SOLID_NOT;
if (hullNumber < 0 || hullNumber > 3)
hullNumber = 0;
@@ -1280,7 +1280,10 @@ void EXT_FUNC EV_Playback(int flags, const edict_t *pInvoker, unsigned short eve
continue;
}
- if (cl == host_client && (flags & FEV_NOTHOST) && cl->lw || (flags & FEV_HOSTONLY) && cl->edict != pInvoker)
+ if ((flags & FEV_NOTHOST) && cl->lw && cl == host_client)
+ continue;
+
+ if ((flags & FEV_HOSTONLY) && cl->edict != pInvoker)
continue;
if (flags & FEV_RELIABLE)
diff --git a/rehlds/engine/sv_log.cpp b/rehlds/engine/sv_log.cpp
index 48e8c43..ccd0fb1 100644
--- a/rehlds/engine/sv_log.cpp
+++ b/rehlds/engine/sv_log.cpp
@@ -119,7 +119,7 @@ void Log_Open(void)
time_t ltime;
struct tm *today;
char szFileBase[MAX_PATH];
- char szTestFile[MAX_PATH];
+ char szTestFile[MAX_PATH+8]; // room for extra string
int i;
FileHandle_t fp;
char *temp;
diff --git a/rehlds/engine/sv_main.cpp b/rehlds/engine/sv_main.cpp
index 70ef0a2..a34d900 100644
--- a/rehlds/engine/sv_main.cpp
+++ b/rehlds/engine/sv_main.cpp
@@ -2059,7 +2059,9 @@ qboolean SV_CheckForDuplicateNames(char *userinfo, qboolean bIsReconnecting, int
return changed;
char newname[MAX_NAME];
- Q_snprintf(newname, sizeof(newname), "(%d)%-0.*s", ++dupc, 28, rawname);
+ const int maxLenDupName = MAX_NAME - (sizeof("(d)") - 1);
+
+ Q_snprintf(newname, sizeof(newname), "(%d)%.*s", ++dupc, maxLenDupName - 1, rawname);
#ifdef REHLDS_FIXES
// Fix possibly incorrectly cut UTF8 chars
@@ -5461,7 +5463,10 @@ void SV_PropagateCustomizations(void)
// For each active player
for (i = 0, pHost = g_psvs.clients; i < g_psvs.maxclients; i++, pHost++)
{
- if (!pHost->active && !pHost->spawned || pHost->fakeclient)
+ if (pHost->fakeclient)
+ continue;
+
+ if (!pHost->active && !pHost->spawned)
continue;
// Send each customization to current player
@@ -6590,7 +6595,10 @@ void SV_BanId_f(void)
for (int i = 0; i < g_psvs.maxclients; i++)
{
client_t *cl = &g_psvs.clients[i];
- if (!cl->active && !cl->connected && !cl->spawned || cl->fakeclient)
+ if (cl->fakeclient)
+ continue;
+
+ if (!cl->active && !cl->connected && !cl->spawned)
continue;
if (!Q_stricmp(SV_GetClientIDString(cl), idstring))
@@ -6663,7 +6671,10 @@ void SV_BanId_f(void)
for (int i = 0; i < g_psvs.maxclients; i++)
{
client_t *cl = &g_psvs.clients[i];
- if (!cl->active && !cl->connected && !cl->spawned || cl->fakeclient)
+ if (cl->fakeclient)
+ continue;
+
+ if (!cl->active && !cl->connected && !cl->spawned)
continue;
if (SV_CompareUserID(&cl->network_userid, id))
@@ -7325,7 +7336,10 @@ void SV_KickPlayer(int nPlayerSlot, int nReason)
Q_sprintf(rgchT, "%s was automatically disconnected\nfrom this secure server.\n", client->name);
for (int i = 0; i < g_psvs.maxclients; i++)
{
- if (!g_psvs.clients[i].active && !g_psvs.clients[i].spawned || g_psvs.clients[i].fakeclient)
+ if (g_psvs.clients[i].fakeclient)
+ continue;
+
+ if (!g_psvs.clients[i].active && !g_psvs.clients[i].spawned)
continue;
MSG_WriteByte(&g_psvs.clients[i].netchan.message, svc_centerprint);
@@ -7522,7 +7536,7 @@ void SV_BeginFileDownload_f(void)
{
if (host_client->fully_connected ||
sv_send_resources.value == 0.0f ||
- sv_downloadurl.string != NULL && sv_downloadurl.string[0] != 0 && Q_strlen(sv_downloadurl.string) <= 128 && sv_allow_dlfile.value == 0.0f ||
+ (sv_downloadurl.string != NULL && sv_downloadurl.string[0] != 0 && Q_strlen(sv_downloadurl.string) <= 128 && sv_allow_dlfile.value == 0.0f) ||
Netchan_CreateFileFragments(TRUE, &host_client->netchan, name) == 0)
{
SV_FailDownload(name);
@@ -8166,17 +8180,17 @@ typedef struct GameToAppIDMapItem_s
} GameToAppIDMapItem_t;
GameToAppIDMapItem_t g_GameToAppIDMap[11] = {
- 0x0A, "cstrike",
- 0x14, "tfc",
- 0x1E, "dod",
- 0x28, "dmc",
- 0x32, "gearbox",
- 0x3C, "ricochet",
- 0x46, "valve",
- 0x50, "czero",
- 0x64, "czeror",
- 0x82, "bshift",
- 0x96, "cstrike_beta",
+ { 0x0A, "cstrike" },
+ { 0x14, "tfc" },
+ { 0x1E, "dod" },
+ { 0x28, "dmc" },
+ { 0x32, "gearbox" },
+ { 0x3C, "ricochet" },
+ { 0x46, "valve" },
+ { 0x50, "czero" },
+ { 0x64, "czeror" },
+ { 0x82, "bshift" },
+ { 0x96, "cstrike_beta" },
};
int GetGameAppID(void)
diff --git a/rehlds/engine/sv_phys.cpp b/rehlds/engine/sv_phys.cpp
index 8f2be63..8fff595 100644
--- a/rehlds/engine/sv_phys.cpp
+++ b/rehlds/engine/sv_phys.cpp
@@ -1255,7 +1255,7 @@ void PF_WaterMove(edict_t *pSelf)
if (!(flags & (FL_IMMUNE_WATER | FL_GODMODE)))
{
- if ((flags & FL_SWIM) && (waterlevel < drownlevel) || (waterlevel >= drownlevel))
+ if (((flags & FL_SWIM) && waterlevel < drownlevel) || (waterlevel >= drownlevel))
{
if (pSelf->v.air_finished < g_psv.time && pSelf->v.pain_finished < g_psv.time)
{
diff --git a/rehlds/engine/sv_upld.cpp b/rehlds/engine/sv_upld.cpp
index 63a266e..e28a0e3 100644
--- a/rehlds/engine/sv_upld.cpp
+++ b/rehlds/engine/sv_upld.cpp
@@ -173,7 +173,10 @@ void SV_Customization(client_t *pPlayer, resource_t *pResource, qboolean bSkipPl
// Send resource to all other active players
for (i = 0, pHost = g_psvs.clients; i < g_psvs.maxclients; i++, pHost++)
{
- if (!pHost->active && !pHost->spawned || pHost->fakeclient)
+ if (pHost->fakeclient)
+ continue;
+
+ if (!pHost->active && !pHost->spawned)
continue;
if (pHost == pPlayer && bSkipPlayer)
diff --git a/rehlds/engine/sv_user.cpp b/rehlds/engine/sv_user.cpp
index 93f7308..f859302 100644
--- a/rehlds/engine/sv_user.cpp
+++ b/rehlds/engine/sv_user.cpp
@@ -28,11 +28,6 @@
#include "precompiled.h"
-typedef struct command_s
-{
- char *command;
-} command_t;
-
sv_adjusted_positions_t truepositions[MAX_CLIENTS];
qboolean g_balreadymoved;
@@ -47,9 +42,9 @@ edict_t *sv_player;
qboolean nofind;
#if defined(SWDS) && defined(REHLDS_FIXES)
-command_t clcommands[] = { "status", "name", "kill", "pause", "spawn", "new", "sendres", "dropclient", "kick", "ping", "dlfile", "setinfo", "sendents", "fullupdate", "setpause", "unpause", NULL };
+const char *clcommands[] = { "status", "name", "kill", "pause", "spawn", "new", "sendres", "dropclient", "kick", "ping", "dlfile", "setinfo", "sendents", "fullupdate", "setpause", "unpause", NULL };
#else
-command_t clcommands[23] = { "status", "god", "notarget", "fly", "name", "noclip", "kill", "pause", "spawn", "new", "sendres", "dropclient", "kick", "ping", "dlfile", "nextdl", "setinfo", "showinfo", "sendents", "fullupdate", "setpause", "unpause", NULL };
+const char *clcommands[23] = { "status", "god", "notarget", "fly", "name", "noclip", "kill", "pause", "spawn", "new", "sendres", "dropclient", "kick", "ping", "dlfile", "nextdl", "setinfo", "showinfo", "sendents", "fullupdate", "setpause", "unpause", NULL };
#endif
cvar_t sv_edgefriction = { "edgefriction", "2", FCVAR_SERVER, 0.0f, NULL };
@@ -560,7 +555,10 @@ void SV_AddLinksToPM_(areanode_t *node, float *pmove_mins, float *pmove_maxs)
if ((check->v.flags & FL_CLIENT) && check->v.health <= 0.0)
continue;
- if (check->v.mins[2] == 0.0 && check->v.maxs[2] == 1.0 || Length(check->v.size) == 0.0)
+ if (check->v.mins[2] == 0.0 && check->v.maxs[2] == 1.0)
+ continue;
+
+ if (Length(check->v.size) == 0.0)
continue;
fmin = check->v.absmin;
@@ -1031,11 +1029,11 @@ void SV_RunCmd(usercmd_t *ucmd, int random_seed)
int SV_ValidateClientCommand(char *pszCommand)
{
- char *p;
+ const char *p;
int i = 0;
COM_Parse(pszCommand);
- while ((p = clcommands[i].command) != NULL)
+ while ((p = clcommands[i]) != NULL)
{
if (!Q_stricmp(com_token, p))
{
@@ -1742,7 +1740,7 @@ void SV_ParseCvarValue2(client_t *cl)
Con_DPrintf("Cvar query response: name:%s, request ID %d, cvar:%s, value:%s\n", cl->name, requestID, cvarName, value);
}
-void EXT_FUNC SV_HandleClientMessage_api(IGameClient* client, int8 opcode) {
+void EXT_FUNC SV_HandleClientMessage_api(IGameClient* client, uint8 opcode) {
client_t* cl = client->GetClient();
if (opcode < clc_bad || opcode > clc_cvarvalue2)
{
diff --git a/rehlds/engine/sv_user.h b/rehlds/engine/sv_user.h
index 8da3360..e5fa453 100644
--- a/rehlds/engine/sv_user.h
+++ b/rehlds/engine/sv_user.h
@@ -35,8 +35,6 @@
const int CMD_MAXBACKUP = 64;
-typedef struct command_s command_t;
-
typedef struct sv_adjusted_positions_s
{
int active;
@@ -59,7 +57,6 @@ typedef struct clc_func_s
} clc_func_t;
extern edict_t *sv_player;
-extern command_t clcommands[23];
extern sv_adjusted_positions_t truepositions[MAX_CLIENTS];
extern qboolean g_balreadymoved;
diff --git a/rehlds/engine/sys_dll.cpp b/rehlds/engine/sys_dll.cpp
index 86d2ae3..add30da 100644
--- a/rehlds/engine/sys_dll.cpp
+++ b/rehlds/engine/sys_dll.cpp
@@ -490,7 +490,7 @@ void NORETURN Sys_Error(const char *error, ...)
#endif // SWDS
//Allahu akbar!
- int *null = 0;
+ volatile int *null = 0;
*null = 0;
exit(-1);
}
diff --git a/rehlds/engine/sys_dll2.cpp b/rehlds/engine/sys_dll2.cpp
index 75aee66..3f2b09e 100644
--- a/rehlds/engine/sys_dll2.cpp
+++ b/rehlds/engine/sys_dll2.cpp
@@ -455,7 +455,7 @@ void Sys_ShowProgressTicks(char *specialProgressMsg)
}
}
-int Sys_InitGame(char *lpOrgCmdLine, char *pBaseDir, void *pwnd, int bIsDedicated)
+int Sys_InitGame(const char *lpOrgCmdLine, const char *pBaseDir, void *pwnd, int bIsDedicated)
{
host_initialized = FALSE;
@@ -640,7 +640,7 @@ NOXREF int BuildMapCycleListHints(char **hints)
}
*/
-bool CDedicatedServerAPI::Init(char *basedir, char *cmdline, CreateInterfaceFn launcherFactory, CreateInterfaceFn filesystemFactory)
+bool CDedicatedServerAPI::Init(const char *basedir, const char *cmdline, CreateInterfaceFn launcherFactory, CreateInterfaceFn filesystemFactory)
{
dedicated_ = (IDedicatedExports *)launcherFactory(VENGINE_DEDICATEDEXPORTS_API_VERSION, NULL);
if (!dedicated_)
diff --git a/rehlds/engine/sys_dll2.h b/rehlds/engine/sys_dll2.h
index 74a247b..1c62ebc 100644
--- a/rehlds/engine/sys_dll2.h
+++ b/rehlds/engine/sys_dll2.h
@@ -58,7 +58,7 @@ private:
char m_OrigCmd[1024];
public:
- EXT_FUNC virtual bool Init(char *basedir, char *cmdline, CreateInterfaceFn launcherFactory, CreateInterfaceFn filesystemFactory);
+ EXT_FUNC virtual bool Init(const char *basedir, const char *cmdline, CreateInterfaceFn launcherFactory, CreateInterfaceFn filesystemFactory);
EXT_FUNC virtual int Shutdown();
EXT_FUNC virtual bool RunFrame();
EXT_FUNC virtual void AddConsoleText(char *text);
@@ -93,7 +93,7 @@ NOXREF void Sys_ShutdownLauncherInterface();
void Sys_InitAuthentication();
NOXREF void Sys_ShutdownAuthentication();
void Sys_ShowProgressTicks(char *specialProgressMsg);
-int Sys_InitGame(char *lpOrgCmdLine, char *pBaseDir, void *pwnd, int bIsDedicated);
+int Sys_InitGame(const char *lpOrgCmdLine, const char *pBaseDir, void *pwnd, int bIsDedicated);
void Sys_ShutdownGame();
void ClearIOStates();
diff --git a/rehlds/engine/sys_engine.cpp b/rehlds/engine/sys_engine.cpp
index ed10b35..beef432 100644
--- a/rehlds/engine/sys_engine.cpp
+++ b/rehlds/engine/sys_engine.cpp
@@ -81,7 +81,7 @@ void ForceReloadProfile()
}
}
-bool CEngine::Load(bool dedicated, char *basedir, char *cmdline)
+bool CEngine::Load(bool dedicated, const char *basedir, const char *cmdline)
{
bool success = false;
SetState(DLL_ACTIVE);
diff --git a/rehlds/engine/sys_engine.h b/rehlds/engine/sys_engine.h
index cedb535..805b89f 100644
--- a/rehlds/engine/sys_engine.h
+++ b/rehlds/engine/sys_engine.h
@@ -56,7 +56,7 @@ public:
CEngine();
virtual ~CEngine();
- virtual bool Load(bool dedicated, char *rootDir, char *cmdLine);
+ virtual bool Load(bool dedicated, const char *rootDir, const char *cmdLine);
virtual void Unload();
virtual void SetState(int iState);
virtual int GetState();
diff --git a/rehlds/engine/tmessage.cpp b/rehlds/engine/tmessage.cpp
index 2e518bc..5bc8a15 100644
--- a/rehlds/engine/tmessage.cpp
+++ b/rehlds/engine/tmessage.cpp
@@ -44,17 +44,19 @@ const char *gNetworkMessageNames[MAX_NETMESSAGE] =
client_textmessage_t gNetworkTextMessage[MAX_NETMESSAGE] =
{
- 0, // effect
- 255, 255, 255, 255,
- 255, 255, 255, 255,
- -1.0f, // x
- -1.0f, // y
- 0.0f, // fadein
- 0.0f, // fadeout
- 0.0f, // holdtime
- 0.0f, // fxTime,
- NETWORK_MESSAGE1,// pName message name.
- gNetworkTextMessageBuffer[0] // pMessage
+ {
+ 0, // effect
+ 255, 255, 255, 255,
+ 255, 255, 255, 255,
+ -1.0f, // x
+ -1.0f, // y
+ 0.0f, // fadein
+ 0.0f, // fadeout
+ 0.0f, // holdtime
+ 0.0f, // fxTime,
+ NETWORK_MESSAGE1,// pName message name.
+ gNetworkTextMessageBuffer[0] // pMessage
+ }
};
char* EXT_FUNC memfgets(unsigned char *pMemFile, int fileSize, int *pFilePos, char *pBuffer, int bufferSize)
diff --git a/rehlds/engine/unicode_strtools.cpp b/rehlds/engine/unicode_strtools.cpp
index 2bd19bd..818145b 100644
--- a/rehlds/engine/unicode_strtools.cpp
+++ b/rehlds/engine/unicode_strtools.cpp
@@ -565,22 +565,22 @@ int Q_UChar32ToUTF8(uchar32 uVal, char * pUTF8Out) {
else if (uVal <= 0x7FF)
{
*pUTF8Out = (uVal >> 6) | 0xC0;
- pUTF8Out[1] = uVal & 0x3F | 0x80;
+ pUTF8Out[1] = (uVal & 0x3F) | 0x80;
return 2;
}
else if (uVal <= 0xFFFF)
{
- *pUTF8Out = (uVal >> 12) | 0xE0;
- pUTF8Out[2] = uVal & 0x3F | 0x80;
- pUTF8Out[1] = (uVal >> 6) & 0x3F | 0x80;
+ *pUTF8Out = ((uVal >> 12)) | 0xE0;
+ pUTF8Out[2] = (uVal & 0x3F) | 0x80;
+ pUTF8Out[1] = (((uVal >> 6)) & 0x3F) | 0x80;
return 3;
}
else
{
- *pUTF8Out = (uVal >> 18) & 7 | 0xF0;
- pUTF8Out[1] = (uVal >> 12) & 0x3F | 0x80;
- pUTF8Out[3] = uVal & 0x3F | 0x80;
- pUTF8Out[2] = (uVal >> 6) & 0x3F | 0x80;
+ *pUTF8Out = ((uVal >> 18) & 7) | 0xF0;
+ pUTF8Out[1] = ((uVal >> 12) & 0x3F) | 0x80;
+ pUTF8Out[3] = (uVal & 0x3F) | 0x80;
+ pUTF8Out[2] = ((uVal >> 6) & 0x3F) | 0x80;
return 4;
}
}
@@ -600,7 +600,7 @@ int __cdecl Q_UChar32ToUTF16(uchar32 uVal, uchar16 *pUTF16Out)
}
else
{
- pUTF16Out[1] = uVal & 0x3FF | 0xDC00;
+ pUTF16Out[1] = (uVal & 0x3FF) | 0xDC00;
pUTF16Out[0] = ((uVal - 0x10000) >> 10) | 0xD800;
return 2;
}
diff --git a/rehlds/engine/vid_null.cpp b/rehlds/engine/vid_null.cpp
index 500eba6..391f09a 100644
--- a/rehlds/engine/vid_null.cpp
+++ b/rehlds/engine/vid_null.cpp
@@ -71,7 +71,7 @@ void R_InitTextures()
{
for (int y = 0; y < texSize; y++, dest++)
{
- if (x < (texSize / 2) == y < (texSize / 2))
+ if ((x < (texSize / 2)) == (y < (texSize / 2)))
*dest = -1;
else
*dest = 0;
diff --git a/rehlds/filesystem/CMakeLists.txt b/rehlds/filesystem/CMakeLists.txt
new file mode 100644
index 0000000..cc26eee
--- /dev/null
+++ b/rehlds/filesystem/CMakeLists.txt
@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 3.1)
+project(rehlds CXX)
+
+add_subdirectory(FileSystem_Stdio)
diff --git a/rehlds/filesystem/FileSystem_Stdio/CMakeLists.txt b/rehlds/filesystem/FileSystem_Stdio/CMakeLists.txt
new file mode 100644
index 0000000..9e22885
--- /dev/null
+++ b/rehlds/filesystem/FileSystem_Stdio/CMakeLists.txt
@@ -0,0 +1,93 @@
+cmake_minimum_required(VERSION 3.1)
+project(filesystem_stdio CXX)
+
+option(DEBUG "Build with debug information." OFF)
+option(USE_INTEL_COMPILER "Use the Intel compiler." OFF)
+option(USE_CLANG_COMPILER "Use the Clang compiler." OFF)
+
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+set(WRAP_FUNCS_LIST
+ "scandir" "opendir" "freopen" "fopen" "fopen64" "open" "open64" "creat"
+ "access" "stat" "lstat" "__xstat" "__lxstat" "__xstat64" "__lxstat64"
+ "chmod" "chown" "lchown" "unlink" "symlink" "link" "mknod" "mount"
+ "mkfifo" "rename" "utime" "utimes" "mkdir" "rmdir"
+)
+
+if (USE_INTEL_COMPILER)
+ set(CMAKE_C_COMPILER "/opt/intel/bin/icc")
+ set(CMAKE_CXX_COMPILER "/opt/intel/bin/icpc")
+elseif (USE_CLANG_COMPILER)
+ set(CMAKE_C_COMPILER "/usr/bin/clang")
+ set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
+endif()
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions")
+
+if (DEBUG)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O3 -ggdb")
+else()
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O3")
+endif()
+
+if (USE_INTEL_COMPILER)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp")
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel -no-intel-extensions")
+else()
+ # 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.
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=generic -msse3\
+ -fpermissive\
+ -Wno-unknown-pragmas -Wno-unused-result -Wno-unused-variable -Wno-unused-function\
+ -Wno-write-strings -Wno-sign-compare")
+
+ if (NOT USE_CLANG_COMPILER)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-stringop-truncation -Wno-class-memaccess")
+ endif()
+endif()
+
+foreach(f ${WRAP_FUNCS_LIST})
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-wrap,${f}")
+endforeach()
+
+set(PROJECT_SRC_DIR
+ "${PROJECT_SOURCE_DIR}/src"
+ "${PROJECT_SOURCE_DIR}/../.."
+)
+
+set(PROJECT_PUBLIC_DIR
+ "${PROJECT_SOURCE_DIR}/../../common"
+ "${PROJECT_SOURCE_DIR}/../../public"
+ "${PROJECT_SOURCE_DIR}/../../public/rehlds"
+)
+
+set(FILESYSTEM_STDIO_SRCS
+ "src/BaseFileSystem.cpp"
+ "src/filesystem_helpers.cpp"
+ "src/FileSystem_Stdio.cpp"
+ "src/linux_support.cpp"
+ "src/pathmatch.cpp"
+ "src/public_amalgamation.cpp"
+)
+
+include_directories(
+ ${PROJECT_SRC_DIR}
+ ${PROJECT_PUBLIC_DIR}
+)
+
+add_definitions(
+ -D_LINUX
+ -DLINUX
+ -D_GLIBCXX_USE_CXX11_ABI=0
+ -D_strdup=strdup
+ -D_stricmp=strcasecmp
+ -D_strnicmp=strncasecmp
+ -D_vsnprintf=vsnprintf
+ -D_snprintf=snprintf
+ -D_unlink=unlink
+)
+
+add_library(filesystem_stdio SHARED ${FILESYSTEM_STDIO_SRCS})
+set_target_properties(filesystem_stdio PROPERTIES PREFIX "" COMPILE_FLAGS "-m32" LINK_FLAGS "-m32" POSITION_INDEPENDENT_CODE ON)
+target_link_libraries(filesystem_stdio dl)
diff --git a/rehlds/filesystem/FileSystem_Stdio/src/BaseFileSystem.cpp b/rehlds/filesystem/FileSystem_Stdio/src/BaseFileSystem.cpp
index 7591428..85c04cb 100644
--- a/rehlds/filesystem/FileSystem_Stdio/src/BaseFileSystem.cpp
+++ b/rehlds/filesystem/FileSystem_Stdio/src/BaseFileSystem.cpp
@@ -1132,8 +1132,8 @@ bool IsWildCardMatch(const char *wildcardString, const char *stringToCheck)
// we only want to advance the pointers if we successfully assigned
// both of our char variables, so we'll do it here rather than in the
// loop condition itself
- *stringToCheck++;
- *wildcardString++;
+ stringToCheck++;
+ wildcardString++;
// if this isn't a case-sensitive match, make both chars uppercase
wcChar = toupper(wcChar);
@@ -1148,7 +1148,7 @@ bool IsWildCardMatch(const char *wildcardString, const char *stringToCheck)
// until we've either found a match or the string has
// ended
if (starMatchesZero)
- *stringToCheck--;
+ stringToCheck--;
while (*stringToCheck)
{
@@ -1501,7 +1501,7 @@ void CBaseFileSystem::Warning(FileWarningLevel_t level, const char *fmt, ...)
#ifdef _WIN32
OutputDebugString(warningtext);
#else
- fprintf(stderr, warningtext);
+ fprintf(stderr, "%s", warningtext);
#endif
}
}
@@ -1654,15 +1654,15 @@ bool CBaseFileSystem::CSearchPath::PackFileLessFunc(CPackFileEntry const &src1,
}
CBaseFileSystem::CSearchPath::CSearchPath() :
- m_PackFiles(0, MAX_ENTRY_PATH, CSearchPath::PackFileLessFunc),
m_Path(CUtlSymbol("")),
m_bIsMapPath(false),
m_bIsPackFile(false),
- m_bAllowWrite(true),
m_lPackFileTime(0),
+ m_hPackFile(nullptr),
m_nNumPackFiles(0),
m_iCurSearchFile(0),
- m_hPackFile(nullptr)
+ m_bAllowWrite(true),
+ m_PackFiles(0, MAX_ENTRY_PATH, CSearchPath::PackFileLessFunc)
{
}
diff --git a/rehlds/filesystem/FileSystem_Stdio/src/filesystem_helpers.cpp b/rehlds/filesystem/FileSystem_Stdio/src/filesystem_helpers.cpp
index 097fd60..67aa18e 100644
--- a/rehlds/filesystem/FileSystem_Stdio/src/filesystem_helpers.cpp
+++ b/rehlds/filesystem/FileSystem_Stdio/src/filesystem_helpers.cpp
@@ -172,7 +172,7 @@ void NORETURN FileSystem_SysError(const char *fmt, ...)
fprintf(fl, "%s\n", string);
fclose(fl);
- int *null = 0;
+ volatile int *null = 0;
*null = 0;
exit(-1);
}
diff --git a/rehlds/hookers/HLTV/Core/DeltaEx.cpp b/rehlds/hookers/HLTV/Core/DeltaEx.cpp
index 4630e76..3c2c58c 100644
--- a/rehlds/hookers/HLTV/Core/DeltaEx.cpp
+++ b/rehlds/hookers/HLTV/Core/DeltaEx.cpp
@@ -63,13 +63,13 @@ delta_definition_t g_DeltaDataDefinition[] =
delta_description_t g_MetaDescription[] =
{
- { DT_INTEGER, DELTA_D_DEF(fieldType), 1, 32, 1.0, 1.0, 0, 0, 0 },
- { DT_STRING, DELTA_D_DEF(fieldName), 1, 1, 1.0, 1.0, 0, 0, 0 },
- { DT_INTEGER, DELTA_D_DEF(fieldOffset), 1, 16, 1.0, 1.0, 0, 0, 0 },
- { DT_INTEGER, DELTA_D_DEF(fieldSize), 1, 8, 1.0, 1.0, 0, 0, 0 },
- { DT_INTEGER, DELTA_D_DEF(significant_bits), 1, 8, 1.0, 1.0, 0, 0, 0 },
- { DT_FLOAT, DELTA_D_DEF(premultiply), 1, 32, 4000.0, 1.0, 0, 0, 0 },
- { DT_FLOAT, DELTA_D_DEF(postmultiply), 1, 32, 4000.0, 1.0, 0, 0, 0 }
+ { DT_INTEGER, DELTA_D_DEF(fieldType), 1, 32, 1.0, 1.0, 0, {0, 0} },
+ { DT_STRING, DELTA_D_DEF(fieldName), 1, 1, 1.0, 1.0, 0, {0, 0} },
+ { DT_INTEGER, DELTA_D_DEF(fieldOffset), 1, 16, 1.0, 1.0, 0, {0, 0} },
+ { DT_INTEGER, DELTA_D_DEF(fieldSize), 1, 8, 1.0, 1.0, 0, {0, 0} },
+ { DT_INTEGER, DELTA_D_DEF(significant_bits), 1, 8, 1.0, 1.0, 0, {0, 0} },
+ { DT_FLOAT, DELTA_D_DEF(premultiply), 1, 32, 4000.0, 1.0, 0, {0, 0} },
+ { DT_FLOAT, DELTA_D_DEF(postmultiply), 1, 32, 4000.0, 1.0, 0, {0, 0} }
};
namespace Delta {
diff --git a/rehlds/public/engine_hlds_api.h b/rehlds/public/engine_hlds_api.h
index 007237e..8ae9b01 100644
--- a/rehlds/public/engine_hlds_api.h
+++ b/rehlds/public/engine_hlds_api.h
@@ -39,7 +39,7 @@
class IDedicatedServerAPI : public IBaseInterface
{
public:
- virtual bool Init(char *basedir, char *cmdline, CreateInterfaceFn launcherFactory, CreateInterfaceFn filesystemFactory) = 0;
+ virtual bool Init(const char *basedir, const char *cmdline, CreateInterfaceFn launcherFactory, CreateInterfaceFn filesystemFactory) = 0;
virtual int Shutdown() = 0;
virtual bool RunFrame() = 0;
virtual void AddConsoleText(char *text) = 0;
diff --git a/rehlds/public/idedicatedexports.h b/rehlds/public/idedicatedexports.h
index 2444e22..4e20b03 100644
--- a/rehlds/public/idedicatedexports.h
+++ b/rehlds/public/idedicatedexports.h
@@ -34,7 +34,7 @@ class IDedicatedExports : public IBaseInterface
{
public:
virtual ~IDedicatedExports() {};
- virtual void Sys_Printf(char *text) = 0;
+ virtual void Sys_Printf(const char *text) = 0;
};
#define VENGINE_DEDICATEDEXPORTS_API_VERSION "VENGINE_DEDICATEDEXPORTS_API_VERSION001"
diff --git a/rehlds/public/interface.cpp b/rehlds/public/interface.cpp
index d5a35ad..3394746 100644
--- a/rehlds/public/interface.cpp
+++ b/rehlds/public/interface.cpp
@@ -130,7 +130,7 @@ CSysModule *Sys_LoadModule(const char *pModuleName)
HMODULE hDLL = LoadLibrary(pModuleName);
#else
HMODULE hDLL = nullptr;
- char szAbsoluteModuleName[1024];
+ char szAbsoluteModuleName[2048];
if (pModuleName[0] != '/')
{
char szCwd[1024];
@@ -150,7 +150,7 @@ CSysModule *Sys_LoadModule(const char *pModuleName)
if (!hDLL)
{
- char str[512];
+ char str[2048+6]; // room for extension string
#if defined(_WIN32)
_snprintf(str, sizeof(str), "%s.dll", pModuleName);
diff --git a/rehlds/public/rehlds/rehlds_api.h b/rehlds/public/rehlds/rehlds_api.h
index 9f4d51f..506d474 100644
--- a/rehlds/public/rehlds/rehlds_api.h
+++ b/rehlds/public/rehlds/rehlds_api.h
@@ -108,8 +108,8 @@ typedef IVoidHookChain IRehldsHook_ClientConnected;
typedef IVoidHookChainRegistry IRehldsHookRegistry_ClientConnected;
//HandleNetCommand
-typedef IVoidHookChain IRehldsHook_HandleNetCommand;
-typedef IVoidHookChainRegistry IRehldsHookRegistry_HandleNetCommand;
+typedef IVoidHookChain IRehldsHook_HandleNetCommand;
+typedef IVoidHookChainRegistry IRehldsHookRegistry_HandleNetCommand;
//Mod_LoadBrushModel
typedef IVoidHookChain IRehldsHook_Mod_LoadBrushModel;
diff --git a/rehlds/public/tier0/characterset.cpp b/rehlds/public/tier0/characterset.cpp
index 9088b64..e179e2e 100644
--- a/rehlds/public/tier0/characterset.cpp
+++ b/rehlds/public/tier0/characterset.cpp
@@ -44,7 +44,7 @@ void CharacterSetBuild(characterset_t *pSetBuffer, const char *pszSetString)
while (pszSetString[i])
{
- pSetBuffer->set[pszSetString[i]] = 1;
+ pSetBuffer->set[(unsigned)pszSetString[i]] = 1;
i++;
}
}
diff --git a/rehlds/public/tier0/dbg.cpp b/rehlds/public/tier0/dbg.cpp
index df1c6ce..dfd73d8 100644
--- a/rehlds/public/tier0/dbg.cpp
+++ b/rehlds/public/tier0/dbg.cpp
@@ -140,7 +140,7 @@ SpewRetval_t _SpewMessage(SpewType_t spewType, char const* pMsgFormat, va_list
/* Printf the file and line for warning + assert only... */
int len = 0;
- if ((spewType == SPEW_ASSERT))
+ if (spewType == SPEW_ASSERT)
{
len = sprintf(pTempBuffer, "%s (%d) : ", s_pFileName, s_Line);
}
@@ -149,7 +149,7 @@ SpewRetval_t _SpewMessage(SpewType_t spewType, char const* pMsgFormat, va_list
len += vsprintf(&pTempBuffer[len], pMsgFormat, args);
// Add \n for warning and assert
- if ((spewType == SPEW_ASSERT))
+ if (spewType == SPEW_ASSERT)
{
len += sprintf(&pTempBuffer[len], "\n");
}
diff --git a/rehlds/public/utlbuffer.cpp b/rehlds/public/utlbuffer.cpp
index 69ba751..13aec0e 100644
--- a/rehlds/public/utlbuffer.cpp
+++ b/rehlds/public/utlbuffer.cpp
@@ -1,4 +1,4 @@
-//========= Copyright © 1996-2001, Valve LLC, All rights reserved. ============
+//========= Copyright 1996-2001, Valve LLC, 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
@@ -205,7 +205,7 @@ int CUtlBuffer::VaScanf(char const* pFmt, va_list list)
char c;
char* pEnd;
- while (c = *pFmt++)
+ while ((c = *pFmt++))
{
// Stop if we hit the end of the buffer
if (m_Get >= Size())
diff --git a/rehlds/public/utlrbtree.h b/rehlds/public/utlrbtree.h
index 45bed14..67463dc 100644
--- a/rehlds/public/utlrbtree.h
+++ b/rehlds/public/utlrbtree.h
@@ -234,11 +234,12 @@ protected:
// Constructor, Destructor
template
CUtlRBTree::CUtlRBTree(int growSize, int initSize, LessFunc_t lessfunc) :
- m_Elements(growSize, initSize),
m_LessFunc(lessfunc),
+ m_Elements(growSize, initSize),
m_Root(InvalidIndex()),
- m_NumElements(0), m_TotalElements(0),
- m_FirstFree(InvalidIndex())
+ m_NumElements(0),
+ m_FirstFree(InvalidIndex()),
+ m_TotalElements(0)
{
}
diff --git a/rehlds/rehlds/jitasm.h b/rehlds/rehlds/jitasm.h
index a33113f..13cb32e 100644
--- a/rehlds/rehlds/jitasm.h
+++ b/rehlds/rehlds/jitasm.h
@@ -322,7 +322,7 @@ namespace detail
bool operator==(const Opd& rhs) const
{
- if ((opdtype_ & O_TYPE_TYPE_MASK) != (rhs.opdtype_ & O_TYPE_TYPE_MASK) || opdsize_ != opdsize_) {return false;}
+ if ((opdtype_ & O_TYPE_TYPE_MASK) != (rhs.opdtype_ & O_TYPE_TYPE_MASK) || opdsize_ != rhs.opdsize_) {return false;}
if (IsReg()) {return reg_ == rhs.reg_ && reg_assignable_ == rhs.reg_assignable_;}
if (IsMem()) {return base_ == rhs.base_ && index_ == rhs.index_ && scale_ == rhs.scale_ && disp_ == rhs.disp_ && addrsize_ == rhs.addrsize_;}
if (IsImm()) {return imm_ == rhs.imm_;}
diff --git a/rehlds/rehlds/platform.cpp b/rehlds/rehlds/platform.cpp
index 21a08f6..d6e8a79 100644
--- a/rehlds/rehlds/platform.cpp
+++ b/rehlds/rehlds/platform.cpp
@@ -102,7 +102,7 @@ int CSimplePlatform::setsockopt(SOCKET s, int level, int optname, const char* op
#ifdef _WIN32
return setsockopt_v11(s, level, optname, optval, optlen);
#else
- return setsockopt(s, level, optname, optval, optlen);
+ return ::setsockopt(s, level, optname, optval, optlen);
#endif
}
@@ -213,6 +213,8 @@ void NORETURN rehlds_syserror(const char* fmt, ...) {
fclose(fl);
//TerminateProcess(GetCurrentProcess(), 1);
- *((int*)NULL) = 0;
+ volatile int *null = 0;
+ *null = 0;
+
while (true);
}
diff --git a/rehlds/rehlds/rehlds_api_impl.h b/rehlds/rehlds/rehlds_api_impl.h
index 7c106c7..3af1e94 100644
--- a/rehlds/rehlds/rehlds_api_impl.h
+++ b/rehlds/rehlds/rehlds_api_impl.h
@@ -103,8 +103,8 @@ typedef IVoidHookChainImpl CRehldsHook_ClientConnected;
typedef IVoidHookChainRegistryImpl CRehldsHookRegistry_ClientConnected;
//HandleNetCommand
-typedef IVoidHookChainImpl CRehldsHook_HandleNetCommand;
-typedef IVoidHookChainRegistryImpl CRehldsHookRegistry_HandleNetCommand;
+typedef IVoidHookChainImpl CRehldsHook_HandleNetCommand;
+typedef IVoidHookChainRegistryImpl CRehldsHookRegistry_HandleNetCommand;
//Mod_LoadBrushModel
typedef IVoidHookChainImpl CRehldsHook_Mod_LoadBrushModel;
diff --git a/rehlds/version/appversion.sh b/rehlds/version/appversion.sh
new file mode 100755
index 0000000..7ced0d1
--- /dev/null
+++ b/rehlds/version/appversion.sh
@@ -0,0 +1,158 @@
+#!/bin/bash
+
+init()
+{
+ SOURCE_DIR=$@
+ GIT_DIR=$SOURCE_DIR/..
+ VERSION_FILE=$GIT_DIR/gradle.properties
+ APPVERSION_FILE=$SOURCE_DIR/version/appversion.h
+
+ if test -z "`git --version`"; then
+ echo "Please install git client"
+ echo "sudo apt-get install git"
+ exit -1
+ fi
+
+ # Read old version
+ if [ -e $APPVERSION_FILE ]; then
+ OLD_VERSION=$(cat $APPVERSION_FILE | grep -wi '#define APP_VERSION' | sed -e 's/#define APP_VERSION[ \t\r\n\v\f]\+\(.*\)/\1/i' -e 's/\r//g')
+ if [ $? -ne 0 ]; then
+ OLD_VERSION=""
+ else
+ # Remove quotes
+ OLD_VERSION=$(echo $OLD_VERSION | xargs)
+ fi
+ fi
+
+ # Get major, minor and maintenance information from gradle.properties
+ MAJOR=$(sed -nr -e '/majorVersion/ s/.*\= *//p' "$VERSION_FILE" | tr -d '\n\r')
+ if [ $? -ne 0 -o "$MAJOR" = "" ]; then
+ MAJOR=0
+ fi
+
+ MINOR=$(sed -nr -e '/minorVersion/ s/.*\= *//p' "$VERSION_FILE" | tr -d '\n\r')
+ if [ $? -ne 0 -o "$MINOR" = "" ]; then
+ MINOR=0
+ fi
+
+ MAINTENANCE=$(sed -nr -e '/maintenanceVersion/ s/.*\= *//p' "$VERSION_FILE" | tr -d '\n\r')
+ if [ $? -ne 0 -o "$MAINTENANCE" = "" ]; then
+ MAINTENANCE=0
+ fi
+
+ BRANCH_NAME=$(git -C "$GIT_DIR/" rev-parse --abbrev-ref HEAD)
+ if [ $? -ne 0 -o "$BRANCH_NAME" = "" ]; then
+ BRANCH_NAME=master
+ fi
+
+ COMMIT_COUNT=$(git -C "$GIT_DIR/" rev-list --count $BRANCH_NAME)
+ if [ $? -ne 0 -o "$COMMIT_COUNT" = "" ]; then
+ COMMIT_COUNT=0
+ fi
+
+ #
+ # Configure remote url repository
+ #
+ # Get remote name by current branch
+ BRANCH_REMOTE=$(git -C "$GIT_DIR/" config branch.$BRANCH_NAME.remote)
+ if [ $? -ne 0 -o "$BRANCH_REMOTE" = "" ]; then
+ BRANCH_REMOTE=origin
+ fi
+
+ # Get commit id
+ COMMIT_SHA=$(git -C "$GIT_DIR/" rev-parse --verify HEAD)
+ COMMIT_SHA=${COMMIT_SHA:0:7}
+
+ # Get remote url
+ COMMIT_URL=$(git -C "$GIT_DIR/" config remote.$BRANCH_REMOTE.url)
+
+ URL_CONSTRUCT=0
+
+ if [[ "$COMMIT_URL" == *"git@"* ]]; then
+ URL_CONSTRUCT=1
+
+ # Strip prefix 'git@'
+ COMMIT_URL=${COMMIT_URL#git@}
+
+ # Strip postfix '.git'
+ COMMIT_URL=${COMMIT_URL%.git}
+
+ # Replace ':' to '/'
+ COMMIT_URL=${COMMIT_URL/:/\/}
+
+ elif [[ "$COMMIT_URL" == *"https://"* ]]; then
+ URL_CONSTRUCT=1
+
+ # Strip prefix 'https://'
+ COMMIT_URL=${COMMIT_URL#https://}
+
+ # Strip postfix '.git'
+ COMMIT_URL=${COMMIT_URL%.git}
+ fi
+
+ if test "$URL_CONSTRUCT" -eq 1; then
+ # Append extra string
+ if [[ "$COMMIT_URL" == *"bitbucket.org"* ]]; then
+ COMMIT_URL=$(echo https://$COMMIT_URL/commits/)
+ else
+ COMMIT_URL=$(echo https://$COMMIT_URL/commit/)
+ fi
+ fi
+
+ #
+ # Detect local modifications
+ #
+ if [ `git -C "$GIT_DIR/" ls-files -m | wc -l` = 0 ]; then
+ MODIFIED=
+ else
+ MODIFIED=+m
+ fi
+
+ NEW_VERSION="$MAJOR.$MINOR.$MAINTENANCE.$COMMIT_COUNT-dev$MODIFIED"
+
+ # Update appversion.h if version has changed or modifications/mixed revisions detected
+ if [ "$NEW_VERSION" != "$OLD_VERSION" ]; then
+ update_appversion
+ fi
+}
+
+update_appversion()
+{
+ day=$(date +%m)
+ year=$(date +%Y)
+ hours=$(date +%H:%M:%S)
+ month=$(LANG=en_us_88591; date +"%b")
+
+ # Write appversion.h
+ echo Updating appversion.h, new version is '"'$NEW_VERSION'"', the old one was $OLD_VERSION
+
+ echo -e "#ifndef __APPVERSION_H__\r">"$APPVERSION_FILE"
+ echo -e "#define __APPVERSION_H__\r">>"$APPVERSION_FILE"
+ echo -e "\r">>"$APPVERSION_FILE"
+ echo -e "//\r">>"$APPVERSION_FILE"
+ echo -e "// This file is generated automatically.\r">>"$APPVERSION_FILE"
+ echo -e "// Don't edit it.\r">>"$APPVERSION_FILE"
+ echo -e "//\r">>"$APPVERSION_FILE"
+ echo -e "\r">>"$APPVERSION_FILE"
+ echo -e "// Version defines\r">>"$APPVERSION_FILE"
+ echo -e '#define APP_VERSION "'$NEW_VERSION'"\r'>>"$APPVERSION_FILE"
+
+ echo -e "#define APP_VERSION_C $MAJOR,$MINOR,$MAINTENANCE,$COMMIT_COUNT\r">>"$APPVERSION_FILE"
+ echo -e '#define APP_VERSION_STRD "'$MAJOR.$MINOR.$MAINTENANCE.$COMMIT_COUNT'"\r'>>"$APPVERSION_FILE"
+ echo -e "#define APP_VERSION_FLAGS 0x0L\r">>"$APPVERSION_FILE"
+ echo -e "\r">>"$APPVERSION_FILE"
+ echo -e '#define APP_COMMIT_DATE "'$month $day $year'"\r'>>"$APPVERSION_FILE"
+ echo -e '#define APP_COMMIT_TIME "'$hours'"\r'>>"$APPVERSION_FILE"
+ echo -e "\r">>"$APPVERSION_FILE"
+
+ echo -e '#define APP_COMMIT_SHA "'$COMMIT_SHA'"\r'>>"$APPVERSION_FILE"
+ echo -e '#define APP_COMMIT_URL "'$COMMIT_URL'"\r'>>"$APPVERSION_FILE"
+ echo -e "\r">>"$APPVERSION_FILE"
+ echo -e "#endif //__APPVERSION_H__\r">>"$APPVERSION_FILE"
+}
+
+# Initialise
+init $*
+
+# Exit normally
+exit 0