diff --git a/dll/dep.c b/dll/dep.c index e640f35..a6e30f1 100644 --- a/dll/dep.c +++ b/dll/dep.c @@ -30,7 +30,7 @@ void debug(char *message, ...) { memset(buf, 0, sizeof(buf)); va_start(args, message); - vsnprintf(buf, sizeof(buf) - 1, message, args); + wvsprintfA(buf, message, args); file = CreateFile((LPCWSTR)DEBUG_FILE, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); SetFilePointer(file, 0, 0, FILE_END); diff --git a/dll/dll.vcxproj b/dll/dll.vcxproj index 88a60e0..cc3fa4c 100644 --- a/dll/dll.vcxproj +++ b/dll/dll.vcxproj @@ -163,7 +163,7 @@ MaxSpeed - true + false WIN32;NDEBUG;_WINDOWS;_USRDLL;DLL_EXPORTS;%(PreprocessorDefinitions) MultiThreaded @@ -172,6 +172,7 @@ Level3 ProgramDatabase CompileAsC + false true @@ -181,12 +182,13 @@ 0x76290000 false MachineX86 + Shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) MaxSpeed - true + false WIN32;NDEBUG;_WINDOWS;_USRDLL;DLL_EXPORTS;USE_SRP3;%(PreprocessorDefinitions) MultiThreaded @@ -195,6 +197,7 @@ Level3 ProgramDatabase CompileAsC + false true @@ -204,12 +207,13 @@ 0x76290000 false MachineX86 + Shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) MaxSpeed - true + false WIN32;_DEBUG;_WINDOWS;_USRDLL;DLL_EXPORTS;USE_SRP3;DEBUG;%(PreprocessorDefinitions) MultiThreaded @@ -218,6 +222,7 @@ Level3 ProgramDatabase CompileAsC + false true @@ -227,12 +232,13 @@ 0x76290000 false MachineX86 + Shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) MaxSpeed - true + false WIN32;_DEBUG;_WINDOWS;_USRDLL;DLL_EXPORTS;DEBUG;%(PreprocessorDefinitions) MultiThreaded @@ -241,6 +247,7 @@ Level3 ProgramDatabase CompileAsC + false true @@ -251,6 +258,7 @@ false true MachineX86 + Shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -283,6 +291,7 @@ CompileAsCpp + CompileAsC @@ -290,6 +299,7 @@ + diff --git a/dll/functions.h b/dll/functions.h index ef3c98f..667c9de 100644 --- a/dll/functions.h +++ b/dll/functions.h @@ -1,6 +1,8 @@ #if !defined(_FUNCTIONS_H) #define _FUNCTIONS_H +#include "nodefaultlib.h" + #if !defined(USE_SRP3) #include "pstdint.h" diff --git a/dll/nodefaultlib.c b/dll/nodefaultlib.c new file mode 100644 index 0000000..ab8ec2a --- /dev/null +++ b/dll/nodefaultlib.c @@ -0,0 +1,45 @@ +#include "nodefaultlib.h" +#define DEBUG_FILE L"debug.log" + +void * __cdecl memset(void *pTarget, int value, size_t cbTarget) +{ + unsigned char *p = (unsigned char *)(pTarget); + while (cbTarget-- > 0) { + *p++ = (unsigned char)(value); + } + return pTarget; +} +int __cdecl memcmp(void const* _Buf1, void const* _Buf2, size_t _Size) +{ + unsigned char u1, u2; + unsigned char *b1 = (unsigned char *)_Buf1; + unsigned char *b2 = (unsigned char *)_Buf2; + + for (; _Size--; b1++, b2++) { + u1 = *b1; + u2 = *b2; + if (u1 != u2) { + return (u1 - u2); + } + } + return 0; +} + +/* Print a log message */ +void debug(char *message, ...) { +#ifdef DEBUG + DWORD temp; + HANDLE file; + va_list args; + char buf[1024]; + + memset(buf, 0, sizeof(buf)); + va_start(args, message); + wvsprintfA(buf, message, args); + + file = CreateFile(DEBUG_FILE, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + SetFilePointer(file, 0, 0, FILE_END); + WriteFile(file, buf, (DWORD)strlen(buf), &temp, NULL); + CloseHandle(file); +#endif +} \ No newline at end of file diff --git a/dll/nodefaultlib.h b/dll/nodefaultlib.h new file mode 100644 index 0000000..fdd37c8 --- /dev/null +++ b/dll/nodefaultlib.h @@ -0,0 +1,12 @@ +#pragma once +#pragma comment(linker, "/entry:DllMain") +#include +#include +#include +#include +#include +#pragma intrinsic(strlen) +#pragma function(memset, memcmp) +int __cdecl memcmp(void const* _Buf1, void const* _Buf2, size_t _Size); +void * __cdecl memset(void *pTarget, int value, size_t cbTarget); +void __cdecl debug(char *, ...); \ No newline at end of file diff --git a/dll/w3lh.c b/dll/w3lh.c index 16588b2..d497b83 100644 --- a/dll/w3lh.c +++ b/dll/w3lh.c @@ -34,7 +34,6 @@ #include "functions.h" //#define DEBUG /* undef to disable logging */ -#define DEBUG_FILE "debug.log" #define LATENCY_FILE "latency.txt" #define GAME_DLL_NAME "Game.dll" #define GAME_MAIN "GameMain" @@ -61,40 +60,23 @@ FARPROC real_game_main; /* pointer to the real "Game.dll" GameMain function */ HMODULE game_dll_base; /* pointer to base of the real "Game.dll" */ HANDLE app_process; /* handle to the war3.exe process */ -/* Print a log message */ -void debug(char *message, ...) { -#ifdef DEBUG - DWORD temp; - HANDLE file; - va_list args; - char buf[1024]; - - memset(buf, 0, sizeof(buf)); - va_start(args, message); - vsnprintf(buf, sizeof(buf) - 1, message, args); - - file = CreateFile(DEBUG_FILE, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - SetFilePointer(file, 0, 0, FILE_END); - WriteFile(file, buf, (DWORD)strlen(buf), &temp, NULL); +char read_latency() { + HFILE file; + OFSTRUCT ofFile; + char buf[4]; + int lt, readNum; + file = OpenFile(LATENCY_FILE, &ofFile, OF_READ); + if (file == HFILE_ERROR) + return DEFAULT_LATENCY; + ReadFile(file, buf, 3, &readNum, NULL); CloseHandle(file); -#endif + buf[3] = '\0'; + lt = StrToInt(buf); + if (lt > 255 || lt < 30) + return DEFAULT_LATENCY; + return (char)lt; } - -char read_latency ( ) { - FILE *file; - int lt; - file = fopen ( LATENCY_FILE, "rt"); - if ( !file) - return DEFAULT_LATENCY; - fscanf( file, "%d", <); - fclose( file); - if ( lt > 255 || lt < 30) - return DEFAULT_LATENCY; - return (char )lt; -} - - /* write patch to memory */ int apply_patch(char *ptr, t_patch *patch) { DWORD temp, oldprot, newprot = PAGE_EXECUTE_READWRITE; @@ -264,7 +246,7 @@ int patch() { MessageBox(NULL, GAME_DLL_LOAD_ERROR, "[lib] Patch Error (w3lh.dll)", MB_OK); return ERR_GAME_DLL_LOAD; } - debug("base: 0x%08X", game_dll_base); + debug("base: 0x%08X\r\n", game_dll_base); real_game_main = GetProcAddress(game_dll_base, GAME_MAIN); if(!real_game_main) { @@ -273,7 +255,7 @@ int patch() { } /* apply delay reduction patches and adRemove patch */ delay_reducer_patch_data[0] = read_latency( ); - debug( "Latency set to: %hhu ms\r\n", ( unsigned char)(delay_reducer_patch_data[0])); + debug( "Latency set to: %hu ms\r\n", ( unsigned char)(delay_reducer_patch_data[0])); apply_patches((char *)game_dll_base, unimportant_patches, GAME_DLL_SIZE); #if ! defined USE_SRP3 diff --git a/dll/w3lh.rc b/dll/w3lh.rc index 96b179c..a140de5 100644 --- a/dll/w3lh.rc +++ b/dll/w3lh.rc @@ -24,8 +24,8 @@ LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT // 1 VERSIONINFO - FILEVERSION 1,4,0,0 - PRODUCTVERSION 1,4,0,0 + FILEVERSION 1,4,0,1 + PRODUCTVERSION 1,4,0,1 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -43,12 +43,12 @@ BEGIN VALUE "Comments", "Latest versions of this loader and other tools @ http://keres.myftp.org" VALUE "CompanyName", "w3l" VALUE "FileDescription", "Warcraft 3 Game.dll hook for PvPGN" - VALUE "FileVersion", "1.4.0.0" + VALUE "FileVersion", "1.4.0.1" VALUE "InternalName", "w3lh" VALUE "LegalCopyright", "(c) 2008 Keres / Rupan / phatdeeva" VALUE "OriginalFilename", "w3lh.dll" VALUE "ProductName", "w3l" - VALUE "ProductVersion", "1.4.0.0" + VALUE "ProductVersion", "1.4.0.1" END END BLOCK "VarFileInfo" diff --git a/dll_27a/dep.c b/dll_27a/dep.c index e640f35..a6e30f1 100644 --- a/dll_27a/dep.c +++ b/dll_27a/dep.c @@ -30,7 +30,7 @@ void debug(char *message, ...) { memset(buf, 0, sizeof(buf)); va_start(args, message); - vsnprintf(buf, sizeof(buf) - 1, message, args); + wvsprintfA(buf, message, args); file = CreateFile((LPCWSTR)DEBUG_FILE, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); SetFilePointer(file, 0, 0, FILE_END); diff --git a/dll_27a/dep.h b/dll_27a/dep.h index f2d4d65..c97ea7d 100644 --- a/dll_27a/dep.h +++ b/dll_27a/dep.h @@ -19,6 +19,7 @@ #ifndef DEP_H__ #define DEP_H__ #include +#include "nodefaultlib.h" enum DepEnforcement { // DEP is completely disabled. DEP_DISABLED, diff --git a/dll_27a/dll.vcxproj b/dll_27a/dll.vcxproj index e8d0650..bb6a0cd 100644 --- a/dll_27a/dll.vcxproj +++ b/dll_27a/dll.vcxproj @@ -147,7 +147,7 @@ Full - true + false WIN32;NDEBUG;_WINDOWS;_USRDLL;DLL_EXPORTS;%(PreprocessorDefinitions) MultiThreaded @@ -159,6 +159,7 @@ true Size false + false true @@ -169,13 +170,14 @@ false MachineX86 false - false + true + Shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) Full - true + false WIN32;NDEBUG;_WINDOWS;_USRDLL;DLL_EXPORTS;USE_SRP3;%(PreprocessorDefinitions) MultiThreaded @@ -187,6 +189,7 @@ Size true false + false true @@ -196,7 +199,8 @@ 0x76290000 false MachineX86 - false + true + Shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -211,6 +215,7 @@ Level3 ProgramDatabase CompileAsC + false true @@ -220,6 +225,8 @@ 0x76290000 false MachineX86 + true + Shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -234,6 +241,7 @@ Level3 ProgramDatabase CompileAsC + false true @@ -244,6 +252,8 @@ false false MachineX86 + true + Shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -276,6 +286,7 @@ CompileAsCpp + CompileAsC @@ -283,6 +294,7 @@ + diff --git a/dll_27a/functions.h b/dll_27a/functions.h index ef3c98f..3ada7d7 100644 --- a/dll_27a/functions.h +++ b/dll_27a/functions.h @@ -1,6 +1,7 @@ #if !defined(_FUNCTIONS_H) #define _FUNCTIONS_H +#include "nodefaultlib.h" #if !defined(USE_SRP3) #include "pstdint.h" diff --git a/dll_27a/nodefaultlib.c b/dll_27a/nodefaultlib.c new file mode 100644 index 0000000..ab8ec2a --- /dev/null +++ b/dll_27a/nodefaultlib.c @@ -0,0 +1,45 @@ +#include "nodefaultlib.h" +#define DEBUG_FILE L"debug.log" + +void * __cdecl memset(void *pTarget, int value, size_t cbTarget) +{ + unsigned char *p = (unsigned char *)(pTarget); + while (cbTarget-- > 0) { + *p++ = (unsigned char)(value); + } + return pTarget; +} +int __cdecl memcmp(void const* _Buf1, void const* _Buf2, size_t _Size) +{ + unsigned char u1, u2; + unsigned char *b1 = (unsigned char *)_Buf1; + unsigned char *b2 = (unsigned char *)_Buf2; + + for (; _Size--; b1++, b2++) { + u1 = *b1; + u2 = *b2; + if (u1 != u2) { + return (u1 - u2); + } + } + return 0; +} + +/* Print a log message */ +void debug(char *message, ...) { +#ifdef DEBUG + DWORD temp; + HANDLE file; + va_list args; + char buf[1024]; + + memset(buf, 0, sizeof(buf)); + va_start(args, message); + wvsprintfA(buf, message, args); + + file = CreateFile(DEBUG_FILE, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + SetFilePointer(file, 0, 0, FILE_END); + WriteFile(file, buf, (DWORD)strlen(buf), &temp, NULL); + CloseHandle(file); +#endif +} \ No newline at end of file diff --git a/dll_27a/nodefaultlib.h b/dll_27a/nodefaultlib.h new file mode 100644 index 0000000..fdd37c8 --- /dev/null +++ b/dll_27a/nodefaultlib.h @@ -0,0 +1,12 @@ +#pragma once +#pragma comment(linker, "/entry:DllMain") +#include +#include +#include +#include +#include +#pragma intrinsic(strlen) +#pragma function(memset, memcmp) +int __cdecl memcmp(void const* _Buf1, void const* _Buf2, size_t _Size); +void * __cdecl memset(void *pTarget, int value, size_t cbTarget); +void __cdecl debug(char *, ...); \ No newline at end of file diff --git a/dll_27a/w3lh.c b/dll_27a/w3lh.c index 4d13fc4..0917cb3 100644 --- a/dll_27a/w3lh.c +++ b/dll_27a/w3lh.c @@ -34,7 +34,6 @@ #include "functions.h" //#define DEBUG /* undef to disable logging */ -#define DEBUG_FILE "debug.log" #define LATENCY_FILE "latency.txt" #define GAME_DLL_NAME "Game.dll" #define GAME_MAIN "GameMain" @@ -61,34 +60,18 @@ FARPROC real_game_main; /* pointer to the real "Game.dll" GameMain function */ HMODULE game_dll_base; /* pointer to base of the real "Game.dll" */ HANDLE app_process; /* handle to the war3.exe process */ -/* Print a log message */ -void debug(char *message, ...) { -#ifdef DEBUG - DWORD temp; - HANDLE file; - va_list args; - char buf[1024]; - - memset(buf, 0, sizeof(buf)); - va_start(args, message); - vsnprintf(buf, sizeof(buf) - 1, message, args); - - file = CreateFile(DEBUG_FILE, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - SetFilePointer(file, 0, 0, FILE_END); - WriteFile(file, buf, (DWORD)strlen(buf), &temp, NULL); - CloseHandle(file); -#endif -} - - char read_latency ( ) { - FILE *file; - int lt; - file = fopen ( LATENCY_FILE, "rt"); - if ( !file) + HFILE file; + OFSTRUCT ofFile; + char buf[4]; + int lt, readNum; + file = OpenFile ( LATENCY_FILE, &ofFile, OF_READ); + if ( file == HFILE_ERROR ) return DEFAULT_LATENCY; - fscanf( file, "%d", <); - fclose( file); + ReadFile( file, buf, 3, &readNum, NULL ); + CloseHandle( file ); + buf[3] = '\0'; + lt = StrToInt( buf ); if ( lt > 255 || lt < 30) return DEFAULT_LATENCY; return (char )lt; @@ -295,7 +278,7 @@ int patch() { } /* apply delay reduction patches and adRemove patch */ delay_reducer_patch_data[0] = read_latency( ); - debug( "Latency set to: %hhu ms\r\n", ( unsigned char)(delay_reducer_patch_data[0])); + debug( "Latency set to: %hu ms\r\n", ( unsigned char)(delay_reducer_patch_data[0])); apply_patches((char *)game_dll_base, unimportant_patches, GAME_DLL_SIZE); #if ! defined USE_SRP3 diff --git a/dll_27a/w3lh.rc b/dll_27a/w3lh.rc index e8c680f..260f080 100644 --- a/dll_27a/w3lh.rc +++ b/dll_27a/w3lh.rc @@ -24,8 +24,8 @@ LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT // 1 VERSIONINFO - FILEVERSION 1,4,0,0 - PRODUCTVERSION 1,4,0,0 + FILEVERSION 1,4,0,1 + PRODUCTVERSION 1,4,0,1 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -43,12 +43,12 @@ BEGIN VALUE "Comments", "Latest versions of this loader and other tools @ http://keres.myftp.org" VALUE "CompanyName", "w3l" VALUE "FileDescription", "Warcraft 3 Game.dll hook for PvPGN" - VALUE "FileVersion", "1.4.0.0" + VALUE "FileVersion", "1.4.0.1" VALUE "InternalName", "w3lh" VALUE "LegalCopyright", "(c) 2008 Keres / Rupan / phatdeeva" VALUE "OriginalFilename", "wl27.dll" VALUE "ProductName", "w3l" - VALUE "ProductVersion", "1.4.0.0" + VALUE "ProductVersion", "1.4.0.1" END END BLOCK "VarFileInfo"