Guest User

Untitled

a guest
Jan 25th, 2013
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.82 KB | None | 0 0
  1. package sign;
  2.  
  3. import java.applet.Applet;
  4. import java.io.*;
  5. import java.net.*;
  6. import javax.sound.midi.*;
  7. import javax.sound.sampled.*;
  8.  
  9. public final class signlink implements Runnable {
  10.  
  11. public static void startpriv(InetAddress inetaddress) {
  12. threadliveid = (int)(Math.random() * 99999999D);
  13. if(active) {
  14. try {
  15. Thread.sleep(500L);
  16. }
  17. catch(Exception _ex) { }
  18. active = false;
  19. }
  20. socketreq = 0;
  21. threadreq = null;
  22. dnsreq = null;
  23. savereq = null;
  24. urlreq = null;
  25. socketip = inetaddress;
  26. Thread thread = new Thread(new signlink());
  27. thread.setDaemon(true);
  28. thread.start();
  29. while(!active)
  30. try {
  31. Thread.sleep(50L);
  32. } catch(Exception _ex) {
  33. }
  34. }
  35.  
  36. public void run() {
  37. active = true;
  38. String s = findcachedir();
  39. uid = getuid(s);
  40. try {
  41. File file = new File(s + "main_file_cache.dat");
  42. if(file.exists() && file.length() > 0x3200000L) {
  43. file.delete();
  44. System.out.println("Deleted main_file_cache.dat, file.length() == " + file.length());
  45. }
  46. cache_dat = new RandomAccessFile(s + "main_file_cache.dat", "rw");
  47. for(int j = 0; j < 5; j++) {
  48. cache_idx[j] = new RandomAccessFile(s + "main_file_cache.idx" + j, "rw");
  49. }
  50.  
  51. } catch(Exception exception) {
  52. exception.printStackTrace();
  53. }
  54. for(int i = threadliveid; threadliveid == i;) {
  55. if(socketreq != 0) {
  56. try {
  57. socket = new Socket(socketip, socketreq);
  58. } catch(Exception _ex) {
  59. socket = null;
  60. }
  61. socketreq = 0;
  62. } else if(threadreq != null) {
  63. Thread thread = new Thread(threadreq);
  64. thread.setDaemon(true);
  65. thread.start();
  66. thread.setPriority(threadreqpri);
  67. threadreq = null;
  68. } else if(dnsreq != null) {
  69. try {
  70. dns = InetAddress.getByName(dnsreq).getHostName();
  71. } catch(Exception _ex) {
  72. dns = "unknown";
  73. }
  74. dnsreq = null;
  75. } else if(savereq != null) {
  76. if(savebuf != null)
  77. try {
  78. FileOutputStream fileoutputstream = new FileOutputStream(s + savereq);
  79. fileoutputstream.write(savebuf, 0, savelen);
  80. fileoutputstream.close();
  81. } catch(Exception _ex) {
  82. }
  83. if(waveplay) {
  84. String wave = s + savereq;
  85. waveplay = false;
  86. //System.out.println("WAVE "+wave);
  87. AudioInputStream audioInputStream = null;
  88. try {
  89. audioInputStream = AudioSystem.getAudioInputStream(new File(wave/*soundFile*/));
  90. } catch (UnsupportedAudioFileException e1) {
  91. e1.printStackTrace();
  92. return;
  93. } catch (IOException e1) {
  94. e1.printStackTrace();
  95. return;
  96. }
  97. AudioFormat format = audioInputStream.getFormat();
  98. SourceDataLine auline = null;
  99. DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
  100. try {
  101. auline = (SourceDataLine) AudioSystem.getLine(info);
  102. auline.open(format);
  103. } catch (LineUnavailableException e) {
  104. e.printStackTrace();
  105. return;
  106. } catch (Exception e) {
  107. e.printStackTrace();
  108. return;
  109. }
  110. if (auline.isControlSupported(FloatControl.Type.PAN)) {
  111. FloatControl pan = (FloatControl) auline.getControl(FloatControl.Type.PAN);
  112. if (curPosition == Position.RIGHT)
  113. pan.setValue(1.0f);
  114. else if (curPosition == Position.LEFT)
  115. pan.setValue(-1.0f);
  116. }
  117. auline.start();
  118. int nBytesRead = 0;
  119. byte[] abData = new byte[EXTERNAL_BUFFER_SIZE];
  120. try {
  121. while (nBytesRead != -1) {
  122. nBytesRead = audioInputStream.read(abData, 0, abData.length);
  123. if (nBytesRead >= 0)
  124. auline.write(abData, 0, nBytesRead);
  125. }
  126. } catch (IOException e) {
  127. e.printStackTrace();
  128. return;
  129. } finally {
  130. auline.drain();
  131. auline.close();
  132. }
  133. }
  134. if(midiplay) {
  135. midi = s + savereq;
  136. try {
  137. if (musicSr != null) {
  138. musicSr.stop();
  139. musicSr.close();
  140. }
  141. musicSr = null;
  142. musicS = null;
  143. File music = new File(midi);
  144. if(music.exists()) {
  145. musicS = MidiSystem.getSequence(music);
  146. }
  147. } catch (Exception ex) {
  148. ex.printStackTrace();
  149. }
  150. midiplay = false;
  151. }
  152. savereq = null;
  153. } else if(urlreq != null) {
  154. try {
  155. System.out.println("urlstream");
  156. urlstream = new DataInputStream((new URL(mainapp.getCodeBase(), urlreq)).openStream());
  157. } catch(Exception _ex) {
  158. urlstream = null;
  159. }
  160. urlreq = null;
  161. }
  162. try {
  163. Thread.sleep(50L);
  164. } catch(Exception _ex) {
  165. }
  166. }
  167.  
  168. }
  169.  
  170. public static String findcachedirorig() {
  171. String locations[] = {
  172. "c:/windows/", "c:/WINDOWS/", "c:/winnt/", "d:/windows/", "d:/winnt/", "e:/windows/", "e:/winnt/", "f:/windows/", "f:/winnt/", "c:/", "~/",
  173. "/tmp/", "", "c:/rscache", "/rscache"
  174. };
  175. String cacheFolder = ".runecreation";
  176. for (int i = 0; i < locations.length; i++) {
  177. try {
  178. String location = locations[i];
  179. if (location.length() > 0) {
  180. File file = new File(location);
  181. if (!file.exists())
  182. continue;
  183. }
  184. File finalDirectory = new File(location + cacheFolder);
  185. if (finalDirectory.exists() || finalDirectory.mkdir())
  186. return location + cacheFolder + System.getProperty("file.separator");
  187. } catch (Exception _ex) {
  188. }
  189. }
  190. return System.getProperty("user.home") + System.getProperty("file.separator") + cacheFolder + System.getProperty("file.separator");
  191. }
  192.  
  193. public static String findcachedirdl() {
  194. return "." + System.getProperty("file.separator") + "cache" + System.getProperty("file.separator");
  195. }
  196.  
  197. public static String findcachedir() {
  198. File file = new File(System.getProperty("user.home") + System.getProperty("file.separator") + ".galkon_runelimited" + System.getProperty("file.separator"));
  199. if (!file.exists()) {
  200. if (!file.mkdir())
  201. return secondDir();
  202. }
  203. return System.getProperty("user.home") + System.getProperty("file.separator") + ".galkon_runelimited" + System.getProperty("file.separator");
  204. }
  205.  
  206. public static String secondDir() {
  207. File file = new File("c:/.galkon_runelimited/");
  208. if (!file.exists())
  209. file.mkdir();
  210. return file.toString();
  211. }
  212.  
  213. private static int getuid(String s) {
  214. try {
  215. File file = new File(s + "uid.dat");
  216. if(!file.exists() || file.length() < 4L) {
  217. DataOutputStream dataoutputstream = new DataOutputStream(new FileOutputStream(s + "uid.dat"));
  218. dataoutputstream.writeInt((int)(Math.random() * 99999999D));
  219. dataoutputstream.close();
  220. }
  221. } catch(Exception _ex) {
  222. }
  223. try {
  224. DataInputStream datainputstream = new DataInputStream(new FileInputStream(s + "uid.dat"));
  225. int i = datainputstream.readInt();
  226. datainputstream.close();
  227. return i + 1;
  228. } catch(Exception _ex) {
  229. return 0;
  230. }
  231. }
  232.  
  233. public static synchronized Socket opensocket(int i) throws IOException {
  234. for(socketreq = i; socketreq != 0;)
  235. try {
  236. Thread.sleep(50L);
  237. }
  238. catch(Exception _ex) { }
  239.  
  240. if(socket == null)
  241. throw new IOException("could not open socket");
  242. else
  243. return socket;
  244. }
  245.  
  246. public static synchronized DataInputStream openurl(String s) throws IOException {
  247. for(urlreq = s; urlreq != null;)
  248. try {
  249. Thread.sleep(50L);
  250. } catch(Exception _ex) {
  251. }
  252. if(urlstream == null)
  253. throw new IOException("could not open: " + s);
  254. else
  255. return urlstream;
  256. }
  257.  
  258. public static synchronized void dnslookup(String s) {
  259. dns = s;
  260. dnsreq = s;
  261. }
  262.  
  263. public static synchronized void startthread(Runnable runnable, int i) {
  264. threadreqpri = i;
  265. threadreq = runnable;
  266. }
  267.  
  268. public static synchronized boolean wavesave(byte abyte0[], int i) {
  269. if(i > 0x1e8480)
  270. return false;
  271. if(savereq != null)
  272. {
  273. return false;
  274. } else {
  275. wavepos = (wavepos + 1) % 5;
  276. savelen = i;
  277. savebuf = abyte0;
  278. waveplay = true;
  279. savereq = "sound" + wavepos + ".wav";
  280. return true;
  281. }
  282. }
  283.  
  284. public static synchronized boolean wavereplay() {
  285. if(savereq != null) {
  286. return false;
  287. } else {
  288. savebuf = null;
  289. waveplay = true;
  290. savereq = "sound" + wavepos + ".wav";
  291. return true;
  292. }
  293. }
  294.  
  295. public static synchronized void midisave(byte abyte0[], int i) {
  296. if(i > 0x1e8480)
  297. return;
  298. if(savereq != null) {
  299. } else {
  300. midipos = (midipos + 1) % 5;
  301. savelen = i;
  302. savebuf = abyte0;
  303. midiplay = true;
  304. savereq = "jingle" + midipos + ".mid";
  305. }
  306. }
  307.  
  308. public static void reporterror(String s) {
  309. System.out.println("Error: " + s);
  310. }
  311.  
  312. private signlink() {
  313. }
  314.  
  315. enum Position {
  316. LEFT, RIGHT, NORMAL
  317. };
  318. private Position curPosition;
  319. private final int EXTERNAL_BUFFER_SIZE = 524288; // 128Kb
  320. public static final int clientversion = 317;
  321. public static int uid;
  322. public static int storeid = 32;
  323. public static RandomAccessFile cache_dat = null;
  324. public static final RandomAccessFile[] cache_idx = new RandomAccessFile[5];
  325. public static boolean sunjava;
  326. public static Applet mainapp = null;
  327. private static boolean active;
  328. private static int threadliveid;
  329. private static InetAddress socketip;
  330. private static int socketreq;
  331. private static Socket socket = null;
  332. private static int threadreqpri = 1;
  333. private static Runnable threadreq = null;
  334. private static String dnsreq = null;
  335. public static String dns = null;
  336. private static String urlreq = null;
  337. private static DataInputStream urlstream = null;
  338. private static int savelen;
  339. private static String savereq = null;
  340. private static byte[] savebuf = null;
  341. private static boolean midiplay;
  342. private static int midipos;
  343. public static String midi = null;
  344. public static int midivol;
  345. public static int midifade;
  346. private static boolean waveplay;
  347. private static int wavepos;
  348. public static int wavevol;
  349. public static boolean reporterror = true;
  350. public static String errorname = "";
  351. Sequencer musicSr = null;
  352. Sequence musicS = null;
  353.  
  354. }
Advertisement
Add Comment
Please, Sign In to add comment