Esempio n. 1
0
extern "C" __declspec(dllexport) void GeDoSaToInit() {
	// read install location from registry
	getInstallDirectory();
	OutputDebugString("GeDoSaTo: Got install dir");

	// loaded in GeDoSaToTool, stay in memory
	if(getExeFileName() == "GeDoSaToTool") {
		OutputDebugString("GeDoSaTo: Tool mode");
		g_tool = true;
		return;
	}

	g_active = true;
	OutputDebugString(format("GeDoSaTo: Active on %s", getExeFileName()).c_str());

	// initialize log
	string logFn = format("logs\\%s_%s.log", getExeFileName().c_str(), getTimeString().c_str());
	std::replace(logFn.begin(), logFn.end(), ':', '-');
	std::replace(logFn.begin(), logFn.end(), ' ', '_');
	logFn = getInstalledFileName(logFn);
	fopen_s(&g_oFile, logFn.c_str(), "w");
	if(!g_oFile) OutputDebugString(format("GeDoSaTo: Error opening log fn %s", logFn.c_str()).c_str());
	else OutputDebugString(format("GeDoSaTo: Opening log fn %s, handle: %p", logFn.c_str(), g_oFile).c_str());
	OutputDebugString("GeDoSaTo: Log file initialized, let that take over");

	// startup
	SDLOG(-1, "===== %s =====\n", getTimeString().c_str());
	SDLOG(-1, "===== start "INTERCEPTOR_NAME" %s = fn: %s\n", GeDoSaToVersion(), getExeFileName().c_str());
	SDLOG(-1, "===== installation directory: %s\n", getInstallDirectory().c_str());

	// load settings
	Settings::get().load();
	Settings::get().report();

	KeyActions::get().load();
	KeyActions::get().report();

	// early steam dll loading
	if(!Settings::get().getPreventSteamOverlay() && Settings::get().getLoadSteamOverlayEarly()) {
		SDLOG(2, "Attempting to pre-load Steam overlay dll.\n");
		LoadLibrary("gameoverlayrenderer.dll");
	}

	// early d3d loading
	if(Settings::get().getLoadD3DEarly()) {
		SDLOG(2, "Early d3d loading.\n");
		auto dllname = getSystemDllName("d3d9.dll");
		LoadLibrary(dllname.c_str());
	}

	// detour
	startDetour();
}
Esempio n. 2
0
void PerfTrace::storeResult() {
	total.stop();
	double tot_ms = total.elapsed() / 1000.0;
	string logFn = format("logs\\%s_%s_perf.txt", getExeFileName().c_str(), getTimeString().c_str());
	std::replace(logFn.begin(), logFn.end(), ':', '-');
	std::replace(logFn.begin(), logFn.end(), ' ', '_');
	logFn = getInstalledFileName(logFn);
	std::ofstream outf(logFn.c_str());
	outf << "Total frames: " << frame_cpu_times.size() << "\n";
	outf << "Total time: " << tot_ms << "\n";
	outf << "Average FPS: " << frame_cpu_times.size()*1000 / tot_ms << "\n\n";

	auto eff_copy = frame_eff_times;
	std::sort(eff_copy.begin(), eff_copy.end());
	auto l = eff_copy.size();
	outf << "99 % frame time: " << eff_copy[static_cast<int>(floor(l * 0.99))] << "\n";
	outf << "95 % frame time: " << eff_copy[static_cast<int>(floor(l * 0.95))] << "\n";
	outf << "75 % frame time: " << eff_copy[static_cast<int>(floor(l * 0.75))] << "\n\n";

	outf << "Individual frames (cpu;gpu;effective):\n";
	for(size_t i = 0; i < l; ++i) {
		outf << format("%8.4f,%8.4f,%8.4f\n", frame_cpu_times[i], frame_gpu_times[i], frame_eff_times[i]);
	}
	outf << "\n";
}
Esempio n. 3
0
void RSManager::dumpSurface(const char* name, IDirect3DSurface9* surface) {
	auto dirname = format("%s\\tmp\\%s", getInstallDirectory().c_str(), getExeFileName().c_str());
	CreateDirectory(dirname.c_str(), NULL);
	auto fullname = format("%s\\dump%03d_%s_%p.tga", dirname.c_str(), dumpCaptureIndex++, name, surface);
	SDLOG(1, "!! dumped RT %p to %s\n", surface, fullname.c_str());
	D3DXSaveSurfaceToFile(fullname.c_str(), D3DXIFF_TGA, surface, NULL, NULL);
}
void RSManagerDX9::registerD3DXCreateTextureFromFileInMemory(LPCVOID pSrcData, UINT SrcDataSize, LPDIRECT3DTEXTURE9 pTexture) {
	SDLOG(1, "RenderstateManager: registerD3DXCreateTextureFromFileInMemory %p | %p (size %d)\n", pTexture, pSrcData, SrcDataSize);
	if(Settings::get().getEnableTextureDumping()) {
		UINT32 hash = SuperFastHash((char*)const_cast<void*>(pSrcData), SrcDataSize);
		SDLOG(1, " - size: %8u, hash: %8x\n", SrcDataSize, hash);

		IDirect3DSurface9* surf = NULL;
		((IDirect3DTexture9*)pTexture)->GetSurfaceLevel(0, &surf);
		if(surf != NULL) {
			string directory = getInstalledFileName(format("textures\\%s\\dump\\", getExeFileName().c_str()));
			SDLOG(1, "%s\n", boost::filesystem::path(directory).string().c_str())
				try {
				boost::filesystem::create_directories(boost::filesystem::path(directory));
				string fn = format("%s%08x.tga", directory.c_str(), hash);
				SDLOG(1, " - dumping texture to %s\n", fn);
				if(SUCCEEDED(D3DXSaveSurfaceToFile(fn.c_str(), D3DXIFF_TGA, surf, NULL, NULL))) {
					SDLOG(1, " - texture dumped\n");
				}
				else {
					SDLOG(-1, "ERROR while texture dumping (D3DX)\n");
				}
			}
			catch(boost::filesystem::filesystem_error e) {
				SDLOG(-1, "ERROR - Filesystem error while trying to create directory:\n%s\n", e.what());
			}
			surf->Release();
		}
Esempio n. 5
0
int createPIDFile(const char* fileName)
{
    char buffer[256];
    char value[64];
    memset(buffer, 0, sizeof(buffer));
    memset(value, 0, sizeof(value));

    if (fileName==NULL || fileName[0]==0)
    {
        std::string sf = getExeFileName();
        strcpy(buffer, sf.c_str());
        strcat(buffer, ".pid");
        fileName=buffer;
    }

    int fd = open(fileName, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
    if (fd<0)
    {
        printf("open file %s error\n", fileName);
        return -1;
    }

    sprintf(value, "%u\n", getpid());

    write(fd, value, sizeof(value));

    close(fd);

    return 0;
}
Esempio n. 6
0
int dropPIDFile(const char *fileName)
{
    char buffer[256];

    if (fileName==NULL || fileName[0]==0)
    {
        std::string sf = getExeFileName();
        strcpy(buffer, sf.c_str());
        strcat(buffer, ".pid");
        fileName=buffer;
    }

    return remove(fileName);
}
Esempio n. 7
0
BOOL WINAPI DllMain(HMODULE hDll, DWORD dwReason, PVOID pvReserved) {	
	if(dwReason == DLL_PROCESS_ATTACH) {
		OutputDebugString("GeDoSaTo: startup");
		DisableThreadLibraryCalls(hDll);
	}
	if(dwReason == DLL_PROCESS_DETACH) {
		OutputDebugString(format("GeDoSaTo: Exiting from %s", getExeFileName()).c_str());
		if(g_active) {
			OutputDebugString("GeDoSaTo: was active");
			Settings::get().shutdown();
			endDetour();
			SDLOG(-1, "===== end =\n");
			fclose(g_oFile);
		}
	}
    return true;
}
void RSManager::captureRTScreen(const string& stype) {
	SDLOG(0, "Capturing screenshot\n");
	char timebuf[128], dirbuff[512], buffer[512];
	time_t ltime;
	time(&ltime);
	struct tm *timeinfo;
	timeinfo = localtime(&ltime);
	strftime(timebuf, 128, "screenshot_%Y-%m-%d_%H-%M-%S.bmp", timeinfo);
	sprintf(dirbuff, "%sscreens\\%s", getInstallDirectory().c_str(), getExeFileName().c_str());
	CreateDirectory(dirbuff, NULL);
	sprintf(buffer, "%s\\%s", dirbuff, timebuf);
	SDLOG(0, " - to %s\n", buffer);
		
	IDirect3DSurface9 *render = NULL;
	d3ddev->GetRenderTarget(0, &render);
	if(render) {
		D3DXSaveSurfaceToFile(buffer, D3DXIFF_BMP, render, NULL, NULL);
		Console::get().add(format("Captured %s screenshot to %s", stype.c_str(), buffer));
	}
	SAFERELEASE(render);
}
void RSManagerDX9::captureRTScreen(const string& stype, IDirect3DSurface9 *rtArg) {
	SDLOG(0, "Capturing screenshot\n");
	static unsigned index = 0;
	char timebuf[128], dirbuff[512], buffer[512];
	time_t ltime;
	time(&ltime);
	struct tm *timeinfo;
	timeinfo = localtime(&ltime);
	strftime(timebuf, 128, "screenshot_%Y-%m-%d_%H-%M-%S", timeinfo);
	sprintf(dirbuff, "%sscreens\\%s", getInstallDirectory().c_str(), getExeFileName().c_str());
	CreateDirectory(dirbuff, NULL);
	sprintf(buffer, "%s\\%s_%u.png", dirbuff, timebuf, index++);
	SDLOG(0, " - to %s\n", buffer);

	IDirect3DSurface9 *render = rtArg;
	if(rtArg == NULL) d3ddev->GetRenderTarget(0, &render);
	if(render) {
		imgWriter->writeSurface(buffer, render);
		Console::get().add(format("Captured %s screenshot to %s", stype.c_str(), buffer));
	}
	if(rtArg == NULL) SAFERELEASE(render);
}
Esempio n. 10
0
BOOL WINAPI DllMain(HMODULE hDll, DWORD dwReason, PVOID pvReserved) {	
	if(dwReason == DLL_PROCESS_ATTACH) {
		OutputDebugString("GeDoSaTo: startup");

		// read install location from registry
		getInstallDirectory();
		OutputDebugString("GeDoSaTo: Got install dir");

		// don't attach to processes on the blacklist / not on the whitelist
		if(getUseBlacklist() ? onList(getExeFileName(), "blacklist.txt") : !onList(getExeFileName(), "whitelist.txt")) {
			OutputDebugString("GeDoSaTo: blacklisted / not whitelisted");
			if(getExeFileName() == "GeDoSaToTool") return true;
			return true;
		}
		g_active = true;
		OutputDebugString("GeDoSaTo: Active");
		
		// initialize log
		string logFn = format("logs\\%s_%s.log", getExeFileName().c_str(), getTimeString().c_str());
		std::replace(logFn.begin(), logFn.end(), ':', '-');
		std::replace(logFn.begin(), logFn.end(), ' ', '_');
		logFn = getInstalledFileName(logFn);
		fopen_s(&g_oFile, logFn.c_str(), "w");
		if(!g_oFile) OutputDebugString(format("GeDoSaTo: Error opening log fn %s", logFn.c_str()).c_str());
		else OutputDebugString(format("GeDoSaTo: Opening log fn %s, handle: %p", logFn.c_str(), g_oFile).c_str());
		OutputDebugString("GeDoSaTo: Log file initialized, let that take over");

		// startup
		sdlogtime(-1);
		SDLOG(-1, "===== start "INTERCEPTOR_NAME" %s = fn: %s\n", GeDoSaToVersion(), getExeFileName().c_str());
		SDLOG(-1, "===== installation directory: %s\n", getInstallDirectory().c_str());

		// load settings
		Settings::get().load();
		Settings::get().report();
		 
		KeyActions::get().load();
		KeyActions::get().report();

		if(!Settings::get().getPreventSteamOverlay() && Settings::get().getLoadSteamOverlayEarly()) {
			SDLOG(2, "Attempting to pre-load Steam overlay dll.\n");
			LoadLibrary("gameoverlayrenderer.dll");
		}

		if(Settings::get().getLoadD3DEarly()) {
			SDLOG(2, "Early d3d loading.\n");
			auto dllname = getSystemDllName("d3d9.dll");
			LoadLibrary(dllname.c_str());
		}

		// detour
		startDetour();
		return true;
	}
	if(dwReason == DLL_PROCESS_DETACH && g_active) {
		Settings::get().shutdown();
		endDetour();
		SDLOG(-1, "===== end =\n");
		fclose(g_oFile);
	}
    return false;
}