Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - war2Nostalgia

Pages: [1]
1
Did some debugging on my own and found some solution which I will share here in case someone else runs into the same problem. For background information, WC2 keeps counts of different units - how many grunts, trolls, ... do you have. When your unit dies WC 2 subtracts 1 from count. There is a check in WC 2 code that if count is already 0 before subtraction takes place then this error is thrown.

Now there is 2 possible solutions:
First is to keep unit counts updated every time you replace units which from programming point of view can be quite a bit of extra work.
Second solution is disable this check by replacing conditional jump jne with unconditional jump jmp. This allows unit count to underflow (0 - 1 = 65535 with 2 byte unsigned ints) but so far I did not experience any negative consequences. Scores on victory screen seem to calculated correctly and game crash.

Here is code extract from WC2 process.
Code: [Select]
Warcraft II BNE.exe+17855 - 66 83 3C 48  00       - cmp word ptr [eax+ecx*2],00 { 0 }
Warcraft II BNE.exe+1785A - 75 0F                 - jne "Warcraft II BNE.exe"+1786B { ->Warcraft II BNE.exe+1786B }
Warcraft II BNE.exe+1785C - 51                    - push ecx
Warcraft II BNE.exe+1785D - 52                    - push edx
Warcraft II BNE.exe+1785E - 68 5C564900           - push "Warcraft II BNE.exe"+9565C { ["count.c (1): %d %d"] }
Warcraft II BNE.exe+17863 - E8 78120700           - call "Warcraft II BNE.exe"+88AE0 { ->Warcraft II BNE.exe+88AE0 }
Warcraft II BNE.exe+17868 - 83 C4 0C              - add esp,0C { 12 }
Warcraft II BNE.exe+1786B - 33 D2                 - xor edx,edx

Cmp compares unit count to 0. Jne jumps to line xor edx,edx if it is not zero. If it is zero then code from push ecx to add esp,0C gets executed. Call "Warcraft II BNE.exe"+88AE0 is the function that crashes the game and displays error message. When condational jump if not equal (jne) is replaced with uncoditional jump (jmp) instruction then bad code is always skipped and error will never be thrown. It's easiest solution since it only needs to modify 1 byte.

TL;DR: At memory address Warcraft II BNE.exe+1785A replace byte 0x75 with 0xEB.

2
Mods & Development / What's the best way to fix count.c (1) error message?
« on: September 25, 2025, 02:29:58 PM »
Hi!

I develop a program that allows me to modify units to be something else - for example upgrade trolls to Kargath. But that sometimes causes me count.c (1) error message. What would be the best way to fix it? When I googled it I found that War2BNE InSight has had it and fixed it but since it is closed source I can't see what they did. I was curious that since people on this forum seem to be into modding maybe someone here have experience on how to deal with count.c (1)?

Pages: [1]