Skip to content
This repository has been archived by the owner on Apr 10, 2021. It is now read-only.

Commit

Permalink
fix sockets breaking game
Browse files Browse the repository at this point in the history
  • Loading branch information
1fbff5f83b23d39d38b1dfcb4cac8d9b committed Jan 12, 2020
1 parent 731b6a9 commit a0b05f2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
8 changes: 0 additions & 8 deletions byond-extools/src/core/hooking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ std::unordered_map<void*, subhook::Hook*> hooks;

//ExecutionContext* last_suspended_ec;

struct QueuedCall
{
Core::Proc proc;
Value src;
Value usr;
std::vector<Value> args;
};

std::vector<QueuedCall> queued_calls;
bool calling_queue = false;

Expand Down
14 changes: 14 additions & 0 deletions byond-extools/src/core/hooking.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,25 @@
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<Value> args;
};

namespace Core
{
void* install_hook(void* original, void* hook);
void remove_hook(void* func);
void remove_all_hooks();
bool hook_custom_opcodes();
void set_topic_filter(TopicFilter tf);
//void schedule_call(Proc proc, std::vector<Value> args, Value src = Value::Null(), Value usr = Value::Null());
}
11 changes: 8 additions & 3 deletions byond-extools/src/datum_socket/datum_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

std::unordered_map<unsigned int, std::unique_ptr<DatumSocket>> sockets;
unsigned int recv_sleep_opcode = -1;
std::vector<SuspendedProc*> timers_to_reset;

DatumSocket::DatumSocket()
{
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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--;
Expand All @@ -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";
}
5 changes: 3 additions & 2 deletions byond-extools/src/datum_socket/datum_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned int, std::unique_ptr<DatumSocket>> sockets;
extern std::unordered_map<unsigned int, std::unique_ptr<DatumSocket>> sockets;
extern std::vector<SuspendedProc*> timers_to_reset;
1 change: 1 addition & 0 deletions byond-extools/src/maptick/maptick.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "maptick.h"
#include "../core/core.h"
#include <chrono>
#include "../datum_socket/datum_socket.h"

//#define MAPTICK_FAST_WRITE

Expand Down

0 comments on commit a0b05f2

Please sign in to comment.