Skip to content

Commit

Permalink
added argv support, getPixel bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
1Ridav committed Jul 29, 2020
1 parent a40cf35 commit b6e490d
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Install/news
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<title></title>
</head>
<body>
<h2 style="text-align: center;"><span style="font-size:26px;"><span style="font-family: tahoma,geneva,sans-serif;">Update 1.10.40 is now released!</span></span></h2>
<h2 style="text-align: center;"><span style="font-size:26px;"><span style="font-family: tahoma,geneva,sans-serif;">Update 1.10.41 is now released!</span></span></h2>
<span style="font-size:16px;"><a href="https://discord.gg/v6QJUYp">Official Discord channel</a></span>
<p><span style="font-size:16px;">Update to the latest version by clicking the update button.</span></p>
<p><span style="font-size:16px;">Updated Jython and JOCL libraries since 1.10.39, make sure that you load them too</span></p>
Expand Down
2 changes: 1 addition & 1 deletion Install/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.40
1.10.41
6 changes: 3 additions & 3 deletions src/main/java/bot/penguee/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ public BufferedImage screenImage() {
* Y axis value
* @return signed 32 bit ARGB (Alpha Red Greeb Blue), 0xFFFFFFFF equals to -1
*/
public int screenPixel(int x, int y) {
public long screenPixel(int x, int y) {
return screen.getPixel(x, y);
}

Expand All @@ -1203,10 +1203,10 @@ public int screenPixel(int x, int y) {
* X axis value
* @param y
* Y axis value
* @return signed 4 byte ARGB (Alpha Red Greeb Blue), 0xFF equals to -1
* @return signed 4 byte ARGB (Alpha Red Greeb Blue)
*/
public byte[] screenPixelARGB(int x, int y) {
int p = screenPixel(x, y);
long p = screenPixel(x, y);
return new byte[] { (byte) (p >>> 24), (byte) (p >>> 16), (byte) (p >>> 8), (byte) p };
}

Expand Down
17 changes: 15 additions & 2 deletions src/main/java/bot/penguee/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class Data {
static Screen screenObject = null;
private static String scriptFileName = "script.py";


static ScriptEngine scriptEngine = null;
private static boolean forceUseGPU = false;
private static boolean useInternalCache = true;
Expand All @@ -34,7 +35,7 @@ public class Data {
public Data() {

}

private static String[] scriptArgs = null;
public static String getFragmentsPath() {
return fragmentsPath;
}
Expand All @@ -53,7 +54,16 @@ public static String getScriptFileName() {
public static void setScriptFileName(String scriptFileName) {
Data.scriptFileName = scriptFileName;
}

public static void setScriptArgs(String [] args){
scriptArgs = args;
}
public static String[] getScriptArgs(){
return scriptArgs;
}
public static ScriptEngine initScriptEngine(){
scriptEngine = new ScriptEngine();
return scriptEngine;
}
public static boolean getForceUseGPU() {
return forceUseGPU;
}
Expand Down Expand Up @@ -107,6 +117,9 @@ static void loadFragments() {

private static void loadFragments(File folder, boolean log) {
System.out.println(folder.getAbsolutePath());
if (!folder.exists())
folder.mkdir();

for (final File fileEntry : folder.listFiles()) {
if (fileEntry.isDirectory()) {
loadFragments(fileEntry, log);
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/bot/penguee/FragmentService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package bot.penguee;

import bot.penguee.exception.FragmentDuplicateException;
import bot.penguee.exception.FragmentNotLoadedException;
import bot.penguee.fragments.Frag;

import java.util.HashMap;

public class FragmentService {
private HashMap<String, Frag> fragments = new HashMap<String, Frag>();
public FragmentService(){

}

public void put(Frag f, String name) throws FragmentDuplicateException {
if (fragments.containsKey(name)){
throw new FragmentDuplicateException(name);
}else{
fragments.put(name, f);
}
}
}
13 changes: 9 additions & 4 deletions src/main/java/bot/penguee/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import java.io.File;
import java.nio.file.Paths;
//I did not want to use Spring Boot, so some
import java.util.Arrays;

//I did not want to use Spring Boot, so some
public class Main {
private static boolean consoleMode = false;

Expand All @@ -23,6 +25,10 @@ public static void main(String[] args) {
Data.setFragmentsPath(args[i+1]);
else
Data.setFragmentsPath(new File("").getAbsolutePath() + File.separator + args[i+1]);
} else if (args[i].equals("-args")) {
//first -args value will be overriden later, don't worry
String[] scriptArgs = Arrays.copyOfRange(args, i, args.length);
Data.setScriptArgs(scriptArgs);
}
}
new Main();
Expand All @@ -40,8 +46,7 @@ private void runConsoleMode() {
@Override
public void run() {
try {
Data.scriptEngine = new ScriptEngine();
Data.scriptEngine.load();
Data.initScriptEngine().load();
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -58,7 +63,7 @@ public void run() {
System.out.println("CORE: Done. " + Data.fragments().size() + " loaded");

try {
Data.scriptEngine.run(Data.getScriptFileName());
Data.scriptEngine.run(Data.getScriptFileName(), Data.getScriptArgs());
} catch (Exception e) {
e.printStackTrace();
System.out.println("CORE: Failed to run script " + Data.getScriptFileName());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/bot/penguee/Update.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.net.URL;

public class Update {
public final static String version = "1.10.40";
public final static String version = "1.10.41";
private static String versionURL = "https://github.com/raw/1Ridav/PengueeBot/master/Install/version";
private static String downloadURL = "https://github.com/1Ridav/PengueeBot/releases/download/v";
private static String newsURL = "https://github.com/raw/1Ridav/PengueeBot/master/Install/news";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package bot.penguee.exception;

public class FragmentDuplicateException extends Exception {

// Parameterless Constructor
public FragmentDuplicateException() {
}

// Constructor that accepts a message
public FragmentDuplicateException(String message) {
super(message);
}
}
2 changes: 1 addition & 1 deletion src/main/java/bot/penguee/screen/ScreenEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public BufferedImage getImage() {
}

@Override
public int getPixel(int x, int y) {
public long getPixel(int x, int y) {
return se.getPixel(x, y);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface ScreenEngineInterface {

BufferedImage getImage();

int getPixel(int x, int y);
long getPixel(int x, int y);


}
4 changes: 2 additions & 2 deletions src/main/java/bot/penguee/screen/cpu/Screen.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public BufferedImage getImage() {
return image;
}

public int getPixel(int x, int y) {
return screenFrag.getRgbData()[y][x];
public long getPixel(int x, int y) {
return Integer.toUnsignedLong(screenFrag.getRgbData()[y][x]);
}

public Rectangle getRect() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/bot/penguee/screen/gpu/ScreenGPU.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,11 @@ public BufferedImage getImage() {
}

@Override
public int getPixel(int x, int y) {
public long getPixel(int x, int y) {
int result[] = new int[1];
clEnqueueReadBuffer(commandQueue, memObjects[0], CL_TRUE, (y * screenRect.width + x) * Sizeof.cl_int, result.length * Sizeof.cl_int,
Pointer.to(result), 0, null, null);
return result[0];
return Integer.toUnsignedLong(result[0]);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/bot/penguee/scripting/ScriptEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void load() {
se.load();
}

public void run(String script) throws Exception {
se.run(script);
public void run(String script, String[] args) throws Exception {
se.run(script, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
public interface ScriptEngineInterface
{
void load();
void run(String script) throws Exception;
void run(String script, String[] args) throws Exception;
}
10 changes: 9 additions & 1 deletion src/main/java/bot/penguee/scripting/jython/JythonVM.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@ public void load() {
}
}

public void run(String script) throws Exception {
public void run(String script, String[] args) throws Exception {
System.out.println("CODE: Waiting for JythonVM to load");
if (!isJythonVMLoaded)
synchronized (jythonLoad) {
jythonLoad.wait();
}
System.out.println("CORE: Running " + script + "...\n\n");

pi.exec("import sys");
pi.exec("sys.path.append(\"./\")");
if (args != null) {
args[0] = script;
pi.exec("sys.argv = []");
for (String arg : args)
pi.exec("sys.argv.append(\'" + arg + "\')");
}

pi.execfile(script);
System.out.println("CORE: Script execution finished.");
}
Expand Down

0 comments on commit b6e490d

Please sign in to comment.