summaryrefslogtreecommitdiffhomepage
path: root/src/demorec.c
diff options
context:
space:
mode:
authorMichael Smith <mikesmiffy128@gmail.com>2023-07-29 14:32:06 +0100
committerMichael Smith <mikesmiffy128@gmail.com>2023-08-02 21:02:31 +0100
commit9a0d8730fa977f666b5c12e4c5901e7d0391e245 (patch)
tree87eebcdcef04ae1e7348ef80e972c08aa4783649 /src/demorec.c
parentd337b09936ecd90bad07b28b48b7103395d97ce5 (diff)
Make various preparations for upcoming features
A lot of this is random WIP from a while back, at least a month ago, and is being committed now to get it out of the way so that other patches can be brought in and integrated against it without causing headaches. Also rolled into this commit is a way to distinguish plugin_unload from exiting the game. This is required for another soon-to-be-integrated feature to avoid crashing on exit, and could in theory also be used to speed up unloading on exit in future. While we're at it, this also avoids the need to linearly scan through the plugin list to do the old branch unloading fix, because we can. Rough summary of the other smaller stuff I can remember doing: - Rework bitbuf a bit - Add some cryptographic nonsense in ac.c (not final at all) - Introduce the first couple of "chunklets" libraries as a sort-of subproject of this one - Tidy up random small bits and bobs - Add source for a small keypair generation tool - Rework democustom to be very marginally more useful
Diffstat (limited to 'src/demorec.c')
-rw-r--r--src/demorec.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/demorec.c b/src/demorec.c
index e176ab3..e728ca5 100644
--- a/src/demorec.c
+++ b/src/demorec.c
@@ -50,6 +50,10 @@ bool demorec_forceauto = false;
#define SIGNONSTATE_SPAWN 5
#define SIGNONSTATE_FULL 6
+DEF_PREDICATE(DemoControlAllowed, void)
+DEF_EVENT(DemoRecordStarting, void)
+DEF_EVENT(DemoRecordStopped, int)
+
typedef void (*VCALLCONV SetSignonState_func)(void *, int);
static SetSignonState_func orig_SetSignonState;
static void VCALLCONV hook_SetSignonState(void *this_, int state) {
@@ -83,6 +87,9 @@ static void VCALLCONV hook_StopRecording(void *this) {
*recording = true;
*demonum = lastnum;
}
+ else {
+ EMIT_DemoRecordStopped(lastnum);
+ }
}
DECL_VFUNC_DYN(void, StartRecording)
@@ -90,10 +97,8 @@ DECL_VFUNC_DYN(void, StartRecording)
static struct con_cmd *cmd_record, *cmd_stop;
static con_cmdcb orig_record_cb, orig_stop_cb;
-DEF_PREDICATE(AllowDemoControl, void)
-
static void hook_record_cb(const struct con_cmdargs *args) {
- if (!CHECK_AllowDemoControl()) return;
+ if (!CHECK_DemoControlAllowed()) return;
bool was = *recording;
if (!was && args->argc == 2 || args->argc == 3) {
// safety check: make sure a directory exists, otherwise recording
@@ -152,10 +157,11 @@ static void hook_record_cb(const struct con_cmdargs *args) {
// mike: I think this is questionably necessary but I'm outvoted :)
con_msg("Demo recording started\n");
}
+ EMIT_DemoRecordStarting();
}
static void hook_stop_cb(const struct con_cmdargs *args) {
- if (!CHECK_AllowDemoControl()) return;
+ if (!CHECK_DemoControlAllowed()) return;
wantstop = true;
orig_stop_cb(args);
wantstop = false;
@@ -229,6 +235,7 @@ bool demorec_start(const char *name) {
struct con_cmdargs args = {.argc = 2, .argv = {0, name, 0}};
orig_record_cb(&args);
if (!was && *recording) *demonum = 0; // same logic as in the hook
+ EMIT_DemoRecordStarting();
return *recording;
}
@@ -237,11 +244,12 @@ int demorec_stop(void) {
// making this correct when recording and stopping in the menu lol
int ret = *demonum;
orig_StopRecording(demorecorder);
+ EMIT_DemoRecordStopped(ret);
return ret;
}
-bool demorec_recording(void) {
- return *recording;
+int demorec_demonum(void) {
+ return *recording ? *demonum : -1;
}
INIT {