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; } }
+62 -63
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,80 +195,80 @@ 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) { LoggingInit();
LoggingInit(); }
}
char filepath[MAX_PATH]; char filepath[MAX_PATH];
GetModuleFileName(0, filepath, MAX_PATH); GetModuleFileName(0, filepath, MAX_PATH);
CRC(filepath); CRC(filepath);
if (!isDebug || !GetPrivateProfileIntA("Debugging", "SkipCompatModeCheck", 0, ddrawIni)) { if (!isDebug || !GetPrivateProfileIntA("Debugging", "SkipCompatModeCheck", 0, ddrawIni)) {
int is64bit; int is64bit;
typedef int (_stdcall *chk64bitproc)(HANDLE, int*); typedef int (_stdcall *chk64bitproc)(HANDLE, int*);
HMODULE h=LoadLibrary("Kernel32.dll"); HMODULE h = LoadLibrary("Kernel32.dll");
chk64bitproc proc = (chk64bitproc)GetProcAddress(h, "IsWow64Process"); chk64bitproc proc = (chk64bitproc)GetProcAddress(h, "IsWow64Process");
if(proc) proc(GetCurrentProcess(), &is64bit); if(proc) proc(GetCurrentProcess(), &is64bit);
else is64bit=0; else is64bit=0;
FreeLibrary(h); FreeLibrary(h);
CompatModeCheck(HKEY_CURRENT_USER, filepath, is64bit?KEY_WOW64_64KEY:0); CompatModeCheck(HKEY_CURRENT_USER, filepath, is64bit?KEY_WOW64_64KEY:0);
CompatModeCheck(HKEY_LOCAL_MACHINE, filepath, is64bit?KEY_WOW64_64KEY:0); CompatModeCheck(HKEY_LOCAL_MACHINE, filepath, is64bit?KEY_WOW64_64KEY:0);
} }
// ini file override // ini file override
bool cmdlineexists = false; bool cmdlineexists = false;
char* cmdline = GetCommandLineA(); char* cmdline = GetCommandLineA();
if (GetPrivateProfileIntA("Main", "UseCommandLine", 0, ddrawIni)) { if (GetPrivateProfileIntA("Main", "UseCommandLine", 0, ddrawIni)) {
while (cmdline[0] == ' ') cmdline++; while (cmdline[0] == ' ') cmdline++;
bool InQuote = false; bool InQuote = false;
int count = -1; int count = -1;
while (true) { while (true) {
count++; count++;
if (cmdline[count] == 0) break;; if (cmdline[count] == 0) break;;
if (cmdline[count] == ' ' && !InQuote) break; if (cmdline[count] == ' ' && !InQuote) break;
if (cmdline[count] == '"') { if (cmdline[count] == '"') {
InQuote = !InQuote; InQuote = !InQuote;
if (!InQuote) break; if (!InQuote) break;
}
}
if (cmdline[count] != 0) {
count++;
while (cmdline[count] == ' ') count++;
cmdline = &cmdline[count];
cmdlineexists = true;
} }
} }
if (cmdline[count] != 0) {
count++;
while (cmdline[count] == ' ') count++;
cmdline = &cmdline[count];
cmdlineexists = true;
}
}
if (cmdlineexists && strlen(cmdline)) { if (cmdlineexists && strlen(cmdline)) {
strcpy_s(ini, ".\\"); strcpy_s(ini, ".\\");
strcat_s(ini, cmdline); strcat_s(ini, cmdline);
HANDLE h = CreateFileA(cmdline, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0); HANDLE h = CreateFileA(cmdline, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
if (h != INVALID_HANDLE_VALUE) CloseHandle(h); if (h != INVALID_HANDLE_VALUE) CloseHandle(h);
else { else {
MessageBox(0, "You gave a command line argument to fallout, but it couldn't be matched to a file\n" \ MessageBox(0, "You gave a command line argument to fallout, but it couldn't be matched to a file\n" \
"Using default ddraw.ini instead", "Warning", MB_TASKMODAL); "Using default ddraw.ini instead", "Warning", MB_TASKMODAL);
strcpy_s(ini, ddrawIni);
}
} else {
strcpy_s(ini, ddrawIni); strcpy_s(ini, ddrawIni);
} }
} else {
GetConfigString("Main", "TranslationsINI", "./Translations.ini", translationIni, 65); strcpy_s(ini, ddrawIni);
DllMain2();
} }
return true;
GetConfigString("Main", "TranslationsINI", "./Translations.ini", translationIni, 65);
InitModules();
} }
} }
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;
} }