Created
June 2, 2015 17:13
-
-
Save theresajayne/95ac217525873af874f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.github.theresajayne.ovlreader; | |
| import java.io.*; | |
| import java.nio.ByteBuffer; | |
| /** | |
| * Created by Theresa on 02/06/2015. | |
| */ | |
| public class OvlReader { | |
| public static void main(String[] args) throws IOException { | |
| OvlReader ovlReader = new OvlReader(); | |
| ovlReader.open("d:/MilkyWay.ovl"); | |
| } | |
| private void open(String s) throws IOException { | |
| File input = new File(s); | |
| if (!input.exists()) { | |
| System.out.println("File not found."); | |
| System.exit(0); | |
| } | |
| byte[] buf = new byte[(int) input.length()]; | |
| FileInputStream fis = new FileInputStream(input); | |
| fis.read(buf, 0, (int) input.length()); | |
| ByteBuffer byteBuffer = ByteBuffer.wrap(buf); | |
| //We should now have a bytebuffer containing the file. | |
| //Milkyway has an offset to the directory of 0x90 | |
| //Factions also offset 0x90 | |
| //Starsystems also. so we can assume that there may be no "offset" for the start of the directory. | |
| //Zlib offset in the files is as follows | |
| //Milkyway 0x0000037c | |
| //Factions 0x0000023c | |
| //Starsystems 0x0001ABB0 | |
| // So try to find the offset to there | |
| //word STATIC is at 01e8 in Factions 54 bytes from zlib | |
| //Starsystems 0x001AB5C (54 bytes from zlib) | |
| //MilkyWay 0x0000310 (6C bytes from zlib) | |
| //Read in the directory | |
| readDirectory(byteBuffer); | |
| } | |
| private void readDirectory(ByteBuffer buffer) { | |
| buffer.position(0x90); | |
| byte a; | |
| boolean lastnull = false; | |
| while (true) { | |
| a = buffer.get(); | |
| if (a == 0x00 && lastnull) { | |
| break; | |
| } | |
| if (lastnull) { | |
| //end of string so put CR | |
| System.out.println(""); | |
| lastnull = false; | |
| } | |
| if (a == 0x00) { | |
| lastnull = true; | |
| } else { | |
| System.out.print((char) a); | |
| } | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment