Code Monkey home page Code Monkey logo

wc3maptranslator's Introduction

WC3MapTranslator
Translate war3mapjson formats for WarCraft III .w3x maps

Quality

Known Vulnerabilities


Overview · Install · Usage · File Support · Specification · Contributing · Special Thanks


Overview

WC3MapTranslator is a TypeScript module to convert between JSON and WarCraft III (.w3x) war3map formats. This makes the map data readable and easily modifiable, a perfect format for storing WC3 maps in Git repositories and inspecting diffs!

TranslationExample

Install

npm install wc3maptranslator

Requires Node ≥ 14

Usage

import {
  CamerasTranslator,
  DoodadsTranslator,
  ImportsTranslator,
  InfoTranslator,
  ObjectsTranslator,
  RegionsTranslator,
  SoundsTranslator,
  StringsTranslator,
  TerrainTranslator,
  UnitsTranslator
} from 'wc3maptranslator';

// E.g. let's create a camera for the map
const cameras = [
  {
    "target": {
      "x": -319.01,
      "y": -90.18
    },
    "offsetZ": 0,
    "rotation": 90,
    "aoa": 304,
    "distance": 2657.34,
    "roll": 5,
    "fov": 70,
    "farClipping": 5000,
    "name": "MyCamera1"
  }
]

// Now translate the JSON into the WarCraft III format
// All translators have: `.jsonToWar` and `.warToJson` functions
const translatedResult = CamerasTranslator.jsonToWar(cameras);

// `translatedResult` contains a `buffer` which can be saved to disk
// This war3map.w3c file can now be placed inside a .w3x via an MPQ
// editor, and you should now see a camera in the Camera Palette!
fs.writeFileSync('war3map.w3c', translatedResult.buffer);

File Support

World files

Type Json → War War → Json File
Terrain check times war3map.w3e
Units check check war3mapUnits.doo
Doodads check check war3map.doo
Regions check check war3map.w3r
Cameras check check war3map.w3c
Sounds (definitions) check check war3map.w3s

Object data files

Type Json → War War → Json File
Units - Objects check check war3map.w3u
Items - Objects check check war3map.w3t
Abilities - Objects check check war3map.w3a
Destructables - Objects check check war3map.w3b
Doodads - Objects check check war3map.w3d
Upgrades - Objects check check war3map.w3q
Buffs - Objects check check war3map.w3h

Trigger files

Type Json → War War → Json File
LUA times times war3map.lua
JASS times times war3map.j
Strings check check war3map.wts

Map files

Type Json → War War → Json File
Info File check check war3map.w3i
Imported Files check check war3map.imp
Pathing times times war3map.wpm
Shadow map times times war3map.shd

Not relevant

minus-solid Custom Text Trigger File (war3map.wct)
minus-solid Trigger Names File (war3map.wtg)
minus-solid Menu Minimap (war3map.mmp)
minus-solid Minimap Image (war3mapMap.blp)
minus-solid Minimap Image (war3mapMap.b00
minus-solid Minimap Image (war3mapMap.tga)
minus-solid Map Preview Image (war3mapPreview.tga)

Specification

WC3MapTranslator format

We have a detailed explaining how to format a map in JSON. It explains everything from the high-level map object, all the way down to creating individual units, tiles, or custom objects.

🔗 WC3MapTranslator format

war3map format

The underlying WarCraft map files (e.g. war3map.doo) have been documented in a separate repository. If you are curious about how a .w3x file is composed, this is the place to learn!

🔗 WC3MapSpecification

Contributing

We encourage contributions! Generally, the process of making a change is:

  1. Fork this repo
  2. Develop your changes on a new branch
  3. Submit a pull request to dev

Your code should:

  • run (your code needs to work, of course)
  • include tests (write unit tests to demonstrate your code works under different conditions)
  • be linted (run npm run lint and follow the project's coding standards)
  • pass CI (we enforce: ESLint, unit tests pass, code coverage)

A code review is required on your PR to be accepted into dev. A project member will get back to you within one week. If you haven't heard from someone regarding your PR, feel free to ping @chiefofgxbxl.

Special Thanks

We owe a lot of thanks to Chocobo on TheHelper for the detailed documentation of the files found in a .w3x archive. Two tutorials are here (1) and here (2).

wc3maptranslator's People

Contributors

chiefofgxbxl avatar dulingzhi avatar rufreakde avatar ttay24 avatar yatyricky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

wc3maptranslator's Issues

Unit testing

Add unit tests, mostly for BufferedHexFileWriter.js

CLI tool

Include a command-line interface so users can translate files without having to write code. We can use npx if the user does not want to install the tool.

Update build, code coverage scripts

Since updating to TypeScript, the Travis build, Coveralls, and other build and code quality tools are broken. These all need to be updated.

Flags

There are some files in the spec that still expect the flag param to be set to an int. However, the sounds spec has a flag that is an object:

e.g.

flags: {
  blah1: false,
  blah2: true,
  blah3: false
}

Translators that have poorly defined flags:

  • Units (world entity)

    similar to doodads flags?

  • Doodads (world entity)

    *flags:
    0= invisible and non-solid tree
    1= visible but non-solid tree
    2= normal tree (visible and solid)

This is a more semantic solution, rather than just a mystery number. The translator could check for an integer first, and then if it is an object create the integer from that object.

Help with downgrading to 3.0.2 (for 1.26)

So I got same issue as people before so I installed 4.0.0 as u adviced then downgraded but still it doesn't work. I don't know if downgrade was 100% successful. Here is log

added 33 packages in 5s

3 packages are looking for funding
  run `npm fund` for details
PS J:\warcraft 333\Warcraft\map\patchwork\WC3MapTranslator-4.0.0> npm install --save [email protected]

up to date, audited 324 packages in 1s

21 packages are looking for funding
  run `npm fund` for details

5 vulnerabilities (3 moderate, 2 high)

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.
PS J:\warcraft 333\Warcraft\map\patchwork\WC3MapTranslator-4.0.0> npm audit
# npm audit report

diff  <3.5.0
Severity: high
Regular Expression Denial of Service (ReDoS) - https://github.com/advisories/GHSA-h6ch-v84p-w6p9
No fix available
node_modules/diff-buf/node_modules/diff
  diff-buf  *
  Depends on vulnerable versions of diff
  node_modules/diff-buf

request  *
Severity: moderate
Server-Side Request Forgery in Request - https://github.com/advisories/GHSA-p8p7-x288-28g6
Depends on vulnerable versions of tough-cookie
No fix available
node_modules/request
  coveralls  *
  Depends on vulnerable versions of request
  node_modules/coveralls

tough-cookie  <4.1.3
Severity: moderate
tough-cookie Prototype Pollution vulnerability - https://github.com/advisories/GHSA-72xf-g2v4-qvf3
No fix available
node_modules/tough-cookie

5 vulnerabilities (3 moderate, 2 high)

Some issues need review, and may require choosing
a different dependency.```

Wc3 version support

Hello, currently using this to make a language translation tool. Is the plan to support only latest wc3 version file format or multiple? Want to know if I should just keep using the 1.1.0 release for my use case.

Return object from each translator

Remove the .write() method in each translator and simply return an object: { errors: [], result: }. Writing the files should be left to the implementing program.

Fix failing translator reversions

The latest build is failing because of new unit tests written to perform the following scenario:

  1. Take war3map data and translate it to JSON (warToJson)
  2. Take that JSON and translate it to war3map data (jsonToWar)
  3. Compare the bytes of both war3map files -- they should match exactly

This makes sense because both the JSON and war3map formats, although different formats, should represent the same data. And it does not matter how many times the developer switches between the two, they should restore the original data format each time.

For instance, there are small discrepancies in a .w3a file:
image

This may be related to #18.

Optional fields

Review entire specification and see if more fields can be made optional by having default values in place. There are a few spots already, but there may be room for more optional fields.

How to use

I'm sorry if this is such a low level question but I am trying to edit the war3map.doo file for a map and I honestly have no idea how to even begin running this program but it seems to be the only one online with the potential capability to do so. Would it be possible for me to get pointed towards how to use the program? I am familiar with Java and C++ but I've never used TypeScript

Create examples directory

The wiki contains some rough example snippets, but the project could benefit the user by having an examples directory. This would contain a code example of each translator, all wrapped in a runnable node project that outputs the files and can be drag-and-dropped into a w3x archive and viewed in World Editor.

Lookup tables

Should the JSON support constant values that are looked up in a reference table? Or should it be up to the program creating the JSON files to do this?

w3a -> Json. "Crs" field problem for abilities "Acrs" and "ACcs" (Curse)

Hello. Thank you for the wonderful program! I noticed one issue that prevents seamless translation between w3a <-> Json. Specifically, the "Crs" field of abilities "Acrs" and "ACcs" (Curse) is three characters long, whereas other similar fields are four characters long. Because of this, the value of this field is lost during transitions, and the Json converter interprets it as "Crs0." The problem is at least relevant for Warcraft 1.26. I haven't tested it on other versions.

ERR_OUT_OF_RANGE in W3Buffer/InfoTranslator

I wanted to convert a war3map.w3i (made in v1.26) to JSON to experiment with it. I have no idea how to use the library, so I came up with this by following the included tests:

const wc3 = require('wc3maptranslator')
const fs = require('fs')

const war3infoPath = "war3map.w3i"

function readWar3MapBuffer(filename) {
    return fs.readFileSync(filename);
}

function readJsonTestFile(filename) {
    return fs.readJsonSync(filename);
}

function writeJsonTestFile(filename, json) {
    return fs.writeJsonSync(filename, json);
}

const w3infoData = readWar3MapBuffer(war3infoPath)
const translatedJson = wc3.InfoTranslator.warToJson(w3infoData).json
writeJsonTestFile("war3info.json", translatedJson)

Looks like an off-by-one error? thats hopefully not related to my code:

$ node .
node:internal/buffer:86
  throw new ERR_OUT_OF_RANGE(type || 'offset',
  ^

RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 735. Received 736
    at new NodeError (node:internal/errors:377:5)
    at boundsError (node:internal/buffer:86:9)
    at Buffer.readInt32LE (node:internal/buffer:390:5)
    at W3Buffer.readInt (/home/user/node_modules/wc3maptranslator/lib/W3Buffer.js:14:34)
    at Function.warToJson (/home/user/node_modules/wc3maptranslator/lib/translators/InfoTranslator.js:346:29)
    at Object.<anonymous> (/home/user/war3-24p/w3i2json.js:32:43)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12) {
  code: 'ERR_OUT_OF_RANGE'
}

Node.js v18.2.0

I installed the library from npm: version 4.0.0. The .w3i file is attached within zip: war3info.zip

Use degrees for all angles

The World entities -> Doodads JSON schema asks for the orientation angle/rotation in radians, whereas all other angles (such as for units placed on the map, camera angle of attack or field of view) ask for degrees.

For consistency, the Doodads translator should ask the JSON input to use degrees for its rotation value.

npm start Error under /examples/

C:\test\node>cd C:\test\node\node_modules\wc3maptranslator\examples\warToJson

C:\test\node\node_modules\wc3maptranslator\examples\warToJson>npm install
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No repository field.

added 7 packages from 3 contributors and audited 7 packages in 3.505s
found 0 vulnerabilities

C:\test\node\node_modules\wc3maptranslator\examples\warToJson>npm start

[email protected] start C:\test\node\node_modules\wc3maptranslator\examples\warToJson
node index.js

internal/modules/cjs/loader.js:800
throw err;
^

Error: Cannot find module 'C:\test\node\node_modules\wc3maptranslator\examples\warToJson\index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
at Function.Module._load (internal/modules/cjs/loader.js:690:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
at internal/main/run_main_module.js:17:11 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: node index.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\qgb\AppData\Roaming\npm-cache_logs\2019-12-16T17_35_37_848Z-debug.log

C:\test\node\node_modules\wc3maptranslator\examples\warToJson>node -v
v12.13.1

C:\test\node\node_modules\wc3maptranslator\examples\warToJson>npm -v
6.13.4

C:\test\node\node_modules\wc3maptranslator\examples\warToJson>

Update Wiki

v1.0 release changed the API slightly, so the WIki needs to be updated to reflect those updates.

Add visual examples to README example section

The example section of the README.md shows a code snippet that doesn't offer much insight because it skips over both the JSON and WC3 "native" data.

Use a specific translator for the code snippet, and then show two side-by-side images:

  1. WC3 hex code
  2. JSON format

so developers can see the data in two formats, and how JSON is easier to read and work with.

Add error checking & reporting

Use the return object of each translator to store ❌ errors that occur in translating. Before any translation takes place, validation should be performed to check the input schema:

  • Are required fields present?
  • Do provided values make sense
    • String length limitations
    • percent values are between 0-100
    • etc.

There is no permission to use the code.

You can add a license easily using the GitHub website if you:

  • Log in.
  • Go to your repo.
  • Click "New File."
  • For the name, type "license.txt" or something. That will cause the license template chooser to appear.
  • Choose a license from the list.
  • Choose "commit directly to the master branch"

Please make this MIT-licensed or something permissive if you don't care about it. That way others can use it. See https://github.com/poikilos/refounded . People can't use it if you don't provide a license, since the default legally is "no permission".

How to use it

So installed it with npm install wc3maptranslator
Now there are some files in the folder where I installed it.
But the problem is what are the commands to use it? I am left on cmd opened in installed module directory
for example I have w3i extracted from map, how do I unpack it to json or just some readable text and then pack it back again?
Sry so far I only managed to understand python and Visual Studio compiling because it's very easy, but here it's like completely 0 info about anything

Improve wiki documentation

  • explanation of type: when to choose string, int, real or unreal (see #7)
  • finding out which type to use for a given ability field (e.g. how do we know Holy Bolt's "amount healed" is of type unreal, instead of real or int?)
  • improve the index page of the wiki

How to use v4 of this package?

Hello 👋 sorry if this is trivial, but I could not get the v4.0.0 of this package working.

I tried multiple ways to run the example in the readme, but i'm not sure what the right setup is. I compiled the example with Typescript and then ran it with Node. Here is the error stack:

Error: Cannot find module './lib/translators'
Require stack:
- C:\Users\Lukas\Documents\Webentwicklung\warcraft3-map-analyzer-install-test\node_modules\wc3maptranslator\index.js
- C:\Users\Lukas\Documents\Webentwicklung\warcraft3-map-analyzer-install-test\dist\index.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\Lukas\Documents\Webentwicklung\warcraft3-map-analyzer-install-test\node_modules\wc3maptranslator\index.js:4:23)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\Lukas\\Documents\\Webentwicklung\\warcraft3-map-analyzer-install-test\\node_modules\\wc3maptranslator\\index.js',
    'C:\\Users\\Lukas\\Documents\\Webentwicklung\\warcraft3-map-analyzer-install-test\\dist\\index.js'
  ]
}

Here is my project setup:

dist/
node_modules/
src/
  index.ts
package-lock.json
package.json
tsconfig.json

index.ts:

import { CamerasTranslator } from 'wc3maptranslator';
import { writeFileSync } from 'fs';

const cameras = [
  {
    "target": {
      "x": -319.01,
      "y": -90.18
    },
    "offsetZ": 0,
    "rotation": 90,
    "aoa": 304,
    "distance": 2657.34,
    "roll": 5,
    "fov": 70,
    "farClipping": 5000,
    "name": "MyCamera1"
  }
]

const translatedResult = CamerasTranslator.jsonToWar(cameras);
writeFileSync('war3map.w3c', translatedResult.buffer);

package.json:

{
  "name": "warcraft3-map-analyzer-install-test",
  "version": "0.0.1",
  "description": "Install test for wc3maptranslator",
  "main": "src/index.ts",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@types/node": "^17.0.24",
    "wc3maptranslator": "^4.0.0"
  },
  "devDependencies": {
    "typescript": "^4.6.3"
  }
}

tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "target": "es6",
    "noImplicitAny": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "dist",
    "baseUrl": ".",
    "paths": {
      "*": [
        "node_modules/*",
        "src/types/*"
      ]
    }
  },
  "include": [
    "src/**/*"
  ]
}

Then I ran tsc to compile the src/index.ts into dist/index.js and ran node .\dist\index.js. The before mentioned error gets thrown.

The versions I used:

  • nvm (nvm-windows): v1.1.9
  • node: v16.13.2
  • npm: v8.1.2
  • tsc: v4.6.3

I thought the problem was that my Node version is outdated and the line const translators_1 = require("./lib/translators"); in w3maptranslator/index.js does not get handled properly. But the readme says at least "Node >= 14" and I used Node v16.

If I understand correctly, the import syntax of JavaScript is from ES6 and the require syntax from CommonJS. Besides 1) transpiling with Typescript, I also tried using 2) bundling a index.js file with Webpack and 3) adding type: module to the package.json. None worked so far.

Any help would be very appreciated!

Best regards, Lukas

Typescript support?

Are there any plans/has work been done for typescript support? Is that something that is wanted?

Extracting the scripts

Hi, two questions:

  1. I haven't found any mention of extracting scripts with this lib. Is it possible or should I look somewhere else?
  2. Is it possible to extract the whole w3x archive file? (trying to understand the structure of the archive... binwalk says it has thousands of zlib compressed blocks which upon extraction do not yield unit files, region files etc.)

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.