Ejemplo n.º 1
0
void ReadConfig()
{
	SWIP ini("x360ce.ini");

    // Read global options
    g_bDisable = ini.get_bool("Options", "Disable");
    if(g_bDisable) return;

	g_bInitBeep = ini.get_bool("Options", "UseInitBeep", 1);

	bool file = ini.get_bool("Options", "Log");
	bool con = ini.get_bool("Options", "Console");

	if (con) LogConsole("x360ce", legal_notice);
	if (file)
	{
		char logfilename[MAX_PATH];
		sprintf_s(logfilename, "x360ce_%s_%u.log", exename.c_str(), GetTickCount());
		LogFile(logfilename);
	}

	PrintLog("Using config file:");
	PrintLog("%s", ini.get_inipath().c_str());

	DWORD ver = ini.get_uint("Options", "Version");
	if (ver != VERSION_CONFIG)
		PrintLog("WARNING: Configuration file version mismatch detected");

    // Simple Game Database support
    // InputHook
    if(pHooks)
    {
		bool override = ini.get_bool("InputHook", "Override");
        DWORD hookMask = ReadGameDatabase();
        if(hookMask && override == false)
        {
            pHooks->SetMask(hookMask);
            pHooks->Enable();
        }
        else
        {
			hookMask = ini.get_uint("InputHook", "HookMask");
            if(hookMask)
            {
                pHooks->SetMask(hookMask);
                pHooks->Enable();
            }
            else
            {
                bool hookCheck = ini.get_bool("InputHook", "HookLL");
                if(hookCheck) pHooks->EnableHook(iHook::HOOK_LL);

				hookCheck = ini.get_bool("InputHook", "HookCOM");
                if(hookCheck) pHooks->EnableHook(iHook::HOOK_COM);

				hookCheck = ini.get_bool("InputHook", "HookDI");
                if(hookCheck) pHooks->EnableHook(iHook::HOOK_DI);

				hookCheck = ini.get_bool("InputHook", "HookPIDVID");
                if(hookCheck) pHooks->EnableHook(iHook::HOOK_PIDVID);

				hookCheck = ini.get_bool("InputHook", "HookSA");
                if(hookCheck) pHooks->EnableHook(iHook::HOOK_SA);

				hookCheck = ini.get_bool("InputHook", "HookNAME");
                if(hookCheck) pHooks->EnableHook(iHook::HOOK_NAME);

				hookCheck = ini.get_bool("InputHook", "HookSTOP");
                if(hookCheck) pHooks->EnableHook(iHook::HOOK_STOP);

				hookCheck = ini.get_bool("InputHook", "HookWT");
                if(hookCheck) pHooks->EnableHook(iHook::HOOK_WT);

				hookCheck = ini.get_bool("InputHook", "HookNoTimeout");
				if (hookCheck) pHooks->EnableHook(iHook::HOOK_NOTIMEOUT);

                if(pHooks->GetMask()) pHooks->Enable();
            }
        }
        if(pHooks->GetState(iHook::HOOK_PIDVID))
        {
            DWORD vid = ini.get_uint("InputHook", "FakeVID",0x045E);
			DWORD pid = ini.get_uint("InputHook", "FakePID", 0x028E);
            if(vid != 0x045E || pid != 0x28E) pHooks->SetFakePIDVID(MAKELONG(vid,pid));
        }

		DWORD timeout = ini.get_uint("InputHook", "Timeout", 30);
		pHooks->SetTimeout(timeout);
    }
Ejemplo n.º 2
0
InputHook::InputHook() :
m_hookmask(HOOK_COM),
m_fakepidvid(MAKELONG(0x045E, 0x028E)),
m_timeout(0),
m_timeout_thread(INVALID_HANDLE_VALUE)
{
	IniFile ini;
	std::string inipath("x360ce.ini");
	if (!ini.Load(inipath))
		CheckCommonDirectory(&inipath, "x360ce");
	if (!ini.Load(inipath)) return;

	bool read_from_database = ReadGameDatabase();

	if (!read_from_database)
	{
		if (!ini.Get("InputHook", "HookMask", &m_hookmask, HOOK_COM))
		{
			bool check = false;
			ini.Get("InputHook", "HookLL", &check);
			if (check) m_hookmask |= HOOK_LL;

			ini.Get("InputHook", "HookCOM", &check);
			if (check) m_hookmask |= HOOK_COM;

			ini.Get("InputHook", "HookDI", &check);
			if (check) m_hookmask |= HOOK_DI;

			ini.Get("InputHook", "HookPIDVID", &check);
			if (check) m_hookmask |= HOOK_PIDVID;

			ini.Get("InputHook", "HookSA", &check);
			if (check) m_hookmask |= HOOK_SA;

			ini.Get("InputHook", "HookNAME", &check);
			if (check) m_hookmask |= HOOK_NAME;

			ini.Get("InputHook", "HookSTOP", &check);
			if (check) m_hookmask |= HOOK_STOP;

			ini.Get("InputHook", "HookWT", &check);
			if (check) m_hookmask |= HOOK_WT;
		}

		if (GetState(HOOK_PIDVID))
		{
			u32 vid;
			u32 pid;
			ini.Get<u32>("InputHook", "FakeVID", &vid, 0x045E);
			ini.Get<u32>("InputHook", "FakePID", &pid, 0x028E);

			if (vid != 0x045E || pid != 0x28E)
				m_fakepidvid = MAKELONG(vid, pid);
		}
	}

	if (m_hookmask)
	{
		PrintLog("InputHook starting...");

		// Initalize InputHook Devices
		for (u32 i = 0; i < XUSER_MAX_COUNT; ++i)
		{
			std::string section;
			std::string key = StringFormat("PAD%u", i + 1);
			if (!ini.Get("Mappings", key, &section))
				continue;

			u32 index = 0;
			if (!ini.Get(section, "UserIndex", &index))
				index = i;

			std::string buffer;
			GUID productid = GUID_NULL;
			GUID instanceid = GUID_NULL;

			if (ini.Get(section, "ProductGUID", &buffer))
				StringToGUID(&productid, buffer);

			if (ini.Get(section, "InstanceGUID", &buffer))
				StringToGUID(&instanceid, buffer);

			if (!IsEqualGUID(productid, GUID_NULL) && !IsEqualGUID(instanceid, GUID_NULL))
			{
				m_devices.push_back(InputHookDevice(index, productid, instanceid));
			}
		}
	}

	if (!m_devices.empty())
	{
		if (!read_from_database)
			ini.Get<u32>("InputHook", "Timeout", &m_timeout, 45);

		std::string maskname;
		if (MaskToName(&maskname, m_hookmask))
			PrintLog("HookMask 0x%08X: %s", m_hookmask, maskname.c_str());

		MH_Initialize();

		if (GetState(HOOK_LL))
			HookLL();

		if (GetState(HOOK_COM))
			HookCOM();

		if (GetState(HOOK_DI))
			HookDI();

		if (GetState(HOOK_SA))
			HookSA();

		if (GetState(HOOK_WT))
			HookWT();

		MH_EnableHook(MH_ALL_HOOKS);
	}
}