static unsigned char GetModsDirNames(GtkListStore *list) { char *homedir; char pdir[BMAX_PATH]; unsigned char iternumb = 0; CACHE1D_FIND_REC *dirs = NULL; GtkTreeIter iter; pathsearchmode = 1; if ((homedir = Bgethomedir())) { Bsnprintf(pdir, sizeof(pdir), "%s/" ".eduke32", homedir); dirs = klistpath(pdir, "*", CACHE1D_FIND_DIR); for (dirs=dirs; dirs != NULL; dirs=dirs->next) { if ((Bstrcmp(dirs->name, "autoload") == 0) || (Bstrcmp(dirs->name, "..") == 0) || (Bstrcmp(dirs->name, ".") == 0)) continue; else { gtk_list_store_append(list, &iter); gtk_list_store_set(list, &iter, 0,dirs->name, -1); iternumb++; } } } klistfree(dirs); dirs = NULL; return iternumb; }
void CONFIG_WriteSettings(void) // save binds and aliases to <cfgname>_settings.cfg { int32_t i; BFILE *fp; char *ptr = Xstrdup(setupfilename); char tempbuf[128]; if (!Bstrcmp(setupfilename, SETUPFILENAME)) Bsprintf(tempbuf, "settings.cfg"); else Bsprintf(tempbuf, "%s_settings.cfg", strtok(ptr, ".")); fp = Bfopen(tempbuf, "wt"); if (fp) { Bfprintf(fp,"// this file is automatically generated by EDuke32\n"); Bfprintf(fp,"// these settings take precedence over your main cfg file\n"); Bfprintf(fp,"// do not modify if you lack common sense\n"); Bfprintf(fp,"unbindall\n"); for (i=0; i<MAXBOUNDKEYS; i++) if (CONTROL_KeyIsBound(i)) Bfprintf(fp,"bind \"%s\"%s \"%s\"\n",CONTROL_KeyBinds[i].key, CONTROL_KeyBinds[i].repeat?"":" norepeat",CONTROL_KeyBinds[i].cmdstr); for (i=0; i<MAXMOUSEBUTTONS; i++) if (CONTROL_MouseIsBound(i)) Bfprintf(fp,"bind \"%s\"%s \"%s\"\n",CONTROL_MouseBinds[i].key, CONTROL_MouseBinds[i].repeat?"":" norepeat",CONTROL_MouseBinds[i].cmdstr); OSD_WriteAliases(fp); if (g_crosshairSum && g_crosshairSum != DefaultCrosshairColors.r+(DefaultCrosshairColors.g<<1)+(DefaultCrosshairColors.b<<2)) Bfprintf(fp, "crosshaircolor %d %d %d\n", CrosshairColors.r, CrosshairColors.g, CrosshairColors.b); OSD_WriteCvars(fp); Bfclose(fp); if (!Bstrcmp(setupfilename, SETUPFILENAME)) OSD_Printf("Wrote settings.cfg\n"); else OSD_Printf("Wrote %s_settings.cfg\n",ptr); Bfree(ptr); return; } if (!Bstrcmp(setupfilename, SETUPFILENAME)) OSD_Printf("Error writing settings.cfg: %s\n", strerror(errno)); else OSD_Printf("Error writing %s_settings.cfg: %s\n",ptr,strerror(errno)); Bfree(ptr); }
static void ProcessGroups(CACHE1D_FIND_REC *srch) { CACHE1D_FIND_REC *sidx; struct grpcache *fg, *fgg; char *fn; struct Bstat st; #define BUFFER_SIZE (1024 * 1024 * 8) uint8_t *buf = (uint8_t *)Xmalloc(BUFFER_SIZE); for (sidx = srch; sidx; sidx = sidx->next) { for (fg = grpcache; fg; fg = fg->next) { if (!Bstrcmp(fg->name, sidx->name)) break; } if (fg) { if (findfrompath(sidx->name, &fn)) continue; // failed to resolve the filename if (Bstat(fn, &st)) { Bfree(fn); continue; } // failed to stat the file Bfree(fn); if (fg->size == (int32_t)st.st_size && fg->mtime == (int32_t)st.st_mtime) { grpinfo_t const * const grptype = FindGrpInfo(fg->crcval, fg->size); if (grptype) { grpfile_t * const grp = (grpfile_t *)Xcalloc(1, sizeof(grpfile_t)); grp->filename = Xstrdup(sidx->name); grp->type = grptype; grp->next = foundgrps; foundgrps = grp; } fgg = (struct grpcache *)Xcalloc(1, sizeof(struct grpcache)); strcpy(fgg->name, fg->name); fgg->size = fg->size; fgg->mtime = fg->mtime; fgg->crcval = fg->crcval; fgg->next = usedgrpcache; usedgrpcache = fgg; continue; } } { int32_t b, fh; int32_t crcval = 0; fh = openfrompath(sidx->name, BO_RDONLY|BO_BINARY, BS_IREAD); if (fh < 0) continue; if (Bfstat(fh, &st)) continue; initprintf(" Checksumming %s...", sidx->name); do { b = read(fh, buf, BUFFER_SIZE); if (b > 0) crcval = Bcrc32((uint8_t *)buf, b, crcval); } while (b == BUFFER_SIZE); close(fh); initprintf(" Done\n"); grpinfo_t const * const grptype = FindGrpInfo(crcval, st.st_size); if (grptype) { grpfile_t * const grp = (grpfile_t *)Xcalloc(1, sizeof(grpfile_t)); grp->filename = Xstrdup(sidx->name); grp->type = grptype; grp->next = foundgrps; foundgrps = grp; } fgg = (struct grpcache *)Xcalloc(1, sizeof(struct grpcache)); Bstrncpy(fgg->name, sidx->name, BMAX_PATH); fgg->size = st.st_size; fgg->mtime = st.st_mtime; fgg->crcval = crcval; fgg->next = usedgrpcache; usedgrpcache = fgg; } } Bfree(buf); }
static int osdcmd_spawn(const osdfuncparm_t *parm) { long x=0,y=0,z=0; unsigned short cstat=0,picnum=0; unsigned char pal=0; short ang=0; short set=0, idx; if (numplayers > 1 || !(ps[myconnectindex].gm & MODE_GAME)) { OSD_Printf("spawn: Can't spawn sprites in multiplayer games or demos\n"); return OSDCMD_OK; } switch (parm->numparms) { case 7: // x,y,z x = Batol(parm->parms[4]); y = Batol(parm->parms[5]); z = Batol(parm->parms[6]); set |= 8; case 4: // ang ang = Batol(parm->parms[3]) & 2047; set |= 4; case 3: // cstat cstat = (unsigned short)Batol(parm->parms[2]); set |= 2; case 2: // pal pal = (unsigned char)Batol(parm->parms[1]); set |= 1; case 1: // tile number if (isdigit(parm->parms[0][0])) { picnum = (unsigned short)Batol(parm->parms[0]); } else { int i,j; for (j=0; j<2; j++) { for (i=0; i<labelcnt; i++) { if ( (j == 0 && !Bstrcmp(label+(i<<6), parm->parms[0])) || (j == 1 && !Bstrcasecmp(label+(i<<6), parm->parms[0])) ) { picnum = (unsigned short)labelcode[i]; break; } } if (i<labelcnt) break; } if (i==labelcnt) { OSD_Printf("spawn: Invalid tile label given\n"); return OSDCMD_OK; } } if (picnum >= MAXTILES) { OSD_Printf("spawn: Invalid tile number\n"); return OSDCMD_OK; } break; default: return OSDCMD_SHOWHELP; } idx = spawn(ps[myconnectindex].i, (short)picnum); if (set & 1) sprite[idx].pal = (char)pal; if (set & 2) sprite[idx].cstat = (short)cstat; if (set & 4) sprite[idx].ang = ang; if (set & 8) { if (setsprite(idx, x,y,z) < 0) { OSD_Printf("spawn: Sprite can't be spawned into null space\n"); deletesprite(idx); } } return OSDCMD_OK; }
static void PopulateForm(unsigned char pgs) { if ((pgs == ALL) || (pgs == POPULATE_VIDEO)) { int32_t mode3d, i; GtkListStore *modes3d; GtkTreeIter iter; char buf[64]; mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, settings.bpp3d, settings.fullscreen, 1); if (mode3d < 0) { int32_t i, cd[] = { 32, 24, 16, 15, 8, 0 }; for (i=0; cd[i];) { if (cd[i] >= settings.bpp3d) i++; else break; } for (; cd[i]; i++) { mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, cd[i], settings.fullscreen, 1); if (mode3d < 0) continue; settings.bpp3d = cd[i]; break; } } modes3d = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(stwidgets.vmode3dcombo))); gtk_list_store_clear(modes3d); for (i=0; i<validmodecnt; i++) { if (validmode[i].fs != settings.fullscreen) continue; // all modes get added to the 3D mode list Bsprintf(buf, "%d x %d %dbpp", validmode[i].xdim, validmode[i].ydim, validmode[i].bpp); gtk_list_store_append(modes3d, &iter); gtk_list_store_set(modes3d, &iter, 0,buf, 1,i, -1); if (i == mode3d) { g_signal_handlers_block_by_func(stwidgets.vmode3dcombo, (gpointer)on_vmode3dcombo_changed, NULL); gtk_combo_box_set_active_iter(GTK_COMBO_BOX(stwidgets.vmode3dcombo), &iter); g_signal_handlers_unblock_by_func(stwidgets.vmode3dcombo, (gpointer)on_vmode3dcombo_changed, NULL); } } } if ((pgs == ALL) || (pgs == POPULATE_CONFIG)) { GtkListStore *devlist, *modsdir; GtkTreeIter iter; GtkTreePath *path; char *value; unsigned char i, r = 0; const char *availabledev[] = { "Keyboard only", "Keyboard and mouse", "Keyboard and joystick", "All supported devices" }; // populate input devices combo devlist = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(stwidgets.inputdevcombo))); gtk_list_store_clear(devlist); for (i=0; i<(int32_t)G_N_ELEMENTS(availabledev); i++) { gtk_list_store_append(devlist, &iter); gtk_list_store_set(devlist, &iter, 0,availabledev[i], -1); } switch (settings.usemouse) { case 0: if (settings.usejoy) gtk_combo_box_set_active(GTK_COMBO_BOX(stwidgets.inputdevcombo), INPUT_JOYSTICK); else gtk_combo_box_set_active(GTK_COMBO_BOX(stwidgets.inputdevcombo), INPUT_KB); break; case 1: if (settings.usejoy) gtk_combo_box_set_active(GTK_COMBO_BOX(stwidgets.inputdevcombo), INPUT_ALL); else gtk_combo_box_set_active(GTK_COMBO_BOX(stwidgets.inputdevcombo), INPUT_MOUSE); break; } // populate custom mod combo modsdir = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(stwidgets.custommodcombo))); gtk_list_store_clear(modsdir); gtk_list_store_append(modsdir, &iter); gtk_list_store_set(modsdir, &iter, 0,"None", -1); r = GetModsDirNames(modsdir); for (i=0; i<=r; i++) { path = gtk_tree_path_new_from_indices(i, -1); gtk_tree_model_get_iter(GTK_TREE_MODEL(modsdir), &iter, path); gtk_tree_model_get(GTK_TREE_MODEL(modsdir), &iter, 0,&value, -1); if (Bstrcmp(settings.custommoddir, "/") == 0) { gtk_combo_box_set_active(GTK_COMBO_BOX(stwidgets.custommodcombo), NONE); settings.custommoddir = NULL; break; } if (Bstrcmp(settings.custommoddir, value) == 0) { gtk_combo_box_set_active_iter(GTK_COMBO_BOX(stwidgets.custommodcombo), &iter); break; } } // populate check buttons gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stwidgets.fullscreencheck), settings.fullscreen); #ifdef POLYMER gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stwidgets.polymercheck), settings.polymer); #endif gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stwidgets.autoloadcheck), settings.autoload); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stwidgets.alwaysshowcheck), settings.forcesetup); } if ((pgs == ALL) || (pgs == POPULATE_GAME)) { struct grpfile *fg; GtkListStore *list; GtkTreeIter iter; GtkTreeView *gamelist; gamelist = GTK_TREE_VIEW(stwidgets.gamelist); list = GTK_LIST_STORE(gtk_tree_view_get_model(gamelist)); gtk_list_store_clear(list); for (fg = foundgrps; fg; fg=fg->next) { struct grpfile *grp; for (grp = listgrps; grp; grp=grp->next) if (fg->crcval == grp->crcval) break; if (grp == NULL) continue; gtk_list_store_append(list, &iter); gtk_list_store_set(list, &iter, 0, grp->name, 1, fg->name, 2, (gpointer)fg, -1); if (!Bstrcasecmp(fg->name, settings.selectedgrp)) { GtkTreeSelection *sel = gtk_tree_view_get_selection(gamelist); g_signal_handlers_block_by_func(sel, (gpointer)on_gamelist_selection_changed, NULL); gtk_tree_selection_select_iter(sel, &iter); g_signal_handlers_unblock_by_func(sel, (gpointer)on_gamelist_selection_changed, NULL); } } } }
int Bcorrectfilename(char *filename, int removefn) { #ifdef _WIN32 int r, trailslash=0; #endif char path[256]="", fn[64]="", scratch[256], *ptr, *ptr2, ch; char cwd[256], *cwdp = cwd; char *tokarr[64]; int ntok=0, i, j; int grpmode = 0; if (!Bstrncasecmp(filename,"GRP:",4)) { grpmode = 1; for (ptr=filename; *ptr; ptr++) if (*ptr == '\\') *ptr = '/'; } #ifdef _WIN32 if (!grpmode) { // Windows uses backslashes so translate all unix-like forwardslashes for (ptr=filename; *ptr; ptr++) if (*ptr == '/') *ptr = '\\'; if (*(ptr-1) == '\\') trailslash = 1; r = GetFullPathName(filename, 256, path, &ptr); if (r > 256) return -1; if (r == 0) return -1; if (!trailslash && removefn && ptr) *ptr=0; if (trailslash) { if (path[ strlen(path) - 1 ] != '\\') strcat(path, "\\"); } for (ptr=path; *ptr; ptr++) if (*ptr == '\\') *ptr = '/'; strcpy(filename,path); } else { #endif #ifndef _WIN32 if (!grpmode) { Bgetcwd(cwd, 256); Bstrcat(cwd, "/"); } else { #endif cwd[0] = '/'; cwd[1] = 0; #ifndef _WIN32 } #endif ptr2 = filename; if (grpmode) { ptr2 += 3; if (ptr2[1] != '/') *ptr2 = '/'; else ptr2++; } if (removefn) { ptr = Bstrrchr(ptr2, '/'); if (ptr) ptr[1] = 0; else if (!grpmode) ptr2[0] = 0; } // now we have all the bits and pieces, clean it all up scratch[0] = 0; if (ptr2[0] != '/') { // relative path, which means prepend the current dir to the path Bstrcat(scratch, cwdp); } Bstrcat(scratch, ptr2); ptr2 = scratch; while ((ptr = Bstrtoken(ptr2==scratch?scratch:NULL,"/",&ptr2,1)) != NULL) { if (!Bstrcmp(ptr,".")) continue; else if (!Bstrcmp(ptr,"..")) { if (ntok>0) ntok--; } else { tokarr[ntok++] = ptr; } } ptr2 = filename; if (grpmode) { Bstrcpy(filename,"GRP:"); ptr2 += 4; } else filename[0] = 0; *(ptr2++) = '/'; for (i=0; i<ntok; i++) { ptr = tokarr[i]; if (i>0) *(ptr2++) = '/'; while (*ptr) *(ptr2++) = *(ptr++); } if (removefn) if (*(ptr2-1) != '/') *(ptr2++) = '/'; *(ptr2) = 0; #ifdef _WIN32 } #endif return 0; }
int32_t ScanGroups(void) { CACHE1D_FIND_REC *srch, *sidx; struct grpcache *fg, *fgg; struct grpfile *grp; char *fn; struct Bstat st; #define BUFFER_SIZE (1024 * 1024 * 8) uint8_t *buf = (uint8_t *)Bmalloc(BUFFER_SIZE); if (!buf) { initprintf("Error allocating %d byte buffer to scan GRPs!\n", BUFFER_SIZE); return 0; } initprintf("Searching for game data...\n"); LoadGameList(); //LoadGroupsCache(); SB: disabled to match local srch = klistpath("/", "*.grp", CACHE1D_FIND_FILE); for (sidx = srch; sidx; sidx = sidx->next) { for (fg = grpcache; fg; fg = fg->next) { if (!Bstrcmp(fg->name, sidx->name)) break; } if (fg) { if (findfrompath(sidx->name, &fn)) continue; // failed to resolve the filename if (Bstat(fn, &st)) { Bfree(fn); continue; } // failed to stat the file Bfree(fn); if (fg->size == st.st_size && fg->mtime == st.st_mtime) { grp = (struct grpfile *)Bcalloc(1, sizeof(struct grpfile)); grp->name = Bstrdup(sidx->name); grp->crcval = fg->crcval; grp->size = fg->size; grp->next = foundgrps; foundgrps = grp; fgg = (struct grpcache *)Bcalloc(1, sizeof(struct grpcache)); strcpy(fgg->name, fg->name); fgg->size = fg->size; fgg->mtime = fg->mtime; fgg->crcval = fg->crcval; fgg->next = usedgrpcache; usedgrpcache = fgg; continue; } } { int32_t b, fh; int32_t crcval; fh = openfrompath(sidx->name, BO_RDONLY|BO_BINARY, BS_IREAD); if (fh < 0) continue; if (Bfstat(fh, &st)) continue; initprintf(" Checksumming %s...", sidx->name); crc32init((uint32_t *)&crcval); do { b = read(fh, buf, BUFFER_SIZE); if (b > 0) crc32block((uint32_t *)&crcval, (uint8_t *)buf, b); } while (b == BUFFER_SIZE); crc32finish((uint32_t *)&crcval); close(fh); initprintf(" Done\n"); grp = (struct grpfile *)Bcalloc(1, sizeof(struct grpfile)); grp->name = Bstrdup(sidx->name); grp->crcval = crcval; grp->size = st.st_size; grp->next = foundgrps; foundgrps = grp; fgg = (struct grpcache *)Bcalloc(1, sizeof(struct grpcache)); Bstrncpy(fgg->name, sidx->name, BMAX_PATH); fgg->size = st.st_size; fgg->mtime = st.st_mtime; fgg->crcval = crcval; fgg->next = usedgrpcache; usedgrpcache = fgg; } } klistfree(srch); FreeGroupsCache(); for (grp = foundgrps; grp; /*grp=grp->next*/) { struct grpfile *igrp; for (igrp = listgrps; igrp; igrp=igrp->next) if (grp->crcval == igrp->crcval) break; if (igrp == NULL) { grp = grp->next; continue; } if (igrp->dependency) { struct grpfile *depgrp; //initprintf("found grp with dep\n"); for (depgrp = foundgrps; depgrp; depgrp=depgrp->next) if (depgrp->crcval == igrp->dependency) break; if (depgrp == NULL || depgrp->crcval != igrp->dependency) // couldn't find dependency { //initprintf("removing %s\n", grp->name); RemoveGroup(igrp->crcval); grp = foundgrps; continue; } } if (igrp->game && !grp->game) grp->game = igrp->game; grp=grp->next; } if (usedgrpcache) { int32_t i = 0; FILE *fp; fp = fopen(GRPCACHEFILE, "wt"); if (fp) { for (fg = usedgrpcache; fg; fg=fgg) { fgg = fg->next; fprintf(fp, "\"%s\" %d %d %d\n", fg->name, fg->size, fg->mtime, fg->crcval); Bfree(fg); i++; } fclose(fp); } // initprintf("Found %d recognized GRP %s.\n",i,i>1?"files":"file"); Bfree(buf); return 0; } initprintf("Found no recognized game data!\n"); Bfree(buf); return 0; }
void baselayer_setupopengl() { char *p,*p2,*p3; static int warnonce = 0; int i; bglEnable(GL_TEXTURE_2D); bglShadeModel(GL_SMOOTH); //GL_FLAT bglClearColor(0,0,0,0.5); //Black Background bglHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); //Use FASTEST for ortho! bglHint(GL_LINE_SMOOTH_HINT,GL_NICEST); bglDisable(GL_DITHER); glinfo.vendor = bglGetString(GL_VENDOR); glinfo.renderer = bglGetString(GL_RENDERER); glinfo.version = bglGetString(GL_VERSION); glinfo.extensions = bglGetString(GL_EXTENSIONS); glinfo.maxanisotropy = 1.0; glinfo.bgra = 0; glinfo.texcompr = 0; // process the extensions string and flag stuff we recognize p = strdup(glinfo.extensions); p3 = p; while ((p2 = Bstrtoken(p3 == p ? p : NULL, " ", (char **) &p3, 1)) != NULL) { if (!Bstrcmp(p2, "GL_EXT_texture_filter_anisotropic")) { // supports anisotropy. get the maximum anisotropy level bglGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &glinfo.maxanisotropy); } else if (!Bstrcmp(p2, "GL_EXT_texture_edge_clamp") || !Bstrcmp(p2, "GL_SGIS_texture_edge_clamp")) { // supports GL_CLAMP_TO_EDGE or GL_CLAMP_TO_EDGE_SGIS glinfo.clamptoedge = 1; } else if (!Bstrcmp(p2, "GL_EXT_bgra")) { // support bgra textures glinfo.bgra = 1; } else if (!Bstrcmp(p2, "GL_ARB_texture_compression")) { // support texture compression glinfo.texcompr = 1; } else if (!Bstrcmp(p2, "GL_ARB_texture_non_power_of_two")) { // support non-power-of-two texture sizes glinfo.texnpot = 1; } else if (!Bstrcmp(p2, "WGL_3DFX_gamma_control")) { // 3dfx cards have issues with fog glinfo.hack_nofog = 1; if (!(warnonce&1)) initprintf("3dfx card detected: OpenGL fog disabled\n"); warnonce |= 1; } else if (!Bstrcmp(p2, "GL_ARB_multisample")) { // supports multisampling glinfo.multisample = 1; } else if (!Bstrcmp(p2, "GL_NV_multisample_filter_hint")) { // supports nvidia's multisample hint extension glinfo.nvmultisamplehint = 1; } else if (!strcmp(p2, "GL_ARB_multitexture")) { glinfo.multitex = 1; } else if (!strcmp(p2, "GL_ARB_texture_env_combine")) { glinfo.envcombine = 1; } } free(p); }