Skip to content

Latest commit

 

History

History
37 lines (32 loc) · 1.12 KB

README.md

File metadata and controls

37 lines (32 loc) · 1.12 KB

How the AuthCode works in Champions of Regnum

// 1. check if auth code exists
HKEY hKey;
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\NGD Studios\\RegnumOnline", 0, KEY_READ, &hKey) == 0) {
    if (RegQueryValueExA(hKey, "AuthCode", 0, &type, (LPBYTE)data, &cbData) == 0) {
        // if it was found then it will use it
    }
    RegCloseKey(hKey);
}

// if not found check HKCU
if (!found) {
    RegOpenKeyExA(HKEY_CURRENT_USER, "SOFTWARE\\NGD Studios\\RegnumOnline", ...);
    RegQueryValueExA(hKey, "AuthCode", ...);
}

// if still not found it will generate a new code
if (!found) {
    srand(time(0));  // seed with current Unix time (seconds)
    
    for (int i = 0; i < 32; i++) {
        int type = rand() % 3;  // 0, 1, or 2
        if (type == 0) {
            code[i] = rand() % 26 + 'A';  // uppercase letters A-Z
        } else if (type == 1) {
            code[i] = rand() % 26 + 'a';  // lowercase letters a-z
        } else {
            code[i] = rand() % 10 + '0';  // digits from 0-9
        }
    }
    
    // saves to registry
    RegSetValueExA(hKey, "AuthCode", 0, REG_BINARY, (BYTE*)code_unicode, 64);
}