Skip to content

Commit

Permalink
Merge pull request #539 from RamonUnch/Add-support-for-non-portable-mode
Browse files Browse the repository at this point in the history
Add support for non-portable mode
  • Loading branch information
RamonUnch authored May 25, 2024
2 parents 4b33dea + ba04c85 commit abc5baf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
26 changes: 24 additions & 2 deletions altsnap.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ int HookSystem()
return 1;
}
}
HWND (WINAPI *Load)(HWND) = (HWND (WINAPI *)(HWND))GetProcAddress(hinstDLL, LOAD_PROC);
HWND (WINAPI *Load)(HWND, const TCHAR *) = (HWND (WINAPI *)(HWND, const TCHAR*))GetProcAddress(hinstDLL, LOAD_PROC);
if(Load) {
g_dllmsgHKhwnd = Load(g_hwnd);
g_dllmsgHKhwnd = Load(g_hwnd, inipath);
}

LOG("HOOKS.DLL Loaded");
Expand Down Expand Up @@ -438,6 +438,28 @@ int WINAPI tWinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, TCHAR *params, int
GetModuleFileName(NULL, inipath, ARR_SZ(inipath));
inipath[MAX_PATH-1] = '\0';
lstrcpy_s(&inipath[lstrlen(inipath)-3], 4, TEXT("ini"));
if (INVALID_FILE_ATTRIBUTES == GetFileAttributes(inipath)
&& GetEnvironmentVariable(TEXT("APPDATA"), NULL, 0)) {
// .ini file is not in current directorry, and APPDATA exists
// we should look for %APPDATA%\AltSnap\AltSnap.ini
TCHAR userini[MAX_PATH];
GetEnvironmentVariable(TEXT("APPDATA"), userini, ARR_SZ(userini));
lstrcat_s(userini, ARR_SZ(userini), TEXT("\\AltSnap"));
if (INVALID_FILE_ATTRIBUTES == GetFileAttributes(userini)) {
CreateDirectory(userini, NULL);
LOG("CreateDirectory(%S)", userini);
}
// Full user ini name.
lstrcat_s(userini, ARR_SZ(userini), TEXT("\\AltSnap.ini"));
if (INVALID_FILE_ATTRIBUTES == GetFileAttributes(userini)) {
// Copy AltSnap.dni (Default ini file) if no ini present
lstrcpy_s(&inipath[lstrlen(inipath)-3], 4, TEXT("dni"));
CopyFile(inipath, userini, FALSE); // AltSnap.dni -> AltSnap.ini
LOG("CopyFile(%S -> %S)", inipath, userini);
}

lstrcpy_s(inipath, ARR_SZ(inipath), userini);
}
LOG("ini file: %S", inipath);

// Read parameters on command line
Expand Down
9 changes: 4 additions & 5 deletions hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -6153,7 +6153,7 @@ static void readblacklist(const TCHAR *section, struct blacklist *blacklist, con
}
// Read all the blacklitsts
#define blacklist_section_length 32767
void readallblacklists(TCHAR *inipath)
void readallblacklists(const TCHAR *inipath)
{
mem00(&BlkLst, sizeof(BlkLst));

Expand Down Expand Up @@ -6376,13 +6376,12 @@ static void freeallinputSequences(void)
#ifdef __cplusplus
extern "C"
#endif
__declspec(dllexport) HWND WINAPI Load(HWND mainhwnd)
__declspec(dllexport) HWND WINAPI Load(HWND mainhwnd, const TCHAR inipath[AT_LEAST MAX_PATH])
{
#if defined(_MSC_VER) && _MSC_VER > 1300
#pragma comment(linker, "/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__)
#endif
// Load settings
TCHAR inipath[MAX_PATH];
unsigned i;
state.action = AC_NONE;
state.shift = 0;
Expand All @@ -6405,8 +6404,8 @@ __declspec(dllexport) HWND WINAPI Load(HWND mainhwnd)


// Get ini path
GetModuleFileName(NULL, inipath, ARR_SZ(inipath));
lstrcpy(&inipath[lstrlen(inipath)-3], TEXT("ini"));
// GetModuleFileName(NULL, inipath, ARR_SZ(inipath));
// lstrcpy(&inipath[lstrlen(inipath)-3], TEXT("ini"));

TCHAR stk_inisection[1420], *inisection; // Stack buffer.
size_t inisectionlen = 8192;
Expand Down
2 changes: 1 addition & 1 deletion hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#define UNLOAD_PROC "Unload"
#else
#define LOW_LEVEL_KB_PROC "_LowLevelKeyboardProc@12"
#define LOAD_PROC "_Load@4"
#define LOAD_PROC "_Load@8"
#define UNLOAD_PROC "_Unload@0"
#endif
#endif
Expand Down

0 comments on commit abc5baf

Please sign in to comment.