[General]: Use std::format more often (#635)
This commit is contained in:
parent
b07ddc57aa
commit
ac90714811
@ -11,7 +11,7 @@ namespace Assets
|
||||
Utils::String::Replace(name, "maps/mp/", "");
|
||||
Utils::String::Replace(name, ".d3dbsp", "");
|
||||
|
||||
Components::FileSystem::File mapFile(Utils::String::VA("comworld/%s.iw4xComWorld", name.data()));
|
||||
Components::FileSystem::File mapFile(std::format("comworld/{}.iw4xComWorld", name));
|
||||
|
||||
if (mapFile.exists())
|
||||
{
|
||||
|
@ -95,8 +95,8 @@ namespace Assets
|
||||
|
||||
void IFont_s::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
|
||||
{
|
||||
Components::FileSystem::File fontDefFile(Utils::String::VA("%s.json", name.data()));
|
||||
Components::FileSystem::File fontFile(Utils::String::VA("%s.ttf", name.data()));
|
||||
Components::FileSystem::File fontDefFile(std::format("{}.json", name));
|
||||
Components::FileSystem::File fontFile(std::format("{}.ttf", name));
|
||||
|
||||
if (!fontDefFile.exists() || !fontFile.exists())
|
||||
{
|
||||
@ -254,7 +254,7 @@ namespace Assets
|
||||
rgbaPixels[i + 3] = static_cast<char>(pixels[i / 4]);
|
||||
}
|
||||
|
||||
Utils::IO::WriteFile(Utils::String::VA("userraw\\images\\%s.iwi", texName), outIwi);
|
||||
Utils::IO::WriteFile(std::format("userraw\\images\\{}.iwi", texName), outIwi);
|
||||
}
|
||||
|
||||
void IFont_s::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
||||
|
@ -64,7 +64,7 @@ namespace Assets
|
||||
|
||||
void IFxEffectDef::loadBinary(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
|
||||
{
|
||||
Components::FileSystem::File fxFile(Utils::String::VA("fx/%s.iw4xFx", name.data()));
|
||||
Components::FileSystem::File fxFile(std::format("fx/{}.iw4xFx", name));
|
||||
|
||||
if (fxFile.exists())
|
||||
{
|
||||
|
@ -23,7 +23,7 @@ namespace Assets
|
||||
const char* tempName = image->name;
|
||||
if (tempName[0] == '*') tempName++;
|
||||
|
||||
Components::FileSystem::File imageFile(Utils::String::VA("images/%s.iw4xImage", tempName));
|
||||
Components::FileSystem::File imageFile(std::format("images/{}.iw4xImage", tempName));
|
||||
if (imageFile.exists())
|
||||
{
|
||||
Utils::Stream::Reader reader(builder->getAllocator(), imageFile.getBuffer());
|
||||
|
@ -7,7 +7,7 @@ namespace Assets
|
||||
{
|
||||
void IGfxLightDef::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
|
||||
{
|
||||
Components::FileSystem::File mapFile(Utils::String::VA("lights/%s.iw4xLight", name.data()));
|
||||
Components::FileSystem::File mapFile(std::format("lights/{}.iw4xLight", name));
|
||||
|
||||
if (mapFile.exists())
|
||||
{
|
||||
|
@ -129,7 +129,7 @@ namespace Assets
|
||||
Utils::String::Replace(name, "maps/mp/", "");
|
||||
Utils::String::Replace(name, ".d3dbsp", "");
|
||||
|
||||
Components::FileSystem::File mapFile(Utils::String::VA("gfxworld/%s.iw4xGfxWorld", name.data()));
|
||||
Components::FileSystem::File mapFile(std::format("gfxworld/{}.iw4xGfxWorld", name));
|
||||
|
||||
if (mapFile.exists())
|
||||
{
|
||||
|
@ -5,7 +5,7 @@ namespace Assets
|
||||
{
|
||||
void ILoadedSound::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
|
||||
{
|
||||
Components::FileSystem::File soundFile(Utils::String::VA("loaded_sound/%s", name.data()));
|
||||
Components::FileSystem::File soundFile(std::format("loaded_sound/{}", name));
|
||||
if (!soundFile.exists())
|
||||
{
|
||||
header->loadSnd = Components::AssetHandler::FindOriginalAsset(this->getType(), name.data()).loadSnd;
|
||||
|
@ -10,7 +10,7 @@ namespace Assets
|
||||
Utils::String::Replace(name, "mp/", "");
|
||||
Utils::String::Replace(name, ".d3dbsp", "");
|
||||
|
||||
Components::FileSystem::File ents(Utils::String::VA("mapents/%s.ents", name.data()));
|
||||
Components::FileSystem::File ents(std::format("mapents/{}.ents", name));
|
||||
if (ents.exists())
|
||||
{
|
||||
Game::MapEnts* entites = builder->getAllocator()->allocate<Game::MapEnts>();
|
||||
@ -48,7 +48,7 @@ namespace Assets
|
||||
|
||||
std::string entityString = ents.getBuffer();
|
||||
|
||||
entites->name = builder->getAllocator()->duplicateString(Utils::String::VA("maps/mp/%s.d3dbsp", name.data()));
|
||||
entites->name = builder->getAllocator()->duplicateString(std::format("maps/mp/{}.d3dbsp", name));
|
||||
entites->entityString = builder->getAllocator()->duplicateString(entityString);
|
||||
entites->numEntityChars = entityString.size() + 1;
|
||||
|
||||
|
@ -53,7 +53,7 @@ namespace Assets
|
||||
{"mc_unlit_alphatest", "mc_unlit_blend_lin"}
|
||||
};
|
||||
|
||||
Components::FileSystem::File materialFile(Utils::String::VA("materials/%s.iw4xMaterial", name.data()));
|
||||
Components::FileSystem::File materialFile(std::format("materials/{}.iw4xMaterial", name));
|
||||
if (!materialFile.exists()) return;
|
||||
|
||||
Utils::Stream::Reader reader(builder->getAllocator(), materialFile.getBuffer());
|
||||
@ -329,7 +329,7 @@ namespace Assets
|
||||
|
||||
void IMaterial::loadJson(Game::XAssetHeader* header, const std::string& name, [[maybe_unused]] Components::ZoneBuilder::Zone* builder)
|
||||
{
|
||||
Components::FileSystem::File materialInfo(Utils::String::VA("materials/%s.json", name.data()));
|
||||
Components::FileSystem::File materialInfo(std::format("materials/{}.json", name));
|
||||
|
||||
if (!materialInfo.exists()) return;
|
||||
|
||||
|
@ -19,7 +19,7 @@ namespace Assets
|
||||
|
||||
void IMaterialPixelShader::loadBinary(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
|
||||
{
|
||||
Components::FileSystem::File psFile(Utils::String::VA("ps/%s.iw4xPS", name.data()));
|
||||
Components::FileSystem::File psFile(std::format("ps/{}.iw4xPS", name));
|
||||
if (!psFile.exists()) return;
|
||||
|
||||
Utils::Stream::Reader reader(builder->getAllocator(), psFile.getBuffer());
|
||||
|
@ -20,7 +20,7 @@ namespace Assets
|
||||
{
|
||||
AssertSize(Game::MaterialPass, 20);
|
||||
|
||||
Components::FileSystem::File techFile(Utils::String::VA("techniques/%s.iw4xTech", name.data()));
|
||||
Components::FileSystem::File techFile(std::format("techniques/{}.iw4xTech", name));
|
||||
if (!techFile.exists()) {
|
||||
*tech = nullptr;
|
||||
Components::Logger::Warning(Game::CON_CHANNEL_DONT_FILTER, "Missing technique '{}'\n", name);
|
||||
@ -101,7 +101,7 @@ namespace Assets
|
||||
|
||||
void IMaterialTechniqueSet::loadBinary(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
|
||||
{
|
||||
Components::FileSystem::File tsFile(Utils::String::VA("techsets/%s.iw4xTS", name.data()));
|
||||
Components::FileSystem::File tsFile(std::format("techsets/{}.iw4xTS", name));
|
||||
if (!tsFile.exists()) return;
|
||||
|
||||
Utils::Stream::Reader reader(builder->getAllocator(), tsFile.getBuffer());
|
||||
|
@ -18,7 +18,7 @@ namespace Assets
|
||||
|
||||
void IMaterialVertexDeclaration::loadBinary(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
|
||||
{
|
||||
Components::FileSystem::File declFile(Utils::String::VA("decl/%s.iw4xDECL", name.data()));
|
||||
Components::FileSystem::File declFile(std::format("decl/{}.iw4xDECL", name));
|
||||
if (!declFile.exists()) return;
|
||||
|
||||
Utils::Stream::Reader reader(builder->getAllocator(), declFile.getBuffer());
|
||||
|
@ -18,7 +18,7 @@ namespace Assets
|
||||
|
||||
void IMaterialVertexShader::loadBinary(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
|
||||
{
|
||||
Components::FileSystem::File vsFile(Utils::String::VA("vs/%s.iw4xVS", name.data()));
|
||||
Components::FileSystem::File vsFile(std::format("vs/{}.iw4xVS", name));
|
||||
if (!vsFile.exists()) return;
|
||||
|
||||
Utils::Stream::Reader reader(builder->getAllocator(), vsFile.getBuffer());
|
||||
|
@ -6,7 +6,7 @@ namespace Assets
|
||||
void IWeapon::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* /*builder*/)
|
||||
{
|
||||
// Try loading raw weapon
|
||||
if (Components::FileSystem::File(Utils::String::VA("weapons/mp/%s", name.data())).exists())
|
||||
if (Components::FileSystem::File(std::format("weapons/mp/{}", name)))
|
||||
{
|
||||
// let the function see temporary assets when calling DB_FindXAssetHeader during the loading function
|
||||
// otherwise it fails to link things properly
|
||||
|
@ -7,7 +7,7 @@ namespace Assets
|
||||
{
|
||||
void IXAnimParts::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
|
||||
{
|
||||
Components::FileSystem::File animFile(Utils::String::VA("xanim/%s.iw4xAnim", name.data()));
|
||||
Components::FileSystem::File animFile(std::format("xanim/{}.iw4xAnim", name));
|
||||
|
||||
if (animFile.exists())
|
||||
{
|
||||
|
@ -85,7 +85,7 @@ namespace Assets
|
||||
|
||||
void IXModel::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
|
||||
{
|
||||
Components::FileSystem::File modelFile(Utils::String::VA("xmodel/%s.iw4xModel", name.data()));
|
||||
Components::FileSystem::File modelFile(std::format("xmodel/{}.iw4xModel", name));
|
||||
|
||||
if (!builder->isPrimaryAsset() && (!Components::ZoneBuilder::PreferDiskAssetsDvar.get<bool>() || !modelFile.exists()))
|
||||
{
|
||||
|
@ -573,7 +573,7 @@ namespace Assets
|
||||
Utils::String::Replace(name, "maps/mp/", "");
|
||||
Utils::String::Replace(name, ".d3dbsp", "");
|
||||
|
||||
Components::FileSystem::File clipFile(Utils::String::VA("clipmap/%s.iw4xClipMap", name.data()));
|
||||
Components::FileSystem::File clipFile(std::format("clipmap/{}.iw4xClipMap", name));
|
||||
if (!clipFile.exists())
|
||||
{
|
||||
return;
|
||||
@ -882,7 +882,7 @@ namespace Assets
|
||||
clipMap->smodelNodeCount = reader.read<unsigned short>();
|
||||
clipMap->smodelNodes = reader.readArray<Game::SModelAabbNode>(clipMap->smodelNodeCount);
|
||||
|
||||
clipMap->mapEnts = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MAP_ENTS, Utils::String::VA("maps/mp/%s.d3dbsp", name.data()), builder).mapEnts;
|
||||
clipMap->mapEnts = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MAP_ENTS, std::format("maps/mp/{}.d3dbsp", name), builder).mapEnts;
|
||||
|
||||
// add triggers to mapEnts
|
||||
if (version >= 2) {
|
||||
|
@ -9,7 +9,7 @@ namespace Assets
|
||||
void ImenuDef_t::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* /*builder*/)
|
||||
{
|
||||
// load from disk
|
||||
auto menus = Components::Menus::LoadMenu(Utils::String::VA("ui_mp/%s.menu", name.data()));
|
||||
auto menus = Components::Menus::LoadMenu(std::format("ui_mp/{}.menu", name));
|
||||
|
||||
if (menus.empty()) return;
|
||||
if (menus.size() > 1) Components::Logger::Print("Menu '{}' on disk has more than one menudef in it. Only saving the first one\n", name);
|
||||
|
@ -5,7 +5,7 @@ namespace Assets
|
||||
{
|
||||
void Isnd_alias_list_t::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
|
||||
{
|
||||
Components::FileSystem::File aliasFile(Utils::String::VA("sounds/%s.json", name.data()));
|
||||
Components::FileSystem::File aliasFile(std::format("sounds/{}.json", name));
|
||||
if (!aliasFile.exists())
|
||||
{
|
||||
header->sound = Components::AssetHandler::FindOriginalAsset(this->getType(), name.data()).sound;
|
||||
|
@ -169,10 +169,10 @@ namespace Components
|
||||
playerTitle[0] = '\0';
|
||||
}
|
||||
|
||||
list.append(Utils::String::VA("\\%s\\%s", std::to_string(i).data(), playerTitle));
|
||||
list.append(std::format("\\{}\\{}", std::to_string(i), playerTitle));
|
||||
}
|
||||
|
||||
const auto* command = Utils::String::VA("%c customTitles \"%s\"", 21, list.data());
|
||||
const auto* command = Utils::String::Format("{:c} customTitles \"{}\"", 21, list);
|
||||
Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, command);
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ namespace Components
|
||||
std::lock_guard _(Mutex);
|
||||
if (item < Lines.size())
|
||||
{
|
||||
return Utils::String::VA("%s", Lines[item].data());
|
||||
return Utils::String::Format("{}", Lines[item]);
|
||||
}
|
||||
|
||||
return "";
|
||||
|
@ -268,8 +268,7 @@ namespace Components
|
||||
});
|
||||
|
||||
Logger::Print("{} was muted\n", client->name);
|
||||
Game::SV_GameSendServerCommand(client - Game::svs_clients, Game::SV_CMD_CAN_IGNORE,
|
||||
Utils::String::VA("%c \"You were muted\"", 0x65));
|
||||
Game::SV_GameSendServerCommand(client - Game::svs_clients, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"You were muted\"", 0x65));
|
||||
}
|
||||
|
||||
void Chat::UnmuteClient(const Game::client_t* client)
|
||||
@ -277,8 +276,7 @@ namespace Components
|
||||
UnmuteInternal(client->steamID);
|
||||
|
||||
Logger::Print("{} was unmuted\n", client->name);
|
||||
Game::SV_GameSendServerCommand(client - Game::svs_clients, Game::SV_CMD_CAN_IGNORE,
|
||||
Utils::String::VA("%c \"You were unmuted\"", 0x65));
|
||||
Game::SV_GameSendServerCommand(client - Game::svs_clients, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"You were unmuted\"", 0x65));
|
||||
}
|
||||
|
||||
void Chat::UnmuteInternal(const std::uint64_t id, bool everyone)
|
||||
@ -369,12 +367,12 @@ namespace Components
|
||||
|
||||
if (!name.empty())
|
||||
{
|
||||
Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s: %s\"", 0x68, name.data(), message.data()));
|
||||
Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::Format("{:c} \"{}: {}\"", 0x68, name, message));
|
||||
Logger::Print(Game::CON_CHANNEL_SERVER, "{}: {}\n", name, message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"Console: %s\"", 0x68, message.data()));
|
||||
Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::Format("{:c} \"Console: {}\"", 0x68, message));
|
||||
Logger::Print(Game::CON_CHANNEL_SERVER, "Console: {}\n", message);
|
||||
}
|
||||
});
|
||||
@ -395,12 +393,12 @@ namespace Components
|
||||
|
||||
if (!name.empty())
|
||||
{
|
||||
Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s: %s\"", 0x68, name.data(), message.data()));
|
||||
Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::Format("{:c} \"{}: {}\"", 0x68, name.data(), message));
|
||||
Logger::Print(Game::CON_CHANNEL_SERVER, "{} -> {}: {}\n", name, client, message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"Console: %s\"", 104, message.data()));
|
||||
Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::Format("{:c} \"Console: {}\"", 0x68, message));
|
||||
Logger::Print(Game::CON_CHANNEL_SERVER, "Console -> {}: {}\n", client, message);
|
||||
}
|
||||
});
|
||||
@ -416,7 +414,7 @@ namespace Components
|
||||
if (params->size() < 2) return;
|
||||
|
||||
auto message = params->join(1);
|
||||
Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x68, message.data()));
|
||||
Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::Format("{:c} \"{}\"", 0x68, message));
|
||||
Logger::Print(Game::CON_CHANNEL_SERVER, "Raw: {}\n", message);
|
||||
});
|
||||
|
||||
@ -432,7 +430,7 @@ namespace Components
|
||||
|
||||
const auto client = atoi(params->get(1));
|
||||
std::string message = params->join(2);
|
||||
Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x68, message.data()));
|
||||
Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::Format("{:c} \"{}\"", 0x68, message));
|
||||
Logger::Print(Game::CON_CHANNEL_SERVER, "Raw -> {}: {}\n", client, message);
|
||||
});
|
||||
|
||||
|
@ -28,15 +28,15 @@ namespace Components
|
||||
list.append(std::format("\\{}\\{}", std::to_string(i), ClientState[i]));
|
||||
}
|
||||
|
||||
const auto* command = Utils::String::VA("%c clanNames \"%s\"", 22, list.data());
|
||||
Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, command);
|
||||
Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::Format("{:c} clanNames \"{}\"", 22, list));
|
||||
}
|
||||
|
||||
void ClanTags::ParseClanTags(const char* infoString)
|
||||
{
|
||||
for (std::size_t i = 0; i < Game::MAX_CLIENTS; ++i)
|
||||
{
|
||||
const auto* clanTag = Game::Info_ValueForKey(infoString, std::to_string(i).data());
|
||||
const auto index = std::to_string(i);
|
||||
const auto* clanTag = Game::Info_ValueForKey(infoString, index.data());
|
||||
|
||||
if (clanTag[0] == '\0')
|
||||
{
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include <STDInclude.hpp>
|
||||
#include "GSC/Script.hpp"
|
||||
|
||||
using namespace Utils::String;
|
||||
|
||||
namespace Components
|
||||
{
|
||||
std::unordered_map<std::string, std::function<void(Game::gentity_s*, const Command::ServerParams*)>> ClientCommand::HandlersSV;
|
||||
@ -12,14 +14,14 @@ namespace Components
|
||||
if (!(*Game::g_cheats)->current.enabled)
|
||||
{
|
||||
Logger::Debug("Cheats are disabled!");
|
||||
Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"GAME_CHEATSNOTENABLED\"", 0x65));
|
||||
Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, VA("%c \"GAME_CHEATSNOTENABLED\"", 0x65));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ent->health < 1)
|
||||
{
|
||||
Logger::Debug("Entity {} must be alive to use this command!", entNum);
|
||||
Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"GAME_MUSTBEALIVECOMMAND\"", 0x65));
|
||||
Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, VA("%c \"GAME_MUSTBEALIVECOMMAND\"", 0x65));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -67,8 +69,7 @@ namespace Components
|
||||
const auto entNum = ent->s.number;
|
||||
Logger::Debug("Noclip toggled for entity {}", entNum);
|
||||
|
||||
Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x65,
|
||||
(ent->client->flags & Game::PLAYER_FLAG_NOCLIP) ? "GAME_NOCLIPON" : "GAME_NOCLIPOFF"));
|
||||
Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, VA("%c \"%s\"", 0x65, (ent->client->flags & Game::PLAYER_FLAG_NOCLIP) ? "GAME_NOCLIPON" : "GAME_NOCLIPOFF"));
|
||||
});
|
||||
|
||||
Add("ufo", [](Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
||||
@ -81,8 +82,7 @@ namespace Components
|
||||
const auto entNum = ent->s.number;
|
||||
Logger::Debug("UFO toggled for entity {}", entNum);
|
||||
|
||||
Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x65,
|
||||
(ent->client->flags & Game::PLAYER_FLAG_UFO) ? "GAME_UFOON" : "GAME_UFOOFF"));
|
||||
Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, VA("%c \"%s\"", 0x65, (ent->client->flags & Game::PLAYER_FLAG_UFO) ? "GAME_UFOON" : "GAME_UFOOFF"));
|
||||
});
|
||||
|
||||
Add("god", [](Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
||||
@ -95,8 +95,7 @@ namespace Components
|
||||
const auto entNum = ent->s.number;
|
||||
Logger::Debug("God toggled for entity {}", entNum);
|
||||
|
||||
Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x65,
|
||||
(ent->flags & Game::FL_GODMODE) ? "GAME_GODMODE_ON" : "GAME_GODMODE_OFF"));
|
||||
Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, VA("%c \"%s\"", 0x65, (ent->flags & Game::FL_GODMODE) ? "GAME_GODMODE_ON" : "GAME_GODMODE_OFF"));
|
||||
});
|
||||
|
||||
Add("demigod", [](Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
||||
@ -109,8 +108,7 @@ namespace Components
|
||||
const auto entNum = ent->s.number;
|
||||
Logger::Debug("Demigod toggled for entity {}", entNum);
|
||||
|
||||
Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x65,
|
||||
(ent->flags & Game::FL_DEMI_GODMODE) ? "GAME_DEMI_GODMODE_ON" : "GAME_DEMI_GODMODE_OFF"));
|
||||
Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, VA("%c \"%s\"", 0x65, (ent->flags & Game::FL_DEMI_GODMODE) ? "GAME_DEMI_GODMODE_ON" : "GAME_DEMI_GODMODE_OFF"));
|
||||
});
|
||||
|
||||
Add("notarget", [](Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
||||
@ -123,8 +121,7 @@ namespace Components
|
||||
const auto entNum = ent->s.number;
|
||||
Logger::Debug("Notarget toggled for entity {}", entNum);
|
||||
|
||||
Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x65,
|
||||
(ent->flags & Game::FL_NOTARGET) ? "GAME_NOTARGETON" : "GAME_NOTARGETOFF"));
|
||||
Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, VA("%c \"%s\"", 0x65, (ent->flags & Game::FL_NOTARGET) ? "GAME_NOTARGETON" : "GAME_NOTARGETOFF"));
|
||||
});
|
||||
|
||||
Add("setviewpos", [](Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
||||
@ -138,8 +135,7 @@ namespace Components
|
||||
|
||||
if (params->size() < 4 || params->size() > 6)
|
||||
{
|
||||
Game::SV_GameSendServerCommand(ent->s.number, Game::SV_CMD_CAN_IGNORE,
|
||||
Utils::String::VA("%c \"GAME_USAGE\x15: setviewpos x y z [yaw] [pitch]\n\"", 0x65));
|
||||
Game::SV_GameSendServerCommand(ent->s.number, Game::SV_CMD_CAN_IGNORE, VA("%c \"GAME_USAGE\x15: setviewpos x y z [yaw] [pitch]\n\"", 0x65));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -170,8 +166,7 @@ namespace Components
|
||||
|
||||
if (params->size() < 2)
|
||||
{
|
||||
Game::SV_GameSendServerCommand(ent->s.number, Game::SV_CMD_CAN_IGNORE,
|
||||
Utils::String::VA("%c \"GAME_USAGE\x15: give <weapon name>\"", 0x65));
|
||||
Game::SV_GameSendServerCommand(ent->s.number, Game::SV_CMD_CAN_IGNORE, VA("%c \"GAME_USAGE\x15: give <weapon name>\"", 0x65));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -308,8 +303,7 @@ namespace Components
|
||||
strncpy_s(ent->client->visionName[visMode],
|
||||
sizeof(Game::gclient_t::visionName[0]) / sizeof(char), name, _TRUNCATE);
|
||||
|
||||
Game::SV_GameSendServerCommand(ent->s.number, Game::SV_CMD_RELIABLE,
|
||||
Utils::String::VA("%c \"%s\" %i", Game::MY_CMDS[visMode], name, duration));
|
||||
Game::SV_GameSendServerCommand(ent->s.number, Game::SV_CMD_RELIABLE, VA("%c \"%s\" %i", Game::MY_CMDS[visMode], name, duration));
|
||||
});
|
||||
|
||||
Add("visionsetnight", []([[maybe_unused]] Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
||||
@ -336,8 +330,7 @@ namespace Components
|
||||
strncpy_s(ent->client->visionName[visMode],
|
||||
sizeof(Game::gclient_t::visionName[0]) / sizeof(char), name, _TRUNCATE);
|
||||
|
||||
Game::SV_GameSendServerCommand(ent->s.number, Game::SV_CMD_RELIABLE,
|
||||
Utils::String::VA("%c \"%s\" %i", Game::MY_CMDS[visMode], name, duration));
|
||||
Game::SV_GameSendServerCommand(ent->s.number, Game::SV_CMD_RELIABLE, VA("%c \"%s\" %i", Game::MY_CMDS[visMode], name, duration));
|
||||
});
|
||||
|
||||
Add("g_testCmd", []([[maybe_unused]] Game::gentity_s* ent, [[maybe_unused]] const Command::ServerParams* params)
|
||||
@ -406,7 +399,7 @@ namespace Components
|
||||
|
||||
// See description of the format string in the function G_DumpEntityDebugInfoToCSV
|
||||
// If empty it means the item does not exist in the current version of the game or it was not possible to reverse it
|
||||
return Utils::String::VA("%i,%s,%.0f,%s,%s,%s,%s,%s,%s,%s,%s,%s,%.0f %.0f %.0f,%.0f %.0f %.0f,%i\n",
|
||||
return VA("%i,%s,%.0f,%s,%s,%s,%s,%s,%s,%s,%s,%s,%.0f %.0f %.0f,%.0f %.0f %.0f,%i\n",
|
||||
entNum, eventType, distance, classname, codeClassname, (model) ? model->name : "",
|
||||
targetName, target, "", scriptLinkName, team, "",
|
||||
point[0], point[1], point[2], angles[0], angles[1], angles[2], 0);
|
||||
@ -442,7 +435,7 @@ namespace Components
|
||||
{
|
||||
assert(filenameSuffix);
|
||||
|
||||
const auto* fileName = Utils::String::VA("%s%s%s%s", "EntInfo", (*filenameSuffix) ? "_" : "", filenameSuffix, ".csv");
|
||||
const auto* fileName = VA("%s%s%s%s", "EntInfo", (*filenameSuffix) ? "_" : "", filenameSuffix, ".csv");
|
||||
Logger::Print(Game::CON_CHANNEL_SERVER, "Opening file \"{}\" for writing.\n", fileName);
|
||||
|
||||
auto h = Game::FS_FOpenTextFileWrite(fileName);
|
||||
|
@ -7,17 +7,17 @@ namespace Components
|
||||
|
||||
bool ConnectProtocol::IsEvaluated()
|
||||
{
|
||||
return ConnectProtocol::Evaluated;
|
||||
return Evaluated;
|
||||
}
|
||||
|
||||
bool ConnectProtocol::Used()
|
||||
{
|
||||
if (!ConnectProtocol::IsEvaluated())
|
||||
if (!IsEvaluated())
|
||||
{
|
||||
ConnectProtocol::EvaluateProtocol();
|
||||
EvaluateProtocol();
|
||||
}
|
||||
|
||||
return (!ConnectProtocol::ConnectString.empty());
|
||||
return (!ConnectString.empty());
|
||||
}
|
||||
|
||||
bool ConnectProtocol::InstallProtocol()
|
||||
@ -25,8 +25,8 @@ namespace Components
|
||||
HKEY hKey = nullptr;
|
||||
std::string data;
|
||||
|
||||
char ownPth[MAX_PATH] = {0};
|
||||
char workdir[MAX_PATH] = {0};
|
||||
char ownPth[MAX_PATH]{};
|
||||
char workdir[MAX_PATH]{};
|
||||
|
||||
DWORD dwsize = MAX_PATH;
|
||||
HMODULE hModule = GetModuleHandleA(nullptr);
|
||||
@ -65,13 +65,13 @@ namespace Components
|
||||
LONG openRes = RegOpenKeyExA(HKEY_CURRENT_USER, "SOFTWARE\\Classes\\iw4x\\shell\\open\\command", 0, KEY_ALL_ACCESS, &hKey);
|
||||
if (openRes == ERROR_SUCCESS)
|
||||
{
|
||||
char regred[MAX_PATH] = { 0 };
|
||||
char regred[MAX_PATH]{};
|
||||
|
||||
// Check if the game has been moved.
|
||||
openRes = RegQueryValueExA(hKey, nullptr, nullptr, nullptr, reinterpret_cast<BYTE*>(regred), &dwsize);
|
||||
if (openRes == ERROR_SUCCESS)
|
||||
{
|
||||
char* endPtr = strstr(regred, "\" \"%1\"");
|
||||
auto* endPtr = std::strstr(regred, "\" \"%1\"");
|
||||
if (endPtr != nullptr)
|
||||
{
|
||||
*endPtr = 0;
|
||||
@ -82,7 +82,8 @@ namespace Components
|
||||
}
|
||||
|
||||
RegCloseKey(hKey);
|
||||
if (strcmp(regred + 1, ownPth))
|
||||
|
||||
if (std::strcmp(regred + 1, ownPth) != 0)
|
||||
{
|
||||
RegDeleteKeyA(HKEY_CURRENT_USER, "SOFTWARE\\Classes\\iw4x");
|
||||
}
|
||||
@ -173,8 +174,8 @@ namespace Components
|
||||
|
||||
void ConnectProtocol::EvaluateProtocol()
|
||||
{
|
||||
if (ConnectProtocol::Evaluated) return;
|
||||
ConnectProtocol::Evaluated = true;
|
||||
if (Evaluated) return;
|
||||
Evaluated = true;
|
||||
|
||||
std::string cmdLine = GetCommandLineA();
|
||||
|
||||
@ -190,15 +191,15 @@ namespace Components
|
||||
cmdLine = cmdLine.substr(0, pos);
|
||||
}
|
||||
|
||||
ConnectProtocol::ConnectString = cmdLine;
|
||||
ConnectString = cmdLine;
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectProtocol::Invocation()
|
||||
{
|
||||
if (ConnectProtocol::Used())
|
||||
if (Used())
|
||||
{
|
||||
Command::Execute(Utils::String::VA("connect %s", ConnectProtocol::ConnectString.data()), false);
|
||||
Command::Execute(std::format("connect {}", ConnectString), false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -209,28 +210,28 @@ namespace Components
|
||||
// IPC handler
|
||||
IPCPipe::On("connect", [](const std::string& data)
|
||||
{
|
||||
Command::Execute(Utils::String::VA("connect %s", data.data()), false);
|
||||
Command::Execute(std::format("connect {}", data), false);
|
||||
});
|
||||
|
||||
// Invocation handler
|
||||
Scheduler::OnGameInitialized(ConnectProtocol::Invocation, Scheduler::Pipeline::MAIN);
|
||||
Scheduler::OnGameInitialized(Invocation, Scheduler::Pipeline::MAIN);
|
||||
|
||||
ConnectProtocol::InstallProtocol();
|
||||
ConnectProtocol::EvaluateProtocol();
|
||||
InstallProtocol();
|
||||
EvaluateProtocol();
|
||||
|
||||
// Fire protocol handlers
|
||||
// Make sure this happens after the pipe-initialization!
|
||||
if (ConnectProtocol::Used())
|
||||
if (Used())
|
||||
{
|
||||
if (!Singleton::IsFirstInstance())
|
||||
{
|
||||
IPCPipe::Write("connect", ConnectProtocol::ConnectString);
|
||||
IPCPipe::Write("connect", ConnectString);
|
||||
ExitProcess(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Only skip intro here, invocation will be done later.
|
||||
Utils::Hook::Set<BYTE>(0x60BECF, 0xEB);
|
||||
Utils::Hook::Set<std::uint8_t>(0x60BECF, 0xEB);
|
||||
|
||||
Scheduler::Once([]
|
||||
{
|
||||
|
@ -114,7 +114,7 @@ namespace Components
|
||||
if (!partyEnable) // Time wrapping should not occur in party servers, but yeah...
|
||||
{
|
||||
if (mapname.empty()) mapname = "mp_rust";
|
||||
Command::Execute(Utils::String::VA("map %s", mapname.data()), true);
|
||||
Command::Execute(std::format("map {}", mapname), true);
|
||||
}
|
||||
}, Scheduler::Pipeline::SERVER);
|
||||
|
||||
|
@ -284,7 +284,7 @@ namespace Components
|
||||
{
|
||||
if (download->terminateThread) return;
|
||||
|
||||
mod = Utils::String::VA("Failed to download file: %s!", download->files[i].name.data());
|
||||
mod = std::format("Failed to download file: {}!", download->files[i].name);
|
||||
download->thread.detach();
|
||||
download->clear();
|
||||
|
||||
|
@ -307,10 +307,10 @@ namespace Components
|
||||
{
|
||||
if (!Utils::IO::FileExists(ArchiveDvarPath))
|
||||
{
|
||||
Utils::IO::WriteFile(ArchiveDvarPath, "// generated by IW4x, do not modify\n");
|
||||
Utils::IO::WriteFile(ArchiveDvarPath, "// generated by IW4x, do not modify\n", false);
|
||||
}
|
||||
|
||||
Utils::IO::WriteFile(ArchiveDvarPath, Utils::String::VA("seta %s \"%s\"\n", var->name, Game::Dvar_DisplayableValue(var)), true);
|
||||
Utils::IO::WriteFile(ArchiveDvarPath, std::format("set {} \"{}\"\n", var->name, Game::Dvar_DisplayableValue(var)), true);
|
||||
}
|
||||
|
||||
void Dvar::DvarSetFromStringByName_Stub(const char* dvarName, const char* value)
|
||||
|
@ -235,10 +235,11 @@ namespace Components
|
||||
const char* dir = Dvar::Var("fs_basepath").get<const char*>();
|
||||
|
||||
std::vector<std::string> paths;
|
||||
std::string modDir = Dvar::Var("fs_game").get<std::string>();
|
||||
auto modDir = Dvar::Var("fs_game").get<std::string>();
|
||||
|
||||
if ((file == "mod"s || file == "mod.ff"s) && !modDir.empty())
|
||||
{
|
||||
paths.push_back(Utils::String::VA("%s\\", modDir.data()));
|
||||
paths.push_back(std::format("{}\\", modDir));
|
||||
}
|
||||
|
||||
if (Utils::String::StartsWith(file, "mp_"))
|
||||
@ -256,17 +257,17 @@ namespace Components
|
||||
Utils::String::Replace(zone, "_load", "");
|
||||
}
|
||||
|
||||
if (Utils::IO::FileExists(Utils::String::VA("usermaps\\%s\\%s.ff", zone.data(), filename.data())))
|
||||
if (Utils::IO::FileExists(std::format("usermaps\\{}\\{}.ff", zone, filename)))
|
||||
{
|
||||
return Utils::String::VA("usermaps\\%s\\", zone.data());
|
||||
return Utils::String::Format("usermaps\\{}\\", zone);
|
||||
}
|
||||
}
|
||||
|
||||
Utils::Merge(&paths, FastFiles::ZonePaths);
|
||||
|
||||
for (auto &path : paths)
|
||||
for (auto& path : paths)
|
||||
{
|
||||
std::string absoluteFile = Utils::String::VA("%s\\%s%s", dir, path.data(), file);
|
||||
auto absoluteFile = std::format("{}\\{}{}", dir, path, file);
|
||||
|
||||
// No ".ff" appended, append it manually
|
||||
if (!Utils::String::EndsWith(absoluteFile, ".ff"))
|
||||
@ -277,11 +278,11 @@ namespace Components
|
||||
// Check if FastFile exists
|
||||
if (Utils::IO::FileExists(absoluteFile))
|
||||
{
|
||||
return Utils::String::VA("%s", path.data());
|
||||
return Utils::String::Format("{}", path);
|
||||
}
|
||||
}
|
||||
|
||||
return Utils::String::VA("zone\\%s\\", Game::Win_GetLanguage());
|
||||
return Utils::String::Format("zone\\{}\\", Game::Win_GetLanguage());
|
||||
}
|
||||
|
||||
void FastFiles::AddZonePath(const std::string& path)
|
||||
|
@ -329,7 +329,7 @@ namespace Components
|
||||
const auto name = Utils::String::ToLower(*pName);
|
||||
for (const auto& func : CustomScrFunctions)
|
||||
{
|
||||
if (std::ranges::find(func.aliases, name) != func.aliases.end())
|
||||
if (Utils::Contains(&func.aliases, name))
|
||||
{
|
||||
*type = func.type;
|
||||
return func.actionFunc;
|
||||
@ -356,7 +356,7 @@ namespace Components
|
||||
const auto name = Utils::String::ToLower(*pName);
|
||||
for (const auto& meth : CustomScrMethods)
|
||||
{
|
||||
if (std::ranges::find(meth.aliases, name) != meth.aliases.end())
|
||||
if (Utils::Contains(&meth.aliases, name))
|
||||
{
|
||||
*type = meth.type;
|
||||
return meth.actionFunc;
|
||||
|
@ -78,7 +78,7 @@ namespace Components
|
||||
std::string data;
|
||||
for (auto& gametype : gametypes)
|
||||
{
|
||||
if (Game::Scr_AddSourceBuffer(nullptr, Utils::String::VA("maps/mp/gametypes/%s.txt", gametype.data()), nullptr, false))
|
||||
if (Game::Scr_AddSourceBuffer(nullptr, Utils::String::Format("maps/mp/gametypes/{}.txt", gametype), nullptr, false))
|
||||
{
|
||||
data.append(gametype);
|
||||
data.append("\r\n");
|
||||
|
@ -266,8 +266,8 @@ namespace Components
|
||||
{
|
||||
if (params->size() < 2) return;
|
||||
|
||||
const auto num = atoi(params->get(1));
|
||||
if (Utils::String::VA("%i", num) == std::string(params->get(1)) && static_cast<unsigned int>(num) < LoggingAddresses[0].size())
|
||||
const auto num = std::atoi(params->get(1));
|
||||
if (!std::strcmp(Utils::String::VA("%i", num), params->get(1)) && static_cast<unsigned int>(num) < LoggingAddresses[0].size())
|
||||
{
|
||||
auto addr = Logger::LoggingAddresses[0].begin() + num;
|
||||
Print("Address {} removed\n", addr->getString());
|
||||
@ -318,7 +318,7 @@ namespace Components
|
||||
if (params->size() < 2) return;
|
||||
|
||||
const auto num = std::atoi(params->get(1));
|
||||
if (Utils::String::VA("%i", num) == std::string(params->get(1)) && static_cast<unsigned int>(num) < LoggingAddresses[1].size())
|
||||
if (!std::strcmp(Utils::String::VA("%i", num), params->get(1)) && static_cast<unsigned int>(num) < LoggingAddresses[1].size())
|
||||
{
|
||||
const auto addr = LoggingAddresses[1].begin() + num;
|
||||
Print("Address {} removed\n", addr->getString());
|
||||
|
@ -29,8 +29,8 @@ namespace Components
|
||||
{
|
||||
if (this->isValid() && !this->searchPath.iwd)
|
||||
{
|
||||
std::string iwdName = Utils::String::VA("%s.iwd", this->mapname.data());
|
||||
std::string path = Utils::String::VA("%s\\usermaps\\%s\\%s", Dvar::Var("fs_basepath").get<const char*>(), this->mapname.data(), iwdName.data());
|
||||
auto iwdName = std::format("{}.iwd", this->mapname);
|
||||
auto path = std::format("{}\\usermaps\\{}\\{}", Dvar::Var("fs_basepath").get<std::string>(), this->mapname, iwdName);
|
||||
|
||||
if (Utils::IO::FileExists(path))
|
||||
{
|
||||
@ -146,10 +146,10 @@ namespace Components
|
||||
team.allocFlags = zoneInfo->allocFlags;
|
||||
team.freeFlags = zoneInfo->freeFlags;
|
||||
|
||||
team.name = allocator.duplicateString(Utils::String::VA("iw4x_team_%s", teams.first.data()));
|
||||
team.name = allocator.duplicateString(std::format("iw4x_team_{}", teams.first));
|
||||
data.push_back(team);
|
||||
|
||||
team.name = allocator.duplicateString(Utils::String::VA("iw4x_team_%s", teams.second.data()));
|
||||
team.name = allocator.duplicateString(std::format("iw4x_team_{}", teams.second));
|
||||
data.push_back(team);
|
||||
}
|
||||
|
||||
@ -166,7 +166,7 @@ namespace Components
|
||||
}
|
||||
|
||||
// Load patch files
|
||||
std::string patchZone = Utils::String::VA("patch_%s", zoneInfo->name);
|
||||
auto patchZone = std::format("patch_{}", zoneInfo->name);
|
||||
if (FastFiles::Exists(patchZone))
|
||||
{
|
||||
data.push_back({patchZone.data(), zoneInfo->allocFlags, zoneInfo->freeFlags});
|
||||
@ -301,7 +301,7 @@ namespace Components
|
||||
|
||||
Game::GfxWorld* world = *reinterpret_cast<Game::GfxWorld**>(0x66DEE94);
|
||||
|
||||
if (FileSystem::File(Utils::String::VA("sun/%s.sun", Maps::CurrentMainZone.data())).exists())
|
||||
if (FileSystem::File(std::format("sun/{}.sun", Maps::CurrentMainZone)))
|
||||
{
|
||||
Game::R_LoadSunThroughDvars(Maps::CurrentMainZone.data(), &world->sun);
|
||||
}
|
||||
@ -404,13 +404,13 @@ namespace Components
|
||||
|
||||
unsigned int Maps::GetUsermapHash(const std::string& map)
|
||||
{
|
||||
if (Utils::IO::DirectoryExists(Utils::String::VA("usermaps/%s", map.data())))
|
||||
if (Utils::IO::DirectoryExists(std::format("usermaps/{}", map)))
|
||||
{
|
||||
std::string hash;
|
||||
|
||||
for (std::size_t i = 0; i < ARRAYSIZE(Maps::UserMapFiles); ++i)
|
||||
{
|
||||
std::string filePath = Utils::String::VA("usermaps/%s/%s%s", map.data(), map.data(), Maps::UserMapFiles[i]);
|
||||
auto filePath = std::format("usermaps/{}/{}{}", map, map, Maps::UserMapFiles[i]);
|
||||
if (Utils::IO::FileExists(filePath))
|
||||
{
|
||||
hash.append(Utils::Cryptography::SHA256::Compute(Utils::IO::ReadFile(filePath)));
|
||||
@ -570,7 +570,7 @@ namespace Components
|
||||
|
||||
bool Maps::IsUserMap(const std::string& mapname)
|
||||
{
|
||||
return Utils::IO::DirectoryExists(Utils::String::VA("usermaps/%s", mapname.data())) && Utils::IO::FileExists(Utils::String::VA("usermaps/%s/%s.ff", mapname.data(), mapname.data()));
|
||||
return Utils::IO::DirectoryExists(std::format("usermaps/{}", mapname)) && Utils::IO::FileExists(std::format("usermaps/{}/{}.ff", mapname, mapname));
|
||||
}
|
||||
|
||||
Game::XAssetEntry* Maps::GetAssetEntryPool()
|
||||
@ -916,7 +916,7 @@ namespace Components
|
||||
unsigned int i = 0;
|
||||
for (auto& model : models)
|
||||
{
|
||||
Game::R_AddCmdDrawText(Utils::String::VA("%d %s", model.second, model.first.data()), 0x7FFFFFFF, font, 15.0f, (height * scale + 1) * (i++ + 1) + 15.0f, scale, scale, 0.0f, color, Game::ITEM_TEXTSTYLE_NORMAL);
|
||||
Game::R_AddCmdDrawText(Utils::String::VA("%d %s", model.second, model.first.data()), std::numeric_limits<int>::max(), font, 15.0f, (height * scale + 1) * (i++ + 1) + 15.0f, scale, scale, 0.0f, color, Game::ITEM_TEXTSTYLE_NORMAL);
|
||||
}
|
||||
}, Scheduler::Pipeline::RENDERER);
|
||||
}
|
||||
|
@ -60,7 +60,6 @@ namespace Components
|
||||
{
|
||||
auto fsGame = Dvar::Var("fs_game");
|
||||
fsGame.set("");
|
||||
fsGame.get<Game::dvar_t*>()->modified = true;
|
||||
|
||||
if (Dvar::Var("cl_modVidRestart").get<bool>())
|
||||
{
|
||||
@ -75,8 +74,7 @@ namespace Components
|
||||
void ModList::RunMod(const std::string& mod)
|
||||
{
|
||||
auto fsGame = Dvar::Var("fs_game");
|
||||
fsGame.set(Utils::String::VA("mods/%s", mod.data()));
|
||||
fsGame.get<Game::dvar_t*>()->modified = true;
|
||||
fsGame.set(std::format("mods/{}", mod));
|
||||
|
||||
if (Dvar::Var("cl_modVidRestart").get<bool>())
|
||||
{
|
||||
|
@ -38,7 +38,7 @@ namespace Components
|
||||
Game::XModelSurfs* ModelSurfs::LoadXModelSurfaces(const std::string& name)
|
||||
{
|
||||
Utils::Memory::Allocator allocator;
|
||||
FileSystem::FileReader model(Utils::String::VA("models/%s", name.data()));
|
||||
FileSystem::FileReader model(std::format("models/{}", name));
|
||||
|
||||
if (!model.exists())
|
||||
{
|
||||
|
@ -576,7 +576,8 @@ namespace Components
|
||||
formatString = "userraw/shader_bin/%.vs";
|
||||
}
|
||||
|
||||
if (Utils::IO::FileExists(Utils::String::VA(formatString, name.data()))) return;
|
||||
const auto path = std::format("{}{}", formatString, name);
|
||||
if (Utils::IO::FileExists(path)) return;
|
||||
|
||||
Utils::Stream buffer(0x1000);
|
||||
auto* dest = buffer.dest<Game::MaterialPixelShader>();
|
||||
@ -588,7 +589,7 @@ namespace Components
|
||||
Utils::Stream::ClearPointer(&dest->prog.loadDef.program);
|
||||
}
|
||||
|
||||
Utils::IO::WriteFile(Utils::String::VA(formatString, name.data()), buffer.toBuffer());
|
||||
Utils::IO::WriteFile(path, buffer.toBuffer());
|
||||
}
|
||||
|
||||
if (type == Game::ASSET_TYPE_TECHNIQUE_SET)
|
||||
|
@ -199,7 +199,7 @@ namespace Components
|
||||
for (int i = 156;; ++i)
|
||||
{
|
||||
// We're on DB thread (OnLoad) so use DB thread for FS
|
||||
FileSystem::File definition(Utils::String::VA("%s/%d.json", filename.data(), i), Game::FsThread::FS_THREAD_DATABASE);
|
||||
FileSystem::File definition(std::format("{}/{}.json", filename, i), Game::FsThread::FS_THREAD_DATABASE);
|
||||
if (!definition.exists()) break;
|
||||
|
||||
std::vector<std::vector<std::string>> enumContainer;
|
||||
|
@ -190,9 +190,7 @@ namespace Components
|
||||
|
||||
for (auto demo : demos)
|
||||
{
|
||||
FileSystem::File meta(Utils::String::VA("demos/%s.json", demo.data()));
|
||||
|
||||
if (meta.exists())
|
||||
if (FileSystem::File meta = std::format("demos/{}.json", demo))
|
||||
{
|
||||
nlohmann::json metaObject;
|
||||
try
|
||||
@ -206,7 +204,7 @@ namespace Components
|
||||
demoInfo.mapname = metaObject["mapname"].get<std::string>();
|
||||
demoInfo.length = metaObject["length"].get<int>();
|
||||
auto timestamp = metaObject["timestamp"].get<std::string>();
|
||||
demoInfo.timeStamp = _atoi64(timestamp.data());
|
||||
demoInfo.timeStamp = std::strtoll(timestamp.data(), nullptr, 10);
|
||||
|
||||
Demos.push_back(demoInfo);
|
||||
}
|
||||
@ -312,11 +310,11 @@ namespace Components
|
||||
for (auto i = 0; i < numDel; ++i)
|
||||
{
|
||||
Logger::Print("Deleting old demo {}\n", files[i]);
|
||||
FileSystem::_DeleteFile("demos", files[i].data());
|
||||
FileSystem::_DeleteFile("demos", Utils::String::VA("%s.json", files[i].data()));
|
||||
FileSystem::_DeleteFile("demos", files[i]);
|
||||
FileSystem::_DeleteFile("demos", std::format("%s.json", files[i]));
|
||||
}
|
||||
|
||||
Command::Execute(Utils::String::VA("record auto_%lld", time(nullptr)), true);
|
||||
Command::Execute(Utils::String::VA("record auto_%lld", std::time(nullptr)), true);
|
||||
}
|
||||
|
||||
return Utils::Hook::Call<DWORD()>(0x42BBB0)();
|
||||
|
@ -23,7 +23,7 @@ namespace Components
|
||||
// Side note: if you need a fastfile larger than 100MB, you're doing it wrong-
|
||||
// Well, decompressed maps can get way larger than 100MB, so let's increase that.
|
||||
buffer(0xC800000),
|
||||
zoneName(name), dataMap("zone_source/" + name + ".csv"), branding{ nullptr }, assetDepth(0)
|
||||
zoneName(name), dataMap("zone_source/" + name + ".csv"), branding{nullptr}, assetDepth(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -1196,9 +1196,10 @@ namespace Components
|
||||
Zone(zoneName).build();
|
||||
});
|
||||
|
||||
Command::Add("buildall", [](Command::Params*)
|
||||
Command::Add("buildall", []([[maybe_unused]] Command::Params* params)
|
||||
{
|
||||
auto zoneSources = FileSystem::GetSysFileList(Dvar::Var("fs_basepath").get<std::string>() + "\\zone_source", "csv", false);
|
||||
auto path = std::format("{}\\zone_source", Dvar::Var("fs_basepath").get<std::string>());
|
||||
auto zoneSources = FileSystem::GetSysFileList(path, "csv", false);
|
||||
|
||||
for (auto source : zoneSources)
|
||||
{
|
||||
@ -1207,7 +1208,7 @@ namespace Components
|
||||
source = source.substr(0, source.find(".csv"));
|
||||
}
|
||||
|
||||
Command::Execute(Utils::String::VA("buildzone %s", source.data()), true);
|
||||
Command::Execute(std::format("buildzone {}", source), true);
|
||||
}
|
||||
});
|
||||
|
||||
@ -1528,12 +1529,12 @@ namespace Components
|
||||
{
|
||||
if (params->size() < 2) return;
|
||||
|
||||
std::string path = Utils::String::VA("%s\\mods\\%s\\images", Dvar::Var("fs_basepath").get<const char*>(), params->get(1));
|
||||
std::vector<std::string> images = FileSystem::GetSysFileList(path, "iwi", false);
|
||||
auto path = std::format("{}\\mods\\{}\\images", Dvar::Var("fs_basepath").get<std::string>(), params->get(1));
|
||||
auto images = FileSystem::GetSysFileList(path, "iwi", false);
|
||||
|
||||
for(auto i = images.begin(); i != images.end();)
|
||||
for (auto i = images.begin(); i != images.end();)
|
||||
{
|
||||
*i = Utils::String::VA("images/%s", i->data());
|
||||
*i = std::format("images/{}", *i);
|
||||
|
||||
if (FileSystem::File(*i).exists())
|
||||
{
|
||||
|
@ -3515,7 +3515,7 @@ namespace Components
|
||||
Logger::Print("decrypted {} images!\n", images.size());
|
||||
});
|
||||
|
||||
Command::Add("decryptSounds", [](Command::Params*)
|
||||
Command::Add("decryptSounds", []([[maybe_unused]] Command::Params* params)
|
||||
{
|
||||
auto sounds = FileSystem::GetSysFileList("iw4x/sound", "iwi");
|
||||
Logger::Print("decrypting {} sounds...\n", sounds.size());
|
||||
@ -3523,19 +3523,19 @@ namespace Components
|
||||
for (auto& sound : sounds)
|
||||
{
|
||||
char* buffer = nullptr;
|
||||
auto fileLength = Game::FS_ReadFile(Utils::String::VA("sound/%s", sound.data()), &buffer);
|
||||
auto len = Game::FS_ReadFile(Utils::String::Format("sound/{}", sound), &buffer);
|
||||
|
||||
if (fileLength && buffer)
|
||||
if (len && buffer)
|
||||
{
|
||||
auto path = std::filesystem::path(sound.data());
|
||||
std::filesystem::create_directories("raw/sound" / path.parent_path());
|
||||
|
||||
if (!std::filesystem::exists(Utils::String::VA("raw/sound/%s", sound.data())))
|
||||
if (!std::filesystem::exists(std::format("raw/sound/{}", sound)))
|
||||
{
|
||||
const auto fp = fopen(Utils::String::VA("raw/sound/%s", sound.data()), "wb");
|
||||
if (fp)
|
||||
FILE* fp;
|
||||
if (!fopen_s(&fp, Utils::String::Format("raw/sound/{}", sound), "wb") && fp)
|
||||
{
|
||||
fwrite(buffer, fileLength, 1, fp);
|
||||
fwrite(buffer, len, 1, fp);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ namespace Utils
|
||||
|
||||
if (this->criticalSectionState != 0)
|
||||
{
|
||||
MessageBoxA(nullptr, Utils::String::VA("Invalid critical section state '%i' for stream destruction!", this->criticalSectionState), "WARNING", MB_ICONEXCLAMATION);
|
||||
MessageBoxA(nullptr, String::VA("Invalid critical section state '%i' for stream destruction!", this->criticalSectionState), "WARNING", MB_ICONEXCLAMATION);
|
||||
}
|
||||
};
|
||||
|
||||
@ -163,7 +163,7 @@ namespace Utils
|
||||
|
||||
if (this->isCriticalSection() && this->length() + (size * count) > this->capacity())
|
||||
{
|
||||
MessageBoxA(nullptr, Utils::String::VA("Potential stream reallocation during critical operation detected! Writing data of the length 0x%X exceeds the allocated stream size of 0x%X\n", (size * count), this->capacity()), "ERROR", MB_ICONERROR);
|
||||
MessageBoxA(nullptr, String::VA("Potential stream reallocation during critical operation detected! Writing data of the length 0x%X exceeds the allocated stream size of 0x%X\n", (size * count), this->capacity()), "ERROR", MB_ICONERROR);
|
||||
__debugbreak();
|
||||
}
|
||||
|
||||
@ -291,9 +291,9 @@ namespace Utils
|
||||
}
|
||||
|
||||
#ifdef WRITE_LOGS
|
||||
std::string data = Utils::String::VA("%*s%d\n", this->structLevel, "", size);
|
||||
if (stream == Game::XFILE_BLOCK_RUNTIME) data = Utils::String::VA("%*s(%d)\n", this->structLevel, "", size);
|
||||
Utils::IO::WriteFile("userraw/logs/zb_writes.log", data, true);
|
||||
const auto* data = String::VA("%*s%u\n", this->structLevel, "", size);
|
||||
if (stream == Game::XFILE_BLOCK_RUNTIME) data = String::VA("%*s(%u)\n", this->structLevel, "", size);
|
||||
IO::WriteFile("userraw/logs/zb_writes.log", data, true);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -365,7 +365,7 @@ namespace Utils
|
||||
--this->criticalSectionState;
|
||||
}
|
||||
|
||||
bool Stream::isCriticalSection()
|
||||
bool Stream::isCriticalSection() const
|
||||
{
|
||||
if (this->criticalSectionState < 0)
|
||||
{
|
||||
@ -381,7 +381,7 @@ namespace Utils
|
||||
{
|
||||
if (this->structLevel >= 0)
|
||||
{
|
||||
Utils::IO::WriteFile("userraw/logs/zb_writes.log", Utils::String::VA("%*s%s\n", this->structLevel++, "", structName), true);
|
||||
IO::WriteFile("userraw/logs/zb_writes.log", String::VA("%*s%s\n", this->structLevel++, "", structName), true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -393,7 +393,7 @@ namespace Utils
|
||||
return;
|
||||
}
|
||||
|
||||
Utils::IO::WriteFile("userraw/logs/zb_writes.log", Utils::String::VA("%*s-----\n", this->structLevel, ""), true);
|
||||
IO::WriteFile("userraw/logs/zb_writes.log", String::VA("%*s-----\n", this->structLevel, ""), true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
// write logs for ZoneBuilder
|
||||
//#define WRITE_LOGS
|
||||
|
||||
#ifndef WRITE_LOGS // they take forever to run so only enable if needed
|
||||
#define SaveLogEnter(x)
|
||||
#define SaveLogExit()
|
||||
@ -67,7 +67,7 @@ namespace Utils
|
||||
unsigned int position;
|
||||
std::string buffer;
|
||||
std::map<void*, void*> pointerMap;
|
||||
Utils::Memory::Allocator* allocator;
|
||||
Memory::Allocator* allocator;
|
||||
};
|
||||
|
||||
enum Alignment
|
||||
@ -89,17 +89,19 @@ namespace Utils
|
||||
Stream(size_t size);
|
||||
~Stream();
|
||||
|
||||
std::size_t length() const;
|
||||
std::size_t capacity() const;
|
||||
[[nodiscard]] std::size_t length() const;
|
||||
[[nodiscard]] std::size_t capacity() const;
|
||||
|
||||
char* save(const void * _str, std::size_t size, std::size_t count = 1);
|
||||
char* save(Game::XFILE_BLOCK_TYPES stream, const void * _str, std::size_t size, std::size_t count);
|
||||
char* save(Game::XFILE_BLOCK_TYPES stream, int value, std::size_t count);
|
||||
template <typename T> inline char* save(T* object)
|
||||
|
||||
template <typename T> char* save(T* object)
|
||||
{
|
||||
return saveArray<T>(object, 1);
|
||||
}
|
||||
template <typename T> inline char* saveArray(T* array, std::size_t count)
|
||||
|
||||
template <typename T> char* saveArray(T* array, std::size_t count)
|
||||
{
|
||||
return save(array, sizeof(T), count);
|
||||
}
|
||||
@ -131,7 +133,8 @@ namespace Utils
|
||||
{
|
||||
return reinterpret_cast<T*>(this->at());
|
||||
}
|
||||
template <typename T> static inline void ClearPointer(T** object)
|
||||
|
||||
template <typename T> static void ClearPointer(T** object)
|
||||
{
|
||||
*object = reinterpret_cast<T*>(-1);
|
||||
}
|
||||
@ -151,7 +154,7 @@ namespace Utils
|
||||
// by editing the code though.
|
||||
void enterCriticalSection();
|
||||
void leaveCriticalSection();
|
||||
bool isCriticalSection();
|
||||
bool isCriticalSection() const;
|
||||
|
||||
// for recording zb writes
|
||||
#ifdef WRITE_LOGS
|
||||
|
@ -84,6 +84,17 @@ namespace Utils::String
|
||||
|
||||
[[nodiscard]] const char* VA(const char* fmt, ...);
|
||||
|
||||
template <typename... Args>
|
||||
[[nodiscard]] const char* Format(std::string_view fmt, Args&&... args)
|
||||
{
|
||||
static thread_local std::string vaBuffer;
|
||||
vaBuffer.clear();
|
||||
|
||||
(SanitizeFormatArgs(args), ...);
|
||||
std::vformat_to(std::back_inserter(vaBuffer), fmt, std::make_format_args(args...));
|
||||
return vaBuffer.data();
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string ToLower(const std::string& text);
|
||||
[[nodiscard]] std::string ToUpper(const std::string& text);
|
||||
|
||||
|
@ -25,7 +25,8 @@ namespace Utils
|
||||
|
||||
bool HasIntersection(unsigned int base1, unsigned int len1, unsigned int base2, unsigned int len2);
|
||||
|
||||
template <typename T> void RotLeft(T& object, size_t bits)
|
||||
template <typename T>
|
||||
void RotLeft(T& object, std::size_t bits)
|
||||
{
|
||||
bits %= sizeof(T) * 8;
|
||||
|
||||
@ -38,31 +39,40 @@ namespace Utils
|
||||
object |= T(negative) << ((sizeof(T) * 8 - 1 + bits) % (sizeof(T) * 8));
|
||||
}
|
||||
|
||||
template <typename T> void RotRight(T& object, size_t bits)
|
||||
template <typename T>
|
||||
void RotRight(T& object, std::size_t bits)
|
||||
{
|
||||
bits %= (sizeof(T) * 8);
|
||||
RotLeft<T>(object, ((sizeof(T) * 8) - bits));
|
||||
}
|
||||
|
||||
template <typename T> void Merge(std::vector<T>* target, T* source, size_t length)
|
||||
template <typename T>
|
||||
void Merge(std::vector<T>* target, T* source, std::size_t length)
|
||||
{
|
||||
if (source)
|
||||
{
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
for (std::size_t i = 0; i < length; ++i)
|
||||
{
|
||||
target->push_back(source[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> void Merge(std::vector<T>* target, std::vector<T> source)
|
||||
template <typename T>
|
||||
void Merge(std::vector<T>* target, std::vector<T> source)
|
||||
{
|
||||
for (auto &entry : source)
|
||||
for (auto& entry : source)
|
||||
{
|
||||
target->push_back(entry);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Contains(const std::vector<T>* haystack, T needle)
|
||||
{
|
||||
return std::ranges::find(*haystack, needle) != haystack->end();
|
||||
}
|
||||
|
||||
template <typename T> using Slot = std::function<T>;
|
||||
template <typename T>
|
||||
class Signal
|
||||
|
Loading…
x
Reference in New Issue
Block a user