Skip to content

Commit

Permalink
Add Basic VPROF Budgets, Add Con Command Unlocker to Core (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
roflmuffin committed Jun 17, 2024
1 parent 877b7c5 commit 7f5103d
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 146 deletions.
4 changes: 3 additions & 1 deletion configs/addons/counterstrikesharp/configs/core.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
"FollowCS2ServerGuidelines": true,
"PluginHotReloadEnabled": true,
"PluginAutoLoadEnabled": true,
"ServerLanguage": "en"
"ServerLanguage": "en",
"UnlockConCommands": true,
"UnlockConVars": true
}
11 changes: 9 additions & 2 deletions docfx/docs/reference/core-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ receive a ban.
> [!NOTE]
> Disable this option at your own risk.

## PluginHotReloadEnabled

When enabled, plugins are automatically reloaded when their .dll file is updated.
Expand All @@ -39,4 +38,12 @@ When enabled, plugins are automatically loaded from the plugins directory on ser

## ServerLanguage

Configures the default language to use for server commands & messages. The format for the culture name based on RFC 4646 is `languagecode2-country`/`regioncode2`, where `languagecode2` is the two-letter language code and `country/regioncode2` is the two-letter subculture code. Examples include `ja-JP` for Japanese (Japan) and `en-US` for English (United States). Defaults to "en".
Configures the default language to use for server commands & messages. The format for the culture name based on RFC 4646 is `languagecode2-country`/`regioncode2`, where `languagecode2` is the two-letter language code and `country/regioncode2` is the two-letter subculture code. Examples include `ja-JP` for Japanese (Japan) and `en-US` for English (United States). Defaults to "en".

## UnlockConCommands

When enabled, will remove the `FCVAR_HIDDEN`,`FCVAR_DEVELOPMENTONLY`, `FCVAR_MISSING0`, `FCVAR_MISSING1`, `FCVAR_MISSING2`, `FCVAR_MISSING3` flags from all console commands.

## UnlockConVars

When enabled, will remove the `FCVAR_HIDDEN`,`FCVAR_DEVELOPMENTONLY`, `FCVAR_MISSING0`, `FCVAR_MISSING1`, `FCVAR_MISSING2`, `FCVAR_MISSING3` flags from all console variables.
30 changes: 20 additions & 10 deletions managed/CounterStrikeSharp.API/Core/CoreConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,21 @@ internal sealed partial class CoreConfigData

[JsonPropertyName("FollowCS2ServerGuidelines")]
public bool FollowCS2ServerGuidelines { get; set; } = true;

[JsonPropertyName("PluginHotReloadEnabled")]
public bool PluginHotReloadEnabled { get; set; } = true;

[JsonPropertyName("PluginAutoLoadEnabled")]
public bool PluginAutoLoadEnabled { get; set; } = true;

[JsonPropertyName("ServerLanguage")]
public string ServerLanguage { get; set; } = "en";

[JsonPropertyName("UnlockConCommands")]
public bool UnlockConCommands { get; set; } = true;

[JsonPropertyName("UnlockConVars")]
public bool UnlockConVars { get; set; } = true;
}

/// <summary>
Expand Down Expand Up @@ -97,14 +103,18 @@ public partial class CoreConfig
/// When enabled, plugins are automatically reloaded when their .dll file is updated.
/// </summary>
public static bool PluginHotReloadEnabled => _coreConfig.PluginHotReloadEnabled;

/// <summary>
/// When enabled, plugins are automatically loaded from the plugins directory on server start.
/// </summary>
public static bool PluginAutoLoadEnabled => _coreConfig.PluginAutoLoadEnabled;

public static string ServerLanguage => _coreConfig.ServerLanguage;


public static bool UnlockConCommands => _coreConfig.UnlockConCommands;

public static bool UnlockConVars => _coreConfig.UnlockConVars;

}

public partial class CoreConfig : IStartupService
Expand Down Expand Up @@ -140,7 +150,7 @@ public void Load()
ReloadCoreConfigCommand));
_commandsRegistered = true;
}

if (!File.Exists(_coreConfigPath))
{
_logger.LogWarning(
Expand Down Expand Up @@ -181,13 +191,13 @@ public void Load()
serverCulture = CultureInfo.InvariantCulture;
}
}

CultureInfo.DefaultThreadCurrentUICulture = serverCulture;
CultureInfo.DefaultThreadCurrentCulture = serverCulture;
CultureInfo.CurrentUICulture = serverCulture;
CultureInfo.CurrentCulture = serverCulture;

_logger.LogInformation("Successfully loaded core configuration");
}
}
}
}
54 changes: 30 additions & 24 deletions src/core/coreconfig.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
/*
* This file is part of CounterStrikeSharp.
* CounterStrikeSharp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CounterStrikeSharp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CounterStrikeSharp. If not, see <https://www.gnu.org/licenses/>. *
*/
* This file is part of CounterStrikeSharp.
* CounterStrikeSharp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CounterStrikeSharp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CounterStrikeSharp. If not, see <https://www.gnu.org/licenses/>. *
*/

#include "core/coreconfig.h"

#include <fstream>

#include "core/log.h"
#include "core/coreconfig.h"

namespace counterstrikesharp {

Expand All @@ -28,10 +30,12 @@ bool CCoreConfig::Init(char* conf_error, int conf_error_size)
{
std::ifstream ifs(std::string(m_sPath + ".json"));

if (!ifs) {
if (!ifs)
{
std::ifstream exampleIfs(std::string(m_sPath + ".example.json"));

if (!exampleIfs) {
if (!exampleIfs)
{
V_snprintf(conf_error, conf_error_size, "CoreConfig file not found.");
return false;
}
Expand All @@ -46,25 +50,27 @@ bool CCoreConfig::Init(char* conf_error, int conf_error_size)

m_json = json::parse(ifs);

try {
try
{
PublicChatTrigger = m_json.value("PublicChatTrigger", PublicChatTrigger);
SilentChatTrigger = m_json.value("SilentChatTrigger", SilentChatTrigger);
FollowCS2ServerGuidelines = m_json.value("FollowCS2ServerGuidelines", FollowCS2ServerGuidelines);
PluginHotReloadEnabled = m_json.value("PluginHotReloadEnabled", PluginHotReloadEnabled);
PluginAutoLoadEnabled = m_json.value("PluginAutoLoadEnabled", PluginAutoLoadEnabled);
ServerLanguage = m_json.value("ServerLanguage", ServerLanguage);
} catch (const std::exception& ex) {
UnlockConCommands = m_json.value("UnlockConCommands", UnlockConCommands);
UnlockConVars = m_json.value("UnlockConVars", UnlockConVars);
}
catch (const std::exception& ex)
{
V_snprintf(conf_error, conf_error_size, "Failed to parse CoreConfig file: %s", ex.what());
return false;
}

return true;
}

const std::string CCoreConfig::GetPath() const
{
return m_sPath;
}
const std::string CCoreConfig::GetPath() const { return m_sPath; }

bool CCoreConfig::IsTriggerInternal(std::vector<std::string> triggers, const std::string& message, std::string& prefix) const
{
Expand All @@ -90,4 +96,4 @@ bool CCoreConfig::IsPublicChatTrigger(const std::string& message, std::string& p
{
return IsTriggerInternal(PublicChatTrigger, message, prefix);
}
} // namespace counterstrikesharp
} // namespace counterstrikesharp
36 changes: 20 additions & 16 deletions src/core/coreconfig.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
/*
* This file is part of CounterStrikeSharp.
* CounterStrikeSharp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CounterStrikeSharp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CounterStrikeSharp. If not, see <https://www.gnu.org/licenses/>. *
*/
* This file is part of CounterStrikeSharp.
* CounterStrikeSharp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CounterStrikeSharp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CounterStrikeSharp. If not, see <https://www.gnu.org/licenses/>. *
*/

#pragma once

#include "core/globals.h"
#include <string>
#include <nlohmann/json.hpp>

#include <string>

#include "core/globals.h"

namespace counterstrikesharp {

class CCoreConfig
Expand All @@ -31,6 +33,8 @@ class CCoreConfig
bool PluginHotReloadEnabled = true;
bool PluginAutoLoadEnabled = true;
std::string ServerLanguage = "en";
bool UnlockConCommands = true;
bool UnlockConVars = true;

using json = nlohmann::json;
CCoreConfig(const std::string& path);
Expand Down
58 changes: 58 additions & 0 deletions src/core/managers/con_command_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include <algorithm>

#include "core/coreconfig.h"
#include "core/log.h"
#include "core/memory.h"
#include "core/utils.h"
Expand Down Expand Up @@ -203,6 +204,63 @@ void ConCommandManager::OnAllInitialized()

m_global_cmd.callback_pre = globals::callbackManager.CreateCallback("OnClientCommandGlobalPre");
m_global_cmd.callback_post = globals::callbackManager.CreateCallback("OnClientCommandGlobalPost");

if (globals::coreConfig->UnlockConCommands)
{
UnlockConCommands();
}

if (globals::coreConfig->UnlockConVars)
{
UnlockConVars();
}
}

static uint64 flagsToRemove = (FCVAR_HIDDEN | FCVAR_DEVELOPMENTONLY | FCVAR_MISSING0 | FCVAR_MISSING1 | FCVAR_MISSING2 | FCVAR_MISSING3);

void UnlockConVars()
{
int unhiddenConVars = 0;

ConVar* currentCvar = nullptr;
ConVarHandle currentCvarHandle;
currentCvarHandle.Set(0);

do
{
currentCvar = globals::cvars->GetConVar(currentCvarHandle);

currentCvarHandle.Set(currentCvarHandle.Get() + 1);

if (!currentCvar) continue;

if (!(currentCvar->flags & flagsToRemove)) continue;

currentCvar->flags &= ~flagsToRemove;
unhiddenConVars++;
} while (currentCvar);
}

void UnlockConCommands()
{
int unhiddenConCommands = 0;

ConCommand* currentConCommand = nullptr;
ConCommand* invalidConCommand = globals::cvars->GetCommand(ConCommandHandle());
ConCommandHandle conCommandHandle;
conCommandHandle.Set(0);

do
{
currentConCommand = globals::cvars->GetCommand(conCommandHandle);

conCommandHandle.Set(conCommandHandle.Get() + 1);

if (!currentConCommand || currentConCommand == invalidConCommand || !(currentConCommand->GetFlags() & flagsToRemove)) continue;

currentConCommand->RemoveFlags(flagsToRemove);
unhiddenConCommands++;
} while (currentConCommand && currentConCommand != invalidConCommand);
}

void ConCommandManager::OnShutdown()
Expand Down
Loading

0 comments on commit 7f5103d

Please sign in to comment.