aboutsummaryrefslogtreecommitdiff
path: root/src/chatrate.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/chatrate.c')
-rw-r--r--src/chatrate.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/chatrate.c b/src/chatrate.c
index 54572a5..9c1f40c 100644
--- a/src/chatrate.c
+++ b/src/chatrate.c
@@ -32,18 +32,16 @@ static uchar *patchedbyte;
// So, instead of adding 0.66 to the current time, we subtract it, and that
// means we can always chat immediately.
-static inline bool find_ratelimit_insn(struct con_cmd *cmd_say) {
- // Find the add instruction
- uchar *insns = (uchar *)cmd_say->cb;
- for (uchar *p = insns; p - insns < 128;) {
+static inline bool find_ratelimit_insn(const uchar *insns) {
+ for (const uchar *p = insns; p - insns < 128;) {
// find FADD
if (p[0] == X86_FLTBLK5 && p[1] == X86_MODRM(0, 0, 5)) {
- patchedbyte = p + 1;
+ patchedbyte = (uchar *)p + 1;
return true;
}
// Portal 2, L4D2 2125-2134, L4D:S all use SSE2, so try finding ADDSD
if (p[0] == X86_PFX_REPN && p[1] == X86_2BYTE & p[2] == X86_2B_ADD) {
- patchedbyte = p + 2;
+ patchedbyte = (uchar *)p + 2;
return true;
}
NEXT_INSN(p, "chat rate limit");
@@ -53,7 +51,7 @@ static inline bool find_ratelimit_insn(struct con_cmd *cmd_say) {
static inline bool patch_ratelimit_insn() {
// if FADD replace with FSUB; otherwise it is ADDSD, replace that with SUBSD
- if (!os_mprot(patchedbyte, 1, PAGE_EXECUTE_READWRITE)) {
+ if_cold (!os_mprot(patchedbyte, 1, PAGE_EXECUTE_READWRITE)) {
errmsg_errorsys("failed to patch chat rate limit: "
"couldn't make memory writable");
return false;
@@ -71,8 +69,8 @@ static inline void unpatch_ratelimit_insn() {
INIT {
struct con_cmd *cmd_say = con_findcmd("say");
- if_cold (!cmd_say) return false;
- if (!find_ratelimit_insn(cmd_say)) {
+ if_cold (!cmd_say) return FEAT_INCOMPAT; // should never happen!
+ if (!find_ratelimit_insn(cmd_say->cb_insns)) {
errmsg_errorx("couldn't find chat rate limit instruction");
return FEAT_INCOMPAT;
}