sysclk: fix integration with saltynx
This commit is contained in:
@@ -32,69 +32,76 @@ bool SysDockIntegration::getCurrentSysDockState() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool wasSaltyNxLoaded = false;
|
|
||||||
SaltyNXIntegration::SaltyNXIntegration() {
|
SaltyNXIntegration::SaltyNXIntegration() {
|
||||||
if(!CheckPort()) {
|
if (!CheckPort())
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
wasSaltyNxLoaded = true;
|
|
||||||
LoadSharedMemory();
|
LoadSharedMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SaltyNXIntegration::CheckPort() {
|
||||||
//Check if SaltyNX is working
|
|
||||||
bool SaltyNXIntegration::CheckPort () {
|
|
||||||
Handle saltysd;
|
Handle saltysd;
|
||||||
for (int i = 0; i < 500; i++) {
|
|
||||||
|
for (int i = 0; i < 67; i++) {
|
||||||
|
if (R_SUCCEEDED(svcConnectToNamedPort(&saltysd, "InjectServ"))) {
|
||||||
|
svcCloseHandle(saltysd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (i == 66) return false;
|
||||||
|
svcSleepThread(1'000'000);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 67; i++) {
|
||||||
if (R_SUCCEEDED(svcConnectToNamedPort(&saltysd, "InjectServ"))) {
|
if (R_SUCCEEDED(svcConnectToNamedPort(&saltysd, "InjectServ"))) {
|
||||||
svcCloseHandle(saltysd);
|
svcCloseHandle(saltysd);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
svcSleepThread(1'000'000);
|
||||||
if (i == 499) return false;
|
|
||||||
svcSleepThread(100'000'000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaltyNXIntegration::LoadSharedMemory() {
|
void SaltyNXIntegration::LoadSharedMemory() {
|
||||||
if (SaltySD_Connect())
|
if (SaltySD_Connect())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SaltySD_GetSharedMemoryHandle(&remoteSharedMemory);
|
SaltySD_GetSharedMemoryHandle(&remoteSharedMemory);
|
||||||
SaltySD_Term();
|
SaltySD_Term();
|
||||||
|
|
||||||
shmemLoadRemote(&_sharedmemory, remoteSharedMemory, 0x1000, Perm_Rw);
|
shmemLoadRemote(&_sharedmemory, remoteSharedMemory, 0x1000, Perm_Rw);
|
||||||
if (!shmemMap(&_sharedmemory))
|
if (!shmemMap(&_sharedmemory))
|
||||||
SharedMemoryUsed = true;
|
SharedMemoryUsed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaltyNXIntegration::searchSharedMemoryBlock(uintptr_t base) {
|
void SaltyNXIntegration::searchSharedMemoryBlock(uintptr_t base) {
|
||||||
ptrdiff_t search_offset = 0;
|
ptrdiff_t search_offset = 0;
|
||||||
while(search_offset < 0x1000) {
|
while (search_offset < 0x1000) {
|
||||||
NxFps = (NxFpsSharedBlock*)(base + search_offset);
|
NxFps = (NxFpsSharedBlock*)(base + search_offset);
|
||||||
if (NxFps -> MAGIC == 0x465053) {
|
if (NxFps->MAGIC == 0x465053)
|
||||||
return;
|
return;
|
||||||
}
|
search_offset += 4;
|
||||||
else search_offset += 4;
|
|
||||||
}
|
}
|
||||||
NxFps = 0;
|
NxFps = 0;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 prevTid = 0;
|
u64 prevTid = 0;
|
||||||
|
|
||||||
u8 SaltyNXIntegration::GetFPS() {
|
u8 SaltyNXIntegration::GetFPS() {
|
||||||
|
if (!SharedMemoryUsed)
|
||||||
|
return 254;
|
||||||
|
|
||||||
u64 tid = ProcessManagement::GetCurrentApplicationId();
|
u64 tid = ProcessManagement::GetCurrentApplicationId();
|
||||||
if(tid == 0 || wasSaltyNxLoaded == false)
|
if (tid == 0)
|
||||||
return 254; // only try to read fps for games, not system apps
|
return 254;
|
||||||
|
|
||||||
if(prevTid != tid) {
|
if (prevTid != tid) {
|
||||||
uintptr_t base = (uintptr_t)shmemGetAddr(&_sharedmemory);
|
NxFps = 0;
|
||||||
searchSharedMemoryBlock(base);
|
|
||||||
prevTid = tid;
|
prevTid = tid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!NxFps) {
|
||||||
|
uintptr_t base = (uintptr_t)shmemGetAddr(&_sharedmemory);
|
||||||
|
searchSharedMemoryBlock(base);
|
||||||
|
}
|
||||||
|
|
||||||
return NxFps ? NxFps->FPS : 254;
|
return NxFps ? NxFps->FPS : 254;
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user