diff --git a/src/game/activemenutick.c b/src/game/activemenutick.c index 577068a49..6638ad876 100644 --- a/src/game/activemenutick.c +++ b/src/game/activemenutick.c @@ -50,8 +50,14 @@ void amTick(void) s8 csticky = joyGetStickYOnSample(j, contpadnum); s8 crstickx = joyGetRStickXOnSample(j, contpadnum); s8 crsticky = joyGetRStickYOnSample(j, contpadnum); +#ifdef AVOID_UB + // if cstickx is -128, it will get negated and stored into absstickx, negating it again if it's 8 bit + s32 absstickx; + s32 abssticky; +#else s8 absstickx; s8 abssticky; +#endif u32 buttonsstate = joyGetButtonsOnSample(j, contpadnum, 0xffffffff); u32 buttonspressed = joyGetButtonsPressedOnSample(j, contpadnum, 0xffffffff); bool stickpushed = false; @@ -69,6 +75,8 @@ void amTick(void) g_AmMenus[g_AmIndex].allbots = false; #ifndef PLATFORM_N64 + s32 newstickx = (s32)cstickx + (s32)crstickx; + s32 newsticky = (s32)csticky + (s32)crsticky; if (j == 0 && g_Vars.currentplayernum == 0 && inputMouseIsLocked()) { f32 mdx, mdy; struct activemenu *am = &g_AmMenus[g_AmIndex]; @@ -79,11 +87,11 @@ void amTick(void) am->mousex = (am->mousex > 127.f) ? 127.f : (am->mousex < -128.f) ? -128.f : am->mousex; am->mousey = (am->mousey > 127.f) ? 127.f : (am->mousey < -128.f) ? -128.f : am->mousey; } - const s32 newstickx = (s32)cstickx + (s32)crstickx + (s32)am->mousex; - const s32 newsticky = (s32)csticky + (s32)crsticky - (s32)am->mousey; - cstickx = (newstickx < -128) ? -128 : (newstickx > 127) ? 127 : newstickx; - csticky = (newsticky < -128) ? -128 : (newsticky > 127) ? 127 : newsticky; + newstickx += (s32)am->mousex; + newsticky -= (s32)am->mousey; } + cstickx = (newstickx < -128) ? -128 : (newstickx > 127) ? 127 : newstickx; + csticky = (newsticky < -128) ? -128 : (newsticky > 127) ? 127 : newsticky; #endif if (g_Vars.currentplayer->activemenumode == AMMODE_EDIT) {