@@ -251,7 +251,7 @@ class MpdType : IPsbType
251251
252252 public bool IsThisType ( PSB psb )
253253 {
254- return psb . Objects . ContainsKey ( "mpd" ) && psb . Objects [ "mpd" ] is PsbResource && psb . Objects . ContainsKey ( "tex" ) && psb . Objects . ContainsKey ( "draw_range_v " ) ;
254+ return psb . Objects . ContainsKey ( "mpd" ) && psb . Objects [ "mpd" ] is PsbResource && psb . Objects . ContainsKey ( "tex" ) && psb . Objects . ContainsKey ( "offset " ) ;
255255 }
256256
257257 public List < T > CollectResources < T > ( PSB psb , bool deDuplication = true ) where T : class , IResourceMetadata
@@ -275,12 +275,17 @@ public void Link(PSB psb, FreeMountContext context, IList<string> resPaths, stri
275275 return ;
276276 }
277277
278- var mpd = psb . Resources . FirstOrDefault ( ) ;
279- if ( mpd == null )
278+ var mpdList = psb . CollectResources < BinaryMetadata > ( ) ;
279+ PsbResource mpd ;
280+ if ( mpdList == null || mpdList . Count == 0 )
280281 {
281282 mpd = new PsbResource ( ) ;
282283 psb . Objects [ "mpd" ] = mpd ;
283284 }
285+ else
286+ {
287+ mpd = mpdList [ 0 ] . Resource ;
288+ }
284289
285290 mpd . Data = File . ReadAllBytes ( path ) ;
286291 }
@@ -298,43 +303,51 @@ public void Link(PSB psb, FreeMountContext context, IDictionary<string, string>
298303 return ;
299304 }
300305
301- var mpd = psb . Resources . FirstOrDefault ( ) ;
302- if ( mpd == null )
306+ var mpdList = psb . CollectResources < BinaryMetadata > ( ) ;
307+ PsbResource mpd ;
308+ if ( mpdList == null || mpdList . Count == 0 )
303309 {
304310 mpd = new PsbResource ( ) ;
305311 psb . Objects [ "mpd" ] = mpd ;
306312 }
307-
313+ else
314+ {
315+ mpd = mpdList [ 0 ] . Resource ;
316+ }
317+
308318 mpd . Data = File . ReadAllBytes ( fullPath ) ;
309319 }
310320
311321 public void UnlinkToFile ( PSB psb , FreeMountContext context , string name , string dirPath , bool outputUnlinkedPsb = true ,
312322 PsbLinkOrderBy order = PsbLinkOrderBy . Name )
313323 {
314- var mpd = psb . Resources . FirstOrDefault ( ) ;
315- if ( mpd == null )
324+ var mpdList = psb . CollectResources < BinaryMetadata > ( ) ;
325+ if ( mpdList == null || mpdList . Count == 0 )
316326 {
317327 return ;
318328 }
319329
330+ var mpd = mpdList [ 0 ] ;
320331 //var pureName = Path.GetFileNameWithoutExtension(name);
321332 var outPath = Path . Combine ( dirPath , $ "{ name } /0.mpd") ;
322333 File . WriteAllBytes ( outPath , mpd . Data ) ;
323334 if ( outputUnlinkedPsb )
324335 {
325- psb . Objects [ "mpd" ] = null ;
326- psb . Resources . Remove ( mpd ) ;
336+ psb . Objects [ "mpd" ] = PsbNull . Null ;
337+ psb . Resources . Remove ( mpd . Resource ) ;
327338 }
328339 }
329340
330341 public Dictionary < string , string > OutputResources ( PSB psb , FreeMountContext context , string name , string dirPath ,
331342 PsbExtractOption extractOption = PsbExtractOption . Original )
332343 {
333- var mpd = psb . Resources . FirstOrDefault ( ) ;
334- if ( mpd == null )
344+ var mpdList = psb . CollectResources < BinaryMetadata > ( ) ;
345+ if ( mpdList == null || mpdList . Count == 0 )
335346 {
336347 return [ ] ;
337348 }
349+
350+ var mpd = mpdList [ 0 ] ;
338351 //var pureName = Path.GetFileNameWithoutExtension(name);
339352 var outPath = Path . Combine ( dirPath , "0.mpd" ) ;
340353 File . WriteAllBytes ( outPath , mpd . Data ) ;
0 commit comments