add MAX_DEPOTS constant + enable assertions in debug mode

This commit is contained in:
fusion32 2025-09-13 00:37:10 -03:00
parent 16f2e00b05
commit 465620a871
7 changed files with 33 additions and 19 deletions

View File

@ -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

View File

@ -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);

View File

@ -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];

View File

@ -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];
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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