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

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.

Thanks for your excellent work on your Civ2 Patcher, which I have used for years with Multiplayer Gold on Windows 10 - it has given me great enjoyment.
Today, I found the sliders had disappeared from the Tax Rate window, so I had no way of changing the tax/science/luxuries rates. I tried relaunching Civ2, restarted the laptop, uninstalled and reinstalled Civ2 from the CD - all to no avail.

Looking in the Windows updates history, I saw there were two security updates on 18 April, KB5001337 and KB5001406. I uninstalled KB5001337, tried Civ2 again, and to my joy the Tax Rate sliders have reappeared!

I thought you may want to know in case others experience the same issue.

When I restarted my laptop just now after uninstalling the Windows update, I found it had installed another security update (KB5000808, installed 21 April) but this doesn't seem to have affected Civ2.

Tomorrow I will try reinstalling the offending update, just to check it is the culprit.
I suppose it is possible that the most recent update on 21 April has corrected a glitch in the offending one, so it may have been a temporary problem.
I will post again soon.

I hope this is of some interest.
 
  1. Hi to All! One Easy tip to launch Civilization 2 on Windows 10 64 bit. Just go windows -> system32 -> find and open file name : OptionalFeatures -> find Legacy Components and just apply. Working Perfect.
 
I had an issues similar to Slider5150 where i could not get the installation wizard to open after pressing install here:

upload_2018-3-10_21-59-44.png


I looked up how to get the 32-bit Setup Launcher process running on Windows 10 and found this reddit thread. https://www.reddit.com/r/techsupport/comments/452lyf/32bit_setup_launcher_not_working_on_windows_10/
There is a comment which leads to an imgur link. https://imgur.com/a/UOQB4

Here are the imgur link instructions and pictures in case the imgur link goes down later

1kecETf.png


go to task manager, click the details tab, find setup.exe

CRjrkwn.jpeg


right click setup.exe and click on analyze wait chain

EphDTN3.png


close the blocking program, in this case: evernote.exe (there will be a different program you need to close for Civ 2)

I hope this can help someone in the future!
 
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?


Hi,
After installing Masterminds patch years ago, today it wouldn't work. I have D/L your patch and tried to install it but either I didn't do it correctly or I am afraid I might not be that tech savvy. I don't know if anyone is still monitoring this. If that's the case, can anyone help me install FoxAhead's patches? I'm running it on W10 BTW! Thanks in advance!!
 
Well for starters you'll need to give a LOT more information than "it wouldn't work". Fox and others can't help if they don't know what went wrong.

You're totally right, my mistake. So I D/L'd the patch into the CIV II folder, I started the game, and it would start configuring the different game options correctly untill it gets to the editing screen where you edit the name. At tht point the game freezes, and it just crashes. I have read this might be due to a memory issue, but again, I have no clue...Thanks again!
 
You're totally right, my mistake. So I D/L'd the patch into the CIV II folder, I started the game, and it would start configuring the different game options correctly untill it gets to the editing screen where you edit the name. At tht point the game freezes, and it just crashes. I have read this might be due to a memory issue, but again, I have no clue...Thanks again!

Hmm crashing on the 'name your ruler' or 'name your city' freetext boxes is exactly what happens with vanilla Civ2 on 64bit operating systems which implies the patch has not been applied successfully.

I noticed in between "I D/L'd the patch into the CIV II folder" and "I started the game" you didn't say "I ran the patch exe and it said it successfully made it's required changes to Civ2 exe"?

 
Hmm crashing on the 'name your ruler' or 'name your city' freetext boxes is exactly what happens with vanilla Civ2 on 64bit operating systems which implies the patch has not been applied successfully.

I noticed in between "I D/L'd the patch into the CIV II folder" and "I started the game" you didn't say "I ran the patch exe and it said it successfully made it's required changes to Civ2 exe"?



Ah, I already thought I'd misread the instructions. Worked like a charm this time, thanks a lot!!!
 
@Blake00 Thanks for answering!
I updated the first post to clarify patching procedure.
@Raaty
I suggest to use
Civilization II MGE User Interface Additions
In addition to including this "64-bit" patch, it also expands the user interface by providing handy features and game information, making the gaming experience much more convenient.
 
I have tried all of these things. But every time it crashes after I am done designing the game it crashes to the desktop while trying to load the world. anyone know how to fix this? windows 11.
 
Hmm so you got past the name your ruler (which is when the 64bit crash hits when unpatched) and it crashed while building the world. That sounds like a new problem.

For testing purposes I'm guessing you don't have any save games to load if you can't get a new game started lol, but are you able to start any pre-made scenarios? eg Civ2 comes with a few and if you've got MGE then it comes with heaps. Would be interesting to see if you can load a scenario and look around the map and enter cities and rename them etc to confirm that the issue only seems to have when the game is worldbuilding on some copies of Win11. That would help narrow things down a bit for FoxAhead.
 
I have tried all of these things. But every time it crashes after I am done designing the game it crashes to the desktop while trying to load the world. anyone know how to fix this? windows 11.

Civilization II Multiplayer Gold Edition 5.4.0f
Patched CIV2.EXE with Civ2x64EditboxPatcher.exe
Used Codec Tweak Tool to enable Indeo 4 codec.
Windows 11, no crashes, CD music, videos.

1678621065622.png
 
Top Bottom