Fixed Sfall not working :)

Separated sfall initialization from WinAPI-specific code in main.cpp and InputFuncs.cpp
This commit is contained in:
phobos2077
2017-03-05 22:41:19 +07:00
parent 3a4b7fe3f5
commit 033221398e
3 changed files with 81 additions and 82 deletions
+16 -16
View File
@@ -30,8 +30,6 @@
#include "InputFuncs.h" #include "InputFuncs.h"
typedef HRESULT (_stdcall *DInputCreateProc)(HINSTANCE a,DWORD b,IDirectInputA** c,IUnknown* d);
namespace sfall namespace sfall
{ {
@@ -381,17 +379,9 @@ public:
} }
}; };
HRESULT _stdcall FakeDirectInputCreate_input(HINSTANCE a, DWORD b, IDirectInputA** c, IUnknown* d) { inline void InitInputFeatures() {
ZeroMemory(keysDown, sizeof(keysDown)); ZeroMemory(keysDown, sizeof(keysDown));
HMODULE dinput = LoadLibraryA("dinput.dll");
if (!dinput || dinput == INVALID_HANDLE_VALUE) return -1;
DInputCreateProc proc = (DInputCreateProc)GetProcAddress(dinput, "DirectInputCreateA");
if (!proc) return -1;
HRESULT hr = proc(a, b, c, d);
if (FAILED(hr)) return hr;
reverseMouse = GetConfigInt("Input", "ReverseMouseButtons", 0) != 0; reverseMouse = GetConfigInt("Input", "ReverseMouseButtons", 0) != 0;
useScrollWheel = GetConfigInt("Input", "UseScrollWheel", 1) != 0; useScrollWheel = GetConfigInt("Input", "UseScrollWheel", 1) != 0;
@@ -412,16 +402,26 @@ HRESULT _stdcall FakeDirectInputCreate_input(HINSTANCE a, DWORD b, IDirectInputA
debugEditorKey = GetConfigInt("Input", "DebugEditorKey", 0); debugEditorKey = GetConfigInt("Input", "DebugEditorKey", 0);
*c = (IDirectInputA*)new FakeDirectInput(*c);
keyboardLayout = GetKeyboardLayout(0); keyboardLayout = GetKeyboardLayout(0);
return hr;
} }
} }
typedef HRESULT (_stdcall *DInputCreateProc)(HINSTANCE a,DWORD b,IDirectInputA** c,IUnknown* d);
// This should be in global namespace // This should be in global namespace
HRESULT _stdcall FakeDirectInputCreate(HINSTANCE a, DWORD b, IDirectInputA** c, IUnknown* d) { HRESULT _stdcall FakeDirectInputCreate(HINSTANCE a, DWORD b, IDirectInputA** c, IUnknown* d) {
return sfall::FakeDirectInputCreate_input(a, b, c, d); HMODULE dinput = LoadLibraryA("dinput.dll");
if (!dinput || dinput == INVALID_HANDLE_VALUE) return -1;
DInputCreateProc proc = (DInputCreateProc)GetProcAddress(dinput, "DirectInputCreateA");
if (!proc) return -1;
HRESULT hr = proc(a, b, c, d);
if (FAILED(hr)) return hr;
*c = (IDirectInputA*)new sfall::FakeDirectInput(*c);
sfall::InitInputFeatures();
return hr;
} }
+3 -3
View File
@@ -39,12 +39,12 @@
#include "Graphics.h" #include "Graphics.h"
#include "LoadGameHook.h" #include "LoadGameHook.h"
typedef HRESULT (_stdcall *DDrawCreateProc)(void*, IDirectDraw**, void*);
typedef IDirect3D9* (_stdcall *D3DCreateProc)(UINT version);
namespace sfall namespace sfall
{ {
typedef HRESULT (_stdcall *DDrawCreateProc)(void*, IDirectDraw**, void*);
typedef IDirect3D9* (_stdcall *D3DCreateProc)(UINT version);
#define UNUSEDFUNCTION { DEBUGMESS("Unused function called: " __FUNCTION__); return DDERR_GENERIC; } #define UNUSEDFUNCTION { DEBUGMESS("Unused function called: " __FUNCTION__); return DDERR_GENERIC; }
#define SAFERELEASE(a) { if (a) { a->Release(); a = 0; } } #define SAFERELEASE(a) { if (a) { a->Release(); a = 0; } }
+9 -10
View File
@@ -119,9 +119,8 @@ size_t Translate(const char* section, const char* setting, const char* defaultVa
return GetPrivateProfileStringA(section, setting, defaultValue, buffer, bufSize, translationIni); return GetPrivateProfileStringA(section, setting, defaultValue, buffer, bufSize, translationIni);
} }
static void InitModules() {
static void DllMain2() { dlogr("In InitModules", DL_MAIN);
dlogr("In DllMain2", DL_MAIN);
auto& manager = ModuleManager::getInstance(); auto& manager = ModuleManager::getInstance();
@@ -169,7 +168,7 @@ static void DllMain2() {
manager.initAll(); manager.initAll();
dlogr("Leave DllMain2", DL_MAIN); dlogr("Leave InitModules", DL_MAIN);
} }
static void CompatModeCheck(HKEY root, const char* filepath, int extra) { static void CompatModeCheck(HKEY root, const char* filepath, int extra) {
@@ -196,8 +195,7 @@ static void CompatModeCheck(HKEY root, const char* filepath, int extra) {
} }
} }
inline bool DllMain1(HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) { inline void SfallInit() {
if (dwReason == DLL_PROCESS_ATTACH) {
// enabling debugging features // enabling debugging features
isDebug = (GetPrivateProfileIntA("Debugging", "Enable", 0, ddrawIni) != 0); isDebug = (GetPrivateProfileIntA("Debugging", "Enable", 0, ddrawIni) != 0);
if (isDebug) { if (isDebug) {
@@ -263,13 +261,14 @@ inline bool DllMain1(HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) {
GetConfigString("Main", "TranslationsINI", "./Translations.ini", translationIni, 65); GetConfigString("Main", "TranslationsINI", "./Translations.ini", translationIni, 65);
DllMain2(); InitModules();
}
return true;
} }
} }
bool _stdcall DllMain(HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) { bool _stdcall DllMain(HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) {
sfall::DllMain1(hDllHandle, dwReason, lpreserved); if (dwReason == DLL_PROCESS_ATTACH) {
sfall::SfallInit();
}
return true;
} }