@@ -11,35 +11,44 @@ namespace ExtractorSharp.Handle {
1111 /// Ver5处理器
1212 /// </summary>
1313 public class FifthHandler : SecondHandler {
14- private readonly Dictionary < Sprite , DDS_Info > Map = new Dictionary < Sprite , DDS_Info > ( ) ;
15- private readonly List < DDS > List = new List < DDS > ( ) ;
14+ private readonly Dictionary < int , DDS_Info > Map = new Dictionary < int , DDS_Info > ( ) ;
15+ public readonly List < DDS > List = new List < DDS > ( ) ;
1616 public FifthHandler ( Album Album ) : base ( Album ) { }
1717
1818
1919 public override Bitmap ConvertToBitmap ( Sprite entity ) {
2020 if ( entity . Type < ColorBits . LINK && entity . Length > 0 ) {
2121 return base . ConvertToBitmap ( entity ) ;
2222 }
23- if ( Map . ContainsKey ( entity ) ) {
24- var index = Map [ entity ] ;
25- var dds = index . DDS ;
26- var bmp = dds . Pictrue . Clone ( index . Rectangle , PixelFormat . DontCare ) ;
27- if ( index . Top != 0 ) {
28- bmp . RotateFlip ( RotateFlipType . Rotate90FlipXY ) ;
29- }
30- return bmp ;
23+
24+ if ( ! Map . ContainsKey ( entity . Index ) ) {
25+ return new Bitmap ( 1 , 1 ) ;
3126 }
32- return new Bitmap ( 1 , 1 ) ;
27+ var index = Map [ entity . Index ] ;
28+ var dds = index . DDS ;
29+ var bmp = dds . Pictrue . Clone ( index . Rectangle , PixelFormat . DontCare ) ;
30+ if ( index . Top != 0 ) {
31+ bmp . RotateFlip ( RotateFlipType . Rotate90FlipXY ) ;
32+ }
33+ return bmp ;
3334
3435 }
3536
3637 public override byte [ ] ConvertToByte ( Sprite entity ) {
3738 if ( entity . Type < ColorBits . LINK && entity . Length > 0 ) {
3839 return base . ConvertToByte ( entity ) ;
3940 }
40- var type = entity . Type < ColorBits . LINK ? entity . Type : entity . Type - 4 ;
41- var dds = DDS . CreateFromBitmap ( entity . Picture , type ) ;
42- Map [ entity ] = new DDS_Info ( ) {
41+
42+ if ( entity . Width * entity . Height == 1 ) {
43+ entity . Compress = Compress . NONE ;
44+ return base . ConvertToByte ( entity ) ;
45+ }
46+ if ( entity . Compress == Compress . ZLIB ) {
47+ //非DDS_ZLIB 不识别
48+ entity . Compress = Compress . DDS_ZLIB ;
49+ }
50+ var dds = DDS . CreateFromBitmap ( entity ) ;
51+ Map [ entity . Index ] = new DDS_Info {
4352 DDS = dds ,
4453 RightDown = new Point ( dds . Width , dds . Height )
4554 } ;
@@ -55,10 +64,11 @@ public override byte[] AdjustData() {
5564 List . Clear ( ) ;
5665 foreach ( var index in Map . Values ) {
5766 var dds = index . DDS ;
58- if ( ! List . Contains ( dds ) ) {
59- dds . Index = List . Count ;
60- List . Add ( dds ) ;
67+ if ( List . Contains ( dds ) ) {
68+ continue ;
6169 }
70+ dds . Index = List . Count ;
71+ List . Add ( dds ) ;
6272 }
6373
6474 var ms = new MemoryStream ( ) ;
@@ -69,13 +79,14 @@ public override byte[] AdjustData() {
6979 ms . WriteInt ( ( int ) dds . Version ) ;
7080 ms . WriteInt ( ( int ) dds . Type ) ;
7181 ms . WriteInt ( dds . Index ) ;
72- ms . WriteInt ( dds . Size ) ;
73- ms . WriteInt ( dds . DDS_Size ) ;
82+ ms . WriteInt ( dds . Length ) ;
83+ ms . WriteInt ( dds . FullLength ) ;
7484 ms . WriteInt ( dds . Width ) ;
7585 ms . WriteInt ( dds . Height ) ;
7686 }
7787
7888 var ver2List = new List < Sprite > ( ) ;
89+ var start = ms . Length ;
7990 foreach ( var entity in Album . List ) {
8091 ms . WriteInt ( ( int ) entity . Type ) ;
8192 if ( entity . Type == ColorBits . LINK ) {
@@ -94,7 +105,7 @@ public override byte[] AdjustData() {
94105 ver2List . Add ( entity ) ;
95106 continue ;
96107 }
97- var info = Map [ entity ] ;
108+ var info = Map [ entity . Index ] ;
98109 ms . WriteInt ( info . Unknown ) ;
99110 ms . WriteInt ( info . DDS . Index ) ;
100111 ms . WriteInt ( info . LeftUp . X ) ;
@@ -103,9 +114,11 @@ public override byte[] AdjustData() {
103114 ms . WriteInt ( info . RightDown . Y ) ;
104115 ms . WriteInt ( info . Top ) ;
105116 }
117+ Album . Info_Length = ms . Length - start ;
106118 foreach ( var dds in List ) {
107119 ms . Write ( dds . Data ) ;
108120 }
121+
109122 foreach ( var sprite in ver2List ) {
110123 ms . Write ( sprite . Data ) ;
111124 }
@@ -121,19 +134,19 @@ public override byte[] AdjustData() {
121134 }
122135
123136 public override void CreateFromStream ( Stream stream ) {
124- int index_count = stream . ReadInt ( ) ;
137+ var index_count = stream . ReadInt ( ) ;
125138 Album . Length = stream . ReadInt ( ) ;
126- int count = stream . ReadInt ( ) ;
139+ var count = stream . ReadInt ( ) ;
127140 var table = new List < Color > ( Colors . ReadPalette ( stream , count ) ) ;
128141 Album . Tables = new List < List < Color > > { table } ;
129142 var list = new List < DDS > ( ) ;
130- for ( int i = 0 ; i < index_count ; i ++ ) {
143+ for ( var i = 0 ; i < index_count ; i ++ ) {
131144 var dds = new DDS {
132145 Version = ( DDS_Version ) stream . ReadInt ( ) ,
133146 Type = ( ColorBits ) stream . ReadInt ( ) ,
134147 Index = stream . ReadInt ( ) ,
135- Size = stream . ReadInt ( ) ,
136- DDS_Size = stream . ReadInt ( ) ,
148+ Length = stream . ReadInt ( ) ,
149+ FullLength = stream . ReadInt ( ) ,
137150 Width = stream . ReadInt ( ) ,
138151 Height = stream . ReadInt ( )
139152 } ;
@@ -162,7 +175,7 @@ public override void CreateFromStream(Stream stream) {
162175 ver2List . Add ( entity ) ;
163176 continue ;
164177 }
165- int j = stream . ReadInt ( ) ;
178+ var j = stream . ReadInt ( ) ;
166179 var k = stream . ReadInt ( ) ;
167180 var dds = list [ k ] ;
168181 var leftup = new Point ( stream . ReadInt ( ) , stream . ReadInt ( ) ) ;
@@ -175,13 +188,14 @@ public override void CreateFromStream(Stream stream) {
175188 RightDown = rightdown ,
176189 Top = top
177190 } ;
178- Map . Add ( entity , info ) ;
191+ Map . Add ( entity . Index , info ) ;
179192 }
193+
180194 foreach ( var entity in dic . Keys ) {
181195 entity . Target = Album . List [ dic [ entity ] ] ;
182196 }
183197 foreach ( var dds in list ) {
184- var data = new byte [ dds . Size ] ;
198+ var data = new byte [ dds . Length ] ;
185199 stream . Read ( data ) ;
186200 dds . Data = data ;
187201 }
0 commit comments