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

Commit

Permalink
Changed API function: AllowRaising now takes a function pointer that …
Browse files Browse the repository at this point in the history
…has a const STRING argument

  Raised callbacks now include the API function name where the exception was thrown
AddMod now returns ModFile * instead of a status code
Added API function: SINT32 IsRecordFormIDsInvalid(Record *RecordID)
  Returns whether the record uses any formIDs that were invalidated by CBash based on the formID's master index
  Does not detect formIDs that either don't exist or aren't valid for a given chunk field
Renamed load flag IsIgnoreAbsentMasters to IsIgnoreInactiveMasters
Fixed some bugs with using the land indexing option
  No longer crashes, no longer reads cell records twice in some circumstances
Fixed usage of IsNoLoad
  More functions are now allowed if IsNoLoad is used

cint:
Now encodes all strings passed to CBash with mbcs (likely to change)
Added dump_record to cint for debugging
Fixed Debug_DumpModFiles
  • Loading branch information
waruddar committed Nov 17, 2011
1 parent 98e6e13 commit 61937da
Show file tree
Hide file tree
Showing 25 changed files with 806 additions and 584 deletions.
Binary file modified CBash.suo
Binary file not shown.
160 changes: 97 additions & 63 deletions CBash/CBash.cpp

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions CBash/CBash.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ DLLEXTERN UINT32 GetVersionRevision();
////////////////////////////////////////////////////////////////////////
//Logging action functions
DLLEXTERN void RedirectMessages(SINT32 (*_LoggingCallback)(const STRING));
DLLEXTERN void AllowRaising(void (*_RaiseCallback)());
DLLEXTERN void AllowRaising(void (*_RaiseCallback)(const STRING));
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
//Collection action functions
Expand All @@ -56,7 +56,7 @@ DLLEXTERN SINT32 DeleteAllCollections();
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
//Mod action functions
DLLEXTERN SINT32 AddMod(Collection *CollectionID, STRING const ModName, const UINT32 ModFlagsField);
DLLEXTERN ModFile * AddMod(Collection *CollectionID, STRING const ModName, const UINT32 ModFlagsField);
DLLEXTERN SINT32 LoadMod(ModFile *ModID);
DLLEXTERN SINT32 UnloadMod(ModFile *ModID);
DLLEXTERN SINT32 CleanModMasters(ModFile *ModID);
Expand Down Expand Up @@ -109,6 +109,7 @@ DLLEXTERN SINT32 GetRecordConflicts(Record *RecordID, RECORDIDARRAY RecordIDs, c
DLLEXTERN SINT32 GetRecordHistory(Record *RecordID, RECORDIDARRAY RecordIDs);
DLLEXTERN SINT32 GetNumIdenticalToMasterRecords(ModFile *ModID);
DLLEXTERN SINT32 GetIdenticalToMasterRecords(ModFile *ModID, RECORDIDARRAY RecordIDs);
DLLEXTERN SINT32 IsRecordsFormIDsInvalid(Record *RecordID);
////////////////////////////////////////////////////////////////////////
//Mod or Record action functions
DLLEXTERN SINT32 UpdateReferences(ModFile *ModID, Record *RecordID, FORMIDARRAY OldFormIDs, FORMIDARRAY NewFormIDs, UINT32ARRAY Changes, const UINT32 ArraySize);
Expand Down
141 changes: 107 additions & 34 deletions CBash/Collection.cpp

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion CBash/Collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Collection
Collection(STRING const &ModsPath, UINT32 _CollectionType);
~Collection();

SINT32 AddMod(STRING const &_FileName, ModFlags &flags, bool IsPreloading=false);
ModFile * AddMod(STRING const &_FileName, ModFlags &flags, bool IsPreloading=false);
ModFile * IsModAdded(STRING const &ModName);
SINT32 SaveMod(ModFile *&curModFile, SaveFlags &flags, STRING const DestinationName);

Expand Down Expand Up @@ -119,6 +119,26 @@ class RecordReader : public RecordOp
bool Accept(Record *&curRecord);
};

class RecordInvalidFormIDChecker : public RecordOp
{
private:
class InvalidFormIDChecker : public FormIDOp
{
public:
InvalidFormIDChecker();
~InvalidFormIDChecker();

bool Accept(UINT32 &curFormID);
bool AcceptMGEF(UINT32 &curMgefCode);
} checker;

public:
RecordInvalidFormIDChecker();
~RecordInvalidFormIDChecker();

bool Accept(Record *&curRecord);
};

class RecordDeindexer : public RecordOp
{
private:
Expand Down
20 changes: 10 additions & 10 deletions CBash/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ GPL License and Copyright Notice ============================================

int (*printer)(const char * _Format, ...) = &printf;
SINT32 (*LoggingCallback)(const STRING) = NULL;
void (*RaiseCallback)() = NULL;
void (*RaiseCallback)(const STRING) = NULL;

#ifdef CBASH_DEBUG_VARS
std::map<unsigned long, unsigned long> uint32_uint32_map1;
Expand Down Expand Up @@ -711,28 +711,28 @@ bool FormIDHandlerClass::IsValid(const unsigned char *_SrcBuf)
return (_SrcBuf >= FileStart && _SrcBuf <= FileEnd);
}

CreateRecordOptions::CreateRecordOptions():
CreationFlags::CreationFlags():
SetAsOverride(false),
CopyWinningParent(false),
ExistingReturned(false)
{
//
}

CreateRecordOptions::CreateRecordOptions(UINT32 nFlags):
CreationFlags::CreationFlags(UINT32 nFlags):
SetAsOverride((nFlags & fSetAsOverride) != 0),
CopyWinningParent((nFlags & fCopyWinningParent) != 0),
ExistingReturned(false)
{
//
}

CreateRecordOptions::~CreateRecordOptions()
CreationFlags::~CreationFlags()
{
//
}

UINT32 CreateRecordOptions::GetFlags()
UINT32 CreationFlags::GetFlags()
{
UINT32 flags = 0;
if(SetAsOverride)
Expand All @@ -756,7 +756,7 @@ ModFlags::ModFlags():
IsIndexLANDs(false),
IsFixupPlaceables(false),
IsCreateNew(false),
IsIgnoreAbsentMasters(false),
IsIgnoreInactiveMasters(false),
LoadedGRUPs(false)
{
//
Expand All @@ -770,14 +770,14 @@ ModFlags::ModFlags(UINT32 _Flags):
IsSkipAllRecords((_Flags & fIsSkipAllRecords) != 0),
IsInLoadOrder((_Flags & fIsInLoadOrder) != 0),
IsSaveable(((_Flags & fIsInLoadOrder) != 0) ? ((_Flags & fIsSaveable) != 0) : false),
IsAddMasters(((_Flags & fIsIgnoreAbsentMasters) != 0) ? false : ((_Flags & fIsAddMasters) != 0)),
IsAddMasters(((_Flags & fIsIgnoreInactiveMasters) != 0) ? false : ((_Flags & fIsAddMasters) != 0)),
IsLoadMasters((_Flags & fIsLoadMasters) != 0),
IsExtendedConflicts((_Flags & fIsExtendedConflicts) != 0),
IsTrackNewTypes((_Flags & fIsTrackNewTypes) != 0),
IsIndexLANDs((_Flags & fIsIndexLANDs) != 0),
IsFixupPlaceables((_Flags & fIsFixupPlaceables) != 0),
IsCreateNew((_Flags & fIsCreateNew) != 0),
IsIgnoreAbsentMasters((_Flags & fIsIgnoreAbsentMasters) != 0),
IsIgnoreInactiveMasters((_Flags & fIsIgnoreInactiveMasters) != 0),
LoadedGRUPs(false)
{
//
Expand Down Expand Up @@ -825,10 +825,10 @@ UINT32 ModFlags::GetFlags()
flags |= fIsFixupPlaceables;
if(IsCreateNew)
flags |= fIsCreateNew;
if(IsIgnoreAbsentMasters)
if(IsIgnoreInactiveMasters)
{
flags &= ~fIsAddMasters;
flags |= fIsIgnoreAbsentMasters;
flags |= fIsIgnoreInactiveMasters;
}
return flags;
}
Expand Down
40 changes: 20 additions & 20 deletions CBash/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ GPL License and Copyright Notice ============================================

extern int (*printer)(const char * _Format, ...);
extern SINT32 (*LoggingCallback)(const STRING);
extern void (*RaiseCallback)();
extern void (*RaiseCallback)(const STRING);

enum whichGameTypes {
eIsOblivion = 0,
Expand Down Expand Up @@ -452,7 +452,7 @@ class FormIDHandlerClass
bool IsValid(const unsigned char *_SrcBuf);
};

class CreateRecordOptions
class CreationFlags
{
private:
enum createFlags
Expand All @@ -462,9 +462,9 @@ class CreateRecordOptions
};

public:
CreateRecordOptions();
CreateRecordOptions(UINT32 nFlags);
~CreateRecordOptions();
CreationFlags();
CreationFlags(UINT32 nFlags);
~CreationFlags();

bool SetAsOverride;
bool CopyWinningParent;
Expand Down Expand Up @@ -528,20 +528,20 @@ class ModFlags
// Scanned: (fIsMinLoad or fIsFullLoad) + fIsSkipNewRecords + fIsExtendedConflicts
enum modFlags
{
fIsMinLoad = 0x00000001,
fIsFullLoad = 0x00000002,
fIsSkipNewRecords = 0x00000004,
fIsInLoadOrder = 0x00000008,
fIsSaveable = 0x00000010,
fIsAddMasters = 0x00000020,
fIsLoadMasters = 0x00000040,
fIsExtendedConflicts = 0x00000080,
fIsTrackNewTypes = 0x00000100,
fIsIndexLANDs = 0x00000200,
fIsFixupPlaceables = 0x00000400,
fIsCreateNew = 0x00000800,
fIsIgnoreAbsentMasters = 0x00001000,
fIsSkipAllRecords = 0x00002000,
fIsMinLoad = 0x00000001,
fIsFullLoad = 0x00000002,
fIsSkipNewRecords = 0x00000004,
fIsInLoadOrder = 0x00000008,
fIsSaveable = 0x00000010,
fIsAddMasters = 0x00000020,
fIsLoadMasters = 0x00000040,
fIsExtendedConflicts = 0x00000080,
fIsTrackNewTypes = 0x00000100,
fIsIndexLANDs = 0x00000200,
fIsFixupPlaceables = 0x00000400,
fIsCreateNew = 0x00000800,
fIsIgnoreInactiveMasters = 0x00001000,
fIsSkipAllRecords = 0x00002000,
};

public:
Expand All @@ -563,7 +563,7 @@ class ModFlags
bool IsIndexLANDs;
bool IsFixupPlaceables;
bool IsCreateNew;
bool IsIgnoreAbsentMasters;
bool IsIgnoreInactiveMasters;

//For internal use, may not be set by constructor
bool LoadedGRUPs;
Expand Down
32 changes: 16 additions & 16 deletions CBash/FalloutNewVegas/FNVFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,13 +895,13 @@ UINT32 FNVFile::GetNumRecords(const UINT32 &RecordType)
return 0;
}

Record * FNVFile::CreateRecord(const UINT32 &RecordType, STRING const &RecordEditorID, Record *&SourceRecord, Record *&ParentRecord, CreateRecordOptions &options)
Record * FNVFile::CreateRecord(const UINT32 &RecordType, STRING const &RecordEditorID, Record *&SourceRecord, Record *&ParentRecord, CreationFlags &options)
{
if(Flags.IsNoLoad)
{
printer("FNVFile::CreateRecord: Error - Unable to create any records in mod \"%s\". The mod is flagged not to be loaded.\n", ModName);
return NULL;
}
//if(Flags.IsNoLoad)
// {
// printer("FNVFile::CreateRecord: Error - Unable to create any records in mod \"%s\". The mod is flagged not to be loaded.\n", ModName);
// return NULL;
// }

Record *newRecord = NULL;

Expand Down Expand Up @@ -2260,11 +2260,11 @@ SINT32 FNVFile::Save(STRING const &SaveName, std::vector<FormIDResolver *> &Expa

void FNVFile::VisitAllRecords(RecordOp &op)
{
if(Flags.IsNoLoad)
{
printer("FNVFile::VisitAllRecords: Error - Unable to visit records in mod \"%s\". The mod is flagged not to be loaded.\n", ModName);
return;
}
//if(Flags.IsNoLoad)
// {
// printer("FNVFile::VisitAllRecords: Error - Unable to visit records in mod \"%s\". The mod is flagged not to be loaded.\n", ModName);
// return;
// }

//This visits every record and subrecord
{
Expand Down Expand Up @@ -2392,11 +2392,11 @@ void FNVFile::VisitAllRecords(RecordOp &op)

void FNVFile::VisitRecords(const UINT32 &RecordType, RecordOp &op)
{
if(Flags.IsNoLoad)
{
printer("FNVFile::VisitRecords: Error - Unable to visit records in mod \"%s\". The mod is flagged not to be loaded.\n", ModName);
return;
}
//if(Flags.IsNoLoad)
// {
// printer("FNVFile::VisitRecords: Error - Unable to visit records in mod \"%s\". The mod is flagged not to be loaded.\n", ModName);
// return;
// }

switch(RecordType)
{
Expand Down
2 changes: 1 addition & 1 deletion CBash/FalloutNewVegas/FNVFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class FNVFile : public ModFile
SINT32 Load(RecordOp &read_parser, RecordOp &indexer, std::vector<FormIDResolver *> &Expanders, std::vector<Record *> &DeletedRecords);
UINT32 GetNumRecords(const UINT32 &RecordType);
STRING GetMasterName(UINT8 &CollapsedIndex);
Record * CreateRecord(const UINT32 &RecordType, STRING const &RecordEditorID, Record *&SourceRecord, Record *&ParentRecord, CreateRecordOptions &options);
Record * CreateRecord(const UINT32 &RecordType, STRING const &RecordEditorID, Record *&SourceRecord, Record *&ParentRecord, CreationFlags &options);
SINT32 DeleteRecord(Record *&curRecord, RecordOp &deindexer);
SINT32 Save(STRING const &SaveName, std::vector<FormIDResolver *> &Expanders, bool CloseMod, RecordOp &indexer);

Expand Down
20 changes: 6 additions & 14 deletions CBash/GRUPRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ class GRUPRecords
//Testing Messages
//if((flags & 0x4000) != 0)
// printer("0x4000 used: %08X!!!!\n", curRecord->formID);
curRecord->IsLoaded(false); //just incase the chosen flags were in use, clear them

//Read (if FullLoad), no-op otherwise
parser.Accept(curRecord);
Expand Down Expand Up @@ -349,7 +348,6 @@ class GRUPRecords<Ob::DIALRecord, RecType, AllocUnit, IsKeyedByEditorID>
//Testing Messages
//if((flags & 0x4000) != 0)
// printer("0x4000 used: %08X!!!!\n", curRecord->formID);
curRecord->IsLoaded(false); //just incase the chosen flags were in use, clear them

//Read (if FullLoad), no-op otherwise
parser.Accept(curRecord);
Expand Down Expand Up @@ -683,7 +681,6 @@ class GRUPRecords<Ob::CELLRecord, RecType, AllocUnit, IsKeyedByEditorID>
//Testing Messages
//if((flags & 0x4000) != 0)
// printer("0x4000 used: %08X!!!!\n", curRecord->formID);
curRecord->IsLoaded(false); //just incase the chosen flags were in use, clear them

//Read (if FullLoad), no-op otherwise
parser.Accept(curRecord);
Expand Down Expand Up @@ -1371,7 +1368,7 @@ class GRUPRecords<Ob::WRLDRecord, RecType, AllocUnit, IsKeyedByEditorID>
{
read_parser.Accept((Record *&)last_cell_record); //may already be loaded, but just to be sure.
//CELL will be unloaded if needed after a second round of indexing when all records are loaded
last_cell_record->XCLC.Load();
last_cell_record->XCLC.Load(); //in-case no XCLC chunk is specified
GridXY_LAND[last_cell_record->XCLC->posX][last_cell_record->XCLC->posY] = (Ob::LANDRecord *)curRecord;
}
break;
Expand All @@ -1390,7 +1387,6 @@ class GRUPRecords<Ob::WRLDRecord, RecType, AllocUnit, IsKeyedByEditorID>
//Testing Messages
//if((flags & 0x4000) != 0)
// printer("0x4000 used: %08X!!!!\n", curRecord->formID);
curRecord->IsLoaded(false); //just incase the chosen flags were in use, clear them

//Read (if FullLoad), no-op otherwise
parser.Accept(curRecord);
Expand Down Expand Up @@ -1421,8 +1417,8 @@ class GRUPRecords<Ob::WRLDRecord, RecType, AllocUnit, IsKeyedByEditorID>
for(UINT32 y = 0; y < last_wrld_record->CELLS.size(); ++y)
{
last_cell_record = (Ob::CELLRecord *)last_wrld_record->CELLS[y];
//reader.Accept((Record **)&last_cell_record); //already read when loaded
//last_cell_record->XCLC.Load(); //already loaded when CELL loaded
read_parser.Accept((Record *&)last_cell_record);
last_cell_record->XCLC.Load(); //in-case no XCLC chunk is specified
posX = last_cell_record->XCLC->posX;
posY = last_cell_record->XCLC->posY;

Expand Down Expand Up @@ -2059,7 +2055,6 @@ class FNVGRUPRecords
//Testing Messages
//if((flags & 0x4000) != 0)
// printer("0x4000 used: %08X!!!!\n", curRecord->formID);
curRecord->IsLoaded(false); //just incase the chosen flags were in use, clear them

//Read (if FullLoad), no-op otherwise
parser.Accept(curRecord);
Expand Down Expand Up @@ -2280,7 +2275,6 @@ class FNVGRUPRecords<FNV::DIALRecord, RecType, AllocUnit, IsKeyedByEditorID>
//Testing Messages
//if((flags & 0x4000) != 0)
// printer("0x4000 used: %08X!!!!\n", curRecord->formID);
curRecord->IsLoaded(false); //just incase the chosen flags were in use, clear them

//Read (if FullLoad), no-op otherwise
parser.Accept(curRecord);
Expand Down Expand Up @@ -2706,7 +2700,6 @@ class FNVGRUPRecords<FNV::CELLRecord, RecType, AllocUnit, IsKeyedByEditorID>
//Testing Messages
//if((flags & 0x4000) != 0)
// printer("0x4000 used: %08X!!!!\n", curRecord->formID);
curRecord->IsLoaded(false); //just incase the chosen flags were in use, clear them

//Read (if FullLoad), no-op otherwise
parser.Accept(curRecord);
Expand Down Expand Up @@ -3518,7 +3511,7 @@ class FNVGRUPRecords<FNV::WRLDRecord, RecType, AllocUnit, IsKeyedByEditorID>
{
read_parser.Accept((Record *&)last_cell_record); //may already be loaded, but just to be sure.
//CELL will be unloaded if needed after a second round of indexing when all records are loaded
last_cell_record->XCLC.Load();
last_cell_record->XCLC.Load(); //in-case no XCLC chunk is specified
GridXY_LAND[last_cell_record->XCLC->posX][last_cell_record->XCLC->posY] = (FNV::LANDRecord *)curRecord;
}
break;
Expand Down Expand Up @@ -3595,7 +3588,6 @@ class FNVGRUPRecords<FNV::WRLDRecord, RecType, AllocUnit, IsKeyedByEditorID>
//Testing Messages
//if((flags & 0x4000) != 0)
// printer("0x4000 used: %08X!!!!\n", curRecord->formID);
curRecord->IsLoaded(false); //just incase the chosen flags were in use, clear them

//Read (if FullLoad), no-op otherwise
parser.Accept(curRecord);
Expand Down Expand Up @@ -3626,8 +3618,8 @@ class FNVGRUPRecords<FNV::WRLDRecord, RecType, AllocUnit, IsKeyedByEditorID>
for(UINT32 y = 0; y < last_wrld_record->CELLS.size(); ++y)
{
last_cell_record = (FNV::CELLRecord *)last_wrld_record->CELLS[y];
//reader.Accept((Record **)&last_cell_record); //already read when loaded
//last_cell_record->XCLC.Load(); //already loaded when CELL loaded
read_parser.Accept((Record *&)last_cell_record);
last_cell_record->XCLC.Load(); //in-case no XCLC chunk is specified
posX = last_cell_record->XCLC->posX;
posY = last_cell_record->XCLC->posY;

Expand Down
Loading

0 comments on commit 61937da

Please sign in to comment.