diff options
author | Michael Smith <mikesmiffy128@gmail.com> | 2022-07-31 16:02:10 +0100 |
---|---|---|
committer | Michael Smith <mikesmiffy128@gmail.com> | 2022-08-10 22:40:52 +0100 |
commit | 5e921bf59373d79d27c322ff86e8b5a37b151e45 (patch) | |
tree | 4d40e39543b085ce4c8cb9b1a7b3c0108de680c0 /src/fov.c | |
parent | c8d7588251fd4fe63ac6afe2a90ca7066c786609 (diff) |
Add magical feature codegen system, at long last
Diffstat (limited to 'src/fov.c')
-rw-r--r-- | src/fov.c | 25 |
1 files changed, 12 insertions, 13 deletions
@@ -24,6 +24,7 @@ #include "errmsg.h" #include "ent.h" #include "event.h" +#include "feature.h" #include "gametype.h" #include "hook.h" #include "intdefs.h" @@ -31,8 +32,11 @@ #include "sst.h" #include "vcall.h" #include "x86.h" +#include "x86util.h" + +FEATURE("extended FOV range") +REQUEST(ent) -bool changedmax = false; DEF_CVAR_MINMAX_UNREG(fov_desired, "Set the base field of view (SST reimplementation)", 75, 75, 120, CON_HIDDEN | CON_ARCHIVE) @@ -58,13 +62,7 @@ static bool find_SetDefaultFOV(struct con_cmd *fov) { mem_loadoffset(p + 1)); return true; } - int len = x86_len(p); - if (len == -1) { - errmsg_errorx("unknown or invalid instruction looking for %s", - "SetDefaultFOV"); - return false; - } - p += len; + NEXT_INSN(p, "SetDefaultFOV"); } return false; } @@ -75,7 +73,7 @@ static void fovcb(struct con_var *v) { if (player) orig_SetDefaultFOV(player, con_getvari(v)); } -// called by sst.c in ClientActive to ensure fov is applied on load +// ensure FOV is applied on load, if the engine wouldn't do that itself HANDLE_EVENT(ClientActive) { if (real_fov_desired == fov_desired) { void *player = ent_get(1); // " @@ -85,14 +83,15 @@ HANDLE_EVENT(ClientActive) { static struct con_cmd *cmd_fov; -bool fov_init(bool has_ent) { +PREINIT { // could work for other games, but generally only portal 1 people want this // (the rest of us consider this cheating and a problem for runs...) - if (!GAMETYPE_MATCHES(Portal1)) { return false; } + return GAMETYPE_MATCHES(Portal1); +} +INIT { cmd_fov = con_findcmd("fov"); if (!cmd_fov) return false; // shouldn't really happen but just in case! - if (real_fov_desired = con_findvar("fov_desired")) { // latest steampipe already goes up to 120 fov if (real_fov_desired->parent->maxval == 120) return false; @@ -122,7 +121,7 @@ bool fov_init(bool has_ent) { return true; } -void fov_end(void) { +END { if (real_fov_desired && real_fov_desired != fov_desired) { real_fov_desired->parent->maxval = 90; if (con_getvarf(real_fov_desired) > 90) { |