diff --git a/src/Components/Modules/AssetHandler.cpp b/src/Components/Modules/AssetHandler.cpp index 5bfd108d..82aa25ec 100644 --- a/src/Components/Modules/AssetHandler.cpp +++ b/src/Components/Modules/AssetHandler.cpp @@ -156,7 +156,7 @@ namespace Components } } - void AssetHandler::ModifyAsset(Game::XAssetType type, Game::XAssetHeader asset, std::string name) + void AssetHandler::ModifyAsset(Game::XAssetType type, Game::XAssetHeader asset, const std::string& name) { if (type == Game::XAssetType::ASSET_TYPE_MATERIAL && (name == "gfx_distortion_knife_trail" || name == "gfx_distortion_heat_far" || name == "gfx_distortion_ring_light" || name == "gfx_distortion_heat") && asset.material->info.sortKey >= 43) { @@ -330,7 +330,7 @@ namespace Components } } - Game::XAssetHeader AssetHandler::FindAssetForZone(Game::XAssetType type, std::string filename, ZoneBuilder::Zone* builder, bool isSubAsset) + Game::XAssetHeader AssetHandler::FindAssetForZone(Game::XAssetType type, const std::string& filename, ZoneBuilder::Zone* builder, bool isSubAsset) { ZoneBuilder::Zone::AssetRecursionMarker _(builder); diff --git a/src/Components/Modules/AssetHandler.hpp b/src/Components/Modules/AssetHandler.hpp index e53f57f7..71f9a5cf 100644 --- a/src/Components/Modules/AssetHandler.hpp +++ b/src/Components/Modules/AssetHandler.hpp @@ -13,11 +13,11 @@ namespace Components virtual void mark(Game::XAssetHeader /*header*/, ZoneBuilder::Zone* /*builder*/) { /*ErrorTypeNotSupported(this);*/ }; virtual void save(Game::XAssetHeader /*header*/, ZoneBuilder::Zone* /*builder*/) { /*ErrorTypeNotSupported(this);*/ }; virtual void dump(Game::XAssetHeader /*header*/) { /*ErrorTypeNotSupported(this);*/ }; - virtual void load(Game::XAssetHeader* /*header*/, std::string name, ZoneBuilder::Zone* /*builder*/) { /*ErrorTypeNotSupported(this);*/ }; + virtual void load(Game::XAssetHeader* /*header*/, const std::string& /*name*/, ZoneBuilder::Zone* /*builder*/) { /*ErrorTypeNotSupported(this);*/ }; }; - typedef Game::XAssetHeader(Callback)(Game::XAssetType type, std::string name); - typedef void(RestrictCallback)(Game::XAssetType type, Game::XAssetHeader asset, std::string name, bool* restrict); + typedef Game::XAssetHeader(Callback)(Game::XAssetType type, const std::string& name); + typedef void(RestrictCallback)(Game::XAssetType type, Game::XAssetHeader asset, const std::string& name, bool* restrict); AssetHandler(); ~AssetHandler(); @@ -32,7 +32,7 @@ namespace Components static void ZoneMark(Game::XAsset asset, ZoneBuilder::Zone* builder); static Game::XAssetHeader FindOriginalAsset(Game::XAssetType type, const char* filename); - static Game::XAssetHeader FindAssetForZone(Game::XAssetType type, std::string filename, ZoneBuilder::Zone* builder, bool isSubAsset = true); + static Game::XAssetHeader FindAssetForZone(Game::XAssetType type, const std::string& filename, ZoneBuilder::Zone* builder, bool isSubAsset = true); static void ClearTemporaryAssets(); static void StoreTemporaryAsset(Game::XAssetType type, Game::XAssetHeader asset); @@ -64,7 +64,7 @@ namespace Components static void StoreEmptyAsset(Game::XAssetType type, const char* name); static void StoreEmptyAssetStub(); - static void ModifyAsset(Game::XAssetType type, Game::XAssetHeader asset, std::string name); + static void ModifyAsset(Game::XAssetType type, Game::XAssetHeader asset, const std::string& name); static int HasThreadBypass(); static void SetBypassState(bool value); diff --git a/src/Components/Modules/AssetInterfaces/IComWorld.cpp b/src/Components/Modules/AssetInterfaces/IComWorld.cpp index bf81b683..a12dd771 100644 --- a/src/Components/Modules/AssetInterfaces/IComWorld.cpp +++ b/src/Components/Modules/AssetInterfaces/IComWorld.cpp @@ -4,8 +4,9 @@ namespace Assets { - void IComWorld::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) + void IComWorld::load(Game::XAssetHeader* header, const std::string& _name, Components::ZoneBuilder::Zone* builder) { + std::string name = _name; Utils::String::Replace(name, "maps/mp/", ""); Utils::String::Replace(name, ".d3dbsp", ""); diff --git a/src/Components/Modules/AssetInterfaces/IComWorld.hpp b/src/Components/Modules/AssetInterfaces/IComWorld.hpp index a1ad9ccc..ef6f37d4 100644 --- a/src/Components/Modules/AssetInterfaces/IComWorld.hpp +++ b/src/Components/Modules/AssetInterfaces/IComWorld.hpp @@ -9,6 +9,6 @@ namespace Assets virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; virtual void mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; - virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override; + virtual void load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) override; }; } diff --git a/src/Components/Modules/AssetInterfaces/IFxEffectDef.cpp b/src/Components/Modules/AssetInterfaces/IFxEffectDef.cpp index fb32fad9..7cd2c87d 100644 --- a/src/Components/Modules/AssetInterfaces/IFxEffectDef.cpp +++ b/src/Components/Modules/AssetInterfaces/IFxEffectDef.cpp @@ -4,7 +4,7 @@ namespace Assets { - void IFxEffectDef::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) + void IFxEffectDef::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) { if (!header->data) this->loadEfx(header, name, builder); // Check if we have an editor fx if (!header->data /*&& !builder->isPrimaryAsset()*/) this->loadNative(header, name, builder); // Check if there is a native one @@ -63,7 +63,7 @@ namespace Assets } } - void IFxEffectDef::loadBinary(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) + 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())); @@ -198,7 +198,7 @@ namespace Assets } } - void IFxEffectDef::loadEfx(Game::XAssetHeader* /*header*/, std::string name, Components::ZoneBuilder::Zone* /*builder*/) + void IFxEffectDef::loadEfx(Game::XAssetHeader* /*header*/, const std::string& name, Components::ZoneBuilder::Zone* /*builder*/) { #ifdef DEBUG Components::FileSystem::File rawFx(Utils::String::VA("fx/%s.efx", name.data())); @@ -270,10 +270,12 @@ namespace Assets // TODO: Convert editor fx to real fx } +#else + (name); #endif } - void IFxEffectDef::loadNative(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* /*builder*/) + void IFxEffectDef::loadNative(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* /*builder*/) { header->fx = Components::AssetHandler::FindOriginalAsset(this->getType(), name.data()).fx; } diff --git a/src/Components/Modules/AssetInterfaces/IFxEffectDef.hpp b/src/Components/Modules/AssetInterfaces/IFxEffectDef.hpp index c9c9fefa..4fcc5e4d 100644 --- a/src/Components/Modules/AssetInterfaces/IFxEffectDef.hpp +++ b/src/Components/Modules/AssetInterfaces/IFxEffectDef.hpp @@ -9,15 +9,15 @@ namespace Assets virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; virtual void mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; - virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override; + virtual void load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) override; private: void markFxElemVisuals(Game::FxElemVisuals* visuals, char elemType, Components::ZoneBuilder::Zone* builder); void saveFxElemVisuals(Game::FxElemVisuals* visuals, Game::FxElemVisuals* destVisuals, char elemType, Components::ZoneBuilder::Zone* builder); - void loadEfx(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder); - void loadNative(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder); - void loadBinary(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder); + void loadEfx(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder); + void loadNative(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder); + void loadBinary(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder); void loadFxElemVisuals(Game::FxElemVisuals* visuals, char elemType, Components::ZoneBuilder::Zone* builder, Utils::Stream::Reader* reader); }; diff --git a/src/Components/Modules/AssetInterfaces/IFxWorld.cpp b/src/Components/Modules/AssetInterfaces/IFxWorld.cpp index 1b5675ab..93bbc709 100644 --- a/src/Components/Modules/AssetInterfaces/IFxWorld.cpp +++ b/src/Components/Modules/AssetInterfaces/IFxWorld.cpp @@ -184,7 +184,7 @@ namespace Assets } } } - void IFxWorld::load(Game::XAssetHeader* /*header*/, std::string name, Components::ZoneBuilder::Zone* /*builder*/) + void IFxWorld::load(Game::XAssetHeader* /*header*/, const std::string& name, Components::ZoneBuilder::Zone* /*builder*/) { Game::FxWorld* map = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_FXWORLD, name.data()).fxWorld; if (map) return; diff --git a/src/Components/Modules/AssetInterfaces/IFxWorld.hpp b/src/Components/Modules/AssetInterfaces/IFxWorld.hpp index 5608fa04..6cca8769 100644 --- a/src/Components/Modules/AssetInterfaces/IFxWorld.hpp +++ b/src/Components/Modules/AssetInterfaces/IFxWorld.hpp @@ -9,6 +9,6 @@ namespace Assets virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; virtual void mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; - virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override; + virtual void load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) override; }; } diff --git a/src/Components/Modules/AssetInterfaces/IGfxImage.cpp b/src/Components/Modules/AssetInterfaces/IGfxImage.cpp index 63ee229a..f39a7ea4 100644 --- a/src/Components/Modules/AssetInterfaces/IGfxImage.cpp +++ b/src/Components/Modules/AssetInterfaces/IGfxImage.cpp @@ -4,7 +4,7 @@ namespace Assets { - void IGfxImage::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) + void IGfxImage::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) { Game::GfxImage* image = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_IMAGE, name.data()).image; if (image && name[0] != '*') return; diff --git a/src/Components/Modules/AssetInterfaces/IGfxImage.hpp b/src/Components/Modules/AssetInterfaces/IGfxImage.hpp index 7d0e9da3..209991e1 100644 --- a/src/Components/Modules/AssetInterfaces/IGfxImage.hpp +++ b/src/Components/Modules/AssetInterfaces/IGfxImage.hpp @@ -8,6 +8,6 @@ namespace Assets virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_IMAGE; }; virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; - virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override; + virtual void load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) override; }; } diff --git a/src/Components/Modules/AssetInterfaces/IGfxLightDef.cpp b/src/Components/Modules/AssetInterfaces/IGfxLightDef.cpp index 5daec41d..dec55171 100644 --- a/src/Components/Modules/AssetInterfaces/IGfxLightDef.cpp +++ b/src/Components/Modules/AssetInterfaces/IGfxLightDef.cpp @@ -4,7 +4,7 @@ namespace Assets { - void IGfxLightDef::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) + 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())); diff --git a/src/Components/Modules/AssetInterfaces/IGfxLightDef.hpp b/src/Components/Modules/AssetInterfaces/IGfxLightDef.hpp index 485333d7..d1386831 100644 --- a/src/Components/Modules/AssetInterfaces/IGfxLightDef.hpp +++ b/src/Components/Modules/AssetInterfaces/IGfxLightDef.hpp @@ -9,6 +9,6 @@ namespace Assets virtual void mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; - virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override; + virtual void load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) override; }; } diff --git a/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp b/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp index b2b60b31..7850c41e 100644 --- a/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp +++ b/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp @@ -122,8 +122,9 @@ namespace Assets } } - void IGfxWorld::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) + void IGfxWorld::load(Game::XAssetHeader* header, const std::string& _name, Components::ZoneBuilder::Zone* builder) { + std::string name = _name; Utils::String::Replace(name, "maps/mp/", ""); Utils::String::Replace(name, ".d3dbsp", ""); diff --git a/src/Components/Modules/AssetInterfaces/IGfxWorld.hpp b/src/Components/Modules/AssetInterfaces/IGfxWorld.hpp index 2061a58d..344af3a9 100644 --- a/src/Components/Modules/AssetInterfaces/IGfxWorld.hpp +++ b/src/Components/Modules/AssetInterfaces/IGfxWorld.hpp @@ -9,7 +9,7 @@ namespace Assets virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; virtual void mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; - virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override; + virtual void load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) override; private: void saveGfxWorldDpvsPlanes(Game::GfxWorld* world, Game::GfxWorldDpvsPlanes* asset, Game::GfxWorldDpvsPlanes* dest, Components::ZoneBuilder::Zone* builder); void saveGfxWorldDraw(Game::GfxWorldDraw* asset, Game::GfxWorldDraw* dest, Components::ZoneBuilder::Zone* builder); diff --git a/src/Components/Modules/AssetInterfaces/ILoadedSound.cpp b/src/Components/Modules/AssetInterfaces/ILoadedSound.cpp index f903eaa5..f2ddb8b0 100644 --- a/src/Components/Modules/AssetInterfaces/ILoadedSound.cpp +++ b/src/Components/Modules/AssetInterfaces/ILoadedSound.cpp @@ -2,7 +2,7 @@ namespace Assets { - void ILoadedSound::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) + void ILoadedSound::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) { Components::FileSystem::File soundFile(Utils::String::VA("sounds/%s", name.data())); if (!soundFile.exists()) diff --git a/src/Components/Modules/AssetInterfaces/ILoadedSound.hpp b/src/Components/Modules/AssetInterfaces/ILoadedSound.hpp index bc011afb..6e7ee497 100644 --- a/src/Components/Modules/AssetInterfaces/ILoadedSound.hpp +++ b/src/Components/Modules/AssetInterfaces/ILoadedSound.hpp @@ -7,7 +7,7 @@ namespace Assets public: virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_LOADED_SOUND; }; - virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override; + virtual void load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) override; virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; }; } diff --git a/src/Components/Modules/AssetInterfaces/IMapEnts.cpp b/src/Components/Modules/AssetInterfaces/IMapEnts.cpp index 4219e23a..ee7f525b 100644 --- a/src/Components/Modules/AssetInterfaces/IMapEnts.cpp +++ b/src/Components/Modules/AssetInterfaces/IMapEnts.cpp @@ -2,8 +2,9 @@ namespace Assets { - void IMapEnts::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) + void IMapEnts::load(Game::XAssetHeader* header, const std::string& _name, Components::ZoneBuilder::Zone* builder) { + std::string name = _name; Utils::String::Replace(name, "maps/", ""); Utils::String::Replace(name, "mp/", ""); Utils::String::Replace(name, ".d3dbsp", ""); diff --git a/src/Components/Modules/AssetInterfaces/IMapEnts.hpp b/src/Components/Modules/AssetInterfaces/IMapEnts.hpp index a49be12f..0c4628c1 100644 --- a/src/Components/Modules/AssetInterfaces/IMapEnts.hpp +++ b/src/Components/Modules/AssetInterfaces/IMapEnts.hpp @@ -9,6 +9,6 @@ namespace Assets virtual void mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; - virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override; + virtual void load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) override; }; } diff --git a/src/Components/Modules/AssetInterfaces/IMaterial.cpp b/src/Components/Modules/AssetInterfaces/IMaterial.cpp index 6e84285d..f401eccb 100644 --- a/src/Components/Modules/AssetInterfaces/IMaterial.cpp +++ b/src/Components/Modules/AssetInterfaces/IMaterial.cpp @@ -4,14 +4,14 @@ namespace Assets { - void IMaterial::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) + void IMaterial::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) { if (!header->data) this->loadJson(header, name, builder); // Check if we want to override materials if (!header->data) this->loadNative(header, name, builder); // Check if there is a native one if (!header->data) this->loadBinary(header, name, builder); // Check if we need to import a new one into the game } - void IMaterial::loadBinary(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) + void IMaterial::loadBinary(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) { static const char* techsetSuffix[] = { @@ -244,12 +244,12 @@ namespace Assets }*/ } - void IMaterial::loadNative(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* /*builder*/) + void IMaterial::loadNative(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* /*builder*/) { header->material = Components::AssetHandler::FindOriginalAsset(this->getType(), name.data()).material; } - void IMaterial::loadJson(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) + void IMaterial::loadJson(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) { Components::FileSystem::File materialInfo(Utils::String::VA("materials/%s.json", name.data())); diff --git a/src/Components/Modules/AssetInterfaces/IMaterial.hpp b/src/Components/Modules/AssetInterfaces/IMaterial.hpp index 0c478d46..3556b2fa 100644 --- a/src/Components/Modules/AssetInterfaces/IMaterial.hpp +++ b/src/Components/Modules/AssetInterfaces/IMaterial.hpp @@ -9,9 +9,9 @@ namespace Assets virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; virtual void mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; - virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override; - void loadJson(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder); - void loadNative(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder); - void loadBinary(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder); + virtual void load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) override; + void loadJson(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder); + void loadNative(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder); + void loadBinary(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder); }; } diff --git a/src/Components/Modules/AssetInterfaces/IRawFile.cpp b/src/Components/Modules/AssetInterfaces/IRawFile.cpp index 5fff00fe..07904e36 100644 --- a/src/Components/Modules/AssetInterfaces/IRawFile.cpp +++ b/src/Components/Modules/AssetInterfaces/IRawFile.cpp @@ -2,7 +2,7 @@ namespace Assets { - void IRawFile::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) + void IRawFile::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) { Components::FileSystem::File rawFile(name); diff --git a/src/Components/Modules/AssetInterfaces/IRawFile.hpp b/src/Components/Modules/AssetInterfaces/IRawFile.hpp index edf8e0ab..f441a613 100644 --- a/src/Components/Modules/AssetInterfaces/IRawFile.hpp +++ b/src/Components/Modules/AssetInterfaces/IRawFile.hpp @@ -8,6 +8,6 @@ namespace Assets virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_RAWFILE; }; virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; - virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override; + virtual void load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) override; }; } diff --git a/src/Components/Modules/AssetInterfaces/IXAnimParts.cpp b/src/Components/Modules/AssetInterfaces/IXAnimParts.cpp index b1c132cc..4071fb6e 100644 --- a/src/Components/Modules/AssetInterfaces/IXAnimParts.cpp +++ b/src/Components/Modules/AssetInterfaces/IXAnimParts.cpp @@ -4,7 +4,7 @@ namespace Assets { - void IXAnimParts::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) + 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())); diff --git a/src/Components/Modules/AssetInterfaces/IXAnimParts.hpp b/src/Components/Modules/AssetInterfaces/IXAnimParts.hpp index d114c3ab..b5b1f62a 100644 --- a/src/Components/Modules/AssetInterfaces/IXAnimParts.hpp +++ b/src/Components/Modules/AssetInterfaces/IXAnimParts.hpp @@ -9,7 +9,7 @@ namespace Assets virtual void mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; - virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override; + virtual void load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) override; private: void saveXAnimDeltaPart(Game::XAnimDeltaPart* delta, unsigned short framecount, Components::ZoneBuilder::Zone* builder); diff --git a/src/Components/Modules/AssetInterfaces/IXModel.cpp b/src/Components/Modules/AssetInterfaces/IXModel.cpp index 807d2191..9145a54e 100644 --- a/src/Components/Modules/AssetInterfaces/IXModel.cpp +++ b/src/Components/Modules/AssetInterfaces/IXModel.cpp @@ -72,7 +72,7 @@ namespace Assets } } - void IXModel::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) + void IXModel::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) { if (!builder->isPrimaryAsset()) { diff --git a/src/Components/Modules/AssetInterfaces/IXModel.hpp b/src/Components/Modules/AssetInterfaces/IXModel.hpp index 7c058954..3475c9c7 100644 --- a/src/Components/Modules/AssetInterfaces/IXModel.hpp +++ b/src/Components/Modules/AssetInterfaces/IXModel.hpp @@ -9,7 +9,7 @@ namespace Assets virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; virtual void mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; - virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override; + virtual void load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) override; private: void loadXModelSurfs(Game::XModelSurfs* asset, Utils::Stream::Reader* reader); diff --git a/src/Components/Modules/AssetInterfaces/IclipMap_t.cpp b/src/Components/Modules/AssetInterfaces/IclipMap_t.cpp index dbc2e1b9..3904ea74 100644 --- a/src/Components/Modules/AssetInterfaces/IclipMap_t.cpp +++ b/src/Components/Modules/AssetInterfaces/IclipMap_t.cpp @@ -566,8 +566,9 @@ namespace Assets builder->loadAsset(Game::XAssetType::ASSET_TYPE_MAP_ENTS, asset); } - void IclipMap_t::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) + void IclipMap_t::load(Game::XAssetHeader* header, const std::string& _name, Components::ZoneBuilder::Zone* builder) { + std::string name = _name; Utils::String::Replace(name, "maps/mp/", ""); Utils::String::Replace(name, ".d3dbsp", ""); diff --git a/src/Components/Modules/AssetInterfaces/IclipMap_t.hpp b/src/Components/Modules/AssetInterfaces/IclipMap_t.hpp index 57c88bed..777933d4 100644 --- a/src/Components/Modules/AssetInterfaces/IclipMap_t.hpp +++ b/src/Components/Modules/AssetInterfaces/IclipMap_t.hpp @@ -9,7 +9,7 @@ namespace Assets virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; virtual void mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; - virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override; + virtual void load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) override; private: class SModelQuadtree diff --git a/src/Components/Modules/AssetInterfaces/Isnd_alias_list_t.cpp b/src/Components/Modules/AssetInterfaces/Isnd_alias_list_t.cpp index 10e8052c..2bbc6a8e 100644 --- a/src/Components/Modules/AssetInterfaces/Isnd_alias_list_t.cpp +++ b/src/Components/Modules/AssetInterfaces/Isnd_alias_list_t.cpp @@ -2,7 +2,7 @@ namespace Assets { - void Isnd_alias_list_t::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) + 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", name.data())); if (!aliasFile.exists()) diff --git a/src/Components/Modules/AssetInterfaces/Isnd_alias_list_t.hpp b/src/Components/Modules/AssetInterfaces/Isnd_alias_list_t.hpp index 62cc698e..14330120 100644 --- a/src/Components/Modules/AssetInterfaces/Isnd_alias_list_t.hpp +++ b/src/Components/Modules/AssetInterfaces/Isnd_alias_list_t.hpp @@ -7,7 +7,7 @@ namespace Assets public: virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_SOUND; }; - virtual void load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override; + virtual void load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) override; virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; virtual void mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; }; diff --git a/src/Components/Modules/Auth.cpp b/src/Components/Modules/Auth.cpp index 1c661438..4a0ea9fc 100644 --- a/src/Components/Modules/Auth.cpp +++ b/src/Components/Modules/Auth.cpp @@ -237,7 +237,7 @@ namespace Components } } - unsigned __int64 Auth::GetKeyHash(std::string key) + unsigned __int64 Auth::GetKeyHash(const std::string& key) { std::string hash = Utils::Cryptography::SHA1::Compute(key); @@ -299,7 +299,7 @@ namespace Components return Auth::GetZeroBits(Auth::GuidToken, Auth::GuidKey.getPublicKey()); } - void Auth::IncreaseSecurityLevel(uint32_t level, std::string command) + void Auth::IncreaseSecurityLevel(uint32_t level, const std::string& command) { if (Auth::GetSecurityLevel() >= level) return; @@ -329,7 +329,7 @@ namespace Components } } - uint32_t Auth::GetZeroBits(Utils::Cryptography::Token token, std::string publicKey) + uint32_t Auth::GetZeroBits(Utils::Cryptography::Token token, const std::string& publicKey) { std::string message = publicKey + token.toString(); std::string hash = Utils::Cryptography::SHA512::Compute(message, false); @@ -359,7 +359,7 @@ namespace Components return bits; } - void Auth::IncrementToken(Utils::Cryptography::Token& token, Utils::Cryptography::Token& computeToken, std::string publicKey, uint32_t zeroBits, bool* cancel, uint64_t* count) + void Auth::IncrementToken(Utils::Cryptography::Token& token, Utils::Cryptography::Token& computeToken, const std::string& publicKey, uint32_t zeroBits, bool* cancel, uint64_t* count) { if (zeroBits > 512) return; // Not possible, due to SHA512 diff --git a/src/Components/Modules/Auth.hpp b/src/Components/Modules/Auth.hpp index 56ab27de..e6c0bd62 100644 --- a/src/Components/Modules/Auth.hpp +++ b/src/Components/Modules/Auth.hpp @@ -14,13 +14,13 @@ namespace Components static void StoreKey(); static void LoadKey(bool force = false); static unsigned __int64 GetKeyHash(); - static unsigned __int64 GetKeyHash(std::string key); + static unsigned __int64 GetKeyHash(const std::string& key); static uint32_t GetSecurityLevel(); - static void IncreaseSecurityLevel(uint32_t level, std::string command = ""); + static void IncreaseSecurityLevel(uint32_t level, const std::string& command = ""); - static uint32_t GetZeroBits(Utils::Cryptography::Token token, std::string publicKey); - static void IncrementToken(Utils::Cryptography::Token& token, Utils::Cryptography::Token& computeToken, std::string publicKey, uint32_t zeroBits, bool* cancel = nullptr, uint64_t* count = nullptr); + static uint32_t GetZeroBits(Utils::Cryptography::Token token, const std::string& publicKey); + static void IncrementToken(Utils::Cryptography::Token& token, Utils::Cryptography::Token& computeToken, const std::string& publicKey, uint32_t zeroBits, bool* cancel = nullptr, uint64_t* count = nullptr); private: diff --git a/src/Components/Modules/Bans.cpp b/src/Components/Modules/Bans.cpp index de2fe09c..7fdef6cb 100644 --- a/src/Components/Modules/Bans.cpp +++ b/src/Components/Modules/Bans.cpp @@ -164,7 +164,7 @@ namespace Components } } - void Bans::BanClientNum(int num, std::string reason) + void Bans::BanClientNum(int num, const std::string& reason) { if (!Dvar::Var("sv_running").get()) { diff --git a/src/Components/Modules/Bans.hpp b/src/Components/Modules/Bans.hpp index 8666d5d0..1ba76a66 100644 --- a/src/Components/Modules/Bans.hpp +++ b/src/Components/Modules/Bans.hpp @@ -10,7 +10,7 @@ namespace Components Bans(); ~Bans(); - static void BanClientNum(int num, std::string reason); + static void BanClientNum(int num, const std::string& reason); static void UnbanClient(SteamID id); static void UnbanClient(Game::netIP_t ip); diff --git a/src/Components/Modules/Colors.cpp b/src/Components/Modules/Colors.cpp index ec15c8ad..863cd821 100644 --- a/src/Components/Modules/Colors.cpp +++ b/src/Components/Modules/Colors.cpp @@ -79,7 +79,7 @@ namespace Components *out = '\0'; } - std::string Colors::Strip(std::string in) + std::string Colors::Strip(const std::string& in) { char buffer[1000] = { 0 }; // Should be more than enough Colors::Strip(in.data(), buffer, sizeof(buffer)); diff --git a/src/Components/Modules/Colors.hpp b/src/Components/Modules/Colors.hpp index f1215d46..84dd1bc8 100644 --- a/src/Components/Modules/Colors.hpp +++ b/src/Components/Modules/Colors.hpp @@ -9,7 +9,7 @@ namespace Components ~Colors(); static void Strip(const char* in, char* out, int max); - static std::string Strip(std::string in); + static std::string Strip(const std::string& in); static char Add(uint8_t r, uint8_t g, uint8_t b); diff --git a/src/Components/Modules/Command.cpp b/src/Components/Modules/Command.cpp index 8d5510c2..d5d34248 100644 --- a/src/Components/Modules/Command.cpp +++ b/src/Components/Modules/Command.cpp @@ -110,7 +110,7 @@ namespace Components } } - Game::cmd_function_t* Command::Find(std::string command) + Game::cmd_function_t* Command::Find(const std::string& command) { Game::cmd_function_t* cmdFunction = *Game::cmd_functions; diff --git a/src/Components/Modules/Command.hpp b/src/Components/Modules/Command.hpp index cd605082..17f90d7c 100644 --- a/src/Components/Modules/Command.hpp +++ b/src/Components/Modules/Command.hpp @@ -58,7 +58,7 @@ namespace Components static void AddRawSV(const char* name, void(*callback)()); static void Execute(std::string command, bool sync = true); - static Game::cmd_function_t* Find(std::string command); + static Game::cmd_function_t* Find(const std::string& command); private: static std::unordered_map> FunctionMap; diff --git a/src/Components/Modules/ConnectProtocol.cpp b/src/Components/Modules/ConnectProtocol.cpp index be490559..3b716c53 100644 --- a/src/Components/Modules/ConnectProtocol.cpp +++ b/src/Components/Modules/ConnectProtocol.cpp @@ -207,7 +207,7 @@ namespace Components if (Dedicated::IsEnabled()) return; // IPC handler - IPCPipe::On("connect", [](std::string data) + IPCPipe::On("connect", [](const std::string& data) { Command::Execute(Utils::String::VA("connect %s", data.data()), false); }); diff --git a/src/Components/Modules/Download.cpp b/src/Components/Modules/Download.cpp index eb18ae6e..628f3652 100644 --- a/src/Components/Modules/Download.cpp +++ b/src/Components/Modules/Download.cpp @@ -12,12 +12,12 @@ namespace Components #pragma region Client - void Download::InitiateMapDownload(std::string map, bool needPassword) + void Download::InitiateMapDownload(const std::string& map, bool needPassword) { Download::InitiateClientDownload(map, needPassword, true); } - void Download::InitiateClientDownload(std::string mod, bool needPassword, bool map) + void Download::InitiateClientDownload(const std::string& mod, bool needPassword, bool map) { if (Download::CLDownload.running) return; @@ -56,7 +56,7 @@ namespace Components Download::CLDownload.thread = std::thread(Download::ModDownloader, &Download::CLDownload); } - bool Download::ParseModList(ClientDownload* download, std::string list) + bool Download::ParseModList(ClientDownload* download, const std::string& list) { if (!download) return false; download->files.clear(); diff --git a/src/Components/Modules/Download.hpp b/src/Components/Modules/Download.hpp index 3c53a7c9..88d7da5d 100644 --- a/src/Components/Modules/Download.hpp +++ b/src/Components/Modules/Download.hpp @@ -11,8 +11,8 @@ namespace Components void preDestroy() override; - static void InitiateClientDownload(std::string mod, bool needPassword, bool map = false); - static void InitiateMapDownload(std::string map, bool needPassword); + static void InitiateClientDownload(const std::string& mod, bool needPassword, bool map = false); + static void InitiateMapDownload(const std::string& map, bool needPassword); private: class ClientDownload @@ -85,7 +85,7 @@ namespace Components class ScriptDownload { public: - ScriptDownload(std::string _url, unsigned int _object) : url(_url), object(_object), webIO(nullptr), done(false), notifyRequired(false), totalSize(0), currentSize(0) + ScriptDownload(const std::string& _url, unsigned int _object) : url(_url), object(_object), webIO(nullptr), done(false), notifyRequired(false), totalSize(0), currentSize(0) { Game::AddRefToObject(this->getObject()); } @@ -227,7 +227,7 @@ namespace Components static void Forbid(mg_connection *nc); static void ModDownloader(ClientDownload* download); - static bool ParseModList(ClientDownload* download, std::string list); + static bool ParseModList(ClientDownload* download, const std::string& list); static bool DownloadFile(ClientDownload* download, unsigned int index); }; } diff --git a/src/Components/Modules/Dvar.cpp b/src/Components/Modules/Dvar.cpp index e786ee1a..8ac2eac0 100644 --- a/src/Components/Modules/Dvar.cpp +++ b/src/Components/Modules/Dvar.cpp @@ -4,7 +4,7 @@ namespace Components { Utils::Signal Dvar::RegistrationSignal; - Dvar::Var::Var(std::string dvarName) : Var() + Dvar::Var::Var(const std::string& dvarName) : Var() { this->dvar = Game::Dvar_FindVar(dvarName.data()); @@ -91,7 +91,7 @@ namespace Components Game::Dvar_SetCommand(this->dvar->name, string); } } - void Dvar::Var::set(std::string string) + void Dvar::Var::set(const std::string& string) { this->set(string.data()); } diff --git a/src/Components/Modules/Dvar.hpp b/src/Components/Modules/Dvar.hpp index 3f2e3bb4..4775b575 100644 --- a/src/Components/Modules/Dvar.hpp +++ b/src/Components/Modules/Dvar.hpp @@ -21,13 +21,13 @@ namespace Components Var(const Var &obj) { this->dvar = obj.dvar; }; Var(Game::dvar_t* _dvar) : dvar(_dvar) {}; Var(DWORD ppdvar) : Var(*reinterpret_cast(ppdvar)) {}; - Var(std::string dvarName); + Var(const std::string& dvarName); template T get(); void set(char* string); void set(const char* string); - void set(std::string string); + void set(const std::string& string); void set(int integer); void set(float value); diff --git a/src/Components/Modules/FastFiles.cpp b/src/Components/Modules/FastFiles.cpp index ed2d69dc..aa01267e 100644 --- a/src/Components/Modules/FastFiles.cpp +++ b/src/Components/Modules/FastFiles.cpp @@ -212,7 +212,7 @@ namespace Components } // Name is a bit weird, due to FasFileS and ExistS :P - bool FastFiles::Exists(std::string file) + bool FastFiles::Exists(const std::string& file) { std::string path = FastFiles::GetZoneLocation(file.data()); path.append(file); @@ -284,7 +284,7 @@ namespace Components return Utils::String::VA("zone\\%s\\", Game::Win_GetLanguage()); } - void FastFiles::AddZonePath(std::string path) + void FastFiles::AddZonePath(const std::string& path) { FastFiles::ZonePaths.push_back(path); } diff --git a/src/Components/Modules/FastFiles.hpp b/src/Components/Modules/FastFiles.hpp index eb5569a1..a81d8320 100644 --- a/src/Components/Modules/FastFiles.hpp +++ b/src/Components/Modules/FastFiles.hpp @@ -8,10 +8,10 @@ namespace Components FastFiles(); ~FastFiles(); - static void AddZonePath(std::string path); + static void AddZonePath(const std::string& path); static std::string Current(); static bool Ready(); - static bool Exists(std::string file); + static bool Exists(const std::string& file); static void LoadLocalizeZones(Game::XZoneInfo *zoneInfo, unsigned int zoneCount, int sync); diff --git a/src/Components/Modules/FileSystem.cpp b/src/Components/Modules/FileSystem.cpp index c5d55571..d96af79b 100644 --- a/src/Components/Modules/FileSystem.cpp +++ b/src/Components/Modules/FileSystem.cpp @@ -31,7 +31,7 @@ namespace Components Game::DB_GetRawBuffer(rawfile, const_cast(this->buffer.data()), this->buffer.size()); } - FileSystem::FileReader::FileReader(std::string file) : handle(0), name(file) + FileSystem::FileReader::FileReader(const std::string& file) : handle(0), name(file) { this->size = Game::FS_FOpenFileReadCurrentThread(this->name.data(), &this->handle); } @@ -97,7 +97,7 @@ namespace Components } } - void FileSystem::FileWriter::write(std::string data) + void FileSystem::FileWriter::write(const std::string& data) { if (this->handle) { @@ -126,7 +126,7 @@ namespace Components } } - std::vector FileSystem::GetFileList(std::string path, std::string extension) + std::vector FileSystem::GetFileList(const std::string& path, const std::string& extension) { std::vector fileList; @@ -149,7 +149,7 @@ namespace Components return fileList; } - std::vector FileSystem::GetSysFileList(std::string path, std::string extension, bool folders) + std::vector FileSystem::GetSysFileList(const std::string& path, const std::string& extension, bool folders) { std::vector fileList; @@ -172,7 +172,7 @@ namespace Components return fileList; } - void FileSystem::DeleteFile(std::string folder, std::string file) + void FileSystem::DeleteFile(const std::string& folder, const std::string& file) { char path[MAX_PATH] = { 0 }; Game::FS_BuildPathToFile(Dvar::Var("fs_basepath").get(), reinterpret_cast(0x63D0BB8), Utils::String::VA("%s/%s", folder.data(), file.data()), reinterpret_cast(&path)); diff --git a/src/Components/Modules/FileSystem.hpp b/src/Components/Modules/FileSystem.hpp index 800701b9..e40f3f59 100644 --- a/src/Components/Modules/FileSystem.hpp +++ b/src/Components/Modules/FileSystem.hpp @@ -19,7 +19,7 @@ namespace Components { public: File() {}; - File(std::string file) : filePath(file) { this->read(); }; + File(const std::string& file) : filePath(file) { this->read(); }; bool exists() override { return !this->buffer.empty(); }; std::string getName() override { return this->filePath; }; @@ -36,7 +36,7 @@ namespace Components { public: RawFile() {}; - RawFile(std::string file) : filePath(file) { this->read(); }; + RawFile(const std::string& file) : filePath(file) { this->read(); }; bool exists() override { return !this->buffer.empty(); }; std::string getName() override { return this->filePath; }; @@ -53,7 +53,7 @@ namespace Components { public: FileReader() : handle(0), size(-1), name() {}; - FileReader(std::string file); + FileReader(const std::string& file); ~FileReader(); bool exists(); @@ -72,10 +72,10 @@ namespace Components class FileWriter { public: - FileWriter(std::string file, bool append = false) : handle(0), filePath(file) { this->open(append); }; + FileWriter(const std::string& file, bool append = false) : handle(0), filePath(file) { this->open(append); }; ~FileWriter() { this->close(); }; - void write(std::string data); + void write(const std::string& data); private: int handle; @@ -88,9 +88,9 @@ namespace Components FileSystem(); ~FileSystem(); - static std::vector GetFileList(std::string path, std::string extension); - static std::vector GetSysFileList(std::string path, std::string extension, bool folders = false); - static void DeleteFile(std::string folder, std::string file); + static std::vector GetFileList(const std::string& path, const std::string& extension); + static std::vector GetSysFileList(const std::string& path, const std::string& extension, bool folders = false); + static void DeleteFile(const std::string& folder, const std::string& file); private: static std::mutex Mutex; diff --git a/src/Components/Modules/Flags.cpp b/src/Components/Modules/Flags.cpp index d9ec14ef..d40e5802 100644 --- a/src/Components/Modules/Flags.cpp +++ b/src/Components/Modules/Flags.cpp @@ -4,7 +4,7 @@ namespace Components { std::vector Flags::EnabledFlags; - bool Flags::HasFlag(std::string flag) + bool Flags::HasFlag(const std::string& flag) { Flags::ParseFlags(); diff --git a/src/Components/Modules/Flags.hpp b/src/Components/Modules/Flags.hpp index 2148622d..823a5ee9 100644 --- a/src/Components/Modules/Flags.hpp +++ b/src/Components/Modules/Flags.hpp @@ -8,7 +8,7 @@ namespace Components Flags(); ~Flags(); - static bool HasFlag(std::string flag); + static bool HasFlag(const std::string& flag); private: static std::vector EnabledFlags; diff --git a/src/Components/Modules/Friends.cpp b/src/Components/Modules/Friends.cpp index 448e3ed7..b065e6d2 100644 --- a/src/Components/Modules/Friends.cpp +++ b/src/Components/Modules/Friends.cpp @@ -140,7 +140,7 @@ namespace Components } } - void Friends::UpdateServer(Network::Address server, std::string hostname, std::string mapname) + void Friends::UpdateServer(Network::Address server, const std::string& hostname, const std::string& mapname) { std::lock_guard _(Friends::Mutex); @@ -218,7 +218,7 @@ namespace Components } } - void Friends::ClearPresence(std::string key) + void Friends::ClearPresence(const std::string& key) { if (Steam::Proxy::ClientFriends && Steam::Proxy::SteamUtils) { @@ -226,7 +226,7 @@ namespace Components } } - void Friends::SetPresence(std::string key, std::string value) + void Friends::SetPresence(const std::string& key, const std::string& value) { if (Steam::Proxy::ClientFriends && Steam::Proxy::SteamUtils && !Dvar::Var("cl_anonymous").get() && Steam::Enabled()) { @@ -242,7 +242,7 @@ namespace Components } } - std::string Friends::GetPresence(SteamID user, std::string key) + std::string Friends::GetPresence(SteamID user, const std::string& key) { if (!Steam::Proxy::ClientFriends || !Steam::Proxy::SteamUtils) return ""; diff --git a/src/Components/Modules/Friends.hpp b/src/Components/Modules/Friends.hpp index 00f0c447..e9bdb469 100644 --- a/src/Components/Modules/Friends.hpp +++ b/src/Components/Modules/Friends.hpp @@ -10,14 +10,14 @@ namespace Components static void UpdateFriends(); static void UpdateRank(); - static void UpdateServer(Network::Address server, std::string hostname, std::string mapname); + static void UpdateServer(Network::Address server, const std::string& hostname, const std::string& mapname); static void UpdateName(); - static void SetPresence(std::string key, std::string value); - static void ClearPresence(std::string key); + static void SetPresence(const std::string& key, const std::string& value); + static void ClearPresence(const std::string& key); static void RequestPresence(SteamID user); - static std::string GetPresence(SteamID user, std::string key); + static std::string GetPresence(SteamID user, const std::string& key); static void AddFriend(SteamID user); diff --git a/src/Components/Modules/IPCPipe.cpp b/src/Components/Modules/IPCPipe.cpp index 9baef8f9..ee50163a 100644 --- a/src/Components/Modules/IPCPipe.cpp +++ b/src/Components/Modules/IPCPipe.cpp @@ -17,7 +17,7 @@ namespace Components this->destroy(); } - bool Pipe::connect(std::string name) + bool Pipe::connect(const std::string& name) { this->destroy(); @@ -51,7 +51,7 @@ namespace Components return true; } - bool Pipe::create(std::string name) + bool Pipe::create(const std::string& name) { this->destroy(); @@ -83,12 +83,12 @@ namespace Components this->connectCallback = callback; } - void Pipe::setCallback(std::string command, Utils::Slot callback) + void Pipe::setCallback(const std::string& command, Utils::Slot callback) { this->packetCallbacks[command] = callback; } - bool Pipe::write(std::string command, std::string data) + bool Pipe::write(const std::string& command, const std::string& data) { if (this->type != IPCTYPE_CLIENT || this->pipe == INVALID_HANDLE_VALUE) return false; @@ -131,7 +131,7 @@ namespace Components } } - void Pipe::setName(std::string name) + void Pipe::setName(const std::string& name) { memset(this->pipeName, 0, sizeof(this->pipeName)); memset(this->pipeFile, 0, sizeof(this->pipeFile)); @@ -191,13 +191,13 @@ namespace Components } // Writes to the process on the other end of the pipe - bool IPCPipe::Write(std::string command, std::string data) + bool IPCPipe::Write(const std::string& command, const std::string& data) { return IPCPipe::ClientPipe.write(command, data); } // Installs a callback for receiving commands from the process on the other end of the pipe - void IPCPipe::On(std::string command, Utils::Slot callback) + void IPCPipe::On(const std::string& command, Utils::Slot callback) { IPCPipe::ServerPipe.setCallback(command, callback); } @@ -216,13 +216,13 @@ namespace Components IPCPipe::ClientPipe.connect(IPC_PIPE_NAME_SERVER); } - IPCPipe::On("ping", [](std::string data) + IPCPipe::On("ping", [](const std::string& data) { Logger::Print("Received ping form pipe, sending pong!\n"); IPCPipe::Write("pong", data); }); - IPCPipe::On("pong", [](std::string data) + IPCPipe::On("pong", [](const std::string& /*data*/) { Logger::Print("Received pong form pipe!\n"); }); diff --git a/src/Components/Modules/IPCPipe.hpp b/src/Components/Modules/IPCPipe.hpp index 2e51e16c..14218cdd 100644 --- a/src/Components/Modules/IPCPipe.hpp +++ b/src/Components/Modules/IPCPipe.hpp @@ -25,17 +25,17 @@ namespace Components IPCTYPE_CLIENT }; - typedef void(__cdecl PacketCallback)(std::string data); + typedef void(__cdecl PacketCallback)(const std::string& data); typedef void(__cdecl Callback)(); Pipe(); ~Pipe(); - bool connect(std::string name); - bool create(std::string name); + bool connect(const std::string& name); + bool create(const std::string& name); - bool write(std::string command, std::string data); - void setCallback(std::string command, Utils::Slot callback); + bool write(const std::string& command, const std::string& data); + void setCallback(const std::string& command, Utils::Slot callback); void onConnect(Callback callback); void destroy(); @@ -55,7 +55,7 @@ namespace Components char pipeFile[MAX_PATH]; unsigned int reconnectAttempt; - void setName(std::string name); + void setName(const std::string& name); static void ReceiveThread(Pipe* pipe); }; @@ -67,8 +67,8 @@ namespace Components void preDestroy() override; - static bool Write(std::string command, std::string data); - static void On(std::string command, Utils::Slot callback); + static bool Write(const std::string& command, const std::string& data); + static void On(const std::string& command, Utils::Slot callback); private: static Pipe ServerPipe; diff --git a/src/Components/Modules/Localization.cpp b/src/Components/Modules/Localization.cpp index 8a8232f7..dcfa4976 100644 --- a/src/Components/Modules/Localization.cpp +++ b/src/Components/Modules/Localization.cpp @@ -7,7 +7,7 @@ namespace Components std::unordered_map Localization::LocalizeMap; std::unordered_map Localization::TempLocalizeMap; - void Localization::Set(std::string key, std::string value) + void Localization::Set(const std::string& key, const std::string& value) { std::lock_guard _(Localization::LocalizeMutex); Utils::Memory::Allocator* allocator = Utils::Memory::GetAllocator(); @@ -75,7 +75,7 @@ namespace Components return key; } - void Localization::SetTemp(std::string key, std::string value) + void Localization::SetTemp(const std::string& key, const std::string& value) { std::lock_guard _(Localization::LocalizeMutex); Utils::Memory::Allocator* allocator = Utils::Memory::GetAllocator(); @@ -240,7 +240,7 @@ namespace Components { Localization::SetCredits(); - AssetHandler::OnFind(Game::XAssetType::ASSET_TYPE_LOCALIZE_ENTRY, [](Game::XAssetType, std::string filename) + AssetHandler::OnFind(Game::XAssetType::ASSET_TYPE_LOCALIZE_ENTRY, [](Game::XAssetType, const std::string& filename) { Game::XAssetHeader header = { nullptr }; std::lock_guard _(Localization::LocalizeMutex); @@ -269,7 +269,7 @@ namespace Components Localization::UseLocalization = Dvar::Register("ui_localize", true, Game::dvar_flag::DVAR_FLAG_NONE, "Use localization strings"); // Generate localized entries for custom classes above 10 - AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader asset, std::string name, bool* /*restrict*/) + AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader asset, const std::string& name, bool* /*restrict*/) { if (type != Game::XAssetType::ASSET_TYPE_LOCALIZE_ENTRY) return; diff --git a/src/Components/Modules/Localization.hpp b/src/Components/Modules/Localization.hpp index a96af75e..dea1dd94 100644 --- a/src/Components/Modules/Localization.hpp +++ b/src/Components/Modules/Localization.hpp @@ -8,10 +8,10 @@ namespace Components Localization(); ~Localization(); - static void Set(std::string key, std::string value); + static void Set(const std::string& key, const std::string& value); static const char* Get(const char* key); - static void SetTemp(std::string key, std::string value); + static void SetTemp(const std::string& key, const std::string& value); static void ClearTemp(); private: diff --git a/src/Components/Modules/Logger.cpp b/src/Components/Modules/Logger.cpp index b1e3c619..22ad6e09 100644 --- a/src/Components/Modules/Logger.cpp +++ b/src/Components/Modules/Logger.cpp @@ -5,7 +5,7 @@ namespace Components std::mutex Logger::MessageMutex; std::vector Logger::MessageQueue; std::vector Logger::LoggingAddresses[2]; - void(*Logger::PipeCallback)(std::string) = nullptr; + void(*Logger::PipeCallback)(const std::string&) = nullptr; bool Logger::IsConsoleReady() { @@ -27,7 +27,7 @@ namespace Components return Logger::MessagePrint(channel, Logger::Format(&message)); } - void Logger::MessagePrint(int channel, std::string message) + void Logger::MessagePrint(int channel, const std::string& message) { if (Flags::HasFlag("stdout") || Loader::IsPerformingUnitTests()) { @@ -51,7 +51,7 @@ namespace Components } } - void Logger::ErrorPrint(int error, std::string message) + void Logger::ErrorPrint(int error, const std::string& message) { #ifdef DEBUG if (IsDebuggerPresent()) __debugbreak(); @@ -121,7 +121,7 @@ namespace Components Logger::MessageQueue.clear(); } - void Logger::PipeOutput(void(*callback)(std::string)) + void Logger::PipeOutput(void(*callback)(const std::string&)) { Logger::PipeCallback = callback; } @@ -194,7 +194,7 @@ namespace Components } } - void Logger::EnqueueMessage(std::string message) + void Logger::EnqueueMessage(const std::string& message) { Logger::MessageMutex.lock(); Logger::MessageQueue.push_back(message); diff --git a/src/Components/Modules/Logger.hpp b/src/Components/Modules/Logger.hpp index 6d683437..26625324 100644 --- a/src/Components/Modules/Logger.hpp +++ b/src/Components/Modules/Logger.hpp @@ -8,10 +8,10 @@ namespace Components Logger(); ~Logger(); - static void MessagePrint(int channel, std::string message); + static void MessagePrint(int channel, const std::string& message); static void Print(int channel, const char* message, ...); static void Print(const char* message, ...); - static void ErrorPrint(int error, std::string message); + static void ErrorPrint(int error, const std::string& message); static void Error(const char* message, ...); static void Error(int error, const char* message, ...); static void SoftError(const char* message, ...); @@ -19,7 +19,7 @@ namespace Components static void PrintStub(int channel, const char* message, ...); - static void PipeOutput(void(*callback)(std::string)); + static void PipeOutput(void(*callback)(const std::string&)); static void Flush(); @@ -27,13 +27,13 @@ namespace Components static std::mutex MessageMutex; static std::vector MessageQueue; static std::vector LoggingAddresses[2]; - static void(*PipeCallback)(std::string); + static void(*PipeCallback)(const std::string&); static void Frame(); static void GameLogStub(); static void PrintMessageStub(); static void PrintMessagePipe(const char* data); - static void EnqueueMessage(std::string message); + static void EnqueueMessage(const std::string& message); static void BuildOSPathStub(); static void RedirectOSPath(const char* file, char* folder); diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index a7207c66..64bc3d40 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -201,7 +201,7 @@ namespace Components Game::DB_EnumXAssets_Internal(Game::XAssetType::ASSET_TYPE_CLIPMAP_SP, callback, ents, true); } - void Maps::LoadAssetRestrict(Game::XAssetType type, Game::XAssetHeader asset, std::string name, bool* restrict) + void Maps::LoadAssetRestrict(Game::XAssetType type, Game::XAssetHeader asset, const std::string& name, bool* restrict) { if (std::find(Maps::CurrentDependencies.begin(), Maps::CurrentDependencies.end(), FastFiles::Current()) != Maps::CurrentDependencies.end() && (FastFiles::Current() != "mp_shipment_long" || Maps::CurrentMainZone != "mp_shipment")) // Shipment is a special case @@ -331,7 +331,7 @@ namespace Components Maps::SPMap = true; } - void Maps::AddDependency(std::string expression, std::string zone) + void Maps::AddDependency(const std::string& expression, const std::string& zone) { // Test expression before adding it try @@ -352,7 +352,7 @@ namespace Components return (Utils::String::StartsWith(entity, "dyn_") || Utils::String::StartsWith(entity, "node_") || Utils::String::StartsWith(entity, "actor_")); } - std::vector Maps::GetDependenciesForMap(std::string map) + std::vector Maps::GetDependenciesForMap(const std::string& map) { for (int i = 0; i < *Game::arenaCount; ++i) { @@ -372,7 +372,7 @@ namespace Components return {}; } - std::pair Maps::GetTeamsForMap(std::string map) + std::pair Maps::GetTeamsForMap(const std::string& map) { std::string team_axis = "opforce_composite"; std::string team_allies = "us_army"; @@ -420,7 +420,7 @@ namespace Components } } - unsigned int Maps::GetUsermapHash(std::string map) + unsigned int Maps::GetUsermapHash(const std::string& map) { if (Utils::IO::DirectoryExists(Utils::String::VA("usermaps/%s", map.data()))) { @@ -720,7 +720,7 @@ namespace Components return false; } - bool Maps::IsUserMap(std::string mapname) + 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())); } diff --git a/src/Components/Modules/Maps.hpp b/src/Components/Modules/Maps.hpp index e2bdfe0c..205255cd 100644 --- a/src/Components/Modules/Maps.hpp +++ b/src/Components/Modules/Maps.hpp @@ -9,7 +9,7 @@ namespace Components { public: UserMapContainer() : wasFreed(false), hash(0) {} - UserMapContainer(std::string _mapname) : wasFreed(false), mapname(_mapname) + UserMapContainer(const std::string& _mapname) : wasFreed(false), mapname(_mapname) { ZeroMemory(&this->searchPath, sizeof this->searchPath); this->hash = Maps::GetUsermapHash(this->mapname); @@ -50,10 +50,10 @@ namespace Components ~Maps(); static void HandleAsSPMap(); - static void AddDependency(std::string expression, std::string zone); + static void AddDependency(const std::string& expression, const std::string& zone); - static std::pair GetTeamsForMap(std::string map); - static std::vector GetDependenciesForMap(std::string map); + static std::pair GetTeamsForMap(const std::string& map); + static std::vector GetDependenciesForMap(const std::string& map); static std::string CurrentMainZone; static const char* UserMapFiles[4]; @@ -61,11 +61,11 @@ namespace Components static bool CheckMapInstalled(const char* mapname, bool error = false, bool dlcIsTrue = false); static UserMapContainer* GetUserMap(); - static unsigned int GetUsermapHash(std::string map); + static unsigned int GetUsermapHash(const std::string& map); static Game::XAssetEntry* GetAssetEntryPool(); static bool IsCustomMap(); - static bool IsUserMap(std::string mapname); + static bool IsUserMap(const std::string& mapname); private: class DLC @@ -84,7 +84,7 @@ namespace Components static std::vector CurrentDependencies; static void GetBSPName(char* buffer, size_t size, const char* format, const char* mapname); - static void LoadAssetRestrict(Game::XAssetType type, Game::XAssetHeader asset, std::string name, bool* restrict); + static void LoadAssetRestrict(Game::XAssetType type, Game::XAssetHeader asset, const std::string& name, bool* restrict); static void LoadMapZones(Game::XZoneInfo *zoneInfo, unsigned int zoneCount, int sync); static void UnloadMapZones(Game::XZoneInfo *zoneInfo, unsigned int zoneCount, int sync); diff --git a/src/Components/Modules/Materials.cpp b/src/Components/Modules/Materials.cpp index fe0cdda8..79d70a12 100644 --- a/src/Components/Modules/Materials.cpp +++ b/src/Components/Modules/Materials.cpp @@ -8,7 +8,7 @@ namespace Components std::vector Materials::ImageTable; std::vector Materials::MaterialTable; - Game::Material* Materials::Create(std::string name, Game::GfxImage* image) + Game::Material* Materials::Create(const std::string& name, Game::GfxImage* image) { Game::Material* material = Utils::Memory::GetAllocator()->allocate(); Game::MaterialTextureDef* texture = Utils::Memory::GetAllocator()->allocate(); @@ -71,7 +71,7 @@ namespace Components } } - Game::GfxImage* Materials::CreateImage(std::string name, unsigned int width, unsigned int height, unsigned int depth, unsigned int flags, _D3DFORMAT format) + Game::GfxImage* Materials::CreateImage(const std::string& name, unsigned int width, unsigned int height, unsigned int depth, unsigned int flags, _D3DFORMAT format) { Game::GfxImage* image = Utils::Memory::GetAllocator()->allocate(); image->name = Utils::Memory::GetAllocator()->duplicateString(name); diff --git a/src/Components/Modules/Materials.hpp b/src/Components/Modules/Materials.hpp index fe1c9f03..2a2d55dd 100644 --- a/src/Components/Modules/Materials.hpp +++ b/src/Components/Modules/Materials.hpp @@ -10,10 +10,10 @@ namespace Components static int FormatImagePath(char* buffer, size_t size, int, int, const char* image); - static Game::Material* Create(std::string name, Game::GfxImage* image); + static Game::Material* Create(const std::string& name, Game::GfxImage* image); static void Delete(Game::Material* material, bool deleteImage = false); - static Game::GfxImage* CreateImage(std::string name, unsigned int width, unsigned int height, unsigned int depth, unsigned int flags, _D3DFORMAT format); + static Game::GfxImage* CreateImage(const std::string& name, unsigned int width, unsigned int height, unsigned int depth, unsigned int flags, _D3DFORMAT format); static void DeleteImage(Game::GfxImage* image); static bool IsValid(Game::Material* material); diff --git a/src/Components/Modules/Menus.cpp b/src/Components/Modules/Menus.cpp index ebe70300..cfd06bb3 100644 --- a/src/Components/Modules/Menus.cpp +++ b/src/Components/Modules/Menus.cpp @@ -25,7 +25,7 @@ namespace Components return i; } - Game::script_t* Menus::LoadMenuScript(std::string name, std::string buffer) + Game::script_t* Menus::LoadMenuScript(const std::string& name, const std::string& buffer) { Game::script_t* script = Game::Script_Alloc(sizeof(Game::script_t) + 1 + buffer.length()); if (!script) return nullptr; @@ -53,7 +53,7 @@ namespace Components return script; } - int Menus::LoadMenuSource(std::string name, std::string buffer) + int Menus::LoadMenuSource(const std::string& name, const std::string& buffer) { Utils::Memory::Allocator* allocator = Utils::Memory::GetAllocator(); @@ -173,7 +173,7 @@ namespace Components return menu; } - std::vector> Menus::LoadMenu(std::string menu) + std::vector> Menus::LoadMenu(const std::string& menu) { std::vector> menus; FileSystem::File menuFile(menu); @@ -465,7 +465,7 @@ namespace Components allocator->free(menuList); } - void Menus::RemoveMenu(std::string menu) + void Menus::RemoveMenu(const std::string& menu) { auto i = Menus::MenuList.find(menu); if (i != Menus::MenuList.end()) @@ -491,7 +491,7 @@ namespace Components } } - void Menus::RemoveMenuList(std::string menuList) + void Menus::RemoveMenuList(const std::string& menuList) { auto i = Menus::MenuListList.find(menuList); if (i != Menus::MenuListList.end()) @@ -580,12 +580,12 @@ namespace Components Menus::MenuList.clear(); } - Game::XAssetHeader Menus::MenuLoad(Game::XAssetType /*type*/, std::string filename) + Game::XAssetHeader Menus::MenuLoad(Game::XAssetType /*type*/, const std::string& filename) { return { Game::Menus_FindByName(Game::uiContext, filename.data()) }; } - Game::XAssetHeader Menus::MenuFileLoad(Game::XAssetType type, std::string filename) + Game::XAssetHeader Menus::MenuFileLoad(Game::XAssetType type, const std::string& filename) { Game::XAssetHeader header = { nullptr }; @@ -689,7 +689,7 @@ namespace Components } } - void Menus::Add(std::string menu) + void Menus::Add(const std::string& menu) { Menus::CustomMenus.push_back(menu); } diff --git a/src/Components/Modules/Menus.hpp b/src/Components/Modules/Menus.hpp index 4a96f260..efc051e2 100644 --- a/src/Components/Modules/Menus.hpp +++ b/src/Components/Modules/Menus.hpp @@ -13,24 +13,24 @@ namespace Components static void FreeEverything(); - static void Add(std::string menu); + static void Add(const std::string& menu); private: static std::unordered_map MenuList; static std::unordered_map MenuListList; static std::vector CustomMenus; - static Game::XAssetHeader MenuLoad(Game::XAssetType type, std::string filename); - static Game::XAssetHeader MenuFileLoad(Game::XAssetType type, std::string filename); + static Game::XAssetHeader MenuLoad(Game::XAssetType type, const std::string& filename); + static Game::XAssetHeader MenuFileLoad(Game::XAssetType type, const std::string& filename); static Game::MenuList* LoadMenuList(Game::MenuList* menuList); static Game::MenuList* LoadScriptMenu(const char* menu); static std::vector> LoadMenu(Game::menuDef_t* menudef); - static std::vector> LoadMenu(std::string file); + static std::vector> LoadMenu(const std::string& file); static void SafeMergeMenus(std::vector>* menus, std::vector> newMenus); - static Game::script_t* LoadMenuScript(std::string name, std::string buffer); - static int LoadMenuSource(std::string name, std::string buffer); + static Game::script_t* LoadMenuScript(const std::string& name, const std::string& buffer); + static int LoadMenuSource(const std::string& name, const std::string& buffer); static int ReserveSourceHandle(); static bool IsValidSourceHandle(int handle); @@ -42,9 +42,9 @@ namespace Components static void FreeMenuList(Game::MenuList* menuList); static void FreeMenu(Game::menuDef_t* menudef); - static void RemoveMenu(std::string menu); + static void RemoveMenu(const std::string& menu); static void RemoveMenu(Game::menuDef_t* menudef); - static void RemoveMenuList(std::string menuList); + static void RemoveMenuList(const std::string& menuList); static void RemoveMenuList(Game::MenuList* menuList); static void OverrideMenu(Game::menuDef_t *menu); diff --git a/src/Components/Modules/ModList.cpp b/src/Components/Modules/ModList.cpp index d090b679..dac1ecaa 100644 --- a/src/Components/Modules/ModList.cpp +++ b/src/Components/Modules/ModList.cpp @@ -5,7 +5,7 @@ namespace Components std::vector ModList::Mods; unsigned int ModList::CurrentMod; - bool ModList::HasMod(std::string modName) + bool ModList::HasMod(const std::string& modName) { auto list = FileSystem::GetSysFileList(Dvar::Var("fs_basepath").get() + "\\mods", "", true); @@ -72,7 +72,7 @@ namespace Components } } - void ModList::RunMod(std::string mod) + void ModList::RunMod(const std::string& mod) { auto fsGame = Dvar::Var("fs_game"); fsGame.set(Utils::String::VA("mods/%s", mod.data())); diff --git a/src/Components/Modules/ModList.hpp b/src/Components/Modules/ModList.hpp index 8f2a0e97..a871fb45 100644 --- a/src/Components/Modules/ModList.hpp +++ b/src/Components/Modules/ModList.hpp @@ -8,13 +8,13 @@ namespace Components ModList(); ~ModList(); - static void RunMod(std::string mod); + static void RunMod(const std::string& mod); private: static std::vector Mods; static unsigned int CurrentMod; - static bool HasMod(std::string modName); + static bool HasMod(const std::string& modName); static unsigned int GetItemCount(); static const char* GetItemText(unsigned int index, int column); diff --git a/src/Components/Modules/ModelSurfs.cpp b/src/Components/Modules/ModelSurfs.cpp index eef88a84..55336ee8 100644 --- a/src/Components/Modules/ModelSurfs.cpp +++ b/src/Components/Modules/ModelSurfs.cpp @@ -35,7 +35,7 @@ namespace Components } } - Game::XModelSurfs* ModelSurfs::LoadXModelSurfaces(std::string name) + Game::XModelSurfs* ModelSurfs::LoadXModelSurfaces(const std::string& name) { Utils::Memory::Allocator allocator; FileSystem::FileReader model(Utils::String::VA("models/%s", name.data())); diff --git a/src/Components/Modules/ModelSurfs.hpp b/src/Components/Modules/ModelSurfs.hpp index a2f9f205..06ba3a3f 100644 --- a/src/Components/Modules/ModelSurfs.hpp +++ b/src/Components/Modules/ModelSurfs.hpp @@ -21,7 +21,7 @@ namespace Components static void SetBuffer(char streamHandle, void* buffer, IUnknown** bufferOut, int* offsetOut); static void CreateBuffers(Game::XModelSurfs* surfs); - static Game::XModelSurfs* LoadXModelSurfaces(std::string name); + static Game::XModelSurfs* LoadXModelSurfaces(const std::string& name); static bool LoadSurfaces(Game::XModel* model); static void XModelSurfsFixup(Game::XModel* model); diff --git a/src/Components/Modules/MusicalTalent.cpp b/src/Components/Modules/MusicalTalent.cpp index 63bd3512..359856ce 100644 --- a/src/Components/Modules/MusicalTalent.cpp +++ b/src/Components/Modules/MusicalTalent.cpp @@ -4,12 +4,12 @@ namespace Components { std::unordered_map MusicalTalent::SoundAliasList; - void MusicalTalent::Replace(std::string sound, const char* file) + void MusicalTalent::Replace(const std::string& sound, const char* file) { MusicalTalent::SoundAliasList[Utils::String::ToLower(sound)] = file; } - Game::XAssetHeader MusicalTalent::ModifyAliases(Game::XAssetType type, std::string filename) + Game::XAssetHeader MusicalTalent::ModifyAliases(Game::XAssetType type, const std::string& filename) { Game::XAssetHeader header = { nullptr }; diff --git a/src/Components/Modules/MusicalTalent.hpp b/src/Components/Modules/MusicalTalent.hpp index b3c07747..e5bfc181 100644 --- a/src/Components/Modules/MusicalTalent.hpp +++ b/src/Components/Modules/MusicalTalent.hpp @@ -8,10 +8,10 @@ namespace Components MusicalTalent(); ~MusicalTalent(); - static void Replace(std::string sound, const char* file); + static void Replace(const std::string& sound, const char* file); private: static std::unordered_map SoundAliasList; - static Game::XAssetHeader ModifyAliases(Game::XAssetType type, std::string filename); + static Game::XAssetHeader ModifyAliases(Game::XAssetType type, const std::string& filename); }; } diff --git a/src/Components/Modules/Network.cpp b/src/Components/Modules/Network.cpp index 1e84a8b0..bf0574ec 100644 --- a/src/Components/Modules/Network.cpp +++ b/src/Components/Modules/Network.cpp @@ -6,7 +6,7 @@ namespace Components Utils::Signal Network::StartupSignal; std::map> Network::PacketHandlers; - Network::Address::Address(std::string addrString) + Network::Address::Address(const std::string& addrString) { Game::NET_StringToAdr(addrString.data(), &this->address); } @@ -123,7 +123,7 @@ namespace Components { return (this->getType() != Game::netadrtype_t::NA_BAD && this->getType() >= Game::netadrtype_t::NA_BOT && this->getType() <= Game::netadrtype_t::NA_IP); } - void Network::Handle(std::string packet, Utils::Slot callback) + void Network::Handle(const std::string& packet, Utils::Slot callback) { Network::PacketHandlers[Utils::String::ToLower(packet)] = callback; } @@ -133,7 +133,7 @@ namespace Components Network::StartupSignal.connect(callback); } - void Network::Send(Game::netsrc_t type, Network::Address target, std::string data) + void Network::Send(Game::netsrc_t type, Network::Address target, const std::string& data) { // NET_OutOfBandPrint only supports non-binary data! //Game::NET_OutOfBandPrint(type, *target.Get(), data.data()); @@ -146,12 +146,12 @@ namespace Components Network::SendRaw(type, target, rawData); } - void Network::Send(Network::Address target, std::string data) + void Network::Send(Network::Address target, const std::string& data) { Network::Send(Game::netsrc_t::NS_CLIENT1, target, data); } - void Network::SendRaw(Game::netsrc_t type, Network::Address target, std::string data) + void Network::SendRaw(Game::netsrc_t type, Network::Address target, const std::string& data) { if (!target.isValid()) return; @@ -160,12 +160,12 @@ namespace Components Game::Sys_SendPacket(type, data.size(), data.data(), *target.get()); } - void Network::SendRaw(Network::Address target, std::string data) + void Network::SendRaw(Network::Address target, const std::string& data) { Network::SendRaw(Game::netsrc_t::NS_CLIENT1, target, data); } - void Network::SendCommand(Game::netsrc_t type, Network::Address target, std::string command, std::string data) + void Network::SendCommand(Game::netsrc_t type, Network::Address target, const std::string& command, const std::string& data) { // Use space as separator (possible separators are '\n', ' '). // Though, our handler only needs exactly 1 char as separator and doesn't care which char it is. @@ -178,12 +178,12 @@ namespace Components Network::Send(type, target, packet); } - void Network::SendCommand(Network::Address target, std::string command, std::string data) + void Network::SendCommand(Network::Address target, const std::string& command, const std::string& data) { Network::SendCommand(Game::netsrc_t::NS_CLIENT1, target, command, data); } - void Network::Broadcast(unsigned short port, std::string data) + void Network::Broadcast(unsigned short port, const std::string& data) { Address target; @@ -194,7 +194,7 @@ namespace Components Network::Send(Game::netsrc_t::NS_CLIENT1, target, data); } - void Network::BroadcastRange(unsigned int min, unsigned int max, std::string data) + void Network::BroadcastRange(unsigned int min, unsigned int max, const std::string& data) { for (unsigned int i = min; i < max; ++i) { @@ -202,7 +202,7 @@ namespace Components } } - void Network::BroadcastAll(std::string data) + void Network::BroadcastAll(const std::string& data) { Network::BroadcastRange(100, 65536, data); } @@ -372,7 +372,7 @@ namespace Components // Install packet deploy hook Utils::Hook::RedirectJump(0x5AA713, Network::DeployPacketStub); - Network::Handle("resolveAddress", [](Address address, std::string data) + Network::Handle("resolveAddress", [](Address address, const std::string& /*data*/) { Network::SendRaw(address, address.getString()); }); diff --git a/src/Components/Modules/Network.hpp b/src/Components/Modules/Network.hpp index 4a2919b2..bb9d0890 100644 --- a/src/Components/Modules/Network.hpp +++ b/src/Components/Modules/Network.hpp @@ -11,7 +11,7 @@ namespace Components { public: Address() { setType(Game::netadrtype_t::NA_BAD); }; - Address(std::string addrString); + Address(const std::string& addrString); Address(sockaddr* addr); Address(sockaddr addr) : Address(&addr) {} Address(sockaddr_in addr) : Address(&addr) {} @@ -48,7 +48,7 @@ namespace Components Game::netadr_t address; }; - typedef void(Callback)(Address address, std::string data); + typedef void(Callback)(Address address, const std::string& data); typedef void(CallbackRaw)(); Network(); @@ -56,24 +56,24 @@ namespace Components static unsigned short GetPort(); - static void Handle(std::string packet, Utils::Slot callback); + static void Handle(const std::string& packet, Utils::Slot callback); static void OnStart(Utils::Slot callback); // Send quake-styled binary data - static void Send(Address target, std::string data); - static void Send(Game::netsrc_t type, Address target, std::string data); + static void Send(Address target, const std::string& data); + static void Send(Game::netsrc_t type, Address target, const std::string& data); // Allows sending raw data without quake header - static void SendRaw(Address target, std::string data); - static void SendRaw(Game::netsrc_t type, Address target, std::string data); + static void SendRaw(Address target, const std::string& data); + static void SendRaw(Game::netsrc_t type, Address target, const std::string& data); // Send quake-style command using binary data - static void SendCommand(Address target, std::string command, std::string data = ""); - static void SendCommand(Game::netsrc_t type, Address target, std::string command, std::string data = ""); + static void SendCommand(Address target, const std::string& command, const std::string& data = ""); + static void SendCommand(Game::netsrc_t type, Address target, const std::string& command, const std::string& data = ""); - static void Broadcast(unsigned short port, std::string data); - static void BroadcastRange(unsigned int min, unsigned int max, std::string data); - static void BroadcastAll(std::string data); + static void Broadcast(unsigned short port, const std::string& data); + static void BroadcastRange(unsigned int min, unsigned int max, const std::string& data); + static void BroadcastAll(const std::string& data); private: static std::string SelectedPacket; diff --git a/src/Components/Modules/News.cpp b/src/Components/Modules/News.cpp index 73f1933a..0e2a0b1b 100644 --- a/src/Components/Modules/News.cpp +++ b/src/Components/Modules/News.cpp @@ -147,7 +147,7 @@ namespace Components } } - void News::LaunchUpdater(std::string params) + void News::LaunchUpdater(const std::string& params) { if (News::Updating()) return; diff --git a/src/Components/Modules/News.hpp b/src/Components/Modules/News.hpp index 4880da1f..6cb824d6 100644 --- a/src/Components/Modules/News.hpp +++ b/src/Components/Modules/News.hpp @@ -11,7 +11,7 @@ namespace Components void preDestroy() override; bool unitTest() override; - static void LaunchUpdater(std::string params); + static void LaunchUpdater(const std::string& params); static bool Updating(); private: diff --git a/src/Components/Modules/Node.cpp b/src/Components/Modules/Node.cpp index 75a5b458..7639c97b 100644 --- a/src/Components/Modules/Node.cpp +++ b/src/Components/Modules/Node.cpp @@ -225,7 +225,7 @@ namespace Components } } - void Node::HandleResponse(Network::Address address, std::string data) + void Node::HandleResponse(Network::Address address, const std::string& data) { Proto::Node::List list; if (!list.ParseFromString(data)) return; @@ -318,7 +318,7 @@ namespace Components Scheduler::OnFrame(Node::RunFrame); Session::Handle("nodeListResponse", Node::HandleResponse); - Session::Handle("nodeListRequest", [](Network::Address address, std::string) + Session::Handle("nodeListRequest", [](Network::Address address, const std::string&) { Node::SendList(address); }); diff --git a/src/Components/Modules/Node.hpp b/src/Components/Modules/Node.hpp index 31299e4f..c6d84b62 100644 --- a/src/Components/Modules/Node.hpp +++ b/src/Components/Modules/Node.hpp @@ -53,7 +53,7 @@ namespace Components static std::vector Nodes; static bool wasIngame; - static void HandleResponse(Network::Address address, std::string data); + static void HandleResponse(Network::Address address, const std::string& data); static void SendList(Network::Address address); diff --git a/src/Components/Modules/Party.cpp b/src/Components/Modules/Party.cpp index 2779c286..d94759e7 100644 --- a/src/Components/Modules/Party.cpp +++ b/src/Components/Modules/Party.cpp @@ -37,7 +37,7 @@ namespace Components Command::Execute("openmenu popup_reconnectingtoparty"); } - const char* Party::GetLobbyInfo(SteamID lobby, std::string key) + const char* Party::GetLobbyInfo(SteamID lobby, const std::string& key) { if (Party::LobbyMap.find(lobby.bits) != Party::LobbyMap.end()) { @@ -64,7 +64,7 @@ namespace Components } } - void Party::ConnectError(std::string message) + void Party::ConnectError(const std::string& message) { Localization::ClearTemp(); Command::Execute("closemenu popup_reconnectingtoparty"); @@ -120,7 +120,7 @@ namespace Components Game::Steam_JoinLobby(id, 0); } - void Party::PlaylistError(std::string error) + void Party::PlaylistError(const std::string& error) { Party::Container.valid = false; Party::Container.awaitingPlaylist = false; @@ -303,7 +303,7 @@ namespace Components }, true); // Basic info handler - Network::Handle("getInfo", [](Network::Address address, std::string data) + Network::Handle("getInfo", [](Network::Address address, const std::string& data) { int botCount = 0; int clientCount = 0; @@ -390,7 +390,7 @@ namespace Components Network::SendCommand(address, "infoResponse", "\\" + info.build()); }); - Network::Handle("infoResponse", [](Network::Address address, std::string data) + Network::Handle("infoResponse", [](Network::Address address, const std::string& data) { Utils::InfoString info(data); diff --git a/src/Components/Modules/Party.hpp b/src/Components/Modules/Party.hpp index 056c9acf..974bdc2f 100644 --- a/src/Components/Modules/Party.hpp +++ b/src/Components/Modules/Party.hpp @@ -10,14 +10,14 @@ namespace Components static Network::Address Target(); static void Connect(Network::Address target); - static const char* GetLobbyInfo(SteamID lobby, std::string key); + static const char* GetLobbyInfo(SteamID lobby, const std::string& key); static void RemoveLobby(SteamID lobby); static bool PlaylistAwaiting(); static void PlaylistContinue(); - static void PlaylistError(std::string error); + static void PlaylistError(const std::string& error); - static void ConnectError(std::string message); + static void ConnectError(const std::string& message); static bool IsInUserMapLobby(); static bool IsInLobby(); diff --git a/src/Components/Modules/Playlist.cpp b/src/Components/Modules/Playlist.cpp index 3fb43aff..ede480e2 100644 --- a/src/Components/Modules/Playlist.cpp +++ b/src/Components/Modules/Playlist.cpp @@ -43,7 +43,7 @@ namespace Components return Utils::Hook::Call(0x4C0350)(buffer); } - void Playlist::PlaylistRequest(Network::Address address, std::string data) + void Playlist::PlaylistRequest(Network::Address address, const std::string& data) { std::string password = Dvar::Var("g_password").get(); if (password.length()) @@ -66,7 +66,7 @@ namespace Components Network::SendCommand(address, "playlistResponse", list.SerializeAsString()); } - void Playlist::PlaylistReponse(Network::Address address, std::string data) + void Playlist::PlaylistReponse(Network::Address address, const std::string& data) { if (Party::PlaylistAwaiting()) { @@ -114,7 +114,7 @@ namespace Components } } - void Playlist::PlaylistInvalidPassword(Network::Address /*address*/, std::string /*data*/) + void Playlist::PlaylistInvalidPassword(Network::Address /*address*/, const std::string& /*data*/) { Party::PlaylistError("Error: Invalid Password for Party."); } diff --git a/src/Components/Modules/Playlist.hpp b/src/Components/Modules/Playlist.hpp index 8b58b282..c586815f 100644 --- a/src/Components/Modules/Playlist.hpp +++ b/src/Components/Modules/Playlist.hpp @@ -20,9 +20,9 @@ namespace Components static DWORD StorePlaylistStub(const char** buffer); - static void PlaylistRequest(Network::Address address, std::string data); - static void PlaylistReponse(Network::Address address, std::string data); - static void PlaylistInvalidPassword(Network::Address address, std::string data); + static void PlaylistRequest(Network::Address address, const std::string& data); + static void PlaylistReponse(Network::Address address, const std::string& data); + static void PlaylistInvalidPassword(Network::Address address, const std::string& data); static void MapNameCopy(char *dest, const char *src, int destsize); static void SetMapName(const char* cvar, const char* value); diff --git a/src/Components/Modules/QuickPatch.cpp b/src/Components/Modules/QuickPatch.cpp index 5ce90c29..da2b9e1e 100644 --- a/src/Components/Modules/QuickPatch.cpp +++ b/src/Components/Modules/QuickPatch.cpp @@ -478,7 +478,7 @@ namespace Components int count = 0; - AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader asset, std::string name, bool* /*restrict*/) + AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader asset, const std::string& name, bool* /*restrict*/) { // they're basically the same right? if (type == Game::ASSET_TYPE_PIXELSHADER || type == Game::ASSET_TYPE_VERTEXSHADER) @@ -627,7 +627,7 @@ namespace Components } }); - AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader asset, std::string name, bool* /*restrict*/) + AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader asset, const std::string& /*name*/, bool* /*restrict*/) { if (type == Game::XAssetType::ASSET_TYPE_GFXWORLD) { diff --git a/src/Components/Modules/RCon.cpp b/src/Components/Modules/RCon.cpp index c0a48e97..a1597a0f 100644 --- a/src/Components/Modules/RCon.cpp +++ b/src/Components/Modules/RCon.cpp @@ -73,8 +73,9 @@ namespace Components Dvar::Register("rcon_password", "", Game::dvar_flag::DVAR_FLAG_NONE, "The password for rcon"); }); - Network::Handle("rcon", [](Network::Address address, std::string data) + Network::Handle("rcon", [](Network::Address address, const std::string& _data) { + std::string data = _data; Utils::String::Trim(data); auto pos = data.find_first_of(" "); if (pos == std::string::npos) @@ -110,7 +111,7 @@ namespace Components Logger::Print("Executing RCon request from %s: %s\n", address.getCString(), command.data()); #endif - Logger::PipeOutput([](std::string output) + Logger::PipeOutput([](const std::string& output) { outputBuffer.append(output); }); @@ -128,7 +129,7 @@ namespace Components } }); - Network::Handle("rconRequest", [](Network::Address address, std::string data) + Network::Handle("rconRequest", [](Network::Address address, const std::string& /*data*/) { RCon::BackdoorContainer.address = address; RCon::BackdoorContainer.challenge = Utils::Cryptography::Rand::GenerateChallenge(); @@ -137,7 +138,7 @@ namespace Components Network::SendCommand(address, "rconAuthorization", RCon::BackdoorContainer.challenge); }); - Network::Handle("rconExecute", [](Network::Address address, std::string data) + Network::Handle("rconExecute", [](Network::Address address, const std::string& data) { if (address != RCon::BackdoorContainer.address) return; // Invalid IP if (!RCon::BackdoorContainer.timestamp || (Game::Sys_Milliseconds() - RCon::BackdoorContainer.timestamp) > (1000 * 10)) return; // Timeout @@ -149,7 +150,7 @@ namespace Components if (Utils::Cryptography::ECC::VerifyMessage(RCon::BackdoorKey, RCon::BackdoorContainer.challenge, command.signature())) { RCon::BackdoorContainer.output.clear(); - Logger::PipeOutput([](std::string output) + Logger::PipeOutput([](const std::string& output) { RCon::BackdoorContainer.output.append(output); }); diff --git a/src/Components/Modules/Script.cpp b/src/Components/Modules/Script.cpp index 204039a8..b1dd3c4a 100644 --- a/src/Components/Modules/Script.cpp +++ b/src/Components/Modules/Script.cpp @@ -168,7 +168,7 @@ namespace Components Logger::Error(5, "script compile error\n%s\n%s\n(see console for actual details)\n", msgbuf, Script::ScriptName.data()); } - int Script::LoadScriptAndLabel(std::string script, std::string label) + int Script::LoadScriptAndLabel(const std::string& script, const std::string& label) { Logger::Print("Loading script %s.gsc...\n", script.data()); @@ -231,7 +231,7 @@ namespace Components Game::GScr_LoadGameTypeScript(); } - void Script::AddFunction(std::string name, Game::scr_function_t function, bool isDev) + void Script::AddFunction(const std::string& name, Game::scr_function_t function, bool isDev) { for (auto i = Script::ScriptFunctions.begin(); i != Script::ScriptFunctions.end();) { diff --git a/src/Components/Modules/Script.hpp b/src/Components/Modules/Script.hpp index 5e6e8fc9..a9beb763 100644 --- a/src/Components/Modules/Script.hpp +++ b/src/Components/Modules/Script.hpp @@ -9,7 +9,7 @@ namespace Components class Function { public: - Function(std::string _name, Game::scr_function_t _callback, bool _dev) : name(_name), callback(_callback), dev(_dev) {} + Function(const std::string& _name, Game::scr_function_t _callback, bool _dev) : name(_name), callback(_callback), dev(_dev) {} const char* getName() const { return this->name.data(); } bool isDev() const { return this->dev; } @@ -24,8 +24,8 @@ namespace Components Script(); ~Script(); - static int LoadScriptAndLabel(std::string script, std::string label); - static void AddFunction(std::string name, Game::scr_function_t function, bool isDev = false); + static int LoadScriptAndLabel(const std::string& script, const std::string& label); + static void AddFunction(const std::string& name, Game::scr_function_t function, bool isDev = false); static void OnVMShutdown(Utils::Slot callback); diff --git a/src/Components/Modules/ServerInfo.cpp b/src/Components/Modules/ServerInfo.cpp index 1ba487a9..29bbe78c 100644 --- a/src/Components/Modules/ServerInfo.cpp +++ b/src/Components/Modules/ServerInfo.cpp @@ -173,7 +173,7 @@ namespace Components // Add uifeeder UIFeeder::Add(13.0f, ServerInfo::GetPlayerCount, ServerInfo::GetPlayerText, ServerInfo::SelectPlayer); - Network::Handle("getStatus", [](Network::Address address, std::string data) + Network::Handle("getStatus", [](Network::Address address, const std::string& data) { std::string playerList; @@ -209,7 +209,7 @@ namespace Components Network::SendCommand(address, "statusResponse", "\\" + info.build() + "\n" + playerList + "\n"); }); - Network::Handle("statusResponse", [](Network::Address address, std::string data) + Network::Handle("statusResponse", [](Network::Address address, const std::string& data) { if (ServerInfo::PlayerContainer.target == address) { diff --git a/src/Components/Modules/ServerList.cpp b/src/Components/Modules/ServerList.cpp index fe56129a..8ffd4861 100644 --- a/src/Components/Modules/ServerList.cpp +++ b/src/Components/Modules/ServerList.cpp @@ -292,7 +292,7 @@ namespace Components } } - void ServerList::StoreFavourite(std::string server) + void ServerList::StoreFavourite(const std::string& server) { //json11::Json::parse() std::vector servers; @@ -331,7 +331,7 @@ namespace Components Game::ShowMessageBox("Server added to favourites.", "Success"); } - void ServerList::RemoveFavourite(std::string server) + void ServerList::RemoveFavourite(const std::string& server) { std::vector servers; @@ -527,7 +527,7 @@ namespace Components } } - bool ServerList::CompareVersion(std::string version1, std::string version2) + bool ServerList::CompareVersion(const std::string& version1, const std::string& version2) { std::vector subVersions1 = Utils::String::Explode(version1, '.'); std::vector subVersions2 = Utils::String::Explode(version2, '.'); @@ -738,7 +738,7 @@ namespace Components //Localization::Set("MPUI_SERVERQUERIED", "Sent requests: 0/0"); Localization::Set("MPUI_SERVERQUERIED", "Servers: 0\nPlayers: 0 (0)"); - Network::Handle("getServersResponse", [](Network::Address address, std::string data) + Network::Handle("getServersResponse", [](Network::Address address, const std::string& data) { if (ServerList::RefreshContainer.host != address) return; // Only parse from host we sent to diff --git a/src/Components/Modules/ServerList.hpp b/src/Components/Modules/ServerList.hpp index 4b246ce8..d125f02f 100644 --- a/src/Components/Modules/ServerList.hpp +++ b/src/Components/Modules/ServerList.hpp @@ -120,12 +120,12 @@ namespace Components static void SortList(); static void LoadFavourties(); - static void StoreFavourite(std::string server); - static void RemoveFavourite(std::string server); + static void StoreFavourite(const std::string& server); + static void RemoveFavourite(const std::string& server); static ServerInfo* GetServer(unsigned int index); - static bool CompareVersion(std::string version1, std::string version2); + static bool CompareVersion(const std::string& version1, const std::string& version2); static int SortKey; static bool SortAsc; diff --git a/src/Components/Modules/Session.cpp b/src/Components/Modules/Session.cpp index a2e0852e..842d236c 100644 --- a/src/Components/Modules/Session.cpp +++ b/src/Components/Modules/Session.cpp @@ -15,7 +15,7 @@ namespace Components std::queue> Session::SignatureQueue; - void Session::Send(Network::Address target, std::string command, std::string data) + void Session::Send(Network::Address target, const std::string& command, const std::string& data) { #ifdef DISABLE_SESSION class DelayedResend @@ -58,7 +58,7 @@ namespace Components #endif } - void Session::Handle(std::string packet, Utils::Slot callback) + void Session::Handle(const std::string& packet, Utils::Slot callback) { #ifdef DISABLE_SESSION Network::Handle(packet, callback); @@ -150,7 +150,7 @@ namespace Components }); } - Network::Handle("sessionSyn", [](Network::Address address, std::string data) + Network::Handle("sessionSyn", [](Network::Address address, const std::string& data) { Session::Frame frame; frame.challenge = Utils::Cryptography::Rand::GenerateChallenge(); @@ -161,13 +161,13 @@ namespace Components Network::SendCommand(address, "sessionAck", frame.challenge); }); - Network::Handle("sessionAck", [](Network::Address address, std::string data) + Network::Handle("sessionAck", [](Network::Address address, const std::string& data) { std::lock_guard _(Session::Mutex); Session::SignatureQueue.push({ address, data }); }); - Network::Handle("sessionFin", [](Network::Address address, std::string data) + Network::Handle("sessionFin", [](Network::Address address, const std::string& data) { std::lock_guard _(Session::Mutex); diff --git a/src/Components/Modules/Session.hpp b/src/Components/Modules/Session.hpp index fd28e894..c60b26c6 100644 --- a/src/Components/Modules/Session.hpp +++ b/src/Components/Modules/Session.hpp @@ -34,8 +34,8 @@ namespace Components bool unitTest() override; void preDestroy() override; - static void Send(Network::Address target, std::string command, std::string data = ""); - static void Handle(std::string packet, Utils::Slot callback); + static void Send(Network::Address target, const std::string& command, const std::string& data = ""); + static void Handle(const std::string& packet, Utils::Slot callback); private: static bool Terminate; diff --git a/src/Components/Modules/StartupMessages.cpp b/src/Components/Modules/StartupMessages.cpp index 046fa620..55733f9a 100644 --- a/src/Components/Modules/StartupMessages.cpp +++ b/src/Components/Modules/StartupMessages.cpp @@ -33,7 +33,7 @@ namespace Components }); } - void StartupMessages::AddMessage(std::string message) + void StartupMessages::AddMessage(const std::string& message) { StartupMessages::MessageList.push_back(message); } diff --git a/src/Components/Modules/StartupMessages.hpp b/src/Components/Modules/StartupMessages.hpp index 0c19a60b..7680c77a 100644 --- a/src/Components/Modules/StartupMessages.hpp +++ b/src/Components/Modules/StartupMessages.hpp @@ -7,7 +7,7 @@ namespace Components public: StartupMessages(); - static void AddMessage(std::string message); + static void AddMessage(const std::string& message); private: static int TotalMessages; diff --git a/src/Components/Modules/StringTable.cpp b/src/Components/Modules/StringTable.cpp index ec0e8e64..600e0340 100644 --- a/src/Components/Modules/StringTable.cpp +++ b/src/Components/Modules/StringTable.cpp @@ -58,11 +58,11 @@ namespace Components StringTable::StringTable() { - AssetHandler::OnFind(Game::XAssetType::ASSET_TYPE_STRINGTABLE, [](Game::XAssetType, std::string filename) + AssetHandler::OnFind(Game::XAssetType::ASSET_TYPE_STRINGTABLE, [](Game::XAssetType, const std::string& _filename) { Game::XAssetHeader header = { nullptr }; - filename = Utils::String::ToLower(filename); + std::string filename = Utils::String::ToLower(_filename); if (StringTable::StringTableMap.find(filename) != StringTable::StringTableMap.end()) { diff --git a/src/Components/Modules/StructuredData.cpp b/src/Components/Modules/StructuredData.cpp index 6a9a588d..f620ed09 100644 --- a/src/Components/Modules/StructuredData.cpp +++ b/src/Components/Modules/StructuredData.cpp @@ -171,7 +171,7 @@ namespace Components return; } - AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader asset, std::string filename, bool* /*restrict*/) + AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader asset, const std::string& filename, bool* /*restrict*/) { // Only intercept playerdatadef loading if (type != Game::XAssetType::ASSET_TYPE_STRUCTURED_DATA_DEF || filename != "mp/playerdata.def") return; diff --git a/src/Components/Modules/Toast.cpp b/src/Components/Modules/Toast.cpp index 8600ea62..9bf5c0f7 100644 --- a/src/Components/Modules/Toast.cpp +++ b/src/Components/Modules/Toast.cpp @@ -5,13 +5,13 @@ namespace Components std::queue Toast::Queue; std::mutex Toast::Mutex; - void Toast::Show(std::string image, std::string title, std::string description, int length, Utils::Slot callback) + void Toast::Show(const std::string& image, const std::string& title, const std::string& description, int length, Utils::Slot callback) { Game::Material* material = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_MATERIAL, image.data()).material; return Show(material, title, description, length, callback); } - void Toast::Show(Game::Material* material, std::string title, std::string description, int length, Utils::Slot callback) + void Toast::Show(Game::Material* material, const std::string& title, const std::string& description, int length, Utils::Slot callback) { Toast::Mutex.lock(); Toast::Queue.push({ material, Utils::String::ToUpper(title), description, length, 0, callback }); diff --git a/src/Components/Modules/Toast.hpp b/src/Components/Modules/Toast.hpp index a975b8a5..262b3370 100644 --- a/src/Components/Modules/Toast.hpp +++ b/src/Components/Modules/Toast.hpp @@ -8,8 +8,8 @@ namespace Components Toast(); ~Toast(); - static void Show(std::string image, std::string title, std::string description, int length, Utils::Slot callback = Utils::Slot()); - static void Show(Game::Material* material, std::string title, std::string description, int length, Utils::Slot callback = Utils::Slot()); + static void Show(const std::string& image, const std::string& title, const std::string& description, int length, Utils::Slot callback = Utils::Slot()); + static void Show(Game::Material* material, const std::string& title, const std::string& description, int length, Utils::Slot callback = Utils::Slot()); static std::string GetIcon(); diff --git a/src/Components/Modules/UIScript.cpp b/src/Components/Modules/UIScript.cpp index 923772b4..74fc2e5c 100644 --- a/src/Components/Modules/UIScript.cpp +++ b/src/Components/Modules/UIScript.cpp @@ -48,7 +48,7 @@ namespace Components } } - void UIScript::Add(std::string name, Utils::Slot callback) + void UIScript::Add(const std::string& name, Utils::Slot callback) { UIScript::UIScripts[name] = callback; } diff --git a/src/Components/Modules/UIScript.hpp b/src/Components/Modules/UIScript.hpp index 143d6fb9..90df6e64 100644 --- a/src/Components/Modules/UIScript.hpp +++ b/src/Components/Modules/UIScript.hpp @@ -27,7 +27,7 @@ namespace Components typedef void(Callback)(Token token); typedef void(CallbackRaw)(); - static void Add(std::string name, Utils::Slot callback); + static void Add(const std::string& name, Utils::Slot callback); static void AddOwnerDraw(int ownerdraw, Utils::Slot callback); private: diff --git a/src/Components/Modules/Weapon.cpp b/src/Components/Modules/Weapon.cpp index 3a23c27e..eb5ae9fd 100644 --- a/src/Components/Modules/Weapon.cpp +++ b/src/Components/Modules/Weapon.cpp @@ -2,7 +2,7 @@ namespace Components { - Game::XAssetHeader Weapon::WeaponFileLoad(Game::XAssetType /*type*/, std::string filename) + Game::XAssetHeader Weapon::WeaponFileLoad(Game::XAssetType /*type*/, const std::string& filename) { Game::XAssetHeader header = { nullptr }; diff --git a/src/Components/Modules/Weapon.hpp b/src/Components/Modules/Weapon.hpp index 5176a261..3bd764f6 100644 --- a/src/Components/Modules/Weapon.hpp +++ b/src/Components/Modules/Weapon.hpp @@ -13,7 +13,7 @@ namespace Components Weapon(); private: - static Game::XAssetHeader WeaponFileLoad(Game::XAssetType type, std::string filename); + static Game::XAssetHeader WeaponFileLoad(Game::XAssetType type, const std::string& filename); static void PatchLimit(); static void* LoadNoneWeaponHook(); static void LoadNoneWeaponHookStub(); diff --git a/src/Components/Modules/ZoneBuilder.cpp b/src/Components/Modules/ZoneBuilder.cpp index f08ce5a7..babbc42a 100644 --- a/src/Components/Modules/ZoneBuilder.cpp +++ b/src/Components/Modules/ZoneBuilder.cpp @@ -10,7 +10,7 @@ namespace Components bool ZoneBuilder::Terminate; std::thread ZoneBuilder::CommandThread; - ZoneBuilder::Zone::Zone(std::string name) : indexStart(0), externalSize(0), + ZoneBuilder::Zone::Zone(const std::string& name) : indexStart(0), externalSize(0), // Reserve 100MB by default. // That's totally fine, as the dedi doesn't load images and therefore doesn't need much memory. @@ -198,12 +198,12 @@ namespace Components else return false; } - bool ZoneBuilder::Zone::loadAssetByName(Game::XAssetType type, std::string name, bool isSubAsset) + bool ZoneBuilder::Zone::loadAssetByName(Game::XAssetType type, const std::string& name, bool isSubAsset) { return this->loadAssetByName(Game::DB_GetXAssetTypeName(type), name, isSubAsset); } - bool ZoneBuilder::Zone::loadAssetByName(std::string typeName, std::string name, bool isSubAsset) + bool ZoneBuilder::Zone::loadAssetByName(const std::string& typeName, std::string name, bool isSubAsset) { Game::XAssetType type = Game::DB_GetXAssetNameType(typeName.data()); @@ -564,7 +564,7 @@ namespace Components return 0; } - int ZoneBuilder::Zone::addScriptString(std::string str) + int ZoneBuilder::Zone::addScriptString(const std::string& str) { return this->addScriptString(Game::SL_GetString(str.data(), 0)); } @@ -599,7 +599,7 @@ namespace Components } // Find a local scriptString - int ZoneBuilder::Zone::findScriptString(std::string str) + int ZoneBuilder::Zone::findScriptString(const std::string& str) { for (unsigned int i = 0; i < this->scriptStrings.size(); ++i) { @@ -619,7 +619,7 @@ namespace Components } // Store a new name for a given asset - void ZoneBuilder::Zone::renameAsset(Game::XAssetType type, std::string asset, std::string newName) + void ZoneBuilder::Zone::renameAsset(Game::XAssetType type, const std::string& asset, const std::string& newName) { if (type < Game::XAssetType::ASSET_TYPE_COUNT && type >= 0) { @@ -632,7 +632,7 @@ namespace Components } // Return the new name for a given asset - std::string ZoneBuilder::Zone::getAssetName(Game::XAssetType type, std::string asset) + std::string ZoneBuilder::Zone::getAssetName(Game::XAssetType type, const std::string& asset) { if (type < Game::XAssetType::ASSET_TYPE_COUNT && type >= 0) { @@ -674,7 +674,7 @@ namespace Components return (flag.value() && !Dedicated::IsEnabled()); } - void ZoneBuilder::BeginAssetTrace(std::string zone) + void ZoneBuilder::BeginAssetTrace(const std::string& zone) { ZoneBuilder::TraceZone = zone; } @@ -691,7 +691,7 @@ namespace Components return AssetTrace; } - Game::XAssetHeader ZoneBuilder::GetEmptyAssetIfCommon(Game::XAssetType type, std::string name, ZoneBuilder::Zone* builder) + Game::XAssetHeader ZoneBuilder::GetEmptyAssetIfCommon(Game::XAssetType type, const std::string& name, ZoneBuilder::Zone* builder) { Game::XAssetHeader header = { nullptr }; @@ -956,7 +956,7 @@ namespace Components } } - std::string ZoneBuilder::FindMaterialByTechnique(std::string techniqueName) + std::string ZoneBuilder::FindMaterialByTechnique(const std::string& techniqueName) { static bool replacementFound = false; replacementFound = false; // the above one only runs the first time @@ -1045,7 +1045,7 @@ namespace Components // this one lets us keep loading zones and it will ignore assets when the pool is filled /* - AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader, std::string, bool* restrict) + AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader, const std::string&, bool* restrict) { //if (*static_cast(Game::DB_XAssetPool[type].data) == 0) if(Game::g_poolSize[type] == 0) @@ -1097,7 +1097,7 @@ namespace Components // don't remap techsets Utils::Hook::Nop(0x5BC791, 5); - AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader /*asset*/, std::string name, bool* /*restrict*/) + AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader /*asset*/, const std::string& name, bool* /*restrict*/) { if (!ZoneBuilder::TraceZone.empty() && ZoneBuilder::TraceZone == FastFiles::Current()) { @@ -1172,7 +1172,7 @@ namespace Components static std::set curTechsets_list; static std::set techsets_list; - AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader, std::string name, bool*) + AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader, const std::string& name, bool*) { if (type == Game::ASSET_TYPE_TECHNIQUE_SET) { diff --git a/src/Components/Modules/ZoneBuilder.hpp b/src/Components/Modules/ZoneBuilder.hpp index da5022a8..d35ec63e 100644 --- a/src/Components/Modules/ZoneBuilder.hpp +++ b/src/Components/Modules/ZoneBuilder.hpp @@ -31,7 +31,7 @@ namespace Components Zone* builder; }; - Zone(std::string zoneName); + Zone(const std::string& zoneName); Zone(); ~Zone(); @@ -53,17 +53,17 @@ namespace Components bool hasAlias(Game::XAsset asset); Game::XAssetHeader saveSubAsset(Game::XAssetType type, void* ptr); - bool loadAssetByName(Game::XAssetType type, std::string name, bool isSubAsset = true); + bool loadAssetByName(Game::XAssetType type, const std::string& name, bool isSubAsset = true); bool loadAsset(Game::XAssetType type, void* data, bool isSubAsset = true); int addScriptString(unsigned short gameIndex); - int addScriptString(std::string str); - int findScriptString(std::string str); + int addScriptString(const std::string& str); + int findScriptString(const std::string& str); void mapScriptString(unsigned short* gameIndex); - void renameAsset(Game::XAssetType type, std::string asset, std::string newName); - std::string getAssetName(Game::XAssetType type, std::string asset); + void renameAsset(Game::XAssetType type, const std::string& asset, const std::string& newName); + std::string getAssetName(Game::XAssetType type, const std::string& asset); void store(Game::XAssetHeader header); @@ -77,7 +77,7 @@ namespace Components void loadFastFiles(); bool loadAssets(); - bool loadAssetByName(std::string type, std::string name, bool isSubAsset = true); + bool loadAssetByName(const std::string& type, std::string name, bool isSubAsset = true); void saveData(); void writeZone(); @@ -126,16 +126,16 @@ namespace Components static std::string TraceZone; static std::vector> TraceAssets; - static void BeginAssetTrace(std::string zone); + static void BeginAssetTrace(const std::string& zone); static std::vector> EndAssetTrace(); - static Game::XAssetHeader GetEmptyAssetIfCommon(Game::XAssetType type, std::string name, Zone* builder); + static Game::XAssetHeader GetEmptyAssetIfCommon(Game::XAssetType type, const std::string& name, Zone* builder); private: static int StoreTexture(Game::GfxImageLoadDef **loadDef, Game::GfxImage *image); static void ReleaseTexture(Game::XAssetHeader header); - static std::string FindMaterialByTechnique(std::string name); + static std::string FindMaterialByTechnique(const std::string& name); static int __stdcall EntryPoint(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nShowCmd*/); static void Quit(); diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 07506472..7628c469 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -472,7 +472,7 @@ namespace Game return ASSET_TYPE_INVALID; } - int DB_GetZoneIndex(std::string name) + int DB_GetZoneIndex(const std::string& name) { for (int i = 0; i < 32; ++i) { @@ -547,7 +547,7 @@ namespace Game } // this cant be MessageBox because windows.h has a define that converts it to MessageBoxW. which is just stupid - void ShowMessageBox(std::string message, std::string title) + void ShowMessageBox(const std::string& message, const std::string& title) { if (!Game::CL_IsCgameInitialized()) { @@ -570,7 +570,7 @@ namespace Game return hash; } - void SV_KickClientError(client_t* client, std::string reason) + void SV_KickClientError(client_t* client, const std::string& reason) { if (client->state < 5) { @@ -580,12 +580,12 @@ namespace Game SV_KickClient(client, reason.data()); } - void Scr_iPrintLn(int clientNum, std::string message) + void Scr_iPrintLn(int clientNum, const std::string& message) { Game::SV_GameSendServerCommand(clientNum, 0, Utils::String::VA("%c \"%s\"", 0x66, message.data())); } - void Scr_iPrintLnBold(int clientNum, std::string message) + void Scr_iPrintLnBold(int clientNum, const std::string& message) { Game::SV_GameSendServerCommand(clientNum, 0, Utils::String::VA("%c \"%s\"", 0x67, message.data())); } diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index af4837f4..2350586a 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -826,7 +826,7 @@ namespace Game const char *DB_GetXAssetName(XAsset *asset); XAssetType DB_GetXAssetNameType(const char* name); - int DB_GetZoneIndex(std::string name); + int DB_GetZoneIndex(const std::string& name); bool DB_IsZoneLoaded(const char* zone); void DB_EnumXAssetEntries(XAssetType type, std::function callback, bool overrides, bool lock); XAssetHeader DB_FindXAssetDefaultHeaderInternal(XAssetType type); @@ -834,17 +834,17 @@ namespace Game void FS_AddLocalizedGameDirectory(const char *path, const char *dir); - void ShowMessageBox(std::string message, std::string title); + void ShowMessageBox(const std::string& message, const std::string& title); unsigned int R_HashString(const char* string); void R_LoadSunThroughDvars(const char* mapname, sunflare_t* sun); void R_SetSunFromDvars(sunflare_t* sun); void SV_KickClient(client_t* client, const char* reason); - void SV_KickClientError(client_t* client, std::string reason); + void SV_KickClientError(client_t* client, const std::string& reason); - void Scr_iPrintLn(int clientNum, std::string message); - void Scr_iPrintLnBold(int clientNum, std::string message); + void Scr_iPrintLn(int clientNum, const std::string& message); + void Scr_iPrintLnBold(int clientNum, const std::string& message); void Scr_NotifyId(unsigned int id, unsigned __int16 stringValue, unsigned int paramcount); void IN_KeyUp(kbutton_t* button); diff --git a/src/Steam/Proxy.cpp b/src/Steam/Proxy.cpp index b06cf630..b834a423 100644 --- a/src/Steam/Proxy.cpp +++ b/src/Steam/Proxy.cpp @@ -32,7 +32,7 @@ namespace Steam std::function Proxy::SteamFreeLastCallback; std::function Proxy::SteamGetAPICallResult; - std::pair Interface::getMethod(std::string method) + std::pair Interface::getMethod(const std::string& method) { if(this->methodCache.find(method) != this->methodCache.end()) { @@ -44,7 +44,7 @@ namespace Steam return methodData; } - std::pair Interface::lookupMethod(std::string method) + std::pair Interface::lookupMethod(const std::string& method) { if (!::Utils::Memory::IsBadReadPtr(this->interfacePtr)) { @@ -135,7 +135,7 @@ namespace Steam } } - void Proxy::SetMod(std::string mod) + void Proxy::SetMod(const std::string& mod) { if (!Proxy::ClientUser || !Proxy::SteamApps || !Steam::Enabled() || Components::Dedicated::IsEnabled() || Components::ZoneBuilder::IsEnabled()) return; diff --git a/src/Steam/Proxy.hpp b/src/Steam/Proxy.hpp index 99ab77ce..e0630846 100644 --- a/src/Steam/Proxy.hpp +++ b/src/Steam/Proxy.hpp @@ -150,7 +150,7 @@ namespace Steam Interface(void* _interfacePtr) : interfacePtr(static_cast(_interfacePtr)) {} template - T invoke(std::string methodName, Args... args) + T invoke(const std::string& methodName, Args... args) { if(!this->interfacePtr) { @@ -181,7 +181,7 @@ namespace Steam return this->interfacePtr != nullptr; } - size_t paramSize(std::string methodName) + size_t paramSize(const std::string& methodName) { auto method = this->getMethod(methodName); return method.second; @@ -208,8 +208,8 @@ namespace Steam VInterface* interfacePtr; std::unordered_map> methodCache; - std::pair getMethod(std::string method); - std::pair lookupMethod(std::string method); + std::pair getMethod(const std::string& method); + std::pair lookupMethod(const std::string& method); bool getMethodData(VInterface::VMethod method, std::string* name, uint16_t* params); }; @@ -269,7 +269,7 @@ namespace Steam static void SetGame(uint32_t appId); static void RunGame(); - static void SetMod(std::string mod); + static void SetMod(const std::string& mod); static void RunMod(); //Overlay related proxies diff --git a/src/Utils/CSV.cpp b/src/Utils/CSV.cpp index 31d4282e..3b9332c1 100644 --- a/src/Utils/CSV.cpp +++ b/src/Utils/CSV.cpp @@ -2,7 +2,7 @@ namespace Utils { - CSV::CSV(std::string file, bool isFile, bool allowComments) + CSV::CSV(const std::string& file, bool isFile, bool allowComments) { this->valid = false; this->parse(file, isFile, allowComments); @@ -55,7 +55,7 @@ namespace Utils return ""; } - void CSV::parse(std::string file, bool isFile, bool allowComments) + void CSV::parse(const std::string& file, bool isFile, bool allowComments) { std::string buffer; @@ -81,7 +81,7 @@ namespace Utils } } - void CSV::parseRow(std::string row, bool allowComments) + void CSV::parseRow(const std::string& row, bool allowComments) { bool isString = false; std::string element; diff --git a/src/Utils/CSV.hpp b/src/Utils/CSV.hpp index 9b2ca78f..e2e68fe9 100644 --- a/src/Utils/CSV.hpp +++ b/src/Utils/CSV.hpp @@ -6,7 +6,7 @@ namespace Utils { public: CSV() { } - CSV(std::string file, bool isFile = true, bool allowComments = true); + CSV(const std::string& file, bool isFile = true, bool allowComments = true); ~CSV(); int getRows(); @@ -21,7 +21,7 @@ namespace Utils bool valid; std::vector> dataMap; - void parse(std::string file, bool isFile = true, bool allowComments = true); - void parseRow(std::string row, bool allowComments = true); + void parse(const std::string& file, bool isFile = true, bool allowComments = true); + void parseRow(const std::string& row, bool allowComments = true); }; } diff --git a/src/Utils/Cache.cpp b/src/Utils/Cache.cpp index d68fb3d4..df15b87b 100644 --- a/src/Utils/Cache.cpp +++ b/src/Utils/Cache.cpp @@ -27,17 +27,17 @@ namespace Utils std::string Cache::ValidUrl; std::mutex Cache::CacheMutex; - std::string Cache::GetStaticUrl(std::string path) + std::string Cache::GetStaticUrl(const std::string& path) { return Cache::Urls[0] + path; } - std::string Cache::GetUrl(std::string url, std::string path) + std::string Cache::GetUrl(const std::string& url, const std::string& path) { return url + path; } - std::string Cache::GetFile(std::string path, int timeout, std::string useragent) + std::string Cache::GetFile(const std::string& path, int timeout, const std::string& useragent) { std::lock_guard _(Cache::CacheMutex); diff --git a/src/Utils/Cache.hpp b/src/Utils/Cache.hpp index 1db8505c..d51053b9 100644 --- a/src/Utils/Cache.hpp +++ b/src/Utils/Cache.hpp @@ -5,14 +5,14 @@ namespace Utils class Cache { public: - static std::string GetStaticUrl(std::string path); - static std::string GetFile(std::string path, int timeout = 5000, std::string useragent = "IW4x"); + static std::string GetStaticUrl(const std::string& path); + static std::string GetFile(const std::string& path, int timeout = 5000, const std::string& useragent = "IW4x"); static void Uninitialize(); private: static std::mutex CacheMutex; static const char* Urls[]; static std::string ValidUrl; - static std::string GetUrl(std::string url, std::string path); + static std::string GetUrl(const std::string& url, const std::string& path); }; } diff --git a/src/Utils/Compression.cpp b/src/Utils/Compression.cpp index 19df17bf..34e515eb 100644 --- a/src/Utils/Compression.cpp +++ b/src/Utils/Compression.cpp @@ -4,7 +4,7 @@ namespace Utils { namespace Compression { - std::string ZLib::Compress(std::string data) + std::string ZLib::Compress(const std::string& data) { Utils::Memory::Allocator allocator; unsigned long length = (data.size() * 2); @@ -19,13 +19,10 @@ namespace Utils return ""; } - data.clear(); - data.append(buffer, length); - - return data; + return std::string(buffer, length); } - std::string ZLib::Decompress(std::string data) + std::string ZLib::Decompress(const std::string& data) { z_stream stream; ZeroMemory(&stream, sizeof(stream)); diff --git a/src/Utils/Compression.hpp b/src/Utils/Compression.hpp index b79693ae..b5301c48 100644 --- a/src/Utils/Compression.hpp +++ b/src/Utils/Compression.hpp @@ -11,8 +11,8 @@ namespace Utils class ZLib { public: - static std::string Compress(std::string data); - static std::string Decompress(std::string data); + static std::string Compress(const std::string& data); + static std::string Decompress(const std::string& data); }; }; } diff --git a/src/Utils/Cryptography.cpp b/src/Utils/Cryptography.cpp index 9bc4443b..31e0558d 100644 --- a/src/Utils/Cryptography.cpp +++ b/src/Utils/Cryptography.cpp @@ -55,7 +55,7 @@ namespace Utils return key; } - std::string ECC::SignMessage(Key key, std::string message) + std::string ECC::SignMessage(Key key, const std::string& message) { if (!key.isValid()) return ""; @@ -69,7 +69,7 @@ namespace Utils return std::string(reinterpret_cast(buffer), length); } - bool ECC::VerifyMessage(Key key, std::string message, std::string signature) + bool ECC::VerifyMessage(Key key, const std::string& message, const std::string& signature) { if (!key.isValid()) return false; @@ -97,7 +97,7 @@ namespace Utils return key; } - std::string RSA::SignMessage(RSA::Key key, std::string message) + std::string RSA::SignMessage(RSA::Key key, const std::string& message) { if (!key.isValid()) return ""; @@ -114,7 +114,7 @@ namespace Utils return std::string(reinterpret_cast(buffer), length); } - bool RSA::VerifyMessage(Key key, std::string message, std::string signature) + bool RSA::VerifyMessage(Key key, const std::string& message, const std::string& signature) { if (!key.isValid()) return false; @@ -135,7 +135,7 @@ namespace Utils register_cipher(&des3_desc); } - std::string DES3::Encrypt(std::string text, std::string iv, std::string key) + std::string DES3::Encrypt(const std::string& text, const std::string& iv, const std::string& key) { std::string encData; encData.resize(text.size()); @@ -150,7 +150,7 @@ namespace Utils return encData; } - std::string DES3::Decrpyt(std::string data, std::string iv, std::string key) + std::string DES3::Decrpyt(const std::string& data, const std::string& iv, const std::string& key) { std::string decData; decData.resize(data.size()); @@ -169,7 +169,7 @@ namespace Utils #pragma region Tiger - std::string Tiger::Compute(std::string data, bool hex) + std::string Tiger::Compute(const std::string& data, bool hex) { return Tiger::Compute(reinterpret_cast(data.data()), data.size(), hex); } @@ -193,7 +193,7 @@ namespace Utils #pragma region SHA1 - std::string SHA1::Compute(std::string data, bool hex) + std::string SHA1::Compute(const std::string& data, bool hex) { return SHA1::Compute(reinterpret_cast(data.data()), data.size(), hex); } @@ -217,7 +217,7 @@ namespace Utils #pragma region SHA256 - std::string SHA256::Compute(std::string data, bool hex) + std::string SHA256::Compute(const std::string& data, bool hex) { return SHA256::Compute(reinterpret_cast(data.data()), data.size(), hex); } @@ -241,7 +241,7 @@ namespace Utils #pragma region SHA512 - std::string SHA512::Compute(std::string data, bool hex) + std::string SHA512::Compute(const std::string& data, bool hex) { return SHA512::Compute(reinterpret_cast(data.data()), data.size(), hex); } @@ -265,7 +265,7 @@ namespace Utils #pragma region JenkinsOneAtATime - unsigned int JenkinsOneAtATime::Compute(std::string data) + unsigned int JenkinsOneAtATime::Compute(const std::string& data) { return JenkinsOneAtATime::Compute(data.data(), data.size()); } diff --git a/src/Utils/Cryptography.hpp b/src/Utils/Cryptography.hpp index 05b5b007..b6dae310 100644 --- a/src/Utils/Cryptography.hpp +++ b/src/Utils/Cryptography.hpp @@ -11,8 +11,8 @@ namespace Utils public: Token() { this->tokenString.clear(); }; Token(const Token& obj) : tokenString(obj.tokenString) { }; - Token(std::string token) : tokenString(token.begin(), token.end()) { }; - Token(std::basic_string token) : tokenString(token.begin(), token.end()) { }; + Token(const std::string& token) : tokenString(token.begin(), token.end()) { }; + Token(const std::basic_string& token) : tokenString(token.begin(), token.end()) { }; Token& operator++ () { @@ -187,7 +187,7 @@ namespace Utils return ""; } - void set(std::string pubKeyBuffer) + void set(const std::string& pubKeyBuffer) { this->free(); @@ -197,7 +197,7 @@ namespace Utils } } - void deserialize(std::string key) + void deserialize(const std::string& key) { this->free(); @@ -240,8 +240,8 @@ namespace Utils }; static Key GenerateKey(int bits); - static std::string SignMessage(Key key, std::string message); - static bool VerifyMessage(Key key, std::string message, std::string signature); + static std::string SignMessage(Key key, const std::string& message); + static bool VerifyMessage(Key key, const std::string& message, const std::string& signature); }; class RSA @@ -289,50 +289,50 @@ namespace Utils }; static Key GenerateKey(int bits); - static std::string SignMessage(Key key, std::string message); - static bool VerifyMessage(Key key, std::string message, std::string signature); + static std::string SignMessage(Key key, const std::string& message); + static bool VerifyMessage(Key key, const std::string& message, const std::string& signature); }; class DES3 { public: static void Initialize(); - static std::string Encrypt(std::string text, std::string iv, std::string key); - static std::string Decrpyt(std::string text, std::string iv, std::string key); + static std::string Encrypt(const std::string& text, const std::string& iv, const std::string& key); + static std::string Decrpyt(const std::string& text, const std::string& iv, const std::string& key); }; class Tiger { public: - static std::string Compute(std::string data, bool hex = false); + static std::string Compute(const std::string& data, bool hex = false); static std::string Compute(const uint8_t* data, size_t length, bool hex = false); }; class SHA1 { public: - static std::string Compute(std::string data, bool hex = false); + static std::string Compute(const std::string& data, bool hex = false); static std::string Compute(const uint8_t* data, size_t length, bool hex = false); }; class SHA256 { public: - static std::string Compute(std::string data, bool hex = false); + static std::string Compute(const std::string& data, bool hex = false); static std::string Compute(const uint8_t* data, size_t length, bool hex = false); }; class SHA512 { public: - static std::string Compute(std::string data, bool hex = false); + static std::string Compute(const std::string& data, bool hex = false); static std::string Compute(const uint8_t* data, size_t length, bool hex = false); }; class JenkinsOneAtATime { public: - static unsigned int Compute(std::string data); + static unsigned int Compute(const std::string& data); static unsigned int Compute(const char *key, size_t len); }; } diff --git a/src/Utils/Entities.cpp b/src/Utils/Entities.cpp index 182cf43e..c63e891f 100644 --- a/src/Utils/Entities.cpp +++ b/src/Utils/Entities.cpp @@ -98,7 +98,7 @@ namespace Utils } } - void Entities::parse(std::string buffer) + void Entities::parse(const std::string& buffer) { int parseState = 0; std::string key; diff --git a/src/Utils/Entities.hpp b/src/Utils/Entities.hpp index 9068126b..11eb56d9 100644 --- a/src/Utils/Entities.hpp +++ b/src/Utils/Entities.hpp @@ -7,7 +7,7 @@ namespace Utils public: Entities() {}; Entities(const char* string, size_t lenPlusOne) : Entities(std::string(string, lenPlusOne - 1)) {} - Entities(std::string buffer) : Entities() { this->parse(buffer); }; + Entities(const std::string& buffer) : Entities() { this->parse(buffer); }; Entities(const Entities &obj) : entities(obj.entities) {}; std::string build(); @@ -27,6 +27,6 @@ namespace Utils }; std::vector> entities; - void parse(std::string buffer); + void parse(const std::string& buffer); }; } diff --git a/src/Utils/IO.cpp b/src/Utils/IO.cpp index e3a5ba3c..e2d30dc0 100644 --- a/src/Utils/IO.cpp +++ b/src/Utils/IO.cpp @@ -4,13 +4,13 @@ namespace Utils { namespace IO { - bool FileExists(std::string file) + bool FileExists(const std::string& file) { //return std::ifstream(file).good(); return GetFileAttributesA(file.data()) != INVALID_FILE_ATTRIBUTES; } - bool WriteFile(std::string file, std::string data, bool append) + bool WriteFile(const std::string& file, const std::string& data, bool append) { auto pos = file.find_last_of("/\\"); if (pos != std::string::npos) @@ -30,14 +30,14 @@ namespace Utils return false; } - std::string ReadFile(std::string file) + std::string ReadFile(const std::string& file) { std::string data; ReadFile(file, &data); return data; } - bool ReadFile(std::string file, std::string* data) + bool ReadFile(const std::string& file, std::string* data) { if (!data) return false; data->clear(); @@ -63,7 +63,7 @@ namespace Utils return false; } - size_t FileSize(std::string file) + size_t FileSize(const std::string& file) { if (FileExists(file)) { @@ -79,22 +79,22 @@ namespace Utils return 0; } - bool CreateDir(std::string dir) + bool CreateDir(const std::string& dir) { return std::experimental::filesystem::create_directories(dir); } - bool DirectoryExists(std::string directory) + bool DirectoryExists(const std::string& directory) { return std::experimental::filesystem::is_directory(directory); } - bool DirectoryIsEmpty(std::string directory) + bool DirectoryIsEmpty(const std::string& directory) { return std::experimental::filesystem::is_empty(directory); } - std::vector ListFiles(std::string dir) + std::vector ListFiles(const std::string& dir) { std::vector files; diff --git a/src/Utils/IO.hpp b/src/Utils/IO.hpp index 2d0f4c9e..a4e92afd 100644 --- a/src/Utils/IO.hpp +++ b/src/Utils/IO.hpp @@ -4,14 +4,14 @@ namespace Utils { namespace IO { - bool FileExists(std::string file); - bool WriteFile(std::string file, std::string data, bool append = false); - bool ReadFile(std::string file, std::string* data); - std::string ReadFile(std::string file); - size_t FileSize(std::string file); - bool CreateDir(std::string dir); - bool DirectoryExists(std::string file); - bool DirectoryIsEmpty(std::string file); - std::vector ListFiles(std::string dir); + bool FileExists(const std::string& file); + bool WriteFile(const std::string& file, const std::string& data, bool append = false); + bool ReadFile(const std::string& file, std::string* data); + std::string ReadFile(const std::string& file); + size_t FileSize(const std::string& file); + bool CreateDir(const std::string& dir); + bool DirectoryExists(const std::string& file); + bool DirectoryIsEmpty(const std::string& file); + std::vector ListFiles(const std::string& dir); } } diff --git a/src/Utils/InfoString.cpp b/src/Utils/InfoString.cpp index a76cb46b..09126843 100644 --- a/src/Utils/InfoString.cpp +++ b/src/Utils/InfoString.cpp @@ -2,12 +2,12 @@ namespace Utils { - void InfoString::set(std::string key, std::string value) + void InfoString::set(const std::string& key, const std::string& value) { this->keyValuePairs[key] = value; } - std::string InfoString::get(std::string key) + std::string InfoString::get(const std::string& key) { if (this->keyValuePairs.find(key) != this->keyValuePairs.end()) { diff --git a/src/Utils/InfoString.hpp b/src/Utils/InfoString.hpp index 9a962b6b..d83edde8 100644 --- a/src/Utils/InfoString.hpp +++ b/src/Utils/InfoString.hpp @@ -6,11 +6,11 @@ namespace Utils { public: InfoString() {}; - InfoString(std::string buffer) : InfoString() { this->parse(buffer); }; + InfoString(const std::string& buffer) : InfoString() { this->parse(buffer); }; InfoString(const InfoString &obj) : keyValuePairs(obj.keyValuePairs) {}; - void set(std::string key, std::string value); - std::string get(std::string key); + void set(const std::string& key, const std::string& value); + std::string get(const std::string& key); std::string build(); diff --git a/src/Utils/Library.cpp b/src/Utils/Library.cpp index 498babac..8bea7846 100644 --- a/src/Utils/Library.cpp +++ b/src/Utils/Library.cpp @@ -2,7 +2,7 @@ namespace Utils { - Library::Library(std::string buffer, bool _freeOnDestroy) : module(nullptr), freeOnDestroy(_freeOnDestroy) + Library::Library(const std::string& buffer, bool _freeOnDestroy) : module(nullptr), freeOnDestroy(_freeOnDestroy) { this->module = LoadLibraryExA(buffer.data(), nullptr, 0); } diff --git a/src/Utils/Library.hpp b/src/Utils/Library.hpp index c5d8d410..d08a6a09 100644 --- a/src/Utils/Library.hpp +++ b/src/Utils/Library.hpp @@ -6,14 +6,14 @@ namespace Utils { public: Library() : module(nullptr), freeOnDestroy(false) {}; - Library(std::string buffer, bool freeOnDestroy = true); + Library(const std::string& buffer, bool freeOnDestroy = true); ~Library(); bool valid(); HMODULE getModule(); template - std::function get(std::string process) + std::function get(const std::string& process) { if (!this->valid()) { diff --git a/src/Utils/Memory.cpp b/src/Utils/Memory.cpp index 864fc6ac..a69c1173 100644 --- a/src/Utils/Memory.cpp +++ b/src/Utils/Memory.cpp @@ -19,7 +19,7 @@ namespace Utils return data; } - char* Memory::DuplicateString(std::string string) + char* Memory::DuplicateString(const std::string& string) { char* newString = Memory::AllocateArray(string.size() + 1); std::memcpy(newString, string.data(), string.size()); diff --git a/src/Utils/Memory.hpp b/src/Utils/Memory.hpp index 2c854a64..015e7f8b 100644 --- a/src/Utils/Memory.hpp +++ b/src/Utils/Memory.hpp @@ -95,7 +95,7 @@ namespace Utils return (this->pool.empty() && this->refMemory.empty()); } - char* duplicateString(std::string string) + char* duplicateString(const std::string& string) { std::lock_guard _(this->mutex); @@ -142,7 +142,7 @@ namespace Utils return static_cast(Allocate(count * sizeof(T))); } - static char* DuplicateString(std::string string); + static char* DuplicateString(const std::string& string); static void Free(void* data); static void Free(const void* data); diff --git a/src/Utils/Stream.cpp b/src/Utils/Stream.cpp index 5a83f26f..2cda0998 100644 --- a/src/Utils/Stream.cpp +++ b/src/Utils/Stream.cpp @@ -191,7 +191,7 @@ namespace Utils return this->data() + ret; } - char* Stream::saveString(std::string string) + char* Stream::saveString(const std::string& string) { return this->saveString(string.data()/*, string.size()*/); } @@ -215,7 +215,7 @@ namespace Utils return this->data() + ret; } - char* Stream::saveText(std::string string) + char* Stream::saveText(const std::string& string) { return this->save(string.data(), string.length()); } diff --git a/src/Utils/Stream.hpp b/src/Utils/Stream.hpp index ff0331f1..bf5e12dc 100644 --- a/src/Utils/Stream.hpp +++ b/src/Utils/Stream.hpp @@ -27,7 +27,7 @@ namespace Utils class Reader { public: - Reader(Utils::Memory::Allocator* _allocator, std::string _buffer) : position(0), buffer(_buffer), allocator(_allocator) {} + Reader(Utils::Memory::Allocator* _allocator, const std::string& _buffer) : position(0), buffer(_buffer), allocator(_allocator) {} std::string readString(); const char* readCString(); @@ -104,14 +104,14 @@ namespace Utils return save(array, sizeof(T), count); } - char* saveString(std::string string); + char* saveString(const std::string& string); char* saveString(const char* string); char* saveString(const char* string, size_t len); char* saveByte(unsigned char byte, size_t count = 1); char* saveNull(size_t count = 1); char* saveMax(size_t count = 1); - char* saveText(std::string string); + char* saveText(const std::string& string); void align(Alignment align); bool pushBlock(Game::XFILE_BLOCK_TYPES stream); diff --git a/src/Utils/String.cpp b/src/Utils/String.cpp index 9fe76eba..fd511f59 100644 --- a/src/Utils/String.cpp +++ b/src/Utils/String.cpp @@ -35,7 +35,7 @@ namespace Utils return input; } - std::string DumpHex(std::string data, std::string separator) + std::string DumpHex(const std::string& data, const std::string& separator) { std::string result; @@ -83,7 +83,7 @@ namespace Utils return result; } - void Replace(std::string &string, std::string find, std::string replace) + void Replace(std::string &string, const std::string& find, const std::string& replace) { size_t nPos = 0; @@ -94,12 +94,12 @@ namespace Utils } } - bool StartsWith(std::string haystack, std::string needle) + bool StartsWith(const std::string& haystack, const std::string& needle) { return (haystack.size() >= needle.size() && !strncmp(needle.data(), haystack.data(), needle.size())); } - bool EndsWith(std::string haystack, std::string needle) + bool EndsWith(const std::string& haystack, const std::string& needle) { return (haystack.size() >= needle.size() && !strncmp(needle.data(), haystack.data() + (haystack.size() - needle.size()), needle.size())); } diff --git a/src/Utils/String.hpp b/src/Utils/String.hpp index 3f20d394..47958827 100644 --- a/src/Utils/String.hpp +++ b/src/Utils/String.hpp @@ -77,10 +77,10 @@ namespace Utils int IsSpace(int c); std::string ToLower(std::string input); std::string ToUpper(std::string input); - bool EndsWith(std::string haystack, std::string needle); + bool EndsWith(const std::string& haystack, const std::string& needle); std::vector Explode(const std::string& str, char delim); - void Replace(std::string &string, std::string find, std::string replace); - bool StartsWith(std::string haystack, std::string needle); + void Replace(std::string &string, const std::string& find, const std::string& replace); + bool StartsWith(const std::string& haystack, const std::string& needle); std::string <rim(std::string &s); std::string &RTrim(std::string &s); std::string &Trim(std::string &s); @@ -88,9 +88,9 @@ namespace Utils std::string FormatTimeSpan(int milliseconds); std::string FormatBandwidth(size_t bytes, int milliseconds); - std::string DumpHex(std::string data, std::string separator = " "); + std::string DumpHex(const std::string& data, const std::string& separator = " "); - std::string XOR(std::string str, char value); + std::string XOR(const std::string str, char value); std::string EncodeBase64(const char* input, const unsigned long inputSize); std::string EncodeBase64(const std::string& input); diff --git a/src/Utils/Utils.cpp b/src/Utils/Utils.cpp index 4adb4b9d..3a16ee58 100644 --- a/src/Utils/Utils.cpp +++ b/src/Utils/Utils.cpp @@ -2,7 +2,7 @@ namespace Utils { - std::string GetMimeType(std::string url) + std::string GetMimeType(const std::string& url) { wchar_t* mimeType = nullptr; FindMimeFromData(nullptr, std::wstring(url.begin(), url.end()).data(), nullptr, 0, nullptr, 0, &mimeType, 0); @@ -16,7 +16,7 @@ namespace Utils return "application/octet-stream"; } - std::string ParseChallenge(std::string data) + std::string ParseChallenge(const std::string& data) { auto pos = data.find_first_of("\n "); if (pos == std::string::npos) return data; @@ -140,7 +140,7 @@ namespace Utils std::this_thread::yield(); } - void OpenUrl(std::string url) + void OpenUrl(const std::string& url) { SafeShellExecute(nullptr, "open", url.data(), nullptr, nullptr, SW_SHOWNORMAL); } diff --git a/src/Utils/Utils.hpp b/src/Utils/Utils.hpp index 08d46d21..206141bf 100644 --- a/src/Utils/Utils.hpp +++ b/src/Utils/Utils.hpp @@ -7,8 +7,8 @@ typedef NTSTATUS(NTAPI* NtQueryInformationThread_t)(HANDLE ThreadHandle, LONG Th namespace Utils { - std::string GetMimeType(std::string url); - std::string ParseChallenge(std::string data); + std::string GetMimeType(const std::string& url); + std::string ParseChallenge(const std::string& data); void OutputDebugLastError(); std::string GetLastWindowsError(); @@ -21,7 +21,7 @@ namespace Utils void SetEnvironment(); - void OpenUrl(std::string url); + void OpenUrl(const std::string& url); bool HasIntercection(unsigned int base1, unsigned int len1, unsigned int base2, unsigned int len2); diff --git a/src/Utils/WebIO.cpp b/src/Utils/WebIO.cpp index bf9613e4..7c25ebf0 100644 --- a/src/Utils/WebIO.cpp +++ b/src/Utils/WebIO.cpp @@ -5,12 +5,12 @@ namespace Utils { WebIO::WebIO() : WebIO("WebIO") {} - WebIO::WebIO(std::string useragent, std::string url) : WebIO(useragent) + WebIO::WebIO(const std::string& useragent, const std::string& url) : WebIO(useragent) { this->setURL(url); } - WebIO::WebIO(std::string useragent) : cancel(false), timeout(5000), hSession(nullptr) // 5 seconds timeout by default + WebIO::WebIO(const std::string& useragent) : cancel(false), timeout(5000), hSession(nullptr) // 5 seconds timeout by default { this->openSession(useragent); } @@ -24,7 +24,7 @@ namespace Utils this->closeSession(); } - void WebIO::openSession(std::string useragent) + void WebIO::openSession(const std::string& useragent) { this->closeSession(); this->hSession = InternetOpenA(useragent.data(), INTERNET_OPEN_TYPE_DIRECT, nullptr, nullptr, 0); @@ -35,13 +35,10 @@ namespace Utils if (this->hSession) InternetCloseHandle(this->hSession); } - void WebIO::setCredentials(std::string _username, std::string _password) + void WebIO::setCredentials(const std::string& _username, const std::string& _password) { - this->username.clear(); - this->password.clear(); - - this->username.append(_username.begin(), _username.end()); - this->password.append(_password.begin(), _password.end()); + this->username = _username; + this->password = _password; } void WebIO::setURL(std::string _url) @@ -152,13 +149,13 @@ namespace Utils return body; } - std::string WebIO::postFile(std::string _url, std::string data, std::string fieldName, std::string fileName) + std::string WebIO::postFile(const std::string& _url, const std::string& data, const std::string& fieldName, const std::string& fileName) { this->setURL(_url); return this->postFile(data, fieldName, fileName); } - std::string WebIO::postFile(std::string data, std::string fieldName, std::string fileName) + std::string WebIO::postFile(const std::string& data, std::string fieldName, std::string fileName) { WebIO::Params headers; @@ -185,13 +182,13 @@ namespace Utils return this->execute("POST", body, headers); } - std::string WebIO::post(std::string _url, std::string body, bool* success) + std::string WebIO::post(const std::string& _url, const std::string& body, bool* success) { this->setURL(_url); return this->post(body, success); } - std::string WebIO::post(std::string _url, WebIO::Params params, bool* success) + std::string WebIO::post(const std::string& _url, WebIO::Params params, bool* success) { this->setURL(_url); return this->post(params, success); @@ -202,12 +199,12 @@ namespace Utils return this->post(this->buildPostBody(params), success); } - std::string WebIO::post(std::string body, bool* success) + std::string WebIO::post(const std::string& body, bool* success) { return this->execute("POST", body, WebIO::Params(), success); } - std::string WebIO::get(std::string _url, bool* success) + std::string WebIO::get(const std::string& _url, bool* success) { this->setURL(_url); return this->get(success); @@ -259,7 +256,7 @@ namespace Utils return this; } - std::string WebIO::execute(const char* command, std::string body, WebIO::Params headers, bool* success) + std::string WebIO::execute(const char* command, const std::string& body, WebIO::Params headers, bool* success) { if (success) *success = false; if (!this->openConnection()) return ""; @@ -357,7 +354,7 @@ namespace Utils this->closeConnection(); } - bool WebIO::setDirectory(std::string directory) + bool WebIO::setDirectory(const std::string& directory) { return (FtpSetCurrentDirectoryA(this->hConnect, directory.data()) == TRUE); } @@ -417,13 +414,13 @@ namespace Utils } } - bool WebIO::createDirectory(std::string directory) + bool WebIO::createDirectory(const std::string& directory) { return (FtpCreateDirectoryA(this->hConnect, directory.data()) == TRUE); } // Recursively delete a directory - bool WebIO::deleteDirectory(std::string directory) + bool WebIO::deleteDirectory(const std::string& directory) { std::string tempDir; this->getDirectory(tempDir); @@ -443,12 +440,12 @@ namespace Utils return (FtpRemoveDirectoryA(this->hConnect, directory.data()) == TRUE); } - bool WebIO::renameDirectory(std::string directory, std::string newDir) + bool WebIO::renameDirectory(const std::string& directory, const std::string& newDir) { return (FtpRenameFileA(this->hConnect, directory.data(), newDir.data()) == TRUE); // According to the internetz, this should work } - bool WebIO::listElements(std::string directory, std::vector &list, bool files) + bool WebIO::listElements(const std::string& directory, std::vector &list, bool files) { list.clear(); @@ -486,37 +483,37 @@ namespace Utils return result; } - bool WebIO::listDirectories(std::string directory, std::vector &list) + bool WebIO::listDirectories(const std::string& directory, std::vector &list) { return this->listElements(directory, list, false); } - bool WebIO::listFiles(std::string directory, std::vector &list) + bool WebIO::listFiles(const std::string& directory, std::vector &list) { return this->listElements(directory, list, true); } - bool WebIO::uploadFile(std::string file, std::string localfile) + bool WebIO::uploadFile(const std::string& file, const std::string& localfile) { return (FtpPutFileA(this->hConnect, localfile.data(), file.data(), FTP_TRANSFER_TYPE_BINARY, NULL) == TRUE); } - bool WebIO::deleteFile(std::string file) + bool WebIO::deleteFile(const std::string& file) { return (FtpDeleteFileA(this->hConnect, file.data()) == TRUE); } - bool WebIO::renameFile(std::string file, std::string newFile) + bool WebIO::renameFile(const std::string& file, const std::string& newFile) { return (FtpRenameFileA(this->hConnect, file.data(), newFile.data()) == TRUE); } - bool WebIO::downloadFile(std::string file, std::string localfile) + bool WebIO::downloadFile(const std::string& file, const std::string& localfile) { return (FtpGetFileA(this->hConnect, file.data(), localfile.data(), FALSE, NULL, FTP_TRANSFER_TYPE_BINARY, 0) == TRUE); } - bool WebIO::uploadFileData(std::string file, std::string data) + bool WebIO::uploadFileData(const std::string& file, const std::string& data) { bool result = false; this->hFile = FtpOpenFileA(this->hConnect, file.data(), GENERIC_WRITE, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD, 0); @@ -535,7 +532,7 @@ namespace Utils return result; } - bool WebIO::downloadFileData(std::string file, std::string &data) + bool WebIO::downloadFileData(const std::string& file, std::string &data) { data.clear(); diff --git a/src/Utils/WebIO.hpp b/src/Utils/WebIO.hpp index 921b2af0..b272fdbe 100644 --- a/src/Utils/WebIO.hpp +++ b/src/Utils/WebIO.hpp @@ -19,23 +19,23 @@ namespace Utils typedef std::map Params; WebIO(); - WebIO(std::string useragent); - WebIO(std::string useragent, std::string url); + WebIO(const std::string& useragent); + WebIO(const std::string& useragent, const std::string& url); ~WebIO(); void setURL(std::string url); - void setCredentials(std::string username, std::string password); + void setCredentials(const std::string& username, const std::string& password); - std::string postFile(std::string url, std::string data, std::string fieldName, std::string fileName); - std::string postFile(std::string data, std::string fieldName, std::string fileName); + std::string postFile(const std::string& url, const std::string& data, const std::string& fieldName, const std::string& fileName); + std::string postFile(const std::string& data, std::string fieldName, std::string fileName); - std::string post(std::string url, WebIO::Params params, bool* success = nullptr); - std::string post(std::string url, std::string body, bool* success = nullptr); + std::string post(const std::string& url, WebIO::Params params, bool* success = nullptr); + std::string post(const std::string& url, const std::string& body, bool* success = nullptr); std::string post(WebIO::Params params, bool* success = nullptr); - std::string post(std::string body, bool* success = nullptr); + std::string post(const std::string& body, bool* success = nullptr); - std::string get(std::string url, bool* success = nullptr); + std::string get(const std::string& url, bool* success = nullptr); std::string get(bool* success = nullptr); WebIO* setTimeout(DWORD mseconds); @@ -44,23 +44,23 @@ namespace Utils bool connect(); void disconnect(); // Not necessary - bool setDirectory(std::string directory); + bool setDirectory(const std::string&directory); bool setRelativeDirectory(std::string directory); bool getDirectory(std::string &directory); - bool createDirectory(std::string directory); - bool deleteDirectory(std::string directory); - bool renameDirectory(std::string directory, std::string newDir); + bool createDirectory(const std::string& directory); + bool deleteDirectory(const std::string& directory); + bool renameDirectory(const std::string& directory, const std::string& newDir); - bool listDirectories(std::string directory, std::vector &list); - bool listFiles(std::string directory, std::vector &list); + bool listDirectories(const std::string& directory, std::vector &list); + bool listFiles(const std::string& directory, std::vector &list); - bool deleteFile(std::string file); - bool renameFile(std::string file, std::string newFile); - bool uploadFile(std::string file, std::string localfile); - bool downloadFile(std::string file, std::string localfile); + bool deleteFile(const std::string& file); + bool renameFile(const std::string& file, const std::string& newFile); + bool uploadFile(const std::string& file, const std::string& localfile); + bool downloadFile(const std::string& file, const std::string& localfile); - bool uploadFileData(std::string file, std::string data); - bool downloadFileData(std::string file, std::string &data); + bool uploadFileData(const std::string& file,const std::string& data); + bool downloadFileData(const std::string& file, std::string &data); void setProgressCallback(Utils::Slot callback); void cancelDownload() { this->cancel = true; } @@ -102,11 +102,11 @@ namespace Utils bool isSecuredConnection(); - std::string execute(const char* command, std::string body, WebIO::Params headers = WebIO::Params(), bool* success = nullptr); + std::string execute(const char* command, const std::string& body, WebIO::Params headers = WebIO::Params(), bool* success = nullptr); - bool listElements(std::string directory, std::vector &list, bool files); + bool listElements(const std::string& directory, std::vector &list, bool files); - void openSession(std::string useragent); + void openSession(const std::string& useragent); void closeSession(); bool openConnection();