-
Notifications
You must be signed in to change notification settings - Fork 39
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
SmileyAG
wants to merge
6
commits into
YaLTeR:master
Choose a base branch
from
SmileyAG:fpr_opt_init_gamedir_once
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2a2ddb9
shared.hpp: enum tables were created to assign IDs to game directories
SmileyAG 4eaf7a1
helper_functions: added com_filebase to get end directory or filename…
SmileyAG faca9d7
helper_functions: added custom function for convert string to lowercase
SmileyAG c3260a2
helper_functions: custom functions were created to assign IDs to game…
SmileyAG 8c3686d
More competent function for one-time initialization of the game direc…
SmileyAG 1ce4b8b
Replace all code that uses the old method for game directory find wit…
SmileyAG File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1157,84 +1157,6 @@ void ClientDLL::StudioAdjustViewmodelAttachments(Vector &vOrigin) | |
vOrigin = last_vieworg + vOut; | ||
} | ||
|
||
void ClientDLL::FileBase(const char *in, char *out) | ||
{ | ||
int len, start, end; | ||
|
||
len = strlen(in); | ||
|
||
// scan backward for '.' | ||
end = len - 1; | ||
while (0 != 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 sting | ||
len = end - start + 1; | ||
|
||
// Copy partial string | ||
strncpy(out, &in[start], len); | ||
// Terminate it | ||
out[len] = 0; | ||
} | ||
|
||
void ClientDLL::ConvertToLowerCase(const char *str) | ||
{ | ||
unsigned char *str_lw = (unsigned char *)str; | ||
while (*str_lw) { | ||
*str_lw = tolower(*str_lw); | ||
str_lw++; | ||
} | ||
} | ||
|
||
bool ClientDLL::DoesGameDirMatch(const char *game) | ||
{ | ||
if (!pEngfuncs) | ||
return false; | ||
|
||
const char *gameDir = pEngfuncs->pfnGetGameDirectory(); | ||
char gd[1024]; | ||
|
||
if (gameDir && gameDir[0]) | ||
{ | ||
FileBase(gameDir, gd); | ||
ConvertToLowerCase(gd); | ||
} | ||
|
||
return !std::strcmp(gd, game); | ||
} | ||
|
||
bool ClientDLL::DoesGameDirContain(const char *game) | ||
{ | ||
if (!pEngfuncs) | ||
return false; | ||
|
||
const char *gameDir = pEngfuncs->pfnGetGameDirectory(); | ||
char gd[1024]; | ||
|
||
if (gameDir && gameDir[0]) | ||
{ | ||
FileBase(gameDir, gd); | ||
ConvertToLowerCase(gd); | ||
} | ||
|
||
return std::strstr(gd, game); | ||
} | ||
|
||
size_t ClientDLL::GetMapName(char* dest, size_t count) | ||
{ | ||
auto map_path = pEngfuncs->pfnGetLevelName(); | ||
|
@@ -1265,7 +1187,7 @@ bool ClientDLL::DoesMapNameMatch(const char *map) | |
GetMapName(map_name, ARRAYSIZE_HL(map_name)); | ||
|
||
if (map_name[0]) | ||
ConvertToLowerCase(map_name); | ||
helper_functions::convert_to_lowercase(map_name); | ||
|
||
return !std::strcmp(map_name, map); | ||
} | ||
|
@@ -1280,9 +1202,9 @@ bool ClientDLL::DoesMapNameContain(const char *map) | |
GetMapName(map_name, ARRAYSIZE_HL(map_name)); | ||
|
||
if (map_name[0]) | ||
ConvertToLowerCase(map_name); | ||
helper_functions::convert_to_lowercase(map_name); | ||
|
||
return std::strstr(map_name, map); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? It's called "DoesMapNameContain" not "DoesMapNameStartWith" |
||
return !std::strncmp(map_name, map, strlen(map)); | ||
} | ||
|
||
void ClientDLL::SetAngleSpeedCap(bool capped) | ||
|
@@ -1861,7 +1783,7 @@ HOOK_DEF_1(ClientDLL, void, __cdecl, CStudioModelRenderer__StudioSetupBones_Linu | |
{ | ||
ptrdiff_t offpCurrentEntity_Linux; | ||
ptrdiff_t offpStudioHeader_Linux; | ||
if (DoesGameDirMatch("dod")) { | ||
if (IsGameDirMatch(MP_DOD)) { | ||
offpCurrentEntity_Linux = 52; | ||
offpStudioHeader_Linux = 72; | ||
} else { | ||
|
@@ -1988,7 +1910,7 @@ HOOK_DEF_1(ClientDLL, void, __fastcall, CStudioModelRenderer__StudioRenderModel, | |
HOOK_DEF_1(ClientDLL, void, __cdecl, CStudioModelRenderer__StudioRenderModel_Linux, void*, thisptr) | ||
{ | ||
ptrdiff_t offpCurrentEntity_Linux; | ||
if (DoesGameDirMatch("dod")) | ||
if (IsGameDirMatch(MP_DOD)) | ||
offpCurrentEntity_Linux = 52; | ||
else | ||
offpCurrentEntity_Linux = 44; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?