Skip to content

Commit

Permalink
Merge pull request #133 from bayaraa/dev
Browse files Browse the repository at this point in the history
Merge Dev to Master
  • Loading branch information
bayaraa authored Jan 13, 2024
2 parents 6f13f55 + 1367987 commit 2bbec75
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 36 deletions.
3 changes: 2 additions & 1 deletion d2gl/src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct D2GLApp {
bool direct = false;

std::string menu_title = "D2GL";
std::string version_str = "1.3.2";
std::string version_str = "1.3.3";
std::string ini_file = "d2gl.ini";
std::string mpq_file = "d2gl.mpq";
std::string log_file = "d2gl.log";
Expand All @@ -49,6 +49,7 @@ struct D2GLApp {
std::string gl_ver_str = "";
bool vsync = true;
uint32_t frame_latency = 1;
bool d2fps_mod = false;

GLCaps gl_caps;
glm::vec<2, uint8_t> gl_ver = { 4, 6 };
Expand Down
7 changes: 4 additions & 3 deletions d2gl/src/graphic/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,13 +904,14 @@ void Context::resetFileTime()

void Context::takeScreenShot()
{
static uint8_t* data = new GLubyte[App.viewport.size.x * App.viewport.size.y * 4];
memset(data, 0, App.viewport.size.x * App.viewport.size.y * 4);
uint8_t* data = new GLubyte[App.viewport.size.x * App.viewport.size.y * 3];
memset(data, 0, App.viewport.size.x * App.viewport.size.y * 3);

glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(App.viewport.offset.x, App.viewport.offset.y, App.viewport.size.x, App.viewport.size.y, GL_RGBA, GL_UNSIGNED_BYTE, data);
glReadPixels(App.viewport.offset.x, App.viewport.offset.y, App.viewport.size.x, App.viewport.size.y, GL_RGB, GL_UNSIGNED_BYTE, data);

std::string file_name = helpers::saveScreenShot(data, App.viewport.size.x, App.viewport.size.y);
delete[] data;
}

void Context::imguiInit()
Expand Down
40 changes: 35 additions & 5 deletions d2gl/src/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ std::string saveScreenShot(uint8_t* data, int width, int height)
}

stbi_flip_vertically_on_write(1);
stbi_write_png(file_name, width, height, 4, data, width * 4);
stbi_write_png(file_name, width, height, 3, data, width * 3);

return file_name;
}
Expand All @@ -438,12 +438,42 @@ void loadDlls(const std::string& dlls, bool late)

for (std::string dll; std::getline(ss, dll, ',');) {
dll.erase(remove_if(dll.begin(), dll.end(), isspace), dll.end());

if (dll != "") {
if (LoadLibraryA(dll.c_str())) {
trace_log("%s loaded.", dll.c_str());
auto segments = splitToVector(dll, ':');
auto handle = LoadLibraryA(segments[0].c_str());
if (handle) {
auto log_str = segments[0] + " loaded";
if (segments.size() == 3) {
bool called = false;
if (segments[1] == "cdecl") {
if (auto func = (void(__cdecl*)())GetProcAddress(handle, segments[2].c_str())) {
called = true;
func();
}
} else if (segments[1] == "stdcall") {
if (auto func = (void(__stdcall*)())GetProcAddress(handle, segments[2].c_str())) {
called = true;
func();
}
} else if (segments[1] == "fastcall") {
if (auto func = (void(__fastcall*)())GetProcAddress(handle, segments[2].c_str())) {
called = true;
func();
}
}
if (called)
log_str += " and " + segments[1] + " " + segments[2] + " function called";
}
trace_log("%s.", log_str.c_str());
if (!late && dll == "d2fps.dll:stdcall:_Init@0") {
App.d2fps_mod = true;
App.vsync = false;
App.foreground_fps.active = false;
App.background_fps.active = false;
App.motion_prediction = false;
}
} else {
error_log("%s not loaded.", dll.c_str());
error_log("%s not loaded.", segments[0].c_str());
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions d2gl/src/modules/hd_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@ bool HDText::drawText(const wchar_t* str, int x, int y, uint32_t color, uint32_t
if (!ISGLIDE3X())
pos.y += font->getFontSize() * 0.08f;

if (App.game.draw_stage == DrawStage::Map && m_text_size == 6 && *d2::screen_shift != SCREENPANEL_NONE) {
const auto center = (int)(*d2::screen_width / 2);
if (*d2::screen_shift == SCREENPANEL_LEFT && x < center)
return true;
if (*d2::screen_shift == SCREENPANEL_RIGHT) {
const auto size = font->getTextSize(str);
if (x + (int)size.x > center)
return true;
}
}

static bool map_text = false;
if (App.game.draw_stage == DrawStage::Map && modules::MiniMap::Instance().isActive()) {
if (m_text_size == 6 && !*d2::automap_on) {
Expand Down
41 changes: 23 additions & 18 deletions d2gl/src/option/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ void Menu::check()
{
if (m_closing) {
win32::setCursorLock();
SendMessage(App.hwnd, WM_SYSKEYUP, VK_CONTROL, 0);
m_closing = false;
}

Expand Down Expand Up @@ -216,20 +217,22 @@ void Menu::draw()
drawCheckbox_m("V-Sync", m_options.vsync, "Vertical Synchronization.", vsync);
checkChanged(m_options.vsync != App.vsync);
drawSeparator();
ImGui::BeginDisabled(m_options.vsync);
drawCheckbox_m("Max Foreground FPS", m_options.foreground_fps.active, "", foreground_fps);
checkChanged(!m_options.vsync && m_options.foreground_fps.active != App.foreground_fps.active);
ImGui::BeginDisabled(!m_options.foreground_fps.active);
drawSlider_m(int, "", m_options.foreground_fps.range, "%d", "Max fps when game window is active.", foreground_fps_val);
checkChanged(!m_options.vsync && m_options.foreground_fps.active && m_options.foreground_fps.range.value != App.foreground_fps.range.value);
ImGui::BeginDisabled(App.d2fps_mod);
ImGui::BeginDisabled(m_options.vsync);
drawCheckbox_m("Max Foreground FPS", m_options.foreground_fps.active, "", foreground_fps);
checkChanged(!m_options.vsync && m_options.foreground_fps.active != App.foreground_fps.active);
ImGui::BeginDisabled(!m_options.foreground_fps.active);
drawSlider_m(int, "", m_options.foreground_fps.range, "%d", "Max fps when game window is active.", foreground_fps_val);
checkChanged(!m_options.vsync && m_options.foreground_fps.active && m_options.foreground_fps.range.value != App.foreground_fps.range.value);
ImGui::EndDisabled();
ImGui::EndDisabled();
drawSeparator();
drawCheckbox_m("Max Background FPS", m_options.background_fps.active, "", background_fps);
checkChanged(m_options.background_fps.active != App.background_fps.active);
ImGui::BeginDisabled(!m_options.background_fps.active);
drawSlider_m(int, "", m_options.background_fps.range, "%d", "Max fps when game window is in inactive.", background_fps_val);
checkChanged(m_options.background_fps.active && m_options.background_fps.range.value != App.background_fps.range.value);
ImGui::EndDisabled();
ImGui::EndDisabled();
drawSeparator();
drawCheckbox_m("Max Background FPS", m_options.background_fps.active, "", background_fps);
checkChanged(m_options.background_fps.active != App.background_fps.active);
ImGui::BeginDisabled(!m_options.background_fps.active);
drawSlider_m(int, "", m_options.background_fps.range, "%d", "Max fps when game window is in inactive.", background_fps_val);
checkChanged(m_options.background_fps.active && m_options.background_fps.range.value != App.background_fps.range.value);
ImGui::EndDisabled();
drawSeparator();
drawCheckbox_m("Auto Minimize", m_options.window.auto_minimize, "Auto minimize when lose focus while in fullscreen.", auto_minimize);
Expand Down Expand Up @@ -398,11 +401,13 @@ void Menu::draw()
ImGui::EndDisabled();
ImGui::EndDisabled();*/
childSeparator("##w6");
drawCheckbox_m("Motion Prediction", App.motion_prediction, "D2DX's motion prediction feature.", motion_prediction)
{
modules::MotionPrediction::Instance().toggle(App.motion_prediction);
saveBool("Feature", "motion_prediction", App.motion_prediction);
}
ImGui::BeginDisabled(App.d2fps_mod);
drawCheckbox_m("Motion Prediction", App.motion_prediction, "D2DX's motion prediction feature.", motion_prediction)
{
modules::MotionPrediction::Instance().toggle(App.motion_prediction);
saveBool("Feature", "motion_prediction", App.motion_prediction);
}
ImGui::EndDisabled();
drawSeparator();
drawCheckbox_m("Skip Intro", App.skip_intro, "Auto skip intro videos on launch.", skip_intro)
saveBool("Feature", "skip_intro", App.skip_intro);
Expand Down
22 changes: 13 additions & 9 deletions d2gl/src/win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

case WM_ACTIVATE:
case WM_ACTIVATEAPP: {
const bool fps_capped = !App.vsync && App.foreground_fps.active;

Expand Down Expand Up @@ -238,16 +239,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
return 0;
}
} else {
if (wParam == 0x4F && GetAsyncKeyState(VK_CONTROL) & 0x8000) {
option::Menu::instance().toggle();

if (option::Menu::instance().isVisible())
setCursorUnlock();
else
setCursorLock();

if (wParam == 0x4F && GetAsyncKeyState(VK_CONTROL) & 0x8000)
return 0;
}

if (option::Menu::instance().isVisible()) {
if (wParam == VK_ESCAPE || (wParam >= 0x30 && wParam <= 0x39))
return 0;
Expand All @@ -256,6 +250,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
break;
}
case WM_KEYUP: {
if (wParam == 0x4F && GetAsyncKeyState(VK_CONTROL) & 0x8000) {
option::Menu::instance().toggle();
if (option::Menu::instance().isVisible())
setCursorUnlock();
else
setCursorLock();

return 0;
}
if (option::Menu::instance().isVisible()) {
if (wParam == VK_ESCAPE) {
option::Menu::instance().toggle();
Expand All @@ -265,6 +268,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
if (wParam >= 0x30 && wParam <= 0x39)
return 0;
}
break;
}

case WM_LBUTTONUP:
Expand Down
Binary file modified ddraw/ddraw.rc
Binary file not shown.
Binary file modified glide3x/glide3x.rc
Binary file not shown.

0 comments on commit 2bbec75

Please sign in to comment.