Skip to content

Commit

Permalink
Game must run always in 1280x720 windowed mode
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorgimenez committed Mar 24, 2024
1 parent 38eb872 commit df0ed98
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 2 additions & 6 deletions internal/config/game_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "", " ")
Expand All @@ -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
}

Expand Down
5 changes: 0 additions & 5 deletions internal/game/memory_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 0 additions & 8 deletions internal/game/mouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
15 changes: 6 additions & 9 deletions internal/game/screenshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit df0ed98

Please sign in to comment.