Fragjacker / DoW-Mod-Manager

The original repository for the DoW Mod Manager application, which was made for the Dawn of War:tm: series.
MIT License
32 stars 7 forks source link

Better fog patch #26

Closed BlueAmulet closed 3 years ago

BlueAmulet commented 3 years ago

The previous fog patch has some issues, misaligning the x87 stack mainly, and some poor naming

jmpFog -> getFog: fld DWORD PTR [ecx+0xc60] This is not a jmp instruction but a fld instruction, it loads the fog end distance onto the x87 stack. The previous solution of removing the instruction entirely, no longer loads something onto the stack, misaligning it and using whatever value happened to exist there before. This has been replaced with the fldz instruction, which always loads 0 onto the stack, and mimics how the fog_toggle command works (sets end distance to 0).

codeF512 -> float96: 0, 0, 192, 66 isn't code and is just the bytes for 96.0 For the below explanation: float512Address is the address for default sky distance, which the fog patch changes from 96 to 512, allowing you to zoom out more without the the ground unloading.

jmpMapSkyDistance -> setMapSkyDistance: fstp DWORD PTR [ebx+0xc70] This is also not a jmp instruction but a fstp instruction, related to how far you can zoom out before the game stops drawing parts of the ground. The game at this instruction is replacing the default sky distance value (now 512) with a more specific value, but we always want the large default. The previous solution of removing the instruction entirely, doesn't remove a value from the stack anymore, misaligning it. This was replaced with fstp st(0), which prevents the game from changing the default value, but also removes the new value from the stack.

Fragjacker commented 3 years ago

Nice find! I will take a look at this ASAP! This isn't my code so I wasn't aware of them issues but if the stack gets mangled, that's bad.