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 BasedOnStyle: GNU
IndentWidth: 4 IndentWidth: 4
TabWidth: 4 TabWidth: 4
UseTab: Always UseTab: ForIndentation
IndentCaseLabels: False IndentCaseLabels: False
BreakBeforeBraces: Attach BreakBeforeBraces: Attach
ColumnLimit: 150 ColumnLimit: 150
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveMacros: Consecutive
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: True
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: AllIfsAndElse

View File

@ -18,28 +18,28 @@ enumWindows (HWND handle, LPARAM param) {
// force show cursor // force show cursor
HOOK_DYNAMIC (i32, __stdcall, ShowMouse, i32 show) { return originalShowMouse (true); } HOOK_DYNAMIC (i32, __stdcall, ShowMouse, i32 show) { return originalShowMouse (true); }
#define DRUM_HIT 20000 #define DRUM_HIT 20000
#define IF_HIT(bind) return IsButtonTapped (bind) ? DRUM_HIT : 0 #define IF_HIT(bind) return IsButtonTapped (bind) ? DRUM_HIT : 0
struct Keybindings EXIT = { .keycodes = { VK_ESCAPE } }; struct Keybindings EXIT = { .keycodes = { VK_ESCAPE } };
struct Keybindings COIN_ADD = { .keycodes = { VK_RETURN }, .buttons = { SDL_CONTROLLER_BUTTON_START } }; struct Keybindings COIN_ADD = { .keycodes = { VK_RETURN }, .buttons = { SDL_CONTROLLER_BUTTON_START } };
struct Keybindings TEST = { .keycodes = { VK_F1 } }; struct Keybindings TEST = { .keycodes = { VK_F1 } };
struct Keybindings SERVICE = { .keycodes = { VK_F2 } }; struct Keybindings SERVICE = { .keycodes = { VK_F2 } };
struct Keybindings DEBUG_UP = { .keycodes = { VK_UP } }; struct Keybindings DEBUG_UP = { .keycodes = { VK_UP } };
struct Keybindings DEBUG_DOWN = { .keycodes = { VK_DOWN } }; struct Keybindings DEBUG_DOWN = { .keycodes = { VK_DOWN } };
struct Keybindings DEBUG_ENTER = { .keycodes = { VK_RETURN } }; struct Keybindings DEBUG_ENTER = { .keycodes = { VK_RETURN } };
struct Keybindings P1_LEFT_BLUE = { .keycodes = { 'D' } }; struct Keybindings P1_LEFT_BLUE = { .keycodes = { 'D' } };
struct Keybindings P1_LEFT_RED = { .keycodes = { 'F' } }; struct Keybindings P1_LEFT_RED = { .keycodes = { 'F' } };
struct Keybindings P1_RIGHT_RED = { .keycodes = { 'J' } }; struct Keybindings P1_RIGHT_RED = { .keycodes = { 'J' } };
struct Keybindings P1_RIGHT_BLUE = { .keycodes = { 'K' } }; struct Keybindings P1_RIGHT_BLUE = { .keycodes = { 'K' } };
struct Keybindings P2_LEFT_BLUE = {}; struct Keybindings P2_LEFT_BLUE = {};
struct Keybindings P2_LEFT_RED = {}; struct Keybindings P2_LEFT_RED = {};
struct Keybindings P2_RIGHT_RED = {}; struct Keybindings P2_RIGHT_RED = {};
struct Keybindings P2_RIGHT_BLUE = {}; struct Keybindings P2_RIGHT_BLUE = {};
int coin_count = 0; int coin_count = 0;
bool testEnabled = false; bool testEnabled = false;
bool inited = false; bool inited = false;
HOOK_DYNAMIC (i64, __fastcall, DecCoin, i32 a1, u16 a2) { HOOK_DYNAMIC (i64, __fastcall, DecCoin, i32 a1, u16 a2) {
coin_count -= a2; coin_count -= a2;
@ -48,24 +48,15 @@ HOOK_DYNAMIC (i64, __fastcall, DecCoin, i32 a1, u16 a2) {
HOOK_DYNAMIC (u16, __fastcall, GetAnalogIn, u8 which) { HOOK_DYNAMIC (u16, __fastcall, GetAnalogIn, u8 which) {
switch (which) { switch (which) {
case 0: // Player 1 Left Blue case 0: IF_HIT (P1_LEFT_BLUE); // Player 1 Left Blue
IF_HIT (P1_LEFT_BLUE); case 1: IF_HIT (P1_LEFT_RED); // Player 1 Left Red
case 1: // Player 1 Left Red case 2: IF_HIT (P1_RIGHT_RED); // Player 1 Right Red
IF_HIT (P1_LEFT_RED); case 3: IF_HIT (P1_RIGHT_BLUE); // Player 1 Right Blue
case 2: // Player 1 Right Red case 4: IF_HIT (P2_LEFT_BLUE); // Player 2 Left Blue
IF_HIT (P1_RIGHT_RED); case 5: IF_HIT (P2_LEFT_RED); // Player 2 Left Red
case 3: // Player 1 Right Blue case 6: IF_HIT (P2_RIGHT_RED); // Player 2 Right Red
IF_HIT (P1_RIGHT_BLUE); case 7: IF_HIT (P2_RIGHT_BLUE); // Player 2 Right Blue
case 4: // Player 2 Left Blue default: return 0;
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;
} }
} }
@ -103,12 +94,9 @@ HOOK_DYNAMIC (u16, __fastcall, GetCoin, i32 a1) {
} }
UpdatePoll (windowHandle); UpdatePoll (windowHandle);
if (IsButtonTapped (COIN_ADD)) if (IsButtonTapped (COIN_ADD)) coin_count++;
coin_count++; if (IsButtonTapped (TEST)) testEnabled = !testEnabled;
if (IsButtonTapped (TEST)) if (IsButtonTapped (EXIT)) ExitProcess (0);
testEnabled = !testEnabled;
if (IsButtonTapped(EXIT))
ExitProcess(0);
} }
return coin_count; return coin_count;
} }
@ -129,17 +117,15 @@ HOOK_DYNAMIC (i64, __stdcall, ResetCoin) {
} }
i32 __stdcall DllMain (HMODULE mod, DWORD cause, void *ctx) { i32 __stdcall DllMain (HMODULE mod, DWORD cause, void *ctx) {
if (cause == DLL_PROCESS_DETACH) if (cause == DLL_PROCESS_DETACH) DisposePoll ();
DisposePoll (); if (cause != DLL_PROCESS_ATTACH) return 1;
if (cause != DLL_PROCESS_ATTACH)
return 1;
// Blatantly stolen patches from mon.im // Blatantly stolen patches from mon.im
WRITE_MEMORY (0x1400239C0, u8, 0xC3); // Stop error WRITE_MEMORY (0x1400239C0, u8, 0xC3); // Stop error
WRITE_MEMORY (0x140314E8D, u8, 0xB0, 0x01); // Unlock songs WRITE_MEMORY (0x140314E8D, u8, 0xB0, 0x01); // Unlock songs
WRITE_MEMORY (0x140692E17, u8, 0xEB); // Shared audio WRITE_MEMORY (0x140692E17, u8, 0xEB); // Shared audio
WRITE_MEMORY (0x140517339, u8, 0xBA, 0x00, 0x00, 0x00, 0x00, WRITE_MEMORY (0x140517339, u8, 0xBA, 0x00, 0x00, 0x00, 0x00,
0x90); // Disable VSync 0x90); // Disable VSync
INSTALL_HOOK_DYNAMIC (ShowMouse, PROC_ADDRESS ("user32.dll", "ShowCursor")); INSTALL_HOOK_DYNAMIC (ShowMouse, PROC_ADDRESS ("user32.dll", "ShowCursor"));
INSTALL_HOOK_DYNAMIC (DecCoin, PROC_ADDRESS ("bnusio.dll", "bnusio_DecCoin")); INSTALL_HOOK_DYNAMIC (DecCoin, PROC_ADDRESS ("bnusio.dll", "bnusio_DecCoin"));

View File

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

View File

@ -23,13 +23,13 @@ typedef uint64_t u64;
#define HOOK(returnType, callingConvention, functionName, location, ...) \ #define HOOK(returnType, callingConvention, functionName, location, ...) \
typedef returnType callingConvention (*functionName) (__VA_ARGS__); \ typedef returnType callingConvention (*functionName) (__VA_ARGS__); \
functionName original##functionName = NULL; \ functionName original##functionName = NULL; \
void *where##functionName = (void *)location; \ void *where##functionName = (void *)location; \
returnType callingConvention implOf##functionName (__VA_ARGS__) returnType callingConvention implOf##functionName (__VA_ARGS__)
#define HOOK_DYNAMIC(returnType, callingConvention, functionName, ...) \ #define HOOK_DYNAMIC(returnType, callingConvention, functionName, ...) \
typedef returnType callingConvention (*functionName) (__VA_ARGS__); \ typedef returnType callingConvention (*functionName) (__VA_ARGS__); \
functionName original##functionName = NULL; \ functionName original##functionName = NULL; \
void *where##functionName = NULL; \ void *where##functionName = NULL; \
returnType callingConvention implOf##functionName (__VA_ARGS__) returnType callingConvention implOf##functionName (__VA_ARGS__)
#define INSTALL_HOOK(functionName) \ #define INSTALL_HOOK(functionName) \
@ -84,10 +84,10 @@ typedef uint64_t u64;
#define COUNTOFARR(arr) sizeof (arr) / sizeof (arr[0]) #define COUNTOFARR(arr) sizeof (arr) / sizeof (arr[0])
#define WARNING_COLOUR (FOREGROUND_RED | FOREGROUND_GREEN) #define WARNING_COLOUR (FOREGROUND_RED | FOREGROUND_GREEN)
#define ERROR_COLOUR FOREGROUND_RED #define ERROR_COLOUR FOREGROUND_RED
#define printWarning(format, ...) printColour (WARNING_COLOUR, format, __VA_ARGS__) #define printWarning(format, ...) printColour (WARNING_COLOUR, format, __VA_ARGS__)
#define printError(format, ...) printColour (ERROR_COLOUR, format, __VA_ARGS__) #define printError(format, ...) printColour (ERROR_COLOUR, format, __VA_ARGS__)
char *configPath (char *name); char *configPath (char *name);
toml_table_t *openConfig (char *configFilePath); toml_table_t *openConfig (char *configFilePath);

View File

@ -6,16 +6,16 @@ struct {
const char *string; const char *string;
uint8_t keycode; uint8_t keycode;
} ConfigKeyboardButtons[] = { } ConfigKeyboardButtons[] = {
{ "F1", 0x70 }, { "F2", 0x71 }, { "F3", 0x72 }, { "F4", 0x73 }, { "F5", 0x74 }, { "F6", 0x75 }, { "F1", 0x70 }, { "F2", 0x71 }, { "F3", 0x72 }, { "F4", 0x73 }, { "F5", 0x74 }, { "F6", 0x75 },
{ "F7", 0x76 }, { "F8", 0x77 }, { "F9", 0x78 }, { "F10", 0x79 }, { "F11", 0x7A }, { "F12", 0x7B }, { "F7", 0x76 }, { "F8", 0x77 }, { "F9", 0x78 }, { "F10", 0x79 }, { "F11", 0x7A }, { "F12", 0x7B },
{ "NUM1", '1' }, { "NUM2", '2' }, { "NUM3", '3' }, { "NUM4", '4' }, { "NUM5", '5' }, { "NUM6", '6' }, { "NUM1", '1' }, { "NUM2", '2' }, { "NUM3", '3' }, { "NUM4", '4' }, { "NUM5", '5' }, { "NUM6", '6' },
{ "NUM7", '7' }, { "NUM8", '8' }, { "NUM9", '9' }, { "NUM0", '0' }, { "Q", 'Q' }, { "W", 'W' }, { "NUM7", '7' }, { "NUM8", '8' }, { "NUM9", '9' }, { "NUM0", '0' }, { "Q", 'Q' }, { "W", 'W' },
{ "E", 'E' }, { "R", 'R' }, { "T", 'T' }, { "Y", 'Y' }, { "U", 'U' }, { "I", 'I' }, { "E", 'E' }, { "R", 'R' }, { "T", 'T' }, { "Y", 'Y' }, { "U", 'U' }, { "I", 'I' },
{ "O", 'O' }, { "P", 'P' }, { "A", 'A' }, { "S", 'S' }, { "D", 'D' }, { "F", 'F' }, { "O", 'O' }, { "P", 'P' }, { "A", 'A' }, { "S", 'S' }, { "D", 'D' }, { "F", 'F' },
{ "G", 'G' }, { "H", 'H' }, { "J", 'J' }, { "K", 'K' }, { "L", 'L' }, { "Z", 'Z' }, { "G", 'G' }, { "H", 'H' }, { "J", 'J' }, { "K", 'K' }, { "L", 'L' }, { "Z", 'Z' },
{ "X", 'X' }, { "C", 'C' }, { "V", 'V' }, { "B", 'B' }, { "N", 'N' }, { "M", 'M' }, { "X", 'X' }, { "C", 'C' }, { "V", 'V' }, { "B", 'B' }, { "N", 'N' }, { "M", 'M' },
{ "UPARROW", 0x26 }, { "LEFTARROW", 0x25 }, { "DOWNARROW", 0x28 }, { "RIGHTARROW", 0x27 }, { "ENTER", 0x0D }, { "SPACE", 0x20 }, { "UPARROW", 0x26 }, { "LEFTARROW", 0x25 }, { "DOWNARROW", 0x28 }, { "RIGHTARROW", 0x27 }, { "ENTER", 0x0D }, { "SPACE", 0x20 },
{ "CONTROL", 0x11 }, { "SHIFT", 0x10 }, { "TAB", 0x09 }, { "ESCAPE", 0x1B }, { "CONTROL", 0x11 }, { "SHIFT", 0x10 }, { "TAB", 0x09 }, { "ESCAPE", 0x1B },
}; };
struct { struct {
@ -49,9 +49,9 @@ struct {
const char *string; const char *string;
enum SDLAxis axis; enum SDLAxis axis;
} ConfigControllerAXIS[] = { } ConfigControllerAXIS[] = {
{ "SDL_LSTICK_LEFT", SDL_AXIS_LEFT_LEFT }, { "SDL_LSTICK_UP", SDL_AXIS_LEFT_UP }, { "SDL_LSTICK_DOWN", SDL_AXIS_LEFT_DOWN }, { "SDL_LSTICK_LEFT", SDL_AXIS_LEFT_LEFT }, { "SDL_LSTICK_UP", SDL_AXIS_LEFT_UP }, { "SDL_LSTICK_DOWN", SDL_AXIS_LEFT_DOWN },
{ "SDL_LSTICK_RIGHT", SDL_AXIS_LEFT_RIGHT }, { "SDL_RSTICK_LEFT", SDL_AXIS_RIGHT_LEFT }, { "SDL_RSTICK_UP", SDL_AXIS_RIGHT_UP }, { "SDL_LSTICK_RIGHT", SDL_AXIS_LEFT_RIGHT }, { "SDL_RSTICK_LEFT", SDL_AXIS_RIGHT_LEFT }, { "SDL_RSTICK_UP", SDL_AXIS_RIGHT_UP },
{ "SDL_RSTICK_DOWN", SDL_AXIS_RIGHT_DOWN }, { "SDL_RSTICK_RIGHT", SDL_AXIS_RIGHT_RIGHT }, { "SDL_LTRIGGER", SDL_AXIS_LTRIGGER_DOWN }, { "SDL_RSTICK_DOWN", SDL_AXIS_RIGHT_DOWN }, { "SDL_RSTICK_RIGHT", SDL_AXIS_RIGHT_RIGHT }, { "SDL_LTRIGGER", SDL_AXIS_LTRIGGER_DOWN },
{ "SDL_RTRIGGER", SDL_AXIS_RTRIGGER_DOWN }, { "SDL_RTRIGGER", SDL_AXIS_RTRIGGER_DOWN },
}; };
@ -95,8 +95,7 @@ SetConfigValue (toml_table_t *table, char *key, struct Keybindings *keybind) {
for (int i = 0;; i++) { for (int i = 0;; i++) {
toml_datum_t bind = toml_string_at (array, i); toml_datum_t bind = toml_string_at (array, i);
if (!bind.ok) if (!bind.ok) break;
break;
struct ConfigValue value = StringToConfigEnum (bind.u.s); struct ConfigValue value = StringToConfigEnum (bind.u.s);
free (bind.u.s); free (bind.u.s);
@ -132,8 +131,7 @@ SetConfigValue (toml_table_t *table, char *key, struct Keybindings *keybind) {
} }
} }
break; break;
default: default: break;
break;
} }
} }
} }
@ -154,23 +152,22 @@ InitializePoll (void *DivaWindowHandle) {
} else { } else {
printError ( printError (
"SDL_Init (SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | " "SDL_Init (SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | "
"SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS | SDL_INIT_VIDEO): " "SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS | SDL_INIT_VIDEO): "
"%s\n", "%s\n",
SDL_GetError ()); SDL_GetError ());
return false; return false;
} }
} }
if (SDL_GameControllerAddMappingsFromFile (configPath ("gamecontrollerdb.txt")) == -1) if (SDL_GameControllerAddMappingsFromFile (configPath ("gamecontrollerdb.txt")) == -1)
printError ("%s (): Cannot read " printError ("%s (): Cannot read "
"plugins/gamecontrollerdb.txt\n", "plugins/gamecontrollerdb.txt\n",
__func__); __func__);
SDL_GameControllerEventState (SDL_ENABLE); SDL_GameControllerEventState (SDL_ENABLE);
for (int i = 0; i < SDL_NumJoysticks (); i++) { for (int i = 0; i < SDL_NumJoysticks (); i++) {
if (!SDL_IsGameController (i)) if (!SDL_IsGameController (i)) continue;
continue;
SDL_GameController *controller = SDL_GameControllerOpen (i); SDL_GameController *controller = SDL_GameControllerOpen (i);
@ -184,127 +181,94 @@ InitializePoll (void *DivaWindowHandle) {
} }
window = SDL_CreateWindowFrom (DivaWindowHandle); window = SDL_CreateWindowFrom (DivaWindowHandle);
if (window != NULL) if (window != NULL) SDL_SetWindowResizable (window, true);
SDL_SetWindowResizable (window, true); else printError ("SDL_CreateWindowFrom (DivaWindowHandle): %s\n", SDL_GetError ());
else
printError ("SDL_CreateWindowFrom (DivaWindowHandle): %s\n", SDL_GetError ());
return hasRumble; return hasRumble;
} }
void void
UpdatePoll (void *DivaWindowHandle) { UpdatePoll (void *DivaWindowHandle) {
if (DivaWindowHandle == NULL || GetForegroundWindow () != DivaWindowHandle) if (DivaWindowHandle == NULL || GetForegroundWindow () != DivaWindowHandle) return;
return;
memcpy (lastKeyboardState, currentKeyboardState, 255); memcpy (lastKeyboardState, currentKeyboardState, 255);
memcpy (lastControllerButtonsState, currentControllerButtonsState, 21); memcpy (lastControllerButtonsState, currentControllerButtonsState, 21);
lastMouseState = currentMouseState; lastMouseState = currentMouseState;
lastControllerAxisState = currentControllerAxisState; lastControllerAxisState = currentControllerAxisState;
for (uint8_t i = 0; i < 0xFF; i++) for (uint8_t i = 0; i < 0xFF; i++)
currentKeyboardState[i] = GetAsyncKeyState (i) != 0; currentKeyboardState[i] = GetAsyncKeyState (i) != 0;
currentMouseState.ScrolledUp = false; currentMouseState.ScrolledUp = false;
currentMouseState.ScrolledDown = false; currentMouseState.ScrolledDown = false;
SDL_Event event; SDL_Event event;
while (SDL_PollEvent (&event) != 0) { while (SDL_PollEvent (&event) != 0) {
switch (event.type) { switch (event.type) {
case SDL_CONTROLLERDEVICEADDED: case SDL_CONTROLLERDEVICEADDED:
if (!SDL_IsGameController (event.cdevice.which)) if (!SDL_IsGameController (event.cdevice.which)) break;
break;
SDL_GameController *controller = SDL_GameControllerOpen (event.cdevice.which); SDL_GameController *controller = SDL_GameControllerOpen (event.cdevice.which);
if (!controller) { if (!controller) {
printError ( printError (
"%s (): Could not open " "%s (): Could not open "
"gamecontroller %s: %s\n", "gamecontroller %s: %s\n",
__func__, SDL_GameControllerNameForIndex (event.cdevice.which), SDL_GetError ()); __func__, SDL_GameControllerNameForIndex (event.cdevice.which), SDL_GetError ());
continue; continue;
} }
controllers[event.cdevice.which] = controller; controllers[event.cdevice.which] = controller;
break; break;
case SDL_CONTROLLERDEVICEREMOVED: case SDL_CONTROLLERDEVICEREMOVED:
if (!SDL_IsGameController (event.cdevice.which)) if (!SDL_IsGameController (event.cdevice.which)) break;
break;
SDL_GameControllerClose (controllers[event.cdevice.which]); SDL_GameControllerClose (controllers[event.cdevice.which]);
break; break;
case SDL_MOUSEWHEEL: case SDL_MOUSEWHEEL:
if (event.wheel.y > 0) if (event.wheel.y > 0) currentMouseState.ScrolledUp = true;
currentMouseState.ScrolledUp = true; else if (event.wheel.y < 0) currentMouseState.ScrolledDown = true;
else if (event.wheel.y < 0)
currentMouseState.ScrolledDown = true;
break; break;
case SDL_CONTROLLERBUTTONUP: case SDL_CONTROLLERBUTTONUP:
case SDL_CONTROLLERBUTTONDOWN: case SDL_CONTROLLERBUTTONDOWN: currentControllerButtonsState[event.cbutton.button] = event.cbutton.state; break;
currentControllerButtonsState[event.cbutton.button] = event.cbutton.state;
break;
case SDL_CONTROLLERAXISMOTION: case SDL_CONTROLLERAXISMOTION:
if (event.caxis.value > 8000) { if (event.caxis.value > 8000) {
switch (event.caxis.axis) { switch (event.caxis.axis) {
case SDL_CONTROLLER_AXIS_LEFTX: case SDL_CONTROLLER_AXIS_LEFTX: currentControllerAxisState.LeftRight = 1; break;
currentControllerAxisState.LeftRight = 1; case SDL_CONTROLLER_AXIS_LEFTY: currentControllerAxisState.LeftDown = 1; break;
break; case SDL_CONTROLLER_AXIS_RIGHTX: currentControllerAxisState.RightRight = 1; break;
case SDL_CONTROLLER_AXIS_LEFTY: case SDL_CONTROLLER_AXIS_RIGHTY: currentControllerAxisState.RightDown = 1; break;
currentControllerAxisState.LeftDown = 1; case SDL_CONTROLLER_AXIS_TRIGGERLEFT: currentControllerAxisState.LTriggerDown = 1; break;
break; case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: currentControllerAxisState.RTriggerDown = 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) { } else if (event.caxis.value < -8000) {
switch (event.caxis.axis) { switch (event.caxis.axis) {
case SDL_CONTROLLER_AXIS_LEFTX: case SDL_CONTROLLER_AXIS_LEFTX: currentControllerAxisState.LeftLeft = 1; break;
currentControllerAxisState.LeftLeft = 1; case SDL_CONTROLLER_AXIS_LEFTY: currentControllerAxisState.LeftUp = 1; break;
break; case SDL_CONTROLLER_AXIS_RIGHTX: currentControllerAxisState.RightLeft = 1; break;
case SDL_CONTROLLER_AXIS_LEFTY: case SDL_CONTROLLER_AXIS_RIGHTY: currentControllerAxisState.RightUp = 1; break;
currentControllerAxisState.LeftUp = 1;
break;
case SDL_CONTROLLER_AXIS_RIGHTX:
currentControllerAxisState.RightLeft = 1;
break;
case SDL_CONTROLLER_AXIS_RIGHTY:
currentControllerAxisState.RightUp = 1;
break;
} }
} else { } else {
switch (event.caxis.axis) { switch (event.caxis.axis) {
case SDL_CONTROLLER_AXIS_LEFTX: case SDL_CONTROLLER_AXIS_LEFTX:
currentControllerAxisState.LeftRight = 0; currentControllerAxisState.LeftRight = 0;
currentControllerAxisState.LeftLeft = 0; currentControllerAxisState.LeftLeft = 0;
break; break;
case SDL_CONTROLLER_AXIS_LEFTY: case SDL_CONTROLLER_AXIS_LEFTY:
currentControllerAxisState.LeftDown = 0; currentControllerAxisState.LeftDown = 0;
currentControllerAxisState.LeftUp = 0; currentControllerAxisState.LeftUp = 0;
break; break;
case SDL_CONTROLLER_AXIS_RIGHTX: case SDL_CONTROLLER_AXIS_RIGHTX:
currentControllerAxisState.RightRight = 0; currentControllerAxisState.RightRight = 0;
currentControllerAxisState.RightLeft = 0; currentControllerAxisState.RightLeft = 0;
break; break;
case SDL_CONTROLLER_AXIS_RIGHTY: case SDL_CONTROLLER_AXIS_RIGHTY:
currentControllerAxisState.RightDown = 0; currentControllerAxisState.RightDown = 0;
currentControllerAxisState.RightUp = 0; currentControllerAxisState.RightUp = 0;
break;
case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
currentControllerAxisState.LTriggerDown = 0;
break;
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
currentControllerAxisState.RTriggerDown = 0;
break; break;
case SDL_CONTROLLER_AXIS_TRIGGERLEFT: currentControllerAxisState.LTriggerDown = 0; break;
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: currentControllerAxisState.RTriggerDown = 0; break;
} }
} }
break; break;
@ -323,13 +287,13 @@ StringToConfigEnum (char *value) {
struct ConfigValue rval = { 0 }; struct ConfigValue rval = { 0 };
for (int i = 0; i < COUNTOFARR (ConfigKeyboardButtons); ++i) for (int i = 0; i < COUNTOFARR (ConfigKeyboardButtons); ++i)
if (!strcmp (value, ConfigKeyboardButtons[i].string)) { if (!strcmp (value, ConfigKeyboardButtons[i].string)) {
rval.type = keycode; rval.type = keycode;
rval.keycode = ConfigKeyboardButtons[i].keycode; rval.keycode = ConfigKeyboardButtons[i].keycode;
return rval; return rval;
} }
for (int i = 0; i < COUNTOFARR (ConfigControllerButtons); ++i) for (int i = 0; i < COUNTOFARR (ConfigControllerButtons); ++i)
if (!strcmp (value, ConfigControllerButtons[i].string)) { if (!strcmp (value, ConfigControllerButtons[i].string)) {
rval.type = button; rval.type = button;
rval.button = ConfigControllerButtons[i].button; rval.button = ConfigControllerButtons[i].button;
return rval; return rval;
} }
@ -341,7 +305,7 @@ StringToConfigEnum (char *value) {
} }
for (int i = 0; i < COUNTOFARR (ConfigMouseScroll); ++i) for (int i = 0; i < COUNTOFARR (ConfigMouseScroll); ++i)
if (!strcmp (value, ConfigMouseScroll[i].string)) { if (!strcmp (value, ConfigMouseScroll[i].string)) {
rval.type = scroll; rval.type = scroll;
rval.scroll = ConfigMouseScroll[i].scroll; rval.scroll = ConfigMouseScroll[i].scroll;
return rval; return rval;
} }
@ -355,44 +319,28 @@ GetInternalButtonState (struct Keybindings bindings) {
struct InternalButtonState buttons = { 0 }; struct InternalButtonState buttons = { 0 };
for (int i = 0; i < COUNTOFARR (ConfigKeyboardButtons); i++) { for (int i = 0; i < COUNTOFARR (ConfigKeyboardButtons); i++) {
if (bindings.keycodes[i] == 0) if (bindings.keycodes[i] == 0) continue;
continue; if (KeyboardIsReleased (bindings.keycodes[i])) buttons.Released = 1;
if (KeyboardIsReleased (bindings.keycodes[i])) if (KeyboardIsDown (bindings.keycodes[i])) buttons.Down = 1;
buttons.Released = 1; if (KeyboardIsTapped (bindings.keycodes[i])) buttons.Tapped = 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++) { for (int i = 0; i < COUNTOFARR (ConfigControllerButtons); i++) {
if (bindings.buttons[i] == SDL_CONTROLLER_BUTTON_INVALID) if (bindings.buttons[i] == SDL_CONTROLLER_BUTTON_INVALID) continue;
continue; if (ControllerButtonIsReleased (bindings.buttons[i])) buttons.Released = 1;
if (ControllerButtonIsReleased (bindings.buttons[i])) if (ControllerButtonIsDown (bindings.buttons[i])) buttons.Down = 1;
buttons.Released = 1; if (ControllerButtonIsTapped (bindings.buttons[i])) buttons.Tapped = 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++) { for (int i = 0; i < COUNTOFARR (ConfigControllerAXIS); i++) {
if (bindings.axis[i] == 0) if (bindings.axis[i] == 0) continue;
continue; if (ControllerAxisIsReleased (bindings.axis[i])) buttons.Released = 1;
if (ControllerAxisIsReleased (bindings.axis[i])) if (ControllerAxisIsDown (bindings.axis[i])) buttons.Down = 1;
buttons.Released = 1; if (ControllerAxisIsTapped (bindings.axis[i])) buttons.Tapped = 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++) { for (int i = 0; i < COUNTOFARR (ConfigMouseScroll); i++) {
if (bindings.scroll[i] == 0) if (bindings.scroll[i] == 0) continue;
continue; if (GetMouseScrollIsReleased (bindings.scroll[i])) buttons.Released = 1;
if (GetMouseScrollIsReleased (bindings.scroll[i])) if (GetMouseScrollIsDown (bindings.scroll[i])) buttons.Down = 1;
buttons.Released = 1; if (GetMouseScrollIsTapped (bindings.scroll[i])) buttons.Tapped = 1;
if (GetMouseScrollIsDown (bindings.scroll[i]))
buttons.Down = 1;
if (GetMouseScrollIsTapped (bindings.scroll[i]))
buttons.Tapped = 1;
} }
return buttons; return buttons;
@ -401,8 +349,7 @@ GetInternalButtonState (struct Keybindings bindings) {
void void
SetRumble (int left, int right) { SetRumble (int left, int right) {
for (int i = 0; i < COUNTOFARR (controllers); i++) { for (int i = 0; i < COUNTOFARR (controllers); i++) {
if (!controllers[i] || !SDL_GameControllerHasRumble (controllers[i])) if (!controllers[i] || !SDL_GameControllerHasRumble (controllers[i])) continue;
continue;
SDL_GameControllerRumble (controllers[i], left, right, 1000); SDL_GameControllerRumble (controllers[i], left, right, 1000);
} }
@ -485,26 +432,20 @@ GetWasMouseScrollDown () {
inline bool inline bool
GetMouseScrollIsReleased (enum Scroll scroll) { GetMouseScrollIsReleased (enum Scroll scroll) {
if (scroll == MOUSE_SCROLL_UP) if (scroll == MOUSE_SCROLL_UP) return !GetMouseScrollUp () && GetWasMouseScrollUp ();
return !GetMouseScrollUp () && GetWasMouseScrollUp (); else return !GetMouseScrollDown () && GetWasMouseScrollDown ();
else
return !GetMouseScrollDown () && GetWasMouseScrollDown ();
} }
inline bool inline bool
GetMouseScrollIsDown (enum Scroll scroll) { GetMouseScrollIsDown (enum Scroll scroll) {
if (scroll == MOUSE_SCROLL_UP) if (scroll == MOUSE_SCROLL_UP) return GetMouseScrollUp ();
return GetMouseScrollUp (); else return GetMouseScrollDown ();
else
return GetMouseScrollDown ();
} }
inline bool inline bool
GetMouseScrollIsTapped (enum Scroll scroll) { GetMouseScrollIsTapped (enum Scroll scroll) {
if (scroll == MOUSE_SCROLL_UP) if (scroll == MOUSE_SCROLL_UP) return GetMouseScrollUp () && !GetWasMouseScrollUp ();
return GetMouseScrollUp () && !GetWasMouseScrollUp (); else return GetMouseScrollDown () && !GetWasMouseScrollDown ();
else
return GetMouseScrollDown () && !GetWasMouseScrollDown ();
} }
inline bool inline bool
@ -540,29 +481,18 @@ ControllerButtonIsReleased (SDL_GameControllerButton button) {
inline bool inline bool
ControllerAxisIsDown (enum SDLAxis axis) { ControllerAxisIsDown (enum SDLAxis axis) {
switch (axis) { switch (axis) {
case SDL_AXIS_LEFT_LEFT: case SDL_AXIS_LEFT_LEFT: return currentControllerAxisState.LeftLeft;
return currentControllerAxisState.LeftLeft; case SDL_AXIS_LEFT_RIGHT: return currentControllerAxisState.LeftRight;
case SDL_AXIS_LEFT_RIGHT: case SDL_AXIS_LEFT_UP: return currentControllerAxisState.LeftUp;
return currentControllerAxisState.LeftRight; case SDL_AXIS_LEFT_DOWN: return currentControllerAxisState.LeftDown;
case SDL_AXIS_LEFT_UP: case SDL_AXIS_RIGHT_LEFT: return currentControllerAxisState.RightLeft;
return currentControllerAxisState.LeftUp; case SDL_AXIS_RIGHT_RIGHT: return currentControllerAxisState.RightRight;
case SDL_AXIS_LEFT_DOWN: case SDL_AXIS_RIGHT_UP: return currentControllerAxisState.RightUp;
return currentControllerAxisState.LeftDown; case SDL_AXIS_RIGHT_DOWN: return currentControllerAxisState.RightDown;
case SDL_AXIS_RIGHT_LEFT: case SDL_AXIS_LTRIGGER_DOWN: return currentControllerAxisState.LTriggerDown;
return currentControllerAxisState.RightLeft; case SDL_AXIS_RTRIGGER_DOWN: return currentControllerAxisState.RTriggerDown;
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_NULL:
case SDL_AXIS_MAX: case SDL_AXIS_MAX: return false;
return false;
} }
} }
@ -574,29 +504,18 @@ ControllerAxisIsUp (enum SDLAxis axis) {
inline bool inline bool
ControllerAxisWasDown (enum SDLAxis axis) { ControllerAxisWasDown (enum SDLAxis axis) {
switch (axis) { switch (axis) {
case SDL_AXIS_LEFT_LEFT: case SDL_AXIS_LEFT_LEFT: return lastControllerAxisState.LeftLeft;
return lastControllerAxisState.LeftLeft; case SDL_AXIS_LEFT_RIGHT: return lastControllerAxisState.LeftRight;
case SDL_AXIS_LEFT_RIGHT: case SDL_AXIS_LEFT_UP: return lastControllerAxisState.LeftUp;
return lastControllerAxisState.LeftRight; case SDL_AXIS_LEFT_DOWN: return lastControllerAxisState.LeftDown;
case SDL_AXIS_LEFT_UP: case SDL_AXIS_RIGHT_LEFT: return lastControllerAxisState.RightLeft;
return lastControllerAxisState.LeftUp; case SDL_AXIS_RIGHT_RIGHT: return lastControllerAxisState.RightRight;
case SDL_AXIS_LEFT_DOWN: case SDL_AXIS_RIGHT_UP: return lastControllerAxisState.RightUp;
return lastControllerAxisState.LeftDown; case SDL_AXIS_RIGHT_DOWN: return lastControllerAxisState.RightDown;
case SDL_AXIS_RIGHT_LEFT: case SDL_AXIS_LTRIGGER_DOWN: return lastControllerAxisState.LTriggerDown;
return lastControllerAxisState.RightLeft; case SDL_AXIS_RTRIGGER_DOWN: return lastControllerAxisState.RTriggerDown;
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_NULL:
case SDL_AXIS_MAX: case SDL_AXIS_MAX: return false;
return false;
} }
} }