Swf Lang Loader

Load and parse Dofus retro swf lang files.

License

License

GroupId

GroupId

fr.arakne
ArtifactId

ArtifactId

swf-lang-loader
Last Version

Last Version

0.1-alpha
Release Date

Release Date

Type

Type

jar
Description

Description

Swf Lang Loader
Load and parse Dofus retro swf lang files.
Project URL

Project URL

https://github.com/Arakne/SwfLangLoader
Source Code Management

Source Code Management

http://github.com/Arakne/SwfLangLoader/tree/master

Download swf-lang-loader

How to add to project

<!-- https://jarcasting.com/artifacts/fr.arakne/swf-lang-loader/ -->
<dependency>
    <groupId>fr.arakne</groupId>
    <artifactId>swf-lang-loader</artifactId>
    <version>0.1-alpha</version>
</dependency>
// https://jarcasting.com/artifacts/fr.arakne/swf-lang-loader/
implementation 'fr.arakne:swf-lang-loader:0.1-alpha'
// https://jarcasting.com/artifacts/fr.arakne/swf-lang-loader/
implementation ("fr.arakne:swf-lang-loader:0.1-alpha")
'fr.arakne:swf-lang-loader:jar:0.1-alpha'
<dependency org="fr.arakne" name="swf-lang-loader" rev="0.1-alpha">
  <artifact name="swf-lang-loader" type="jar" />
</dependency>
@Grapes(
@Grab(group='fr.arakne', module='swf-lang-loader', version='0.1-alpha')
)
libraryDependencies += "fr.arakne" % "swf-lang-loader" % "0.1-alpha"
[fr.arakne/swf-lang-loader "0.1-alpha"]

Dependencies

compile (2)

Group / Artifact Type Version
com.google.code.gson : gson jar [2.8.0,)
com.jpexs » ffdec-lib jar 11.3.0

test (2)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-api jar 5.5.2
org.junit.jupiter : junit-jupiter-engine jar 5.5.2

Project Modules

There are no modules declared in this project.

Swf Map Loader

Build Status Scrutinizer Code Quality Code Coverage javadoc Maven Central

Load and parse Dofus retro swf lang files.

Installation

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

<dependency>
    <groupId>fr.arakne</groupId>
    <artifactId>swf-lang-loader</artifactId>
    <version>0.1-alpha</version>
</dependency>

Usage

Simple usage

On this example, we find the nearest bank map for the given player :

public class Main {
    public MapPosition findNearestBankMap(Player player){
        // Declare the loader 
        // The first parameter is the langs location, which contains versions_xx.txt files, and swf folder
        // The second parameter is the language. Can be "fr", "en", "de", "es", "it", "nl", "pt"
        LangLoader loader = new LangLoader("http://my-cdn.dofus-server.com/lang", "fr");

        // Load maps and hints swf files
        MapsFile maps = loader.maps();
        HintsFile hints = loader.hints();

        // Get map position
        MapPosition currentPosition = maps.position(player.map().id());

        // Get all banks hints, convert to map position, and get the nearest position
        return hints.byType(Hint.TYPE_BANK)
            .map(hint -> maps.position(hint.mapId()))
            .min(Comparator.comparingInt(currentPosition::distance))
        ;
    }
}

Configure loader & cache system

The loader can be configurer to customize the version loader, and cache system. If enabled (by default), the loader will keep decompiled action script files as cache.

public class Main {
    public LangLoader getLoader() {
        return new LangLoader(
            "http://my-cdn.dofus-server.com/lang", // The lang CDN 
            "fr", // The language
            new TxtVersionsLoader(), // Define the version loading strategy. TxtVersionsLoader will parse versions_xx.txt file
            new SwfFileLoader(
                Paths.get("my/cache/directory"), // Define the cache directory
                true // Enable caching ? (i.e. keep AS files for further use)
            )
        );
    }
}

You can also clear the cache, and force reload all swf files by calling LangLoader#clear() method.

Load a custom SWF structure

You can declare a custom SWF file and load it by using SwfFileLoader.

public class Main {
    // Define the structure class. Here extends BaseLangFile to handle default (i.e. undeclared) SWF variable
    class MyCustomSwf extends BaseLangFile {
        // Declare "FOO" swf variable as string
        // When an assignation `FOO = xxx;` will be parsed, the value "xxx" will be interpreted as String, and MyCustomSwf#foo will be set. 
        @SwfVariable("FOO")
        private String foo;
    
        // The variable name is optional if the java field name match with the SWF variable.
        // The parser handle JSON objects type
        @SwfVariable
        private MySubObject SUB;

        // Handle associative assignation (i.e. `OBJ["foo"] = {...};`)
        // Extract key and value type for declaration. Can handle any primitive value as key.
        @SwfVariable("OBJ")
        final private Map<String, MyOtherObject> objects = new HashMap<>();
    }

    public static void main(String[] args) {
        // Declare the swf loader
        SwfFileLoader loader = new SwfFileLoader();

        // Declare the hydrator by parsing class annotations
        MapperHydrator<MyCustomSwf> hydrator = MapperHydrator.parseAnnotations(MyCustomSwf.class);
        
        // Instantiate the SWF structure
        MyCustomSwf swf = new MyCustomSwf();
        // Load and parse SWF file. The URL can be a local file
        loader.load(new URL("http://my-cdn.dofus-server.com/lang/swf/custom_fr_123.swf"), swf, hydrator);

        // Here, you can use swf
        System.out.println(swf.foo);
    }
}

Licence

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

Use FFDec Library which is licensed with GNU LGPL v3, for parsing SWF files.

fr.arakne
Open source Dofus 1.29 platform

Versions

Version
0.1-alpha