-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathSummaryGenerator.cs
More file actions
1499 lines (1406 loc) · 64.2 KB
/
SummaryGenerator.cs
File metadata and controls
1499 lines (1406 loc) · 64.2 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
namespace KismetAnalyzer;
using System.Text.RegularExpressions;
using UAssetAPI;
using UAssetAPI.UnrealTypes;
using UAssetAPI.ExportTypes;
using UAssetAPI.FieldTypes;
using UAssetAPI.Kismet.Bytecode;
using UAssetAPI.Kismet.Bytecode.Expressions;
using Dot;
using static Dot.Html;
public class SummaryGenerator
{
public class Lines
{
public List<Element> Elements { get; }
public int Address { get; }
public List<Lines> Children { get; }
public Lines(int address = -1)
{
Elements = new List<Element>();
Address = address;
Children = new List<Lines>();
if (address >= 0)
{
Elements.Add(new Element(ElementKind.Address, $"{address}: "));
}
}
public Lines(string label) : this(-1)
{
Elements.Add(new Element(ElementKind.PlainText, label));
}
// Fluent builders for semantic elements
public Lines Expr(KismetExpression expr) { Elements.Add(new Element(ElementKind.ExpressionType, "EX_" + expr.Inst)); return this; }
public Lines Addr(uint addr) { Elements.Add(new Element(ElementKind.Address, addr.ToString())); return this; }
public Lines Addr(int addr) { Elements.Add(new Element(ElementKind.Address, addr.ToString())); return this; }
public Lines Var(string name) { Elements.Add(new Element(ElementKind.Variable, name)); return this; }
public Lines Func(string name) { Elements.Add(new Element(ElementKind.Function, name)); return this; }
public Lines Str(string value) { Elements.Add(new Element(ElementKind.StringLiteral, value)); return this; }
public Lines Num(string value) { Elements.Add(new Element(ElementKind.NumericLiteral, value)); return this; }
public Lines Num<T>(T value) where T : struct { Elements.Add(new Element(ElementKind.NumericLiteral, value.ToString()!)); return this; }
public Lines Type(string name) { Elements.Add(new Element(ElementKind.TypeName, name)); return this; }
public Lines Kw(string keyword) { Elements.Add(new Element(ElementKind.Keyword, keyword)); return this; }
public Lines Text(string text) { Elements.Add(new Element(ElementKind.PlainText, text)); return this; }
public Lines Add(Lines line)
{
Children.Add(line);
return this;
}
public Lines Add(string line)
{
Children.Add(new Lines(line));
return this;
}
// Returns elements for rendering
public IEnumerable<(int Address, int Nest, List<Element> Elements)> GetElements()
{
yield return (Address, 0, Elements);
foreach (var child in Children)
{
foreach (var (address, nest, elements) in child.GetElements())
{
yield return (address, nest + 1, elements);
}
}
}
}
public class Instruction
{
public uint Address { get; }
public List<Reference> ReferencedAddresses { get; }
public Lines Content { get; }
public Instruction(uint address, List<Reference> referencedAddresses, Lines content)
{
Address = address;
ReferencedAddresses = referencedAddresses;
Content = content;
}
}
public readonly struct Reference
{
public uint Address { get; }
public ReferenceType Type { get; }
public string? FunctionName { get; }
public Reference(uint address, ReferenceType type, string? functionName = null)
{
Address = address;
Type = type;
FunctionName = functionName;
}
}
public enum ReferenceType
{
Normal,
Jump,
JumpTrue,
JumpFalse,
Push,
Pop,
Latent,
Function,
}
public class BasicBlock
{
public uint StartAddress { get; }
public List<Instruction> Instructions { get; }
public List<BlockEdge> Successors { get; }
public bool IsTerminal { get; set; }
public BasicBlock(uint startAddress)
{
StartAddress = startAddress;
Instructions = new List<Instruction>();
Successors = new List<BlockEdge>();
IsTerminal = false;
}
public uint EndAddress => Instructions.Count > 0
? Instructions[^1].Address
: StartAddress;
}
public readonly struct BlockEdge
{
public uint TargetAddress { get; }
public ReferenceType Type { get; }
public string? FunctionName { get; }
public BlockEdge(uint targetAddress, ReferenceType type, string? functionName = null)
{
TargetAddress = targetAddress;
Type = type;
FunctionName = functionName;
}
}
UAsset Asset;
TextWriter Output;
TextWriter DotOutput;
Graph Graph;
FunctionExport? CurrentFunction;
public SummaryGenerator(UAsset asset, TextWriter output, TextWriter dotOutput)
{
Asset = asset;
Output = output;
DotOutput = dotOutput;
Graph = new Graph("digraph");
Graph.GraphAttributes["fontname"] = "monospace";
Graph.GraphAttributes["pack"] = "true";
Graph.NodeAttributes["fontname"] = "monospace";
Graph.EdgeAttributes["fontname"] = "monospace";
}
public bool Summarize()
{
var anyExport = false;
var classExport = Asset.GetClassExport();
if (classExport != null)
{
anyExport = true;
var classLines = new Lines().Kw("ClassExport:").Text(" ").Type(classExport.ObjectName.ToString());
classLines.Add(new Lines().Kw("SuperStruct:").Text(" ").Type(ToString(classExport.SuperStruct)));
var propLines = new Lines().Kw("Properties:");
foreach (var (propType, propName, propFlags) in GetProperties(classExport))
{
var lines = new Lines().Type(propType).Text(" ").Var(propName);
var flags = new List<string>();
foreach (EPropertyFlags flag in Enum.GetValues(typeof(EPropertyFlags)))
{
if (flag != EPropertyFlags.CPF_None && propFlags.HasFlag(flag))
{
flags.Add(flag.ToString());
}
}
if (flags.Count > 0) lines.Add(new Lines().Kw(String.Join("|", flags)));
propLines.Add(lines);
}
classLines.Add(propLines);
var classNode = new Node(classExport.ObjectName.ToString());
var classCell = Td().Attr("ALIGN", "LEFT").Attr("BALIGN", "LEFT");
DotHtmlLabelRenderer.RenderTo(classCell, classLines);
classNode.HtmlLabel = Table("#d4ffd4").Add(Tr().Add(classCell));
classNode.Attributes["shape"] = "none";
Graph.Nodes.Add(classNode);
}
else
{
Output.WriteLine("No ClassExport");
}
// Pre-pass: Collect all instructions and cross-function entry points
var allFunctionInstructions = new Dictionary<string, List<Instruction>>();
var externalEntryPoints = new Dictionary<string, HashSet<uint>>();
foreach (var export in Asset.Exports)
{
if (export is FunctionExport e)
{
CurrentFunction = e;
string functionName = e.ObjectName.ToString();
var instructions = new List<Instruction>();
uint index = 0;
foreach (var exp in e.ScriptBytecode)
{
instructions.Add(Stringify(exp, ref index));
}
allFunctionInstructions[functionName] = instructions;
// Collect cross-function entry points (calls into other functions with int arg)
foreach (var instr in instructions)
{
foreach (var reference in instr.ReferencedAddresses)
{
if (reference.Type == ReferenceType.Function && reference.FunctionName != null)
{
if (!externalEntryPoints.ContainsKey(reference.FunctionName))
{
externalEntryPoints[reference.FunctionName] = new HashSet<uint>();
}
externalEntryPoints[reference.FunctionName].Add(reference.Address);
}
}
}
}
}
// Set packmode based on total header nodes (functions + class)
var headerCount = allFunctionInstructions.Count + (classExport != null ? 1 : 0);
Graph.GraphAttributes["packmode"] = $"array_ti{headerCount}";
foreach (var export in Asset.Exports)
{
if (export is FunctionExport e)
{
if (classExport == null) throw new InvalidOperationException("ClassExport found");
anyExport = true;
Output.WriteLine("FunctionExport " + e.ObjectName);
string functionName = e.ObjectName.ToString();
var functionLines = new Lines().Kw("Function").Text(" ").Func(functionName);
foreach (var (propType, propName, propFlags) in GetProperties(e))
{
var flags = new List<string>();
foreach (EPropertyFlags flag in Enum.GetValues(typeof(EPropertyFlags)))
{
if (flag != EPropertyFlags.CPF_None && propFlags.HasFlag(flag))
{
flags.Add(flag.ToString());
}
}
var propLines = new Lines().Type(propType).Text(" ").Var(propName);
if (flags.Count > 0) propLines.Add(new Lines().Kw(String.Join("|", flags)));
functionLines.Add(propLines);
}
var functionNode = new Node(functionName);
var functionCell = Td().Attr("ALIGN", "LEFT").Attr("BALIGN", "LEFT");
DotHtmlLabelRenderer.RenderTo(functionCell, functionLines);
functionNode.HtmlLabel = Table("#ffd4d4").Add(Tr().Add(functionCell));
functionNode.Attributes["shape"] = "none";
Graph.Nodes.Add(functionNode);
var instructions = allFunctionInstructions[functionName];
// Get external entry points for this function (calls from other functions)
var externalLeaders = externalEntryPoints.GetValueOrDefault(functionName) ?? new HashSet<uint>();
// Build basic blocks with both internal and external leaders
var leaders = IdentifyBlockLeaders(instructions, functionName);
leaders.UnionWith(externalLeaders);
var blocks = BuildBasicBlocks(instructions, leaders);
// Build address-to-block mapping for edge resolution
var addressToBlock = new Dictionary<uint, BasicBlock>();
foreach (var block in blocks)
{
addressToBlock[block.StartAddress] = block;
}
// Function entry edge to first block
if (blocks.Count > 0)
{
var functionEdge = new Edge(functionName, $"{functionName}__block_{blocks[0].StartAddress}");
functionEdge.BCompass = "n";
Graph.Edges.Add(functionEdge);
}
// Generate TXT and DOT output for each block
foreach (var block in blocks)
{
// Skip blocks that only contain EX_EndOfScript
if (block.Instructions.Count == 1 &&
block.Instructions[0].Content.Elements.Any(e =>
e.Kind == ElementKind.ExpressionType && e.Value == "EX_EndOfScript"))
{
continue;
}
// TXT output with full block headers
Output.WriteLine($"=== Block @ {block.StartAddress} ===");
Output.WriteLine($" Successors: {FormatSuccessors(block.Successors)}");
Output.WriteLine();
PlainTextRenderer.RenderTo(Output, block.Instructions.Select(i => i.Content));
Output.WriteLine();
// DOT output: one node per block
var nodeId = $"{functionName}__block_{block.StartAddress}";
var node = new Node(nodeId);
// Build label with header and content cells
var headerCell = Td().Add($"{classExport.ObjectName}::{functionName} @ {block.StartAddress}");
var contentCell = Td().Attr("ALIGN", "LEFT").Attr("BALIGN", "LEFT");
DotHtmlLabelRenderer.RenderTo(contentCell, block.Instructions.Select(i => i.Content));
node.HtmlLabel = Table("#eeeeee")
.Add(Tr().Add(headerCell))
.Add(Tr().Add(contentCell));
node.Attributes["shape"] = "none";
Graph.Nodes.Add(node);
// Create edges based on block successors
foreach (var successor in block.Successors)
{
string targetNodeId;
if (successor.FunctionName != null)
{
// Cross-function reference
targetNodeId = $"{successor.FunctionName}__block_{successor.TargetAddress}";
}
else if (addressToBlock.TryGetValue(successor.TargetAddress, out var targetBlock))
{
// Local block reference
targetNodeId = $"{functionName}__block_{targetBlock.StartAddress}";
}
else
{
// Target might be in the middle of a block - find containing block
var containingBlock = blocks.FirstOrDefault(b =>
b.Instructions.Any(i => i.Address == successor.TargetAddress));
if (containingBlock != null)
{
targetNodeId = $"{functionName}__block_{containingBlock.StartAddress}";
}
else
{
// Unknown target - create orphan edge
targetNodeId = $"{functionName}__addr_{successor.TargetAddress}";
}
}
var edge = new Edge(nodeId, targetNodeId);
edge.BCompass = "n";
switch (successor.Type)
{
case ReferenceType.Normal:
edge.Attributes["style"] = "solid";
break;
case ReferenceType.JumpTrue:
edge.Attributes["color"] = "green";
break;
case ReferenceType.JumpFalse:
edge.Attributes["color"] = "red";
edge.Attributes["arrowhead"] = "onormal";
edge.ACompass = "e";
break;
case ReferenceType.Jump:
edge.Attributes["color"] = "blue";
edge.Attributes["style"] = "dashed";
break;
case ReferenceType.Push:
edge.Attributes["color"] = "purple";
edge.Attributes["style"] = "dotted";
edge.Attributes["penwidth"] = "2";
edge.Attributes["arrowhead"] = "onormal";
edge.ACompass = "e";
break;
case ReferenceType.Latent:
edge.Attributes["color"] = "orange";
edge.Attributes["style"] = "dashed";
edge.Attributes["arrowhead"] = "onormal";
edge.ACompass = "e";
break;
case ReferenceType.Function:
edge.Attributes["color"] = "gray";
edge.Attributes["style"] = "dotted";
edge.Attributes["penwidth"] = "2";
edge.Attributes["arrowhead"] = "vee";
edge.ACompass = "e";
break;
}
Graph.Edges.Add(edge);
}
}
}
}
Graph.Write(DotOutput);
return anyExport;
}
static HashSet<uint> IdentifyBlockLeaders(List<Instruction> instructions, string functionName)
{
var leaders = new HashSet<uint>();
if (instructions.Count == 0) return leaders;
// First instruction is always a leader
leaders.Add(instructions[0].Address);
// Count how many times each address is targeted by non-sequential jumps
var targetCounts = new Dictionary<uint, int>();
foreach (var instr in instructions)
{
foreach (var reference in instr.ReferencedAddresses)
{
// Skip Normal (fall-through) - it's sequential flow, not a branch
if (reference.Type == ReferenceType.Normal)
continue;
if (reference.FunctionName == null ||
(reference.Type == ReferenceType.Latent && reference.FunctionName == functionName))
{
var addr = reference.Address;
targetCounts[addr] = targetCounts.GetValueOrDefault(addr, 0) + 1;
// Conditional branches and special flow always create leaders
// (they represent divergence points)
if (reference.Type == ReferenceType.JumpTrue ||
reference.Type == ReferenceType.JumpFalse ||
reference.Type == ReferenceType.Push ||
reference.Type == ReferenceType.Latent)
{
leaders.Add(addr);
}
}
}
}
// Addresses targeted by multiple non-sequential jumps are convergence points
foreach (var (addr, count) in targetCounts)
{
if (count > 1)
{
leaders.Add(addr);
}
}
return leaders;
}
static List<BasicBlock> BuildBasicBlocks(List<Instruction> instructions, HashSet<uint> leaders)
{
var blocks = new List<BasicBlock>();
if (instructions.Count == 0) return blocks;
// Build address -> instruction map for control flow traversal
var byAddress = instructions.ToDictionary(i => i.Address);
// Track visited addresses and queue of addresses to process
var visited = new HashSet<uint>();
var toVisit = new Queue<uint>();
toVisit.Enqueue(instructions[0].Address);
// Also queue all leaders (they may be jump targets not reachable sequentially)
foreach (var leader in leaders)
toVisit.Enqueue(leader);
while (toVisit.Count > 0)
{
var startAddr = toVisit.Dequeue();
if (visited.Contains(startAddr) || !byAddress.ContainsKey(startAddr))
continue;
var currentBlock = new BasicBlock(startAddr);
blocks.Add(currentBlock);
var currentAddr = startAddr;
while (byAddress.TryGetValue(currentAddr, out var instr) && !visited.Contains(currentAddr))
{
// If we hit a leader (and it's not the start of this block), end block
if (leaders.Contains(currentAddr) && currentAddr != startAddr)
{
toVisit.Enqueue(currentAddr);
break;
}
visited.Add(currentAddr);
currentBlock.Instructions.Add(instr);
// Check if this is a block terminator (branching or special flow)
if (IsBlockTerminator(instr))
{
currentBlock.IsTerminal = IsAbsoluteTerminator(instr);
// Queue all branch targets
foreach (var r in instr.ReferencedAddresses.Where(r => r.FunctionName == null))
toVisit.Enqueue(r.Address);
break;
}
// Follow Normal reference (fall-through or unconditional jump target)
var normalRef = instr.ReferencedAddresses
.FirstOrDefault(r => r.Type == ReferenceType.Normal && r.FunctionName == null);
if (normalRef.Address != 0 || instr.ReferencedAddresses.Any(r => r.Type == ReferenceType.Normal && r.Address == 0))
{
currentAddr = normalRef.Address;
}
else
{
// No Normal reference - terminal instruction
currentBlock.IsTerminal = true;
break;
}
}
}
// Build successor edges for each block
foreach (var block in blocks)
{
if (block.Instructions.Count == 0) continue;
// Collect non-local references from ALL instructions in the block
// (e.g., calls to ubergraph, latent action continuations, push execution flow)
foreach (var instr in block.Instructions)
{
foreach (var reference in instr.ReferencedAddresses)
{
if (reference.Type == ReferenceType.Function ||
reference.Type == ReferenceType.Latent ||
reference.Type == ReferenceType.Push)
{
block.Successors.Add(new BlockEdge(
reference.Address,
reference.Type,
reference.FunctionName));
}
}
}
// Control flow successors come from the last instruction
var lastInstr = block.Instructions[^1];
foreach (var reference in lastInstr.ReferencedAddresses)
{
// Skip types already added above, and skip Pop (indirect jump with no known target)
if (reference.Type != ReferenceType.Function &&
reference.Type != ReferenceType.Latent &&
reference.Type != ReferenceType.Push &&
reference.Type != ReferenceType.Pop)
{
block.Successors.Add(new BlockEdge(
reference.Address,
reference.Type,
reference.FunctionName));
}
}
}
return blocks;
}
static bool IsBlockTerminator(Instruction instr)
{
// Block terminates when control flow branches or has special flow
// - JumpTrue/JumpFalse = conditional branch
// - Push/Latent = special flow (latent actions, push execution flow)
// - Pop = indirect jump to previously pushed address
// - No Normal reference = no fall-through (terminal instructions)
return instr.ReferencedAddresses.Any(r =>
r.Type == ReferenceType.JumpTrue ||
r.Type == ReferenceType.JumpFalse ||
r.Type == ReferenceType.Push ||
r.Type == ReferenceType.Pop ||
r.Type == ReferenceType.Latent) ||
!instr.ReferencedAddresses.Any(r => r.Type == ReferenceType.Normal);
}
static bool IsAbsoluteTerminator(Instruction instr)
{
// No fall-through = no Normal reference
return !instr.ReferencedAddresses.Any(r => r.Type == ReferenceType.Normal);
}
static string FormatSuccessors(List<BlockEdge> successors)
{
return string.Join(", ", successors.Select(s =>
{
var target = s.FunctionName != null ? $"{s.FunctionName}:{s.TargetAddress}" : s.TargetAddress.ToString();
return s.Type == ReferenceType.Normal ? target : $"{target} ({s.Type})";
}));
}
Instruction Stringify(KismetExpression exp, ref uint index)
{
var referencedAddresses = new List<Reference>();
var address = index;
var content = Stringify(exp, ref index, referencedAddresses, true);
return new Instruction(address, referencedAddresses, content);
}
Lines Stringify(KismetExpression exp, ref uint index, List<Reference> referencedAddresses, bool top = false)
{
int addr = (int)index;
index++;
Lines lines;
switch (exp)
{
case EX_PushExecutionFlow e:
{
lines = new Lines(addr).Expr(e).Text(" ").Addr(e.PushingAddress);
referencedAddresses.Add(new Reference(e.PushingAddress, ReferenceType.Push));
index += 4;
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_ComputedJump e:
{
lines = new Lines(addr).Expr(e);
lines.Add(Stringify(e.CodeOffsetExpression, ref index, referencedAddresses));
// TODO how to map out where this jumps?
break;
}
case EX_Jump e:
{
lines = new Lines(addr).Expr(e).Text(" ").Addr(e.CodeOffset);
// Normal reference - single target, like fall-through but to non-sequential address
referencedAddresses.Add(new Reference(e.CodeOffset, ReferenceType.Normal));
index += 4;
break;
}
case EX_JumpIfNot e:
{
lines = new Lines(addr).Expr(e).Text(" ").Addr(e.CodeOffset);
referencedAddresses.Add(new Reference(e.CodeOffset, ReferenceType.JumpFalse));
index += 4;
lines.Add(Stringify(e.BooleanExpression, ref index, referencedAddresses));
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.JumpTrue));
break;
}
case EX_LocalVariable e:
{
lines = new Lines(addr).Expr(e).Text(" ").Var(ToString(e.Variable));
index += 8;
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_LocalOutVariable e:
{
lines = new Lines(addr).Expr(e).Text(" ").Var(ToString(e.Variable));
index += 8;
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_DefaultVariable e:
{
lines = new Lines(addr).Expr(e).Text(" ").Var(ToString(e.Variable));
index += 8;
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_InstanceVariable e:
{
lines = new Lines(addr).Expr(e).Text(" ").Var(ToString(e.Variable));
index += 8;
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_ObjToInterfaceCast e:
{
lines = new Lines(addr).Expr(e).Text(" ").Type(ToString(e.ClassPtr));
index += 8;
lines.Add(Stringify(e.Target, ref index, referencedAddresses));
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_InterfaceToObjCast e:
{
lines = new Lines(addr).Expr(e).Text(" ").Type(ToString(e.ClassPtr));
index += 8;
lines.Add(Stringify(e.Target, ref index, referencedAddresses));
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_Let e:
{
lines = new Lines(addr).Expr(e);
index += 8;
lines.Add(Stringify(e.Variable, ref index, referencedAddresses));
lines.Add(Stringify(e.Expression, ref index, referencedAddresses));
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_LetObj e:
{
lines = new Lines(addr).Expr(e);
lines.Add(Stringify(e.VariableExpression, ref index, referencedAddresses));
lines.Add(Stringify(e.AssignmentExpression, ref index, referencedAddresses));
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_LetDelegate e:
{
lines = new Lines(addr).Expr(e);
lines.Add(Stringify(e.VariableExpression, ref index, referencedAddresses));
lines.Add(Stringify(e.AssignmentExpression, ref index, referencedAddresses));
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_LetBool e:
{
lines = new Lines(addr).Expr(e);
lines.Add(Stringify(e.VariableExpression, ref index, referencedAddresses));
lines.Add(Stringify(e.AssignmentExpression, ref index, referencedAddresses));
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_LetWeakObjPtr e:
{
lines = new Lines(addr).Expr(e);
lines.Add(Stringify(e.VariableExpression, ref index, referencedAddresses));
lines.Add(Stringify(e.AssignmentExpression, ref index, referencedAddresses));
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_LetValueOnPersistentFrame e:
{
lines = new Lines(addr).Expr(e).Text(" ").Var(ToString(e.DestinationProperty));
index += 8;
lines.Add(Stringify(e.AssignmentExpression, ref index, referencedAddresses));
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_StructMemberContext e:
{
lines = new Lines(addr).Expr(e).Text(" ").Var(ToString(e.StructMemberExpression));
index += 8;
lines.Add(Stringify(e.StructExpression, ref index, referencedAddresses));
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_MetaCast e:
{
lines = new Lines(addr).Expr(e).Text(" ").Type(ToString(e.ClassPtr));
index += 8;
lines.Add(Stringify(e.Target, ref index, referencedAddresses));
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_DynamicCast e:
{
lines = new Lines(addr).Expr(e).Text(" ").Type(ToString(e.ClassPtr));
index += 8;
lines.Add(Stringify(e.Target, ref index, referencedAddresses));
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_PrimitiveCast e:
{
lines = new Lines(addr).Expr(e).Text(" ").Type(e.ConversionType.ToString());
index++;
switch (e.ConversionType)
{
case ECastToken.InterfaceToBool:
{
break;
}
case ECastToken.ObjectToBool:
{
break;
}
case ECastToken.ObjectToInterface:
{
index += 8;
// TODO InterfaceClass
break;
}
}
lines.Add(Stringify(e.Target, ref index, referencedAddresses));
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_PopExecutionFlow e:
{
lines = new Lines(addr).Expr(e);
referencedAddresses.Add(new Reference(uint.MaxValue, ReferenceType.Pop));
break;
}
case EX_PopExecutionFlowIfNot e:
{
lines = new Lines(addr).Expr(e);
lines.Add(Stringify(e.BooleanExpression, ref index, referencedAddresses));
if (top) referencedAddresses.Add(new Reference(uint.MaxValue, ReferenceType.Pop));
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.JumpTrue));
break;
}
case EX_CallMath e:
{
lines = new Lines(addr).Expr(e).Text(" ").Func(ToString(e.StackNode));
index += 8;
foreach (var arg in e.Parameters)
{
lines.Add(Stringify(arg, ref index, referencedAddresses));
}
index++;
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_SwitchValue e:
{
lines = new Lines(addr).Expr(e);
index += 6;
lines.Add(Stringify(e.IndexTerm, ref index, referencedAddresses));
// lines.Add("OffsetToSwitchEnd = " + e.EndGotoOffset);
var ci = -1;
foreach (var c in e.Cases)
{
ci++;
var nested = new Lines((int)addr).Kw("case").Text(" ").Num(ci).Text(":");
nested.Add(Stringify(c.CaseIndexValueTerm, ref index, referencedAddresses));
index += 4;
// nested.Add("NextCaseOffset = " + c.NextOffset);
nested.Add(Stringify(c.CaseTerm, ref index, referencedAddresses));
lines.Add(nested);
}
var defaultCase = new Lines((int)addr).Kw("default").Text(":");
defaultCase.Add(Stringify(e.DefaultTerm, ref index, referencedAddresses));
lines.Add(defaultCase);
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_Self e:
{
lines = new Lines(addr).Expr(e);
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_TextConst e:
{
lines = new Lines(addr).Expr(e);
index++;
switch (e.Value.TextLiteralType)
{
case EBlueprintTextLiteralType.Empty:
{
break;
}
case EBlueprintTextLiteralType.LocalizedText:
{
lines.Add(new Lines().Kw("SourceString").Text(" = ").Str(ReadString(e.Value.LocalizedSource, ref index)));
lines.Add(new Lines().Kw("LocalizedKey").Text(" = ").Str(ReadString(e.Value.LocalizedKey, ref index)));
lines.Add(new Lines().Kw("LocalizedNamespace").Text(" = ").Str(ReadString(e.Value.LocalizedNamespace, ref index)));
break;
}
case EBlueprintTextLiteralType.InvariantText:
{
lines.Add(new Lines().Kw("SourceString").Text(" = ").Str(ReadString(e.Value.InvariantLiteralString, ref index)));
break;
}
case EBlueprintTextLiteralType.LiteralString:
{
lines.Add(new Lines().Kw("SourceString").Text(" = ").Str(ReadString(e.Value.LiteralString, ref index)));
break;
}
case EBlueprintTextLiteralType.StringTableEntry:
{
index += 8;
lines.Add(new Lines().Kw("TableId").Text(" = ").Str(ReadString(e.Value.StringTableId, ref index)));
lines.Add(new Lines().Kw("TableKey").Text(" = ").Str(ReadString(e.Value.StringTableKey, ref index)));
break;
}
}
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_ObjectConst e:
{
lines = new Lines(addr).Expr(e).Text(" ").Var(ToString(e.Value));
index += 8;
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_VectorConst e:
{
lines = new Lines(addr).Expr(e).Text(" ").Num($"{e.Value.X},{e.Value.Y},{e.Value.Z}");
index += Asset.ObjectVersionUE5 >= ObjectVersionUE5.LARGE_WORLD_COORDINATES ? 24U : 12U;
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_Vector3fConst e:
{
lines = new Lines(addr).Expr(e).Text(" ").Num($"{e.X},{e.Y},{e.Z}");
index += 12;
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_RotationConst e:
{
lines = new Lines(addr).Expr(e).Text(" ").Num($"{e.Value.Pitch},{e.Value.Yaw},{e.Value.Roll}");
index += Asset.ObjectVersionUE5 >= ObjectVersionUE5.LARGE_WORLD_COORDINATES ? 24U : 12U;
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_TransformConst e:
{
lines = new Lines(addr).Expr(e).Text(" ")
.Num($"[Rot={e.Value.Rotation.X},{e.Value.Rotation.Y},{e.Value.Rotation.Z},{e.Value.Rotation.W}] [Pos={e.Value.Translation.X},{e.Value.Translation.Y},{e.Value.Translation.Z}] [Scale={e.Value.Scale3D.X},{e.Value.Scale3D.Y},{e.Value.Scale3D.Z}]");
index += Asset.ObjectVersionUE5 >= ObjectVersionUE5.LARGE_WORLD_COORDINATES ? 80U : 40U;
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_Context e:
{
lines = new Lines(addr).Expr(e);
lines.Add(Stringify(e.ObjectExpression, ref index, referencedAddresses));
index += 4;
//lines.Add("SkipOffsetForNull = " + e.Offset);
index += 8;
lines.Add(Stringify(e.ContextExpression, ref index, referencedAddresses));
//lines.Add("RValue = " + ToString(e.RValuePointer));
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_CallMulticastDelegate e:
{
lines = new Lines(addr).Expr(e).Text(" ").Func(ToString(e.StackNode));
index += 8;
//lines.Add("IsSelfContext = " + (Asset.GetClassExport().OuterIndex.Index == e.StackNode.Index));
lines.Add(Stringify(e.Delegate, ref index, referencedAddresses));
foreach (var arg in e.Parameters)
{
lines.Add(Stringify(arg, ref index, referencedAddresses));
}
index++;
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_LocalFinalFunction e:
{
lines = new Lines(addr).Expr(e).Text(" ").Func(ToString(e.StackNode));
index += 8;
foreach (var arg in e.Parameters)
{
lines.Add(Stringify(arg, ref index, referencedAddresses));
}
index++;
if (e.Parameters.Length == 1 && e.Parameters[0] is EX_IntConst value)
{
if (e.StackNode.IsExport())
{
referencedAddresses.Add(new Reference((uint)value.Value, ReferenceType.Function, e.StackNode.ToExport(Asset).ObjectName.ToString()));
}
else
{
Console.Error.WriteLine("WARN: Unimplemented StackNode import");
}
}
else
{
Console.Error.WriteLine("WARN: Unimplemented non-EX_IntConst");
}
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}
case EX_FinalFunction e:
{
lines = new Lines(addr).Expr(e).Text(" ").Func(ToString(e.StackNode));
index += 8;
foreach (var arg in e.Parameters)
{
lines.Add(Stringify(arg, ref index, referencedAddresses));
}
index++;
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
break;
}