@chicowall/grf-loader 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -0
- package/index.d.ts +24 -0
- package/package.json +70 -0
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# GRF Loader
|
|
2
|
+
|
|
3
|
+
**GRF** is an archive file format that support lossless data compression used on **Ragnarok Online** to store game assets. A GRF file may contain one or more files or directories that may have been compressed (deflate) and encrypted (variant of DES).
|
|
4
|
+
|
|
5
|
+
[](https://github.com/vthibault/roBrowser) [](https://opensource.org/licenses/MIT)
|
|
6
|
+
  
|
|
7
|
+
|
|
8
|
+
## About
|
|
9
|
+
|
|
10
|
+
- Only supports GRF version 0x200.
|
|
11
|
+
- It's working both on node and browser environments
|
|
12
|
+
- Supports DES description.
|
|
13
|
+
- Avoid bloating client/server memory _(by not loading the whole file into the RAM)_
|
|
14
|
+
- Does not supports custom encryption
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
npm install grf-loader
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Basic usage
|
|
23
|
+
|
|
24
|
+
- Load a grf file on node.js
|
|
25
|
+
- Load a grf from the browser
|
|
26
|
+
- List all files content
|
|
27
|
+
- Extract a file from the GRF
|
|
28
|
+
|
|
29
|
+
### Load a grf file on node.js
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import {GrfNode} from 'grf-loader';
|
|
33
|
+
import {openSync} from 'path';
|
|
34
|
+
|
|
35
|
+
const fd = openSync('path/to/data.grf', 'r');
|
|
36
|
+
const grf = new GrfNode(fd);
|
|
37
|
+
|
|
38
|
+
// Start parsing the grf.
|
|
39
|
+
await grf.load();
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Load a grf from the browser
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import {GrfBrowser} from 'grf-loader';
|
|
46
|
+
|
|
47
|
+
const blob = document.querySelector('input[type="file"]').files[0];
|
|
48
|
+
const grf = new GrfBrowser(blob);
|
|
49
|
+
|
|
50
|
+
// Start parsing the grf
|
|
51
|
+
await grf.load();
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### List all files content
|
|
55
|
+
|
|
56
|
+
Once the GRF is loaded, it's possible to list all files included inside it
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
grf.files.forEach((entry, path) => {
|
|
60
|
+
console.log(path);
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Extract a file from the GRF
|
|
65
|
+
|
|
66
|
+
Once the GRF is loaded, it's possible to extract all files you need
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
const {data, error} = await grf.getFile('data\\clientinfo.xml');
|
|
70
|
+
|
|
71
|
+
// data is a Uint8Array data, so we transform it into text
|
|
72
|
+
const content = String.fromCharCode.apply(null, data);
|
|
73
|
+
console.log(content);
|
|
74
|
+
```
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
declare module 'grf-loader' {
|
|
2
|
+
export interface TFileEntry {
|
|
3
|
+
type: number;
|
|
4
|
+
offset: number;
|
|
5
|
+
realSize: number;
|
|
6
|
+
compressedSize: number;
|
|
7
|
+
lengthAligned: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
class Grf<T> {
|
|
11
|
+
constructor(fd: T);
|
|
12
|
+
version: number;
|
|
13
|
+
fileCount: number;
|
|
14
|
+
loaded: boolean;
|
|
15
|
+
files: Map<string, TFileEntry>;
|
|
16
|
+
load(): Promise<void>;
|
|
17
|
+
getFile(
|
|
18
|
+
filename: string
|
|
19
|
+
): Promise<{data: null | Uint8Array; error: null | string}>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class GrfBrowser extends Grf<File | Blob> {}
|
|
23
|
+
export class GrfNode extends Grf<number> {}
|
|
24
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chicowall/grf-loader",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"version": "1.0.0",
|
|
7
|
+
"description": "A loader for GRF files (Ragnarok Online game file)",
|
|
8
|
+
"main": "./dist/cjs/grf-loader.js",
|
|
9
|
+
"module": "./dist/esm/grf-loader.js",
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"browser": {
|
|
12
|
+
"./dist/cjs/grf-loader.js": "./dist/umd/grf-loader.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist/",
|
|
16
|
+
"index.d.ts"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test:node": "jest",
|
|
20
|
+
"test:browser": "cypress run",
|
|
21
|
+
"test": "yarn test:node --detectOpenHandles && yarn test:browser",
|
|
22
|
+
"lint": "tsc --noEmit",
|
|
23
|
+
"build": "del dist && rollup -c"
|
|
24
|
+
},
|
|
25
|
+
"author": "Vincent Thibault <vthibault.mobile@gmail.com>",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/vthibault/grf-loader/issues"
|
|
29
|
+
},
|
|
30
|
+
"repository": "github:vthibault/grf-loader",
|
|
31
|
+
"keywords": [
|
|
32
|
+
"grf-loader",
|
|
33
|
+
"grf-parser",
|
|
34
|
+
"grf-reader",
|
|
35
|
+
"grf",
|
|
36
|
+
"loader",
|
|
37
|
+
"reader",
|
|
38
|
+
"ro",
|
|
39
|
+
"ragnarok",
|
|
40
|
+
"ragnarok-online"
|
|
41
|
+
],
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@babel/core": "^7.10.2",
|
|
44
|
+
"@babel/preset-env": "^7.10.2",
|
|
45
|
+
"@babel/preset-typescript": "^7.10.1",
|
|
46
|
+
"@rollup/plugin-typescript": "^4.1.2",
|
|
47
|
+
"@types/cypress": "^1.1.3",
|
|
48
|
+
"@types/jdataview": "^0.0.31",
|
|
49
|
+
"@types/jest": "^25.2.3",
|
|
50
|
+
"@types/pako": "^1.0.1",
|
|
51
|
+
"babel-jest": "^26.0.1",
|
|
52
|
+
"cypress": "^4.7.0",
|
|
53
|
+
"del-cli": "^3.0.1",
|
|
54
|
+
"jest": "^26.0.1",
|
|
55
|
+
"prettier": "2.0.5",
|
|
56
|
+
"rollup": "^2.12.0",
|
|
57
|
+
"rollup-plugin-terser": "^6.1.0",
|
|
58
|
+
"typescript": "^3.9.3"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"jdataview": "^2.5.0",
|
|
62
|
+
"pako": "^1.0.11"
|
|
63
|
+
},
|
|
64
|
+
"jest": {
|
|
65
|
+
"clearMocks": true,
|
|
66
|
+
"collectCoverage": true,
|
|
67
|
+
"coverageDirectory": "coverage",
|
|
68
|
+
"testEnvironment": "node"
|
|
69
|
+
}
|
|
70
|
+
}
|