Homebrew Toolbox and tutorial: How to use Ninjhax and make your own homebrews

  • Thread starter xem
  • Start date
  • Views 30,879
  • Replies 90
  • Likes 14

xem

Well-Known Member
OP
Member
Joined
Nov 22, 2014
Messages
142
Trophies
0
Age
37
Location
Valbonne
XP
343
Country
France
I didn't say emulators were illegal or forbidden by my tutorial. You can emulate games you have, or homebrews, or public domain games.
I just said that I don't do that to encourage piracy.
 

yodamerlin

Bok bok.
Member
Joined
Apr 1, 2014
Messages
322
Trophies
0
XP
1,050
Country
United Kingdom
I know next to nothing about programming but I assume you can change it in the main.c code, here:

Code:
        u32 kDown = hidKeysDown();
        if (kDown & KEY_START)
            break; // break in order to return to hbmenu

Line 20 in the ctrulib template.

Anyway, it's a great tutorial project, I'm looking forward for the prog part! :)
Yeah, we know how to do it. But do we want to? And do we want all apps to follow there guidelines?
That is the question.
 

xem

Well-Known Member
OP
Member
Joined
Nov 22, 2014
Messages
142
Trophies
0
Age
37
Location
Valbonne
XP
343
Country
France
Hi,

I just reorganized the project in different files, and added a doxygen dump of ctrulib, which I plan to use as a basis for my upcoming documentation.

If someone here is an expert in doxygen and can make a better export than the one I have, please send it as a pull request or upload it somewhere. Thanks! :)

Cheers,

M.E
 
  • Like
Reactions: Sparks43

Stalkid64

Well-Known Member
Member
Joined
Apr 20, 2008
Messages
119
Trophies
0
XP
185
Country
United States
Enjoyed playing around a bit with the examples so far (shame the FTP is so utterly terrible), looking forward to learning more. A good, clear start.
 
  • Like
Reactions: xem

shinyquagsire23

SALT/Sm4sh Leak Guy
Member
Joined
Nov 18, 2012
Messages
1,977
Trophies
2
Age
26
Location
Las Vegas
XP
3,765
Country
United States
OK, I thought it was just the netloader bit from the homebrew menu (lets you do a cat derp.3dsx | nc xxx,xxx,xxx,xxx 9000 to transfer files to 3DS), but I'm having some baffling issues in getting this stuff to not crash. Just adding or modifying one random variable in some cases will just completely crash the 3DS back to the home menu. Is the newest version of DevKitPro even stable for 3DS? Or should I revert to the last version?

EDIT: Derp, I had just passed a float to a function I wrote which asked for an int, which then most likely was interpreted as an absurdely large value and wrote to some memory outside the buffer. I'll probably go ahead and make those functions a bit more safe because they've been giving me a lot of trouble lately.
 

ChrisRX

Well-Known Member
Member
Joined
Nov 8, 2006
Messages
490
Trophies
0
Website
Visit site
XP
420
Country
I'm not having any luck with netcat loading. When I press Y on the homebrew channel nothing changes on screen, I don't know if it should.

Then if I use netcat to pipe a .3dsx file to the 3DS' IP, nothing happens. It takes a few seconds to send some of the demos compiled from ctrulib but then the files aren't loaded on the 3DS.

Is there something I'm missing? Could someone help me out?
 

xem

Well-Known Member
OP
Member
Joined
Nov 22, 2014
Messages
142
Trophies
0
Age
37
Location
Valbonne
XP
343
Country
France
A contributor added this netcat part in the tuto but I didn't try yet. I pressed Y and saw that nothing happened too... weird. If other people confirm that it doesn't work, I'll remove it.
 

ChrisRX

Well-Known Member
Member
Joined
Nov 8, 2006
Messages
490
Trophies
0
Website
Visit site
XP
420
Country
A contributor added this netcat part in the tuto but I didn't try yet. I pressed Y and saw that nothing happened too... weird. If other people confirm that it doesn't work, I'll remove it.

I looked at the hbmenu code and the Y netcat part wasn't added until after the original release. I compiled the latest hbmenu from github and your instructions worked fine.
You may want to add that if anyone wants to use this feature they'll need to compile the latest hbmenu.

Thanks for your work on this guide.
 
  • Like
Reactions: xem

shinyquagsire23

SALT/Sm4sh Leak Guy
Member
Joined
Nov 18, 2012
Messages
1,977
Trophies
2
Age
26
Location
Las Vegas
XP
3,765
Country
United States
A contributor added this netcat part in the tuto but I didn't try yet. I pressed Y and saw that nothing happened too... weird. If other people confirm that it doesn't work, I'll remove it.

Even if you don't remove it, you might want to add that it can sometimes fail and only retrieve corrupted data and crash your 3DS. I've had this happen several times, and usually I can just run it again and it (might) work. It's definitely useful for testing though, because it's extremely fast. I don't even have a working SD card reader on my desktop and since ftpony refuses to work on Linux (or at all) this is my best bet. And if I need to test any final packages I can use my laptop to transfer files to the SD card.
 

xem

Well-Known Member
OP
Member
Joined
Nov 22, 2014
Messages
142
Trophies
0
Age
37
Location
Valbonne
XP
343
Country
France
I looked at the hbmenu code and the Y netcat part wasn't added until after the original release. I compiled the latest hbmenu from github and your instructions worked fine.
You may want to add that if anyone wants to use this feature they'll need to compile the latest hbmenu.

Thanks for your work on this guide.
you're welcome, thank YOU for this information!

Thankstoo shinyquagsire23 for the warninghttps://gbatemp.net/members/shinyquagsire23.318030/
 

jamieyello

Professional Dumbass
Member
Joined
Mar 11, 2013
Messages
385
Trophies
0
XP
556
Country
United States
Thanks for making this!

Using your code I was able to make my pic move around on the screen when pressing buttons.

Code:
#include <3ds.h>
 
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
 
#include "spidimage_bin.h"
 
void gfxDrawSprite(gfxScreen_t screen, gfx3dSide_t side, u8* spriteData, u16 width, u16 height, s16 x, s16 y) {
  //This function includes documantation so you might be able to figure out what the function is doing, you don't need to understand this to use it!
  if(!spriteData)return; //check if the function has sprite data, if not stop!
 
  u16 fbWidth, fbHeight; //set variables for width and height
  u8* fbAdr = gfxGetFramebuffer(screen, side, &fbWidth, &fbHeight); //get framebuffer for the screen and side used.
 
  if(x + width < 0 || x >= fbWidth)return; //check invalid x cords
  if(y + height < 0 ||y >= fbHeight)return; //check invalid y cords
 
  u16 xOffset = 0, yOffset = 0; //set offset for x and y
  u16 widthDrawn = width, heightDrawn = height; //set width/height vars that for drawing
 
  if(x < 0) xOffset = -x; //use offset
  if(y < 0) yOffset = -y; //use offset
  if(x + width >= fbWidth) widthDrawn = fbWidth - x;
  if(y + height >= fbHeight) heightDrawn = fbHeight - y;
  widthDrawn -=xOffset;
  heightDrawn -=yOffset;
 
  int j;
  for(j = yOffset; j < yOffset + heightDrawn; j++) { //for loop for drawing image
    memcpy(&fbAdr[ ((x + xOffset) + (y + j) * fbWidth) * 3 ], &spriteData[ ((xOffset + j) * width) * 3 ], widthDrawn * 3); //copy imagedata into memory
  }
}
 
void gfxDrawSpriteAlpha(gfxScreen_t screen, gfx3dSide_t side, u8* spriteData, u16 width, u16 height, s16 x, s16 y) {
  if(!spriteData)return;
 
  u16 fbWidth, fbHeight;
  u8* fbAdr = gfxGetFramebuffer(screen, side, &fbWidth, &fbHeight);
 
  if(x + width < 0 || x >= fbWidth)return;
  if(y + height < 0 || y >= fbHeight)return;
 
  u16 xOffset = 0, yOffset = 0;
  u16 widthDrawn = width, heightDrawn = height;
 
  if(x < 0)xOffset = -x;
  if(y < 0)yOffset = -y;
  if(x + width >= fbWidth) widthDrawn = fbWidth - x;
  if(y + height >= fbHeight)heightDrawn = fbHeight - y;
  widthDrawn -=xOffset;
  heightDrawn -=yOffset;
 
  //TODO : optimize
  fbAdr += ( y + yOffset) * fbWidth * 3;
  spriteData += yOffset * width * 4;
  int j, i;
  for(j = yOffset; j < yOffset + heightDrawn; j++) {
    u8* fbd = &fbAdr[ (x + xOffset) * 3 ];
    u8* data = &spriteData[ xOffset * 4 ];
    for(i = xOffset; i < xOffset + widthDrawn; i++) {
      if(data[3]) {
        fbd[0] = data[0];
        fbd[1] = data[1];
        fbd[2] = data[2];
      }
      fbd +=3;
      data +=4;
    }
    fbAdr += fbWidth * 3;
    spriteData += width * 4;
  }
}
 
void gfxDrawSpriteAlphaBlend(gfxScreen_t screen, gfx3dSide_t side, u8* spriteData, u16 width, u16 height, s16 x, s16 y) {
  if(!spriteData)return;
 
  u16 fbWidth, fbHeight;
  u8* fbAdr = gfxGetFramebuffer(screen, side, &fbWidth, &fbHeight);
 
  if(x + width < 0 || x >= fbWidth)return;
  if(y + height < 0 || y >= fbHeight)return;
 
  u16 xOffset = 0, yOffset = 0;
  u16 widthDrawn = width, heightDrawn = height;
 
  if(x < 0)xOffset = -x;
  if(y < 0)yOffset = -y;
  if(x + width >= fbWidth) widthDrawn = fbWidth - x;
  if(y + height >= fbHeight)heightDrawn = fbHeight - y;
  widthDrawn -=xOffset;
  heightDrawn -=yOffset;
 
 
  //TODO : optimize
  fbAdr += (y + yOffset) * fbWidth * 3;
  spriteData += yOffset * width *4;
  int j, i;
  for(j = yOffset; j < (yOffset + heightDrawn); j++) {
    u8* fbd = &fbAdr[ (x + xOffset) * 3 ];
    u8* data = &spriteData[ xOffset * 4 ];
    for(i = xOffset; i < xOffset + widthDrawn; i++) {
      if(data[3]) {
        u8 alphaSource = data[3];
        fbd[0] = ((data[0] * alphaSource)+(fbd[0] * (255 - alphaSource))) / 256;
        fbd[1] = ((data[1] * alphaSource)+(fbd[1] * (255 - alphaSource))) / 256;
        fbd[2] = ((data[2] * alphaSource)+(fbd[2] * (255 - alphaSource))) / 256;
      }
      fbd +=3;
      data +=4;
    }
    fbAdr += fbWidth * 3;
    spriteData += width * 4;
  }
}
 
int xpos;
int ypos;
 
 
int main()
{
  // Initializations
  srvInit();        // services
  aptInit();        // applets
  hidInit(NULL);    // input
  gfxInit();        // graphics
  gfxSet3D(false);  // stereoscopy (true: enabled / false: disabled)
  u32 kDown;        // keys down
  u32 kHeld;        // keys pressed
  u32 kUp;          // keys up
 
  // Main loop
  while (aptMainLoop())
  {
 
    // Wait for next frame
    gspWaitForVBlank();
 
    // Read which buttons are currently pressed or not
    hidScanInput();
    kDown = hidKeysDown();
    kHeld = hidKeysHeld();
    kUp = hidKeysUp();
 
 
    // If START button is pressed, break loop and quit
    if (kDown & KEY_START){
      break;
    }
 
    if (kHeld & KEY_LEFT){
        ypos-=1;
    }
 
    if (kHeld & KEY_RIGHT){
        ypos+=1;
    }
 
    if (kHeld & KEY_UP){
        xpos+=1;
    }
 
    if (kHeld & KEY_DOWN){
        xpos-=1;
    }
 
 
    gfxDrawSprite(GFX_TOP,GFX_LEFT,spidimage_bin,100,100,xpos,ypos);
 
 
    // Flush and swap framebuffers
 
    gfxFlushBuffers();
    gfxSwapBuffers();
  }
 
  // Exit
  gfxExit();
  hidExit();
  aptExit();
  srvExit();
 
  // Return to hbmenu
  return 0;
}

make didn't like it for whatever reason when I used #include <functions.h> (and had the functions c file in the source folder along with main) so I just copied and pasted all the functions to the top of my code and that worked just fine. I know I'm doing something wrong but whatever. What would be the command to clear the screen? Because right now I've got a trail thing happening. There's also a weird flickering effect going on if you look closely.

Edit added .zip
 

Attachments

  • test.zip
    208.5 KB · Views: 141

mdlmemorybank

Well-Known Member
Newcomer
Joined
Apr 25, 2008
Messages
91
Trophies
1
XP
372
Country
United States
Its a wonderful thing your doing here and I really appreciate it. If smealum opened a door to homebrew you certainly are helping people take their first steps through it. Cant wait to learn more from you and keep putting one foot in front of the other :D Thank you
 
  • Like
Reactions: xem

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
  • K3Nv2 @ K3Nv2:
    Don't know burnt pizza can be pretty bad
  • Xdqwerty @ Xdqwerty:
    gonna download sonic generations to my ps3
  • BigOnYa @ BigOnYa:
    How do you put games on there? Does it have like a game store on the ps3?
  • K3Nv2 @ K3Nv2:
    Black market store
    +1
  • Xdqwerty @ Xdqwerty:
    @BigOnYa, download a pkg file, put it in a usb or a sd card, put the usb or sd card to ps3, turn on ps3hen, go to install game, install the game
    +1
  • BigOnYa @ BigOnYa:
    Ok yea that's same with me, was just curious. Coolio
    +1
  • Xdqwerty @ Xdqwerty:
    good night
  • BigOnYa @ BigOnYa:
    Nighty night
  • K3Nv2 @ K3Nv2:
    Lmao my keyboard decided to randomly die
  • BigOnYa @ BigOnYa:
    Its prob your new router interfering w it
  • K3Nv2 @ K3Nv2:
    How when my old one worked fine
  • BigOnYa @ BigOnYa:
    You figure out ring and all smart devices? And POE
  • K3Nv2 @ K3Nv2:
    Yeah but gave up on PPPoE
    +1
  • Sicklyboy @ Sicklyboy:
    did you fix it ken?
  • K3Nv2 @ K3Nv2:
    Bob the builder
  • K3Nv2 @ K3Nv2:
    Uck
  • BakerMan @ BakerMan:
    you
  • K3Nv2 @ K3Nv2:
    Deeze nuts
  • BakerMan @ BakerMan:
    $21 bill dropped

    iu
  • K3Nv2 @ K3Nv2:
    Wtf are you doing with that $20 cutting up meth
  • BigOnYa @ BigOnYa:
    Going to jail if he tries to spend it
  • K3Nv2 @ K3Nv2:
    Try to buy something with it
    K3Nv2 @ K3Nv2: Try to buy something with it