MCPcopy Create free account
hub / github.com/dhewm/dhewm3 / CalculateChecksum

Method CalculateChecksum

neo/game/script/Script_Program.cpp:2060–2124  ·  view source on GitHub ↗

================ idProgram::CalculateChecksum ================ */

Source from the content-addressed store, hash-verified

2058================
2059*/
2060int idProgram::CalculateChecksum( bool forOldSavegame ) const {
2061 int i, result;
2062
2063 typedef struct {
2064 unsigned short op;
2065 int a;
2066 int b;
2067 int c;
2068 unsigned short linenumber;
2069 unsigned short file;
2070 } statementBlock_t;
2071
2072 statementBlock_t *statementList = new statementBlock_t[ statements.Num() ];
2073
2074 memset( statementList, 0, ( sizeof(statementBlock_t) * statements.Num() ) );
2075
2076 // DG hack: get the vardef for the argSize == 0 constant for savegame-compat
2077 int constantZeroNum = -1;
2078 if ( forOldSavegame ) {
2079 for( idVarDef* def = GetDefList( "<IMMEDIATE>" ); def != NULL; def = def->Next() ) {
2080 if ( def->Type() == ev_argsize && def->value.argSize == 0 ) {
2081 constantZeroNum = def->num;
2082 break;
2083 }
2084 }
2085 }
2086
2087 // Copy info into new list, using the variable numbers instead of a pointer to the variable
2088 for( i = 0; i < statements.Num(); i++ ) {
2089 statementList[i].op = statements[i].op;
2090
2091 if ( statements[i].a ) {
2092 statementList[i].a = statements[i].a->num;
2093 } else {
2094 statementList[i].a = -1;
2095 }
2096 if ( statements[i].b ) {
2097 statementList[i].b = statements[i].b->num;
2098 } else {
2099 statementList[i].b = -1;
2100 }
2101 if ( statements[i].c ) {
2102 // DG: old savegames wrongly assumed argSize 0 for some statements.
2103 // So for the checksums to match we need to use the corresponding vardef num here
2104 // See idCompiler::EmitFunctionParms() and ParseFunctionDef() for more details.
2105 if ( forOldSavegame && statements[i].op == OP_OBJECTCALL
2106 && statements[i].flags == statement_t::FLAG_OBJECTCALL_IMPL_NOT_PARSED_YET ) {
2107 statementList[i].c = constantZeroNum;
2108 } else {
2109 statementList[i].c = statements[i].c->num;
2110 }
2111 } else {
2112 statementList[i].c = -1;
2113 }
2114
2115 statementList[i].linenumber = statements[i].linenumber;
2116 statementList[i].file = statements[i].file;
2117 }

Callers

nothing calls this directly

Calls 4

MD4_BlockChecksumFunction · 0.85
NumMethod · 0.45
NextMethod · 0.45
TypeMethod · 0.45

Tested by

no test coverage detected