Skip to content

Commit

Permalink
Fix duplicate threads for wifi, minor clean.
Browse files Browse the repository at this point in the history
  • Loading branch information
Koi-3088 committed Apr 18, 2023
1 parent 99ad23b commit 0669006
Showing 1 changed file with 7 additions and 36 deletions.
43 changes: 7 additions & 36 deletions sys-botbase/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ void __appExit(void)
pmdmntExit();
ldrDmntExit();
pminfoExit();
fsExit();
fsdevUnmountAll();
handle_disconnect();
capsscExit();
viExit();
Expand All @@ -160,7 +158,7 @@ bool echoCommands = false;
void makeTouch(HidTouchState* state, u64 sequentialCount, u64 holdTime, bool hold)
{
mutexLock(&touchMutex);
memset(&currentTouchEvent, 0, sizeof currentTouchEvent);
memset(&currentTouchEvent, 0, sizeof(currentTouchEvent));
currentTouchEvent.states = state;
currentTouchEvent.sequentialCount = sequentialCount;
currentTouchEvent.holdTime = holdTime;
Expand All @@ -172,7 +170,7 @@ void makeTouch(HidTouchState* state, u64 sequentialCount, u64 holdTime, bool hol
void makeKeys(HiddbgKeyboardAutoPilotState* states, u64 sequentialCount)
{
mutexLock(&keyMutex);
memset(&currentKeyEvent, 0, sizeof currentKeyEvent);
memset(&currentKeyEvent, 0, sizeof(currentKeyEvent));
currentKeyEvent.states = states;
currentKeyEvent.sequentialCount = sequentialCount;
currentKeyEvent.state = 1;
Expand Down Expand Up @@ -1141,47 +1139,17 @@ void wifiMainLoop()

int c = sizeof(struct sockaddr_in);
struct sockaddr_in client;

struct pollfd *pfds = malloc(sizeof *pfds * fd_size);
struct pollfd* pfds = malloc(sizeof(*pfds) * fd_size);

int listenfd = setupServerSocket();
pfds[0].fd = listenfd;
pfds[0].events = POLLIN;
fd_count = 1;

int newfd;

Result rc;
int fr_count = 0;

initFreezes();

// freeze thread
mutexInit(&freezeMutex);
rc = threadCreate(&freezeThread, sub_freeze, (void*)&freeze_thr_state, NULL, THREAD_SIZE, 0x2C, -2);
if (R_SUCCEEDED(rc))
rc = threadStart(&freezeThread);

// touch thread
mutexInit(&touchMutex);
rc = threadCreate(&touchThread, sub_touch, (void*)&currentTouchEvent, NULL, THREAD_SIZE, 0x2C, -2);
if (R_SUCCEEDED(rc))
rc = threadStart(&touchThread);

// key thread
mutexInit(&keyMutex);
rc = threadCreate(&keyboardThread, sub_key, (void*)&currentKeyEvent, NULL, THREAD_SIZE, 0x2C, -2);
if (R_SUCCEEDED(rc))
rc = threadStart(&keyboardThread);

// click sequence thread
mutexInit(&clickMutex);
rc = threadCreate(&clickThread, sub_click, (void*)currentClick, NULL, THREAD_SIZE, 0x2C, -2);
if (R_SUCCEEDED(rc))
rc = threadStart(&clickThread);

flashLed();

while (appletMainLoop())
{
poll(pfds, fd_count, -1);
Expand Down Expand Up @@ -1256,8 +1224,8 @@ void usbMainLoop()
{
USBResponse response;
int fr_count = 0;
flashLed();

flashLed();
while (appletMainLoop())
{
int lenUSB;
Expand Down Expand Up @@ -1472,6 +1440,9 @@ bool handle_connection()
if (usb)
rc = usbCommsInitialize();
else rc = socketInitializeDefault();

fsExit();
fsdevUnmountAll();

if (R_FAILED(rc))
return false;
Expand Down

0 comments on commit 0669006

Please sign in to comment.