Clean up code
This commit is contained in:
parent
40959068c5
commit
dadc030205
12
Makefile
12
Makefile
@ -1,12 +1,10 @@
|
|||||||
OUT = TAL
|
OUT = TAL
|
||||||
CC := x86_64-w64-mingw32-gcc
|
CC := x86_64-w64-mingw32-gcc
|
||||||
CXX := x86_64-w64-mingw32-g++
|
|
||||||
TARGET := x86_64-pc-windows-gnu
|
TARGET := x86_64-pc-windows-gnu
|
||||||
SDL_TARGET := x86_64-w64-mingw32
|
SDL_TARGET := x86_64-w64-mingw32
|
||||||
SRC = src/dllmain.c src/helpers.c src/poll.c src/boilerplate.c src/card.cpp tomlc99/toml.c minhook/src/buffer.c minhook/src/hook.c minhook/src/trampoline.c minhook/src/hde/hde32.c minhook/src/hde/hde64.c
|
SRC = src/dllmain.c src/helpers.c src/poll.c src/boilerplate.c tomlc99/toml.c minhook/src/buffer.c minhook/src/hook.c minhook/src/trampoline.c minhook/src/hde/hde32.c minhook/src/hde/hde64.c
|
||||||
OBJ = ${addprefix ${TARGET}/,${subst .cpp,.o,${SRC:.c=.o}}}
|
OBJ = ${addprefix ${TARGET}/,${SRC:.c=.o}}
|
||||||
CFLAGS = -std=c99 -Iminhook/include -ISDL/${SDL_TARGET}/include -ISDL/include -Itomlc99 -Wall -Ofast -DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=_WIN32_WINNT_WIN7
|
CFLAGS = -std=c99 -Iminhook/include -ISDL/${SDL_TARGET}/include -ISDL/include -Itomlc99 -Wall -Ofast -DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=_WIN32_WINNT_WIN7
|
||||||
CXXFLAGS = -std=c++17 -Imingw-std-threads -Iminhook/include -ISDL/${SDL_TARGET}/include -ISDL/include -Itomlc99 -Wall -Ofast -DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=_WIN32_WINNT_WIN7
|
|
||||||
LDFLAGS := -shared -static -static-libgcc -s
|
LDFLAGS := -shared -static -static-libgcc -s
|
||||||
LIBS := SDL/${SDL_TARGET}/build/.libs/libSDL2.a SDL/${SDL_TARGET}/build/.libs/libSDL2main.a -lmingw32 -luuid -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lsetupapi -lversion -pthread
|
LIBS := SDL/${SDL_TARGET}/build/.libs/libSDL2.a SDL/${SDL_TARGET}/build/.libs/libSDL2main.a -lmingw32 -luuid -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lsetupapi -lversion -pthread
|
||||||
DEPS = SDL
|
DEPS = SDL
|
||||||
@ -29,10 +27,6 @@ ${TARGET}/%.o: %.c
|
|||||||
@echo BUILD $@
|
@echo BUILD $@
|
||||||
@${CC} -c ${CFLAGS} $< -o $@
|
@${CC} -c ${CFLAGS} $< -o $@
|
||||||
|
|
||||||
${TARGET}/%.o: %.cpp
|
|
||||||
@echo BUILD $@
|
|
||||||
@${CXX} -c ${CXXFLAGS} $< -o $@
|
|
||||||
|
|
||||||
.PHONY: SDL
|
.PHONY: SDL
|
||||||
SDL:
|
SDL:
|
||||||
@mkdir -p SDL/${SDL_TARGET}
|
@mkdir -p SDL/${SDL_TARGET}
|
||||||
@ -42,7 +36,7 @@ SDL:
|
|||||||
.PHONY: ${OUT}
|
.PHONY: ${OUT}
|
||||||
${OUT}: dirs ${DEPS} ${OBJ}
|
${OUT}: dirs ${DEPS} ${OBJ}
|
||||||
@echo LINK $@
|
@echo LINK $@
|
||||||
@${CXX} ${CXXFLAGS} -o ${TARGET}/$@.dll ${OBJ} ${LDFLAGS} ${LIBS}
|
@${CC} ${CFLAGS} -o ${TARGET}/$@.dll ${OBJ} ${LDFLAGS} ${LIBS}
|
||||||
|
|
||||||
.PHONY: fmt
|
.PHONY: fmt
|
||||||
fmt:
|
fmt:
|
||||||
|
45
src/card.cpp
45
src/card.cpp
@ -1,45 +0,0 @@
|
|||||||
#include "card.h"
|
|
||||||
#include "mingw.thread.h"
|
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
|
||||||
|
|
||||||
void
|
|
||||||
attach (callbackAttach callback, i32 *data) {
|
|
||||||
mingw_stdthread::thread t ([callback, data] () {
|
|
||||||
mingw_stdthread::this_thread::sleep_for (250ms);
|
|
||||||
callback (0, 0, data);
|
|
||||||
});
|
|
||||||
t.detach ();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool touchActive = true;
|
|
||||||
|
|
||||||
void
|
|
||||||
touch (callbackTouch callback, u64 data, Keybindings insertBind) {
|
|
||||||
touchActive = true;
|
|
||||||
mingw_stdthread::thread t ([callback, data, insertBind] () {
|
|
||||||
while (touchActive) {
|
|
||||||
mingw_stdthread::this_thread::sleep_for (100ms);
|
|
||||||
if (IsButtonDown (insertBind)) {
|
|
||||||
u8 cardData[168] = { 0x01, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x92, 0x2E, 0x58, 0x32, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x5C, 0x97, 0x44, 0xF0, 0x88, 0x04, 0x00, 0x43, 0x26,
|
|
||||||
0x2C, 0x33, 0x00, 0x04, 0x06, 0x10, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
|
||||||
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
|
||||||
0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4E, 0x42, 0x47, 0x49, 0x43, 0x36, 0x00, 0x00, 0xFA, 0xE9, 0x69, 0x00, 0xF6,
|
|
||||||
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
||||||
memcpy (cardData + 0x2C, "7F5C9744F111111143262C3300040610", 33);
|
|
||||||
memcpy (cardData + 0x50, "30764352518498791337", 21);
|
|
||||||
callback (0, 0, cardData, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
t.detach ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
touchCancel () {
|
|
||||||
touchActive = false;
|
|
||||||
}
|
|
13
src/card.h
13
src/card.h
@ -1,13 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "helpers.h"
|
|
||||||
#include "poll.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
void attach (callbackAttach callback, i32 *data);
|
|
||||||
void touch (callbackTouch callback, u64 data, Keybindings insertBind);
|
|
||||||
void touchCancel ();
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
@ -1,5 +1,4 @@
|
|||||||
#include "boilerplate.h"
|
#include "boilerplate.h"
|
||||||
#include "card.h"
|
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "poll.h"
|
#include "poll.h"
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@ -8,6 +7,14 @@ bool testEnabled = false;
|
|||||||
u16 drumMax = 0xFFFF;
|
u16 drumMax = 0xFFFF;
|
||||||
u16 drumMin = 0xFFFF;
|
u16 drumMin = 0xFFFF;
|
||||||
|
|
||||||
|
typedef i32 (*callbackAttach) (i32, i32, i32 *);
|
||||||
|
typedef void (*callbackTouch) (i32, i32, u8[168], u64);
|
||||||
|
bool waitingForTouch = false;
|
||||||
|
callbackTouch touchCallback;
|
||||||
|
u64 touchData;
|
||||||
|
callbackAttach attachCallback;
|
||||||
|
i32 *attachData;
|
||||||
|
|
||||||
#define ON_HIT(bind) IsButtonTapped (bind) ? drumMax == drumMin ? drumMax : (u16)(rand () % drumMax + drumMin) : 0
|
#define ON_HIT(bind) IsButtonTapped (bind) ? drumMax == drumMin ? drumMax : (u16)(rand () % drumMax + drumMin) : 0
|
||||||
|
|
||||||
Keybindings EXIT = { .keycodes = { VK_ESCAPE } };
|
Keybindings EXIT = { .keycodes = { VK_ESCAPE } };
|
||||||
@ -44,48 +51,62 @@ u16 __fastcall bnusio_GetAnalogIn (u8 which) {
|
|||||||
u16 __fastcall bnusio_GetCoin (i32 a1) {
|
u16 __fastcall bnusio_GetCoin (i32 a1) {
|
||||||
static int coin_count = 0;
|
static int coin_count = 0;
|
||||||
|
|
||||||
if (a1 == 1) {
|
if (a1 != 1) return coin_count;
|
||||||
static bool inited = false;
|
static bool inited = false;
|
||||||
static HWND windowHandle = 0;
|
static HWND windowHandle = 0;
|
||||||
|
|
||||||
if (!inited) {
|
if (!inited) {
|
||||||
windowHandle = FindWindowA ("nuFoundation.Window", 0);
|
windowHandle = FindWindowA ("nuFoundation.Window", 0);
|
||||||
|
|
||||||
InitializePoll (windowHandle);
|
InitializePoll (windowHandle);
|
||||||
|
|
||||||
toml_table_t *config = openConfig (configPath ("keyconfig.toml"));
|
toml_table_t *config = openConfig (configPath ("keyconfig.toml"));
|
||||||
if (config) {
|
if (config) {
|
||||||
SetConfigValue (config, "EXIT", &EXIT);
|
SetConfigValue (config, "EXIT", &EXIT);
|
||||||
|
|
||||||
SetConfigValue (config, "TEST", &TEST);
|
SetConfigValue (config, "TEST", &TEST);
|
||||||
SetConfigValue (config, "SERVICE", &SERVICE);
|
SetConfigValue (config, "SERVICE", &SERVICE);
|
||||||
SetConfigValue (config, "DEBUG_UP", &DEBUG_UP);
|
SetConfigValue (config, "DEBUG_UP", &DEBUG_UP);
|
||||||
SetConfigValue (config, "DEBUG_DOWN", &DEBUG_DOWN);
|
SetConfigValue (config, "DEBUG_DOWN", &DEBUG_DOWN);
|
||||||
SetConfigValue (config, "DEBUG_ENTER", &DEBUG_ENTER);
|
SetConfigValue (config, "DEBUG_ENTER", &DEBUG_ENTER);
|
||||||
|
|
||||||
SetConfigValue (config, "COIN_ADD", &COIN_ADD);
|
SetConfigValue (config, "COIN_ADD", &COIN_ADD);
|
||||||
SetConfigValue (config, "CARD_INSERT", &CARD_INSERT);
|
SetConfigValue (config, "CARD_INSERT", &CARD_INSERT);
|
||||||
|
|
||||||
SetConfigValue (config, "P1_LEFT_BLUE", &P1_LEFT_BLUE);
|
SetConfigValue (config, "P1_LEFT_BLUE", &P1_LEFT_BLUE);
|
||||||
SetConfigValue (config, "P1_LEFT_RED", &P1_LEFT_RED);
|
SetConfigValue (config, "P1_LEFT_RED", &P1_LEFT_RED);
|
||||||
SetConfigValue (config, "P1_RIGHT_RED", &P1_RIGHT_RED);
|
SetConfigValue (config, "P1_RIGHT_RED", &P1_RIGHT_RED);
|
||||||
SetConfigValue (config, "P1_RIGHT_BLUE", &P1_RIGHT_BLUE);
|
SetConfigValue (config, "P1_RIGHT_BLUE", &P1_RIGHT_BLUE);
|
||||||
SetConfigValue (config, "P2_LEFT_BLUE", &P2_LEFT_BLUE);
|
SetConfigValue (config, "P2_LEFT_BLUE", &P2_LEFT_BLUE);
|
||||||
SetConfigValue (config, "P2_LEFT_RED", &P2_LEFT_RED);
|
SetConfigValue (config, "P2_LEFT_RED", &P2_LEFT_RED);
|
||||||
SetConfigValue (config, "P2_RIGHT_RED", &P2_RIGHT_RED);
|
SetConfigValue (config, "P2_RIGHT_RED", &P2_RIGHT_RED);
|
||||||
SetConfigValue (config, "P2_RIGHT_BLUE", &P2_RIGHT_BLUE);
|
SetConfigValue (config, "P2_RIGHT_BLUE", &P2_RIGHT_BLUE);
|
||||||
|
|
||||||
toml_free (config);
|
toml_free (config);
|
||||||
}
|
|
||||||
|
|
||||||
inited = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdatePoll (windowHandle);
|
inited = true;
|
||||||
if (IsButtonTapped (COIN_ADD) && !testEnabled) coin_count++;
|
|
||||||
if (IsButtonTapped (TEST)) testEnabled = !testEnabled;
|
|
||||||
if (IsButtonTapped (EXIT)) ExitProcess (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdatePoll (windowHandle);
|
||||||
|
if (IsButtonTapped (COIN_ADD) && !testEnabled) coin_count++;
|
||||||
|
if (IsButtonTapped (TEST)) testEnabled = !testEnabled;
|
||||||
|
if (IsButtonTapped (EXIT)) ExitProcess (0);
|
||||||
|
if (waitingForTouch && IsButtonTapped (CARD_INSERT)) {
|
||||||
|
u8 cardData[168]
|
||||||
|
= { 0x01, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x92, 0x2E, 0x58, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x5C, 0x97, 0x44, 0xF0, 0x88, 0x04, 0x00, 0x43, 0x26, 0x2C, 0x33, 0x00, 0x04,
|
||||||
|
0x06, 0x10, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4E, 0x42, 0x47, 0x49, 0x43, 0x36,
|
||||||
|
0x00, 0x00, 0xFA, 0xE9, 0x69, 0x00, 0xF6, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
memcpy (cardData + 0x2C, "7F5C9744F111111143262C3300040610", 33);
|
||||||
|
memcpy (cardData + 0x50, "30764352518498791337", 21);
|
||||||
|
touchCallback (0, 0, cardData, touchData);
|
||||||
|
}
|
||||||
|
if (attachCallback) attachCallback (0, 0, attachData);
|
||||||
return coin_count;
|
return coin_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,17 +121,21 @@ u32 __stdcall bnusio_GetSwIn () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
HOOK_DYNAMIC (u64, __stdcall, bngrw_attach, i32 a1, char *a2, i32 a3, i32 a4, callbackAttach callback, i32 *a6) {
|
HOOK_DYNAMIC (u64, __stdcall, bngrw_attach, i32 a1, char *a2, i32 a3, i32 a4, callbackAttach callback, i32 *a6) {
|
||||||
attach (callback, a6);
|
// This is way too fucking jank
|
||||||
|
attachCallback = callback;
|
||||||
|
attachData = a6;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
HOOK_DYNAMIC (i32, __stdcall, bngrw_reqWaitTouch, u32 a1, i32 a2, u32 a3, callbackTouch callback, u64 a5) {
|
HOOK_DYNAMIC (i32, __stdcall, bngrw_reqWaitTouch, u32 a1, i32 a2, u32 a3, callbackTouch callback, u64 a5) {
|
||||||
touch (callback, a5, CARD_INSERT);
|
waitingForTouch = true;
|
||||||
|
touchCallback = callback;
|
||||||
|
touchData = a5;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
HOOK_DYNAMIC (i32, __stdcall, bngrw_ReqCancel, u32 a1) {
|
HOOK_DYNAMIC (i32, __stdcall, bngrw_ReqCancel, u32 a1) {
|
||||||
touchCancel ();
|
waitingForTouch = false;
|
||||||
return (7 < a1 ? -100 : 1);
|
return (7 < a1 ? -100 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,8 +14,6 @@ typedef uint8_t u8;
|
|||||||
typedef uint16_t u16;
|
typedef uint16_t u16;
|
||||||
typedef uint32_t u32;
|
typedef uint32_t u32;
|
||||||
typedef uint64_t u64;
|
typedef uint64_t u64;
|
||||||
typedef i32 (*callbackAttach) (i32, i32, i32 *);
|
|
||||||
typedef void (*callbackTouch) (i32, i32, u8[168], u64);
|
|
||||||
|
|
||||||
#ifdef BASE_ADDRESS
|
#ifdef BASE_ADDRESS
|
||||||
#define ASLR(address, handle) ((u64)handle + (u64)address - (u64)BASE_ADDRESS)
|
#define ASLR(address, handle) ((u64)handle + (u64)address - (u64)BASE_ADDRESS)
|
||||||
|
@ -62,9 +62,6 @@ struct InternalButtonState {
|
|||||||
unsigned int Tapped : 1;
|
unsigned int Tapped : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
bool InitializePoll (void *DivaWindowHandle);
|
bool InitializePoll (void *DivaWindowHandle);
|
||||||
void UpdatePoll (void *DivaWindowHandle);
|
void UpdatePoll (void *DivaWindowHandle);
|
||||||
void DisposePoll ();
|
void DisposePoll ();
|
||||||
@ -107,6 +104,3 @@ bool ControllerAxisIsReleased (enum SDLAxis axis);
|
|||||||
bool IsButtonTapped (struct Keybindings bindings);
|
bool IsButtonTapped (struct Keybindings bindings);
|
||||||
bool IsButtonReleased (struct Keybindings bindings);
|
bool IsButtonReleased (struct Keybindings bindings);
|
||||||
bool IsButtonDown (struct Keybindings bindings);
|
bool IsButtonDown (struct Keybindings bindings);
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
Loading…
Reference in New Issue
Block a user