DEFAULT.BAK 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. //
  2. // Save & Load defaults
  3. //
  4. #include <dir.h>
  5. #include <string.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <io.h>
  9. #include <bios.h>
  10. #include "default.h"
  11. #include "keys.h"
  12. #include "main.h"
  13. int usemouse;
  14. int usejoystick;
  15. extern net_t netinfo;
  16. extern DMXINFO newc;
  17. extern CONTS curk;
  18. int mouseSensitivity = 4;
  19. int showMessages = 1;
  20. int sfxVolume = 15;
  21. int musicVolume = 15;
  22. int detailLevel = 1;
  23. int screenblocks = 10;
  24. int usegamma = 0;
  25. int comport = 1;
  26. char chatmacros[10][40];
  27. default_t defaults[] =
  28. {
  29. {"mouse_sensitivity",&mouseSensitivity, 5},
  30. {"sfx_volume",&sfxVolume, 8},
  31. {"music_volume",&musicVolume, 8},
  32. {"show_messages",&showMessages, 1},
  33. {"key_right",&curk.right, SC_RIGHT },
  34. {"key_left",&curk.left, SC_LEFT },
  35. {"key_up",&curk.up, SC_UP },
  36. {"key_down",&curk.down, SC_DOWN },
  37. {"key_strafeleft",&curk.key3, SC_COMMA },
  38. {"key_straferight",&curk.key4, SC_PERIOD },
  39. {"key_fire",&curk.fire, SC_CTRL },
  40. {"key_use",&curk.use, SC_SPACE },
  41. {"key_strafe",&curk.key1, SC_ALT },
  42. {"key_speed",&curk.key2, SC_RIGHT_SHIFT },
  43. #ifdef HERETIC
  44. {"key_flydown",&curk.flydown,SC_INSERT},
  45. {"key_flycenter",&curk.flycenter,SC_HOME},
  46. {"key_flyup",&curk.flyup,SC_PAGEUP},
  47. {"key_lookdown",&curk.lookdown,SC_DELETE},
  48. {"key_lookcenter",&curk.lookcenter,SC_END},
  49. {"key_lookup",&curk.lookup,SC_PAGEDN},
  50. {"key_invleft",&curk.invleft,0x1a},
  51. {"key_invright",&curk.invright,0x1b},
  52. #endif
  53. #ifdef STRIFE
  54. {"key_lookdown",&curk.lookdown, SC_PAGEDN},
  55. {"key_lookup",&curk.lookup,SC_PAGEUP},
  56. {"key_invleft",&curk.invleft,SC_INSERT},
  57. {"key_invright",&curk.invright,SC_DELETE},
  58. {"key_useHealth",&curk.healthuse,SC_H},
  59. {"key_invUse",&curk.invuse,SC_ENTER},
  60. {"key_invDrop",&curk.invdrop,SC_BACKSPACE},
  61. {"key_invHome",&curk.invhome,SC_HOME},
  62. {"key_invEnd",&curk.invend,SC_END},
  63. {"key_invPop",&curk.invpop,SC_Z},
  64. {"key_invquery",&curk.invquery,SC_Q},
  65. {"key_jump",&curk.jump,SC_A},
  66. #endif
  67. {"use_mouse",&usemouse, 1 },
  68. {"mouseb_fire",&curk.mouse[ID_FIRE],ID_FIRE },
  69. {"mouseb_strafe",&curk.mouse[ID_STRAFE],ID_STRAFE },
  70. {"mouseb_forward",&curk.mouse[ID_FORWARD],ID_FORWARD },
  71. {"use_joystick",&usejoystick, 0},
  72. {"joyb_fire",&curk.joy[ID_FIRE],ID_FIRE},
  73. {"joyb_strafe",&curk.joy[ID_STRAFE],ID_STRAFE},
  74. {"joyb_use",&curk.joy[ID_USE],ID_USE},
  75. {"joyb_speed",&curk.joy[ID_FORWARD],ID_FORWARD},
  76. {"screenblocks",&screenblocks, 9},
  77. {"detaillevel",&detailLevel, 0},
  78. {"showmessages",&showMessages, 1 },
  79. {"comport",&comport, 1 },
  80. {"snd_channels", (int *)&newc.numdig, 3 },
  81. {"snd_musicdevice", (int *)&newc.m.card, 0 },
  82. {"snd_sfxdevice", (int *)&newc.d.card, 0 },
  83. {"snd_sbport", (int *)&newc.m.port, 0x220 },
  84. {"snd_sbirq", (int *)&newc.d.irq, 5 },
  85. {"snd_sbdma", (int *)&newc.d.dma, 1 },
  86. {"snd_mport", (int *)&newc.m.midiport, 0x330 },
  87. {"usegamma", &usegamma, 0 },
  88. {"chatmacro0",(int *)chatmacros[0],0},
  89. {"chatmacro1",(int *)chatmacros[1],0},
  90. {"chatmacro2",(int *)chatmacros[2],0},
  91. {"chatmacro3",(int *)chatmacros[3],0},
  92. {"chatmacro4",(int *)chatmacros[4],0},
  93. {"chatmacro5",(int *)chatmacros[5],0},
  94. {"chatmacro6",(int *)chatmacros[6],0},
  95. {"chatmacro7",(int *)chatmacros[7],0},
  96. {"chatmacro8",(int *)chatmacros[8],0},
  97. {"chatmacro9",(int *)chatmacros[9],0},
  98. {"",NULL,0},
  99. };
  100. int numdefaults;
  101. char * defaultfile;
  102. /*
  103. ==============
  104. =
  105. = M_SaveDefaults
  106. =
  107. ==============
  108. */
  109. void M_SaveDefaults (void)
  110. {
  111. int i;
  112. FILE * f;
  113. if ( newc.m.port == -1 )
  114. {
  115. if ( newc.d.port == -1 )
  116. newc.m.port = 0x220;
  117. else
  118. newc.m.port = newc.d.port;
  119. }
  120. if ( newc.control != C_KEY )
  121. {
  122. if ( newc.control == C_MOUSE )
  123. usemouse = 1;
  124. if ( newc.control == C_JOYSTICK )
  125. usejoystick = 1;
  126. }
  127. numdefaults = sizeof(defaults)/sizeof(default_t);
  128. f = fopen (defaultfile, "w");
  129. if (!f)
  130. return; // can't write the file, but don't complain
  131. for (i=0 ; i<numdefaults ; i++)
  132. if (!strncmp(defaults[i].name,"chatmacro",9))
  133. {
  134. int v = defaults[i].name[9] - '0';
  135. fprintf (f,"%s\t\t\"%s\"\n",defaults[i].name, chatmacros[v]);
  136. }
  137. else
  138. fprintf (f,"%s\t\t%i\n",defaults[i].name, *defaults[i].location);
  139. fclose (f);
  140. }
  141. int CheckParm(char *string)
  142. {
  143. int i;
  144. for (i = 1;i < myargc;i++)
  145. if (!strcmp(myargv[i],string))
  146. return i;
  147. return 0;
  148. }
  149. /*
  150. ==============
  151. =
  152. = M_LoadDefaults
  153. =
  154. ==============
  155. */
  156. int M_LoadDefaults (void)
  157. {
  158. int i;
  159. FILE *f;
  160. char def[80];
  161. char strparm[50];
  162. int parm;
  163. char macro[40];
  164. //
  165. // set everything to base values
  166. //
  167. numdefaults = sizeof(defaults)/sizeof(defaults[0]);
  168. for (i=0 ; i<numdefaults ; i++)
  169. if (!strncmp(defaults[i].name,"chatmacro",9))
  170. strcpy((char *)defaults[i].location,"no macro");
  171. else
  172. *defaults[i].location = defaults[i].defaultvalue;
  173. cdrom = 0;
  174. if (CheckParm("-cdrom"))
  175. {
  176. mkdir(DEFAULTPATH);
  177. defaultfile = DEFAULTPATH"\\"DEFAULTNAME;
  178. cdrom = 1;
  179. }
  180. else
  181. defaultfile = DEFAULTNAME; // hard-coded path GONE!
  182. i = CheckParm("-config");
  183. if (i)
  184. defaultfile = myargv[i+1];
  185. //
  186. // read the file in, overriding any set defaults
  187. //
  188. f = fopen (defaultfile, "r");
  189. if (!f)
  190. return(0); // no overrides
  191. while (!feof(f))
  192. {
  193. fscanf ( f, "%79s %[^\n]", def, strparm );
  194. macro[0] = 0;
  195. if (!strncmp(def,"chatmacro",9))
  196. sscanf(strparm+1,"%[^\"]",macro);
  197. else
  198. if (strparm[0] == '0' && strparm[1] == 'x')
  199. sscanf(strparm+2, "%x", &parm);
  200. else
  201. sscanf(strparm, "%i", &parm);
  202. for (i=0 ; i<numdefaults ; i++)
  203. if (!strcmp(def, defaults[i].name) )
  204. {
  205. if (!strncmp(def,"chatmacro",9))
  206. strcpy((char *)defaults[i].location,macro);
  207. else
  208. *defaults[i].location = parm;
  209. break;
  210. }
  211. }
  212. fclose (f);
  213. newc.d.port = newc.m.port;
  214. if ( usemouse )
  215. newc.control = C_MOUSE;
  216. else if ( usejoystick )
  217. newc.control = C_JOYSTICK;
  218. else
  219. newc.control = C_KEY;
  220. return(1);
  221. }