Code:
unsigned int hash(unsigned char* inpStr, size_t len)
{
unsigned int value = 0,temp = 0;
for(size_t i=0;i<len;i++)
{
temp = inpStr[i];
temp += value;
value = temp << 10;
temp += value;
value = temp >> 6;
value ^= temp;
}
temp = value << 3;
temp += value;
unsigned int temp2 = temp >> 11;
temp = temp2 ^ temp;
temp2 = temp << 15;
value = temp2 + temp;
if(value < 2) value += 2;
return value;
}
Microsoft::Win32::RegistryKey^ GetNetworkRegistryKey(String^ id) {
try
{
Microsoft::Win32::RegistryKey^ networkInterfaceKey = Microsoft::Win32::Registry::LocalMachine->OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}", false);
cli::array<String^>^ keyNames = networkInterfaceKey->GetSubKeyNames();
for each (String^ keyName in keyNames) {
Microsoft::Win32::RegistryKey^ key = networkInterfaceKey->OpenSubKey(keyName);
String^ value = (String^)key->GetValue("NetCfgInstanceId", "");
if (value == id) {
return key;
}
}
return nullptr;
}
catch (System::Security::SecurityException^)
{
return nullptr;
}
}
String^ GetDeviceIDForDriverKey(String^ key)
{
int index = 0;
char buffer[1024];
String^ deviceID = "";
SP_DEVINFO_DATA data;
memset(&data, 0, sizeof(data));
data.cbSize = sizeof(data);
HDEVINFO handle = SetupDiGetClassDevs(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT);
while (SetupDiEnumDeviceInfo(handle, index, &data))
{
index++;
if (SetupDiGetDeviceRegistryPropertyA(handle, &data, SPDRP_DRIVER, NULL, (PBYTE)buffer, sizeof(buffer), NULL))
{
String^ key2 = gcnew String(buffer);
if (key->Replace("HKEY_LOCAL_MACHINE\\", "")->ToLower() == key2->ToLower())
{
if (SetupDiGetDeviceRegistryPropertyA(handle, &data, SPDRP_HARDWAREID, NULL, (PBYTE)buffer, sizeof(buffer), NULL))
{
deviceID = gcnew String(buffer);
}
}
}
}
int err = GetLastError();
if (handle)
{
SetupDiDestroyDeviceInfoList(handle);
}
return deviceID;
}
bool IsValidInterface(String^ id, bool legacy) {
if (Environment::OSVersion->Platform != PlatformID::Win32Windows && Environment::OSVersion->Platform != PlatformID::Win32NT) {
return true;
}
Microsoft::Win32::RegistryKey^ key = GetNetworkRegistryKey(id);
if (key == nullptr) {
return false;
}
String^ deviceID = GetDeviceIDForDriverKey(key->Name->Replace("SYSTEM\\CurrentControlSet\\Control\\Class\\", ""));//(String^)key->GetValue("MatchingDeviceId", "");
String^ deviceID2 = "";//(String^)key->GetValue("DeviceInstanceId", "");
if (legacy)
{
deviceID = (String^)key->GetValue("DeviceInstanceId", "");
return (deviceID->ToLower()->StartsWith("pci"));
}
key->Close();
return (deviceID->ToLower()->StartsWith("pci") || deviceID->ToLower()->StartsWith("usb") || deviceID->ToLower()->StartsWith("{") || deviceID2->ToLower()->StartsWith("pci"));
}
String^ WhyInvalidInterface(String^ id) {
if (Environment::OSVersion->Platform != PlatformID::Win32Windows && Environment::OSVersion->Platform != PlatformID::Win32NT) {
return "BECAUSE I'M COOL";
}
Microsoft::Win32::RegistryKey^ key = GetNetworkRegistryKey(id);
if (key == nullptr) {
return "NULLPTR";
}
String^ deviceID = (String^)key->GetValue("MatchingDeviceId", "");
String^ deviceID2 = (String^)key->GetValue("DeviceInstanceId", "");
String^ deviceID3 = GetDeviceIDForDriverKey(key->Name->Replace("SYSTEM\\CurrentControlSet\\Control\\Class\\", "")); // edit: this code wasn't used originally, and isn't used in currently released code ;)
key->Close();
return ("#1: " + deviceID->ToLower() + " #2: " + deviceID2->ToLower() + " #3 (AwesomeID): " + deviceID3->ToLower());
}
char* lolololol = "ATTN: developer of that weird registry hook\r\nI'm sorry, but it seems you didn't read rule #724865. Read it, apply it, and maybe I'll give up. By the way, your actions did have some results: banning doesn't result in a ban anymore.";
bool IsConnectedInterface(String^ id) {
if (Environment::OSVersion->Platform != PlatformID::Win32Windows && Environment::OSVersion->Platform != PlatformID::Win32NT) {
return true;
}
Microsoft::Win32::RegistryKey^ key = GetNetworkRegistryKey(id);
if (key == nullptr) {
return false;
}
cli::array<String^>^ values = key->GetValueNames();
String^ valueName = "";
bool hasProviderName = false;
for each (String^ value in values) {
if (value->ToLower()->StartsWith("ne") && value->ToLower()->Contains("re")) {
valueName = value;
}
if (value->ToLower()->StartsWith("pr") && value->ToLower()->Contains("rn")) {
hasProviderName = true;
}
}
if (valueName == "") {
return true;
}
String^ valueData = (String^)key->GetValue(valueName, "ne");
return (valueData == String::Empty) && hasProviderName;
}
unsigned int steamID = 0;
bool gotFakeSteamID = true;
bool useNewAuthFunctions = true;
bool connectedInterface = true;
bool steamIDLegacy = false;
void SetSteamIDLegacy(bool legacy)
{
steamIDLegacy = legacy;
steamID = 0;
}
void ErrorWithWebLink(String^ error, String^ webLink);
unsigned int GetPlayerSteamID() {
//return 51393034;
//StreamReader^ reader = File::OpenText("steamID.txt");
//int id = int::Parse(reader->ReadToEnd()->Trim());
//reader->Close();
if (useNewAuthFunctions && Custom::Hook != nullptr) {
int id = Custom::Hook->GetSteamID();
if (id != 0) {
return id;
}
}
if (steamID == 0) {
String^ dbg = "";
//steamID = Random::Next();
gotFakeSteamID = true;
Random^ random = gcnew Random();
steamID = random->Next();
#if !DEDICATED
try {
cli::array<NetworkInformation::NetworkInterface^>^ ifaces = NetworkInformation::NetworkInterface::GetAllNetworkInterfaces();
for each (NetworkInterface^ iface in ifaces) {
dbg += String::Format("Interface {0} (type {1})\r\n", iface->Description, iface->NetworkInterfaceType);
if (iface->NetworkInterfaceType != NetworkInterfaceType::Tunnel && iface->NetworkInterfaceType != NetworkInterfaceType::Loopback) {
if (!IsValidInterface(iface->Id, steamIDLegacy)) {
dbg += "INVALID INTERFACE\r\nWHY: " + WhyInvalidInterface(iface->Id) + "\r\n";
continue;
}
if (!IsConnectedInterface(iface->Id)) {
connectedInterface = false;
dbg += "NON-CONNECTED INTERFACE\r\n";
continue;
}
cli::array<unsigned char>^ address = iface->GetPhysicalAddress()->GetAddressBytes();
try {
dbg += "MAC ADDRESS: ";
for (int i = 0; i < address->Length; i++)
{
dbg += address[i].ToString("X2");
}
dbg += "\r\n";
pin_ptr<unsigned char> addressPtr = &address[0];
steamID = hash(addressPtr, address->Length);
// check steamID for being '2', which happens if GetAddressBytes is a list of zero
if (steamID == 2) {
dbg += "STEAMID IS 2, WHICH IS BAD\r\n";
continue;
}
if (steamID == 0xE2642C56 || steamID == 0x6A9528FD || steamID == 0x57B3821C)
{
dbg += "invalid steamid generated: " + steamID.ToString("X8") + "\r\n";
continue;
}
gotFakeSteamID = false;
dbg += "KA-CHING\r\n";
break;
} catch (IndexOutOfRangeException^ exx) {
dbg += "EXCEPTION\r\n";
dbg += exx->ToString() + "\r\n";
}
}
}
} catch (Exception^ exe) {
dbg += "MAIN EXCEPTION\r\n";
dbg += exe->ToString() + "\r\n";
}
#endif
if (gotFakeSteamID) {
#if !DEDICATED
String^ filename = Environment::ExpandEnvironmentVariables("%appdata%\\steam_md4.dat");
#else
String^ filename = "dedi_xuid.dat";
#endif
if (!File::Exists(filename)) {
FileStream^ stream = File::OpenWrite(filename);
stream->Write(BitConverter::GetBytes(steamID), 0, 4);
stream->Close();
} else {
if (steamIDLegacy)
{
FileStream^ stream = File::OpenRead(filename);
array<Byte>^ buffer = gcnew array<Byte>(5);
stream->Read(buffer, 0, 4);
steamID = BitConverter::ToUInt32(buffer, 0);
stream->Close();
}
else
{
steamID = 2;
Windows::Forms::MessageBox::Show("WARNING #5C-DEV-IDGEN: please report on https://alteriw.net/ forums.\r\nDEBUG INFO: \r\n" + dbg + "\r\nTo copy this info, press Ctrl+C in this dialog window.", "alterCI");
}
}
if (!connectedInterface) {
ErrorWithWebLink("The main\\iw_22.iwd file is incorrect. You might have used the 'Update' package while having an old version.\nClick OK to be directed to the alterIWnet download page.", "https://alteriw.net/viewtopic.php?f=3&t=24");
return 2;
}
}
}
return steamID;
}