HamsterWrench

Make games! Discuss those games here.

Moderators: Bob the Hamster, marionline, SDHawk

User avatar
Ichiro
Slime Knight
Posts: 238
Joined: Sat Sep 11, 2010 1:20 am
Location: john madden

HamsterWrench

Post by Ichiro »

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)
User avatar
Spoonweaver
Liquid Metal King Slime
Posts: 6466
Joined: Mon Dec 08, 2008 7:07 am
Contact:

Post by Spoonweaver »

Cool beans. I fully endorse this.
User avatar
Ichiro
Slime Knight
Posts: 238
Joined: Sat Sep 11, 2010 1:20 am
Location: john madden

Post by Ichiro »

If you have a Google account associated with your email. tell me if you want to be added to the list.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

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.
User avatar
Ichiro
Slime Knight
Posts: 238
Joined: Sat Sep 11, 2010 1:20 am
Location: john madden

Post by Ichiro »

I'll take a look at that, thank you
User avatar
Baconlabs
Liquid Metal Slime
Posts: 1067
Joined: Mon Nov 02, 2009 6:29 am
Location: Middlin, TN

Post by Baconlabs »

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.
Aww dang, I thought it was pretty cool when I first read about it.
User avatar
Ichiro
Slime Knight
Posts: 238
Joined: Sat Sep 11, 2010 1:20 am
Location: john madden

Post by Ichiro »

I'm making a little bit of progress. I just wrote an addition to the lump class that now makes it possible to find out what the lump elements are and how much space they take up.
User avatar
Ichiro
Slime Knight
Posts: 238
Joined: Sat Sep 11, 2010 1:20 am
Location: john madden

Post by Ichiro »

OK, something's going on with my lump reader methods. It reads fine until a certain point, then just starts producing If someone can look over my code and help me out, I'd appreciate it.
User avatar
Ichiro
Slime Knight
Posts: 238
Joined: Sat Sep 11, 2010 1:20 am
Location: john madden

Post by Ichiro »

I could use some help with the loader routine.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Can you post the lump reading code here?
User avatar
Ichiro
Slime Knight
Posts: 238
Joined: Sat Sep 11, 2010 1:20 am
Location: john madden

Post by Ichiro »

Code: Select all

package com.hamsterrepublic.hamsterwrench.data;

import java.io.*;

public final class Lump &#123;
	private File lumpFile;
	private File dir;
	public Lump&#40;String f&#41; throws FileNotFoundException&#123;
		lumpFile = new File&#40;f&#41;;
		if&#40;!lumpFile.isFile&#40;&#41;&#41;&#123;
			throw new FileNotFoundException&#40;&#41;;
		&#125;else&#123;
			System.out.println&#40;"file " + lumpFile.getAbsolutePath&#40;&#41; + " loaded, length " + lumpFile.length&#40;&#41; + " bytes."&#41;;
			dir = new File&#40;lumpFile.getParent&#40;&#41; + File.separatorChar + "RPGfiles"&#41;;
			dir.mkdir&#40;&#41;;
		&#125;
	&#125;

	public void readLumpStructure&#40;&#41;&#123;
		LumpReader lr = new LumpReader&#40;&#41;;
		System.out.println&#40;"Reading elements of lump..."&#41;;
		lr.getElementData&#40;&#41;;
		while &#40;!lr.eof&#41;&#123;
			System.out.println&#40;"Element " + lr.getName&#40;&#41; + ", size " + lr.getSize&#40;&#41;&#41;;
			lr.hop&#40;&#41;;
			lr.getElementData&#40;&#41;;
		&#125;
		System.out.println&#40;"done."&#41;;
		lr.destroy&#40;&#41;;
		lr = null;
	&#125;

	public void unlumpAll&#40;&#41;&#123;
		LumpReader lr = new LumpReader&#40;&#41;;
		System.out.println&#40;"Reading elements of lump..."&#41;;
		lr.getElementData&#40;&#41;;
		while &#40;!lr.eof&#41;&#123;
			System.out.print&#40;"Writing " + lr.getName&#40;&#41; + ", size " + lr.getSize&#40;&#41; + "..."&#41;;
			lr.dumpToFile&#40;&#41;;
			System.out.println&#40;"OK!"&#41;;
			lr.getElementData&#40;&#41;;
		&#125;
		System.out.println&#40;"done."&#41;;
		lr.destroy&#40;&#41;;
		lr = null;
	&#125;

	class LumpReader &#123;
		private String name = null;
		private long size = 0L;
		private FileReader fr;
		private BufferedReader br;
		private boolean readyForReading = false;
		private boolean eof = false;
		public LumpReader&#40;&#41;&#123;
			//Initializes the readers. 
			try &#123;
				fr = new FileReader&#40;lumpFile&#41;;
				br = new BufferedReader&#40;fr&#41;;
			&#125; catch &#40;FileNotFoundException e&#41; &#123;
				//If all goes correctly, we'll never reach this due to the FNFE throw in the outer class
				e.printStackTrace&#40;&#41;;
			&#125;
		&#125;

		//getters

		public boolean readable&#40;&#41;&#123;
			return readyForReading;
		&#125;
		public String getName&#40;&#41;&#123;
			return name;
		&#125;
		public long getSize&#40;&#41;&#123;
			return size;
		&#125;
		public boolean isEOF&#40;&#41;&#123;
			return eof;
		&#125;

		public void getElementData&#40;&#41;&#123;
			if&#40;!readyForReading&#41;&#123;
				StringBuilder s = new StringBuilder&#40;&#41;;
				int n;
				int&#91;&#93; l;
				l = new int&#91;4&#93;;

				try&#123;
					do&#123;
						n = br.read&#40;&#41;;
						if&#40;n != 0 && n != -1&#41;&#123;
							s.append&#40;&#40;char&#41; n&#41;;
						&#125;
					&#125;while&#40;n != 0 && n != -1&#41;;
					if&#40;n == -1&#41;&#123;
						eof = true;
					&#125;else&#123;
						name = s.toString&#40;&#41;;

						//PDP-endian to big-endian
						l&#91;1&#93; = br.read&#40;&#41;;
						l&#91;0&#93; = br.read&#40;&#41;;
						l&#91;3&#93; = br.read&#40;&#41;;
						l&#91;2&#93; = br.read&#40;&#41;;

						for &#40;int i = 0; i < l.length; i++&#41;
						&#123;
							size = &#40;size << 8&#41; + &#40;l&#91;i&#93;&#41;;
						&#125;
						readyForReading = true;
					&#125;
				&#125;catch&#40;Exception ex&#41;&#123;
					ex.printStackTrace&#40;&#41;;
				&#125;

			&#125;else&#123;
				System.err.println&#40;"The reader is in read data mode."&#41;;
			&#125;
		&#125;

		public void dumpToFile&#40;&#41;&#123;
			if&#40;readyForReading&#41;&#123;
				try&#123;
					FileWriter fw = new FileWriter&#40;dir.getAbsolutePath&#40;&#41; + File.separatorChar + name&#41;;
					for&#40;int i=0; i < size; i++&#41;&#123;
						fw.write&#40;br.read&#40;&#41;&#41;;
					&#125;
					fw.close&#40;&#41;;
					fw = null;
					name = null;
					size = 0L;
					readyForReading = false;
				&#125; catch &#40;IOException e&#41; &#123;
					e.printStackTrace&#40;&#41;;
				&#125;
			&#125;else&#123;
				System.err.println&#40;"The reader is currently in get element mode."&#41;;
			&#125;

		&#125;

		public void hop&#40;&#41;&#123;
			if &#40;readyForReading&#41;&#123;
				try &#123;
					br.skip&#40;size&#41;;
					name = null;
					size = 0L;
					readyForReading = false;
				&#125; catch &#40;IOException e&#41; &#123;
					e.printStackTrace&#40;&#41;;
				&#125;
			&#125;else&#123;
				System.err.println&#40;"The reader is currently in get element mode."&#41;;
			&#125;

		&#125;

		public void destroy&#40;&#41;&#123;
			try &#123;
				fr.close&#40;&#41;;
				br.close&#40;&#41;;
			&#125; catch &#40;IOException e&#41; &#123;
				e.printStackTrace&#40;&#41;;
			&#125;
		&#125;

	&#125;


&#125;
User avatar
Ichiro
Slime Knight
Posts: 238
Joined: Sat Sep 11, 2010 1:20 am
Location: john madden

Post by Ichiro »

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/
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

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!
mnoorani
Slime
Posts: 5
Joined: Sun Jun 19, 2011 10:30 am

Post by mnoorani »

Good luck!
User avatar
Ichiro
Slime Knight
Posts: 238
Joined: Sat Sep 11, 2010 1:20 am
Location: john madden

Post by Ichiro »

So the hero class is less cluttered now and I updated the constants.
Post Reply