-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from berichan/master
Add freeze thread, pointer follows, keyboard emulation + threads for both hid emu
- Loading branch information
Showing
10 changed files
with
703 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,4 @@ | |
} | ||
], | ||
"version": 4 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "DKP aarch64", | ||
"includePath": [ | ||
"C:/devkitPro/devkitA64/aarch64-none-elf/include/**", | ||
"C:/devkitPro/devkitA64/lib/gcc/aarch64-none-elf/10.2.0/include/**", | ||
"C:/devkitPro/libnx/include/**", | ||
"C:/devkitPro/portlibs/switch/include/**" | ||
], | ||
"defines": [ | ||
"SWITCH", | ||
"__SWITCH__", | ||
"DEBUG" | ||
], | ||
"compilerPath": "C:/devkitPro/devkitA64/bin/aarch64-none-elf-g++", | ||
"cStandard": "c11", | ||
"cppStandard": "c++17", | ||
"intelliSenseMode": "gcc-arm64" | ||
} | ||
], | ||
"version": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"files.associations": { | ||
"switch.h": "c" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#include <string.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <sys/socket.h> | ||
#include <sys/errno.h> | ||
#include <arpa/inet.h> | ||
#include <unistd.h> | ||
#include <switch.h> | ||
#include "freeze.h" | ||
|
||
FreezeBlock* freezes; | ||
|
||
void initFreezes(void) | ||
{ | ||
freezes = calloc(FREEZE_DIC_LENGTH, sizeof(FreezeBlock)); | ||
} | ||
|
||
void freeFreezes(void) | ||
{ | ||
free(freezes); | ||
} | ||
|
||
int findAddrSlot(u64 addr) | ||
{ | ||
for (int i = 0; i < FREEZE_DIC_LENGTH; i++) | ||
{ | ||
if (freezes[i].address == addr) | ||
return i; | ||
} | ||
|
||
return -1; | ||
} | ||
|
||
int findNextEmptySlot() | ||
{ | ||
return findAddrSlot(0); | ||
} | ||
|
||
int addToFreezeMap(u64 addr, u8* v_data, u64 v_size, u64 tid) | ||
{ | ||
// update slot if already exists | ||
int slot = findAddrSlot(addr); | ||
if (slot == -1) | ||
slot = findNextEmptySlot(); | ||
else | ||
removeFromFreezeMap(addr); | ||
|
||
if (slot == -1) | ||
return 0; | ||
|
||
freezes[slot].address = addr; | ||
freezes[slot].vData = v_data; | ||
freezes[slot].size = v_size; | ||
freezes[slot].state = 1; | ||
freezes[slot].titleId = tid; | ||
|
||
return slot; | ||
} | ||
|
||
int removeFromFreezeMap(u64 addr) | ||
{ | ||
int slot = findAddrSlot(addr); | ||
if (slot == -1) | ||
return 0; | ||
freezes[slot].address = 0; | ||
freezes[slot].state = 0; | ||
free(freezes[slot].vData); | ||
return slot; | ||
} | ||
|
||
int getFreezeCount(bool print) | ||
{ | ||
int count = 0; | ||
for (int i = 0; i < FREEZE_DIC_LENGTH; i++) | ||
{ | ||
if (freezes[i].state != 0) | ||
++count; | ||
} | ||
if (print) | ||
{ | ||
printf("%02X", count); | ||
printf("\n"); | ||
} | ||
return count; | ||
} | ||
|
||
// returns 0 if there was nothing to clear | ||
u8 clearFreezes(void) | ||
{ | ||
u8 clearedOne = 0; | ||
for (int i = 0; i < FREEZE_DIC_LENGTH; i++) | ||
{ | ||
if (freezes[i].state != 0) | ||
{ | ||
removeFromFreezeMap(freezes[i].address); | ||
clearedOne = 1; | ||
} | ||
} | ||
return clearedOne; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <switch.h> | ||
#define FREEZE_DIC_LENGTH 255 | ||
|
||
typedef struct { | ||
char state; | ||
u64 address; | ||
u8* vData; | ||
u64 size; | ||
u64 titleId; | ||
} FreezeBlock; | ||
|
||
extern FreezeBlock* freezes; | ||
|
||
void initFreezes(void); | ||
void freeFreezes(void); | ||
int findAddrSlot(u64 addr); | ||
int findNextEmptySlot(); | ||
int addToFreezeMap(u64 addr, u8* v_data, u64 v_size, u64 tid); | ||
int removeFromFreezeMap(u64 addr); | ||
int getFreezeCount(bool print); | ||
u8 clearFreezes(void); |
Oops, something went wrong.