aboutsummaryrefslogtreecommitdiff
path: root/src/ac.c
diff options
context:
space:
mode:
authorGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-03-10 02:37:19 +0000
committerGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-04-06 16:41:13 +0100
commit244fea664121acf12871ab5858a5fe95a2606b52 (patch)
treee42b1990ef97adc0f0ab48b9be7e11de7fee0558 /src/ac.c
parentd86b7b41453c69b3854baa7cdc05a79a3cdfe092 (diff)
downloadsst-244fea664121acf12871ab5858a5fe95a2606b52.tar.gz
sst-244fea664121acf12871ab5858a5fe95a2606b52.zip
Rewrite and redesign codegen and feature system
Also switch to somewhat proper C23 flags while we're at it. This is a huge change. It took me forever, in between being really busy. Sorry about that. But the good news is I'm now free to start integrating the various patches that have accumulated since last release. Well, at least in between still being really busy. Gotta manage expectations. The main benefit of introducing GAMESPECIFIC() is that features that don't apply to a particular game no longer show up *at all*, and less time is wasted on init. It also enables a cool optimisation wherein unnecessary REQUIRE_GAMEDATA() checks can elided at compile time whenever the gamedata is known up-front to always exist in supported games. The DEF_FEAT_CVAR macro family meanwhile makes it easier to manage the lifecycle of cvars/ccmds, with less manual registering, unhiding and such. Originally I was going to try and just hack these features into the existing codegen abomination, but it just got too terrible. This rewrite should make it easier to continue tweaking codegen behaviour in future. It also has slightly better error messages.
Diffstat (limited to 'src/ac.c')
-rw-r--r--src/ac.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/ac.c b/src/ac.c
index 7f3157c..e8aef8d 100644
--- a/src/ac.c
+++ b/src/ac.c
@@ -1,5 +1,5 @@
/*
- * Copyright © 2024 Michael Smith <mikesmiffy128@gmail.com>
+ * Copyright © 2025 Michael Smith <mikesmiffy128@gmail.com>
* Copyright © 2023 Willian Henrique <wsimanbrazil@yahoo.com.br>
*
* Permission to use, copy, modify, and/or distribute this software for any
@@ -32,13 +32,13 @@
#include "crypto.h"
#include "democustom.h"
#include "demorec.h"
-#include "hook.h"
#include "engineapi.h"
#include "errmsg.h"
#include "event.h"
#include "feature.h"
#include "gamedata.h"
#include "gametype.h"
+#include "hook.h"
#include "intdefs.h"
#include "langext.h"
#include "mem.h"
@@ -50,6 +50,7 @@
#include "x86util.h"
FEATURE()
+GAMESPECIFIC(L4D) // TODO(compat): wanna add support for more stuff, obviously!
REQUIRE(bind)
REQUIRE(democustom)
REQUIRE_GAMEDATA(vtidx_GetDesktopResolution)
@@ -291,7 +292,7 @@ static void hook_Key_Event(struct inputevent *ev) {
//const char *desc[] = {"DOWN", "UP", "DBL"};
//const char desclen[] = {4, 2, 3};
switch (ev->type) {
- CASES(BTNDOWN, BTNUP, BTNDOUBLECLICK):;
+ CASES(BTNDOWN, BTNUP, BTNDOUBLECLICK):
// TODO(rta): do something interesting with button data
//uchar buf[28], *p = buf;
//msg_putasz4(p, 2); p += 1;
@@ -378,24 +379,20 @@ HANDLE_EVENT(PluginUnloaded, void) {
// TODO(rta): do something with plugin list here
}
-PREINIT {
- return GAMETYPE_MATCHES(L4D); // TODO(compat): add more here obviously
-}
-
INIT {
- if_cold (!find_Key_Event()) return false;
+ if_cold (!find_Key_Event()) return FEAT_INCOMPAT;
orig_Key_Event = (Key_Event_func)hook_inline((void *)orig_Key_Event,
(void *)&hook_Key_Event);
if_cold (!orig_Key_Event) {
errmsg_errorsys("couldn't hook Key_Event function");
- return false;
+ return FEAT_FAIL;
}
#ifdef _WIN32
keybox = VirtualAlloc(0, 4096, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
if_cold (!keybox) {
errmsg_errorsys("couldn't allocate memory for session state");
- return false;
+ return FEAT_FAIL;
}
if_cold (!VirtualLock(keybox, 4096)) {
errmsg_errorsys("couldn't secure session state");
@@ -411,7 +408,7 @@ INIT {
keybox = mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
if_cold (keybox == MAP_FAILED) {
errmsg_errorstd("couldn't allocate memory for session state");
- return false;
+ return FEAT_FAIL;
}
// linux-specific madvise stuff (there are some equivalents in OpenBSD and
// FreeBSD, if anyone's wondering, but we don't need to worry about those)
@@ -432,7 +429,7 @@ INIT {
// run of bytes
memcpy(keybox->lbpub, lbpubkeys[LBPK_L4D], 32);
}
- return true;
+ return FEAT_OK;
#ifdef _WIN32
e: WerUnregisterExcludedMemoryBlock(keybox); // this'd better not fail!
@@ -441,7 +438,7 @@ e2: VirtualFree(keybox, 4096, MEM_RELEASE);
e: munmap(keybox, 4096);
#endif
unhook_inline((void *)orig_Key_Event);
- return false;
+ return FEAT_FAIL;
}
END {