Advertisement
Suyo

PROJECT DIVA CUSTOM DLC SLOT CHANGER v0.15

Feb 21st, 2012
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.27 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.DataOutputStream;
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7. import java.io.InputStreamReader;
  8.  
  9. /* This program is free software. It comes without any warranty, to
  10.  * the extent permitted by applicable law. You can redistribute it
  11.  * and/or modify it under the terms of the Do What The Fuck You Want
  12.  * To Public License, Version 2, as published by Sam Hocevar. See
  13.  * http://sam.zoy.org/wtfpl/COPYING for more details. */
  14.  
  15. public class SlotChanger {
  16.  
  17.     /**
  18.      * @param args
  19.      */
  20.     public static void main(String[] args) {
  21.         System.out.println("### PROJECT DIVA CUSTOM DLC SLOT CHANGER v0.15");
  22.         System.out.println("Written by Suyo (ProjectDIVA.net)");
  23.         System.out.println("----------------------------------------");
  24.        
  25.         FileInputStream fis;
  26.         String ifilen = "in.EDAT";
  27.         if (args[0] != null) ifilen = args[0];
  28.         String ofilen = "out.EDAT";
  29.         File ifile = new File(ifilen);
  30.         File ofile = new File(ofilen);
  31.        
  32.         if (!ifile.exists() || !ifile.isFile()) {
  33.             System.out.println(ifilen+": does not exist!");
  34.             return;
  35.         }
  36.         if (ofile.exists()) {
  37.             System.out.println(ofilen+": exists already! Please rename it before running this!");
  38.             return;
  39.         }
  40.        
  41.         int[] fileArray;
  42.         try {
  43.             System.out.println("Opening "+ifilen+"...");
  44.             fis = new FileInputStream(ifile);
  45.             fileArray = new int[(int) ifile.length()];
  46.          
  47.             int i=0;
  48.             int offs=0;
  49.          
  50.             System.out.println("Reading file... this could take a while.");
  51.             while(i != -1) { /* -1 is a constant for 'EOF' : end of file. */
  52.                 i=fis.read();
  53.                 if (i!=-1) fileArray[offs] = i;
  54.                 offs++;
  55.             }
  56.             fis.close();
  57.         } catch (Exception e) {
  58.             System.out.println(ifilen+": Unknown error while opening!");
  59.             return;
  60.         }
  61.        
  62.         System.out.println("\nDLC Type: "+((char) fileArray[0x1800]));
  63.         System.out.println("Current Slot: "+((char) fileArray[0x1803])+((char) fileArray[0x1804])+((char) fileArray[0x1805]));
  64.        
  65.         System.out.print("Enter new Slot (0-999): ");
  66.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  67.         String newslot = null;
  68.         try {
  69.             newslot = br.readLine();
  70.         } catch (IOException ioe) {
  71.             System.out.println("IO error trying to read new slot!");
  72.             return;
  73.         }
  74.        
  75.         try {
  76.             int i = Integer.parseInt(newslot);
  77.             if (i>999) {
  78.                 System.out.println("The number is too big!");
  79.                 return;
  80.             } else if (i<0) {
  81.                 System.out.println("The number is too small!");
  82.                 return;
  83.             }
  84.         } catch(NumberFormatException nfe) {
  85.             System.out.println("This isn't a number!");
  86.             return;
  87.         }
  88.          
  89.         while (newslot.length()<3) newslot = "0" + newslot;
  90.         fileArray[0x1803] = newslot.charAt(0);
  91.         fileArray[0x1804] = newslot.charAt(1);
  92.         fileArray[0x1805] = newslot.charAt(2);
  93.        
  94.         try {
  95.             System.out.println("\nOpening "+ofilen+"...");
  96.             FileOutputStream fos = new FileOutputStream(ofile);
  97.             DataOutputStream dos = new DataOutputStream(fos);
  98.             System.out.println("Writing file... this could take a while.");
  99.             for (int i: fileArray) {
  100.                 dos.writeByte(i);
  101.             }
  102.             dos.close();
  103.         } catch (Exception e) {
  104.             System.out.println(ofilen+": Unknown Error while writing!");
  105.         }
  106.        
  107.         System.out.println("\nSuccess! We're done here.");
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement