├── DQAsset
├── DQAsset.csproj
├── UE4Versions.cs
├── ISerializable.cs
├── UE4Structs.cs
├── Program.cs
├── PackageFileSummary.cs
├── FTableRowBase.cs
├── Shared.cs
└── UAsset.cs
├── DQAsset.sln
├── README.md
└── .gitignore
/DQAsset/DQAsset.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 | none
10 | false
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/DQAsset/UE4Versions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DQAsset
6 | {
7 | public enum UE4Versions : int
8 | {
9 | VER_UE4_OLDEST_LOADABLE_PACKAGE = 214,
10 | VER_UE4_WORLD_LEVEL_INFO = 224,
11 | VER_UE4_ADDED_CHUNKID_TO_ASSETDATA_AND_UPACKAGE = 278,
12 | VER_UE4_CHANGED_CHUNKID_TO_BE_AN_ARRAY_OF_CHUNKIDS = 326,
13 | VER_UE4_ENGINE_VERSION_OBJECT = 336,
14 | VER_UE4_LOAD_FOR_EDITOR_GAME = 365,
15 | VER_UE4_ADD_STRING_ASSET_REFERENCES_MAP = 384,
16 | VER_UE4_PACKAGE_SUMMARY_HAS_COMPATIBLE_ENGINE_VERSION = 444,
17 | VER_UE4_SERIALIZE_TEXT_IN_PACKAGES = 459,
18 | VER_UE4_COOKED_ASSETS_IN_EDITOR_SUPPORT = 485,
19 | VER_UE4_NAME_HASHES_SERIALIZED = 504,
20 | VER_UE4_PRELOAD_DEPENDENCIES_IN_COOKED_EXPORTS = 507,
21 | VER_UE4_TemplateIndex_IN_COOKED_EXPORTS = 508,
22 | VER_UE4_ADDED_SEARCHABLE_NAMES = 510,
23 | VER_UE4_64BIT_EXPORTMAP_SERIALSIZES = 511,
24 | VER_UE4_ADDED_PACKAGE_SUMMARY_LOCALIZATION_ID = 516,
25 | VER_UE4_ADDED_PACKAGE_OWNER = 518,
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/DQAsset.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30907.101
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DQAsset", "DQAsset\DQAsset.csproj", "{E8A8537F-3579-40FE-9057-41BB770731F7}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {E8A8537F-3579-40FE-9057-41BB770731F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {E8A8537F-3579-40FE-9057-41BB770731F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {E8A8537F-3579-40FE-9057-41BB770731F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {E8A8537F-3579-40FE-9057-41BB770731F7}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {1C49CF2B-A940-4836-89AD-CE9449F1B949}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DQXIAsset
2 | UAsset <-> CSV converter for DQXIS/UE4 DataTables, supporting almost all DQXIS table structs.
3 |
4 | The UE4 package reading code here is pretty tightly coupled with the packages used by DQXIS, and not likely to work well with any other UE4 titles (unless they happened to be based on DQXIS's UE4 branch or something)
5 |
6 | DQXIS datatables are kinda unique from other UE4 games datatables, instead of each row containing properties that describe each field name/type/value, rows instead have a single StructProperty inside them, which contains the row data pretty much as a C/C++ struct/binary blob.
7 |
8 | Fortunately for us the format of these StructProperties is stored inside the EXE (as can be seen in [DQXIS-SDK](https://github.com/emoose/DQXIS-SDK)), though the format defined in the EXE doesn't always seem to match up with the actual row data, oftentimes having certain fields moved around/reordered, and padding fields added/removed.
9 |
10 | There are a couple datatables in DQXIS that do use the normal UE4 datatable format though, these seem to be denoted by a "UDS" prefix ('user-defined struct').
11 | I've tried adding some support for these in here but it's not that great since I didn't design for that kind of table, you'd probably have better luck editing those with [kaiheilos's Uasset Viewer tool](https://github.com/kaiheilos/Utilities).
12 |
13 | ---
14 |
15 | For info about using this tool see the Releases page: https://github.com/emoose/DQXIAsset/releases/
16 |
--------------------------------------------------------------------------------
/DQAsset/ISerializable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Text;
5 |
6 | namespace DQAsset
7 | {
8 | public interface ISerializable
9 | {
10 | void Deserialize(BinaryReader reader, PackageFile package);
11 |
12 | void Serialize(BinaryWriter writer, PackageFile package);
13 | }
14 |
15 | public interface ISerializableText : ISerializable
16 | {
17 | void DeserializeText(string text, PackageFile package);
18 | string SerializeText(PackageFile package, bool isMainElement);
19 | string SerializeTextHeader(PackageFile package);
20 | }
21 |
22 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.GenericParameter | AttributeTargets.Class)]
23 | public class SerializerAttribute : Attribute
24 | {
25 | // Struct size isn't contained in the uexp data, maybe there's a flag in uasset somewhere that defines this?
26 | public bool NoStructSize { get; set; }
27 |
28 | // Number of bytes/array elements
29 | public int Size { get; set; }
30 |
31 | // Won't be written into/read from CSV file, eg. for padding bytes, if used make sure to remove PropertiesData.Clear() line from Program.cs!
32 | public bool Hidden { get; set; }
33 |
34 | // Only serializes/deserializes if field is set
35 | public string OnlyIfSet { get; set; }
36 | public string OnlyIfNotSet { get; set; }
37 |
38 |
39 | public string[] OnlyIfAllSet { get; set; }
40 | public string[] OnlyIfAllNotSet { get; set; }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/DQAsset/UE4Structs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace DQAsset
5 | {
6 | public struct GenerationInfo
7 | {
8 | public int ExportCount;
9 | public int NameCount;
10 | }
11 |
12 | public struct CompressedChunk
13 | {
14 | public int UncompressedOffset;
15 | public int UncompressedSize;
16 | public int CompressedOffset;
17 | public int CompressedSize;
18 | }
19 |
20 | public class FVector2D : FTableRowBase
21 | {
22 | public float X;
23 | public float Y;
24 | }
25 |
26 | public class FVector : FTableRowBase
27 | {
28 | public float X;
29 | public float Y;
30 | public float Z;
31 | }
32 |
33 | public class FRotator : FTableRowBase
34 | {
35 | public float Pitch;
36 | public float Yaw;
37 | public float Roll;
38 | }
39 |
40 | public class FLinearColor : FTableRowBase
41 | {
42 | public float R;
43 | public float G;
44 | public float B;
45 | public float A;
46 | }
47 |
48 | // ScriptStruct CoreUObject.Quat
49 | // 0x0010
50 | public class FQuat : FTableRowBase
51 | {
52 | public float X; // 0x0000(0x0004) (Edit, BlueprintVisi, ZeroConstructor, SaveGame, IsPlainOldData)
53 | public float Y; // 0x0004(0x0004) (Edit, BlueprintVisi, ZeroConstructor, SaveGame, IsPlainOldData)
54 | public float Z; // 0x0008(0x0004) (Edit, BlueprintVisi, ZeroConstructor, SaveGame, IsPlainOldData)
55 | public float W; // 0x000C(0x0004) (Edit, BlueprintVisi, ZeroConstructor, SaveGame, IsPlainOldData)
56 | }
57 |
58 | // ScriptStruct CoreUObject.Transform
59 | // 0x0030
60 | public class FTransform : FTableRowBase
61 | {
62 | public FQuat Rotation; // 0x0000(0x0010) (Edit, BlueprintVisi, SaveGame, IsPlainOldData)
63 | public FVector Translation; // 0x0010(0x000C) (Edit, BlueprintVisi, SaveGame, IsPlainOldData)
64 | public FVector Scale3D; // 0x0020(0x000C) (Edit, BlueprintVisi, SaveGame, IsPlainOldData)
65 | }
66 |
67 | public class UObject : FTableRowBase
68 | {
69 | public FName Unknown0x0; // 0x0008(0x0008) (Edit, BlueprintVisi, BlueprintReadOnly, ZeroConstructor, DisableEditOnInstance, IsPlainOldData)
70 | public FName Unknown0x8;
71 | public FName Unknown0x10;
72 | public byte Unknown0x18;
73 | public int ClassIndex;
74 | public FName Unknown0x1D;
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | [Rr]elease-CI/
25 | x64/
26 | x86/
27 | [Ww][Ii][Nn]32/
28 | [Aa][Rr][Mm]/
29 | [Aa][Rr][Mm]64/
30 | bld/
31 | [Bb]in/
32 | [Oo]bj/
33 | [Ll]og/
34 | [Ll]ogs/
35 |
36 | # Visual Studio 2015/2017 cache/options directory
37 | .vs/
38 | # Uncomment if you have tasks that create the project's static files in wwwroot
39 | #wwwroot/
40 |
41 | # Visual Studio 2017 auto generated files
42 | Generated\ Files/
43 |
44 | # MSTest test Results
45 | [Tt]est[Rr]esult*/
46 | [Bb]uild[Ll]og.*
47 |
48 | # NUnit
49 | *.VisualState.xml
50 | TestResult.xml
51 | nunit-*.xml
52 |
53 | # Build Results of an ATL Project
54 | [Dd]ebugPS/
55 | [Rr]eleasePS/
56 | dlldata.c
57 |
58 | # Benchmark Results
59 | BenchmarkDotNet.Artifacts/
60 |
61 | # .NET Core
62 | project.lock.json
63 | project.fragment.lock.json
64 | artifacts/
65 |
66 | # ASP.NET Scaffolding
67 | ScaffoldingReadMe.txt
68 |
69 | # StyleCop
70 | StyleCopReport.xml
71 |
72 | # Files built by Visual Studio
73 | *_i.c
74 | *_p.c
75 | *_h.h
76 | *.ilk
77 | *.meta
78 | *.obj
79 | *.iobj
80 | *.pch
81 | *.pdb
82 | *.ipdb
83 | *.pgc
84 | *.pgd
85 | *.rsp
86 | *.sbr
87 | *.tlb
88 | *.tli
89 | *.tlh
90 | *.tmp
91 | *.tmp_proj
92 | *_wpftmp.csproj
93 | *.log
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*.json
147 | coverage*.xml
148 | coverage*.info
149 |
150 | # Visual Studio code coverage results
151 | *.coverage
152 | *.coveragexml
153 |
154 | # NCrunch
155 | _NCrunch_*
156 | .*crunch*.local.xml
157 | nCrunchTemp_*
158 |
159 | # MightyMoose
160 | *.mm.*
161 | AutoTest.Net/
162 |
163 | # Web workbench (sass)
164 | .sass-cache/
165 |
166 | # Installshield output folder
167 | [Ee]xpress/
168 |
169 | # DocProject is a documentation generator add-in
170 | DocProject/buildhelp/
171 | DocProject/Help/*.HxT
172 | DocProject/Help/*.HxC
173 | DocProject/Help/*.hhc
174 | DocProject/Help/*.hhk
175 | DocProject/Help/*.hhp
176 | DocProject/Help/Html2
177 | DocProject/Help/html
178 |
179 | # Click-Once directory
180 | publish/
181 |
182 | # Publish Web Output
183 | *.[Pp]ublish.xml
184 | *.azurePubxml
185 | # Note: Comment the next line if you want to checkin your web deploy settings,
186 | # but database connection strings (with potential passwords) will be unencrypted
187 | *.pubxml
188 | *.publishproj
189 |
190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
191 | # checkin your Azure Web App publish settings, but sensitive information contained
192 | # in these scripts will be unencrypted
193 | PublishScripts/
194 |
195 | # NuGet Packages
196 | *.nupkg
197 | # NuGet Symbol Packages
198 | *.snupkg
199 | # The packages folder can be ignored because of Package Restore
200 | **/[Pp]ackages/*
201 | # except build/, which is used as an MSBuild target.
202 | !**/[Pp]ackages/build/
203 | # Uncomment if necessary however generally it will be regenerated when needed
204 | #!**/[Pp]ackages/repositories.config
205 | # NuGet v3's project.json files produces more ignorable files
206 | *.nuget.props
207 | *.nuget.targets
208 |
209 | # Microsoft Azure Build Output
210 | csx/
211 | *.build.csdef
212 |
213 | # Microsoft Azure Emulator
214 | ecf/
215 | rcf/
216 |
217 | # Windows Store app package directories and files
218 | AppPackages/
219 | BundleArtifacts/
220 | Package.StoreAssociation.xml
221 | _pkginfo.txt
222 | *.appx
223 | *.appxbundle
224 | *.appxupload
225 |
226 | # Visual Studio cache files
227 | # files ending in .cache can be ignored
228 | *.[Cc]ache
229 | # but keep track of directories ending in .cache
230 | !?*.[Cc]ache/
231 |
232 | # Others
233 | ClientBin/
234 | ~$*
235 | *~
236 | *.dbmdl
237 | *.dbproj.schemaview
238 | *.jfm
239 | *.pfx
240 | *.publishsettings
241 | orleans.codegen.cs
242 |
243 | # Including strong name files can present a security risk
244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
245 | #*.snk
246 |
247 | # Since there are multiple workflows, uncomment next line to ignore bower_components
248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
249 | #bower_components/
250 |
251 | # RIA/Silverlight projects
252 | Generated_Code/
253 |
254 | # Backup & report files from converting an old project file
255 | # to a newer Visual Studio version. Backup files are not needed,
256 | # because we have git ;-)
257 | _UpgradeReport_Files/
258 | Backup*/
259 | UpgradeLog*.XML
260 | UpgradeLog*.htm
261 | ServiceFabricBackup/
262 | *.rptproj.bak
263 |
264 | # SQL Server files
265 | *.mdf
266 | *.ldf
267 | *.ndf
268 |
269 | # Business Intelligence projects
270 | *.rdl.data
271 | *.bim.layout
272 | *.bim_*.settings
273 | *.rptproj.rsuser
274 | *- [Bb]ackup.rdl
275 | *- [Bb]ackup ([0-9]).rdl
276 | *- [Bb]ackup ([0-9][0-9]).rdl
277 |
278 | # Microsoft Fakes
279 | FakesAssemblies/
280 |
281 | # GhostDoc plugin setting file
282 | *.GhostDoc.xml
283 |
284 | # Node.js Tools for Visual Studio
285 | .ntvs_analysis.dat
286 | node_modules/
287 |
288 | # Visual Studio 6 build log
289 | *.plg
290 |
291 | # Visual Studio 6 workspace options file
292 | *.opt
293 |
294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
295 | *.vbw
296 |
297 | # Visual Studio LightSwitch build output
298 | **/*.HTMLClient/GeneratedArtifacts
299 | **/*.DesktopClient/GeneratedArtifacts
300 | **/*.DesktopClient/ModelManifest.xml
301 | **/*.Server/GeneratedArtifacts
302 | **/*.Server/ModelManifest.xml
303 | _Pvt_Extensions
304 |
305 | # Paket dependency manager
306 | .paket/paket.exe
307 | paket-files/
308 |
309 | # FAKE - F# Make
310 | .fake/
311 |
312 | # CodeRush personal settings
313 | .cr/personal
314 |
315 | # Python Tools for Visual Studio (PTVS)
316 | __pycache__/
317 | *.pyc
318 |
319 | # Cake - Uncomment if you are using it
320 | # tools/**
321 | # !tools/packages.config
322 |
323 | # Tabs Studio
324 | *.tss
325 |
326 | # Telerik's JustMock configuration file
327 | *.jmconfig
328 |
329 | # BizTalk build output
330 | *.btp.cs
331 | *.btm.cs
332 | *.odx.cs
333 | *.xsd.cs
334 |
335 | # OpenCover UI analysis results
336 | OpenCover/
337 |
338 | # Azure Stream Analytics local run output
339 | ASALocalRun/
340 |
341 | # MSBuild Binary and Structured Log
342 | *.binlog
343 |
344 | # NVidia Nsight GPU debugger configuration file
345 | *.nvuser
346 |
347 | # MFractors (Xamarin productivity tool) working folder
348 | .mfractor/
349 |
350 | # Local History for Visual Studio
351 | .localhistory/
352 |
353 | # BeatPulse healthcheck temp database
354 | healthchecksdb
355 |
356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
357 | MigrationBackup/
358 |
359 | # Ionide (cross platform F# VS Code tools) working folder
360 | .ionide/
361 |
362 | # Fody - auto-generated XML schema
363 | FodyWeavers.xsd
364 |
--------------------------------------------------------------------------------
/DQAsset/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 |
5 | namespace DQAsset
6 | {
7 | class Program
8 | {
9 | public static bool DoFNameCleanup = true;
10 |
11 | static bool CompareOutput = false;
12 | static string BadFiles = "";
13 | static bool SkipIfOutputExists = false;
14 |
15 | static List FileBlackList = new List()
16 | {
17 | // most of these seem to use UserDefinedStructs (UDS), not sure how to handle those yet
18 | "DT_Coordinate.uasset", // strange file
19 | "DT_Crowd_SetList.uasset",
20 | "DT_DebugAutoPlay.uasset",
21 | "DT_DebugChairAnimation.uasset",
22 | "DT_DebugCommandMacro.uasset", // seems to work fine, but contains newline chars (and is huge)
23 | "DT_DebugCsCoordinate.uasset",
24 | "DT_DebugNpcAnimation.uasset",
25 | "DT_DebugNpcAnimCheck.uasset",
26 | "DT_DebugNpcClassCoordinate.uasset",
27 | "DT_DebugNpcSpawnTable.uasset",
28 | "DT_NavBuild.uasset",
29 | "DT_BattleAutoCameraCollision.uasset", // UDS STRUCT_DT_AutoCameraCollision
30 | "DT_PokerItem_.uasset", // UDS
31 | "DT_TextDataTest.csv", // messes up our CSV splitting regex
32 | };
33 |
34 | // Reads PackageFile from a UAsset file, if UExp exists next to it then they'll be merged before reading
35 | static PackageFile ReadPackage(string UAssetPath, bool convertingFromCsv)
36 | {
37 | var UExpPath = Path.ChangeExtension(UAssetPath, ".uexp");
38 |
39 | var uasset = File.ReadAllBytes(UAssetPath);
40 | var uassetLength = uasset.Length;
41 | if (File.Exists(UExpPath))
42 | {
43 | var uexp = File.ReadAllBytes(UExpPath);
44 | var uexpLength = uexp.Length;
45 |
46 | Array.Resize(ref uasset, uasset.Length + uexp.Length);
47 | Array.Copy(uexp, 0, uasset, uassetLength, uexpLength);
48 | }
49 |
50 | using (var reader = new BinaryReader(new MemoryStream(uasset)))
51 | {
52 | var sum = new PackageFile();
53 | if (convertingFromCsv)
54 | sum.SkipPropertyDataLoad = true;
55 | sum.Deserialize(reader);
56 | return sum;
57 | }
58 | }
59 |
60 | // some code to help with C++ -> C# struct conversion...
61 | static void JackDTStructsPostProcess()
62 | {
63 | var lines = File.ReadAllLines(@"C:\src\DQAsset\JackDTStructs.txt");
64 | var res = "";
65 | foreach (var line in lines)
66 | {
67 | var curLine = line;
68 | if (curLine.Contains(" MISSED OFFSET"))
69 | continue;
70 |
71 | if ((curLine.Contains("[0x10]") || curLine.Contains("[0x18]")) && curLine.Contains("UNKNOWN PROPERTY:") &&
72 | (curLine.Contains("SoftObjectProperty") || curLine.Contains("SoftClassProperty") || curLine.Contains("ArrayProperty")))
73 | {
74 | var fieldLast = curLine.LastIndexOf('.');
75 | var fieldName = curLine.Substring(fieldLast + 1);
76 | if (!curLine.Contains("ArrayProperty"))
77 | curLine = " public FName " + fieldName + ";";
78 | else
79 | curLine = " public List " + fieldName + ";";
80 | }
81 | else if (curLine.Contains("*") || curLine.Contains("TWeakObjectPtr"))
82 | curLine = " //" + curLine.Substring(4);
83 |
84 | if (curLine.Contains("TEnumAsByte<"))
85 | curLine = curLine.Replace("TEnumAsByte<", "").Replace(">", ""); // meh
86 |
87 | curLine = curLine.Replace(" : public ", " // : public ");
88 |
89 | curLine = curLine.Replace("public struct ", "public ");
90 |
91 | res += curLine + "\r\n";
92 | }
93 | File.WriteAllText(@"C:\src\DQAsset\JackDTStructs_new3.txt", res);
94 | }
95 |
96 | static void HandleInput(string inputFile, string outputFile)
97 | {
98 | var inputUAsset = inputFile;
99 |
100 | bool convertingFromCsv = false;
101 |
102 | var inputExtension = Path.GetExtension(inputFile).ToLower();
103 | if (inputExtension == ".csv")
104 | {
105 | if (string.IsNullOrEmpty(outputFile))
106 | outputFile = Path.Combine(Path.GetDirectoryName(inputFile), Path.GetFileNameWithoutExtension(inputFile) + "_mod");
107 | else
108 | {
109 | // remove extension from output path if user gave .uasset/.uexp
110 | var ext = Path.GetExtension(outputFile).ToLower();
111 | if (ext == ".uasset" || ext == ".uexp")
112 | outputFile = outputFile.Substring(0, outputFile.LastIndexOf('.'));
113 | }
114 |
115 | convertingFromCsv = true;
116 | inputUAsset = Path.ChangeExtension(inputFile, ".uasset");
117 | }
118 | else
119 | if (string.IsNullOrEmpty(outputFile))
120 | outputFile = Path.ChangeExtension(inputFile, ".csv");
121 |
122 | var outputUAsset = outputFile + ".uasset";
123 | var outputUexp = outputFile + ".uexp";
124 |
125 | if (SkipIfOutputExists && (File.Exists(outputFile) || File.Exists(outputUAsset)))
126 | return;
127 |
128 | if (!File.Exists(inputUAsset))
129 | {
130 | Console.WriteLine("failed to load base uasset from path");
131 | Console.WriteLine($" {inputUAsset}");
132 | return;
133 | }
134 |
135 | var package = ReadPackage(inputUAsset, convertingFromCsv);
136 | if (!convertingFromCsv)
137 | {
138 | File.WriteAllText(outputFile, package.SerializeText());
139 | Console.WriteLine("wrote out CSV to path");
140 | Console.WriteLine($" {outputFile}");
141 | return;
142 | }
143 |
144 | // Not converting to text, must be converting from text
145 | if (!File.Exists(inputFile))
146 | {
147 | Console.WriteLine("failed to load csv data from path");
148 | Console.WriteLine($" {inputFile}");
149 | return;
150 | }
151 |
152 | // Clear existing rows from loaded UAsset, so only ones defined in CSV will still exist
153 | // TODO: this shouldn't be used if any fields are marked with Serializer(Hidden=true), since atm we don't construct default object for them :(
154 | // If any structs are added which use that, comment this line to fix the serializer afterward...
155 | // (or alternatively, fix the serializer code properly so it constructs a default object ^^)
156 | package.ExportObjects[0].PropertiesData.Clear();
157 |
158 | var csvData = File.ReadAllText(inputFile);
159 | package.DeserializeText(csvData);
160 |
161 | using (var outputUAssetWriter = new BinaryWriter(File.Create(outputUAsset)))
162 | using (var outputUexpWriter = new BinaryWriter(File.Create(outputUexp)))
163 | package.Serialize(outputUexpWriter, outputUAssetWriter, Program.DoFNameCleanup);
164 |
165 | Console.WriteLine("wrote out uasset/uexp files to path");
166 | Console.WriteLine($" {outputFile}.uasset/uexp");
167 |
168 | if (CompareOutput)
169 | {
170 | var hasher = System.Security.Cryptography.SHA256.Create();
171 |
172 | var origUAsset = Path.ChangeExtension(inputFile, ".uasset");
173 | var origUExp = Path.ChangeExtension(inputFile, ".uexp");
174 | var newUAsset = outputUAsset;
175 | var newUExp = outputUexp;
176 |
177 | var origUExpHash = hasher.ComputeHash(File.ReadAllBytes(origUExp));
178 | var newUExpHash = hasher.ComputeHash(File.ReadAllBytes(newUExp));
179 | if (origUExpHash.ToHexString() != newUExpHash.ToHexString())
180 | {
181 | Console.WriteLine("INVALID UEXP:");
182 | Console.WriteLine(" " + origUAsset);
183 | BadFiles += inputFile + "\r\n";
184 | return;
185 | }
186 |
187 | var origUAssetHash = hasher.ComputeHash(File.ReadAllBytes(origUAsset));
188 | var newUAssetHash = hasher.ComputeHash(File.ReadAllBytes(newUAsset));
189 | if (origUAssetHash.ToHexString() != newUAssetHash.ToHexString())
190 | {
191 | Console.WriteLine("INVALID UASSET:");
192 | Console.WriteLine(" " + origUAsset);
193 | BadFiles += inputFile + "\r\n";
194 | return;
195 | }
196 | }
197 | }
198 |
199 | static void BatchFolder(string folderPath)
200 | {
201 | SkipIfOutputExists = false;
202 | CompareOutput = true;
203 | var assets = Directory.GetFiles(folderPath, "*.uasset", SearchOption.AllDirectories);
204 | foreach (var asset in assets)
205 | {
206 | var fname = Path.GetFileName(asset);
207 | if (FileBlackList.Contains(fname) ||
208 | fname.StartsWith("DT_PokerItem_"))
209 |
210 | {
211 | Console.WriteLine("blacklisted: " + asset);
212 | continue;
213 | }
214 | Console.WriteLine(asset);
215 | HandleInput(asset, string.Empty);
216 | }
217 | }
218 |
219 | static void Main(string[] args)
220 | {
221 | Console.WriteLine("DQXIAsset by emoose");
222 | Console.WriteLine("https://github.com/emoose/DQXIAsset");
223 | Console.WriteLine();
224 |
225 | //JackDTStructsPostProcess();
226 | //BatchFolder(@"C:\Games\DQXI\JackGame\Content\DataTables");
227 | //File.WriteAllText(@"C:\Games\DQXI\bad.txt", BadFiles);
228 |
229 | if (args.Length < 1)
230 | {
231 | Console.WriteLine("Allows converting UAsset/UExp pair to CSV, or CSV to UAsset/UExp pair");
232 | Console.WriteLine("Usage: DQAsset.exe [-o