Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimization: initialize game directory only once and assign personal ID to it #550

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
45 changes: 45 additions & 0 deletions BunnymodXT/helper_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,49 @@ namespace helper_functions
}
#endif
}

void _com_filebase(const char *in, int &len, int &start)
{
int len, start, end;

len = strlen(in);

// Scan backward for '.'
end = len - 1;
while (end && in[end] != '.' && in[end] != '/' && in[end] != '\\')
end--;

if (in[end] != '.') // No '.', copy to end
end = len - 1;
else
end--; // Found ',', copy to left of '.'

// Scan backward for '/'
start = len - 1;
while (start >= 0 && in[start] != '/' && in[start] != '\\')
start--;

if (in[start] != '/' && in[start] != '\\')
start = 0;
else
start++;

// Length of new string
len = end - start + 1;
}

void com_filebase(const char *in, char *out)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed in regular char form?

{
int len, start;
_com_filebase(in, len, start);
strncpy(out, &in[start], len);
out[len] = 0;
}

void com_filebase(const char *in, std::string &out)
{
int len, start;
_com_filebase(in, len, start);
out = std::string(&in[start], len);
}
};
2 changes: 2 additions & 0 deletions BunnymodXT/helper_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace helper_functions
std::string swap_lib(const char* current_lib_path, std::string new_lib_path, const char *start);
void crash_if_failed(std::string str);
void disable_vsync();
void com_filebase(const char *in, char *out);
void com_filebase(const char *in, std::string &out);

inline void allow_multiple_instances() // Make it possible to run multiple Half-Life instances.
{
Expand Down