From a0b05f28e46f33f3e167f83d867e5979320ed623 Mon Sep 17 00:00:00 2001 From: 1fbff5f83b23d39d38b1dfcb4cac8d9b <0a02d0db@opayq.com> Date: Sun, 12 Jan 2020 01:35:44 +0100 Subject: [PATCH] fix sockets breaking game --- byond-extools/src/core/hooking.cpp | 8 -------- byond-extools/src/core/hooking.h | 14 ++++++++++++++ byond-extools/src/datum_socket/datum_socket.cpp | 11 ++++++++--- byond-extools/src/datum_socket/datum_socket.h | 5 +++-- byond-extools/src/maptick/maptick.cpp | 1 + 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/byond-extools/src/core/hooking.cpp b/byond-extools/src/core/hooking.cpp index 687e49c5..23579dc9 100644 --- a/byond-extools/src/core/hooking.cpp +++ b/byond-extools/src/core/hooking.cpp @@ -16,14 +16,6 @@ std::unordered_map hooks; //ExecutionContext* last_suspended_ec; -struct QueuedCall -{ - Core::Proc proc; - Value src; - Value usr; - std::vector args; -}; - std::vector queued_calls; bool calling_queue = false; diff --git a/byond-extools/src/core/hooking.h b/byond-extools/src/core/hooking.h index e9c861d1..98cbe844 100644 --- a/byond-extools/src/core/hooking.h +++ b/byond-extools/src/core/hooking.h @@ -13,6 +13,19 @@ typedef bool(*TopicFilter)(BSocket* socket, int socket_id); extern TopicFilter current_topic_filter; +namespace Core +{ + struct Proc; +} + +struct QueuedCall +{ + Core::Proc& proc; + Value src; + Value usr; + std::vector args; +}; + namespace Core { void* install_hook(void* original, void* hook); @@ -20,4 +33,5 @@ namespace Core void remove_all_hooks(); bool hook_custom_opcodes(); void set_topic_filter(TopicFilter tf); + //void schedule_call(Proc proc, std::vector args, Value src = Value::Null(), Value usr = Value::Null()); } \ No newline at end of file diff --git a/byond-extools/src/datum_socket/datum_socket.cpp b/byond-extools/src/datum_socket/datum_socket.cpp index d310a81f..f253dbe1 100644 --- a/byond-extools/src/datum_socket/datum_socket.cpp +++ b/byond-extools/src/datum_socket/datum_socket.cpp @@ -9,6 +9,7 @@ std::unordered_map> sockets; unsigned int recv_sleep_opcode = -1; +std::vector timers_to_reset; DatumSocket::DatumSocket() { @@ -29,6 +30,7 @@ bool DatumSocket::connect(std::string addr, std::string port) bool connected = stream.connect(port.c_str(), addr.c_str()); if (connected) { + open = true; std::thread(&DatumSocket::recv_loop, this).detach(); } return connected; @@ -69,7 +71,7 @@ void DatumSocket::recv_loop() buffer_lock.unlock(); if (data_awaiter) { - data_awaiter->time_to_resume = 0; + StartTiming(data_awaiter); data_awaiter = nullptr; } } @@ -116,8 +118,7 @@ void recv_suspend(ExecutionContext* ctx) { ctx->current_opcode++; SuspendedProc* proc = Suspend(ctx, 0); - proc->time_to_resume = 0x7FFFFF; - StartTiming(proc); + proc->time_to_resume = 1; int datum_id = ctx->constants->src.value; sockets[datum_id]->set_awaiter(proc); ctx->current_opcode--; @@ -138,6 +139,10 @@ bool enable_sockets() extern "C" __declspec(dllexport) const char* init_sockets(int a, const char** b) { + if (!Core::initialize()) + { + return "no"; + } enable_sockets(); return "ok"; } \ No newline at end of file diff --git a/byond-extools/src/datum_socket/datum_socket.h b/byond-extools/src/datum_socket/datum_socket.h index f7afb126..02302f11 100644 --- a/byond-extools/src/datum_socket/datum_socket.h +++ b/byond-extools/src/datum_socket/datum_socket.h @@ -25,7 +25,8 @@ class DatumSocket std::string buffer; std::mutex buffer_lock; SuspendedProc* data_awaiter = nullptr; - bool open = true; + bool open = false; }; -extern std::unordered_map> sockets; \ No newline at end of file +extern std::unordered_map> sockets; +extern std::vector timers_to_reset; \ No newline at end of file diff --git a/byond-extools/src/maptick/maptick.cpp b/byond-extools/src/maptick/maptick.cpp index 5fc236bc..d97b3050 100644 --- a/byond-extools/src/maptick/maptick.cpp +++ b/byond-extools/src/maptick/maptick.cpp @@ -1,6 +1,7 @@ #include "maptick.h" #include "../core/core.h" #include +#include "../datum_socket/datum_socket.h" //#define MAPTICK_FAST_WRITE