GithubHelp home page GithubHelp logo

hearthsim / hearthstone-deckstrings Goto Github PK

View Code? Open in Web Editor NEW
50.0 10.0 11.0 128 KB

🔗 Decode and encode Hearthstone Deckstrings.

Home Page: https://hearthsim.info/docs/deckstrings/

License: ISC License

TypeScript 33.52% JavaScript 66.48%
hearthstone deckstrings

hearthstone-deckstrings's Introduction

deckstrings for Hearthstone

npm

Decode and encode Hearthstone deckstrings.

A mapping between DBF ids and cards can be found at HearthstoneJSON.

Any deckstring or deck definition returned by this library will be "canonical": The cards and heroes are sorted by DBF id in ascending order.

Install

Install the package from npm using your favourite package manager:

$ yarn add deckstrings

Usage

import { encode, decode, FormatType } from "deckstrings";

const deck = {
	cards: [[1, 2], [2, 2], [3, 2], [4, 1]], // [dbfId, count] pairs
	sideboardCards: [[5, 1, 90749]], // [dbfId, count, sideboardOwnerDbfId] triplets
	heroes: [7], // Garrosh Hellscream
	format: FormatType.FT_WILD, // or FT_STANDARD or FT_CLASSIC
};

const deckstring = encode(deck);
console.log(deckstring); // AAEBAQcBBAMBAgMAAQEF/cQFAAA=

const decoded = decode(deckstring);
console.log(JSON.stringify(deck) === JSON.stringify(decoded)); // true

hearthstone-deckstrings's People

Contributors

beheh avatar jleclanche 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hearthstone-deckstrings's Issues

Could not read varint in lib/index.js

Decoding certain deck codes fail to process, such as this one:

AAECAa0GHqEE1Qq0AvsM5MICysMCCfYHnALovwKQ0wLqvwKDuwK+yAKhrAKS tALYuwLTCvDPAtcK0cEC2MEC+wGKAe0F5QS1uwLyDJcCpQkA=

Here is the error I am receiving:
RangeError: Could not decode varint at Object.read [as decode] (/dir/node_modules/deckstrings/lib/index.js:48:13) at BufferReader.nextVarint (/dir/node_modules/deckstrings/lib/index.js:181:27) at Object.decode (/dir/node_modules/deckstrings/lib/index.js:287:36) at /dir/bot.js:89:28 at Array.forEach (native) at DiscordClient.details (/dir/bot.js:87:10) at DiscordClient.EventEmitter.emit (events.js:106:17) at DiscordClient.handleWSMessage (/dir/node_modules/discord.io/lib/index.js:1803:11) at WebSocket.EventEmitter.emit (events.js:98:17) at Receiver.ontext (/dir/node_modules/discord.io/node_modules/ws/lib/WebSocket.js:841:10) at /dir/node_modules/discord.io/node_modules/ws/lib/Receiver.js:536:18 at Receiver.applyExtensions (/dir/node_modules/discord.io/node_modules/ws/lib/Receiver.js:371:5) at /dir/node_modules/discord.io/node_modules/ws/lib/Receiver.js:508:14 at Receiver.flush (/dir/node_modules/discord.io/node_modules/ws/lib/Receiver.js:347:3) at Receiver.opcodes.1.finish (/dir/node_modules/discord.io/node_modules/ws/lib/Receiver.js:541:12) at Receiver.expectHandler (/dir/node_modules/discord.io/node_modules/ws/lib/Receiver.js:499:31)

Export FormatType

So that users of the library do not need to use the magical constants 1 and 2, but rather:

import { encode, FormatType } from "deckstrings";

encode({
    ...params,
    format: FormatType.FT_WILD,
});

Unable to parse latest deckstrings

Hi there, I am a Hearthstone gamer and have tried to use this library to parse the deckstrings. After installing it using npm i deckstrings, I ran the following code

const { decode } = require("deckstrings");
var deckstring = "AAECAaIHHrQBsgLtAs0DrwSIB8f4AqCAA7SGA7SRA4+XA5CXA5KXA/uaA/6aA/yjA4SnA/WnA7euA7muA8GuA/6uA6qvA86vA/2wA4KxA5GxA+O0A5+3A8vAAwAA";
var deck = decode(deckstring);

However it throws an exception:

RangeError: Could not decode varint
    at Object.read [as decode] (/root/hearthstone-deck/node_modules/deckstrings/dist/index.js:50:13)
    at BufferReader.nextVarint (/root/hearthstone-deck/node_modules/deckstrings/dist/index.js:162:28)
    at decode$2 (/root/hearthstone-deck/node_modules/deckstrings/dist/index.js:276:24)
    at module.exports (/root/hearthstone-deck/core.js:102:14)
    at /root/hearthstone-deck/server.js:40:12
    at Layer.handle [as handle_request] (/root/hearthstone-deck/node_modules/express/lib/router/layer.js:95:5)
    at next (/root/hearthstone-deck/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/root/hearthstone-deck/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/root/hearthstone-deck/node_modules/express/lib/router/layer.js:95:5)
    at /root/hearthstone-deck/node_modules/express/lib/router/index.js:281:22

Then I found the Hearthstone deckstring at different times on a game forum for analysis, and the results seem to prove that the deckstring after Saviors of Uldum was released, could not be parsed.

Date Deckstring / event Result
July 20 AAECAf0ECqQDkAe4CLwI7vYCw/gCxvgCoIADlpoDn7cDCqsE5gThB40IyIcD0okDg5YDn5sD4psD/50DAA== Success
August 01 AAECAf0EAu72Ar6kAw5xwwG7AqsE5gSWBewFvAjIhwOfmwPimwO/pAPdqQP0qwMA Success
August 06 Saviors of Uldum Released N/A
August 17 AAECAR8engGoArUDxwOHBMkErgaKB+UHlwjFCNsJ/gyY8AKA8wKggAOnggObhQOghQP1iQPmlgP5lgO+mAO2nAP8owOfpQOipQOmpQOEpwOftwMAAA== Failure
December 01 AAECAZICDLQDrtICv/IC5PsC9fwC2p0D+KEDyKID3KID9KID/bYD1dIDCUBWX/4B0wPEBqmiA++iA9mpAwA= Failure
December 30 AAECAaIHHrQBsgLtAs0DrwSIB8f4AqCAA7SGA7SRA4+XA5CXA5KXA/uaA/6aA/yjA4SnA/WnA7euA7muA8GuA/6uA6qvA86vA/2wA4KxA5GxA+O0A5+3A8vAAwAA Failure

I'm not sure if this is because Blizzard modified the algorithm. Could anyone help me?

SyntaxError: Unexpected token import

hi, i get this error when attempting to run the example code? i ran the install command and created a index.js file with the example code but get the following error

/Users/michael/node/deckstrings-test/index.js:1
(function (exports, require, module, __filename, __dirname) { import {encode, decode} from "deckstrings";
                                                              ^^^^^^
SyntaxError: Unexpected token import
    at Object.exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:513:28)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Function.Module.runMain (module.js:575:10)
    at startup (node.js:160:18)
    at node.js:449:3

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.