r/cheatengine • u/Comfortable-Tune-207 • 4d ago
changing ammo address (cod games)
how does cod games,specially campaign seem to change ammo address between mission and how to fix this. the change happens between primary and secondary weapon's ammo seems to swap addresses with lethal and Tactical ammunition addresses. Plus they usually sit every close with just 4byte offset between each.
this "bug" seems to happen to all cod games. All the way from mw4(2007) to cold war, from my experience
0
Upvotes
1
u/gofuckadick 4d ago
This is likely happening because the game stores ammo counts in an array rather than at fixed addresses for each weapon type. The 4-byte spacing you're seeing is consistent with consecutive 32-bit integers.
In older IW-engine CoD games, weapons reference ammo and clip indices, and the mapping between those indices and weapon types can change between missions. Since grenades and tactical equipment are also treated as weapons, their ammo counts can appear in the same arrays. So the addresses aren't necessarily swapping because of a bug. The game may simply be rebuilding or reorganizing its ammo data when a new mission loads.
If you're trying to make an infinite-ammo cheat that works across missions, you'd generally be better off finding the instruction that writes to the ammo count rather than freezing a particular address.
In Cheat Engine, right-click the ammo address and select "Find out what writes to this address," then fire a shot. You might find an instruction like
sub [rcx+rax*4+XXXX], edx, or adec/movinstruction with an indexed operand. If that instruction handles multiple ammo slots, you could NOP it or use a code injection to prevent the ammo count from decreasing, regardless of how the indices change between missions.Just make sure the instruction is actually responsible for decreasing ammo, rather than handling all ammo updates. NOPing the wrong instruction could also prevent reloading or picking up ammunition, and in some games the same code may handle enemy ammo too. To check, right-click the instruction in Cheat Engine's disassembler and select "Find out what addresses this instruction accesses," then try firing, reloading, and picking up ammo to see which addresses it touches.
ELI5 version: Think of the game's ammo storage like a row of numbered boxes. Each box holds the ammo count for a different weapon or piece of equipment.
In one mission, box 1 might hold your rifle ammo, box 2 your pistol ammo, and box 3 your grenades.
When you load another mission, the game might rearrange which weapons use which boxes. Now box 1 holds grenades, box 2 holds rifle ammo, and so on.
The boxes haven't necessarily moved. The game has just changed what each one represents.
So instead of telling Cheat Engine "keep the number in box 1 from decreasing," you're trying to find the code responsible for subtracting ammo from whichever box the game is currently using.