about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--CMakeLists.txt7
-rw-r--r--ap_state.cpp40
-rw-r--r--ap_state.h2
-rw-r--r--game_data.cpp7
-rw-r--r--game_data.h1
6 files changed, 37 insertions, 21 deletions
diff --git a/.gitignore b/.gitignore index d008edb..a7cadc7 100644 --- a/.gitignore +++ b/.gitignore
@@ -2,3 +2,4 @@ build/
2builds/ 2builds/
3assets/LL1.yaml 3assets/LL1.yaml
4.DS_Store 4.DS_Store
5.vs
diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d9a111..fea5d7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -3,6 +3,11 @@ project (lingo_ap_tracker)
3 3
4set(CMAKE_BUILD_TYPE Debug) 4set(CMAKE_BUILD_TYPE Debug)
5 5
6if (MSVC)
7set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
8set(CMAKE_WIN32_EXECUTABLE true)
9endif(MSVC)
10
6find_package(wxWidgets CONFIG REQUIRED) 11find_package(wxWidgets CONFIG REQUIRED)
7find_package(OpenSSL REQUIRED) 12find_package(OpenSSL REQUIRED)
8find_package(yaml-cpp REQUIRED) 13find_package(yaml-cpp REQUIRED)
@@ -36,6 +41,6 @@ add_executable(lingo_ap_tracker
36 eye_indicator.cpp 41 eye_indicator.cpp
37 tracker_state.cpp 42 tracker_state.cpp
38) 43)
39set_property(TARGET lingo_ap_tracker PROPERTY CXX_STANDARD 17) 44set_property(TARGET lingo_ap_tracker PROPERTY CXX_STANDARD 20)
40set_property(TARGET lingo_ap_tracker PROPERTY CXX_STANDARD_REQUIRED ON) 45set_property(TARGET lingo_ap_tracker PROPERTY CXX_STANDARD_REQUIRED ON)
41target_link_libraries(lingo_ap_tracker PRIVATE OpenSSL::SSL OpenSSL::Crypto wx::core wx::base yaml-cpp) 46target_link_libraries(lingo_ap_tracker PRIVATE OpenSSL::SSL OpenSSL::Crypto wx::core wx::base yaml-cpp)
diff --git a/ap_state.cpp b/ap_state.cpp index 910feb7..2c8ba0a 100644 --- a/ap_state.cpp +++ b/ap_state.cpp
@@ -1,8 +1,12 @@
1#include "ap_state.h" 1#include "ap_state.h"
2 2
3#include <hkutil/string.h> 3#define HAS_STD_FILESYSTEM
4#define _WEBSOCKETPP_CPP11_STRICT_
5#pragma comment(lib, "crypt32")
4 6
7#include <apclient.hpp>
5#include <apuuid.hpp> 8#include <apuuid.hpp>
9#include <hkutil/string.h>
6#include <chrono> 10#include <chrono>
7#include <exception> 11#include <exception>
8#include <list> 12#include <list>
@@ -17,13 +21,15 @@ constexpr int AP_REVISION = 0;
17 21
18constexpr int ITEM_HANDLING = 7; // <- all 22constexpr int ITEM_HANDLING = 7; // <- all
19 23
24static APClient* apclient = nullptr;
25
20APState::APState() { 26APState::APState() {
21 std::thread([this]() { 27 std::thread([this]() {
22 for (;;) { 28 for (;;) {
23 { 29 {
24 std::lock_guard client_guard(client_mutex_); 30 std::lock_guard client_guard(client_mutex_);
25 if (apclient_) { 31 if (apclient) {
26 apclient_->poll(); 32 apclient->poll();
27 } 33 }
28 } 34 }
29 35
@@ -39,11 +45,13 @@ void APState::Connect(std::string server, std::string player,
39 { 45 {
40 std::lock_guard client_guard(client_mutex_); 46 std::lock_guard client_guard(client_mutex_);
41 47
42 if (apclient_) { 48 if (apclient) {
43 apclient_->reset(); 49 apclient->reset();
50 delete apclient;
51 apclient = nullptr;
44 } 52 }
45 53
46 apclient_ = std::make_unique<APClient>(ap_get_uuid(""), "Lingo", server); 54 apclient = new APClient(ap_get_uuid(""), "Lingo", server);
47 } 55 }
48 56
49 inventory_.clear(); 57 inventory_.clear();
@@ -52,15 +60,15 @@ void APState::Connect(std::string server, std::string player,
52 bool connected = false; 60 bool connected = false;
53 bool has_connection_result = false; 61 bool has_connection_result = false;
54 62
55 apclient_->set_room_info_handler([&]() { 63 apclient->set_room_info_handler([&]() {
56 tracker_frame_->SetStatusMessage( 64 tracker_frame_->SetStatusMessage(
57 "Connected to Archipelago server. Authenticating..."); 65 "Connected to Archipelago server. Authenticating...");
58 66
59 apclient_->ConnectSlot(player, password, ITEM_HANDLING, {"Tracker"}, 67 apclient->ConnectSlot(player, password, ITEM_HANDLING, {"Tracker"},
60 {AP_MAJOR, AP_MINOR, AP_REVISION}); 68 {AP_MAJOR, AP_MINOR, AP_REVISION});
61 }); 69 });
62 70
63 apclient_->set_location_checked_handler( 71 apclient->set_location_checked_handler(
64 [&](const std::list<int64_t>& locations) { 72 [&](const std::list<int64_t>& locations) {
65 for (const int64_t location_id : locations) { 73 for (const int64_t location_id : locations) {
66 checked_locations_.insert(location_id); 74 checked_locations_.insert(location_id);
@@ -70,15 +78,15 @@ void APState::Connect(std::string server, std::string player,
70 RefreshTracker(); 78 RefreshTracker();
71 }); 79 });
72 80
73 apclient_->set_slot_disconnected_handler([&]() { 81 apclient->set_slot_disconnected_handler([&]() {
74 tracker_frame_->SetStatusMessage("Disconnected from Archipelago."); 82 tracker_frame_->SetStatusMessage("Disconnected from Archipelago.");
75 }); 83 });
76 84
77 apclient_->set_socket_disconnected_handler([&]() { 85 apclient->set_socket_disconnected_handler([&]() {
78 tracker_frame_->SetStatusMessage("Disconnected from Archipelago."); 86 tracker_frame_->SetStatusMessage("Disconnected from Archipelago.");
79 }); 87 });
80 88
81 apclient_->set_items_received_handler( 89 apclient->set_items_received_handler(
82 [&](const std::list<APClient::NetworkItem>& items) { 90 [&](const std::list<APClient::NetworkItem>& items) {
83 for (const APClient::NetworkItem& item : items) { 91 for (const APClient::NetworkItem& item : items) {
84 // TODO: Progressive items. 92 // TODO: Progressive items.
@@ -90,7 +98,7 @@ void APState::Connect(std::string server, std::string player,
90 RefreshTracker(); 98 RefreshTracker();
91 }); 99 });
92 100
93 apclient_->set_slot_connected_handler([&](const nlohmann::json& slot_data) { 101 apclient->set_slot_connected_handler([&](const nlohmann::json& slot_data) {
94 tracker_frame_->SetStatusMessage("Connected to Archipelago!"); 102 tracker_frame_->SetStatusMessage("Connected to Archipelago!");
95 103
96 door_shuffle_mode_ = slot_data["shuffle_doors"].get<DoorShuffleMode>(); 104 door_shuffle_mode_ = slot_data["shuffle_doors"].get<DoorShuffleMode>();
@@ -100,7 +108,7 @@ void APState::Connect(std::string server, std::string player,
100 has_connection_result = true; 108 has_connection_result = true;
101 }); 109 });
102 110
103 apclient_->set_slot_refused_handler( 111 apclient->set_slot_refused_handler(
104 [&](const std::list<std::string>& errors) { 112 [&](const std::list<std::string>& errors) {
105 connected = false; 113 connected = false;
106 has_connection_result = true; 114 has_connection_result = true;
@@ -163,7 +171,7 @@ void APState::Connect(std::string server, std::string player,
163 section_id++) { 171 section_id++) {
164 const Location& location = map_area.locations.at(section_id); 172 const Location& location = map_area.locations.at(section_id);
165 173
166 int64_t ap_id = apclient_->get_location_id(location.ap_location_name); 174 int64_t ap_id = apclient->get_location_id(location.ap_location_name);
167 if (ap_id == APClient::INVALID_NAME_ID) { 175 if (ap_id == APClient::INVALID_NAME_ID) {
168 std::cout << "Could not find AP location ID for " 176 std::cout << "Could not find AP location ID for "
169 << location.ap_location_name << std::endl; 177 << location.ap_location_name << std::endl;
@@ -232,7 +240,7 @@ void APState::RefreshTracker() {
232} 240}
233 241
234int64_t APState::GetItemId(const std::string& item_name) { 242int64_t APState::GetItemId(const std::string& item_name) {
235 int64_t ap_id = apclient_->get_item_id(item_name); 243 int64_t ap_id = apclient->get_item_id(item_name);
236 if (ap_id == APClient::INVALID_NAME_ID) { 244 if (ap_id == APClient::INVALID_NAME_ID) {
237 std::cout << "Could not find AP item ID for " << item_name << std::endl; 245 std::cout << "Could not find AP item ID for " << item_name << std::endl;
238 } 246 }
diff --git a/ap_state.h b/ap_state.h index d815f93..5ed7574 100644 --- a/ap_state.h +++ b/ap_state.h
@@ -1,7 +1,6 @@
1#ifndef AP_STATE_H_664A4180 1#ifndef AP_STATE_H_664A4180
2#define AP_STATE_H_664A4180 2#define AP_STATE_H_664A4180
3 3
4#include <apclient.hpp>
5#include <memory> 4#include <memory>
6#include <mutex> 5#include <mutex>
7#include <set> 6#include <set>
@@ -40,7 +39,6 @@ class APState {
40 39
41 TrackerFrame* tracker_frame_; 40 TrackerFrame* tracker_frame_;
42 41
43 std::unique_ptr<APClient> apclient_;
44 bool client_active_ = false; 42 bool client_active_ = false;
45 std::mutex client_mutex_; 43 std::mutex client_mutex_;
46 44
diff --git a/game_data.cpp b/game_data.cpp index b1504de..80ffd97 100644 --- a/game_data.cpp +++ b/game_data.cpp
@@ -308,7 +308,10 @@ int GameData::AddOrGetDoor(std::string room, std::string door) {
308 308
309 if (!door_by_id_.count(full_name)) { 309 if (!door_by_id_.count(full_name)) {
310 door_by_id_[full_name] = doors_.size(); 310 door_by_id_[full_name] = doors_.size();
311 doors_.push_back({.name = door, .room = AddOrGetRoom(room)}); 311 doors_.push_back({
312 .room = AddOrGetRoom(room),
313 .name = door
314 });
312 } 315 }
313 316
314 return door_by_id_[full_name]; 317 return door_by_id_[full_name];
@@ -321,7 +324,7 @@ int GameData::AddOrGetPanel(std::string room, std::string panel) {
321 int panel_id = panels_.size(); 324 int panel_id = panels_.size();
322 panel_by_id_[full_name] = panel_id; 325 panel_by_id_[full_name] = panel_id;
323 panels_.push_back( 326 panels_.push_back(
324 {.id = panel_id, .name = panel, .room = AddOrGetRoom(room)}); 327 {.id = panel_id, .room = AddOrGetRoom(room), .name = panel});
325 } 328 }
326 329
327 return panel_by_id_[full_name]; 330 return panel_by_id_[full_name];
diff --git a/game_data.h b/game_data.h index 3c50b68..6ee277b 100644 --- a/game_data.h +++ b/game_data.h
@@ -2,6 +2,7 @@
2#define GAME_DATA_H_9C42AC51 2#define GAME_DATA_H_9C42AC51
3 3
4#include <map> 4#include <map>
5#include <optional>
5#include <string> 6#include <string>
6#include <vector> 7#include <vector>
7 8