Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Custom resource caching?  (Read 764 times)
0 Members and 1 Guest are viewing this topic.
Offline GabrielBailey74
« Posted 2013-10-17 03:14:19 »

Hey JGO, I was wondering if there's already a useful library out there that can pack my resources into a .dat file or something?

Example project layout:
  • src
  • cache/icons.dat

Than in my project I'd be able to call something like:
1  
2  
3  
4  
5  
6  
7  
8  
static StreamSystem streamSystem = new StreamSystem("cache/");

static void load() {
   Image shopIcon = streamSystem.getImage(
      "icons.dat", // resources packed into .dat
     "ShopIcon.PNG" // our image to load
  );
}

Thanks for the feedback guys ^_^

Offline xsvenson
« Reply #1 - Posted 2013-10-17 10:23:08 »

Yes, .jar files.
What are You trying to do? Image atlas ?  Or something else ?

“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #2 - Posted 2013-10-17 18:46:33 »

You can use the built-in zip file api in the standard java api and rename the .zip file to .dat Smiley

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline GabrielBailey74
« Reply #3 - Posted 2013-10-18 04:10:29 »

Yes, .jar files.
What are You trying to do? Image atlas ?  Or something else ?
I mainly don't want my resources 'bluntly' out in the open Cheesy
Now I know I can't fully stop people from grabbing/editing the resources but I'd like to remove the 'bluntly' part and possibly store everything in "Cache files" ^_^ (.dat etc)

You can use the built-in zip file api in the standard java api and rename the .zip file to .dat Smiley
Never thought of that Tongue
Wouldn't they just need to rename the .dat to .zip though? XD

I'll fiddle around with some ideas tonight in my IDE ^_^

EDIT:
How would I 'casually' go about storing a .png in a .dat file (Encoded, see below)
Beautiful charset output: 3cÿrBR·ÒçÓW~ò$ãÔ€ä5Al½ô

Feedback's still welcome guys =D

Offline Jeremy
« Reply #4 - Posted 2013-10-18 04:58:32 »

Yes, .jar files.
What are You trying to do? Image atlas ?  Or something else ?
I mainly don't want my resources 'bluntly' out in the open Cheesy
Now I know I can't fully stop people from grabbing/editing the resources but I'd like to remove the 'bluntly' part and possibly store everything in "Cache files" ^_^ (.dat etc)

You can use the built-in zip file api in the standard java api and rename the .zip file to .dat Smiley
Never thought of that Tongue
Wouldn't they just need to rename the .dat to .zip though? XD

I'll fiddle around with some ideas tonight in my IDE ^_^

EDIT:
How would I 'casually' go about storing a .png in a .dat file (Encoded, see below)
Beautiful charset output: 3cÿrBR·ÒçÓW~ò$ãÔ€ä5Al½ô

Feedback's still welcome guys =D

I really advice against doing this because it is much more trouble than it is worth, but you can do something _really_ simple, like this:

1. Compress your resources (loosely) into a ZIP archive
2. Apply a simple encryption algorithm (really simple, since the purpose here isn't to 'keep them out' so much as it is to making it not so blunt to acquire access to the resources. Also, the encryption algorithm is entirely local so there isn't much in the way of someone tearing apart your usage of the Java encryption API and grabbing the key if they really wanted it anyway...) So (in this example) XOR encryption.
3. Decorate a FileInputStream (to the Zip Archive containing your resources) with an XorDecryptionInputStream (basically just applies an XOR to every byte you read from the stream to decrypt it. A simple one byte key is entirely sufficient for these purposes) and pass that to the ZipInputStream
5. Use the ZipInputStream as you would.

XOR encryption isn't that great, and there are flaws (you have to avoid NULL bytes etc) but assuming you just want to make the archive unreadable\unrepairable, it should work fine for your purposes.

Also, with XOR Encryption

Original XOR Key  = Encrypted

But

Original XOR Encrypted = Key.

So if they know what the data is supposed to be, your key is exposed. And they can figure out some signature in a Zip Archives Filesystem.

But all that is besides the fact, since security isn't an issue here.

JevaEngine, Latest Playthrough (This demo is networked with a centralized server model)

http://www.youtube.com/watch?v=rWA8bajpVXg
Offline GabrielBailey74
« Reply #5 - Posted 2013-10-18 05:07:14 »

This idea in its rawest form is:
Export a .png to a .txt file.
Encode / encrypt the .txt file.
Change the format to from .txt to .dat.

Apply a simple encryption algorithm.

How would I go about doing that?
1  
2  
3  
// get .png
// pack .png into .zip
// I'm now lost.

Sorry, maybe I should've stated my progress / familiarity with encryption / decryption + exporting haha.

The most I've done:
DES Cipher encryption / decryption of strings.
Exporting a images pixels to a .txt file with encryption applied.
Importing a image via encrypted pixels.

Thanks for the feedback ^_^

Offline GabrielBailey74
« Reply #6 - Posted 2013-10-18 07:01:03 »

1. Compress your resources (loosely) into a ZIP archive
2. Apply a simple encryption algorithm (really simple, since the purpose here isn't to 'keep them out' so much as it is to making it not so blunt to acquire access to the resources. Also, the encryption algorithm is entirely local so there isn't much in the way of someone tearing apart your usage of the Java encryption API and grabbing the key if they really wanted it anyway...) So (in this example) XOR encryption.
3. Decorate a FileInputStream (to the Zip Archive containing your resources) with an XorDecryptionInputStream (basically just applies an XOR to every byte you read from the stream to decrypt it. A simple one byte key is entirely sufficient for these purposes) and pass that to the ZipInputStream
5. Use the ZipInputStream as you would.

Thanks mate ^_^

I made a program that:
Takes the resource (.png) than imports the raw .png data for encryption prior to exporting it into the cache.dat file ^_^

Next thing I need to think about is how to retrieve a certain object in the .dat cache file, should I use resource headers?
(The headers will be encrypted also ^_^)

Here is the cache.dat file contents (pseudo):
Quote
<!-- ShopIcon.png --!>
ENCRYPTED DATA HERE

<!-- AttackIcon.png --!>
ENCRYPTED DATA HERE

Note:
Since I can't post the encrypted data on the text area on JGO and successfully click post, here are the links ^_^
I'm happy with the output, there's no tenfold on the encryption files size.

Old encryption output for 87kb png: 500KB.
New encryption output for 87kb png: same size.

Raw imported PNG data: http://pastebin.com/jyZ8VuuC
Encrypted PNG data: http://pastebin.com/L7fLrSD7
Source code: http://pastebin.java-gaming.org/ab4d1673771

Offline Roquen
« Reply #7 - Posted 2013-10-18 09:29:14 »

Simply using a non-standard file extension is going to cut out most people.  You could always not include the first few header bytes (which makes the format obvious) and that would knock out a bunch more.  You're now down to programmers than can be bothered to decompile your code...which no matter what you do they can walk around.

If you want to kick-it-up to the next level I'd suggest using a 7zip like compression library...at least that way you get something productive (better compression ratios).

Encrypting is simply a waste of your & the CPUs time and doesn't reduce the number of people that get to your data, so don't bother.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (20 views)
2014-07-29 18:09:19

Riven (13 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (31 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (28 views)
2014-07-23 21:07:15

Riven (29 views)
2014-07-23 20:56:16

ctomni231 (60 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!