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

Refactor calculating file hashes #567

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

SadPencil
Copy link
Member

@SadPencil SadPencil commented Oct 4, 2024

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:

    string folderName = @"E:\SteamLibrary";
    string fileName1 = Directory.GetFiles(folderName).First().Dump(); // "E:\SteamLibrary\libraryfolder.vdf"
    string fileName2 = new DirectoryInfo(folderName).EnumerateFiles("*").First().Name.Dump(); // "libraryfolder.vdf"
  • 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

Copy link

github-actions bot commented Oct 4, 2024

Nightly build for this pull request:

@SadPencil SadPencil force-pushed the refactor-file-hash-calculator branch from 7c2709d to 0fd8721 Compare October 4, 2024 10:10
@SadPencil SadPencil added this to the 2.11.2.0 milestone Oct 4, 2024
@Metadorius
Copy link
Member

  • 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.

I am not sure, IIRC they are order-independent?

@SadPencil
Copy link
Member Author

  • 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.

I am not sure, IIRC they are order-independent?

No. They are order-dependent.

fh.INIHashes = AddToStringIfFileExists(fh.INIHashes, filePath);

        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;
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants