Skip to content

Commit

Permalink
Save FIELD_BOOLEAN as byte array
Browse files Browse the repository at this point in the history
Resolves twhl-community#65

(cherry picked from commit c147156)
  • Loading branch information
SamVanheer authored and LogicAndTrick committed Dec 24, 2021
1 parent 85a7b77 commit 1d686dd
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions dlls/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2489,6 +2489,7 @@ int CSave :: WriteFields( const char *cname, const char *pname, void *pBaseData,
int i, j, actualCount, emptyCount;
TYPEDESCRIPTION *pTest;
int entityArray[MAX_ENTITYARRAY];
byte boolArray[MAX_ENTITYARRAY];

// Precalculate the number of empty fields
emptyCount = 0;
Expand Down Expand Up @@ -2565,6 +2566,18 @@ int CSave :: WriteFields( const char *cname, const char *pname, void *pBaseData,
break;

case FIELD_BOOLEAN:
{
//TODO: need to refactor save game stuff to make this cleaner and reusable
//Convert booleans to bytes
for (j = 0; j < pTest->fieldSize; j++)
{
boolArray[j] = ((BOOL*)pOutputData)[j] ? 1 : 0;
}

WriteData(pTest->fieldName, pTest->fieldSize, (char*)boolArray);
}
break;

case FIELD_INTEGER:
WriteInt( pTest->fieldName, (int *)pOutputData, pTest->fieldSize );
break;
Expand Down Expand Up @@ -2784,6 +2797,15 @@ int CRestore::ReadField( void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCou
break;

case FIELD_BOOLEAN:
{
// Input and Output sizes are different!
pOutputData = (char*)pOutputData + j * (sizeof(bool) - gSizes[pTest->fieldType]);
const BOOL value = *((byte*)pInputData) != 0;

*((BOOL*)pOutputData) = value;
}
break;

case FIELD_INTEGER:
*((int *)pOutputData) = *( int *)pInputData;
break;
Expand Down

0 comments on commit 1d686dd

Please sign in to comment.