Subversion Repositories spk

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
11 cycrow 1
#include <iostream>
2
#include <windows.h>
3
#include <TCHAR.h>
4
#include "..\Direct3D-Hook\Direct3D-Hook.h"
5
 
6
#include "../../Base Engine/Common/String.h"
7
 
8
int main ( int argc, char **argv )
9
/*int APIENTRY WinMain(HINSTANCE hInstance,
10
                     HINSTANCE hPrevInstance,
11
                     LPSTR     lpCmdLine,
12
                     int       nCmdShow)*/
13
{
14
	String filename;
15
 
16
 
17
	if ( argc >= 2 )
18
		filename = argv[1];
19
 
20
	if ( filename.Right(4).lower() != ".exe" )
21
	{
22
		if ( filename.Empty() )
23
			filename = "x3.exe";
24
		else
25
			filename += "/x3.exe";
26
	}
27
	filename = filename.FindReplace ( "/", "\\" );
28
 
29
	std::cout << "Running Program: " << filename.c_str() << std::endl;
30
 
31
	// check if the file exists
32
	FILE *id = fopen ( filename.c_str(), "r+" );
33
	if ( !id )
34
	{
35
		std::cout<< "Could not find the main executable to run, exiting..." << std::endl;
36
		return 1;
37
	}
38
 
39
	fclose ( id );
40
 
41
	// Create/update the registry entry
42
	HKEY regKey = 0;
43
	if(ERROR_SUCCESS != RegCreateKeyEx(HKEY_CURRENT_USER, L"Software\\Direct3D-Hook", 0, 0, 0, KEY_READ | KEY_WRITE,
44
		0, &regKey, 0))
45
	{
46
		std::cout<< "Could not open or create registry key: HKEY_CURRENT_USER\\Software\\Direct3D-Hook"<< std::endl
47
			<< "Press enter to exit..."<< std::endl;
48
		std::cin.ignore();
49
		return 2;
50
	}
51
 
52
/*	if ( ERROR_SUCCESS != RegSetValueEx(regKey, 0, 0, REG_SZ, 
53
		reinterpret_cast<char*>((char *)filename.c_str()),
54
		(filename.Length() + 1) * sizeof(char)) )*/
55
 
56
 
57
//	if ( ERROR_SUCCESS != RegSetValueEx(regKey, 0, 0, REG_SZ, _t(filename.c_str()), filename.Length() + 1) )
58
	if ( ERROR_SUCCESS != RegSetValueExA ( regKey, 0, 0, REG_SZ, reinterpret_cast<BYTE*>("x3.exe"), 6 ) )
59
	{
60
		std::cout<< "Could not update key value."<< std::endl
61
			<< "Press enter to exit..."<< std::endl;
62
		std::cin.ignore();
63
		return 3;
64
	}
65
	std::cout<< "Hooking Direct3D...";
66
	InstallHook();
67
 
68
	String f = filename;
69
	for ( int i = 2; i < argc; i++ )
70
		f += String(" ") + argv[i];
71
 
72
	system ( f.c_str() );
73
 
74
	RemoveHook();
75
 
76
	return 0;
77
}