Skip to content

Load and parse Dofus retro swf lang files

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/SwfLangLoader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swf Lang Loader

Java CI codecov 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.3-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.

About

Load and parse Dofus retro swf lang files

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