Commit 6d88e3bee20e44c0ba39889e47c17cd5681a5421

Authored by Imanol-Mikel Barba Sabariego
1 parent 9debe0f4

Adding waypoint stuff, and a some sanity checks (need a lot more)

Showing 2 changed files with 90 additions and 0 deletions
d2waypoints.c 0 → 100644
  1 +#include "d2waypoints.h"
  2 +
  3 +int isWaypointActivated(D2WaypointsData* d, unsigned int waypoint, unsigned int difficulty) {
  4 + if(waypoint > D2S_WAYPOINTSDATA_NUMWAYPOINTS) {
  5 + return -1;
  6 + }
  7 + unsigned int byte = waypoint / 8;
  8 + unsigned int offset = waypoint % 8;
  9 + return (d->waypoints[difficulty].waypointData[byte] & (1 << offset)) >> offset;
  10 +}
  11 +
  12 +// TODO: Return success
  13 +void setWaypointActivated(D2WaypointsData* d, unsigned int waypoint, unsigned int difficulty, int activated) {
  14 + if(waypoint > D2S_WAYPOINTSDATA_NUMWAYPOINTS) {
  15 + return;
  16 + }
  17 + unsigned int byte = waypoint / 8;
  18 + unsigned int offset = waypoint % 8;
  19 + d->waypoints[difficulty].waypointData[byte] |= (1 << offset);
  20 +}
0 \ No newline at end of file 21 \ No newline at end of file
d2waypoints.h 0 → 100644
  1 +#ifndef D2WAYPOINTS_H
  2 +#define D2WAYPOINTS_H
  3 +
  4 +#include <stdint.h>
  5 +
  6 +#include "d2strings.h"
  7 +
  8 +#define D2S_WAYPOINTSDATA_HEADER_LENGTH 2
  9 +#define D2S_WAYPOINTSDATA_LENGTH 5
  10 +#define D2S_WAYPOINTSDATA_NUMWAYPOINTS 39
  11 +
  12 +const char* const waypoints[] = {
  13 + D2S_WAYPOINT_0,
  14 + D2S_WAYPOINT_1,
  15 + D2S_WAYPOINT_2,
  16 + D2S_WAYPOINT_3,
  17 + D2S_WAYPOINT_4,
  18 + D2S_WAYPOINT_5,
  19 + D2S_WAYPOINT_6,
  20 + D2S_WAYPOINT_7,
  21 + D2S_WAYPOINT_8,
  22 + D2S_WAYPOINT_9,
  23 + D2S_WAYPOINT_10,
  24 + D2S_WAYPOINT_11,
  25 + D2S_WAYPOINT_12,
  26 + D2S_WAYPOINT_13,
  27 + D2S_WAYPOINT_14,
  28 + D2S_WAYPOINT_15,
  29 + D2S_WAYPOINT_16,
  30 + D2S_WAYPOINT_17,
  31 + D2S_WAYPOINT_18,
  32 + D2S_WAYPOINT_19,
  33 + D2S_WAYPOINT_20,
  34 + D2S_WAYPOINT_21,
  35 + D2S_WAYPOINT_22,
  36 + D2S_WAYPOINT_23,
  37 + D2S_WAYPOINT_24,
  38 + D2S_WAYPOINT_25,
  39 + D2S_WAYPOINT_26,
  40 + D2S_WAYPOINT_27,
  41 + D2S_WAYPOINT_28,
  42 + D2S_WAYPOINT_29,
  43 + D2S_WAYPOINT_30,
  44 + D2S_WAYPOINT_31,
  45 + D2S_WAYPOINT_32,
  46 + D2S_WAYPOINT_33,
  47 + D2S_WAYPOINT_34,
  48 + D2S_WAYPOINT_35,
  49 + D2S_WAYPOINT_36,
  50 + D2S_WAYPOINT_37,
  51 + D2S_WAYPOINT_38
  52 +};
  53 +
  54 +typedef struct __attribute__((packed)) {
  55 + uint16_t unknown1; // Apparently, always 0x0201
  56 + uint8_t waypointData[D2S_WAYPOINTSDATA_LENGTH];
  57 + uint8_t unknown2[17];
  58 +} D2Waypoints;
  59 +
  60 +typedef struct __attribute__((packed)) {
  61 + const char* header[D2S_WAYPOINTSDATA_HEADER_LENGTH]; // WS
  62 + uint32_t unknown1; // This is likely version data
  63 + uint16_t size; // in bytes
  64 + D2Waypoints waypoints[3]; // 1 set for each difficulty
  65 +} D2WaypointsData;
  66 +
  67 +int isWaypointActivated(D2WaypointsData* d, unsigned int waypoint, unsigned int difficulty);
  68 +void setWaypointActivated(D2WaypointsData* d, unsigned int waypoint, unsigned int difficulty, int activated);
  69 +
  70 +#endif
0 \ No newline at end of file 71 \ No newline at end of file