diff --git a/durazno/custom_func.c b/durazno/custom_func.c index e28fbde..7e749e5 100644 --- a/durazno/custom_func.c +++ b/durazno/custom_func.c @@ -8,8 +8,9 @@ static DWORD cheap_find_last_of(char *string, char c) { DWORD charpos = 0; + char *strpos; - for (char *strpos = string; *strpos; strpos++) + for (strpos = string; *strpos; strpos++) { if (*strpos == c) charpos = (DWORD)(strpos - string); @@ -34,8 +35,9 @@ int cheap_atoi_n(char *str, int n) { // no negative int num = 0; + char *p; - for (char *p = str; *p && n; p++, n--) + for (p = str; *p && n; p++, n--) { if (*p >= '0' && *p <= '9') num = num * 10 + (*p - '0'); diff --git a/durazno/durazno.c b/durazno/durazno.c index 57c6015..d862989 100644 --- a/durazno/durazno.c +++ b/durazno/durazno.c @@ -27,15 +27,20 @@ static BOOL load_xinput_dll(HINSTANCE instance) { char sysdir[MAX_PATH]; - UINT sysdir_len = GetSystemDirectoryA(sysdir, MAX_PATH); - if (sysdir_len == 0 || sysdir_len >= MAX_PATH) return FALSE; - char modname[MAX_PATH]; - DWORD modname_len = GetModuleFileNameA(instance, modname, MAX_PATH); + UINT sysdir_len; + DWORD modname_len; + DWORD namepos; + char *dllpath; + + sysdir_len = GetSystemDirectoryA(sysdir, MAX_PATH); + if (sysdir_len == 0 || sysdir_len >= MAX_PATH) return FALSE; + + modname_len = GetModuleFileNameA(instance, modname, MAX_PATH); if (!modname_len) return FALSE; - DWORD namepos = cheap_find_last_of(modname, '\\'); - char *dllpath = lstrcatA(sysdir, &modname[namepos]); + namepos = cheap_find_last_of(modname, '\\'); + dllpath = lstrcatA(sysdir, &modname[namepos]); if (!dllpath) return FALSE; XInput.dll = LoadLibraryA(dllpath); @@ -80,12 +85,14 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) DWORD WINAPI XInputGetState(DWORD dwUserIndex, XINPUT_STATE* pState) { + DWORD retval; + struct settings *set = &settings[dwUserIndex]; if(set->disabled) return ERROR_DEVICE_NOT_CONNECTED; - DWORD retval = XInput.GetState(set->index, pState); + retval = XInput.GetState(set->index, pState); if (retval == ERROR_SUCCESS) { @@ -169,12 +176,14 @@ DWORD WINAPI XInputGetAudioDeviceIds(DWORD dwUserIndex, LPWSTR pRenderDeviceId, DWORD WINAPI XInputGetStateEx(DWORD dwUserIndex, XINPUT_STATE *pState) { + DWORD retval; + struct settings *set = &settings[dwUserIndex]; if (set->disabled) return ERROR_DEVICE_NOT_CONNECTED; - DWORD retval = XInput.GetStateEx(set->index, pState); + retval = XInput.GetStateEx(set->index, pState); if (retval == ERROR_SUCCESS) { @@ -246,8 +255,9 @@ DWORD WINAPI DuraznoGetStateEx(DWORD dwUserIndex, XINPUT_STATE* pState) DWORD WINAPI GetControllerInput(DWORD port) { XINPUT_STATE state; + int i; - for (int i = 0; i < 100; i++) + for (i = 0; i < 100; i++) { if (DuraznoGetState(port, &state) != ERROR_SUCCESS) return (DWORD)-1; diff --git a/durazno/file_io.c b/durazno/file_io.c index a14e9b0..711adb4 100644 --- a/durazno/file_io.c +++ b/durazno/file_io.c @@ -18,7 +18,9 @@ void load_remap(char *secbuf, struct remap *remap) if (length != 71) { - for (int i = 0; i < 24; i++) + int i; + + for (i = 0; i < 24; i++) { remap[i].control = i; @@ -29,7 +31,9 @@ void load_remap(char *secbuf, struct remap *remap) } else { - for (int i = 0; i < 24; i++, secdata += 3) + int i; + + for (i = 0; i < 24; i++, secdata += 3) { int control = remap[i].control = cheap_atoi_n(secdata, 2); @@ -58,10 +62,12 @@ void load_remap(char *secbuf, struct remap *remap) static void save_remap(char *secbuf, struct remap *remap) { + int i; + wsprintfA(secbuf, "Remap="); secbuf = next_str(secbuf) - 1; - - for (int i = 0; i < 24; i++, secbuf += 3) + + for (i = 0; i < 24; i++, secbuf += 3) { wsprintfA(secbuf, "%02d ", remap[i].control); } @@ -109,6 +115,8 @@ void toggle_inverted(struct settings *set) static void ini_load(void) { + int port; + if (GetPrivateProfileIntA("General", "INIVersion", 0, INI_FILENAME) != INI_VERSION) { // clear the file or something @@ -117,7 +125,7 @@ void ini_load(void) GetPrivateProfileStringA("General", "LoadDLL", "", custom_dll, MAX_PATH, INI_FILENAME); - for (int port = 0; port < 4; port++) + for (port = 0; port < 4; port++) { struct settings *set = &settings[port]; wsprintfA(fileiobuf, "Controller%d", port); @@ -164,6 +172,7 @@ void ini_load(void) static void ini_save(void) { + int port; char *secbuf = fileiobuf; wsprintfA(secbuf, "INIversion=%d", INI_VERSION); secbuf = next_str(secbuf); @@ -172,13 +181,15 @@ void ini_save(void) WritePrivateProfileSectionA("General", fileiobuf, INI_FILENAME); - for (int port = 0; port < 4; port++) + for (port = 0; port < 4; port++) { struct settings *set = &settings[port]; + char *section; + char *secdata; - char *section = fileiobuf; + section = fileiobuf; wsprintfA(section, "Controller%d", port); - char *secdata = next_str(section); + secdata = next_str(section); secbuf = secdata; wsprintfA(secbuf, "Port=%d", set->index); secbuf = next_str(secbuf); diff --git a/makefile b/makefile index a90abb2..8dc07c9 100644 --- a/makefile +++ b/makefile @@ -1,7 +1,7 @@ #NMAKE -CC_FLAGS = /c /O2 /GL /D _USING_V110_SDK71_ /D _WINDLL /D _MBCS /MD /GS- /nologo -LINKER_FLAGS = /NODEFAULTLIB /MANIFEST:NO /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /LTCG /ENTRY:"DllMain" /DYNAMICBASE:NO /NXCOMPAT /SAFESEH:NO /DLL /NOLOGO +CC_FLAGS = /c /O1 /Oi /fp:fast /GS- /GR- /MT /nologo /Wall +LINKER_FLAGS = /DLL /SUBSYSTEM:WINDOWS /MANIFEST:NO /NOLOGO SOURCE = durazno\durazno.c @@ -14,7 +14,7 @@ all: $(TARGETS) @del build\*.lib durazno.obj: - @cl $(CC_FLAGS) $(SOURCE) -Fo:durazno.obj + @cl $(CC_FLAGS) $(SOURCE) /Fodurazno.obj $(TARGETS): durazno.obj @link durazno.obj kernel32.lib user32.lib $(LINKER_FLAGS) /DEF:durazno\$(@).def /OUT:build\$(@).dll