Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Jun 11, 2024
1 parent 9177040 commit 87e11a8
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 57 deletions.
3 changes: 1 addition & 2 deletions Plugins/Renderer/gl_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "plugins.h"
#include "exportfuncs.h"
#include "privatehook.h"
#include "util.h"

#include "zone.h"

Expand Down Expand Up @@ -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);
Expand Down
20 changes: 0 additions & 20 deletions Plugins/Renderer/gl_rmisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
38 changes: 38 additions & 0 deletions Plugins/Renderer/util.cpp
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 7 additions & 0 deletions Plugins/Renderer/util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include <stdint.h>
#include <string>

void RemoveFileExtension(std::string& filePath);
void COM_FixSlashes(char* pname);
32 changes: 1 addition & 31 deletions Plugins/ResourceReplacer/ResourceReplacer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,7 @@
#include <regex>
#include <strtools.h>
#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
{
Expand Down
2 changes: 0 additions & 2 deletions Plugins/ResourceReplacer/exportfuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions Plugins/ResourceReplacer/privatehook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
#include <capstone.h>
#include <vector>
#include <set>

#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"
Expand All @@ -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)
Expand Down
49 changes: 49 additions & 0 deletions Plugins/ResourceReplacer/util.cpp
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions Plugins/ResourceReplacer/util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include <stdint.h>
#include <string>

std::string TrimString(const std::string& str);
void RemoveFileExtension(std::string& filePath);
void COM_FixSlashes(char* pname);

0 comments on commit 87e11a8

Please sign in to comment.