Skip to content

fix(registry): prioritize HKEY_CURRENT_USER over HKEY_LOCAL_MACHINE #1844

Open
bobtista wants to merge 3 commits intoTheSuperHackers:mainfrom
bobtista:bobtista/fix-registry-hkcu-priority
Open

fix(registry): prioritize HKEY_CURRENT_USER over HKEY_LOCAL_MACHINE #1844
bobtista wants to merge 3 commits intoTheSuperHackers:mainfrom
bobtista:bobtista/fix-registry-hkcu-priority

Conversation

@bobtista
Copy link

@bobtista bobtista commented Nov 13, 2025

Per-user settings (e.g. HTTP Proxy) should always go in HKEY_CURRENT_USER.

Flips both read and write priority to prefer HKCU over HKLM across all registry helpers, with HKLM as fallback. This prevents stale HKCU values when the game is run with admin privileges.

@bobtista bobtista marked this pull request as ready for review December 3, 2025 18:03
@Skyaero42
Copy link

Imagine the following:

  • I install the game (e.g. through Steam) for windows user1
  • I play the game (key is in CURRENT_USER)
  • I login as user2 in windows
  • I start the game.

could this be an issue, or is there a key generated for user2 as well?

@bobtista
Copy link
Author

Imagine the following:

  • I install the game (e.g. through Steam) for windows user1
  • I play the game (key is in CURRENT_USER)
  • I login as user2 in windows
  • I start the game.

could this be an issue, or is there a key generated for user2 as well?

Ok changed it so:
Reads (HKCU → HKLM): Users can override machine-wide defaults; if no user override exists, fall back to the shared value.
Writes (HKLM → HKCU): Preserves the original behavior—try global first, then per-user if needed.

This is good enough for this issue/change IMHO - Eventually, we should probably have intentional “is this setting global or per-user?” code in the game logic rather than relying on whether the user ran the game as admin or not.


fullPath.append(path);
if (getUnsignedIntFromRegistry(HKEY_LOCAL_MACHINE, fullPath.c_str(), key.c_str(), val))
if (getUnsignedIntFromRegistry(HKEY_CURRENT_USER, fullPath.c_str(), key.c_str(), val))
Copy link

Choose a reason for hiding this comment

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

If I am not mistaken this will be wrong when HKEY_CURRENT_USER var is set to something and game is run with Admin privileges and writing to HKEY_LOCAL_MACHINE. Then it will not update HKEY_CURRENT_USER and its value never changes.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, the write functions (SetStringInRegistry, SetUnsignedIntInRegistry) were still preferring HKLM, so running as admin would write to HKLM while reads would return the stale HKCU value. Fixed by flipping the write priority to also prefer HKCU, matching the read side. So now both SetStringInRegistry and SetUnsignedIntInRegistry to try HKCU first

@xezon xezon added Bug Something is not working right, typically is user facing Minor Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour labels Jan 26, 2026
@greptile-apps
Copy link

greptile-apps bot commented Feb 16, 2026

Greptile Summary

Changed registry access priority to check HKEY_CURRENT_USER before HKEY_LOCAL_MACHINE for both read and write operations, ensuring per-user settings like HTTP Proxy are properly isolated per user rather than using potentially stale machine-wide values.

  • Updated read operations (GetStringFromRegistry, GetUnsignedIntFromRegistry) across all three registry.cpp files to prioritize HKCU
  • Updated write operations (SetStringInRegistry, SetUnsignedIntInRegistry) in WWVegas registry.cpp to prioritize HKCU
  • Added explanatory comments in WWVegas file documenting the change
  • Minor formatting issue: @fix in comments should be wrapped in backticks to prevent platform mention interpretation

Confidence Score: 4/5

  • This PR is safe to merge with only minor formatting issues to address.
  • The logic changes are correct and solve the stated problem of prioritizing per-user registry settings. The implementation is consistent across all three files and properly handles fallback to HKLM when HKCU values are not found. The only issues are minor formatting problems with @ symbols in comments that should be wrapped in backticks.
  • Core/Libraries/Source/WWVegas/WWDownload/registry.cpp needs minor comment formatting fixes for the @fix annotations.

Important Files Changed

Filename Overview
Core/Libraries/Source/WWVegas/WWDownload/registry.cpp Correctly prioritizes HKCU over HKLM for both reads and writes. Minor formatting issue with @ symbols in comments.
Generals/Code/GameEngine/Source/Common/System/registry.cpp Correctly prioritizes HKCU over HKLM for read operations. No write functions present in this file.
GeneralsMD/Code/GameEngine/Source/Common/System/registry.cpp Correctly prioritizes HKCU over HKLM for read operations. No write functions present in this file.

Flowchart

flowchart TD
    A[Registry Read Request] --> B{Check HKEY_CURRENT_USER}
    B -->|Found| C[Return Value]
    B -->|Not Found| D{Check HKEY_LOCAL_MACHINE}
    D -->|Found| C
    D -->|Not Found| E[Return Failure]
    
    F[Registry Write Request] --> G{Try Write to HKEY_CURRENT_USER}
    G -->|Success| H[Return Success]
    G -->|Failure| I{Try Write to HKEY_LOCAL_MACHINE}
    I -->|Success| H
    I -->|Failure| J[Return Failure]
    
    style B fill:#90EE90
    style G fill:#90EE90
    style D fill:#FFB6C1
    style I fill:#FFB6C1
Loading

Last reviewed commit: 4d47837

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

fullPath.append(path);

if (setStringInRegistry( HKEY_LOCAL_MACHINE, fullPath, key, val))
// TheSuperHackers @fix bobtista 12/02/2026 Prefer HKCU for writes to match read priority
Copy link

Choose a reason for hiding this comment

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

Wrap @fix in backticks to prevent platform mention interpretation.

Suggested change
// TheSuperHackers @fix bobtista 12/02/2026 Prefer HKCU for writes to match read priority
// TheSuperHackers `@fix` bobtista 12/02/2026 Prefer HKCU for writes to match read priority

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: Core/Libraries/Source/WWVegas/WWDownload/registry.cpp
Line: 157:157

Comment:
Wrap `@fix` in backticks to prevent platform mention interpretation.

```suggestion
	// TheSuperHackers `@fix` bobtista 12/02/2026 Prefer HKCU for writes to match read priority
```

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

fullPath.append(path);

if (setUnsignedIntInRegistry( HKEY_LOCAL_MACHINE, fullPath, key, val))
// TheSuperHackers @fix bobtista 12/02/2026 Prefer HKCU for writes to match read priority
Copy link

Choose a reason for hiding this comment

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

Wrap @fix in backticks to prevent platform mention interpretation.

Suggested change
// TheSuperHackers @fix bobtista 12/02/2026 Prefer HKCU for writes to match read priority
// TheSuperHackers `@fix` bobtista 12/02/2026 Prefer HKCU for writes to match read priority

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: Core/Libraries/Source/WWVegas/WWDownload/registry.cpp
Line: 173:173

Comment:
Wrap `@fix` in backticks to prevent platform mention interpretation.

```suggestion
	// TheSuperHackers `@fix` bobtista 12/02/2026 Prefer HKCU for writes to match read priority
```

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something is not working right, typically is user facing Gen Relates to Generals Minor Severity: Minor < Major < Critical < Blocker ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GetStringFromRegistry can fail to read from the correct registry location depending on process admin privileges

3 participants