1
0
mirror of synced 2024-11-23 22:51:02 +01:00

Update style

This commit is contained in:
BroGamer 2022-06-20 07:17:39 +12:00
parent 1847ab85d8
commit 7266f58506
5 changed files with 147 additions and 240 deletions

View File

@ -1,7 +1,13 @@
BasedOnStyle: GNU
IndentWidth: 4
TabWidth: 4
UseTab: Always
UseTab: ForIndentation
IndentCaseLabels: False
BreakBeforeBraces: Attach
ColumnLimit: 150
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveMacros: Consecutive
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: True
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: AllIfsAndElse

View File

@ -48,24 +48,15 @@ HOOK_DYNAMIC (i64, __fastcall, DecCoin, i32 a1, u16 a2) {
HOOK_DYNAMIC (u16, __fastcall, GetAnalogIn, u8 which) {
switch (which) {
case 0: // Player 1 Left Blue
IF_HIT (P1_LEFT_BLUE);
case 1: // Player 1 Left Red
IF_HIT (P1_LEFT_RED);
case 2: // Player 1 Right Red
IF_HIT (P1_RIGHT_RED);
case 3: // Player 1 Right Blue
IF_HIT (P1_RIGHT_BLUE);
case 4: // Player 2 Left Blue
IF_HIT (P2_LEFT_BLUE);
case 5: // Player 2 Left Red
IF_HIT (P2_LEFT_RED);
case 6: // Player 2 Right Red
IF_HIT (P2_RIGHT_RED);
case 7: // Player 2 Right Blue
IF_HIT (P2_RIGHT_BLUE);
default:
return 0;
case 0: IF_HIT (P1_LEFT_BLUE); // Player 1 Left Blue
case 1: IF_HIT (P1_LEFT_RED); // Player 1 Left Red
case 2: IF_HIT (P1_RIGHT_RED); // Player 1 Right Red
case 3: IF_HIT (P1_RIGHT_BLUE); // Player 1 Right Blue
case 4: IF_HIT (P2_LEFT_BLUE); // Player 2 Left Blue
case 5: IF_HIT (P2_LEFT_RED); // Player 2 Left Red
case 6: IF_HIT (P2_RIGHT_RED); // Player 2 Right Red
case 7: IF_HIT (P2_RIGHT_BLUE); // Player 2 Right Blue
default: return 0;
}
}
@ -103,12 +94,9 @@ HOOK_DYNAMIC (u16, __fastcall, GetCoin, i32 a1) {
}
UpdatePoll (windowHandle);
if (IsButtonTapped (COIN_ADD))
coin_count++;
if (IsButtonTapped (TEST))
testEnabled = !testEnabled;
if (IsButtonTapped(EXIT))
ExitProcess(0);
if (IsButtonTapped (COIN_ADD)) coin_count++;
if (IsButtonTapped (TEST)) testEnabled = !testEnabled;
if (IsButtonTapped (EXIT)) ExitProcess (0);
}
return coin_count;
}
@ -129,10 +117,8 @@ HOOK_DYNAMIC (i64, __stdcall, ResetCoin) {
}
i32 __stdcall DllMain (HMODULE mod, DWORD cause, void *ctx) {
if (cause == DLL_PROCESS_DETACH)
DisposePoll ();
if (cause != DLL_PROCESS_ATTACH)
return 1;
if (cause == DLL_PROCESS_DETACH) DisposePoll ();
if (cause != DLL_PROCESS_ATTACH) return 1;
// Blatantly stolen patches from mon.im
WRITE_MEMORY (0x1400239C0, u8, 0xC3); // Stop error

View File

@ -46,8 +46,7 @@ openConfigSection (toml_table_t *config, char *sectionName) {
bool
readConfigBool (toml_table_t *table, char *key, bool notFoundValue) {
toml_datum_t data = toml_bool_in (table, key);
if (!data.ok)
return notFoundValue;
if (!data.ok) return notFoundValue;
return (bool)data.u.b;
}
@ -55,8 +54,7 @@ readConfigBool (toml_table_t *table, char *key, bool notFoundValue) {
int64_t
readConfigInt (toml_table_t *table, char *key, int64_t notFoundValue) {
toml_datum_t data = toml_int_in (table, key);
if (!data.ok)
return notFoundValue;
if (!data.ok) return notFoundValue;
return data.u.i;
}
@ -64,8 +62,7 @@ readConfigInt (toml_table_t *table, char *key, int64_t notFoundValue) {
char *
readConfigString (toml_table_t *table, char *key, char *notFoundValue) {
toml_datum_t data = toml_string_in (table, key);
if (!data.ok)
return notFoundValue;
if (!data.ok) return notFoundValue;
return data.u.s;
}
@ -75,8 +72,7 @@ printColour (int colour, const char *format, ...) {
va_list args;
va_start (args, format);
if (consoleHandle == 0)
consoleHandle = GetStdHandle (STD_OUTPUT_HANDLE);
if (consoleHandle == 0) consoleHandle = GetStdHandle (STD_OUTPUT_HANDLE);
char buffer[255];
vsprintf (buffer, format, args);

View File

@ -95,8 +95,7 @@ SetConfigValue (toml_table_t *table, char *key, struct Keybindings *keybind) {
for (int i = 0;; i++) {
toml_datum_t bind = toml_string_at (array, i);
if (!bind.ok)
break;
if (!bind.ok) break;
struct ConfigValue value = StringToConfigEnum (bind.u.s);
free (bind.u.s);
@ -132,8 +131,7 @@ SetConfigValue (toml_table_t *table, char *key, struct Keybindings *keybind) {
}
}
break;
default:
break;
default: break;
}
}
}
@ -169,8 +167,7 @@ InitializePoll (void *DivaWindowHandle) {
SDL_GameControllerEventState (SDL_ENABLE);
for (int i = 0; i < SDL_NumJoysticks (); i++) {
if (!SDL_IsGameController (i))
continue;
if (!SDL_IsGameController (i)) continue;
SDL_GameController *controller = SDL_GameControllerOpen (i);
@ -184,18 +181,15 @@ InitializePoll (void *DivaWindowHandle) {
}
window = SDL_CreateWindowFrom (DivaWindowHandle);
if (window != NULL)
SDL_SetWindowResizable (window, true);
else
printError ("SDL_CreateWindowFrom (DivaWindowHandle): %s\n", SDL_GetError ());
if (window != NULL) SDL_SetWindowResizable (window, true);
else printError ("SDL_CreateWindowFrom (DivaWindowHandle): %s\n", SDL_GetError ());
return hasRumble;
}
void
UpdatePoll (void *DivaWindowHandle) {
if (DivaWindowHandle == NULL || GetForegroundWindow () != DivaWindowHandle)
return;
if (DivaWindowHandle == NULL || GetForegroundWindow () != DivaWindowHandle) return;
memcpy (lastKeyboardState, currentKeyboardState, 255);
memcpy (lastControllerButtonsState, currentControllerButtonsState, 21);
@ -212,8 +206,7 @@ UpdatePoll (void *DivaWindowHandle) {
while (SDL_PollEvent (&event) != 0) {
switch (event.type) {
case SDL_CONTROLLERDEVICEADDED:
if (!SDL_IsGameController (event.cdevice.which))
break;
if (!SDL_IsGameController (event.cdevice.which)) break;
SDL_GameController *controller = SDL_GameControllerOpen (event.cdevice.which);
@ -229,57 +222,32 @@ UpdatePoll (void *DivaWindowHandle) {
controllers[event.cdevice.which] = controller;
break;
case SDL_CONTROLLERDEVICEREMOVED:
if (!SDL_IsGameController (event.cdevice.which))
break;
if (!SDL_IsGameController (event.cdevice.which)) break;
SDL_GameControllerClose (controllers[event.cdevice.which]);
break;
case SDL_MOUSEWHEEL:
if (event.wheel.y > 0)
currentMouseState.ScrolledUp = true;
else if (event.wheel.y < 0)
currentMouseState.ScrolledDown = true;
if (event.wheel.y > 0) currentMouseState.ScrolledUp = true;
else if (event.wheel.y < 0) currentMouseState.ScrolledDown = true;
break;
case SDL_CONTROLLERBUTTONUP:
case SDL_CONTROLLERBUTTONDOWN:
currentControllerButtonsState[event.cbutton.button] = event.cbutton.state;
break;
case SDL_CONTROLLERBUTTONDOWN: currentControllerButtonsState[event.cbutton.button] = event.cbutton.state; break;
case SDL_CONTROLLERAXISMOTION:
if (event.caxis.value > 8000) {
switch (event.caxis.axis) {
case SDL_CONTROLLER_AXIS_LEFTX:
currentControllerAxisState.LeftRight = 1;
break;
case SDL_CONTROLLER_AXIS_LEFTY:
currentControllerAxisState.LeftDown = 1;
break;
case SDL_CONTROLLER_AXIS_RIGHTX:
currentControllerAxisState.RightRight = 1;
break;
case SDL_CONTROLLER_AXIS_RIGHTY:
currentControllerAxisState.RightDown = 1;
break;
case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
currentControllerAxisState.LTriggerDown = 1;
break;
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
currentControllerAxisState.RTriggerDown = 1;
break;
case SDL_CONTROLLER_AXIS_LEFTX: currentControllerAxisState.LeftRight = 1; break;
case SDL_CONTROLLER_AXIS_LEFTY: currentControllerAxisState.LeftDown = 1; break;
case SDL_CONTROLLER_AXIS_RIGHTX: currentControllerAxisState.RightRight = 1; break;
case SDL_CONTROLLER_AXIS_RIGHTY: currentControllerAxisState.RightDown = 1; break;
case SDL_CONTROLLER_AXIS_TRIGGERLEFT: currentControllerAxisState.LTriggerDown = 1; break;
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: currentControllerAxisState.RTriggerDown = 1; break;
}
} else if (event.caxis.value < -8000) {
switch (event.caxis.axis) {
case SDL_CONTROLLER_AXIS_LEFTX:
currentControllerAxisState.LeftLeft = 1;
break;
case SDL_CONTROLLER_AXIS_LEFTY:
currentControllerAxisState.LeftUp = 1;
break;
case SDL_CONTROLLER_AXIS_RIGHTX:
currentControllerAxisState.RightLeft = 1;
break;
case SDL_CONTROLLER_AXIS_RIGHTY:
currentControllerAxisState.RightUp = 1;
break;
case SDL_CONTROLLER_AXIS_LEFTX: currentControllerAxisState.LeftLeft = 1; break;
case SDL_CONTROLLER_AXIS_LEFTY: currentControllerAxisState.LeftUp = 1; break;
case SDL_CONTROLLER_AXIS_RIGHTX: currentControllerAxisState.RightLeft = 1; break;
case SDL_CONTROLLER_AXIS_RIGHTY: currentControllerAxisState.RightUp = 1; break;
}
} else {
switch (event.caxis.axis) {
@ -299,12 +267,8 @@ UpdatePoll (void *DivaWindowHandle) {
currentControllerAxisState.RightDown = 0;
currentControllerAxisState.RightUp = 0;
break;
case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
currentControllerAxisState.LTriggerDown = 0;
break;
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
currentControllerAxisState.RTriggerDown = 0;
break;
case SDL_CONTROLLER_AXIS_TRIGGERLEFT: currentControllerAxisState.LTriggerDown = 0; break;
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: currentControllerAxisState.RTriggerDown = 0; break;
}
}
break;
@ -355,44 +319,28 @@ GetInternalButtonState (struct Keybindings bindings) {
struct InternalButtonState buttons = { 0 };
for (int i = 0; i < COUNTOFARR (ConfigKeyboardButtons); i++) {
if (bindings.keycodes[i] == 0)
continue;
if (KeyboardIsReleased (bindings.keycodes[i]))
buttons.Released = 1;
if (KeyboardIsDown (bindings.keycodes[i]))
buttons.Down = 1;
if (KeyboardIsTapped (bindings.keycodes[i]))
buttons.Tapped = 1;
if (bindings.keycodes[i] == 0) continue;
if (KeyboardIsReleased (bindings.keycodes[i])) buttons.Released = 1;
if (KeyboardIsDown (bindings.keycodes[i])) buttons.Down = 1;
if (KeyboardIsTapped (bindings.keycodes[i])) buttons.Tapped = 1;
}
for (int i = 0; i < COUNTOFARR (ConfigControllerButtons); i++) {
if (bindings.buttons[i] == SDL_CONTROLLER_BUTTON_INVALID)
continue;
if (ControllerButtonIsReleased (bindings.buttons[i]))
buttons.Released = 1;
if (ControllerButtonIsDown (bindings.buttons[i]))
buttons.Down = 1;
if (ControllerButtonIsTapped (bindings.buttons[i]))
buttons.Tapped = 1;
if (bindings.buttons[i] == SDL_CONTROLLER_BUTTON_INVALID) continue;
if (ControllerButtonIsReleased (bindings.buttons[i])) buttons.Released = 1;
if (ControllerButtonIsDown (bindings.buttons[i])) buttons.Down = 1;
if (ControllerButtonIsTapped (bindings.buttons[i])) buttons.Tapped = 1;
}
for (int i = 0; i < COUNTOFARR (ConfigControllerAXIS); i++) {
if (bindings.axis[i] == 0)
continue;
if (ControllerAxisIsReleased (bindings.axis[i]))
buttons.Released = 1;
if (ControllerAxisIsDown (bindings.axis[i]))
buttons.Down = 1;
if (ControllerAxisIsTapped (bindings.axis[i]))
buttons.Tapped = 1;
if (bindings.axis[i] == 0) continue;
if (ControllerAxisIsReleased (bindings.axis[i])) buttons.Released = 1;
if (ControllerAxisIsDown (bindings.axis[i])) buttons.Down = 1;
if (ControllerAxisIsTapped (bindings.axis[i])) buttons.Tapped = 1;
}
for (int i = 0; i < COUNTOFARR (ConfigMouseScroll); i++) {
if (bindings.scroll[i] == 0)
continue;
if (GetMouseScrollIsReleased (bindings.scroll[i]))
buttons.Released = 1;
if (GetMouseScrollIsDown (bindings.scroll[i]))
buttons.Down = 1;
if (GetMouseScrollIsTapped (bindings.scroll[i]))
buttons.Tapped = 1;
if (bindings.scroll[i] == 0) continue;
if (GetMouseScrollIsReleased (bindings.scroll[i])) buttons.Released = 1;
if (GetMouseScrollIsDown (bindings.scroll[i])) buttons.Down = 1;
if (GetMouseScrollIsTapped (bindings.scroll[i])) buttons.Tapped = 1;
}
return buttons;
@ -401,8 +349,7 @@ GetInternalButtonState (struct Keybindings bindings) {
void
SetRumble (int left, int right) {
for (int i = 0; i < COUNTOFARR (controllers); i++) {
if (!controllers[i] || !SDL_GameControllerHasRumble (controllers[i]))
continue;
if (!controllers[i] || !SDL_GameControllerHasRumble (controllers[i])) continue;
SDL_GameControllerRumble (controllers[i], left, right, 1000);
}
@ -485,26 +432,20 @@ GetWasMouseScrollDown () {
inline bool
GetMouseScrollIsReleased (enum Scroll scroll) {
if (scroll == MOUSE_SCROLL_UP)
return !GetMouseScrollUp () && GetWasMouseScrollUp ();
else
return !GetMouseScrollDown () && GetWasMouseScrollDown ();
if (scroll == MOUSE_SCROLL_UP) return !GetMouseScrollUp () && GetWasMouseScrollUp ();
else return !GetMouseScrollDown () && GetWasMouseScrollDown ();
}
inline bool
GetMouseScrollIsDown (enum Scroll scroll) {
if (scroll == MOUSE_SCROLL_UP)
return GetMouseScrollUp ();
else
return GetMouseScrollDown ();
if (scroll == MOUSE_SCROLL_UP) return GetMouseScrollUp ();
else return GetMouseScrollDown ();
}
inline bool
GetMouseScrollIsTapped (enum Scroll scroll) {
if (scroll == MOUSE_SCROLL_UP)
return GetMouseScrollUp () && !GetWasMouseScrollUp ();
else
return GetMouseScrollDown () && !GetWasMouseScrollDown ();
if (scroll == MOUSE_SCROLL_UP) return GetMouseScrollUp () && !GetWasMouseScrollUp ();
else return GetMouseScrollDown () && !GetWasMouseScrollDown ();
}
inline bool
@ -540,29 +481,18 @@ ControllerButtonIsReleased (SDL_GameControllerButton button) {
inline bool
ControllerAxisIsDown (enum SDLAxis axis) {
switch (axis) {
case SDL_AXIS_LEFT_LEFT:
return currentControllerAxisState.LeftLeft;
case SDL_AXIS_LEFT_RIGHT:
return currentControllerAxisState.LeftRight;
case SDL_AXIS_LEFT_UP:
return currentControllerAxisState.LeftUp;
case SDL_AXIS_LEFT_DOWN:
return currentControllerAxisState.LeftDown;
case SDL_AXIS_RIGHT_LEFT:
return currentControllerAxisState.RightLeft;
case SDL_AXIS_RIGHT_RIGHT:
return currentControllerAxisState.RightRight;
case SDL_AXIS_RIGHT_UP:
return currentControllerAxisState.RightUp;
case SDL_AXIS_RIGHT_DOWN:
return currentControllerAxisState.RightDown;
case SDL_AXIS_LTRIGGER_DOWN:
return currentControllerAxisState.LTriggerDown;
case SDL_AXIS_RTRIGGER_DOWN:
return currentControllerAxisState.RTriggerDown;
case SDL_AXIS_LEFT_LEFT: return currentControllerAxisState.LeftLeft;
case SDL_AXIS_LEFT_RIGHT: return currentControllerAxisState.LeftRight;
case SDL_AXIS_LEFT_UP: return currentControllerAxisState.LeftUp;
case SDL_AXIS_LEFT_DOWN: return currentControllerAxisState.LeftDown;
case SDL_AXIS_RIGHT_LEFT: return currentControllerAxisState.RightLeft;
case SDL_AXIS_RIGHT_RIGHT: return currentControllerAxisState.RightRight;
case SDL_AXIS_RIGHT_UP: return currentControllerAxisState.RightUp;
case SDL_AXIS_RIGHT_DOWN: return currentControllerAxisState.RightDown;
case SDL_AXIS_LTRIGGER_DOWN: return currentControllerAxisState.LTriggerDown;
case SDL_AXIS_RTRIGGER_DOWN: return currentControllerAxisState.RTriggerDown;
case SDL_AXIS_NULL:
case SDL_AXIS_MAX:
return false;
case SDL_AXIS_MAX: return false;
}
}
@ -574,29 +504,18 @@ ControllerAxisIsUp (enum SDLAxis axis) {
inline bool
ControllerAxisWasDown (enum SDLAxis axis) {
switch (axis) {
case SDL_AXIS_LEFT_LEFT:
return lastControllerAxisState.LeftLeft;
case SDL_AXIS_LEFT_RIGHT:
return lastControllerAxisState.LeftRight;
case SDL_AXIS_LEFT_UP:
return lastControllerAxisState.LeftUp;
case SDL_AXIS_LEFT_DOWN:
return lastControllerAxisState.LeftDown;
case SDL_AXIS_RIGHT_LEFT:
return lastControllerAxisState.RightLeft;
case SDL_AXIS_RIGHT_RIGHT:
return lastControllerAxisState.RightRight;
case SDL_AXIS_RIGHT_UP:
return lastControllerAxisState.RightUp;
case SDL_AXIS_RIGHT_DOWN:
return lastControllerAxisState.RightDown;
case SDL_AXIS_LTRIGGER_DOWN:
return lastControllerAxisState.LTriggerDown;
case SDL_AXIS_RTRIGGER_DOWN:
return lastControllerAxisState.RTriggerDown;
case SDL_AXIS_LEFT_LEFT: return lastControllerAxisState.LeftLeft;
case SDL_AXIS_LEFT_RIGHT: return lastControllerAxisState.LeftRight;
case SDL_AXIS_LEFT_UP: return lastControllerAxisState.LeftUp;
case SDL_AXIS_LEFT_DOWN: return lastControllerAxisState.LeftDown;
case SDL_AXIS_RIGHT_LEFT: return lastControllerAxisState.RightLeft;
case SDL_AXIS_RIGHT_RIGHT: return lastControllerAxisState.RightRight;
case SDL_AXIS_RIGHT_UP: return lastControllerAxisState.RightUp;
case SDL_AXIS_RIGHT_DOWN: return lastControllerAxisState.RightDown;
case SDL_AXIS_LTRIGGER_DOWN: return lastControllerAxisState.LTriggerDown;
case SDL_AXIS_RTRIGGER_DOWN: return lastControllerAxisState.RTriggerDown;
case SDL_AXIS_NULL:
case SDL_AXIS_MAX:
return false;
case SDL_AXIS_MAX: return false;
}
}