Button List for NTR cheat plugin creation?

Discussion in '3DS - ROM Hacking, Translations and Utilities' started by Metab, May 7, 2016.

  1. Metab
    OP

    Metab GBAtemp Regular

    Member
    156
    94
    Mar 23, 2013
    Where dat ass is
    Learning how to create cheats with this:
    https://gbatemp.net/threads/tutorial-building-ntr-custom-firmware-cheat-plugins-w-cheat-menu.411189/
    Is there some documentation on each button on the 3DS' corresponding code snippet for useage?

    A snippet in the thread tells me select is 'BUTTON_SE'

    Code:
    key = getKey();
            if (key == BUTTON_SE) {
                // toggle cheats when SELECT button pressed
                cheatEnabled = !cheatEnabled;
                // wait until key is up
                waitKeyUp();
            }
            if (cheatEnabled) {
                // freeze hearts
                WRITEU16(0x168b6044 , 0x5050);
                // freeze rupees
                WRITEU16(0x168b5fa8 , 9999);
            }
     
  2. Nanquitas

    Nanquitas GBAtemp Addict

    Member
    2,168
    1,856
    Sep 29, 2015
    France
    South of France :)
    Hi :)

    The buttons are defined in a file (don't remember the names), but here the list:
    Code:
    BUTTON_A
    BUTTON_B
    BUTTON_X
    BUTTON_Y
    BUTTON_DL
    BUTTON_DR
    BUTTON_DD
    BUTTON_DU
    BUTTON_L
    BUTTON_R
    BUTTON_SE
    BUTTON_ST
    Of course you can use multiple button with the '+' operator.
    exemple:
    Code:
    if (getKey() == BUTTON_L + BUTTON_R + BUTTON_X)
    {
    // do a super ultra amazing thing !!!
    }
    Some functions I found useful if you don't have those:
    Code:
    //Wait for the all the input to be released
    void    releaseKey(void)
    {
        while (1)
        {
            if (getKey() == 0)
                return;
        }
    }
    
    //Wait for the input to change
    void    waitKeyChange(u32  keys)
    {
        while (1)
        {
            if (getKey() != keys)
                return;
        }
    }
    
    //Wait for an input
    u32    waitKey(void)
    {
        while (1)
        {
            if (getKey() != 0)
                return (getKey());
        }
    }
     
    cearp likes this.
  3. Metab
    OP

    Metab GBAtemp Regular

    Member
    156
    94
    Mar 23, 2013
    Where dat ass is
    WOw I really appreciate you posting that it helps alot,
    So far out of the codes ive tested (freez vaue for Naruto game, and A to boost on mario game) its all crashed, am I just getting bad codes (atleast with the freeze ones which are straight foward)?
     
  4. Nanquitas

    Nanquitas GBAtemp Addict

    Member
    2,168
    1,856
    Sep 29, 2015
    France
    South of France :)
    Post the code you wrote, I'll help you debugging it. ;)

    If the console crash, it's more than just a bad code.
    Probably a wrong address, or an address you don't have the right to edit.
     
    cearp likes this.
  5. Metab
    OP

    Metab GBAtemp Regular

    Member
    156
    94
    Mar 23, 2013
    Where dat ass is
    Sure, sec
    But when it crashes its not like bam, gone, its like 'something went wrong, hold power button' message.
     
  6. Nanquitas

    Nanquitas GBAtemp Addict

    Member
    2,168
    1,856
    Sep 29, 2015
    France
    South of France :)
    Yeah, it's always like that. ;)
     
  7. Metab
    OP

    Metab GBAtemp Regular

    Member
    156
    94
    Mar 23, 2013
    Where dat ass is
    Ah no worries, here my Mario Kart 7 attempts
    cheatEnabled[0] boolean was an attempt at 'A to boost' copied straight from http://www.fort42.com/gateshark/game14/6819/
    cheatEnabled[1] boolean is attempting to unlock all charatcers from here http://www.fort42.com/gateshark/game14/1998/
    Code:
    #include "global.h"
    
    #define WRITEU8(addr, data) *(vu8*)(addr) = data
    #define WRITEU16(addr, data) *(vu16*)(addr) = data
    #define WRITEU32(addr, data) *(vu32*)(addr) = data
    
    u32 threadStack[0x1000];
    Handle fsUserHandle;
    FS_archive sdmcArchive;
    
    
    #define IO_BASE_PAD        1
    #define IO_BASE_LCD        2
    #define IO_BASE_PDC        3
    #define IO_BASE_GSPHEAP        4
    
    u32 IoBasePad = 0xFFFD4000;
    
    u32 getKey() {
        return (*(vu32*)(IoBasePad) ^ 0xFFF) & 0xFFF;
    }
    
    void waitKeyUp() {
        while (getKey() != 0) {
            svc_sleepThread(100000000);
        }
    }
    
    u8 cheatEnabled[64];
    int isNewNtr = 0;
    
    
    u32 plgGetIoBase(u32 IoType);
    GAME_PLUGIN_MENU gamePluginMenu;
    
    void initMenu() {
        memset(&gamePluginMenu, 0, sizeof(GAME_PLUGIN_MENU));
    }
    
    void addMenuEntry(u8* str) {
        if (gamePluginMenu.count > 64) {
            return;
        }
        u32 pos = gamePluginMenu.count;
        u32 len = strlen(str) + 1;
        gamePluginMenu.offsetInBuffer[pos] = gamePluginMenu.bufOffset;
        strcpy(&(gamePluginMenu.buf[gamePluginMenu.bufOffset]), str);
       
        gamePluginMenu.count += 1;
        gamePluginMenu.bufOffset += len;
    }
    
    u32 updateMenu() {
        PLGLOADER_INFO *plgLoaderInfo = (void*)0x07000000;
        plgLoaderInfo->gamePluginPid = getCurrentProcessId();
        plgLoaderInfo->gamePluginMenuAddr = (u32)&gamePluginMenu;
       
        u32 ret = 0;
        u32 hProcess;
        u32 homeMenuPid = plgGetIoBase(5);
        if (homeMenuPid == 0) {
            return 1;
        }
        ret = svc_openProcess(&hProcess, homeMenuPid);
        if (ret != 0) {
            return ret;
        }
        copyRemoteMemory( hProcess, &(plgLoaderInfo->gamePluginPid), CURRENT_PROCESS_HANDLE,  &(plgLoaderInfo->gamePluginPid), 8);
        final:
        svc_closeHandle(hProcess);
        return ret;
    }
    
    int scanMenu() {
        u32 i;
        for (i = 0; i < gamePluginMenu.count; i++) {
            if (gamePluginMenu.state[i]) {
                gamePluginMenu.state[i] = 0;
                return i;
            }
        }
        return -1;
    }
    
    // detect language (0: english)
    int detectLanguage() {
        // unimplemented
        return 0;
    }
    
    // add one cheat menu entry
    void addCheatMenuEntry(u8* str) {
        u8 buf[100];
        xsprintf(buf, "[ ] %s", str);
        addMenuEntry(buf);
    }
    
    // this function will be called when the state of cheat item changed
    void onCheatItemChanged(int id, int enable) {
        // TODO: handle on cheat item is select or unselected
       
    
    }
    
    // freeze the value
    void freezeCheatValue() {
        if(cheatEnabled[1]) {
            WRITEU16(0xD3000000, 0x14000000);
            WRITEU16(0x1013CD30, 0x00003FFF);
        }
       
        /*if (cheatEnabled[0]) {
            WRITEU16(0x2041A178, 0x00000078);
            WRITEU16(0x20419FDC, 0x00000078);
            WRITEU16(0x2041A314, 0x00000078);
            WRITEU16(0x2041A984, 0x00000078);
            WRITEU16(0x2041AE58, 0x00000078);
            WRITEU16(0x2041A64C, 0x00000078);
        }*/
        // TODO: handle your own cheat items
    }
    
    // update the menu status
    void updateCheatEnableDisplay(id) {
        gamePluginMenu.buf[gamePluginMenu.offsetInBuffer[id] + 1] = cheatEnabled[id] ? 'X' : ' ';
    }
    
    // scan and handle events
    void scanCheatMenu() {
        int ret = scanMenu();
        if (ret != -1) {
            cheatEnabled[ret] = !cheatEnabled[ret];
            updateCheatEnableDisplay(ret);
            onCheatItemChanged(ret, cheatEnabled[ret]);
        }
    }
    
    // init
    void initCheatMenu() {
        initMenu();
        addCheatMenuEntry("A to boost(Broken!)");
        addCheatMenuEntry("All Karts!");
        //addCheatMenuEntry("Naruto EXP");
       
        updateMenu();
    }
    
    void gamePluginEntry() {
        u32 ret, key;
        INIT_SHARED_FUNC(plgGetIoBase, 8);
        INIT_SHARED_FUNC(copyRemoteMemory, 9);
        // wait for game starts up (5 seconds)
        svc_sleepThread(5000000000);
    
        if (((NS_CONFIG*)(NS_CONFIGURE_ADDR))->sharedFunc[8]) {
            isNewNtr = 1;
        } else {
            isNewNtr = 0;
        }
       
        if (isNewNtr) {
            IoBasePad = plgGetIoBase(IO_BASE_PAD);
        }
        initCheatMenu();
        while (1) {
            svc_sleepThread(100000000);
            key = getKey();
            if (cheatEnabled[0]) {
                if (key == BUTTON_A) {
                    WRITEU16(0xD3000000, 0x10000000);
                    WRITEU16(0x947909D4, 0x00000001);
                    WRITEU16(0x6400F750, 0x00000000);
                    WRITEU16(0xB400F750, 0x00000000);
                    WRITEU16(0xB0000518, 0x00000000);
                    WRITEU16(0xB000001C, 0x00000000);
                    WRITEU16(0x0000103C, 0x04000000);
                    WRITEU16(0xD2000000, 0x00000000);
                     // toggle cheats when SELECT button pressed
                     //cheatEnabled[0] = !cheatEnabled[0];
                     // wait until key is up
                     //waitKeyUp();
                }
            }
            scanCheatMenu();
            freezeCheatValue();
        }
    }
    Please ignore how messy it is, I plan to write a program that will just auto generate this piece of code and I can just dump gateway codes into!
     
  8. Nanquitas

    Nanquitas GBAtemp Addict

    Member
    2,168
    1,856
    Sep 29, 2015
    France
    South of France :)
    Hmm, the problem is that you just wrote the raw gateways codes, you didn't convert them in C.

    Look how the gateways codes are working (and means), and convert them in C.

    In my github (search for Nanquitas ;) ) I've shared two sources of plugins I made.
    Look for the cheats.c file, all the codes I've translated are in it.
     
  9. Metab
    OP

    Metab GBAtemp Regular

    Member
    156
    94
    Mar 23, 2013
    Where dat ass is
    Ah I see, ive fond your github page but im not sure how to convert these values in C (Or what that means! D:)
    But your code is great reference and will make making my program and cheat files way easier!
     
  10. Nanquitas

    Nanquitas GBAtemp Addict

    Member
    2,168
    1,856
    Sep 29, 2015
    France
    South of France :)
    To help you if you plan using my sources:
    Also my plugins are usable online. ;)
     
  11. Metab
    OP

    Metab GBAtemp Regular

    Member
    156
    94
    Mar 23, 2013
    Where dat ass is
    Thats awesome, how did you convert gateway cheats to a useable format for NTR though? D:
     
  12. Nanquitas

    Nanquitas GBAtemp Addict

    Member
    2,168
    1,856
    Sep 29, 2015
    France
    South of France :)
    I just figured what the gateways codes are doing, and I reproduced what they're doing in C. ;)
     
  13. Metab
    OP

    Metab GBAtemp Regular

    Member
    156
    94
    Mar 23, 2013
    Where dat ass is
    Impressive, sounds like making NTR cheat plugins is abi beyond me at the moment
     
  14. Nanquitas

    Nanquitas GBAtemp Addict

    Member
    2,168
    1,856
    Sep 29, 2015
    France
    South of France :)
    If you're motivated, with a little time to learn the basics of C programming, I'm sure you can find how the whole thing work.

    Or you can take one of my plugin, and comparing the C code I wrote with the Gateway's codes from fort42 to see how I did the conversion. ;)
     
  15. BerserkLeon

    BerserkLeon Not-so-new member

    Member
    434
    63
    Mar 22, 2010
    United States
    Pennsylvania
    @Nanquitas how did you make them work online? I've only experience with menucheat.

    Also I don't know C but Ill look for your sources and see what code types you've figured out.

    ...A program to drop the copy/pasteble stuff into a new file sounds nice, but you could probably do it with autohotkey or another macro program.
     
  16. Ricken

    Ricken No way... Not now...

    Member
    2,258
    2,525
    Jan 19, 2016
    United States
    Shibuya, The small one from Vegas
    Just let me say, you would be a godsend if you made something to convert the Gateshark codes then generate a cheat.plg ;)
     
  17. Nanquitas

    Nanquitas GBAtemp Addict

    Member
    2,168
    1,856
    Sep 29, 2015
    France
    South of France :)
    I did my own main.c to make them work online.
    The sources given by Cell9 contains the main.c already compiled and it's in it that Cell9 blocked the networks. ;)

    All the Gateshark Code can be converted to plugin. ;)

    — Posts automatically merged - Please don't double post! —

    Maybe I'll work on something like that, but I want to do a plugin that can read and execute gateways code from text file directly on the 3DS.
    But I don't know when I'll do that, I haven't too much time and I already have a project going on (RAM Explorer)...

    But one day who knows... ;)
     
    Ricken and BerserkLeon like this.
  18. Ricken

    Ricken No way... Not now...

    Member
    2,258
    2,525
    Jan 19, 2016
    United States
    Shibuya, The small one from Vegas
    Same effect :yay3ds:

    Regardless, Either would be amazing