From 6d88e3bee20e44c0ba39889e47c17cd5681a5421 Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Sat, 25 Jul 2020 19:54:32 +0100 Subject: [PATCH] Adding waypoint stuff, and a some sanity checks (need a lot more) --- d2waypoints.c | 20 ++++++++++++++++++++ d2waypoints.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 0 deletions(-) create mode 100644 d2waypoints.c create mode 100644 d2waypoints.h diff --git a/d2waypoints.c b/d2waypoints.c new file mode 100644 index 0000000..e7322ab --- /dev/null +++ b/d2waypoints.c @@ -0,0 +1,20 @@ +#include "d2waypoints.h" + +int isWaypointActivated(D2WaypointsData* d, unsigned int waypoint, unsigned int difficulty) { + if(waypoint > D2S_WAYPOINTSDATA_NUMWAYPOINTS) { + return -1; + } + unsigned int byte = waypoint / 8; + unsigned int offset = waypoint % 8; + return (d->waypoints[difficulty].waypointData[byte] & (1 << offset)) >> offset; +} + +// TODO: Return success +void setWaypointActivated(D2WaypointsData* d, unsigned int waypoint, unsigned int difficulty, int activated) { + if(waypoint > D2S_WAYPOINTSDATA_NUMWAYPOINTS) { + return; + } + unsigned int byte = waypoint / 8; + unsigned int offset = waypoint % 8; + d->waypoints[difficulty].waypointData[byte] |= (1 << offset); +} \ No newline at end of file diff --git a/d2waypoints.h b/d2waypoints.h new file mode 100644 index 0000000..c5172ee --- /dev/null +++ b/d2waypoints.h @@ -0,0 +1,70 @@ +#ifndef D2WAYPOINTS_H +#define D2WAYPOINTS_H + +#include + +#include "d2strings.h" + +#define D2S_WAYPOINTSDATA_HEADER_LENGTH 2 +#define D2S_WAYPOINTSDATA_LENGTH 5 +#define D2S_WAYPOINTSDATA_NUMWAYPOINTS 39 + +const char* const waypoints[] = { + D2S_WAYPOINT_0, + D2S_WAYPOINT_1, + D2S_WAYPOINT_2, + D2S_WAYPOINT_3, + D2S_WAYPOINT_4, + D2S_WAYPOINT_5, + D2S_WAYPOINT_6, + D2S_WAYPOINT_7, + D2S_WAYPOINT_8, + D2S_WAYPOINT_9, + D2S_WAYPOINT_10, + D2S_WAYPOINT_11, + D2S_WAYPOINT_12, + D2S_WAYPOINT_13, + D2S_WAYPOINT_14, + D2S_WAYPOINT_15, + D2S_WAYPOINT_16, + D2S_WAYPOINT_17, + D2S_WAYPOINT_18, + D2S_WAYPOINT_19, + D2S_WAYPOINT_20, + D2S_WAYPOINT_21, + D2S_WAYPOINT_22, + D2S_WAYPOINT_23, + D2S_WAYPOINT_24, + D2S_WAYPOINT_25, + D2S_WAYPOINT_26, + D2S_WAYPOINT_27, + D2S_WAYPOINT_28, + D2S_WAYPOINT_29, + D2S_WAYPOINT_30, + D2S_WAYPOINT_31, + D2S_WAYPOINT_32, + D2S_WAYPOINT_33, + D2S_WAYPOINT_34, + D2S_WAYPOINT_35, + D2S_WAYPOINT_36, + D2S_WAYPOINT_37, + D2S_WAYPOINT_38 +}; + +typedef struct __attribute__((packed)) { + uint16_t unknown1; // Apparently, always 0x0201 + uint8_t waypointData[D2S_WAYPOINTSDATA_LENGTH]; + uint8_t unknown2[17]; +} D2Waypoints; + +typedef struct __attribute__((packed)) { + const char* header[D2S_WAYPOINTSDATA_HEADER_LENGTH]; // WS + uint32_t unknown1; // This is likely version data + uint16_t size; // in bytes + D2Waypoints waypoints[3]; // 1 set for each difficulty +} D2WaypointsData; + +int isWaypointActivated(D2WaypointsData* d, unsigned int waypoint, unsigned int difficulty); +void setWaypointActivated(D2WaypointsData* d, unsigned int waypoint, unsigned int difficulty, int activated); + +#endif \ No newline at end of file -- libgit2 0.22.2