From 87e11a863a19fed3e18c973fef490d55d586d7fb Mon Sep 17 00:00:00 2001 From: hzqst <113660872@qq.com> Date: Tue, 11 Jun 2024 22:24:28 +0800 Subject: [PATCH] 1 --- Plugins/Renderer/gl_local.h | 3 +- Plugins/Renderer/gl_rmisc.cpp | 20 -------- Plugins/Renderer/util.cpp | 38 ++++++++++++++ Plugins/Renderer/util.h | 7 +++ Plugins/ResourceReplacer/ResourceReplacer.cpp | 32 +----------- Plugins/ResourceReplacer/exportfuncs.cpp | 2 - Plugins/ResourceReplacer/privatehook.cpp | 5 +- Plugins/ResourceReplacer/util.cpp | 49 +++++++++++++++++++ Plugins/ResourceReplacer/util.h | 8 +++ 9 files changed, 107 insertions(+), 57 deletions(-) create mode 100644 Plugins/Renderer/util.cpp create mode 100644 Plugins/Renderer/util.h create mode 100644 Plugins/ResourceReplacer/util.cpp create mode 100644 Plugins/ResourceReplacer/util.h diff --git a/Plugins/Renderer/gl_local.h b/Plugins/Renderer/gl_local.h index 50b4d3c8..24d637f4 100644 --- a/Plugins/Renderer/gl_local.h +++ b/Plugins/Renderer/gl_local.h @@ -24,6 +24,7 @@ #include "plugins.h" #include "exportfuncs.h" #include "privatehook.h" +#include "util.h" #include "zone.h" @@ -561,8 +562,6 @@ int EngineGetMaxTempEnts(void); TEMPENTITY *EngineGetTempTentsBase(void); TEMPENTITY *EngineGetTempTentByIndex(int index); -void RemoveFileExtension(std::string& filePath); - float GetFrameRateFromFrameDuration(int frameduration); int _cdecl SDL_GL_SetAttribute(int attr, int value); diff --git a/Plugins/Renderer/gl_rmisc.cpp b/Plugins/Renderer/gl_rmisc.cpp index fdc85461..af78d952 100644 --- a/Plugins/Renderer/gl_rmisc.cpp +++ b/Plugins/Renderer/gl_rmisc.cpp @@ -815,26 +815,6 @@ void GL_FreeFBO(FBO_Container_t* s) GL_ClearFBO(s); } -void RemoveFileExtension(std::string& filePath) -{ - // Find the last occurrence of '.' - size_t lastDotPosition = filePath.find_last_of("."); - - // Check if the dot is part of a directory component rather than an extension - size_t lastPathSeparator = filePath.find_last_of("/\\"); - - if (lastDotPosition != std::string::npos) { - // Ensure the dot is after the last path separator - if (lastPathSeparator != std::string::npos && lastDotPosition < lastPathSeparator) { - return; // Dot is part of a directory name, not an extension - } - // Return the substring from the beginning to the dot - filePath = filePath.substr(0, lastDotPosition); - } - - // No extension found, return the original path -} - float GetFrameRateFromFrameDuration(int frameduration) { if (frameduration > 0) diff --git a/Plugins/Renderer/util.cpp b/Plugins/Renderer/util.cpp new file mode 100644 index 00000000..efb74b8a --- /dev/null +++ b/Plugins/Renderer/util.cpp @@ -0,0 +1,38 @@ +#include "util.h" + +void RemoveFileExtension(std::string& filePath) +{ + // Find the last occurrence of '.' + size_t lastDotPosition = filePath.find_last_of("."); + + // Check if the dot is part of a directory component rather than an extension + size_t lastPathSeparator = filePath.find_last_of("/\\"); + + if (lastDotPosition != std::string::npos) { + // Ensure the dot is after the last path separator + if (lastPathSeparator != std::string::npos && lastDotPosition < lastPathSeparator) { + return; // Dot is part of a directory name, not an extension + } + // Return the substring from the beginning to the dot + filePath = filePath.substr(0, lastDotPosition); + } + + // No extension found, return the original path +} + +void COM_FixSlashes(char* pname) +{ +#ifdef _WIN32 + while (*pname) { + if (*pname == '/') + *pname = '\\'; + pname++; + } +#else + while (*pname) { + if (*pname == '\\') + *pname = '/'; + pname++; + } +#endif +} \ No newline at end of file diff --git a/Plugins/Renderer/util.h b/Plugins/Renderer/util.h new file mode 100644 index 00000000..f0c92775 --- /dev/null +++ b/Plugins/Renderer/util.h @@ -0,0 +1,7 @@ +#pragma once + +#include +#include + +void RemoveFileExtension(std::string& filePath); +void COM_FixSlashes(char* pname); \ No newline at end of file diff --git a/Plugins/ResourceReplacer/ResourceReplacer.cpp b/Plugins/ResourceReplacer/ResourceReplacer.cpp index 9b633007..8c141816 100644 --- a/Plugins/ResourceReplacer/ResourceReplacer.cpp +++ b/Plugins/ResourceReplacer/ResourceReplacer.cpp @@ -6,37 +6,7 @@ #include #include #include "ResourceReplacer.h" - -void RemoveFileExtension(std::string& filePath) -{ - // Find the last occurrence of '.' - size_t lastDotPosition = filePath.find_last_of("."); - - // Check if the dot is part of a directory component rather than an extension - size_t lastPathSeparator = filePath.find_last_of("/\\"); - - if (lastDotPosition != std::string::npos) { - // Ensure the dot is after the last path separator - if (lastPathSeparator != std::string::npos && lastDotPosition < lastPathSeparator) { - return; // Dot is part of a directory name, not an extension - } - // Return the substring from the beginning to the dot - filePath = filePath.substr(0, lastDotPosition); - } - - // No extension found, return the original path -} - -std::string TrimString(const std::string& str) -{ - size_t first = str.find_first_not_of(" \t\n\r\f\v"); - size_t last = str.find_last_not_of(" \t\n\r\f\v"); - - if (first == std::string::npos || last == std::string::npos) - return ""; - - return str.substr(first, (last - first + 1)); -} +#include "util.h" class IResourceReplaceEntry { diff --git a/Plugins/ResourceReplacer/exportfuncs.cpp b/Plugins/ResourceReplacer/exportfuncs.cpp index a58f9d1c..69c9cacd 100644 --- a/Plugins/ResourceReplacer/exportfuncs.cpp +++ b/Plugins/ResourceReplacer/exportfuncs.cpp @@ -11,8 +11,6 @@ engine_studio_api_t IEngineStudio; r_studio_interface_t **gpStudioInterface; IKeyValuesSystem* g_pKeyValuesSystem = NULL; -void RemoveFileExtension(std::string& filePath); - int HUD_VidInit(void) { ModelReplacer()->FreeMapEntries(); diff --git a/Plugins/ResourceReplacer/privatehook.cpp b/Plugins/ResourceReplacer/privatehook.cpp index e5854183..8f48c7c3 100644 --- a/Plugins/ResourceReplacer/privatehook.cpp +++ b/Plugins/ResourceReplacer/privatehook.cpp @@ -2,8 +2,11 @@ #include #include #include + #include "plugins.h" #include "privatehook.h" +#include "util.h" + #include "ResourceReplacer.h" #define S_LOADSOUND_SIG_SVENGINE "\x81\xEC\x2A\x2A\x00\x00\xA1\x2A\x2A\x2A\x2A\x33\xC4\x89\x84\x24\x2A\x2A\x00\x00\x8B\x8C\x24\x2A\x2A\x00\x00\x56\x8B\xB4\x24\x2A\x2A\x00\x00\x8A\x06\x3C\x2A" @@ -18,8 +21,6 @@ static hook_t* g_phook_S_LoadSound_FS_Open = NULL; static hook_t* g_phook_Mod_LoadModel_FS_Open = NULL; static hook_t* g_phook_CL_PrecacheResources = NULL; -void RemoveFileExtension(std::string& filePath); - qboolean CL_PrecacheResources() { if (1) diff --git a/Plugins/ResourceReplacer/util.cpp b/Plugins/ResourceReplacer/util.cpp new file mode 100644 index 00000000..57ba92b7 --- /dev/null +++ b/Plugins/ResourceReplacer/util.cpp @@ -0,0 +1,49 @@ +#include "util.h" + +std::string TrimString(const std::string& str) +{ + size_t first = str.find_first_not_of(" \t\n\r\f\v"); + size_t last = str.find_last_not_of(" \t\n\r\f\v"); + + if (first == std::string::npos || last == std::string::npos) + return ""; + + return str.substr(first, (last - first + 1)); +} + +void RemoveFileExtension(std::string& filePath) +{ + // Find the last occurrence of '.' + size_t lastDotPosition = filePath.find_last_of("."); + + // Check if the dot is part of a directory component rather than an extension + size_t lastPathSeparator = filePath.find_last_of("/\\"); + + if (lastDotPosition != std::string::npos) { + // Ensure the dot is after the last path separator + if (lastPathSeparator != std::string::npos && lastDotPosition < lastPathSeparator) { + return; // Dot is part of a directory name, not an extension + } + // Return the substring from the beginning to the dot + filePath = filePath.substr(0, lastDotPosition); + } + + // No extension found, return the original path +} + +void COM_FixSlashes(char* pname) +{ +#ifdef _WIN32 + while (*pname) { + if (*pname == '/') + *pname = '\\'; + pname++; + } +#else + while (*pname) { + if (*pname == '\\') + *pname = '/'; + pname++; + } +#endif +} \ No newline at end of file diff --git a/Plugins/ResourceReplacer/util.h b/Plugins/ResourceReplacer/util.h new file mode 100644 index 00000000..e811c127 --- /dev/null +++ b/Plugins/ResourceReplacer/util.h @@ -0,0 +1,8 @@ +#pragma once + +#include +#include + +std::string TrimString(const std::string& str); +void RemoveFileExtension(std::string& filePath); +void COM_FixSlashes(char* pname);