https://github.com/carloshenrq/php-grf
This is a lib to allow PHP to read and write GRF (Gravity Ragnarok Files).
https://github.com/carloshenrq/php-grf
gravity-ragnarok-file grf php php-grf ragnarok ragnarokonline
Last synced: 5 months ago
JSON representation
This is a lib to allow PHP to read and write GRF (Gravity Ragnarok Files).
- Host: GitHub
- URL: https://github.com/carloshenrq/php-grf
- Owner: carloshenrq
- License: mit
- Created: 2019-02-25T18:30:10.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-21T00:55:43.000Z (almost 7 years ago)
- Last Synced: 2025-10-17T22:29:07.641Z (8 months ago)
- Topics: gravity-ragnarok-file, grf, php, php-grf, ragnarok, ragnarokonline
- Language: PHP
- Homepage:
- Size: 986 KB
- Stars: 17
- Watchers: 2
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP-GRF [](https://github.com/carloshenrq/php-grf/releases) [](https://github.com/carloshenrq/php-grf)
This is a lib to allow PHP to read and write GRF (Gravity Ragnarok Files).
### Build Status
[](https://travis-ci.com/carloshenrq/php-grf) [](https://ci.appveyor.com/project/carloshenrq/php-grf) [](https://github.com/carloshenrq/php-grf/issues) [](https://github.com/carloshenrq/php-grf/pulls)
### Code Quality
[](https://www.codefactor.io/repository/github/carloshenrq/php-grf/overview/master) [](https://www.codacy.com/app/carloshenrq/php-grf?utm_source=github.com&utm_medium=referral&utm_content=carloshenrq/php-grf&utm_campaign=Badge_Grade)
### Code Coverage
[](https://codecov.io/gh/carloshenrq/php-grf) [](https://www.codacy.com/app/carloshenrq/php-grf?utm_source=github.com&utm_medium=referral&utm_content=carloshenrq/php-grf&utm_campaign=Badge_Coverage)
## How i can colaborate?
Please! check our issues and if you can fix or add new features, you're welcome.
Also, see if what you're about to change is in ours pull requests.
## How to open a file to read?
The code ahead, will show you how to extract all files inside grf.
```
getEntries() as $entry) {
$dir = dirname($entry->getFilename());
if (is_dir($dir) === false)
mkdir ($dir, 0777, true);
$file = str_replace('\\', '/', $entry->getFilename());
$buffer = $entry->getUnCompressedBuffer();
$fp = fopen($file, 'wb');
fwrite($fp, $buffer);
fflush($fp);
fclose($fp);
}
// Dispose all resources used
$grf = null;
```
If you wanna search inside entries:
```
getEntries()->where(function($entry) {
return $entry->getUnCompressedSize() > 1000;
});
// Dispose all resources used
$grf = null;
```
Know the full path inside grf the file is?
```
getEntries();
$entry = $entries['data\\0_Tex1.bmp'];
if ($entry === null) { // not found
}
// Dispose all resources used
$grf = null;
```
## How to open a grf file to write?
The same way you open to read, you can write. See:
```
require_once 'php-grf/lib/autoload.php';
// Instance a reader/writer for your grf file
$grf = new GrfFile('php-grf/tests/test200.grf');
$grf->addFile('file-outside.txt', 'data\\file-inside.txt');
// Dispose all resources used
$grf->close(); // Auto save when closed
$grf = null;
```
When you call `$grf->save()` or `$grf->close()` this'll repack your grf.
Large grf files may take some minutes to finish.
## How to create a grf file to write?
Look here how to create a new grf file:
```
require_once 'php-grf/lib/autoload.php';
// Creates a new grf file with no files inside
$grf = GrfFile::create('your-grf-file.grf');
// Dispose all resources used
$grf->close(); // Auto save when closed
$grf = null;
```
To add files, just check the section above...
## Install
To install, you only need use composer require to use.
```
composer require carloshlfz/php-grf
```
Just make sure you've `vendor/autoload.php` loaded and is just start to use.
## Credits and other infos
The grf file inside tests folder `test200.grf` is from [arminherling/GRF](https://github.com/arminherling/GRF/).
This code is based on [MagicalTux/grf](https://github.com/MagicalTux/grf)