aboutsummaryrefslogtreecommitdiff
path: root/src/l4dreset.c
diff options
context:
space:
mode:
authorGravatar Michael Smith <mikesmiffy128@gmail.com> 2024-09-25 18:25:08 +0100
committerGravatar Michael Smith <mikesmiffy128@gmail.com> 2024-09-28 18:28:13 +0100
commitbc9198ba9b654117118a06399d4dbf273262501d (patch)
tree73572d7807797ff22333aeefffae19a708bdd9af /src/l4dreset.c
parenta62d7366a6061c1873b87ead944e2521f589b0c7 (diff)
downloadsst-bc9198ba9b654117118a06399d4dbf273262501d.tar.gz
sst-bc9198ba9b654117118a06399d4dbf273262501d.zip
Create and use macros to define accessor functions
Avoids the need to manually mess around with mem_offset() and gamedata off_ and sz_ values as often, because that's kind of annoying. Should also make the codebase a little less confusing for new players.
Diffstat (limited to 'src/l4dreset.c')
-rw-r--r--src/l4dreset.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/l4dreset.c b/src/l4dreset.c
index a53b987..9e72f04 100644
--- a/src/l4dreset.c
+++ b/src/l4dreset.c
@@ -19,6 +19,7 @@
#include <string.h>
#include "abi.h"
+#include "accessor.h"
#include "con_.h"
#include "engineapi.h"
#include "ent.h"
@@ -75,9 +76,11 @@ DECL_VFUNC(const char *, SetIssueDetails, 1 + NVDTOR, const char *)
DECL_VFUNC(const char *, GetDisplayString, 8 + NVDTOR)
DECL_VFUNC(const char *, ExecuteCommand, 9 + NVDTOR)
+DEF_PTR_ACCESSOR(struct CUtlVector, voteissues)
+DEF_PTR_ACCESSOR(struct CUtlVector, callerrecords)
+
static struct CVoteIssue *getissue(const char *textkey) {
- struct CUtlVector *issuevec = mem_offset(*votecontroller, off_voteissues);
- struct CVoteIssue **issues = issuevec->m.mem;
+ struct CVoteIssue **issues = getptr_voteissues(*votecontroller)->m.mem;
for (int i = 0; /*i < issuevec->sz*/; ++i) { // key MUST be valid!
if (!strcmp(GetDisplayString(issues[i]), textkey)) return issues[i];
}
@@ -86,12 +89,12 @@ static struct CVoteIssue *getissue(const char *textkey) {
static inline void reset(void) {
// reset the vote cooldowns if possible (will skip L4D1). only necessary on
// versions >2045 and on map 1, but it's easiest to do unconditionally.
- // the way this is written will *hopefully* produce a nice neat lea+cmovne.
- struct CUtlVector *recordvector = mem_offset(*votecontroller,
- off_callerrecords);
// This is equivalent to CUtlVector::RemoveAll() as there's no
// destructors to call. The result as is if nobody had ever voted.
- if_random (off_callerrecords != -1) recordvector->sz = 0;
+ // the way this is written will *hopefully* produce a nice neat lea+cmovne.
+ if_random (off_callerrecords != -1) {
+ getptr_callerrecords(*votecontroller)->sz = 0;
+ }
ExecuteCommand(getissue("#L4D_vote_restart_game"));
}