Added support for excluding properties from generation results that already have valid names. Plus some more property names

This commit is contained in:
Aruki 2018-10-14 20:29:50 -06:00
parent bd8579167d
commit 95d270cde7
18 changed files with 176 additions and 52 deletions

View File

@ -101,6 +101,9 @@ struct SNameValue
/** Name of the property */
TString Name;
/** Whether this name is valid */
bool IsValid;
/** List of all properties using this ID */
std::list<IProperty*> PropertyList;
@ -154,6 +157,14 @@ void LoadMap()
CXMLReader Reader(gpkMapPath);
ASSERT(Reader.IsValid());
Reader << SerialParameter("PropertyMap", gNameMap, SH_HexDisplay);
// Iterate over the map and set up the valid flags
for (auto Iter = gNameMap.begin(); Iter != gNameMap.end(); Iter++)
{
const SNameKey& kKey = Iter->first;
SNameValue& Value = Iter->second;
Value.IsValid = (CalculatePropertyID(*Value.Name, *gHashToTypeName[kKey.TypeHash]) == kKey.ID);
}
}
gMapIsLoaded = true;
@ -230,13 +241,31 @@ const char* GetPropertyName(u32 ID, const char* pkTypeName)
return MapFind == gNameMap.end() ? "Unknown" : *MapFind->second.Name;
}
/** Calculate the property ID of a given name/type. */
u32 CalculatePropertyID(const char* pkName, const char* pkTypeName)
{
CCRC32 CRC;
CRC.Hash(pkName);
CRC.Hash(pkTypeName);
return CRC.Digest();
}
/** Returns whether the specified ID is in the map. */
bool IsValidPropertyID(u32 ID, const char* pkTypeName)
bool IsValidPropertyID(u32 ID, const char* pkTypeName, bool* pOutIsValid /*= nullptr*/)
{
SNameKey Key = CreateKey(ID, pkTypeName);
auto MapFind = gNameMap.find(Key);
return MapFind != gNameMap.end();
if (MapFind != gNameMap.end())
{
if (pOutIsValid != nullptr)
{
SNameValue& Value = MapFind->second;
*pOutIsValid = Value.IsValid;
}
return true;
}
else return false;
}
/** Retrieves a list of all properties that match the requested property ID. */
@ -355,6 +384,7 @@ void ChangeTypeName(IProperty* pProperty, const char* pkOldTypeName, const char*
{
SNameValue Value;
Value.Name = pProperty->Name();
Value.IsValid = ( CalculatePropertyID(*Value.Name, pkNewTypeName) == pProperty->ID() );
gNameMap[NewKey] = Value;
Find = gNameMap.find(NewKey);
}
@ -365,7 +395,7 @@ void ChangeTypeName(IProperty* pProperty, const char* pkOldTypeName, const char*
}
}
gHashToTypeName[NewTypeHash] = pkNewTypeName;
RegisterTypeName(NewTypeHash, pkNewTypeName);
}
/** Change a type name. */
@ -401,6 +431,7 @@ void ChangeTypeNameGlobally(const char* pkOldTypeName, const char* pkNewTypeName
}
}
RegisterTypeName(NewTypeHash, pkNewTypeName);
gHashToTypeName[NewTypeHash] = pkNewTypeName;
}
@ -430,6 +461,7 @@ void RegisterProperty(IProperty* pProperty)
SNameValue Value;
Value.Name = LegacyMapFind->second;
Value.IsValid = ( CalculatePropertyID(*Value.Name, pProperty->HashableTypeName()) == pProperty->ID() );
pProperty->SetName(Value.Name);
gNameMap[Key] = Value;
@ -465,4 +497,50 @@ void UnregisterProperty(IProperty* pProperty)
}
}
/** Class for iterating through the map */
class CIteratorImpl
{
public:
std::map<SNameKey, SNameValue>::const_iterator mIter;
};
CIterator::CIterator()
{
mpImpl = new CIteratorImpl;
mpImpl->mIter = gNameMap.begin();
}
CIterator::~CIterator()
{
delete mpImpl;
}
u32 CIterator::ID() const
{
return mpImpl->mIter->first.ID;
}
const char* CIterator::Name() const
{
return *mpImpl->mIter->second.Name;
}
const char* CIterator::TypeName() const
{
u32 TypeHash = mpImpl->mIter->first.TypeHash;
auto Find = gHashToTypeName.find(TypeHash);
ASSERT(Find != gHashToTypeName.end());
return *Find->second;
}
CIterator::operator bool() const
{
return mpImpl->mIter != gNameMap.end();
}
void CIterator::operator++()
{
mpImpl->mIter++;
}
}

View File

@ -22,8 +22,14 @@ const char* GetPropertyName(IProperty* pProperty);
*/
const char* GetPropertyName(u32 ID, const char* pkTypeName);
/** Returns whether the specified name is in the map. */
bool IsValidPropertyID(u32 ID, const char* pkTypeName);
/** Calculate the property ID of a given name/type. */
u32 CalculatePropertyID(const char* pkName, const char* pkTypeName);
/**
* Returns whether the specified name is in the map.
* If the ID is valid and pOutIsValid is non-null, it will return whether the current name is correct.
*/
bool IsValidPropertyID(u32 ID, const char* pkTypeName, bool* pOutIsValid = nullptr);
/** Retrieves a list of all properties that match the requested property ID. */
void RetrievePropertiesWithID(u32 ID, const char* pkTypeName, std::list<IProperty*>& OutList);
@ -46,6 +52,24 @@ void RegisterProperty(IProperty* pProperty);
/** Unregisters a property from the name map. Should be called on all properties that use the map on destruction. */
void UnregisterProperty(IProperty* pProperty);
/** Class that allows for iteration through the name map */
class CIterator
{
/** Private implementation */
class CIteratorImpl* mpImpl;
public:
CIterator();
~CIterator();
u32 ID() const;
const char* Name() const;
const char* TypeName() const;
operator bool() const;
void operator ++();
};
}
#endif // NPROPERTYMAP_H

View File

@ -176,7 +176,7 @@ void CPropertyNameGenerator::Generate(const SPropertyNameGenerationParameters& r
u32 PropertyID = FullHash.Digest();
// Check if this hash is a property ID
if (IsValidPropertyID(PropertyID, pkTypeName))
if (IsValidPropertyID(PropertyID, pkTypeName, rkParams))
{
SGeneratedPropertyName PropertyName;
NPropertyMap::RetrieveXMLsWithProperty(PropertyID, pkTypeName, PropertyName.XmlList);
@ -253,7 +253,7 @@ void CPropertyNameGenerator::Generate(const SPropertyNameGenerationParameters& r
}
/** Returns whether a given property ID is valid */
bool CPropertyNameGenerator::IsValidPropertyID(u32 ID, const char* pkType)
bool CPropertyNameGenerator::IsValidPropertyID(u32 ID, const char* pkType, const SPropertyNameGenerationParameters& rkParams)
{
if (!mValidTypePairMap.empty())
{
@ -267,5 +267,9 @@ bool CPropertyNameGenerator::IsValidPropertyID(u32 ID, const char* pkType)
return false;
}
else
return NPropertyMap::IsValidPropertyID(ID, pkType);
{
bool IsAlreadyNamed;
bool IsValid = NPropertyMap::IsValidPropertyID(ID, pkType, &IsAlreadyNamed);
return IsValid && (!IsAlreadyNamed || !rkParams.ExcludeAccuratelyNamedProperties);
}
}

View File

@ -40,6 +40,9 @@ struct SPropertyNameGenerationParameters
/** List of ID/type pairs to check against. If empty, all properties are valid. */
std::vector<SPropertyIdTypePair> ValidIdPairs;
/** Whether to exclude properties that already have accurate names from the generation results. */
bool ExcludeAccuratelyNamedProperties;
/** Whether to print the output from the generation process to the log */
bool PrintToLog;
};
@ -99,7 +102,7 @@ public:
void Generate(const SPropertyNameGenerationParameters& rkParams, IProgressNotifier* pProgressNotifier);
/** Returns whether a given property ID is valid */
bool IsValidPropertyID(u32 ID, const char* pkType);
bool IsValidPropertyID(u32 ID, const char* pkType, const SPropertyNameGenerationParameters& rkParams);
/** Accessors */
bool IsRunning() const

View File

@ -162,6 +162,7 @@ void CGeneratePropertyNamesDialog::StartGeneration()
Params.Suffix = TO_TSTRING( mpUI->SuffixLineEdit->text() );
Params.Casing = mpUI->CasingComboBox->currentEnum();
Params.ValidIdPairs = mIdPairs.toStdVector();
Params.ExcludeAccuratelyNamedProperties = mpUI->UnnamedOnlyCheckBox->isChecked();
Params.PrintToLog = mpUI->LogOutputCheckBox->isChecked();
// Run the task and configure ourselves so we can update correctly

View File

@ -88,6 +88,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="UnnamedOnlyCheckBox">
<property name="text">
<string>Exclude known properties</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -759,10 +759,18 @@
<Key>CameraRotation</Key>
<Value Path="Structs/CameraRotation.xml"/>
</Element>
<Element>
<Key>CameraShakerData</Key>
<Value Path="Structs/CameraShakerData.xml"/>
</Element>
<Element>
<Key>CameraShakerEnvelope</Key>
<Value Path="Structs/CameraShakerEnvelope.xml"/>
</Element>
<Element>
<Key>CharacterGlueData</Key>
<Value Path="Structs/CharacterGlueData.xml"/>
</Element>
<Element>
<Key>CheckpointData</Key>
<Value Path="Structs/CheckpointData.xml"/>
@ -1223,10 +1231,6 @@
<Key>ShadowData</Key>
<Value Path="Structs/ShadowData.xml"/>
</Element>
<Element>
<Key>ShakerData</Key>
<Value Path="Structs/ShakerData.xml"/>
</Element>
<Element>
<Key>Shape</Key>
<Value Path="Enums/Shape.xml"/>
@ -1543,10 +1547,6 @@
<Key>UnknownStruct138</Key>
<Value Path="Structs/UnknownStruct138.xml"/>
</Element>
<Element>
<Key>UnknownStruct139</Key>
<Value Path="Structs/UnknownStruct139.xml"/>
</Element>
<Element>
<Key>UnknownStruct14</Key>
<Value Path="Structs/UnknownStruct14.xml"/>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<PropertyTemplate ArchiveVer="4" Game="DKCReturns">
<PropertyArchetype Type="Struct">
<Name>ShakerData</Name>
<Name>CameraShakerData</Name>
<SubProperties>
<Element Type="Int" ID="0xC3E75C5F">
<CookPreference>Always</CookPreference>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<PropertyTemplate ArchiveVer="4" Game="DKCReturns">
<PropertyArchetype Type="Struct">
<Name>UnknownStruct139</Name>
<Name>CharacterGlueData</Name>
<SubProperties>
<Element Type="Enum" ID="0x411D0552">
<DefaultValue>0xD4E949F7</DefaultValue>

View File

@ -10,7 +10,7 @@
<Element Type="Struct" ID="0x975DCEF7" Archetype="GenericCreatureStructG"/>
<Element Type="Struct" ID="0x8ABB25C4" Archetype="PlayerCrushData"/>
<Element Type="Struct" ID="0xF4D39593" Archetype="TrackObjectModuleData"/>
<Element Type="Struct" ID="0x9D9CE325" Archetype="UnknownStruct139"/>
<Element Type="Struct" ID="0x9D9CE325" Archetype="CharacterGlueData"/>
<Element Type="Struct" ID="0x34A979A6" Archetype="TandemBeam"/>
</SubProperties>
</PropertyArchetype>

View File

@ -927,6 +927,10 @@
<Key>CameraRotation</Key>
<Value Path="Structs/CameraRotation.xml"/>
</Element>
<Element>
<Key>CameraShakerData</Key>
<Value Path="Structs/CameraShakerData.xml"/>
</Element>
<Element>
<Key>CameraShakerEnvelope</Key>
<Value Path="Structs/CameraShakerEnvelope.xml"/>
@ -1443,10 +1447,6 @@
<Key>SeedBoss3Data</Key>
<Value Path="Structs/SeedBoss3Data.xml"/>
</Element>
<Element>
<Key>ShakerData</Key>
<Value Path="Structs/ShakerData.xml"/>
</Element>
<Element>
<Key>Ship</Key>
<Value Path="Structs/Ship.xml"/>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<PropertyTemplate ArchiveVer="4" Game="Corruption">
<PropertyArchetype Type="Struct">
<Name>ShakerData</Name>
<Name>CameraShakerData</Name>
<SubProperties>
<Element Type="Int" ID="0xC3E75C5F">
<DefaultValue>48</DefaultValue>

View File

@ -687,6 +687,10 @@
<Key>CameraRotation</Key>
<Value Path="Structs/CameraRotation.xml"/>
</Element>
<Element>
<Key>CameraShakerData</Key>
<Value Path="Structs/CameraShakerData.xml"/>
</Element>
<Element>
<Key>CameraShakerEnvelope</Key>
<Value Path="Structs/CameraShakerEnvelope.xml"/>
@ -1115,10 +1119,6 @@
<Key>SeedBoss1Stage</Key>
<Value Path="Structs/SeedBoss1Stage.xml"/>
</Element>
<Element>
<Key>ShakerData</Key>
<Value Path="Structs/ShakerData.xml"/>
</Element>
<Element>
<Key>Ship</Key>
<Value Path="Structs/Ship.xml"/>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<PropertyTemplate ArchiveVer="4" Game="CorruptionProto">
<PropertyArchetype Type="Struct">
<Name>ShakerData</Name>
<Name>CameraShakerData</Name>
<SubProperties>
<Element Type="Int" ID="0xC3E75C5F">
<DefaultValue>48</DefaultValue>

View File

@ -1727,7 +1727,7 @@
</Element>
<Element>
<Key ID="0xC431344" Type="bool"/>
<Value Name="Unknown"/>
<Value Name="ApplyBoostAfterUnStun"/>
</Element>
<Element>
<Key ID="0xC4763D7" Type="float"/>
@ -2695,7 +2695,7 @@
</Element>
<Element>
<Key ID="0x130539A0" Type="Vector"/>
<Value Name="Unknown"/>
<Value Name="IceGibParticlesOffset"/>
</Element>
<Element>
<Key ID="0x13072E6C" Type="asset"/>
@ -7395,7 +7395,7 @@
</Element>
<Element>
<Key ID="0x31896ED0" Type="GenericCreatureStructC"/>
<Value Name="GenericCreatureStructC"/>
<Value Name="ActorRule3"/>
</Element>
<Element>
<Key ID="0x3196B2E7" Type="Color"/>
@ -8363,7 +8363,7 @@
</Element>
<Element>
<Key ID="0x38711325" Type="bool"/>
<Value Name="Unknown"/>
<Value Name="StunOnlyWhenOnGround"/>
</Element>
<Element>
<Key ID="0x3874576D" Type="BloggStruct"/>
@ -9515,7 +9515,7 @@
</Element>
<Element>
<Key ID="0x3FF111B9" Type="UnknownStruct2"/>
<Value Name="UnknownStruct2"/>
<Value Name="Attack"/>
</Element>
<Element>
<Key ID="0x3FF87A8C" Type="bool"/>
@ -9635,7 +9635,7 @@
</Element>
<Element>
<Key ID="0x40A372B6" Type="bool"/>
<Value Name="Unknown"/>
<Value Name="CanUnStun"/>
</Element>
<Element>
<Key ID="0x40AB00FA" Type="Vector"/>
@ -10111,7 +10111,7 @@
</Element>
<Element>
<Key ID="0x43BBB1DD" Type="PatternedAITypedef"/>
<Value Name="PatternedAITypedef"/>
<Value Name="PatternedInfo"/>
</Element>
<Element>
<Key ID="0x43BC661C" Type="bool"/>
@ -13267,7 +13267,7 @@
</Element>
<Element>
<Key ID="0x586EE888" Type="GenericCreatureStructC"/>
<Value Name="GenericCreatureStructC"/>
<Value Name="ActorRule4"/>
</Element>
<Element>
<Key ID="0x58769EB2" Type="DamageInfo"/>
@ -14723,7 +14723,7 @@
</Element>
<Element>
<Key ID="0x62F0CFFC" Type="float"/>
<Value Name="Unknown"/>
<Value Name="GroundPoundDistanceVerticalMultiplier"/>
</Element>
<Element>
<Key ID="0x62FB47A5" Type="float"/>
@ -23571,7 +23571,11 @@
</Element>
<Element>
<Key ID="0x9D9CE325" Type="UnknownStruct139"/>
<Value Name="UnknownStruct139"/>
<Value Name="CharacterGlue"/>
</Element>
<Element>
<Key ID="0x9D9CE325" Type="CharacterGlueData"/>
<Value Name="CharacterGlue"/>
</Element>
<Element>
<Key ID="0x9D9D3760" Type="float"/>
@ -25115,7 +25119,7 @@
</Element>
<Element>
<Key ID="0xA792725D" Type="UnknownStruct98"/>
<Value Name="UnknownStruct98"/>
<Value Name="Idle"/>
</Element>
<Element>
<Key ID="0xA793E5F3" Type="int"/>
@ -26127,7 +26131,7 @@
</Element>
<Element>
<Key ID="0xAE53ED4E" Type="GenericCreatureStructC"/>
<Value Name="GenericCreatureStructC"/>
<Value Name="ActorRule2"/>
</Element>
<Element>
<Key ID="0xAE599017" Type="float"/>
@ -29771,7 +29775,7 @@
</Element>
<Element>
<Key ID="0xC69F691A" Type="SeedBoss1HandData"/>
<Value Name="SeedBoss1HandData"/>
<Value Name="HandData"/>
</Element>
<Element>
<Key ID="0xC6A6B724" Type="float"/>
@ -29991,7 +29995,7 @@
</Element>
<Element>
<Key ID="0xC7B46B16" Type="GenericCreatureStructC"/>
<Value Name="GenericCreatureStructC"/>
<Value Name="ActorRule5"/>
</Element>
<Element>
<Key ID="0xC7BD1022" Type="UnknownStruct263"/>
@ -32055,7 +32059,7 @@
</Element>
<Element>
<Key ID="0xD5110050" Type="UnknownStruct97"/>
<Value Name="UnknownStruct97"/>
<Value Name="Damage"/>
</Element>
<Element>
<Key ID="0xD51CA051" Type="sound"/>
@ -32091,7 +32095,7 @@
</Element>
<Element>
<Key ID="0xD54D6FAD" Type="GenericCreatureStructC"/>
<Value Name="GenericCreatureStructC"/>
<Value Name="ActorRule1"/>
</Element>
<Element>
<Key ID="0xD5505EA4" Type="float"/>
@ -34115,7 +34119,7 @@
</Element>
<Element>
<Key ID="0xE38A723D" Type="bool"/>
<Value Name="Unknown"/>
<Value Name="KnockbackInsteadOfStun"/>
</Element>
<Element>
<Key ID="0xE38B44AF" Type="asset"/>
@ -37199,7 +37203,7 @@
</Element>
<Element>
<Key ID="0xF6E66110" Type="SeedBoss1Data"/>
<Value Name="SeedBoss1Data"/>
<Value Name="Data"/>
</Element>
<Element>
<Key ID="0xF6F185D6" Type="sound"/>
@ -37595,7 +37599,7 @@
</Element>
<Element>
<Key ID="0xF9656C39" Type="Color"/>
<Value Name="Unknown"/>
<Value Name="ColorHyperQuake"/>
</Element>
<Element>
<Key ID="0xF9670AC1" Type="float"/>

View File

@ -10,7 +10,7 @@
</Element>
</SubProperties>
</Element>
<Element Type="Struct" ID="0xAD547F96" Archetype="ShakerData"/>
<Element Type="Struct" ID="0xAD547F96" Archetype="CameraShakerData"/>
</SubProperties>
</Properties>
<EditorProperties>

View File

@ -4,7 +4,7 @@
<Name>CameraShaker</Name>
<SubProperties>
<Element Type="Struct" ID="0x255A4580" Archetype="EditorProperties"/>
<Element Type="Struct" ID="0xAD547F96" Archetype="ShakerData"/>
<Element Type="Struct" ID="0xAD547F96" Archetype="CameraShakerData"/>
</SubProperties>
</Properties>
<EditorProperties>

View File

@ -4,7 +4,7 @@
<Name>CameraShaker</Name>
<SubProperties>
<Element Type="Struct" ID="0x255A4580" Archetype="EditorProperties"/>
<Element Type="Struct" ID="0xAD547F96" Archetype="ShakerData"/>
<Element Type="Struct" ID="0xAD547F96" Archetype="CameraShakerData"/>
</SubProperties>
</Properties>
<EditorProperties>