Add WaitTouch plugin
This commit is contained in:
parent
c53247cf3e
commit
cc469e1fd4
26
PLUGINS.md
Normal file
26
PLUGINS.md
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
### Guide for making additional plugins
|
||||||
|
|
||||||
|
Plugins are just libraries with certain exported functions that go in the plugins folder.
|
||||||
|
|
||||||
|
```
|
||||||
|
void PreInit()
|
||||||
|
```
|
||||||
|
Runs in dllmain, may run into loader locks. You can also just use your own dllmain for this but that involves writing out all the arguments.
|
||||||
|
```
|
||||||
|
void Init()
|
||||||
|
```
|
||||||
|
Runs on bngrw_Init, may be a bit late for some things but should generally allow functions which would cause loader locks to run fine if a bit late.
|
||||||
|
```
|
||||||
|
void Exit()
|
||||||
|
```
|
||||||
|
Runs on bnusio_Close, dispose of any data here.
|
||||||
|
```
|
||||||
|
void WaitTouch(i32 (*callback) (i32, i32, u8[168], u64), u64 data)
|
||||||
|
```
|
||||||
|
Runs on bngrw_reqWaitTouch. Call the callback like so when you wish to have a card scanned.
|
||||||
|
```
|
||||||
|
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, chipId, 33);
|
||||||
|
memcpy (cardData + 0x50, accessCode, 21);
|
||||||
|
callback(0, 0, cardData, data);
|
||||||
|
```
|
@ -11,16 +11,18 @@ char accessCode1[21] = "00000000000000000001";
|
|||||||
char accessCode2[21] = "00000000000000000002";
|
char accessCode2[21] = "00000000000000000002";
|
||||||
char chipId1[33] = "00000000000000000000000000000001";
|
char chipId1[33] = "00000000000000000000000000000001";
|
||||||
char chipId2[33] = "00000000000000000000000000000002";
|
char chipId2[33] = "00000000000000000000000000000002";
|
||||||
|
|
||||||
char *server = "https://divamodarchive.com";
|
char *server = "https://divamodarchive.com";
|
||||||
|
|
||||||
typedef i32 (*callbackAttach) (i32, i32, i32 *);
|
typedef i32 (*callbackAttach) (i32, i32, i32 *);
|
||||||
typedef void (*callbackTouch) (i32, i32, u8[168], u64);
|
typedef void (*callbackTouch) (i32, i32, u8[168], u64);
|
||||||
|
typedef void event ();
|
||||||
|
typedef void waitTouchEvent (callbackTouch, u64);
|
||||||
bool waitingForTouch = false;
|
bool waitingForTouch = false;
|
||||||
callbackTouch touchCallback;
|
callbackTouch touchCallback;
|
||||||
u64 touchData;
|
u64 touchData;
|
||||||
callbackAttach attachCallback;
|
callbackAttach attachCallback;
|
||||||
i32 *attachData;
|
i32 *attachData;
|
||||||
|
HMODULE plugins[255] = { 0 };
|
||||||
|
|
||||||
#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
|
||||||
|
|
||||||
@ -136,62 +138,18 @@ u32 __stdcall bnusio_GetSwIn () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
i64 __stdcall bnusio_Close () {
|
i64 __stdcall bnusio_Close () {
|
||||||
wchar_t path[MAX_PATH];
|
for (int i = 0; plugins[i] != 0; i++) {
|
||||||
GetModuleFileNameW (NULL, path, MAX_PATH);
|
FARPROC exitEvent = GetProcAddress (plugins[i], "Exit");
|
||||||
*wcsrchr (path, '\\') = '\0';
|
|
||||||
SetCurrentDirectoryW (path);
|
|
||||||
|
|
||||||
WIN32_FIND_DATAW fd;
|
|
||||||
HANDLE hFind = FindFirstFileW (L"plugins/*.dll", &fd);
|
|
||||||
if (hFind != INVALID_HANDLE_VALUE) {
|
|
||||||
do {
|
|
||||||
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue;
|
|
||||||
wchar_t filePath[MAX_PATH];
|
|
||||||
wcscpy (filePath, path);
|
|
||||||
wcscat (filePath, L"/plugins/");
|
|
||||||
wcscat (filePath, fd.cFileName);
|
|
||||||
HMODULE hModule = LoadLibraryW (filePath);
|
|
||||||
if (!hModule) {
|
|
||||||
wchar_t buf[128];
|
|
||||||
swprintf (buf, 128, L"Failed to load plugin %d", GetLastError ());
|
|
||||||
MessageBoxW (NULL, buf, fd.cFileName, MB_ICONERROR);
|
|
||||||
} else {
|
|
||||||
FARPROC exitEvent = GetProcAddress (hModule, "Exit");
|
|
||||||
if (exitEvent) ((event *)exitEvent) ();
|
if (exitEvent) ((event *)exitEvent) ();
|
||||||
}
|
}
|
||||||
} while (FindNextFileW (hFind, &fd));
|
|
||||||
FindClose (hFind);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
HOOK_DYNAMIC (u64, __stdcall, bngrw_Init) {
|
HOOK_DYNAMIC (u64, __stdcall, bngrw_Init) {
|
||||||
wchar_t path[MAX_PATH];
|
for (int i = 0; plugins[i] != 0; i++) {
|
||||||
GetModuleFileNameW (NULL, path, MAX_PATH);
|
FARPROC initEvent = GetProcAddress (plugins[i], "Init");
|
||||||
*wcsrchr (path, '\\') = '\0';
|
|
||||||
SetCurrentDirectoryW (path);
|
|
||||||
|
|
||||||
WIN32_FIND_DATAW fd;
|
|
||||||
HANDLE hFind = FindFirstFileW (L"plugins/*.dll", &fd);
|
|
||||||
if (hFind != INVALID_HANDLE_VALUE) {
|
|
||||||
do {
|
|
||||||
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue;
|
|
||||||
wchar_t filePath[MAX_PATH];
|
|
||||||
wcscpy (filePath, path);
|
|
||||||
wcscat (filePath, L"/plugins/");
|
|
||||||
wcscat (filePath, fd.cFileName);
|
|
||||||
HMODULE hModule = LoadLibraryW (filePath);
|
|
||||||
if (!hModule) {
|
|
||||||
wchar_t buf[128];
|
|
||||||
swprintf (buf, 128, L"Failed to load plugin %d", GetLastError ());
|
|
||||||
MessageBoxW (NULL, buf, fd.cFileName, MB_ICONERROR);
|
|
||||||
} else {
|
|
||||||
FARPROC initEvent = GetProcAddress (hModule, "Init");
|
|
||||||
if (initEvent) ((event *)initEvent) ();
|
if (initEvent) ((event *)initEvent) ();
|
||||||
}
|
}
|
||||||
} while (FindNextFileW (hFind, &fd));
|
|
||||||
FindClose (hFind);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,6 +164,10 @@ HOOK_DYNAMIC (i32, __stdcall, bngrw_reqWaitTouch, u32 a1, i32 a2, u32 a3, callba
|
|||||||
waitingForTouch = true;
|
waitingForTouch = true;
|
||||||
touchCallback = callback;
|
touchCallback = callback;
|
||||||
touchData = a5;
|
touchData = a5;
|
||||||
|
for (int i = 0; plugins[i] != 0; i++) {
|
||||||
|
FARPROC touchEvent = GetProcAddress (plugins[i], "WaitTouch");
|
||||||
|
if (touchEvent) ((waitTouchEvent *)touchEvent) (callback, a5);
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,6 +199,7 @@ i32 __stdcall DllMain (HMODULE mod, DWORD cause, void *ctx) {
|
|||||||
SetCurrentDirectoryW (path);
|
SetCurrentDirectoryW (path);
|
||||||
|
|
||||||
WIN32_FIND_DATAW fd;
|
WIN32_FIND_DATAW fd;
|
||||||
|
int i = 0;
|
||||||
HANDLE hFind = FindFirstFileW (L"plugins/*.dll", &fd);
|
HANDLE hFind = FindFirstFileW (L"plugins/*.dll", &fd);
|
||||||
if (hFind != INVALID_HANDLE_VALUE) {
|
if (hFind != INVALID_HANDLE_VALUE) {
|
||||||
do {
|
do {
|
||||||
@ -251,6 +214,8 @@ i32 __stdcall DllMain (HMODULE mod, DWORD cause, void *ctx) {
|
|||||||
swprintf (buf, 128, L"Failed to load plugin %d", GetLastError ());
|
swprintf (buf, 128, L"Failed to load plugin %d", GetLastError ());
|
||||||
MessageBoxW (NULL, buf, fd.cFileName, MB_ICONERROR);
|
MessageBoxW (NULL, buf, fd.cFileName, MB_ICONERROR);
|
||||||
} else {
|
} else {
|
||||||
|
plugins[i] = hModule;
|
||||||
|
i++;
|
||||||
FARPROC preInitEvent = GetProcAddress (hModule, "PreInit");
|
FARPROC preInitEvent = GetProcAddress (hModule, "PreInit");
|
||||||
if (preInitEvent) ((event *)preInitEvent) ();
|
if (preInitEvent) ((event *)preInitEvent) ();
|
||||||
}
|
}
|
||||||
|
@ -14,7 +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 void event ();
|
|
||||||
|
|
||||||
#ifdef DEFINE_GUID
|
#ifdef DEFINE_GUID
|
||||||
#undef DEFINE_GUID
|
#undef DEFINE_GUID
|
||||||
|
Loading…
Reference in New Issue
Block a user