-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDataTableBaker.cs
More file actions
143 lines (127 loc) · 5.27 KB
/
DataTableBaker.cs
File metadata and controls
143 lines (127 loc) · 5.27 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
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using UAssetAPI;
using UAssetAPI.PropertyTypes;
using UAssetAPI.StructTypes;
namespace AstroModIntegrator
{
public class DataTableBaker
{
private ModIntegrator ParentIntegrator;
public DataTableBaker(ModIntegrator ParentIntegrator)
{
this.ParentIntegrator = ParentIntegrator;
}
public UAsset Bake(Metadata[] allMods, List<string> optionalModIDs, byte[] superRawData)
{
UAsset y = new UAsset(IntegratorUtils.EngineVersion);
y.UseSeparateBulkDataFiles = true;
y.Read(new AssetBinaryReader(new MemoryStream(superRawData), y));
DataTableExport targetCategory = null;
foreach (Export cat in y.Exports)
{
if (cat is DataTableExport)
{
targetCategory = (DataTableExport)cat;
break;
}
}
List<StructPropertyData> tab = targetCategory.Table.Data;
FName[] columns = tab[0].Value.Select(x => x.Name).ToArray();
List<StructPropertyData> newTable = new List<StructPropertyData>();
foreach (Metadata mod in allMods)
{
if (mod == null) continue;
y.AddNameReference(new FString(mod.ModID));
string codedSyncMode = "SyncMode::NewEnumerator0";
switch(mod.Sync)
{
case SyncMode.None:
codedSyncMode = "SyncMode::NewEnumerator0";
break;
case SyncMode.ServerOnly:
codedSyncMode = "SyncMode::NewEnumerator1";
break;
case SyncMode.ClientOnly:
codedSyncMode = "SyncMode::NewEnumerator2";
break;
case SyncMode.ServerAndClient:
codedSyncMode = "SyncMode::NewEnumerator3";
break;
}
List<PropertyData> rows = new List<PropertyData>();
rows.Add(new StrPropertyData(columns[0])
{
Value = new FString(mod.Name ?? "", Encoding.ASCII),
});
rows.Add(new StrPropertyData(columns[1])
{
Value = new FString(mod.Author ?? "", Encoding.ASCII),
});
rows.Add(new StrPropertyData(columns[2])
{
Value = new FString(mod.Description ?? "", Encoding.ASCII),
});
rows.Add(new StrPropertyData(columns[3])
{
Value = new FString(mod.ModVersion?.ToString() ?? "", Encoding.ASCII),
});
rows.Add(new StrPropertyData(columns[4])
{
Value = new FString(mod.AstroBuild?.ToString() ?? "", Encoding.ASCII),
});
y.AddNameReference(new FString("SyncMode"));
y.AddNameReference(new FString(codedSyncMode));
rows.Add(new BytePropertyData(columns[5])
{
ByteType = BytePropertyType.FName,
EnumType = new FName("SyncMode"),
EnumValue = new FName(codedSyncMode)
});
rows.Add(new StrPropertyData(columns[6])
{
Value = new FString(mod.Homepage ?? "", Encoding.ASCII),
});
rows.Add(new BoolPropertyData(columns[7])
{
Value = optionalModIDs.Contains(mod.ModID),
});
newTable.Add(new StructPropertyData(new FName(mod.ModID))
{
StructType = tab[0].StructType,
Value = rows
});
}
targetCategory.Table.Data = newTable;
return y;
}
public UAsset Bake2(byte[] superRawData)
{
UAsset y = new UAsset(IntegratorUtils.EngineVersion);
y.UseSeparateBulkDataFiles = true;
y.Read(new AssetBinaryReader(new MemoryStream(superRawData), y));
FPackageIndex brandNewLink = y.AddImport(new Import("/Script/Engine", "BlueprintGeneratedClass", y.AddImport(new Import("/Script/CoreUObject", "Package", FPackageIndex.FromRawIndex(0), "/Game/Integrator/IntegratorStatics_BP")), "IntegratorStatics_BP_C"));
NormalExport cat1 = y.Exports[0] as NormalExport;
if (cat1 == null) return null;
cat1.Data = new List<PropertyData>()
{
new StrPropertyData(new FName("IntegratorVersion"))
{
Value = new FString(IntegratorUtils.CurrentVersion.ToString(), Encoding.ASCII)
},
new BoolPropertyData(new FName("RefuseMismatchedConnections"))
{
Value = ParentIntegrator.RefuseMismatchedConnections
},
new ObjectPropertyData(new FName("NativeClass"))
{
Value = brandNewLink
}
};
return y;
}
}
}