So a bit of context: I am writing a .dll that intends to expand a black 'view bar' that obscures vision past normal ranges in a 2d tile-based game.
The view bar's height is controlled by one value in a packed address, and its horizontal distance (the problem value) is controlled by another value in the same packed address. The game, however, will crash unless stepped-over manually in Visual Studio, or in x32dbg if the program is not paused when the changes occur.
I have checked the address and can confirm its validity. I took some time in x32dbg to look over the memory address in question (img-related) and found that the values cause a crash if:
A) the distance between the horizontal (0x17) and vertical (0x13) values exceeded 4 (only on horizontal value change oddly enough).
B) if the values were changed when the program in question was not paused by a debugger.
C) if the horizontal value is updated after the vertical value is not, even if it fits the aforementioned alignment conditions.
This is the weird part: The vertical value can change to quite-literally any value within reasonable bounds and not cause a crash. It's only the horizontal value that causes issues. On top of that, the address in question sometimes at complete random will write correctly under normal running conditions.
Overall, with all the info considered: this leads me to believe the values are being changed unevenly. One value is changed first in the code before the other while the program is still running, and if the program runs a compare function which ensures the two are aligned properly in the small time window that it is NOT properly aligned, it causes a crash.
My question is: how would I implement my code in a way to ensure the values are equally written, or at-least given time by the program to fully complete?
I will post some of the code in question below: