summaryrefslogtreecommitdiffhomepage
path: root/src/gameinfo.c
diff options
context:
space:
mode:
authorMichael Smith <mikesmiffy128@gmail.com>2022-04-30 00:23:31 +0100
committerMichael Smith <mikesmiffy128@gmail.com>2022-04-30 00:34:47 +0100
commit1a5c55eb89c22e8822ec057a3731a6d753f13859 (patch)
treefa09dd757a1966649119f70717bd11d679c0f179 /src/gameinfo.c
parent1aaedffd8c68614936c59d4681e6dc111cb32691 (diff)
Centralise engine access, add Portal FOV changer
- A bunch of stuff is now defined in one header, engineapi.h - engineapi.c is responsible for setting up any interfaces/stuff that's used in more than one place - mkgamedata is pretty much rewritten and now supports nested conditionals - gamedata variables no longer have the gamedata_ prefix because it was just annoyingly long all the time - vcall macros are somewhat revamped and support dynamic (gamedata) indices - Portal 1 FOV can be set anywhere from 75-120 using fov_desired - tested in both the main versions currently used by runners - A few typos were also fixed ("intput," "writeable," "indexes")
Diffstat (limited to 'src/gameinfo.c')
-rw-r--r--src/gameinfo.c37
1 files changed, 8 insertions, 29 deletions
diff --git a/src/gameinfo.c b/src/gameinfo.c
index 95cce97..36c9402 100644
--- a/src/gameinfo.c
+++ b/src/gameinfo.c
@@ -20,6 +20,7 @@
#endif
#include "con_.h"
+#include "engineapi.h"
#include "gametype.h"
#include "intdefs.h"
#include "kv.h"
@@ -173,13 +174,7 @@ static void kv_cb(enum kv_token type, const char *p, uint len, void *_ctxt) {
};
// values for ctxt->matchtype
- enum {
- mt_none,
- mt_title,
- mt_nest,
- mt_game,
- mt_gamebin
- };
+ enum { mt_none, mt_title, mt_nest, mt_game, mt_gamebin };
#define MATCH(s) (len == sizeof(s) - 1 && matchtok(p, s, sizeof(s) - 1))
switch (type) {
@@ -238,29 +233,13 @@ static void kv_cb(enum kv_token type, const char *p, uint len, void *_ctxt) {
#undef MATCH
}
-bool gameinfo_init(void *(*ifacef)(const char *, int *)) {
- typedef char *(*VCALLCONV GetGameDirectory_func)(void *this);
- GetGameDirectory_func **engclient;
- int off;
- if (engclient = ifacef("VEngineClient015", 0)) { // portal 2 (post-release?)
- off = 35;
- }
- else if (engclient = ifacef("VEngineClient014", 0)) { // l4d2000-~2027, bms?
- if (!GAMETYPE_MATCHES(L4D2x)) goto unsup;
- off = 73; // YES, THIS IS SEVENTY THREE ALL OF A SUDDEN. I KNOW. CRAZY.
- }
- else if (engclient = ifacef("VEngineClient013", 0)) { // ...most things?
- if (GAMETYPE_MATCHES(L4Dx)) off = 36; // THEY CHANGED IT BACK LATER!?
- else off = 35;
- }
- else if (engclient = ifacef("VEngineClient012", 0)) { // dmomm, ep1, ...
- off = 37;
- }
- else {
-unsup: con_warn("gameinfo: unsupported VEngineClient interface\n");
+DECL_VFUNC_DYN(const char *, GetGameDirectory)
+
+bool gameinfo_init(void) {
+ if (!has_vtidx_GetGameDirectory) {
+ con_warn("gameinfo: unsupported VEngineClient interface\n");
return false;
}
- GetGameDirectory_func GetGameDirectory = (*engclient)[off];
// engine always calls chdir() with its own base path on startup, so engine
// base dir is just cwd
@@ -280,7 +259,7 @@ unsup: con_warn("gameinfo: unsupported VEngineClient interface\n");
#ifdef _WIN32
int gamedirlen = _snwprintf(gamedir, sizeof(gamedir) / sizeof(*gamedir),
- L"%S", GetGameDirectory(engclient));
+ L"%S", VCALL(engclient, GetGameDirectory));
if (gamedirlen < 0) { // encoding error??? ugh...
con_warn("gameinfo: invalid game directory path!\n");
return false;