Civilization II 64-bit Editbox Patcher (MGE+ToT) (Also works on Win10 1709 Fall Creators Update)

Thanks so much for all the time you have spent on this.
I have tried to follow your instructions but I am running into a problem.
I turned on Legacy settings, installed the game, and downloaded the patch.
when I try to apply the patch I get the following:

ersion '5.2.5f Multiplayer 16-November-98 ' detected.
READY TO PATCH!
You can click 'Patch!' now (backup file will be created).
Error: Cannot open file "C:\Program Files (x86)\MicroProse Software\Civilization II Multiplayer Gold Edition\civ2.exe". Access is denied
Patching failed.

any ideas what I am doing wrong?
 
It looks like I can answer my own question.
I was poking around other forums and saw a thread about short file names. I changed the install file to CIV MGE directly on the C drive.
Then i patched and it worked! I am still trying to figure out the movies issue, but at least i can play now. thanks again.
 
Thanks for sharing the technical details. Even though I wrote a working patch (at least for the last 10 years) for the problem, I never *knew* exactly what it was. Debugging assembler without the source code was (and pretty much still is) beyond my technical expertise. I did a bit of trial and error, found something that worked (at least, that was good enough) and decided to share it with the rest of the world. Even after all this time, I'm glad to have a little more insight on the original problem.
Dear, MastermindX, Excuse me, please, that I ignored your message for almost a month. I wanted to answer you, but I was busy and constantly postponed it for later.
Firstly, I am glad to see you here after so long absence on the forum. Secondly, I wanted to express my gratitude for the patch that you gave to the world 10 years ago. It allowed me to play the game without crashes all these years. And it also inspired me to sit down at once and start to learn disassembly from scratch.
Thank you!
 
Last edited:
Dear FoxAhead, so cool that you are helping everyone out! I have recently run into problems as well, and your latest Civ2x64EditboxPatcher hasn't worked for me. I have Windows 10, version 1709, build 16299.371, and when I run your patch, this message comes up:

Version '5.4.0f Multiplayer 26-March-99 Patch 3 ' detected.
The file is already patched.
CAN NOT PATCH!

Perhaps you could offer me any advice on what to try next, I'm keen to keep playing Civ2 MGE and build a new scenario. Any tips would be much appreciated!
 
The file is already patched.
CAN NOT PATCH!
Well, that means that file you want to patch is already patched and you can play without crashes.
 
Ah yes, I made an error! I used your new Civ2x64EditboxPatcher on civ2.exe, which now works fine (with CD) - so that's great :)
However, I have been using the no-cd patch shortcut to play on my laptop without using the external CD-reader, and I was wondering if there's a way to make your new patch also work without CD? Just for comfort - at least I can play now! :)
 
My civ2 games crashed after the Windows 1709 update. I've found this patch and now it works perfectly. Thank you very much, I've really missed being able to play Civ2, which for me is the real thing.
 
Hello!

Preamble


I know that more than 10 years have passed since the Mastermind's patch was presented to run the game on the 64-bit systems. Nevertheless, I want to present you yet another patch.

I was playing Civilization 2 MGE many years on my windows 7 64-bit. And always confusing about input fields not reacting on keyboard strokes like Enter, TAB or Esc. It was little annoying to press 'B' to build city and after that move mouse to hunt OK button rather than just press Enter. I remembered that sometime in the past everything worked fine. Suddenly I took debugger and dive deep in assembly code for a week. Finally I realized that problem was in Mastermind's patch. Yes it allows to run game on 64-bit but the normal key-processing for input fields was broken. And after a while I managed to make my own patch that works without any side effects.

Description


This is Civilization II 64-bit Editbox Patcher.

It eliminates game and editor crashes on 64-bit systems when the game tries to display edit controls (input fields) for entering text (like city name, emperor name, world sizes etc.).

Unlike the existing well known patch by Mastermind it will retain the full functionality of edit controls including the response to the Enter, TAB or Escape keys.

So, the establishing city is now just 'B', 'Enter'. And customizing world size is like '100', 'TAB', '100', 'Enter'. No more mouse clicking.

Supported game versions are:
  • Civilization II Multiplayer Gold Edition
  • Civilization II: Test of Time
The patcher can even detect if Mastermind's patch has already been applied and will replace it.

Download and source code


https://github.com/FoxAhead/Civilization-II-64-bit-Editbox-Patcher/releases

Technical details


Spoiler :

Like Mastermind mentioned the problem was in callback procedure for Editbox control.
The pseudocode for place with error looks like this:
Code:
v17 = GetWindowLongA(hWnd, 0xA);
nIndex = GetClassLongA(hWnd, GCL_CBWNDEXTRA) - 8;
lpPrevWndFunc = GetWindowLongA(hWnd, nIndex);

The problem was in hard-coded 0xA which is offset for parameter in extra window memory. Here we are getting two parameters: v17 - pointer to some Style data, and lpPrevWndFunc - pointer to parent callback. The second one is acquired correctly using offset in nIndex. But offset for the first one is hard-coded = 0xA. In 32-bit OS size of extra window memory for 'Edit' window class equals 6 bytes. So plus our two integer (4 bytes) parameters gives total: 6+4*2 = 14 bytes. Call for GetClassLongA(hWnd, GCL_CBWNDEXTRA) returns us this total bytes of extra memory used. To get offset for lpPrevWndFunc you have to subtract 8 from total (14) (which is done correctly). And to get offset for v17 you have to subtract 4 from total (14) which gives you exactly 10 ( = 0xA in hexadecimal). And that works well until 64-bit comes on scene where size of extra window memory for 'Edit' window class equals 8 bytes. So with our two additional integers total size equals 16. And with offset for lpPrevWndFunc being still calculated correctly (16-8) the offset for v17 must be 16 - 4 = 12 (0xC) and not 10 (0xA).
The first simplest solution is to change this single byte from 0xA to 0xC and all will be working fine until... Well, for example you decide to copy this patched file back to 32-bit system (to play on vacation on old notebook with Windows 98 or XP x32). And this patched file will not work on 32-bit OS. So there is no backward compatibility.
The correct way to patch is to achieve code something like this:
Code:
nIndex = GetClassLongA(hWnd, GCL_CBWNDEXTRA);
v17           = GetWindowLongA(hWnd, nIndex - 4);
lpPrevWndFunc = GetWindowLongA(hWnd, nIndex - 8);
Here two first steps are swapped. Firstly we have to get total size of extra memory. And then we can calculate each offset correctly.
And then comes sweet part of juggling assembly code to achieve desired in less opcodes changed. And you have to fit in fixed frame because changing size of EXE is unacceptable. After 6th iteration I managed to make patch changing only 10 bytes.
Before:
Code:
005D2A01 55                  push   ebp
005D2A02 8B EC               mov    ebp, esp
005D2A04 83 EC 1C            sub    esp, 1Ch
005D2A07 53                  push   ebx
005D2A08 56                  push   esi
005D2A09 57                  push   edi
005D2A0A 6A 0A               push   0Ah             ; nIndex
005D2A0C 8B 45 08            mov    eax, [ebp+hWnd]
005D2A0F 50                  push   eax             ; hWnd
005D2A10 FF 15 2C 7E 6E 00   call   ds:GetWindowLongA
005D2A16 89 45 F8            mov    [ebp+var_8], eax
005D2A19 6A EE               push   GCL_CBWNDEXTRA  ; nIndex
005D2A1B 8B 45 08            mov    eax, [ebp+hWnd]
005D2A1E 50                  push   eax             ; hWnd
005D2A1F FF 15 9C 7E 6E 00   call   ds:GetClassLongA
005D2A25 83 E8 08            sub    eax, 8
005D2A28 89 45 F4            mov    [ebp+nIndex], eax
005D2A2B 8B 45 F4            mov    eax, [ebp+nIndex]
005D2A2E 50                  push   eax             ; nIndex
005D2A2F 8B 45 08            mov    eax, [ebp+hWnd]
005D2A32 50                  push   eax             ; hWnd
005D2A33 FF 15 2C 7E 6E 00   call   ds:GetWindowLongA
005D2A39 89 45 EC            mov    [ebp+lpPrevWndFunc], eax
005D2A3C 8B 45 0C            mov    eax, [ebp+Msg]
005D2A3F 89 45 E4            mov    [ebp+var_1C], eax
005D2A42 E9 4D 02 00 00      jmp    loc_5D2C94
After:
Code:
005D2A01 55                  push   ebp
005D2A02 8B EC               mov    ebp, esp
005D2A04 83 EC 1C            sub    esp, 1Ch
005D2A07 53                  push   ebx
005D2A08 56                  push   esi
005D2A09 57                  push   edi
005D2A0A 6A EE               push   GCL_CBWNDEXTRA  ; nIndex
005D2A0C 8B 45 08            mov    eax, [ebp+hWnd]
005D2A0F 50                  push   eax             ; hWnd
005D2A10 FF 15 9C 7E 6E 00   call   ds:GetClassLongA
005D2A16 89 C3               mov    ebx, eax
005D2A18 2C 04               sub    al, 4
005D2A1A 50                  push   eax             ; nIndex
005D2A1B 8B 45 08            mov    eax, [ebp+hWnd]
005D2A1E 50                  push   eax             ; hWnd
005D2A1F FF 15 2C 7E 6E 00   call   ds:GetWindowLongA
005D2A25 83 EB 08            sub    ebx, 8
005D2A28 89 45 F8            mov    [ebp+var_8], eax
005D2A2B 8B 45 F4            mov    eax, [ebp+var_C]
005D2A2E 53                  push   ebx             ; nIndex
005D2A2F 8B 45 08            mov    eax, [ebp+hWnd]
005D2A32 50                  push   eax             ; hWnd
005D2A33 FF 15 2C 7E 6E 00   call   ds:GetWindowLongA
005D2A39 89 45 EC            mov    [ebp+lpPrevWndFunc], eax
005D2A3C 8B 45 0C            mov    eax, [ebp+Msg]
005D2A3F 89 45 E4            mov    [ebp+var_1C], eax
005D2A42 E9 4D 02 00 00      jmp    loc_5D2C94
P.S.
After almost completing working on patch I found that someone named iunnamed already made another patch explaining exactly the same reason of crashes:
https://www.old-games.ru/forum/threads/sid-meiers-civilization-2.7950/page-9#post-1013691
I inspected it. That patch works good - input fields work correctly. The difference is just it for MGE 5.4.0f game only. Nor for Map Editor nor for ToT nor for other variations of MGE-like family. Also it lacks of GUI. And also it change 17 bytes of EXE.

I made my patcher on Delphi 7 because I wanted:
1) to make it possible run on old systems without external dependencies like .NET. (Tested on Windows 98 SE.);
2) to make GUI;
3) to develop it fast;
Downside of this is size of 400kB. But who cares nowadays about 400kB?


Dear FoxAhead,

Thank you for your great job!
I've been played for years on my Win7 PC with Mastermind patch with no problems.
Now, I got a new Win10 PC (version installed 1709 - 16299.371) and I find the error. I am trying to use your new patch, but it does not work!!
Let me explain: the application runs but it remains in the taskbar as an icon and does not work. I try to launch it from different paths, but the result is the same.
What can I do, in your opinion?

Thank you!!
 

Attachments

  • Capture.JPG
    Capture.JPG
    89.7 KB · Views: 257
Dear FoxAhead,

Thank you for your great job!
I've been played for years on my Win7 PC with Mastermind patch with no problems.
Now, I got a new Win10 PC (version installed 1709 - 16299.371) and I find the error. I am trying to use your new patch, but it does not work!!
Let me explain: the application runs but it remains in the taskbar as an icon and does not work. I try to launch it from different paths, but the result is the same.
What can I do, in your opinion?

Thank you!!
Hm... that's strange. I just updated my Win 10 to version 1803 (OS Build 17134.81) and my patcher launches fine. May be you could check some compatibility settings for it?
 
Hey there. Found this through a deep dive on Reddit.

I'm trying to play on Windows 10 and everytime it gets to name something (like my ruler name) it crashes the game. I tried to launch the patch, but it doesn't seem to allow me to actually use it. It opens and seems to be running but I can't actually open the window (Like it is running off screen). Normal methods (Like hitting Cascade Windows or shift right clicking and hitting the option move normally available) does not seem to actually work.

Any ideas?

Edit: It seems I am likely having a similar issue to AlexCosta. It opens and if I hover over the icon I can see that it is trying to do something, but it doesn't actually let me use it at all. It is like it isn't actually opening (or rather that is what it looks like at first glance and further inspection makes it appear that it is running, but off screen)
 
Last edited:
Hey there. Found this through a deep dive on Reddit.

I'm trying to play on Windows 10 and everytime it gets to name something (like my ruler name) it crashes the game. I tried to launch the patch, but it doesn't seem to allow me to actually use it. It opens and seems to be running but I can't actually open the window (Like it is running off screen). Normal methods (Like hitting Cascade Windows or shift right clicking and hitting the option move normally available) does not seem to actually work.

Any ideas?

Edit: It seems I am likely having a similar issue to AlexCosta. It opens and if I hover over the icon I can see that it is trying to do something, but it doesn't actually let me use it at all. It is like it isn't actually opening (or rather that is what it looks like at first glance and further inspection makes it appear that it is running, but off screen)
Hi!
Again I updated my Win10 and tested. On my computer it works fine. OS version is 1803 (OS Build 17134.112).
Have you tried to run as Administrator? Or try some compatibility settings? (Though in my case it was not necessary).
upload_2018-6-20_13-8-38.png
 
I tried to use this patch. It refuses to run without the CD in the drive. What MORE do I need to do to run without the CD in the drive?
 
Hi - I have signed up because despite trying everything above, I can't get it to work on my Windows 10 Home Edition.

I want to start from scratch again. I have the original 16 Bit Civ2 Disc. Is there a step by step guide that works (has current links if things need to be downloaded) that can take me through this please?
 
I have the original 16 Bit Civ2 Disc

Well there's your problem, you've been wasting your time lol. FoxAheads tools are for the 32bit final MGE release of Civ2. You cannot run a 16bit application on a modern 64bit operating system, no fancy fan patch is gonna change that. So you'll either need to run a XP virtual machine (I recommend Oracle VirtualBox) to install your 16bit copy on or you'll need to follow thamis's advice and download the 32bit MGE version of Civ2 from that abandonware website.
 
Hello, I can say the this patch works on Win10 20H2... so ya, wow.
The pop up, plays music, really loud and is kind of annoying. Can it be dis abled?

BTW - using the mouse to click the pop up before playing isnt viable, but a simple hit enter and it completes.

SO the music - can it be disabled?
Thanks.
 
Top Bottom