RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.fs.cache.FileSystem Class Reference

Represents a file system of Caches and Archives. More...

Collaboration diagram for com.runehive.fs.cache.FileSystem:

Public Member Functions

Archive getArchive (int id)
 Gets an Archive for the specified id, this method fails-fast if no archive can be found.
ByteBuffer getArchiveHashes () throws IOException
 Returns the cached archiveHashes if they exist, otherwise they are calculated and cached for future use.
Cache getCache (int id)
 Gets a Cache for the specified id, this method fails-fast if no cache can be found.
ByteBuffer getFile (int cacheId, int indexId) throws IOException
 Returns a ByteBuffer of file data for the specified index within the specified Cache.

Static Public Member Functions

static FileSystem create (String directory) throws IOException
 Constructs and initializes a FileSystem from the specified
directory
.

Static Public Attributes

static final int ANIMATION_INDEX = 2
 Represents the id of the animations cache.
static final int CONFIG_ARCHIVE = 2
 Represents the id of the configurations archive.
static final int CONFIG_INDEX = 0
 Represents the id of the configurations cache.
static final int INTERFACE_ARCHIVE = 3
 Represents the id of the interface archive.
static final int MANIFEST_ARCHIVE = 5
 Represents the id of the manifest archive.
static final int MAP_INDEX = 4
 Represents the id of the tool.mapviewer and landscape cache.
static final int MEDIA_ARCHIVE = 4
 Represents the id of the media and sprite archive.
static final int MIDI_INDEX = 3
 Represents the id of the sounds and music cache.
static final int MODEL_INDEX = 1
 Represents the id of the model cache.
static final int SOUND_ARCHIVE = 8
 Represents the id of the sound and music archive.
static final int TEXTURES_ARCHIVE = 6
 Represents the id of the textures archive.
static final int TITLE_ARCHIVE = 1
 Represents the id of the title screen archive.
static final int WORD_ARCHIVE = 7
 Represents the id of the word archive - user for storing profane or illegal words not allowed to be spoken in-game.

Private Member Functions

 FileSystem (Cache[] caches, Archive[] archives)
 Constructs a new FileSystem with the specified Caches and Archives.

Private Attributes

ByteBuffer archiveHashes
 The cached archive hashes.
final Archive[] archives
 All of the Archives within this FileSystem.
final Cache[] caches
 All of the Caches within this FileSystem.

Static Private Attributes

static final String DATA_PREFIX = "main_file_cache.dat"
 Represents the prefix of this FileSystems main cache files.
static final String INDEX_PREFIX = "main_file_cache.idx"
 Represents the prefix of this FileSystems index files.
static final int MAXIMUM_ARCHIVES = 9
 Represents the maximum amount of archives within this file system.
static final int MAXIMUM_INDICES = 256
 Represents the maximum amount of indices within this file system.

Detailed Description

Represents a file system of Caches and Archives.

Author
Ryley Kimmel ryley.nosp@m..kim.nosp@m.mel@l.nosp@m.ive..nosp@m.com
Artem Batutin artem.nosp@m.batu.nosp@m.tin@g.nosp@m.mail.nosp@m..com

Definition at line 24 of file FileSystem.java.

Constructor & Destructor Documentation

◆ FileSystem()

com.runehive.fs.cache.FileSystem.FileSystem ( Cache[] caches,
Archive[] archives )
private

Constructs a new FileSystem with the specified Caches and Archives.

Parameters
cachesAll of the Caches within this FileSystem.
archivesAll of the Archives within this FileSystem.

Definition at line 98 of file FileSystem.java.

98 {
99 this.caches = caches;
100 this.archives = archives;
101 }

References archives, and caches.

Referenced by create().

Here is the caller graph for this function:

Member Function Documentation

◆ create()

FileSystem com.runehive.fs.cache.FileSystem.create ( String directory) throws IOException
static

Constructs and initializes a FileSystem from the specified
directory
.

Parameters
directoryThe directory of the FileSystem.
Returns
The constructed FileSystem instance.
Exceptions
IOExceptionIf some I/O exception occurs.

Definition at line 111 of file FileSystem.java.

111 {
112 Path root = Paths.get(directory);
113 Preconditions.checkArgument(Files.isDirectory(root), "Supplied path must be a directory! " + root);
114
115 Path data = root.resolve(DATA_PREFIX);
116 Preconditions.checkArgument(Files.exists(data), "No data file found in the specified path!");
117
118 SeekableByteChannel dataChannel = Files.newByteChannel(data, READ, WRITE);
119
120 Cache[] caches = new Cache[MAXIMUM_INDICES];
121 Archive[] archives = new Archive[MAXIMUM_ARCHIVES];
122
123 for (int index = 0; index < caches.length; index++) {
124 Path path = root.resolve(INDEX_PREFIX + index);
125 if (Files.exists(path)) {
126 SeekableByteChannel indexChannel = Files.newByteChannel(path, READ, WRITE);
127 caches[index] = new Cache(dataChannel, indexChannel, index);
128 }
129 }
130
131 // We don't use index 0
132 for (int id = 1; id < archives.length; id++) {
133 Cache cache = Objects.requireNonNull(caches[CONFIG_INDEX], "Configuration cache is null - unable to decode archives");
134 archives[id] = Archive.decode(cache.get(id));
135 }
136
137 return new FileSystem(caches, archives);
138 }
val index

References archives, caches, CONFIG_INDEX, DATA_PREFIX, com.runehive.fs.cache.archive.Archive.decode(), FileSystem(), INDEX_PREFIX, MAXIMUM_ARCHIVES, and MAXIMUM_INDICES.

Referenced by com.runehive.RuneHive.processSequentialStartupTasks().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getArchive()

Archive com.runehive.fs.cache.FileSystem.getArchive ( int id)

Gets an Archive for the specified id, this method fails-fast if no archive can be found.

Parameters
idThe id of the Archive to fetch.
Returns
The Archive for the specified id.
Exceptions
NullPointerExceptionIf the archive cannot be found.

Definition at line 148 of file FileSystem.java.

148 {
149 Preconditions.checkElementIndex(id, archives.length);
150 return Objects.requireNonNull(archives[id]);
151 }

References archives.

◆ getArchiveHashes()

ByteBuffer com.runehive.fs.cache.FileSystem.getArchiveHashes ( ) throws IOException

Returns the cached archiveHashes if they exist, otherwise they are calculated and cached for future use.

Returns
The hashes of each Archive.
Exceptions
IOExceptionIf some I/O exception occurs.

Definition at line 189 of file FileSystem.java.

189 {
190 synchronized (this) {
191 if (archiveHashes != null) {
192 return archiveHashes.duplicate();
193 }
194 }
195
196 int[] crcs = new int[MAXIMUM_ARCHIVES];
197
198 CRC32 crc32 = new CRC32();
199 for (int file = 1; file < crcs.length; file++) {
200 crc32.reset();
201
202 ByteBuffer buffer = getFile(CONFIG_INDEX, file);
203 crc32.update(buffer);
204
205 crcs[file] = (int) crc32.getValue();
206 }
207
208 ByteBuffer buffer = ByteBuffer.allocate((crcs.length + 1) * Integer.BYTES);
209
210 int hash = 1234;
211 for (int crc : crcs) {
212 hash = (hash << 1) + crc;
213 buffer.putInt(crc);
214 }
215
216 buffer.putInt(hash);
217 buffer.flip();
218
219 synchronized (this) {
220 archiveHashes = buffer.asReadOnlyBuffer();
221 return archiveHashes.duplicate();
222 }
223 }

References archiveHashes, CONFIG_INDEX, getFile(), and MAXIMUM_ARCHIVES.

Here is the call graph for this function:

◆ getCache()

Cache com.runehive.fs.cache.FileSystem.getCache ( int id)

Gets a Cache for the specified id, this method fails-fast if no cache can be found.

Parameters
idThe id of the Cache to fetch.
Returns
The Cache for the specified id.
Exceptions
NullPointerExceptionIf the cache cannot be found.

Definition at line 161 of file FileSystem.java.

161 {
162 Preconditions.checkElementIndex(id, caches.length);
163 return Objects.requireNonNull(caches[id]);
164 }

References caches.

Referenced by getFile().

Here is the caller graph for this function:

◆ getFile()

ByteBuffer com.runehive.fs.cache.FileSystem.getFile ( int cacheId,
int indexId ) throws IOException

Returns a ByteBuffer of file data for the specified index within the specified Cache.

Parameters
cacheIdThe id of the cache.
indexIdThe id of the index within the cache.
Returns
A ByteBuffer of file data for the specified index.
Exceptions
IOExceptionIf some I/O exception occurs.

Definition at line 175 of file FileSystem.java.

175 {
176 Cache cache = getCache(cacheId);
177 synchronized (cache) {
178 return cache.get(indexId);
179 }
180 }

References getCache().

Referenced by getArchiveHashes().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ ANIMATION_INDEX

final int com.runehive.fs.cache.FileSystem.ANIMATION_INDEX = 2
static

Represents the id of the animations cache.

Definition at line 33 of file FileSystem.java.

◆ archiveHashes

ByteBuffer com.runehive.fs.cache.FileSystem.archiveHashes
private

The cached archive hashes.

Definition at line 87 of file FileSystem.java.

Referenced by getArchiveHashes().

◆ archives

final Archive [] com.runehive.fs.cache.FileSystem.archives
private

All of the Archives within this FileSystem.

Definition at line 84 of file FileSystem.java.

Referenced by create(), FileSystem(), and getArchive().

◆ caches

final Cache [] com.runehive.fs.cache.FileSystem.caches
private

All of the Caches within this FileSystem.

Definition at line 81 of file FileSystem.java.

Referenced by create(), FileSystem(), and getCache().

◆ CONFIG_ARCHIVE

final int com.runehive.fs.cache.FileSystem.CONFIG_ARCHIVE = 2
static

◆ CONFIG_INDEX

final int com.runehive.fs.cache.FileSystem.CONFIG_INDEX = 0
static

Represents the id of the configurations cache.

Definition at line 27 of file FileSystem.java.

Referenced by create(), and getArchiveHashes().

◆ DATA_PREFIX

final String com.runehive.fs.cache.FileSystem.DATA_PREFIX = "main_file_cache.dat"
staticprivate

Represents the prefix of this FileSystems main cache files.

Definition at line 75 of file FileSystem.java.

Referenced by create().

◆ INDEX_PREFIX

final String com.runehive.fs.cache.FileSystem.INDEX_PREFIX = "main_file_cache.idx"
staticprivate

Represents the prefix of this FileSystems index files.

Definition at line 78 of file FileSystem.java.

Referenced by create().

◆ INTERFACE_ARCHIVE

final int com.runehive.fs.cache.FileSystem.INTERFACE_ARCHIVE = 3
static

Represents the id of the interface archive.

Definition at line 48 of file FileSystem.java.

◆ MANIFEST_ARCHIVE

final int com.runehive.fs.cache.FileSystem.MANIFEST_ARCHIVE = 5
static

Represents the id of the manifest archive.

Definition at line 54 of file FileSystem.java.

Referenced by com.runehive.fs.cache.decoder.MapDefinitionDecoder.run().

◆ MAP_INDEX

final int com.runehive.fs.cache.FileSystem.MAP_INDEX = 4
static

Represents the id of the tool.mapviewer and landscape cache.

Definition at line 39 of file FileSystem.java.

Referenced by com.runehive.fs.cache.decoder.RegionDecoder.run().

◆ MAXIMUM_ARCHIVES

final int com.runehive.fs.cache.FileSystem.MAXIMUM_ARCHIVES = 9
staticprivate

Represents the maximum amount of archives within this file system.

Definition at line 69 of file FileSystem.java.

Referenced by create(), and getArchiveHashes().

◆ MAXIMUM_INDICES

final int com.runehive.fs.cache.FileSystem.MAXIMUM_INDICES = 256
staticprivate

Represents the maximum amount of indices within this file system.

Definition at line 72 of file FileSystem.java.

Referenced by create().

◆ MEDIA_ARCHIVE

final int com.runehive.fs.cache.FileSystem.MEDIA_ARCHIVE = 4
static

Represents the id of the media and sprite archive.

Definition at line 51 of file FileSystem.java.

◆ MIDI_INDEX

final int com.runehive.fs.cache.FileSystem.MIDI_INDEX = 3
static

Represents the id of the sounds and music cache.

Definition at line 36 of file FileSystem.java.

◆ MODEL_INDEX

final int com.runehive.fs.cache.FileSystem.MODEL_INDEX = 1
static

Represents the id of the model cache.

Definition at line 30 of file FileSystem.java.

◆ SOUND_ARCHIVE

final int com.runehive.fs.cache.FileSystem.SOUND_ARCHIVE = 8
static

Represents the id of the sound and music archive.

Definition at line 66 of file FileSystem.java.

◆ TEXTURES_ARCHIVE

final int com.runehive.fs.cache.FileSystem.TEXTURES_ARCHIVE = 6
static

Represents the id of the textures archive.

Definition at line 57 of file FileSystem.java.

◆ TITLE_ARCHIVE

final int com.runehive.fs.cache.FileSystem.TITLE_ARCHIVE = 1
static

Represents the id of the title screen archive.

Definition at line 42 of file FileSystem.java.

◆ WORD_ARCHIVE

final int com.runehive.fs.cache.FileSystem.WORD_ARCHIVE = 7
static

Represents the id of the word archive - user for storing profane or illegal words not allowed to be spoken in-game.

Definition at line 63 of file FileSystem.java.


The documentation for this class was generated from the following file: