From df0ed980a9d7d9117a1798f5f6e199a30637d195 Mon Sep 17 00:00:00 2001 From: Hector Gimenez Date: Sun, 24 Mar 2024 21:45:52 +0900 Subject: [PATCH] Game must run always in 1280x720 windowed mode --- README.md | 2 +- internal/config/game_settings.go | 8 ++------ internal/game/memory_reader.go | 5 ----- internal/game/mouse.go | 8 -------- internal/game/screenshot.go | 15 ++++++--------- 5 files changed, 9 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 2a0ed8e9..7ca17ad9 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ not aware of any ban for using it. I'm not responsible for any ban or any other - **Diablo II: LOD 1.13c** (IMPORTANT: It will **NOT** work without it, this step is not optional) ## Quick Start -- Open Diablo II: Resurrected and ensure the game resolution is set to windowed mode and 1280x720 or 1920x1080 in HiDPI mode. You can close the game after this step. +- Open Diablo II: Resurrected and ensure the game resolution is set to windowed mode and 1280x720. You can close the game after this step. - If you haven't done yet, install **Diablo II: LOD 1.13c** - [Download](https://github.com/hectorgimenez/koolo/releases) the latest Koolo release (recommended for most users), or alternatively you can [build it from source](#development-environment) - Extract the zip file in a directory of your choice. diff --git a/internal/config/game_settings.go b/internal/config/game_settings.go index aaa595fe..9a245c3c 100644 --- a/internal/config/game_settings.go +++ b/internal/config/game_settings.go @@ -17,8 +17,7 @@ func AdjustGameSettings() error { return err } - scale := GetCurrentDisplayScale() - settingsJson["Screen Resolution (Windowed)"] = fmt.Sprintf("%dx%d", int(1280*scale), int(720*scale)) + settingsJson["Screen Resolution (Windowed)"] = "1280x720" settingsJson["Window Mode"] = 0 settingsContent, err := json.MarshalIndent(settingsJson, "", " ") @@ -40,11 +39,8 @@ func AreGameSettingsAdjusted() (bool, error) { return false, nil } - scale := GetCurrentDisplayScale() - targetRes := fmt.Sprintf("%dx%d", int(1280*scale), int(720*scale)) - resolution, ok := settingsJson["Screen Resolution (Windowed)"] - if !ok || !strings.Contains(resolution.(string), targetRes) { + if !ok || !strings.Contains(resolution.(string), "1280x720") { return false, nil } diff --git a/internal/game/memory_reader.go b/internal/game/memory_reader.go index 6afadbc8..e1a251c9 100644 --- a/internal/game/memory_reader.go +++ b/internal/game/memory_reader.go @@ -102,8 +102,3 @@ func (gd *MemoryReader) getMapSeed(playerUnit uintptr) (uint, error) { return mapSeed, nil } - -func (gd *MemoryReader) WindowScale() float64 { - dpi := win.GetDpiForWindow(gd.HWND) - return float64(dpi) / 96.0 -} diff --git a/internal/game/mouse.go b/internal/game/mouse.go index ed2c5022..c76486c9 100644 --- a/internal/game/mouse.go +++ b/internal/game/mouse.go @@ -24,10 +24,6 @@ func (hid *HID) MovePointer(x, y int) { x = hid.gr.WindowLeftX + x y = hid.gr.WindowTopY + y - scale := hid.gr.WindowScale() - x = int(float64(x) * scale) - y = int(float64(y) * scale) - hid.gi.CursorPos(x, y) lParam := calculateLparam(x, y) win.SendMessage(hid.gr.HWND, win.WM_NCHITTEST, 0, lParam) @@ -41,10 +37,6 @@ func (hid *HID) Click(btn MouseButton, x, y int) { x = hid.gr.WindowLeftX + x y = hid.gr.WindowTopY + y - scale := hid.gr.WindowScale() - x = int(float64(x) * scale) - y = int(float64(y) * scale) - lParam := calculateLparam(x, y) buttonDown := uint32(win.WM_LBUTTONDOWN) buttonUp := uint32(win.WM_LBUTTONUP) diff --git a/internal/game/screenshot.go b/internal/game/screenshot.go index b3e29793..13a74e20 100644 --- a/internal/game/screenshot.go +++ b/internal/game/screenshot.go @@ -7,13 +7,10 @@ import ( ) func (gd *MemoryReader) Screenshot() image.Image { - sizeX := int(float64(gd.GameAreaSizeX) * gd.WindowScale()) - sizeY := int(float64(gd.GameAreaSizeY) * gd.WindowScale()) - // Create a device context compatible with the window hdcWindow, _, _ := winproc.GetWindowDC.Call(uintptr(gd.HWND)) hdcMem, _, _ := winproc.CreateCompatibleDC.Call(hdcWindow) - hbmMem, _, _ := winproc.CreateCompatibleBitmap.Call(hdcWindow, uintptr(sizeX), uintptr(sizeY)) + hbmMem, _, _ := winproc.CreateCompatibleBitmap.Call(hdcWindow, uintptr(gd.GameAreaSizeX), uintptr(gd.GameAreaSizeY)) _, _, _ = winproc.SelectObject.Call(hdcMem, hbmMem) // Use PrintWindow to copy the window into the bitmap @@ -33,28 +30,28 @@ func (gd *MemoryReader) Screenshot() image.Image { BiClrImportant uint32 }{ BiSize: 40, // The size of the BITMAPINFOHEADER structure - BiWidth: int32(sizeX), - BiHeight: -int32(sizeY), // negative to indicate top-down bitmap + BiWidth: int32(gd.GameAreaSizeX), + BiHeight: -int32(gd.GameAreaSizeY), // negative to indicate top-down bitmap BiPlanes: 1, BiBitCount: 32, // 32 bits-per-pixel BiCompression: 0, // BI_RGB, no compression BiSizeImage: 0, // 0 for BI_RGB } - bufSize := sizeX * sizeY * 4 + bufSize := gd.GameAreaSizeX * gd.GameAreaSizeY * 4 buf := make([]byte, bufSize) winproc.GetDIBits.Call( hdcMem, hbmMem, 0, - uintptr(sizeY), + uintptr(gd.GameAreaSizeY), uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&bmpInfo)), 0, // DIB_RGB_COLORS ) // Convert raw bytes to *image.RGBA - img := image.NewRGBA(image.Rect(0, 0, sizeX, sizeY)) + img := image.NewRGBA(image.Rect(0, 0, gd.GameAreaSizeX, gd.GameAreaSizeY)) copy(img.Pix, buf) // Windows is using BRG instead of RGB, let's swap red and blue layers