Exemplo n.º 1
0
int autoBootFix(int index) {

    int delay = config->autobootfix;
    while (aptMainLoop() && delay > 0) {
        gfxSwap();
        delay--;
    }
    return load(config->entries[index].path,
                config->entries[index].offset);
}
Exemplo n.º 2
0
void debug(const char *fmt, ...) {
    char s[512];
    memset(s, 0, 512);
    va_list args;
    va_start(args, fmt);
    vsprintf(s, fmt, args);
    va_end(args);

    while (aptMainLoop()) {
        hidScanInput();
        if (hidKeysDown())
            break;

        drawBg();
        gfxDrawText(GFX_TOP, GFX_LEFT, &fontDefault, s, MENU_MIN_X + 16, MENU_MIN_Y + 16);
        gfxDrawText(GFX_TOP, GFX_LEFT, &fontDefault, "Press any key to continue...", MENU_MIN_X + 16, MENU_MIN_Y + 64);
        gfxSwap();
    }
}
Exemplo n.º 3
0
bool confirm(int confirmButton, const char *fmt, ...) {
    char s[512];
    memset(s, 0, 512);
    va_list args;
    va_start(args, fmt);
    vsprintf(s, fmt, args);
    va_end(args);

    while (aptMainLoop()) {
        hidScanInput();
        u32 key = hidKeysDown();
        if (key & BIT(confirmButton)) {
            return true;
        } else if (key) {
            return false;
        }

        drawBg();
        gfxDrawText(GFX_TOP, GFX_LEFT, &fontDefault, s, MENU_MIN_X + 16, MENU_MIN_Y + 16);
        gfxDrawText(GFX_TOP, GFX_LEFT, &fontDefault, "Press any key to cancel...", MENU_MIN_X + 16, MENU_MIN_Y + 64);
        gfxDrawTextf(GFX_TOP, GFX_LEFT, &fontDefault, MENU_MIN_X + 16, MENU_MIN_Y + 84, "Press (%s) to confirm...", get_button(confirmButton));
        gfxSwap();
    }
}
int menu_netloaderarm9(void) {

    s32 sockfd;
    struct sockaddr_in sa;
    s32 clientfd;
    struct sockaddr_in client_addr;
    s32 addrlen = sizeof(client_addr);
    s32 sflags = 0;

    if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
        debug("Err: socket");
        return -1;
    }

    bzero(&sa, sizeof(sa));
    sa.sin_family = AF_INET;
    sa.sin_port = htons(BRAHMA_NETWORK_PORT);
    sa.sin_addr.s_addr = gethostid();

    if (bind(sockfd, (struct sockaddr *) &sa, sizeof(sa)) != 0) {
        debug("Err: bind");
        close(sockfd);
        return -1;
    }

    if (listen(sockfd, 1) != 0) {
        debug("Err: listen()");
        close(sockfd);
        return -1;
    }

    char msg[256];
    sprintf(msg,
            "NetLoader Active - waiting for arm9\n\n"
                    "IP: %s, Port: %d\n\nPress B to cancel\n",
            inet_ntoa(sa.sin_addr), BRAHMA_NETWORK_PORT);
    drawBg();
    gfxDrawTextf(GFX_TOP, GFX_LEFT, &fontDefault, MENU_MIN_X + 16, MENU_MIN_Y + 16, msg);
    gfxSwap();

    sflags = fcntl(sockfd, F_GETFL);
    if (sflags == -1) {
        debug("Err: fcntl() (1)\n");
        close(sockfd);
    }
    fcntl(sockfd, F_SETFL, sflags | O_NONBLOCK);

    while (aptMainLoop()) {

        hidScanInput();
        if (hidKeysDown() & KEY_B) {
            close(sockfd);
            return -1;
        }

        clientfd = accept(sockfd, (struct sockaddr *) &client_addr, &addrlen);
        svcSleepThread(100000000);
        if (clientfd > 0)
            break;
    }

    s32 recvd;
    u32 total = 0;
    u8 *arm9_buf = memalign(0x1000, ARM9_PAYLOAD_MAX_SIZE);

    while ((recvd = recv(clientfd, arm9_buf + total,
                         ARM9_PAYLOAD_MAX_SIZE - total, 0)) != 0) {
        if (recvd != -1) {
            total += recvd;
            drawBg();
            gfxDrawTextf(GFX_TOP, GFX_LEFT, &fontDefault, MENU_MIN_X + 16, MENU_MIN_Y + 16, "%i", total);
            gfxSwap();
        }
        if (total >= ARM9_PAYLOAD_MAX_SIZE) {
            debug("Err: invalid payload size\n");
            close(clientfd);
            close(sockfd);
            free(arm9_buf);
            return -1;
        }
    }

    fcntl(sockfd, F_SETFL, sflags & ~O_NONBLOCK);
    close(clientfd);
    close(sockfd);

    gfxExit();

    brahma_init();
    if (load_arm9_payload_from_mem(arm9_buf, total) != 1) {
        debug("Err: Couldn't load arm9 payload...\n");
        return -1;
    }
    firm_reboot();
    brahma_exit();
}
Exemplo n.º 5
0
int menu_more() {

    int i = 0;
    menu_index = 0;

    while (aptMainLoop()) {

        hidScanInput();
        u32 kDown = hidKeysDown();

        if (kDown & KEY_DOWN) {
            menu_index++;
            if (menu_index >= menu_count)
                menu_index = 0;
        }

        if (kDown & KEY_UP) {
            menu_index--;
            if (menu_index < 0)
                menu_index = menu_count - 1;
        }

        if (kDown & KEY_A) {
            if (menu_index == 0 && menu_choose() == 0) {
                return 0;
            } else if (menu_index == 1 && menu_netloader() == 0) {
                return 0;
            } else if (menu_index == 2) {
                menu_config();
            } else if (menu_index == 3) {
                reboot();
            } else if (menu_index == 4) {
                poweroff();
            }
        }

        if (kDown & KEY_B) {
            return -1;
        }

        drawBg();
        drawTitle("*** Select an option ***");

        for (i = 0; i < menu_count; i++) {
            drawItem(i == menu_index, 16 * i, menu_item[i]);
        }

        // draw "help"
        switch (menu_index) {
            case 0:
                drawInfo("Browse for a file to boot or add a boot entry");
                break;
            case 1:
                drawInfo("Netload a file (3dsx) from the computer with 3dslink");
                break;
            case 2:
                drawInfo("Edit boot settings");
                break;
            case 3:
                drawInfo("Reboot the 3ds...");
                break;
            case 4:
                drawInfo("Shutdown the 3ds...");
                break;
            default:
                break;
        }

        gfxSwap();
    }
    return -1;
}
Exemplo n.º 6
0
void pick_file(file_s *picked, const char *path) {

    picker = malloc(sizeof(picker_s));
    get_dir(path);

    // key repeat timer
    static time_t t_start = 0, t_end = 0, t_elapsed = 0;

    while (aptMainLoop()) {

        hidScanInput();
        u32 kHeld = hidKeysHeld();
        u32 kDown = hidKeysDown();

        if (hidKeysUp()) {
            time(&t_start); // reset held timer
        }

        if (kDown & KEY_DOWN) {
            picker->file_index++;
            if (picker->file_index >= picker->file_count)
                picker->file_index = 0;
            time(&t_start);
        } else if (kHeld & KEY_DOWN) {
            time(&t_end);
            t_elapsed = t_end - t_start;
            if (t_elapsed > 0) {
                picker->file_index++;
                if (picker->file_index >= picker->file_count)
                    picker->file_index = 0;
                svcSleep(100);
            }
        }

        if (kDown & KEY_UP) {
            picker->file_index--;
            if (picker->file_index < 0)
                picker->file_index = picker->file_count - 1;
            time(&t_start);
        } else if (kHeld & KEY_UP) {
            time(&t_end);
            t_elapsed = t_end - t_start;
            if (t_elapsed > 0) {
                picker->file_index--;
                if (picker->file_index < 0)
                    picker->file_index = picker->file_count - 1;
                svcSleep(100);
            }
        }

        if (kDown & KEY_A) {
            if (picker->file_count > 0) {
                int index = picker->file_index;
                if (!picker->files[index].isDir) {
                    if (confirm(0, "Launch \"%s\" ?", picker->files[index].name)) {
                        strncpy(picked->name, picker->files[index].name, 512);
                        strncpy(picked->path, picker->files[index].path, 512);
                        picked->isDir = picker->files[index].isDir;
                        picked->size = picker->files[index].size;
                        break;
                    }
                }
                else {
                    get_dir(picker->files[index].path);
                }
            }
        } else if (kDown & KEY_X) {
            int index = picker->file_index;
            if (!picker->files[index].isDir) {
                const char *ext = get_filename_ext(picker->files[index].name);
                if (strcasecmp(ext, "3dsx") == 0) {
                    if (confirm(3, "Add entry to boot menu: \"%s\" ?", picker->files[index].name)) {
                        if (config->count > CONFIG_MAX_ENTRIES - 1) {
                            debug("Maximum entries reached (%i)\n", CONFIG_MAX_ENTRIES);
                        } else if (configAddEntry(picker->files[index].name, picker->files[index].path, 0) == 0) {
                            debug("Added entry: %s\n", picker->files[index].name);
                        } else {
                            debug("Error adding entry: %s\n", picker->files[index].name);
                        }
                    }
                }
            }
        }
        else if (kDown & KEY_B) {
            // exit if we can't go back
            if (strlen(picker->now_path) <= 1)
                break;

            // remove slash if needed
            if (end_with(picker->now_path, '/'))
                picker->now_path[strlen(picker->now_path) - 1] = '\0';

            // build path
            char *slash = strrchr(picker->now_path, '/');
            if (slash == NULL)
                break;
            int len = (int) (slash - picker->now_path);
            picker->now_path[len] = '\0';

            // enter new dir
            get_dir(picker->now_path);
        }

        drawBg();
        drawTitle("*** Select a file ***");

        int i, y = 0;
        int page = picker->file_index / MAX_LINE;
        for (i = page * MAX_LINE; i < page * MAX_LINE + MAX_LINE; i++) {
            if (i >= picker->file_count)
                break;

            drawItemN(i == picker->file_index, 47, 16 * i, picker->files[i].name);
            if (i == picker->file_index && !picker->files[i].isDir) {
                drawInfo("Press (A) to launch\nPress (X) to add to boot menu");

            }
            y++;
        }
        gfxSwap();
    }
    free(picker);
}