From 655693582afb4608655bb625249f989150fe9b50 Mon Sep 17 00:00:00 2001 From: ds Date: Fri, 13 Nov 2020 19:16:56 +0300 Subject: [PATCH] Switch build to msvc for windows. Switch build to clang for linux. Mingw binaries isn't working with vanilla hlds / listenserver. And i'm too lazy to debug them. For consistency reason, linux switched clang, so we're only have clang for linux & osx and msvc for windows. --- .github/workflows/build.yml | 10 +-- inc/engine.h | 3 + meson.build | 10 ++- src/engine.cpp | 125 ++++++++++++------------------------ src/linkage.cpp | 44 ++++++++++++- version_script.lds | 1 + 6 files changed, 99 insertions(+), 94 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 19e5d93..ad3cd93 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,12 +8,6 @@ jobs: runs-on: self-hosted steps: - - name: Runner Cleanup - shell: bash - run: | - echo "Cleaning up previous run" - rm -rf "${{ github.workspace }}/*" - - uses: actions/checkout@v2 with: submodules: true @@ -22,9 +16,9 @@ jobs: - name: Setup Meson shell: bash run: | - meson setup build_x86_win32 --cross-file=/actions/meson/linux-mingw-w64-32bit.txt + meson setup build_x86_win32 --cross-file=/actions/meson/windows-msvc-32bit.txt -Db_vscrt=mt meson setup build_x86_macos --cross-file=/actions/meson/darwin-clang-32bit.txt - meson setup build_x86_linux + CXX=clang meson setup build_x86_linux - name: Build Bot shell: bash diff --git a/inc/engine.h b/inc/engine.h index 82d5316..fd1f52d 100644 --- a/inc/engine.h +++ b/inc/engine.h @@ -213,6 +213,9 @@ public: // this function is checking that pointed by ent pointer obstacle, can be destroyed bool isShootableBreakable (edict_t *ent); + // print the version to server console on startup + void printBotVersion (); + // public inlines public: // get the current time on server diff --git a/meson.build b/meson.build index 461970e..e4a4e11 100644 --- a/meson.build +++ b/meson.build @@ -197,7 +197,15 @@ if isWindows and (isVC or isIntel) ] if isOptimize - ccflags += '/GL' + ccflags += [ + '/GL', + '/arch:SSE2', + '/GS-', + '/Ob2', + '/Oy', + '/Oi' + ] + ldflags += '/LTCG' endif diff --git a/src/engine.cpp b/src/engine.cpp index 38fd7e9..1123e3b 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -825,48 +825,6 @@ bool Game::postload () { // initialize weapons conf.initWeapons (); - // print game detection info - auto displayCSVersion = [&] () { - String gameVersionStr; - StringArray gameVersionFlags; - - if (is (GameFlags::Legacy)) { - gameVersionStr.assign ("Legacy"); - } - else if (is (GameFlags::ConditionZero)) { - gameVersionStr.assign ("Condition Zero"); - } - else if (is (GameFlags::Modern)) { - gameVersionStr.assign ("v1.6"); - } - - if (is (GameFlags::Xash3D)) { - gameVersionStr.append (" @ Xash3D Engine"); - - if (is (GameFlags::Mobility)) { - gameVersionStr.append (" Mobile"); - } - gameVersionStr.replace ("Legacy", "1.6 Limited"); - } - - if (is (GameFlags::HasBotVoice)) { - gameVersionFlags.push ("BotVoice"); - } - - if (is (GameFlags::ReGameDLL)) { - gameVersionFlags.push ("ReGameDLL"); - } - - if (is (GameFlags::HasFakePings)) { - gameVersionFlags.push ("FakePing"); - } - - if (is (GameFlags::Metamod)) { - gameVersionFlags.push ("Metamod"); - } - ctrl.msg ("\n%s v%s successfully loaded for game: Counter-Strike %s.\n\tFlags: %s.\n", product.name, product.version, gameVersionStr, gameVersionFlags.empty () ? "None" : String::join (gameVersionFlags, ", ")); - }; - if (plat.android) { m_gameFlags |= (GameFlags::Xash3D | GameFlags::Mobility | GameFlags::HasBotVoice | GameFlags::ReGameDLL); @@ -878,7 +836,6 @@ bool Game::postload () { if (!m_gameLib.load (gamedll)) { logger.fatal ("Unable to load gamedll \"%s\". Exiting... (gamedir: %s)", gamedll, getRunningModName ()); } - displayCSVersion (); } else { bool binaryLoaded = loadCSBinary (); @@ -886,7 +843,6 @@ bool Game::postload () { if (!binaryLoaded && !is (GameFlags::Metamod)) { logger.fatal ("Mod that you has started, not supported by this bot (gamedir: %s)", getRunningModName ()); } - displayCSVersion (); if (is (GameFlags::Metamod)) { m_gameLib.unload (); @@ -1026,6 +982,47 @@ bool Game::isShootableBreakable (edict_t *ent) { return false; } +void Game::printBotVersion () { + String gameVersionStr; + StringArray gameVersionFlags; + + if (is (GameFlags::Legacy)) { + gameVersionStr.assign ("Legacy"); + } + else if (is (GameFlags::ConditionZero)) { + gameVersionStr.assign ("Condition Zero"); + } + else if (is (GameFlags::Modern)) { + gameVersionStr.assign ("v1.6"); + } + + if (is (GameFlags::Xash3D)) { + gameVersionStr.append (" @ Xash3D Engine"); + + if (is (GameFlags::Mobility)) { + gameVersionStr.append (" Mobile"); + } + gameVersionStr.replace ("Legacy", "1.6 Limited"); + } + + if (is (GameFlags::HasBotVoice)) { + gameVersionFlags.push ("BotVoice"); + } + + if (is (GameFlags::ReGameDLL)) { + gameVersionFlags.push ("ReGameDLL"); + } + + if (is (GameFlags::HasFakePings)) { + gameVersionFlags.push ("FakePing"); + } + + if (is (GameFlags::Metamod)) { + gameVersionFlags.push ("Metamod"); + } + ctrl.msg ("\n%s v%s successfully loaded for game: Counter-Strike %s.\n\tFlags: %s.\n", product.name, product.version, gameVersionStr, gameVersionFlags.empty () ? "None" : String::join (gameVersionFlags, ", ")); +} + void LightMeasure::initializeLightstyles () { // this function initializes lighting information... @@ -1204,43 +1201,3 @@ float LightMeasure::getLightLevel (const Vector &point) { float LightMeasure::getSkyColor () { return static_cast (Color (sv_skycolor_r.int_ (), sv_skycolor_g.int_ (), sv_skycolor_b.int_ ()).avg ()); } - -DETOUR_RETURN EntityLinkage::lookup (SharedLibrary::Handle module, const char *function) { - static const auto &gamedll = game.lib ().handle (); - static const auto &self = m_self.handle (); - - const auto resolve = [&] (SharedLibrary::Handle handle) { - return reinterpret_cast (m_dlsym (static_cast (handle), function)); - }; - - // if requested module is yapb module, put in cache the looked up symbol - if (self != module || (plat.win32 && (static_cast (reinterpret_cast (function) >> 16) & 0xffff) == 0)) { - return resolve (module); - } - - if (m_exports.has (function)) { - return m_exports[function]; - } - auto botAddr = resolve (self); - - if (!botAddr) { - auto gameAddr = resolve (gamedll); - - if (gameAddr) { - return m_exports[function] = gameAddr; - } - } - else { - return m_exports[function] = botAddr; - } - return nullptr; -} - -void EntityLinkage::initialize () { - if (plat.arm) { - return; - } - - m_dlsym.install (reinterpret_cast (EntityLinkage::replacement), true); - m_self.locate (&engfuncs); -} diff --git a/src/linkage.cpp b/src/linkage.cpp index 86dd269..6a201e0 100644 --- a/src/linkage.cpp +++ b/src/linkage.cpp @@ -120,6 +120,9 @@ CR_EXPORT int GetEntityAPI (gamefuncs_t *table, int) { conf.loadMainConfig (true); conf.adjustWeaponPrices (); + // print info about dll + game.printBotVersion (); + if (game.is (GameFlags::Metamod)) { RETURN_META (MRES_IGNORED); } @@ -793,7 +796,6 @@ CR_EXPORT int GetNewDLLFunctions (newgamefuncs_t *table, int *interfaceVersion) logger.error ("Could not resolve symbol \"%s\" in the game dll. Continuing...", __FUNCTION__); return HLFalse; } - dllfuncs.newapi_table = table; return HLTrue; } @@ -945,5 +947,45 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t api_GiveFnptrsToDll (functionTable, glob); } +DETOUR_RETURN EntityLinkage::lookup (SharedLibrary::Handle module, const char *function) { + static const auto &gamedll = game.lib ().handle (); + static const auto &self = m_self.handle (); + + const auto resolve = [&] (SharedLibrary::Handle handle) { + return reinterpret_cast (m_dlsym (static_cast (handle), function)); + }; + + // if requested module is yapb module, put in cache the looked up symbol + if (self != module || (plat.win32 && (static_cast (reinterpret_cast (function) >> 16) & 0xffff) == 0)) { + return resolve (module); + } + + if (m_exports.has (function)) { + return m_exports[function]; + } + auto botAddr = resolve (self); + + if (!botAddr) { + auto gameAddr = resolve (gamedll); + + if (gameAddr) { + return m_exports[function] = gameAddr; + } + } + else { + return m_exports[function] = botAddr; + } + return nullptr; +} + +void EntityLinkage::initialize () { + if (plat.arm) { + return; + } + + m_dlsym.install (reinterpret_cast (EntityLinkage::replacement), true); + m_self.locate (&engfuncs); +} + // add linkents for android #include "android.cpp" diff --git a/version_script.lds b/version_script.lds index 987bce3..0f0065f 100644 --- a/version_script.lds +++ b/version_script.lds @@ -4,6 +4,7 @@ YAPB_ABI_1.0 { GiveFnptrsToDll; GetBotAPI; GetEntityAPI; + GetNewDLLFunctions; local: *; }; \ No newline at end of file