HamsterWrench
Moderators: Bob the Hamster, marionline, SDHawk
HamsterWrench
OK, this may seem a little overambitious, but I am planning work on a set of Java-based tools to work with RPG files. I envision it being an alternative to CUSTOM when it's good enough.
Here's where it lies right now:
http://code.google.com/p/hamsterwrench/
(if it looks a little spartan, that's because I just started coding today)
Here's where it lies right now:
http://code.google.com/p/hamsterwrench/
(if it looks a little spartan, that's because I just started coding today)
- Spoonweaver
- Liquid Metal King Slime
- Posts: 6467
- Joined: Mon Dec 08, 2008 7:07 am
- Contact:
- Bob the Hamster
- Lord of the Slimes
- Posts: 7660
- Joined: Tue Oct 16, 2007 2:34 pm
- Location: Hamster Republic (Ontario Enclave)
- Contact:
Have you looked at the <a href="https://code.google.com/p/ohrrpgce-fmf/">OHRRPGCE FMF</a> project? It has been discontinued, but it is written in Java, and it might have some code that you could re-use.
Aww dang, I thought it was pretty cool when I first read about it.James Paige wrote:Have you looked at the <a href="https://code.google.com/p/ohrrpgce-fmf/">OHRRPGCE FMF</a> project? It has been discontinued, but it is written in Java, and it might have some code that you could re-use.
- Bob the Hamster
- Lord of the Slimes
- Posts: 7660
- Joined: Tue Oct 16, 2007 2:34 pm
- Location: Hamster Republic (Ontario Enclave)
- Contact:
Code: Select all
package com.hamsterrepublic.hamsterwrench.data;
import java.io.*;
public final class Lump {
private File lumpFile;
private File dir;
public Lump(String f) throws FileNotFoundException{
lumpFile = new File(f);
if(!lumpFile.isFile()){
throw new FileNotFoundException();
}else{
System.out.println("file " + lumpFile.getAbsolutePath() + " loaded, length " + lumpFile.length() + " bytes.");
dir = new File(lumpFile.getParent() + File.separatorChar + "RPGfiles");
dir.mkdir();
}
}
public void readLumpStructure(){
LumpReader lr = new LumpReader();
System.out.println("Reading elements of lump...");
lr.getElementData();
while (!lr.eof){
System.out.println("Element " + lr.getName() + ", size " + lr.getSize());
lr.hop();
lr.getElementData();
}
System.out.println("done.");
lr.destroy();
lr = null;
}
public void unlumpAll(){
LumpReader lr = new LumpReader();
System.out.println("Reading elements of lump...");
lr.getElementData();
while (!lr.eof){
System.out.print("Writing " + lr.getName() + ", size " + lr.getSize() + "...");
lr.dumpToFile();
System.out.println("OK!");
lr.getElementData();
}
System.out.println("done.");
lr.destroy();
lr = null;
}
class LumpReader {
private String name = null;
private long size = 0L;
private FileReader fr;
private BufferedReader br;
private boolean readyForReading = false;
private boolean eof = false;
public LumpReader(){
//Initializes the readers.
try {
fr = new FileReader(lumpFile);
br = new BufferedReader(fr);
} catch (FileNotFoundException e) {
//If all goes correctly, we'll never reach this due to the FNFE throw in the outer class
e.printStackTrace();
}
}
//getters
public boolean readable(){
return readyForReading;
}
public String getName(){
return name;
}
public long getSize(){
return size;
}
public boolean isEOF(){
return eof;
}
public void getElementData(){
if(!readyForReading){
StringBuilder s = new StringBuilder();
int n;
int[] l;
l = new int[4];
try{
do{
n = br.read();
if(n != 0 && n != -1){
s.append((char) n);
}
}while(n != 0 && n != -1);
if(n == -1){
eof = true;
}else{
name = s.toString();
//PDP-endian to big-endian
l[1] = br.read();
l[0] = br.read();
l[3] = br.read();
l[2] = br.read();
for (int i = 0; i < l.length; i++)
{
size = (size << 8) + (l[i]);
}
readyForReading = true;
}
}catch(Exception ex){
ex.printStackTrace();
}
}else{
System.err.println("The reader is in read data mode.");
}
}
public void dumpToFile(){
if(readyForReading){
try{
FileWriter fw = new FileWriter(dir.getAbsolutePath() + File.separatorChar + name);
for(int i=0; i < size; i++){
fw.write(br.read());
}
fw.close();
fw = null;
name = null;
size = 0L;
readyForReading = false;
} catch (IOException e) {
e.printStackTrace();
}
}else{
System.err.println("The reader is currently in get element mode.");
}
}
public void hop(){
if (readyForReading){
try {
br.skip(size);
name = null;
size = 0L;
readyForReading = false;
} catch (IOException e) {
e.printStackTrace();
}
}else{
System.err.println("The reader is currently in get element mode.");
}
}
public void destroy(){
try {
fr.close();
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Hi.
Sorry to be a thread neck romancer, but I'm still working on this project and I've got the lump extractor working!
As always, you can see my work (and even help if you want) at: http://code.google.com/p/hamsterwrench/
Sorry to be a thread neck romancer, but I'm still working on this project and I've got the lump extractor working!
As always, you can see my work (and even help if you want) at: http://code.google.com/p/hamsterwrench/
Great to hear you finally figured out the problem. I tried reading your lump extraction code, but aside from having written a decent poker bot in Java once (they made it so dang hard to use any other language!), I don't know the first thing about Java. I can't even figure how to properly compile anymore.
Best of luck!
Best of luck!