Skip to content

Commit 88455fb

Browse files
authored
Fix display of Babyz content
1 parent a495386 commit 88455fb

File tree

2 files changed

+115
-3
lines changed

2 files changed

+115
-3
lines changed

Flh.cs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
2+
3+
using System.Collections.Generic;
4+
5+
namespace Kaitai
6+
{
7+
public partial class Flh : KaitaiStruct
8+
{
9+
public static Flh FromFile(string fileName)
10+
{
11+
return new Flh(new KaitaiStream(fileName));
12+
}
13+
14+
public Flh(KaitaiStream p__io, KaitaiStruct p__parent = null, Flh p__root = null) : base(p__io)
15+
{
16+
m_parent = p__parent;
17+
m_root = p__root ?? this;
18+
_read();
19+
}
20+
private void _read()
21+
{
22+
_lw1 = m_io.ReadU4le();
23+
_framecount = m_io.ReadU2le();
24+
_maxwidth = m_io.ReadU2le();
25+
_maxheight = m_io.ReadU2le();
26+
_padding = m_io.ReadU2le();
27+
_frames = new List<Anim>();
28+
for (var i = 0; i < Framecount; i++)
29+
{
30+
_frames.Add(new Anim(m_io, this, m_root));
31+
}
32+
}
33+
public partial class Anim : KaitaiStruct
34+
{
35+
public static Anim FromFile(string fileName)
36+
{
37+
return new Anim(new KaitaiStream(fileName));
38+
}
39+
40+
public Anim(KaitaiStream p__io, Flh p__parent = null, Flh p__root = null) : base(p__io)
41+
{
42+
m_parent = p__parent;
43+
m_root = p__root;
44+
_read();
45+
}
46+
private void _read()
47+
{
48+
_x1 = m_io.ReadU2le();
49+
_y1 = m_io.ReadU2le();
50+
_x2 = m_io.ReadU2le();
51+
_y2 = m_io.ReadU2le();
52+
_zero = m_io.ReadU4le();
53+
_f = m_io.ReadU4le();
54+
_name = System.Text.Encoding.GetEncoding("UTF-8").GetString(m_io.ReadBytes(16));
55+
_flags = m_io.ReadU4le();
56+
_offset = m_io.ReadU4le();
57+
}
58+
private ushort _x1;
59+
private ushort _y1;
60+
private ushort _x2;
61+
private ushort _y2;
62+
private uint _zero;
63+
private uint _f;
64+
private string _name;
65+
private uint _flags;
66+
private uint _offset;
67+
private Flh m_root;
68+
private Flh m_parent;
69+
public ushort X1 { get { return _x1; } }
70+
public ushort Y1 { get { return _y1; } }
71+
public ushort X2 { get { return _x2; } }
72+
public ushort Y2 { get { return _y2; } }
73+
public uint Zero { get { return _zero; } }
74+
public uint F { get { return _f; } }
75+
public string Name { get { return _name; } }
76+
public uint Flags { get { return _flags; } }
77+
public uint Offset { get { return _offset; } }
78+
public Flh M_Root { get { return m_root; } }
79+
public Flh M_Parent { get { return m_parent; } }
80+
}
81+
private uint _lw1;
82+
private ushort _framecount;
83+
private ushort _maxwidth;
84+
private ushort _maxheight;
85+
private ushort _padding;
86+
private List<Anim> _frames;
87+
private Flh m_root;
88+
private KaitaiStruct m_parent;
89+
public uint Lw1 { get { return _lw1; } }
90+
public ushort Framecount { get { return _framecount; } }
91+
public ushort Maxwidth { get { return _maxwidth; } }
92+
public ushort Maxheight { get { return _maxheight; } }
93+
public ushort Padding { get { return _padding; } }
94+
public List<Anim> Frames { get { return _frames; } }
95+
public Flh M_Root { get { return m_root; } }
96+
public KaitaiStruct M_Parent { get { return m_parent; } }
97+
}
98+
}

PetzThumbnailHandler.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,29 @@ public static Bitmap GetThumbnail(byte[] bytes, string type, uint width)
7979
flhname = "awaya";
8080
}
8181
var asm = AsmResolver.PE.PEImage.FromBytes(bytes);
82+
83+
// Weird way of doing this, but it seems like there is no way to figure it out from data
84+
// Tinker makes you set the palette manually
85+
// There's a flh field which seems like it might indicate palette but
86+
// it's wrong on Babyz toys which came from Petz (e.g. catz plush)
8287
var isBabyz = asm.Imports.Any(x => x.Name == "Babyz.exe");
88+
8389
var resourceTypes = asm.Resources.Entries.Where(x => x.Name == "FLM" || x.Name == "FLH");
84-
bool includeaway = type == "clo" || resourceTypes.Count() == 2;
90+
// if we only have 1 FLH/FLM set then it's probably a lnz toy with away only
91+
// Babyz toys look better always using the away, Petz toys look better the other way round
92+
bool includeaway = isBabyz || type == "clo" || resourceTypes.Count() == 2;
8593
resourceTypes = resourceTypes.SelectMany(x => (x as IResourceDirectory).Entries)
8694
.Where(x => !x.Name.ToLower().Contains("away") || includeaway);
8795
resourceTypes = resourceTypes.SelectMany(x => (x as IResourceDirectory).Entries);
8896

89-
BinaryStreamReader flh = resourceTypes.Where(x => x.ParentDirectory.ParentDirectory.Name == "FLH").Select(x => (x as IResourceData).CreateReader()).First();
90-
BinaryStreamReader flm = resourceTypes.Where(x => x.ParentDirectory.ParentDirectory.Name == "FLM").Select(x => (x as IResourceData).CreateReader()).First();
97+
// Prioritise "away" graphics for clothes and Babyz
98+
BinaryStreamReader flh = resourceTypes.Where(x => x.ParentDirectory.ParentDirectory.Name == "FLH")
99+
.OrderBy(x => (type == "clo" || isBabyz) && x.ParentDirectory.Name.ToLower().Contains("away") ? 0 : 1)
100+
.Select(x => (x as IResourceData).CreateReader())
101+
.First();
102+
BinaryStreamReader flm = resourceTypes.Where(x => x.ParentDirectory.ParentDirectory.Name == "FLM")
103+
.OrderBy(x => (type == "clo" || isBabyz) && x.ParentDirectory.Name.ToLower().Contains("away") ? 0 : 1)
104+
.Select(x => (x as IResourceData).CreateReader()).First();
91105

92106
var kaitaiflh = new Flh(new KaitaiStream(flh.ReadToEnd()));
93107
var frame = kaitaiflh.Frames.FirstOrDefault(x => x.Name.ToLower().Contains(flhname) && (x.Flags & 2) != 0);

0 commit comments

Comments
 (0)