add src files decompiled via jad
[rsa2client.git] / src / mcsClient / Decompress.java
1 // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
2 // Jad home page: http://www.kpdus.com/jad.html
3 // Decompiler options: packimports(3) fieldsfirst nonlb space 
4
5 package mcsClient;
6
7 import java.awt.image.MemoryImageSource;
8 import java.io.*;
9 import java.util.logging.Level;
10 import java.util.logging.Logger;
11
12 // Referenced classes of package mcsClient:
13 //            HexConversion
14
15 public final class Decompress {
16     class VideoCommands {
17
18         private static final byte BF = 96;
19         private static final byte NC = 0;
20         private static final byte CA = 64;
21         private static final byte CB = 32;
22         private static final byte MM = 96;
23         private static final byte WP = -128;
24         private static final byte EF = 112;
25         private static final byte CMD_MASK = -32;
26         private static final byte RC_MASK = 31;
27         private static final byte RC_SIZE = 5;
28
29         VideoCommands() {
30         }
31     }
32
33
34     public static boolean PRINT_DATA = false;
35     private byte imageData[];
36     boolean pixelsInParts;
37     private int oldY;
38     private static Logger logger = Logger.getAnonymousLogger();
39
40     public Decompress(byte abyte0[]) {
41         oldY = 0;
42         imageData = abyte0;
43         logger.setLevel(Level.WARNING);
44         String s = System.getProperty("mcs.debug");
45         if (s != null && s.equalsIgnoreCase("true"))
46             logger.setLevel(Level.ALL);
47     }
48
49     public void doDecompress(DataInputStream datainputstream, int i, int j, int k, MemoryImageSource memoryimagesource, int l, int i1) throws ArrayIndexOutOfBoundsException {
50         int j1 = j;
51         boolean flag = false;
52         int l1 = 0;
53         int i2 = 0;
54         int j2 = 0;
55         byte byte1 = 96;
56         byte byte2 = 96;
57         byte byte3 = 0;
58         boolean flag1 = false;
59         boolean flag2 = false;
60         boolean flag3 = false;
61         boolean flag4 = false;
62         int k2 = 0;
63         int i3 = ((j1 + k + l) - 1) / l;
64         if (j == 0) {
65             pixelsInParts = false;
66             oldY = 0;
67         }
68         int j3 = 0;
69         boolean flag5 = false;
70         do {
71             if (j1 >= j + k) {
72                 if (j1 > j + k)
73                     logger.info("ERROR0: imageDataIndex = " + j1 + ", videoRamOffset = " + j + ", videoRamCount = " + k);
74                 if (pixelsInParts)
75                     memoryimagesource.newPixels(0, oldY, l - 1, i3 - oldY, false);
76                 break;
77             }
78             if (j3 >= i) {
79                 if (j3 > i)
80                     logger.warning("ERROR: bytesRead > datagramLength, bytesRead = " + j3 + ", datagramLength = " + i);
81                 if (!flag3)
82                     break;
83                 j2 = i2;
84                 j2 += 2;
85                 byte2 = byte1;
86                 flag1 = true;
87                 flag3 = false;
88                 flag5 = true;
89             }
90             if (!flag5) {
91                 try {
92                     l1 = datainputstream.readUnsignedByte();
93                     if (PRINT_DATA) {
94                         System.out.print(" " + HexConversion.toString(l1));
95                         if (++k2 >= 32) {
96                             k2 = 0;
97                             System.out.println();
98                         }
99                     }
100                 }
101                 catch (IOException ioexception) {
102                     logger.info("Decompress - error reading datagram byte " + ioexception);
103                     return;
104                 }
105                 j3++;
106                 byte byte0 = (byte)(l1 & 0xffffffe0);
107                 if (flag3)
108                     if (byte0 == byte1) {
109                         byte3++;
110                         i2 |= (l1 & 0x1f) << byte3 * 5;
111                         if (i2 > l * i1)
112                             logger.info("Bad repeat count " + i2);
113                         if (j1 + i2 + 3 >= j + k) {
114                             j2 = i2;
115                             j2 += 2;
116                             byte2 = byte1;
117                             flag1 = true;
118                             flag3 = false;
119                             byte3 = 0;
120                         }
121                     } else {
122                         j2 = i2;
123                         j2 += 2;
124                         byte2 = byte1;
125                         flag1 = true;
126                         flag3 = false;
127                         byte3 = 0;
128                     }
129                 switch (byte0) {
130                 case 0: // '\0'
131                 case 32: // ' '
132                 case 64: // '@'
133                     if (byte0 != byte1) {
134                         i2 = l1 & 0x1f;
135                         flag3 = true;
136                         byte3 = 0;
137                     }
138                     break;
139
140                 case 96: // '`'
141                     flag4 = true;
142                     break;
143
144                 default:
145                     if ((l1 & 0x80) != 0) {
146                         flag2 = true;
147                         break;
148                     }
149                     logger.severe("Unknown video command received, got: " + byte0);
150                     try {
151                         datainputstream.close();
152                     }
153                     catch (IOException ioexception1) {
154                         logger.info(ioexception1.toString());
155                     }
156                     return;
157                 }
158                 byte1 = byte0;
159             }
160             if (flag1) {
161                 switch (byte2) {
162                 default:
163                     break;
164
165                 case 0: // '\0'
166                     if (j2 > 0x80000) {
167                         int l2 = ((j1 + l) - 1) / l;
168                         memoryimagesource.newPixels(0, oldY, l - 1, l2 - oldY, false);
169                         oldY = ((j1 + j2) - (l - 1)) / l;
170                         pixelsInParts = true;
171                     }
172                     j1 += j2;
173                     break;
174
175                 case 64: // '@'
176                     if (j1 - j < l)
177                         logger.warning("Error: copy above index = " + (j1 - j));
178                     while (j2 > 0) 
179                         try {
180                             imageData[j1] = imageData[j1 - l];
181                             j1++;
182                             j2--;
183                         }
184                         catch (ArrayIndexOutOfBoundsException arrayindexoutofboundsexception) {
185                             logger.warning("imageDataIndex: " + j1);
186                             throw arrayindexoutofboundsexception;
187                         }
188                     break;
189
190                 case 32: // ' '
191                     if (j1 - j < 1)
192                         logger.warning("Error: copy left index = " + (j1 - j));
193                     byte byte4 = imageData[j1 - 1];
194                     while (j2 > 0) 
195                         try {
196                             imageData[j1] = byte4;
197                             j1++;
198                             j2--;
199                         }
200                         catch (ArrayIndexOutOfBoundsException arrayindexoutofboundsexception1) {
201                             logger.info("imageDataIndex: " + j1);
202                             throw arrayindexoutofboundsexception1;
203                         }
204                     break;
205                 }
206                 flag1 = false;
207             }
208             if (j1 >= j + k) {
209                 if (pixelsInParts)
210                     memoryimagesource.newPixels(0, oldY, l - 1, i3 - oldY, false);
211                 break;
212             }
213             if (flag4) {
214                 byte byte6 = 0;
215                 int k1 = j1;
216                 byte byte5 = imageData[j1 - 1];
217                 int k3 = j1 - 2;
218                 while (k3 >= j)  {
219                     if (imageData[k3] == byte5) {
220                         k3--;
221                         continue;
222                     }
223                     byte6 = imageData[k3];
224                     break;
225                 }
226                 try {
227                     imageData[j1++] = (l1 & 8) == 0 ? byte5 : byte6;
228                     imageData[j1++] = (l1 & 4) == 0 ? byte5 : byte6;
229                     imageData[j1++] = (l1 & 2) == 0 ? byte5 : byte6;
230                     imageData[j1++] = (l1 & 1) == 0 ? byte5 : byte6;
231                 }
232                 catch (ArrayIndexOutOfBoundsException arrayindexoutofboundsexception2) {
233                     logger.info("imageDataIndex: " + j1);
234                     throw arrayindexoutofboundsexception2;
235                 }
236                 if ((l1 & 0x10) != 0)
237                     do {
238                         try {
239                             l1 = datainputstream.readUnsignedByte();
240                             if (PRINT_DATA) {
241                                 System.out.print(" " + HexConversion.toString(l1));
242                                 if (++k2 >= 32) {
243                                     k2 = 0;
244                                     System.out.println();
245                                 }
246                             }
247                         }
248                         catch (IOException ioexception2) {
249                             logger.info("Decompress - error reading monochrome byte");
250                             return;
251                         }
252                         j3++;
253                         try {
254                             imageData[j1++] = (l1 & 0x40) == 0 ? byte5 : byte6;
255                             imageData[j1++] = (l1 & 0x20) == 0 ? byte5 : byte6;
256                             imageData[j1++] = (l1 & 0x10) == 0 ? byte5 : byte6;
257                             imageData[j1++] = (l1 & 8) == 0 ? byte5 : byte6;
258                             imageData[j1++] = (l1 & 4) == 0 ? byte5 : byte6;
259                             imageData[j1++] = (l1 & 2) == 0 ? byte5 : byte6;
260                             imageData[j1++] = (l1 & 1) == 0 ? byte5 : byte6;
261                         }
262                         catch (ArrayIndexOutOfBoundsException arrayindexoutofboundsexception3) {
263                             logger.info("imageDataIndex: " + j1);
264                             throw arrayindexoutofboundsexception3;
265                         }
266                     } while ((l1 & 0x80) != 0);
267                 flag4 = false;
268             }
269             if (j1 >= j + k) {
270                 if (j1 > j + k)
271                     logger.info("ERROR2: imageDataIndex = " + j1 + ", videoRamOffset = " + j + ", videoRamCount = " + k);
272                 if (pixelsInParts)
273                     memoryimagesource.newPixels(0, oldY, l - 1, i3 - oldY, false);
274                 break;
275             }
276             if (flag2) {
277                 imageData[j1++] = (byte)(l1 & 0x7f);
278                 flag2 = false;
279             }
280             if (j1 < j + k)
281                 continue;
282             if (j1 > j + k)
283                 logger.info("ERROR3: imageDataIndex = " + j1 + ", videoRamOffset = " + j + ", videoRamCount = " + k);
284             if (pixelsInParts)
285                 memoryimagesource.newPixels(0, oldY, l - 1, i3 - oldY, false);
286             break;
287         } while (true);
288     }
289
290 }