Skip to content

Commit

Permalink
Sucesfully reimplemented complete accept and auto call features. Cham…
Browse files Browse the repository at this point in the history
…pion selecting is still buggy.
  • Loading branch information
Darker committed May 8, 2017
1 parent e3d9f72 commit 6cc0bce
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 46 deletions.
6 changes: 3 additions & 3 deletions src/cz/autoclient/PVP_net/ConstData.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ConstData {
public static final String window_title = "League of Legends";
public static final String window_title_part = "League of Legends";
public static final String process_name = "LeagueClientUx.exe";
public static final String game_process_name = "";
public static final String game_process_name = "League of Legends.exe";
public static final String test_process_name = "Annoyance.exe";

public static final String patcher_window_title = "LoL Patcher";
Expand All @@ -33,8 +33,8 @@ public class ConstData {

public static final Window getClientWindow() {
return MSWindow.findWindow(new WindowValidator.CompositeValidatorAND(new WindowValidator[] {
new WindowValidator.ExactTitleValidator("League of Legends"),
new WindowValidator.ProcessNameValidator(ConstData.process_name)
new WindowValidator.ExactTitleValidator(window_title),
new WindowValidator.ProcessNameValidator(process_name)
})
);
}
Expand Down
11 changes: 8 additions & 3 deletions src/cz/autoclient/PVP_net/PixelOffsetV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ public enum PixelOffsetV2 implements ComparablePixel {
Accept_ProgressBar(0.58633890923329D, 0.7516655808867138D, new Color(71, 252, 246, 1), 20),

Lobby_Chat(0.141431781011012D, 0.9498319613023019D, new Color(1, 10, 19, 1), 3),
Lobby_Search(0.6516816408080522D, 0.09908319020779409D, new Color(2, 5, 12, 1), 3),
Lobby_ClientChatButton(0.9678251509271224D, 0.9481236304366503D, new Color(205, 190, 145, 1), 1),
Lobby_ClientChatButtonOutside(0.9582159256955398D, 0.963498608227515D, new Color(30, 35, 40, 1), 1),
Lobby_Search(0.6716816408080522D, 0.09908319020779409D, new Color(2, 5, 12, 1), 15),
Lobby_ClientChatButton(0.9678251509271224D, 0.9481236304366503D, new Color(205, 190, 145, 1), 3),
Lobby_ClientChatButtonOutside(0.9582159256955398D, 0.963498608227515D, new Color(30, 35, 40, 1), 3),
Lobby_ChanpionSlot1(0.29229661714686006D, 0.19474971868428495D, new Color(36, 135, 246, 1), 1),
Lobby_EditRunesLight(0.32208521536476636D, 0.9515402921679534D, new Color(205, 190, 145, 1), 15),
Lobby_EditRunesDark(0.3192024477952916D, 0.9447069687053471D, new Color(30, 35, 40, 1), 10),
Lobby_Locked_GoldFrame(0.25578156126684587D, 0.41683273121899583D, new Color(200, 167, 95, 1), 10),
Lobby_Locked_GoldFrame2(0.7429692805080876D, 0.40487441515943445D, new Color(200, 168, 101, 1), 10),
Lobby_NotLocked_GoldFrame(0.7919763291891594D, 0.39974942256247964D, new Color(200, 169, 105, 1), 10),

NOOP(0.9582159256955398D, 0.963498608227515D)
;
Expand Down
8 changes: 7 additions & 1 deletion src/cz/autoclient/autoclick/GraphicPredicate.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package cz.autoclient.autoclick;

import cz.autoclient.autoclick.comvis.DebugDrawing;
import cz.autoclient.autoclick.windows.Window;
import java.awt.image.BufferedImage;

Expand All @@ -14,8 +15,13 @@
* @author Jakub
*/
public interface GraphicPredicate {

public default boolean test(Window window) {
return test(window.screenshot());
// debug only
//@TODO: remove when not debugging
BufferedImage img = window.screenshot();
DebugDrawing.lastDebugImage = DebugDrawing.cloneImage(img);
return test(img);
}
public boolean test(BufferedImage i);
}
16 changes: 12 additions & 4 deletions src/cz/autoclient/autoclick/PixelGroupSimple.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

package cz.autoclient.autoclick;

import cz.autoclient.autoclick.comvis.DebugDrawing;
import cz.autoclient.main_automation.WindowTools;
import java.awt.Color;
import java.awt.image.BufferedImage;

/**
Expand All @@ -19,14 +21,20 @@ public class PixelGroupSimple implements PixelGroupWithPixels {
public PixelGroupSimple(ComparablePixel... pixels) {
this.pixels = pixels;
}

@Override
public boolean test(BufferedImage i) {
boolean result = true;
for(ComparablePixel p:pixels) {
if(!WindowTools.checkPoint(i, p))
return false;
if(!WindowTools.checkPoint(i, p)) {
result = false;
DebugDrawing.drawPoint(DebugDrawing.lastDebugImage, p, Color.red);
}
else {
DebugDrawing.drawPoint(DebugDrawing.lastDebugImage, p, Color.green);
}
}
return true;
return result;
}

@Override
Expand Down
13 changes: 1 addition & 12 deletions src/cz/autoclient/autoclick/RecursiveGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,14 @@

package cz.autoclient.autoclick;

import java.awt.image.BufferedImage;

/**
*
* @author Jakub
*/
public class RecursiveGroup implements PixelGroup {
public abstract class RecursiveGroup implements PixelGroup {
protected final PixelGroup[] groups;

public RecursiveGroup(PixelGroup... groups) {
this.groups = groups;
}
@Override
public boolean test(BufferedImage i) {
for(PixelGroup g:groups) {
if(!g.test(i))
return false;
}
return true;
}

}
27 changes: 27 additions & 0 deletions src/cz/autoclient/autoclick/RecursiveGroupAND.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package cz.autoclient.autoclick;

import java.awt.image.BufferedImage;

/**
*
* @author Jakub
*/
public class RecursiveGroupAND extends RecursiveGroup {
public RecursiveGroupAND(PixelGroup... groups) {
super(groups);
}
@Override
public boolean test(BufferedImage i) {
for(PixelGroup g:groups) {
if(!g.test(i))
return false;
}
return true;
}
}
27 changes: 27 additions & 0 deletions src/cz/autoclient/autoclick/RecursiveGroupOR.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package cz.autoclient.autoclick;

import java.awt.image.BufferedImage;

/**
*
* @author Jakub
*/
public class RecursiveGroupOR extends RecursiveGroup {
public RecursiveGroupOR(PixelGroup... groups) {
super(groups);
}
@Override
public boolean test(BufferedImage i) {
for(PixelGroup g:groups) {
if(g.test(i))
return true;
}
return false;
}
}
2 changes: 2 additions & 0 deletions src/cz/autoclient/autoclick/comvis/DebugDrawing.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
* @author Jakub
*/
public class DebugDrawing {
// nasty shit, just saving last image here...
public static BufferedImage lastDebugImage = null;
public static void drawResult(BufferedImage target, Rect rect, Color color) {
//silent fail for invalid result
if(rect==null)
Expand Down
3 changes: 0 additions & 3 deletions src/cz/autoclient/autoclick/windows/WindowValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ public boolean isValid(Window w) {
//System.out.println("Error getting process handle of window "+w.getTitle());
return false;
}
if(filename.indexOf("Client")!=-1) {
System.out.println(filename + " "+ w.getTitle());
}
if(!filename.endsWith(processFilename))
return false;
String[] separators = new String[] {"\\", "/"};
Expand Down
5 changes: 1 addition & 4 deletions src/cz/autoclient/autoclick/windows/ms_windows/MSWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ public boolean isValid() {
private ShowWindow getWindowPlacement() {
WinDefExt.WINDOWPLACEMENT placement = new WinDefExt.WINDOWPLACEMENT();
UserExt.GetWindowPlacement(hwnd, placement);
//System.out.println("Window placement: "+placement.showCmd);
return ShowWindow.byCode(placement.showCmd);
}
/**
Expand Down Expand Up @@ -525,8 +524,6 @@ private int sendMsg(int msg, int wparam, int lparam) throws WindowAccessDeniedEx
}
private void sendMsg(Messages msg, int wparam, int lparam) {
sendMsg(msg.code, wparam, lparam);
//System.out.println("Message "+msg.name()+" result: "+sendMsg(msg.code, wparam, lparam));
//System.out.println(" ERRORLEVEL: "+getLastError());
}
public static User32Ext UserExt = User32Ext.INSTANCE;
public static GDI32Ext GDIExt = GDI32Ext.INSTANCE;
Expand Down Expand Up @@ -681,7 +678,7 @@ public boolean callback(WinDef.HWND handle, Pointer arg1)


int pid = UserExt.GetWindowThreadProcessId(handle, new IntByReference(0));
System.out.println(getWindowTitle(handle)+" : "+pid);
//System.out.println(getWindowTitle(handle)+" : "+pid);
if(pid==required_pid) {
//And if we gained one, put it in our array
WindowID[0] = handle;
Expand Down
65 changes: 52 additions & 13 deletions src/cz/autoclient/main_automation/AutomatV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
import cz.autoclient.PVP_net.PixelOffsetV2;
import cz.autoclient.PVP_net.Setnames;
import cz.autoclient.autoclick.ComparablePixel;
import cz.autoclient.autoclick.PixelGroupSimple;
import cz.autoclient.autoclick.Rect;
import cz.autoclient.autoclick.RecursiveGroupOR;
import cz.autoclient.autoclick.exceptions.APIException;
import cz.autoclient.autoclick.windows.MouseButton;
import cz.autoclient.autoclick.windows.Window;
import cz.autoclient.autoclick.windows.WindowRobot;
import cz.autoclient.autoclick.windows.WindowValidator;
import cz.autoclient.autoclick.windows.ms_windows.MSWindow;
import static cz.autoclient.main_automation.Automat.dbgmsg;
import static cz.autoclient.main_automation.Automat.errmsg;
Expand All @@ -42,7 +45,7 @@ public AutomatV2(Gui acgui, Settings settings) {
public void run() {
dbgmsg("Automation started!");
accepted = false;
window = MSWindow.windowFromName(ConstData.window_title_part, false);
window = ConstData.getClientWindow();
//window = MSWindow.
if (window == null) {
errmsg("No PVP.net window found!");
Expand Down Expand Up @@ -101,19 +104,22 @@ public void waitForGame() throws InterruptedException {
*/
public boolean handleStandardLobby() throws InterruptedException {
long waitStart = System.currentTimeMillis();
ComparablePixel[] lobbyPixels = new ComparablePixel[] {
final ComparablePixel[] lobbyPixels = new ComparablePixel[] {
PixelOffsetV2.Lobby_Chat,
PixelOffsetV2.Lobby_ClientChatButton,
PixelOffsetV2.Lobby_ClientChatButtonOutside,
PixelOffsetV2.Lobby_Search,
PixelOffsetV2.Lobby_NotLocked_GoldFrame,
PixelOffsetV2.Lobby_EditRunesLight,
PixelOffsetV2.Lobby_EditRunesDark,
};
boolean inLobby = false;
while(System.currentTimeMillis()- waitStart < 12000) {
while(System.currentTimeMillis()- waitStart < 13000) {
if(WindowTools.checkPoint(window, lobbyPixels)>=4) {
inLobby = true;
break;
}
sleep(40);
sleep(30);
}
if(!inLobby) {
dbgmsg("Lobby didn't open, waiting for another game.");
Expand All @@ -136,10 +142,43 @@ public boolean handleStandardLobby() throws InterruptedException {
if(!selectChampion.done() || (selectChampion instanceof SleepAction.NoAction)) {
selectChampion(chname);
}
// Wait for game to start


return true;
final ComparablePixel[] lockedPixels = new ComparablePixel[] {
PixelOffsetV2.Lobby_Chat,
PixelOffsetV2.Lobby_Locked_GoldFrame,
PixelOffsetV2.Lobby_Locked_GoldFrame,
PixelOffsetV2.Lobby_ClientChatButton,
PixelOffsetV2.Lobby_EditRunesLight,
PixelOffsetV2.Lobby_EditRunesDark,
};
RecursiveGroupOR requiredPixels = new RecursiveGroupOR(
new PixelGroupSimple(lobbyPixels),
new PixelGroupSimple(lockedPixels)
);
// Wait for lobby to dissapear
while(true) {
while(requiredPixels.test(window)) {
sleep(500L);
}
//DebugDrawing.displayImage(DebugDrawing.lastDebugImage);
dbgmsg("Lobby gone, has the game started?");
long startTime = System.currentTimeMillis();
while(!requiredPixels.test(window)) {
Window gameWindow = MSWindow.findWindow(new WindowValidator.CompositeValidatorAND(new WindowValidator[] {
new WindowValidator.ProcessNameValidator(ConstData.game_process_name)
}));
if(gameWindow != null) {
dbgmsg("Game started, ending.");
return true;
}
if(System.currentTimeMillis()-startTime>8000) {
dbgmsg("Lobby still gone, assuming that someone dodged the game.");
return false;
}
sleep(300);
}
dbgmsg("Lobby reappeared, waiting for game to start.");
}
}
@Override
public void selectChampion(final String name) throws InterruptedException {
Expand All @@ -159,14 +198,14 @@ public void selectChampion(final String name) throws InterruptedException {
Rect coords = PixelOffsetV2.Lobby_ChanpionSlot1.toRect(wrect);
//window.click(coords.left, coords.top, MouseButton.Right);
//sleep(32L);
for(int y=0; y<8; ++y)
for(int x=0; x<8; ++x) {
window.mouseOver(coords.left+x, coords.top+y);
sleep(10L);
for(int y=0; y<10; ++y)
for(int x=0; x<0; ++x) {
window.mouseOver(coords.left+x-5, coords.top+y-5);
window.click(coords.left+x-5, coords.top+y-5);
sleep(8L);
}

slowClick(PixelOffsetV2.Lobby_ChanpionSlot1, 40);
sleep(50L);
}


Expand Down
10 changes: 7 additions & 3 deletions test/cz/autoclient/experiments/GetProcessNameFromWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import cz.autoclient.autoclick.windows.Window;
import cz.autoclient.autoclick.windows.WindowValidator;
import cz.autoclient.autoclick.windows.ms_windows.MSWindow;
import java.util.regex.Pattern;

/**
*
Expand All @@ -21,14 +22,17 @@ public static void main(String[] args) {

// Try to find window by process name
Window win2 = MSWindow.findWindow(new WindowValidator.CompositeValidatorAND(new WindowValidator[] {
new WindowValidator.ExactTitleValidator("League of Legends"),
new WindowValidator.ProcessNameValidator(ConstData.process_name)
//new WindowValidator.TitlePatternWindowValidator(Pattern.compile("League of")),
new WindowValidator.ProcessNameValidator(ConstData.game_process_name)

//new WindowValidator.ExactTitleValidator("League of Legends"),
//new WindowValidator.ProcessNameValidator(ConstData.process_name)
})
);
System.out.println("Lookup took "+(System.currentTimeMillis()-time)/1000.0 + " seconds.");
if(win2!=null) {
System.out.println(win2.getProcessName());
win2.close();
//win2.close();
}
else {
System.out.println("No window by process bitch!");
Expand Down

0 comments on commit 6cc0bce

Please sign in to comment.