diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index 4f7e2c40..73d1388d 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -126,7 +126,7 @@ namespace Components #ifdef DEBUG if (!Loader::IsPerformingUnitTests()) { - Logger::Print("Unregistering component: %s\n", component->getName().data()); + Logger::Print("Unregister component: {}\n", component->getName()); } #endif delete component; @@ -178,12 +178,12 @@ namespace Components for (auto component : Loader::Components) { #if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - Logger::Print("Testing '%s'...\n", component->getName().data()); + Logger::Print("Testing '{}'...\n", component->getName()); #endif auto startTime = std::chrono::high_resolution_clock::now(); bool testRes = component->unitTest(); auto duration = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - startTime).count(); - Logger::Print("Test done (%llims): %s\n\n", duration, (testRes ? "Success" : "Error")); + Logger::Print("Test done ({}ms): {}\n\n", duration, (testRes ? "Success" : "Error")); result &= testRes; } @@ -206,7 +206,7 @@ namespace Components #if defined(DEBUG) || defined(FORCE_UNIT_TESTS) if (!Loader::IsPerformingUnitTests()) { - Logger::Print("Component registered: %s\n", component->getName().data()); + Logger::Print("Component registered: {}\n", component->getName()); } #endif Loader::Components.push_back(component); diff --git a/src/Components/Modules/AssetHandler.cpp b/src/Components/Modules/AssetHandler.cpp index f20ce605..b853b070 100644 --- a/src/Components/Modules/AssetHandler.cpp +++ b/src/Components/Modules/AssetHandler.cpp @@ -25,12 +25,12 @@ namespace Components if (AssetHandler::AssetInterfaces.contains(iAsset->getType())) { - Logger::Print("Duplicate asset interface: %s\n", Game::DB_GetXAssetTypeName(iAsset->getType())); + Logger::Print("Duplicate asset interface: {}\n", Game::DB_GetXAssetTypeName(iAsset->getType())); delete AssetHandler::AssetInterfaces[iAsset->getType()]; } else { - Logger::Print("Asset interface registered: %s\n", Game::DB_GetXAssetTypeName(iAsset->getType())); + Logger::Print("Asset interface registered: {}\n", Game::DB_GetXAssetTypeName(iAsset->getType())); } AssetHandler::AssetInterfaces[iAsset->getType()] = iAsset; @@ -96,7 +96,7 @@ namespace Components if (AssetHandler::BypassState < 0) { AssetHandler::BypassState = 0; - Logger::Error("Bypass state is below 0!"); + Logger::Error(Game::ERR_FATAL, "Bypass state is below 0!"); } } @@ -345,7 +345,7 @@ namespace Components } else { - Logger::Error("No interface for type '%s'!", Game::DB_GetXAssetTypeName(asset.type)); + Logger::Error(Game::ERR_FATAL, "No interface for type '{}'!", Game::DB_GetXAssetTypeName(asset.type)); } } @@ -357,7 +357,7 @@ namespace Components } else { - Logger::Error("No interface for type '%s'!", Game::DB_GetXAssetTypeName(asset.type)); + Logger::Error(Game::ERR_FATAL, "No interface for type '{}'!", Game::DB_GetXAssetTypeName(asset.type)); } } @@ -520,8 +520,7 @@ namespace Components { for (auto& asset : AssetHandler::EmptyAssets) { - Game::Com_PrintWarning(Game::conChannel_t::CON_CHANNEL_FILES, - reinterpret_cast(0x724428), Game::DB_GetXAssetTypeName(asset.first), asset.second.data()); + Logger::Warning(Game::CON_CHANNEL_FILES, "Could not load {} \"{}\".\n", Game::DB_GetXAssetTypeName(asset.first), asset.second); } AssetHandler::EmptyAssets.clear(); diff --git a/src/Components/Modules/AssetInterfaces/IComWorld.cpp b/src/Components/Modules/AssetInterfaces/IComWorld.cpp index 4854c3a6..e8d795b5 100644 --- a/src/Components/Modules/AssetInterfaces/IComWorld.cpp +++ b/src/Components/Modules/AssetInterfaces/IComWorld.cpp @@ -19,13 +19,13 @@ namespace Assets __int64 magic = reader.read<__int64>(); if (std::memcmp(&magic, "IW4xComW", 8)) { - Components::Logger::Error("Reading comworld '%s' failed, header is invalid!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Reading comworld '{}' failed, header is invalid!", name); } int version = reader.read(); if (version != IW4X_COMMAP_VERSION) { - Components::Logger::Error("Reading comworld '%s' failed, expected version is %d, but it was %d!", name.data(), IW4X_COMMAP_VERSION, version); + Components::Logger::Error(Game::ERR_FATAL, "Reading comworld '{}' failed, expected version is {}, but it was {}!", name, IW4X_COMMAP_VERSION, version); } Game::ComWorld* asset = reader.readObject(); diff --git a/src/Components/Modules/AssetInterfaces/IFont_s.cpp b/src/Components/Modules/AssetInterfaces/IFont_s.cpp index 00ba3307..d757254b 100644 --- a/src/Components/Modules/AssetInterfaces/IFont_s.cpp +++ b/src/Components/Modules/AssetInterfaces/IFont_s.cpp @@ -104,13 +104,13 @@ namespace Assets if (!errors.empty()) { - Components::Logger::Error("Font define %s is broken: %s.", name.data(), errors.data()); + Components::Logger::Error(Game::ERR_FATAL, "Font define {} is broken: {}", name, errors); return; } if (!fontDef.is_object()) { - Components::Logger::Error("Font define %s is invaild.", name.data(), errors.data()); + Components::Logger::Error(Game::ERR_FATAL, "Font define {} is invalid {}", name, errors); return; } @@ -162,7 +162,7 @@ namespace Assets { if (std::find(charset.begin(), charset.end(), i) == charset.end()) { - Components::Logger::Error("Font %s missing codepoint %d.", name.data(), i); + Components::Logger::Error(Game::ERR_FATAL, "Font {} missing codepoint {}", name.data(), i); } } } @@ -186,15 +186,15 @@ namespace Assets if (result == -1) { - Components::Logger::Error("Truetype font %s is broken.", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Truetype font {} is broken", name); } else if (result < 0) { - Components::Logger::Error("Texture size of font %s is not enough.", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Texture size of font {} is not enough", name); } else if(h - result > size) { - Components::Logger::Print("Warn: Texture of font %s have too much left over space: %d\n", name.data(), h - result); + Components::Logger::Warning(Game::CON_CHANNEL_DONT_FILTER, "Texture of font {} have too much left over space: {}\n", name, h - result); } header->font = font; diff --git a/src/Components/Modules/AssetInterfaces/IFxEffectDef.cpp b/src/Components/Modules/AssetInterfaces/IFxEffectDef.cpp index 0cdd6b3a..97f0876a 100644 --- a/src/Components/Modules/AssetInterfaces/IFxEffectDef.cpp +++ b/src/Components/Modules/AssetInterfaces/IFxEffectDef.cpp @@ -72,13 +72,13 @@ namespace Assets __int64 magic = buffer.read<__int64>(); if (std::memcmp(&magic, "IW4xFx ", 8)) { - Components::Logger::Error("Reading fx '%s' failed, header is invalid!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Reading fx '{}' failed, header is invalid!", name); } int version = buffer.read(); if (version != IW4X_FX_VERSION) { - Components::Logger::Error("Reading fx '%s' failed, expected version is %d, but it was %d!", name.data(), IW4X_FX_VERSION, version); + Components::Logger::Error(Game::ERR_FATAL, "Reading fx '{}' failed, expected version is {}, but it was {}!", name, IW4X_FX_VERSION, version); } Game::FxEffectDef* asset = buffer.readObject(); @@ -188,7 +188,7 @@ namespace Assets } else if (elemDef->extended.trailDef) { - Components::Logger::Error("Fx element of type %d has traildef, that's impossible?\n", elemDef->elemType); + Components::Logger::Error(Game::ERR_FATAL, "Fx element of type {} has traildef, that's impossible?\n", elemDef->elemType); } } } @@ -211,14 +211,14 @@ namespace Assets if (format != "iwfx"s) { Game::Com_EndParseSession(); - Components::Logger::Error("Effect needs to be updated from the legacy format.\n"); + Components::Logger::Error(Game::ERR_FATAL, "Effect needs to be updated from the legacy format.\n"); } int version = atoi(Game::Com_Parse(&session)); if (version > 2) { Game::Com_EndParseSession(); - Components::Logger::Error("Version %i is too high. I can only handle up to %i.\n", version, 2); + Components::Logger::Error(Game::ERR_FATAL, "Version {} is too high. I can only handle up to 2.\n", version); } Utils::Memory::Allocator allocator; @@ -231,12 +231,12 @@ namespace Assets if (!value) break; if (*value != '{') { - Components::Logger::Error("Expected '{' to start a new segment, found '%s' instead.\n", value); + Components::Logger::Error(Game::ERR_FATAL, "Expected '{' to start a new segment, found '{}' instead.\n", value); } if (efx->elemCount >= ARRAYSIZE(efx->elems)) { - Components::Logger::Error("Cannot have more than %i segments.\n", ARRAYSIZE(efx->elems)); + Components::Logger::Error(Game::ERR_FATAL, "Cannot have more than {} segments.\n", ARRAYSIZE(efx->elems)); } Game::FxEditorElemDef* element = &efx->elems[efx->elemCount]; @@ -253,13 +253,13 @@ namespace Assets { // TODO: Allow loading assets from raw! if (Game::s_elemFields[i].handler(&session, element)) break; - Components::Logger::Error("Failed to parse element %s!\n", newValue.data()); + Components::Logger::Error(Game::ERR_FATAL, "Failed to parse element {}!\n", newValue); } } if (!Game::Com_MatchToken(&session, ";", 1)) { - Components::Logger::Error("Expected token ';'\n"); + Components::Logger::Error(Game::ERR_FATAL, "Expected token ';'\n"); } } } diff --git a/src/Components/Modules/AssetInterfaces/IFxWorld.cpp b/src/Components/Modules/AssetInterfaces/IFxWorld.cpp index 9473dfd0..e3bddb0d 100644 --- a/src/Components/Modules/AssetInterfaces/IFxWorld.cpp +++ b/src/Components/Modules/AssetInterfaces/IFxWorld.cpp @@ -184,11 +184,12 @@ namespace Assets } } } + 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; - Components::Logger::Error("Missing fx_map %s... you can't make them yet you idiot.", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Missing fx_map {}... you can't make them yet you idiot.", name); } } diff --git a/src/Components/Modules/AssetInterfaces/IGfxImage.cpp b/src/Components/Modules/AssetInterfaces/IGfxImage.cpp index f0981c9e..e01732a2 100644 --- a/src/Components/Modules/AssetInterfaces/IGfxImage.cpp +++ b/src/Components/Modules/AssetInterfaces/IGfxImage.cpp @@ -12,7 +12,7 @@ namespace Assets image = builder->getAllocator()->allocate(); if (!image) { - Components::Logger::Error("Failed to allocate GfxImage structure!"); + Components::Logger::Error(Game::ERR_FATAL, "Failed to allocate GfxImage structure!"); return; } @@ -30,7 +30,7 @@ namespace Assets __int64 magic = reader.read<__int64>(); if (std::memcmp(&magic, "IW4xImg" IW4X_IMG_VERSION, 8)) { - Components::Logger::Error(0, "Reading image '%s' failed, header is invalid!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Reading image '{}' failed, header is invalid!", name); } image->mapType = reader.read(); @@ -53,7 +53,7 @@ namespace Assets if (image->texture.loadDef->resourceSize != dataLength) { - Components::Logger::Error("Resource size doesn't match the data length (%s)!\n", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Resource size doesn't match the data length ({})!\n", name); } image->width = loadDef.dimensions[0]; @@ -72,7 +72,7 @@ namespace Assets if (!iwi.exists()) { - Components::Logger::Error("Loading image '%s' failed!", iwi.getName().data()); + Components::Logger::Error(Game::ERR_FATAL, "Loading image '{}' failed!", iwi.getName()); return; } @@ -82,7 +82,7 @@ namespace Assets if (std::memcmp(iwiHeader->tag, "IWi", 3) && iwiHeader->version == 8) { - Components::Logger::Error("Image is not a valid IWi!"); + Components::Logger::Error(Game::ERR_FATAL, "Image is not a valid IWi!"); return; } @@ -93,7 +93,7 @@ namespace Assets image->texture.loadDef = builder->getAllocator()->allocate(); if (!image->texture.loadDef) { - Components::Logger::Error("Failed to allocate GfxImageLoadDef structure!"); + Components::Logger::Error(Game::ERR_FATAL, "Failed to allocate GfxImageLoadDef structure!"); return; } diff --git a/src/Components/Modules/AssetInterfaces/IGfxLightDef.cpp b/src/Components/Modules/AssetInterfaces/IGfxLightDef.cpp index b842d9d9..a9785457 100644 --- a/src/Components/Modules/AssetInterfaces/IGfxLightDef.cpp +++ b/src/Components/Modules/AssetInterfaces/IGfxLightDef.cpp @@ -15,14 +15,14 @@ namespace Assets char* magic = reader.readArray(7); if (std::memcmp(magic, "IW4xLit", 7)) { - Components::Logger::Error(0, "Reading light '%s' failed, header is invalid!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Reading light '{}' failed, header is invalid!", name); } std::string version; version.push_back(reader.read()); if (version != IW4X_LIGHT_VERSION) { - Components::Logger::Error("Reading light '%s' failed, expected version is %d, but it was %d!", name.data(), atoi(IW4X_LIGHT_VERSION), atoi(version.data())); + Components::Logger::Error(Game::ERR_FATAL, "Reading light '{}' failed, expected version is {}, but it was {}!", name, IW4X_LIGHT_VERSION, version); } Game::GfxLightDef* asset = reader.readObject(); diff --git a/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp b/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp index b581c8c1..3b0752d1 100644 --- a/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp +++ b/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp @@ -137,13 +137,13 @@ namespace Assets __int64 magic = reader.read<__int64>(); if (std::memcmp(&magic, "IW4xGfxW", 8)) { - Components::Logger::Error("Reading gfxworld '%s' failed, header is invalid!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Reading gfxworld '{}' failed, header is invalid!", name); } int version = reader.read(); if (version != IW4X_GFXMAP_VERSION) { - Components::Logger::Error("Reading gfxworld '%s' failed, expected version is %d, but it was %d!", name.data(), IW4X_GFXMAP_VERSION, version); + Components::Logger::Error(Game::ERR_FATAL, "Reading gfxworld '{}' failed, expected version is {}, but it was {}!", name, IW4X_GFXMAP_VERSION, version); } Game::GfxWorld* asset = reader.readObject(); diff --git a/src/Components/Modules/AssetInterfaces/ILoadedSound.cpp b/src/Components/Modules/AssetInterfaces/ILoadedSound.cpp index 303212f0..69e4989d 100644 --- a/src/Components/Modules/AssetInterfaces/ILoadedSound.cpp +++ b/src/Components/Modules/AssetInterfaces/ILoadedSound.cpp @@ -29,7 +29,7 @@ namespace Assets unsigned int chunkIDBuffer = reader.read(); if (chunkIDBuffer != 0x46464952) // RIFF { - Components::Logger::Error(0, "Reading sound '%s' failed, header is invalid!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Reading sound '{}' failed, header is invalid!", name); return; } @@ -38,7 +38,7 @@ namespace Assets unsigned int format = reader.read(); if (format != 0x45564157) // WAVE { - Components::Logger::Error(0, "Reading sound '%s' failed, header is invalid!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Reading sound '{}' failed, header is invalid!", name); return; } @@ -55,7 +55,7 @@ namespace Assets sound->sound.info.format = reader.read(); if (sound->sound.info.format != 1 && sound->sound.info.format != 17) { - Components::Logger::Error(0, "Reading sound '%s' failed, invalid format!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Reading sound '{}' failed, invalid format!", name); return; } @@ -89,11 +89,11 @@ namespace Assets if (!sound->sound.info.data_ptr) { - Components::Logger::Error(0, "Reading sound '%s' failed, invalid format!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Reading sound '{}' failed, invalid format!", name); return; } - sound->name = builder->getAllocator()->duplicateString(name.c_str()); + sound->name = builder->getAllocator()->duplicateString(name.data()); header->loadSnd = sound; } diff --git a/src/Components/Modules/AssetInterfaces/IMaterial.cpp b/src/Components/Modules/AssetInterfaces/IMaterial.cpp index 1ac097d5..0c1ce956 100644 --- a/src/Components/Modules/AssetInterfaces/IMaterial.cpp +++ b/src/Components/Modules/AssetInterfaces/IMaterial.cpp @@ -64,14 +64,14 @@ namespace Assets char* magic = reader.readArray(7); if (std::memcmp(magic, "IW4xMat", 7)) { - Components::Logger::Error(0, "Reading material '%s' failed, header is invalid!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Reading material '{}' failed, header is invalid!", name); } std::string version; version.push_back(reader.read()); if (version != IW4X_MAT_VERSION) { - Components::Logger::Error("Reading material '%s' failed, expected version is %d, but it was %d!", name.data(), atoi(IW4X_MAT_VERSION), atoi(version.data())); + Components::Logger::Error(Game::ERR_FATAL, "Reading material '{}' failed, expected version is {}, but it was {}!", name, IW4X_MAT_VERSION, version); } Game::Material* asset = reader.readObject(); @@ -106,18 +106,18 @@ namespace Assets asset->techniqueSet = techsetPtr; if (asset->techniqueSet->name[0] == ',') continue; // Try to find a better one - Components::Logger::Print("Techset '%s' has been mapped to '%s'\n", techsetName.data(), asset->techniqueSet->name); + Components::Logger::Print("Techset '{}' has been mapped to '{}'\n", techsetName, asset->techniqueSet->name); break; } } } else { - Components::Logger::Print("Techset %s exists with the same name in iw4, and was mapped 1:1 with %s\n", techsetName.data(), asset->techniqueSet->name); + Components::Logger::Print("Techset {} exists with the same name in iw4, and was mapped 1:1 with %s\n", techsetName, asset->techniqueSet->name); } if (!asset->techniqueSet) { - Components::Logger::Error("Missing techset: '%s' not found", techsetName.data()); + Components::Logger::Error(Game::ERR_FATAL, "Missing techset: '{}' not found", techsetName); } } @@ -195,7 +195,7 @@ namespace Assets std::memcpy(asset->stateBitsEntry, header.material->stateBitsEntry, 48); asset->constantCount = header.material->constantCount; asset->constantTable = header.material->constantTable; - Components::Logger::Print("For %s, copied constants & statebits from %s\n", asset->info.name, header.material->info.name); + Components::Logger::Print("For {}, copied constants & statebits from {}\n", asset->info.name, header.material->info.name); replacementFound = true; } } @@ -231,7 +231,7 @@ namespace Assets if (techsetMatches(header.material, asset)) { - Components::Logger::Print("Material %s with techset %s has been mapped to %s\n", asset->info.name, asset->techniqueSet->name, header.material->techniqueSet->name); + Components::Logger::Print("Material {} with techset {} has been mapped to {}\n", asset->info.name, asset->techniqueSet->name, header.material->techniqueSet->name); asset->info.sortKey = header.material->info.sortKey; replacementFound = true; } @@ -241,7 +241,7 @@ namespace Assets if (!replacementFound && asset->techniqueSet) { - Components::Logger::Print("No replacement found for material %s with techset %s\n", asset->info.name, asset->techniqueSet->name); + Components::Logger::Print("No replacement found for material {} with techset {}\n", asset->info.name, asset->techniqueSet->name); std::string techName = asset->techniqueSet->name; if (techSetCorrespondance.contains(techName)) { @@ -258,9 +258,8 @@ namespace Assets if (header.material->techniqueSet == iw4TechSet->asset.header.techniqueSet) { - Components::Logger::Print("Material %s with techset %s has been mapped to %s (last chance!), taking the sort key of material %s\n", - asset->info.name, asset->techniqueSet->name, - header.material->techniqueSet->name, header.material->info.name); + Components::Logger::Print("Material {} with techset {} has been mapped to {} (last chance!), taking the sort key of material {}\n", + asset->info.name, asset->techniqueSet->name, header.material->techniqueSet->name, header.material->info.name); asset->info.sortKey = header.material->info.sortKey; asset->techniqueSet = iw4TechSet->asset.header.techniqueSet; @@ -279,23 +278,23 @@ namespace Assets if (!replacementFound) { - Components::Logger::Print("Could not find any loaded material with techset %s (in replacement of %s), so I cannot set the sortkey for material %s\n", iw4TechSetName.data(), asset->techniqueSet->name, asset->info.name); + Components::Logger::Print("Could not find any loaded material with techset {} (in replacement of {}), so I cannot set the sortkey for material {}\n", iw4TechSetName, asset->techniqueSet->name, asset->info.name); } } else { - Components::Logger::Print("Could not find any loaded techset with iw4 name %s for iw3 techset %s\n", iw4TechSetName.data(), asset->techniqueSet->name); + Components::Logger::Print("Could not find any loaded techset with iw4 name {} for iw3 techset {}\n", iw4TechSetName, asset->techniqueSet->name); } } else { - Components::Logger::Print("Could not match iw3 techset %s with any of the techsets I know! This is a critical error, there's a good chance the map will not be playable.\n", techName.data()); + Components::Logger::Print("Could not match iw3 techset {} with any of the techsets I know! This is a critical error, there's a good chance the map will not be playable.\n", techName); } } if (!reader.end()) { - Components::Logger::Error("Material data left!"); + Components::Logger::Error(Game::ERR_FATAL, "Material data left!"); } /*char baseIndex = 0; @@ -340,7 +339,7 @@ namespace Assets if (!infoData.is_object()) { - Components::Logger::Error("Failed to load material information for %s!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Failed to load material information for {}!", name); return; } @@ -348,7 +347,7 @@ namespace Assets if (!base.is_string()) { - Components::Logger::Error("No valid material base provided for %s!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "No valid material base provided for {}!", name); return; } @@ -356,7 +355,7 @@ namespace Assets if (!baseMaterial) // TODO: Maybe check if default asset? Maybe not? You could still want to use the default one as base!? { - Components::Logger::Error("Basematerial '%s' not found for %s!", base.string_value().data(), name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Basematerial '{}' not found for {}!", base.string_value(), name); return; } @@ -364,7 +363,7 @@ namespace Assets if (!material) { - Components::Logger::Error("Failed to allocate material structure!"); + Components::Logger::Error(Game::ERR_FATAL, "Failed to allocate material structure!"); return; } @@ -452,7 +451,8 @@ namespace Assets if (!applied) { - Components::Logger::Error(0, "Unable to find texture for map '%s' in %s!", map.string_value().data(), baseMaterial->info.name); + Components::Logger::Error(Game::ERR_FATAL, "Unable to find texture for map '{}' in {}!", + map.string_value(), baseMaterial->info.name); } } else @@ -469,7 +469,7 @@ namespace Assets if (!textureTable) { - Components::Logger::Error("Failed to allocate texture table!"); + Components::Logger::Error(Game::ERR_FATAL, "Failed to allocate texture table!"); return; } diff --git a/src/Components/Modules/AssetInterfaces/IMaterialPixelShader.cpp b/src/Components/Modules/AssetInterfaces/IMaterialPixelShader.cpp index 09023c78..c3a93270 100644 --- a/src/Components/Modules/AssetInterfaces/IMaterialPixelShader.cpp +++ b/src/Components/Modules/AssetInterfaces/IMaterialPixelShader.cpp @@ -26,14 +26,15 @@ namespace Assets char* magic = reader.readArray(8); if (std::memcmp(magic, "IW4xPIXL", 8)) { - Components::Logger::Error(0, "Reading pixel shader '%s' failed, header is invalid!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Reading pixel shader '{}' failed, header is invalid!", name); } std::string version; version.push_back(reader.read()); if (version != IW4X_TECHSET_VERSION) { - Components::Logger::Error("Reading pixel shader '%s' failed, expected version is %d, but it was %d!", name.data(), atoi(IW4X_TECHSET_VERSION), atoi(version.data())); + Components::Logger::Error(Game::ERR_FATAL, + "Reading pixel shader '{}' failed, expected version is {}, but it was {}!", name, IW4X_TECHSET_VERSION, version); } Game::MaterialPixelShader* asset = reader.readObject(); diff --git a/src/Components/Modules/AssetInterfaces/IMaterialTechniqueSet.cpp b/src/Components/Modules/AssetInterfaces/IMaterialTechniqueSet.cpp index 0e7e481e..1ca15ff1 100644 --- a/src/Components/Modules/AssetInterfaces/IMaterialTechniqueSet.cpp +++ b/src/Components/Modules/AssetInterfaces/IMaterialTechniqueSet.cpp @@ -22,7 +22,7 @@ namespace Assets Components::FileSystem::File techFile(Utils::String::VA("techniques/%s.iw4xTech", name.data())); if (!techFile.exists()) { *tech = nullptr; - Components::Logger::Print("Warning: Missing technique '%s'\n", name.data()); + Components::Logger::Warning(Game::CON_CHANNEL_DONT_FILTER, "Missing technique '{}'\n", name); return; } @@ -31,14 +31,15 @@ namespace Assets char* magic = reader.readArray(8); if (std::memcmp(magic, "IW4xTECH", 8)) { - Components::Logger::Error(0, "Reading technique '%s' failed, header is invalid!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Reading technique '{}' failed, header is invalid!", name); } std::string version; version.push_back(reader.read()); if (version != IW4X_TECHSET_VERSION) { - Components::Logger::Error("Reading technique '%s' failed, expected version is %d, but it was %d!", name.data(), atoi(IW4X_TECHSET_VERSION), atoi(version.data())); + Components::Logger::Error(Game::ERR_FATAL, + "Reading technique '{}' failed, expected version is {}, but it was {}!", name, IW4X_TECHSET_VERSION, version.data()); } unsigned short flags = reader.read(); @@ -107,14 +108,15 @@ namespace Assets char* magic = reader.readArray(8); if (std::memcmp(magic, "IW4xTSET", 8)) { - Components::Logger::Error(0, "Reading techset '%s' failed, header is invalid!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Reading techset '{}' failed, header is invalid!", name); } std::string version; version.push_back(reader.read()); if (version != IW4X_TECHSET_VERSION) { - Components::Logger::Error("Reading techset '%s' failed, expected version is %d, but it was %d!", name.data(), atoi(IW4X_TECHSET_VERSION), atoi(version.data())); + Components::Logger::Error(Game::ERR_FATAL, "Reading techset '{}' failed, expected version is {}, but it was {}!", + name, IW4X_TECHSET_VERSION, version); } Game::MaterialTechniqueSet* asset = reader.readObject(); diff --git a/src/Components/Modules/AssetInterfaces/IMaterialVertexDeclaration.cpp b/src/Components/Modules/AssetInterfaces/IMaterialVertexDeclaration.cpp index d4441653..5fceac6d 100644 --- a/src/Components/Modules/AssetInterfaces/IMaterialVertexDeclaration.cpp +++ b/src/Components/Modules/AssetInterfaces/IMaterialVertexDeclaration.cpp @@ -25,14 +25,15 @@ namespace Assets char* magic = reader.readArray(8); if (std::memcmp(magic, "IW4xDECL", 8)) { - Components::Logger::Error(0, "Reading vertex declaration '%s' failed, header is invalid!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Reading vertex declaration '{}' failed, header is invalid!", name); } std::string version; version.push_back(reader.read()); if (version != IW4X_TECHSET_VERSION) { - Components::Logger::Error("Reading vertex declaration '%s' failed, expected version is %d, but it was %d!", name.data(), atoi(IW4X_TECHSET_VERSION), atoi(version.data())); + Components::Logger::Error(Game::ERR_FATAL, "Reading vertex declaration '{}' failed, expected version is {}, but it was {}!", + name, IW4X_TECHSET_VERSION, version.data()); } Game::MaterialVertexDeclaration* asset = reader.readObject(); diff --git a/src/Components/Modules/AssetInterfaces/IMaterialVertexShader.cpp b/src/Components/Modules/AssetInterfaces/IMaterialVertexShader.cpp index ab9bb2c5..a8fd5d1d 100644 --- a/src/Components/Modules/AssetInterfaces/IMaterialVertexShader.cpp +++ b/src/Components/Modules/AssetInterfaces/IMaterialVertexShader.cpp @@ -25,14 +25,15 @@ namespace Assets char* magic = reader.readArray(8); if (std::memcmp(magic, "IW4xVERT", 8)) { - Components::Logger::Error(0, "Reading vertex shader '%s' failed, header is invalid!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Reading vertex shader '{}' failed, header is invalid!", name); } std::string version; version.push_back(reader.read()); if (version != IW4X_TECHSET_VERSION) { - Components::Logger::Error("Reading vertex shader '%s' failed, expected version is %d, but it was %d!", name.data(), atoi(IW4X_TECHSET_VERSION), atoi(version.data())); + Components::Logger::Error(Game::ERR_FATAL, "Reading vertex shader '{}' failed, expected version is {}, but it was {}!", + name, IW4X_TECHSET_VERSION, version); } Game::MaterialVertexShader* asset = reader.readObject(); diff --git a/src/Components/Modules/AssetInterfaces/IXAnimParts.cpp b/src/Components/Modules/AssetInterfaces/IXAnimParts.cpp index 940b5858..d92af4fe 100644 --- a/src/Components/Modules/AssetInterfaces/IXAnimParts.cpp +++ b/src/Components/Modules/AssetInterfaces/IXAnimParts.cpp @@ -15,13 +15,13 @@ namespace Assets __int64 magic = reader.read<__int64>(); if (std::memcmp(&magic, "IW4xAnim", 8)) { - Components::Logger::Error(0, "Reading animation '%s' failed, header is invalid!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Reading animation '{}' failed, header is invalid!", name); } int version = reader.read(); if (version != IW4X_ANIM_VERSION) { - Components::Logger::Error(0, "Reading animation '%s' failed, expected version is %d, but it was %d!", name.data(), IW4X_ANIM_VERSION, version); + Components::Logger::Error(Game::ERR_FATAL, "Reading animation '{}' failed, expected version is {}, but it was {}!", name, IW4X_ANIM_VERSION, version); } Game::XAnimParts* xanim = reader.readArray(); @@ -96,7 +96,7 @@ namespace Assets if (!reader.end()) { - Components::Logger::Error(0, "Reading animation '%s' failed, remaining raw data found!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Reading animation '{}' failed, remaining raw data found!", name); } header->parts = xanim; diff --git a/src/Components/Modules/AssetInterfaces/IXModel.cpp b/src/Components/Modules/AssetInterfaces/IXModel.cpp index 69be49ce..ff3a75bb 100644 --- a/src/Components/Modules/AssetInterfaces/IXModel.cpp +++ b/src/Components/Modules/AssetInterfaces/IXModel.cpp @@ -100,18 +100,18 @@ namespace Assets __int64 magic = reader.read<__int64>(); if (std::memcmp(&magic, "IW4xModl", 8)) { - Components::Logger::Error(0, "Reading model '%s' failed, header is invalid!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Reading model '{}' failed, header is invalid!", name); } int version = reader.read(); if (version != IW4X_MODEL_VERSION) { - Components::Logger::Error(0, "Reading model '%s' failed, expected version is %d, but it was %d!", name.data(), IW4X_MODEL_VERSION, version); + Components::Logger::Error(Game::ERR_FATAL, "Reading model '{}' failed, expected version is {}, but it was {}!", name, IW4X_MODEL_VERSION, version); } if (version == 4) { - Components::Logger::Print("WARNING: Model '%s' is in legacy format, please update it!\n", name.data()); + Components::Logger::Warning(Game::CON_CHANNEL_DONT_FILTER, "Model '{}' is in legacy format, please update it!\n", name); } Game::XModel* asset = reader.readObject(); @@ -310,7 +310,7 @@ namespace Assets if (!reader.end()) { - Components::Logger::Error(0, "Reading model '%s' failed, remaining raw data found!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Reading model '{}' failed, remaining raw data found!", name); } header->model = asset; diff --git a/src/Components/Modules/AssetInterfaces/IclipMap_t.cpp b/src/Components/Modules/AssetInterfaces/IclipMap_t.cpp index df933bbc..17b07d9c 100644 --- a/src/Components/Modules/AssetInterfaces/IclipMap_t.cpp +++ b/src/Components/Modules/AssetInterfaces/IclipMap_t.cpp @@ -601,13 +601,13 @@ namespace Assets __int64 magic = reader.read<__int64>(); if (std::memcmp(&magic, "IW4xClip", 8)) { - Components::Logger::Error(0, "Reading clipMap_t '%s' failed, header is invalid!", name.data()); + Components::Logger::Error(Game::ERR_FATAL, "Reading clipMap_t '{}' failed, header is invalid!", name); } int version = reader.read(); if (version > IW4X_CLIPMAP_VERSION) { - Components::Logger::Error(0, "Reading clipmap '%s' failed, expected version is %d, but it was %d!", name.data(), IW4X_CLIPMAP_VERSION, version); + Components::Logger::Error(Game::ERR_FATAL, "Reading clipmap '{}' failed, expected version is {}, but it was {}!", name, IW4X_CLIPMAP_VERSION, version); } clipMap->name = reader.readCString(); @@ -682,7 +682,7 @@ namespace Assets int planeIndex = reader.read(); if (planeIndex < 0 || planeIndex >= clipMap->planeCount) { - Components::Logger::Error("invalid plane index"); + Components::Logger::Error(Game::ERR_FATAL, "invalid plane index"); return; } clipMap->brushsides[i].plane = &clipMap->planes[planeIndex]; @@ -705,7 +705,7 @@ namespace Assets int planeIndex = reader.read(); if (planeIndex < 0 || planeIndex >= clipMap->planeCount) { - Components::Logger::Error("invalid plane index\n"); + Components::Logger::Error(Game::ERR_FATAL, "invalid plane index\n"); return; } clipMap->nodes[i].plane = &clipMap->planes[planeIndex]; @@ -773,7 +773,7 @@ namespace Assets int index = reader.read(); if (index < 0 || index > clipMap->borderCount) { - Components::Logger::Error("invalid border index\n"); + Components::Logger::Error(Game::ERR_FATAL, "invalid border index\n"); return; } clipMap->partitions[i].borders = &clipMap->borders[index]; @@ -800,10 +800,10 @@ namespace Assets clipMap->brushes[i].numsides = reader.read() & 0xFFFF; // todo: check for overflow here if (clipMap->brushes[i].numsides > 0) { - unsigned int index = reader.read(); + auto index = reader.read(); if (index < 0 || index > clipMap->numBrushSides) { - Components::Logger::Error("invalid side index\n"); + Components::Logger::Error(Game::ERR_FATAL, "invalid side index\n"); return; } clipMap->brushes[i].sides = &clipMap->brushsides[index]; @@ -813,10 +813,10 @@ namespace Assets clipMap->brushes[i].sides = nullptr; } - unsigned int index = reader.read(); + auto index = reader.read(); if (index > clipMap->numBrushEdges) { - Components::Logger::Error("invalid edge index\n"); + Components::Logger::Error(Game::ERR_FATAL, "invalid edge index\n"); return; } clipMap->brushes[i].baseAdjacentSide = &clipMap->brushEdges[index]; @@ -935,7 +935,7 @@ namespace Assets if (!reader.end()) { - Components::Logger::Error("Clipmap data left!"); + Components::Logger::Error(Game::ERR_FATAL, "Clipmap data left!"); } header->clipMap = clipMap; diff --git a/src/Components/Modules/AssetInterfaces/ImenuDef_t.cpp b/src/Components/Modules/AssetInterfaces/ImenuDef_t.cpp index 09e4d101..9b451411 100644 --- a/src/Components/Modules/AssetInterfaces/ImenuDef_t.cpp +++ b/src/Components/Modules/AssetInterfaces/ImenuDef_t.cpp @@ -11,7 +11,7 @@ namespace Assets auto menus = Components::Menus::LoadMenu(Utils::String::VA("ui_mp/%s.menu", name.data())); if (menus.size() == 0) return; - if (menus.size() > 1) Components::Logger::Print("Menu '%s' on disk has more than one menudef in it. Only saving the first one\n", name.data()); + if (menus.size() > 1) Components::Logger::Print("Menu '{}' on disk has more than one menudef in it. Only saving the first one\n", name); header->menu = menus[0].second; } diff --git a/src/Components/Modules/AssetInterfaces/Isnd_alias_list_t.cpp b/src/Components/Modules/AssetInterfaces/Isnd_alias_list_t.cpp index 55cdf5d2..2c2e90c7 100644 --- a/src/Components/Modules/AssetInterfaces/Isnd_alias_list_t.cpp +++ b/src/Components/Modules/AssetInterfaces/Isnd_alias_list_t.cpp @@ -42,7 +42,7 @@ namespace Assets if (!infoData.is_object()) { - Components::Logger::Error("Failed to load sound %s!", name.c_str()); + Components::Logger::Error(Game::ERR_FATAL, "Failed to load sound {}!", name); return; } @@ -86,14 +86,14 @@ namespace Assets { soundFile = head["soundfile"]; - Components::Logger::Print("Fixed casing on %s\n", name.c_str()); + Components::Logger::Print("Fixed casing on {}\n", name); } if (type.is_null() || soundFile.is_null()) { - Components::Logger::Print("Type is %s\n", type.dump().c_str()); - Components::Logger::Print("SoundFile is %s\n", soundFile.dump().c_str()); - Components::Logger::Error("Failed to parse sound %s! Each alias must have at least a type and a soundFile\n", name.c_str()); + Components::Logger::Print("Type is {}\n", type.dump()); + Components::Logger::Print("SoundFile is {}\n", soundFile.dump()); + Components::Logger::Error(Game::ERR_FATAL, "Failed to parse sound {}! Each alias must have at least a type and a soundFile\n", name); return; } @@ -102,102 +102,102 @@ namespace Assets // TODO: actually support all of those properties if (!CHECK(type, number)) { - Components::Logger::Print("%s is not number but %d (%s)\n", "type", type.type(), type.dump().c_str()); + Components::Logger::Print("{} is not number but {} ({})\n", "type", Utils::Json::TypeToString(type.type()), type.dump()); } if (!CHECK(subtitle, string)) { - Components::Logger::Print("%s is not string but %d (%s)\n", "subtitle", subtitle.type(), subtitle.dump().c_str()); + Components::Logger::Print("{} is not string but {} ({})\n", "subtitle", Utils::Json::TypeToString(subtitle.type()), subtitle.dump()); } if (!CHECK(aliasName, string)) { - Components::Logger::Print("%s is not string but %d (%s)\n", "aliasName", aliasName.type(), aliasName.dump().c_str()); + Components::Logger::Print("{} is not string but {} ({})\n", "aliasName", Utils::Json::TypeToString(aliasName.type()), aliasName.dump()); } if (!CHECK(secondaryAliasName, string)) { - Components::Logger::Print("%s is not string but %d (%s)\n", "secondaryAliasName", secondaryAliasName.type(), secondaryAliasName.dump().c_str()); + Components::Logger::Print("{} is not string but {} ({})\n", "secondaryAliasName", Utils::Json::TypeToString(secondaryAliasName.type()), secondaryAliasName.dump()); } if (!CHECK(chainAliasName, string)) { - Components::Logger::Print("%s is not string but %d (%s)\n", "chainAliasName", chainAliasName.type(), chainAliasName.dump().c_str()); + Components::Logger::Print("{} is not string but {} ({})\n", "chainAliasName", Utils::Json::TypeToString(chainAliasName.type()), chainAliasName.dump()); } if (!CHECK(soundFile, string)) { - Components::Logger::Print("%s is not string but %d (%s)\n", "soundFile", soundFile.type(), soundFile.dump().c_str()); + Components::Logger::Print("{} is not string but {} ({})\n", "soundFile", Utils::Json::TypeToString(soundFile.type()), soundFile.dump()); } if (!CHECK(sequence, number)) { - Components::Logger::Print("%s is not number but %d (%s)\n", "sequence", sequence.type(), sequence.dump().c_str()); + Components::Logger::Print("{} is not number but {} ({})\n", "sequence", Utils::Json::TypeToString(sequence.type()), sequence.dump()); } if (!CHECK(volMin, number)) { - Components::Logger::Print("%s is not number but %d (%s)\n", "volMin", volMin.type(), volMin.dump().c_str()); + Components::Logger::Print("{} is not number but {} ({})\n", "volMin", Utils::Json::TypeToString(volMin.type()), volMin.dump()); } if (!CHECK(volMax, number)) { - Components::Logger::Print("%s is not number but %d (%s)\n", "volMax", volMax.type(), volMax.dump().c_str()); + Components::Logger::Print("{} is not number but {} ({})\n", "volMax", Utils::Json::TypeToString(volMax.type()), volMax.dump()); } if (!CHECK(pitchMin, number)) { - Components::Logger::Print("%s is not number but %d (%s)\n", "pitchMin", pitchMin.type(), pitchMin.dump().c_str()); + Components::Logger::Print("{} is not number but {} ({})\n", "pitchMin", Utils::Json::TypeToString(pitchMin.type()), pitchMin.dump()); } if (!CHECK(pitchMax, number)) { - Components::Logger::Print("%s is not number but %d (%s)\n", "pitchMax", pitchMax.type(), pitchMax.dump().c_str()); + Components::Logger::Print("{} is not number but {} ()\n", "pitchMax", Utils::Json::TypeToString(pitchMax.type()), pitchMax.dump()); } if (!CHECK(probability, number)) { - Components::Logger::Print("%s is not number but %d (%s)\n", "probability", probability.type(), probability.dump().c_str()); + Components::Logger::Print("{} is not number but {} ({}))\n", "probability", Utils::Json::TypeToString(probability.type()), probability.dump()); } if (!CHECK(lfePercentage, number)) { - Components::Logger::Print("%s is not number but %d (%s)\n", "lfePercentage", lfePercentage.type(), lfePercentage.dump().c_str()); + Components::Logger::Print("{} is not number but {} ({})\n", "lfePercentage", Utils::Json::TypeToString(lfePercentage.type()), lfePercentage.dump()); } if (!CHECK(centerPercentage, number)) { - Components::Logger::Print("%s is not number but %d (%s)\n", "centerPercentage", centerPercentage.type(), centerPercentage.dump().c_str()); + Components::Logger::Print("{} is not number but {} ({})\n", "centerPercentage", Utils::Json::TypeToString(centerPercentage.type()), centerPercentage.dump()); } if (!CHECK(startDelay, number)) { - Components::Logger::Print("%s is not number but %d (%s)\n", "startDelay", startDelay.type(), startDelay.dump().c_str()); + Components::Logger::Print("{} is not number but {} ({})\n", "startDelay", Utils::Json::TypeToString(startDelay.type()), startDelay.dump()); } if (!CHECK(volumeFalloffCurve, string)) { - Components::Logger::Print("%s is not string but %d (%s)\n", "volumeFalloffCurve", volumeFalloffCurve.type(), volumeFalloffCurve.dump().c_str()); + Components::Logger::Print("{}s is not string but {} ({})\n", "volumeFalloffCurve", Utils::Json::TypeToString(volumeFalloffCurve.type()), volumeFalloffCurve.dump()); } if (!CHECK(envelopMin, number)) { - Components::Logger::Print("%s is not number but %d (%s)\n", "envelopMin", envelopMin.type(), envelopMin.dump().c_str()); + Components::Logger::Print("{} is not number but {} ({})\n", "envelopMin", Utils::Json::TypeToString(envelopMin.type()), envelopMin.dump()); } if (!CHECK(envelopMax, number)) { - Components::Logger::Print("%s is not number but %d (%s)\n", "envelopMax", envelopMax.type(), envelopMax.dump().c_str()); + Components::Logger::Print("{} is not number but {} ({})\n", "envelopMax", Utils::Json::TypeToString(envelopMax.type()), envelopMax.dump()); } if (!CHECK(envelopPercentage, number)) { - Components::Logger::Print("%s is not number but %d (%s)\n", "envelopPercentage", envelopPercentage.type(), envelopPercentage.dump().c_str()); + Components::Logger::Print("{} is not number but {} ({})\n", "envelopPercentage", Utils::Json::TypeToString(envelopPercentage.type()), envelopPercentage.dump()); } if (!CHECK(speakerMap, object)) { - Components::Logger::Print("%s is not object but %d (%s)\n", "speakerMap", speakerMap.type(), speakerMap.dump().c_str()); + Components::Logger::Print("{} is not object but {} ({})\n", "speakerMap", Utils::Json::TypeToString(speakerMap.type()), speakerMap.dump()); } @@ -248,7 +248,7 @@ namespace Assets alias->speakerMap = builder->getAllocator()->allocate(); if (!alias->speakerMap) { - Components::Logger::Print("Error allocating memory for speakermap in sound alias%s!\n", alias->aliasName); + Components::Logger::Print("Error allocating memory for speakermap in sound alias{}!\n", alias->aliasName); return; } @@ -328,7 +328,7 @@ namespace Assets } else { - Components::Logger::Error("Failed to parse sound %s! Invalid sound type %s\n", name.c_str(), type.string_value().c_str()); + Components::Logger::Error(Game::ERR_FATAL, "Failed to parse sound {}! Invalid sound type {}\n", name, type.string_value()); return; } @@ -336,7 +336,7 @@ namespace Assets } else { - Components::Logger::Error("Failed to parse sound %s!\n", name.c_str()); + Components::Logger::Error(Game::ERR_FATAL, "Failed to parse sound {}!\n", name); return; } } diff --git a/src/Components/Modules/Auth.cpp b/src/Components/Modules/Auth.cpp index 54fd81b2..a3ff5fb1 100644 --- a/src/Components/Modules/Auth.cpp +++ b/src/Components/Modules/Auth.cpp @@ -41,7 +41,7 @@ namespace Components Auth::TokenContainer.generating = false; Auth::StoreKey(); - Logger::Print("Security level is %d\n", Auth::GetSecurityLevel()); + Logger::DebugInfo("Security level is %d", Auth::GetSecurityLevel()); Command::Execute("closemenu security_increase_popmenu", false); if (!Auth::TokenContainer.cancel) @@ -67,14 +67,14 @@ namespace Components Steam::SteamUser()->GetSteamID(); if (!Auth::GuidKey.isValid()) { - Logger::SoftError("Connecting failed: Guid key is invalid!"); + Logger::Error(Game::ERR_SERVERDISCONNECT, "Connecting failed: Guid key is invalid!"); return; } if (std::find(Auth::BannedUids.begin(), Auth::BannedUids.end(), Steam::SteamUser()->GetSteamID().bits) != Auth::BannedUids.end()) { Auth::GenerateKey(); - Logger::SoftError("Your online profile is invalid. A new key has been generated."); + Logger::Error(Game::ERR_SERVERDISCONNECT, "Your online profile is invalid. A new key has been generated."); return; } @@ -86,7 +86,7 @@ namespace Components if (params.size() < 3) { Game::SV_Cmd_EndTokenizedString(); - Logger::SoftError("Connecting failed: Command parsing error!"); + Logger::Error(Game::ERR_SERVERDISCONNECT, "Connecting failed: Command parsing error!"); return; } @@ -96,7 +96,7 @@ namespace Components if (challenge.empty()) { Game::SV_Cmd_EndTokenizedString(); - Logger::SoftError("Connecting failed: Challenge parsing error!"); + Logger::Error(Game::ERR_SERVERDISCONNECT, "Connecting failed: Challenge parsing error!"); return; } @@ -233,7 +233,7 @@ namespace Components return; } - Logger::Print("Verified XUID %llX (%d) from %s\n", xuid, userLevel, address.getCString()); + Logger::DebugInfo("Verified XUID {:#X} ({}) from {}", xuid, userLevel, address.getCString()); Game::SV_DirectConnect(*address.get()); } #endif @@ -448,7 +448,7 @@ namespace Components // Guid command Command::Add("guid", [](Command::Params*) { - Logger::Print("Your guid: %llX\n", Steam::SteamUser()->GetSteamID().bits); + Logger::Print("Your guid: {:#X}\n", Steam::SteamUser()->GetSteamID().bits); }); if (!Dedicated::IsEnabled() && !ZoneBuilder::IsEnabled()) @@ -458,9 +458,9 @@ namespace Components if (params->size() < 2) { uint32_t level = Auth::GetZeroBits(Auth::GuidToken, Auth::GuidKey.getPublicKey()); - Logger::Print("Your current security level is %d\n", level); - Logger::Print("Your security token is: %s\n", Utils::String::DumpHex(Auth::GuidToken.toString(), "").data()); - Logger::Print("Your computation token is: %s\n", Utils::String::DumpHex(Auth::ComputeToken.toString(), "").data()); + Logger::Print("Your current security level is {}\n", level); + Logger::Print("Your security token is: {}\n", Utils::String::DumpHex(Auth::GuidToken.toString(), "")); + Logger::Print("Your computation token is: {}\n", Utils::String::DumpHex(Auth::ComputeToken.toString(), "")); Toast::Show("cardicon_locked", "^5Security Level", Utils::String::VA("Your security level is %d", level), 3000); } diff --git a/src/Components/Modules/Bans.cpp b/src/Components/Modules/Bans.cpp index 27929498..c76054d6 100644 --- a/src/Components/Modules/Bans.cpp +++ b/src/Components/Modules/Bans.cpp @@ -126,7 +126,7 @@ namespace Components if (!error.empty()) { - Logger::Error("Failed to parse bans (bans.json): %s", error.data()); + Logger::Error(Game::ERR_FATAL, "Failed to parse bans (bans.json): {}", error); } if (!list) return; @@ -176,7 +176,7 @@ namespace Components if (*Game::svs_clientCount <= num) { - Logger::Print("Player %d is not on the server\n", num); + Logger::Print("Player {} is not on the server\n", num); return; } @@ -253,7 +253,7 @@ namespace Components Network::Address address(params->get(2)); Bans::UnbanClient(address.getIP()); - Logger::Print("Unbanned IP %s\n", params->get(2)); + Logger::Print("Unbanned IP {}\n", params->get(2)); } else if (type == "guid"s) @@ -263,7 +263,7 @@ namespace Components Bans::UnbanClient(id); - Logger::Print("Unbanned GUID %s\n", params->get(2)); + Logger::Print("Unbanned GUID {}\n", params->get(2)); } }); diff --git a/src/Components/Modules/Bots.cpp b/src/Components/Modules/Bots.cpp index 1158bd1d..8c073bcd 100644 --- a/src/Components/Modules/Bots.cpp +++ b/src/Components/Modules/Bots.cpp @@ -367,8 +367,7 @@ namespace Components if (input == end) { - Logger::Print("Warning: %s is not a valid input\n" - "Usage: %s optional or optional <\"all\">\n", + Logger::Warning(Game::CON_CHANNEL_DONT_FILTER, "{} is not a valid input\nUsage: {} optional or optional <\"all\">\n", input, params->get(0)); return; } @@ -386,7 +385,7 @@ namespace Components } Toast::Show("cardicon_headshot", "^2Success", Utils::String::VA("Spawning %d %s...", count, (count == 1 ? "bot" : "bots")), 3000); - Logger::Print("Spawning %d %s...\n", count, (count == 1 ? "bot" : "bots")); + Logger::DebugInfo("Spawning {} {}", count, (count == 1 ? "bot" : "bots")); Bots::Spawn(count); }); diff --git a/src/Components/Modules/Chat.cpp b/src/Components/Modules/Chat.cpp index f675fdd6..c16c02e6 100644 --- a/src/Components/Modules/Chat.cpp +++ b/src/Components/Modules/Chat.cpp @@ -231,14 +231,14 @@ namespace Components Chat::MuteList.insert(client->steamID); lock.unlock(); - Logger::Print("%s was muted\n", client->name); + Logger::Print("{} was muted\n", client->name); Game::SV_GameSendServerCommand(client->gentity->s.number, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"You were muted\"", 0x65)); return; } lock.unlock(); - Logger::Print("%s is already muted\n", client->name); + Logger::Print("{} is already muted\n", client->name); Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s is already muted\"", 0x65, client->name)); } @@ -247,7 +247,7 @@ namespace Components { Chat::UnmuteInternal(client->steamID); - Logger::Print("%s was unmuted\n", client->name); + Logger::Print("{} was unmuted\n", client->name); Game::SV_GameSendServerCommand(client->gentity->s.number, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"You were unmuted\"", 0x65)); } @@ -275,7 +275,7 @@ namespace Components const auto* cmd = params->get(0); if (params->size() < 2) { - Logger::Print("Usage: %s : prevent the player from using the chat\n", cmd); + Logger::Print("Usage: {} : prevent the player from using the chat\n", cmd); return; } @@ -297,7 +297,7 @@ namespace Components const auto* cmd = params->get(0); if (params->size() < 2) { - Logger::Print("Usage: %s \n%s all = unmute everyone\n", cmd, cmd); + Logger::Print("Usage: {} \n{} all = unmute everyone\n", cmd, cmd); return; } diff --git a/src/Components/Modules/ClientCommand.cpp b/src/Components/Modules/ClientCommand.cpp index 6896bbd9..2963f109 100644 --- a/src/Components/Modules/ClientCommand.cpp +++ b/src/Components/Modules/ClientCommand.cpp @@ -10,14 +10,14 @@ namespace Components if (!Dvar::Var("sv_cheats").get()) { - Logger::Print("CheatsOk: cheats are disabled!\n"); + Logger::DebugInfo("Cheats are disabled!"); Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"GAME_CHEATSNOTENABLED\"", 0x65)); return false; } if (ent->health < 1) { - Logger::Print("CheatsOk: entity %i must be alive to use this command!\n", entNum); + Logger::DebugInfo("Entity {} must be alive to use this command!", entNum); Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"GAME_MUSTBEALIVECOMMAND\"", 0x65)); return false; } @@ -38,7 +38,7 @@ namespace Components if (ent->client == nullptr) { - Logger::Print("ClientCommand: client %d is not fully in game yet\n", clientNum); + Logger::DebugInfo("ClientCommand: client {} is not fully in game yet", clientNum); return; } @@ -64,7 +64,7 @@ namespace Components ent->client->flags ^= Game::PLAYER_FLAG_NOCLIP; const auto entNum = ent->s.number; - Logger::Print("Noclip toggled for entity %i\n", entNum); + Logger::DebugInfo("Noclip toggled for entity {}", entNum); Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x65, (ent->client->flags & Game::PLAYER_FLAG_NOCLIP) ? "GAME_NOCLIPON" : "GAME_NOCLIPOFF")); @@ -78,7 +78,7 @@ namespace Components ent->client->flags ^= Game::PLAYER_FLAG_UFO; const auto entNum = ent->s.number; - Logger::Print("UFO toggled for entity %i\n", entNum); + Logger::DebugInfo("UFO toggled for entity {}", entNum); Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x65, (ent->client->flags & Game::PLAYER_FLAG_UFO) ? "GAME_UFOON" : "GAME_UFOOFF")); @@ -92,7 +92,7 @@ namespace Components ent->flags ^= Game::FL_GODMODE; const auto entNum = ent->s.number; - Logger::Print("God toggled for entity %i\n", entNum); + Logger::DebugInfo("God toggled for entity {}", entNum); Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x65, (ent->flags & Game::FL_GODMODE) ? "GAME_GODMODE_ON" : "GAME_GODMODE_OFF")); @@ -106,7 +106,7 @@ namespace Components ent->flags ^= Game::FL_DEMI_GODMODE; const auto entNum = ent->s.number; - Logger::Print("Demigod toggled for entity %i\n", entNum); + Logger::DebugInfo("Demigod toggled for entity {}", entNum); Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x65, (ent->flags & Game::FL_DEMI_GODMODE) ? "GAME_DEMI_GODMODE_ON" : "GAME_DEMI_GODMODE_OFF")); @@ -120,7 +120,7 @@ namespace Components ent->flags ^= Game::FL_NOTARGET; const auto entNum = ent->s.number; - Logger::Print("Notarget toggled for entity %i\n", entNum); + Logger::DebugInfo("Notarget toggled for entity {}", entNum); Game::SV_GameSendServerCommand(entNum, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x65, (ent->flags & Game::FL_NOTARGET) ? "GAME_NOTARGETON" : "GAME_NOTARGETOFF")); @@ -157,6 +157,8 @@ namespace Components angles[0] = std::strtof(params->get(5), nullptr); // Pitch } + Logger::DebugInfo("Teleported entity {} to {:f} {:f} {:f}\nviewpos {:f} {:f}", ent->s.number, + origin[0], origin[1], origin[2], angles[0], angles[2]); Game::TeleportPlayer(ent, origin, angles); }); } @@ -180,7 +182,7 @@ namespace Components ClientCommand::Add("entitycount", []([[maybe_unused]] Game::gentity_s* ent, [[maybe_unused]] Command::ServerParams* params) { - Logger::Print("Entity count = %i\n", Game::level->num_entities); + Logger::Print("Entity count = {}\n", Game::level->num_entities); }); // Also known as: "vis" @@ -243,7 +245,9 @@ namespace Components ClientCommand::Add("g_testCmd", []([[maybe_unused]] Game::gentity_s* ent, [[maybe_unused]] Command::ServerParams* params) { assert(ent != nullptr); + ent->client->ps.stunTime = 1000 + Game::level->time; // 1000 is the default test stun time + Logger::DebugInfo("playerState_s.stunTime is {}", ent->client->ps.stunTime); }); ClientCommand::Add("kill", []([[maybe_unused]] Game::gentity_s* ent, [[maybe_unused]] Command::ServerParams* params) @@ -277,6 +281,7 @@ namespace Components Game::level->initializing = 1; const auto* weaponName = params->get(1); + Logger::DebugInfo("Giving weapon {} to entity {}", weaponName, ent->s.number); const auto weaponIndex = Game::G_GetWeaponIndexForName(weaponName); if (weaponIndex == 0) @@ -287,8 +292,8 @@ namespace Components if (Game::BG_GetWeaponDef(weaponIndex)->inventoryType == Game::weapInventoryType_t::WEAPINVENTORY_ALTMODE) { - Game::Com_PrintError(Game::CON_CHANNEL_ERROR, - "You can't directly spawn the altfire weapon '%s'. Spawn a weapon that has this altmode instead.\n", weaponName); + Logger::PrintError(Game::CON_CHANNEL_ERROR, + "You can't directly spawn the altfire weapon '{}'. Spawn a weapon that has this altmode instead.\n", weaponName); Game::level->initializing = 0; return; } @@ -310,9 +315,11 @@ namespace Components case Game::OFFHAND_CLASS_FRAG_GRENADE: case Game::OFFHAND_CLASS_THROWINGKNIFE: case Game::OFFHAND_CLASS_OTHER: + Logger::DebugInfo("Setting offhandPrimary"); client->ps.weapCommon.offhandPrimary = offHandClass; break; default: + Logger::DebugInfo("Setting offhandSecondary"); client->ps.weapCommon.offhandSecondary = offHandClass; break; } @@ -324,6 +331,7 @@ namespace Components if (weapEnt->r.isInUse) { + Logger::DebugInfo("Freeing up entity {}", weapEnt->s.number); Game::G_FreeEntity(weapEnt); } diff --git a/src/Components/Modules/Console.cpp b/src/Components/Modules/Console.cpp index 0f2bc7d6..349feb90 100644 --- a/src/Components/Modules/Console.cpp +++ b/src/Components/Modules/Console.cpp @@ -13,8 +13,8 @@ namespace Components int Console::Height = 25; int Console::Width = 80; - char Console::LineBuffer[1024] = { 0 }; - char Console::LineBuffer2[1024] = { 0 }; + char Console::LineBuffer[1024] = {0}; + char Console::LineBuffer2[1024] = {0}; int Console::LineBufferIndex = 0; bool Console::HasConsole = false; @@ -24,7 +24,7 @@ namespace Components Game::SafeArea Console::OriginalSafeArea; - char** Console::GetAutoCompleteFileList(const char *path, const char *extension, Game::FsListBehavior_e behavior, int *numfiles, int allocTrackType) + char** Console::GetAutoCompleteFileList(const char* path, const char* extension, Game::FsListBehavior_e behavior, int* numfiles, int allocTrackType) { if (path == reinterpret_cast(0xBAADF00D) || path == reinterpret_cast(0xCDCDCDCD) || ::Utils::Memory::IsBadReadPtr(path)) return nullptr; return Game::FS_GetFileList(path, extension, behavior, numfiles, allocTrackType); @@ -44,8 +44,8 @@ namespace Components void Console::RefreshStatus() { - std::string mapname = Dvar::Var("mapname").get(); - std::string hostname = TextRenderer::StripColors(Dvar::Var("sv_hostname").get()); + const auto mapname = Dvar::Var("mapname").get(); + const auto hostname = TextRenderer::StripColors(Dvar::Var("sv_hostname").get()); if (Console::HasConsole) { @@ -72,7 +72,7 @@ namespace Components } wclear(Console::InfoWindow); - wprintw(Console::InfoWindow, "%s : %d/%d players : map %s", hostname.data(), clientCount, maxclientCount, (mapname.size() ? mapname.data() : "none")); + wprintw(Console::InfoWindow, "%s : %d/%d players : map %s", hostname.data(), clientCount, maxclientCount, (!mapname.empty()) ? mapname.data() : "none"); wnoutrefresh(Console::InfoWindow); } else if (IsWindow(Console::GetWindow()) != FALSE) @@ -318,17 +318,16 @@ namespace Components Console::RefreshOutput(); } - void Console::Error(const char* format, ...) + void Console::Error(const char* fmt, ...) { - static char buffer[32768]; + char buf[4096] = {0}; va_list va; - va_start(va, format); - _vsnprintf_s(buffer, sizeof(buffer), format, va); + va_start(va, fmt); + _vsnprintf_s(buf, _TRUNCATE, fmt, va); va_end(va); - Game::Com_Printf(0, "ERROR:\n"); - Game::Com_Printf(0, buffer); + Logger::PrintError(Game::CON_CHANNEL_ERROR, "{}", buf); Console::RefreshOutput(); @@ -426,13 +425,13 @@ namespace Components fflush(stdout); } - void Console::StdOutError(const char* format, ...) + void Console::StdOutError(const char* fmt, ...) { - char buffer[0x1000] = { 0 }; + char buffer[4096] = {0}; va_list ap; - va_start(ap, format); - _vsnprintf_s(buffer, sizeof(buffer), format, ap); + va_start(ap, fmt); + _vsnprintf_s(buffer, _TRUNCATE, fmt, ap); va_end(ap); perror(buffer); @@ -520,7 +519,7 @@ namespace Components { "con_outputWindowColor", { 0.25f, 0.25f, 0.25f, 0.85f } }, }; - for (int i = 0; i < ARRAYSIZE(patchedColors); ++i) + for (std::size_t i = 0; i < ARRAYSIZE(patchedColors); ++i) { if (std::strcmp(dvarName, patchedColors[i].name) == 0) { diff --git a/src/Components/Modules/Console.hpp b/src/Components/Modules/Console.hpp index 2ca6eb60..baf414b0 100644 --- a/src/Components/Modules/Console.hpp +++ b/src/Components/Modules/Console.hpp @@ -50,12 +50,12 @@ namespace Components static const char* Input(); static void Print(const char* message); - static void Error(const char* format, ...); + static void Error(const char* fmt, ...); static void Create(); static void Destroy(); static void StdOutPrint(const char* message); - static void StdOutError(const char* format, ...); + static void StdOutError(const char* fmt, ...); static void ConsoleRunner(); diff --git a/src/Components/Modules/D3D9Ex.cpp b/src/Components/Modules/D3D9Ex.cpp index d9222836..2da78542 100644 --- a/src/Components/Modules/D3D9Ex.cpp +++ b/src/Components/Modules/D3D9Ex.cpp @@ -573,7 +573,7 @@ namespace Components // TODO: Fix the actual error! if (IsBadReadPtr(pConstantData, Vector4fCount * 16)) { - //Logger::Print("Invalid shader constant array!\n"); + Logger::DebugInfo("Invalid shader constant array!"); return D3DERR_INVALIDCALL; } diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index 40bd8a4e..00ec8568 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -135,7 +135,7 @@ namespace Components Network::Address master(Utils::String::VA("%s:%u", masterServerName, masterPort)); - Logger::Print(Game::conChannel_t::CON_CHANNEL_SERVER, "Sending heartbeat to master: %s:%u\n", masterServerName, masterPort); + Logger::Print(Game::CON_CHANNEL_SERVER, "Sending heartbeat to master: {}:{}\n", masterServerName, masterPort); Network::SendCommand(master, "heartbeat", "IW4"); } @@ -160,12 +160,12 @@ namespace Components if (!name.empty()) { Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s: %s\"", 104, name.data(), message.data())); - Game::Com_Printf(15, "%s: %s\n", name.data(), message.data()); + Logger::Print(Game::CON_CHANNEL_SERVER, "{}: {}\n", name, message); } else { Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"Console: %s\"", 104, message.data())); - Game::Com_Printf(15, "Console: %s\n", message.data()); + Logger::Print(Game::CON_CHANNEL_SERVER, "Console: {}\n", message); } }); @@ -181,12 +181,12 @@ namespace Components if (!name.empty()) { Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s: %s\"", 104, name.data(), message.data())); - Game::Com_Printf(15, "%s -> %i: %s\n", name.data(), client, message.data()); + Logger::Print(Game::CON_CHANNEL_SERVER, "{} -> {}: {}\n", name, client, message); } else { Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"Console: %s\"", 104, message.data())); - Game::Com_Printf(15, "Console -> %i: %s\n", client, message.data()); + Logger::Print(Game::CON_CHANNEL_SERVER, "Console -> {}: {}\n", client, message); } }); @@ -197,7 +197,7 @@ namespace Components auto message = params->join(1); Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 104, message.data())); - Game::Com_Printf(15, "Raw: %s\n", message.data()); + Logger::Print(Game::CON_CHANNEL_SERVER, "Raw: {}\n", message); }); // Tellraw command @@ -208,7 +208,7 @@ namespace Components const auto client = atoi(params->get(1)); std::string message = params->join(2); Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 104, message.data())); - Game::Com_Printf(15, "Raw -> %i: %s\n", client, message.data()); + Logger::Print(Game::CON_CHANNEL_SERVER, "Raw -> {}: {}\n", client, message); }); } diff --git a/src/Components/Modules/Discovery.cpp b/src/Components/Modules/Discovery.cpp index 69accfde..a97502ea 100644 --- a/src/Components/Modules/Discovery.cpp +++ b/src/Components/Modules/Discovery.cpp @@ -37,7 +37,7 @@ namespace Components unsigned int maxPort = Dvar::Var("net_discoveryPortRangeMax").get(); Network::BroadcastRange(minPort, maxPort, Utils::String::VA("discovery %s", Discovery::Challenge.data())); - Logger::Print("Discovery sent within %dms, awaiting responses...\n", Game::Sys_Milliseconds() - start); + Logger::Print("Discovery sent within {}ms, awaiting responses...\n", Game::Sys_Milliseconds() - start); Discovery::IsPerforming = false; } @@ -52,11 +52,11 @@ namespace Components if (!address.isLocal()) { - Logger::Print("Received discovery request from non-local address: %s\n", address.getCString()); + Logger::Print("Received discovery request from non-local address: {}\n", address.getCString()); return; } - Logger::Print("Received discovery request from %s\n", address.getCString()); + Logger::Print("Received discovery request from {}\n", address.getCString()); Network::SendCommand(address, "discoveryResponse", data); }); @@ -66,17 +66,17 @@ namespace Components if (!address.isLocal()) { - Logger::Print("Received discovery response from non-local address: %s\n", address.getCString()); + Logger::Print("Received discovery response from non-local address: {}\n", address.getCString()); return; } if (Utils::ParseChallenge(data) != Discovery::Challenge) { - Logger::Print("Received discovery with invalid challenge from: %s\n", address.getCString()); + Logger::Print("Received discovery with invalid challenge from: {}\n", address.getCString()); return; } - Logger::Print("Received discovery response from: %s\n", address.getCString()); + Logger::Print("Received discovery response from: {}\n", address.getCString()); if (ServerList::IsOfflineList()) { diff --git a/src/Components/Modules/Download.cpp b/src/Components/Modules/Download.cpp index d6eddceb..a6e93940 100644 --- a/src/Components/Modules/Download.cpp +++ b/src/Components/Modules/Download.cpp @@ -66,7 +66,7 @@ namespace Components if (!error.empty() || !listData.is_array()) { - Logger::Print("Error: %s\n", error.data()); + Logger::Print("Error: {}\n", error); return false; } @@ -201,7 +201,7 @@ namespace Components + (download->isPrivate ? ("?password=" + download->hashedPassword) : ""); } - Logger::Print("Downloading from url %s\n", url.data()); + Logger::Print("Downloading from url {}\n", url); Download::FileDownload fDownload; fDownload.file = file; diff --git a/src/Components/Modules/Dvar.cpp b/src/Components/Modules/Dvar.cpp index 88f6928c..b5af4b30 100644 --- a/src/Components/Modules/Dvar.cpp +++ b/src/Components/Modules/Dvar.cpp @@ -224,7 +224,7 @@ namespace Components std::string saneName = TextRenderer::StripAllTextIcons(TextRenderer::StripColors(Utils::String::Trim(name))); if (saneName.size() < 3 || (saneName[0] == '[' && saneName[1] == '{')) { - Logger::Print("Username '%s' is invalid. It must at least be 3 characters long and not appear empty!\n", name.data()); + Logger::Print("Username '{}' is invalid. It must at least be 3 characters long and not appear empty!\n", name); Dvar::Var("name").set(lastValidName); } else diff --git a/src/Components/Modules/Exception.cpp b/src/Components/Modules/Exception.cpp index a58dfefa..4234b081 100644 --- a/src/Components/Modules/Exception.cpp +++ b/src/Components/Modules/Exception.cpp @@ -203,6 +203,7 @@ namespace Components //Utils::Hook(0x4B241F, Exception::ErrorLongJmp, HOOK_CALL).install()->quick(); Utils::Hook(0x6B8898, Exception::LongJmp, HOOK_JUMP).install()->quick(); +#ifdef _DEBUG Command::Add("mapTest", [](Command::Params* params) { Game::UI_UpdateArenas(); @@ -210,22 +211,16 @@ namespace Components std::string command; for (auto i = 0; i < (params->size() >= 2 ? atoi(params->get(1)) : *Game::arenaCount); ++i) { - const auto* mapname = ArenaLength::NewArenas[i % *Game::arenaCount].mapName; + const auto* mapName = ArenaLength::NewArenas[i % *Game::arenaCount].mapName; if (!(i % 2)) command.append("wait 250;disconnect;wait 750;"); // Test a disconnect else command.append("wait 500;"); // Test direct map switch - command.append(Utils::String::VA("map %s;", mapname)); + command.append(Utils::String::VA("map %s;", mapName)); } Command::Execute(command, false); }); - - Command::Add("debug_exceptionhandler", [](Command::Params*) - { - Logger::Print("Rerunning SetUnhandledExceptionHandler...\n"); - auto oldHandler = Exception::Hook(); - Logger::Print("Old exception handler was 0x%010X.\n", oldHandler); - }); +#endif } Exception::~Exception() diff --git a/src/Components/Modules/FastFiles.cpp b/src/Components/Modules/FastFiles.cpp index 29bc4c66..f728b786 100644 --- a/src/Components/Modules/FastFiles.cpp +++ b/src/Components/Modules/FastFiles.cpp @@ -327,7 +327,7 @@ namespace Components if (*version != XFILE_VERSION) { - Logger::Error("Zone version %d is not supported!", Zones::Version()); + Logger::Error(Game::ERR_FATAL, "Zone version {} is not supported!", Zones::Version()); } } @@ -343,11 +343,11 @@ namespace Components if (header[1] < XFILE_VERSION_IW4X) { - Logger::Error("The fastfile you are trying to load is outdated (%d, expected %d)", header[1], XFILE_VERSION_IW4X); + Logger::Error(Game::ERR_FATAL, "The fastfile you are trying to load is outdated ({}, expected {})", header[1], XFILE_VERSION_IW4X); } else if (header[1] > XFILE_VERSION_IW4X) { - Logger::Error("You are loading a fastfile that is too new (%d, expected %d), update your game or rebuild the fastfile", header[1], XFILE_VERSION_IW4X); + Logger::Error(Game::ERR_FATAL, "You are loading a fastfile that is too new ({}, expected {}), update your game or rebuild the fastfile", header[1], XFILE_VERSION_IW4X); } *reinterpret_cast(header) = XFILE_MAGIC_UNSIGNED; diff --git a/src/Components/Modules/FrameTime.cpp b/src/Components/Modules/FrameTime.cpp index 661ea80b..3ee6570e 100644 --- a/src/Components/Modules/FrameTime.cpp +++ b/src/Components/Modules/FrameTime.cpp @@ -31,7 +31,7 @@ namespace Components if (retval == SOCKET_ERROR) { - Logger::Print("Warning: select() syscall failed: %s\n", Game::NET_ErrorString()); + Logger::Warning(Game::CON_CHANNEL_SYSTEM, "Select() syscall failed: {}\n", Game::NET_ErrorString()); } else if (retval > 0) { diff --git a/src/Components/Modules/Friends.cpp b/src/Components/Modules/Friends.cpp index fc642019..390aee75 100644 --- a/src/Components/Modules/Friends.cpp +++ b/src/Components/Modules/Friends.cpp @@ -591,7 +591,7 @@ namespace Components { if (params->size() < 2u) { - Logger::Print("Usage: %s \n", params->get(0)); + Logger::Print("Usage: {} \n", params->get(0)); return; } diff --git a/src/Components/Modules/Gamepad.cpp b/src/Components/Modules/Gamepad.cpp index 0d725b38..a951bd85 100644 --- a/src/Components/Modules/Gamepad.cpp +++ b/src/Components/Modules/Gamepad.cpp @@ -1390,17 +1390,15 @@ namespace Components GPad_UpdateSticksDown(gamePadIndex); -#ifdef DEBUG if (gpad_debug.get()) { - Logger::Print("Left: X: %f Y: %f\n", lVec[0], lVec[1]); - Logger::Print("Right: X: %f Y: %f\n", rVec[0], rVec[1]); - Logger::Print("Down: %i:%i %i:%i %i:%i %i:%i\n", gamePad.stickDown[0][Game::GPAD_STICK_POS], gamePad.stickDown[0][Game::GPAD_STICK_NEG], - gamePad.stickDown[1][Game::GPAD_STICK_POS], gamePad.stickDown[1][Game::GPAD_STICK_NEG], - gamePad.stickDown[2][Game::GPAD_STICK_POS], gamePad.stickDown[2][Game::GPAD_STICK_NEG], - gamePad.stickDown[3][Game::GPAD_STICK_POS], gamePad.stickDown[3][Game::GPAD_STICK_NEG]); + Logger::Debug("Left: X: {:f} Y: {:f}", lVec[0], lVec[1]); + Logger::Debug("Right: X: {:f} Y: {:f}", rVec[0], rVec[1]); + Logger::Debug("Down: {}:{} {}:{} {}:{} {}:{}", gamePad.stickDown[0][Game::GPAD_STICK_POS], gamePad.stickDown[0][Game::GPAD_STICK_NEG], + gamePad.stickDown[1][Game::GPAD_STICK_POS], gamePad.stickDown[1][Game::GPAD_STICK_NEG], + gamePad.stickDown[2][Game::GPAD_STICK_POS], gamePad.stickDown[2][Game::GPAD_STICK_NEG], + gamePad.stickDown[3][Game::GPAD_STICK_POS], gamePad.stickDown[3][Game::GPAD_STICK_NEG]); } -#endif } void Gamepad::GPad_UpdateDigitals(const int gamePadIndex, const XINPUT_GAMEPAD& state) @@ -1419,12 +1417,10 @@ namespace Components if (std::fabs(gamePad.sticks[2]) > leftDeflect || std::fabs(gamePad.sticks[3]) > rightDeflect) gamePad.digitals &= ~static_cast(XINPUT_GAMEPAD_RIGHT_THUMB); -#ifdef DEBUG if (gpad_debug.get()) { - Logger::Print("Buttons: %x\n", gamePad.digitals); + Logger::Debug("Buttons: {:#x}", gamePad.digitals); } -#endif } void Gamepad::GPad_UpdateAnalogs(const int gamePadIndex, const XINPUT_GAMEPAD& state) @@ -1446,12 +1442,10 @@ namespace Components if (gamePad.analogs[1] < buttonDeadZone) gamePad.analogs[1] = 0.0f; -#ifdef DEBUG if (gpad_debug.get()) { - Logger::Print("Triggers: %f %f\n", gamePad.analogs[0], gamePad.analogs[1]); + Logger::Debug("Triggers: {:f} {:f}", gamePad.analogs[0], gamePad.analogs[1]); } -#endif } void Gamepad::GPad_UpdateAll() @@ -1658,21 +1652,21 @@ namespace Components const Game::GamepadPhysicalAxis physicalAxis = StringToPhysicalAxis(physicalAxisText); if (physicalAxis == Game::GPAD_PHYSAXIS_NONE) { - Logger::Print("\"%s\" isn't a valid physical axis\n", physicalAxisText); + Logger::Print("\"{}\" isn't a valid physical axis\n", physicalAxisText); return; } const Game::GamepadVirtualAxis virtualAxis = StringToVirtualAxis(virtualAxisText); if (virtualAxis == Game::GPAD_VIRTAXIS_NONE) { - Logger::Print("\"%s\" isn't a valid virtual axis\n", virtualAxisText); + Logger::Print("\"{}\" isn't a valid virtual axis\n", virtualAxisText); return; } const Game::GamepadMapping mapping = StringToGamePadMapping(mappingText); if (mapping == Game::GPAD_MAP_NONE) { - Logger::Print("\"%s\" isn't a valid input type\n", mappingText); + Logger::Print("\"{}\" isn't a valid input type\n", mappingText); return; } diff --git a/src/Components/Modules/Logger.cpp b/src/Components/Modules/Logger.cpp index 080b2746..f62f6604 100644 --- a/src/Components/Modules/Logger.cpp +++ b/src/Components/Modules/Logger.cpp @@ -12,79 +12,88 @@ namespace Components return (IsWindow(Console::GetWindow()) != FALSE || (Dedicated::IsEnabled() && !Flags::HasFlag("console"))); } - void Logger::PrintStub(int channel, const char* message, ...) + void Logger::PrintStub(const int channel, const char* message, ...) { - return Logger::MessagePrint(channel, Logger::Format(&message)); + char buf[4096] = {0}; + + va_list va; + va_start(va, message); + _vsnprintf_s(buf, _TRUNCATE, message, va); + va_end(va); + + Logger::MessagePrint(channel, {buf}); } - void Logger::Print(const char* message, ...) - { - return Logger::MessagePrint(0, Logger::Format(&message)); - } - - void Logger::Print(int channel, const char* message, ...) - { - return Logger::MessagePrint(channel, Logger::Format(&message)); - } - - void Logger::MessagePrint(int channel, const std::string& message) + void Logger::MessagePrint(const int channel, const std::string& msg) { if (Flags::HasFlag("stdout") || Loader::IsPerformingUnitTests()) { - printf("%s", message.data()); + printf("%s", msg.data()); fflush(stdout); return; } if (!Logger::IsConsoleReady()) { - OutputDebugStringA(message.data()); + OutputDebugStringA(msg.data()); } if (!Game::Sys_IsMainThread()) { - Logger::EnqueueMessage(message); + Logger::EnqueueMessage(msg); } else { - Game::Com_PrintMessage(channel, message.data(), 0); + Game::Com_PrintMessage(channel, msg.data(), 0); } } - void Logger::ErrorPrint(Game::errorParm_t error, const std::string& message) + void Logger::DebugInternal(const bool verbose, const std::source_location& srcLoc, const std::string_view fmt, std::format_args&& args) { -#ifdef DEBUG + const auto msg = std::vformat(fmt, args); + + const auto out = verbose + ? std::format("Debug:\n {}\nFile: {}\nLine: {}\n", msg, srcLoc.file_name(), srcLoc.line()) + : std::format("Debug:\n {}\n", msg); + + Logger::MessagePrint(Game::CON_CHANNEL_DONT_FILTER, out); + } + + void Logger::PrintInternal(int channel, std::string_view fmt, std::format_args&& args) + { + const auto msg = std::vformat(fmt, args); + + Logger::MessagePrint(channel, msg); + } + + void Logger::ErrorInternal(const Game::errorParm_t error, const std::string_view fmt, std::format_args&& args) + { +#ifdef _DEBUG if (IsDebuggerPresent()) __debugbreak(); #endif - return Game::Com_Error(error, "%s", message.data()); + const auto msg = std::vformat(fmt, args); + Game::Com_Error(error, "%s", msg.data()); } - void Logger::Error(Game::errorParm_t error, const char* message, ...) + void Logger::PrintErrorInternal(int channel, std::string_view fmt, std::format_args&& args) { - return Logger::ErrorPrint(error, Logger::Format(&message)); + const auto msg = "^1Error: " + std::vformat(fmt, args); + + ++(*Game::com_errorPrintsCount); + Logger::MessagePrint(channel, msg); + + if (*Game::cls_uiStarted != 0 && (*Game::com_fixedConsolePosition == 0)) + { + Game::CL_ConsoleFixPosition(); + } } - void Logger::Error(const char* message, ...) + void Logger::WarningInternal(int channel, std::string_view fmt, std::format_args&& args) { - return Logger::ErrorPrint(Game::ERR_FATAL, Logger::Format(&message)); - } + const auto msg = "^3" + std::vformat(fmt, args); - void Logger::SoftError(const char* message, ...) - { - return Logger::ErrorPrint(Game::ERR_SERVERDISCONNECT, Logger::Format(&message)); - } - - std::string Logger::Format(const char** message) - { - char buffer[4096] = {0}; - - va_list ap = reinterpret_cast(const_cast(&message[1])); - - _vsnprintf_s(buffer, _TRUNCATE, *message, ap); - va_end(ap); - - return {buffer}; + Logger::MessagePrint(channel, msg); } void Logger::Flush() @@ -106,9 +115,9 @@ namespace Components { std::lock_guard _(Logger::MessageMutex); - for (unsigned int i = 0; i < Logger::MessageQueue.size(); ++i) + for (std::size_t i = 0; i < Logger::MessageQueue.size(); ++i) { - Game::Com_PrintMessage(0, Logger::MessageQueue[i].data(), 0); + Game::Com_PrintMessage(Game::CON_CHANNEL_DONT_FILTER, Logger::MessageQueue[i].data(), 0); if (!Logger::IsConsoleReady()) { diff --git a/src/Components/Modules/Logger.hpp b/src/Components/Modules/Logger.hpp index a6799b96..4ff9fdd0 100644 --- a/src/Components/Modules/Logger.hpp +++ b/src/Components/Modules/Logger.hpp @@ -7,14 +7,7 @@ namespace Components public: Logger(); ~Logger(); - - 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(Game::errorParm_t error, const std::string& message); - static void Error(const char* message, ...); - static void Error(Game::errorParm_t error, const char* message, ...); - static void SoftError(const char* message, ...); + static bool IsConsoleReady(); static void PrintStub(int channel, const char* message, ...); @@ -23,6 +16,110 @@ namespace Components static void Flush(); + static void MessagePrint(int channel, const std::string& msg); + static void PrintInternal(int channel, std::string_view fmt, std::format_args&& args); + static void ErrorInternal(Game::errorParm_t error, std::string_view fmt, std::format_args&& args); + static void PrintErrorInternal(int channel, std::string_view fmt, std::format_args&& args); + static void WarningInternal(int channel, std::string_view fmt, std::format_args&& args); + static void DebugInternal(bool verbose, const std::source_location& srcLoc, std::string_view fmt, std::format_args&& args); + + static inline void Print(std::string_view fmt) + { + PrintInternal(Game::CON_CHANNEL_DONT_FILTER, fmt, std::make_format_args(0)); + } + + static inline void Print(int channel, std::string_view fmt) + { + PrintInternal(channel, fmt, std::make_format_args(0)); + } + + template + static inline void Print(std::string_view fmt, Args&&... args) + { + PrintInternal(Game::CON_CHANNEL_DONT_FILTER, fmt, std::make_format_args(args...)); + } + + template + static inline void Print(int channel, std::string_view fmt, Args&&... args) + { + PrintInternal(channel, fmt, std::make_format_args(args...)); + } + + static inline void Error(Game::errorParm_t error, std::string_view fmt) + { + ErrorInternal(error, fmt, std::make_format_args(0)); + } + + template + static inline void Error(Game::errorParm_t error, std::string_view fmt, Args&&... args) + { + ErrorInternal(error, fmt, std::make_format_args(args...)); + } + + static inline void Warning(int channel, std::string_view fmt) + { + WarningInternal(channel, fmt, std::make_format_args(0)); + } + + template + static inline void Warning(int channel, std::string_view fmt, Args&&... args) + { + WarningInternal(channel, fmt, std::make_format_args(args...)); + } + + static inline void PrintError(int channel, std::string_view fmt) + { + PrintErrorInternal(channel, fmt, std::make_format_args(0)); + } + + template + static inline void PrintError(int channel, std::string_view fmt, Args&&... args) + { + PrintErrorInternal(channel, fmt, std::make_format_args(args...)); + } + +#ifdef _DEBUG + static inline void DebugInfo([[maybe_unused]] std::string_view fmt) + { + DebugInternal(true, std::source_location::current(), fmt, std::make_format_args(0)); + } + + template + static inline void DebugInfo([[maybe_unused]] std::string_view fmt, [[maybe_unused]] Args&&... args) + { + DebugInternal(true, std::source_location::current(), fmt, std::make_format_args(args...)); + } + + static inline void Debug([[maybe_unused]] std::string_view fmt) + { + DebugInternal(false, std::source_location::current(), fmt, std::make_format_args(0)); + } + + template + static inline void Debug([[maybe_unused]] std::string_view fmt, [[maybe_unused]] Args&&... args) + { + DebugInternal(false, std::source_location::current(), fmt, std::make_format_args(args...)); + } +#else + static inline void DebugInfo([[maybe_unused]] std::string_view fmt) + { + } + + template + static inline void DebugInfo([[maybe_unused]] std::string_view fmt, [[maybe_unused]] Args&&... args) + { + } + + static inline void Debug([[maybe_unused]] std::string_view fmt) + { + } + + template + static inline void Debug([[maybe_unused]] std::string_view fmt, [[maybe_unused]] Args&&... args) + { + } +#endif + private: static std::mutex MessageMutex; static std::vector MessageQueue; @@ -39,7 +136,5 @@ namespace Components static void RedirectOSPath(const char* file, char* folder); static void NetworkLog(const char* data, bool gLog); - - static std::string Format(const char** message); }; } diff --git a/src/Components/Modules/MapDump.cpp b/src/Components/Modules/MapDump.cpp index ba87a6ff..1271b43c 100644 --- a/src/Components/Modules/MapDump.cpp +++ b/src/Components/Modules/MapDump.cpp @@ -13,7 +13,7 @@ namespace Components { if (!this->world_) return; - Logger::Print("Exporting '%s'...\n", this->world_->baseName); + Logger::Print("Exporting '{}'...\n", this->world_->baseName); this->parseVertices(); this->parseFaces(); @@ -471,7 +471,7 @@ namespace Components MapDumper dumper(world); dumper.dump(); - Logger::Print("Map '%s' exported!\n", world->baseName); + Logger::Print("Map '{}' exported!\n", world->baseName); } else { diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index 6ba13f3c..65e40a3d 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -612,8 +612,8 @@ namespace Components { if (error) { - Components::Logger::SoftError("Missing DLC pack %s (%d) containing map %s (%s).\nPlease download it to play this map.", - pack.name.data(), pack.index, Game::UI_LocalizeMapName(mapname), mapname); + Logger::Error(Game::ERR_DISCONNECT, "Missing DLC pack {} ({}) containing map {} ({}).\nPlease download it to play this map.", + pack.name, pack.index, Game::UI_LocalizeMapName(mapname), mapname); } return dlcIsTrue; @@ -621,7 +621,12 @@ namespace Components } } - if (error) Components::Logger::SoftError("Missing map file %s.\nYou may have a damaged installation or are attempting to load a non-existant map.", mapname); + if (error) + { + Logger::Error(Game::ERR_DISCONNECT, + "Missing map file {}.\nYou may have a damaged installation or are attempting to load a non-existent map.", mapname); + } + return false; } diff --git a/src/Components/Modules/ModList.cpp b/src/Components/Modules/ModList.cpp index 955142a9..96d00bd6 100644 --- a/src/Components/Modules/ModList.cpp +++ b/src/Components/Modules/ModList.cpp @@ -43,9 +43,9 @@ namespace Components void ModList::UIScript_LoadMods(UIScript::Token) { auto folder = Dvar::Var("fs_basepath").get() + "\\mods"; - Game::Com_Printf(0, "Searching for mods in %s...\n", folder.data()); + Logger::DebugInfo("Searching for mods in {}...\n", folder); ModList::Mods = FileSystem::GetSysFileList(folder, "", true); - Game::Com_Printf(0, "Found %i mods!\n", ModList::Mods.size()); + Logger::DebugInfo("Found {} mods!\n", ModList::Mods.size()); } void ModList::UIScript_RunMod(UIScript::Token) diff --git a/src/Components/Modules/ModelSurfs.cpp b/src/Components/Modules/ModelSurfs.cpp index 4378068a..40c61812 100644 --- a/src/Components/Modules/ModelSurfs.cpp +++ b/src/Components/Modules/ModelSurfs.cpp @@ -56,18 +56,18 @@ namespace Components } #endif - Logger::Error("Loading model %s failed!", name.data()); + Logger::Error(Game::ERR_FATAL, "Loading model {} failed!", name); } Game::CModelHeader header; if (!model.read(&header, sizeof header)) { - Logger::Error("Reading header for model %s failed!", name.data()); + Logger::Error(Game::ERR_FATAL, "Reading header for model {} failed!", name); } if (header.version != 1) { - Logger::Error("Model %s has an invalid version %d (should be 1)!", name.data(), header.version); + Logger::Error(Game::ERR_FATAL, "Model {} has an invalid version {} (should be 1)!", name, header.version); } // Allocate section buffers @@ -82,7 +82,7 @@ namespace Components model.seek(header.sectionHeader[i].offset, Game::FS_SEEK_SET); if (!model.read(header.sectionHeader[i].buffer, header.sectionHeader[i].size)) { - Logger::Error("Reading section %d for model %s failed!", i, name.data()); + Logger::Error(Game::ERR_FATAL, "Reading section {} for model {} failed!", i, name); } } diff --git a/src/Components/Modules/Network.cpp b/src/Components/Modules/Network.cpp index a0c960a1..b4dbf17a 100644 --- a/src/Components/Modules/Network.cpp +++ b/src/Components/Modules/Network.cpp @@ -266,7 +266,7 @@ namespace Components { if (client->reliableAcknowledge < 0) { - Logger::Print(Game::conChannel_t::CON_CHANNEL_NETWORK, "Negative reliableAcknowledge from %s - cl->reliableSequence is %i, reliableAcknowledge is %i\n", + Logger::Print(Game::conChannel_t::CON_CHANNEL_NETWORK, "Negative reliableAcknowledge from {} - cl->reliableSequence is {}, reliableAcknowledge is {}\n", client->name, client->reliableSequence, client->reliableAcknowledge); client->reliableAcknowledge = client->reliableSequence; Network::SendCommand(Game::NS_SERVER, client->netchan.remoteAddress, "error", "EXE_LOSTRELIABLECOMMANDS"); diff --git a/src/Components/Modules/News.cpp b/src/Components/Modules/News.cpp index a377084e..57791c46 100644 --- a/src/Components/Modules/News.cpp +++ b/src/Components/Modules/News.cpp @@ -13,7 +13,7 @@ namespace Components if (News::Thread.joinable()) { - Logger::Print("Awaiting thread termination...\n"); + Logger::DebugInfo("Awaiting thread termination..."); News::Thread.join(); if (!strcmp(Localization::Get("MPUI_MOTD_TEXT"), NEWS_MOTD_DEFAULT)) @@ -23,7 +23,7 @@ namespace Components } else { - Logger::Print("Successfully fetched motd.\n"); + Logger::DebugInfo("Successfully fetched motd"); } } diff --git a/src/Components/Modules/Node.cpp b/src/Components/Modules/Node.cpp index c76e3cd3..57a1e73b 100644 --- a/src/Components/Modules/Node.cpp +++ b/src/Components/Modules/Node.cpp @@ -41,7 +41,7 @@ namespace Components Session::Send(this->address, "nodeListRequest"); Node::SendList(this->address); - NODE_LOG("Sent request to %s\n", this->address.getCString()); + Logger::DebugInfo("Sent request to {}\n", this->address.getCString()); } void Node::Entry::reset() @@ -235,7 +235,7 @@ namespace Components Proto::Node::List list; if (!list.ParseFromString(data)) return; - NODE_LOG("Received response from %s\n", address.getCString()); + Logger::DebugInfo("Received response from {}\n", address.getCString()); std::lock_guard _(Node::Mutex); @@ -253,12 +253,12 @@ namespace Components { if (!Dedicated::IsEnabled() && ServerList::IsOnlineList() && !ServerList::useMasterServer && list.protocol() == PROTOCOL) { - NODE_LOG("Inserting %s into the serverlist\n", address.getCString()); + Logger::DebugInfo("Inserting {} into the serverlist\n", address.getCString()); ServerList::InsertRequest(address); } else { - NODE_LOG("Dropping serverlist insertion for %s\n", address.getCString()); + Logger::DebugInfo("Dropping serverlist insertion for {}\n", address.getCString()); } for (auto& node : Node::Nodes) @@ -322,7 +322,7 @@ namespace Components { Scheduler::Once([&] { - NODE_LOG("Sending %d nodeListResponse length to %s\n", nodeListData.length(), address.getCString()); + Logger::DebugInfo("Sending {} nodeListResponse length to {}\n", nodeListData.length(), address.getCString()); Session::Send(address, "nodeListResponse", nodeListData); }, Scheduler::Pipeline::MAIN, NODE_SEND_RATE * i++); } @@ -372,12 +372,12 @@ namespace Components Command::Add("listnodes", [](Command::Params*) { - Logger::Print("Nodes: %d\n", Node::Nodes.size()); + Logger::Print("Nodes: {}\n", Node::Nodes.size()); std::lock_guard _(Node::Mutex); for (auto& node : Node::Nodes) { - Logger::Print("%s\t(%s)\n", node.address.getCString(), node.isValid() ? "Valid" : "Invalid"); + Logger::Print("{}\t({})\n", node.address.getCString(), node.isValid() ? "Valid" : "Invalid"); } }); diff --git a/src/Components/Modules/Node.hpp b/src/Components/Modules/Node.hpp index aa7943c3..253cc8d4 100644 --- a/src/Components/Modules/Node.hpp +++ b/src/Components/Modules/Node.hpp @@ -4,12 +4,6 @@ #define NODE_MAX_NODES_TO_SEND 64 #define NODE_SEND_RATE 500ms -#ifdef NODE_LOG_MESSAGES -#define NODE_LOG(x, ...) Logger::Print(x, __VA_ARGS__) -#else -#define NODE_LOG(x, ...) -#endif - namespace Components { class Node : public Component diff --git a/src/Components/Modules/Party.cpp b/src/Components/Modules/Party.cpp index b76a8704..e48791cf 100644 --- a/src/Components/Modules/Party.cpp +++ b/src/Components/Modules/Party.cpp @@ -106,7 +106,7 @@ namespace Components Party::Container.target.setIP(*Game::localIP); Party::Container.target.setType(Game::netadrtype_t::NA_IP); - Logger::Print("Trying to connect to party with loopback address, using a local ip instead: %s\n", Party::Container.target.getCString()); + Logger::Print("Trying to connect to party with loopback address, using a local ip instead: {}\n", Party::Container.target.getCString()); } else { diff --git a/src/Components/Modules/Playlist.cpp b/src/Components/Modules/Playlist.cpp index 9319e212..aca2fd0b 100644 --- a/src/Components/Modules/Playlist.cpp +++ b/src/Components/Modules/Playlist.cpp @@ -26,13 +26,13 @@ namespace Components if (playlist.exists()) { - Logger::Print("Parsing playlist '%s'...\n", playlist.getName().data()); + Logger::Print("Parsing playlist '{}'...\n", playlist.getName()); Game::Playlist_ParsePlaylists(playlist.getBuffer().data()); Utils::Hook::Set(0x1AD3680, true); // Playlist loaded } else { - Logger::Print("Unable to load playlist '%s'!\n", playlist.getName().data()); + Logger::Print("Unable to load playlist '{}'!\n", playlist.getName()); } } diff --git a/src/Components/Modules/QuickPatch.cpp b/src/Components/Modules/QuickPatch.cpp index 4da9797f..6b842af2 100644 --- a/src/Components/Modules/QuickPatch.cpp +++ b/src/Components/Modules/QuickPatch.cpp @@ -741,7 +741,7 @@ namespace Components } auto duration = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - startTime).count(); - Logger::Print("took %llims\n", duration); + Logger::Print("took {}ms\n", duration); printf("Testing ZLib compression..."); diff --git a/src/Components/Modules/RCon.cpp b/src/Components/Modules/RCon.cpp index c3aeab3c..894065be 100644 --- a/src/Components/Modules/RCon.cpp +++ b/src/Components/Modules/RCon.cpp @@ -90,7 +90,7 @@ namespace Components const auto pos = data.find_first_of(' '); if (pos == std::string::npos) { - Logger::Print(Game::CON_CHANNEL_NETWORK, "Invalid RCon request from %s\n", address.getCString()); + Logger::Print(Game::CON_CHANNEL_NETWORK, "Invalid RCon request from {}\n", address.getCString()); return; } @@ -108,7 +108,7 @@ namespace Components if (svPassword.empty()) { - Logger::Print(Game::CON_CHANNEL_NETWORK, "RCon request from %s dropped. No password set!\n", address.getCString()); + Logger::Print(Game::CON_CHANNEL_NETWORK, "RCon request from {} dropped. No password set!\n", address.getCString()); return; } @@ -121,7 +121,7 @@ namespace Components if (RCon::RconLogRequests.get()) #endif { - Logger::Print(Game::CON_CHANNEL_NETWORK, "Executing RCon request from %s: %s\n", address.getCString(), command.data()); + Logger::Print(Game::CON_CHANNEL_NETWORK, "Executing RCon request from {}: {}\n", address.getCString(), command); } Logger::PipeOutput([](const std::string& output) @@ -138,7 +138,7 @@ namespace Components } else { - Logger::Print(Game::CON_CHANNEL_NETWORK, "Invalid RCon password sent from %s\n", address.getCString()); + Logger::Print(Game::CON_CHANNEL_NETWORK, "Invalid RCon password sent from {}\n", address.getCString()); } }); diff --git a/src/Components/Modules/RawFiles.cpp b/src/Components/Modules/RawFiles.cpp index 108da3e0..027ac4fb 100644 --- a/src/Components/Modules/RawFiles.cpp +++ b/src/Components/Modules/RawFiles.cpp @@ -34,7 +34,7 @@ namespace Components if (file.exists()) { Utils::IO::WriteFile("raw/" + file.getName(), file.getBuffer()); - Logger::Print("File '%s' written to raw!\n", file.getName().data()); + Logger::Print("File '{}' written to raw!\n", file.getName()); return; } @@ -43,11 +43,11 @@ namespace Components if (data) { Utils::IO::WriteFile("raw/" + file.getName(), data); - Logger::Print("File '%s' written to raw!\n", file.getName().data()); + Logger::Print("File '{}' written to raw!\n", file.getName()); } else { - Logger::Print("File '%s' does not exist!\n", file.getName().data()); + Logger::Print("File '{}' does not exist!\n", file.getName()); } }); } diff --git a/src/Components/Modules/RawMouse.cpp b/src/Components/Modules/RawMouse.cpp index 2f928d7c..dfd8575a 100644 --- a/src/Components/Modules/RawMouse.cpp +++ b/src/Components/Modules/RawMouse.cpp @@ -111,9 +111,7 @@ namespace Components { if (Window::GetWindow() && RawMouse::M_RawInput.get()) { -#ifdef DEBUG - Logger::Print("Raw Mouse Init.\n"); -#endif + Logger::Debug("Raw Mouse Init"); RAWINPUTDEVICE Rid[1]; Rid[0].usUsagePage = 0x01; // HID_USAGE_PAGE_GENERIC diff --git a/src/Components/Modules/Renderer.cpp b/src/Components/Modules/Renderer.cpp index 8693d474..28feacf3 100644 --- a/src/Components/Modules/Renderer.cpp +++ b/src/Components/Modules/Renderer.cpp @@ -119,7 +119,7 @@ namespace Components void Renderer::R_TextureFromCodeError(const char* sampler, Game::GfxCmdBufState* state) { - Game::Com_Error(Game::ERR_FATAL, "Tried to use sampler '%s' when it isn't valid for material '%s' and technique '%s'", + Logger::Error(Game::ERR_FATAL, "Tried to use sampler '{}' when it isn't valid for material '{}' and technique '{}'", sampler, state->material->info.name, state->technique->name); } @@ -128,25 +128,19 @@ namespace Components __asm { // original code - mov eax, DWORD PTR[eax * 4 + 0066E600Ch]; - - // store GfxCmdBufContext - /*push edx; - mov edx, [esp + 24h]; - mov gfxState, edx; - pop edx;*/ + mov eax, dword ptr [eax * 4 + 0x66E600C] // show error - pushad; - push[esp + 24h + 20h]; - push eax; - call R_TextureFromCodeError; - add esp, 8; - popad; + pushad + push [esp + 0x24 + 0x20] + push eax + call R_TextureFromCodeError + add esp, 8 + popad // go back - push 0x0054CAC1; - retn; + push 0x54CAC1 + retn } } @@ -155,19 +149,19 @@ namespace Components __asm { // original code - mov edx, DWORD PTR[eax * 4 + 0066E600Ch]; + mov edx, dword ptr [eax * 4 + 0x66E600C] // show error - pushad; - push ebx; - push edx; - call R_TextureFromCodeError; - add esp, 8; - popad; + pushad + push ebx + push edx + call R_TextureFromCodeError + add esp, 8 + popad // go back - push 0x0054CFA4; - retn; + push 0x54CFA4 + retn } } @@ -318,8 +312,8 @@ namespace Components scene->sceneDObj[i].cull.bounds.halfSize[1] < 0 || scene->sceneDObj[i].cull.bounds.halfSize[2] < 0) { - - Components::Logger::Print("WARNING: Negative half size for DOBJ %s, this will cause culling issues!", scene->sceneDObj[i].obj->models[0]->name); + Logger::Warning(Game::CON_CHANNEL_DONT_FILTER, "Negative half size for DOBJ {}, this will cause culling issues!", + scene->sceneDObj[i].obj->models[0]->name); } Game::R_AddDebugBounds(dobjsColor, &scene->sceneDObj[i].cull.bounds); diff --git a/src/Components/Modules/Script.cpp b/src/Components/Modules/Script.cpp index 79007579..fdba1d3d 100644 --- a/src/Components/Modules/Script.cpp +++ b/src/Components/Modules/Script.cpp @@ -22,12 +22,12 @@ namespace Components Game::Scr_ShutdownAllocNode(); - Logger::Print(23, "\n"); - Logger::Print(23, "******* script compile error *******\n"); - Logger::Print(23, "Error: unknown function %s in %s\n", funcName, Script::ScriptName.data()); - Logger::Print(23, "************************************\n"); + Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, "\n"); + Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, "******* script compile error *******\n"); + Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, "Error: unknown function {} in {}\n", funcName, Script::ScriptName); + Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, "************************************\n"); - Logger::Error(Game::ERR_SCRIPT_DROP, "script compile error\nunknown function %s\n%s\n\n", funcName, Script::ScriptName.data()); + Logger::Error(Game::ERR_SCRIPT_DROP, "script compile error\nunknown function {}\n{}\n\n", funcName, Script::ScriptName); } __declspec(naked) void Script::StoreFunctionNameStub() @@ -60,11 +60,11 @@ namespace Components // scrVmPub.debugCode seems to be always false if (Game::scrVmPub->debugCode || Game::scrVarPub->developer_script) { - Game::RuntimeErrorInternal(23, codePos, index, msg); + Game::RuntimeErrorInternal(Game::CON_CHANNEL_PARSERSCRIPT, codePos, index, msg); } else { - Logger::Print(23, "%s\n", msg); + Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, "{}\n", msg); } // Let's not throw error unless we have to @@ -73,7 +73,7 @@ namespace Components if (dialogMessage == nullptr) dialogMessage = ""; - Logger::Error(Game::ERR_SCRIPT_DROP, "\x15script runtime error\n(see console for details)\n%s\n%s", msg, dialogMessage); + Logger::Error(Game::ERR_SCRIPT_DROP, "\x15script runtime error\n(see console for details)\n{}\n{}", msg, dialogMessage); } } @@ -168,19 +168,19 @@ namespace Components } } - Logger::Print(23, "in file %s, line %d:", filename, line); - Logger::Print(23, "%s\n", buffer.data() + lineOffset); + Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, "in file {}, line {}:", filename, line); + Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, "{}\n", buffer.substr(lineOffset)); for (auto i = 0; i < (inlineOffset - 1); ++i) { - Logger::Print(23, " "); + Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, " "); } - Logger::Print(23, "*\n"); + Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, "*\n"); } else { - Logger::Print(23, "in file %s, offset %d\n", filename, offset); + Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, "in file {}, offset {}\n", filename, offset); } } @@ -194,38 +194,38 @@ namespace Components Game::Scr_ShutdownAllocNode(); - Logger::Print(23, "\n"); - Logger::Print(23, "******* script compile error *******\n"); - Logger::Print(23, "Error: %s ", msgbuf); + Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, "\n"); + Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, "******* script compile error *******\n"); + Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, "Error: {} ", msgbuf); Script::PrintSourcePos(Script::ScriptName.data(), offset); - Logger::Print(23, "************************************\n\n"); + Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, "************************************\n\n"); - Logger::Error(Game::ERR_SCRIPT_DROP, "script compile error\n%s\n%s\n(see console for actual details)\n", msgbuf, Script::ScriptName.data()); + Logger::Error(Game::ERR_SCRIPT_DROP, "script compile error\n{}\n{}\n(see console for actual details)\n", msgbuf, Script::ScriptName); } int Script::LoadScriptAndLabel(const std::string& script, const std::string& label) { - Logger::Print("Loading script %s.gsc...\n", script.data()); + Logger::Print("Loading script {}.gsc...\n", script); if (!Game::Scr_LoadScript(script.data())) { - Logger::Print("Script %s encountered an error while loading. (doesn't exist?)", script.data()); - Logger::Error(Game::ERR_DROP, reinterpret_cast(0x70B810), script.data()); + Logger::Print("Script {} encountered an error while loading. (doesn't exist?)", script); + Logger::Error(Game::ERR_DROP, "Could not find script '{}'", script); } else { - Logger::Print("Script %s.gsc loaded successfully.\n", script.data()); + Logger::Print("Script {}.gsc loaded successfully.\n", script); } - Logger::Print("Finding script handle %s::%s...\n", script.data(), label.data()); + Logger::DebugInfo("Finding script handle {}::{}...", script.data(), label.data()); const auto handle = Game::Scr_GetFunctionHandle(script.data(), label.data()); if (handle) { - Logger::Print("Script handle %s::%s loaded successfully.\n", script.data(), label.data()); + Logger::Print("Script handle {}::{} loaded successfully.\n", script, label); return handle; } - Logger::Print("Script handle %s::%s couldn't be loaded. (file with no entry point?)\n", script.data(), label.data()); + Logger::Print("Script handle {}::{} couldn't be loaded. (file with no entry point?)\n", script, label); return handle; } @@ -372,8 +372,8 @@ namespace Components if (bestCodePos == -1) return; - Logger::Print(23, "\n@ %d (%d - %d)\n", scriptPos, bestCodePos, nextCodePos); - Logger::Print(23, "in %s (%.1f%% through the source)\n\n", file.data(), ((offset * 100.0f) / (nextCodePos - bestCodePos))); + Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, "\n@ {} ({} - {})\n", scriptPos, bestCodePos, nextCodePos); + Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, "in {} ({} through the source)\n\n", file, ((offset * 100.0f) / (nextCodePos - bestCodePos))); } __declspec(naked) void Script::Scr_PrintPrevCodePosStub() @@ -471,13 +471,13 @@ namespace Components { if (what[0] == '\0' || with[0] == '\0') { - Logger::Print("Warning: Invalid parameters passed to ReplacedFunctions\n"); + Logger::Warning(Game::CON_CHANNEL_SCRIPT, "Invalid parameters passed to ReplacedFunctions\n"); return; } if (Script::ReplacedFunctions.contains(what)) { - Logger::Print("Warning: ReplacedFunctions already contains codePosValue for a function\n"); + Logger::Warning(Game::CON_CHANNEL_SCRIPT, "ReplacedFunctions already contains codePosValue for a function\n"); } Script::ReplacedFunctions[what] = with; @@ -589,9 +589,9 @@ namespace Components // Allow printing to the console even when developer is 0 Script::AddFunction("PrintConsole", [] // gsc: PrintConsole() { - for (auto i = 0u; i < Game::Scr_GetNumParam(); i++) + for (std::size_t i = 0; i < Game::Scr_GetNumParam(); ++i) { - const auto str = Game::Scr_GetString(i); + const auto* str = Game::Scr_GetString(i); if (str == nullptr) { @@ -599,7 +599,7 @@ namespace Components return; } - Logger::Print(Game::level->scriptPrintChannel, "%s", str); + Logger::Print(Game::level->scriptPrintChannel, "{}", str); } }); @@ -731,7 +731,7 @@ namespace Components const auto timeTaken = static_cast((nowMs - Script::LastFrameTime) * timeScale); if (timeTaken >= 500) - Logger::Print(23, "Hitch warning: %i msec frame time\n", timeTaken); + Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, "Hitch warning: {} msec frame time\n", timeTaken); } Script::LastFrameTime = nowMs; diff --git a/src/Components/Modules/Security.cpp b/src/Components/Modules/Security.cpp index f60922a3..8be9579f 100644 --- a/src/Components/Modules/Security.cpp +++ b/src/Components/Modules/Security.cpp @@ -49,7 +49,7 @@ namespace Components // If it's a command don't execute it if (Command::Find(name) != nullptr) { - Logger::Print(0, "CL_SelectStringTableEntryInDvar_f: parameter is a command\n"); + Logger::DebugInfo("CL_SelectStringTableEntryInDvar_f: parameter is a command\n"); return; } @@ -67,7 +67,7 @@ namespace Components // If it's a dvar check that it does not have disallowed flags if ((dvar->flags & disallowedFlags) != 0) { - Logger::Print(0, "CL_SelectStringTableEntryInDvar_f: parameter is a protected dvar\n"); + Logger::DebugInfo("CL_SelectStringTableEntryInDvar_f: parameter is a protected dvar\n"); return; } } @@ -107,6 +107,7 @@ namespace Components if (static_cast(net_message->cursize) >= sizeof(Game::DeferredMsg::data)) { + Logger::DebugInfo("Dropping net_message. Size is {}", net_message->cursize); return; } @@ -132,7 +133,7 @@ namespace Components Utils::Hook::Nop(0x41698E, 5); // Disable Svcmd_EntityList_f // Patch selectStringTableEntryInDvar - Utils::Hook::Set(0x405959, Security::SelectStringTableEntryInDvarStub); + Utils::Hook::Set(0x405959, SelectStringTableEntryInDvarStub); // Patch G_GetClientScore for uninitialized game Utils::Hook(0x469AC0, G_GetClientScore, HOOK_JUMP).install()->quick(); diff --git a/src/Components/Modules/ServerList.cpp b/src/Components/Modules/ServerList.cpp index f235ad02..fed4b403 100644 --- a/src/Components/Modules/ServerList.cpp +++ b/src/Components/Modules/ServerList.cpp @@ -287,7 +287,7 @@ namespace Components Game::netadr_t masterServerAddr; if (!ServerList::GetMasterServer(masterServerName, masterPort, masterServerAddr)) { - Logger::Print("Could not resolve address for %s:%u", masterServerName, masterPort); + Logger::Print("Could not resolve address for {}:{}", masterServerName, masterPort); Toast::Show("cardicon_headshot", "^1Error", Utils::String::VA("Could not resolve address for %s:%u", masterServerName, masterPort), 5000); return; } @@ -659,7 +659,7 @@ namespace Components { ServerList::RefreshContainer.awatingList = false; - Logger::Print("We haven't received a response from the master within %d seconds!\n", (Game::Sys_Milliseconds() - ServerList::RefreshContainer.awaitTime) / 1000); + Logger::Print("We haven't received a response from the master within {} seconds!\n", (Game::Sys_Milliseconds() - ServerList::RefreshContainer.awaitTime) / 1000); Toast::Show("cardicon_headshot", "^1Error", "Failed to reach master server, using node servers instead.", 5000); useMasterServer = false; @@ -823,7 +823,7 @@ namespace Components ServerList::InsertRequest(serverAddr); } - Logger::Print("Parsed %d servers from master\n", ServerList::RefreshContainer.servers.size() - count); + Logger::Print("Parsed {} servers from master\n", ServerList::RefreshContainer.servers.size() - count); }); // Set default masterServerName + port and save it @@ -864,7 +864,7 @@ namespace Components ServerList::SortAsc = true; } - Logger::Print("Sorting server list by token: %d\n", ServerList::SortKey); + Logger::Print("Sorting server list by token: {}\n", ServerList::SortKey); ServerList::SortList(); }); @@ -914,7 +914,7 @@ namespace Components count += server.clients; } - Logger::Print("There are %d players playing.\n", count); + Logger::DebugInfo("There are %d players playing", count); }); #endif // Add required ownerDraws diff --git a/src/Components/Modules/StructuredData.cpp b/src/Components/Modules/StructuredData.cpp index db5a514e..ff938b9f 100644 --- a/src/Components/Modules/StructuredData.cpp +++ b/src/Components/Modules/StructuredData.cpp @@ -53,7 +53,7 @@ namespace Components { value = *i; dataVector.erase(i); - Logger::Print("Playerdatadef entry '%s' will be rebased!\n", value); + Logger::Print("Playerdatadef entry '{}' will be rebased!\n", value); break; } } @@ -182,13 +182,13 @@ namespace Components if (data->defCount != 1) { - Logger::Error("PlayerDataDefSet contains more than 1 definition!"); + Logger::Error(Game::ERR_FATAL, "PlayerDataDefSet contains more than 1 definition!"); return; } if (data->defs[0].version != 155) { - Logger::Error("Initial PlayerDataDef is not version 155, patching not possible!"); + Logger::Error(Game::ERR_FATAL, "Initial PlayerDataDef is not version 155, patching not possible!"); return; } @@ -209,17 +209,17 @@ namespace Components if (!errors.empty()) { - Logger::Error("Parsing patch file '%s' for PlayerDataDef version %d failed: %s", definition.getName().data(), i, errors.data()); + Logger::Error(Game::ERR_FATAL, "Parsing patch file '{}' for PlayerDataDef version {} failed: {}", definition.getName(), i, errors); return; } if (!defData.is_object()) { - Logger::Error("PlayerDataDef patch for version %d is invalid!", i); + Logger::Error(Game::ERR_FATAL, "PlayerDataDef patch for version {} is invalid!", i); return; } - for (unsigned int pType = 0; pType < StructuredData::PlayerDataType::ENUM_MAX; ++pType) + for (std::size_t pType = 0; pType < StructuredData::PlayerDataType::ENUM_MAX; ++pType) { auto enumData = defData[StructuredData::EnumTranslation[pType]]; @@ -293,7 +293,7 @@ namespace Components // Invalid patch data if (patchData.size() != StructuredData::PlayerDataType::ENUM_MAX) { - Logger::Error("PlayerDataDef patch for version %d wasn't parsed correctly!", newData[i].version); + Logger::Error(Game::ERR_FATAL, "PlayerDataDef patch for version {} wasn't parsed correctly!", newData[i].version); continue; } diff --git a/src/Components/Modules/TextRenderer.cpp b/src/Components/Modules/TextRenderer.cpp index 2b7fcbf2..780912ff 100644 --- a/src/Components/Modules/TextRenderer.cpp +++ b/src/Components/Modules/TextRenderer.cpp @@ -762,7 +762,7 @@ namespace Components if(strcmp(material->techniqueSet->name, "2d") != 0) { - Logger::Print("^1Fonticon material '%s' does not have 2d techset!\n", material->info.name); + Logger::Print("^1Fonticon material '{}' does not have 2d techset!\n", material->info.name); material = Game::DB_FindXAssetHeader(Game::ASSET_TYPE_MATERIAL, "default").material; } diff --git a/src/Components/Modules/Theatre.cpp b/src/Components/Modules/Theatre.cpp index 84a95284..4acc40e4 100644 --- a/src/Components/Modules/Theatre.cpp +++ b/src/Components/Modules/Theatre.cpp @@ -223,7 +223,7 @@ namespace Components { Theatre::DemoInfo info = Theatre::Demos[Theatre::CurrentSelection]; - Logger::Print("Deleting demo %s...\n", info.name.data()); + Logger::Print("Deleting demo {}...\n", info.name); FileSystem::DeleteFile("demos", info.name + ".dm_13"); FileSystem::DeleteFile("demos", info.name + ".dm_13.json"); @@ -308,7 +308,7 @@ namespace Components for (int i = 0; i < numDel; ++i) { - Logger::Print("Deleting old demo %s\n", files[i].data()); + Logger::Print("Deleting old demo {}\n", files[i]); FileSystem::DeleteFile("demos", files[i].data()); FileSystem::DeleteFile("demos", Utils::String::VA("%s.json", files[i].data())); } diff --git a/src/Components/Modules/UserInfo.cpp b/src/Components/Modules/UserInfo.cpp index 8670c486..24de7a55 100644 --- a/src/Components/Modules/UserInfo.cpp +++ b/src/Components/Modules/UserInfo.cpp @@ -48,6 +48,12 @@ namespace Components const auto* ent = Game::GetPlayerEntity(entref); const auto* name = Game::Scr_GetString(0); + if (name == nullptr) + { + Game::Scr_ParamError(0, "^1SetName: Illegal parameter!\n"); + } + + Logger::DebugInfo("Setting name of {} to {}", ent->s.number, name); UserInfoOverrides[ent->s.number]["name"] = name; Game::ClientUserinfoChanged(ent->s.number); }); @@ -56,6 +62,7 @@ namespace Components { const auto* ent = Game::GetPlayerEntity(entref); + Logger::DebugInfo("Resetting name of {} ", ent->s.number); UserInfoOverrides[ent->s.number].erase("name"); Game::ClientUserinfoChanged(ent->s.number); }); diff --git a/src/Components/Modules/Weapon.cpp b/src/Components/Modules/Weapon.cpp index 3f57f50a..1b9719a3 100644 --- a/src/Components/Modules/Weapon.cpp +++ b/src/Components/Modules/Weapon.cpp @@ -47,8 +47,7 @@ namespace Components if (input == end) { - Logger::Print("Warning: %s is not a valid input\n" - "Usage: %s \n", + Logger::Warning(Game::CON_CHANNEL_DONT_FILTER, "{} is not a valid input\nUsage: {} \n", input, params.get(0)); return 0; } diff --git a/src/Components/Modules/ZoneBuilder.cpp b/src/Components/Modules/ZoneBuilder.cpp index 9e060357..610122eb 100644 --- a/src/Components/Modules/ZoneBuilder.cpp +++ b/src/Components/Modules/ZoneBuilder.cpp @@ -46,7 +46,7 @@ namespace Components if (!found) { - Logger::Print("Asset %s of type %s was loaded, but not written!", name.data(), Game::DB_GetXAssetTypeName(subAsset.type)); + Logger::Print("Asset {} of type {} was loaded, but not written!", name, Game::DB_GetXAssetTypeName(subAsset.type)); } } @@ -66,7 +66,7 @@ namespace Components if (!found) { - Logger::Error("Asset %s of type %s was written, but not loaded!", name.data(), Game::DB_GetXAssetTypeName(alias.first.type)); + Logger::Error(Game::ERR_FATAL, "Asset {} of type {} was written, but not loaded!", name, Game::DB_GetXAssetTypeName(alias.first.type)); } } #endif @@ -97,7 +97,7 @@ namespace Components { if(!this->dataMap.isValid()) { - Logger::Print("Unable to load CSV for '%s'!\n", this->zoneName.data()); + Logger::Print("Unable to load CSV for '{}'!\n", this->zoneName); return; } @@ -113,7 +113,7 @@ namespace Components if(this->buffer.hasBlock()) { - Logger::Error("Non-popped blocks left!\n"); + Logger::Error(Game::ERR_FATAL, "Non-popped blocks left!\n"); } Logger::Print("Compressing...\n"); @@ -141,7 +141,7 @@ namespace Components } else { - Logger::Print("Zone '%s' already loaded\n", fastfile.data()); + Logger::Print("Zone '{}' already loaded\n", fastfile); } } } @@ -175,7 +175,8 @@ namespace Components } else { - Logger::Error("Unable to rename '%s' to '%s' as the asset type '%s' is invalid!", oldName.data(), newName.data(), typeName.data()); + Logger::Error(Game::ERR_FATAL, "Unable to rename '{}' to '{}' as the asset type '{}' is invalid!", + oldName, newName, typeName); } } } @@ -209,8 +210,11 @@ namespace Components { Game::XAssetType type = Game::DB_GetXAssetNameType(typeName.data()); - if (name.find(" ", 0) != std::string::npos) - Logger::Print("Warning: asset with name '%s' contains spaces. Check your zone source file to ensure this is correct!\n", name.data()); + if (name.find(" ", 0) != std::string::npos) + { + Logger::Warning(Game::CON_CHANNEL_DONT_FILTER, + "Asset with name '{}' contains spaces. Check your zone source file to ensure this is correct!\n", name); + } // Sanitize name for empty assets if (name[0] == ',') name.erase(name.begin()); @@ -219,7 +223,7 @@ namespace Components if (type == Game::XAssetType::ASSET_TYPE_INVALID || type >= Game::XAssetType::ASSET_TYPE_COUNT) { - Logger::Error("Error: Invalid asset type '%s'\n", typeName.data()); + Logger::Error(Game::ERR_FATAL, "Invalid asset type '{}'\n", typeName); return false; } @@ -227,7 +231,7 @@ namespace Components if (!assetHeader.data) { - Logger::Error("Error: Missing asset '%s' of type '%s'\n", name.data(), Game::DB_GetXAssetTypeName(type)); + Logger::Error(Game::ERR_FATAL, "Missing asset '{}' of type '{}'\n", name, Game::DB_GetXAssetTypeName(type)); return false; } @@ -341,12 +345,10 @@ namespace Components asset.header = this->findSubAsset(type, name); if (!asset.header.data) { - Logger::Error("Missing required asset '%s' (%s). Export failed!", name.data(), Game::DB_GetXAssetTypeName(type)); + Logger::Error(Game::ERR_FATAL, "Missing required asset '{}' ({}). Export failed!", name, Game::DB_GetXAssetTypeName(type)); } -#ifdef DEBUG - Components::Logger::Print("Saving require (%s): %s\n", Game::DB_GetXAssetTypeName(type), Game::DB_GetXAssetNameHandlers[type](&header)); -#endif + Logger::DebugInfo("Saving require ({}): {}\n", Game::DB_GetXAssetTypeName(type), Game::DB_GetXAssetNameHandlers[type](&header)); // we alias the next 4 (aligned) bytes of the stream b/c DB_InsertPointer gives us a nice pointer to use as the alias // otherwise it would be a fuckfest trying to figure out where the alias is in the stream @@ -413,7 +415,7 @@ namespace Components } #endif - Utils::IO::WriteFile("uncompressed", zoneBuffer); + Utils::IO::WriteFile("uncompressed", zoneBuffer); zoneBuffer = Utils::Compression::ZLib::Compress(zoneBuffer); outBuffer.append(zoneBuffer); @@ -422,7 +424,8 @@ namespace Components Utils::IO::WriteFile(outFile, outBuffer); Logger::Print("done.\n"); - Logger::Print("Zone '%s' written with %d assets and %d script strings\n", outFile.data(), (this->aliasList.size() + this->loadedAssets.size()), this->scriptStrings.size()); + Logger::Print("Zone '{}' written with {} assets and {} script strings\n", + outFile, (this->aliasList.size() + this->loadedAssets.size()), this->scriptStrings.size()); } void ZoneBuilder::Zone::saveData() @@ -446,10 +449,11 @@ namespace Components // Write ScriptStrings, if available if (!this->scriptStrings.empty()) { - this->buffer.saveNull(4); // Empty script string? - // This actually represents a NULL string, but as scriptString. - // So scriptString loading for NULL scriptStrings from fastfile results in a NULL scriptString. - // That's the reason why the count is incremented by 1, if scriptStrings are available. + this->buffer.saveNull(4); + // Empty script string? + // This actually represents a NULL string, but as scriptString. + // So scriptString loading for NULL scriptStrings from fastfile results in a NULL scriptString. + // That's the reason why the count is incremented by 1, if scriptStrings are available. // Write ScriptString pointer table for (size_t i = 0; i < this->scriptStrings.size(); ++i) @@ -485,9 +489,8 @@ namespace Components this->buffer.pushBlock(Game::XFILE_BLOCK_TEMP); this->buffer.align(Utils::Stream::ALIGN_4); -#ifdef DEBUG - Components::Logger::Print("Saving (%s): %s\n", Game::DB_GetXAssetTypeName(asset.type), Game::DB_GetXAssetNameHandlers[asset.type](&asset.header)); -#endif + Logger::DebugInfo("Saving ({}): {}", + Game::DB_GetXAssetTypeName(asset.type), Game::DB_GetXAssetNameHandlers[asset.type](&asset.header)); this->store(asset.header); AssetHandler::ZoneSave(asset, this); @@ -519,7 +522,7 @@ namespace Components if (this->findAsset(Game::XAssetType::ASSET_TYPE_RAWFILE, this->branding.name) != -1) { - Logger::Error("Unable to add branding. Asset '%s' already exists!", this->branding.name); + Logger::Error(Game::ERR_FATAL, "Unable to add branding. Asset '{}' already exists!", this->branding.name); } Game::XAssetHeader header = { &this->branding }; @@ -635,7 +638,7 @@ namespace Components } else { - Logger::Error("Unable to rename '%s' to '%s' as the asset type is invalid!", asset.data(), newName.data()); + Logger::Error(Game::ERR_FATAL, "Unable to rename '{}' to '{}' as the asset type is invalid!", asset, newName); } } @@ -651,7 +654,7 @@ namespace Components } else { - Logger::Error("Unable to get name for '%s' as the asset type is invalid!", asset.data()); + Logger::Error(Game::ERR_FATAL, "Unable to get name for '{}' as the asset type is invalid!", asset); } return asset; @@ -709,20 +712,20 @@ namespace Components if (zoneIndex > 0) { - Game::XAssetEntry* entry = Game::DB_FindXAssetEntry(type, name.data()); + Game::XAssetEntry* entry = Game::DB_FindXAssetEntry(type, name.data()); - if (entry && entry->zoneIndex == zoneIndex) - { - // Allocate an empty asset (filled with zeros) - header.data = builder->getAllocator()->allocate(Game::DB_GetXAssetSizeHandlers[type]()); + if (entry && entry->zoneIndex == zoneIndex) + { + // Allocate an empty asset (filled with zeros) + header.data = builder->getAllocator()->allocate(Game::DB_GetXAssetSizeHandlers[type]()); - // Set the name to the original name, so it can be stored - Game::DB_SetXAssetNameHandlers[type](&header, name.data()); - AssetHandler::StoreTemporaryAsset(type, header); + // Set the name to the original name, so it can be stored + Game::DB_SetXAssetNameHandlers[type](&header, name.data()); + AssetHandler::StoreTemporaryAsset(type, header); - // Set the name to the empty name - Game::DB_SetXAssetNameHandlers[type](&header, builder->getAllocator()->duplicateString("," + name)); - } + // Set the name to the empty name + Game::DB_SetXAssetNameHandlers[type](&header, builder->getAllocator()->duplicateString("," + name)); + } } } @@ -844,16 +847,11 @@ namespace Components } }); - Command::Add("quit", [](Command::Params*) + Command::Add("quit", []([[maybe_unused]] Command::Params* params) { Game::Com_Quitf_t(); }); - Command::Add("error", [](Command::Params*) - { - Game::Com_Error(Game::ERR_FATAL, "This is a test %s\n", "error"); - }); - // now load default assets and shaders if (FastFiles::Exists("defaults") && FastFiles::Exists("techsets")) { @@ -861,7 +859,8 @@ namespace Components } else { - Logger::Print("Warning: Missing new init zones (defaults.ff & techsets.ff). You will need to load fastfiles to manually obtain techsets.\n"); + Logger::Warning(Game::CON_CHANNEL_DONT_FILTER, + "Missing new init zones (defaults.ff & techsets.ff). You will need to load fastfiles to manually obtain techsets.\n"); Game::DB_LoadXAssets(baseZones_old, ARRAYSIZE(baseZones_old), 0); } @@ -875,10 +874,10 @@ namespace Components // defaults need to load before we do this Utils::Hook::Call(0x4E1F30)(); // G_SetupWeaponDef - Utils::Hook::Call(0x4454C0)(); // Item_SetupKeywordHash (for loading menus) - Utils::Hook::Call(0x501BC0)(); // Menu_SetupKeywordHash (for loading menus) - Utils::Hook::Call(0x4A1280)(); // something related to uiInfoArray - + Utils::Hook::Call(0x4454C0)(); // Item_SetupKeywordHash (for loading menus) + Utils::Hook::Call(0x501BC0)(); // Menu_SetupKeywordHash (for loading menus) + Utils::Hook::Call(0x4A1280)(); // something related to uiInfoArray + Utils::Hook::Call(0x464A90)(GetCommandLineA()); // Com_ParseCommandLine Utils::Hook::Call(0x60C3D0)(); // Com_AddStartupCommands @@ -923,12 +922,13 @@ namespace Components return 0; } - void ZoneBuilder::HandleError(int level, const char* format, ...) + void ZoneBuilder::HandleError(Game::errorParm_t code, const char* fmt, ...) { - char buffer[256] = { 0 }; + char buffer[4096] = {0}; va_list args; - va_start(args, format); - vsnprintf_s(buffer, 256, format, args); + va_start(args, fmt); + _vsnprintf_s(buffer, _TRUNCATE, fmt, args); + va_end(args); if (!Flags::HasFlag("stdout")) { @@ -940,9 +940,10 @@ namespace Components fflush(stderr); } - va_end(args); - - if (!level) ExitProcess(1); + if (code == Game::ERR_FATAL) + { + ExitProcess(1); + } } __declspec(naked) void ZoneBuilder::SoftErrorAssetOverflow() @@ -1084,8 +1085,8 @@ namespace Components // set new entry point Utils::Hook(0x4513DA, ZoneBuilder::EntryPoint, HOOK_JUMP).install()->quick(); - // handle com_error calls - Utils::Hook(0x4B22D0, ZoneBuilder::HandleError, HOOK_JUMP).install()->quick(); + // handle Com_error Calls + Utils::Hook(Game::Com_Error, ZoneBuilder::HandleError, HOOK_JUMP).install()->quick(); // thread fuckery hooks Utils::Hook(0x4C37D0, ZoneBuilder::IsThreadMainThreadHook, HOOK_JUMP).install()->quick(); @@ -1104,29 +1105,30 @@ namespace Components if (!ZoneBuilder::TraceZone.empty() && ZoneBuilder::TraceZone == FastFiles::Current()) { ZoneBuilder::TraceAssets.push_back({ type, name }); - OutputDebugStringA((name + "\n").data()); + OutputDebugStringA((name + "\n").data()); } }); Command::Add("verifyzone", [](Command::Params* params) { if (params->size() < 2) return; - /* - Utils::Hook(0x4AE9C2, [] { - Game::WeaponCompleteDef** varPtr = (Game::WeaponCompleteDef**)0x112A9F4; - Game::WeaponCompleteDef* var = *varPtr; - OutputDebugStringA(""); - Utils::Hook::Call(0x4D1D60)(); // DB_PopStreamPos - }, HOOK_JUMP).install()->quick(); + /* + Utils::Hook(0x4AE9C2, [] + { + Game::WeaponCompleteDef** varPtr = (Game::WeaponCompleteDef**)0x112A9F4; + Game::WeaponCompleteDef* var = *varPtr; + OutputDebugStringA(""); + Utils::Hook::Call(0x4D1D60)(); // DB_PopStreamPos + }, HOOK_JUMP).install()->quick(); - - Utils::Hook(0x4AE9B4, [] { - Game::WeaponCompleteDef** varPtr = (Game::WeaponCompleteDef**)0x112A9F4; - Game::WeaponCompleteDef* var = *varPtr; - OutputDebugStringA(""); - Utils::Hook::Call(0x4D1D60)(); // DB_PopStreamPos - }, HOOK_JUMP).install()->quick(); - */ + Utils::Hook(0x4AE9B4, [] + { + Game::WeaponCompleteDef** varPtr = (Game::WeaponCompleteDef**)0x112A9F4; + Game::WeaponCompleteDef* var = *varPtr; + OutputDebugStringA(""); + Utils::Hook::Call(0x4D1D60)(); // DB_PopStreamPos + }, HOOK_JUMP).install()->quick(); + */ std::string zone = params->get(1); @@ -1137,14 +1139,14 @@ namespace Components info.allocFlags = Game::DB_ZONE_MOD; info.freeFlags = 0; - Logger::Print("Loading zone '%s'...\n", zone.data()); + Logger::Print("Loading zone '{}'...\n", zone); Game::DB_LoadXAssets(&info, 1, true); AssetHandler::FindOriginalAsset(Game::XAssetType::ASSET_TYPE_RAWFILE, zone.data()); // Lock until zone is loaded auto assets = ZoneBuilder::EndAssetTrace(); - Logger::Print("Unloading zone '%s'...\n", zone.data()); + Logger::Print("Unloading zone '{}'...\n", zone); info.freeFlags = Game::DB_ZONE_MOD; info.allocFlags = 0; info.name = nullptr; @@ -1152,12 +1154,12 @@ namespace Components Game::DB_LoadXAssets(&info, 1, true); AssetHandler::FindOriginalAsset(Game::XAssetType::ASSET_TYPE_RAWFILE, "default"); // Lock until zone is unloaded - Logger::Print("Zone '%s' loaded with %d assets:\n", zone.data(), assets.size()); + Logger::Print("Zone '{}' loaded with {} assets:\n", zone, assets.size()); int count = 0; for (auto i = assets.begin(); i != assets.end(); ++i, ++count) { - Logger::Print(" %d: %s: %s\n", count, Game::DB_GetXAssetTypeName(i->first), i->second.data()); + Logger::Print(" {}: {}: {}\n", count, Game::DB_GetXAssetTypeName(i->first), i->second); } Logger::Print("\n"); @@ -1168,7 +1170,7 @@ namespace Components if (params->size() < 2) return; std::string zoneName = params->get(1); - Logger::Print("Building zone '%s'...\n", zoneName.data()); + Logger::Print("Building zone '{}'...\n", zoneName); Zone(zoneName).build(); }); @@ -1219,13 +1221,13 @@ namespace Components if (Utils::IO::FileExists("zone/techsets/" + zone + "_techsets.ff")) { - Logger::Print("Skipping previously generated zone %s\n", zone.data()); + Logger::Print("Skipping previously generated zone {}\n", zone); continue; } if (zone.find("_load") != std::string::npos) { - Logger::Print("Skipping loadscreen zone %s\n", zone.data()); + Logger::Print("Skipping loadscreen zone {}\n", zone); continue; } @@ -1249,7 +1251,7 @@ namespace Components if (curTechsets_list.size() == 0) { - Logger::Print("Skipping empty zone %s\n", zone.data()); + Logger::Print("Skipping empty zone {}\n", zone); // unload zone info.name = nullptr; info.allocFlags = 0x0; @@ -1278,7 +1280,7 @@ namespace Components // build the techset zone std::string zoneName = "techsets/" + zone + "_techsets"; - Logger::Print("Building zone '%s'...\n", zoneName.data()); + Logger::Print("Building zone '{}'...\n", zoneName); Zone(zoneName).build(); // unload original zone @@ -1326,7 +1328,7 @@ namespace Components } else { - Logger::Print("Zone '%s' already loaded\n", it.data()); + Logger::Print("Zone '{}' already loaded\n", it); } if (i == 20) // cap at 20 just to be safe @@ -1351,7 +1353,7 @@ namespace Components Utils::IO::WriteFile(tempZoneFile, csvStr.data()); - Logger::Print("Building zone '%s'...\n", tempZone.data()); + Logger::Print("Building zone '{}'...\n", tempZone); Zone(tempZone).build(); // unload all zones @@ -1382,7 +1384,7 @@ namespace Components std::string mat = ZoneBuilder::FindMaterialByTechnique(tech); if (mat.length() == 0) { - Logger::Print("Couldn't find a material for techset %s. Sort Keys will be incorrect.\n", tech.c_str()); + Logger::Print("Couldn't find a material for techset {}. Sort Keys will be incorrect.\n", tech); csvStr.append("techset," + tech + "\n"); } else @@ -1396,7 +1398,7 @@ namespace Components Utils::IO::WriteFile(tempZoneFile, csvStr.data()); - Logger::Print("Building zone '%s'...\n", tempZone.data()); + Logger::Print("Building zone '{}'...\n", tempZone); Zone(tempZone).build(); // unload all zones @@ -1412,7 +1414,7 @@ namespace Components // build final techsets fastfile if (subCount > 24) { - Logger::ErrorPrint(Game::ERR_DROP, "How did you have 576 fastfiles?\n"); + Logger::Error(Game::ERR_DROP, "How did you have 576 fastfiles?\n"); } curTechsets_list.clear(); @@ -1463,7 +1465,7 @@ namespace Components Game::DB_EnumXAssets(type, [](Game::XAssetHeader header, void* data) { Game::XAsset asset = { *reinterpret_cast(data), header }; - Logger::Print("%s\n", Game::DB_GetXAssetName(&asset)); + Logger::Print("{}\n", Game::DB_GetXAssetName(&asset)); }, &type, false); } }); @@ -1496,7 +1498,8 @@ namespace Components { Game::DB_EnumXAssets(Game::ASSET_TYPE_MATERIAL, [](Game::XAssetHeader header, void*) { - Logger::Print("%s: %X %X %X\n", header.material->info.name, header.material->info.sortKey & 0xFF, header.material->info.gameFlags & 0xFF, header.material->stateFlags & 0xFF); + Logger::Print("{}: {:#X} {:#X} {:#X}\n", + header.material->info.name, header.material->info.sortKey & 0xFF, header.material->info.gameFlags & 0xFF, header.material->stateFlags & 0xFF); }, nullptr, false); }); @@ -1521,7 +1524,7 @@ namespace Components } Logger::Print("------------------- BEGIN IWI DUMP -------------------\n"); - Logger::Print("%s\n", json11::Json(images).dump().data()); + Logger::Print("{}\n", json11::Json(images).dump()); Logger::Print("------------------- END IWI DUMP -------------------\n"); }); diff --git a/src/Components/Modules/ZoneBuilder.hpp b/src/Components/Modules/ZoneBuilder.hpp index 5c647816..1275382f 100644 --- a/src/Components/Modules/ZoneBuilder.hpp +++ b/src/Components/Modules/ZoneBuilder.hpp @@ -139,7 +139,7 @@ namespace Components static std::string FindMaterialByTechnique(const std::string& name); static int __stdcall EntryPoint(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nShowCmd*/); - static void HandleError(int level, const char* format, ...); + static void HandleError(Game::errorParm_t code, const char* fmt, ...); static void SoftErrorAssetOverflow(); static void AssumeMainThreadRole(); diff --git a/src/Components/Modules/Zones.cpp b/src/Components/Modules/Zones.cpp index 24af1db6..bf3de6f7 100644 --- a/src/Components/Modules/Zones.cpp +++ b/src/Components/Modules/Zones.cpp @@ -246,7 +246,7 @@ namespace Components // Check if that special flag is set if (!(surface332.flag & 0x20)) { - Logger::Error("We're not able to handle XSurface buffer allocation yet!"); + Logger::Error(Game::ERR_FATAL, "We're not able to handle XSurface buffer allocation yet!"); } // Copy the correct data back to our surface @@ -3521,7 +3521,7 @@ namespace Components Command::Add("decryptImages", [](Command::Params*) { auto images = Game::Sys_ListFilesWrapper("iw4x/images", "iwi"); - Logger::Print("decrypting %u images...\n", images.size()); + Logger::Print("decrypting {} images...\n", images.size()); for (auto& image : images) { @@ -3549,12 +3549,12 @@ namespace Components } } - Logger::Print("decrypted %u images!\n", images.size()); + Logger::Print("decrypted {} images!\n", images.size()); }); Command::Add("decryptSounds", [](Command::Params*) { auto sounds = Game::Sys_ListFilesWrapper("iw4x/sound", "iwi"); - Logger::Print("decrypting %u sounds...\n", sounds.size()); + Logger::Print("decrypting {} sounds...\n", sounds.size()); for (auto& sound : sounds) { @@ -3580,7 +3580,7 @@ namespace Components } } - Logger::Print("decrypted %u sounds!\n", sounds.size()); + Logger::Print("decrypted {} sounds!\n", sounds.size()); }); // patch max filecount Sys_ListFiles can return diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index b3a3a4ed..5abbd490 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -60,6 +60,7 @@ namespace Game CL_HandleRelayPacket_t CL_HandleRelayPacket = CL_HandleRelayPacket_t(0x5A8C70); CL_ResetViewport_t CL_ResetViewport = CL_ResetViewport_t(0x4A8830); CL_SelectStringTableEntryInDvar_f_t CL_SelectStringTableEntryInDvar_f = CL_SelectStringTableEntryInDvar_f_t(0x4A4560); + CL_ConsoleFixPosition_t CL_ConsoleFixPosition = CL_ConsoleFixPosition_t(0x44A430); Cmd_AddCommand_t Cmd_AddCommand = Cmd_AddCommand_t(0x470090); Cmd_AddServerCommand_t Cmd_AddServerCommand = Cmd_AddServerCommand_t(0x4DCE00); @@ -69,6 +70,7 @@ namespace Game Com_Error_t Com_Error = Com_Error_t(0x4B22D0); Com_Printf_t Com_Printf = Com_Printf_t(0x402500); Com_PrintError_t Com_PrintError = Com_PrintError_t(0x4F8C70); + Com_PrintWarning_t Com_PrintWarning = Com_PrintWarning_t(0x4E0200); Com_PrintMessage_t Com_PrintMessage = Com_PrintMessage_t(0x4AA830); Com_EndParseSession_t Com_EndParseSession = Com_EndParseSession_t(0x4B80B0); Com_BeginParseSession_t Com_BeginParseSession = Com_BeginParseSession_t(0x4AAB80); @@ -77,7 +79,6 @@ namespace Game Com_MatchToken_t Com_MatchToken = Com_MatchToken_t(0x447130); Com_SetSlowMotion_t Com_SetSlowMotion = Com_SetSlowMotion_t(0x446E20); Com_Quitf_t Com_Quit_f = Com_Quitf_t(0x4D4000); - Com_PrintWarning_t Com_PrintWarning = Com_PrintWarning_t(0x4E0200); Con_DrawMiniConsole_t Con_DrawMiniConsole = Con_DrawMiniConsole_t(0x464F30); Con_DrawSolidConsole_t Con_DrawSolidConsole = Con_DrawSolidConsole_t(0x5A5040); @@ -581,6 +582,12 @@ namespace Game unsigned long* _tls_index = reinterpret_cast(0x66D94A8); + int* cls_uiStarted = reinterpret_cast(0xA7FFA0); + + int* com_fixedConsolePosition = reinterpret_cast(0x1AD8EC8); + + int* com_errorPrintsCount = reinterpret_cast(0x1AD7910); + void Sys_LockRead(FastCriticalSection* critSect) { InterlockedIncrement(&critSect->readCount); @@ -868,22 +875,20 @@ namespace Game { return reinterpret_cast(0x6466628); } - else if (Game::Sys_IsRenderThread()) + if (Game::Sys_IsRenderThread()) { return reinterpret_cast(0x646AC34); } - else if (Game::Sys_IsServerThread()) + if (Game::Sys_IsServerThread()) { return reinterpret_cast(0x646F240); } - else if(Game::Sys_IsDatabaseThread()) + if (Game::Sys_IsDatabaseThread()) { return reinterpret_cast(0x647384C); } - else - { - return nullptr; - } + + return nullptr; } void Com_SetParseNegativeNumbers(int parse) diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 67d6aa39..c9c398f7 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -121,6 +121,9 @@ namespace Game typedef void(__cdecl * CL_SelectStringTableEntryInDvar_f_t)(); extern CL_SelectStringTableEntryInDvar_f_t CL_SelectStringTableEntryInDvar_f; + typedef void(__cdecl * CL_ConsoleFixPosition_t)(); + extern CL_ConsoleFixPosition_t CL_ConsoleFixPosition; + typedef void(__cdecl * Cmd_AddCommand_t)(const char* cmdName, void(*function), cmd_function_t* allocedCmd, bool isKey); extern Cmd_AddCommand_t Cmd_AddCommand; @@ -136,13 +139,16 @@ namespace Game typedef void(__cdecl * Com_Error_t)(errorParm_t type, const char* message, ...); extern Com_Error_t Com_Error; - typedef void(__cdecl * Com_Printf_t)(int channel, const char *fmt, ...); + typedef void(__cdecl * Com_Printf_t)(int channel, const char* fmt, ...); extern Com_Printf_t Com_Printf; typedef void(__cdecl * Com_PrintError_t)(int channel, const char* fmt, ...); extern Com_PrintError_t Com_PrintError; - typedef void(__cdecl * Com_PrintMessage_t)(int channel, const char *msg, int error); + typedef void(__cdecl * Com_PrintWarning_t)(int channel, const char* fmt, ...); + extern Com_PrintWarning_t Com_PrintWarning; + + typedef void(__cdecl * Com_PrintMessage_t)(int channel, const char* msg, int error); extern Com_PrintMessage_t Com_PrintMessage; typedef void(__cdecl * Com_EndParseSession_t)(); @@ -166,9 +172,6 @@ namespace Game typedef void(__cdecl * Com_Quitf_t)(); extern Com_Quitf_t Com_Quit_f; - typedef void(__cdecl * Com_PrintWarning_t)(int, const char*, ...); - extern Com_PrintWarning_t Com_PrintWarning; - typedef char* (__cdecl * Con_DrawMiniConsole_t)(int localClientNum, int xPos, int yPos, float alpha); extern Con_DrawMiniConsole_t Con_DrawMiniConsole; @@ -1199,6 +1202,12 @@ namespace Game extern unsigned long* _tls_index; + extern int* cls_uiStarted; + + extern int* com_fixedConsolePosition; + + extern int* com_errorPrintsCount; + void Sys_LockRead(FastCriticalSection* critSect); void Sys_UnlockRead(FastCriticalSection* critSect); diff --git a/src/STDInclude.hpp b/src/STDInclude.hpp index 8b9d29a8..46086ffb 100644 --- a/src/STDInclude.hpp +++ b/src/STDInclude.hpp @@ -19,11 +19,11 @@ #include #include #include -#include +#include #include -#include +#include #include -#include +#include #include #pragma warning(push) @@ -46,6 +46,8 @@ #include #include #include +#include +#include #pragma warning(pop) @@ -124,6 +126,7 @@ using namespace std::literals; #include "Utils/Hooking.hpp" #include "Utils/InfoString.hpp" #include "Utils/IO.hpp" +#include "Utils/Json.hpp" #include "Utils/Library.hpp" #include "Utils/String.hpp" #include "Utils/Thread.hpp" diff --git a/src/Steam/Interfaces/SteamUser.cpp b/src/Steam/Interfaces/SteamUser.cpp index 3e95be40..a61a2e2f 100644 --- a/src/Steam/Interfaces/SteamUser.cpp +++ b/src/Steam/Interfaces/SteamUser.cpp @@ -42,7 +42,6 @@ namespace Steam int User::InitiateGameConnection(void *pAuthBlob, int cbMaxAuthBlob, SteamID steamIDGameServer, unsigned int unIPServer, unsigned short usPortServer, bool bSecure) { - Components::Logger::Print("%s\n", __FUNCTION__); return 0; } diff --git a/src/Utils/Json.cpp b/src/Utils/Json.cpp new file mode 100644 index 00000000..334ad9ef --- /dev/null +++ b/src/Utils/Json.cpp @@ -0,0 +1,25 @@ +#include + +namespace Utils::Json +{ + std::string TypeToString(json11::Json::Type type) + { + switch (type) + { + case json11::Json::NUL: + return "NUL"; + case json11::Json::NUMBER: + return "NUMBER"; + case json11::Json::BOOL: + return "BOOL"; + case json11::Json::STRING: + return "STRING"; + case json11::Json::ARRAY: + return "ARRAY"; + case json11::Json::OBJECT: + return "OBJECT"; + default: + return "NUL"; + } + } +} diff --git a/src/Utils/Json.hpp b/src/Utils/Json.hpp new file mode 100644 index 00000000..0c76fab2 --- /dev/null +++ b/src/Utils/Json.hpp @@ -0,0 +1,6 @@ +#pragma once + +namespace Utils::Json +{ + std::string TypeToString(json11::Json::Type type); +}