Skip to content

Commit 1a48a80

Browse files
authored
BFME2X crash fix
1 parent 83a3421 commit 1a48a80

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

dllmain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ int __stdcall DllMain(HINSTANCE hInstDLL, DWORD dwReason, LPVOID lpReserved) {
308308
} else if (!__stricmp(p, "game.dat")) {
309309
char* p2 = GetModExpName(GetModuleHandleA(0));
310310
if (p2) {
311-
if (!__strcmp(p2, "RTS.exe")) patch_bfme2(); // Battle for Middle-earth II
311+
if (!__strcmp(p2, "RTS.exe")) patch_bfme2(); // Battle for Middle-earth II / Rise of the Witch King
312312
}
313313
} else if (!__stricmp(p, "game.exe")) {
314314
LPGUID pguid = GetModPdbGuid(GetModuleHandleA(0));

include/game_bfme2.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,23 @@ __forceinline static void bfme2_hook_gs() {
3333

3434
// missing options.ini causes crash on startup
3535
__forceinline static void bfme2_create_options() {
36-
char path[MAX_PATH+56];
36+
char path[MAX_PATH+72];
3737
HANDLE hFile = 0;
38-
DWORD dw = 0;
38+
DWORD dw, len;
3939
if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, path) >= 0) {
40-
__strcat(path, "\\My Battle for Middle-earth(tm) II Files");
40+
len = __strlen(path);
41+
if (len > MAX_PATH) return;
42+
__strcpy(path+len, "\\My Battle for Middle-earth(tm) II Files");
4143
CreateDirectoryA(path, NULL);
42-
__strcat(path, "\\options.ini");
44+
__strcpy(path+len+40, "\\options.ini");
45+
hFile = CreateFileA(path, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
46+
if (hFile && hFile != INVALID_HANDLE_VALUE) {
47+
WriteFile(hFile, bfme2_options_ini, 150, &dw, NULL);
48+
CloseHandle(hFile);
49+
}
50+
__strcpy(path+len, "\\My The Lord of the Rings, The Rise of the Witch-king Files");
51+
CreateDirectoryA(path, NULL);
52+
__strcpy(path+len+59, "\\options.ini");
4353
hFile = CreateFileA(path, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
4454
if (hFile && hFile != INVALID_HANDLE_VALUE) {
4555
WriteFile(hFile, bfme2_options_ini, 150, &dw, NULL);

0 commit comments

Comments
 (0)