static bool WriteDisassembly(UINT64 hash, wstring shaderType, AsmTextBlob* asmTextBlob) { wchar_t fullName[MAX_PATH]; FILE *f; wsprintf(fullName, L"%ls\\%08lx%08lx-%ls.txt", G->SHADER_PATH, (UINT32)(hash >> 32), (UINT32)(hash), shaderType.c_str()); // Check if the file already exists. _wfopen_s(&f, fullName, L"rb"); if (f) { LogInfoW(L" Shader Mark .bin file already exists: %s\n", fullName); fclose(f); return false; } _wfopen_s(&f, fullName, L"wb"); if (!f) { LogInfoW(L" Shader Mark could not write asm text file: %s\n", fullName); return false; } // Size - 1 to strip NULL terminator fwrite(asmTextBlob->GetBufferPointer(), 1, asmTextBlob->GetBufferSize() - 1, f); fclose(f); LogInfoW(L" storing disassembly to %s\n", fullName); return true; }
static bool WriteHLSL(string hlslText, AsmTextBlob* asmTextBlob, UINT64 hash, wstring shaderType) { wchar_t fullName[MAX_PATH]; FILE *fw; wsprintf(fullName, L"%ls\\%08lx%08lx-%ls_replace.txt", G->SHADER_PATH, (UINT32)(hash >> 32), (UINT32)hash, shaderType.c_str()); _wfopen_s(&fw, fullName, L"rb"); if (fw) { LogInfoW(L" marked shader file already exists: %s\n", fullName); fclose(fw); _wfopen_s(&fw, fullName, L"ab"); if (fw) { fprintf_s(fw, " "); // Touch file to update mod date as a convenience. fclose(fw); } BeepShort(); // Short High beep for for double beep that it's already there. return true; } _wfopen_s(&fw, fullName, L"wb"); if (!fw) { LogInfoW(L" error storing marked shader to %s\n", fullName); return false; } LogInfoW(L" storing patched shader to %s\n", fullName); fwrite(hlslText.c_str(), 1, hlslText.size(), fw); fprintf_s(fw, "\n\n/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); // Size - 1 to strip NULL terminator fwrite(asmTextBlob->GetBufferPointer(), 1, asmTextBlob->GetBufferSize() - 1, fw); fprintf_s(fw, "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/\n"); fclose(fw); return true; }
void InitializeDLL() { if (!gInitialized) { gInitialized = true; wchar_t dir[MAX_PATH]; GetModuleFileName(0, dir, MAX_PATH); wcsrchr(dir, L'\\')[1] = 0; wcscat(dir, L"d3dx.ini"); // If specified in Logging section, wait for Attach to Debugger. bool waitfordebugger = false; int debugger = GetPrivateProfileInt(L"Logging", L"waitfordebugger", 0, dir); if (debugger > 0) { waitfordebugger = true; do { Sleep(250); } while (!IsDebuggerPresent()); if (debugger > 1) __debugbreak(); } // Switch to unbuffered logging to remove need for fflush calls, and r/w access to make it easy // to open active files. if (GetPrivateProfileInt(L"Logging", L"calls", 1, dir)) { LogFile = _fsopen("dxgi_log.txt", "w", _SH_DENYNO); LogInfo("\n *** DXGI DLL starting init - %s\n\n", LogTime().c_str()); } gLogDebug = GetPrivateProfileInt(L"Logging", L"debug", 0, dir) == 1; // Unbuffered logging to remove need for fflush calls, and r/w access to make it easy // to open active files. int unbuffered = -1; if (GetPrivateProfileInt(L"Logging", L"unbuffered", 0, dir)) { unbuffered = setvbuf(LogFile, NULL, _IONBF, 0); LogInfo(" unbuffered=1 return: %d\n", unbuffered); } // Set the CPU affinity based upon d3dx.ini setting. Useful for debugging and shader hunting in AC3. if (GetPrivateProfileInt(L"Logging", L"force_cpu_affinity", 0, dir)) { DWORD one = 0x01; BOOL result = SetProcessAffinityMask(GetCurrentProcess(), one); LogInfo(" CPU Affinity forced to 1- no multithreading: %s\n", result ? "true" : "false"); } if (LogFile) { LogInfo("[Logging]\n"); LogInfo(" calls=1\n"); LogDebug(" debug=1\n"); if (waitfordebugger) LogInfo(" waitfordebugger=1\n"); } wchar_t val[MAX_PATH]; int read = GetPrivateProfileString(L"Device", L"width", 0, val, MAX_PATH, dir); if (read) swscanf_s(val, L"%d", &SCREEN_WIDTH); read = GetPrivateProfileString(L"Device", L"height", 0, val, MAX_PATH, dir); if (read) swscanf_s(val, L"%d", &SCREEN_HEIGHT); read = GetPrivateProfileString(L"Device", L"refresh_rate", 0, val, MAX_PATH, dir); if (read) swscanf_s(val, L"%d", &SCREEN_REFRESH); SCREEN_FULLSCREEN = GetPrivateProfileInt(L"Device", L"full_screen", 0, dir) == 1; SCREEN_ALLOW_COMMANDS = GetPrivateProfileInt(L"Device", L"allow_windowcommands", 0, dir) == 1; read = GetPrivateProfileString(L"Device", L"filter_refresh_rate", 0, val, MAX_PATH, dir); if (read) swscanf_s(val, L"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", FILTER_REFRESH+0, FILTER_REFRESH+1, FILTER_REFRESH+2, FILTER_REFRESH+3, &FILTER_REFRESH+4, FILTER_REFRESH+5, FILTER_REFRESH+6, FILTER_REFRESH+7, FILTER_REFRESH+8, &FILTER_REFRESH+9); if (LogFile) { LogInfo("[Device]\n"); if (SCREEN_WIDTH != -1) LogInfo(" width=%d\n", SCREEN_WIDTH); if (SCREEN_HEIGHT != -1) LogInfo(" height=%d\n", SCREEN_HEIGHT); if (SCREEN_REFRESH != -1) LogInfo(" refresh_rate=%d\n", SCREEN_REFRESH); if (FILTER_REFRESH[0]) LogInfoW(L" filter_refresh_rate=%s\n", FILTER_REFRESH[0]); if (SCREEN_FULLSCREEN) LogInfo(" full_screen=1\n"); if (SCREEN_ALLOW_COMMANDS) LogInfo(" allow_windowcommands=1\n"); } } LogInfo(" *** DXGI DLL successfully initialized. *** \n\n"); }