Skip to content

Commit 9f10b60

Browse files
committed
Add to tOSIRISModuleInit serial_version field
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.
1 parent 93d7729 commit 9f10b60

File tree

4 files changed

+25
-30
lines changed

4 files changed

+25
-30
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ endif()
7575

7676
# 64 bit machines have a different game checksum than 32 bit machines
7777
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
78-
add_definitions(-DCHECKSUM=2273890030UL)
78+
add_definitions(-DCHECKSUM=2273864794UL)
7979
else()
80-
add_definitions(-DCHECKSUM=2273873406UL)
80+
add_definitions(-DCHECKSUM=2273860746UL)
8181
endif()
8282

8383
if(BUILD_TESTING)

Descent3/OsirisLoadandBind.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,12 +631,13 @@ void Osiris_InitModuleLoader(void) {
631631
// Generates a checksum of the game's structures, to give to the modules
632632
// so they can use to compare to the time when they were compiled, to see
633633
// if they are compatible.
634-
uint32_t Osiris_CreateGameChecksum(void) {
634+
uint32_t Osiris_CreateGameChecksum() {
635635
uint32_t value = 0xe1e1b0b0;
636+
tOSIRISModuleInit tmp;
636637

637638
value += sizeof(object);
638639
value += sizeof(player) * 2;
639-
value += sizeof(tOSIRISModuleInit) * 3;
640+
value += tmp.serial_version * 3;
640641
value += sizeof(tOSIRISEventInfo) * 5;
641642
value += sizeof(tOSIRISTIMER) * 7;
642643
value += sizeof(tOSIRISSCRIPTID) * 11;

Descent3/tests/porting-tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525
// This is copy of actual Osiris_CreateGameChecksum(void) from OsirisLoadandBind.cpp
2626
uint32_t Osiris_CreateGameChecksumTest() {
2727
uint32_t value = 0xe1e1b0b0;
28+
tOSIRISModuleInit tmp;
2829

2930
value += sizeof(object);
3031
value += sizeof(player) * 2;
31-
value += sizeof(tOSIRISModuleInit) * 3;
32+
value += tmp.serial_version * 3;
3233
value += sizeof(tOSIRISEventInfo) * 5;
3334
value += sizeof(tOSIRISTIMER) * 7;
3435
value += sizeof(tOSIRISSCRIPTID) * 11;

scripts/osiris_common.h

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Descent 3
2+
* Descent 3
33
* Copyright (C) 2024 Parallax Software
44
*
55
* This program is free software: you can redistribute it and/or modify
@@ -969,6 +969,10 @@ struct gb_menu {
969969
// =======================================================================
970970

971971
struct tOSIRISModuleInit {
972+
// IMPORTANT! Increment serial each time when tOSIRISModuleInit is changed
973+
// (and update CHECKSUM define accordingly).
974+
uint32_t serial_version = 1;
975+
972976
int32_t *fp[MAX_MODULEFUNCS];
973977
std::vector<std::string> string_table;
974978
int32_t string_count;
@@ -996,8 +1000,7 @@ struct tOSIRISEVTINTERVAL {
9961000
float game_time;
9971001
}; // struct for EVT_INTERVAL data
9981002

999-
struct tOSIRISIEVTAIFRAME {
1000-
}; // struct for EVT_AI_FRAME data
1003+
struct tOSIRISIEVTAIFRAME {}; // struct for EVT_AI_FRAME data
10011004

10021005
struct tOSIRISEVTDAMAGED {
10031006
float damage;
@@ -1010,12 +1013,11 @@ struct tOSIRISEVTCOLLIDE {
10101013
int32_t it_handle;
10111014
}; // struct for EVT_COLLIDE data
10121015

1013-
struct tOSIRISEVTCREATED {
1014-
}; // struct for EVT_CREATED data
1016+
struct tOSIRISEVTCREATED {}; // struct for EVT_CREATED data
10151017

10161018
struct tOSIRISEVTDESTROY {
1017-
uint8_t is_dying; // if this is !=0 than the event is coming because it is
1018-
// really being destroyed. Else it is due to the level ending.
1019+
uint8_t is_dying; // if this is !=0 than the event is coming because it is
1020+
// really being destroyed. Else it is due to the level ending.
10191021
}; // struct for EVT_DESTROY data
10201022

10211023
struct tOSIRISEVTTIMER {
@@ -1046,14 +1048,11 @@ struct tOSIRISEVTAINOTIFY {
10461048
};
10471049
}; // struct for EVT_AI_NOTIFY data
10481050

1049-
struct tOSIRISEVTAIINIT {
1050-
}; // struct for EVT_AI_INIT data
1051+
struct tOSIRISEVTAIINIT {}; // struct for EVT_AI_INIT data
10511052

1052-
struct tOSIRISEVTLEVELSTART {
1053-
}; // struct for EVT_LEVELSTART data
1053+
struct tOSIRISEVTLEVELSTART {}; // struct for EVT_LEVELSTART data
10541054

1055-
struct tOSIRISEVTLEVELEND {
1056-
}; // struct for EVT_LEVELEND data
1055+
struct tOSIRISEVTLEVELEND {}; // struct for EVT_LEVELEND data
10571056

10581057
struct tOSIRISEVTCHANGESEG {
10591058
int32_t room_num;
@@ -1078,11 +1077,9 @@ struct tOSIRISEVTMATCENCREATE {
10781077
int32_t id;
10791078
}; // struct for EVT_MATCEN_CREATE data
10801079

1081-
struct tOSIRISEVTDOORACTIVATE {
1082-
}; // struct for EVT_DOOR_ACTIVATE data
1080+
struct tOSIRISEVTDOORACTIVATE {}; // struct for EVT_DOOR_ACTIVATE data
10831081

1084-
struct tOSIRISEVTDOORCLOSE {
1085-
}; // struct for EVT_DOOR_CLOSE data
1082+
struct tOSIRISEVTDOORCLOSE {}; // struct for EVT_DOOR_CLOSE data
10861083

10871084
struct tOSIRISEVTLEVELGOALCOMPLETE {
10881085
int32_t level_goal_index;
@@ -1092,14 +1089,11 @@ struct tOSIRISEVTLEVELGOALITEMCOMPLETE {
10921089
int32_t level_goal_index;
10931090
};
10941091

1095-
struct tOSIRISEVTALLLEVELGOALSCOMPLETE {
1096-
};
1092+
struct tOSIRISEVTALLLEVELGOALSCOMPLETE {};
10971093

1098-
struct tOSIRISEVTPLAYERMOVIESTART {
1099-
};
1094+
struct tOSIRISEVTPLAYERMOVIESTART {};
11001095

1101-
struct tOSIRISEVTPLAYERMOVIEEND {
1102-
};
1096+
struct tOSIRISEVTPLAYERMOVIEEND {};
11031097

11041098
struct tOSIRISEVTPLAYERRESPAWN {
11051099
int32_t it_handle; // player respawning
@@ -1156,7 +1150,7 @@ struct tOSIRISEventInfo {
11561150
int32_t me_handle;
11571151
void *extra_info;
11581152
}; // contains the necessary data for all events
1159-
// to pass what they need to their event handlers.
1153+
// to pass what they need to their event handlers.
11601154

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

13071301
// Second message
13081302
char message2[MSAFE_MESSAGE_LENGTH];
1309-
13101303
};
13111304

13121305
struct ray_info {

0 commit comments

Comments
 (0)