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

Commit

Permalink
SaveMod now takes an extra STRING parameter to determine what name th…
Browse files Browse the repository at this point in the history
…e saved mod will use

It is no longer possible to get a string without a null terminator via the API
MGEFCodes are returned as 4 character sequences when possible
'school' for effects and MGEF records renamed 'schoolType', and IsAlteration and friends added
Variety of minor stylistic changes

cint
  Minor fixes
  FormIDs/MGEFCodes/ActorValues can now be compared against non-subscriptable values
  Record::bsb now works
    Bad order of operations fixed with added parenthesis
    exterior block/subblocks were switched
  • Loading branch information
waruddar committed Sep 18, 2011
1 parent 9549959 commit d1754c6
Show file tree
Hide file tree
Showing 28 changed files with 657 additions and 421 deletions.
Binary file modified CBash.suo
Binary file not shown.
4 changes: 2 additions & 2 deletions CBash/CBash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ CPPDLLEXTERN SINT32 CleanModMasters(ModFile *ModID)
return -1;
}

CPPDLLEXTERN SINT32 SaveMod(ModFile *ModID, const UINT32 SaveFlagsField)
CPPDLLEXTERN SINT32 SaveMod(ModFile *ModID, const UINT32 SaveFlagsField, STRING const DestinationName)
{
SINT32 err = 0;
SaveFlags flags(SaveFlagsField);
Expand All @@ -559,7 +559,7 @@ CPPDLLEXTERN SINT32 SaveMod(ModFile *ModID, const UINT32 SaveFlagsField)
PROFILE_FUNC
//ValidatePointer(CollectionID);
//ValidatePointer(ModID);
err = ModID->Parent->SaveMod(ModID, flags);
err = ModID->Parent->SaveMod(ModID, flags, DestinationName);
}
catch(std::exception &ex)
{
Expand Down
2 changes: 1 addition & 1 deletion CBash/CBash.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ DLLEXTERN SINT32 AddMod(Collection *CollectionID, STRING const ModName, const UI
DLLEXTERN SINT32 LoadMod(ModFile *ModID);
DLLEXTERN SINT32 UnloadMod(ModFile *ModID);
DLLEXTERN SINT32 CleanModMasters(ModFile *ModID);
DLLEXTERN SINT32 SaveMod(ModFile *ModID, const UINT32 SaveFlagsField);
DLLEXTERN SINT32 SaveMod(ModFile *ModID, const UINT32 SaveFlagsField, STRING const DestinationName);
////////////////////////////////////////////////////////////////////////
//Mod info functions
DLLEXTERN SINT32 GetAllNumMods(Collection *CollectionID);
Expand Down
6 changes: 3 additions & 3 deletions CBash/Collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ ModFile * Collection::IsModAdded(STRING const &ModName)
return NULL;
}

SINT32 Collection::SaveMod(ModFile *&curModFile, SaveFlags &flags)
SINT32 Collection::SaveMod(ModFile *&curModFile, SaveFlags &flags, STRING const DestinationName)
{
if(!curModFile->Flags.IsSaveable)
{
Expand All @@ -233,13 +233,13 @@ SINT32 Collection::SaveMod(ModFile *&curModFile, SaveFlags &flags)

_chdir(ModsDir);

STRING temp_name = GetTemporaryFileName(curModFile->ModName); //deleted when RenameOp is destroyed
STRING temp_name = GetTemporaryFileName(DestinationName != NULL ? DestinationName : curModFile->ModName); //deleted when RenameOp is destroyed

//Save the mod to temp file
curModFile->Save(temp_name, Expanders, flags.IsCloseCollection, indexer);
//Delay renaming temp file to original filename until collection is closed
//This way the file mapping can remain open and the entire file doesn't have to be loaded into memory
closing_ops.push_back(new RenameOp(temp_name, curModFile->FileName));
closing_ops.push_back(new RenameOp(temp_name, DestinationName != NULL ? DestinationName : curModFile->FileName));
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion CBash/Collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Collection

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

SINT32 Load();
void UndeleteRecords(std::vector<std::pair<ModFile *, std::vector<Record *> > > &DeletedRecords);
Expand Down
69 changes: 42 additions & 27 deletions CBash/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1016,46 +1016,61 @@ StringRecord& StringRecord::operator = (const StringRecord &rhs)
}

NonNullStringRecord::NonNullStringRecord():
value(NULL),
_value(NULL),
DiskSize(0)
{
//
}

NonNullStringRecord::NonNullStringRecord(const NonNullStringRecord &p):
value(NULL),
_value(NULL),
DiskSize(0)
{
if(!p.IsLoaded())
return;

if(p.DiskSize)
{
value = p.value;
_value = p._value;
DiskSize = p.DiskSize;
}
else
{
UINT32 size = p.GetSize();
value = new char[size];
memcpy(value, p.value, size);
_value = new char[size];
memcpy(_value, p._value, size);
}
}

NonNullStringRecord::~NonNullStringRecord()
{
if(DiskSize == 0)
delete []value;
delete []_value;
}

UINT32 NonNullStringRecord::GetSize() const
{
return value != NULL ? (DiskSize ? DiskSize : (UINT32)strlen(value)) : 0;
return _value != NULL ? (DiskSize ? DiskSize : (UINT32)strlen(_value)) : 0;
}

STRING NonNullStringRecord::GetString()
{
if(DiskSize != 0)
{
//Have to sanitize the string before letting it be used
//The string needs a null terminator added, so load it from disk
STRING nvalue = new char[DiskSize + 1];
nvalue[DiskSize] = 0x00;
memcpy(nvalue, _value, DiskSize);
_value = nvalue;
DiskSize = 0;
}
return _value;
}

bool NonNullStringRecord::IsLoaded() const
{
return value != NULL;
return _value != NULL;
}

void NonNullStringRecord::Load()
Expand All @@ -1067,8 +1082,8 @@ void NonNullStringRecord::Unload()
{
if(DiskSize == 0)
{
delete []value;
value = NULL;
delete []_value;
_value = NULL;
}
}

Expand All @@ -1081,29 +1096,29 @@ bool NonNullStringRecord::Read(unsigned char *&buffer, const UINT32 &subSize, co
}
if(CompressedOnDisk)
{
value = new char[subSize + 1];
value[subSize] = 0x00;
memcpy(value, buffer, subSize);
_value = new char[subSize + 1];
_value[subSize] = 0x00;
memcpy(_value, buffer, subSize);
}
else
{
DiskSize = subSize;
value = (char *)buffer;
_value = (char *)buffer;
}
buffer += subSize;
return true;
}

void NonNullStringRecord::Write(UINT32 _Type, FileWriter &writer)
{
if(value != NULL)
writer.record_write_subrecord(_Type, value, DiskSize ? DiskSize : (UINT32)strlen(value));
if(_value != NULL)
writer.record_write_subrecord(_Type, _value, DiskSize ? DiskSize : (UINT32)strlen(_value));
}

void NonNullStringRecord::ReqWrite(UINT32 _Type, FileWriter &writer)
{
if(value != NULL)
writer.record_write_subrecord(_Type, value, DiskSize ? DiskSize : (UINT32)strlen(value));
if(_value != NULL)
writer.record_write_subrecord(_Type, _value, DiskSize ? DiskSize : (UINT32)strlen(_value));
else
{
char null = 0x00;
Expand All @@ -1118,19 +1133,19 @@ void NonNullStringRecord::Copy(STRING FieldValue)
{
DiskSize = 0;
UINT32 size = (UINT32)strlen(FieldValue) + 1;
value = new char[size];
memcpy(value, FieldValue, size);
_value = new char[size];
memcpy(_value, FieldValue, size);
}
}

bool NonNullStringRecord::equals(const NonNullStringRecord &other) const
{
return cmps(value, other.value) == 0;
return cmps(_value, other._value) == 0;
}

bool NonNullStringRecord::equalsi(const NonNullStringRecord &other) const
{
return icmps(value, other.value) == 0;
return icmps(_value, other._value) == 0;
}

NonNullStringRecord& NonNullStringRecord::operator = (const NonNullStringRecord &rhs)
Expand All @@ -1140,15 +1155,15 @@ NonNullStringRecord& NonNullStringRecord::operator = (const NonNullStringRecord
Unload();
if(rhs.DiskSize)
{
value = rhs.value;
_value = rhs._value;
DiskSize = rhs.DiskSize;
}
else if(rhs.value != NULL)
else if(rhs._value != NULL)
{
DiskSize = 0;
UINT32 size = (UINT32)strlen(rhs.value) + 1;
value = new char[size];
memcpy(value, rhs.value, size);
UINT32 size = (UINT32)strlen(rhs._value) + 1;
_value = new char[size];
memcpy(_value, rhs._value, size);
}
}
return *this;
Expand Down
6 changes: 4 additions & 2 deletions CBash/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ enum API_FieldTypes {
UNKNOWN_OR_FORMID_OR_UINT32_FIELD,
UNKNOWN_OR_SINT32_FIELD,
UNKNOWN_OR_UINT32_FLAG_FIELD,
MGEFCODE_OR_UINT32_FIELD,
MGEFCODE_OR_CHAR4_FIELD,
FORMID_OR_MGEFCODE_OR_ACTORVALUE_OR_UINT32_FIELD,
RESOLVED_MGEFCODE_FIELD,
STATIC_MGEFCODE_FIELD,
Expand Down Expand Up @@ -650,15 +650,17 @@ class NonNullStringRecord
{
private:
UINT32 DiskSize;
STRING _value;

public:
STRING value;
__declspec(property(get=GetString)) STRING value;

NonNullStringRecord();
NonNullStringRecord(const NonNullStringRecord &p);
~NonNullStringRecord();

UINT32 GetSize() const;
STRING GetString();

bool IsLoaded() const;
void Load();
Expand Down
8 changes: 4 additions & 4 deletions CBash/FalloutNewVegas/Records/API/MGEFRecordAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ UINT32 MGEFRecord::GetFieldAttribute(FIELD_IDENTIFIERS, UINT32 WhichAttribute)
case 18: //associated
return FORMID_FIELD;
case 19: //schoolUnused
return SINT32_FIELD;
return UINT32_TYPE_FIELD;
case 20: //resistType
return SINT32_TYPE_FIELD;
case 21: //numCounters
Expand Down Expand Up @@ -231,7 +231,7 @@ void * MGEFRecord::GetField(FIELD_IDENTIFIERS, void **FieldValues)
case 18: //associated
return &DATA.value.associated;
case 19: //schoolUnused
return &DATA.value.school;
return &DATA.value.schoolType;
case 20: //resistType
return &DATA.value.resistType;
case 21: //numCounters
Expand Down Expand Up @@ -367,7 +367,7 @@ bool MGEFRecord::SetField(FIELD_IDENTIFIERS, void *FieldValue, UINT32 ArraySize)
DATA.value.associated = *(FORMID *)FieldValue;
return true;
case 19: //schoolUnused
DATA.value.school = *(SINT32 *)FieldValue;
DATA.value.schoolType = *(UINT32 *)FieldValue;
break;
case 20: //resistType
DATA.value.resistType = *(SINT32 *)FieldValue;
Expand Down Expand Up @@ -512,7 +512,7 @@ void MGEFRecord::DeleteField(FIELD_IDENTIFIERS)
DATA.value.associated = defaultDATA.associated;
return;
case 19: //schoolUnused
DATA.value.school = defaultDATA.school;
DATA.value.schoolType = defaultDATA.schoolType;
return;
case 20: //resistType
DATA.value.resistType = defaultDATA.resistType;
Expand Down
72 changes: 71 additions & 1 deletion CBash/FalloutNewVegas/Records/MGEFRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ MGEFRecord::MGEFDATA::MGEFDATA():
flags(0),
baseCost(0.0f),
associated(0),
school(0),
schoolType(0),
resistType(-1),
numCounters(0),
light(0),
Expand Down Expand Up @@ -595,6 +595,76 @@ void MGEFRecord::SetType(UINT32 Type)
DATA.value.archType = Type;
}

bool MGEFRecord::IsSchoolAlteration()
{
return (DATA.value.schoolType == eAlteration);
}

void MGEFRecord::IsSchoolAlteration(bool value)
{
DATA.value.schoolType = value ? eAlteration : eConjuration;
}

bool MGEFRecord::IsSchoolConjuration()
{
return (DATA.value.schoolType == eConjuration);
}

void MGEFRecord::IsSchoolConjuration(bool value)
{
DATA.value.schoolType = value ? eConjuration : eAlteration;
}

bool MGEFRecord::IsSchoolDestruction()
{
return (DATA.value.schoolType == eDestruction);
}

void MGEFRecord::IsSchoolDestruction(bool value)
{
DATA.value.schoolType = value ? eDestruction : eAlteration;
}

bool MGEFRecord::IsSchoolIllusion()
{
return (DATA.value.schoolType == eIllusion);
}

void MGEFRecord::IsSchoolIllusion(bool value)
{
DATA.value.schoolType = value ? eIllusion : eAlteration;
}

bool MGEFRecord::IsSchoolMysticism()
{
return (DATA.value.schoolType == eMysticism);
}

void MGEFRecord::IsSchoolMysticism(bool value)
{
DATA.value.schoolType = value ? eMysticism : eAlteration;
}

bool MGEFRecord::IsSchoolRestoration()
{
return (DATA.value.schoolType == eRestoration);
}

void MGEFRecord::IsSchoolRestoration(bool value)
{
DATA.value.schoolType = value ? eRestoration : eAlteration;
}

bool MGEFRecord::IsSchool(UINT32 Type)
{
return (DATA.value.schoolType == Type);
}

void MGEFRecord::SetSchool(UINT32 Type)
{
DATA.value.schoolType = Type;
}

UINT32 MGEFRecord::GetType()
{
return REV32(MGEF);
Expand Down
Loading

0 comments on commit d1754c6

Please sign in to comment.