Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
HalfMoon1532 authored Aug 15, 2022
1 parent 9ba0fae commit cf32b11
Show file tree
Hide file tree
Showing 12 changed files with 418 additions and 129 deletions.
3 changes: 2 additions & 1 deletion genshintools/genshintools.iml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_14">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
Expand All @@ -26,5 +26,6 @@
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.8.2" level="project" />
<orderEntry type="library" name="Maven: net.java.dev.jna:jna-platform:5.12.1" level="project" />
<orderEntry type="library" name="Maven: net.java.dev.jna:jna:5.12.1" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.7" level="project" />
</component>
</module>
5 changes: 5 additions & 0 deletions genshintools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
<artifactId>jna-platform</artifactId>
<version>5.12.1</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.google.code.gson</groupId>-->
<!-- <artifactId>gson</artifactId>-->
<!-- <version>2.7</version>-->
<!-- </dependency>-->
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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());

}
Expand All @@ -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) {
Expand All @@ -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");
Expand All @@ -119,7 +204,6 @@ public void initialize(URL location, ResourceBundle resources) {
Thread detect = new Thread(()->{
hotKey.registerHotKey();
while(true){

hotKey.waitHotKey();
changeStatus();
}
Expand Down
7 changes: 7 additions & 0 deletions genshintools/src/main/java/com/hua/genshintools/Main.java
Original file line number Diff line number Diff line change
@@ -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]);
}
}
64 changes: 64 additions & 0 deletions genshintools/src/main/java/com/hua/genshintools/cache/Cache.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
22 changes: 22 additions & 0 deletions genshintools/src/main/java/com/hua/genshintools/cache/Info.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
67 changes: 67 additions & 0 deletions genshintools/src/main/java/com/hua/genshintools/cache/Test.java
Original file line number Diff line number Diff line change
@@ -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'<ch&&ch<'z')||('A'<ch&&ch<'Z')){
// System.out.println("true");
// }else System.out.println("false");
// System.out.println(b);
//
// System.out.println(Pattern.matches("[a-zA-Z0\\(\\)() ]", '0'+""));
// }
//todo true||false&&

@Override
public void run() {
//如果中断了,则跳出执行
while(true){
if(Thread.currentThread().isInterrupted()){
System.out.println("收到中断停止执行");
break;
}
reInterrupt();
}
}

private void reInterrupt(){
//模拟内部中断
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println(Thread.currentThread().isInterrupted());
e.printStackTrace();
//检测中断状态
System.out.println(Thread.currentThread().isInterrupted());
//添加此行代码,因为虽然中断了,线程中断被捕获,然后中断消息也会被清除,
//所以加入Thread.currentThread.interrupt();
//手动恢复中断状态
Thread.currentThread().interrupt();
//检测中断状态是否恢复
System.out.println(Thread.currentThread().isInterrupted());
}
}

public static void main(String[] args) {
Thread thread=new Thread(new Test());
thread.start();
try {
//先休眠,然后再让线程中断
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
thread.interrupt();
}

}
Loading

0 comments on commit cf32b11

Please sign in to comment.