VOID FormatRamDisk() { WCHAR mountPoint[] = L" :"; VOID *deviceHandle = 0; RAMDISK_CREATE_DATA createData = { 0 }; deviceHandle = OpenRamDisk(); if (deviceHandle == INVALID_HANDLE_VALUE) return; R0QueryRamDisk(deviceHandle, &createData); NtClose(deviceHandle); if (createData.DriveLetter == NULL) //could not get a drive letter, return. return; mountPoint[0] = createData.DriveLetter; FormatEx = (PFORMATEX) Module_GetProcedureAddress( Module_Load(L"fmifs.dll"), "FormatEx" ); FormatEx( mountPoint, FMIFS_HARDDISK, L"NTFS", L"RAM Disk", TRUE, 0, FormatExCallback ); }
VOID GetHardwareInfo() { int i = 0; int monitorCount; HANDLE gdi32; int cores = 0; //use 64 bits to force allmul() on 32 bit builds UINT64 physicalPages; UINT64 pageSize; InitGpuHardware(); GPU_Initialize(PushSharedMemory->HarwareInformation.DisplayDevice.pciAddress); PushSharedMemory->HarwareInformation.DisplayDevice.FrameBuffer.Total = GPU_GetTotalMemory(); PushSharedMemory->HarwareInformation.DisplayDevice.EngineClockMax = GPU_GetMaximumEngineClock(); PushSharedMemory->HarwareInformation.DisplayDevice.MemoryClockMax = GPU_GetMaximumMemoryClock(); PushSharedMemory->HarwareInformation.DisplayDevice.VoltageMax = GPU_GetMaximumVoltage(); if (Ini_ReadBoolean(L"Settings", L"GpuUsageD3DKMT", FALSE, L".\\" PUSH_SETTINGS_FILE)) PushGpuLoadD3DKMT = TRUE; // Get the number of processors in the system NtQuerySystemInformation(SystemBasicInformation, &HwInfoSystemBasicInformation, sizeof(SYSTEM_BASIC_INFORMATION), 0); PushSharedMemory->HarwareInformation.Processor.NumberOfThreads = HwInfoSystemBasicInformation.NumberOfProcessors; physicalPages = HwInfoSystemBasicInformation.NumberOfPhysicalPages; pageSize = HwInfoSystemBasicInformation.PageSize; //byte => megabytes PushSharedMemory->HarwareInformation.Memory.Total = (physicalPages * pageSize) / 1048576; cores = CPU_Intialize(); PushSharedMemory->HarwareInformation.Processor.NumberOfCores = cores; PushSharedMemory->HarwareInformation.Processor.TjMax = CPU_GetTemperatureMaximal(); PushSharedMemory->HarwareInformation.Processor.MhzBase = CPU_GetBaseSpeed(); // Monitors gdi32 = Module_Load(L"gdi32.dll"); GetNumberOfPhysicalMonitors = Module_GetProcedureAddress(gdi32, "GetNumberOfPhysicalMonitors"); GetPhysicalMonitors = Module_GetProcedureAddress(gdi32, "GetPhysicalMonitors"); DDCCIGetTimingReport = Module_GetProcedureAddress(gdi32, "DDCCIGetTimingReport"); DDCCIGetVCPFeature = Module_GetProcedureAddress(gdi32, "DDCCIGetVCPFeature"); DDCCISetVCPFeature = Module_GetProcedureAddress(gdi32, "DDCCISetVCPFeature"); monitorCount = GetSystemMetrics(SM_CMONITORS); MonitorWidth = GetSystemMetrics(SM_CXSCREEN); MonitorHeight = GetSystemMetrics(SM_CYSCREEN); MonitorHandles = Memory_Allocate(sizeof(HANDLE) * monitorCount); EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, NULL); }
VOID GetDisplayAdapterDevicePath( WCHAR* Buffer ) { HANDLE cfgmgr32; cfgmgr32 = Module_Load(L"cfgmgr32.dll"); CM_Get_Device_Interface_List_ExW = (TYPE_CM_Get_Device_Interface_List_ExW) Module_GetProcedureAddress(cfgmgr32, "CM_Get_Device_Interface_List_ExW"); CM_Get_Device_Interface_List_ExW(&GUID_DISPLAY_DEVICE_ARRIVAL_I, NULL, Buffer, 213, 0, NULL); }
bool LightsDriver_Dynamic::LoadInternal() { ASSERT( !m_sLibraryPath.empty() ); const struct LightsModuleInfo *info = Module_GetModuleInfo(); CHECKPOINT; if( info == NULL ) { LOG->Warn( "Could not get LightsModuleInfo from LightsDriver \"%s\".", m_sLibraryPath.c_str() ); return false; } CHECKPOINT; if( LIGHTS_API_VERSION_MAJOR != info->mi_api_ver_major || LIGHTS_API_VERSION_MINOR != info->mi_api_ver_minor ) { LOG->Warn( "LightsDriver \"%s\" uses API version %d.%d, binary uses %d.%d. Disabled.", info->mi_name, info->mi_api_ver_major, info->mi_api_ver_minor, LIGHTS_API_VERSION_MAJOR, LIGHTS_API_VERSION_MINOR ); return false; } CHECKPOINT; LOG->Trace( "%s: attempting to load LightsDriver \"%s\".", __FUNCTION__, info->mi_name ); CHECKPOINT; int iError = Module_Load(); CHECKPOINT; CHECKPOINT; if( iError != 0 ) { CHECKPOINT; CString sError = ssprintf( "Error initializing LightsDriver \"%s\": %s", info->mi_name, (Module_GetError != NULL) ? Module_GetError(iError) : "(no error message)" ); LOG->Warn( sError ); CHECKPOINT; Module_Unload(); CHECKPOINT; return false; } CHECKPOINT; LOG->Debug( "Established connection with LightsDriver \"%s\".", info->mi_name ); LOG->Info( "LightsDriver module: %s, author: %s, version: %d.%d", info->mi_name, info->mi_author, info->mi_api_ver_major, info->mi_api_ver_minor ); m_bLoaded = true; CHECKPOINT; return true; }
INT32 __stdcall start( ) { HANDLE sectionHandle, *hMutex; HANDLE eventHandle; HANDLE threadHandle; DWORD sectionSize; MSG messages; OBJECT_ATTRIBUTES objAttrib = {0}; PTEB threadEnvironmentBlock; UNICODE_STRING eventSource; LDR_DATA_TABLE_ENTRY *module; SECTION_BASIC_INFORMATION sectionInfo; LARGE_INTEGER newSectionSize; InitializeCRT(); threadEnvironmentBlock = NtCurrentTeb(); PushProcessId = threadEnvironmentBlock->ClientId.UniqueProcess; PushHeapHandle = threadEnvironmentBlock->ProcessEnvironmentBlock->ProcessHeap; PushSessionId = threadEnvironmentBlock->ProcessEnvironmentBlock->SessionId; // Check if already running hMutex = CreateMutexW(0, FALSE, L"PushOneInstance"); if (threadEnvironmentBlock->LastErrorValue == ERROR_ALREADY_EXISTS || threadEnvironmentBlock->LastErrorValue == ERROR_ACCESS_DENIED) { MessageBoxW(0, L"Only one instance!", 0,0); ExitProcess(0); } //create image event eventHandle = NULL; UnicodeString_Init(&eventSource, L"Global\\" PUSH_IMAGE_EVENT_NAME); objAttrib.Length = sizeof(OBJECT_ATTRIBUTES); objAttrib.RootDirectory = BaseGetNamedObjectDirectory(); objAttrib.ObjectName = &eventSource; objAttrib.Attributes = OBJ_OPENIF; objAttrib.SecurityDescriptor = NULL; objAttrib.SecurityQualityOfService = NULL; NtCreateEvent(&eventHandle, EVENT_ALL_ACCESS, &objAttrib, NotificationEvent, FALSE); // populate file name and path module = (LDR_DATA_TABLE_ENTRY*)threadEnvironmentBlock->ProcessEnvironmentBlock->Ldr->InLoadOrderModuleList.Flink; Memory_Copy(PushFilePath, module->FullDllName.Buffer, module->FullDllName.Length); PushFilePath[module->FullDllName.Length] = L'\0'; // Start Driver. Driver_Extract(); PushDriverLoaded = Driver_Load(); //initialize instance PushInstance = Module_GetHandle(L"Push.exe"); // Create interface MwCreateMainWindow(); // Create section. sectionSize = sizeof(PUSH_SHARED_MEMORY) + OSD_GetSize(); PushSharedMemory = (PUSH_SHARED_MEMORY*)Memory_MapViewOfSection(PUSH_SECTION_NAME, sectionSize, §ionHandle); if (!PushSharedMemory) { Log(L"Could not create shared memory"); return 0; } Log(L"Created section of size %i bytes", sectionSize); //zero struct Memory_Clear(PushSharedMemory, sizeof(PUSH_SHARED_MEMORY)); //initialize window handle used by overlay //PushSharedMemory->WindowHandle = PushMainWindow->Handle; //initialize default font properties for overlay String_Copy(PushSharedMemory->FontName, L"Verdana"); PushSharedMemory->FontBold = TRUE; if (File_Exists(PUSH_SETTINGS_FILE)) { wchar_t *buffer; wchar_t marker; // Check if file is UTF-16LE. buffer = (WCHAR*) File_Load(PUSH_SETTINGS_FILE, NULL); marker = buffer[0]; Memory_Free(buffer); if (marker == 0xFEFF) //is UTF-LE. { // Init settings from ini file. buffer = Memory_Allocate(100 * sizeof(WCHAR)); Ini_GetString(L"Settings", L"FrameLimit", NULL, buffer, 5, L".\\" PUSH_SETTINGS_FILE); PushSharedMemory->FrameLimit = _wtoi(buffer); if (Ini_ReadBoolean(L"Settings", L"ThreadOptimization", FALSE, L".\\" PUSH_SETTINGS_FILE)) PushSharedMemory->ThreadOptimization = TRUE; if (Ini_ReadBoolean(L"Settings", L"KeepFps", FALSE, L".\\" PUSH_SETTINGS_FILE)) PushSharedMemory->KeepFps = TRUE; Ini_GetString(L"Settings", L"OverlayInterface", NULL, buffer, 5, L".\\" PUSH_SETTINGS_FILE); if (String_Compare(buffer, L"PURE") == 0) PushOverlayInterface = OVERLAY_INTERFACE_PURE; else if (String_Compare(buffer, L"RTSS") == 0) PushOverlayInterface = OVERLAY_INTERFACE_RTSS; Ini_GetString(L"Settings", L"KeyboardHookType", L"AUTO", buffer, 10, L".\\" PUSH_SETTINGS_FILE); if (String_Compare(buffer, L"AUTO") == 0) { PushSharedMemory->KeyboardHookType = KEYBOARD_HOOK_AUTO; } else if (String_Compare(buffer, L"SUBCLASS") == 0) { PushSharedMemory->KeyboardHookType = KEYBOARD_HOOK_SUBCLASS; } else if (String_Compare(buffer, L"MESSAGE") == 0) { PushSharedMemory->KeyboardHookType = KEYBOARD_HOOK_MESSAGE; } else if (String_Compare(buffer, L"KEYBOARD") == 0) { PushSharedMemory->KeyboardHookType = KEYBOARD_HOOK_KEYBOARD; } else if (String_Compare(buffer, L"DETOURS") == 0) { PushSharedMemory->KeyboardHookType = KEYBOARD_HOOK_DETOURS; } else if (String_Compare(buffer, L"RAW") == 0) { PushSharedMemory->KeyboardHookType = KEYBOARD_HOOK_RAW; } else { PushSharedMemory->KeyboardHookType = KEYBOARD_HOOK_AUTO; } Ini_GetString(L"Settings", L"EngineClockMax", NULL, buffer, 5, L".\\" PUSH_SETTINGS_FILE); PushSharedMemory->HarwareInformation.DisplayDevice.EngineOverclock = _wtoi(buffer); Ini_GetString(L"Settings", L"MemoryClockMax", NULL, buffer, 5, L".\\" PUSH_SETTINGS_FILE); PushSharedMemory->HarwareInformation.DisplayDevice.MemoryOverclock = _wtoi(buffer); Ini_GetString(L"Settings", L"ControllerTimeout", NULL, buffer, 5, L".\\" PUSH_SETTINGS_FILE); PushSharedMemory->ControllerTimeout = _wtoi(buffer); Ini_GetString(L"Settings", L"FontName", L"Verdana", buffer, 100, L".\\" PUSH_SETTINGS_FILE); String_Copy(PushSharedMemory->FontName, buffer); Memory_Free(buffer); if (Ini_ReadBoolean(L"Settings", L"FontBold", FALSE, L".\\" PUSH_SETTINGS_FILE)) PushSharedMemory->FontBold = TRUE; } else { MessageBoxW( NULL, L"Settings file not UTF-16LE! " L"Resave the file as \"Unicode\" or Push won't read it!", L"Bad Settings file", NULL ); } } if (!PushDriverLoaded) { wchar_t driverPath[260]; Resource_Extract(L"DRIVERALT", L"WinRing0x64.sys"); GetDriverPath(L"WinRing0x64.sys", driverPath); Wr0DriverLoaded = Wr0Initialize(driverPath); } //initialize HWInfo GetHardwareInfo(); //initialize OSD items NtQuerySection( sectionHandle, SectionBasicInformation, §ionInfo, sizeof(SECTION_BASIC_INFORMATION), NULL ); newSectionSize.QuadPart = OSD_Initialize() + sizeof(PUSH_SHARED_MEMORY); if (newSectionSize.QuadPart > sectionInfo.MaximumSize.QuadPart) { Log(L"Shared memory too small!"); } //Check for controllers/gamepads/bluetooth adapters //EnumerateDevices(); // Check for running games Process_EnumProcesses(ProcessEnum); // Activate process monitoring if (PushDriverLoaded) { PushToggleProcessMonitoring(TRUE); } else { HANDLE overlayLib = NULL; void* prcAddress = 0; Resource_Extract(L"OVERLAY32", PUSH_LIB_NAME_32); overlayLib = Module_Load(L"overlay32.dll"); prcAddress = Module_GetProcedureAddress(overlayLib, "InstallOverlayHook"); if (prcAddress) { InstallOverlayHook = (TYPE_InstallOverlayHook)prcAddress; InstallOverlayHook(); } } g_szPrevGame[5] = '\0'; NtCreateThreadEx( &PushMonitorThreadHandle, THREAD_ALL_ACCESS, NULL, NtCurrentProcess(), &MonitorThread, NULL, NoThreadFlags, 0, 0, 0, NULL ); NtCreateThreadEx( &threadHandle, THREAD_ALL_ACCESS, NULL, NtCurrentProcess(), &PipeThread, NULL, NoThreadFlags, 0, 0, 0, NULL ); // Handle messages while(GetMessageW(&messages, 0,0,0)) { TranslateMessage(&messages); DispatchMessageW(&messages); } ExitProcess(0); return 0; }