Skip to content

Commit ee651b1

Browse files
committed
add game password and change the way game name/pwd is introduced
1 parent aa04cc5 commit ee651b1

File tree

9 files changed

+62
-58
lines changed

9 files changed

+62
-58
lines changed

build.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ echo Cleaning up previous artifacts...
55
if exist build rmdir /s /q build > NUL || goto :error
66

77
echo Building Koolo binary...
8-
go build -trimpath -tags static --ldflags -extldflags="-static" -o build/koolo.exe ./cmd/koolo/main.go > NUL || goto :error
8+
go build -trimpath -tags static --ldflags -extldflags="-static" -ldflags="-s -w" -o build/koolo.exe ./cmd/koolo/main.go > NUL || goto :error
99

1010
echo Copying assets...
1111
mkdir build\config > NUL || goto :error

config/config.yaml.dist

+1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ companion:
188188
leaderName: ''
189189
remote: discord # Only discord supported, telegram doesn't allow interacting between bots
190190
gameNameTemplate: game- # Template for the game name, for example "game-" will lead to "game-1", "game-2", etc.
191+
gamePassword: xxx
191192

192193
# Gambling settings. If enabled, bot will start gambling when all the gold stash tabs are full.
193194
# While gold > 500k it will iterate over the items list trying to buy one of each item type.

internal/character/hammerdin.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (s Hammerdin) KillCouncil() action.Action {
171171
})
172172

173173
for _, m := range councilMembers {
174-
for i := 0; i < hammerdinMaxAttacksLoop; i++ {
174+
for range hammerdinMaxAttacksLoop {
175175
steps = append(steps,
176176
step.PrimaryAttack(
177177
m.UnitID,
@@ -198,7 +198,7 @@ func (s Hammerdin) killMonster(npc npc.ID, t data.MonsterType) action.Action {
198198
}
199199

200200
helper.Sleep(100)
201-
for i := 0; i < hammerdinMaxAttacksLoop; i++ {
201+
for range hammerdinMaxAttacksLoop {
202202
steps = append(steps,
203203
step.PrimaryAttack(
204204
m.UnitID,

internal/companion_supervisor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (s *CompanionSupervisor) Start(ctx context.Context, factory *run.Factory) e
6666
continue
6767
}
6868

69-
event.Events <- event.Text(fmt.Sprintf("New game created. GameName: " + gameName + "|||x"))
69+
event.Events <- event.Text(fmt.Sprintf("New game created. GameName: " + gameName + "|||" + config.Config.Companion.GamePassword))
7070

7171
err = s.startBot(ctx, factory.BuildRuns(), firstRun)
7272
firstRun = false

internal/config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ type StructConfig struct {
128128
LeaderName string `yaml:"leaderName"`
129129
Remote string `yaml:"remote"`
130130
GameNameTemplate string `yaml:"gameNameTemplate"`
131+
GamePassword string `yaml:"gamePassword"`
131132
} `yaml:"companion"`
132133
Gambling struct {
133134
Enabled bool `yaml:"enabled"`

internal/helper/game_manager.go

+27-16
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (gm *GameManager) ExitGame() error {
2222
hid.PressKey("esc")
2323
hid.Click(hid.LeftButton, hid.GameAreaSizeX/2, int(float64(hid.GameAreaSizeY)/2.2))
2424

25-
for i := 0; i < 5; i++ {
25+
for range 5 {
2626
if !gm.gr.InGame() {
2727
return nil
2828
}
@@ -31,11 +31,11 @@ func (gm *GameManager) ExitGame() error {
3131

3232
// If we are still in game, probably character is dead, so let's do it nicely.
3333
// Probably closing the socket is more reliable, but was not working properly for me on singleplayer.
34-
for i := 0; i < 10; i++ {
34+
for range 10 {
3535
if gm.gr.GetData(false).OpenMenus.QuitMenu {
3636
hid.Click(hid.LeftButton, hid.GameAreaSizeX/2, int(float64(hid.GameAreaSizeY)/2.2))
3737

38-
for i := 0; i < 5; i++ {
38+
for range 5 {
3939
if !gm.gr.InGame() {
4040
return nil
4141
}
@@ -54,7 +54,7 @@ func (gm *GameManager) NewGame() error {
5454
return errors.New("character still in a game")
5555
}
5656

57-
for i := 0; i < 30; i++ {
57+
for range 30 {
5858
gm.gr.InGame()
5959
if gm.gr.InCharacterSelectionScreen() {
6060
Sleep(2000) // Wait for character selection screen to load
@@ -77,7 +77,7 @@ func (gm *GameManager) NewGame() error {
7777
Sleep(250)
7878
hid.Click(hid.LeftButton, createX, createY)
7979

80-
for i := 0; i < 30; i++ {
80+
for range 30 {
8181
if gm.gr.InGame() {
8282
return nil
8383
}
@@ -87,6 +87,12 @@ func (gm *GameManager) NewGame() error {
8787
return errors.New("error creating game! Timeout")
8888
}
8989

90+
func (gm *GameManager) clearGameNameOrPasswordField() {
91+
for range 16 {
92+
hid.PressKey("backspace")
93+
}
94+
}
95+
9096
func (gm *GameManager) CreateOnlineGame(gameCounter int) (string, error) {
9197
// Enter bnet lobby
9298
hid.Click(hid.LeftButton, 744, 650)
@@ -97,21 +103,26 @@ func (gm *GameManager) CreateOnlineGame(gameCounter int) (string, error) {
97103
Sleep(200)
98104

99105
// Click the game name textbox, delete text and type new game name
100-
hid.Click(hid.LeftButton, 925, 116)
101-
hid.PressKeyCombination("lctrl", "a")
106+
hid.Click(hid.LeftButton, 1000, 116)
107+
gm.clearGameNameOrPasswordField()
102108
gameName := config.Config.Companion.GameNameTemplate + fmt.Sprintf("%d", gameCounter)
103109
for _, ch := range gameName {
104110
hid.PressKey(fmt.Sprintf("%c", ch))
105111
}
106112

107113
// Same for password
108-
hid.Click(hid.LeftButton, 925, 161)
114+
hid.Click(hid.LeftButton, 1000, 161)
109115
Sleep(200)
110-
hid.PressKeyCombination("lctrl", "a")
111-
hid.PressKey("x")
116+
gamePassword := config.Config.Companion.GamePassword
117+
if gamePassword != "" {
118+
gm.clearGameNameOrPasswordField()
119+
for _, ch := range gamePassword {
120+
hid.PressKey(fmt.Sprintf("%c", ch))
121+
}
122+
}
112123
hid.PressKey("enter")
113124

114-
for i := 0; i < 30; i++ {
125+
for range 30 {
115126
if gm.gr.InGame() {
116127
return gameName, nil
117128
}
@@ -131,25 +142,25 @@ func (gm *GameManager) JoinOnlineGame(gameName, password string) error {
131142
Sleep(200)
132143

133144
// Click the game name textbox, delete text and type new game name
134-
hid.Click(hid.LeftButton, 836, 100)
145+
hid.Click(hid.LeftButton, 950, 100)
135146
Sleep(200)
136-
hid.PressKeyCombination("lctrl", "a")
147+
gm.clearGameNameOrPasswordField()
137148
Sleep(200)
138149
for _, ch := range gameName {
139150
hid.PressKey(fmt.Sprintf("%c", ch))
140151
}
141152

142153
// Same for password
143-
hid.Click(hid.LeftButton, 1020, 100)
154+
hid.Click(hid.LeftButton, 1130, 100)
144155
Sleep(200)
145-
hid.PressKeyCombination("lctrl", "a")
156+
gm.clearGameNameOrPasswordField()
146157
Sleep(200)
147158
for _, ch := range password {
148159
hid.PressKey(fmt.Sprintf("%c", ch))
149160
}
150161
hid.PressKey("enter")
151162

152-
for i := 0; i < 30; i++ {
163+
for range 30 {
153164
if gm.gr.InGame() {
154165
return nil
155166
}

internal/hid/keyboard.go

+27-36
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ func KeyUp(key string) {
3131
win.PostMessage(memory.HWND, win.WM_KEYUP, getASCIICode(key), 0)
3232
}
3333

34-
func PressKeyCombination(keys ...string) {
35-
for _, k := range keys {
36-
win.PostMessage(memory.HWND, win.WM_KEYDOWN, getASCIICode(k), 0)
37-
}
38-
time.Sleep(time.Millisecond * 200)
39-
for _, k := range keys {
40-
win.PostMessage(memory.HWND, win.WM_KEYUP, getASCIICode(k), 0)
41-
}
42-
}
43-
4434
func getASCIICode(key string) uintptr {
4535
if len(key) == 1 {
4636
return uintptr(strings.ToUpper(key)[0])
@@ -50,30 +40,31 @@ func getASCIICode(key string) uintptr {
5040
}
5141

5242
var specialChars = map[string]uintptr{
53-
"esc": win.VK_ESCAPE,
54-
"enter": win.VK_RETURN,
55-
"f1": win.VK_F1,
56-
"f2": win.VK_F2,
57-
"f3": win.VK_F3,
58-
"f4": win.VK_F4,
59-
"f5": win.VK_F5,
60-
"f6": win.VK_F6,
61-
"f7": win.VK_F7,
62-
"f8": win.VK_F8,
63-
"f9": win.VK_F9,
64-
"f10": win.VK_F10,
65-
"f11": win.VK_F11,
66-
"f12": win.VK_F12,
67-
"lctrl": win.VK_LCONTROL,
68-
"home": win.VK_HOME,
69-
"down": win.VK_DOWN,
70-
"up": win.VK_UP,
71-
"left": win.VK_LEFT,
72-
"right": win.VK_RIGHT,
73-
"tab": win.VK_TAB,
74-
"space": win.VK_SPACE,
75-
"alt": win.VK_MENU,
76-
"lalt": win.VK_LMENU,
77-
"ralt": win.VK_RMENU,
78-
"shift": win.VK_LSHIFT,
43+
"esc": win.VK_ESCAPE,
44+
"enter": win.VK_RETURN,
45+
"f1": win.VK_F1,
46+
"f2": win.VK_F2,
47+
"f3": win.VK_F3,
48+
"f4": win.VK_F4,
49+
"f5": win.VK_F5,
50+
"f6": win.VK_F6,
51+
"f7": win.VK_F7,
52+
"f8": win.VK_F8,
53+
"f9": win.VK_F9,
54+
"f10": win.VK_F10,
55+
"f11": win.VK_F11,
56+
"f12": win.VK_F12,
57+
"lctrl": win.VK_LCONTROL,
58+
"home": win.VK_HOME,
59+
"down": win.VK_DOWN,
60+
"up": win.VK_UP,
61+
"left": win.VK_LEFT,
62+
"right": win.VK_RIGHT,
63+
"tab": win.VK_TAB,
64+
"space": win.VK_SPACE,
65+
"alt": win.VK_MENU,
66+
"lalt": win.VK_LMENU,
67+
"ralt": win.VK_RMENU,
68+
"shift": win.VK_LSHIFT,
69+
"backspace": win.VK_BACK,
7970
}

internal/pather/path.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (p *Pather) Intersects(d data.Data, position data.Position, padding int) bo
2727
pT := path.(*Tile)
2828
xMatch := false
2929
yMatch := false
30-
for i := 0; i < padding; i++ {
30+
for i := range padding {
3131
if pT.X == position.X+i || pT.X == position.X-i {
3232
xMatch = true
3333
}

internal/run/tristram.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (a Tristram) openPortalIfNotOpened() action.Action {
8585
}
8686

8787
// We don't know which order the stones are, so we activate all of them one by one in sequential order, 5 times
88-
for i := 0; i < 5; i++ {
88+
for range 5 {
8989
for _, cainStone := range []object.Name{
9090
object.CairnStoneAlpha,
9191
object.CairnStoneBeta,

0 commit comments

Comments
 (0)