Merge pull request #224 from mateon1/bugfix1
Some checks failed
GithubCI / build (push) Has been cancelled

Add BUGFIX to ExecuteScriptCommand
This commit is contained in:
AnonymousRandomPerson 2024-09-26 17:40:38 -04:00 committed by GitHub
commit 3f743bca1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1110,8 +1110,17 @@ s32 ExecuteScriptCommand(Action *action) {
s32 cap1 = curCmd.arg1 * 2 - 1; s32 cap1 = curCmd.arg1 * 2 - 1;
s32 cap2 = curCmd.arg2 * 2 - 1; s32 cap2 = curCmd.arg2 * 2 - 1;
action->callbacks->getHitboxCenter(action->parentObject, &scriptData->pos1); action->callbacks->getHitboxCenter(action->parentObject, &scriptData->pos1);
// BUG: (or two): these lines use the wrong script command arguments to calculate the position offset
// making the target position nonsense. But even if they were correct,
// the way the cap is calculated would make the random offset biased off-center.
// This doesn't affect the released version because these script commands are never used.
#ifndef BUGFIX
scriptData->pos2.x = scriptData->pos1.x + ((OtherRandInt(cap1) - curCmd.argShort) << 8); scriptData->pos2.x = scriptData->pos1.x + ((OtherRandInt(cap1) - curCmd.argShort) << 8);
scriptData->pos2.y = scriptData->pos1.y + ((OtherRandInt(cap2) - curCmd.arg1) << 8); scriptData->pos2.y = scriptData->pos1.y + ((OtherRandInt(cap2) - curCmd.arg1) << 8);
#else
scriptData->pos2.x = scriptData->pos1.x + ((OtherRandInt(curCmd.arg1 * 2 + 1) - curCmd.arg1) << 8);
scriptData->pos2.y = scriptData->pos1.y + ((OtherRandInt(curCmd.arg2 * 2 + 1) - curCmd.arg2) << 8);
#endif
if (curCmd.op == 0x7f || curCmd.op == 0x85) { if (curCmd.op == 0x7f || curCmd.op == 0x85) {
scriptData->unk2A = sub_8009FB8(scriptData->pos2.x - scriptData->pos1.x, scriptData->pos2.y - scriptData->pos1.y) / curCmd.argShort; scriptData->unk2A = sub_8009FB8(scriptData->pos2.x - scriptData->pos1.x, scriptData->pos2.y - scriptData->pos1.y) / curCmd.argShort;
if (scriptData->unk2A <= 0) scriptData->unk2A = 1; if (scriptData->unk2A <= 0) scriptData->unk2A = 1;