Custom.cfg (#213)
Added custom configs. These are used for replacing some hardcoded strings inside bot code, currently custom cvar for parachute detection is available, as well as custom c4 model names. Added editorconfig, and fixed CRLF for files (was a mix between LF & CRLF). Fixed use-after-free sanitizer error with chatlib. Fixed configs files loaded with memory-loader does not process last line in config files.
This commit is contained in:
parent
ed46e3238d
commit
075bff2988
21 changed files with 533 additions and 404 deletions
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// YaPB - Counter-Strike Bot based on PODBot by Markus Klinge.
|
||||
// Copyright Š 2004-2020 YaPB Project <yapb@jeefo.net>.
|
||||
// Copyright © 2004-2020 YaPB Project <yapb@jeefo.net>.
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
|
|
@ -28,6 +28,7 @@ void BotConfig::loadConfigs () {
|
|||
loadLogosConfig ();
|
||||
loadAvatarsConfig ();
|
||||
loadDifficultyConfig ();
|
||||
loadCustomConfig ();
|
||||
}
|
||||
|
||||
void BotConfig::loadMainConfig (bool isFirstLoad) {
|
||||
|
|
@ -614,6 +615,38 @@ void BotConfig::loadMapSpecificConfig () {
|
|||
}
|
||||
}
|
||||
|
||||
void BotConfig::loadCustomConfig () {
|
||||
String line;
|
||||
MemFile file;
|
||||
|
||||
m_custom["C4ModelName"] = "c4.mdl";
|
||||
m_custom["AMXParachuteCvar"] = "sv_parachute";
|
||||
|
||||
// custom inititalization
|
||||
if (util.openConfig ("custom.cfg", "Custom config file not found. Loading defaults.", &file)) {
|
||||
m_custom.clear ();
|
||||
|
||||
while (file.getLine (line)) {
|
||||
line.trim ();
|
||||
|
||||
if (isCommentLine (line)) {
|
||||
continue;
|
||||
}
|
||||
auto values = line.split ("=");
|
||||
|
||||
if (values.length () != 2) {
|
||||
logger.error ("Bad configuration for custom.cfg");
|
||||
return;
|
||||
}
|
||||
auto kv = Twin <String, String> (values[0].trim (), values[1].trim ());
|
||||
|
||||
if (!kv.first.empty () && !kv.second.empty ()) {
|
||||
m_custom[kv.first] = kv.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BotConfig::loadLogosConfig () {
|
||||
setupMemoryFiles ();
|
||||
|
||||
|
|
@ -750,6 +783,14 @@ const char *BotConfig::translate (StringRef input) {
|
|||
return input.chars (); // nothing found
|
||||
}
|
||||
|
||||
void BotConfig::showCustomValues () {
|
||||
game.print ("Current values for custom config items:");
|
||||
|
||||
m_custom.foreach ([&](const String &key, const String &val) {
|
||||
game.print (" %s = %s", key, val);
|
||||
});
|
||||
}
|
||||
|
||||
uint32 BotConfig::hashLangString (StringRef str) {
|
||||
auto test = [] (const char ch) {
|
||||
return (ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue