AutoHotkey script for CSBWin

Discuss Chaos Strikes Back for Windows and Linux, an unofficial port of Chaos Strikes Back to PC by Paul Stevens, as well as CSBuild, an associated dungeon editor.

Moderator: Zyx

Forum rules
Please read the Forum rules and policies before posting.
Post Reply
RogerS
Craftsman
Posts: 143
Joined: Thu Mar 11, 2021 11:29 pm

AutoHotkey script for CSBWin

Post by RogerS »

Hi,

I recently started playing Dungeon Master for the first time. Although I had an Amiga back in the day, for some reason I never came across a copy of this game.

After a brief go at the DOS version, then RTC (until I started having major issues with Wizard Eyes on the western part of level 5), I finally settled on CSBWin.

My party currently consists of Nabi, Syra, Wu Tse and Elija.

Anyway, the repetitive task of making and drinking buffing potions (got addicted to those when playing RTC) made me motivated to find a way to make that process quicker and easier.

What I've come up with so far is the following AHK script.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetKeyDelay, 250
SetMouseDelay, 25

#IfWinActive CSB for Windows
F6::
BuffHeroes()
return

^F6::
BuffHeroes(true)
return

F7::
Send {F1}614 {F2}614 {F3}614 {F4}614{Space}
return

F8::
Send {F1}6454 {F2}6454 {F3}6454 {F4}6454{Space}
return

r::
SwapWeapons(1)
SwapWeapons(2)
return

t::
SwapWeapons(3)
SwapWeapons(4)
return

^z::
FullHeal(1)
return

^x::
FullHeal(2)
return

^c::
FullHeal(3)
return

^v::
FullHeal(4)
return

+z::
EmergencyHeal(1)
return

+x::
EmergencyHeal(2)
return

+c::
EmergencyHeal(3)
return

; This one doesn't work for some reason? Is SHIFT+V reserved for CSBWin?
+v::
EmergencyHeal(4)
return

^1::
Volley(1)
return

^2::
Volley(2)
return

^3::
Volley(3)
return

^4::
Volley(4)
return

^5::
Volley(5)
return

^6::
Volley(6)
return

SetSpeed(speed)
{
  WinMenuSelectItem, CSB for Windows,, Speed, %speed%
}

Magic(hero)
{
  key := "F" . hero
  Send {%key%}
}

Inventory(hero)
{
  key := {1: "z", 2: "x", 3: "c", 4: "v"}[hero]
  Send {%key%}
}

MagicInventory(hero)
{
  Magic(hero)
  Inventory(hero)
}

BuffHeroes(DoubleKu := false)
{
  SetKeyDelay, 100
  SetSpeed("Quick as a Bunny")
  BuffHero(1, DoubleKu)
  BuffHero(2, DoubleKu)
  BuffHero(3, DoubleKu)
  BuffHero(4, DoubleKu)
  SetSpeed("Normal")
  SetKeyDelay, 250
}

BuffHero(hero, DoubleKu := false)
{
  MagicInventory(hero)
  MakeBuffs(DoubleKu)
  Inventory(hero)
}

SwapWeapons(hero)
{
  Inventory(hero)
  Send ljl
  Inventory(hero)
}

FullHeal(hero)
{
  MagicInventory(hero)
  SwapItems()
  Send 62{Space}
  DrinkPotion()
  SwapItems()
  Inventory(hero)
}

EmergencyHeal(hero)
{
  Inventory(hero)
  Send iui
  Inventory(hero)
  return
}

Volley(i)
{
  Send {F1}%i%44 {F2}%i%44 {F3}%i%44 {F4}%i%44{Space}
}

MakeBuffs(DoubleKu := false)
{
  SwapItems()
  Send 1451{Space}
  DrinkPotion()
  Send 1352{Space}
  DrinkPotion()
  Send 1153{Space}
  DrinkPotion()
  Send 1154{Space}
  DrinkPotion()
  
  if (DoubleKu)
  {
    Send 1451{Space}
    DrinkPotion()
  }
  
  SwapItems()
}

SwapItems()
{
  ;MouseClick, left, 374, 418
  ;MouseClick, left, 356, 509
  ;MouseClick, left, 374, 418
  Send kjk
}

DrinkPotion()
{
  ;MouseClick, left, 356, 509
  ;MouseClick, left, 325, 310
  ;MouseClick, left, 356, 509
  Send juj
}


+Esc::ExitApp  ; Exit script with SHIFT+Esc
In order for this to work, the following lines are needed in config.txt (in addition to the standard binds of 1 to 6 for runes and F1 to F4 for a champion's magic):

Code: Select all

mscan 1 005a  37 17 R  ; 'Z' = first character inventory
mscan 1 0058  7c 17 R  ; 'X' = second character inventory
mscan 1 0043  C1 17 R  ; 'C' = third character inventory
mscan 1 0056 107 17 R  ; 'V' = fourth character inventory
mscan 1 0055 41 37 L  ; 'U'  = mouth
mscan 1 0049 5b 37 L  ; 'I'  = inventory slot to the right of mouth
mscan 1 004a 47 5e L  ; 'J'  = main hand
mscan 1 004b 4c 4c L  ; 'K'  = inventory slot closest to main hand
mscan 1 004c 5b 4c L  ; 'L'  = inventory slot second closest to main hand
An empty bottle needs to be in the lower left inventory slot closest to your main hand, your secondary weapon in the slot to the right of that, and a healing potion in the upper left inventory slot closest to the mouth.

Initially I only wanted the script to automatically buff the party, but once I had done that I decided to add some other stuff to it as well and improve/clean up the code.

Hopefully someone might find this useful.
RogerS
Craftsman
Posts: 143
Joined: Thu Mar 11, 2021 11:29 pm

Re: AutoHotkey script for CSBWin

Post by RogerS »

I've cleaned up the code a bit further, and I've also changed the emergency heal shortcuts to use ALT instead of SHIFT, which seems to be a lot more reliable.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetKeyDelay, 250
SetMouseDelay, 25

#IfWinActive CSB for Windows
F6::
BuffHeroes()
return

^F6::
BuffHeroes(true)
return

F7::
Send {F1}614 {F2}614 {F3}614 {F4}614{Space}
return

F8::
Send {F1}6454 {F2}6454 {F3}6454 {F4}6454{Space}
return

r::
SwapWeapons(1)
SwapWeapons(2)
return

t::
SwapWeapons(3)
SwapWeapons(4)
return

^z::
^x::
^c::
^v::
FullHeal(GetHeroSelected())
return

!z::
!x::
!c::
!v::
EmergencyHeal(GetHeroSelected())
return

^1::
^2::
^3::
^4::
^5::
^6::
Volley(A_ThisHotkey)
return

GetHeroSelected()
{
  return {"z": 1, "x": 2, "c": 3, "v": 4}[SubStr(A_ThisHotkey, 2)]
}

SetSpeed(speed)
{
  WinMenuSelectItem, CSB for Windows,, Speed, %speed%
}

Magic(hero)
{
  key := "F" . hero
  Send {%key%}
}

Inventory(hero)
{
  key := {1: "z", 2: "x", 3: "c", 4: "v"}[hero]
  Send {%key%}
}

MagicInventory(hero)
{
  Magic(hero)
  Inventory(hero)
}

BuffHeroes(DoubleKu := false)
{
  SetKeyDelay, 100
  SetSpeed("Quick as a Bunny")
  BuffHero(1, DoubleKu)
  BuffHero(2, DoubleKu)
  BuffHero(3, DoubleKu)
  BuffHero(4, DoubleKu)
  SetSpeed("Normal")
  SetKeyDelay, 250
}

BuffHero(hero, DoubleKu := false)
{
  MagicInventory(hero)
  MakeBuffs(DoubleKu)
  Inventory(hero)
}

SwapWeapons(hero)
{
  Inventory(hero)
  Send ljl
  Inventory(hero)
}

FullHeal(hero)
{
  MagicInventory(hero)
  SwapItems()
  Send 62{Space}
  DrinkPotion()
  SwapItems()
  Inventory(hero)
}

EmergencyHeal(hero)
{
  Inventory(hero)
  Send iui
  Inventory(hero)
}

Volley(i)
{
  Send {F1}%i%44 {F2}%i%44 {F3}%i%44 {F4}%i%44{Space}
}

MakeBuffs(DoubleKu := false)
{
  SwapItems()
  Send 1451{Space}
  DrinkPotion()
  Send 1352{Space}
  DrinkPotion()
  Send 1153{Space}
  DrinkPotion()
  Send 1154{Space}
  DrinkPotion()
  
  if (DoubleKu)
  {
    Send 1451{Space}
    DrinkPotion()
  }
  
  SwapItems()
}

SwapItems()
{
  ;MouseClick, left, 374, 418
  ;MouseClick, left, 356, 509
  ;MouseClick, left, 374, 418
  Send kjk
}

DrinkPotion()
{
  ;MouseClick, left, 356, 509
  ;MouseClick, left, 325, 310
  ;MouseClick, left, 356, 509
  Send juj
}


+Esc::ExitApp  ; Exit script with SHIFT+Esc
Post Reply

Return to “Chaos Strikes Back for Windows & Linux (CSBWin) / CSBuild”