refactoring ...

This commit is contained in:
SegFault42 2016-10-29 19:04:46 +02:00
parent e9559ec5ff
commit 60a5116ec1
6 changed files with 279 additions and 287 deletions

View File

@ -65,7 +65,7 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
LIBS := -lpng16 -lz -lm -lctru
LIBS := -lz -lm -lctru #-lpng16
OS := $(shell uname)
@ -304,4 +304,4 @@ endif
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------

View File

@ -1,373 +1,366 @@
#include <3ds.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <malloc.h>
#include <unistd.h>
#include "actu.h"
#include "cfgs.h"
#include "frd.h"
#include "mcu.h"
#include "screenshot.h"
/*#include "screenshot.h"*/
#define SDK(a,b,c,d) ((a<<24)|(b<<16)|(c<<8)|d)
#define SDK(a,b,c,d) ((a<<24)|(b<<16)|(c<<8)|d)
#define RED "\x1b[31m"
#define GREEN "\x1b[32m"
#define YELLOW "\x1b[33m"
#define BLUE "\x1b[34m"
#define CYAN "\x1b[36m"
#define END "\x1b[0m"
int vaPrint(char *format, ...)
int vaPrint(char *format, ...)
{
va_list args;
va_start(args, format);
int ret = vprintf(format, args);
va_end(args);
va_list args;
int ret = vprintf(format, args);
va_start(args, format);
va_end(args);
gfxFlushBuffers();
gfxSwapBuffers();
return ret;
}
const char * getModel()
const char *getModel()
{
const char *models[] =
u8 model = 0;
const char *models[] =
{
"O3DS",
"O3DS XL",
"N3DS",
"2DS",
"N3DS XL",
"Unknown"
};
"O3DS",
"O3DS XL",
"N3DS",
"2DS",
"N3DS XL",
"Unknown"
};
u8 model = 0;
CFGU_GetSystemModel(&model);
if (model < 5)
return models[model];
else
return models[5];
CFGU_GetSystemModel(&model);
if (model < 5)
return models[model];
else
return models[5];
}
const char * getRegion()
const char *getRegion()
{
const char *regions[] =
u8 region = 0;
const char *regions[] =
{
"JPN",
"USA",
"EUR",
"AUS",
"CHN",
"KOR",
"TWN",
"Unknown"
};
"JPN",
"USA",
"EUR",
"AUS",
"CHN",
"KOR",
"TWN",
"Unknown"
};
u8 region = 0;
CFGU_SecureInfoGetRegion(&region);
CFGU_SecureInfoGetRegion(&region);
if (region < 7)
return regions[region];
else
return regions[7];
if (region < 7)
return regions[region];
else
return regions[7];
}
const char * getLang()
{
const char *languages[] =
u8 language;
const char *languages[] =
{
"Japanese",
"English",
"French",
"German",
"Italian",
"Spanish",
"Simplified Chinese",
"Korean",
"Dutch",
"Portugese",
"Russian",
"Traditional Chinese"
};
"Japanese",
"English",
"French",
"German",
"Italian",
"Spanish",
"Simplified Chinese",
"Korean",
"Dutch",
"Portugese",
"Russian",
"Traditional Chinese"
};
u8 language;
CFGU_GetSystemLanguage(&language);
CFGU_GetSystemLanguage(&language);
if (language < 11)
return languages[language];
else
return languages[11];
if (language < 11)
return languages[language];
else
return languages[11];
}
bool detectSD()
bool detectSD()
{
bool isSD;
FSUSER_IsSdmcDetected(&isSD);
return isSD;
bool isSD;
FSUSER_IsSdmcDetected(&isSD);
return isSD;
}
const char * batteryStatus()
{
u8 batteryStateBool;
PTMU_GetBatteryChargeState(&batteryStateBool);
u8 batteryStateBool;
if (!batteryStateBool)
return "Not charging";
else
return "Charging";
PTMU_GetBatteryChargeState(&batteryStateBool);
if (!batteryStateBool)
return "Not charging";
else
return "Charging";
}
char * getMacAddress()
char *getMacAddress()
{
u8* macByte = (u8*)0x1FF81060;
static char macAddress[18];
u8 *macByte = (u8*)0x1FF81060;
static char macAddress[18];
// sprintf automatically zero-terminates the string
sprintf(macAddress, "%02X:%02X:%02X:%02X:%02X:%02X", *macByte, *(macByte + 1), *(macByte + 2), *(macByte + 3), *(macByte + 4), *(macByte + 5));
// sprintf automatically zero-terminates the string
sprintf(macAddress, "%02X:%02X:%02X:%02X:%02X:%02X", *macByte, *(macByte + 1), *(macByte + 2), *(macByte + 3), *(macByte + 4), *(macByte + 5));
return macAddress;
return macAddress;
}
u32 titleCount(FS_MediaType mediaType)
{
u32 count = 0;
u32 count = 0;
AM_GetTitleCount(mediaType, &count);
return count;
return count;
}
void getScreenType()
{
bool isNew3DS = 0;
APT_CheckNew3DS(&isNew3DS);
bool isNew3DS = 0;
u8 screens = 0;
APT_CheckNew3DS(&isNew3DS);
printf("\x1b[31m*\x1b[0m Screen Info: ");
if (isNew3DS)
{
u8 screens = 0;
GSPLCD_GetVendors(&screens);
switch ((screens >> 4) & 0xF)
{
case 1:
printf("Upper: IPS ");
break;
case 0xC:
printf("Upper: TN ");
break;
default:
printf("Upper: Unknown ");
break;
}
switch (screens & 0xF)
{
case 1:
printf("| Lower: IPS\n");
break;
case 0xC:
printf("| Lower: TN\n");
break;
default:
printf("| Lower: Unknown\n");
break;
}
}
else
{
printf("Upper: TN | Lower: TN\n");
}
if (isNew3DS)
{
GSPLCD_GetVendors(&screens);
switch ((screens >> 4) & 0xF)
{
case 1:
printf("Upper: IPS ");
break;
case 0xC:
printf("Upper: TN ");
break;
default:
printf("Upper: Unknown ");
break;
}
switch (screens & 0xF)
{
case 1:
printf("| Lower: IPS\n");
break;
case 0xC:
printf("| Lower: TN\n");
break;
default:
printf("| Lower: Unknown\n");
break;
}
}
else
printf("Upper: TN | Lower: TN\n");
}
u64 principalIdToFriendCode(u64 pid)
{
u64 fc = 0;
frdPrincipalIdToFriendCode(&fc, pid);
u64 fc = 0;
frdPrincipalIdToFriendCode(&fc, pid);
return fc;
}
FriendKey getMyFriendKey(void)
{
FriendKey fk;
FriendKey fk;
frdGetMyFriendKey(&fk);
return fk;
}
char * getSerialNum(void)
{
static char str[32];
char serial[0x10];
cfgsSecureInfoGetSerialNo(serial);
strcpy(str, serial);
static char str[32];
char serial[0x10];
cfgsSecureInfoGetSerialNo(serial);
strcpy(str, serial);
return str;
}
u32 getDeviceId(void)
{
u32 tmp = 0;
AM_GetDeviceId(&tmp);
return tmp;
u32 tmp = 0;
AM_GetDeviceId(&tmp);
return tmp;
}
u64 getSoapId(void)
{
u32 tmp = 0;
AM_GetDeviceId(&tmp);
return (tmp | (((u64) 4) << 32));
u32 tmp = 0;
AM_GetDeviceId(&tmp);
return (tmp | (((u64) 4) << 32));
}
int main(int argc, char *argv[])
{
gfxInitDefault();
cfguInit();
{
gfxInitDefault();
cfguInit();
cfgsInit();
//frdInit(SDK(11,4,0,200));
fsInit();
sdmcInit();
ptmuInit();
fsInit();
sdmcInit();
ptmuInit();
mcuInit();
amInit();
psInit();
aptInit();
hidInit();
hidInit();
acInit();
gspLcdInit();
consoleInit(GFX_TOP, NULL);
gspLcdInit();
consoleInit(GFX_TOP, NULL);
char *str_ver = malloc(255), *str_sysver = malloc(255);
u32 os_ver = osGetKernelVersion(), firm_ver = osGetKernelVersion();
char *str_ver = (char *)malloc(sizeof(char) * 255), *str_sysver = (char *)malloc(sizeof(char) * 255);
double wifiPercent;
double volPercent;
double _3dSliderPercent;
u32 os_ver = osGetKernelVersion(), firm_ver = osGetKernelVersion();
u32 installedTitles = titleCount(MEDIATYPE_SD);
u32 nnidNum = 0xFFFFFFFF;
s32 ret;
u8 buf[16];
u8 batteryPercent;
u8 batteryVolt;
u8 volume;
FS_ArchiveResource resource = {0};
OS_VersionBin *nver = (OS_VersionBin *)malloc(sizeof(OS_VersionBin));
OS_VersionBin *cver = (OS_VersionBin *)malloc(sizeof(OS_VersionBin));
printf("\x1b[32m3DSident 0.7\x1b[0m\n\n");
snprintf(str_ver, 255, "\x1b[33m*\x1b[0m Kernel version: %lu.%lu-%lu\n\x1b[33m*\x1b[0m FIRM version is %lu.%lu-%lu\n",
GET_VERSION_MAJOR(os_ver), GET_VERSION_MINOR(os_ver), GET_VERSION_REVISION(os_ver),
GET_VERSION_MAJOR(firm_ver), GET_VERSION_MINOR(firm_ver), GET_VERSION_REVISION(firm_ver));
printf(str_ver);
OS_VersionBin *nver = (OS_VersionBin*)malloc(sizeof(OS_VersionBin));
OS_VersionBin *cver = (OS_VersionBin*)malloc(sizeof(OS_VersionBin));
memset(nver, 0, sizeof(OS_VersionBin));
memset(cver, 0, sizeof(OS_VersionBin));
s32 ret = osGetSystemVersionData(nver, cver);
if (ret)
printf("\x1b[33m*\x1b[0m osGetSystemVersionData returned 0x%08liX\n\n", ret);
snprintf(str_sysver, 100, "\x1b[33m*\x1b[0m Current system version: %d.%d.%d-%d\n\n",
cver->mainver, cver->minor, cver->build, nver->mainver);
if (!ret)
printf(str_sysver);
printf("\x1b[31m*\x1b[0m Model: %s %s\n", getModel(), getRegion());
getScreenType();
//printf("\x1b[31m*\x1b[0m Friend key: %llu\n", principalIdToFriendCode(getMyFriendKey().principalId));
printf("\x1b[31m*\x1b[0m Language: %s\n", getLang());
u32 nnidNum = 0xFFFFFFFF;
ret = actInit();
/*if (ret)
vaPrint("actInit failed! %08x\n", ret);*/
ret = ACTU_Initialize(0xB0002C8, 0, 0);
/*if (ret)
vaPrint("ACTU_Initialize failed! %08x\n", ret);*/
ret = ACTU_GetAccountDataBlock(0xFE, 4, 12, &nnidNum);
/*if (ret)
vaPrint("ACTU_GetAccountDataBlock failed! %08x\n", ret);*/
ret = actExit();
/*if (ret)
vaPrint("actExit failed! %08x\n", ret);*/
if (nnidNum != 0xFFFFFFFF)
while (aptMainLoop())
{
vaPrint("\x1b[31m*\x1b[0m NNID number: %08X\n", (int) nnidNum);
printf(GREEN"3DSident 0.7\n\n"END);
//============================Yellow information===========================
snprintf(str_ver, 255, "\x1b[33m*\x1b[0m Kernel version: %lu.%lu-%lu\n\x1b[33m*\x1b[0m FIRM version is: %lu.%lu-%lu\n",
GET_VERSION_MAJOR(os_ver),
GET_VERSION_MINOR(os_ver),
GET_VERSION_REVISION(os_ver),
GET_VERSION_MAJOR(firm_ver),
GET_VERSION_MINOR(firm_ver),
GET_VERSION_REVISION(firm_ver)
);
printf(str_ver);
memset(nver, 0, sizeof(OS_VersionBin));
memset(cver, 0, sizeof(OS_VersionBin));
ret = osGetSystemVersionData(nver, cver);
if (ret)
printf("\x1b[33m*\x1b[0m osGetSystemVersionData returned 0x%08liX\n\n", ret);
snprintf(str_sysver, 100, "\x1b[33m*\x1b[0m Current system version: %d.%d.%d-%d\n\n", cver->mainver, cver->minor, cver->build, nver->mainver);
if (!ret)
printf(str_sysver);
//=========================================================================
//============================Yellow information===========================
printf("\x1b[31m*\x1b[0m Model: %s %s\n", getModel(), getRegion());
getScreenType();
printf("\x1b[31m*\x1b[0m Language: %s\n", getLang());
ret = actInit();
ret = ACTU_Initialize(0xB0002C8, 0, 0);
ret = ACTU_GetAccountDataBlock(0xFE, 4, 12, &nnidNum);
ret = actExit();
if (nnidNum != 0xFFFFFFFF)
vaPrint("\x1b[31m*\x1b[0m NNID number: %08X\n", (int) nnidNum);
else
vaPrint("\x1b[31m*\x1b[0m NNID number: Error could not retrieve NNID\n");
printf("\x1b[31m*\x1b[0m Device ID: (%lu)\n", getDeviceId());
printf("\x1b[31m*\x1b[0m ECS Device ID: (%llu)\n", getSoapId());
printf("\x1b[31m*\x1b[0m MAC Address: %s\n", getMacAddress());
printf("\x1b[31m*\x1b[0m Serial number: %s\n", getSerialNum());
FSUSER_GetSdmcCid(buf, 0x10);
printf("\x1b[31m*\x1b[0m SDMC CID: %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
buf[6], buf[7], buf[8], buf[9], buf[10], buf[11],
buf[12], buf[13], buf[14], buf[15]);
FSUSER_GetNandCid(buf, 0x10);
printf("\x1b[31m*\x1b[0m NAND CID: %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n\n",
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
buf[6], buf[7], buf[8], buf[9], buf[10], buf[11],
buf[12], buf[13], buf[14], buf[15]);
mcuGetBatteryLevel(&batteryPercent);
printf("\x1b[34m*\x1b[0m Battery percentage: %d%% (%s)\n", batteryPercent, batteryStatus());
mcuGetBatteryVoltage(&batteryVolt);
printf("\x1b[34m*\x1b[0m Battery voltage: %d\n\n", batteryVolt);//,(Estimated: %0.1lf V) estimatedVolt);
FSUSER_GetArchiveResource(&resource, SYSTEM_MEDIATYPE_SD);
printf("\x1b[32m*\x1b[0m SD Size: %.1f MB / %.1f MB\n", (((u64) resource.freeClusters * (u64) resource.clusterSize) / 1024.0 / 1024.0), (((u64) resource.totalClusters * (u64) resource.clusterSize) / 1024.0 / 1024.0));
FSUSER_GetArchiveResource(&resource, SYSTEM_MEDIATYPE_CTR_NAND);
printf("\x1b[32m*\x1b[0m CTR Size: %.1f MB / %.1f MB\n", (((u64) resource.freeClusters * (u64) resource.clusterSize) / 1024.0 / 1024.0), (((u64) resource.totalClusters * (u64) resource.clusterSize) / 1024.0 / 1024.0));
printf("\x1b[32m*\x1b[0m Installed titles: %i\n", (int)installedTitles);
wifiPercent = (osGetWifiStrength() * 33.3333333333);
printf("\x1b[32m*\x1b[0m WiFi signal strength: %d (%.0lf%%)\n", osGetWifiStrength(), wifiPercent);
mcuGetVolume(&volume);
volPercent = (volume * 1.5873015873);
printf("\x1b[32m*\x1b[0m Volume slider state: %d (%.0lf%%)\n", volume, volPercent);
_3dSliderPercent = (osGet3DSliderState() * 100.0);
printf("\x1b[32m*\x1b[0m 3D slider state: %.1lf (%.0lf%%)\n", osGet3DSliderState(), _3dSliderPercent);
printf("\n\x1b[32m> Press any key to exit =)\x1b[0m\n");
gspWaitForVBlank();
hidScanInput();
if (hidKeysDown())
{
/*captureScreenshot();*/
break;
}
gfxFlushBuffers();
gfxSwapBuffers();
}
else
{
vaPrint("\x1b[31m*\x1b[0m NNID number: Error could not retrieve NNID\n");
}
printf("\x1b[31m*\x1b[0m Device ID: (%lu)\n", getDeviceId());
printf("\x1b[31m*\x1b[0m ECS Device ID: (%llu)\n", getSoapId());
printf("\x1b[31m*\x1b[0m MAC Address: %s\n", getMacAddress());
printf("\x1b[31m*\x1b[0m Serial number: %s\n", getSerialNum());
u8 buf[16];
FSUSER_GetSdmcCid(buf, 0x10);
printf("\x1b[31m*\x1b[0m SDMC CID: %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
buf[6], buf[7], buf[8], buf[9], buf[10], buf[11],
buf[12], buf[13], buf[14], buf[15]);
FSUSER_GetNandCid(buf, 0x10);
printf("\x1b[31m*\x1b[0m NAND CID: %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n\n",
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
buf[6], buf[7], buf[8], buf[9], buf[10], buf[11],
buf[12], buf[13], buf[14], buf[15]);
/*u32 deviceId;
PS_GetDeviceId(&deviceId);
printf("\x1b[31m*\x1b[0m Device ID: %lu\n", deviceId);*/
u8 batteryPercent;
mcuGetBatteryLevel(&batteryPercent);
printf("\x1b[34m*\x1b[0m Battery percentage: %d%% (%s)\n", batteryPercent, batteryStatus());
u8 batteryVolt;
mcuGetBatteryVoltage(&batteryVolt);
//double estimatedVolt = (batteryVolt * 0.02248803827);
printf("\x1b[34m*\x1b[0m Battery voltage: %d\n\n", batteryVolt);//,(Estimated: %0.1lf V) estimatedVolt);
//printf("\x1b[32m*\x1b[0m SD Detected: %s\n", detectSD() ? "Yes" : "No"); Don't need this
FS_ArchiveResource resource = {0};
FSUSER_GetArchiveResource(&resource, SYSTEM_MEDIATYPE_SD);
printf("\x1b[32m*\x1b[0m SD Size: %.1f MB / %.1f MB\n", (((u64) resource.freeClusters * (u64) resource.clusterSize) / 1024.0 / 1024.0), (((u64) resource.totalClusters * (u64) resource.clusterSize) / 1024.0 / 1024.0));
FSUSER_GetArchiveResource(&resource, SYSTEM_MEDIATYPE_CTR_NAND);
printf("\x1b[32m*\x1b[0m CTR Size: %.1f MB / %.1f MB\n", (((u64) resource.freeClusters * (u64) resource.clusterSize) / 1024.0 / 1024.0), (((u64) resource.totalClusters * (u64) resource.clusterSize) / 1024.0 / 1024.0));
u32 installedTitles = titleCount(MEDIATYPE_SD);
printf("\x1b[32m*\x1b[0m Installed titles: %i\n", (int)installedTitles);
/*u32 wifiStatus = 0;
ACU_GetWifiStatus(&wifiStatus);
int wifiStat = wifiStatus + osGetWifiStrength();*/
double wifiPercent = (osGetWifiStrength() * 33.3333333333);
printf("\x1b[32m*\x1b[0m WiFi signal strength: %d (%.0lf%%)\n", osGetWifiStrength(), wifiPercent);
u8 volume;
mcuGetVolume(&volume);
double volPercent = (volume * 1.5873015873);
printf("\x1b[32m*\x1b[0m Volume slider state: %d (%.0lf%%)\n", volume, volPercent);
double _3dSliderPercent = (osGet3DSliderState() * 100.0);
printf("\x1b[32m*\x1b[0m 3D slider state: %.1lf (%.0lf%%)\n", osGet3DSliderState(), _3dSliderPercent);
printf("\n\x1b[32m> Press any key to exit =)\x1b[0m\n");
free(nver);
free(cver);
free(str_ver);
free(str_sysver);
while (aptMainLoop())
{
gspWaitForVBlank();
hidScanInput();
if (hidKeysDown())
{
captureScreenshot();
break;
}
gfxFlushBuffers();
gfxSwapBuffers();
}
free(nver);
free(cver);
free(str_ver);
free(str_sysver);
gspLcdExit();
acExit();
hidExit();
@ -375,12 +368,11 @@ int main(int argc, char *argv[])
psExit();
amExit();
mcuExit();
ptmuExit();
sdmcExit();
fsExit();
//frdExit();
ptmuExit();
sdmcExit();
fsExit();
cfgsExit();
cfguExit();
gfxExit();
return 0;
cfguExit();
gfxExit();
return 0;
}

View File

@ -3,7 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <png.h>
//#include <png.h>
#include <zlib.h>
#include <3ds.h>
@ -13,4 +13,4 @@
int level, screenCapture;
unsigned int format_choice;
GSPGPU_FramebufferFormats format; // = GSP_RGBA8_OES
void captureScreenshot();
void captureScreenshot();

0
tools/osx/bannertool Normal file → Executable file
View File

0
tools/osx/makerom Normal file → Executable file
View File