Homebrew Homebrew Development

Tjessx

Well-Known Member
Member
Joined
Dec 3, 2014
Messages
1,160
Trophies
0
Age
27
XP
952
Country
Belgium
So, i started working on the online highscore thing for homebrew applications.
And I was thinking, if people use open source applications, it would be very easy to rewrite the code part and give yourself a higher score.
Anyone an idea of stopping this? cause i can't think of one.
 

Jwiz33

Banned
Joined
Jun 5, 2014
Messages
2,654
Trophies
0
Location
in the illuminati headquar—I have said too much!
Website
iwillcleanyourbasement.webstarts.com
XP
1,492
Country
United States
So, i started working on the online highscore thing for homebrew applications.
And I was thinking, if people use open source applications, it would be very easy to rewrite the code part and give yourself a higher score.
Anyone an idea of stopping this? cause i can't think of one.
Leaderboards aren't accurate nowadays because of cheaters/hackers anyways, so why would this need to be different? :D (This is kind of a joke, by the way)
 

Garcia98

Hey! Listen!
Member
Joined
Sep 8, 2015
Messages
361
Trophies
0
Location
Salamanca
Website
github.com
XP
267
Country
So, i started working on the online highscore thing for homebrew applications.
And I was thinking, if people use open source applications, it would be very easy to rewrite the code part and give yourself a higher score.
Anyone an idea of stopping this? cause i can't think of one.

Maybe checking the md5sum of the 3dsx file? (so only scores from an official app version will be uploaded)
 
  • Like
Reactions: lemanuel

TheCruel

Developer
Banned
Joined
Dec 6, 2013
Messages
1,350
Trophies
2
XP
3,131
Country
United States
So, i started working on the online highscore thing for homebrew applications.
And I was thinking, if people use open source applications, it would be very easy to rewrite the code part and give yourself a higher score.
Anyone an idea of stopping this? cause i can't think of one.
You can make it more difficult by adding additional steps, but you can't prevent it unfortunately.

You could perhaps just implement cheat detection server-side to ban IPs, and that could perhaps deter most people.
 

Tjessx

Well-Known Member
Member
Joined
Dec 3, 2014
Messages
1,160
Trophies
0
Age
27
XP
952
Country
Belgium
I was thinking about that too, but it still wouldn't be really hard.just gonna filter out unrelasitic stuff based on what we know.
 

yodamerlin

Bok bok.
Member
Joined
Apr 1, 2014
Messages
322
Trophies
0
XP
1,050
Country
United Kingdom
So, i started working on the online highscore thing for homebrew applications.
And I was thinking, if people use open source applications, it would be very easy to rewrite the code part and give yourself a higher score.
Anyone an idea of stopping this? cause i can't think of one.
It would be difficult, but you could verify the game by storing exactly what the player did and sending that off, then simulate those actions server side and get the score from that. But because this is a general thing, it would be difficult, neigh impossible.
 

Tjessx

Well-Known Member
Member
Joined
Dec 3, 2014
Messages
1,160
Trophies
0
Age
27
XP
952
Country
Belgium
It would be difficult, but you could verify the game by storing exactly what the player did and sending that off, then simulate those actions server side and get the score from that. But because this is a general thing, it would be difficult, neigh impossible.
This way every different game should implement this system which is way too hard.
Think i'm just gonna leave it practically unprotected, and just log everything i can see server side, and let that decide if it is accurate.
 

TheCruel

Developer
Banned
Joined
Dec 6, 2013
Messages
1,350
Trophies
2
XP
3,131
Country
United States
This way every different game should implement this system which is way too hard.
Think i'm just gonna leave it practically unprotected, and just log everything i can see server side, and let that decide if it is accurate.
Yeah, just don't open-source the cheat detection portion to make it a bit more difficult for people.
 

daxtsu

Well-Known Member
Member
Joined
Jun 9, 2007
Messages
5,627
Trophies
2
XP
5,194
Country
Antarctica
I wrote a small example homebrew that lets you turn the top screen's backlight on and off, and it also plays nice with the home button, and exiting the homebrew (in other words, when you press home, it turns the lights back on, when resuming from the home menu, it turns it back off if it was off before pressing home, and when exiting, it also turns the lights back on). Note that this requires a newer ctrulib (or hack it into your own build of this homebrew I guess), since the gsp::Lcd stuff is very recent. Also note this won't work on firmwares above 9.2 for now, until the next *hax release since there's no way to access gsp::Lcd yet.

Edit: This is the old version which uses polling. I suggest using the newer version below, which uses an event hook to be informed whenever home is pressed instead.
Code:
#include <3ds.h>
#include <stdio.h>

void SetBacklight(GSPLCD_Screens screen, bool on)
{
    if (gspLcdInit() == 0)
    {
        if (on)
            GSPLCD_PowerOnBacklight(screen);
        else
            GSPLCD_PowerOffBacklight(screen);

        gspLcdExit();
    }
}

int main(int argc, char **argv) {
    gfxInitDefault();
    consoleInit(GFX_TOP, NULL);

    printf("Press A to turn the top backlight ON.\n");
    printf("Press B to turn the top backlight OFF.\n");
    printf("Press START to exit.\n");

    bool backLightShouldBeOff = false;
    bool wasSuspended = false;
    u32 hidDown = 0;

    while (aptMainLoop())
    {
        gspWaitForVBlank();
        hidScanInput();

        if ((aptGetStatus() == APP_SUSPENDING) && (aptGetStatusPower() == 0))
        {
            SetBacklight(GSPLCD_BOTH, true);
            wasSuspended = true;
            continue;
        }

        if (wasSuspended && backLightShouldBeOff)
        {
            wasSuspended = false;
            SetBacklight(GSPLCD_TOP, false);
        }

        hidDown = hidKeysDown();

        if (hidDown & KEY_B)
        {
            SetBacklight(GSPLCD_TOP, false);
            backLightShouldBeOff = true;
        }

        if (hidDown & KEY_A)
        {
            SetBacklight(GSPLCD_TOP, true);
            backLightShouldBeOff = false;
        }

        if (hidDown & KEY_START)
            break;

        gfxFlushBuffers();
        gfxSwapBuffers();
    }

    // Turn both backlights back on when exiting.
    SetBacklight(GSPLCD_BOTH, true);
    gfxExit();

    return 0;
}

Here's an alternate version which uses a hook (an event handler basically) to know when home is pressed.
Code:
#include <3ds.h>
#include <stdio.h>

static aptHookCookie aptEventHook;
static bool backLightIsOff;

static void backlightOn(GSPLCD_Screens screen)
{
    // Always get the Lcd handle and release it immediately.
    // The 3DS tends to hang if you don't release it right away.
    if (gspLcdInit() == 0)
    {
        GSPLCD_PowerOnBacklight(screen);
        gspLcdExit();
    }

    backLightIsOff = false;
}

static void backlightOff(GSPLCD_Screens screen)
{
    // Always get the Lcd handle and release it immediately.
    // The 3DS tends to hang if you don't release it right away.
    if (gspLcdInit() == 0)
    {
        GSPLCD_PowerOffBacklight(screen);
        gspLcdExit();
    }

    backLightIsOff = true;
}

static void aptEventHookHandler(int hook, void* param)
{
    // ONSUSPEND means home was pressed, and the application is pausing
    // to go to the home menu.
    if (hook == APTHOOK_ONSUSPEND)
    {
        // Don't use backlightOn here, it'll mess up the boolean.
        if (gspLcdInit() == 0)
        {
            GSPLCD_PowerOnBacklight(screen);
            gspLcdExit();
        }
        return;
    }

    // ONRESTORE is when the 3DS is exiting the home menu and going back to the
    // application.
    if ((hook == APTHOOK_ONRESTORE) && backLightIsOff)
    {
        backlightOff(GSPLCD_TOP);
    }
}

static void backlightInit()
{
    // Getting a hook into APT will let us know when home is pressed.
    // Also turn on both backlights so we're in a known state.
    aptHook(&aptEventHook, aptEventHookHandler, NULL);
    backlightOn(GSPLCD_BOTH);
}

static void backlightExit()
{
    // Clean up by releasing the hook and turning the backlights on again.
    aptUnhook(&aptEventHook);
    backlightOn(GSPLCD_BOTH);
}

int main(int argc, char **argv) {
    gfxInitDefault();
    consoleInit(GFX_TOP, NULL);

    backlightInit();

    printf("Press A to turn the top backlight ON.\n");
    printf("Press B to turn the top backlight OFF.\n");
    printf("Press START to exit.\n");
  
    u32 hidDown = 0;

    while (aptMainLoop())
    {
        gspWaitForVBlank();
        hidScanInput();

        hidDown = hidKeysDown();

        if (hidDown & KEY_B)
            backlightOff(GSPLCD_TOP);

        if (hidDown & KEY_A)
            backlightOn(GSPLCD_TOP);

        if (hidDown & KEY_START)
            break;

        gfxFlushBuffers();
        gfxSwapBuffers();
    }

    backlightExit();
    gfxExit();

    return 0;
}

Edit: Swapped gfxFlush with GfxSwap.
Edit 2: Added another version which waits for events to happen instead of polling, and it's much cleaner in general. Thanks to @aliaspider for the idea.
 
Last edited by daxtsu,

Tjessx

Well-Known Member
Member
Joined
Dec 3, 2014
Messages
1,160
Trophies
0
Age
27
XP
952
Country
Belgium
I'm sorry i post so easy questions here, but google doesn't work for me.
Tried 4-5 things, but for some reason it doesn't work.

I need to subtract a part of the string, i got the index and the lenght.
Code:
int print_part(char* message, int index, int length) {
  //get that part of the string
  printf(message);
}

Your help is appreciated.
Thanks
 

daxtsu

Well-Known Member
Member
Joined
Jun 9, 2007
Messages
5,627
Trophies
2
XP
5,194
Country
Antarctica
I'm sorry i post so easy questions here, but google doesn't work for me.
Tried 4-5 things, but for some reason it doesn't work.

I need to subtract a part of the string, i got the index and the lenght.
Code:
int print_part(char* message, int index, int length) {
  //get that part of the string
  printf(message);
}

Your help is appreciated.
Thanks

There are probably more sophisticated and "safe" ways of doing it, but here's a basic way you can do it:
Code:
void printPartOfString(char* message, int index, int length)
{
    char* part = malloc(length + 1);
 
    if (part)
    {
        strncpy(part, message + index, length);
        part[length] = '\0';
        printf("%s", part);
        free(part);
    }
}

Edit: You might also want to use unsigned ints or u32s (which are just typedef'd unsigned ints usually, or uint32_t) instead of regular ints for index and length, since you can't have negative indices or lengths with strings.
 
Last edited by daxtsu,

Arseface_TM

Board Game Dev
Member
Joined
Sep 16, 2015
Messages
331
Trophies
0
Age
32
XP
306
Country
United States
How do I load a font to the console?

I see there's a setFont procedure but I don't know how to tell it what font to use, or what format that font has to be in.

EDIT:
I'm also having trouble figuring out how to send ctrl+"letter" to the console.
 
Last edited by Arseface_TM,

elhobbs

Well-Known Member
Member
Joined
Jul 28, 2008
Messages
1,044
Trophies
1
XP
3,033
Country
United States
How do I load a font to the console?

I see there's a setFont procedure but I don't know how to tell it what font to use, or what format that font has to be in.

EDIT:
I'm also having trouble figuring out how to send ctrl+"letter" to the console.
What are you expecting ctrl+"letter" to do? This is a display console - printing text to the screen.
 

daxtsu

Well-Known Member
Member
Joined
Jun 9, 2007
Messages
5,627
Trophies
2
XP
5,194
Country
Antarctica
Since there's not really an example in ctrulib for news:u yet, I went ahead and made an example in C (still thinking of submitting it to Github, but not sure yet):

Code:
#include <3ds.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
{
    gfxInitDefault();
    consoleInit(GFX_TOP, NULL);

    Result newsInitResult = newsInit();
    if (newsInitResult != 0)
    {
        printf("Unable to initialise news:u, error %08lx\n", newsInitResult);
    }
    else
    {
        const char *message = "Hello, world";
        const char *title = "Title of message";

        // When going from utf-8 to utf-16, you need enough room in the buffer for double the
        // string length (hence the * sizeof(uint16_t)), plus two bytes
        // (another sizeof(uin16_t)) for a utf-16 null terminator.
        const size_t messageLen = strlen(message);
        const size_t message16Len = (messageLen * sizeof(u16)) + sizeof(u16);
        u16 *message16Buffer = malloc(message16Len);

        const size_t titleLen = strlen(title);
        const size_t title16Len = (titleLen * sizeof(u16)) + sizeof(u16);
        u16 *title16Buffer = malloc(title16Len);

        if (message16Buffer && title16Buffer)
        {
            memset(message16Buffer, 0, message16Len);
            utf8_to_utf16(message16Buffer, (u8 *)message, messageLen);

            memset(title16Buffer, 0, title16Len);
            utf8_to_utf16(title16Buffer, (u8 *)title, titleLen);

            NEWSU_AddNotification(title16Buffer, titleLen, message16Buffer, messageLen, NULL, 0, false);

            printf("Added a notification. Check the HOME menu to\nsee what it says!\n");
        }
        else
            printf("Unable to allocate memory for string buffer(s).\n");

        newsExit();

        free(message16Buffer);
        free(title16Buffer);
    }

    printf("Press START to exit.\n");

    while (aptMainLoop())
    {
        gspWaitForVBlank();
        hidScanInput();

        if (hidKeysDown() & KEY_START)
            break;

        gfxFlushBuffers();
        gfxSwapBuffers();
    }

    gfxExit();

    return 0;
}

With C++11 enabled you could use u in front of strings instead of having to make buffers and do all the conversion stuff.

Code:
NEWSU_AddNotification(u"Title of message", strlen("Title of message"), u"Hello, world!", strlen("Hello, world!"), nullptr, 0, false);
 
Last edited by daxtsu,

Rinnegatamante

Well-Known Member
Member
Joined
Nov 24, 2014
Messages
3,162
Trophies
2
Age
29
Location
Bologna
Website
rinnegatamante.it
XP
4,857
Country
Italy
I'm getting mad with this code. I really don't understand where the problem is.

I'm writing a socket-based app, this piece of code is executed by the PC connected to 3DS:

Code:
            printf("\nGET_SONG_LIST: Retrieving songs list...");
             DIR* songsdir = opendir("./songs");
             if (songsdir == NULL) printf("\nERROR: Cannot find songs directory!");
             int totalSongs = populateDatabase(songsdir);
             printf(" Done!");
             int dim;
             char* query;
             if (totalSongs == 0){
               query = malloc(2);
               query[0] = ':';
               query[1] = 0;
               dim = 1;
             }else{
               query = parseSongs(songList, totalSongs);
               dim = 128*totalSongs;
             }
             printf("\nGET_SONG_LIST: Sending songs list...");
             sleep(1);
             send(my_socket->sock, query, dim, 0);
             while (recv(my_socket->sock, NULL, 2, 0) < 1){}
             printf(" Done!");
             free(query);
             break;

When i execute it, i get on the screen "GET_SONG_LIST: Retrieving songs list... Done!", then application seems to freeze (no crash, shell still active, no other responses).
I also tried to comment the parseSongs call and force the app to use the code in the if clauses for totalSongs = 0; it should at least shows "GET_SONG_LIST: Sending songs list..." i think :/
Does someone know where i'm wrong?
 

Tjessx

Well-Known Member
Member
Joined
Dec 3, 2014
Messages
1,160
Trophies
0
Age
27
XP
952
Country
Belgium
I'm getting mad with this code. I really don't understand where the problem is.

I'm writing a socket-based app, this piece of code is executed by the PC connected to 3DS:

Code:
            printf("\nGET_SONG_LIST: Retrieving songs list...");
             DIR* songsdir = opendir("./songs");
             if (songsdir == NULL) printf("\nERROR: Cannot find songs directory!");
             int totalSongs = populateDatabase(songsdir);
             printf(" Done!");
             int dim;
             char* query;
             if (totalSongs == 0){
               query = malloc(2);
               query[0] = ':';
               query[1] = 0;
               dim = 1;
             }else{
               query = parseSongs(songList, totalSongs);
               dim = 128*totalSongs;
             }
             printf("\nGET_SONG_LIST: Sending songs list...");
             sleep(1);
             send(my_socket->sock, query, dim, 0);
             while (recv(my_socket->sock, NULL, 2, 0) < 1){}
             printf(" Done!");
             free(query);
             break;

When i execute it, i get on the screen "GET_SONG_LIST: Retrieving songs list... Done!", then application seems to freeze (no crash, shell still active, no other responses).
I also tried to comment the parseSongs call and force the app to use the code in the if clauses for totalSongs = 0; it should at least shows "GET_SONG_LIST: Sending songs list..." i think :/
Does someone know where i'm wrong?
is the socket on non_blocking mode?
try to end the server message with \r\n\0
 

Rinnegatamante

Well-Known Member
Member
Joined
Nov 24, 2014
Messages
3,162
Trophies
2
Age
29
Location
Bologna
Website
rinnegatamante.it
XP
4,857
Country
Italy
is the socket on non_blocking mode?
try to end the server message with \r\n\0
Nope, the socket is in Blocking mode cause i need it to be in such mode.
What server message i have to edit? The ones sent from 3DS to PC or the reverse ones? (But should not the problem be between the Done printf and the successive ones?
 

Tjessx

Well-Known Member
Member
Joined
Dec 3, 2014
Messages
1,160
Trophies
0
Age
27
XP
952
Country
Belgium
Nope, the socket is in Blocking mode cause i need it to be in such mode.
What server message i have to edit? The ones sent from 3DS to PC or the reverse ones? (But should not the problem be between the Done printf and the successive ones?
Nevermidn, that isn't it since it hangs somewhere in this code:
Code:
int dim;
             char* query;
             if (totalSongs == 0){
               query = malloc(2);
               query[0] = ':';
               query[1] = 0;
               dim = 1;
             }else{
               query = parseSongs(songList, totalSongs);
               dim = 128*totalSongs;
             }

Which is extremely weird
 

joshjosh100

Member
Newcomer
Joined
Oct 11, 2015
Messages
24
Trophies
0
Age
26
XP
77
Country
United States
So, I didnt know where to post this at so I'm asking my question here, is there a guide on how to MAKE Homebrew? not just being able to compile it/Collection of tools...... Sorry if this is in a wrong section
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    ZeroT21 @ ZeroT21: :rofl2: