@@ -2,35 +2,22 @@ import { b64Decode } from "../utils";
22import { requestMessagesResponses } from "../constants" ;
33import { DecodedProto } from "../types" ;
44
5- // For decode dynamics action social.
65let action_social = 0 ;
7- /**
8- * Callback as used by {@link DecoderInternalPayloadAsResponse}.
9- * @type {function }
10- * @param {number|any }
11- */
12- /**
13- * Returns decoded proto as JSON. Uses Tuples by https://github.com/Furtif/pogo-protos/blob/master/test/test.js, if that implemented.
14- */
156function DecoderInternalPayloadAsResponse ( method : number , data : any ) : any {
16- // Reset value.
177 action_social = 0 ;
188 let proto_tuple : any = Object . values ( requestMessagesResponses ) [ method ] ;
199 let result : any = { Not_Implemented_yet : data } ;
10+
11+ if ( ! data ) {
12+ return { } ;
13+ }
2014 for ( let i = 0 ; i < Object . keys ( requestMessagesResponses ) . length ; i ++ ) {
2115 proto_tuple = Object . values ( requestMessagesResponses ) [ i ] ;
2216 const my_req = proto_tuple [ 0 ] ;
2317 if ( my_req == method ) {
24- if ( proto_tuple [ 2 ] != null && b64Decode ( data ) ) {
18+ if ( proto_tuple [ 2 ] != null && data && b64Decode ( data ) . length > 0 ) {
2519 try {
2620 result = proto_tuple [ 2 ] . decode ( b64Decode ( data ) ) . toJSON ( ) ;
27- /*
28- // This not need more because protos as replaced bytes for the proto.
29- if (method == 10010) {
30- let profile = POGOProtos.Rpc.PlayerPublicProfileProto.decode(b64Decode(result.friend[0].player.public_data)).toJSON();
31- result.friend[0].player.public_data = profile;
32- }
33- */
3421 }
3522 catch ( error ) {
3623 console . error ( `Intenal ProxySocial decoder ${ my_req } Error: ${ error } ` ) ;
@@ -85,14 +72,22 @@ export const decodePayload = (contents: any, dataType: string): DecodedProto[] =
8572
8673export const decodeProto = ( method : number , data : string , dataType : string ) : DecodedProto | string => {
8774 let returnObject : DecodedProto | string = "Not Found" ;
75+ let methodFound = false ;
76+
8877 for ( let i = 0 ; i < Object . keys ( requestMessagesResponses ) . length ; i ++ ) {
8978 let foundMethod : any = Object . values ( requestMessagesResponses ) [ i ] ;
9079 let foundMethodString : string = Object . keys ( requestMessagesResponses ) [ i ] ;
9180 const foundReq = foundMethod [ 0 ] ;
9281 if ( foundReq == method ) {
82+ methodFound = true ;
9383 if ( foundMethod [ 1 ] != null && dataType === "request" ) {
9484 try {
95- let parsedData = foundMethod [ 1 ] . decode ( b64Decode ( data ) ) . toJSON ( ) ;
85+ let parsedData ;
86+ if ( ! data || data === "" ) {
87+ parsedData = { } ;
88+ } else {
89+ parsedData = foundMethod [ 1 ] . decode ( b64Decode ( data ) ) . toJSON ( ) ;
90+ }
9691 if ( foundMethod [ 0 ] === 5012 || foundMethod [ 0 ] === 600005 ) {
9792 action_social = parsedData . action ;
9893 Object . values ( requestMessagesResponses ) . forEach ( val => {
@@ -109,13 +104,35 @@ export const decodeProto = (method: number, data: string, dataType: string): Dec
109104 } ;
110105 } catch ( error ) {
111106 console . error ( `Error parsing request ${ foundMethodString } -> ${ error } ` ) ;
107+ returnObject = {
108+ methodId : foundMethod [ 0 ] ,
109+ methodName : remasterOrCleanMethodString ( foundMethodString ) + " [PARSE ERROR]" ,
110+ data : {
111+ error : "Failed to decode proto" ,
112+ rawBase64 : data ,
113+ errorMessage : error . toString ( )
114+ } ,
115+ } ;
112116 }
113117 } else if ( dataType === "request" ) {
114118 console . warn ( `Request ${ foundMethod [ 0 ] } Not Implemented` )
119+ returnObject = {
120+ methodId : foundMethod [ 0 ] ,
121+ methodName : remasterOrCleanMethodString ( foundMethodString ) + " [NOT IMPLEMENTED]" ,
122+ data : {
123+ error : "Proto not implemented" ,
124+ rawBase64 : data
125+ } ,
126+ } ;
115127 }
116128 if ( foundMethod [ 2 ] != null && dataType === "response" ) {
117129 try {
118- let parsedData = foundMethod [ 2 ] . decode ( b64Decode ( data ) ) . toJSON ( ) ;
130+ let parsedData ;
131+ if ( ! data || data === "" ) {
132+ parsedData = { } ;
133+ } else {
134+ parsedData = foundMethod [ 2 ] . decode ( b64Decode ( data ) ) . toJSON ( ) ;
135+ }
119136 if ( foundMethod [ 0 ] === 5012 && action_social > 0 && parsedData . payload ) {
120137 parsedData . payload = DecoderInternalPayloadAsResponse ( action_social , parsedData . payload ) ;
121138 }
@@ -129,11 +146,40 @@ export const decodeProto = (method: number, data: string, dataType: string): Dec
129146 } ;
130147 } catch ( error ) {
131148 console . error ( `Error parsing response ${ foundMethodString } method: [${ foundReq } ] -> ${ error } ` ) ;
149+ returnObject = {
150+ methodId : foundMethod [ 0 ] ,
151+ methodName : remasterOrCleanMethodString ( foundMethodString ) + " [PARSE ERROR]" ,
152+ data : {
153+ error : "Failed to decode proto" ,
154+ rawBase64 : data ,
155+ errorMessage : error . toString ( )
156+ } ,
157+ } ;
132158 }
133159 } else if ( dataType === "response" ) {
134160 console . warn ( `Response ${ foundReq } Not Implemented` )
161+ returnObject = {
162+ methodId : foundMethod [ 0 ] ,
163+ methodName : remasterOrCleanMethodString ( foundMethodString ) + " [NOT IMPLEMENTED]" ,
164+ data : {
165+ error : "Proto not implemented" ,
166+ rawBase64 : data
167+ } ,
168+ } ;
135169 }
136170 }
137171 }
172+
173+ if ( ! methodFound && returnObject === "Not Found" ) {
174+ returnObject = {
175+ methodId : method . toString ( ) ,
176+ methodName : `Unknown Method ${ method } [UNKNOWN]` ,
177+ data : {
178+ error : "Unknown method ID" ,
179+ rawBase64 : data
180+ } ,
181+ } ;
182+ }
183+
138184 return returnObject ;
139185} ;
0 commit comments