From 465620a871e7da8d72d82a999eac8623570d13fd Mon Sep 17 00:00:00 2001 From: fusion32 Date: Sat, 13 Sep 2025 00:37:10 -0300 Subject: add `MAX_DEPOTS` constant + enable assertions in debug mode --- Makefile | 2 +- src/common.hh | 18 +++++++++++++++++- src/cr.hh | 4 ++-- src/crplayer.cc | 16 ++++++---------- src/moveuse.cc | 2 +- src/receiving.cc | 2 +- tools/makefile.go | 8 +++++--- 7 files changed, 33 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 80eda20..097c430 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ LFLAGS = -Wl,-t -lcrypto DEBUG ?= 0 ifneq ($(DEBUG), 0) - CFLAGS += -g -Og + CFLAGS += -g -Og -DENABLE_ASSERTIONS=1 else CFLAGS += -O2 endif diff --git a/src/common.hh b/src/common.hh index daf66ad..a8f1460 100644 --- a/src/common.hh +++ b/src/common.hh @@ -66,7 +66,7 @@ typedef size_t usize; #endif #define ASSERT_ALWAYS(expr) if(!(expr)) { TRAP(); } -#if BUILD_DEBUG +#if ENABLE_ASSERTIONS # define ASSERT(expr) ASSERT_ALWAYS(expr) #else # define ASSERT(expr) ((void)(expr)) @@ -86,6 +86,22 @@ STATIC_ASSERT(OS_LINUX); # define sigev_notify_thread_id _sigev_un._tid #endif +// Constants +// ============================================================================= +// TODO(fusion): There are many constants that are hardcoded as decompilation +// artifacts. We should define them here and use when appropriate. It is not +// as simple because I've been using `NARRAY` in some cases and they're used +// essentially everywhere. + +//#define MAX_NAME 30 // used with most short strings (should replace MAX_IDENT_LENGTH too) +//#define MAX_IPADDRESS 16 +//#define MAX_BUDDIES 100 +//#define MAX_SKILLS 25 +//#define MAX_SPELLS 256 +//#define MAX_QUESTS 500 +#define MAX_DEPOTS 9 +//#define MAX_OPEN_CONTAINERS 16 + // shm.cc // ============================================================================= void StartGame(void); diff --git a/src/cr.hh b/src/cr.hh index 6617c76..c4034e5 100644 --- a/src/cr.hh +++ b/src/cr.hh @@ -143,8 +143,8 @@ struct TPlayerData { int MurderTimestamps[20]; uint8 *Inventory; int InventorySize; - uint8 *Depot[9]; - int DepotSize[9]; + uint8 *Depot[MAX_DEPOTS]; + int DepotSize[MAX_DEPOTS]; uint32 AccountID; int Sex; char Name[30]; diff --git a/src/crplayer.cc b/src/crplayer.cc index 86c2aba..66e5ba5 100644 --- a/src/crplayer.cc +++ b/src/crplayer.cc @@ -1986,7 +1986,7 @@ void LoadDepot(TPlayerData *PlayerData, int DepotNr, Object Con){ throw ERROR; } - if(DepotNr < 0 || DepotNr >= 9){ // MAX_DEPOT ? + if(DepotNr < 0 || DepotNr >= MAX_DEPOTS){ error("LoadDepot: Ungültige Depotnummer %d.\n", DepotNr); throw ERROR; } @@ -2022,7 +2022,7 @@ void SaveDepot(TPlayerData *PlayerData, int DepotNr, Object Con){ throw ERROR; } - if(DepotNr < 0 || DepotNr >= 9){ // MAX_DEPOT ? + if(DepotNr < 0 || DepotNr >= MAX_DEPOTS){ error("SaveDepot: Ungültige Depotnummer %d.\n", DepotNr); throw ERROR; } @@ -2364,7 +2364,7 @@ bool LoadPlayerData(TPlayerData *Slot){ } int DepotNr = Script.getNumber(); - if(DepotNr < 0 || DepotNr >= NARRAY(Slot->Depot)){ + if(DepotNr < 0 || DepotNr >= MAX_DEPOTS){ Script.error("illegal depot number"); } @@ -2398,9 +2398,7 @@ bool LoadPlayerData(TPlayerData *Slot){ Slot->Inventory = NULL; Slot->InventorySize = 0; - for(int DepotNr = 0; - DepotNr < NARRAY(Slot->Depot); - DepotNr += 1){ + for(int DepotNr = 0; DepotNr < MAX_DEPOTS; DepotNr += 1){ delete[] Slot->Depot[DepotNr]; Slot->Depot[DepotNr] = NULL; Slot->DepotSize[DepotNr] = 0; @@ -2597,9 +2595,7 @@ void SavePlayerData(TPlayerData *Slot){ bool FirstDepot = true; Script.writeText("Depots = {"); - for(int DepotNr = 0; - DepotNr < NARRAY(Slot->Depot); - DepotNr += 1){ + for(int DepotNr = 0; DepotNr < MAX_DEPOTS; DepotNr += 1){ if(Slot->Depot[DepotNr] != NULL){ TReadBuffer Buffer(Slot->Depot[DepotNr], Slot->DepotSize[DepotNr]); if(!FirstDepot){ @@ -2671,7 +2667,7 @@ void FreePlayerPoolSlot(TPlayerData *Slot){ } delete[] Slot->Inventory; - for(int DepotNr = 0; DepotNr < 9; DepotNr += 1){ // MAX_DEPOT ? + for(int DepotNr = 0; DepotNr < MAX_DEPOTS; DepotNr += 1){ delete[] Slot->Depot[DepotNr]; } diff --git a/src/moveuse.cc b/src/moveuse.cc index b1c7090..bdf6565 100644 --- a/src/moveuse.cc +++ b/src/moveuse.cc @@ -874,7 +874,7 @@ void SendMails(TPlayerData *PlayerData){ } int DepotNr = Mail->DepotNumber; - if(DepotNr < 0 || DepotNr >= 9){ // MAX_DEPOT ? + if(DepotNr < 0 || DepotNr >= MAX_DEPOTS){ error("SendMails: Ungültige Depotnummer %d.\n", DepotNr); DepotNr = 0; } diff --git a/src/receiving.cc b/src/receiving.cc index 7546396..3cf3f66 100644 --- a/src/receiving.cc +++ b/src/receiving.cc @@ -1620,7 +1620,7 @@ void CRuleViolation(TConnection *Connection, TReadBuffer *Buffer){ } } - PunishmentOrder(Player, Name,IPAddress, Reason, Action, Comment, + PunishmentOrder(Player, Name, IPAddress, Reason, Action, Comment, NumberOfStatements, ReportedStatements, StatementID, IPBanishment); } diff --git a/tools/makefile.go b/tools/makefile.go index 6b0ad55..b76efcf 100644 --- a/tools/makefile.go +++ b/tools/makefile.go @@ -26,7 +26,9 @@ var ( "-DOS_LINUX=1", "-DARCH_X64=1", } - linkerOptions = []string{ + debugOptions = []string{"-g", "-Og", "-DENABLE_ASSERTIONS=1"} + releaseOptions = []string{"-O2"} + linkerOptions = []string{ "-Wl,-t", "-lcrypto", } @@ -78,9 +80,9 @@ func main() { // DEBUG SWITCH fmt.Fprint(&output, "DEBUG ?= 0\n") fmt.Fprint(&output, "ifneq ($(DEBUG), 0)\n") - fmt.Fprint(&output, "\tCFLAGS += -g -Og\n") + fmt.Fprintf(&output, "\tCFLAGS += %v\n", strings.Join(debugOptions, " ")) fmt.Fprint(&output, "else\n") - fmt.Fprint(&output, "\tCFLAGS += -O2\n") + fmt.Fprintf(&output, "\tCFLAGS += %v\n", strings.Join(releaseOptions, " ")) fmt.Fprint(&output, "endif\n\n") // HEADERS -- cgit v1.2.3