Skip to content

Commit

Permalink
BFME2X crash fix
Browse files Browse the repository at this point in the history
  • Loading branch information
anzz1 authored Dec 8, 2023
1 parent 83a3421 commit 1a48a80
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ int __stdcall DllMain(HINSTANCE hInstDLL, DWORD dwReason, LPVOID lpReserved) {
} else if (!__stricmp(p, "game.dat")) {
char* p2 = GetModExpName(GetModuleHandleA(0));
if (p2) {
if (!__strcmp(p2, "RTS.exe")) patch_bfme2(); // Battle for Middle-earth II
if (!__strcmp(p2, "RTS.exe")) patch_bfme2(); // Battle for Middle-earth II / Rise of the Witch King
}
} else if (!__stricmp(p, "game.exe")) {
LPGUID pguid = GetModPdbGuid(GetModuleHandleA(0));
Expand Down
18 changes: 14 additions & 4 deletions include/game_bfme2.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,23 @@ __forceinline static void bfme2_hook_gs() {

// missing options.ini causes crash on startup
__forceinline static void bfme2_create_options() {
char path[MAX_PATH+56];
char path[MAX_PATH+72];
HANDLE hFile = 0;
DWORD dw = 0;
DWORD dw, len;
if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, path) >= 0) {
__strcat(path, "\\My Battle for Middle-earth(tm) II Files");
len = __strlen(path);
if (len > MAX_PATH) return;
__strcpy(path+len, "\\My Battle for Middle-earth(tm) II Files");
CreateDirectoryA(path, NULL);
__strcat(path, "\\options.ini");
__strcpy(path+len+40, "\\options.ini");
hFile = CreateFileA(path, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile && hFile != INVALID_HANDLE_VALUE) {
WriteFile(hFile, bfme2_options_ini, 150, &dw, NULL);
CloseHandle(hFile);
}
__strcpy(path+len, "\\My The Lord of the Rings, The Rise of the Witch-king Files");
CreateDirectoryA(path, NULL);
__strcpy(path+len+59, "\\options.ini");
hFile = CreateFileA(path, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile && hFile != INVALID_HANDLE_VALUE) {
WriteFile(hFile, bfme2_options_ini, 150, &dw, NULL);
Expand Down

0 comments on commit 1a48a80

Please sign in to comment.