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

Patch applier #5

Open
ghost opened this issue Jun 4, 2020 · 1 comment
Open

Patch applier #5

ghost opened this issue Jun 4, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Jun 4, 2020

I don't know if you had intentions to do it or not, but I wrote a simple C# code to replace the engine2 string in hlvr.exe with hlnonvr:

   internal void ApplyNonVRPatch()
    {
        string fullPath = installPath + "\\game\\bin\\win64\\hlvr.exe";
        Dictionary<int, string> strings = new Dictionary<int, string>();

        byte[] byteArray = File.ReadAllBytes(fullPath);

        List<char> chars = new List<char>();
        for (int i = 0; i < byteArray.Length; i++)
        {
            byte b = byteArray[i];

            if (b == 0 && chars.Count > 0)
            {
                string word = new String(chars.ToArray());
                strings.Add(i - word.Length, word);
                chars.Clear();
            }
            else if (b > 0)
                chars.Add(Convert.ToChar(b));
        }

        strings = strings.Where(x => x.Value.Contains("engine2"))
            .ToDictionary(x => x.Key, x => x.Value);

        foreach (KeyValuePair<int, string> kv in strings)
        {
            string value = kv.Value.Replace("engine2", "hlnonvr");
            char[] charArray = value.ToCharArray();
            for (int i = 0; i < charArray.Length; i++)
            {
                byteArray[kv.Key + i] = Convert.ToByte(charArray[i]);
            }
        }

        try
        {
            File.WriteAllBytes(fullPath.Replace("hlvr.exe", "hlnonvr.exe"), byteArray);
            File.Copy(AppDomain.CurrentDomain.BaseDirectory + "/Tools/HLnonVR/hlnonvr.dll", installPath + "\\game\\bin\\win64\\hlnonvr.dll");
        }
        catch (Exception) { }
    }
@ghost
Copy link
Author

ghost commented Jun 4, 2020

It wouldn't actually be "distributing valve code", and it would call out people who are afraid to use a hex editor.

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

No branches or pull requests

0 participants