Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.PrintStream;
- import java.util.Arrays;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.nio.file.Path;
- public class interpretescript
- {
- private int[][] found = new int[4][1000];
- private int amount = 2;
- private int pos = 0x2AC094;
- static FileOutputStream write = null;
- static byte[] command = new byte[16];
- static byte[] file = new byte[0x4000000];
- public interpretescript()
- {
- }
- public void main() throws IOException
- {
- Path path = Paths.get("dead.z64");
- file = Files.readAllBytes(path);
- while(true){
- command = read(pos, 16);
- pos+=command[1];
- int backup = pos;
- boolean detect = false;
- switch(command[0]){
- case 0x00:
- pos = arraytoint(command, 0x04, 4);
- pos += arraytoint(command, 0x0D, 3);
- detect = true;
- break;
- case 0x07:
- break;
- case 0x22:
- build();
- return;
- }
- while(detect){
- command = read(pos, 16);
- pos+=command[1];
- switch(command[0]){
- case 0x17:
- case 0x1A:
- int temporary = arraytoint(command, 0x04,4);
- for (int k = 0; (k<(amount-2));k++){
- if (found[1][k]==(temporary)){
- found[3][amount] = 1;
- }
- }
- found[0][amount] = pos-0x0C;
- found[1][amount] = arraytoint(command, 0x04,4);
- found[2][amount] = arraytoint(command, 0x08,4);
- amount++;
- break;
- case 0x1D:
- detect = false;
- pos = backup;
- break;
- default:
- break;
- }
- }
- }
- }
- public byte[] read(int position, int amount) throws IOException{
- byte[] meth = new byte[40];
- for (int i=0; i<amount;i++){
- meth[i] = file[pos+i];
- }
- return (Arrays.copyOfRange(meth, 0, amount));
- }
- public int arraytoint (byte[] array, int start, int length){
- int returnvalue=0;
- for (int i =0; i<length; i++){
- returnvalue+= (array[start+i]&0xFF)*((int)Math.pow(256, length-1-i));
- }
- return returnvalue;
- }
- public void build()throws IOException{
- write = new FileOutputStream("fix.z64");
- pos = 0x2a6134;
- command = read(pos, 16);
- found[0][1] = pos;
- found[1][1] = arraytoint(command, 0x04,4);
- found[2][1] = arraytoint(command, 0x08,4);
- found[3][1] = 1;
- pos = 0x2a6260;
- command = read(pos, 16);
- found[0][0] = pos;
- found[1][0] = arraytoint(command, 0x04,4);
- found[2][0] = arraytoint(command, 0x08,4);
- int read = 0;
- for (int j =0;j<amount;j++){
- pos = found[0][j];
- int oldstart = arraytoint(file,pos+4,4);
- int start = (oldstart -oldstart%4);
- file[pos+4] = (byte) (start/(256*256*256));
- file[pos+5] = (byte) (start/(256*256));
- file[pos+6] = (byte) (start/(256));
- file[pos+7] = (byte) (start);
- int oldend = arraytoint(file,pos+8,4);
- int end = (oldend - oldend%4);
- file[pos+8] = (byte) (end/(256*256*256));
- file[pos+9] = (byte) (end/(256*256));
- file[pos+0xA] = (byte) (end/(256));
- file[pos+0xB] = (byte) (end);
- if (found [3][j] ==0){
- for (int temp = 0; (temp < (oldend-oldstart)); temp++){
- file[temp+start] = file[temp+oldstart];
- }
- }
- }
- write.write(file);
- write.flush();
- write.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement