Skip to content

Commit

Permalink
Add to tOSIRISModuleInit serial_version field
Browse files Browse the repository at this point in the history
This field intended to solve problem when CHECKSUM is different on various platforms and environments due variadic size of structs. Unfortunately, this approach cannot be applied for all structs used in checksum calculation since part of them are poorly serialized/deserialized by fread() / fwrite() functions.
  • Loading branch information
winterheart committed Aug 11, 2024
1 parent 3a5f5a5 commit 116b574
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 30 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ endif()

# 64 bit machines have a different game checksum than 32 bit machines
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
add_definitions(-DCHECKSUM=2273890030UL)
add_definitions(-DCHECKSUM=2273864794UL)
else()
add_definitions(-DCHECKSUM=2273873406UL)
add_definitions(-DCHECKSUM=2273860746UL)
endif()

if(BUILD_TESTING)
Expand Down
5 changes: 3 additions & 2 deletions Descent3/OsirisLoadandBind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,12 +631,13 @@ void Osiris_InitModuleLoader(void) {
// Generates a checksum of the game's structures, to give to the modules
// so they can use to compare to the time when they were compiled, to see
// if they are compatible.
uint32_t Osiris_CreateGameChecksum(void) {
uint32_t Osiris_CreateGameChecksum() {
uint32_t value = 0xe1e1b0b0;
tOSIRISModuleInit tmp;

value += sizeof(object);
value += sizeof(player) * 2;
value += sizeof(tOSIRISModuleInit) * 3;
value += tmp.serial_version * 3;
value += sizeof(tOSIRISEventInfo) * 5;
value += sizeof(tOSIRISTIMER) * 7;
value += sizeof(tOSIRISSCRIPTID) * 11;
Expand Down
3 changes: 2 additions & 1 deletion Descent3/tests/porting-tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
// This is copy of actual Osiris_CreateGameChecksum(void) from OsirisLoadandBind.cpp
uint32_t Osiris_CreateGameChecksumTest() {
uint32_t value = 0xe1e1b0b0;
tOSIRISModuleInit tmp;

value += sizeof(object);
value += sizeof(player) * 2;
value += sizeof(tOSIRISModuleInit) * 3;
value += tmp.serial_version * 3;
value += sizeof(tOSIRISEventInfo) * 5;
value += sizeof(tOSIRISTIMER) * 7;
value += sizeof(tOSIRISSCRIPTID) * 11;
Expand Down
43 changes: 18 additions & 25 deletions scripts/osiris_common.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Descent 3
* Descent 3
* Copyright (C) 2024 Parallax Software
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -969,6 +969,10 @@ struct gb_menu {
// =======================================================================

struct tOSIRISModuleInit {
// IMPORTANT! Increment serial each time when tOSIRISModuleInit is changed
// (and update CHECKSUM define accordingly).
uint32_t serial_version = 1;

int32_t *fp[MAX_MODULEFUNCS];
std::vector<std::string> string_table;
int32_t string_count;
Expand Down Expand Up @@ -996,8 +1000,7 @@ struct tOSIRISEVTINTERVAL {
float game_time;
}; // struct for EVT_INTERVAL data

struct tOSIRISIEVTAIFRAME {
}; // struct for EVT_AI_FRAME data
struct tOSIRISIEVTAIFRAME {}; // struct for EVT_AI_FRAME data

struct tOSIRISEVTDAMAGED {
float damage;
Expand All @@ -1010,12 +1013,11 @@ struct tOSIRISEVTCOLLIDE {
int32_t it_handle;
}; // struct for EVT_COLLIDE data

struct tOSIRISEVTCREATED {
}; // struct for EVT_CREATED data
struct tOSIRISEVTCREATED {}; // struct for EVT_CREATED data

struct tOSIRISEVTDESTROY {
uint8_t is_dying; // if this is !=0 than the event is coming because it is
// really being destroyed. Else it is due to the level ending.
uint8_t is_dying; // if this is !=0 than the event is coming because it is
// really being destroyed. Else it is due to the level ending.
}; // struct for EVT_DESTROY data

struct tOSIRISEVTTIMER {
Expand Down Expand Up @@ -1046,14 +1048,11 @@ struct tOSIRISEVTAINOTIFY {
};
}; // struct for EVT_AI_NOTIFY data

struct tOSIRISEVTAIINIT {
}; // struct for EVT_AI_INIT data
struct tOSIRISEVTAIINIT {}; // struct for EVT_AI_INIT data

struct tOSIRISEVTLEVELSTART {
}; // struct for EVT_LEVELSTART data
struct tOSIRISEVTLEVELSTART {}; // struct for EVT_LEVELSTART data

struct tOSIRISEVTLEVELEND {
}; // struct for EVT_LEVELEND data
struct tOSIRISEVTLEVELEND {}; // struct for EVT_LEVELEND data

struct tOSIRISEVTCHANGESEG {
int32_t room_num;
Expand All @@ -1078,11 +1077,9 @@ struct tOSIRISEVTMATCENCREATE {
int32_t id;
}; // struct for EVT_MATCEN_CREATE data

struct tOSIRISEVTDOORACTIVATE {
}; // struct for EVT_DOOR_ACTIVATE data
struct tOSIRISEVTDOORACTIVATE {}; // struct for EVT_DOOR_ACTIVATE data

struct tOSIRISEVTDOORCLOSE {
}; // struct for EVT_DOOR_CLOSE data
struct tOSIRISEVTDOORCLOSE {}; // struct for EVT_DOOR_CLOSE data

struct tOSIRISEVTLEVELGOALCOMPLETE {
int32_t level_goal_index;
Expand All @@ -1092,14 +1089,11 @@ struct tOSIRISEVTLEVELGOALITEMCOMPLETE {
int32_t level_goal_index;
};

struct tOSIRISEVTALLLEVELGOALSCOMPLETE {
};
struct tOSIRISEVTALLLEVELGOALSCOMPLETE {};

struct tOSIRISEVTPLAYERMOVIESTART {
};
struct tOSIRISEVTPLAYERMOVIESTART {};

struct tOSIRISEVTPLAYERMOVIEEND {
};
struct tOSIRISEVTPLAYERMOVIEEND {};

struct tOSIRISEVTPLAYERRESPAWN {
int32_t it_handle; // player respawning
Expand Down Expand Up @@ -1156,7 +1150,7 @@ struct tOSIRISEventInfo {
int32_t me_handle;
void *extra_info;
}; // contains the necessary data for all events
// to pass what they need to their event handlers.
// to pass what they need to their event handlers.

#define OTF_REPEATER 0x0001 // this timer is to repeat repeat_count times
#define OTF_TRIGGER 0x0002 // this timer is for a trigger, use trigger_number
Expand Down Expand Up @@ -1306,7 +1300,6 @@ struct msafe_struct {

// Second message
char message2[MSAFE_MESSAGE_LENGTH];

};

struct ray_info {
Expand Down

0 comments on commit 116b574

Please sign in to comment.