mirror of
https://github.com/stenzek/duckstation.git
synced 2025-06-07 20:15:32 +00:00
Cheats: Add bounds check to 5107/5147
This commit is contained in:
parent
c98dbb9d9e
commit
93a7e7cef5
@ -2836,15 +2836,18 @@ void Cheats::GamesharkCheatCode::Apply() const
|
|||||||
// This cheat type requires a separate cheat to set up 4 consecutive cht_arrays before this will work
|
// This cheat type requires a separate cheat to set up 4 consecutive cht_arrays before this will work
|
||||||
// cht_register[cht_reg_no1] = the base address of the first element of the first array
|
// cht_register[cht_reg_no1] = the base address of the first element of the first array
|
||||||
// cht_register[cht_reg_no1+1] = the array size (basically the address diff between the start of each array)
|
// cht_register[cht_reg_no1+1] = the array size (basically the address diff between the start of each array)
|
||||||
//cht_register[cht_reg_no1+2] = the index of which array in the series to poke (this must be greater than 0)
|
// cht_register[cht_reg_no1+2] = the index of which array in the series to poke (this must be greater than
|
||||||
//cht_register[cht_reg_no1+3] must == 0xD0D0 to ensure it only pokes when the above cht_regs have been set
|
// 0) cht_register[cht_reg_no1+3] must == 0xD0D0 to ensure it only pokes when the above cht_regs have been
|
||||||
|
// set
|
||||||
// (safety valve)
|
// (safety valve)
|
||||||
// cht_offset = the index of the individual array to change (so must be 0 to cht_register[cht_reg_no1+1])
|
// cht_offset = the index of the individual array to change (so must be 0 to cht_register[cht_reg_no1+1])
|
||||||
if (cht_register[cht_reg_no1 + 3] == 0xD0D0 && cht_register[cht_reg_no1 + 2] > 0
|
if ((cht_reg_no1 <= (std::size(cht_register) - 4)) && cht_register[cht_reg_no1 + 3] == 0xD0D0 &&
|
||||||
&& cht_register[cht_reg_no1 + 1] >= cht_offset)
|
cht_register[cht_reg_no1 + 2] > 0 && cht_register[cht_reg_no1 + 1] >= cht_offset)
|
||||||
|
{
|
||||||
DoMemoryWrite<u8>((cht_register[cht_reg_no1] - cht_register[cht_reg_no1 + 1]) +
|
DoMemoryWrite<u8>((cht_register[cht_reg_no1] - cht_register[cht_reg_no1 + 1]) +
|
||||||
(cht_register[cht_reg_no1 + 1] * cht_register[cht_reg_no1 + 2]) + cht_offset,
|
(cht_register[cht_reg_no1 + 1] * cht_register[cht_reg_no1 + 2]) + cht_offset,
|
||||||
Truncate8(poke_value & 0xFFu));
|
Truncate8(poke_value & 0xFFu));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x40: // Write the u16 from cht_register[cht_reg_no1] to address
|
case 0x40: // Write the u16 from cht_register[cht_reg_no1] to address
|
||||||
@ -2877,15 +2880,18 @@ void Cheats::GamesharkCheatCode::Apply() const
|
|||||||
// This cheat type requires a separate cheat to set up 4 consecutive cht_arrays before this will work
|
// This cheat type requires a separate cheat to set up 4 consecutive cht_arrays before this will work
|
||||||
// cht_register[cht_reg_no1] = the base address of the first element of the first array
|
// cht_register[cht_reg_no1] = the base address of the first element of the first array
|
||||||
// cht_register[cht_reg_no1+1] = the array size (basically the address diff between the start of each array)
|
// cht_register[cht_reg_no1+1] = the array size (basically the address diff between the start of each array)
|
||||||
//cht_register[cht_reg_no1+2] = the index of which array in the series to poke (this must be greater than 0)
|
// cht_register[cht_reg_no1+2] = the index of which array in the series to poke (this must be greater than
|
||||||
//cht_register[cht_reg_no1+3] must == 0xD0D0 to ensure it only pokes when the above cht_regs have been set
|
// 0) cht_register[cht_reg_no1+3] must == 0xD0D0 to ensure it only pokes when the above cht_regs have been
|
||||||
|
// set
|
||||||
// (safety valve)
|
// (safety valve)
|
||||||
// cht_offset = the index of the individual array to change (so must be 0 to cht_register[cht_reg_no1+1])
|
// cht_offset = the index of the individual array to change (so must be 0 to cht_register[cht_reg_no1+1])
|
||||||
if (cht_register[cht_reg_no1 + 3] == 0xD0D0 && cht_register[cht_reg_no1 + 2] > 0
|
if ((cht_reg_no1 <= (std::size(cht_register) - 4)) && cht_register[cht_reg_no1 + 3] == 0xD0D0 &&
|
||||||
&& cht_register[cht_reg_no1 + 1] >= cht_offset)
|
cht_register[cht_reg_no1 + 2] > 0 && cht_register[cht_reg_no1 + 1] >= cht_offset)
|
||||||
|
{
|
||||||
DoMemoryWrite<u16>((cht_register[cht_reg_no1] - cht_register[cht_reg_no1 + 1]) +
|
DoMemoryWrite<u16>((cht_register[cht_reg_no1] - cht_register[cht_reg_no1 + 1]) +
|
||||||
(cht_register[cht_reg_no1 + 1] * cht_register[cht_reg_no1 + 2]) + cht_offset,
|
(cht_register[cht_reg_no1 + 1] * cht_register[cht_reg_no1 + 2]) + cht_offset,
|
||||||
Truncate16(poke_value & 0xFFFFu));
|
Truncate16(poke_value & 0xFFFFu));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x80: // Write the u32 from cht_register[cht_reg_no1] to address
|
case 0x80: // Write the u32 from cht_register[cht_reg_no1] to address
|
||||||
|
Loading…
x
Reference in New Issue
Block a user