Advertisement
KazeR4300i

VC compatibility?

Jan 29th, 2015
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. import java.io.FileInputStream;
  2. import java.io.FileOutputStream;
  3. import java.io.IOException;
  4. import java.io.PrintStream;
  5. import java.util.Arrays;
  6. import java.nio.file.Files;
  7. import java.nio.file.Paths;
  8. import java.nio.file.Path;
  9.  
  10. public class interpretescript
  11. {
  12. private int[][] found = new int[4][1000];
  13. private int amount = 2;
  14. private int pos = 0x2AC094;
  15. static FileOutputStream write = null;
  16. static byte[] command = new byte[16];
  17. static byte[] file = new byte[0x4000000];
  18. public interpretescript()
  19. {
  20. }
  21.  
  22. public void main() throws IOException
  23. {
  24. Path path = Paths.get("dead.z64");
  25. file = Files.readAllBytes(path);
  26. while(true){
  27. command = read(pos, 16);
  28. pos+=command[1];
  29. int backup = pos;
  30. boolean detect = false;
  31. switch(command[0]){
  32. case 0x00:
  33. pos = arraytoint(command, 0x04, 4);
  34. pos += arraytoint(command, 0x0D, 3);
  35. detect = true;
  36. break;
  37. case 0x07:
  38. break;
  39. case 0x22:
  40. build();
  41. return;
  42.  
  43. }
  44. while(detect){
  45. command = read(pos, 16);
  46. pos+=command[1];
  47. switch(command[0]){
  48. case 0x17:
  49. case 0x1A:
  50. int temporary = arraytoint(command, 0x04,4);
  51. for (int k = 0; (k<(amount-2));k++){
  52. if (found[1][k]==(temporary)){
  53. found[3][amount] = 1;
  54. }
  55. }
  56. found[0][amount] = pos-0x0C;
  57. found[1][amount] = arraytoint(command, 0x04,4);
  58. found[2][amount] = arraytoint(command, 0x08,4);
  59. amount++;
  60. break;
  61. case 0x1D:
  62. detect = false;
  63. pos = backup;
  64. break;
  65. default:
  66. break;
  67.  
  68. }
  69. }
  70. }
  71. }
  72.  
  73. public byte[] read(int position, int amount) throws IOException{
  74. byte[] meth = new byte[40];
  75. for (int i=0; i<amount;i++){
  76. meth[i] = file[pos+i];
  77. }
  78. return (Arrays.copyOfRange(meth, 0, amount));
  79. }
  80.  
  81. public int arraytoint (byte[] array, int start, int length){
  82. int returnvalue=0;
  83. for (int i =0; i<length; i++){
  84. returnvalue+= (array[start+i]&0xFF)*((int)Math.pow(256, length-1-i));
  85.  
  86. }
  87. return returnvalue;
  88. }
  89.  
  90. public void build()throws IOException{
  91. write = new FileOutputStream("fix.z64");
  92. pos = 0x2a6134;
  93. command = read(pos, 16);
  94. found[0][1] = pos;
  95. found[1][1] = arraytoint(command, 0x04,4);
  96. found[2][1] = arraytoint(command, 0x08,4);
  97. found[3][1] = 1;
  98. pos = 0x2a6260;
  99. command = read(pos, 16);
  100. found[0][0] = pos;
  101. found[1][0] = arraytoint(command, 0x04,4);
  102. found[2][0] = arraytoint(command, 0x08,4);
  103. int read = 0;
  104. for (int j =0;j<amount;j++){
  105. pos = found[0][j];
  106. int oldstart = arraytoint(file,pos+4,4);
  107. int start = (oldstart -oldstart%4);
  108. file[pos+4] = (byte) (start/(256*256*256));
  109. file[pos+5] = (byte) (start/(256*256));
  110. file[pos+6] = (byte) (start/(256));
  111. file[pos+7] = (byte) (start);
  112. int oldend = arraytoint(file,pos+8,4);
  113. int end = (oldend - oldend%4);
  114. file[pos+8] = (byte) (end/(256*256*256));
  115. file[pos+9] = (byte) (end/(256*256));
  116. file[pos+0xA] = (byte) (end/(256));
  117. file[pos+0xB] = (byte) (end);
  118. if (found [3][j] ==0){
  119. for (int temp = 0; (temp < (oldend-oldstart)); temp++){
  120. file[temp+start] = file[temp+oldstart];
  121. }
  122. }
  123. }
  124. write.write(file);
  125. write.flush();
  126. write.close();
  127.  
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement