📄 dehacked.c
字号:
// Emacs style mode select -*- C++ -*- //-----------------------------------------------------------------------------//// $Id: dehacked.c,v 1.11 2001/04/30 17:19:24 stroggonmeth Exp $//// Copyright (C) 1998-2000 by DooM Legacy Team.//// This program is free software; you can redistribute it and/or// modify it under the terms of the GNU General Public License// as published by the Free Software Foundation; either version 2// of the License, or (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.////// $Log: dehacked.c,v $// Revision 1.11 2001/04/30 17:19:24 stroggonmeth// HW fix and misc. changes//// Revision 1.10 2001/02/10 12:27:13 bpereira// no message//// Revision 1.9 2001/01/25 22:15:41 bpereira// added heretic support//// Revision 1.8 2000/11/04 16:23:42 bpereira// no message//// Revision 1.7 2000/11/03 13:15:13 hurdler// Some debug comments, please verify this and change what is needed!//// Revision 1.6 2000/11/02 17:50:06 stroggonmeth// Big 3Dfloors & FraggleScript commit!!//// Revision 1.5 2000/08/31 14:30:55 bpereira// no message//// Revision 1.4 2000/04/16 18:38:07 bpereira// no message//// Revision 1.3 2000/04/05 15:47:46 stroggonmeth// Added hack for Dehacked lumps. Transparent sprites are now affected by colormaps.//// Revision 1.2 2000/02/27 00:42:10 hurdler// fix CR+LF problem//// Revision 1.1.1.1 2000/02/22 20:32:32 hurdler// Initial import into CVS (v1.29 pr3)////// DESCRIPTION:// Load dehacked file and change table and text from the exe////-----------------------------------------------------------------------------#include "doomdef.h"#include "command.h"#include "console.h"#include "g_game.h"#include "sounds.h"#include "info.h"#include "m_cheat.h"#include "d_think.h"#include "dstrings.h"#include "m_argv.h"#include "p_inter.h"//SoM: 4/4/2000: DEHACKED LUMPS#include "z_zone.h"#include "w_wad.h"boolean deh_loaded = false;#define MAXLINELEN 200// the code was first write for a file// converted to use memory with this functionstypedef struct { char *data; char *curpos; int size;} MYFILE;#define myfeof( a ) (a->data+a->size<=a->curpos)char *myfgets(char *buf, int bufsize, MYFILE *f){ int i=0; if( myfeof(f) ) return NULL; // we need on byte for null terminated string bufsize--; while(i<bufsize && !myfeof(f) ) { char c = *f->curpos++; if( c!='\r' ) buf[i++]=c; if( c=='\n' ) break; } buf[i] = '\0'; //CONS_Printf("fgets [0]=%d [1]=%d '%s'\n",buf[0],buf[1],buf); return buf;}size_t myfread( char *buf, size_t size, size_t count, MYFILE *f ){ size_t byteread = size-(f->curpos-f->data); if( size*count < byteread ) byteread = size*count; if( byteread>0 ) { ULONG i; for(i=0;i<byteread;i++) { char c=*f->curpos++; if( c!='\r' ) buf[i]=c; else i--; } } return byteread/size;}static int deh_num_error=0;static void deh_error(char *first, ...){ va_list argptr; if (devparm) { char buf[1000]; va_start (argptr,first); vsprintf (buf, first,argptr); va_end (argptr); CONS_Printf("%s\n",buf); } deh_num_error++;}/* ======================================================================== */// Load a dehacked file format 6 I (BP) don't know other format/* ======================================================================== *//* a sample to see Thing 1 (Player) { // MT_PLAYERint doomednum; ID # = 3232 -1, // doomednumint spawnstate; Initial frame = 32 S_PLAY, // spawnstateint spawnhealth; Hit points = 3232 100, // spawnhealthint seestate; First moving frame = 32 S_PLAY_RUN1, // seestateint seesound; Alert sound = 32 sfx_None, // seesoundint reactiontime; Reaction time = 3232 0, // reactiontimeint attacksound; Attack sound = 32 sfx_None, // attacksoundint painstate; Injury frame = 32 S_PLAY_PAIN, // painstateint painchance; Pain chance = 3232 255, // painchanceint painsound; Pain sound = 32 sfx_plpain, // painsoundint meleestate; Close attack frame = 32 S_NULL, // meleestateint missilestate; Far attack frame = 32 S_PLAY_ATK1, // missilestateint deathstate; Death frame = 32 S_PLAY_DIE1, // deathstateint xdeathstate; Exploding frame = 32 S_PLAY_XDIE1, // xdeathstateint deathsound; Death sound = 32 sfx_pldeth, // deathsoundint speed; Speed = 3232 0, // speedint radius; Width = 211812352 16*FRACUNIT, // radiusint height; Height = 211812352 56*FRACUNIT, // heightint mass; Mass = 3232 100, // massint damage; Missile damage = 3232 0, // damageint activesound; Action sound = 32 sfx_None, // activesoundint flags; Bits = 3232 MF_SOLID|MF_SHOOTABLE|MF_DROPOFF|MF_PICKUP|MF_NOTDMATCH,int raisestate; Respawn frame = 32 S_NULL // raisestate }, */static int searchvalue(char *s){ while(s[0]!='=' && s[0]!='\0') s++; if (s[0]=='=') return atoi(&s[1]); else { deh_error("No value find\n"); return 0; }}static void readthing(MYFILE *f,int num){ char s[MAXLINELEN]; char *word; int value; do{ if(myfgets(s,sizeof(s),f)!=NULL) { if(s[0]=='\n') break; value=searchvalue(s); // set the value in apropriet field word=strtok(s," "); if(!strcmp(word,"ID")) mobjinfo[num].doomednum =value; else if(!strcmp(word,"Initial")) mobjinfo[num].spawnstate =value; else if(!strcmp(word,"Hit")) mobjinfo[num].spawnhealth =value; else if(!strcmp(word,"First")) mobjinfo[num].seestate =value; else if(!strcmp(word,"Alert")) mobjinfo[num].seesound =value; else if(!strcmp(word,"Reaction")) mobjinfo[num].reactiontime=value; else if(!strcmp(word,"Attack")) mobjinfo[num].attacksound =value; else if(!strcmp(word,"Injury")) mobjinfo[num].painstate =value; else if(!strcmp(word,"Pain")) { word=strtok(NULL," "); if(!strcmp(word,"chance")) mobjinfo[num].painchance =value; else if(!strcmp(word,"sound")) mobjinfo[num].painsound =value; } else if(!strcmp(word,"Close")) mobjinfo[num].meleestate =value; else if(!strcmp(word,"Far")) mobjinfo[num].missilestate=value; else if(!strcmp(word,"Death")) { word=strtok(NULL," "); if(!strcmp(word,"frame")) mobjinfo[num].deathstate =value; else if(!strcmp(word,"sound")) mobjinfo[num].deathsound =value; } else if(!strcmp(word,"Exploding")) mobjinfo[num].xdeathstate =value; else if(!strcmp(word,"Speed")) mobjinfo[num].speed =value; else if(!strcmp(word,"Width")) mobjinfo[num].radius =value; else if(!strcmp(word,"Height")) mobjinfo[num].height =value; else if(!strcmp(word,"Mass")) mobjinfo[num].mass =value; else if(!strcmp(word,"Missile")) mobjinfo[num].damage =value; else if(!strcmp(word,"Action")) mobjinfo[num].activesound =value; else if(!strcmp(word,"Bits")) mobjinfo[num].flags =value; else if(!strcmp(word,"Bits2")) mobjinfo[num].flags2 =value; else if(!strcmp(word,"Respawn")) mobjinfo[num].raisestate =value; else deh_error("Thing %d : unknow word '%s'\n",num,word); } } while(s[0]!='\n' && !myfeof(f)); //finish when the line is empty}/*Sprite number = 10Sprite subnumber = 32968Duration = 200Next frame = 200*/static void readframe(MYFILE* f,int num){ char s[MAXLINELEN]; char *word1,*word2; int value; do{ if(myfgets(s,sizeof(s),f)!=NULL) { if(s[0]=='\n') break; value=searchvalue(s); // set the value in apropriet field word1=strtok(s," "); word2=strtok(NULL," "); if(!strcmp(word1,"Sprite")) { if(!strcmp(word2,"number")) states[num].sprite =value; else if(!strcmp(word2,"subnumber")) states[num].frame =value; } else if(!strcmp(word1,"Duration")) states[num].tics =value; else if(!strcmp(word1,"Next")) states[num].nextstate=value; else deh_error("Frame %d : unknow word '%s'\n",num,word1); } } while(s[0]!='\n' && !myfeof(f));}static void readsound(MYFILE* f,int num,char *savesfxnames[]){ char s[MAXLINELEN]; char *word; int value; do{ if(myfgets(s,sizeof(s),f)!=NULL) { if(s[0]=='\n') break; value=searchvalue(s); word=strtok(s," "); if(!strcmp(word,"Offset")) { value-=150360; if(value<=64) value/=8; else if(value<=260) value=(value+4)/8; else value=(value+8)/8; if(value>=-1 && value<sfx_freeslot0-1) S_sfx[num].name=savesfxnames[value+1]; else deh_error("Sound %d : offset out of bound\n",num); } else if(!strcmp(word,"Zero/One")) S_sfx[num].singularity=value; else if(!strcmp(word,"Value")) S_sfx[num].priority =value; else deh_error("Sound %d : unknow word '%s'\n",num,word); } } while(s[0]!='\n' && !myfeof(f));}static void readtext(MYFILE* f,int len1,int len2,char *savesfxname[],char *savesprnames[]){ char s[2001]; int i; // it is hard to change all the text in doom // here i implement only vital things // yes text change somes tables like music, sound and sprite name if(len1+len2 > 2000) { deh_error("Text too big\n"); return; } if(myfread(s,len1+len2,1,f)) { s[len1+len2]='\0'; // sound table for(i=0;i<sfx_freeslot0;i++) if(!strncmp(savesfxname[i],s,len1)) { strncpy(S_sfx[i].name,&(s[len1]),len2); S_sfx[i].name[len2]='\0'; return; } // sprite table for(i=0;i<NUMSPRITES;i++) if(!strncmp(savesprnames[i],s,len1)) { strncpy(sprnames[i],&(s[len1]),len2); sprnames[i][len2]='\0'; return; } // music table for(i=1;i<NUMMUSIC;i++) if( S_music[i].name && (!strncmp(S_music[i].name,s,len1)) ) { strncpy(S_music[i].name,&(s[len1]),len2); S_music[i].name[len2]='\0'; return; } // text table for(i=0;i<SPECIALDEHACKED;i++) { if(!strncmp(text[i],s,len1) && strlen(text[i])==(unsigned)len1) { if(strlen(text[i])<(unsigned)len2) // increase size of the text { text[i]=(char *)malloc(len2+1); if(text[i]==NULL) I_Error("ReadText : No More free Mem"); } strncpy(text[i],s + len1,len2); text[i][len2]='\0'; return; } } // special text : text changed in Legacy but with dehacked support for(i=SPECIALDEHACKED;i<NUMTEXT;i++) { int temp = strlen(text[i]); if(len1>temp && strstr(s,text[i])) { char *t; // remove space for center the text t=&s[len1+len2-1]; while(t[0]==' ') { t[0]='\0'; t--; } // skip the space while(s[len1]==' ') len1++; // remove version string identifier t=strstr(&(s[len1]),"v%i.%i"); if(!t) { t=strstr(&(s[len1]),"%i.%i"); if(!t) { t=strstr(&(s[len1]),"%i"); if(!t) { t=s+len1+strlen(&(s[len1])); } } } t[0]='\0'; len2=strlen(&s[len1]); if(strlen(text[i])<(unsigned)len2) // incresse size of the text { text[i]=(char *)malloc(len2+1); if(text[i]==NULL) I_Error("ReadText : No More free Mem"); } strncpy(text[i],&(s[len1]),len2); text[i][len2]='\0'; return; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -