Skip to content

Commit

Permalink
Major upgrade to the cell s2 system
Browse files Browse the repository at this point in the history
  • Loading branch information
d-pollard committed Jul 22, 2016
1 parent 1855d77 commit 526d671
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 59 deletions.
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
"name": "pokemon-go-node-api",
"version": "1.2.5",
"description": "Pokemon GO node.js module",
"author": "Arm4x",
"author": "Derek M.F. P",
"license": "MIT",
"main": "poke.io.js",
"dependencies": {
"bignum": "^0.12.5",
"events": "^1.1.1",
"geocoder": "^0.2.2",
"gpsoauthnode": "^0.0.5",
"istanbul": "^0.4.4",
"protobufjs": "^5.0.1",
"simple-s2-node": "^0.0.2",
"request": "^2.73.0",
"s2geometry-node": "^1.1.0",
"tape": "^4.6.0"
},
"devDependencies": {},
Expand All @@ -22,7 +21,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/Armax/Pokemon-GO-node-api"
"url": "https://github.com/d-pollard/Pokemon-GO-node-api"
},
"keywords": [
"pokemon",
Expand Down
76 changes: 51 additions & 25 deletions poke.io.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ const ProtoBuf = require('protobufjs');
const GoogleOAuth = require('gpsoauthnode');
const Long = require('long');
const ByteBuffer = require('bytebuffer');
const bignum = require('bignum');

const s2 = require('simple-s2-node');
const s2 = require('s2geometry-node');
const Logins = require('./logins');
const fs = require('fs');
const pokemonlist = JSON.parse(fs.readFileSync(__dirname + '/pokemons.json', 'utf8'));

let builder = ProtoBuf.loadProtoFile('pokemon.proto');
if (builder === null) {
builder = ProtoBuf.loadProtoFile(__dirname + '/pokemon.proto');
builder = ProtoBuf.loadProtoFile(__dirname + '/pokemon2.proto');

This comment has been minimized.

Copy link
@tuxity

tuxity Jul 22, 2016

Should be builder = ProtoBuf.loadProtoFile(__dirname + '/pokemon.proto'); here

This comment has been minimized.

Copy link
@d-pollard

d-pollard Jul 22, 2016

Author Owner

Oops, yeah I must have been testing some other proto out

}

const pokemonProto = builder.build();

This comment has been minimized.

Copy link
@FabioAntunes

FabioAntunes Jul 22, 2016

This gives me an error:

const pokemonProto = builder.build();
                            ^

TypeError: Cannot read property 'build' of null
Expand All @@ -31,8 +30,9 @@ function GetCoords(self) {
return [latitude, longitude];
};


function getNeighbors(lat, lng) {
var origin = s2.S2CellId.from_lat_lng(s2.S2LatLng.from_degrees(lat, lng)).parent(15);
var origin = new s2.S2CellId(new s2.S2LatLng(lat, lng)).parent(15);
var walk = [origin.id()];
// 10 before and 10 after
var next = origin.next();
Expand Down Expand Up @@ -238,45 +238,34 @@ function Pokeio() {
self.Heartbeat = function (callback) {
let {apiEndpoint, accessToken} = self.playerInfo;

let nullbytes = new Buffer(21);

var nullbytes = new Array(21);
nullbytes.fill(0);

// Generating walk data using s2 geometry
var walk = getNeighbors(self.playerInfo.latitude, self.playerInfo.longitude).sort((a, b) => {
return a.cmp(b);
});
var buffer = new ByteBuffer(21 * 10).LE();
walk.forEach((elem) => {
buffer.writeVarint64(s2.S2Utils.long_from_bignum(elem));
var walk = getNeighbors(self.playerInfo.latitude, self.playerInfo.longitude).sort(function (a, b) {
return a > b;
});

// Creating MessageQuad for Requests type=106
buffer.flip();
var walkData = new RequestEnvelop.MessageQuad({
'f1': buffer.toBuffer(),
'f1': walk,
'f2': nullbytes,
'lat': self.playerInfo.latitude,
'long': self.playerInfo.longitude
});

var req = [
new RequestEnvelop.Requests(106, walkData.encode().toBuffer()),
new RequestEnvelop.Requests(126),
new RequestEnvelop.Requests(4, (new RequestEnvelop.Unknown3(Date.now().toString())).encode().toBuffer()),
new RequestEnvelop.Requests(129),
new RequestEnvelop.Requests(5, (new RequestEnvelop.Unknown3('05daf51635c82611d1aac95c0b051d3ec088a930')).encode().toBuffer())
];
var req = [new RequestEnvelop.Requests(106, walkData.encode().toBuffer()), new RequestEnvelop.Requests(126), new RequestEnvelop.Requests(4, new RequestEnvelop.Unknown3(Date.now().toString()).encode().toBuffer()), new RequestEnvelop.Requests(129), new RequestEnvelop.Requests(5, new RequestEnvelop.Unknown3('05daf51635c82611d1aac95c0b051d3ec088a930').encode().toBuffer())];

api_req(apiEndpoint, accessToken, req, function (err, f_ret) {
if (err) {
return callback(err);
}
else if (!f_ret || !f_ret.payload || !f_ret.payload[0]) {
} else if (!f_ret || !f_ret.payload || !f_ret.payload[0]) {
return callback('No result');
}

var heartbeat = ResponseEnvelop.HeartbeatPayload.decode(f_ret.payload[0]);
callback(null, heartbeat)
callback(null, heartbeat);
});
};

Expand All @@ -299,7 +288,7 @@ function Pokeio() {
'spawnpoint_id': mapPokemon.SpawnPointId,
'hit_pokemon': true,
'spin_modifier': 1,
'normalized_hit_position': 1
'normalized_hit_position': 2
});

var req = new RequestEnvelop.Requests(103, catchPokemon.encode().toBuffer());
Expand All @@ -319,11 +308,12 @@ function Pokeio() {
};

self.EncounterPokemon = function (catchablePokemon, callback) {
// console.log(catchablePokemon);
let {apiEndpoint, accessToken, latitude, longitude} = self.playerInfo;

var encounterPokemon = new RequestEnvelop.EncounterMessage({
'encounter_id': catchablePokemon.EncounterId,
'spawn_point_id': catchablePokemon.SpawnPointId,
'spawnpoint_id': catchablePokemon.SpawnPointId,
'player_latitude': latitude,
'player_longitude': longitude
});
Expand Down Expand Up @@ -391,6 +381,42 @@ function Pokeio() {
});
}
};

self.changePosition = function () {
self.playerInfo.longitude = self.playerInfo.longitude + 0.000055;
self.playerInfo.latitude = self.playerInfo.latitude + 0.000055;
return true;
};

self.hatchEggs = function(cb) {
self.changePosition();
self.Heartbeat(cb);
};

self.GetFort = function(fortid, fortlat, fortlong, callback) {
var FortMessage = new RequestEnvelop.FortSearchMessage({
'fort_id': fortid,
'player_latitude': fortlat,
'player_longitude': fortlong,
'fort_latitude': fortlat,
'fort_longitude': fortlong
});

// console.log(FortMessage);

var req = new RequestEnvelop.Requests(101, FortMessage.encode().toBuffer());

api_req(self.playerInfo.apiEndpoint, self.playerInfo.accessToken, req, function (err, f_ret) {
if (err) {
return callback(err);
} else if (!f_ret || !f_ret.payload || !f_ret.payload[0]) {
return callback('No result');
}

var FortSearchResponse = ResponseEnvelop.FortSearchResponse.decode(f_ret.payload[0]);
callback(null, FortSearchResponse);
});
}
}

module.exports = new Pokeio();
Expand Down
85 changes: 55 additions & 30 deletions pokemon.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,35 @@ message RequestEnvelop {
}

message MessageQuad {
repeated bytes f1 = 1;
required bytes f2 = 2;
repeated uint64 f1 = 1 [packed=true];
repeated int64 f2 = 2 [packed=true];
required double lat = 3;
required double long = 4;
}
message EncounterMessage {
repeated fixed64 encounter_id = 1;
required string spawn_point_id = 2;
required double player_latitude = 3;
required double player_longitude = 4;
}

message CatchPokemonMessage {
repeated fixed64 encounter_id = 1;
required fixed64 encounter_id = 1;
required int32 pokeball = 2;
required double normalized_reticle_size = 3;
required string spawnpoint_id = 4;
required bool hit_pokemon = 5;
required double spin_modifier = 6;
required double normalized_hit_position = 7;
}

message EncounterMessage {
repeated fixed64 encounter_id = 1;
required string spawnpoint_id = 2;
required double player_latitude = 3;
required double player_longitude = 4;
}

message FortSearchMessage {
required string fort_id = 1;
required double player_latitude = 2;
required double player_longitude = 3;
required double fort_latitude = 4;
required double fort_longitude = 5;
}
}

Expand Down Expand Up @@ -888,27 +898,19 @@ message ResponseEnvelop {
CHECKPOINT = 1;
}


message CatchPokemonResponse {
optional CatchStatus status = 1;
optional double miss_percent = 2;
// optional uint64 captured_pokemon_id = 3;
// optional CaptureScore scores = 4;

enum CatchStatus {
CATCH_ERROR = 0;
CATCH_SUCCESS = 1;
CATCH_ESCAPE = 2;
CATCH_FLEE = 3;
CATCH_MISSED = 4;
}
}

message CaptureScore {
repeated ActivityType activity_type = 1;
repeated int32 xp = 2;
repeated int32 candy = 3;
repeated int32 stardust = 4;
optional CatchStatus Status = 1;
optional double MissPercent = 2;
// optional uint64 CapturedPokemonId = 3;
optional CaptureAward CaptureAward = 4;

enum CatchStatus {
CATCH_ERROR = 0;
CATCH_SUCCESS = 1;
CATCH_ESCAPE = 2;
CATCH_FLEE = 3;
CATCH_MISSED = 4;
}
}

enum ActivityType {
Expand Down Expand Up @@ -955,7 +957,7 @@ message ResponseEnvelop {
optional WildPokemonProto WildPokemon = 1;
optional Background EncounterBackground = 2;
optional Status EncounterStatus = 3;
// optional CaptureProbability EncounterCaptureProbability = 4;
//optional CaptureProbability EncounterCaptureProbability = 4;

enum Background {
PARK = 0;
Expand All @@ -973,4 +975,27 @@ message ResponseEnvelop {
POKEMON_INVENTORY_FULL = 7;
}
}

message FortSearchResponse {
optional Result result = 1;
repeated ItemAward items_awarded = 2;
optional int32 gems_awarded = 3;
optional PokemonData pokemon_data_egg = 4;
optional int32 experience_awarded = 5;
optional int64 cooldown_complete_timestamp_ms = 6;
optional int32 chain_hack_sequence_number = 7;

enum Result {
NO_RESULT_SET = 0;
SUCCESS = 1;
OUT_OF_RANGE = 2;
IN_COOLDOWN_PERIOD = 3;
INVENTORY_FULL = 4;
}
}

message ItemAward {
optional ItemId item_id = 1;
optional int32 item_count = 2;
}
}

14 comments on commit 526d671

@LASkuma
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What environment are you using? I can't compile s2geometry-node.

@d-pollard
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LASkuma - ubuntu with node v6.2.2, what version of node are you using?

@LASkuma
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried 4.x, 6.2.1 and 6.3.0. All of them don't work for me. The problem comes from isinf function inside of s2geometry-node. I've also tried a lot of different gcc and g++ versions but still no luck.

@d-pollard
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What OS are you on? If it's windows, I believe there might be an issue with the library for windows users, I will talk to the creator tomorrow (today) and take a look at it myself.

@LASkuma
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's Ubuntu. It seems that I can only run it on my mac.

@d-pollard
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's weird - I'm on ubuntu and I run it perfectly fine. Maybe try sudo npm install and then just npm install

@LASkuma
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What version of Ubuntu are you using? I'm using 16.04. I really think I should switch back to 14.04.

@d-pollard
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm on ubuntu 14.04

@LASkuma
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try 14.04 then.

@d-pollard
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know! Hopefully I'll have issues turned back on for this repo by tomorrow. Feel free to contribute.

@LASkuma
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course.

@LASkuma
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Built succeed from Ubuntu 14.04.

@vekexasia
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyone suceeded with ubuntu 16.04?

@xakiru
Copy link

@xakiru xakiru commented on 526d671 Aug 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still trying on ubuntu 16.04 with no luck...

Please sign in to comment.