TheSuperHackers/GeneralsGameCode

Game crashes when a lot of units are being moved at once

xezon opened this issue · 1 comments

xezon commented

Game crashes when a lot of units are being moved at once. Happens in both play and replay. I don't have a replay at hand anymore, but back in the day I figured following solution. It works, but may have side effects. I think the consequence was, that some units would no longer move with the other mass amount of units.

Inject identical hack in game.dat at following 2 addresses:

0x55B6A2 taking 6 bytes
0x55B732 taking 6 bytes

// CPU Disasm (Zero Hour 1.04)
// Address   Hex dump          Command                                  Comments
// 0055B720  /$  55            PUSH EBP
// 0055B721  |.  56            PUSH ESI
// 0055B722  |.  8B7424 0C     MOV ESI,DWORD PTR SS:[ARG.1]
// 0055B726  |.  33ED          XOR EBP,EBP
// 0055B728  |.  85F6          TEST ESI,ESI
// 0055B72A      EB 7B         JE SHORT 0055B7A7
// 0055B72C  |.  53            PUSH EBX
// 0055B72D  |.  B8 DFFFFFFF   MOV EAX,-21
// 0055B732  |>  8B0E          /MOV ECX,DWORD PTR DS:[ESI]
// 0055B734  |.  8BD6          |MOV EDX,ESI
// 0055B736  |.  8B31          |MOV ESI,DWORD PTR DS:[ECX]              <- crash, ecx is 0
// 0055B738  |.  45            |INC EBP
// 0055B739  |.  85F6          |TEST ESI,ESI

// Game crashes when a lot of units are on the move

DWORD ccFixMoveUnitCrashRet;
__declspec(naked) void CC_FixMoveUnitCrash()
{
	__asm
	{
		pop [ccFixMoveUnitCrashRet]
		MOV ECX,DWORD PTR DS:[ESI]
		test ecx,ecx
		je Fix
		MOV EDX,ESI
		MOV ESI,DWORD PTR DS:[ECX]
		push [ccFixMoveUnitCrashRet]
		ret

	Fix:
		mov ecx, ccFixMoveUnitCrashRet
		add ecx, 0x6A
		jmp ecx
	}
}

Basically we test ecx for 0, and then jump 6A bytes to skip a bunch of game code and continue execution of program. If ecx is not 0, then it works as usual.

A recent video which shows this crash: https://youtu.be/_kwCzWM2-2s?t=7048