Hacking [WIP] MysteriUs

ryuutseku85

Well-Known Member
OP
Member
Joined
Dec 14, 2015
Messages
112
Trophies
0
Age
39
XP
432
Country
France
Hi everyone ,

it's finally the release day!

this is my first homebrew so please be indulgent .

it's still need some minor adjustement but work complety fine .

i use a tricky way to generate a random number.(i will explain later).

i will give my code for the next update with lots of comment , that way beginner can easely understand it and i hope make there own to grow the community.

i post the 550 and 532 in the zip , but i don't have a 532 system to verify if this work.

Comments and Critics are welcome.

Ryuutseku85



The game will be simple :
find the mysterious number , the wiiu will search for a mysterious number , it will ask you what is it , and it will answer , "more" , "less" or "congratulations !!! you win ".
all of you now this game , right ?
so lets begin ,

i have this code
loader.c
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "loader.h"
#include "control.h"


void START ()
{


   asm(
     "lis %r1, 0x1ab5 ;"
     "ori %r1, %r1, 0xd138 ;"
     );

   uint32_t coreinit_handle;
   OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);

   void(*OSScreenInit)();
   unsigned int(*OSScreenGetBufferSizeEx)(unsigned int bufferNum);
   unsigned int(*OSScreenSetBufferEx)(unsigned int bufferNum, void * addr);

   void*(*memset)(void * dest, uint32_t value, uint32_t bytes);
   void(*OSFreeToSystem)(void *ptr);
   void* (*OSAllocFromSystem)(uint32_t size, int align);
   OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem);

   int(*IM_Open)();
   int(*IM_Close)(int fd);
   int(*IM_SetDeviceState)(int fd, void *mem, int state, int a, int b);
   /****************************>  Exports  <****************************/

   OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenInit", &OSScreenInit);
   OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx);
   OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenSetBufferEx", &OSScreenSetBufferEx);

   OSDynLoad_FindExport(coreinit_handle, 0, "memset", &memset);
   OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem);
   OSDynLoad_FindExport(coreinit_handle, 0, "OSFreeToSystem", &OSFreeToSystem);

   OSDynLoad_FindExport(coreinit_handle, 0, "IM_Open", &IM_Open);
   OSDynLoad_FindExport(coreinit_handle, 0, "IM_Close", &IM_Close);
   OSDynLoad_FindExport(coreinit_handle, 0, "IM_SetDeviceState", &IM_SetDeviceState);

   int fd = IM_Open();
   void *mem = OSAllocFromSystem(0x100, 64);
   memset(mem, 0, 0x100);

   IM_SetDeviceState(fd, mem, 3, 0, 0);
   IM_Close(fd);
   OSFreeToSystem(mem);

   unsigned int t1 = 0x1FFFFFFF;
   while(t1--) ;

   OSScreenInit();

   int buf0_size = OSScreenGetBufferSizeEx(0);
   int buf1_size = OSScreenGetBufferSizeEx(1);

   OSScreenSetBufferEx(0, (void *)0xF4000000);
   OSScreenSetBufferEx(1, (void *)0xF4000000 + buf0_size);

   int ii = 0;
   for (ii; ii < 2; ii++)
   {
     fillScreen(0,0,0,0);
     flipBuffers();
   }
   _getIN();
}
void _getIN()
{

   uint32_t coreinit_handle;
   OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);

   unsigned int vpad_handle;
   OSDynLoad_Acquire("vpad.rpl", &vpad_handle);

   int(*VPADRead)(int controller, VPADData *buffer, unsigned int num, int *error);

   void(*_Exit)();

   OSDynLoad_FindExport(vpad_handle, 0, "VPADRead", &VPADRead);

   OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit);

   VPADData vpad_data;

   int error;

   VPADRead(0, &vpad_data, 1, &error);




  printf("  MysteriU  \n");

  int compteur = 0;

  int nombreentre = 0;

  int nombremystere = 0;

  const int min = 1 ;

  const int max = 10;

  srand(time(NULL));
  nombremystere = (rand()% (max -min +1)+ min);

  printf("what is the mysterious number\n\n");

  compteur++ ;

  scanf("%d" , &nombreentre);

  if(nombreentre < nombremystere)

  printf("it's more \n\n") ;


  if(nombreentre > nombremystere)

  printf("it's less \n\n") ;



  if (nombreentre==nombremystere)

  printf("congrats ! you win!!!\n\n", compteur);
  printf("\n\n\n");

  return 0;
}
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "loader.h"
#include "control.h"


void START ()
{


    asm(
        "lis %r1, 0x1ab5 ;"
        "ori %r1, %r1, 0xd138 ;"
        );

    uint32_t coreinit_handle;
    OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);

    void(*OSScreenInit)();
    unsigned int(*OSScreenGetBufferSizeEx)(unsigned int bufferNum);
    unsigned int(*OSScreenSetBufferEx)(unsigned int bufferNum, void * addr);

    void*(*memset)(void * dest, uint32_t value, uint32_t bytes);
    void(*OSFreeToSystem)(void *ptr);
    void* (*OSAllocFromSystem)(uint32_t size, int align);
    OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem);

    int(*IM_Open)();
    int(*IM_Close)(int fd);
    int(*IM_SetDeviceState)(int fd, void *mem, int state, int a, int b);
    /****************************>             Exports             <****************************/

    OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenInit", &OSScreenInit);
    OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx);
    OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenSetBufferEx", &OSScreenSetBufferEx);

    OSDynLoad_FindExport(coreinit_handle, 0, "memset", &memset);
    OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem);
    OSDynLoad_FindExport(coreinit_handle, 0, "OSFreeToSystem", &OSFreeToSystem);

    OSDynLoad_FindExport(coreinit_handle, 0, "IM_Open", &IM_Open);
    OSDynLoad_FindExport(coreinit_handle, 0, "IM_Close", &IM_Close);
    OSDynLoad_FindExport(coreinit_handle, 0, "IM_SetDeviceState", &IM_SetDeviceState);

    int fd = IM_Open();
    void *mem = OSAllocFromSystem(0x100, 64);
    memset(mem, 0, 0x100);

    IM_SetDeviceState(fd, mem, 3, 0, 0);
    IM_Close(fd);
    OSFreeToSystem(mem);

    unsigned int t1 = 0x1FFFFFFF;
    while(t1--) ;

    OSScreenInit();

    int buf0_size = OSScreenGetBufferSizeEx(0);
    int buf1_size = OSScreenGetBufferSizeEx(1);

    OSScreenSetBufferEx(0, (void *)0xF4000000);
    OSScreenSetBufferEx(1, (void *)0xF4000000 + buf0_size);

    int ii = 0;
    for (ii; ii < 2; ii++)
    {
        fillScreen(0,0,0,0);
        flipBuffers();
    }
    _getIN();
}
void _getIN()
{

    uint32_t coreinit_handle;
    OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);

    unsigned int vpad_handle;
    OSDynLoad_Acquire("vpad.rpl", &vpad_handle);

    int(*VPADRead)(int controller, VPADData *buffer, unsigned int num, int *error);

    void(*_Exit)();

    OSDynLoad_FindExport(vpad_handle, 0, "VPADRead", &VPADRead);

    OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit);

    VPADData vpad_data;

    int error;

    VPADRead(0, &vpad_data, 1, &error);




    printf("       MYSTERIU           \n");

    int compteur = 0;

    int nombreentre = 0;

    int nombremystere = 0;

    const int min = 1 ;

    const int max = 10;

    srand(time(NULL));
    nombremystere = (rand()% (max -min +1)+ min);

    printf("quel est le nombre secret?\n\n");

    compteur++ ;

    scanf("%d" , &nombreentre);

    if(nombreentre < nombremystere)

        printf("c'est plus\n\n") ;


    if(nombreentre > nombremystere)

        printf("c'est moins\n\n") ;



    if (nombreentre==nombremystere)

        printf("bravo ! tu as trouve le nombre secret en %d fois\n\n", compteur);
        printf("\n\n\n");

    return 0;
}

controller (for later with more choice)
Code:
#define BUTTON_A        0x8000
#define BUTTON_B        0x4000
#define BUTTON_X        0x2000
#define BUTTON_Y        0x1000
#define BUTTON_LEFT     0x0800
#define BUTTON_RIGHT    0x0400
#define BUTTON_UP       0x0200
#define BUTTON_DOWN     0x0100
#define BUTTON_ZL       0x0080
#define BUTTON_ZR       0x0040
#define BUTTON_L        0x0020
#define BUTTON_R        0x0010
#define BUTTON_PLUS     0x0008
#define BUTTON_MINUS    0x0004
#define BUTTON_HOME     0x0002
#define BUTTON_SYNC     0x0001
#define BUTTON_STICK_R  0x00020000
#define BUTTON_STICK_L  0x00040000
#define BUTTON_TV       0x00010000

and loader.h
Code:
#include "../../../../../../../devkitPro/libwiiu/src/coreinit.h"
#include "../../../../../../../devkitPro/libwiiu/src/vpad.h"
#include "../../../../../../../devkitPro/libwiiu/src/draw.h"
#include "../../../../../../../devkitPro/libwiiu/src/string.h"

void _getIN();

the problem is that actually nothing work , i don't know how to wrote something on the screen , and do how to make the player answer . i find i will do an void exit for the end too .

thanks for your help.
 

Attachments

  • MysteriU.zip
    9.4 KB · Views: 149
Last edited by ryuutseku85,

Leanny

Well-Known Member
Member
Joined
Feb 14, 2009
Messages
112
Trophies
1
XP
375
Country
Gambia, The
i don't know how to wrote something on the screen , and do how to make the player answer . i find i will do an void exit for the end too .

thanks for your help.

For writing you can use __os_snprintf(). Check osscreenexamples/ios for an example. For the answering you can do the following:
0. you need one variable for the number and one for the current position.
1. check for input (up, down, left, right, a)
2a. if left, current position + 1, if right, current position -1.
2b. if up, number = (number-(number/10^position)*(10^position)) + (((number/10^position)%10+1)%10)*10^position, assuming you start at position 0. This basicly just increases the number on a specific position to 1 and in case you leave the current position, it will be resettet to 0.
2c. analog to above, just subtract for down.
2d. for a apply it
3. draw the current number with some arrows. You can do this with simple math for positions

use this just as an idea on how to do it, there is still lots of stuff to do for it to work completly.
 
  • Like
Reactions: ryuutseku85

ryuutseku85

Well-Known Member
OP
Member
Joined
Dec 14, 2015
Messages
112
Trophies
0
Age
39
XP
432
Country
France
hi ,
can someone explain me how this fu*****g __os_printf work , please?

i made my structure for the button and title
Code:
struct rendertext
{
  int a;
  int b;
  int x;
  int y;
  char output[1000];
};

struct title
{
  int mysteriu;
  int press_a;
  char title[1000];
};

then made my initialisation
Code:
struct rendertext text;
    text.a=0;
    text.b=0;
    text.x=0;
    text.y=0;

    struct title titre;
    titre.mysteriu=0;
    titre.press_a=0;
    while(1)

the i start the game
Code:
just before that we have ou initialisation of both struct

while(1)
    {
        VPADRead(0, &vpad_data, 1, &error);




//game start//

int choice = 0;


do
{choice = 0;

        int Number = 0 ;

        int compteur = 0;

        int nombreentre = 0;

        int nombremystere = 8;

        const int min = 1 ;

        const int max = 10;

        int ask = 0;
     
    do
    {

        __os_snprintf(titre.title,1000,"MysteriU\n");
        __os_snprintf(titre.title,1000,"Press A to play.\n");
        if (vpad_data.btn_trigger && BUTTON_A);
        {
            text.a=1;
        }
    }
    while (text.a!=1);
and i got a blank screen i also try with the drawstring and _printstr
(the only one who actually print something on the screen is _printstr , but i can do anything after that , i think the wiiu just freeze.)

thanks for those who gonna help me.

Code:
#include "loader.h"
#include "control.h"

void _start ()
{


    asm(
        "lis %r1, 0x1ab5 ;"
        "ori %r1, %r1, 0xd138 ;"
        );

    uint32_t coreinit_handle;
    OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);

    void(*OSScreenInit)();
    unsigned int(*OSScreenGetBufferSizeEx)(unsigned int bufferNum);
    unsigned int(*OSScreenSetBufferEx)(unsigned int bufferNum, void * addr);

    void*(*memset)(void * dest, uint32_t value, uint32_t bytes);
    void(*OSFreeToSystem)(void *ptr);
    void* (*OSAllocFromSystem)(uint32_t size, int align);
    OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem);

    int(*IM_Open)();
    int(*IM_Close)(int fd);
    int(*IM_SetDeviceState)(int fd, void *mem, int state, int a, int b);
    /****************************>             Exports             <****************************/

    OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenInit", &OSScreenInit);
    OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx);
    OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenSetBufferEx", &OSScreenSetBufferEx);

    OSDynLoad_FindExport(coreinit_handle, 0, "memset", &memset);
    OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem);
    OSDynLoad_FindExport(coreinit_handle, 0, "OSFreeToSystem", &OSFreeToSystem);

    OSDynLoad_FindExport(coreinit_handle, 0, "IM_Open", &IM_Open);
    OSDynLoad_FindExport(coreinit_handle, 0, "IM_Close", &IM_Close);
    OSDynLoad_FindExport(coreinit_handle, 0, "IM_SetDeviceState", &IM_SetDeviceState);

    int fd = IM_Open();
    void *mem = OSAllocFromSystem(0x100, 64);
    memset(mem, 0, 0x100);

    IM_SetDeviceState(fd, mem, 3, 0, 0);
    IM_Close(fd);
    OSFreeToSystem(mem);

    unsigned int t1 = 0x1FFFFFFF;
    while(t1--) ;

    OSScreenInit();

    int buf0_size = OSScreenGetBufferSizeEx(0);
    int buf1_size = OSScreenGetBufferSizeEx(1);

    OSScreenSetBufferEx(0, (void *)0xF4000000);
    OSScreenSetBufferEx(1, (void *)0xF4000000 + buf0_size);

    int ii = 0;
    for (ii; ii < 2; ii++)
    {
        fillScreen(0,0,0,0);
        flipBuffers();
    }
    _getIN();

}
void _getIN()
{

    uint32_t coreinit_handle;
    OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);

    unsigned int vpad_handle;
    OSDynLoad_Acquire("vpad.rpl", &vpad_handle);

    int(*VPADRead)(int controller, VPADData *buffer, unsigned int num, int *error);

    void(*_Exit)();

    OSDynLoad_FindExport(vpad_handle, 0, "VPADRead", &VPADRead);

    OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit);

    VPADData vpad_data;

    int error;

    VPADRead(0, &vpad_data, 1, &error);

    struct rendertext text;
    text.a=0;
    text.b=0;
    text.x=0;
    text.y=0;

    struct title titre;
    titre.mysteriu=0;
    titre.press_a=0;
    while(1)
    {
        VPADRead(0, &vpad_data, 1, &error);




//game start//

int choice = 0;


do
{choice = 0;

        int Number = 0 ;

        int compteur = 0;

        int nombreentre = 0;

        int nombremystere = 8;

        const int min = 1 ;

        const int max = 10;

        int ask = 0;
        char mysteriu[10];
    do
    {

        __os_snprintf(titre.title,1000,"MysteriU\n");
        __os_snprintf(titre.title,1000,"Press A to play.\n");
        if (vpad_data.btn_trigger && BUTTON_A);
        {
            text.a=1;
        }
    }
    while (text.a!=1);

            if (vpad_data.btn_trigger && BUTTON_A);
            {
                do
    {
        char between[120];
        char POM[120];//+ or -//
        char confirm[100];
        char number[10];

        int i =0;

        __os_snprintf(between,120,"what is the mysterius number?\n");

        _printstr("what is the mysterious Number?\n The number is between 0 and 10.\n\n use + or - button to answer and validate by pressing A.\n\n\n");
        __os_snprintf(between,120,"The number is between %d and %d .\n",min,max);

        __os_snprintf(POM,120,"Press the + and - button to answer.\n\n");

        __os_snprintf(confirm,120,"A to confirm\n");

do
{


        if (vpad_data.btn_trigger && BUTTON_PLUS)
            {
                Number++;

                    __os_snprintf(number,10,"%d",Number);



            }


        if (vpad_data.btn_trigger & BUTTON_MINUS)
            {
                Number--;
                    __os_snprintf(number,10,"%d",Number);

            }
}

            while (vpad_data.btn_trigger!= BUTTON_A);

        if (vpad_data.btn_trigger && BUTTON_A)
        {
           ask++;
        }





    }
   while (ask != 1);

        nombreentre=Number;

    if(nombreentre < nombremystere)
{
    char more[50];
    __os_snprintf(more,50,"it's more than %d \n",Number);

}



    if(nombreentre > nombremystere)
    { char less[50];
    __os_snprintf(less,50,"it's less than %d \n",Number);

    }




    if (nombreentre==nombremystere)
    {
        char win[100];
        char continuer[100];
        __os_snprintf(win,100,"congrats you win ! do you want to play again ?\n");

        __os_snprintf(continuer,100,"Would you like to play again?\n");

        if (vpad_data.btn_trigger && BUTTON_Y)
        {
            choice++;
        }


            if (vpad_data.btn_trigger && BUTTON_X)
            {
                _printstr("thanks for playing");
                _doExit();
            }
    }
}


        if (vpad_data.btn_trigger && BUTTON_HOME)
        {
            _doExit();
        }


}
while (choice=!1);

_doExit();
}
}

void _printstr(char *str)
{
    int ii = 0;
    for (ii; ii < 2; ii++)
    {
        fillScreen(0,0,0);
        drawString(0,0,0,0,str);
        flipBuffers();
    }
}

void _doExit()
{
    void(*_Exit)();
    uint32_t coreinit_handle;
    OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit);
    _Exit();
}
 
Last edited by ryuutseku85,

Blackspoon

Active Member
Newcomer
Joined
Feb 19, 2016
Messages
31
Trophies
0
Age
31
Location
next to the blackfork
XP
152
Country
Gambia, The
Let me help you out.
First you should have a look at this:
www.learn-c.org

It should help you to understand the basics of C.

__os_snprintf doesnt print anything on the screen. It just format the char buffer like this:
Code:
char buffer[255];
__os_snprintf(buffer,  255, "Simple String.");

The string "Simple String" was put into the buffer variable.
Now you can take the buffer and put it as a parameter in your _printstr function:

Code:
char buffer[255];
__os_snprintf(buffer,  255, "Simple String.");

_printstr(buffer);

If you want to put an integer in a string you can use a placeholder and add an agrument:

Code:
int integer = 53421;
char buffer[255];
__os_snprintf(buffer,  255, "The integer has the value: %i", integer);

_printstr(buffer);
__os_snprintf is documented here: http://wiiubrew.org/wiki/Coreinit.rpl#Internal

__os_snprintf is a wiiu equivalent to the function snprintf at other operating systems and its handling is the same.
Look at this page http://www.cplusplus.com/reference/cstdio/snprintf/ for more formating options.



I hope it would help you a littlebit.

Blackspoon
 
Last edited by Blackspoon,
  • Like
Reactions: ryuutseku85

ryuutseku85

Well-Known Member
OP
Member
Joined
Dec 14, 2015
Messages
112
Trophies
0
Age
39
XP
432
Country
France
Thanks a lot , i do C since january so i am still learning :)

so i have to say it's comming (some tweak need to be done with the IF statement)

MysteriU screen start.jpg
 
  • Like
Reactions: Masterwin

ryuutseku85

Well-Known Member
OP
Member
Joined
Dec 14, 2015
Messages
112
Trophies
0
Age
39
XP
432
Country
France
hi ,

so here we go again ...

first off :
in the browser we have a rpl call randgen.rpl and it get NSSGetRandom function that need two arg (obviously min and max in my case).

so this being said , let's go to the problem (again an other ?)
so i have my code , nothing seem wrong to me , but i don't know why but my wiiu freeze at my screen start .

here is my c code :
Code:
#include "loader.h"
#include "control.h"

void _start ()
{


    asm(
        "lis %r1, 0x1ab5 ;"
        "ori %r1, %r1, 0xd138 ;"
        );

    uint32_t coreinit_handle;
    OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);


    void(*OSScreenInit)();
    unsigned int(*OSScreenGetBufferSizeEx)(unsigned int bufferNum);
    unsigned int(*OSScreenSetBufferEx)(unsigned int bufferNum, void * addr);

    void*(*memset)(void * dest, uint32_t value, uint32_t bytes);
    void(*OSFreeToSystem)(void *ptr);
    void* (*OSAllocFromSystem)(uint32_t size, int align);
    OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem);

    int(*IM_Open)();
    int(*IM_Close)(int fd);
    int(*IM_SetDeviceState)(int fd, void *mem, int state, int a, int b);
    /****************************>             Exports             <****************************/

    OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenInit", &OSScreenInit);
    OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx);
    OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenSetBufferEx", &OSScreenSetBufferEx);

    OSDynLoad_FindExport(coreinit_handle, 0, "memset", &memset);
    OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem);
    OSDynLoad_FindExport(coreinit_handle, 0, "OSFreeToSystem", &OSFreeToSystem);

    OSDynLoad_FindExport(coreinit_handle, 0, "IM_Open", &IM_Open);
    OSDynLoad_FindExport(coreinit_handle, 0, "IM_Close", &IM_Close);
    OSDynLoad_FindExport(coreinit_handle, 0, "IM_SetDeviceState", &IM_SetDeviceState);

    int fd = IM_Open();
    void *mem = OSAllocFromSystem(0x100, 64);
    memset(mem, 0, 0x100);

    IM_SetDeviceState(fd, mem, 3, 0, 0);
    IM_Close(fd);
    OSFreeToSystem(mem);

    unsigned int t1 = 0x1FFFFFFF;
    while(t1--) ;

    OSScreenInit();

    int buf0_size = OSScreenGetBufferSizeEx(0);
    int buf1_size = OSScreenGetBufferSizeEx(1);

    OSScreenSetBufferEx(0, (void *)0xF4000000);
    OSScreenSetBufferEx(1, (void *)0xF4000000 + buf0_size);

    int ii = 0;
    for (ii; ii < 2; ii++)
    {
        fillScreen(0,0,0,0);
        flipBuffers();
    }
    _getIN();

}

void _getIN()
{

    uint32_t coreinit_handle;
    OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);

    unsigned int vpad_handle;
    OSDynLoad_Acquire("vpad.rpl", &vpad_handle);


    int(*VPADRead)(int controller, VPADData *buffer, unsigned int num, int *error);


    void(*_Exit)();

    OSDynLoad_FindExport(vpad_handle, 0, "VPADRead", &VPADRead);

    OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit);


    fillScreen(0,0,0,0);

    VPADData vpad_data;

    int error;
    int menu=0;
    int Game=0;
    int choicenumber=0;
    int number=0;
    int Mline=0;
    int Nline=0;
    int ask = 0;
    int compteur = 0;
    int nombreentre = 0;
    int nombremystere;
    int min;
    int max;
    int unite=0;
    int dizaine=0;
    int centaine=0;
    int mille=0;
    int dix_mille=0;
    int arrow =0;
    int ScreenSync=0;
    int WaitTime = 0;


    VPADRead(0, &vpad_data, 1, &error);

    while(1)
    {
        VPADRead(0, &vpad_data, 1, &error);

//Start Screen//
        if (menu==0 && Game == 0)
        {
            WaitTime=250;
            //print our start screen//

            while (WaitTime-- > 0)
            {
                fillScreen(0,0,0,0);
                DisplayMenu(Mline);
                flipBuffers();
            }
            menu++;
            Game++;
        }
        else
            {
            menu++;
            Game++;
            }

if(Game==1 && menu == 1)
{
            min=1;
            max=10;

        nombremystere=rand(min,max);
        fillScreen(0,0,0,0);
        DisplayGame(Nline ,min, max ,nombremystere ,nombreentre,unite,dizaine,centaine,mille,dix_mille,choicenumber);
        flipBuffers();
}
else
{
    _Exit();
}

if (vpad_data.btn_trigger & BUTTON_A)
{
     if(Game==1 && menu==1)
    {
        {
            fillScreen(0,0,0,0);
            DisplayResultat(nombreentre,nombremystere,menu,Game,compteur);
            flipBuffers();
        }
    }
}



if (vpad_data.btn_trigger & BUTTON_HOME)
        {
            _Exit();
        }

if(vpad_data.btn_trigger & BUTTON_LEFT)
{
    if (Game==1 && menu==1)
        {
                if (Nline<6)
                {
                    Nline++;
                }
                else
                {
                    Nline=0;
                }
        }

}

if(vpad_data.btn_trigger & BUTTON_RIGHT)
{
    if(Game==1 && menu==1)
        {
                if (Nline>0)
                {
                    Nline--;
                }
                else
                {
                    Nline=6;
                }
            }
}

if(vpad_data.btn_trigger & BUTTON_DOWN)
{
    if(Game==1 && menu==1)
    {choicenumber--;
        if (unite<0 && choicenumber==0)
             {
                 unite = 9 ;
             }
             if (dizaine<0 && choicenumber == 1)
             {
                 dizaine = 90 ;
             }
             if (centaine<0 && choicenumber == 2)
             {
                 centaine = 900 ;
             }
             if (mille<0 && choicenumber == 3)
             {
                 mille = 9000 ;
             }
             if (dix_mille<0 && choicenumber == 4)
             {
                 dix_mille = 90000 ;
             }
            if(choicenumber==0)
                    {
                    unite--;
                    }
            if (choicenumber == 1)
                    {
                    dizaine - 10;
                    }
            if (choicenumber == 2)
                    {
                    centaine - 100;
                    }
            if(choicenumber == 3)
                    {
                    mille - 1000;
                    }
            if(choicenumber == 4)
                    {
                dix_mille - 10000;
                    }
    }
}
    if(vpad_data.btn_trigger & BUTTON_UP)
         {
         if(Game==1 && menu==1)
         {choicenumber++;
                 if (unite>9 && choicenumber==0)
             {
                 unite = 0 ;
             }
             if (dizaine>90 && choicenumber == 1)
             {
                 dizaine = 0 ;
             }
             if (centaine>900 && choicenumber == 2)
             {
                 centaine = 0 ;
             }
             if (mille>9000 && choicenumber == 3)
             {
                 mille = 0 ;
             }
             if (dix_mille>90000 && choicenumber == 4)
             {
                 dix_mille = 0 ;
             }
            if(choicenumber==0)
                    {
                    unite + 1;
                    }
            if (choicenumber == 1)
                    {
                    dizaine + 10;
                    }
            if (choicenumber == 2)
                    {
                    centaine + 100;
                    }
            if(choicenumber == 3)
                    {
                    mille + 1000;
                    }
            if(choicenumber == 4)
                    {
                    dix_mille + 10000;
                    }
         }

}


if(vpad_data.btn_trigger & BUTTON_X)
{
    if(Game==2 && menu==2)
         {
            _Exit();
        }
}

if(vpad_data.btn_trigger & BUTTON_B)
{
    if(Game==1 && menu==1)
    {
        menu=1;
        Game=1;
    }
    _Exit();
}

    //if button Y is push//
    if(vpad_data.btn_trigger & BUTTON_Y)

        {
            _getIN();
        }

    }
_clearscreen();
}
void DisplayMenu(int Mline)
{
    char Name[255];
    char Thanks1[255];
    char Thanks2[255];
    char homebrew[255];
    char Wait[255];

    __os_snprintf(Name,255,    "                      MysteriU   **V0.1**");
    __os_snprintf(homebrew,255,"                Homebrew made by RYUUTSEKU85");
    __os_snprintf(Wait,255, "                       Loading, please wait");
    __os_snprintf(Thanks1,255, "Special thanks to : ");
    __os_snprintf(Thanks2,255, "MELLMA,PWSINCD,BLACKSPOON,DATALOGER,CYAN,BRIENJ");
    drawString(0,0,Name);
    drawString(0,1,homebrew);
    drawString(0,5,Wait);
    drawString(1,14,Thanks1);
    drawString(1,15,Thanks2);

}

void DisplayGame(int Nline ,int mini, int maxi, int nombremystere , int nombreentree , int unite , int dizaine , int centaine , int mille , int dix_mille , int choicenumber)
{

    char printfarrow0[10];
    char printfarrow1[10];
    char printfarrow2[10];
    char printfarrow3[10];
    char printfarrow4[10];
    char printfunite[1];
    char printfdizaine[1];
    char printfcentaine[1];
    char printfmille[1];
    char printfdix_mille[1];
    char buffer[10000];
    char Remenber[30];
    char POM[30];
    char LOR[30];
    char test[100];


        __os_snprintf(test,100,"verification nombre mystere : %d",nombremystere);
        __os_snprintf(POM,30,"Press up or down to modify a number");
        __os_snprintf(LOR,30,"Press left or right to move the cursor");
        __os_snprintf(printfunite,    1,"    %d",unite);
        __os_snprintf(printfdizaine,  1,"   %d",dizaine);
        __os_snprintf(printfcentaine, 1,"  %d",centaine);
        __os_snprintf(printfmille,    1," %d",mille);
        __os_snprintf(printfdix_mille,1,"%d",dix_mille);
        __os_snprintf(buffer,10000,"you selected the number %d, Press + to validate.",nombreentree);
        __os_snprintf(Remenber,30,"don't forget: the mysterious number is between %d and %d ",mini,maxi);

        drawString(0,4,test);
        drawString(0,5,POM);
        drawString(0,7,LOR);
        drawString(0,Nline,printfunite);
        drawString(0,Nline,printfdizaine);
        drawString(0,Nline,printfcentaine);
        drawString(0,Nline,printfmille);
        drawString(0,Nline,printfdix_mille);

        drawString(0,10,buffer);
        drawString(0,20,Remenber);

        nombreentree=dix_mille+mille+centaine+dizaine+unite;

        if(choicenumber==0)//unite//
        {
            __os_snprintf(printfarrow0,   30,"    ^");
            drawString(0,6,printfarrow0);

        }
        if (choicenumber == 1)//dizaine//
        {
            __os_snprintf(printfarrow1,   30,"   ^");
            drawString(0,6,printfarrow1);

        }
        if(choicenumber == 2)//centaine//
        {
            __os_snprintf(printfarrow2,   30,"  ^");
            drawString(0,6,printfarrow2);

        }

        if(choicenumber == 3)//mille//
        {
            __os_snprintf(printfarrow3,   30," ^");
            drawString(0,6,printfarrow3);

        }
        if (choicenumber== 4)//dix_mille//
        {
            __os_snprintf(printfarrow4,   30,"^");
            drawString(0,6,printfarrow4);
        }



}


void DisplayWinner(int nombreentre , int nombremystere , int Game , int compteur, int menu)
{
    if(nombreentre==nombremystere)
    {
        char winner[100];


        __os_snprintf(winner,100,"congrats you win ! in %d tries \n Do you want to play again?\n Y for YES and X for NO",compteur );
        drawString(0,10,winner);
    }

}


void DisplayResultat(int nombreentre ,int nombremystere, int Menu , int Game , int compteur)
{
    if (nombreentre<nombremystere)
          drawString(0,10,"it's more.   press B to answer again");
    if (nombreentre>nombremystere)
         drawString(0,10,"it's less.   press B to answer again");
    if (nombreentre==nombremystere)
    {
        DisplayWinner(nombreentre,nombremystere,Game,compteur,Menu);
    }


}

void _printstr(char *str)
{
    int ii = 0;
    for (ii; ii < 2; ii++)
    {
        fillScreen(0,0,0,0);
        drawString(0,0,str);
        flipBuffers();
    }
}

void _doExit()
{
    void(*_Exit)();
    uint32_t coreinit_handle;
    OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit);
    _Exit();
}

unsigned int rand (int min,int max)
{
    unsigned int randgen_handle;
    unsigned int (*NSSGetRandom)(int min, int max);//create pointeur to nssgetrandom//

    OSDynLoad_Acquire("randgen.rpl", &randgen_handle);//get a handle on randgen.rpl//
    OSDynLoad_FindExport(randgen_handle, 0, "NSSGetRandom", &NSSGetRandom);// get nssgetrandom from wiiu browser//

    return NSSGetRandom(min,max);
}

so ? , what i don't do correctly ? maybe @brienj can help me with it cause i take exemple on his liteNESU menu.
 
  • Like
Reactions: Masterwin

Blackspoon

Active Member
Newcomer
Joined
Feb 19, 2016
Messages
31
Trophies
0
Age
31
Location
next to the blackfork
XP
152
Country
Gambia, The
The randgen.rpl isnt a real lib provided by the os. I think this cause the freeze.

And the default implemented rand function, provided by cstdlib, will freeze the wiiu if you executing it from the userspace. I dunno if it works correctly with kexploit and a clean startup environment.

@Kakkoii has post a nice libary to get random numbers.
https://gbatemp.net/threads/wiiu-homebrew-development.391050/page-11#post-6160401

Alternative you can write a pseudo random function.
 
Last edited by Blackspoon,

ajd4096

Well-Known Member
Member
Joined
Feb 17, 2009
Messages
179
Trophies
1
XP
562
Country
Last edited by ajd4096,
  • Like
Reactions: Blackspoon

MrRean

WiiU Helper / Hacker
Member
Joined
Jan 21, 2013
Messages
422
Trophies
0
Age
26
XP
1,597
Country
United States
You can just call _Exit() as-is, because it's address is hardcoded into the coreinit.h file in libwiiu/src, so you don't have to void it to declare it.

Same with OSFatal(). Also, why print()? You could try some of the OSScreen functions, or just use OSFatal()

not bad for a first program though :}
 
Last edited by MrRean,
  • Like
Reactions: ryuutseku85

vgmoose

Well-Known Member
Member
Joined
Jan 31, 2016
Messages
363
Trophies
1
Website
github.com
XP
3,241
Country
United States
A bit of self promotion, but I have a lot of examples you might want to see in Space Game.

For pseudo-random numbers, I use this function, which you can invoke by passing the pointer to an integer (a seed) like this. To initialize the seed, you can base it off the time.

Another great resource is Eliboa's Snake. Cool stuff so far :)
 
Last edited by vgmoose,
  • Like
Reactions: ryuutseku85

ryuutseku85

Well-Known Member
OP
Member
Joined
Dec 14, 2015
Messages
112
Trophies
0
Age
39
XP
432
Country
France
Thanks Mr rean , but come tell me it again when I will release it lol .
Vgmoose , each time I ask me something I take a look at two homebrew that ( I think ) are the most teachfull , they are lite NESU and ... Space game lol .

For snake , I find it hard to understand with the use a structure and the name that don't evoke something like for example the s* for snack .

Yours explain me how the vpad_data function work and how to use it .

For the random generator I think I may have find a different way that I will explore .

Thanks a lot for your support , until brienj or anyone else explain me the menu I will do it the old way lol .

When I will finish this , I think I gonna make a big tuto for the noob's one , so I can help them the wway some of you help me :)
 

brienj

Trying to avoid getting cancer
Member
Joined
Jan 3, 2016
Messages
1,232
Trophies
0
Website
twitter.com
XP
2,142
Country
United States
Thanks Mr rean , but come tell me it again when I will release it lol .
Vgmoose , each time I ask me something I take a look at two homebrew that ( I think ) are the most teachfull , they are lite NESU and ... Space game lol .

For snake , I find it hard to understand with the use a structure and the name that don't evoke something like for example the s* for snack .

Yours explain me how the vpad_data function work and how to use it .

For the random generator I think I may have find a different way that I will explore .

Thanks a lot for your support , until brienj or anyone else explain me the menu I will do it the old way lol .

When I will finish this , I think I gonna make a big tuto for the noob's one , so I can help them the wway some of you help me :)
The menu I used, uses arrows for the selection part. By changing the menuLine value, it makes the arrows get drawn on a different line. You need to make sure that you are including a header that defines the DrawString function you are using. Without seeing all of your source code, it is hard to determine exactly where any problem may lie.

Like I told you on the other forums, you could use the TinyMT library, it is what I started using in AstUroids not long after starting that project. It works perfectly on the Wii U, or if you want one simple function, use the random number generator that vgmoose uses in his Space Game.
 
Last edited by brienj,
  • Like
Reactions: ryuutseku85

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • DragonMals @ DragonMals:
    he's
  • Faust03 @ Faust03:
    twitter is a very toxic website
  • K3Nv2 @ K3Nv2:
    Nuh uh
  • DragonMals @ DragonMals:
    An underrated opinion: While Bluesky as a platform is better than Twitter, Bluesky's userbase won't be better than Twitter as people are saying because everyone from the non-bootleg site are moving to the bootleg one expecting for themselves to change with their attitude, but that never works like that.
  • DragonMals @ DragonMals:
    I will say though: Bluesky as a micro-blogging site? Needs a bit more oomph and I would officially like it better than Twiter. Can't even post gifs on that site, like what the fuck?
  • K3Nv2 @ K3Nv2:
    Diarrhea is toxic
  • BigOnYa @ BigOnYa:
    Can you post milfs though?
  • K3Nv2 @ K3Nv2:
    Gilfs
    +3
  • BigOnYa @ BigOnYa:
    Kilfs. (Ken knows)
  • K3Nv2 @ K3Nv2:
    Gay
    +1
  • NinStar @ NinStar:
    fake and gay
    +1
  • K3Nv2 @ K3Nv2:
    Fake news is hot
  • realtimesave @ realtimesave:
    hey guyz
    +2
  • SylverReZ @ SylverReZ:
    @realtimesave, I'm here. Why?
  • SylverReZ @ SylverReZ:
    Have you found anywhere else to sell your Switch OLED?
  • SylverReZ @ SylverReZ:
    Ello :)
    +1
  • Xdqwerty @ Xdqwerty:
    @DragonMals, Yeah one is gonna have the same attitude in any site no matter what
  • Xdqwerty @ Xdqwerty:
    @SylverReZ, how are you?
  • SylverReZ @ SylverReZ:
    I'm okay.
    +1
  • BigOnYa @ BigOnYa:
    I'll buy it, full price, meet me in the dark alley behind that closed blockbuster.
  • K3Nv2 @ K3Nv2:
    You'll get the money and he'll say keep the switch
    K3Nv2 @ K3Nv2: You'll get the money and he'll say keep the switch