d_deh.c 109 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116
  1. /* Emacs style mode select -*- C++ -*-
  2. *-----------------------------------------------------------------------------
  3. *
  4. *
  5. * PrBoom: a Doom port merged with LxDoom and LSDLDoom
  6. * based on BOOM, a modified and improved DOOM engine
  7. * Copyright (C) 1999 by
  8. * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
  9. * Copyright (C) 1999-2004 by
  10. * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
  11. * Copyright 2005, 2006 by
  12. * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version 2
  17. * of the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  27. * 02111-1307, USA.
  28. *
  29. * DESCRIPTION:
  30. * Dehacked file support
  31. * New for the TeamTNT "Boom" engine
  32. *
  33. * Author: Ty Halderman, TeamTNT
  34. *
  35. *--------------------------------------------------------------------*/
  36. // killough 5/2/98: fixed headers, removed rendunant external declarations:
  37. #include "doomdef.h"
  38. #include "doomtype.h"
  39. #include "doomstat.h"
  40. #include "d_deh.h"
  41. #include "sounds.h"
  42. #include "info.h"
  43. #include "m_cheat.h"
  44. #include "p_inter.h"
  45. #include "p_enemy.h"
  46. #include "g_game.h"
  47. #include "d_think.h"
  48. #include "w_wad.h"
  49. // CPhipps - modify to use logical output routine
  50. #include "lprintf.h"
  51. #define TRUE 1
  52. #define FALSE 0
  53. #ifndef HAVE_STRLWR
  54. #include <ctype.h>
  55. static char* strlwr(char* str)
  56. {
  57. char* p;
  58. for (p=str; *p; p++) *p = tolower(*p);
  59. return str;
  60. }
  61. #endif
  62. // killough 10/98: new functions, to allow processing DEH files in-memory
  63. // (e.g. from wads)
  64. typedef struct {
  65. /* cph 2006/08/06 -
  66. * if lump != NULL, lump is the start of the lump,
  67. * inp is the current read pos. */
  68. const byte *inp, *lump;
  69. long size;
  70. /* else, !lump, and f is the file being read */
  71. FILE* f;
  72. } DEHFILE;
  73. // killough 10/98: emulate IO whether input really comes from a file or not
  74. static char *dehfgets(char *buf, size_t n, DEHFILE *fp)
  75. {
  76. if (!fp->lump) // If this is a real file,
  77. return (fgets)(buf, n, fp->f); // return regular fgets
  78. if (!n || !*fp->inp || fp->size<=0) // If no more characters
  79. return NULL;
  80. if (n==1)
  81. fp->size--, *buf = *fp->inp++;
  82. else
  83. { // copy buffer
  84. char *p = buf;
  85. while (n>1 && *fp->inp && fp->size &&
  86. (n--, fp->size--, *p++ = *fp->inp++) != '\n')
  87. ;
  88. *p = 0;
  89. }
  90. return buf; // Return buffer pointer
  91. }
  92. static int dehfeof(DEHFILE *fp)
  93. {
  94. return !fp->lump ? feof(fp->f) : !*fp->inp || fp->size<=0;
  95. }
  96. static int dehfgetc(DEHFILE *fp)
  97. {
  98. return !fp->lump ? fgetc(fp->f) : fp->size > 0 ?
  99. fp->size--, *fp->inp++ : EOF;
  100. }
  101. // haleyjd 9/22/99
  102. int HelperThing = -1; // in P_SpawnMapThing to substitute helper thing
  103. // variables used in other routines
  104. boolean deh_pars = FALSE; // in wi_stuff to allow pars in modified games
  105. // #include "d_deh.h" -- we don't do that here but we declare the
  106. // variables. This externalizes everything that there is a string
  107. // set for in the language files. See d_deh.h for detailed comments,
  108. // original English values etc. These are set to the macro values,
  109. // which are set by D_ENGLSH.H or D_FRENCH.H(etc). BEX files are a
  110. // better way of changing these strings globally by language.
  111. // ====================================================================
  112. // Any of these can be changed using the bex extensions
  113. #include "dstrings.h" // to get the initial values
  114. /* cph - const's
  115. * - removed redundant "can't XXX in a netgame" strings.
  116. */
  117. const char *s_D_DEVSTR = D_DEVSTR;
  118. const char *s_D_CDROM = D_CDROM;
  119. const char *s_PRESSKEY = PRESSKEY;
  120. const char *s_PRESSYN = PRESSYN;
  121. const char *s_QUITMSG = QUITMSG;
  122. const char *s_QSAVESPOT = QSAVESPOT; // PRESSKEY;
  123. const char *s_SAVEDEAD = SAVEDEAD; // PRESSKEY; // remove duplicate y/n
  124. const char *s_QSPROMPT = QSPROMPT; // PRESSYN;
  125. const char *s_QLPROMPT = QLPROMPT; // PRESSYN;
  126. const char *s_NEWGAME = NEWGAME; // PRESSKEY;
  127. const char *s_RESTARTLEVEL= RESTARTLEVEL; // PRESSYN;
  128. const char *s_NIGHTMARE = NIGHTMARE; // PRESSYN;
  129. const char *s_SWSTRING = SWSTRING; // PRESSKEY;
  130. const char *s_MSGOFF = MSGOFF;
  131. const char *s_MSGON = MSGON;
  132. const char *s_NETEND = NETEND; // PRESSKEY;
  133. const char *s_ENDGAME = ENDGAME; // PRESSYN; // killough 4/4/98: end
  134. const char *s_DOSY = DOSY;
  135. const char *s_DETAILHI = DETAILHI;
  136. const char *s_DETAILLO = DETAILLO;
  137. const char *s_GAMMALVL0 = GAMMALVL0;
  138. const char *s_GAMMALVL1 = GAMMALVL1;
  139. const char *s_GAMMALVL2 = GAMMALVL2;
  140. const char *s_GAMMALVL3 = GAMMALVL3;
  141. const char *s_GAMMALVL4 = GAMMALVL4;
  142. const char *s_EMPTYSTRING = EMPTYSTRING;
  143. const char *s_GOTARMOR = GOTARMOR;
  144. const char *s_GOTMEGA = GOTMEGA;
  145. const char *s_GOTHTHBONUS = GOTHTHBONUS;
  146. const char *s_GOTARMBONUS = GOTARMBONUS;
  147. const char *s_GOTSTIM = GOTSTIM;
  148. const char *s_GOTMEDINEED = GOTMEDINEED;
  149. const char *s_GOTMEDIKIT = GOTMEDIKIT;
  150. const char *s_GOTSUPER = GOTSUPER;
  151. const char *s_GOTBLUECARD = GOTBLUECARD;
  152. const char *s_GOTYELWCARD = GOTYELWCARD;
  153. const char *s_GOTREDCARD = GOTREDCARD;
  154. const char *s_GOTBLUESKUL = GOTBLUESKUL;
  155. const char *s_GOTYELWSKUL = GOTYELWSKUL;
  156. const char *s_GOTREDSKULL = GOTREDSKULL;
  157. const char *s_GOTINVUL = GOTINVUL;
  158. const char *s_GOTBERSERK = GOTBERSERK;
  159. const char *s_GOTINVIS = GOTINVIS;
  160. const char *s_GOTSUIT = GOTSUIT;
  161. const char *s_GOTMAP = GOTMAP;
  162. const char *s_GOTVISOR = GOTVISOR;
  163. const char *s_GOTMSPHERE = GOTMSPHERE;
  164. const char *s_GOTCLIP = GOTCLIP;
  165. const char *s_GOTCLIPBOX = GOTCLIPBOX;
  166. const char *s_GOTROCKET = GOTROCKET;
  167. const char *s_GOTROCKBOX = GOTROCKBOX;
  168. const char *s_GOTCELL = GOTCELL;
  169. const char *s_GOTCELLBOX = GOTCELLBOX;
  170. const char *s_GOTSHELLS = GOTSHELLS;
  171. const char *s_GOTSHELLBOX = GOTSHELLBOX;
  172. const char *s_GOTBACKPACK = GOTBACKPACK;
  173. const char *s_GOTBFG9000 = GOTBFG9000;
  174. const char *s_GOTCHAINGUN = GOTCHAINGUN;
  175. const char *s_GOTCHAINSAW = GOTCHAINSAW;
  176. const char *s_GOTLAUNCHER = GOTLAUNCHER;
  177. const char *s_GOTPLASMA = GOTPLASMA;
  178. const char *s_GOTSHOTGUN = GOTSHOTGUN;
  179. const char *s_GOTSHOTGUN2 = GOTSHOTGUN2;
  180. const char *s_PD_BLUEO = PD_BLUEO;
  181. const char *s_PD_REDO = PD_REDO;
  182. const char *s_PD_YELLOWO = PD_YELLOWO;
  183. const char *s_PD_BLUEK = PD_BLUEK;
  184. const char *s_PD_REDK = PD_REDK;
  185. const char *s_PD_YELLOWK = PD_YELLOWK;
  186. const char *s_PD_BLUEC = PD_BLUEC;
  187. const char *s_PD_REDC = PD_REDC;
  188. const char *s_PD_YELLOWC = PD_YELLOWC;
  189. const char *s_PD_BLUES = PD_BLUES;
  190. const char *s_PD_REDS = PD_REDS;
  191. const char *s_PD_YELLOWS = PD_YELLOWS;
  192. const char *s_PD_ANY = PD_ANY;
  193. const char *s_PD_ALL3 = PD_ALL3;
  194. const char *s_PD_ALL6 = PD_ALL6;
  195. const char *s_GGSAVED = GGSAVED;
  196. const char *s_HUSTR_MSGU = HUSTR_MSGU;
  197. const char *s_HUSTR_E1M1 = HUSTR_E1M1;
  198. const char *s_HUSTR_E1M2 = HUSTR_E1M2;
  199. const char *s_HUSTR_E1M3 = HUSTR_E1M3;
  200. const char *s_HUSTR_E1M4 = HUSTR_E1M4;
  201. const char *s_HUSTR_E1M5 = HUSTR_E1M5;
  202. const char *s_HUSTR_E1M6 = HUSTR_E1M6;
  203. const char *s_HUSTR_E1M7 = HUSTR_E1M7;
  204. const char *s_HUSTR_E1M8 = HUSTR_E1M8;
  205. const char *s_HUSTR_E1M9 = HUSTR_E1M9;
  206. const char *s_HUSTR_E2M1 = HUSTR_E2M1;
  207. const char *s_HUSTR_E2M2 = HUSTR_E2M2;
  208. const char *s_HUSTR_E2M3 = HUSTR_E2M3;
  209. const char *s_HUSTR_E2M4 = HUSTR_E2M4;
  210. const char *s_HUSTR_E2M5 = HUSTR_E2M5;
  211. const char *s_HUSTR_E2M6 = HUSTR_E2M6;
  212. const char *s_HUSTR_E2M7 = HUSTR_E2M7;
  213. const char *s_HUSTR_E2M8 = HUSTR_E2M8;
  214. const char *s_HUSTR_E2M9 = HUSTR_E2M9;
  215. const char *s_HUSTR_E3M1 = HUSTR_E3M1;
  216. const char *s_HUSTR_E3M2 = HUSTR_E3M2;
  217. const char *s_HUSTR_E3M3 = HUSTR_E3M3;
  218. const char *s_HUSTR_E3M4 = HUSTR_E3M4;
  219. const char *s_HUSTR_E3M5 = HUSTR_E3M5;
  220. const char *s_HUSTR_E3M6 = HUSTR_E3M6;
  221. const char *s_HUSTR_E3M7 = HUSTR_E3M7;
  222. const char *s_HUSTR_E3M8 = HUSTR_E3M8;
  223. const char *s_HUSTR_E3M9 = HUSTR_E3M9;
  224. const char *s_HUSTR_E4M1 = HUSTR_E4M1;
  225. const char *s_HUSTR_E4M2 = HUSTR_E4M2;
  226. const char *s_HUSTR_E4M3 = HUSTR_E4M3;
  227. const char *s_HUSTR_E4M4 = HUSTR_E4M4;
  228. const char *s_HUSTR_E4M5 = HUSTR_E4M5;
  229. const char *s_HUSTR_E4M6 = HUSTR_E4M6;
  230. const char *s_HUSTR_E4M7 = HUSTR_E4M7;
  231. const char *s_HUSTR_E4M8 = HUSTR_E4M8;
  232. const char *s_HUSTR_E4M9 = HUSTR_E4M9;
  233. const char *s_HUSTR_1 = HUSTR_1;
  234. const char *s_HUSTR_2 = HUSTR_2;
  235. const char *s_HUSTR_3 = HUSTR_3;
  236. const char *s_HUSTR_4 = HUSTR_4;
  237. const char *s_HUSTR_5 = HUSTR_5;
  238. const char *s_HUSTR_6 = HUSTR_6;
  239. const char *s_HUSTR_7 = HUSTR_7;
  240. const char *s_HUSTR_8 = HUSTR_8;
  241. const char *s_HUSTR_9 = HUSTR_9;
  242. const char *s_HUSTR_10 = HUSTR_10;
  243. const char *s_HUSTR_11 = HUSTR_11;
  244. const char *s_HUSTR_12 = HUSTR_12;
  245. const char *s_HUSTR_13 = HUSTR_13;
  246. const char *s_HUSTR_14 = HUSTR_14;
  247. const char *s_HUSTR_15 = HUSTR_15;
  248. const char *s_HUSTR_16 = HUSTR_16;
  249. const char *s_HUSTR_17 = HUSTR_17;
  250. const char *s_HUSTR_18 = HUSTR_18;
  251. const char *s_HUSTR_19 = HUSTR_19;
  252. const char *s_HUSTR_20 = HUSTR_20;
  253. const char *s_HUSTR_21 = HUSTR_21;
  254. const char *s_HUSTR_22 = HUSTR_22;
  255. const char *s_HUSTR_23 = HUSTR_23;
  256. const char *s_HUSTR_24 = HUSTR_24;
  257. const char *s_HUSTR_25 = HUSTR_25;
  258. const char *s_HUSTR_26 = HUSTR_26;
  259. const char *s_HUSTR_27 = HUSTR_27;
  260. const char *s_HUSTR_28 = HUSTR_28;
  261. const char *s_HUSTR_29 = HUSTR_29;
  262. const char *s_HUSTR_30 = HUSTR_30;
  263. const char *s_HUSTR_31 = HUSTR_31;
  264. const char *s_HUSTR_32 = HUSTR_32;
  265. const char *s_PHUSTR_1 = PHUSTR_1;
  266. const char *s_PHUSTR_2 = PHUSTR_2;
  267. const char *s_PHUSTR_3 = PHUSTR_3;
  268. const char *s_PHUSTR_4 = PHUSTR_4;
  269. const char *s_PHUSTR_5 = PHUSTR_5;
  270. const char *s_PHUSTR_6 = PHUSTR_6;
  271. const char *s_PHUSTR_7 = PHUSTR_7;
  272. const char *s_PHUSTR_8 = PHUSTR_8;
  273. const char *s_PHUSTR_9 = PHUSTR_9;
  274. const char *s_PHUSTR_10 = PHUSTR_10;
  275. const char *s_PHUSTR_11 = PHUSTR_11;
  276. const char *s_PHUSTR_12 = PHUSTR_12;
  277. const char *s_PHUSTR_13 = PHUSTR_13;
  278. const char *s_PHUSTR_14 = PHUSTR_14;
  279. const char *s_PHUSTR_15 = PHUSTR_15;
  280. const char *s_PHUSTR_16 = PHUSTR_16;
  281. const char *s_PHUSTR_17 = PHUSTR_17;
  282. const char *s_PHUSTR_18 = PHUSTR_18;
  283. const char *s_PHUSTR_19 = PHUSTR_19;
  284. const char *s_PHUSTR_20 = PHUSTR_20;
  285. const char *s_PHUSTR_21 = PHUSTR_21;
  286. const char *s_PHUSTR_22 = PHUSTR_22;
  287. const char *s_PHUSTR_23 = PHUSTR_23;
  288. const char *s_PHUSTR_24 = PHUSTR_24;
  289. const char *s_PHUSTR_25 = PHUSTR_25;
  290. const char *s_PHUSTR_26 = PHUSTR_26;
  291. const char *s_PHUSTR_27 = PHUSTR_27;
  292. const char *s_PHUSTR_28 = PHUSTR_28;
  293. const char *s_PHUSTR_29 = PHUSTR_29;
  294. const char *s_PHUSTR_30 = PHUSTR_30;
  295. const char *s_PHUSTR_31 = PHUSTR_31;
  296. const char *s_PHUSTR_32 = PHUSTR_32;
  297. const char *s_THUSTR_1 = THUSTR_1;
  298. const char *s_THUSTR_2 = THUSTR_2;
  299. const char *s_THUSTR_3 = THUSTR_3;
  300. const char *s_THUSTR_4 = THUSTR_4;
  301. const char *s_THUSTR_5 = THUSTR_5;
  302. const char *s_THUSTR_6 = THUSTR_6;
  303. const char *s_THUSTR_7 = THUSTR_7;
  304. const char *s_THUSTR_8 = THUSTR_8;
  305. const char *s_THUSTR_9 = THUSTR_9;
  306. const char *s_THUSTR_10 = THUSTR_10;
  307. const char *s_THUSTR_11 = THUSTR_11;
  308. const char *s_THUSTR_12 = THUSTR_12;
  309. const char *s_THUSTR_13 = THUSTR_13;
  310. const char *s_THUSTR_14 = THUSTR_14;
  311. const char *s_THUSTR_15 = THUSTR_15;
  312. const char *s_THUSTR_16 = THUSTR_16;
  313. const char *s_THUSTR_17 = THUSTR_17;
  314. const char *s_THUSTR_18 = THUSTR_18;
  315. const char *s_THUSTR_19 = THUSTR_19;
  316. const char *s_THUSTR_20 = THUSTR_20;
  317. const char *s_THUSTR_21 = THUSTR_21;
  318. const char *s_THUSTR_22 = THUSTR_22;
  319. const char *s_THUSTR_23 = THUSTR_23;
  320. const char *s_THUSTR_24 = THUSTR_24;
  321. const char *s_THUSTR_25 = THUSTR_25;
  322. const char *s_THUSTR_26 = THUSTR_26;
  323. const char *s_THUSTR_27 = THUSTR_27;
  324. const char *s_THUSTR_28 = THUSTR_28;
  325. const char *s_THUSTR_29 = THUSTR_29;
  326. const char *s_THUSTR_30 = THUSTR_30;
  327. const char *s_THUSTR_31 = THUSTR_31;
  328. const char *s_THUSTR_32 = THUSTR_32;
  329. const char *s_HUSTR_CHATMACRO1 = HUSTR_CHATMACRO1;
  330. const char *s_HUSTR_CHATMACRO2 = HUSTR_CHATMACRO2;
  331. const char *s_HUSTR_CHATMACRO3 = HUSTR_CHATMACRO3;
  332. const char *s_HUSTR_CHATMACRO4 = HUSTR_CHATMACRO4;
  333. const char *s_HUSTR_CHATMACRO5 = HUSTR_CHATMACRO5;
  334. const char *s_HUSTR_CHATMACRO6 = HUSTR_CHATMACRO6;
  335. const char *s_HUSTR_CHATMACRO7 = HUSTR_CHATMACRO7;
  336. const char *s_HUSTR_CHATMACRO8 = HUSTR_CHATMACRO8;
  337. const char *s_HUSTR_CHATMACRO9 = HUSTR_CHATMACRO9;
  338. const char *s_HUSTR_CHATMACRO0 = HUSTR_CHATMACRO0;
  339. const char *s_HUSTR_TALKTOSELF1 = HUSTR_TALKTOSELF1;
  340. const char *s_HUSTR_TALKTOSELF2 = HUSTR_TALKTOSELF2;
  341. const char *s_HUSTR_TALKTOSELF3 = HUSTR_TALKTOSELF3;
  342. const char *s_HUSTR_TALKTOSELF4 = HUSTR_TALKTOSELF4;
  343. const char *s_HUSTR_TALKTOSELF5 = HUSTR_TALKTOSELF5;
  344. const char *s_HUSTR_MESSAGESENT = HUSTR_MESSAGESENT;
  345. const char *s_HUSTR_PLRGREEN = HUSTR_PLRGREEN;
  346. const char *s_HUSTR_PLRINDIGO = HUSTR_PLRINDIGO;
  347. const char *s_HUSTR_PLRBROWN = HUSTR_PLRBROWN;
  348. const char *s_HUSTR_PLRRED = HUSTR_PLRRED;
  349. const char *s_AMSTR_FOLLOWON = AMSTR_FOLLOWON;
  350. const char *s_AMSTR_FOLLOWOFF = AMSTR_FOLLOWOFF;
  351. const char *s_AMSTR_GRIDON = AMSTR_GRIDON;
  352. const char *s_AMSTR_GRIDOFF = AMSTR_GRIDOFF;
  353. const char *s_AMSTR_MARKEDSPOT = AMSTR_MARKEDSPOT;
  354. const char *s_AMSTR_MARKSCLEARED = AMSTR_MARKSCLEARED;
  355. // CPhipps - automap rotate & overlay
  356. const char* s_AMSTR_ROTATEON = AMSTR_ROTATEON;
  357. const char* s_AMSTR_ROTATEOFF = AMSTR_ROTATEOFF;
  358. const char* s_AMSTR_OVERLAYON = AMSTR_OVERLAYON;
  359. const char* s_AMSTR_OVERLAYOFF = AMSTR_OVERLAYOFF;
  360. const char *s_STSTR_MUS = STSTR_MUS;
  361. const char *s_STSTR_NOMUS = STSTR_NOMUS;
  362. const char *s_STSTR_DQDON = STSTR_DQDON;
  363. const char *s_STSTR_DQDOFF = STSTR_DQDOFF;
  364. const char *s_STSTR_KFAADDED = STSTR_KFAADDED;
  365. const char *s_STSTR_FAADDED = STSTR_FAADDED;
  366. const char *s_STSTR_NCON = STSTR_NCON;
  367. const char *s_STSTR_NCOFF = STSTR_NCOFF;
  368. const char *s_STSTR_BEHOLD = STSTR_BEHOLD;
  369. const char *s_STSTR_BEHOLDX = STSTR_BEHOLDX;
  370. const char *s_STSTR_CHOPPERS = STSTR_CHOPPERS;
  371. const char *s_STSTR_CLEV = STSTR_CLEV;
  372. const char *s_STSTR_COMPON = STSTR_COMPON;
  373. const char *s_STSTR_COMPOFF = STSTR_COMPOFF;
  374. const char *s_E1TEXT = E1TEXT;
  375. const char *s_E2TEXT = E2TEXT;
  376. const char *s_E3TEXT = E3TEXT;
  377. const char *s_E4TEXT = E4TEXT;
  378. const char *s_C1TEXT = C1TEXT;
  379. const char *s_C2TEXT = C2TEXT;
  380. const char *s_C3TEXT = C3TEXT;
  381. const char *s_C4TEXT = C4TEXT;
  382. const char *s_C5TEXT = C5TEXT;
  383. const char *s_C6TEXT = C6TEXT;
  384. const char *s_P1TEXT = P1TEXT;
  385. const char *s_P2TEXT = P2TEXT;
  386. const char *s_P3TEXT = P3TEXT;
  387. const char *s_P4TEXT = P4TEXT;
  388. const char *s_P5TEXT = P5TEXT;
  389. const char *s_P6TEXT = P6TEXT;
  390. const char *s_T1TEXT = T1TEXT;
  391. const char *s_T2TEXT = T2TEXT;
  392. const char *s_T3TEXT = T3TEXT;
  393. const char *s_T4TEXT = T4TEXT;
  394. const char *s_T5TEXT = T5TEXT;
  395. const char *s_T6TEXT = T6TEXT;
  396. const char *s_CC_ZOMBIE = CC_ZOMBIE;
  397. const char *s_CC_SHOTGUN = CC_SHOTGUN;
  398. const char *s_CC_HEAVY = CC_HEAVY;
  399. const char *s_CC_IMP = CC_IMP;
  400. const char *s_CC_DEMON = CC_DEMON;
  401. const char *s_CC_LOST = CC_LOST;
  402. const char *s_CC_CACO = CC_CACO;
  403. const char *s_CC_HELL = CC_HELL;
  404. const char *s_CC_BARON = CC_BARON;
  405. const char *s_CC_ARACH = CC_ARACH;
  406. const char *s_CC_PAIN = CC_PAIN;
  407. const char *s_CC_REVEN = CC_REVEN;
  408. const char *s_CC_MANCU = CC_MANCU;
  409. const char *s_CC_ARCH = CC_ARCH;
  410. const char *s_CC_SPIDER = CC_SPIDER;
  411. const char *s_CC_CYBER = CC_CYBER;
  412. const char *s_CC_HERO = CC_HERO;
  413. // Ty 03/30/98 - new substitutions for background textures
  414. // during int screens
  415. const char *bgflatE1 = "FLOOR4_8"; // end of DOOM Episode 1
  416. const char *bgflatE2 = "SFLR6_1"; // end of DOOM Episode 2
  417. const char *bgflatE3 = "MFLR8_4"; // end of DOOM Episode 3
  418. const char *bgflatE4 = "MFLR8_3"; // end of DOOM Episode 4
  419. const char *bgflat06 = "SLIME16"; // DOOM2 after MAP06
  420. const char *bgflat11 = "RROCK14"; // DOOM2 after MAP11
  421. const char *bgflat20 = "RROCK07"; // DOOM2 after MAP20
  422. const char *bgflat30 = "RROCK17"; // DOOM2 after MAP30
  423. const char *bgflat15 = "RROCK13"; // DOOM2 going MAP15 to MAP31
  424. const char *bgflat31 = "RROCK19"; // DOOM2 going MAP31 to MAP32
  425. const char *bgcastcall = "BOSSBACK"; // Panel behind cast call
  426. const char *startup1 = ""; // blank lines are default and are not printed
  427. const char *startup2 = "";
  428. const char *startup3 = "";
  429. const char *startup4 = "";
  430. const char *startup5 = "";
  431. /* Ty 05/03/98 - externalized
  432. * cph - updated for prboom */
  433. const char *savegamename = "prbmsav";
  434. // end d_deh.h variable declarations
  435. // ====================================================================
  436. // Do this for a lookup--the pointer (loaded above) is cross-referenced
  437. // to a string key that is the same as the define above. We will use
  438. // strdups to set these new values that we read from the file, orphaning
  439. // the original value set above.
  440. // CPhipps - make strings pointed to const
  441. typedef struct {
  442. const char **ppstr; // doubly indirect pointer to string
  443. const char *lookup; // pointer to lookup string name
  444. } deh_strs;
  445. /* CPhipps - const, static
  446. * - removed redundant "Can't XXX in a netgame" strings
  447. */
  448. static const deh_strs deh_strlookup[] = {
  449. {&s_D_DEVSTR,"D_DEVSTR"},
  450. {&s_D_CDROM,"D_CDROM"},
  451. {&s_PRESSKEY,"PRESSKEY"},
  452. {&s_PRESSYN,"PRESSYN"},
  453. {&s_QUITMSG,"QUITMSG"},
  454. {&s_QSAVESPOT,"QSAVESPOT"},
  455. {&s_SAVEDEAD,"SAVEDEAD"},
  456. /* cph - disabled to prevent format string attacks in WAD files
  457. {&s_QSPROMPT,"QSPROMPT"},
  458. {&s_QLPROMPT,"QLPROMPT"},*/
  459. {&s_NEWGAME,"NEWGAME"},
  460. {&s_RESTARTLEVEL,"RESTARTLEVEL"},
  461. {&s_NIGHTMARE,"NIGHTMARE"},
  462. {&s_SWSTRING,"SWSTRING"},
  463. {&s_MSGOFF,"MSGOFF"},
  464. {&s_MSGON,"MSGON"},
  465. {&s_NETEND,"NETEND"},
  466. {&s_ENDGAME,"ENDGAME"},
  467. {&s_DOSY,"DOSY"},
  468. {&s_DETAILHI,"DETAILHI"},
  469. {&s_DETAILLO,"DETAILLO"},
  470. {&s_GAMMALVL0,"GAMMALVL0"},
  471. {&s_GAMMALVL1,"GAMMALVL1"},
  472. {&s_GAMMALVL2,"GAMMALVL2"},
  473. {&s_GAMMALVL3,"GAMMALVL3"},
  474. {&s_GAMMALVL4,"GAMMALVL4"},
  475. {&s_EMPTYSTRING,"EMPTYSTRING"},
  476. {&s_GOTARMOR,"GOTARMOR"},
  477. {&s_GOTMEGA,"GOTMEGA"},
  478. {&s_GOTHTHBONUS,"GOTHTHBONUS"},
  479. {&s_GOTARMBONUS,"GOTARMBONUS"},
  480. {&s_GOTSTIM,"GOTSTIM"},
  481. {&s_GOTMEDINEED,"GOTMEDINEED"},
  482. {&s_GOTMEDIKIT,"GOTMEDIKIT"},
  483. {&s_GOTSUPER,"GOTSUPER"},
  484. {&s_GOTBLUECARD,"GOTBLUECARD"},
  485. {&s_GOTYELWCARD,"GOTYELWCARD"},
  486. {&s_GOTREDCARD,"GOTREDCARD"},
  487. {&s_GOTBLUESKUL,"GOTBLUESKUL"},
  488. {&s_GOTYELWSKUL,"GOTYELWSKUL"},
  489. {&s_GOTREDSKULL,"GOTREDSKULL"},
  490. {&s_GOTINVUL,"GOTINVUL"},
  491. {&s_GOTBERSERK,"GOTBERSERK"},
  492. {&s_GOTINVIS,"GOTINVIS"},
  493. {&s_GOTSUIT,"GOTSUIT"},
  494. {&s_GOTMAP,"GOTMAP"},
  495. {&s_GOTVISOR,"GOTVISOR"},
  496. {&s_GOTMSPHERE,"GOTMSPHERE"},
  497. {&s_GOTCLIP,"GOTCLIP"},
  498. {&s_GOTCLIPBOX,"GOTCLIPBOX"},
  499. {&s_GOTROCKET,"GOTROCKET"},
  500. {&s_GOTROCKBOX,"GOTROCKBOX"},
  501. {&s_GOTCELL,"GOTCELL"},
  502. {&s_GOTCELLBOX,"GOTCELLBOX"},
  503. {&s_GOTSHELLS,"GOTSHELLS"},
  504. {&s_GOTSHELLBOX,"GOTSHELLBOX"},
  505. {&s_GOTBACKPACK,"GOTBACKPACK"},
  506. {&s_GOTBFG9000,"GOTBFG9000"},
  507. {&s_GOTCHAINGUN,"GOTCHAINGUN"},
  508. {&s_GOTCHAINSAW,"GOTCHAINSAW"},
  509. {&s_GOTLAUNCHER,"GOTLAUNCHER"},
  510. {&s_GOTPLASMA,"GOTPLASMA"},
  511. {&s_GOTSHOTGUN,"GOTSHOTGUN"},
  512. {&s_GOTSHOTGUN2,"GOTSHOTGUN2"},
  513. {&s_PD_BLUEO,"PD_BLUEO"},
  514. {&s_PD_REDO,"PD_REDO"},
  515. {&s_PD_YELLOWO,"PD_YELLOWO"},
  516. {&s_PD_BLUEK,"PD_BLUEK"},
  517. {&s_PD_REDK,"PD_REDK"},
  518. {&s_PD_YELLOWK,"PD_YELLOWK"},
  519. {&s_PD_BLUEC,"PD_BLUEC"},
  520. {&s_PD_REDC,"PD_REDC"},
  521. {&s_PD_YELLOWC,"PD_YELLOWC"},
  522. {&s_PD_BLUES,"PD_BLUES"},
  523. {&s_PD_REDS,"PD_REDS"},
  524. {&s_PD_YELLOWS,"PD_YELLOWS"},
  525. {&s_PD_ANY,"PD_ANY"},
  526. {&s_PD_ALL3,"PD_ALL3"},
  527. {&s_PD_ALL6,"PD_ALL6"},
  528. {&s_GGSAVED,"GGSAVED"},
  529. {&s_HUSTR_MSGU,"HUSTR_MSGU"},
  530. {&s_HUSTR_E1M1,"HUSTR_E1M1"},
  531. {&s_HUSTR_E1M2,"HUSTR_E1M2"},
  532. {&s_HUSTR_E1M3,"HUSTR_E1M3"},
  533. {&s_HUSTR_E1M4,"HUSTR_E1M4"},
  534. {&s_HUSTR_E1M5,"HUSTR_E1M5"},
  535. {&s_HUSTR_E1M6,"HUSTR_E1M6"},
  536. {&s_HUSTR_E1M7,"HUSTR_E1M7"},
  537. {&s_HUSTR_E1M8,"HUSTR_E1M8"},
  538. {&s_HUSTR_E1M9,"HUSTR_E1M9"},
  539. {&s_HUSTR_E2M1,"HUSTR_E2M1"},
  540. {&s_HUSTR_E2M2,"HUSTR_E2M2"},
  541. {&s_HUSTR_E2M3,"HUSTR_E2M3"},
  542. {&s_HUSTR_E2M4,"HUSTR_E2M4"},
  543. {&s_HUSTR_E2M5,"HUSTR_E2M5"},
  544. {&s_HUSTR_E2M6,"HUSTR_E2M6"},
  545. {&s_HUSTR_E2M7,"HUSTR_E2M7"},
  546. {&s_HUSTR_E2M8,"HUSTR_E2M8"},
  547. {&s_HUSTR_E2M9,"HUSTR_E2M9"},
  548. {&s_HUSTR_E3M1,"HUSTR_E3M1"},
  549. {&s_HUSTR_E3M2,"HUSTR_E3M2"},
  550. {&s_HUSTR_E3M3,"HUSTR_E3M3"},
  551. {&s_HUSTR_E3M4,"HUSTR_E3M4"},
  552. {&s_HUSTR_E3M5,"HUSTR_E3M5"},
  553. {&s_HUSTR_E3M6,"HUSTR_E3M6"},
  554. {&s_HUSTR_E3M7,"HUSTR_E3M7"},
  555. {&s_HUSTR_E3M8,"HUSTR_E3M8"},
  556. {&s_HUSTR_E3M9,"HUSTR_E3M9"},
  557. {&s_HUSTR_E4M1,"HUSTR_E4M1"},
  558. {&s_HUSTR_E4M2,"HUSTR_E4M2"},
  559. {&s_HUSTR_E4M3,"HUSTR_E4M3"},
  560. {&s_HUSTR_E4M4,"HUSTR_E4M4"},
  561. {&s_HUSTR_E4M5,"HUSTR_E4M5"},
  562. {&s_HUSTR_E4M6,"HUSTR_E4M6"},
  563. {&s_HUSTR_E4M7,"HUSTR_E4M7"},
  564. {&s_HUSTR_E4M8,"HUSTR_E4M8"},
  565. {&s_HUSTR_E4M9,"HUSTR_E4M9"},
  566. {&s_HUSTR_1,"HUSTR_1"},
  567. {&s_HUSTR_2,"HUSTR_2"},
  568. {&s_HUSTR_3,"HUSTR_3"},
  569. {&s_HUSTR_4,"HUSTR_4"},
  570. {&s_HUSTR_5,"HUSTR_5"},
  571. {&s_HUSTR_6,"HUSTR_6"},
  572. {&s_HUSTR_7,"HUSTR_7"},
  573. {&s_HUSTR_8,"HUSTR_8"},
  574. {&s_HUSTR_9,"HUSTR_9"},
  575. {&s_HUSTR_10,"HUSTR_10"},
  576. {&s_HUSTR_11,"HUSTR_11"},
  577. {&s_HUSTR_12,"HUSTR_12"},
  578. {&s_HUSTR_13,"HUSTR_13"},
  579. {&s_HUSTR_14,"HUSTR_14"},
  580. {&s_HUSTR_15,"HUSTR_15"},
  581. {&s_HUSTR_16,"HUSTR_16"},
  582. {&s_HUSTR_17,"HUSTR_17"},
  583. {&s_HUSTR_18,"HUSTR_18"},
  584. {&s_HUSTR_19,"HUSTR_19"},
  585. {&s_HUSTR_20,"HUSTR_20"},
  586. {&s_HUSTR_21,"HUSTR_21"},
  587. {&s_HUSTR_22,"HUSTR_22"},
  588. {&s_HUSTR_23,"HUSTR_23"},
  589. {&s_HUSTR_24,"HUSTR_24"},
  590. {&s_HUSTR_25,"HUSTR_25"},
  591. {&s_HUSTR_26,"HUSTR_26"},
  592. {&s_HUSTR_27,"HUSTR_27"},
  593. {&s_HUSTR_28,"HUSTR_28"},
  594. {&s_HUSTR_29,"HUSTR_29"},
  595. {&s_HUSTR_30,"HUSTR_30"},
  596. {&s_HUSTR_31,"HUSTR_31"},
  597. {&s_HUSTR_32,"HUSTR_32"},
  598. {&s_PHUSTR_1,"PHUSTR_1"},
  599. {&s_PHUSTR_2,"PHUSTR_2"},
  600. {&s_PHUSTR_3,"PHUSTR_3"},
  601. {&s_PHUSTR_4,"PHUSTR_4"},
  602. {&s_PHUSTR_5,"PHUSTR_5"},
  603. {&s_PHUSTR_6,"PHUSTR_6"},
  604. {&s_PHUSTR_7,"PHUSTR_7"},
  605. {&s_PHUSTR_8,"PHUSTR_8"},
  606. {&s_PHUSTR_9,"PHUSTR_9"},
  607. {&s_PHUSTR_10,"PHUSTR_10"},
  608. {&s_PHUSTR_11,"PHUSTR_11"},
  609. {&s_PHUSTR_12,"PHUSTR_12"},
  610. {&s_PHUSTR_13,"PHUSTR_13"},
  611. {&s_PHUSTR_14,"PHUSTR_14"},
  612. {&s_PHUSTR_15,"PHUSTR_15"},
  613. {&s_PHUSTR_16,"PHUSTR_16"},
  614. {&s_PHUSTR_17,"PHUSTR_17"},
  615. {&s_PHUSTR_18,"PHUSTR_18"},
  616. {&s_PHUSTR_19,"PHUSTR_19"},
  617. {&s_PHUSTR_20,"PHUSTR_20"},
  618. {&s_PHUSTR_21,"PHUSTR_21"},
  619. {&s_PHUSTR_22,"PHUSTR_22"},
  620. {&s_PHUSTR_23,"PHUSTR_23"},
  621. {&s_PHUSTR_24,"PHUSTR_24"},
  622. {&s_PHUSTR_25,"PHUSTR_25"},
  623. {&s_PHUSTR_26,"PHUSTR_26"},
  624. {&s_PHUSTR_27,"PHUSTR_27"},
  625. {&s_PHUSTR_28,"PHUSTR_28"},
  626. {&s_PHUSTR_29,"PHUSTR_29"},
  627. {&s_PHUSTR_30,"PHUSTR_30"},
  628. {&s_PHUSTR_31,"PHUSTR_31"},
  629. {&s_PHUSTR_32,"PHUSTR_32"},
  630. {&s_THUSTR_1,"THUSTR_1"},
  631. {&s_THUSTR_2,"THUSTR_2"},
  632. {&s_THUSTR_3,"THUSTR_3"},
  633. {&s_THUSTR_4,"THUSTR_4"},
  634. {&s_THUSTR_5,"THUSTR_5"},
  635. {&s_THUSTR_6,"THUSTR_6"},
  636. {&s_THUSTR_7,"THUSTR_7"},
  637. {&s_THUSTR_8,"THUSTR_8"},
  638. {&s_THUSTR_9,"THUSTR_9"},
  639. {&s_THUSTR_10,"THUSTR_10"},
  640. {&s_THUSTR_11,"THUSTR_11"},
  641. {&s_THUSTR_12,"THUSTR_12"},
  642. {&s_THUSTR_13,"THUSTR_13"},
  643. {&s_THUSTR_14,"THUSTR_14"},
  644. {&s_THUSTR_15,"THUSTR_15"},
  645. {&s_THUSTR_16,"THUSTR_16"},
  646. {&s_THUSTR_17,"THUSTR_17"},
  647. {&s_THUSTR_18,"THUSTR_18"},
  648. {&s_THUSTR_19,"THUSTR_19"},
  649. {&s_THUSTR_20,"THUSTR_20"},
  650. {&s_THUSTR_21,"THUSTR_21"},
  651. {&s_THUSTR_22,"THUSTR_22"},
  652. {&s_THUSTR_23,"THUSTR_23"},
  653. {&s_THUSTR_24,"THUSTR_24"},
  654. {&s_THUSTR_25,"THUSTR_25"},
  655. {&s_THUSTR_26,"THUSTR_26"},
  656. {&s_THUSTR_27,"THUSTR_27"},
  657. {&s_THUSTR_28,"THUSTR_28"},
  658. {&s_THUSTR_29,"THUSTR_29"},
  659. {&s_THUSTR_30,"THUSTR_30"},
  660. {&s_THUSTR_31,"THUSTR_31"},
  661. {&s_THUSTR_32,"THUSTR_32"},
  662. {&s_HUSTR_CHATMACRO1,"HUSTR_CHATMACRO1"},
  663. {&s_HUSTR_CHATMACRO2,"HUSTR_CHATMACRO2"},
  664. {&s_HUSTR_CHATMACRO3,"HUSTR_CHATMACRO3"},
  665. {&s_HUSTR_CHATMACRO4,"HUSTR_CHATMACRO4"},
  666. {&s_HUSTR_CHATMACRO5,"HUSTR_CHATMACRO5"},
  667. {&s_HUSTR_CHATMACRO6,"HUSTR_CHATMACRO6"},
  668. {&s_HUSTR_CHATMACRO7,"HUSTR_CHATMACRO7"},
  669. {&s_HUSTR_CHATMACRO8,"HUSTR_CHATMACRO8"},
  670. {&s_HUSTR_CHATMACRO9,"HUSTR_CHATMACRO9"},
  671. {&s_HUSTR_CHATMACRO0,"HUSTR_CHATMACRO0"},
  672. {&s_HUSTR_TALKTOSELF1,"HUSTR_TALKTOSELF1"},
  673. {&s_HUSTR_TALKTOSELF2,"HUSTR_TALKTOSELF2"},
  674. {&s_HUSTR_TALKTOSELF3,"HUSTR_TALKTOSELF3"},
  675. {&s_HUSTR_TALKTOSELF4,"HUSTR_TALKTOSELF4"},
  676. {&s_HUSTR_TALKTOSELF5,"HUSTR_TALKTOSELF5"},
  677. {&s_HUSTR_MESSAGESENT,"HUSTR_MESSAGESENT"},
  678. {&s_HUSTR_PLRGREEN,"HUSTR_PLRGREEN"},
  679. {&s_HUSTR_PLRINDIGO,"HUSTR_PLRINDIGO"},
  680. {&s_HUSTR_PLRBROWN,"HUSTR_PLRBROWN"},
  681. {&s_HUSTR_PLRRED,"HUSTR_PLRRED"},
  682. //{c_HUSTR_KEYGREEN,"HUSTR_KEYGREEN"},
  683. //{c_HUSTR_KEYINDIGO,"HUSTR_KEYINDIGO"},
  684. //{c_HUSTR_KEYBROWN,"HUSTR_KEYBROWN"},
  685. //{c_HUSTR_KEYRED,"HUSTR_KEYRED"},
  686. {&s_AMSTR_FOLLOWON,"AMSTR_FOLLOWON"},
  687. {&s_AMSTR_FOLLOWOFF,"AMSTR_FOLLOWOFF"},
  688. {&s_AMSTR_GRIDON,"AMSTR_GRIDON"},
  689. {&s_AMSTR_GRIDOFF,"AMSTR_GRIDOFF"},
  690. {&s_AMSTR_MARKEDSPOT,"AMSTR_MARKEDSPOT"},
  691. {&s_AMSTR_MARKSCLEARED,"AMSTR_MARKSCLEARED"},
  692. {&s_STSTR_MUS,"STSTR_MUS"},
  693. {&s_STSTR_NOMUS,"STSTR_NOMUS"},
  694. {&s_STSTR_DQDON,"STSTR_DQDON"},
  695. {&s_STSTR_DQDOFF,"STSTR_DQDOFF"},
  696. {&s_STSTR_KFAADDED,"STSTR_KFAADDED"},
  697. {&s_STSTR_FAADDED,"STSTR_FAADDED"},
  698. {&s_STSTR_NCON,"STSTR_NCON"},
  699. {&s_STSTR_NCOFF,"STSTR_NCOFF"},
  700. {&s_STSTR_BEHOLD,"STSTR_BEHOLD"},
  701. {&s_STSTR_BEHOLDX,"STSTR_BEHOLDX"},
  702. {&s_STSTR_CHOPPERS,"STSTR_CHOPPERS"},
  703. {&s_STSTR_CLEV,"STSTR_CLEV"},
  704. {&s_STSTR_COMPON,"STSTR_COMPON"},
  705. {&s_STSTR_COMPOFF,"STSTR_COMPOFF"},
  706. {&s_E1TEXT,"E1TEXT"},
  707. {&s_E2TEXT,"E2TEXT"},
  708. {&s_E3TEXT,"E3TEXT"},
  709. {&s_E4TEXT,"E4TEXT"},
  710. {&s_C1TEXT,"C1TEXT"},
  711. {&s_C2TEXT,"C2TEXT"},
  712. {&s_C3TEXT,"C3TEXT"},
  713. {&s_C4TEXT,"C4TEXT"},
  714. {&s_C5TEXT,"C5TEXT"},
  715. {&s_C6TEXT,"C6TEXT"},
  716. {&s_P1TEXT,"P1TEXT"},
  717. {&s_P2TEXT,"P2TEXT"},
  718. {&s_P3TEXT,"P3TEXT"},
  719. {&s_P4TEXT,"P4TEXT"},
  720. {&s_P5TEXT,"P5TEXT"},
  721. {&s_P6TEXT,"P6TEXT"},
  722. {&s_T1TEXT,"T1TEXT"},
  723. {&s_T2TEXT,"T2TEXT"},
  724. {&s_T3TEXT,"T3TEXT"},
  725. {&s_T4TEXT,"T4TEXT"},
  726. {&s_T5TEXT,"T5TEXT"},
  727. {&s_T6TEXT,"T6TEXT"},
  728. {&s_CC_ZOMBIE,"CC_ZOMBIE"},
  729. {&s_CC_SHOTGUN,"CC_SHOTGUN"},
  730. {&s_CC_HEAVY,"CC_HEAVY"},
  731. {&s_CC_IMP,"CC_IMP"},
  732. {&s_CC_DEMON,"CC_DEMON"},
  733. {&s_CC_LOST,"CC_LOST"},
  734. {&s_CC_CACO,"CC_CACO"},
  735. {&s_CC_HELL,"CC_HELL"},
  736. {&s_CC_BARON,"CC_BARON"},
  737. {&s_CC_ARACH,"CC_ARACH"},
  738. {&s_CC_PAIN,"CC_PAIN"},
  739. {&s_CC_REVEN,"CC_REVEN"},
  740. {&s_CC_MANCU,"CC_MANCU"},
  741. {&s_CC_ARCH,"CC_ARCH"},
  742. {&s_CC_SPIDER,"CC_SPIDER"},
  743. {&s_CC_CYBER,"CC_CYBER"},
  744. {&s_CC_HERO,"CC_HERO"},
  745. {&bgflatE1,"BGFLATE1"},
  746. {&bgflatE2,"BGFLATE2"},
  747. {&bgflatE3,"BGFLATE3"},
  748. {&bgflatE4,"BGFLATE4"},
  749. {&bgflat06,"BGFLAT06"},
  750. {&bgflat11,"BGFLAT11"},
  751. {&bgflat20,"BGFLAT20"},
  752. {&bgflat30,"BGFLAT30"},
  753. {&bgflat15,"BGFLAT15"},
  754. {&bgflat31,"BGFLAT31"},
  755. {&bgcastcall,"BGCASTCALL"},
  756. // Ty 04/08/98 - added 5 general purpose startup announcement
  757. // strings for hacker use. See m_menu.c
  758. {&startup1,"STARTUP1"},
  759. {&startup2,"STARTUP2"},
  760. {&startup3,"STARTUP3"},
  761. {&startup4,"STARTUP4"},
  762. {&startup5,"STARTUP5"},
  763. {&savegamename,"SAVEGAMENAME"}, // Ty 05/03/98
  764. };
  765. static int deh_numstrlookup =
  766. sizeof(deh_strlookup)/sizeof(deh_strlookup[0]);
  767. const char *deh_newlevel = "NEWLEVEL"; // CPhipps - const
  768. // DOOM shareware/registered/retail (Ultimate) names.
  769. // CPhipps - const**const
  770. const char **const mapnames[] =
  771. {
  772. &s_HUSTR_E1M1,
  773. &s_HUSTR_E1M2,
  774. &s_HUSTR_E1M3,
  775. &s_HUSTR_E1M4,
  776. &s_HUSTR_E1M5,
  777. &s_HUSTR_E1M6,
  778. &s_HUSTR_E1M7,
  779. &s_HUSTR_E1M8,
  780. &s_HUSTR_E1M9,
  781. &s_HUSTR_E2M1,
  782. &s_HUSTR_E2M2,
  783. &s_HUSTR_E2M3,
  784. &s_HUSTR_E2M4,
  785. &s_HUSTR_E2M5,
  786. &s_HUSTR_E2M6,
  787. &s_HUSTR_E2M7,
  788. &s_HUSTR_E2M8,
  789. &s_HUSTR_E2M9,
  790. &s_HUSTR_E3M1,
  791. &s_HUSTR_E3M2,
  792. &s_HUSTR_E3M3,
  793. &s_HUSTR_E3M4,
  794. &s_HUSTR_E3M5,
  795. &s_HUSTR_E3M6,
  796. &s_HUSTR_E3M7,
  797. &s_HUSTR_E3M8,
  798. &s_HUSTR_E3M9,
  799. &s_HUSTR_E4M1,
  800. &s_HUSTR_E4M2,
  801. &s_HUSTR_E4M3,
  802. &s_HUSTR_E4M4,
  803. &s_HUSTR_E4M5,
  804. &s_HUSTR_E4M6,
  805. &s_HUSTR_E4M7,
  806. &s_HUSTR_E4M8,
  807. &s_HUSTR_E4M9,
  808. &deh_newlevel, // spares? Unused.
  809. &deh_newlevel,
  810. &deh_newlevel,
  811. &deh_newlevel,
  812. &deh_newlevel,
  813. &deh_newlevel,
  814. &deh_newlevel,
  815. &deh_newlevel,
  816. &deh_newlevel
  817. };
  818. // CPhipps - const**const
  819. const char **const mapnames2[] = // DOOM 2 map names.
  820. {
  821. &s_HUSTR_1,
  822. &s_HUSTR_2,
  823. &s_HUSTR_3,
  824. &s_HUSTR_4,
  825. &s_HUSTR_5,
  826. &s_HUSTR_6,
  827. &s_HUSTR_7,
  828. &s_HUSTR_8,
  829. &s_HUSTR_9,
  830. &s_HUSTR_10,
  831. &s_HUSTR_11,
  832. &s_HUSTR_12,
  833. &s_HUSTR_13,
  834. &s_HUSTR_14,
  835. &s_HUSTR_15,
  836. &s_HUSTR_16,
  837. &s_HUSTR_17,
  838. &s_HUSTR_18,
  839. &s_HUSTR_19,
  840. &s_HUSTR_20,
  841. &s_HUSTR_21,
  842. &s_HUSTR_22,
  843. &s_HUSTR_23,
  844. &s_HUSTR_24,
  845. &s_HUSTR_25,
  846. &s_HUSTR_26,
  847. &s_HUSTR_27,
  848. &s_HUSTR_28,
  849. &s_HUSTR_29,
  850. &s_HUSTR_30,
  851. &s_HUSTR_31,
  852. &s_HUSTR_32,
  853. };
  854. // CPhipps - const**const
  855. const char **const mapnamesp[] = // Plutonia WAD map names.
  856. {
  857. &s_PHUSTR_1,
  858. &s_PHUSTR_2,
  859. &s_PHUSTR_3,
  860. &s_PHUSTR_4,
  861. &s_PHUSTR_5,
  862. &s_PHUSTR_6,
  863. &s_PHUSTR_7,
  864. &s_PHUSTR_8,
  865. &s_PHUSTR_9,
  866. &s_PHUSTR_10,
  867. &s_PHUSTR_11,
  868. &s_PHUSTR_12,
  869. &s_PHUSTR_13,
  870. &s_PHUSTR_14,
  871. &s_PHUSTR_15,
  872. &s_PHUSTR_16,
  873. &s_PHUSTR_17,
  874. &s_PHUSTR_18,
  875. &s_PHUSTR_19,
  876. &s_PHUSTR_20,
  877. &s_PHUSTR_21,
  878. &s_PHUSTR_22,
  879. &s_PHUSTR_23,
  880. &s_PHUSTR_24,
  881. &s_PHUSTR_25,
  882. &s_PHUSTR_26,
  883. &s_PHUSTR_27,
  884. &s_PHUSTR_28,
  885. &s_PHUSTR_29,
  886. &s_PHUSTR_30,
  887. &s_PHUSTR_31,
  888. &s_PHUSTR_32,
  889. };
  890. // CPhipps - const**const
  891. const char **const mapnamest[] = // TNT WAD map names.
  892. {
  893. &s_THUSTR_1,
  894. &s_THUSTR_2,
  895. &s_THUSTR_3,
  896. &s_THUSTR_4,
  897. &s_THUSTR_5,
  898. &s_THUSTR_6,
  899. &s_THUSTR_7,
  900. &s_THUSTR_8,
  901. &s_THUSTR_9,
  902. &s_THUSTR_10,
  903. &s_THUSTR_11,
  904. &s_THUSTR_12,
  905. &s_THUSTR_13,
  906. &s_THUSTR_14,
  907. &s_THUSTR_15,
  908. &s_THUSTR_16,
  909. &s_THUSTR_17,
  910. &s_THUSTR_18,
  911. &s_THUSTR_19,
  912. &s_THUSTR_20,
  913. &s_THUSTR_21,
  914. &s_THUSTR_22,
  915. &s_THUSTR_23,
  916. &s_THUSTR_24,
  917. &s_THUSTR_25,
  918. &s_THUSTR_26,
  919. &s_THUSTR_27,
  920. &s_THUSTR_28,
  921. &s_THUSTR_29,
  922. &s_THUSTR_30,
  923. &s_THUSTR_31,
  924. &s_THUSTR_32,
  925. };
  926. // Function prototypes
  927. void lfstrip(char *); // strip the \r and/or \n off of a line
  928. void rstrip(char *); // strip trailing whitespace
  929. char * ptr_lstrip(char *); // point past leading whitespace
  930. boolean deh_GetData(char *, char *, uint_64_t *, char **, FILE *);
  931. boolean deh_procStringSub(char *, char *, char *, FILE *);
  932. char * dehReformatStr(char *);
  933. // Prototypes for block processing functions
  934. // Pointers to these functions are used as the blocks are encountered.
  935. static void deh_procThing(DEHFILE *fpin, FILE* fpout, char *line);
  936. static void deh_procFrame(DEHFILE *, FILE*, char *);
  937. static void deh_procPointer(DEHFILE *, FILE*, char *);
  938. static void deh_procSounds(DEHFILE *, FILE*, char *);
  939. static void deh_procAmmo(DEHFILE *, FILE*, char *);
  940. static void deh_procWeapon(DEHFILE *, FILE*, char *);
  941. static void deh_procSprite(DEHFILE *, FILE*, char *);
  942. static void deh_procCheat(DEHFILE *, FILE*, char *);
  943. static void deh_procMisc(DEHFILE *, FILE*, char *);
  944. static void deh_procText(DEHFILE *, FILE*, char *);
  945. static void deh_procPars(DEHFILE *, FILE*, char *);
  946. static void deh_procStrings(DEHFILE *, FILE*, char *);
  947. static void deh_procError(DEHFILE *, FILE*, char *);
  948. static void deh_procBexCodePointers(DEHFILE *, FILE*, char *);
  949. static void deh_procHelperThing(DEHFILE *, FILE *, char *); // haleyjd 9/22/99
  950. // haleyjd: handlers to fully deprecate the DeHackEd text section
  951. static void deh_procBexSounds(DEHFILE *, FILE *, char *);
  952. static void deh_procBexMusic(DEHFILE *, FILE *, char *);
  953. static void deh_procBexSprites(DEHFILE *, FILE *, char *);
  954. // Structure deh_block is used to hold the block names that can
  955. // be encountered, and the routines to use to decipher them
  956. typedef struct
  957. {
  958. const char *key; // a mnemonic block code name // CPhipps - const*
  959. void (*const fptr)(DEHFILE *, FILE*, char *); // handler
  960. } deh_block;
  961. #define DEH_BUFFERMAX 1024 // input buffer area size, hardcodedfor now
  962. // killough 8/9/98: make DEH_BLOCKMAX self-adjusting
  963. #define DEH_BLOCKMAX (sizeof deh_blocks/sizeof*deh_blocks) // size of array
  964. #define DEH_MAXKEYLEN 32 // as much of any key as we'll look at
  965. #define DEH_MOBJINFOMAX 24 // number of ints in the mobjinfo_t structure (!)
  966. // Put all the block header values, and the function to be called when that
  967. // one is encountered, in this array:
  968. static const deh_block deh_blocks[] = { // CPhipps - static const
  969. /* 0 */ {"Thing",deh_procThing},
  970. /* 1 */ {"Frame",deh_procFrame},
  971. /* 2 */ {"Pointer",deh_procPointer},
  972. /* 3 */ {"Sound",deh_procSounds}, // Ty 03/16/98 corrected from "Sounds"
  973. /* 4 */ {"Ammo",deh_procAmmo},
  974. /* 5 */ {"Weapon",deh_procWeapon},
  975. /* 6 */ {"Sprite",deh_procSprite},
  976. /* 7 */ {"Cheat",deh_procCheat},
  977. /* 8 */ {"Misc",deh_procMisc},
  978. /* 9 */ {"Text",deh_procText}, // -- end of standard "deh" entries,
  979. // begin BOOM Extensions (BEX)
  980. /* 10 */ {"[STRINGS]",deh_procStrings}, // new string changes
  981. /* 11 */ {"[PARS]",deh_procPars}, // alternative block marker
  982. /* 12 */ {"[CODEPTR]",deh_procBexCodePointers}, // bex codepointers by mnemonic
  983. /* 13 */ {"[HELPER]", deh_procHelperThing}, // helper thing substitution haleyjd 9/22/99
  984. /* 14 */ {"[SPRITES]", deh_procBexSprites}, // bex style sprites
  985. /* 15 */ {"[SOUNDS]", deh_procBexSounds}, // bex style sounds
  986. /* 16 */ {"[MUSIC]", deh_procBexMusic}, // bex style music
  987. /* 17 */ {"", deh_procError} // dummy to handle anything else
  988. };
  989. // flag to skip included deh-style text, used with INCLUDE NOTEXT directive
  990. static boolean includenotext = false;
  991. // MOBJINFO - Dehacked block name = "Thing"
  992. // Usage: Thing nn (name)
  993. // These are for mobjinfo_t types. Each is an integer
  994. // within the structure, so we can use index of the string in this
  995. // array to offset by sizeof(int) into the mobjinfo_t array at [nn]
  996. // * things are base zero but dehacked considers them to start at #1. ***
  997. // CPhipps - static const
  998. static const char *deh_mobjinfo[DEH_MOBJINFOMAX] =
  999. {
  1000. "ID #", // .doomednum
  1001. "Initial frame", // .spawnstate
  1002. "Hit points", // .spawnhealth
  1003. "First moving frame", // .seestate
  1004. "Alert sound", // .seesound
  1005. "Reaction time", // .reactiontime
  1006. "Attack sound", // .attacksound
  1007. "Injury frame", // .painstate
  1008. "Pain chance", // .painchance
  1009. "Pain sound", // .painsound
  1010. "Close attack frame", // .meleestate
  1011. "Far attack frame", // .missilestate
  1012. "Death frame", // .deathstate
  1013. "Exploding frame", // .xdeathstate
  1014. "Death sound", // .deathsound
  1015. "Speed", // .speed
  1016. "Width", // .radius
  1017. "Height", // .height
  1018. "Mass", // .mass
  1019. "Missile damage", // .damage
  1020. "Action sound", // .activesound
  1021. "Bits", // .flags
  1022. "Bits2", // .flags
  1023. "Respawn frame" // .raisestate
  1024. };
  1025. // Strings that are used to indicate flags ("Bits" in mobjinfo)
  1026. // This is an array of bit masks that are related to p_mobj.h
  1027. // values, using the smae names without the MF_ in front.
  1028. // Ty 08/27/98 new code
  1029. //
  1030. // killough 10/98:
  1031. //
  1032. // Convert array to struct to allow multiple values, make array size variable
  1033. #define DEH_MOBJFLAGMAX (sizeof deh_mobjflags/sizeof*deh_mobjflags)
  1034. struct deh_mobjflags_s {
  1035. const char *name; // CPhipps - const*
  1036. uint_64_t value;
  1037. };
  1038. // CPhipps - static const
  1039. static const struct deh_mobjflags_s deh_mobjflags[] = {
  1040. {"SPECIAL", MF_SPECIAL}, // call P_Specialthing when touched
  1041. {"SOLID", MF_SOLID}, // block movement
  1042. {"SHOOTABLE", MF_SHOOTABLE}, // can be hit
  1043. {"NOSECTOR", MF_NOSECTOR}, // invisible but touchable
  1044. {"NOBLOCKMAP", MF_NOBLOCKMAP}, // inert but displayable
  1045. {"AMBUSH", MF_AMBUSH}, // deaf monster
  1046. {"JUSTHIT", MF_JUSTHIT}, // will try to attack right back
  1047. {"JUSTATTACKED", MF_JUSTATTACKED}, // take at least 1 step before attacking
  1048. {"SPAWNCEILING", MF_SPAWNCEILING}, // initially hang from ceiling
  1049. {"NOGRAVITY", MF_NOGRAVITY}, // don't apply gravity during play
  1050. {"DROPOFF", MF_DROPOFF}, // can jump from high places
  1051. {"PICKUP", MF_PICKUP}, // will pick up items
  1052. {"NOCLIP", MF_NOCLIP}, // goes through walls
  1053. {"SLIDE", MF_SLIDE}, // keep info about sliding along walls
  1054. {"FLOAT", MF_FLOAT}, // allow movement to any height
  1055. {"TELEPORT", MF_TELEPORT}, // don't cross lines or look at heights
  1056. {"MISSILE", MF_MISSILE}, // don't hit same species, explode on block
  1057. {"DROPPED", MF_DROPPED}, // dropped, not spawned (like ammo clip)
  1058. {"SHADOW", MF_SHADOW}, // use fuzzy draw like spectres
  1059. {"NOBLOOD", MF_NOBLOOD}, // puffs instead of blood when shot
  1060. {"CORPSE", MF_CORPSE}, // so it will slide down steps when dead
  1061. {"INFLOAT", MF_INFLOAT}, // float but not to target height
  1062. {"COUNTKILL", MF_COUNTKILL}, // count toward the kills total
  1063. {"COUNTITEM", MF_COUNTITEM}, // count toward the items total
  1064. {"SKULLFLY", MF_SKULLFLY}, // special handling for flying skulls
  1065. {"NOTDMATCH", MF_NOTDMATCH}, // do not spawn in deathmatch
  1066. // killough 10/98: TRANSLATION consists of 2 bits, not 1:
  1067. {"TRANSLATION", MF_TRANSLATION1}, // for Boom bug-compatibility
  1068. {"TRANSLATION1", MF_TRANSLATION1}, // use translation table for color (players)
  1069. {"TRANSLATION2", MF_TRANSLATION2}, // use translation table for color (players)
  1070. {"UNUSED1", MF_TRANSLATION2}, // unused bit # 1 -- For Boom bug-compatibility
  1071. {"UNUSED2", MF_UNUSED2}, // unused bit # 2 -- For Boom compatibility
  1072. {"UNUSED3", MF_UNUSED3}, // unused bit # 3 -- For Boom compatibility
  1073. {"UNUSED4", MF_TRANSLUCENT}, // unused bit # 4 -- For Boom compatibility
  1074. {"TRANSLUCENT", MF_TRANSLUCENT}, // apply translucency to sprite (BOOM)
  1075. {"TOUCHY", MF_TOUCHY}, // dies on contact with solid objects (MBF)
  1076. {"BOUNCES", MF_BOUNCES}, // bounces off floors, ceilings and maybe walls (MBF)
  1077. {"FRIEND", MF_FRIEND}, // a friend of the player(s) (MBF)
  1078. };
  1079. // STATE - Dehacked block name = "Frame" and "Pointer"
  1080. // Usage: Frame nn
  1081. // Usage: Pointer nn (Frame nn)
  1082. // These are indexed separately, for lookup to the actual
  1083. // function pointers. Here we'll take whatever Dehacked gives
  1084. // us and go from there. The (Frame nn) after the pointer is the
  1085. // real place to put this value. The "Pointer" value is an xref
  1086. // that Dehacked uses and is useless to us.
  1087. // * states are base zero and have a dummy #0 (TROO)
  1088. static const char *deh_state[] = // CPhipps - static const*
  1089. {
  1090. "Sprite number", // .sprite (spritenum_t) // an enum
  1091. "Sprite subnumber", // .frame (long)
  1092. "Duration", // .tics (long)
  1093. "Next frame", // .nextstate (statenum_t)
  1094. // This is set in a separate "Pointer" block from Dehacked
  1095. "Codep Frame", // pointer to first use of action (actionf_t)
  1096. "Unknown 1", // .misc1 (long)
  1097. "Unknown 2" // .misc2 (long)
  1098. };
  1099. // SFXINFO_STRUCT - Dehacked block name = "Sounds"
  1100. // Sound effects, typically not changed (redirected, and new sfx put
  1101. // into the pwad, but not changed here. Can you tell that Gregdidn't
  1102. // know what they were for, mostly? Can you tell that I don't either?
  1103. // Mostly I just put these into the same slots as they are in the struct.
  1104. // This may not be supported in our -deh option if it doesn't make sense by then.
  1105. // * sounds are base zero but have a dummy #0
  1106. static const char *deh_sfxinfo[] = // CPhipps - static const*
  1107. {
  1108. "Offset", // pointer to a name string, changed in text
  1109. "Zero/One", // .singularity (int, one at a time flag)
  1110. "Value", // .priority
  1111. "Zero 1", // .link (sfxinfo_t*) referenced sound if linked
  1112. "Zero 2", // .pitch
  1113. "Zero 3", // .volume
  1114. "Zero 4", // .data (SAMPLE*) sound data
  1115. "Neg. One 1", // .usefulness
  1116. "Neg. One 2" // .lumpnum
  1117. };
  1118. // MUSICINFO is not supported in Dehacked. Ignored here.
  1119. // * music entries are base zero but have a dummy #0
  1120. // SPRITE - Dehacked block name = "Sprite"
  1121. // Usage = Sprite nn
  1122. // Sprite redirection by offset into the text area - unsupported by BOOM
  1123. // * sprites are base zero and dehacked uses it that way.
  1124. // static const char *deh_sprite[] = // CPhipps - static const*
  1125. // {
  1126. // "Offset" // supposed to be the offset into the text section
  1127. // };
  1128. // AMMO - Dehacked block name = "Ammo"
  1129. // usage = Ammo n (name)
  1130. // Ammo information for the few types of ammo
  1131. static const char *deh_ammo[] = // CPhipps - static const*
  1132. {
  1133. "Max ammo", // maxammo[]
  1134. "Per ammo" // clipammo[]
  1135. };
  1136. // WEAPONS - Dehacked block name = "Weapon"
  1137. // Usage: Weapon nn (name)
  1138. // Basically a list of frames and what kind of ammo (see above)it uses.
  1139. static const char *deh_weapon[] = // CPhipps - static const*
  1140. {
  1141. "Ammo type", // .ammo
  1142. "Deselect frame", // .upstate
  1143. "Select frame", // .downstate
  1144. "Bobbing frame", // .readystate
  1145. "Shooting frame", // .atkstate
  1146. "Firing frame" // .flashstate
  1147. };
  1148. // CHEATS - Dehacked block name = "Cheat"
  1149. // Usage: Cheat 0
  1150. // Always uses a zero in the dehacked file, for consistency. No meaning.
  1151. // These are just plain funky terms compared with id's
  1152. //
  1153. // killough 4/18/98: integrated into main cheat table now (see st_stuff.c)
  1154. // MISC - Dehacked block name = "Misc"
  1155. // Usage: Misc 0
  1156. // Always uses a zero in the dehacked file, for consistency. No meaning.
  1157. static const char *deh_misc[] = // CPhipps - static const*
  1158. {
  1159. "Initial Health", // initial_health
  1160. "Initial Bullets", // initial_bullets
  1161. "Max Health", // maxhealth
  1162. "Max Armor", // max_armor
  1163. "Green Armor Class", // green_armor_class
  1164. "Blue Armor Class", // blue_armor_class
  1165. "Max Soulsphere", // max_soul
  1166. "Soulsphere Health", // soul_health
  1167. "Megasphere Health", // mega_health
  1168. "God Mode Health", // god_health
  1169. "IDFA Armor", // idfa_armor
  1170. "IDFA Armor Class", // idfa_armor_class
  1171. "IDKFA Armor", // idkfa_armor
  1172. "IDKFA Armor Class", // idkfa_armor_class
  1173. "BFG Cells/Shot", // BFGCELLS
  1174. "Monsters Infight" // Unknown--not a specific number it seems, but
  1175. // the logic has to be here somewhere or
  1176. // it'd happen always
  1177. };
  1178. // TEXT - Dehacked block name = "Text"
  1179. // Usage: Text fromlen tolen
  1180. // Dehacked allows a bit of adjustment to the length (why?)
  1181. // BEX extension [CODEPTR]
  1182. // Usage: Start block, then each line is:
  1183. // FRAME nnn = PointerMnemonic
  1184. typedef struct {
  1185. actionf_t cptr; // actual pointer to the subroutine
  1186. const char *lookup; // mnemonic lookup string to be specified in BEX
  1187. // CPhipps - const*
  1188. } deh_bexptr;
  1189. static const deh_bexptr deh_bexptrs[] = // CPhipps - static const
  1190. {
  1191. {A_Light0, "A_Light0"},
  1192. {A_WeaponReady, "A_WeaponReady"},
  1193. {A_Lower, "A_Lower"},
  1194. {A_Raise, "A_Raise"},
  1195. {A_Punch, "A_Punch"},
  1196. {A_ReFire, "A_ReFire"},
  1197. {A_FirePistol, "A_FirePistol"},
  1198. {A_Light1, "A_Light1"},
  1199. {A_FireShotgun, "A_FireShotgun"},
  1200. {A_Light2, "A_Light2"},
  1201. {A_FireShotgun2, "A_FireShotgun2"},
  1202. {A_CheckReload, "A_CheckReload"},
  1203. {A_OpenShotgun2, "A_OpenShotgun2"},
  1204. {A_LoadShotgun2, "A_LoadShotgun2"},
  1205. {A_CloseShotgun2, "A_CloseShotgun2"},
  1206. {A_FireCGun, "A_FireCGun"},
  1207. {A_GunFlash, "A_GunFlash"},
  1208. {A_FireMissile, "A_FireMissile"},
  1209. {A_Saw, "A_Saw"},
  1210. {A_FirePlasma, "A_FirePlasma"},
  1211. {A_BFGsound, "A_BFGsound"},
  1212. {A_FireBFG, "A_FireBFG"},
  1213. {A_BFGSpray, "A_BFGSpray"},
  1214. {A_Explode, "A_Explode"},
  1215. {A_Pain, "A_Pain"},
  1216. {A_PlayerScream, "A_PlayerScream"},
  1217. {A_Fall, "A_Fall"},
  1218. {A_XScream, "A_XScream"},
  1219. {A_Look, "A_Look"},
  1220. {A_Chase, "A_Chase"},
  1221. {A_FaceTarget, "A_FaceTarget"},
  1222. {A_PosAttack, "A_PosAttack"},
  1223. {A_Scream, "A_Scream"},
  1224. {A_SPosAttack, "A_SPosAttack"},
  1225. {A_VileChase, "A_VileChase"},
  1226. {A_VileStart, "A_VileStart"},
  1227. {A_VileTarget, "A_VileTarget"},
  1228. {A_VileAttack, "A_VileAttack"},
  1229. {A_StartFire, "A_StartFire"},
  1230. {A_Fire, "A_Fire"},
  1231. {A_FireCrackle, "A_FireCrackle"},
  1232. {A_Tracer, "A_Tracer"},
  1233. {A_SkelWhoosh, "A_SkelWhoosh"},
  1234. {A_SkelFist, "A_SkelFist"},
  1235. {A_SkelMissile, "A_SkelMissile"},
  1236. {A_FatRaise, "A_FatRaise"},
  1237. {A_FatAttack1, "A_FatAttack1"},
  1238. {A_FatAttack2, "A_FatAttack2"},
  1239. {A_FatAttack3, "A_FatAttack3"},
  1240. {A_BossDeath, "A_BossDeath"},
  1241. {A_CPosAttack, "A_CPosAttack"},
  1242. {A_CPosRefire, "A_CPosRefire"},
  1243. {A_TroopAttack, "A_TroopAttack"},
  1244. {A_SargAttack, "A_SargAttack"},
  1245. {A_HeadAttack, "A_HeadAttack"},
  1246. {A_BruisAttack, "A_BruisAttack"},
  1247. {A_SkullAttack, "A_SkullAttack"},
  1248. {A_Metal, "A_Metal"},
  1249. {A_SpidRefire, "A_SpidRefire"},
  1250. {A_BabyMetal, "A_BabyMetal"},
  1251. {A_BspiAttack, "A_BspiAttack"},
  1252. {A_Hoof, "A_Hoof"},
  1253. {A_CyberAttack, "A_CyberAttack"},
  1254. {A_PainAttack, "A_PainAttack"},
  1255. {A_PainDie, "A_PainDie"},
  1256. {A_KeenDie, "A_KeenDie"},
  1257. {A_BrainPain, "A_BrainPain"},
  1258. {A_BrainScream, "A_BrainScream"},
  1259. {A_BrainDie, "A_BrainDie"},
  1260. {A_BrainAwake, "A_BrainAwake"},
  1261. {A_BrainSpit, "A_BrainSpit"},
  1262. {A_SpawnSound, "A_SpawnSound"},
  1263. {A_SpawnFly, "A_SpawnFly"},
  1264. {A_BrainExplode, "A_BrainExplode"},
  1265. {A_Detonate, "A_Detonate"}, // killough 8/9/98
  1266. {A_Mushroom, "A_Mushroom"}, // killough 10/98
  1267. {A_Die, "A_Die"}, // killough 11/98
  1268. {A_Spawn, "A_Spawn"}, // killough 11/98
  1269. {A_Turn, "A_Turn"}, // killough 11/98
  1270. {A_Face, "A_Face"}, // killough 11/98
  1271. {A_Scratch, "A_Scratch"}, // killough 11/98
  1272. {A_PlaySound, "A_PlaySound"}, // killough 11/98
  1273. {A_RandomJump, "A_RandomJump"}, // killough 11/98
  1274. {A_LineEffect, "A_LineEffect"}, // killough 11/98
  1275. // This NULL entry must be the last in the list
  1276. {NULL, "A_NULL"}, // Ty 05/16/98
  1277. };
  1278. // to hold startup code pointers from INFO.C
  1279. // CPhipps - static
  1280. static actionf_t deh_codeptr[NUMSTATES];
  1281. // haleyjd: support for BEX SPRITES, SOUNDS, and MUSIC
  1282. char *deh_spritenames[NUMSPRITES + 1];
  1283. char *deh_musicnames[NUMMUSIC + 1];
  1284. char *deh_soundnames[NUMSFX + 1];
  1285. void D_BuildBEXTables(void)
  1286. {
  1287. int i;
  1288. // moved from ProcessDehFile, then we don't need the static int i
  1289. for (i = 0; i < NUMSTATES; i++) // remember what they start as for deh xref
  1290. deh_codeptr[i] = states[i].action;
  1291. for(i = 0; i < NUMSPRITES; i++)
  1292. deh_spritenames[i] = strdup(sprnames[i]);
  1293. deh_spritenames[NUMSPRITES] = NULL;
  1294. for(i = 1; i < NUMMUSIC; i++)
  1295. deh_musicnames[i] = strdup(S_music[i].name);
  1296. deh_musicnames[0] = deh_musicnames[NUMMUSIC] = NULL;
  1297. for(i = 1; i < NUMSFX; i++)
  1298. deh_soundnames[i] = strdup(S_sfx[i].name);
  1299. deh_soundnames[0] = deh_soundnames[NUMSFX] = NULL;
  1300. }
  1301. // ====================================================================
  1302. // ProcessDehFile
  1303. // Purpose: Read and process a DEH or BEX file
  1304. // Args: filename -- name of the DEH/BEX file
  1305. // outfilename -- output file (DEHOUT.TXT), appended to here
  1306. // Returns: void
  1307. //
  1308. // killough 10/98:
  1309. // substantially modified to allow input from wad lumps instead of .deh files.
  1310. void ProcessDehFile(const char *filename, const char *outfilename, int lumpnum)
  1311. {
  1312. static FILE *fileout; // In case -dehout was used
  1313. DEHFILE infile, *filein = &infile; // killough 10/98
  1314. char inbuffer[DEH_BUFFERMAX]; // Place to put the primary infostring
  1315. // Open output file if we're writing output
  1316. if (outfilename && *outfilename && !fileout)
  1317. {
  1318. static boolean firstfile = true; // to allow append to output log
  1319. if (!strcmp(outfilename, "-"))
  1320. fileout = stdout;
  1321. else
  1322. if (!(fileout=fopen(outfilename, firstfile ? "wt" : "at")))
  1323. {
  1324. lprintf(LO_WARN, "Could not open -dehout file %s\n... using stdout.\n",
  1325. outfilename);
  1326. fileout = stdout;
  1327. }
  1328. firstfile = false;
  1329. }
  1330. // killough 10/98: allow DEH files to come from wad lumps
  1331. if (filename)
  1332. {
  1333. if (!(infile.f = fopen(filename,"rt")))
  1334. {
  1335. lprintf(LO_WARN, "-deh file %s not found\n",filename);
  1336. return; // should be checked up front anyway
  1337. }
  1338. infile.lump = NULL;
  1339. }
  1340. else // DEH file comes from lump indicated by third argument
  1341. {
  1342. infile.size = W_LumpLength(lumpnum);
  1343. infile.inp = infile.lump = W_CacheLumpNum(lumpnum);
  1344. filename = "(WAD)";
  1345. }
  1346. lprintf(LO_INFO, "Loading DEH file %s\n",filename);
  1347. if (fileout) fprintf(fileout,"\nLoading DEH file %s\n\n",filename);
  1348. // move deh_codeptr initialisation to D_BuildBEXTables
  1349. // loop until end of file
  1350. while (dehfgets(inbuffer,sizeof(inbuffer),filein))
  1351. {
  1352. unsigned i;
  1353. lfstrip(inbuffer);
  1354. if (fileout) fprintf(fileout,"Line='%s'\n",inbuffer);
  1355. if (!*inbuffer || *inbuffer == '#' || *inbuffer == ' ')
  1356. continue; /* Blank line or comment line */
  1357. // -- If DEH_BLOCKMAX is set right, the processing is independently
  1358. // -- handled based on data in the deh_blocks[] structure array
  1359. // killough 10/98: INCLUDE code rewritten to allow arbitrary nesting,
  1360. // and to greatly simplify code, fix memory leaks, other bugs
  1361. if (!strnicmp(inbuffer,"INCLUDE",7)) // include a file
  1362. {
  1363. // preserve state while including a file
  1364. // killough 10/98: moved to here
  1365. char *nextfile;
  1366. boolean oldnotext = includenotext; // killough 10/98
  1367. // killough 10/98: exclude if inside wads (only to discourage
  1368. // the practice, since the code could otherwise handle it)
  1369. if (infile.lump)
  1370. {
  1371. if (fileout)
  1372. fprintf(fileout,
  1373. "No files may be included from wads: %s\n",inbuffer);
  1374. continue;
  1375. }
  1376. // check for no-text directive, used when including a DEH
  1377. // file but using the BEX format to handle strings
  1378. if (!strnicmp(nextfile = ptr_lstrip(inbuffer+7),"NOTEXT",6))
  1379. includenotext = true, nextfile = ptr_lstrip(nextfile+6);
  1380. if (fileout)
  1381. fprintf(fileout,"Branching to include file %s...\n", nextfile);
  1382. // killough 10/98:
  1383. // Second argument must be NULL to prevent closing fileout too soon
  1384. ProcessDehFile(nextfile,NULL,0); // do the included file
  1385. includenotext = oldnotext;
  1386. if (fileout) fprintf(fileout,"...continuing with %s\n",filename);
  1387. continue;
  1388. }
  1389. for (i=0; i<DEH_BLOCKMAX; i++)
  1390. if (!strncasecmp(inbuffer,deh_blocks[i].key,strlen(deh_blocks[i].key)))
  1391. { // matches one
  1392. if (fileout)
  1393. fprintf(fileout,"Processing function [%d] for %s\n",
  1394. i, deh_blocks[i].key);
  1395. deh_blocks[i].fptr(filein,fileout,inbuffer); // call function
  1396. break; // we got one, that's enough for this block
  1397. }
  1398. }
  1399. if (infile.lump)
  1400. W_UnlockLumpNum(lumpnum); // Mark purgable
  1401. else
  1402. fclose(infile.f); // Close real file
  1403. if (outfilename) // killough 10/98: only at top recursion level
  1404. {
  1405. if (fileout != stdout)
  1406. fclose(fileout);
  1407. fileout = NULL;
  1408. }
  1409. }
  1410. // ====================================================================
  1411. // deh_procBexCodePointers
  1412. // Purpose: Handle [CODEPTR] block, BOOM Extension
  1413. // Args: fpin -- input file stream
  1414. // fpout -- output file stream (DEHOUT.TXT)
  1415. // line -- current line in file to process
  1416. // Returns: void
  1417. //
  1418. static void deh_procBexCodePointers(DEHFILE *fpin, FILE* fpout, char *line)
  1419. {
  1420. char key[DEH_MAXKEYLEN];
  1421. char inbuffer[DEH_BUFFERMAX];
  1422. int indexnum;
  1423. char mnemonic[DEH_MAXKEYLEN]; // to hold the codepointer mnemonic
  1424. int i; // looper
  1425. boolean found; // know if we found this one during lookup or not
  1426. // Ty 05/16/98 - initialize it to something, dummy!
  1427. strncpy(inbuffer,line,DEH_BUFFERMAX);
  1428. // for this one, we just read 'em until we hit a blank line
  1429. while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
  1430. {
  1431. if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
  1432. lfstrip(inbuffer);
  1433. if (!*inbuffer) break; // killough 11/98: really exit on blank line
  1434. // killough 8/98: allow hex numbers in input:
  1435. if ( (3 != sscanf(inbuffer,"%s %i = %s", key, &indexnum, mnemonic))
  1436. || (stricmp(key,"FRAME")) ) // NOTE: different format from normal
  1437. {
  1438. if (fpout) fprintf(fpout,
  1439. "Invalid BEX codepointer line - must start with 'FRAME': '%s'\n",
  1440. inbuffer);
  1441. return; // early return
  1442. }
  1443. if (fpout) fprintf(fpout,"Processing pointer at index %d: %s\n",
  1444. indexnum, mnemonic);
  1445. if (indexnum < 0 || indexnum >= NUMSTATES)
  1446. {
  1447. if (fpout) fprintf(fpout,"Bad pointer number %d of %d\n",
  1448. indexnum, NUMSTATES);
  1449. return; // killough 10/98: fix SegViol
  1450. }
  1451. strcpy(key,"A_"); // reusing the key area to prefix the mnemonic
  1452. strcat(key,ptr_lstrip(mnemonic));
  1453. found = FALSE;
  1454. i= -1; // incremented to start at zero at the top of the loop
  1455. do // Ty 05/16/98 - fix loop logic to look for null ending entry
  1456. {
  1457. ++i;
  1458. if (!stricmp(key,deh_bexptrs[i].lookup))
  1459. { // Ty 06/01/98 - add to states[].action for new djgcc version
  1460. states[indexnum].action = deh_bexptrs[i].cptr; // assign
  1461. if (fpout) fprintf(fpout,
  1462. " - applied %s from codeptr[%d] to states[%d]\n",
  1463. deh_bexptrs[i].lookup,i,indexnum);
  1464. found = TRUE;
  1465. }
  1466. } while (!found && (deh_bexptrs[i].cptr != NULL));
  1467. if (!found)
  1468. if (fpout) fprintf(fpout,
  1469. "Invalid frame pointer mnemonic '%s' at %d\n",
  1470. mnemonic, indexnum);
  1471. }
  1472. return;
  1473. }
  1474. //---------------------------------------------------------------------------
  1475. // To be on the safe, compatible side, we manually convert DEH bitflags
  1476. // to prboom types - POPE
  1477. //---------------------------------------------------------------------------
  1478. static uint_64_t getConvertedDEHBits(uint_64_t bits) {
  1479. static const uint_64_t bitMap[32] = {
  1480. /* cf linuxdoom-1.10 p_mobj.h */
  1481. MF_SPECIAL, // 0 Can be picked up - When touched the thing can be picked up.
  1482. MF_SOLID, // 1 Obstacle - The thing is solid and will not let you (or others) pass through it
  1483. MF_SHOOTABLE, // 2 Shootable - Can be shot.
  1484. MF_NOSECTOR, // 3 Total Invisibility - Invisible, but can be touched
  1485. MF_NOBLOCKMAP, // 4 Don't use the blocklinks (inert but displayable)
  1486. MF_AMBUSH, // 5 Semi deaf - The thing is a deaf monster
  1487. MF_JUSTHIT, // 6 In pain - Will try to attack right back after being hit
  1488. MF_JUSTATTACKED, // 7 Steps before attack - Will take at least one step before attacking
  1489. MF_SPAWNCEILING, // 8 Hangs from ceiling - When the level starts, this thing will be at ceiling height.
  1490. MF_NOGRAVITY, // 9 No gravity - Gravity does not affect this thing
  1491. MF_DROPOFF, // 10 Travels over cliffs - Monsters normally do not walk off ledges/steps they could not walk up. With this set they can walk off any height of cliff. Usually only used for flying monsters.
  1492. MF_PICKUP, // 11 Pick up items - The thing can pick up gettable items.
  1493. MF_NOCLIP, // 12 No clipping - Thing can walk through walls.
  1494. MF_SLIDE, // 13 Slides along walls - Keep info about sliding along walls (don't really know much about this one).
  1495. MF_FLOAT, // 14 Floating - Thing can move to any height
  1496. MF_TELEPORT, // 15 Semi no clipping - Don't cross lines or look at teleport heights. (don't really know much about this one either).
  1497. MF_MISSILE, // 16 Projectiles - Behaves like a projectile, explodes when hitting something that blocks movement
  1498. MF_DROPPED, // 17 Disappearing weapon - Dropped, not spawned (like an ammo clip) I have not had much success in using this one.
  1499. MF_SHADOW, // 18 Partial invisibility - Drawn like a spectre.
  1500. MF_NOBLOOD, // 19 Puffs (vs. bleeds) - If hit will spawn bullet puffs instead of blood splats.
  1501. MF_CORPSE, // 20 Sliding helpless - Will slide down steps when dead.
  1502. MF_INFLOAT, // 21 No auto levelling - float but not to target height (?)
  1503. MF_COUNTKILL, // 22 Affects kill % - counted as a killable enemy and affects percentage kills on level summary.
  1504. MF_COUNTITEM, // 23 Affects item % - affects percentage items gathered on level summary.
  1505. MF_SKULLFLY, // 24 Running - special handling for flying skulls.
  1506. MF_NOTDMATCH, // 25 Not in deathmatch - do not spawn in deathmatch (like keys)
  1507. MF_TRANSLATION1, // 26 Color 1 (grey / red)
  1508. MF_TRANSLATION2, // 27 Color 2 (brown / red)
  1509. // Convert bit 28 to MF_TOUCHY, not (MF_TRANSLATION1|MF_TRANSLATION2)
  1510. // fixes bug #1576151 (part 1)
  1511. MF_TOUCHY, // 28 - explodes on contact (MBF)
  1512. MF_BOUNCES, // 29 - bounces off walls and floors (MBF)
  1513. MF_FRIEND, // 30 - friendly monster helps players (MBF)
  1514. MF_TRANSLUCENT // e6y: Translucency via dehacked/bex doesn't work without it
  1515. };
  1516. int i;
  1517. uint_64_t shiftBits = bits;
  1518. uint_64_t convertedBits = 0;
  1519. for (i=0; i<32; i++) {
  1520. if (shiftBits & 0x1) convertedBits |= bitMap[i];
  1521. shiftBits >>= 1;
  1522. }
  1523. return convertedBits;
  1524. }
  1525. //---------------------------------------------------------------------------
  1526. // See usage below for an explanation of this function's existence - POPE
  1527. //---------------------------------------------------------------------------
  1528. static void setMobjInfoValue(int mobjInfoIndex, int keyIndex, uint_64_t value) {
  1529. mobjinfo_t *mi;
  1530. if (mobjInfoIndex >= NUMMOBJTYPES || mobjInfoIndex < 0) return;
  1531. mi = &mobjinfo[mobjInfoIndex];
  1532. switch (keyIndex) {
  1533. case 0: mi->doomednum = (int)value; return;
  1534. case 1: mi->spawnstate = (int)value; return;
  1535. case 2: mi->spawnhealth = (int)value; return;
  1536. case 3: mi->seestate = (int)value; return;
  1537. case 4: mi->seesound = (int)value; return;
  1538. case 5: mi->reactiontime = (int)value; return;
  1539. case 6: mi->attacksound = (int)value; return;
  1540. case 7: mi->painstate = (int)value; return;
  1541. case 8: mi->painchance = (int)value; return;
  1542. case 9: mi->painsound = (int)value; return;
  1543. case 10: mi->meleestate = (int)value; return;
  1544. case 11: mi->missilestate = (int)value; return;
  1545. case 12: mi->deathstate = (int)value; return;
  1546. case 13: mi->xdeathstate = (int)value; return;
  1547. case 14: mi->deathsound = (int)value; return;
  1548. case 15: mi->speed = (int)value; return;
  1549. case 16: mi->radius = (int)value; return;
  1550. case 17: mi->height = (int)value; return;
  1551. case 18: mi->mass = (int)value; return;
  1552. case 19: mi->damage = (int)value; return;
  1553. case 20: mi->activesound = (int)value; return;
  1554. case 21: mi->flags = value; return;
  1555. case 22: return; // "Bits2", unused
  1556. case 23: mi->raisestate = (int)value; return;
  1557. default: return;
  1558. }
  1559. }
  1560. // ====================================================================
  1561. // deh_procThing
  1562. // Purpose: Handle DEH Thing block
  1563. // Args: fpin -- input file stream
  1564. // fpout -- output file stream (DEHOUT.TXT)
  1565. // line -- current line in file to process
  1566. // Returns: void
  1567. //
  1568. // Ty 8/27/98 - revised to also allow mnemonics for
  1569. // bit masks for monster attributes
  1570. //
  1571. static void deh_procThing(DEHFILE *fpin, FILE* fpout, char *line)
  1572. {
  1573. char key[DEH_MAXKEYLEN];
  1574. char inbuffer[DEH_BUFFERMAX];
  1575. uint_64_t value; // All deh values are ints or longs
  1576. int indexnum;
  1577. int ix;
  1578. char *strval;
  1579. strncpy(inbuffer,line,DEH_BUFFERMAX);
  1580. if (fpout) fprintf(fpout,"Thing line: '%s'\n",inbuffer);
  1581. // killough 8/98: allow hex numbers in input:
  1582. ix = sscanf(inbuffer,"%s %i",key, &indexnum);
  1583. if (fpout) fprintf(fpout,"count=%d, Thing %d\n",ix, indexnum);
  1584. // Note that the mobjinfo[] array is base zero, but object numbers
  1585. // in the dehacked file start with one. Grumble.
  1586. --indexnum;
  1587. // now process the stuff
  1588. // Note that for Things we can look up the key and use its offset
  1589. // in the array of key strings as an int offset in the structure
  1590. // get a line until a blank or end of file--it's not
  1591. // blank now because it has our incoming key in it
  1592. while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
  1593. {
  1594. // e6y: Correction of wrong processing of Bits parameter if its value is equal to zero
  1595. // No more desync on HACX demos.
  1596. int bGetData;
  1597. if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
  1598. lfstrip(inbuffer); // toss the end of line
  1599. // killough 11/98: really bail out on blank lines (break != continue)
  1600. if (!*inbuffer) break; // bail out with blank line between sections
  1601. // e6y: Correction of wrong processing of Bits parameter if its value is equal to zero
  1602. // No more desync on HACX demos.
  1603. bGetData = deh_GetData(inbuffer,key,&value,&strval,fpout);
  1604. if (!bGetData)
  1605. // Old code: if (!deh_GetData(inbuffer,key,&value,&strval,fpout)) // returns TRUE if ok
  1606. {
  1607. if (fpout) fprintf(fpout,"Bad data pair in '%s'\n",inbuffer);
  1608. continue;
  1609. }
  1610. for (ix=0; ix<DEH_MOBJINFOMAX; ix++) {
  1611. if (strcasecmp(key,deh_mobjinfo[ix])) continue;
  1612. if (strcasecmp(key,"bits")) {
  1613. // standard value set
  1614. // The old code here was the cause of a DEH-related bug in prboom.
  1615. // When the mobjinfo_t.flags member was graduated to an int64, this
  1616. // code was caught unawares and was indexing each property of the
  1617. // mobjinfo as if it were still an int32. This caused sets of the
  1618. // "raisestate" member to partially overwrite the "flags" member,
  1619. // thus screwing everything up and making most DEH patches result in
  1620. // unshootable enemy types. Moved to a separate function above
  1621. // and stripped of all hairy struct address indexing. - POPE
  1622. setMobjInfoValue(indexnum, ix, value);
  1623. }
  1624. else {
  1625. // bit set
  1626. // e6y: Correction of wrong processing of Bits parameter if its value is equal to zero
  1627. // No more desync on HACX demos.
  1628. if (bGetData==1) { // proff
  1629. value = getConvertedDEHBits(value);
  1630. mobjinfo[indexnum].flags = value;
  1631. }
  1632. else {
  1633. // figure out what the bits are
  1634. value = 0;
  1635. // killough 10/98: replace '+' kludge with strtok() loop
  1636. // Fix error-handling case ('found' var wasn't being reset)
  1637. //
  1638. // Use OR logic instead of addition, to allow repetition
  1639. for (;(strval = strtok(strval,",+| \t\f\r")); strval = NULL) {
  1640. size_t iy;
  1641. for (iy=0; iy < DEH_MOBJFLAGMAX; iy++) {
  1642. if (strcasecmp(strval,deh_mobjflags[iy].name)) continue;
  1643. if (fpout) {
  1644. fprintf(fpout,
  1645. "ORed value 0x%08lX%08lX %s\n",
  1646. (unsigned long)(deh_mobjflags[iy].value>>32) & 0xffffffff,
  1647. (unsigned long)deh_mobjflags[iy].value & 0xffffffff, strval
  1648. );
  1649. }
  1650. value |= deh_mobjflags[iy].value;
  1651. break;
  1652. }
  1653. if (iy >= DEH_MOBJFLAGMAX && fpout) {
  1654. fprintf(fpout, "Could not find bit mnemonic %s\n", strval);
  1655. }
  1656. }
  1657. // Don't worry about conversion -- simply print values
  1658. if (fpout) {
  1659. fprintf(fpout,
  1660. "Bits = 0x%08lX%08lX\n",
  1661. (unsigned long)(value>>32) & 0xffffffff,
  1662. (unsigned long)value & 0xffffffff
  1663. );
  1664. }
  1665. mobjinfo[indexnum].flags = value; // e6y
  1666. }
  1667. }
  1668. if (fpout) {
  1669. fprintf(fpout,
  1670. "Assigned 0x%08lx%08lx to %s(%d) at index %d\n",
  1671. (unsigned long)(value>>32) & 0xffffffff,
  1672. (unsigned long)value & 0xffffffff, key, indexnum, ix
  1673. );
  1674. }
  1675. }
  1676. }
  1677. return;
  1678. }
  1679. // ====================================================================
  1680. // deh_procFrame
  1681. // Purpose: Handle DEH Frame block
  1682. // Args: fpin -- input file stream
  1683. // fpout -- output file stream (DEHOUT.TXT)
  1684. // line -- current line in file to process
  1685. // Returns: void
  1686. //
  1687. static void deh_procFrame(DEHFILE *fpin, FILE* fpout, char *line)
  1688. {
  1689. char key[DEH_MAXKEYLEN];
  1690. char inbuffer[DEH_BUFFERMAX];
  1691. uint_64_t value; // All deh values are ints or longs
  1692. int indexnum;
  1693. strncpy(inbuffer,line,DEH_BUFFERMAX);
  1694. // killough 8/98: allow hex numbers in input:
  1695. sscanf(inbuffer,"%s %i",key, &indexnum);
  1696. if (fpout) fprintf(fpout,"Processing Frame at index %d: %s\n",indexnum,key);
  1697. if (indexnum < 0 || indexnum >= NUMSTATES)
  1698. if (fpout) fprintf(fpout,"Bad frame number %d of %d\n",indexnum, NUMSTATES);
  1699. while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
  1700. {
  1701. if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
  1702. lfstrip(inbuffer);
  1703. if (!*inbuffer) break; // killough 11/98
  1704. if (!deh_GetData(inbuffer,key,&value,NULL,fpout)) // returns TRUE if ok
  1705. {
  1706. if (fpout) fprintf(fpout,"Bad data pair in '%s'\n",inbuffer);
  1707. continue;
  1708. }
  1709. if (!strcasecmp(key,deh_state[0])) // Sprite number
  1710. {
  1711. if (fpout) fprintf(fpout," - sprite = %lld\n",value);
  1712. states[indexnum].sprite = (spritenum_t)value;
  1713. }
  1714. else
  1715. if (!strcasecmp(key,deh_state[1])) // Sprite subnumber
  1716. {
  1717. if (fpout) fprintf(fpout," - frame = %lld\n",value);
  1718. states[indexnum].frame = (long)value; // long
  1719. }
  1720. else
  1721. if (!strcasecmp(key,deh_state[2])) // Duration
  1722. {
  1723. if (fpout) fprintf(fpout," - tics = %lld\n",value);
  1724. states[indexnum].tics = (long)value; // long
  1725. }
  1726. else
  1727. if (!strcasecmp(key,deh_state[3])) // Next frame
  1728. {
  1729. if (fpout) fprintf(fpout," - nextstate = %lld\n",value);
  1730. states[indexnum].nextstate = (statenum_t)value;
  1731. }
  1732. else
  1733. if (!strcasecmp(key,deh_state[4])) // Codep frame (not set in Frame deh block)
  1734. {
  1735. if (fpout) fprintf(fpout," - codep, should not be set in Frame section!\n");
  1736. /* nop */ ;
  1737. }
  1738. else
  1739. if (!strcasecmp(key,deh_state[5])) // Unknown 1
  1740. {
  1741. if (fpout) fprintf(fpout," - misc1 = %lld\n",value);
  1742. states[indexnum].misc1 = (long)value; // long
  1743. }
  1744. else
  1745. if (!strcasecmp(key,deh_state[6])) // Unknown 2
  1746. {
  1747. if (fpout) fprintf(fpout," - misc2 = %lld\n",value);
  1748. states[indexnum].misc2 = (long)value; // long
  1749. }
  1750. else
  1751. if (fpout) fprintf(fpout,"Invalid frame string index for '%s'\n",key);
  1752. }
  1753. return;
  1754. }
  1755. // ====================================================================
  1756. // deh_procPointer
  1757. // Purpose: Handle DEH Code pointer block, can use BEX [CODEPTR] instead
  1758. // Args: fpin -- input file stream
  1759. // fpout -- output file stream (DEHOUT.TXT)
  1760. // line -- current line in file to process
  1761. // Returns: void
  1762. //
  1763. static void deh_procPointer(DEHFILE *fpin, FILE* fpout, char *line) // done
  1764. {
  1765. char key[DEH_MAXKEYLEN];
  1766. char inbuffer[DEH_BUFFERMAX];
  1767. uint_64_t value; // All deh values are ints or longs
  1768. int indexnum;
  1769. int i; // looper
  1770. strncpy(inbuffer,line,DEH_BUFFERMAX);
  1771. // NOTE: different format from normal
  1772. // killough 8/98: allow hex numbers in input, fix error case:
  1773. if (sscanf(inbuffer,"%*s %*i (%s %i)",key, &indexnum) != 2)
  1774. {
  1775. if (fpout) fprintf(fpout,"Bad data pair in '%s'\n",inbuffer);
  1776. return;
  1777. }
  1778. if (fpout) fprintf(fpout,"Processing Pointer at index %d: %s\n",indexnum, key);
  1779. if (indexnum < 0 || indexnum >= NUMSTATES)
  1780. {
  1781. if (fpout)
  1782. fprintf(fpout,"Bad pointer number %d of %d\n",indexnum, NUMSTATES);
  1783. return;
  1784. }
  1785. while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
  1786. {
  1787. if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
  1788. lfstrip(inbuffer);
  1789. if (!*inbuffer) break; // killough 11/98
  1790. if (!deh_GetData(inbuffer,key,&value,NULL,fpout)) // returns TRUE if ok
  1791. {
  1792. if (fpout) fprintf(fpout,"Bad data pair in '%s'\n",inbuffer);
  1793. continue;
  1794. }
  1795. if (value >= NUMSTATES)
  1796. {
  1797. if (fpout)
  1798. fprintf(fpout,"Bad pointer number %lld of %d\n",value, NUMSTATES);
  1799. return;
  1800. }
  1801. if (!strcasecmp(key,deh_state[4])) // Codep frame (not set in Frame deh block)
  1802. {
  1803. states[indexnum].action = deh_codeptr[value];
  1804. if (fpout) fprintf(fpout," - applied from codeptr[%lld] to states[%d]\n",
  1805. value,indexnum);
  1806. // Write BEX-oriented line to match:
  1807. // for (i=0;i<NUMSTATES;i++) could go past the end of the array
  1808. for (i=0;i<sizeof(deh_bexptrs)/sizeof(*deh_bexptrs);i++)
  1809. {
  1810. if (!memcmp(&deh_bexptrs[i].cptr,&deh_codeptr[value],sizeof(actionf_t)))
  1811. {
  1812. if (fpout) fprintf(fpout,"BEX [CODEPTR] -> FRAME %d = %s\n",
  1813. indexnum, &deh_bexptrs[i].lookup[2]);
  1814. break;
  1815. }
  1816. if (deh_bexptrs[i].cptr == NULL) // stop at null entry
  1817. break;
  1818. }
  1819. }
  1820. else
  1821. if (fpout) fprintf(fpout,"Invalid frame pointer index for '%s' at %lld\n",
  1822. key, value);
  1823. }
  1824. return;
  1825. }
  1826. // ====================================================================
  1827. // deh_procSounds
  1828. // Purpose: Handle DEH Sounds block
  1829. // Args: fpin -- input file stream
  1830. // fpout -- output file stream (DEHOUT.TXT)
  1831. // line -- current line in file to process
  1832. // Returns: void
  1833. //
  1834. static void deh_procSounds(DEHFILE *fpin, FILE* fpout, char *line)
  1835. {
  1836. assert( false || "Does the iOS version ever call this function? I hope not." );
  1837. (void)deh_sfxinfo;
  1838. #if 0
  1839. char key[DEH_MAXKEYLEN];
  1840. char inbuffer[DEH_BUFFERMAX];
  1841. uint_64_t value; // All deh values are ints or longs
  1842. int indexnum;
  1843. strncpy(inbuffer,line,DEH_BUFFERMAX);
  1844. // killough 8/98: allow hex numbers in input:
  1845. sscanf(inbuffer,"%s %i",key, &indexnum);
  1846. if (fpout) fprintf(fpout,"Processing Sounds at index %d: %s\n",
  1847. indexnum, key);
  1848. if (indexnum < 0 || indexnum >= NUMSFX)
  1849. if (fpout) fprintf(fpout,"Bad sound number %d of %d\n",
  1850. indexnum, NUMSFX);
  1851. while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
  1852. {
  1853. if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
  1854. lfstrip(inbuffer);
  1855. if (!*inbuffer) break; // killough 11/98
  1856. if (!deh_GetData(inbuffer,key,&value,NULL,fpout)) // returns TRUE if ok
  1857. {
  1858. if (fpout) fprintf(fpout,"Bad data pair in '%s'\n",inbuffer);
  1859. continue;
  1860. }
  1861. if (!strcasecmp(key,deh_sfxinfo[0])) // Offset
  1862. /* nop */ ; // we don't know what this is, I don't think
  1863. else
  1864. if (!strcasecmp(key,deh_sfxinfo[1])) // Zero/One
  1865. S_sfx[indexnum].singularity = (int)value;
  1866. else
  1867. if (!strcasecmp(key,deh_sfxinfo[2])) // Value
  1868. S_sfx[indexnum].priority = (int)value;
  1869. else
  1870. if (!strcasecmp(key,deh_sfxinfo[3])) // Zero 1
  1871. S_sfx[indexnum].link = (sfxinfo_t *)value;
  1872. else
  1873. if (!strcasecmp(key,deh_sfxinfo[4])) // Zero 2
  1874. S_sfx[indexnum].pitch = (int)value;
  1875. else
  1876. if (!strcasecmp(key,deh_sfxinfo[5])) // Zero 3
  1877. S_sfx[indexnum].volume = (int)value;
  1878. else
  1879. if (!strcasecmp(key,deh_sfxinfo[6])) // Zero 4
  1880. S_sfx[indexnum].data = (void *) value; // killough 5/3/98: changed cast
  1881. else
  1882. if (!strcasecmp(key,deh_sfxinfo[7])) // Neg. One 1
  1883. S_sfx[indexnum].usefulness = (int)value;
  1884. else
  1885. if (!strcasecmp(key,deh_sfxinfo[8])) // Neg. One 2
  1886. S_sfx[indexnum].lumpnum = (int)value;
  1887. else
  1888. if (fpout) fprintf(fpout,
  1889. "Invalid sound string index for '%s'\n",key);
  1890. }
  1891. return;
  1892. #endif
  1893. }
  1894. // ====================================================================
  1895. // deh_procAmmo
  1896. // Purpose: Handle DEH Ammo block
  1897. // Args: fpin -- input file stream
  1898. // fpout -- output file stream (DEHOUT.TXT)
  1899. // line -- current line in file to process
  1900. // Returns: void
  1901. //
  1902. static void deh_procAmmo(DEHFILE *fpin, FILE* fpout, char *line)
  1903. {
  1904. char key[DEH_MAXKEYLEN];
  1905. char inbuffer[DEH_BUFFERMAX];
  1906. uint_64_t value; // All deh values are ints or longs
  1907. int indexnum;
  1908. strncpy(inbuffer,line,DEH_BUFFERMAX);
  1909. // killough 8/98: allow hex numbers in input:
  1910. sscanf(inbuffer,"%s %i",key, &indexnum);
  1911. if (fpout) fprintf(fpout,"Processing Ammo at index %d: %s\n",
  1912. indexnum, key);
  1913. if (indexnum < 0 || indexnum >= NUMAMMO)
  1914. if (fpout) fprintf(fpout,"Bad ammo number %d of %d\n",
  1915. indexnum,NUMAMMO);
  1916. while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
  1917. {
  1918. if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
  1919. lfstrip(inbuffer);
  1920. if (!*inbuffer) break; // killough 11/98
  1921. if (!deh_GetData(inbuffer,key,&value,NULL,fpout)) // returns TRUE if ok
  1922. {
  1923. if (fpout) fprintf(fpout,"Bad data pair in '%s'\n",inbuffer);
  1924. continue;
  1925. }
  1926. if (!strcasecmp(key,deh_ammo[0])) // Max ammo
  1927. maxammo[indexnum] = (int)value;
  1928. else
  1929. if (!strcasecmp(key,deh_ammo[1])) // Per ammo
  1930. clipammo[indexnum] = (int)value;
  1931. else
  1932. if (fpout) fprintf(fpout,"Invalid ammo string index for '%s'\n",key);
  1933. }
  1934. return;
  1935. }
  1936. // ====================================================================
  1937. // deh_procWeapon
  1938. // Purpose: Handle DEH Weapon block
  1939. // Args: fpin -- input file stream
  1940. // fpout -- output file stream (DEHOUT.TXT)
  1941. // line -- current line in file to process
  1942. // Returns: void
  1943. //
  1944. static void deh_procWeapon(DEHFILE *fpin, FILE* fpout, char *line)
  1945. {
  1946. char key[DEH_MAXKEYLEN];
  1947. char inbuffer[DEH_BUFFERMAX];
  1948. uint_64_t value; // All deh values are ints or longs
  1949. int indexnum;
  1950. strncpy(inbuffer,line,DEH_BUFFERMAX);
  1951. // killough 8/98: allow hex numbers in input:
  1952. sscanf(inbuffer,"%s %i",key, &indexnum);
  1953. if (fpout) fprintf(fpout,"Processing Weapon at index %d: %s\n",
  1954. indexnum, key);
  1955. if (indexnum < 0 || indexnum >= NUMWEAPONS)
  1956. if (fpout) fprintf(fpout,"Bad weapon number %d of %d\n",
  1957. indexnum, NUMAMMO);
  1958. while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
  1959. {
  1960. if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
  1961. lfstrip(inbuffer);
  1962. if (!*inbuffer) break; // killough 11/98
  1963. if (!deh_GetData(inbuffer,key,&value,NULL,fpout)) // returns TRUE if ok
  1964. {
  1965. if (fpout) fprintf(fpout,"Bad data pair in '%s'\n",inbuffer);
  1966. continue;
  1967. }
  1968. if (!strcasecmp(key,deh_weapon[0])) // Ammo type
  1969. weaponinfo[indexnum].ammo = (ammotype_t)value;
  1970. else
  1971. if (!strcasecmp(key,deh_weapon[1])) // Deselect frame
  1972. weaponinfo[indexnum].upstate = (int)value;
  1973. else
  1974. if (!strcasecmp(key,deh_weapon[2])) // Select frame
  1975. weaponinfo[indexnum].downstate = (int)value;
  1976. else
  1977. if (!strcasecmp(key,deh_weapon[3])) // Bobbing frame
  1978. weaponinfo[indexnum].readystate = (int)value;
  1979. else
  1980. if (!strcasecmp(key,deh_weapon[4])) // Shooting frame
  1981. weaponinfo[indexnum].atkstate = (int)value;
  1982. else
  1983. if (!strcasecmp(key,deh_weapon[5])) // Firing frame
  1984. weaponinfo[indexnum].flashstate = (int)value;
  1985. else
  1986. if (fpout) fprintf(fpout,"Invalid weapon string index for '%s'\n",key);
  1987. }
  1988. return;
  1989. }
  1990. // ====================================================================
  1991. // deh_procSprite
  1992. // Purpose: Dummy - we do not support the DEH Sprite block
  1993. // Args: fpin -- input file stream
  1994. // fpout -- output file stream (DEHOUT.TXT)
  1995. // line -- current line in file to process
  1996. // Returns: void
  1997. //
  1998. static void deh_procSprite(DEHFILE *fpin, FILE* fpout, char *line) // Not supported
  1999. {
  2000. char key[DEH_MAXKEYLEN];
  2001. char inbuffer[DEH_BUFFERMAX];
  2002. int indexnum;
  2003. // Too little is known about what this is supposed to do, and
  2004. // there are better ways of handling sprite renaming. Not supported.
  2005. strncpy(inbuffer,line,DEH_BUFFERMAX);
  2006. // killough 8/98: allow hex numbers in input:
  2007. sscanf(inbuffer,"%s %i",key, &indexnum);
  2008. if (fpout) fprintf(fpout,
  2009. "Ignoring Sprite offset change at index %d: %s\n",indexnum, key);
  2010. while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
  2011. {
  2012. if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
  2013. lfstrip(inbuffer);
  2014. if (!*inbuffer) break; // killough 11/98
  2015. // ignore line
  2016. if (fpout) fprintf(fpout,"- %s\n",inbuffer);
  2017. }
  2018. return;
  2019. }
  2020. // ====================================================================
  2021. // deh_procPars
  2022. // Purpose: Handle BEX extension for PAR times
  2023. // Args: fpin -- input file stream
  2024. // fpout -- output file stream (DEHOUT.TXT)
  2025. // line -- current line in file to process
  2026. // Returns: void
  2027. //
  2028. static void deh_procPars(DEHFILE *fpin, FILE* fpout, char *line) // extension
  2029. {
  2030. char key[DEH_MAXKEYLEN];
  2031. char inbuffer[DEH_BUFFERMAX];
  2032. int indexnum;
  2033. int episode, level, partime, oldpar;
  2034. // new item, par times
  2035. // usage: After [PARS] Par 0 section identifier, use one or more of these
  2036. // lines:
  2037. // par 3 5 120
  2038. // par 14 230
  2039. // The first would make the par for E3M5 be 120 seconds, and the
  2040. // second one makes the par for MAP14 be 230 seconds. The number
  2041. // of parameters on the line determines which group of par values
  2042. // is being changed. Error checking is done based on current fixed
  2043. // array sizes of[4][10] and [32]
  2044. strncpy(inbuffer,line,DEH_BUFFERMAX);
  2045. // killough 8/98: allow hex numbers in input:
  2046. sscanf(inbuffer,"%s %i",key, &indexnum);
  2047. if (fpout) fprintf(fpout,
  2048. "Processing Par value at index %d: %s\n",indexnum, key);
  2049. // indexnum is a dummy entry
  2050. while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
  2051. {
  2052. if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
  2053. lfstrip(strlwr(inbuffer)); // lowercase it
  2054. if (!*inbuffer) break; // killough 11/98
  2055. if (3 != sscanf(inbuffer,"par %i %i %i",&episode, &level, &partime))
  2056. { // not 3
  2057. if (2 != sscanf(inbuffer,"par %i %i",&level, &partime))
  2058. { // not 2
  2059. if (fpout) fprintf(fpout,"Invalid par time setting string: %s\n",inbuffer);
  2060. }
  2061. else
  2062. { // is 2
  2063. // Ty 07/11/98 - wrong range check, not zero-based
  2064. if (level < 1 || level > 32) // base 0 array (but 1-based parm)
  2065. {
  2066. if (fpout) fprintf(fpout,"Invalid MAPnn value MAP%d\n",level);
  2067. }
  2068. else
  2069. {
  2070. oldpar = cpars[level-1];
  2071. if (fpout) fprintf(fpout,"Changed par time for MAP%02d from %d to %d\n",level,oldpar,partime);
  2072. cpars[level-1] = partime;
  2073. deh_pars = TRUE;
  2074. }
  2075. }
  2076. }
  2077. else
  2078. { // is 3
  2079. // note that though it's a [4][10] array, the "left" and "top" aren't used,
  2080. // effectively making it a base 1 array.
  2081. // Ty 07/11/98 - level was being checked against max 3 - dumb error
  2082. // Note that episode 4 does not have par times per original design
  2083. // in Ultimate DOOM so that is not supported here.
  2084. if (episode < 1 || episode > 3 || level < 1 || level > 9)
  2085. {
  2086. if (fpout) fprintf(fpout,
  2087. "Invalid ExMx values E%dM%d\n",episode, level);
  2088. }
  2089. else
  2090. {
  2091. oldpar = pars[episode][level];
  2092. pars[episode][level] = partime;
  2093. if (fpout) fprintf(fpout,
  2094. "Changed par time for E%dM%d from %d to %d\n",
  2095. episode,level,oldpar,partime);
  2096. deh_pars = TRUE;
  2097. }
  2098. }
  2099. }
  2100. return;
  2101. }
  2102. // ====================================================================
  2103. // deh_procCheat
  2104. // Purpose: Handle DEH Cheat block
  2105. // Args: fpin -- input file stream
  2106. // fpout -- output file stream (DEHOUT.TXT)
  2107. // line -- current line in file to process
  2108. // Returns: void
  2109. //
  2110. static void deh_procCheat(DEHFILE *fpin, FILE* fpout, char *line) // done
  2111. {
  2112. char key[DEH_MAXKEYLEN];
  2113. char inbuffer[DEH_BUFFERMAX];
  2114. uint_64_t value; // All deh values are ints or longs
  2115. char ch = 0; // CPhipps - `writable' null string to initialise...
  2116. char *strval = &ch; // pointer to the value area
  2117. int ix, iy; // array indices
  2118. char *p; // utility pointer
  2119. if (fpout) fprintf(fpout,"Processing Cheat: %s\n",line);
  2120. strncpy(inbuffer,line,DEH_BUFFERMAX);
  2121. while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
  2122. {
  2123. if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
  2124. lfstrip(inbuffer);
  2125. if (!*inbuffer) break; // killough 11/98
  2126. if (!deh_GetData(inbuffer,key,&value,&strval,fpout)) // returns TRUE if ok
  2127. {
  2128. if (fpout) fprintf(fpout,"Bad data pair in '%s'\n",inbuffer);
  2129. continue;
  2130. }
  2131. // Otherwise we got a (perhaps valid) cheat name,
  2132. // so look up the key in the array
  2133. // killough 4/18/98: use main cheat code table in st_stuff.c now
  2134. for (ix=0; cheat[ix].cheat; ix++)
  2135. if (cheat[ix].deh_cheat) // killough 4/18/98: skip non-deh
  2136. {
  2137. if (!stricmp(key,cheat[ix].deh_cheat)) // found the cheat, ignored case
  2138. {
  2139. // replace it but don't overflow it. Use current length as limit.
  2140. // Ty 03/13/98 - add 0xff code
  2141. // Deal with the fact that the cheats in deh files are extended
  2142. // with character 0xFF to the original cheat length, which we don't do.
  2143. for (iy=0; strval[iy]; iy++)
  2144. strval[iy] = (strval[iy]==(char)0xff) ? '\0' : strval[iy];
  2145. iy = ix; // killough 4/18/98
  2146. // Ty 03/14/98 - skip leading spaces
  2147. p = strval;
  2148. while (*p == ' ') ++p;
  2149. // Ty 03/16/98 - change to use a strdup and orphan the original
  2150. // Also has the advantage of allowing length changes.
  2151. // strncpy(cheat[iy].cheat,p,strlen(cheat[iy].cheat));
  2152. #if 0
  2153. { // killough 9/12/98: disable cheats which are prefixes of this one
  2154. int i;
  2155. for (i=0; cheat[i].cheat; i++)
  2156. if (cheat[i].when & not_deh &&
  2157. !strncasecmp(cheat[i].cheat,
  2158. cheat[iy].cheat,
  2159. strlen(cheat[i].cheat)) && i != iy)
  2160. cheat[i].deh_modified = true;
  2161. }
  2162. #endif
  2163. cheat[iy].cheat = strdup(p);
  2164. if (fpout) fprintf(fpout,
  2165. "Assigned new cheat '%s' to cheat '%s'at index %d\n",
  2166. p, cheat[ix].deh_cheat, iy); // killough 4/18/98
  2167. }
  2168. }
  2169. if (fpout) fprintf(fpout,"- %s\n",inbuffer);
  2170. }
  2171. return;
  2172. }
  2173. // ====================================================================
  2174. // deh_procMisc
  2175. // Purpose: Handle DEH Misc block
  2176. // Args: fpin -- input file stream
  2177. // fpout -- output file stream (DEHOUT.TXT)
  2178. // line -- current line in file to process
  2179. // Returns: void
  2180. //
  2181. static void deh_procMisc(DEHFILE *fpin, FILE* fpout, char *line) // done
  2182. {
  2183. char key[DEH_MAXKEYLEN];
  2184. char inbuffer[DEH_BUFFERMAX];
  2185. uint_64_t value; // All deh values are ints or longs
  2186. strncpy(inbuffer,line,DEH_BUFFERMAX);
  2187. while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
  2188. {
  2189. if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
  2190. lfstrip(inbuffer);
  2191. if (!*inbuffer) break; // killough 11/98
  2192. if (!deh_GetData(inbuffer,key,&value,NULL,fpout)) // returns TRUE if ok
  2193. {
  2194. if (fpout) fprintf(fpout,"Bad data pair in '%s'\n",inbuffer);
  2195. continue;
  2196. }
  2197. // Otherwise it's ok
  2198. if (fpout) fprintf(fpout,"Processing Misc item '%s'\n", key);
  2199. if (!strcasecmp(key,deh_misc[0])) // Initial Health
  2200. initial_health = (int)value;
  2201. else
  2202. if (!strcasecmp(key,deh_misc[1])) // Initial Bullets
  2203. initial_bullets = (int)value;
  2204. else
  2205. if (!strcasecmp(key,deh_misc[2])) // Max Health
  2206. maxhealth = (int)value;
  2207. else
  2208. if (!strcasecmp(key,deh_misc[3])) // Max Armor
  2209. max_armor = (int)value;
  2210. else
  2211. if (!strcasecmp(key,deh_misc[4])) // Green Armor Class
  2212. green_armor_class = (int)value;
  2213. else
  2214. if (!strcasecmp(key,deh_misc[5])) // Blue Armor Class
  2215. blue_armor_class = (int)value;
  2216. else
  2217. if (!strcasecmp(key,deh_misc[6])) // Max Soulsphere
  2218. max_soul = (int)value;
  2219. else
  2220. if (!strcasecmp(key,deh_misc[7])) // Soulsphere Health
  2221. soul_health = (int)value;
  2222. else
  2223. if (!strcasecmp(key,deh_misc[8])) // Megasphere Health
  2224. mega_health = (int)value;
  2225. else
  2226. if (!strcasecmp(key,deh_misc[9])) // God Mode Health
  2227. god_health = (int)value;
  2228. else
  2229. if (!strcasecmp(key,deh_misc[10])) // IDFA Armor
  2230. idfa_armor = (int)value;
  2231. else
  2232. if (!strcasecmp(key,deh_misc[11])) // IDFA Armor Class
  2233. idfa_armor_class = (int)value;
  2234. else
  2235. if (!strcasecmp(key,deh_misc[12])) // IDKFA Armor
  2236. idkfa_armor = (int)value;
  2237. else
  2238. if (!strcasecmp(key,deh_misc[13])) // IDKFA Armor Class
  2239. idkfa_armor_class = (int)value;
  2240. else
  2241. if (!strcasecmp(key,deh_misc[14])) // BFG Cells/Shot
  2242. bfgcells = (int)value;
  2243. else
  2244. if (!strcasecmp(key,deh_misc[15])) { // Monsters Infight
  2245. // e6y: Dehacked support - monsters infight
  2246. if (value == 202) monsters_infight = 0;
  2247. else if (value == 221) monsters_infight = 1;
  2248. else if (fpout) fprintf(fpout,
  2249. "Invalid value for 'Monsters Infight': %i", (int)value);
  2250. /* No such switch in DOOM - nop */ //e6y ;
  2251. } else
  2252. if (fpout) fprintf(fpout,
  2253. "Invalid misc item string index for '%s'\n",key);
  2254. }
  2255. return;
  2256. }
  2257. // ====================================================================
  2258. // deh_procText
  2259. // Purpose: Handle DEH Text block
  2260. // Notes: We look things up in the current information and if found
  2261. // we replace it. At the same time we write the new and
  2262. // improved BEX syntax to the log file for future use.
  2263. // Args: fpin -- input file stream
  2264. // fpout -- output file stream (DEHOUT.TXT)
  2265. // line -- current line in file to process
  2266. // Returns: void
  2267. //
  2268. static void deh_procText(DEHFILE *fpin, FILE* fpout, char *line)
  2269. {
  2270. char key[DEH_MAXKEYLEN];
  2271. char inbuffer[DEH_BUFFERMAX*2]; // can't use line -- double size buffer too.
  2272. int i; // loop variable
  2273. int fromlen, tolen; // as specified on the text block line
  2274. int usedlen; // shorter of fromlen and tolen if not matched
  2275. boolean found = FALSE; // to allow early exit once found
  2276. char* line2 = NULL; // duplicate line for rerouting
  2277. // e6y
  2278. // Correction for DEHs which swap the values of two strings. For example:
  2279. // Text 4 4 Text 4 4; Text 6 6 Text 6 6
  2280. // BOSSBOS2 BOS2BOSS; RUNNINSTALKS STALKSRUNNIN
  2281. // It corrects buggy behaviour on "All Hell is Breaking Loose" TC
  2282. // http://www.doomworld.com/idgames/index.php?id=6480
  2283. static boolean sprnames_state[NUMSPRITES+1];
  2284. static boolean S_sfx_state[NUMSFX];
  2285. static boolean S_music_state[NUMMUSIC];
  2286. // Ty 04/11/98 - Included file may have NOTEXT skip flag set
  2287. if (includenotext) // flag to skip included deh-style text
  2288. {
  2289. if (fpout) fprintf(fpout,
  2290. "Skipped text block because of notext directive\n");
  2291. strcpy(inbuffer,line);
  2292. while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
  2293. dehfgets(inbuffer, sizeof(inbuffer), fpin); // skip block
  2294. // Ty 05/17/98 - don't care if this fails
  2295. return; // ************** Early return
  2296. }
  2297. // killough 8/98: allow hex numbers in input:
  2298. sscanf(line,"%s %i %i",key,&fromlen,&tolen);
  2299. if (fpout) fprintf(fpout,
  2300. "Processing Text (key=%s, from=%d, to=%d)\n",
  2301. key, fromlen, tolen);
  2302. // killough 10/98: fix incorrect usage of feof
  2303. {
  2304. int c, totlen = 0;
  2305. while (totlen < fromlen + tolen && (c = dehfgetc(fpin)) != EOF)
  2306. if (c != '\r')
  2307. inbuffer[totlen++] = c;
  2308. inbuffer[totlen]='\0';
  2309. }
  2310. // if the from and to are 4, this may be a sprite rename. Check it
  2311. // against the array and process it as such if it matches. Remember
  2312. // that the original names are (and should remain) uppercase.
  2313. // Future: this will be from a separate [SPRITES] block.
  2314. if (fromlen==4 && tolen==4)
  2315. {
  2316. i=0;
  2317. while (sprnames[i]) // null terminated list in info.c //jff 3/19/98
  2318. { //check pointer
  2319. if (!strnicmp(sprnames[i],inbuffer,fromlen) && !sprnames_state[i]) //not first char
  2320. {
  2321. if (fpout) fprintf(fpout,
  2322. "Changing name of sprite at index %d from %s to %*s\n",
  2323. i,sprnames[i],tolen,&inbuffer[fromlen]);
  2324. // Ty 03/18/98 - not using strdup because length is fixed
  2325. // killough 10/98: but it's an array of pointers, so we must
  2326. // use strdup unless we redeclare sprnames and change all else
  2327. {
  2328. // CPhipps - fix constness problem
  2329. char *s;
  2330. sprnames[i] = s = strdup(sprnames[i]);
  2331. //e6y: flag the sprite as changed
  2332. sprnames_state[i] = true;
  2333. strncpy(s,&inbuffer[fromlen],tolen);
  2334. }
  2335. found = TRUE;
  2336. break; // only one will match--quit early
  2337. }
  2338. ++i; // next array element
  2339. }
  2340. }
  2341. else
  2342. if (fromlen < 7 && tolen < 7) // lengths of music and sfx are 6 or shorter
  2343. {
  2344. usedlen = (fromlen < tolen) ? fromlen : tolen;
  2345. if (fromlen != tolen)
  2346. if (fpout) fprintf(fpout,
  2347. "Warning: Mismatched lengths from=%d, to=%d, used %d\n",
  2348. fromlen, tolen, usedlen);
  2349. // Try sound effects entries - see sounds.c
  2350. for (i=1; i<NUMSFX; i++)
  2351. {
  2352. // avoid short prefix erroneous match
  2353. if (strlen(S_sfx[i].name) != (size_t)fromlen) continue;
  2354. if (!strnicmp(S_sfx[i].name,inbuffer,fromlen) && !S_sfx_state[i])
  2355. {
  2356. if (fpout) fprintf(fpout,
  2357. "Changing name of sfx from %s to %*s\n",
  2358. S_sfx[i].name,usedlen,&inbuffer[fromlen]);
  2359. S_sfx[i].name = strdup(&inbuffer[fromlen]);
  2360. //e6y: flag the SFX as changed
  2361. S_sfx_state[i] = true;
  2362. found = TRUE;
  2363. break; // only one matches, quit early
  2364. }
  2365. }
  2366. if (!found) // not yet
  2367. {
  2368. // Try music name entries - see sounds.c
  2369. for (i=1; i<NUMMUSIC; i++)
  2370. {
  2371. // avoid short prefix erroneous match
  2372. if (strlen(S_music[i].name) != (size_t)fromlen) continue;
  2373. if (!strnicmp(S_music[i].name,inbuffer,fromlen) && !S_music_state[i])
  2374. {
  2375. if (fpout) fprintf(fpout,
  2376. "Changing name of music from %s to %*s\n",
  2377. S_music[i].name,usedlen,&inbuffer[fromlen]);
  2378. S_music[i].name = strdup(&inbuffer[fromlen]);
  2379. //e6y: flag the music as changed
  2380. S_music_state[i] = true;
  2381. found = TRUE;
  2382. break; // only one matches, quit early
  2383. }
  2384. }
  2385. } // end !found test
  2386. }
  2387. if (!found) // Nothing we want to handle here--see if strings can deal with it.
  2388. {
  2389. if (fpout) fprintf(fpout,"Checking text area through strings for '%.12s%s' from=%d to=%d\n",inbuffer, (strlen(inbuffer) > 12) ? "..." : "",fromlen,tolen);
  2390. if ((size_t)fromlen <= strlen(inbuffer))
  2391. {
  2392. line2 = strdup(&inbuffer[fromlen]);
  2393. inbuffer[fromlen] = '\0';
  2394. }
  2395. deh_procStringSub(NULL, inbuffer, line2, fpout);
  2396. }
  2397. free(line2); // may be NULL, ignored by free()
  2398. return;
  2399. }
  2400. static void deh_procError(DEHFILE *fpin, FILE* fpout, char *line)
  2401. {
  2402. char inbuffer[DEH_BUFFERMAX];
  2403. strncpy(inbuffer,line,DEH_BUFFERMAX);
  2404. if (fpout) fprintf(fpout,"Unmatched Block: '%s'\n",inbuffer);
  2405. return;
  2406. }
  2407. // ====================================================================
  2408. // deh_procStrings
  2409. // Purpose: Handle BEX [STRINGS] extension
  2410. // Args: fpin -- input file stream
  2411. // fpout -- output file stream (DEHOUT.TXT)
  2412. // line -- current line in file to process
  2413. // Returns: void
  2414. //
  2415. static void deh_procStrings(DEHFILE *fpin, FILE* fpout, char *line)
  2416. {
  2417. char key[DEH_MAXKEYLEN];
  2418. char inbuffer[DEH_BUFFERMAX];
  2419. uint_64_t value; // All deh values are ints or longs
  2420. char *strval; // holds the string value of the line
  2421. static int maxstrlen = 128; // maximum string length, bumped 128 at
  2422. // a time as needed
  2423. // holds the final result of the string after concatenation
  2424. static char *holdstring = NULL;
  2425. boolean found = false; // looking for string continuation
  2426. if (fpout) fprintf(fpout,"Processing extended string substitution\n");
  2427. if (!holdstring) holdstring = malloc(maxstrlen*sizeof(*holdstring));
  2428. *holdstring = '\0'; // empty string to start with
  2429. strncpy(inbuffer,line,DEH_BUFFERMAX);
  2430. // Ty 04/24/98 - have to allow inbuffer to start with a blank for
  2431. // the continuations of C1TEXT etc.
  2432. while (!dehfeof(fpin) && *inbuffer) /* && (*inbuffer != ' ') */
  2433. {
  2434. if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
  2435. if (*inbuffer == '#') continue; // skip comment lines
  2436. lfstrip(inbuffer);
  2437. if (!*inbuffer) break; // killough 11/98
  2438. if (!*holdstring) // first one--get the key
  2439. {
  2440. if (!deh_GetData(inbuffer,key,&value,&strval,fpout)) // returns TRUE if ok
  2441. {
  2442. if (fpout) fprintf(fpout,"Bad data pair in '%s'\n",inbuffer);
  2443. continue;
  2444. }
  2445. }
  2446. while (strlen(holdstring) + strlen(inbuffer) > (size_t)maxstrlen) // Ty03/29/98 - fix stupid error
  2447. {
  2448. // killough 11/98: allocate enough the first time
  2449. maxstrlen += strlen(holdstring) + strlen(inbuffer) - maxstrlen;
  2450. if (fpout) fprintf(fpout,
  2451. "* increased buffer from to %d for buffer size %d\n",
  2452. maxstrlen,(int)strlen(inbuffer));
  2453. holdstring = realloc(holdstring,maxstrlen*sizeof(*holdstring));
  2454. }
  2455. // concatenate the whole buffer if continuation or the value iffirst
  2456. strcat(holdstring,ptr_lstrip(((*holdstring) ? inbuffer : strval)));
  2457. rstrip(holdstring);
  2458. // delete any trailing blanks past the backslash
  2459. // note that blanks before the backslash will be concatenated
  2460. // but ones at the beginning of the next line will not, allowing
  2461. // indentation in the file to read well without affecting the
  2462. // string itself.
  2463. if (holdstring[strlen(holdstring)-1] == '\\')
  2464. {
  2465. holdstring[strlen(holdstring)-1] = '\0';
  2466. continue; // ready to concatenate
  2467. }
  2468. if (*holdstring) // didn't have a backslash, trap above would catch that
  2469. {
  2470. // go process the current string
  2471. found = deh_procStringSub(key, NULL, holdstring, fpout); // supply keyand not search string
  2472. if (!found)
  2473. if (fpout) fprintf(fpout,
  2474. "Invalid string key '%s', substitution skipped.\n",key);
  2475. *holdstring = '\0'; // empty string for the next one
  2476. }
  2477. }
  2478. return;
  2479. }
  2480. // ====================================================================
  2481. // deh_procStringSub
  2482. // Purpose: Common string parsing and handling routine for DEH and BEX
  2483. // Args: key -- place to put the mnemonic for the string if found
  2484. // lookfor -- original value string to look for
  2485. // newstring -- string to put in its place if found
  2486. // fpout -- file stream pointer for log file (DEHOUT.TXT)
  2487. // Returns: boolean: True if string found, false if not
  2488. //
  2489. boolean deh_procStringSub(char *key, char *lookfor, char *newstring, FILE *fpout)
  2490. {
  2491. boolean found; // loop exit flag
  2492. int i; // looper
  2493. found = false;
  2494. for (i=0;i<deh_numstrlookup;i++)
  2495. {
  2496. found = lookfor ?
  2497. !stricmp(*deh_strlookup[i].ppstr,lookfor) :
  2498. !stricmp(deh_strlookup[i].lookup,key);
  2499. if (found)
  2500. {
  2501. char *t;
  2502. *deh_strlookup[i].ppstr = t = strdup(newstring); // orphan originalstring
  2503. found = true;
  2504. // Handle embedded \n's in the incoming string, convert to 0x0a's
  2505. {
  2506. const char *s;
  2507. for (s=*deh_strlookup[i].ppstr; *s; ++s, ++t)
  2508. {
  2509. if (*s == '\\' && (s[1] == 'n' || s[1] == 'N')) //found one
  2510. ++s, *t = '\n'; // skip one extra for second character
  2511. else
  2512. *t = *s;
  2513. }
  2514. *t = '\0'; // cap off the target string
  2515. }
  2516. if (key)
  2517. if (fpout) fprintf(fpout,
  2518. "Assigned key %s => '%s'\n",key,newstring);
  2519. if (!key)
  2520. if (fpout) fprintf(fpout,
  2521. "Assigned '%.12s%s' to'%.12s%s' at key %s\n",
  2522. lookfor, (strlen(lookfor) > 12) ? "..." : "",
  2523. newstring, (strlen(newstring) > 12) ? "..." :"",
  2524. deh_strlookup[i].lookup);
  2525. if (!key) // must have passed an old style string so showBEX
  2526. if (fpout) fprintf(fpout,
  2527. "*BEX FORMAT:\n%s = %s\n*END BEX\n",
  2528. deh_strlookup[i].lookup,
  2529. dehReformatStr(newstring));
  2530. break;
  2531. }
  2532. }
  2533. if (!found)
  2534. if (fpout) fprintf(fpout,
  2535. "Could not find '%.12s'\n",key ? key: lookfor);
  2536. return found;
  2537. }
  2538. //========================================================================
  2539. // haleyjd 9/22/99
  2540. //
  2541. // deh_procHelperThing
  2542. //
  2543. // Allows handy substitution of any thing for helper dogs. DEH patches
  2544. // are being made frequently for this purpose and it requires a complete
  2545. // rewiring of the DOG thing. I feel this is a waste of effort, and so
  2546. // have added this new [HELPER] BEX block
  2547. static void deh_procHelperThing(DEHFILE *fpin, FILE *fpout, char *line)
  2548. {
  2549. char key[DEH_MAXKEYLEN];
  2550. char inbuffer[DEH_BUFFERMAX];
  2551. uint_64_t value; // All deh values are ints or longs
  2552. strncpy(inbuffer,line,DEH_BUFFERMAX);
  2553. while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
  2554. {
  2555. if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
  2556. lfstrip(inbuffer);
  2557. if (!*inbuffer) break;
  2558. if (!deh_GetData(inbuffer,key,&value,NULL,fpout)) // returns TRUE if ok
  2559. {
  2560. if (fpout) fprintf(fpout,"Bad data pair in '%s'\n",inbuffer);
  2561. continue;
  2562. }
  2563. // Otherwise it's ok
  2564. if (fpout)
  2565. {
  2566. fprintf(fpout,"Processing Helper Thing item '%s'\n", key);
  2567. fprintf(fpout,"value is %i", (int)value);
  2568. }
  2569. if (!strncasecmp(key, "type", 4))
  2570. HelperThing = (int)value;
  2571. }
  2572. return;
  2573. }
  2574. //
  2575. // deh_procBexSprites
  2576. //
  2577. // Supports sprite name substitutions without requiring use
  2578. // of the DeHackEd Text block
  2579. //
  2580. static void deh_procBexSprites(DEHFILE *fpin, FILE *fpout, char *line)
  2581. {
  2582. char key[DEH_MAXKEYLEN];
  2583. char inbuffer[DEH_BUFFERMAX];
  2584. uint_64_t value; // All deh values are ints or longs
  2585. char *strval; // holds the string value of the line
  2586. char candidate[5];
  2587. int rover;
  2588. if(fpout)
  2589. fprintf(fpout,"Processing sprite name substitution\n");
  2590. strncpy(inbuffer,line,DEH_BUFFERMAX);
  2591. while(!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
  2592. {
  2593. if(!dehfgets(inbuffer, sizeof(inbuffer), fpin))
  2594. break;
  2595. if(*inbuffer == '#')
  2596. continue; // skip comment lines
  2597. lfstrip(inbuffer);
  2598. if(!*inbuffer)
  2599. break; // killough 11/98
  2600. if(!deh_GetData(inbuffer,key,&value,&strval,fpout)) // returns TRUE if ok
  2601. {
  2602. if(fpout)
  2603. fprintf(fpout,"Bad data pair in '%s'\n",inbuffer);
  2604. continue;
  2605. }
  2606. // do it
  2607. memset(candidate, 0, sizeof(candidate));
  2608. strncpy(candidate, ptr_lstrip(strval), 4);
  2609. if(strlen(candidate) != 4)
  2610. {
  2611. if(fpout)
  2612. fprintf(fpout, "Bad length for sprite name '%s'\n",
  2613. candidate);
  2614. continue;
  2615. }
  2616. rover = 0;
  2617. while(deh_spritenames[rover])
  2618. {
  2619. if(!strncasecmp(deh_spritenames[rover], key, 4))
  2620. {
  2621. if(fpout)
  2622. fprintf(fpout, "Substituting '%s' for sprite '%s'\n",
  2623. candidate, deh_spritenames[rover]);
  2624. sprnames[rover] = strdup(candidate);
  2625. break;
  2626. }
  2627. rover++;
  2628. }
  2629. }
  2630. }
  2631. // ditto for sound names
  2632. static void deh_procBexSounds(DEHFILE *fpin, FILE *fpout, char *line)
  2633. {
  2634. char key[DEH_MAXKEYLEN];
  2635. char inbuffer[DEH_BUFFERMAX];
  2636. uint_64_t value; // All deh values are ints or longs
  2637. char *strval; // holds the string value of the line
  2638. char candidate[7];
  2639. int rover, len;
  2640. if(fpout)
  2641. fprintf(fpout,"Processing sound name substitution\n");
  2642. strncpy(inbuffer,line,DEH_BUFFERMAX);
  2643. while(!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
  2644. {
  2645. if(!dehfgets(inbuffer, sizeof(inbuffer), fpin))
  2646. break;
  2647. if(*inbuffer == '#')
  2648. continue; // skip comment lines
  2649. lfstrip(inbuffer);
  2650. if(!*inbuffer)
  2651. break; // killough 11/98
  2652. if(!deh_GetData(inbuffer,key,&value,&strval,fpout)) // returns TRUE if ok
  2653. {
  2654. if(fpout)
  2655. fprintf(fpout,"Bad data pair in '%s'\n",inbuffer);
  2656. continue;
  2657. }
  2658. // do it
  2659. memset(candidate, 0, 7);
  2660. strncpy(candidate, ptr_lstrip(strval), 6);
  2661. len = strlen(candidate);
  2662. if(len < 1 || len > 6)
  2663. {
  2664. if(fpout)
  2665. fprintf(fpout, "Bad length for sound name '%s'\n",
  2666. candidate);
  2667. continue;
  2668. }
  2669. rover = 1;
  2670. while(deh_soundnames[rover])
  2671. {
  2672. if(!strncasecmp(deh_soundnames[rover], key, 6))
  2673. {
  2674. if(fpout)
  2675. fprintf(fpout, "Substituting '%s' for sound '%s'\n",
  2676. candidate, deh_soundnames[rover]);
  2677. S_sfx[rover].name = strdup(candidate);
  2678. break;
  2679. }
  2680. rover++;
  2681. }
  2682. }
  2683. }
  2684. // ditto for music names
  2685. static void deh_procBexMusic(DEHFILE *fpin, FILE *fpout, char *line)
  2686. {
  2687. char key[DEH_MAXKEYLEN];
  2688. char inbuffer[DEH_BUFFERMAX];
  2689. uint_64_t value; // All deh values are ints or longs
  2690. char *strval; // holds the string value of the line
  2691. char candidate[7];
  2692. int rover, len;
  2693. if(fpout)
  2694. fprintf(fpout,"Processing music name substitution\n");
  2695. strncpy(inbuffer,line,DEH_BUFFERMAX);
  2696. while(!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
  2697. {
  2698. if(!dehfgets(inbuffer, sizeof(inbuffer), fpin))
  2699. break;
  2700. if(*inbuffer == '#')
  2701. continue; // skip comment lines
  2702. lfstrip(inbuffer);
  2703. if(!*inbuffer)
  2704. break; // killough 11/98
  2705. if(!deh_GetData(inbuffer,key,&value,&strval,fpout)) // returns TRUE if ok
  2706. {
  2707. if(fpout)
  2708. fprintf(fpout,"Bad data pair in '%s'\n",inbuffer);
  2709. continue;
  2710. }
  2711. // do it
  2712. memset(candidate, 0, 7);
  2713. strncpy(candidate, ptr_lstrip(strval), 6);
  2714. len = strlen(candidate);
  2715. if(len < 1 || len > 6)
  2716. {
  2717. if(fpout)
  2718. fprintf(fpout, "Bad length for music name '%s'\n",
  2719. candidate);
  2720. continue;
  2721. }
  2722. rover = 1;
  2723. while(deh_musicnames[rover])
  2724. {
  2725. if(!strncasecmp(deh_musicnames[rover], key, 6))
  2726. {
  2727. if(fpout)
  2728. fprintf(fpout, "Substituting '%s' for music '%s'\n",
  2729. candidate, deh_musicnames[rover]);
  2730. S_music[rover].name = strdup(candidate);
  2731. break;
  2732. }
  2733. rover++;
  2734. }
  2735. }
  2736. }
  2737. // ====================================================================
  2738. // General utility function(s)
  2739. // ====================================================================
  2740. // ====================================================================
  2741. // dehReformatStr
  2742. // Purpose: Convert a string into a continuous string with embedded
  2743. // linefeeds for "\n" sequences in the source string
  2744. // Args: string -- the string to convert
  2745. // Returns: the converted string (converted in a static buffer)
  2746. //
  2747. char *dehReformatStr(char *string)
  2748. {
  2749. static char buff[DEH_BUFFERMAX]; // only processing the changed string,
  2750. // don't need double buffer
  2751. char *s, *t;
  2752. s = string; // source
  2753. t = buff; // target
  2754. // let's play...
  2755. while (*s)
  2756. {
  2757. if (*s == '\n')
  2758. ++s, *t++ = '\\', *t++ = 'n', *t++ = '\\', *t++='\n';
  2759. else
  2760. *t++ = *s++;
  2761. }
  2762. *t = '\0';
  2763. return buff;
  2764. }
  2765. // ====================================================================
  2766. // lfstrip
  2767. // Purpose: Strips CR/LF off the end of a string
  2768. // Args: s -- the string to work on
  2769. // Returns: void -- the string is modified in place
  2770. //
  2771. // killough 10/98: only strip at end of line, not entire string
  2772. void lfstrip(char *s) // strip the \r and/or \n off of a line
  2773. {
  2774. char *p = s+strlen(s);
  2775. while (p > s && (*--p=='\r' || *p=='\n'))
  2776. *p = 0;
  2777. }
  2778. // ====================================================================
  2779. // rstrip
  2780. // Purpose: Strips trailing blanks off a string
  2781. // Args: s -- the string to work on
  2782. // Returns: void -- the string is modified in place
  2783. //
  2784. void rstrip(char *s) // strip trailing whitespace
  2785. {
  2786. char *p = s+strlen(s); // killough 4/4/98: same here
  2787. while (p > s && isspace(*--p)) // break on first non-whitespace
  2788. *p='\0';
  2789. }
  2790. // ====================================================================
  2791. // ptr_lstrip
  2792. // Purpose: Points past leading whitespace in a string
  2793. // Args: s -- the string to work on
  2794. // Returns: char * pointing to the first nonblank character in the
  2795. // string. The original string is not changed.
  2796. //
  2797. char *ptr_lstrip(char *p) // point past leading whitespace
  2798. {
  2799. while (isspace(*p))
  2800. p++;
  2801. return p;
  2802. }
  2803. // e6y: Correction of wrong processing of Bits parameter if its value is equal to zero
  2804. // No more desync on HACX demos.
  2805. // FIXME!!! (lame)
  2806. static boolean StrToInt(char *s, long *l)
  2807. {
  2808. return (
  2809. (sscanf(s, " 0x%lx", l) == 1) ||
  2810. (sscanf(s, " 0X%lx", l) == 1) ||
  2811. (sscanf(s, " 0%lo", l) == 1) ||
  2812. (sscanf(s, " %ld", l) == 1)
  2813. );
  2814. }
  2815. // ====================================================================
  2816. // deh_GetData
  2817. // Purpose: Get a key and data pair from a passed string
  2818. // Args: s -- the string to be examined
  2819. // k -- a place to put the key
  2820. // l -- pointer to a long integer to store the number
  2821. // strval -- a pointer to the place in s where the number
  2822. // value comes from. Pass NULL to not use this.
  2823. // fpout -- stream pointer to output log (DEHOUT.TXT)
  2824. // Notes: Expects a key phrase, optional space, equal sign,
  2825. // optional space and a value, mostly an int but treated
  2826. // as a long just in case. The passed pointer to hold
  2827. // the key must be DEH_MAXKEYLEN in size.
  2828. boolean deh_GetData(char *s, char *k, uint_64_t *l, char **strval, FILE *fpout)
  2829. {
  2830. char *t; // current char
  2831. long val; // to hold value of pair
  2832. char buffer[DEH_MAXKEYLEN]; // to hold key in progress
  2833. // e6y: Correction of wrong processing of Bits parameter if its value is equal to zero
  2834. // No more desync on HACX demos.
  2835. boolean okrc = 1; // assume good unless we have problems
  2836. int i; // iterator
  2837. *buffer = '\0';
  2838. val = 0; // defaults in case not otherwise set
  2839. for (i=0, t=s; *t && i < DEH_MAXKEYLEN; t++, i++)
  2840. {
  2841. if (*t == '=') break;
  2842. buffer[i] = *t; // copy it
  2843. }
  2844. buffer[--i] = '\0'; // terminate the key before the '='
  2845. if (!*t) // end of string with no equal sign
  2846. {
  2847. okrc = FALSE;
  2848. }
  2849. else
  2850. {
  2851. if (!*++t)
  2852. {
  2853. val = 0; // in case "thiskey =" with no value
  2854. okrc = FALSE;
  2855. }
  2856. // we've incremented t
  2857. // e6y: Correction of wrong processing of Bits parameter if its value is equal to zero
  2858. // No more desync on HACX demos.
  2859. // Old code: e6y val = strtol(t,NULL,0); // killough 8/9/98: allow hex or octal input
  2860. if (!StrToInt(t,&val))
  2861. {
  2862. val = 0;
  2863. okrc = 2;
  2864. }
  2865. }
  2866. // go put the results in the passed pointers
  2867. *l = val; // may be a faked zero
  2868. // if spaces between key and equal sign, strip them
  2869. strcpy(k,ptr_lstrip(buffer)); // could be a zero-length string
  2870. if (strval != NULL) // pass NULL if you don't want this back
  2871. *strval = t; // pointer, has to be somewhere in s,
  2872. // even if pointing at the zero byte.
  2873. return(okrc);
  2874. }