-
-
Notifications
You must be signed in to change notification settings - Fork 94
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
Refactor calculating file hashes #567
Refactor calculating file hashes #567
Conversation
Nightly build for this pull request:
|
7c2709d
to
0fd8721
Compare
I am not sure, IIRC they are order-independent? |
No. They are order-dependent.
fh.INIHashes = AddToStringIfFileExists(fh.INIHashes, filePath);
string AddToStringIfFileExists(string str, string path)
{
if (File.Exists(path))
return str + Utilities.CalculateSHA1ForFile(SafePath.CombineFilePath(ProgramConstants.GamePath, path));
return str;
} |
private const string CONFIGNAME = "FHCConfig.ini"; | ||
private bool calculateGameExeHash = true; | ||
|
||
string[] fileNamesToCheck = new string[] | ||
private static readonly IReadOnlyList<string> knownTextFileExtensions = [".txt", ".ini", ".json", ".xml"]; |
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.
I am not sure if this is a robust impl, what do we risking if a used text file is not included here?
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.
This design is mostly for preventing an honest-but-curious user viewing a text file bundled with a mod, and their text editor (probably with an auto saving, or one could accidentally hit Ctrl+S even if they think they haven't change any single character) might save that file with the line breaks normalized (they might be non-consistent due to, e.g., collaboration in Git).
If a text file does not have the known extensions here, the behavior should be similar with the one as if this PR is not merged, i.e., be treated as a binary file.
This PR reworks the file hash calculator to:
Fix a bug introduced in .NET 6 Cross platform #341 (codes here, diff here), where all files in "Map Code" and "Game Options" folders are not included. This bug should be a threat for anti-cheating detection.
TLDR: the bug is introduced because:
Fix a potential bug introduced in implementing multi-language support. Files in
ClientConfiguration.Instance.TranslationGameFiles.Where(tgf => tgf.Checked)
(these files should be checked) are not sorted, leaving the file order as uncertain, especially in cross-platform scenarios. Now, all enumerated files will be sorted with path separators normalized.For known text file extensions like
.ini
, when computing hashes, the client will try to normalize the difference between Windows (\r\n
in the end of every line except for the last) and UNIX (\n
in the end of every line).Remove redundancy parameter in
CalculateHashes(List<GameMode> gameModes)
that has been unused since 801bee2