Skip to content

Load and parse Dofus maps from SWF CDN

License

LGPL-3.0, GPL-3.0 licenses found

Licenses found

LGPL-3.0
COPYING.LESSER
GPL-3.0
COPYING
Notifications You must be signed in to change notification settings

Arakne/SwfMapLoader

Repository files navigation

Swf Map Loader

CI codecov javadoc Maven Central

Load and parse Dofus 1.29 maps from swf file and CDN.

Installation

For installing using maven, add this dependency into the pom.xml :

<dependency>
    <groupId>fr.arakne</groupId>
    <artifactId>swf-map-loader</artifactId>
    <version>0.2-alpha</version>
</dependency>

Usage

Create your Map class

Create your map and cell classes. The map should inherit SimpleMap, which provide simple adapter for SwfMapStructure. More details about maps implementation here.

// The SimpleMap parameter should be the cell implementation
public class MyMap extends SimpleMap<MyCell> {
    public MyMap(SwfMapStructure structure, CellData[] cells, MapFactory<MyCell, MyMap> mapFactory) {
        super(structure, cells, mapFactory);
    }

    // Add methods here.
    // structure and cells attributes are accessible here (with protected access)
}

// The AbstractCellDataAdapter should be the map implementation
public class MyCell extends AbstractCellDataAdapter<MyMap, MyCell> {
    public MyCell(MyMap map, CellData data, int id) {
        super(map, data, id);
    }

    // Implements other methods here...
}

After that, you can create your factory for instantiate those classes :

class MyMapFactory implements MapFactory<MyCell, MyMap> {
    @Override
    public MyMap createMap(SwfMapStructure structure, CellData[] cells) {
        return new MyMap(structure, cells, this);
    }

    @Override
    public MyCell createCell(MyCustomMap map, int id, CellData cell) {
        return new MyCell(map, cell, id);
    }
}

Configure the loader

Once map and cell classes implemented, you can configure the MapLoader. For this purpose, you can use MapLoaderConfigurator :

// Create the configurator. Note: parameters must match with map and cell implementations
MapLoaderConfigurator<MyCell, MyMap> configurator = new MapLoaderConfigurator<>();

configurator
    .factory(new MyMapFactory()) // Configure the factory : link the custom map implementation to the loader
    .baseUrl("http://my-server.com/dofus/maps") // Define the CDN URL. SWF files must be located at the given path
    .cacheFile("./map-cache.sqlite") // Enable SQLite cache system : maps will be parsed once, and will be retrieved from the cache for further access.
;

// Create the map loader
MapLoader<MyCell, MyMap> loader = configurator.create();

Load maps

Final step : you can load the map !

// Handler for the GDM packet
class LoadMapPacketHandler {
    private MapLoader<MyCell, MyMap> loader;
    // ...

    public void handlePacket(String data) {
        String[] parts = data.split("\\|");

        // Load the map
        client.setCurrentMap(
            loader.load(Integer.parseInt(parts[0]), parts[1], parts[2])
        );
    }
}

You can also directly load a SWF file :

File swfFile = new File("...");
String mapKey = xxx;

// Convert File to URL, and loads it
MyMap map = loader.load(swfFile.toURI().toURL(), mapKey);

Licence

This project is licensed under the LGPLv3 licence. See COPYING and COPYING.LESSER files for details.

It also links FFDec Library which is licensed with GNU LGPL v3, for parsing SWF files. See lib/ffdec for more details.

About

Load and parse Dofus maps from SWF CDN

Topics

Resources

License

LGPL-3.0, GPL-3.0 licenses found

Licenses found

LGPL-3.0
COPYING.LESSER
GPL-3.0
COPYING

Stars

Watchers

Forks

Packages

No packages published

Languages