-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn if Metamod is detected. Auto disable it for cstrike. (#508)
* Warn if Metamod is detected. Auto disable it for cstrike. * fix windows build * actual fix * stdafx.hpp: included regex library * LoadThisDll declaration has been fixed, code has been rewritten for more flexibility, helper functions are now declared in a separate file * LoadThisDll: debug messages for old and new path * Add library extension at compile time instead of runtime * Fixed the message about detecting a third-party plugin and removed the message about disabling AmxModX * swap_lib: return the original path if we did not find the desired folder in the path * crash_if_failed: use exit(1) instead of clearing pointers to engine interfaces for cause an intentional crash * com_fixslashes: replaced regex with std::replace * Throw an error if metamod is detected, but swap_lib returned us the original path in the end * Catch the case where the previous character from the start is not a slash * stdafx.hpp: removed regex library * helper_functions.hpp: moved defines at the top of header * swap_lib: changed return type from const char* to std::string * Declare a variable at the beginning to be in scope of original function and .c_str() wouldn't be a dangling pointer at that point I didn't immediately release that the result was a dangling pointer, the life of which ended at the end of the condition Of course, since we didn't allocate memory to it, after the original function is called it will still be freed, but it seems that the engine no longer uses this pointer too, and therefore we don't seem to need to store it.... So even if then it will be dangling, then specifically with this function it should not cause some issues after its call --------- Co-authored-by: SmileyAG <[email protected]>
- Loading branch information
Showing
5 changed files
with
137 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "stdafx.hpp" | ||
#include "modules.hpp" | ||
#include "helper_functions.hpp" | ||
|
||
namespace helper_functions | ||
{ | ||
void com_fixslashes(std::string &str) | ||
{ | ||
// https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/game_shared/bot/nav_file.cpp#L680 | ||
#ifdef _WIN32 | ||
std::replace(str.begin(), str.end(), '/', '\\'); | ||
#else | ||
std::replace(str.begin(), str.end(), '\\', '/'); | ||
#endif | ||
} | ||
|
||
std::string swap_lib(const char* current_lib_path, std::string new_lib_path, const char *start) | ||
{ | ||
const std::string filename = current_lib_path; | ||
const auto index = filename.find(start); | ||
|
||
if ((index == std::string::npos) || // String not found in current path. | ||
((index > 0) && (filename[index - 1] != PATH_SLASH))) // Previous character from the specified start is not a slash. | ||
return current_lib_path; | ||
|
||
com_fixslashes(new_lib_path); | ||
|
||
std::string new_path = filename.substr(0, index) + new_lib_path + DLL_EXTENSION; | ||
|
||
return new_path; | ||
} | ||
|
||
void crash_if_failed(std::string str) | ||
{ | ||
EngineWarning("%s", str.c_str()); | ||
|
||
#ifdef _WIN32 | ||
MessageBox(NULL, str.c_str(), "Fatal Error", MB_OK | MB_ICONERROR); | ||
#endif | ||
|
||
std::exit(1); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#ifdef _WIN32 | ||
#define DLL_EXTENSION ".dll" | ||
#define PATH_SLASH '\\' | ||
#else | ||
#define DLL_EXTENSION ".so" | ||
#define PATH_SLASH '/' | ||
#endif | ||
|
||
namespace helper_functions | ||
{ | ||
void com_fixslashes(std::string &str); | ||
std::string swap_lib(const char* current_lib_path, std::string new_lib_path, const char *start); | ||
void crash_if_failed(std::string str); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters