Skip to content

Commit 6f4d45e

Browse files
Rewrite as minimal pure C registry monitor
Convert from C++ template to a lightweight pure C implementation that monitors the Red Alert 3 CD key registry and fixes the Steam %CDKEY% placeholder issue. The tool uses event-driven registry notifications instead of polling, automatically requests UAC elevation, and generates unique replacement keys using system entropy sources. - Remove C++ template, implement in pure C with no CRT dependency - Use RegNotifyChangeKeyValue for zero-CPU event-driven monitoring - Add automatic UAC elevation via ShellExecuteEx - Generate random keys using performance counters and system time - Optimize build for minimal size (~8KB executable) - Add comprehensive README with usage and technical documentation - Add author credits (Ozan Yasin Dogan, Bodrum/Türkiye) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a19f746 commit 6f4d45e

5 files changed

Lines changed: 462 additions & 31 deletions

File tree

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) [year] [fullname]
3+
Copyright (c) 2025 Ozan Yasin Dogan, Türkiye
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 161 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,161 @@
1-
# Ra3CDKeyFix
1+
# RA3 CD Key Fix
2+
3+
A lightweight Windows utility that automatically fixes the Red Alert 3 CD key registry issue when running the game through Steam.
4+
5+
## The Problem
6+
7+
When **Command & Conquer: Red Alert 3** is installed via Steam, the game's CD key registry value is often set to a placeholder string `%CDKEY%` instead of an actual valid key. This happens because Steam handles CD key distribution differently, and some installations fail to properly populate this value.
8+
9+
The affected registry key is:
10+
```
11+
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Electronic Arts\Electronic Arts\Red Alert 3\ergc
12+
```
13+
14+
This causes issues with:
15+
- Online multiplayer functionality
16+
- Game authentication
17+
- Certain game features that validate the CD key
18+
19+
## The Solution
20+
21+
**RA3 CD Key Fix** monitors this registry key in real-time and automatically replaces the `%CDKEY%` placeholder with a randomly generated unique identifier whenever it's detected. The tool runs in the background and reacts instantly to any changes.
22+
23+
## How It Works
24+
25+
### Event-Driven Registry Monitoring
26+
27+
Unlike polling-based solutions that constantly check the registry at intervals, this tool uses the Windows API function `RegNotifyChangeKeyValue()` to receive notifications only when the registry key actually changes. This approach:
28+
29+
- **Uses zero CPU** while waiting for changes
30+
- **Reacts instantly** when a change occurs
31+
- **Is battery-friendly** for laptop users
32+
33+
### Random Key Generation
34+
35+
When a `%CDKEY%` placeholder is detected, the tool generates a 32-character hexadecimal key using multiple entropy sources:
36+
- High-resolution performance counter (`QueryPerformanceCounter`)
37+
- System uptime (`GetTickCount64`)
38+
- Process and thread IDs
39+
- Current system time with millisecond precision
40+
41+
This ensures each generated key is unique.
42+
43+
### Automatic UAC Elevation
44+
45+
The tool automatically requests administrator privileges when launched. If you run it without elevation, it will prompt for admin rights via the Windows UAC dialog.
46+
47+
## Why Administrator Privileges?
48+
49+
The CD key is stored under `HKEY_LOCAL_MACHINE` (HKLM), which is a system-wide registry hive. Windows protects this area to prevent unauthorized software from making system-wide changes.
50+
51+
To read from and write to this location, the application must run with elevated (administrator) privileges. This is a Windows security requirement, not a limitation of the tool.
52+
53+
**The tool only accesses the specific Red Alert 3 registry key** - it does not modify any other system settings.
54+
55+
## Usage
56+
57+
1. Download `Ra3CDKeyFix.exe` from the [Releases](../../releases) page
58+
2. Run the executable
59+
3. Accept the UAC prompt when asked for administrator privileges
60+
4. Launch Red Alert 3 from Steam
61+
5. Once the game starts, you can close the tool (press `Ctrl+C`)
62+
63+
**Note:** Steam sets the `%CDKEY%` placeholder only when the game launches. The tool detects and fixes this immediately, so you don't need to keep it running throughout your gaming session - just during game startup.
64+
65+
### Output Example
66+
67+
```
68+
RA3 CD Key Fix - Registry Monitor
69+
==================================
70+
Author: Ozan Yasin Dogan, Bodrum/Türkiye
71+
72+
Monitoring: HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Electronic Arts\Electronic Arts\Red Alert 3\ergc
73+
Press Ctrl+C to exit.
74+
75+
[14:32:15] Started monitoring registry key.
76+
[14:32:15] Current CD Key: %CDKEY%
77+
[14:32:15] Replaced with: A7F3B2E19C4D8A6F0E5B7C2D9A1F4E8B
78+
[14:35:42] Registry change detected.
79+
[14:35:42] Current CD Key: A7F3B2E19C4D8A6F0E5B7C2D9A1F4E8B
80+
```
81+
82+
## Building from Source
83+
84+
### Requirements
85+
86+
- Windows 10 or later
87+
- Visual Studio 2022 with "Desktop development with C++" workload
88+
89+
### Build Steps
90+
91+
1. Clone the repository
92+
2. Open `Ra3CDKeyFix.slnx` in Visual Studio 2022
93+
3. Select **Release | x64** configuration
94+
4. Build the solution (F7 or Build → Build Solution)
95+
96+
The output executable will be approximately **8 KB** in size.
97+
98+
### Build Characteristics
99+
100+
The release build is optimized for minimal size:
101+
- Pure C code (no C++ runtime)
102+
- No C Runtime Library (CRT) dependency
103+
- Direct Win32 API calls only
104+
- Custom entry point (`WinMainCRTStartup`)
105+
- Optimized for size (`/O1 /Os`)
106+
107+
Dependencies are limited to core Windows libraries:
108+
- `kernel32.lib` - Core Windows functions
109+
- `advapi32.lib` - Registry functions
110+
- `shell32.lib` - Shell execution (for UAC elevation)
111+
112+
## Technical Details
113+
114+
| Property | Value |
115+
|----------|-------|
116+
| Language | C (C17) |
117+
| Target Platform | Windows x64 |
118+
| Binary Size | ~8 KB |
119+
| External Dependencies | None (Windows APIs only) |
120+
| Monitoring Method | Event-driven (`RegNotifyChangeKeyValue`) |
121+
| Privileges Required | Administrator |
122+
123+
## Frequently Asked Questions
124+
125+
### Is this safe to use?
126+
127+
Yes. The tool only monitors and modifies a single registry key specific to Red Alert 3. The source code is open and available for review.
128+
129+
### Will this affect my Steam installation?
130+
131+
No. The tool only fixes the CD key value when it contains the placeholder. It doesn't interfere with Steam or the game files.
132+
133+
### Do I need to run this every time I play?
134+
135+
Yes, run it before launching the game each time. Steam resets the CD key to `%CDKEY%` every time you start Red Alert 3. Simply launch the tool, start the game from Steam, and you can close the tool once the game is running.
136+
137+
### Can I run this at Windows startup?
138+
139+
You can, but it's not necessary. Since the fix only takes a second, it's easier to just run it before launching the game. If you prefer to have it always running, you can use Task Scheduler with "Run with highest privileges" option to avoid the UAC prompt.
140+
141+
### The tool says "Registry key not found"
142+
143+
This means Red Alert 3 is not installed, or the registry structure is different on your system. The game must be installed for the registry key to exist.
144+
145+
## Author
146+
147+
**Ozan Yasin Dogan**
148+
Bodrum, Türkiye
149+
150+
## License
151+
152+
This project is licensed under the MIT License - see the [LICENSE.txt](LICENSE.txt) file for details.
153+
154+
## Contributing
155+
156+
Contributions are welcome! Feel free to submit issues and pull requests.
157+
158+
## Acknowledgments
159+
160+
- Electronic Arts for Command & Conquer: Red Alert 3
161+
- The C&C community for keeping these classic games alive

0 commit comments

Comments
 (0)