Skip to content

Commit 36cb71b

Browse files
committed
Updates for XB1 DE
1 parent cd408c4 commit 36cb71b

12 files changed

+352
-18
lines changed

XbTool/XbTool/Bdat/BdatFieldInfo.cs

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public enum BdatFieldType
4343
Event,
4444
ShopTable,
4545
Enum,
46+
Quest,
4647
QuestFlag,
4748
QuestFlagIra,
4849
Flag,

XbTool/XbTool/Bdat/BdatTable.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace XbTool.Bdat
1111
[DebuggerDisplay("{" + nameof(Name) + ", nq}")]
1212
public class BdatTable
1313
{
14-
public string Name { get; }
14+
public string Name { get; set; }
1515
public string Filename { get; set; }
1616

1717
public int EncryptionFlag { get; } // Maybe other flags too?
@@ -66,6 +66,7 @@ public BdatTable(DataBuffer table)
6666
break;
6767
case Game.XBX:
6868
case Game.XB2:
69+
case Game.XB1DE:
6970
Members = ReadTableMembers(table);
7071
break;
7172
}

XbTool/XbTool/Bdat/BdatTables.cs

+40-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,20 @@ public BdatTables(string[] filenames, Game game, bool readMetadata)
3737
{
3838
Game = game;
3939
Tables = ReadAllBdats(filenames, game);
40-
TablesDict = Tables.ToDictionary(x => x.Name, x => x);
40+
41+
// todo: better way of dealing with XB1's duplicate name
42+
var dictionary = new Dictionary<string, BdatTable>();
43+
44+
foreach (BdatTable table in Tables)
45+
{
46+
if (dictionary.ContainsKey(table.Name))
47+
{
48+
table.Name = table.Filename + table.Name;
49+
}
50+
dictionary.Add(table.Name, table);
51+
}
52+
53+
TablesDict = dictionary;
4154
if (readMetadata) ReadMetadata();
4255
}
4356

@@ -146,7 +159,7 @@ private static BdatTable[] ReadBdatFile(DataBuffer file, string filename)
146159
public void ReadFieldInfo()
147160
{
148161
BdatFields = BdatInfoImport.ReadBdatFieldInfo(Game.ToString().ToLower());
149-
ResolveWildcards();
162+
ResolveFieldInfoWildcards();
150163

151164
Dictionary<string, BdatTable> tablesDict = Tables.ToDictionary(x => x.Name, x => x);
152165

@@ -181,7 +194,10 @@ public void ReadArrayInfos()
181194
{
182195
foreach (BdatArrayInfo array in BdatArrays)
183196
{
184-
BdatType type = Types.First(x => x.Name == array.Table);
197+
BdatType type = Types.FirstOrDefault(x => x.Name == array.Table);
198+
199+
if (type == null) continue;
200+
185201
array.IsReferences = true;
186202

187203
foreach (string element in array.Elements)
@@ -225,6 +241,8 @@ public void ReadTableInfo()
225241
{
226242
DisplayFields = BdatInfoImport.ReadBdatTableInfo(Game.ToString().ToLower());
227243

244+
ResolveTableInfoWildcards();
245+
228246
foreach (BdatTable table in Tables)
229247
{
230248
if (DisplayFields.ContainsKey(table.Name)) continue;
@@ -238,7 +256,7 @@ public void ReadTableInfo()
238256
}
239257
}
240258

241-
private void ResolveWildcards()
259+
private void ResolveFieldInfoWildcards()
242260
{
243261
KeyValuePair<(string table, string member), BdatFieldInfo>[] fields = BdatFields.Where(x => x.Value.Table.Contains('*')).ToArray();
244262
Dictionary<string, BdatTable> tablesDict = Tables.ToDictionary(x => x.Name, x => x);
@@ -309,6 +327,24 @@ private void ResolveWildcards()
309327
}
310328
}
311329

330+
private void ResolveTableInfoWildcards()
331+
{
332+
KeyValuePair<string, string>[] tables = DisplayFields.Where(x => x.Key.Contains('*')).ToArray();
333+
Dictionary<string, BdatTable> tablesDict = Tables.ToDictionary(x => x.Name, x => x);
334+
335+
foreach (KeyValuePair<string, string> table in tables)
336+
{
337+
var regex = new Regex("^" + Regex.Escape(table.Key).Replace(@"\*\#", "(.\\d*)").Replace(@"\*", "(.*)") + "$");
338+
Match[] matches = Tables.Select(x => regex.Match(x.Name)).Where(x => x.Success).ToArray();
339+
foreach (Match match in matches)
340+
{
341+
DisplayFields.Add(match.Value, table.Value);
342+
}
343+
344+
DisplayFields.Remove(table.Key);
345+
}
346+
}
347+
312348
private static BdatType[] CalculateBdatTypes(BdatTable[] tables)
313349
{
314350
Dictionary<string, string> customTypeNames = ReadTypeNames();

XbTool/XbTool/BdatString/BdatStringTools.cs

+50
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,37 @@ public static string GetItemTableXb1(ItemTypeXb1 type)
8484
}
8585
}
8686

87+
public static string GetQuestTableXb1(int id)
88+
{
89+
if (id > 1200) return "JNL_quest2601";
90+
if (id > 1000) return "JNL_quest2501";
91+
if (id > 960) return "JNL_quest2201";
92+
if (id > 920) return "JNL_quest2101";
93+
if (id > 890) return "JNL_quest2001";
94+
if (id > 850) return "JNL_quest1901";
95+
if (id > 849) return "JNL_quest1801";
96+
if (id > 810) return "JNL_quest1701";
97+
if (id > 809) return "JNL_quest1602";
98+
if (id > 750) return "JNL_quest1601";
99+
if (id > 720) return "JNL_quest1501";
100+
if (id > 680) return "JNL_quest1401";
101+
if (id > 640) return "JNL_quest1301";
102+
if (id > 625) return "JNL_quest1202";
103+
if (id > 610) return "JNL_quest1201";
104+
if (id > 535) return "JNL_quest1101";
105+
if (id > 495) return "JNL_quest1001";
106+
if (id > 465) return "JNL_quest0901";
107+
if (id > 464) return "JNL_quest0801";
108+
if (id > 350) return "JNL_quest0701";
109+
if (id > 310) return "JNL_quest0601";
110+
if (id > 275) return "JNL_quest0501";
111+
if (id > 260) return "JNL_quest0402";
112+
if (id > 173) return "JNL_quest0401";
113+
if (id > 115) return "JNL_quest0301";
114+
if (id > 85) return "JNL_quest0201";
115+
return "JNL_quest0101";
116+
}
117+
87118
public static string GetItemTableXbx(ItemTypeXbx type)
88119
{
89120
switch (type)
@@ -383,6 +414,25 @@ public static string GetShopTable(ShopType shopType)
383414
return null;
384415
}
385416

417+
public static string GetTaskTableXb1(TaskTypeXb1 taskType, int itemId)
418+
{
419+
switch (taskType)
420+
{
421+
case TaskTypeXb1.KillEnemy:
422+
return "BTL_enelist";
423+
case TaskTypeXb1.GetItem:
424+
return "ITM_itemlist";
425+
case TaskTypeXb1.TalkNpc:
426+
return "FLD_npclist";
427+
case TaskTypeXb1.CompleteQuest:
428+
return GetQuestTableXb1(itemId);
429+
case TaskTypeXb1.InteractObject:
430+
break;
431+
}
432+
433+
return null;
434+
}
435+
386436
public static string PrintEnumFlags(Type enumType, object value)
387437
{
388438
var sb = new StringBuilder();

XbTool/XbTool/BdatString/Metadata.cs

+18-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
45
using System.Text;
56
using XbTool.Bdat;
@@ -68,7 +69,7 @@ public static void ResolveItemRef(BdatStringValue value)
6869
break;
6970
case BdatFieldType.Item:
7071
if (tables.Game == Game.XB2) ApplyRef(BdatStringTools.GetItemTableXb2(refId));
71-
if (tables.Game == Game.XB1)
72+
if (tables.Game == Game.XB1 || tables.Game == Game.XB1DE)
7273
{
7374
var itemType = (ItemTypeXb1)int.Parse(item[field.RefField].ValueString);
7475
ApplyRef(BdatStringTools.GetItemTableXb1(itemType));
@@ -86,6 +87,11 @@ public static void ResolveItemRef(BdatStringValue value)
8687
case BdatFieldType.EventSetup:
8788
ApplyRef(BdatStringTools.GetEventSetupTable(refId));
8889
break;
90+
case BdatFieldType.Quest when tables.Game == Game.XB1DE:
91+
ApplyRef(BdatStringTools.GetQuestTableXb1(refId));
92+
break;
93+
case BdatFieldType.Quest:
94+
throw new InvalidDataException();
8995
case BdatFieldType.QuestFlag:
9096
ApplyRef(BdatStringTools.GetQuestListTable(refId));
9197
break;
@@ -95,20 +101,25 @@ public static void ResolveItemRef(BdatStringValue value)
95101
case BdatFieldType.Condition:
96102
if (tables.Game == Game.XB2)
97103
{
98-
var conditionType = (ConditionType) int.Parse(item[field.RefField].ValueString);
104+
var conditionType = (ConditionType)int.Parse(item[field.RefField].ValueString);
99105
ApplyRef(BdatStringTools.GetConditionTable(conditionType));
100106
}
101107
if (tables.Game == Game.XBX)
102108
{
103-
var conditionType = (ConditionTypeXbx) int.Parse(item[field.RefField].ValueString);
109+
var conditionType = (ConditionTypeXbx)int.Parse(item[field.RefField].ValueString);
104110
ApplyRef(BdatStringTools.GetConditionTableXbx(conditionType));
105111
}
106112

107113
break;
108-
case BdatFieldType.Task:
114+
case BdatFieldType.Task when tables.Game == Game.XB2:
109115
var taskType = (TaskType)int.Parse(item[field.RefField].ValueString);
110116
ApplyRef(BdatStringTools.GetTaskTable(taskType));
111117
break;
118+
case BdatFieldType.Task when tables.Game == Game.XB1 || tables.Game == Game.XB1DE:
119+
var taskTypeXb1 = (TaskTypeXb1)int.Parse(item[field.RefField].ValueString);
120+
int itemId = int.Parse(item[field.Field].ValueString);
121+
ApplyRef(BdatStringTools.GetTaskTableXb1(taskTypeXb1, itemId));
122+
break;
112123
case BdatFieldType.ShopTable:
113124
var shopType = (ShopType)int.Parse(item[field.RefField].ValueString);
114125
ApplyRef(BdatStringTools.GetShopTable(shopType));
@@ -117,8 +128,8 @@ public static void ResolveItemRef(BdatStringValue value)
117128
ApplyRef(BdatStringTools.GetCharacterTable(refId));
118129
break;
119130
case BdatFieldType.Enhance:
120-
if(tables.Game == Game.XB2) value.Display = BdatStringTools.GetEnhanceCaption(value);
121-
if(tables.Game == Game.XBX) value.Display = BdatStringTools.GetEnhanceCaptionXbx(value);
131+
if (tables.Game == Game.XB2) value.Display = BdatStringTools.GetEnhanceCaption(value);
132+
if (tables.Game == Game.XBX) value.Display = BdatStringTools.GetEnhanceCaptionXbx(value);
122133
break;
123134
case BdatFieldType.WeatherIdMap:
124135
value.Display = BdatStringTools.PrintWeatherIdMap(refId, 13, tables);
@@ -149,7 +160,7 @@ public static void ResolveItemRef(BdatStringValue value)
149160
case BdatFieldType.Place:
150161
var placeCat = (PlaceCategory)int.Parse(item[field.RefField].ValueString);
151162
string placeTable = GimmickData.GetPlaceTable(placeCat, refId);
152-
if(placeTable != null) ApplyRef(placeTable);
163+
if (placeTable != null) ApplyRef(placeTable);
153164
break;
154165
}
155166

XbTool/XbTool/Common/DataBuffer.cs

+18-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public DataBuffer(byte[] file, Game game, int start)
2424
File = file;
2525
Start = start;
2626
Game = game;
27-
Endianness = game == Game.XB2 ? Endianness.Little : Endianness.Big;
27+
Endianness = GetGameEndianness(game);
2828
Length = file.Length - start;
2929
}
3030

@@ -33,10 +33,24 @@ public DataBuffer(byte[] file, Game game, int start, int length)
3333
File = file;
3434
Start = start;
3535
Game = game;
36-
Endianness = game == Game.XB2 ? Endianness.Little : Endianness.Big;
36+
Endianness = GetGameEndianness(game);
3737
Length = length;
3838
}
3939

40+
private Endianness GetGameEndianness(Game game)
41+
{
42+
switch (game)
43+
{
44+
case Game.XB1:
45+
case Game.XBX:
46+
return Endianness.Big;
47+
case Game.XB2:
48+
case Game.XB1DE:
49+
default:
50+
return Endianness.Little;
51+
}
52+
}
53+
4054
public byte this[int index]
4155
{
4256
get => File[Start + index];
@@ -354,6 +368,7 @@ public enum Game
354368
{
355369
XB1 = 1,
356370
XBX,
357-
XB2
371+
XB2,
372+
XB1DE
358373
}
359374
}

XbTool/XbTool/Data/xb1de_arrays.csv

Whitespace-only changes.

0 commit comments

Comments
 (0)