5
5
using LibHac . Fs ;
6
6
using LibHac . FsSystem ;
7
7
using XbTool . Bdat ;
8
+ using XbTool . BdatString ;
8
9
using XbTool . Common ;
9
10
using XbTool . Types ;
10
11
11
12
namespace XbTool . Gimmick
12
13
{
13
14
public static class ReadGmk
14
15
{
15
- public static MapInfo [ ] ReadAll ( IFileSystem fs , BdatCollection tables , IProgressReport progress = null )
16
+ public static MapInfo [ ] ReadAll ( IFileSystem fs , BdatStringCollection tables , IProgressReport progress = null )
16
17
{
17
18
progress ? . LogMessage ( "Reading map info and gimmick sets" ) ;
18
19
Dictionary < string , MapInfo > maps = MapInfo . ReadAll ( fs ) ;
19
20
20
- BdatTable < FLD_maplist > mapList = tables . FLD_maplist ;
21
- BdatTable < MNU_MapInfo > areaList = tables . MNU_MapInfo ;
21
+ BdatStringItem [ ] mapList = tables . Tables [ " FLD_maplist" ] . Items ;
22
+ BdatStringItem [ ] areaList = tables . Tables [ " MNU_MapInfo" ] . Items ;
22
23
23
24
foreach ( MapInfo mapInfo in maps . Values )
24
25
{
25
- FLD_maplist map = mapList . FirstOrDefault ( x => x . resource == mapInfo . Name && x . _nameID != null ) ;
26
+ BdatStringItem map = mapList . FirstOrDefault ( x => x [ " resource" ] . DisplayString == mapInfo . Name && x [ "nameID" ] . DisplayString != null ) ;
26
27
if ( map == null ) continue ;
27
- if ( map . _nameID != null ) mapInfo . DisplayName = map . _nameID . name ;
28
+ mapInfo . DisplayName = map [ "nameID" ] . DisplayString ;
28
29
29
30
foreach ( MapAreaInfo areaInfo in mapInfo . Areas )
30
31
{
31
- MNU_MapInfo area = areaList . FirstOrDefault ( x =>
32
- x . level_name == areaInfo . Name || x . level_name2 == areaInfo . Name ) ;
32
+ BdatStringItem area = areaList . FirstOrDefault ( x =>
33
+ x [ " level_name" ] . DisplayString == areaInfo . Name || x [ " level_name2" ] . DisplayString == areaInfo . Name ) ;
33
34
if ( area == null )
34
35
{
35
36
progress ? . LogMessage ( $ "Found area { areaInfo . Name } that is not in the BDAT tables") ;
@@ -40,24 +41,24 @@ public static MapInfo[] ReadAll(IFileSystem fs, BdatCollection tables, IProgress
40
41
// These 2 maps are always the same except one has a small addition or removal.
41
42
// We want the map with the most objects on it, so we use the second map for
42
43
// Gormott (ma05a), and the first map for everywhere else.
43
- if ( ! string . IsNullOrWhiteSpace ( area . level_name2 )
44
- && area . level_name == areaInfo . Name
44
+ if ( ! string . IsNullOrWhiteSpace ( area [ " level_name2" ] . DisplayString )
45
+ && area [ " level_name" ] . DisplayString == areaInfo . Name
45
46
&& mapInfo . Name == "ma05a" )
46
47
{
47
48
areaInfo . Priority = int . MaxValue ;
48
49
}
49
- else if ( ! string . IsNullOrWhiteSpace ( area . level_name2 )
50
- && area . level_name2 == areaInfo . Name
50
+ else if ( ! string . IsNullOrWhiteSpace ( area [ " level_name2" ] . DisplayString )
51
+ && area [ " level_name2" ] . DisplayString == areaInfo . Name
51
52
&& mapInfo . Name != "ma05a" )
52
53
{
53
54
areaInfo . Priority = int . MaxValue ;
54
55
}
55
56
else
56
57
{
57
- areaInfo . Priority = area . level_priority ;
58
+ areaInfo . Priority = int . Parse ( area [ " level_priority" ] . ValueString ) ;
58
59
}
59
60
60
- if ( area . _disp_name ? . name != null ) areaInfo . DisplayName = area . _disp_name . name ;
61
+ if ( area [ "disp_name" ] . DisplayString != null ) areaInfo . DisplayName = area [ "disp_name" ] . DisplayString ;
61
62
}
62
63
63
64
Dictionary < string , Lvb > gimmickSet = ReadGimmickSet ( fs , tables , map . Id ) ;
@@ -67,31 +68,40 @@ public static MapInfo[] ReadAll(IFileSystem fs, BdatCollection tables, IProgress
67
68
return maps . Values . ToArray ( ) ;
68
69
}
69
70
70
- public static Dictionary < string , Lvb > ReadGimmickSet ( IFileSystem fs , BdatCollection tables , int mapId )
71
+ public static Dictionary < string , Lvb > ReadGimmickSet ( IFileSystem fs , BdatStringCollection tables , int mapId )
71
72
{
72
- RSC_GmkSetList setBdat = tables . RSC_GmkSetList . First ( x => x . mapId == mapId ) ;
73
+ BdatStringItem setBdat = tables . Tables [ "RSC_GmkSetList" ] . Items . First ( x => int . Parse ( x [ "mapId" ] . ValueString ) == mapId ) ;
74
+ IEnumerable < string > fields = setBdat . Values . Keys . Where ( x => ! x . Contains ( "_bdat" ) ) ;
73
75
Dictionary < string , FieldInfo > fieldsDict = setBdat . GetType ( ) . GetFields ( ) . ToDictionary ( x => x . Name , x => x ) ;
74
- IEnumerable < FieldInfo > fields = fieldsDict . Values . Where ( x => x . FieldType == typeof ( string ) && ! x . Name . Contains ( "_bdat" ) ) ;
75
76
var gimmicks = new Dictionary < string , Lvb > ( ) ;
76
77
77
- foreach ( FieldInfo field in fields )
78
+ foreach ( string field in fields )
78
79
{
79
- string value = ( string ) field . GetValue ( setBdat ) ;
80
+ string value = setBdat [ field ] . DisplayString ;
80
81
if ( value == null ) continue ;
81
82
string filename = $ "/gmk/{ value } .lvb";
82
83
if ( ! fs . FileExists ( filename ) ) continue ;
83
84
84
85
byte [ ] file = fs . ReadFile ( filename ) ;
85
- var lvb = new Lvb ( new DataBuffer ( file , Game . XB2 , 0 ) ) { Filename = field . Name } ;
86
+ var lvb = new Lvb ( new DataBuffer ( file , Game . XB2 , 0 ) ) { Filename = field } ;
86
87
87
- string bdatField = field . Name + "_bdat" ;
88
- if ( fieldsDict . ContainsKey ( bdatField ) )
88
+ string bdatField = field + "_bdat" ;
89
+ if ( setBdat . Values . ContainsKey ( bdatField ) )
89
90
{
90
- string bdatName = ( string ) fieldsDict [ bdatField ] . GetValue ( setBdat ) ;
91
- if ( ! string . IsNullOrWhiteSpace ( bdatName ) ) lvb . BdatName = bdatName ;
91
+ string bdatName = setBdat [ bdatField ] . DisplayString ;
92
+ if ( ! string . IsNullOrWhiteSpace ( bdatName ) )
93
+ {
94
+ lvb . BdatName = bdatName ;
95
+ foreach ( var gmk in lvb . Info )
96
+ {
97
+ gmk . BdatItem = tables [ lvb . BdatName ] . Items . FirstOrDefault ( itm => itm [ "name" ] . DisplayString == gmk . Name ) ;
98
+ if ( gmk . BdatItem != null )
99
+ gmk . BdatItem . Gmk = gmk ;
100
+ }
101
+ }
92
102
}
93
103
94
- gimmicks . Add ( field . Name , lvb ) ;
104
+ gimmicks . Add ( field , lvb ) ;
95
105
}
96
106
97
107
return gimmicks ;
0 commit comments