Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

Commit

Permalink
Basic support (reads, writes, is exposed, not set tested)
Browse files Browse the repository at this point in the history
  FNV::QUSTRecord, FNV::IDLERecord, FNV::PACKRecord, FNV::CSTYRecord, FNV::LSCRRecord
All currently supported records have been write tested.
  Includes copy as new, override.
  Resulting esp loaded in TES4Edit for confirmation.
All currently supported records have been extensively read tested.
  All situations where a chunk is smaller than expected have been dealt with.
Various tweaks to various records as a result of read/write testing.
Commented out pointer checks in API
  Caller assumes all responsibility for passing valid pointers
CopyRecord tweaked to behave better on hardcoded formIDs and editorID keyed records
  • Loading branch information
waruddar committed May 19, 2011
1 parent 14abf9d commit 0598c4b
Show file tree
Hide file tree
Showing 74 changed files with 11,352 additions and 4,826 deletions.
Binary file modified CBash.suo
Binary file not shown.
136 changes: 68 additions & 68 deletions CBash/CBash.cpp

Large diffs are not rendered by default.

318 changes: 314 additions & 4 deletions CBash/CBash.vcproj

Large diffs are not rendered by default.

28 changes: 22 additions & 6 deletions CBash/Collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ Record * Collection::CreateRecord(ModFile *&curModFile, const UINT32 &RecordType
LookupRecord(curModFile, RecordFormID, DummyRecord);
else if(RecordEditorID != NULL)
LookupRecord(curModFile, RecordEditorID, DummyRecord);

if(DummyRecord != NULL)
return DummyRecord;

Expand Down Expand Up @@ -793,21 +794,36 @@ Record * Collection::CopyRecord(ModFile *&curModFile, Record *&curRecord, ModFil
Record *ParentRecord = NULL;
Record *RecordCopy = NULL;

if((DestRecordFormID & 0x00FFFFFF) < END_HARDCODED_IDS)
DestRecordFormID &= 0x00FFFFFF;

if(options.SetAsOverride)
{
//See if its trying to copy a record that already exists in the destination mod
if(curRecord->IsKeyedByEditorID())
LookupRecord(DestModFile, curRecord->GetEditorIDKey(), RecordCopy);
LookupRecord(DestModFile, DestRecordEditorID ? DestRecordEditorID : curRecord->GetEditorIDKey(), RecordCopy);
else
LookupRecord(DestModFile, DestRecordFormID ? DestRecordFormID : curRecord->formID, RecordCopy);
}
else if(DestRecordFormID != 0)
{
//If the objectID of a formID is less than END_HARDCODED_IDS, then it doesn't use the modIndex portion
//instead, it "belongs" to the engine, and they all override each other
if((DestRecordFormID & 0x00FFFFFF) < END_HARDCODED_IDS)
DestRecordFormID &= 0x00FFFFFF;

if(RecordCopy != NULL)
return RecordCopy;
//See if its trying to copy a record that already exists in the destination mod
if(curRecord->IsKeyedByEditorID())
LookupRecord(DestModFile, DestRecordEditorID ? DestRecordEditorID : curRecord->GetEditorIDKey(), RecordCopy);
else
LookupRecord(DestModFile, DestRecordFormID, RecordCopy);
}
else if(curRecord->IsKeyedByEditorID())
{
//See if its trying to copy a record that already exists in the destination mod
LookupRecord(DestModFile, DestRecordEditorID ? DestRecordEditorID : curRecord->GetEditorIDKey(), RecordCopy);
}

if(RecordCopy != NULL)
return RecordCopy;

if(DestParentFormID)
{
//See if the parent record already exists in the destination mod
Expand Down
130 changes: 88 additions & 42 deletions CBash/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1014,12 +1014,16 @@ struct OptSimpleSubRecord
else if(subSize < sizeof(T))
{
#ifdef CBASH_CHUNK_WARN
printf("OptSimpleSubRecord: Info - Unable to fully parse chunk (%c%c%c%c). Size "
"of chunk (%u) is less than the size of the subrecord (%u) and any "
"remaining fields have their default value.\n",
(buffer + curPos)[-6], (buffer + curPos)[-5], (buffer + curPos)[-4], (buffer + curPos)[-3],
subSize, sizeof(T));
CBASH_CHUNK_DEBUG
UINT32 test = *((UINT32 *)(buffer + curPos - 6));
if (!(test == REV32(PKPT) && subSize == 1 && sizeof(T) == 2))
{
printf("OptSimpleSubRecord: Info - Unable to fully parse chunk (%c%c%c%c). Size "
"of chunk (%u) is less than the size of the subrecord (%u) and any "
"remaining fields have their default value.\n",
(buffer + curPos)[-6], (buffer + curPos)[-5], (buffer + curPos)[-4], (buffer + curPos)[-3],
subSize, sizeof(T));
CBASH_CHUNK_DEBUG
}
#endif
memcpy(&value, buffer + curPos, subSize);
}
Expand All @@ -1037,6 +1041,11 @@ struct OptSimpleSubRecord
writer.record_write_subrecord(_Type, &value, sizeof(T));
}

void ReqWrite(UINT32 _Type, FileWriter &writer)
{
writer.record_write_subrecord(_Type, &value, sizeof(T));
}

OptSimpleSubRecord<T, defaultValue>& operator = (const OptSimpleSubRecord<T, defaultValue> &rhs)
{
if(this != &rhs)
Expand Down Expand Up @@ -1129,6 +1138,10 @@ struct OptSimpleFloatSubRecord
if(IsLoaded())
writer.record_write_subrecord(_Type, &value, sizeof(FLOAT32));
}
void ReqWrite(UINT32 _Type, FileWriter &writer)
{
writer.record_write_subrecord(_Type, &value, sizeof(FLOAT32));
}

OptSimpleFloatSubRecord<defaultValue>& operator = (const OptSimpleFloatSubRecord<defaultValue> &rhs)
{
Expand Down Expand Up @@ -1521,30 +1534,46 @@ struct ReqSubRecord
{
if(subSize > sizeof(T))
{
#ifdef CBASH_CHUNK_WARN
printf("ReqSubRecord: Warning - Unable to fully parse chunk (%c%c%c%c). "
"Size of chunk (%u) is larger than the size of the subrecord (%u) "
"and will be truncated.\n",
(buffer + curPos)[-6], (buffer + curPos)[-5], (buffer + curPos)[-4], (buffer + curPos)[-3],
subSize, sizeof(T));
CBASH_CHUNK_DEBUG
#endif
#ifdef CBASH_CHUNK_WARN
printf("ReqSubRecord: Warning - Unable to fully parse chunk (%c%c%c%c). "
"Size of chunk (%u) is larger than the size of the subrecord (%u) "
"and will be truncated.\n",
(buffer + curPos)[-6], (buffer + curPos)[-5], (buffer + curPos)[-4], (buffer + curPos)[-3],
subSize, sizeof(T));
CBASH_CHUNK_DEBUG
#endif
memcpy(&value, buffer + curPos, sizeof(T));
}
#ifdef CBASH_CHUNK_LCHECK
else if(subSize < sizeof(T))
#ifdef CBASH_CHUNK_LCHECK
else if(subSize < sizeof(T))
{
#ifdef CBASH_CHUNK_WARN
#ifdef CBASH_CHUNK_WARN
UINT32 test = *((UINT32 *)(buffer + curPos - 6));
UINT32 test2 = *((UINT32 *)(buffer + curPos + subSize));
if (!(test == REV32(DATA) && (test2 == REV32(DIAL) || test2 == REV32(GRUP)) && subSize == 1 && sizeof(T) == 2) &&
!(test == REV32(DATA) && (test2 == REV32(CNAM) || test2 == REV32(RNAM) || test2 == REV32(WMI1)) && sizeof(T) == 4 && subSize == 1) &&
!(test == REV32(SNDX) && subSize == 12) &&
!(test == REV32(DNAM) && test2 == REV32(ITXT) && subSize == 3) &&
!(test == REV32(DNAM) && (test2 == REV32(ARMO) || test2 == REV32(BNAM)) && subSize == 4 && sizeof(T) == 12) &&
!(test == REV32(DNAM) && (test2 == REV32(CRDT) || test2 == REV32(VATS)) && sizeof(T) == 204) && //multiple possible subSizes
!(test == REV32(VATS) && (test2 == REV32(VNAM) || test2 == REV32(WEAP)) && subSize == 16 && sizeof(T) == 20) &&
!(test == REV32(DATA) && (test2 == REV32(NAM1) || test2 == REV32(NAM2) || test2 == REV32(VNAM) || test2 == REV32(PROJ)) && subSize == 68 && sizeof(T) == 84) &&
!(test == REV32(DATA) && (test2 == REV32(CTDA) || test2 == REV32(INDX) || test2 == REV32(QOBJ)) && subSize == 2 && sizeof(T) == 8) &&
!(test == REV32(DATA) && (test2 == REV32(IDLE) || test2 == REV32(GRUP)) && subSize == 6 && sizeof(T) == 8) &&
!(test == REV32(PKDT) && subSize == 8 && sizeof(T) == 12)
)
{
printf("ReqSubRecord: Info - Unable to fully parse chunk (%c%c%c%c). Size "
"of chunk (%u) is less than the size of the subrecord (%u) and any "
"remaining fields have their default value.\n",
(buffer + curPos)[-6], (buffer + curPos)[-5], (buffer + curPos)[-4], (buffer + curPos)[-3],
subSize, sizeof(T));
CBASH_CHUNK_DEBUG
#endif
}
#endif
memcpy(&value, buffer + curPos, subSize);
}
#endif
#endif
else
memcpy(&value, buffer + curPos, subSize);
//size = subSize;
Expand Down Expand Up @@ -1631,14 +1660,21 @@ struct OptSubRecord
#ifdef CBASH_CHUNK_LCHECK
else if(subSize < sizeof(T))
{
#ifdef CBASH_CHUNK_WARN
#ifdef CBASH_CHUNK_WARN
UINT32 test = *((UINT32 *)(buffer + curPos - 6));
UINT32 test2 = *((UINT32 *)(buffer + curPos + subSize));
if (!(test == REV32(XCLC) && subSize == 8) &&
!(test == REV32(DAT2) && (test2 == REV32(ONAM) || test2 == REV32(QNAM) || test2 == REV32(RCIL) || test2 == REV32(AMMO)) && subSize == 12 && sizeof(T) == 20)
)
{
printf("OptSubRecord: Info - Unable to fully parse chunk (%c%c%c%c). Size "
"of chunk (%u) is less than the size of the subrecord (%u) and any "
"remaining fields have their default value.\n",
(buffer + curPos)[-6], (buffer + curPos)[-5], (buffer + curPos)[-4], (buffer + curPos)[-3],
subSize, sizeof(T));
CBASH_CHUNK_DEBUG
#endif
}
#endif
memcpy(value, buffer + curPos, subSize);
}
#endif
Expand Down Expand Up @@ -1746,30 +1782,34 @@ struct SemiOptSubRecord
value = new T();
if(subSize > sizeof(T))
{
#ifdef CBASH_CHUNK_WARN
printf("SemiOptSubRecord: Warning - Unable to fully parse chunk (%c%c%c%c). "
"Size of chunk (%u) is larger than the size of the subrecord (%u) "
"and will be truncated.\n",
(buffer + curPos)[-6], (buffer + curPos)[-5], (buffer + curPos)[-4], (buffer + curPos)[-3],
subSize, sizeof(T));
CBASH_CHUNK_DEBUG
#endif
#ifdef CBASH_CHUNK_WARN
printf("SemiOptSubRecord: Warning - Unable to fully parse chunk (%c%c%c%c). "
"Size of chunk (%u) is larger than the size of the subrecord (%u) "
"and will be truncated.\n",
(buffer + curPos)[-6], (buffer + curPos)[-5], (buffer + curPos)[-4], (buffer + curPos)[-3],
subSize, sizeof(T));
CBASH_CHUNK_DEBUG
#endif
memcpy(value, buffer + curPos, sizeof(T));
}
#ifdef CBASH_CHUNK_LCHECK
else if(subSize < sizeof(T))
#ifdef CBASH_CHUNK_LCHECK
else if(subSize < sizeof(T))
{
#ifdef CBASH_CHUNK_WARN
#ifdef CBASH_CHUNK_WARN
UINT32 test = *((UINT32 *)(buffer + curPos - 6));
if(!(test == REV32(XLOC) && subSize == 12 && sizeof(T) == 20))
{
printf("SemiOptSubRecord: Info - Unable to fully parse chunk (%c%c%c%c). Size "
"of chunk (%u) is less than the size of the subrecord (%u) and any "
"remaining fields have their default value.\n",
(buffer + curPos)[-6], (buffer + curPos)[-5], (buffer + curPos)[-4], (buffer + curPos)[-3],
subSize, sizeof(T));
CBASH_CHUNK_DEBUG
#endif
}
#endif
memcpy(value, buffer + curPos, subSize);
}
#endif
#endif
else
memcpy(value, buffer + curPos, subSize);
curPos += subSize;
Expand Down Expand Up @@ -2328,12 +2368,18 @@ struct OrderedSparseArray<T *, _Pr>
else if(subSize < sizeof(T))
{
#ifdef CBASH_CHUNK_WARN
printf("OrderedSparseArray: Info - Unable to fully parse chunk (%c%c%c%c). Size "
"of chunk (%u) is less than the size of the subrecord (%u) and any "
"remaining fields have their default value.\n",
(buffer + curPos)[-6], (buffer + curPos)[-5], (buffer + curPos)[-4], (buffer + curPos)[-3],
subSize, sizeof(T));
CBASH_CHUNK_DEBUG
UINT32 test = *((UINT32 *)(buffer + curPos - 6));
if (!((test == REV32(SCRO) || test == REV32(SCRV)) && subSize == 4) &&
!(test == REV32(CTDA) && (subSize == 20 || subSize == 24)&& sizeof(T) == 28)
)
{
printf("OrderedSparseArray: Info - Unable to fully parse chunk (%c%c%c%c). Size "
"of chunk (%u) is less than the size of the subrecord (%u) and any "
"remaining fields have their default value.\n",
(buffer + curPos)[-6], (buffer + curPos)[-5], (buffer + curPos)[-4], (buffer + curPos)[-3],
subSize, sizeof(T));
CBASH_CHUNK_DEBUG
}
#endif
memcpy(&(*value.back()), buffer + curPos, subSize);
}
Expand Down Expand Up @@ -2555,7 +2601,7 @@ struct UnorderedSparseArray<T *>
if(subSize > sizeof(T))
{
#ifdef CBASH_CHUNK_WARN
printf("OrderedSparseArray: Warning - Unable to fully parse chunk (%c%c%c%c). "
printf("UnorderedSparseArray: Warning - Unable to fully parse chunk (%c%c%c%c). "
"Size of chunk (%u) is larger than the size of the subrecord (%u) "
"and will be truncated.\n",
(buffer + curPos)[-6], (buffer + curPos)[-5], (buffer + curPos)[-4], (buffer + curPos)[-3],
Expand All @@ -2568,7 +2614,7 @@ struct UnorderedSparseArray<T *>
else if(subSize < sizeof(T))
{
#ifdef CBASH_CHUNK_WARN
printf("OrderedSparseArray: Info - Unable to fully parse chunk (%c%c%c%c). Size "
printf("UnorderedSparseArray: Info - Unable to fully parse chunk (%c%c%c%c). Size "
"of chunk (%u) is less than the size of the subrecord (%u) and any "
"remaining fields have their default value.\n",
(buffer + curPos)[-6], (buffer + curPos)[-5], (buffer + curPos)[-4], (buffer + curPos)[-3],
Expand Down
Loading

0 comments on commit 0598c4b

Please sign in to comment.