static void s_RemoveRegistry(wchar_t *s) { HKEY key, result; wchar_t *subkey, *last; DWORD rc; SplitRegistryKey("remove-registry!", s, &key, &subkey, &last); /* open the key */ if (last == subkey) { rc = RegOpenKeyExW(key, L"", 0, KEY_ALL_ACCESS, &result); } else { *last = '\0'; /* Truncate subkey at backslash */ rc = RegOpenKeyExW(key, subkey, 0, KEY_ALL_ACCESS, &result); *last++ = '\\'; /* Restore backslash */ } if (rc == ERROR_SUCCESS) { /* delete the value */ rc = RegDeleteValueW(result, last); if (rc == ERROR_FILE_NOT_FOUND) /* value by given name not found; try deleting as key */ rc = RegDeleteKeyW(result, last); RegCloseKey(result); } if (rc != ERROR_SUCCESS) { char *s_utf8 = Swide_to_utf8(s); ptr s_scheme = Sstring_utf8(s_utf8, -1); free(s_utf8); S_error2("remove-registry!", "cannot remove ~a (~a)", s_scheme, rc == ERROR_FILE_NOT_FOUND ? Sstring("not found") : rc == ERROR_ACCESS_DENIED ? Sstring("insufficient permission or subkeys exist") : s_ErrorString(rc)); } }
static ptr s_ErrorString(DWORD dwMessageId) { char *lpMsgBuf; DWORD len; ptr result; len = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwMessageId, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL); /* If FormatMessage fails, use the error code in hexadecimal. */ if (len == 0) { #define HEXERRBUFSIZ ((sizeof(dwMessageId) * 2) + 3) char hexerrbuf[HEXERRBUFSIZ]; snprintf(hexerrbuf, HEXERRBUFSIZ, "0x%x", dwMessageId); return Sstring(hexerrbuf); #undef HEXERRBUFSIZ } /* Otherwise remove trailing newlines & returns and strip trailing period. */ while (len > 0) { char c = lpMsgBuf[len - 1]; if (c == '\n' || c == '\r') len--; else if (c == '.') { len--; break; } else break; } result = Sstring_of_length(lpMsgBuf, len); LocalFree(lpMsgBuf); return result; }
/* Warning: may return pointer to static string */ const char *S_pathname(const char *who, const char *inpath, IBOOL errorp, char *buffer) { const char *path = S_pathname_impl(inpath, buffer); if (path != NULL) return path; if (errorp) S_error1(who, "unable to expand path name ~s", Sstring(inpath)); return inpath; }
static void s_PutRegistry(wchar_t *s, wchar_t *val) { HKEY key, result; wchar_t *subkey, *last; DWORD rc, type; size_t n = (wcslen(val) + 1) * sizeof(wchar_t); #if (size_t_bits > 32) if ((DWORD)n != n) { char *s_utf8 = Swide_to_utf8(s); ptr s_scheme = Sstring_utf8(s_utf8, -1); free(s_utf8); S_error2("put-registry!", "cannot set ~a (~a)", s_scheme, Sstring("too long")); } #endif SplitRegistryKey("put-registry!", s, &key, &subkey, &last); /* create/open the key */ if (last == subkey) { rc = RegCreateKeyExW(key, L"", 0, NULL, 0, KEY_SET_VALUE, NULL, &result, NULL); } else { *last = '\0'; /* Truncate subkey at backslash */ rc = RegCreateKeyExW(key, subkey, 0, NULL, 0, KEY_SET_VALUE, NULL, &result, NULL); *last++ = '\\'; /* Restore backslash */ } if (rc == ERROR_SUCCESS) { /* lookup type for key (if it exists), if not assume REG_SZ */ if (ERROR_SUCCESS != RegQueryValueExW(result, last, NULL, &type, NULL, NULL)) type = REG_SZ; /* set the value */ rc = RegSetValueExW(result, last, 0, type, (const BYTE*)val, (DWORD)n); RegCloseKey(result); } if (rc != ERROR_SUCCESS) { char *s_utf8 = Swide_to_utf8(s); ptr s_scheme = Sstring_utf8(s_utf8, -1); free(s_utf8); S_error2("put-registry!", "cannot set ~a (~a)", s_scheme, rc == ERROR_FILE_NOT_FOUND ? Sstring("not found") : s_ErrorString(rc)); } }
void GameTick() { if( didflip ) { StartSend(); Sbyte( 0x29 ); //effect Sstring( "random.click", -1 ); Sint( (uint16_t)(flipx<<3) ); Sint( (uint16_t)(flipy<<3) ); Sint( (uint16_t)(flipz<<3) ); Sfloat( 32 ); //100% volume Sbyte( 63 ); //100% speed DoneSend(); didflip = 0; } }
void GameTick() { if( didflip ) { StartSend(); Sbyte( 0x29 ); //effect Sstring( "random.click", -1 ); Sint( (uint16_t)(4<<3) ); Sint( (uint16_t)(64<<3) ); Sint( (uint16_t)(sel<<3) ); Sfloat( 32 ); //100% volume Sbyte( 63 ); //100% speed DoneSend(); didflip = 0; SetManyWS( pgm_read_byte( &wools[sel*3+0] ), pgm_read_byte( &wools[sel*3+1] ), pgm_read_byte( &wools[sel*3+2] ), 20 ); } }