diff --git a/README.md b/README.md index 71ea2be2..821bf2a1 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ There are several software requirements for building Regamedll_CS:
gradlew --max-workers=1 clean buildRelease* For faster building without unit tests use this:exclamation:
gradlew --max-workers=1 clean buildFixes-On Linux (ICC): +#### On Linux (ICC):
./gradlew --max-workers=1 clean buildRelease* For faster building without unit tests use this:exclamation:
./gradlew --max-workers=1 clean buildFixes-On Linux (GCC): +#### On Linux (Clang): +
./gradlew --max-workers=1 clean -PuseClang buildRelease+ +* For faster building without unit tests use this:exclamation: +
./gradlew --max-workers=1 clean -PuseClang buildFixes+ +#### On Linux (GCC):
./gradlew --max-workers=1 clean -PuseGcc buildRelease* For faster building without unit tests use this:exclamation: @@ -142,6 +148,20 @@ On Linux (GCC): Compiled binaries will be placed in the build/binaries/ directory +### Simplified building using CMake 3.1 and later +#### On Windows: +
Open solution msvc\ReGameDLL.sln and build it+ +#### On Linux: +* Run script `regamedll/compile.sh` +* Options using `regamedll/compile.sh -D[option]=[ON or OFF]` (without square brackets) +
+DEBUG - Enables debugging mode +USE_INTEL_COMPILER - Switch main compiler to ICC +USE_CLANG_COMPILER - Switch main compiler to Clang +USE_STATIC_LIBSTDC - Enables static linking library libstdc++ ++ ### Credits Thanks to the project [ReHLDS](https://github.com/dreamstalker/rehlds) ( ReGameDLL_CS was created on the basis of ReHLDS ) diff --git a/regamedll/CMakeLists.txt b/regamedll/CMakeLists.txt new file mode 100644 index 00000000..ff6431d5 --- /dev/null +++ b/regamedll/CMakeLists.txt @@ -0,0 +1,148 @@ +cmake_minimum_required(VERSION 3.1) +project(regamedll CXX) + +option(DEBUG "Build debug application." 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} -fno-exceptions") + +if (USE_INTEL_COMPILER OR USE_CLANG_COMPILER) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fasm-blocks") +endif() + +if (DEBUG) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -ggdb -O3 -Wall -ffunction-sections -fdata-sections") +else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O3 -fno-rtti -ffunction-sections -fdata-sections") +endif() + +if (USE_INTEL_COMPILER) + 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\ + -Wno-write-strings -Wno-invalid-offsetof\ + -Wno-unused-variable -Wno-unused-function\ + -Wno-unused-result -Wno-invalid-offsetof\ + -fpermissive -Wno-switch -Wno-enum-compare\ + -Wno-unknown-pragmas -Wno-unused-value") + + if (USE_CLANG_COMPILER) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}\ + -Wno-unused-local-typedef\ + -Wno-unused-private-field\ + -fno-strict-vtable-pointers\ + -Wno-overloaded-virtual") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}\ + -Wno-unused-local-typedefs\ + -Wno-sign-compare\ + -Wno-strict-aliasing\ + -Wno-unused-but-set-variable\ + -fno-devirtualize") + 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}/dlls" + "${PROJECT_SOURCE_DIR}/game_shared" + "${PROJECT_SOURCE_DIR}/pm_shared" + "${PROJECT_SOURCE_DIR}/regamedll" +) + +set(PROJECT_PUBLIC_DIR + "${PROJECT_SOURCE_DIR}/public" + "${PROJECT_SOURCE_DIR}/public/regamedll" +) + +set(ENGINE_SRCS + "engine/unicode_strtools.cpp" +) + +file(GLOB SHARED_SRCS + "game_shared/bot/*.cpp" + "game_shared/*.cpp" + "pm_shared/*.cpp" + "regamedll/*.cpp" + "public/FileSystem.cpp" + "public/interface.cpp" + "public/MemPool.cpp" + "version/version.cpp" +) + +list(REMOVE_ITEM SHARED_SRCS EXCLUDE "${PROJECT_SOURCE_DIR}/regamedll/classes_dummy.cpp") + +file(GLOB GAMEDLL_SRCS + "dlls/*.cpp" + "dlls/API/*.cpp" + "dlls/addons/*.cpp" + "dlls/wpn_shared/*.cpp" + "dlls/bot/*.cpp" + "dlls/bot/states/*.cpp" + "dlls/hostage/*.cpp" + "dlls/hostage/states/*.cpp" +) + +include_directories( + ${PROJECT_SRC_DIR} + ${PROJECT_PUBLIC_DIR} +) + +link_directories(${PROJECT_SOURCE_DIR}/lib/linux32) + +add_definitions( + -DREGAMEDLL_FIXES + -DBUILD_LATEST + -DREGAMEDLL_ADD + -DREGAMEDLL_API + -DUNICODE_FIXES + -DCLIENT_WEAPONS + -DUSE_QSTRING + -DGNUC + -DPOSIX + -D_LINUX + -DLINUX + -D_stricmp=strcasecmp + -D_strnicmp=strncasecmp + -D_strdup=strdup + -D_unlink=unlink + -D_vsnprintf=vsnprintf + -D_write=write + -D_close=close + -D_access=access + -D_vsnwprintf=vswprintf +) + +add_library(regamedll SHARED ${appversion.sh} ${GAMEDLL_SRCS} ${ENGINE_SRCS} ${SHARED_SRCS}) +set_property(TARGET regamedll PROPERTY LIBRARY_OUTPUT_NAME cs) +add_custom_target(appversion COMMAND ${PROJECT_SOURCE_DIR}/version/appversion.sh ${PROJECT_SOURCE_DIR} regamedll) +set_target_properties(regamedll PROPERTIES PREFIX "" COMPILE_FLAGS "-m32" LINK_FLAGS "-m32" POSITION_INDEPENDENT_CODE ON) +target_link_libraries(regamedll dl aelf32) +add_dependencies(regamedll appversion) diff --git a/regamedll/build.gradle b/regamedll/build.gradle index 0f6ec68e..6964226f 100644 --- a/regamedll/build.gradle +++ b/regamedll/build.gradle @@ -92,6 +92,7 @@ void postEvaluate(NativeBinarySpec b) { void setupToolchain(NativeBinarySpec b) { boolean useGcc = project.hasProperty("useGcc") + boolean useClang = project.hasProperty("useClang") boolean unitTestExecutable = b.component.name.endsWith('_tests') boolean regamedllFixes = b.flavor.name.contains('regamedllFixes') @@ -121,7 +122,7 @@ void setupToolchain(NativeBinarySpec b) cfg.compilerOptions.enhancedInstructionsSet = EnhancedInstructionsSet.DISABLED } else { - cfg.compilerOptions.args '/Oi', '/GF', '/GS-', '/GR-' + cfg.compilerOptions.args '/Oi', '/GF', '/GS', '/GR' } cfg.projectLibpath(project, '/lib') @@ -129,7 +130,7 @@ void setupToolchain(NativeBinarySpec b) } else if (cfg instanceof GccToolchainConfig) { - if (!useGcc) + if (!useGcc && !useClang) { cfg.compilerOptions.pchConfig = new GccToolchainConfig.PrecompilerHeaderOptions( enabled: true, @@ -150,10 +151,17 @@ void setupToolchain(NativeBinarySpec b) '_access' : 'access' ]) - if (useGcc) { + if (useGcc || useClang) { // 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. - cfg.compilerOptions.args '-mtune=generic', '-msse3', '-Wno-write-strings', '-Wno-invalid-offsetof', '-fpermissive', '-fno-devirtualize' + cfg.compilerOptions.args '-mtune=generic', '-msse3', '-Wno-write-strings', '-Wno-invalid-offsetof', '-fpermissive', '-Wno-switch', '-Wno-unused-value', '-Wno-enum-compare' + + if (useGcc) { + cfg.compilerOptions.args '-fno-devirtualize' + else { + cfg.compilerOptions.args '-fno-strict-vtable-pointers', '-Wno-overloaded-virtual' + } + } else { cfg.compilerOptions.args '-Qoption,cpp,--treat_func_as_string_literal_cpp' @@ -169,7 +177,7 @@ void setupToolchain(NativeBinarySpec b) cfg.singleDefines 'BUILD_STATIC_LIBSTDC' } - cfg.compilerOptions.args '-g0', '-fno-rtti', '-fno-exceptions' + cfg.compilerOptions.args '-g0', '-fno-exceptions' cfg.projectLibpath(project, '/lib/linux32') cfg.extraLibs 'dl', 'm', 'aelf32' } @@ -276,7 +284,10 @@ model { toolChains { visualCpp(VisualCpp) { } - if (project.hasProperty("useGcc")) { + if (project.hasProperty("useClang")) { + clang(Clang) + } + else if (project.hasProperty("useGcc")) { gcc(Gcc) } else { icc(Icc) @@ -343,11 +354,18 @@ task buildFixes { } } +task buildDebug { + dependsOn binaries.withType(SharedLibraryBinarySpec).matching { + SharedLibraryBinarySpec blib -> blib.buildable && blib.buildType.name == 'debug' && blib.flavor.name == 'regamedllFixes' && blib.component.name == 'regamedll_mp_gamedll' + } +} + buildFixes.finalizedBy(buildFinalize); +buildDebug.finalizedBy(buildFinalize); buildRelease.finalizedBy(buildFinalize); gradle.taskGraph.whenReady { graph -> - if (!graph.hasTask(buildFixes)) { + if (!graph.hasTask(buildFixes) && !graph.hasTask(buildDebug)) { return; } @@ -396,7 +414,7 @@ tasks.clean.doLast { task generateAppVersion { - RegamedllVersionInfo verInfo = (RegamedllVersionInfo) rootProject.regamedllVersionInfo + RegamedllVersionInfo verInfo = (RegamedllVersionInfo)rootProject.regamedllVersionInfo def tplFile = project.file('version/appversion.vm') def renderedFile = project.file('version/appversion.h') diff --git a/regamedll/compile.sh b/regamedll/compile.sh new file mode 100644 index 00000000..c75a2eed --- /dev/null +++ b/regamedll/compile.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +rm -rf build +mkdir build +cd build +cmake ../ $* +make diff --git a/regamedll/dlls/func_break.cpp b/regamedll/dlls/func_break.cpp index 238febf9..fa819f83 100644 --- a/regamedll/dlls/func_break.cpp +++ b/regamedll/dlls/func_break.cpp @@ -397,7 +397,7 @@ void CBreakable::DamageSound() int pitch; float fvol; char *rgpsz[6]; - int i; + int i = 0; int material = m_Material; if (RANDOM_LONG(0, 2)) diff --git a/regamedll/dlls/hostage/hostage_improv.cpp b/regamedll/dlls/hostage/hostage_improv.cpp index 9045a891..a70d2c76 100644 --- a/regamedll/dlls/hostage/hostage_improv.cpp +++ b/regamedll/dlls/hostage/hostage_improv.cpp @@ -201,6 +201,7 @@ void CHostageImprov::MoveTowards(const Vector &pos, float deltaT) switch (m_moveType) { case Stopped: + default: accelRate = 0; break; case Walking: diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index 4af41c6f..1d75039b 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -2098,7 +2098,6 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib) case 1: { UTIL_ScreenFade(this, Vector(0, 0, 0), 3, 3, 255, (FFADE_OUT | FFADE_STAYOUT)); - break; } case 2: @@ -2116,7 +2115,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib) { CBasePlayer* pObserver = UTIL_PlayerByIndex(i); - if (pObserver == this || pObserver && pObserver->IsObservingPlayer(this)) + if (pObserver == this || (pObserver && pObserver->IsObservingPlayer(this))) { UTIL_ScreenFade(pObserver, Vector(0, 0, 0), 1, 4, 255, (FFADE_OUT)); } @@ -2677,9 +2676,6 @@ void EXT_FUNC CBasePlayer::__API_HOOK(SetAnimation)(PLAYER_ANIM playerAnim) animDesired = LookupActivity(ACT_DIE_BACKSHOT); m_iThrowDirection = THROW_HITVEL; break; - case 3: - animDesired = LookupActivity(ACT_DIESIMPLE); - break; case 4: animDesired = LookupActivity(ACT_DIEBACKWARD); m_iThrowDirection = THROW_HITVEL; @@ -2698,6 +2694,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(SetAnimation)(PLAYER_ANIM playerAnim) animDesired = LookupActivity(ACT_DIE_HEADSHOT); break; default: + animDesired = LookupActivity(ACT_DIESIMPLE); break; } break; @@ -2750,11 +2747,10 @@ void EXT_FUNC CBasePlayer::__API_HOOK(SetAnimation)(PLAYER_ANIM playerAnim) break; } default: - { animDesired = LookupActivity(ACT_DIESIMPLE); break; - } } + if (pev->flags & FL_DUCKING) { animDesired = LookupSequence("crouch_die"); @@ -4349,7 +4345,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(PreThink)() #ifdef REGAMEDLL_FIXES IsAlive() && #endif - m_flIdleCheckTime <= (double)gpGlobals->time || m_flIdleCheckTime == 0.0f) + (m_flIdleCheckTime <= (double)gpGlobals->time || m_flIdleCheckTime == 0.0f)) { // check every 5 seconds m_flIdleCheckTime = gpGlobals->time + 5.0; diff --git a/regamedll/dlls/saverestore.cpp b/regamedll/dlls/saverestore.cpp index 0522ce8f..a8e63d12 100644 --- a/regamedll/dlls/saverestore.cpp +++ b/regamedll/dlls/saverestore.cpp @@ -282,8 +282,8 @@ extern "C" { inline unsigned _rotr(unsigned val, int shift) { - register unsigned lobit; - register unsigned num = val; + unsigned lobit; + unsigned num = val; shift &= 0x1f; diff --git a/regamedll/dlls/sound.cpp b/regamedll/dlls/sound.cpp index 31099871..57605f7f 100644 --- a/regamedll/dlls/sound.cpp +++ b/regamedll/dlls/sound.cpp @@ -772,7 +772,7 @@ void CAmbientGeneric::KeyValue(KeyValueData *pkvd) // lfotype else if (FStrEq(pkvd->szKeyName, "lfotype")) { - m_dpv.lfotype = (LowFreqOsc)Q_atoi(pkvd->szValue); + m_dpv.lfotype = Q_atoi(pkvd->szValue); if (m_dpv.lfotype > 4) m_dpv.lfotype = LFO_TRIANGLE; diff --git a/regamedll/dlls/sound.h b/regamedll/dlls/sound.h index 7c876f53..d2f0b41a 100644 --- a/regamedll/dlls/sound.h +++ b/regamedll/dlls/sound.h @@ -38,7 +38,7 @@ const int MAX_SENTENCE_DPV_RESET = 27; // Max number of dynamic pitch volumes const float MAX_ANNOUNCE_MINS = 2.25f; const float MIN_ANNOUNCE_MINS = 0.25f; -enum LowFreqOsc : int +enum { LFO_OFF = 0, LFO_SQUARE, // Square @@ -75,7 +75,7 @@ typedef struct dynpitchvol int fadeout; // Volume fade out time 0 - 100 // Low Frequency Oscillator - LowFreqOsc lfotype; // 0) off 1) square 2) triangle 3) random + int lfotype; // 0) off 1) square 2) triangle 3) random int lforate; // 0 - 1000, how fast lfo osciallates int lfomodpitch; // 0-100 mod of current pitch. 0 is off. diff --git a/regamedll/dlls/soundent.cpp b/regamedll/dlls/soundent.cpp index 4825e6d3..de8980b8 100644 --- a/regamedll/dlls/soundent.cpp +++ b/regamedll/dlls/soundent.cpp @@ -238,7 +238,7 @@ void CSoundEnt::Initialize() int CSoundEnt::ISoundsInList(int iListType) { int i; - int iThisSound; + int iThisSound = SOUNDLIST_EMPTY; if (iListType == SOUNDLISTTYPE_FREE) { @@ -251,6 +251,7 @@ int CSoundEnt::ISoundsInList(int iListType) else { ALERT(at_console, "Unknown Sound List Type!\n"); + iThisSound = iListType; } if (iThisSound == SOUNDLIST_EMPTY) diff --git a/regamedll/engine/unicode_strtools.cpp b/regamedll/engine/unicode_strtools.cpp index d20118c3..d19c92f0 100644 --- a/regamedll/engine/unicode_strtools.cpp +++ b/regamedll/engine/unicode_strtools.cpp @@ -563,7 +563,7 @@ int Q_UChar32ToUTF8(uchar32 uVal, char *pUTF8Out) if (uVal <= 0xFFFF) { pUTF8Out[0] = (unsigned char)(uVal >> 12) | 0xE0; - pUTF8Out[1] = (unsigned char)(uVal >> 6) & 0x3F | 0x80; + pUTF8Out[1] = (unsigned char)((uVal >> 6) & 0x3F) | 0x80; pUTF8Out[2] = (unsigned char)(uVal & 0x3F) | 0x80; return 3; } diff --git a/regamedll/game_shared/bot/nav_file.cpp b/regamedll/game_shared/bot/nav_file.cpp index 9c486026..1e8bf717 100644 --- a/regamedll/game_shared/bot/nav_file.cpp +++ b/regamedll/game_shared/bot/nav_file.cpp @@ -331,7 +331,7 @@ void CNavArea::Load(SteamFile *file, unsigned int version) // Load hiding spots // load number of hiding spots - unsigned char hidingSpotCount; + unsigned char hidingSpotCount = 0; file->Read(&hidingSpotCount, sizeof(unsigned char)); if (version == 1) @@ -366,13 +366,13 @@ void CNavArea::Load(SteamFile *file, unsigned int version) file->Read(&m_approachCount, sizeof(unsigned char)); // load approach area info (IDs) - unsigned char type; + unsigned char type = 0; for (int a = 0; a < m_approachCount; a++) { file->Read(&m_approach[a].here.id, sizeof(unsigned int)); file->Read(&m_approach[a].prev.id, sizeof(unsigned int)); - file->Read(&type, sizeof(unsigned char) ); + file->Read(&type, sizeof(unsigned char)); m_approach[a].prevToHereHow = (NavTraverseType)type; file->Read(&m_approach[a].next.id, sizeof(unsigned int)); @@ -398,7 +398,7 @@ void CNavArea::Load(SteamFile *file, unsigned int version) file->Read(&encounter.path.to.x, 3 * sizeof(float)); // read list of spots along this path - unsigned char spotCount; + unsigned char spotCount = 0; file->Read(&spotCount, sizeof(unsigned char)); for (int s = 0; s < spotCount; s++) @@ -418,7 +418,7 @@ void CNavArea::Load(SteamFile *file, unsigned int version) file->Read(&encounter.from.id, sizeof(unsigned int)); - unsigned char dir; + unsigned char dir = 0; file->Read(&dir, sizeof(unsigned char)); encounter.fromDir = static_cast