Ejemplo n.º 1
0
void Ini_SetString(const char *category, const char *key, const char *value, char *source)
{
	char *s;
	char buffer[120];

	if (source == NULL || category == NULL) return;

	s = Ini_GetString(category, NULL, NULL, NULL, 0, source);
	if (s == NULL && key != NULL) {
		sprintf(buffer, "\r\n[%s]\r\n", category);
		strcat(source, buffer);
	}

	s = Ini_GetString(category, key, NULL, NULL, 0, source);
	if (s != NULL) {
		uint16 count = strcspn(s, "\r\n");
		if (count != 0) {
			strcpy(s, s + count + 1);
		}
		if (*s == '\n') {
			strcpy(s, s + 1);
		}
	} else {
		s = Ini_GetString(category, NULL, NULL, NULL, 0, source);
	}

	if (value != NULL) {
		sprintf(buffer, "%s=%s\r\n", key, value);
		memmove(s + strlen(buffer), s, strlen(s) + 1);
		memcpy(s, buffer, strlen(buffer));
	}
}
Ejemplo n.º 2
0
static void ini_test2()
{
		arString_t	*str;
		iniObject_t *obj;
		str = AR_CreateString();
		
		obj = NULL;

		if(AR_LoadBomTextFile(L"C:\\Users\\liupeng\\Desktop\\360zipplugin.ini", NULL, str) != AR_S_YES)
		{
				goto END_POINT;
		}

		obj = Ini_CreateObject();

		if(obj == NULL)
		{
				goto END_POINT;
		}

		if(Ini_LoadObjectFromString(obj, AR_GetStringCString(str)) != AR_S_YES)
		{
				goto END_POINT;
		}
		
		/*
		printf("Ini_GetInt == %d\r\n", Ini_GetInt(obj,  INI_EMPTY_SECTION_NAME, L"a", 0));
		printf("Ini_GetUInt == %u\r\n", Ini_GetUInt(obj,  INI_EMPTY_SECTION_NAME, L"b", 0));
		printf("Ini_GetFloat == %g\r\n", Ini_GetFloat(obj,  INI_EMPTY_SECTION_NAME, L"c", 0.0f));
		*/


		{
				const wchar_t *files = Ini_GetString(obj, L"360main", L"files0");
				printf("%ls\r\n", files);
		}

		
		{
				const wchar_t *files = Ini_GetString(obj, L"RarFiles.lst", L"URL");
				printf("%ls\r\n", files);
		}

END_POINT:
		if(obj)
		{
				Ini_DestroyObject(obj);
				obj = NULL;
		}

		if(str)
		{
				AR_DestroyString(str);
				str = NULL;
		}
}
Ejemplo n.º 3
0
static void StrategicMap_ReadProgression(HouseType houseID, int campaignID, StrategicMapData* map)
{
	int count = 0;

	char category[16];
	snprintf(category, sizeof(category), "GROUP%d", campaignID);

	for (int i = 0; i < HOUSE_MAX; i++)
	{
		const HouseType h = (HouseType)((houseID + i) % HOUSE_MAX);

		char key[16];
		strncpy(key, g_table_houseInfo[h].name, 3);
		key[3] = '\0';

		char buf[128];
		if (Ini_GetString(category, key, NULL, buf, sizeof(buf), (char*)g_fileRegionINI) == NULL)
			continue;

		char* s = buf;
		while (*s != '\0')
		{
			const int region = atoi(s);

			if (region != 0)
			{
				snprintf(key, sizeof(key), "%sTXT%d",  g_table_languageInfo.suffix, region);
				Ini_GetString(category, key, NULL, map->progression[count].text, sizeof(map->progression[count].text), (char*)g_fileRegionINI);

				/* Attempt non-language-specific TXT. */
				if (map->progression[count].text[0] == '\0')
				{
					snprintf(key, sizeof(key), "TXT%d", region);
					Ini_GetString(category, key, NULL, map->progression[count].text, sizeof(map->progression[count].text), (char*)g_fileRegionINI);
				}
			}

			while (*s != '\0')
			{
				if (*s++ == ',')
					break;
			}

			map->progression[count].houseID = h;
			map->progression[count].region = region;
			count++;
		}
	}

	for (; count < STRATEGIC_MAP_MAX_PROGRESSION; count++)
	{
		map->progression[count].houseID = HOUSE_INVALID;
		map->progression[count].region = -1;
	}
}
Ejemplo n.º 4
0
static void Scenario_Load_House(uint8 houseID)
{
	const char *houseName = g_table_houseInfo[houseID].name;
	char *houseType;
	char buf[128];
	char *b;
	House *h;

	/* Get the type of the House (CPU / Human) */
	Ini_GetString(houseName, "Brain", "NONE", buf, 127, s_scenarioBuffer);
	for (b = buf; *b != '\0'; b++) if (*b >= 'a' && *b <= 'z') *b += 'A' - 'a';
	houseType = strstr("HUMAN$CPU", buf);
	if (houseType == NULL) return;

	/* Create the house */
	h = House_Allocate(houseID);

	h->credits      = Ini_GetInteger(houseName, "Credits",  0, s_scenarioBuffer);
	h->creditsQuota = Ini_GetInteger(houseName, "Quota",    0, s_scenarioBuffer);
	h->unitCountMax = Ini_GetInteger(houseName, "MaxUnit", 39, s_scenarioBuffer);

	/* For 'Brain = Human' we have to set a few additional things */
	if (*houseType != 'H') return;

	h->flags.human = true;

	g_playerHouseID       = houseID;
	g_playerHouse         = h;
	g_playerCreditsNoSilo = h->credits;
}
Ejemplo n.º 5
0
static void Scenario_Load_Chunk(const char *category, void (*ptr)(const char *key, char *settings))
{
	char *buffer = g_readBuffer;

	Ini_GetString(category, NULL, NULL, g_readBuffer, g_readBufferSize, s_scenarioBuffer);
	while (true) {
		char buf[127];

		if (*buffer == '\0') break;

		Ini_GetString(category, buffer, NULL, buf, 127, s_scenarioBuffer);

		(*ptr)(buffer, buf);
		buffer += strlen(buffer) + 1;
	}
}
Ejemplo n.º 6
0
static void Scenario_Load_General()
{
	g_scenario.winFlags          = Ini_GetInteger("BASIC", "WinFlags",    0,                            s_scenarioBuffer);
	g_scenario.loseFlags         = Ini_GetInteger("BASIC", "LoseFlags",   0,                            s_scenarioBuffer);
	g_scenario.mapSeed           = Ini_GetInteger("MAP",   "Seed",        0,                            s_scenarioBuffer);
	g_scenario.timeOut           = Ini_GetInteger("BASIC", "TimeOut",     0,                            s_scenarioBuffer);
	g_minimapPosition            = Ini_GetInteger("BASIC", "TacticalPos", g_minimapPosition,            s_scenarioBuffer);
	g_selectionRectanglePosition = Ini_GetInteger("BASIC", "CursorPos",   g_selectionRectanglePosition, s_scenarioBuffer);
	g_scenario.mapScale          = Ini_GetInteger("BASIC", "MapScale",    0,                            s_scenarioBuffer);

	Ini_GetString("BASIC", "BriefPicture", "HARVEST.WSA",  g_scenario.pictureBriefing, 14, s_scenarioBuffer);
	Ini_GetString("BASIC", "WinPicture",   "WIN1.WSA",     g_scenario.pictureWin,      14, s_scenarioBuffer);
	Ini_GetString("BASIC", "LosePicture",  "LOSTBILD.WSA", g_scenario.pictureLose,     14, s_scenarioBuffer);

	g_viewportPosition  = g_minimapPosition;
	g_selectionPosition = g_selectionRectanglePosition;
}
Ejemplo n.º 7
0
DWORD GetConfig(wchar_t *Button, WCHAR* File)
{
    WCHAR buffer[255];

    Ini_GetString(CONTROLLER_SECTION, Button, L"0x0", buffer, 255, File);

    return wcstol(buffer, NULL, 16);
}
Ejemplo n.º 8
0
int Ini_GetInteger(const char *category, const char *key, int defaultValue, char *source)
{
	char value[16];
	char buffer[16];

	sprintf(value, "%d", defaultValue);

	Ini_GetString(category, key, value, buffer, 15, source);
	return atoi(buffer);
}
Ejemplo n.º 9
0
static void StrategicMap_ReadArrows(int campaignID, StrategicMapData* map)
{
	char category[16];
	int count = 0;
	bool any_unattempted_regions = false;

	snprintf(category, sizeof(category), "GROUP%d", campaignID);

	for (int i = 0; i < 5; i++)
	{
		char key[8];
		char buf[128];
		int index, shapeID, x, y;

		snprintf(key, sizeof(key), "REG%d", i + 1);

		if (Ini_GetString(category, key, NULL, buf, sizeof(buf), (char*)g_fileRegionINI) == NULL)
			break;

		if (sscanf(buf, "%d,%d,%d,%d", &index, &shapeID, &x, &y) != 4)
			continue;

		assert(count < STRATEGIC_MAP_MAX_ARROWS);

		if ((index != 0) && !StrategicMap_IsRegionAttempted(index))
			any_unattempted_regions = true;

		map->arrow[count].index = index;
		map->arrow[count].shapeID = SHAPE_ARROW + shapeID;
		map->arrow[count].x = x;
		map->arrow[count].y = y;
		count++;
	}

	if (any_unattempted_regions)
	{
		for (int i = 0; i < count; i++)
		{
			if (StrategicMap_IsRegionAttempted(map->arrow[i].index))
				map->arrow[i].index = -1;
		}
	}
	else
	{
		g_strategicRegionBits = 0;
	}

	for (; count < STRATEGIC_MAP_MAX_ARROWS; count++)
	{
		map->arrow[count].index = -1;
		map->arrow[count].shapeID = SHAPE_INVALID;
	}
}
Ejemplo n.º 10
0
char *IniFile_GetString(const char *key, const char *defaultValue, char *dest, uint16 length)
{
	char * p;
	uint16 i;
	if (g_openduneini == NULL) return NULL;
	p = Ini_GetString("opendune", key, defaultValue, dest, length, g_openduneini);
	if (p) {
		/* Trim space from the beginning of the dest */
		for (i = 0; i < length && (dest[i] == ' ' || dest[i] == '\t') && (dest[i] != '\0'); i++);
		if (i > 0 && i < length) memmove(dest, dest+i, length - i);
	}
	return p;
}
Ejemplo n.º 11
0
/** 
 * 连接游戏服务器
 */
void CMole2dGameFrameDlg::ConnectLoginServer(std::string name,std::string pw)
{
	if(name.empty() || pw.empty()) return;

	m_totalOnlinePlayers=0;
	m_loginName = name;
	m_loginPW = pw;

	Ini_SetFile(IDD_CLIENT_CONFIG_FILE);

	std::string serverip = Ini_GetString("SystemSet","ServerIp","127.0.0.1");
	int serverport = Ini_GetInt("SystemSet","ServerPort",1234);

	if(!serverip.empty() && serverport > 0)
		Connect(serverip,serverport);

	AfxGetMainWnd()->SendMessage(IDD_SHOW_CONN_TIP,5,0);	
}
Ejemplo n.º 12
0
static void Scenario_Load_MapParts(const char *key, void (*ptr)(uint16 packed, Tile *t))
{
	char *s;
	char buf[128];

	Ini_GetString("MAP", key, '\0', buf, 127, s_scenarioBuffer);

	s = strtok(buf, ",\r\n");
	while (s != NULL) {
		uint16 packed;
		Tile *t;

		packed = atoi(s);
		t = &g_map[packed];

		(*ptr)(packed, t);

		s = strtok(NULL, ",\r\n");
	}
}
Ejemplo n.º 13
0
void StrategicMap_Init()
{
	g_playerHouseID = HOUSE_HARKONNEN;
	Sprites_CPS_LoadRegionClick();

	for (int region = 1; region <= STRATEGIC_MAP_MAX_REGIONS; region++)
	{
		char key[4];
		char buf[128];

		snprintf(key, sizeof(key), "%d", region);

		if (Ini_GetString("PIECES", key, NULL, buf, sizeof(buf), (char*)g_fileRegionINI) == NULL)
			exit(1);

		if (sscanf(buf, "%d,%d", &region_data[region].x, &region_data[region].y) != 2)
			exit(1);

		region_data[region].x += 8;
		region_data[region].y += 24;
	}
}
Ejemplo n.º 14
0
static void StrategicMap_ReadOwnership(int campaignID, StrategicMapData* map)
{
	for (int region = 0; region <= STRATEGIC_MAP_MAX_REGIONS; region++)
	{
		map->owner[region] = HOUSE_INVALID;
	}

	for (int i = 0; i < campaignID; i++)
	{
		char category[16];
		snprintf(category, sizeof(category), "GROUP%d", i);

		for (HouseType houseID = HOUSE_HARKONNEN; houseID < HOUSE_MAX; houseID++)
		{
			char key[4];
			strncpy(key, g_table_houseInfo[houseID].name, 3);
			key[3] = '\0';

			char buf[128];
			if (Ini_GetString(category, key, NULL, buf, sizeof(buf), (char*)g_fileRegionINI) == NULL)
				continue;

			const char* s = buf;
			while (*s != '\0')
			{
				const int region = atoi(s);

				if (region != 0)
					map->owner[region] = houseID;

				while (*s != '\0')
				{
					if (*s++ == ',')
						break;
				}
			}
		}
	}
}
Ejemplo n.º 15
0
void	CMultiMoveClientDlg::init_dlg_items()
{
		
		const wchar_t *ip_str;
		uint_64_t port;
		CString port_str;
		

		ip_str = Ini_GetString(m_cfg, MM_CLI_CONFIG_SEC, MM_CLI_CONFIG_UP_IP);
		port   = Ini_GetUInt(m_cfg, MM_CLI_CONFIG_SEC, MM_CLI_CONFIG_UP_PORT, 0);

		port_str.Format(TEXT("%I64u"), port);

		if(ip_str == NULL || inet_addr_wcs(ip_str) == INADDR_NONE)
		{
				ip_str = TEXT("0.0.0.0");
		}
		
		m_up_ip.SetWindowText(ip_str);
		m_up_port.SetWindowText(port_str);

		/***************************************Down*****************************/

		ip_str = Ini_GetString(m_cfg, MM_CLI_CONFIG_SEC, MM_CLI_CONFIG_DOWN_IP);
		port   = Ini_GetUInt(m_cfg, MM_CLI_CONFIG_SEC, MM_CLI_CONFIG_DOWN_PORT, 0);

		port_str.Format(TEXT("%I64u"), port);

		if(ip_str == NULL || inet_addr_wcs(ip_str) == INADDR_NONE)
		{
				ip_str = TEXT("0.0.0.0");
		}

		m_down_ip.SetWindowText(ip_str);
		m_down_port.SetWindowText(port_str);

		/***************************************Left*****************************/


		ip_str = Ini_GetString(m_cfg, MM_CLI_CONFIG_SEC, MM_CLI_CONFIG_LEFT_IP);
		port   = Ini_GetUInt(m_cfg, MM_CLI_CONFIG_SEC, MM_CLI_CONFIG_LEFT_PORT, 0);

		port_str.Format(TEXT("%I64u"), port);

		if(ip_str == NULL || inet_addr_wcs(ip_str) == INADDR_NONE)
		{
				ip_str = TEXT("0.0.0.0");
		}

		m_left_ip.SetWindowText(ip_str);
		m_left_port.SetWindowText(port_str);

		/***************************************Right*****************************/

		ip_str = Ini_GetString(m_cfg, MM_CLI_CONFIG_SEC, MM_CLI_CONFIG_RIGHT_IP);
		port   = Ini_GetUInt(m_cfg, MM_CLI_CONFIG_SEC, MM_CLI_CONFIG_RIGHT_PORT, 0);

		port_str.Format(TEXT("%I64u"), port);

		if(ip_str == NULL || inet_addr_wcs(ip_str) == INADDR_NONE)
		{
				ip_str = TEXT("0.0.0.0");
		}
	
		m_right_ip.SetWindowText(ip_str);
		m_right_port.SetWindowText(port_str);

}
Ejemplo n.º 16
0
static void ReadProfileIni(const char *filename)
{
	char *source;
	char *key;
	char *keys;
	char buffer[120];
	uint16 locsi;

	if (filename == NULL) return;
	if (!File_Exists(filename)) return;

	source = GFX_Screen_Get_ByIndex(SCREEN_1);

	memset(source, 0, 32000);
	File_ReadBlockFile(filename, source, GFX_Screen_GetSize_ByIndex(SCREEN_1));

	keys = source + strlen(source) + 5000;
	*keys = '\0';

	Ini_GetString("construct", NULL, keys, keys, 2000, source);

	for (key = keys; *key != '\0'; key += strlen(key) + 1) {
		ObjectInfo *oi = NULL;
		uint16 count;
		uint8 type;
		uint16 buildCredits;
		uint16 buildTime;
		uint16 fogUncoverRadius;
		uint16 availableCampaign;
		uint16 sortPriority;
		uint16 priorityBuild;
		uint16 priorityTarget;
		uint16 hitpoints;

		type = Unit_StringToType(key);
		if (type != UNIT_INVALID) {
			oi = &g_table_unitInfo[type].o;
		} else {
			type = Structure_StringToType(key);
			if (type != STRUCTURE_INVALID) oi = &g_table_structureInfo[type].o;
		}

		if (oi == NULL) continue;

		Ini_GetString("construct", key, buffer, buffer, 120, source);
		count = sscanf(buffer, "%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu", &buildCredits, &buildTime, &hitpoints, &fogUncoverRadius, &availableCampaign, &priorityBuild, &priorityTarget, &sortPriority);
		oi->buildCredits      = buildCredits;
		oi->buildTime         = buildTime;
		oi->hitpoints         = hitpoints;
		oi->fogUncoverRadius  = fogUncoverRadius;
		oi->availableCampaign = availableCampaign;
		oi->priorityBuild     = priorityBuild;
		oi->priorityTarget    = priorityTarget;
		if (count <= 7) continue;
		oi->sortPriority = (uint8)sortPriority;
	}

	if (g_debugGame) {
		for (locsi = 0; locsi < UNIT_MAX; locsi++) {
			ObjectInfo *oi = &g_table_unitInfo[locsi].o;

			sprintf(buffer, "%*s%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d",
				15 - (int)strlen(oi->name), "", oi->buildCredits, oi->buildTime, oi->hitpoints, oi->fogUncoverRadius,
				oi->availableCampaign, oi->priorityBuild, oi->priorityTarget, oi->sortPriority);

			Ini_SetString("construct", oi->name, buffer, source);
		}

		for (locsi = 0; locsi < STRUCTURE_MAX; locsi++) {
			ObjectInfo *oi = &g_table_unitInfo[locsi].o;

			sprintf(buffer, "%*s%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d",
				15 - (int)strlen(oi->name), "", oi->buildCredits, oi->buildTime, oi->hitpoints, oi->fogUncoverRadius,
				oi->availableCampaign, oi->priorityBuild, oi->priorityTarget, oi->sortPriority);

			Ini_SetString("construct", oi->name, buffer, source);
		}
	}

	*keys = '\0';

	Ini_GetString("combat", NULL, keys, keys, 2000, source);

	for (key = keys; *key != '\0'; key += strlen(key) + 1) {
		uint16 damage;
		uint16 movingSpeedFactor;
		uint16 fireDelay;
		uint16 fireDistance;

		Ini_GetString("combat", key, buffer, buffer, 120, source);
		String_Trim(buffer);
		if (sscanf(buffer, "%hu,%hu,%hu,%hu", &fireDistance, &damage, &fireDelay, &movingSpeedFactor) < 4) continue;

		for (locsi = 0; locsi < UNIT_MAX; locsi++) {
			UnitInfo *ui = &g_table_unitInfo[locsi];

			if (strcasecmp(ui->o.name, key) != 0) continue;

			ui->damage            = damage;
			ui->movingSpeedFactor = movingSpeedFactor;
			ui->fireDelay         = fireDelay;
			ui->fireDistance      = fireDistance;
			break;
		}
	}

	if (!g_debugGame) return;

	for (locsi = 0; locsi < UNIT_MAX; locsi++) {
		const UnitInfo *ui = &g_table_unitInfo[locsi];

		sprintf(buffer, "%*s%4d,%4d,%4d,%4d", 15 - (int)strlen(ui->o.name), "", ui->fireDistance, ui->damage, ui->fireDelay, ui->movingSpeedFactor);
		Ini_SetString("combat", ui->o.name, buffer, source);
	}
}
Ejemplo n.º 17
0
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, &sectionHandle);

    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,
        &sectionInfo,
        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;
}