EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DestinyBinDump.cpp
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: Zhur
24  Rewrite: Allan
25 */
26 
27 #include "eve-common.h"
28 
29 #include "destiny/DestinyBinDump.h"
30 
31 namespace Destiny {
32 
33  const char *const modeNames[] = {
34  "GOTO",
35  "FOLLOW",
36  "STOP",
37  "WARP",
38  "ORBIT",
39  "MISSILE",
40  "MUSHROOM",
41  "BOID",
42  "TROLL",
43  "MINIBALL",
44  "FIELD",
45  "RIGID",
46  "FORMATION"
47  };
48 
49 void DumpUpdate(LogType into, const uint8 *data, uint32 len) {
50  const AddBall_header *global_head = (const AddBall_header *) data;
51  _log(into, "AddBall: packet_type: %u, len: %u, stamp: %u ", global_head->packet_type, len, global_head->stamp);
52  data += sizeof(AddBall_header);
53  len -= sizeof(AddBall_header);
54 
55  while(len > 0) {
56  uint32 used = DumpBall(into, data, len);
57  if (used == 0)
58  return; //error
59  data += used;
60  len -= used;
61  }
62 }
63 
64 uint32 DumpBall(LogType into, const uint8 *data, uint32 len) {
65  uint32 init_len = len;
66 
67  const BallHeader *ballhead = (const BallHeader *) data;
68  data += sizeof(BallHeader);
69  len -= sizeof(BallHeader);
70 
71  if ((ballhead->entityID == 0) or (ballhead->entityID > 2147483647)) { // max int32
72  _log(into, "Error: Invalid entityID for ball %li", ballhead->entityID);
73  return 0;
74  }
75 
76  if (ballhead->mode > MAX_DSTBALL) {
77  _log(into, "Error: Invalid ball mode %u for ball %li", ballhead->mode, ballhead->entityID);
78  return 0;
79  }
80 
81  /* not used yet.
82  const NameStruct *name = (const NameStruct *) data;
83  data += sizeof(NameStruct);
84  len -= sizeof(NameStruct);
85  if (name->name_len > 0) {
86  _log(into, " Name: len: %u", name->name_len);
87  _log(into, " ~ %s", name->name);
88 
89  data += name->name_len*sizeof(uint16);
90  len -= name->name_len*sizeof(uint16);
91  }
92  */
93  _log(into, "entity: %li, mode: %s(%u) flags: %s", ballhead->entityID, modeNames[ballhead->mode], ballhead->mode, Destiny::GetFlagNames(ballhead->flags).c_str());
94  _log(into, " pos: %.2f, %.2f, %.2f, radius: %.1f", ballhead->posX, ballhead->posY, ballhead->posZ, ballhead->radius);
95 
96  if (ballhead->mode != Ball::Mode::RIGID) {
97  const MassSector *masschunk = (const MassSector *) data;
98  data += sizeof(MassSector);
99  len -= sizeof(MassSector);
100 
101  _log(into, " mass: %.2f, cloak: %u, harmonic: %i, corp: %i, alliance: %li" ,
102  masschunk->mass, masschunk->cloak, masschunk->harmonic, masschunk->corporationID, masschunk->allianceID);
103  }
104 
105  //this seems a little strange, but this is how it works...
106  if ((ballhead->flags & Ball::Flag::IsFree) == Ball::Flag::IsFree) {
107  const DataSector *shipchunk = (const DataSector *) data;
108  data += sizeof(DataSector);
109  len -= sizeof(DataSector);
110 
111  _log(into, " maxSpeed: %.2f, Velocity: %.2f, %.2f, %.2f IM: %.4f, SF: %.3f",
112  shipchunk->maxSpeed,
113  shipchunk->velX, shipchunk->velY, shipchunk->velZ,
114  shipchunk->inertia,
115  shipchunk->speedfraction);
116  }
117 
118  _log(into, " %s:", modeNames[ballhead->mode]);
119  switch(ballhead->mode) {
120  case Ball::Mode::BOID:
121  case Ball::Mode::MINIBALL: {
122  _log(into, " This is not coded (or correct) yet.");
123  return 0;
124  } break;
125  case Ball::Mode::GOTO: {
126  const GOTO_Struct *b = (const GOTO_Struct *) data;
127  data += sizeof(GOTO_Struct);
128  len -= sizeof(GOTO_Struct);
129  _log(into, " formID: %u, direction: %.2f, %.2f, %.2f", b->formationID, b->x, b->y, b->z);
130  } break;
131  case Ball::Mode::FOLLOW: {
132  const FOLLOW_Struct *b = (const FOLLOW_Struct *) data;
133  data += sizeof(FOLLOW_Struct);
134  len -= sizeof(FOLLOW_Struct);
135  _log(into, " formID: %u, followID: %li, distance: %.1f", b->formationID, b->followID, b->followRange);
136  } break;
137  case Ball::Mode::STOP: {
138  const STOP_Struct *b = (const STOP_Struct *) data;
139  data += sizeof(STOP_Struct);
140  len -= sizeof(STOP_Struct);
141  _log(into, " formID: %u ", b->formationID);
142  } break;
143  case Ball::Mode::WARP: {
144  const WARP_Struct *b = (const WARP_Struct *) data;
145  data += sizeof(WARP_Struct);
146  len -= sizeof(WARP_Struct);
147  _log(into, " formID: %u, TargPt: %.2f, %.2f, %.2f start: %i", b->formationID, b->targX, b->targY, b->targZ, b->effectStamp);
148  _log(into, " followRange: %li, followID: %li, warpSpeed: %i", b->followRange, b->followID, b->speed);
149  } break;
150  case Ball::Mode::ORBIT: {
151  const ORBIT_Struct *b = (const ORBIT_Struct *) data;
152  data += sizeof(ORBIT_Struct);
153  len -= sizeof(ORBIT_Struct);
154  _log(into, " formID: %u, targetID: %u, distance: %.1f", b->formationID, b->targetID, b->followRange);
155  } break;
156  case Ball::Mode::MISSILE: {
157  const MISSILE_Struct *b = (const MISSILE_Struct *) data;
158  data += sizeof(MISSILE_Struct);
159  len -= sizeof(MISSILE_Struct);
160  _log(into, " formID: %u, targetID: %li, followRange: %.1f, ownerID: %li, start: %i", b->formationID, b->targetID, b->followRange, b->ownerID, b->effectStamp);
161  _log(into, " pos: %.2f, %.2f, %.2f", b->x, b->y, b->z);
162  } break;
163  case Ball::Mode::MUSHROOM: {
164  const MUSHROOM_Struct *b = (const MUSHROOM_Struct *) data;
165  data += sizeof(MUSHROOM_Struct);
166  len -= sizeof(MUSHROOM_Struct);
167  _log(into, " formID: %u, distance: %.2f, u125: %.3f, start: %i, ownerID: %li", b->formationID, b->followRange, b->unknown125, b->effectStamp, b->ownerID);
168  } break;
169  case Ball::Mode::TROLL: {
170  const TROLL_Struct *b = (const TROLL_Struct *) data;
171  data += sizeof(TROLL_Struct);
172  len -= sizeof(TROLL_Struct);
173  _log(into, " formID: %u, start: %i", b->formationID, b->effectStamp);
174  } break;
175  case Ball::Mode::FIELD: {
176  const FIELD_Struct *b = (const FIELD_Struct *) data;
177  data += sizeof(FIELD_Struct);
178  len -= sizeof(FIELD_Struct);
179  _log(into, " formID: %u ", b->formationID);
180  } break;
181  case Ball::Mode::RIGID: {
182  const RIGID_Struct *b = (const RIGID_Struct *) data;
183  data += sizeof(RIGID_Struct);
184  len -= sizeof(RIGID_Struct);
185  _log(into, " formID: %u ", b->formationID);
186  } break;
187  case Ball::Mode::FORMATION: { // not used
188  const FORMATION_Struct *b = (const FORMATION_Struct *) data;
189  data += sizeof(FORMATION_Struct);
190  len -= sizeof(FORMATION_Struct);
191  _log(into, " formID: %u, followID: %li, followRange: %.2f, start: %i", b->formationID, b->followID, b->followRange, b->effectStamp);
192  } break;
193  default:
194  _log(into, "Error: Unknown ball mode %u!", ballhead->mode);
195  _hex(into, data-sizeof(BallHeader), (len>128)?128:(len+sizeof(BallHeader)));
196  return 0;
197  }
198 
199  /*
200  if (ballhead->flags & HasMiniBalls) {
201  const MiniBallList* mbl = (const MiniBallList*)data;
202  data += sizeof( MiniBallList );
203  len -= sizeof( MiniBallList );
204 
205  if (mbl->count) {
206  _log( into, " MiniBall Count: %d", mbl->count );
207  for( uint16 r = 0; r < mbl->count; ++r ) {
208  const MiniBall* mini = (const MiniBall*)data;
209  data += sizeof( MiniBall );
210  len -= sizeof( MiniBall );
211  _log( into, " [%d] pos=(%.3f, %.3f, %.3f) radius: %.2f", r, mini->x, mini->y, mini->z, mini->radius );
212  }
213  }
214  }
215  */
216  if (len > init_len) {
217  _log(into, "ERROR: Consumed more bytes than given: had %u, used %u", init_len, len);
218  return init_len;
219  }
220  return init_len - len;
221 }
222 
223 std::string GetFlagNames(uint8 flags)
224 {
225  std::string res = "";
226  if (flags & Ball::Flag::IsFree) {
227  res += "IsFree";
228  if (flags > Ball::Flag::IsFree)
229  res += ", ";
230  }
231  if (flags & Ball::Flag::IsGlobal) {
232  res += "IsGlobal";
233  if (flags > Ball::Flag::IsGlobal)
234  res += ", ";
235  }
236  if (flags & Ball::Flag::IsMassive) {
237  res += "IsMassive";
238  if (flags > Ball::Flag::IsMassive)
239  res += ", ";
240  }
241  if (flags & Ball::Flag::IsInteractive) {
242  res += "IsInteractive";
243  if (flags > Ball::Flag::IsInteractive)
244  res += ", ";
245  }
246  if (flags & Ball::Flag::IsMoribund) {
247  res += "IsMoribund";
248  if (flags > Ball::Flag::IsMoribund)
249  res += ", ";
250  }
251  if (flags & Ball::Flag::HasMiniBalls)
252  res += "HasMiniBalls";
253 
254  res += "(";
255  res += std::to_string(flags);
256  res += ")";
257  return res;
258 }
259 
260 }
unsigned __int8 uint8
Definition: eve-compat.h:46
#define _log(type, fmt,...)
Definition: logsys.h:124
static const uint8 MAX_DSTBALL
#define _hex(type, data, len)
Definition: logsys.h:133
uint32 DumpBall(LogType into, const uint8 *data, uint32 len)
unsigned __int32 uint32
Definition: eve-compat.h:50
LogType
Definition: logsys.h:59
void DumpUpdate(LogType into, const uint8 *data, uint32 len)
std::string GetFlagNames(uint8 flags)
const char *const modeNames[]