-
Notifications
You must be signed in to change notification settings - Fork 0
Example 01: List all the props and textures used on a lot
Warning
These code snippets are very outdated. Do not use them. (Dec 2025)
The standard DBPFFile constructor requires the full path of the file. We then grab the list of entries and iterate over it to look for Exemplar type entries only. Once we have an Exemplar entry, decode it. The output is a collection of properties. Examine these properties for those of type LotConfigPropertyLotObjectData (ID: 0x88edc900 thru 0x88edce00). Rep 13 (the 13th value) of this type property is a reference to the instance id (IID) of the item used on the lot. We'll add these to a Dictionary, listOfRep13IIDs.
Create a new DBPFFile object from the target file name and get the list of entries in that file.
DBPFFile dbpf = new DBPFFile(filePath);
OrderedDictionary listOfEntries = dbpf.ListOfEntries;
Next, we want to loop through each subfile/entry in the main file and if the entry is an Exemplar, decode it. We must decode it in order to analyze its features (list of properties) later on.
foreach (DBPFEntry entry in listOfEntries.Values) {
if (entry.TGI.MatchesKnownTGI(DBPFTGI.EXEMPLAR)) {
entry.DecodeEntry();
}
}
There are a multitude of different exemplar types (see Exemplar Types), but we're only concerned about type 0x10 or LotConfiguration.
int exType = entry.GetExemplarType();
if (!(exType == (int) DBPFProperty.ExemplarTypes.LotConfiguration)) {
continue;
}
Since we are only looking at LotConfiguration type exemplars, we know there will always be LotConfigPropertyLotObjectData properties. The property ID of these properties is always between 0x88edc900 and 0x88edce00 (first one is always 0x88edc900 and can continue on for max 1280 repetitions total) so we'll grab as many as we find on the lot. Ultimately, since we need information contained inside of this property, we'll decode the property to access that data.
foreach (DBPFProperty property in entry.ListOfProperties.Values) {
if (property.ID >= 0x88edc900 && property.ID <= 0x88edce00) {
property.DecodeValues();
}
}
Create an Array object to store the decoded values from the property (a list of uint values in this case) to easily analyze it.
Array lotObjects = Array.CreateInstance(property.DataType.PrimitiveDataType, property.NumberOfReps);
lotObjects = property.DecodedValues;
The first rep of a LotConfigPropertyLotObjectData property determines its type. We're looking for only those of 0x0 (building) or 0x1 (prop) or 0x2 (texture) or 0x4 (flora). If it's one of these, then we'll add it to a list.
uint lotObjectType = (uint) lotObjects.GetValue(0);
if (lotObjectType == (int) DBPFProperty.LotConfigPropertyLotObjectTypes.Building || lotObjectType == (int) DBPFProperty.LotConfigPropertyLotObjectTypes.Prop ||
lotObjectType == (int) DBPFProperty.LotConfigPropertyLotObjectTypes.Texture || lotObjectType == (int) DBPFProperty.LotConfigPropertyLotObjectTypes.Flora) {
listOfRep13IIDs.Add(idx, lotObjects.GetValue(12) });
idx++;
}
And finally with all of the code bits put together:
DBPFFile dbpf = new DBPFFile(filePath);
OrderedDictionary listOfEntries = dbpf.ListOfEntries;
foreach (DBPFEntry entry in listOfEntries.Values) {
if (entry.TGI.MatchesKnownTGI(DBPFTGI.EXEMPLAR)) {
entry.DecodeEntry();
int exType = entry.GetExemplarType();
if (!(exType == (int) DBPFProperty.ExemplarTypes.LotConfiguration)) {
continue;
}
foreach (DBPFProperty property in entry.ListOfProperties.Values) {
if (property.ID >= 0x88edc900 && property.ID <= 0x88edce00) {
property.DecodeValues();
Array lotObjects = Array.CreateInstance(property.DataType.PrimitiveDataType, property.NumberOfReps);
lotObjects = property.DecodedValues;
uint lotObjectType = (uint) lotObjects.GetValue(0);
if (lotObjectType == (int) DBPFProperty.LotConfigPropertyLotObjectTypes.Building || lotObjectType == (int) DBPFProperty.LotConfigPropertyLotObjectTypes.Prop ||
lotObjectType == (int) DBPFProperty.LotConfigPropertyLotObjectTypes.Texture || lotObjectType == (int) DBPFProperty.LotConfigPropertyLotObjectTypes.Flora) {
listOfRep13IIDs.Add(idx, lotObjects.GetValue(12) });
idx++;
}
}
}