Fix CI to use BAT files only for win build.

For consistency have the CI use the same build path as
the end-user builds.

Use where.exe from wine-10.0.

CI's version is a stub. Use one that actually works, until the CI gets
updated.

Also, fix broken RtlGenRandom by importing ADVAPI32's GetUserNameW(),
and calling GetModuleHandleW() / GetProcAddress() for SystemFunction032().
Instead of trying to use a fake import lib.

Bonus: Can now use the host system's username as the default for the
steam user name instead of "Noob".
("Noob" is still used as the fallback if this call fails, or the host
system's username is invalid.)
This commit is contained in:
redpolline 2025-02-04 18:28:11 -05:00
parent abd8300d47
commit 74d22df42e
17 changed files with 926 additions and 317 deletions

View file

@ -19,14 +19,37 @@
#ifdef __WINDOWS__
HMODULE hadvapi32 = NULL;
BOOLEAN (NTAPI *real_RtlGenRandom)(PVOID,ULONG) = NULL;
static void
randombytes(char * const buf, const size_t size)
{
while (!RtlGenRandom((PVOID) buf, (ULONG) size)) {
PRINT_DEBUG("RtlGenRandom ERROR\n");
Sleep(100);
PRINT_DEBUG("%s %p %zu.\n", "mine_RtlGenRandom() called.", buf, size);
if (hadvapi32 == NULL) {
hadvapi32 = GetModuleHandleW(L"advapi32.dll");
if (hadvapi32 == NULL) {
PRINT_DEBUG("%s.\n", "GetModuleHandle() failed for advapi32.dll");
}
PRINT_DEBUG("advapi32.dll handle: 0x%x.\n", hadvapi32);
}
if (hadvapi32 != NULL &&
real_RtlGenRandom == NULL) {
real_RtlGenRandom = (BOOLEAN(NTAPI *)(PVOID,ULONG))GetProcAddress(hadvapi32, "SystemFunction036");
if (real_RtlGenRandom == NULL) {
PRINT_DEBUG("%s.\n", "GetProcAddress() failed for RtlGenRandom()");
}
PRINT_DEBUG("real_RtlGenRandom address: 0x%p.\n", real_RtlGenRandom);
}
if (real_RtlGenRandom != NULL) {
PRINT_DEBUG("%s.\n", "Calling real_RtlGenRandom");
while (!real_RtlGenRandom((PVOID) buf, (ULONG) size)) {
PRINT_DEBUG("RtlGenRandom ERROR\n");
Sleep(100);
}
PRINT_DEBUG("%s.\n", "real_RtlGenRandom returned");
}
return;
}
std::string get_env_variable(std::string name)

View file

@ -1,4 +0,0 @@
#include <windows.h>
#define RtlGenRandom SystemFunction036
#define DLLEXPORT __declspec(dllexport)
DLLEXPORT BOOLEAN WINAPI RtlGenRandom(PVOID in, ULONG len) {}

View file

@ -1,3 +0,0 @@
LIBRARY advapi32.dll
EXPORTS
SystemFunction036

View file

@ -217,9 +217,39 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s
load_custom_broadcasts(Local_Storage::get_game_settings_path() + "custom_master_server.txt", custom_master_server);
// Acount name
char name[32] = {};
char name[32] = { '\0' };
if (local_storage->get_data_settings("account_name.txt", name, sizeof(name) - 1) <= 0) {
strcpy(name, DEFAULT_NAME);
PRINT_DEBUG("%s.\n", "Attempting to set steam user name from system user name");
#if defined(STEAM_WIN32)
DWORD username_dword = 32;
wchar_t username[32] = { '\0' };
if (GetUserNameW((wchar_t*)&username, &username_dword) == TRUE) {
std::wstring username_wstr(username);
std::string username_str = utf8_encode(username_wstr);
size_t username_len = username_str.length();
if (username_len > 0 &&
username_len < 31) {
memcpy(&name, username_str.c_str(), username_len);
name[31] = '\0';
}
}
#else
char * env_username = getenv("USER");
if (env_username != NULL) {
size_t username_len = strlen(env_username);
if (username_len > 0 &&
username_len < 31) {
memcpy(&name, env_username, username_len);
name[31] = '\0';
}
}
#endif
char empty_name[32] = { '\0' };
if (memcmp(name, empty_name, 32) == 0) {
PRINT_DEBUG("%s %s.\n", "Setting steam user name to", DEFAULT_NAME);
strcpy(name, DEFAULT_NAME);
}
PRINT_DEBUG("Username: %s.\n", name);
local_storage->store_data_settings("account_name.txt", name, strlen(name));
}