Skip to content

Commit f85b358

Browse files
Further simplification of member variables
1 parent aba9d84 commit f85b358

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

TextDumper/TextDumperTool.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ public class TextDumperTool
1111
StringBuilder m_StringBuilder = new StringBuilder(1024);
1212
DumpOptions m_Options;
1313
string m_TypeFilter; // m_Options.TypeFilter normalized: null when blank/unset, otherwise the user-provided string
14-
bool m_FilterByTypeId; // true when m_TypeFilter parses as a ClassID (numeric)
15-
int m_FilterTypeId; // valid only when m_FilterByTypeId is true
14+
int m_FilterTypeId; // > 0 when filtering by Unity ClassID (numeric form of m_TypeFilter); 0 means no ID filter
15+
16+
TextWriter m_Writer; // Output, either to a file or Console.Out
17+
18+
// Set during the processed of each Serialized File
1619
UnityFileReader m_Reader;
1720
SerializedFile m_SerializedFile;
18-
TextWriter m_Writer;
1921

2022
public enum DumpFormat
2123
{
@@ -37,7 +39,7 @@ public int Dump(DumpOptions options)
3739
{
3840
m_Options = options;
3941
m_TypeFilter = string.IsNullOrWhiteSpace(m_Options.TypeFilter) ? null : m_Options.TypeFilter;
40-
m_FilterByTypeId = m_TypeFilter != null && int.TryParse(m_TypeFilter, out m_FilterTypeId);
42+
m_FilterTypeId = (m_TypeFilter != null && int.TryParse(m_TypeFilter, out var parsed) && parsed > 0) ? parsed : 0;
4143

4244
try
4345
{
@@ -189,9 +191,12 @@ void OutputSerializedFile(string path)
189191
if (objectId != 0 && obj.Id != objectId)
190192
continue;
191193

194+
if (m_FilterTypeId > 0 && obj.TypeId != m_FilterTypeId)
195+
continue;
196+
192197
var root = m_SerializedFile.GetTypeTreeRoot(obj.Id);
193198

194-
if (!ObjectMatchesTypeFilter(obj, root))
199+
if (m_TypeFilter != null && m_FilterTypeId == 0 && !MatchesTypeNameFilter(obj, root))
195200
continue;
196201

197202
var offset = obj.Offset;
@@ -500,14 +505,8 @@ string ReadPascalStringAndAlign(ref long offset)
500505
static bool IsTerminusSentinel(string className, string namespaceName, string assemblyName) =>
501506
className == "Terminus" && namespaceName == "UnityEngine.DMAT" && assemblyName == "FAKE_ASM";
502507

503-
bool ObjectMatchesTypeFilter(ObjectInfo obj, TypeTreeNode root)
508+
bool MatchesTypeNameFilter(ObjectInfo obj, TypeTreeNode root)
504509
{
505-
if (m_TypeFilter == null)
506-
return true;
507-
508-
if (m_FilterByTypeId)
509-
return obj.TypeId == m_FilterTypeId;
510-
511510
var typeName = TypeIdRegistry.GetTypeName(obj.TypeId);
512511
// GetTypeName returns the id as a string when the type is unknown;
513512
// fall back to the TypeTree root node for script types.
@@ -545,7 +544,7 @@ string ReadValue(TypeTreeNode node, long offset)
545544
return m_Reader.ReadUInt64(offset).ToString();
546545

547546
case TypeCode.SByte:
548-
return m_Reader.ReadUInt8(offset).ToString();
547+
return m_Reader.ReadInt8(offset).ToString();
549548

550549
case TypeCode.Byte:
551550
case TypeCode.Char:

0 commit comments

Comments
 (0)