-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUObjectReader.cs
More file actions
121 lines (102 loc) · 3.48 KB
/
Copy pathUObjectReader.cs
File metadata and controls
121 lines (102 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using Serilog;
using UAssetReader.Runtime.Core.Misc;
using UAssetReader.Runtime.CoreUObject.UObject;
namespace UAssetReader.Core.IO;
public class UObjectReader
{
/// <summary>
/// Debug output logger.
/// </summary>
private ILogger? Logger { get; }
/// <summary>
/// Stream reader used to process the current stream.
/// </summary>
private UStreamReader StreamReader { get; }
/// <summary>
/// Class constructor.
/// </summary>
/// <param name="stream">Source stream to process.</param>
/// <param name="logger">Debug output logger.</param>
public UObjectReader(Stream stream, ILogger? logger = null)
{
StreamReader = new UStreamReader(stream, logger);
Logger = logger;
}
/// <summary>
/// Read value of the EObjectFlags enum from the current stream.
/// </summary>
/// <returns>Value of EObjectFlags enum.</returns>
public EObjectFlags ReadEObjectFlags()
{
Logger?.Debug("Reading EObjectFlags at {Position}", StreamReader.Position);
return (EObjectFlags) StreamReader.ReadUInt32();
}
/// <summary>
/// Read an instance of FGuid class from the current stream.
/// </summary>
/// <returns>An instance of FGuid.</returns>
public FGuid ReadFGuid()
{
Logger?.Debug("Reading FGuid at {Position}", StreamReader.Position);
return new FGuid
{
Value = StreamReader.ReadGuid(),
};
}
/// <summary>
/// Read an instance of FName class from the current stream.
/// </summary>
/// <returns>An instance of FName.</returns>
public FName ReadFName()
{
Logger?.Debug("Reading FName at {Position}", StreamReader.Position);
// Retrieve index of the name entry.
int index = StreamReader.ReadInt32();
// Read and discard (skip) additional bytes (unknown).
// Potentially https://docs.unrealengine.com/5.0/en-US/API/Runtime/Core/UObject/EFindName/.
StreamReader.Skip(sizeof(int));
return new FName
{
Index = index
};
}
/// <summary>
/// Read an instance of FPackageIndex class from the current stream.
/// </summary>
/// <returns>An instance of FPackageIndex.</returns>
public FPackageIndex ReadFPackageIndex()
{
Logger?.Debug("Reading FPackageIndex at {Position}", StreamReader.Position);
return new FPackageIndex
{
Index = StreamReader.ReadInt32()
};
}
/// <summary>
/// Read an instance of FPropertyGuid class from the current stream.
/// </summary>
/// <returns>An instance of FPropertyGuid.</returns>
public FGuid? ReadFPropertyGuid()
{
Logger?.Debug("Reading property FGuid at {Position}", StreamReader.Position);
// Determine if GUID value is present in the stream.
bool hasGuid = StreamReader.ReadBool();
// Read the existing GUID if present or use NULL if not.
return hasGuid ? ReadFGuid() : null;
}
/// <summary>
/// Read an instance of FPropertyTag class from the current stream.
/// </summary>
/// <returns>An instance of FPropertyTag.</returns>
public FPropertyTag ReadFPropertyTag()
{
Logger?.Debug("Reading FPropertyTag at {Position}", StreamReader.Position);
return new FPropertyTag
{
Name = ReadFName(),
Type = ReadFName(),
Size = StreamReader.ReadInt32(),
Index = StreamReader.ReadInt32(),
};
}
}