diff --git a/genshintools/genshintools.iml b/genshintools/genshintools.iml
index 40d21f4..3a07a3d 100644
--- a/genshintools/genshintools.iml
+++ b/genshintools/genshintools.iml
@@ -1,6 +1,6 @@
-
+
@@ -26,5 +26,6 @@
+
\ No newline at end of file
diff --git a/genshintools/pom.xml b/genshintools/pom.xml
index 4823b75..56d77a6 100644
--- a/genshintools/pom.xml
+++ b/genshintools/pom.xml
@@ -43,6 +43,11 @@
jna-platform
5.12.1
+
+
+
+
+
diff --git a/genshintools/src/main/java/com/hua/genshintools/HelloApplication.java b/genshintools/src/main/java/com/hua/genshintools/HelloApplication.java
index bd7787a..d9e3a6a 100644
--- a/genshintools/src/main/java/com/hua/genshintools/HelloApplication.java
+++ b/genshintools/src/main/java/com/hua/genshintools/HelloApplication.java
@@ -14,7 +14,7 @@ public void start(Stage stage) throws IOException {
System.out.println(System.getProperty("user.dir"));
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 400, 300);
- stage.setTitle("连夜删库跑路");
+ stage.setTitle("auto-play");
stage.setScene(scene);
stage.setResizable(false);
stage.show();
diff --git a/genshintools/src/main/java/com/hua/genshintools/HelloController.java b/genshintools/src/main/java/com/hua/genshintools/HelloController.java
index d6bbf9f..c9a1ac1 100644
--- a/genshintools/src/main/java/com/hua/genshintools/HelloController.java
+++ b/genshintools/src/main/java/com/hua/genshintools/HelloController.java
@@ -1,11 +1,13 @@
package com.hua.genshintools;
+import com.hua.genshintools.cache.Cache;
import com.hua.genshintools.win32.HotKey;
import com.hua.genshintools.win32.VirtualInput;
import com.sun.jna.platform.win32.WinDef;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
+import javafx.scene.CacheHint;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.stage.DirectoryChooser;
@@ -18,8 +20,14 @@
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
+import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
import java.util.ResourceBundle;
+import java.util.regex.Pattern;
public class HelloController implements Initializable {
@FXML
@@ -56,7 +64,11 @@ protected void select(){
);
choosed = fileChooser.showOpenDialog(chooseFile.getScene().getWindow());
- if(choosed!=null)file.setText(choosed.getName());
+ if(choosed!=null){
+ file.setText(choosed.getName());
+// Cache.getInfo().lastOpen=choosed.getName();
+// Cache.getCache().writeCache();
+ }
// System.out.println(choosed.getName());
}
@@ -76,26 +88,39 @@ protected void bind(){
if(hwnd!=null)handle.setText("原神"+hwnd.getPointer().hashCode());
else handle.setText("原神未打开");
}
- Runnable runnable=new Runnable(){
+ Runnable runnable=new Runnable(){
+ StringBuilder temp=new StringBuilder();
@Override
public void run() {
if(choosed!=null&&choosed.exists()&&hwnd!=null){
+
//读取
FileInputStream in;
FileChannel ch;
try{
in=new FileInputStream(choosed);
ch=in.getChannel();
+ temp.delete(0,temp.capacity());
ByteBuffer buffer=ByteBuffer.allocate(1024);
+ vInput.reset();
for(;ch.read(buffer)>0;){
if(Thread.currentThread().isInterrupted()){
break;
}
buffer.flip();
- vInput.play(hwnd,new String(buffer.array(), Charset.defaultCharset()));
+ resolve(buffer);
buffer.clear();
+ if(Thread.currentThread().isInterrupted()){
+ break;
+ }
}
+ buffer.clear();
+ buffer.put((byte)0xff);
+ buffer.flip();
+ resolve(buffer);
+ findBpm=true;
+ temp.delete(0,temp.capacity());
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
@@ -106,11 +131,71 @@ public void run() {
status.setText("已停止");
});
}
+ boolean flag=false;
+ boolean findBpm=true;
+ int bpm;
+ void resolve(ByteBuffer buffer){
+ if(buffer.get(0)==(byte)0xff){
+ vInput.play(hwnd,temp.toString());
+ return;
+ }
+ CharsetDecoder decoder=Charset.defaultCharset().newDecoder();
+ String str = new String(buffer.array(), Charset.defaultCharset());
+ try {
+ str=decoder.decode(buffer).toString();
+ } catch (CharacterCodingException e) {
+ throw new RuntimeException(e);
+ }
+ for(char ch:str.toCharArray()){
+ if(Thread.currentThread().isInterrupted())return;
+ if(findBpm&&Pattern.matches("[0-9\\[]",ch+"")){
+ if(ch!='['&&ch!='【') temp.append(ch);
+ continue;
+ }
+ if(findBpm&&Pattern.matches("[\\]】]",ch+"")){
+ try{
+ bpm=Integer.parseInt(temp.toString());
+ vInput.setBpm(bpm);
+ findBpm=false;
+ temp.delete(0,temp.capacity());
+ System.out.println("bpm:"+bpm);
+ }catch (Exception e){
+ String log=file.getText()+":bpm解析错误 "+Calendar.getInstance().getTime();
+ Cache.getCache().errPrint(log);
+ System.out.println(log);
+ }
+ continue;
+ }
+ if(Pattern.matches("[a-zA-Z0\\(\\)() ]",ch+"")){//字母为边界
+ if(findBpm){
+ temp.delete(0,temp.capacity());
+ findBpm=false;
+ }
+ if(temp.toString().length()>0){
+ vInput.play(hwnd,temp.toString());
+ temp.delete(0,temp.capacity());
+ }
+ temp.append(ch);
+ continue;
+ }
+ if(ch=='\n'||ch=='\r'){
+ System.out.println();
+ continue;
+ }
+ temp.append(ch);
+ }
+ }
};
Thread playProc;
@Override
public void initialize(URL location, ResourceBundle resources) {
+ //读取记录
+// if(Cache.getInfo().lastOpen!=null){
+// if(new File("./"+Cache.getInfo().lastOpen).exists())
+// choosed=new File("./"+Cache.getInfo().lastOpen);
+// file.setText(choosed.getName());
+// }
//初始化 绑定热键 获得原神句柄
if(hotKey.registerHotKey()){
HotKeyInfo.setText("绑定热键F9");
@@ -119,7 +204,6 @@ public void initialize(URL location, ResourceBundle resources) {
Thread detect = new Thread(()->{
hotKey.registerHotKey();
while(true){
-
hotKey.waitHotKey();
changeStatus();
}
diff --git a/genshintools/src/main/java/com/hua/genshintools/Main.java b/genshintools/src/main/java/com/hua/genshintools/Main.java
index dab4aea..4ecb5f2 100644
--- a/genshintools/src/main/java/com/hua/genshintools/Main.java
+++ b/genshintools/src/main/java/com/hua/genshintools/Main.java
@@ -1,7 +1,14 @@
package com.hua.genshintools;
+import com.hua.genshintools.cache.Cache;
+import com.sun.jna.platform.win32.*;
+
public class Main {
public static void main(String[] args) {
+// User32.INSTANCE.CreateWindowEx()
+// Kernel32.INSTANCE.CreateProcessW()
+ Cache.getCache().readCache();
+ System.out.println(System.getenv("user.dir"));
HelloApplication.main(new String[0]);
}
}
diff --git a/genshintools/src/main/java/com/hua/genshintools/cache/Cache.java b/genshintools/src/main/java/com/hua/genshintools/cache/Cache.java
new file mode 100644
index 0000000..80da985
--- /dev/null
+++ b/genshintools/src/main/java/com/hua/genshintools/cache/Cache.java
@@ -0,0 +1,64 @@
+package com.hua.genshintools.cache;
+
+//import com.google.gson.Gson;
+
+import javax.security.auth.callback.Callback;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.charset.Charset;
+
+
+public class Cache {
+ private static final Cache cache=new Cache();
+ private File file = new File("./cache");
+ private File error = new File("./error");
+ private static Info info;
+ public void readCache() {
+ try {
+ if (!file.exists()) {
+ file.createNewFile();
+ info=new Info();
+ } else {
+ FileInputStream in = new FileInputStream(file);
+// info=new Gson().fromJson(new String(in.readAllBytes(),Charset.defaultCharset()),Info.class);
+ if(info==null)info=new Info();
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+ public void writeCache(){
+ try{
+ if(!file.exists()){
+ file.createNewFile();
+ }else if(info!=null){
+ FileOutputStream out=new FileOutputStream(file);
+// out.write(new Gson().toJson(info,Info.class).getBytes(Charset.defaultCharset()));
+ }
+ }catch(IOException e){
+ e.printStackTrace();
+ }
+ }
+ public void errPrint(String str){
+ try{
+ if(!error.exists()){
+ error.createNewFile();
+ }else if(info!=null){
+ FileOutputStream out=new FileOutputStream(file);
+ out.write(str.getBytes(Charset.defaultCharset()));
+ }
+ }catch(IOException e){
+ e.printStackTrace();
+ }
+ }
+ public static Info getInfo(){
+ return info;
+ }
+ public static Cache getCache(){
+ return cache;
+ }
+
+}
diff --git a/genshintools/src/main/java/com/hua/genshintools/cache/Info.java b/genshintools/src/main/java/com/hua/genshintools/cache/Info.java
new file mode 100644
index 0000000..922ddd9
--- /dev/null
+++ b/genshintools/src/main/java/com/hua/genshintools/cache/Info.java
@@ -0,0 +1,22 @@
+package com.hua.genshintools.cache;
+
+public class Info{
+ public String lastOpen;
+ public int GlobalBpm;
+
+ public String getLastOpen() {
+ return lastOpen;
+ }
+
+ public void setLastOpen(String lastOpen) {
+ this.lastOpen = lastOpen;
+ }
+
+ public int getGlobalBpm() {
+ return GlobalBpm;
+ }
+
+ public void setGlobalBpm(int globalBpm) {
+ this.GlobalBpm = globalBpm;
+ }
+}
\ No newline at end of file
diff --git a/genshintools/src/main/java/com/hua/genshintools/cache/Test.java b/genshintools/src/main/java/com/hua/genshintools/cache/Test.java
new file mode 100644
index 0000000..b61ecf9
--- /dev/null
+++ b/genshintools/src/main/java/com/hua/genshintools/cache/Test.java
@@ -0,0 +1,67 @@
+package com.hua.genshintools.cache;
+
+
+import java.lang.reflect.Method;
+import java.nio.charset.Charset;
+import java.util.Calendar;
+import java.util.regex.Pattern;
+
+public class Test implements Runnable{
+// public static void main(String[] args) {
+// System.out.println(Pattern.matches("[a-z\\(\\) ]", " "));
+// byte b=(byte)0xff;
+// b&=0xff;
+// System.out.println(b==(byte)0xff);
+// char ch='\n';
+// if(('a'>>16&0xff+buffer.get(j)&0xff);
+ System.out.format("%02x",buffer.get());
+ if(j==1) System.out.print(" ");
+ }
+
+ System.out.println();
+ buffer.clear();
+ }
+ }
+}
diff --git a/genshintools/src/main/java/com/hua/genshintools/win32/HotKey.java b/genshintools/src/main/java/com/hua/genshintools/win32/HotKey.java
index f84f7e8..981743c 100644
--- a/genshintools/src/main/java/com/hua/genshintools/win32/HotKey.java
+++ b/genshintools/src/main/java/com/hua/genshintools/win32/HotKey.java
@@ -15,7 +15,7 @@ public void waitHotKey(){
WinUser.MSG msg=new WinUser.MSG();
if(User32.INSTANCE.GetMessage(msg,null,0,0)!=0){
System.out.println("接受到热键");
- System.out.println("start to Unregister");
+// System.out.println("start to Unregister");
}
else{
System.out.println("WM_QUIT");
diff --git a/genshintools/src/main/java/com/hua/genshintools/win32/VirtualInput.java b/genshintools/src/main/java/com/hua/genshintools/win32/VirtualInput.java
index 22a6ed4..4013966 100644
--- a/genshintools/src/main/java/com/hua/genshintools/win32/VirtualInput.java
+++ b/genshintools/src/main/java/com/hua/genshintools/win32/VirtualInput.java
@@ -4,12 +4,17 @@
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.platform.win32.*;
import com.sun.jna.platform.win32.WinDef.*;
+
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
+import java.util.Random;
+import java.util.regex.Pattern;
public class VirtualInput {
- public static final Map mapToVKCode=new HashMap();
- static{
+ public static final Map mapToVKCode = new HashMap();
+
+ static {
mapToVKCode.put("back", 8);
mapToVKCode.put("tab", 9);
mapToVKCode.put("return", 13);
@@ -69,19 +74,22 @@ public class VirtualInput {
mapToVKCode.put("lmenu", 164);
mapToVKCode.put("rmenu", 165);
}
+
public static final int __WM_KEYDOWN = 0x100;
public static final int __WM_KEYUP = 0x101;
- public static final HKL DWHKL=User32.INSTANCE.GetKeyboardLayout(0);
+ public static final HKL DWHKL = User32.INSTANCE.GetKeyboardLayout(0);
HWND hwnd;
- public HWND findWnd(){
- String windowName="原神";
- return hwnd=User32.INSTANCE.FindWindow("UnityWndClass",windowName);
+
+ public HWND findWnd() {
+ String windowName = "原神";
+ return hwnd = User32.INSTANCE.FindWindow("UnityWndClass", windowName);
}
+
public static void main(String[] args) throws Exception {
- String windowName="原神";
- HWND hwnd=User32.INSTANCE.FindWindow("UnityWndClass",windowName);
+ String windowName = "原神";
+ HWND hwnd = User32.INSTANCE.FindWindow("UnityWndClass", windowName);
- if(hwnd==null){
+ if (hwnd == null) {
System.out.println("无窗口");
return;
}
@@ -89,144 +97,145 @@ public static void main(String[] args) throws Exception {
// if(true)return;
Thread.sleep(3000);
- String str=
- "aanads\n" +
- "\n" +
- "addbmn\n" +
- "\n" +
- "amnnasdb\n" +
- "\n" +
- "cbbcgd\n" +
- "\n" +
- "dsnads\n" +
- "\n" +
- "addbmn\n" +
- "\n" +
- "amnnddas\n" +
- "\n" +
- "addsdn\n" +
- "\n" +
- "dgh dhg\n" +
- "\n" +
- "ghg dsd\n" +
- "\n" +
- "dsanads\n" +
- "\n" +
- "dhhhas\n" +
- "\n" +
- "dgh dhg\n" +
- "\n" +
- "ghgghd\n" +
- "\n" +
- "dsanasdb\n" +
- "\n" +
- "bcbbmn";
- new VirtualInput().play(hwnd,str);
-
- new VirtualInput().pressKey(hwnd,"w");
- if(hwnd==null){
+ String str = "aanads";
+ new VirtualInput().play(hwnd, str);
+
+ new VirtualInput().pressKey(hwnd, "w");
+ if (hwnd == null) {
System.out.println("the Window is missing");
- }else{
+ } else {
System.out.println("get the handle");
- User32.INSTANCE.ShowWindow(hwnd,WinUser.SW_RESTORE);
+ User32.INSTANCE.ShowWindow(hwnd, WinUser.SW_RESTORE);
}
}
- public void pressKey(HWND hwnd,String key){
- keyDown(hwnd,key);
+ public void pressKey(HWND hwnd, String key) {
+ keyDown(hwnd, key);
try {
Thread.sleep(20);
} catch (InterruptedException e) {
- throw new RuntimeException(e);
+ if(!Thread.currentThread().isInterrupted())Thread.currentThread().interrupt();
}
- keyUp(hwnd,key);
+ keyUp(hwnd, key);
}
- public void keyDown(HWND hwnd,String key){
- int vkCode=getVirtualKey(key);
- int scanCode=User32.INSTANCE.MapVirtualKeyEx(vkCode,0,DWHKL);
- WPARAM wParam=new WPARAM(vkCode);
- LPARAM lParam=new LPARAM(scanCode<<16| 1);
- User32.INSTANCE.PostMessage(hwnd,__WM_KEYDOWN,wParam,lParam);
+
+ public void keyDown(HWND hwnd, String key) {
+ int vkCode = getVirtualKey(key);
+ int scanCode = User32.INSTANCE.MapVirtualKeyEx(vkCode, 0, DWHKL);
+ WPARAM wParam = new WPARAM(vkCode);
+ LPARAM lParam = new LPARAM(scanCode << 16 | 1);
+ User32.INSTANCE.PostMessage(hwnd, __WM_KEYDOWN, wParam, lParam);
}
- public void keyUp(HWND hwnd,String key){
- int vkCode=getVirtualKey(key);
- int scanCode=User32.INSTANCE.MapVirtualKeyEx(vkCode,0,DWHKL);
+
+ public void keyUp(HWND hwnd, String key) {
+ int vkCode = getVirtualKey(key);
+ int scanCode = User32.INSTANCE.MapVirtualKeyEx(vkCode, 0, DWHKL);
// System.out.println("vkCode"+vkCode+"scanCode"+scanCode);
- WPARAM wParam=new WPARAM(vkCode);
- LPARAM lParam=new LPARAM(scanCode<<16| 0XC0000001);
- User32.INSTANCE.PostMessage(hwnd,__WM_KEYUP,wParam,lParam);
+ WPARAM wParam = new WPARAM(vkCode);
+ LPARAM lParam = new LPARAM(scanCode << 16 | 0XC0000001);
+ User32.INSTANCE.PostMessage(hwnd, __WM_KEYUP, wParam, lParam);
}
- public int getVirtualKey(String str){
- if(str.length()==1&&31'0'){
- custom.append(ch);
- System.out.println("0-9");
+
+ private static int speed = 400;
+ int delay;
+ private static char[] a={'z','x','c','v','b','n','m'},
+ b={'a','s','d','f','g','h','j'},
+ c={'q','w','e','r','t','y','u'};
+ Random random = new Random();
+ public void play(HWND hwnd, String str) {
+// delay = speed;
+
+ try{
+ if(Pattern.matches("[ /]",str)){
+ Thread.sleep(delay);
+ System.out.print(str);
+ return;
}
- if(ch=='('||ch=='('){
- delay=0;
- System.out.println("(");
- continue;
+ if(Pattern.matches("[((]",str)){
+
+// Thread.sleep(delay);
+// System.out.print("[" + delay + "](");
+ System.out.print(str);
+ delay = random.nextInt(10);
+ return;
}
- if(ch==')'||ch==')'){
- delay=speed;
- System.out.println(")");
- continue;
+ if(Pattern.matches("[))]",str.charAt(0)+"")){
+ delay = speed;
+ System.out.print(str);
+ Thread.sleep(suffixResolve(1,str.toCharArray()));
+ return;
}
- if((ch<'z'||ch<'Z')&&(ch>'a'||ch>'A')){
- pressKey(hwnd,ch+"");
- try {
- Thread.sleep(delay);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
+ char[] chars = str.toCharArray();
+
+ if(chars.length>1){
+ if(Pattern.matches("[1-7]",chars[1]+"")) {
+ //数字谱
+ if (chars[1] == '0' || chars[1] > '7') return;
+ int x=Integer.parseInt(chars[1]+"");
+ if (chars[0] == 'a' || chars[0] == 'A') {
+ pressKey(hwnd, a[x - 1] + "");
+ } else if (chars[0] == 'b' || chars[0] == 'B') {
+ pressKey(hwnd, b[x - 1] + "");
+ } else if (chars[0] == 'c' || chars[0] == 'C') {
+ pressKey(hwnd, c[x - 1] + "");
+ } else {
+ return;
+ }
+ Thread.sleep(suffixResolve(2, chars));
+ System.out.print(chars);
+ return;
}
- System.out.println("a-z");
- continue;
}
- try {
- if(ch==' '){
- Thread.sleep(50);
- System.out.println(" ");
- }
- if(ch=='\n'){
- Thread.sleep(2*delay);
- System.out.println("\\n");
- }
- if(ch==']'||ch=='】'&&Integer.parseInt(custom.toString())<300){
- Thread.sleep(Integer.parseInt(custom.toString())*100);
- System.out.println("]");
- }
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
+// if(a.toString().matches())
+ if(chars[0]!='0') pressKey(hwnd,chars[0]+"");
+ Thread.sleep(suffixResolve(1,chars));
+ System.out.print(chars);
+ }catch (Exception e){
+// if(e instanceof InterruptedException)return;
+ if(! (e instanceof InterruptedException))e.printStackTrace();
+ if(!Thread.currentThread().interrupted()&&e instanceof InterruptedException)
+ Thread.currentThread().interrupt();
+ }
+
+ }
+ public int suffixResolve(int begin,char[] chars){
+ int up=1,down=1,addition=2;
+ for(int i=begin;i4){
+ up=4;
+ }
+ System.out.print(" ["+delay*up/down*addition/2+"] ");
+ return delay*up/down*addition/2;
+ }
+ }
+ public void setBpm(int bpm){
+ delay=speed=60*1000/bpm/4;
+ }
+ public void reset(){
+ delay=speed;
}
-
-
-
-
-
-
-
public interface CLibrary extends Library {
diff --git a/genshintools/src/main/java/module-info.java b/genshintools/src/main/java/module-info.java
index 3757fd7..f9b1a13 100644
--- a/genshintools/src/main/java/module-info.java
+++ b/genshintools/src/main/java/module-info.java
@@ -5,6 +5,7 @@
requires com.sun.jna;
+
opens com.hua.genshintools to javafx.fxml;
exports com.hua.genshintools;
}
\ No newline at end of file