m_cheat.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Emacs style mode select -*- C++ -*-
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. // $Log:$
  18. //
  19. // DESCRIPTION:
  20. // Cheat sequence checking.
  21. //
  22. //-----------------------------------------------------------------------------
  23. static const char
  24. rcsid[] = "$Id: m_cheat.c,v 1.1 1997/02/03 21:24:34 b1 Exp $";
  25. #include "m_cheat.h"
  26. //
  27. // CHEAT SEQUENCE PACKAGE
  28. //
  29. static int firsttime = 1;
  30. static unsigned char cheat_xlate_table[256];
  31. //
  32. // Called in st_stuff module, which handles the input.
  33. // Returns a 1 if the cheat was successful, 0 if failed.
  34. //
  35. int
  36. cht_CheckCheat
  37. ( cheatseq_t* cht,
  38. char key )
  39. {
  40. int i;
  41. int rc = 0;
  42. if (firsttime)
  43. {
  44. firsttime = 0;
  45. for (i=0;i<256;i++) cheat_xlate_table[i] = SCRAMBLE(i);
  46. }
  47. if (!cht->p)
  48. cht->p = cht->sequence; // initialize if first time
  49. if (*cht->p == 0)
  50. *(cht->p++) = key;
  51. else if
  52. (cheat_xlate_table[(unsigned char)key] == *cht->p) cht->p++;
  53. else
  54. cht->p = cht->sequence;
  55. if (*cht->p == 1)
  56. cht->p++;
  57. else if (*cht->p == 0xff) // end of sequence character
  58. {
  59. cht->p = cht->sequence;
  60. rc = 1;
  61. }
  62. return rc;
  63. }
  64. void
  65. cht_GetParam
  66. ( cheatseq_t* cht,
  67. char* buffer )
  68. {
  69. unsigned char *p, c;
  70. p = cht->sequence;
  71. while (*(p++) != 1);
  72. do
  73. {
  74. c = *p;
  75. *(buffer++) = c;
  76. *(p++) = 0;
  77. }
  78. while (c && *p!=0xff );
  79. if (*p==0xff)
  80. *buffer = 0;
  81. }