component* menu_video_confirm_create(scene *s, settings_video *old_settings) { video_menu_confirm_data *local = malloc(sizeof(video_menu_confirm_data)); memset(local, 0, sizeof(video_menu_confirm_data)); local->video_accept_secs = 20; local->old_video_settings = old_settings; time(&local->video_accept_timer); // Text config text_settings tconf; text_defaults(&tconf); tconf.font = FONT_BIG; tconf.halign = TEXT_CENTER; tconf.cforeground = color_create(0, 121, 0, 255); component* menu = menu_create(11); menu_attach(menu, label_create(&tconf, "ACCEPT RESOLUTION?")); menu_attach(menu, filler_create()); local->timeout_label = label_create(&tconf, ""); menu_attach(menu, local->timeout_label); menu_attach(menu, filler_create()); menu_attach(menu, textbutton_create(&tconf, "OK", COM_ENABLED, video_confirm_ok_clicked, local)); menu_attach(menu, textbutton_create(&tconf, "CANCEL", COM_ENABLED, video_confirm_cancel_clicked, local)); menu_set_userdata(menu, local); menu_set_free_cb(menu, menu_video_confirm_free); menu_set_tick_cb(menu, menu_video_confirm_tick); menu_video_confirm_update(menu); return menu; }
struct _label * elf32_label_address (struct _elf32 * elf32, struct _map * memory, uint64_t address) { Elf32_Shdr * plt_shdr = elf32_shdr_by_name(elf32, ".plt"); uint64_t plt_bottom; uint64_t plt_top; if (plt_shdr == NULL) { plt_bottom = -1; plt_top = -1; } else { plt_bottom = plt_shdr->sh_addr; plt_top = plt_bottom + plt_shdr->sh_size; } // plt functions are a special case, as we try to identify their targets // in the got // address is within the plt if ( (address >= plt_bottom) && (address < plt_top)) { // disassemble instruction uint8_t * data = &(elf32->data[address - elf32_base_address(elf32)]); ud_t ud_obj; ud_init(&ud_obj); ud_set_mode (&ud_obj, 32); ud_set_input_buffer(&ud_obj, data, 0x20); ud_disassemble(&ud_obj); if ( (ud_obj.mnemonic == UD_Ijmp) && (udis86_sign_extend_lval(&(ud_obj.operand[0])) != -1)) { uint64_t target = udis86_sign_extend_lval(&(ud_obj.operand[0])); const char * name = elf32_rel_name_by_address(elf32, target); if (name != NULL) { char plttmp[256]; snprintf(plttmp, 256, "%s@plt", name); struct _label * label; label = label_create(address, plttmp, LABEL_FUNCTION); return label; } } } // look for a symbol const char * name = elf32_sym_name_by_address(elf32, address); // no symbol if ((name == NULL) || (strcmp(name, "") == 0)) { char tmp[128]; snprintf(tmp, 128, "fun_%llx", (unsigned long long) address); name = tmp; } // symbol exists struct _label * label = label_create(address, name, LABEL_FUNCTION); return label; }
component* menu_connect_create(scene *s) { connect_menu_data *local = malloc(sizeof(connect_menu_data)); memset(local, 0, sizeof(connect_menu_data)); local->s = s; // Text config text_settings tconf; text_defaults(&tconf); tconf.font = FONT_BIG; tconf.halign = TEXT_CENTER; tconf.cforeground = color_create(0, 121, 0, 255); component* menu = menu_create(11); menu_attach(menu, label_create(&tconf, "CONNECT TO SERVER")); menu_attach(menu, filler_create()); local->addr_input = textinput_create(&tconf, "Host/IP", settings_get()->net.net_connect_ip); local->connect_button = textbutton_create(&tconf, "CONNECT", COM_ENABLED, menu_connect_start, s); local->cancel_button = textbutton_create(&tconf, "CANCEL", COM_ENABLED, menu_connect_cancel, s); widget_set_id(local->connect_button, NETWORK_CONNECT_IP_BUTTON_ID); menu_attach(menu, local->addr_input); menu_attach(menu, local->connect_button); menu_attach(menu, local->cancel_button); menu_set_userdata(menu, local); menu_set_free_cb(menu, menu_connect_free); menu_set_tick_cb(menu, menu_connect_tick); return menu; }
component* menu_listen_create(scene *s) { listen_menu_data *local = malloc(sizeof(listen_menu_data)); s->gs->role = ROLE_SERVER; local->s = s; // Form address (host) ENetAddress address; address.host = ENET_HOST_ANY; address.port = settings_get()->net.net_listen_port; // Set up host local->host = enet_host_create(&address, 1, 2, 0, 0); if(local->host == NULL) { DEBUG("Failed to initialize ENet server"); free(local); return NULL; } enet_socket_set_option(local->host->socket, ENET_SOCKOPT_REUSEADDR, 1); // Text config text_settings tconf; text_defaults(&tconf); tconf.font = FONT_BIG; tconf.halign = TEXT_CENTER; tconf.cforeground = color_create(0, 121, 0, 255); // Create the menu component* menu = menu_create(11); menu_attach(menu, label_create(&tconf, "START SERVER")); menu_attach(menu, filler_create()); menu_attach(menu, label_create(&tconf, "Waiting ...")); menu_attach(menu, filler_create()); local->cancel_button = textbutton_create(&tconf, "CANCEL", COM_ENABLED, menu_listen_cancel, s); menu_attach(menu, local->cancel_button); menu_set_userdata(menu, local); menu_set_free_cb(menu, menu_listen_free); menu_set_tick_cb(menu, menu_listen_tick); return menu; }
widget_t* calib_screen_create() { calib_screen_t* s = calloc(1, sizeof(calib_screen_t)); s->widget = widget_create(NULL, &calib_widget_class, s, display_rect); widget_set_background(s->widget, BLACK); rect_t rect = { .x = 15, .y = 15, .width = 56, .height = 56, }; s->complete_button = button_create(s->widget, rect, img_left, WHITE, BLACK, complete_calib); widget_hide(s->complete_button); button_set_up_bg_color(s->complete_button, BLACK); button_set_up_icon_color(s->complete_button, WHITE); button_set_down_bg_color(s->complete_button, BLACK); button_set_down_icon_color(s->complete_button, LIGHT_GRAY); button_set_disabled_bg_color(s->complete_button, BLACK); button_set_disabled_icon_color(s->complete_button, DARK_GRAY); rect.x = 320 - 56 - 15; rect.y = 240 - 56 - 15; s->recal_button = button_create(s->widget, rect, img_update, WHITE, BLACK, restart_calib); widget_hide(s->recal_button); button_set_up_bg_color(s->recal_button, BLACK); button_set_up_icon_color(s->recal_button, WHITE); button_set_down_bg_color(s->recal_button, BLACK); button_set_down_icon_color(s->recal_button, LIGHT_GRAY); button_set_disabled_bg_color(s->recal_button, BLACK); button_set_disabled_icon_color(s->recal_button, DARK_GRAY); rect.x = 50; rect.y = 100; rect.width = 175; s->lbl_instructions = label_create(s->widget, rect, "Touch and hold the marker until it turns green", font_opensans_regular_18, WHITE, 3); gui_msg_subscribe(MSG_TOUCH_INPUT, s->widget); return s->widget; } static void calib_widget_destroy(widget_t* w) { calib_screen_t* s = widget_get_instance_data(w); gui_msg_unsubscribe(MSG_TOUCH_INPUT, s->widget); free(s); }
component* menu_audio_create(scene *s) { // Menu userdata audio_menu_data *local = malloc(sizeof(audio_menu_data)); memset(local, 0, sizeof(audio_menu_data)); local->old_audio_settings = settings_get()->sound; // Text config text_settings tconf; text_defaults(&tconf); tconf.font = FONT_BIG; tconf.halign = TEXT_CENTER; tconf.cforeground = color_create(0, 121, 0, 255); // Create menu and its header component* menu = menu_create(11); menu_attach(menu, label_create(&tconf, "AUDIO")); menu_attach(menu, filler_create()); menu_attach(menu, textslider_create_bind(&tconf, "SOUND", 10, 1, menu_audio_sound_slide, NULL, &settings_get()->sound.sound_vol)); menu_attach(menu, textslider_create_bind(&tconf, "MUSIC", 10, 1, menu_audio_music_slide, NULL, &settings_get()->sound.music_vol)); menu_attach(menu, textselector_create_bind_opts(&tconf, "MONO", NULL, NULL, &settings_get()->sound.music_mono, mono_opts, 2)); local->lib_selector = textselector_create(&tconf, "PLAYBACK:", menu_audio_library_toggled, local); module_source *sources = music_get_module_sources(); for(int i = 0; sources[i].name != 0; i++) { textselector_add_option(local->lib_selector, sources[i].name); if(sources[i].id == settings_get()->sound.music_library) { textselector_set_pos(local->lib_selector, i); } } menu_attach(menu, local->lib_selector); local->freq_selector = textselector_create(&tconf, "FREQUENCY:", menu_audio_freq_toggled, local); menu_audio_reset_freqs(local, 1); menu_attach(menu, local->freq_selector); local->resampler_selector = textselector_create(&tconf, "RESAMPLE:", menu_audio_resampler_toggled, local); menu_audio_reset_resamplers(local, 1); menu_attach(menu, local->resampler_selector); menu_attach(menu, textbutton_create(&tconf, "DONE", COM_ENABLED, menu_audio_done, local)); // Userdata & free function for it menu_set_userdata(menu, local); menu_set_free_cb(menu, menu_audio_free); return menu; }
component* menu_gameplay_create(scene *s) { const char* fightmode_opts[] = {"NORMAL","HYPER"}; const char* hazard_opts[] = {"OFF","ON"}; // Text config text_settings tconf; text_defaults(&tconf); tconf.font = FONT_BIG; tconf.halign = TEXT_CENTER; tconf.cforeground = color_create(0, 121, 0, 255); component* menu = menu_create(11); menu_attach(menu, label_create(&tconf, "GAMEPLAY")); menu_attach(menu, filler_create()); menu_attach(menu, textslider_create_bind(&tconf, "SPEED", 10, 1, menu_gameplay_speed_slide, s, &settings_get()->gameplay.speed)); menu_attach(menu, textselector_create_bind_opts(&tconf, "FIGHT MODE", NULL, NULL, &settings_get()->gameplay.fight_mode, fightmode_opts, 2)); menu_attach(menu, textslider_create_bind(&tconf, "POWER 1", 8, 0, NULL, NULL, &settings_get()->gameplay.power1)); menu_attach(menu, textslider_create_bind(&tconf, "POWER 2", 8, 0, NULL, NULL, &settings_get()->gameplay.power2)); menu_attach(menu, textselector_create_bind_opts(&tconf, "HAZARDS", NULL, NULL, &settings_get()->gameplay.hazards_on, hazard_opts, 2)); menu_attach(menu, textselector_create_bind_opts(&tconf, "CPU:", NULL, NULL, &settings_get()->gameplay.difficulty, ai_difficulty_names, NUMBER_OF_AI_DIFFICULTY_TYPES)); menu_attach(menu, textselector_create_bind_opts(&tconf, "", NULL, NULL, &settings_get()->gameplay.rounds, round_type_names, NUMBER_OF_ROUND_TYPES)); menu_attach(menu, textbutton_create(&tconf, "DONE", COM_ENABLED, menu_gameplay_done, NULL)); return menu; }
void textentry_screen_show(textentry_format_t format, text_handler_t text_handler, void* user_data) { int i; textentry_screen_t* screen = calloc(1, sizeof(textentry_screen_t)); screen->text_handler = text_handler; screen->user_data = user_data; switch (format) { case TXT_FMT_IP: screen->btn_layout = btn_layout_numeric; screen->num_rows = NUM_ROWS_NUMERIC; break; default: case TXT_FMT_ANY: screen->btn_layout = btn_layout_all; screen->num_rows = NUM_ROWS_ALL; break; } screen->widget = widget_create(NULL, &textentry_screen_widget_class, screen, display_rect); rect_t rect = { .x = 7, .y = 5, .width = 48, .height = 48, }; widget_t* back_btn = button_create(screen->widget, rect, img_cancel, WHITE, BLACK, back_button_clicked); button_set_up_bg_color(back_btn, BLACK); button_set_up_icon_color(back_btn, WHITE); button_set_down_bg_color(back_btn, BLACK); button_set_down_icon_color(back_btn, LIGHT_GRAY); button_set_disabled_bg_color(back_btn, BLACK); button_set_disabled_icon_color(back_btn, DARK_GRAY); rect.x = 7; rect.y = 65; for (i = 0; i < NUM_VISIBLE_ROWS; ++i) { int j; for (j = 0; j < NUM_BUTTONS_PER_ROW; ++j) { widget_t* b = button_create(screen->widget, rect, img_circle, WHITE, BLACK, char_button_clicked); button_set_font(b, font_opensans_regular_22); button_set_up_bg_color(b, BLACK); button_set_up_icon_color(b, WHITE); button_set_down_bg_color(b, BLACK); button_set_down_icon_color(b, LIGHT_GRAY); button_set_disabled_bg_color(b, BLACK); button_set_disabled_icon_color(b, DARK_GRAY); screen->buttons[i][j] = b; rect.x += 52; } rect.y += 58; rect.x = 7; } rect.x = 268; rect.y = 5; widget_t* b = button_create(screen->widget, rect, img_check, WHITE, BLACK, ok_button_clicked); button_set_up_bg_color(b, BLACK); button_set_up_icon_color(b, WHITE); button_set_down_bg_color(b, BLACK); button_set_down_icon_color(b, LIGHT_GRAY); button_set_disabled_bg_color(b, BLACK); button_set_disabled_icon_color(b, DARK_GRAY); rect.y = 65; b = button_create(screen->widget, rect, img_backspace, WHITE, BLACK, backspace_button_clicked); button_set_up_bg_color(b, BLACK); button_set_up_icon_color(b, WHITE); button_set_down_bg_color(b, BLACK); button_set_down_icon_color(b, LIGHT_GRAY); button_set_disabled_bg_color(b, BLACK); button_set_disabled_icon_color(b, DARK_GRAY); rect.y += 58; b = button_create(screen->widget, rect, img_up, WHITE, BLACK, up_button_clicked); button_set_up_bg_color(b, BLACK); button_set_up_icon_color(b, WHITE); button_set_down_bg_color(b, BLACK); button_set_down_icon_color(b, LIGHT_GRAY); button_set_disabled_bg_color(b, BLACK); button_set_disabled_icon_color(b, DARK_GRAY); rect.y += 58; b = button_create(screen->widget, rect, img_down, WHITE, BLACK, down_button_clicked); button_set_up_bg_color(b, BLACK); button_set_up_icon_color(b, WHITE); button_set_down_bg_color(b, BLACK); button_set_down_icon_color(b, LIGHT_GRAY); button_set_disabled_bg_color(b, BLACK); button_set_disabled_icon_color(b, DARK_GRAY); update_input_buttons(screen); rect.x = 60; rect.y = 8; rect.width = 200; screen->text_label = label_create(screen->widget, rect, "", font_opensans_regular_22, WHITE, 2); widget_set_background(screen->text_label, LIGHT_GRAY); gui_push_screen(screen->widget); } static void update_input_buttons(textentry_screen_t* screen) { int i; for (i = 0; i < NUM_VISIBLE_ROWS; ++i) { btn_row_t* row = &screen->btn_layout[screen->row_idx + i]; int j; for (j = 0; j < NUM_BUTTONS_PER_ROW; ++j) { widget_t* btn = screen->buttons[i][j]; const char* btn_text = (*row)[j]; if (btn_text == NULL) widget_hide(btn); else { if (*btn_text == ' ') button_set_icon(btn, img_space); else button_set_icon(btn, img_circle); button_set_text(btn, btn_text); widget_show(btn); } } } }
component* lab_dash_main_create(scene *s, dashboard_widgets *dw) { component *xy = xysizer_create(); text_settings tconf_dark; text_defaults(&tconf_dark); tconf_dark.font = FONT_SMALL; tconf_dark.cforeground = color_create(0, 200, 0, 255); text_settings tconf_light; text_defaults(&tconf_light); tconf_light.font = FONT_SMALL; tconf_light.cforeground = color_create(50, 240, 50, 255); // Pilot image dw->photo = pilotpic_create(PIC_PLAYERS, 1); xysizer_attach(xy, dw->photo, 12, -1, -1, -1); // Texts dw->name = label_create(&tconf_light, "NO NAME"); dw->rank = label_create(&tconf_dark, "RANK: 0"); dw->wins = label_create(&tconf_dark, "WINS: 0"); dw->losses = label_create(&tconf_dark, "LOSES: 0"); dw->money = label_create(&tconf_dark, "MONEY: $ 0K"); dw->tournament = label_create(&tconf_light, "NO TOURNAMENT"); xysizer_attach(xy, dw->name, 12, 58, 200, 6); xysizer_attach(xy, dw->rank, 18, 64, 200, 6); xysizer_attach(xy, dw->wins, 18, 70, 200, 6); xysizer_attach(xy, dw->losses, 12, 76, 200, 6); xysizer_attach(xy, dw->money, 12, 82, 200, 6); xysizer_attach(xy, dw->tournament, 12, 88, 200, 6); // Bars and texts (bottom left side) xysizer_attach(xy, label_create(&tconf_dark, "POWER"), 12, 95, -1, -1); dw->power = gauge_create(GAUGE_SMALL, 25, 3); xysizer_attach(xy, dw->power, 12, 102, -1, -1); xysizer_attach(xy, label_create(&tconf_dark, "AGILITY"), 12, 106, -1, -1); dw->agility = gauge_create(GAUGE_SMALL, 25, 3); xysizer_attach(xy, dw->agility, 12, 113, -1, -1); xysizer_attach(xy, label_create(&tconf_dark, "ENDURANCE"), 12, 117, -1, -1); dw->endurance = gauge_create(GAUGE_SMALL, 25, 3); xysizer_attach(xy, dw->endurance, 12, 124, -1, -1); // Bars and texts (bottom middle) xysizer_attach(xy, label_create(&tconf_dark, "ARM POWER"), 125, 95, 200, 6); dw->arm_power = gauge_create(GAUGE_BIG, 8, 3); xysizer_attach(xy, dw->arm_power, 125, 102, -1, -1); xysizer_attach(xy, label_create(&tconf_dark, "LEG POWER"), 125, 106, 200, 6); dw->leg_power = gauge_create(GAUGE_BIG, 8, 3); xysizer_attach(xy, dw->leg_power, 125, 113, -1, -1); xysizer_attach(xy, label_create(&tconf_dark, "ARMOR"), 125, 117, 200, 6); dw->armor = gauge_create(GAUGE_BIG, 8, 3); xysizer_attach(xy, dw->armor, 125, 124, -1, -1); // Bars and texts (bottom right side) xysizer_attach(xy, label_create(&tconf_dark, "ARM SPEED"), 228, 95, 200, 6); dw->arm_speed = gauge_create(GAUGE_BIG, 8, 3); xysizer_attach(xy, dw->arm_speed, 228, 102, -1, -1); xysizer_attach(xy, label_create(&tconf_dark, "LEG SPEED"), 228, 106, 200, 6); dw->leg_speed = gauge_create(GAUGE_BIG, 7, 3); xysizer_attach(xy, dw->leg_speed, 228, 113, -1, -1); xysizer_attach(xy, label_create(&tconf_dark, "STUN RES"), 228, 117, 200, 6); dw->stun_resistance = gauge_create(GAUGE_BIG, 7, 3); xysizer_attach(xy, dw->stun_resistance, 228, 124, -1, -1); return xy; }