-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathm_cheat.c
130 lines (106 loc) · 3.93 KB
/
m_cheat.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
==============================================================================
DOOM Retro
The classic, refined DOOM source port. For Windows PC.
==============================================================================
Copyright © 1993-2025 by id Software LLC, a ZeniMax Media company.
Copyright © 2013-2025 by Brad Harding <mailto:[email protected]>.
This file is a part of DOOM Retro.
DOOM Retro is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the license, or (at your
option) any later version.
DOOM Retro is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with DOOM Retro. If not, see <https://www.gnu.org/licenses/>.
DOOM is a registered trademark of id Software LLC, a ZeniMax Media
company, in the US and/or other countries, and is used without
permission. All other trademarks are the property of their respective
holders. DOOM Retro is in no way affiliated with nor endorsed by
id Software.
==============================================================================
*/
#include <ctype.h>
#include <string.h>
#include "c_console.h"
#include "doomstat.h"
#include "hu_stuff.h"
#include "m_cheat.h"
#include "m_misc.h"
//
// CHEAT SEQUENCE PACKAGE
//
//
// Called in st_stuff.c, which handles the input.
// Returns true if the cheat was successful, false if it failed.
//
char cheatkey = '\0';
bool cht_CheckCheat(cheatseq_t *cht, unsigned char key)
{
if (*consolecheat && M_StringCompare(consolecheat, cht->sequence))
{
consolecheat[0] = '\0';
if (*consolecheatparm)
{
cht->parameter_buf[0] = consolecheatparm[0];
cht->parameter_buf[1] = consolecheatparm[1];
cht->param_chars_read = 2;
consolecheatparm[0] = '\0';
}
return true;
}
// [BH] you have 2 or 4 seconds to enter all characters of a cheat sequence correctly
if (cht->timeout && maptime - cht->timeout > (cht->longtimeout ? HU_MSGTIMEOUT : HU_MSGTIMEOUT / 2))
{
cht->chars_read = 0;
cht->param_chars_read = 0;
}
cht->timeout = maptime;
if (cht->chars_read < strlen(cht->sequence))
{
// still reading characters from the cheat code
// and verifying. reset back to the beginning
// if a key is wrong
if (toupper(key) == toupper(cht->sequence[cht->chars_read]))
cht->chars_read++;
else
// [BH] recognize key as first in sequence if it matches, rather than resetting
cht->chars_read = (toupper(key) == toupper(cht->sequence[0]));
cht->param_chars_read = 0;
if (cht->chars_read > 1 && !cht->movekey)
cheatkey = key;
}
else if (cht->param_chars_read < cht->parameter_chars)
{
// we have passed the end of the cheat sequence and are
// entering parameters now
if (!isdigit(key))
{
cht->chars_read = 0;
cht->param_chars_read = 0;
cht->timeout = 0;
return false;
}
else
{
cht->parameter_buf[cht->param_chars_read] = key;
cht->param_chars_read++;
}
}
if (cht->chars_read >= strlen(cht->sequence) && cht->param_chars_read >= cht->parameter_chars)
{
cht->chars_read = 0;
cht->param_chars_read = 0;
cht->timeout = 0;
return true;
}
// cheat not matched yet
return false;
}
void cht_GetParam(const cheatseq_t *cht, char *buffer)
{
memcpy(buffer, cht->parameter_buf, cht->parameter_chars);
}