Skip to content

Commit

Permalink
Combined code into a single class (or else what was the point of havi…
Browse files Browse the repository at this point in the history
…ng the RInput object), reworked some of the bug fixes for CS:GO and TF2 that weren't working as intended, and made type casting more efficient and consistent
  • Loading branch information
VolsandJezuz committed Jan 5, 2016
1 parent b0245fa commit 9c6b587
Show file tree
Hide file tree
Showing 8 changed files with 359 additions and 440 deletions.
22 changes: 11 additions & 11 deletions RInput.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<Tool
Name="VCLinkerTool"
UseUnicodeResponseFiles="false"
AdditionalDependencies="shlwapi.lib dxguid.lib comctl32.lib detours.lib"
AdditionalDependencies="detours.lib dxguid.lib shlwapi.lib comctl32.lib"
Version="1.43-debug"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib&quot;;&quot;C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x86&quot;"
Expand Down Expand Up @@ -189,7 +189,7 @@
<Tool
Name="VCLinkerTool"
UseUnicodeResponseFiles="false"
AdditionalDependencies="shlwapi.lib dxguid.lib comctl32.lib detours.lib"
AdditionalDependencies="detours.lib dxguid.lib shlwapi.lib comctl32.lib"
Version="1.43"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib&quot;;&quot;C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x86&quot;"
Expand Down Expand Up @@ -252,7 +252,15 @@
>
</File>
<File
RelativePath=".\stdafx.h"
RelativePath=".\main.h"
>
</File>
<File
RelativePath=".\rawinput.h"
>
</File>
<File
RelativePath=".\versioninfo.h"
>
</File>
</Filter>
Expand All @@ -271,10 +279,6 @@
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\d3d9hook.cpp"
>
</File>
<File
RelativePath=".\main.cpp"
>
Expand All @@ -283,10 +287,6 @@
RelativePath=".\rawinput.cpp"
>
</File>
<File
RelativePath=".\stdafx.cpp"
>
</File>
</Filter>
<File
RelativePath=".\detours.lib"
Expand Down
89 changes: 0 additions & 89 deletions d3d9hook.cpp

This file was deleted.

4 changes: 3 additions & 1 deletion detours.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
// Copyright 1995-2001, Microsoft Corporation
//

#pragma once
#ifndef _DETOURS_H_
#define _DETOURS_H_

//////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -607,5 +608,6 @@ inline PBYTE DetourGenNop(PBYTE pbCode)
#endif DETOURS_INTERAL
#endif // __cplusplus

#endif // _DETOURS_H_
//
//////////////////////////////////////////////////////////////// End of File.
107 changes: 28 additions & 79 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,106 +29,34 @@
along with RInput. If not, see <http://www.gnu.org/licenses/>.
*/

#include "stdafx.h"
#include <string>
#include <shlwapi.h>
#include "main.h"

static HINSTANCE g_hInstance = NULL;

// Expose the entry point function called by RInput.exe
extern "C" __declspec(dllexport) void entryPoint();

int __stdcall DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
switch(dwReason)
{
case DLL_PROCESS_ATTACH:
// No need for a threaded entry
if (!DisableThreadLibraryCalls(hInstance))
return 0;
else
{
g_hInstance = hInstance;
char szEXEPath[MAX_PATH];

// Detect source games for enabling specific bug fixes
if (GetModuleFileNameA(NULL, szEXEPath, sizeof(szEXEPath)))
{
char TF2path[sizeof(szEXEPath)];
strcpy_s(TF2path, _countof(TF2path), szEXEPath);
PathStripPathA(szEXEPath);
// Bug fixes now limited to tested source games
char *source_exes[] = {"csgo.exe", "hl2.exe", "portal2.exe", NULL};

for (char **iSource_exes = source_exes; *iSource_exes != NULL; ++iSource_exes)
{
++n_sourceEXE;

if ((std::string)szEXEPath == (std::string)*iSource_exes)
{
if (n_sourceEXE == TF2)
{
// Make sure hl2.exe is TF2
PathRemoveFileSpecA(TF2path);
std::string sTF2path = (std::string)TF2path;
char testTF2[16];

for (size_t j = 1; j <= 15; ++j)
testTF2[j] = TF2path[sTF2path.size() + j - 15];

char tf2[16] = "Team Fortress 2";

for (int k = 1; k < 16; ++k)
{
// Check hl2.exe is TF2
if (testTF2[k] != tf2[k])
n_sourceEXE = NOBUGFIXES;
}
}

break;
}
}
}
else
n_sourceEXE = NOBUGFIXES;
}
return FALSE;

g_hInstance = hInstance;
break;

case DLL_PROCESS_DETACH:
// Stop CS:GO and TF2 D3D9 hooking
// Unhook cursor functions and unload from injected process
CRawInput::hookLibrary(false);
CRawInput::unload();
break;
}

return 1;
}

void unloadLibrary()
{
__asm
{
push -2
push 0
push g_hInstance
mov eax, TerminateThread
push eax
mov eax, FreeLibrary
jmp eax
}
}

void displayError(WCHAR* pwszError)
{
MessageBoxW(NULL, pwszError, L"Raw Input error!", MB_ICONERROR | MB_OK);
CRawInput::hookLibrary(false);
unloadLibrary();
return TRUE;
}

// Validate that we are working with at least Windows XP
inline bool validateVersion()
bool validateVersion()
{
DWORD dwVersion = GetVersion();
double fCompareVersion = LOBYTE(LOWORD(dwVersion)) + 0.1 * HIBYTE(LOWORD(dwVersion));
Expand Down Expand Up @@ -161,4 +89,25 @@ extern "C" __declspec(dllexport) void entryPoint()

if (!CRawInput::pollInput())
displayError(L"Failed to poll mouse input");
}

void unloadLibrary()
{
__asm
{
push -2
push 0
push g_hInstance
mov eax, TerminateThread
push eax
mov eax, FreeLibrary
jmp eax
}
}

void displayError(WCHAR* pwszError)
{
MessageBoxW(NULL, pwszError, L"Raw Input error!", MB_ICONERROR | MB_OK);
CRawInput::hookLibrary(FALSE);
unloadLibrary();
}
Loading

0 comments on commit 9c6b587

Please sign in to comment.