Skip to content

Commit

Permalink
Merge pull request #22 from ejt1/feat-libuv
Browse files Browse the repository at this point in the history
libuv implementation
  • Loading branch information
ejt1 authored Feb 10, 2024
2 parents 8558c04 + fe9b1a3 commit f74a8dd
Show file tree
Hide file tree
Showing 515 changed files with 132,194 additions and 4,440 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ set(D2BS_SRCS
"${CMAKE_CURRENT_SOURCE_DIR}/src/Spidermonkey Engine/Core/JS/JSScript.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Spidermonkey Engine/Core/JS/JSSocket.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Spidermonkey Engine/Core/JS/JSUnit.cpp"

"${CMAKE_CURRENT_SOURCE_DIR}/src/Spidermonkey Engine/Core/JSTimer.cc"

"${CMAKE_CURRENT_SOURCE_DIR}/src/Spidermonkey Engine/Engine/Bindings.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Spidermonkey Engine/Engine/js32.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Spidermonkey Engine/Engine/Script.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Spidermonkey Engine/Engine/ScriptEngine.cpp"
Expand Down Expand Up @@ -123,6 +126,8 @@ target_link_libraries(D2BS PRIVATE

# vendor dependencies
libquickjs
minhook)
minhook
# libuv
uv_a)

install(TARGETS D2BS RUNTIME DESTINATION bin/d2bs)
4 changes: 3 additions & 1 deletion dist/d2bs/kolbot/libs/SoloPlay/Functions/AttackOverrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,9 @@ Attack.pwnDia = function () {
if (me.mp > manaStatic + manaTP + manaTP
&& diabloMissiles.length < 3 && !dia.attacking
&& dia.hpPercent > Config.CastStatic) {
let [x, y] = me;
//let [x, y] = me; // BUG(ejt): TypeError: value is not iterable
let x = me.x;
let y = me.y;
ClassAttack.switchCurse(dia, true); // curse him if we can
// re-check his mode
if (!dia.attacking) {
Expand Down
13 changes: 9 additions & 4 deletions dist/d2bs/kolbot/libs/core/Misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ const Misc = {
* @param {string} [script]
*/
errorReport: function (error, script) {
let msg, oogmsg, filemsg, source, stack;
let msg, oogmsg, filemsg, source = "<unknown>", lineNumber = 0, stack;
let stackLog = "";

let date = new Date();
Expand All @@ -658,10 +658,15 @@ const Misc = {
oogmsg = error.replace(/ÿc[0-9!"+<:;.*]/gi, "");
filemsg = dateString + " <" + me.profile + "> " + error.replace(/ÿc[0-9!"+<:;.*]/gi, "") + "\n";
} else {
source = error.fileName.substring(error.fileName.lastIndexOf("\\") + 1, error.fileName.length);
msg = "ÿc1Error in ÿc0" + script + " ÿc1(" + source + " line ÿc1" + error.lineNumber + "): ÿc1" + error.message;
if (error.fileName) {
source = error.fileName.substring(error.fileName.lastIndexOf("\\") + 1, error.fileName.length);
}
if (error.lineNumber) {
lineNumber = error.lineNumber;
}
msg = "ÿc1Error in ÿc0" + script + " ÿc1(" + source + " line ÿc1" + lineNumber + "): ÿc1" + error.message;
oogmsg = (
"Error in " + script + " (" + source + " #" + error.lineNumber + ") " + error.message
"Error in " + script + " (" + source + " #" + lineNumber + ") " + error.message
+ " (Area: " + me.area + ", Ping:" + me.ping + ", Game: " + me.gamename + ")"
);
filemsg = dateString + " <" + me.profile + "> " + msg.replace(/ÿc[0-9!"+<:;.*]/gi, "") + "\n";
Expand Down
2 changes: 1 addition & 1 deletion src/Diablo II/Handlers/D2Handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void __fastcall GamePlayerAssignment(D2UnitStrc* pPlayer) {

void GameLeave(void) {
Vars.bQuitting = false;
sScriptEngine->ForEachScript(StopIngameScript, NULL, 0);
sScriptEngine->ForEachScript(StopIngameScript, NULL);
ActMap::ClearCache();
}

Expand Down
10 changes: 7 additions & 3 deletions src/Engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <MinHook.h>
#include <mutex>

Engine::Engine() : m_hModule(nullptr), m_pScriptEngine(std::make_unique<ScriptEngine>()) {
Engine::Engine() : m_hModule(nullptr), m_loop(uv_default_loop()), m_pScriptEngine(std::make_unique<ScriptEngine>()) {
m_instance = this;
m_fnWndProc = nullptr;
m_fnCreateWindow = nullptr;
Expand All @@ -26,6 +26,7 @@ Engine::Engine() : m_hModule(nullptr), m_pScriptEngine(std::make_unique<ScriptEn
}

Engine::~Engine() {
uv_loop_close(m_loop);
}

bool Engine::Initialize(HMODULE hModule) {
Expand Down Expand Up @@ -172,6 +173,9 @@ void Engine::OnUpdate() {
Print("ÿc2D2BSÿc0 :: Engine startup complete!");
});

// spin the event loop
uv_run(m_loop, UV_RUN_NOWAIT);

static bool beginStarter = true;
static bool bInGame = false;

Expand All @@ -187,11 +191,11 @@ void Engine::OnUpdate() {

D2CLIENT_InitInventory();
sScriptEngine->ForEachScript(
[](Script* script, void*, uint32_t) {
[](Script* script, void*) {
script->UpdatePlayerGid();
return true;
},
NULL, 0);
NULL);
sScriptEngine->UpdateConsole();
Vars.bQuitting = false;
OnGameEntered();
Expand Down
3 changes: 3 additions & 0 deletions src/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "ScreenHook.h"
#include "Globals.h"

#include <uv.h>

class Engine final {
public:
Engine();
Expand Down Expand Up @@ -44,5 +46,6 @@ class Engine final {
static void HandleGameDrawMenu();

HMODULE m_hModule;
uv_loop_t* m_loop;
std::unique_ptr<ScriptEngine> m_pScriptEngine;
};
1 change: 0 additions & 1 deletion src/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ struct Variables {
std::queue<std::string> qPrintBuffer;
std::map<unsigned __int32, D2CellFileStrc*> mCachedCellFiles;
std::vector<std::pair<DWORD, DWORD>> vUnitList;
// std::list<Event*> EventList;
CRITICAL_SECTION cEventSection;
CRITICAL_SECTION cPrintSection;
CRITICAL_SECTION cTextHookSection;
Expand Down
Loading

0 comments on commit f74a8dd

Please sign in to comment.