diff --git a/bin/ArcadeReader$1.class b/bin/ArcadeReader$1.class deleted file mode 100644 index bac1e40..0000000 Binary files a/bin/ArcadeReader$1.class and /dev/null differ diff --git a/bin/ArcadeReader.class b/bin/ArcadeReader.class deleted file mode 100644 index 8dbaea3..0000000 Binary files a/bin/ArcadeReader.class and /dev/null differ diff --git a/bin/readers/DDRReader.class b/bin/readers/DDRReader.class deleted file mode 100644 index 35c712c..0000000 Binary files a/bin/readers/DDRReader.class and /dev/null differ diff --git a/bin/readers/ITGReader.class b/bin/readers/ITGReader.class deleted file mode 100644 index 6849b7e..0000000 Binary files a/bin/readers/ITGReader.class and /dev/null differ diff --git a/bin/readers/LoveLiveReader.class b/bin/readers/LoveLiveReader.class deleted file mode 100644 index 1049d3b..0000000 Binary files a/bin/readers/LoveLiveReader.class and /dev/null differ diff --git a/bin/readers/SoundVoltexReader.class b/bin/readers/SoundVoltexReader.class deleted file mode 100644 index 798d4a7..0000000 Binary files a/bin/readers/SoundVoltexReader.class and /dev/null differ diff --git a/bin/readers/TestReader.class b/bin/readers/TestReader.class deleted file mode 100644 index 98c63d7..0000000 Binary files a/bin/readers/TestReader.class and /dev/null differ diff --git a/bin/sigPlace.class b/bin/sigPlace.class deleted file mode 100644 index 6409d82..0000000 Binary files a/bin/sigPlace.class and /dev/null differ diff --git a/bin/sigServer.class b/bin/sigServer.class deleted file mode 100644 index 99337b0..0000000 Binary files a/bin/sigServer.class and /dev/null differ diff --git a/exceptions/FailedResponseException.java b/exceptions/FailedResponseException.java new file mode 100644 index 0000000..d0c48de --- /dev/null +++ b/exceptions/FailedResponseException.java @@ -0,0 +1,7 @@ +package exceptions; + +public class FailedResponseException extends Exception{ + public FailedResponseException(String msg) { + super(msg); + } +} diff --git a/readers/Box.class b/readers/Box.class deleted file mode 100644 index 946d240..0000000 Binary files a/readers/Box.class and /dev/null differ diff --git a/readers/Box.java b/readers/Box.java index 2f0c678..5048bf9 100644 --- a/readers/Box.java +++ b/readers/Box.java @@ -6,6 +6,7 @@ public class Box{ public int w; public int h; boolean ja_required; + boolean isNumber = false; final static int BOX_THRESHOLD=8; //How many pixels outside the specified region the score can be. public Box(int x,int y,int w, int h) { this.x=x; @@ -16,4 +17,10 @@ public class Box{ boolean insideBox(int x,int y) { return this.x-BOX_THRESHOLD<=x&&this.x+this.w+BOX_THRESHOLD>=x&&this.y-BOX_THRESHOLD<=y&&this.y+this.h+BOX_THRESHOLD>=y; } + public void setNumber(boolean isNumber) { + this.isNumber = isNumber; + } + public boolean isNumber() { + return isNumber; + } } \ No newline at end of file diff --git a/readers/ColorRange.class b/readers/ColorRange.class deleted file mode 100644 index ea03060..0000000 Binary files a/readers/ColorRange.class and /dev/null differ diff --git a/readers/PopnReader.class b/readers/PopnReader.class deleted file mode 100644 index 7ff3ecc..0000000 Binary files a/readers/PopnReader.class and /dev/null differ diff --git a/readers/Reader.class b/readers/Reader.class deleted file mode 100644 index 4e578a6..0000000 Binary files a/readers/Reader.class and /dev/null differ diff --git a/readers/Reader.java b/readers/Reader.java index f519e0c..db04381 100644 --- a/readers/Reader.java +++ b/readers/Reader.java @@ -29,6 +29,7 @@ public abstract class Reader{ protected void addRegion(Box box,boolean isNumb) { readRegions.add(box); if (isNumb) { + box.setNumber(true); sig_data_size++; } } @@ -436,4 +437,15 @@ public abstract class Reader{ return false; return true; } + + public boolean isReasonableData() { + for (int i=0;i run() throws FailedResponseException { + build(); + try { + if (file==null) { + return client.send(req,BodyHandlers.ofString()); + } else { + return client.send(req,BodyHandlers.ofFile(file)); + } + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + } + throw new FailedResponseException("No proper response returned. THIS SHOULD NOT BE HAPPENING!"); + } + protected java.net.http.HttpRequest.Builder finalizeRequestPreBuild(java.net.http.HttpRequest.Builder requestBuild) throws FailedResponseException { + return requestBuild.GET(); + } + protected Builder finalizeClientPreBuild(Builder clientBuild) { + return clientBuild; + } + protected void build(){ + boolean AUTH_REQUIRED=user.length()>0&&pass.length()>0; + try { + java.net.http.HttpRequest.Builder requestBuild=HttpRequest.newBuilder(new URI(url)) + .version(HttpClient.Version.HTTP_2) + .timeout(Duration.ofMillis(timeout)); + if (headers!=null&&headers.length>0) { + requestBuild.headers(headers); + } + req = finalizeRequestPreBuild(requestBuild).build(); + Builder clientBuild=HttpClient.newBuilder() + .followRedirects(HttpClient.Redirect.ALWAYS); + if (AUTH_REQUIRED) { + clientBuild.authenticator(new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(user,pass.toCharArray()); + } + }); + } + client = finalizeClientPreBuild(clientBuild).build(); + } catch (URISyntaxException | FailedResponseException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/requests/MultipartUtility.java b/requests/MultipartUtility.java new file mode 100644 index 0000000..08e9297 --- /dev/null +++ b/requests/MultipartUtility.java @@ -0,0 +1,149 @@ +package requests; +import java.io.BufferedReader; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.List; + +/** + * This utility class provides an abstraction layer for sending multipart HTTP + * POST requests to a web server. + * @author www.codejava.net + * + */ +public class MultipartUtility { + private final String boundary; + private static final String LINE_FEED = "\r\n"; + private HttpURLConnection httpConn; + private String charset; + private OutputStream outputStream; + private PrintWriter writer; + + /** + * This constructor initializes a new HTTP POST request with content type + * is set to multipart/form-data + * @param requestURL + * @param charset + * @throws IOException + */ + public MultipartUtility(String requestURL, String charset) + throws IOException { + this.charset = charset; + + // creates a unique boundary based on time stamp + boundary = "===" + System.currentTimeMillis() + "==="; + + URL url = new URL(requestURL); + httpConn = (HttpURLConnection) url.openConnection(); + httpConn.setUseCaches(false); + httpConn.setDoOutput(true); // indicates POST method + httpConn.setDoInput(true); + httpConn.setRequestProperty("Content-Type", + "multipart/form-data; boundary=" + boundary); + httpConn.setRequestProperty("User-Agent", "CodeJava Agent"); + httpConn.setRequestProperty("Test", "Bonjour"); + outputStream = httpConn.getOutputStream(); + writer = new PrintWriter(new OutputStreamWriter(outputStream, charset), + true); + } + + /** + * Adds a form field to the request + * @param name field name + * @param value field value + */ + public void addFormField(String name, String value) { + writer.append("--" + boundary).append(LINE_FEED); + writer.append("Content-Disposition: form-data; name=\"" + name + "\"") + .append(LINE_FEED); + writer.append("Content-Type: text/plain; charset=" + charset).append( + LINE_FEED); + writer.append(LINE_FEED); + writer.append(value).append(LINE_FEED); + writer.flush(); + } + + /** + * Adds a upload file section to the request + * @param fieldName name attribute in + * @param uploadFile a File to be uploaded + * @throws IOException + */ + public void addFilePart(String fieldName, File uploadFile) + throws IOException { + String fileName = uploadFile.getName(); + writer.append("--" + boundary).append(LINE_FEED); + writer.append( + "Content-Disposition: form-data; name=\"" + fieldName + + "\"; filename=\"" + fileName + "\"") + .append(LINE_FEED); + writer.append( + "Content-Type: " + + URLConnection.guessContentTypeFromName(fileName)) + .append(LINE_FEED); + writer.append("Content-Transfer-Encoding: binary").append(LINE_FEED); + writer.flush(); + + FileInputStream inputStream = new FileInputStream(uploadFile); + char[] buffer = new char[1024]; + String s = new String(buffer); + byte[] data = s.getBytes("ISO-8859-1"); + int bytesRead = -1; + while ((bytesRead = inputStream.read(data)) > 0) { + outputStream.write(data, 0, bytesRead); + } + inputStream.close(); + + writer.flush(); + } + + /** + * Adds a header field to the request. + * @param name - name of the header field + * @param value - value of the header field + */ + public void addHeaderField(String name, String value) { + writer.append(name + ": " + value).append(LINE_FEED); + writer.flush(); + } + + /** + * Completes the request and receives response from the server. + * @return a list of Strings as response in case the server returned + * status OK, otherwise an exception is thrown. + * @throws IOException + */ + public List finish() throws IOException { + List response = new ArrayList(); + + writer.flush(); + writer.append("--" + boundary + "--").append(LINE_FEED); + writer.close(); + + // checks server's status code first + int status = httpConn.getResponseCode(); + if (status == HttpURLConnection.HTTP_OK) { + BufferedReader reader = new BufferedReader(new InputStreamReader( + httpConn.getInputStream())); + String line = null; + while ((line = reader.readLine()) != null) { + response.add(line); + } + reader.close(); + httpConn.disconnect(); + } else { + System.out.println("Server returned non-OK status: " + status); + } + + return response; + } +} \ No newline at end of file diff --git a/requests/POSTRequest.java b/requests/POSTRequest.java new file mode 100644 index 0000000..7c14ee9 --- /dev/null +++ b/requests/POSTRequest.java @@ -0,0 +1,130 @@ +package requests; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpHeaders; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.net.http.HttpClient.Builder; +import java.net.http.HttpClient.Version; +import java.nio.charset.StandardCharsets; +import java.nio.file.Path; +import java.util.List; +import java.util.Optional; + +import javax.net.ssl.SSLSession; + +import exceptions.FailedResponseException; + +public class POSTRequest extends GETRequest{ + + String body = ""; + Path uploadFile = null; + + public POSTRequest(String url, String body, String username, String password, long timeout, Path outputFile, String... headers) { + super(url, username, password, timeout, outputFile, headers); + this.body=body; + } + + public POSTRequest(String url, String body, long timeout, Path outputFile, String... headers) { + super(url, timeout, outputFile, headers); + this.body=body; + } + + public POSTRequest(String url, String body, long timeout, String... headers) { + super(url, timeout, headers); + this.body=body; + } + + public POSTRequest(String url, String body) { + super(url); + this.body=body; + } + + public POSTRequest(String url, Path uploadFile) { + super(url); + this.uploadFile=uploadFile; + } + @Override + public HttpResponse run() throws FailedResponseException { + if (uploadFile!=null) { + String charset = "ISO-8859-1"; + File file = uploadFile.toFile(); + String requestURL = url; + + try { + MultipartUtility multipart = new MultipartUtility(requestURL, charset); + + multipart.addHeaderField("User-Agent", "SIG HTTPCLIENT"); + + multipart.addFilePart("fileUpload", file); + + List response = multipart.finish(); + return new HttpResponse(){ + @Override + public int statusCode() { + return 0; + } + @Override + public HttpRequest request() { + return null; + } + @Override + public Optional> previousResponse() { + return null; + } + @Override + public HttpHeaders headers() { + return null; + } + @Override + public String body() { + StringBuilder sb = new StringBuilder(); + for (String s : response) { + sb.append(s); + } + return sb.toString(); + } + @Override + public Optional sslSession() { + return null; + } + @Override + public URI uri() { + return null; + } + @Override + public Version version() { + return null; + } + }; + } catch (IOException ex) { + System.err.println(ex); + throw new FailedResponseException("Could not send response for POST File upload. THIS SHOULD NOT BE HAPPENING!"); + } + } else { + return super.run(); + } + } + @Override + protected java.net.http.HttpRequest.Builder finalizeRequestPreBuild( + java.net.http.HttpRequest.Builder requestBuild) throws FailedResponseException{ + requestBuild.headers("Content-Type","application/json"); + try { + return file!=null?requestBuild.POST(HttpRequest.BodyPublishers.ofFile(file)): + body.length()>0?requestBuild.POST(HttpRequest.BodyPublishers.ofString(body)): + requestBuild.POST(HttpRequest.BodyPublishers.noBody()); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + throw new FailedResponseException("Could not complete request build. THIS SHOULD NOT BE HAPPENING!"); + } + + @Override + protected Builder finalizeClientPreBuild(Builder clientBuild) { + return clientBuild; + } + +} \ No newline at end of file diff --git a/sigPlace.java b/sigPlace.java index 00c2ca9..6907500 100644 --- a/sigPlace.java +++ b/sigPlace.java @@ -17,12 +17,17 @@ import java.util.regex.Pattern; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; +import java.awt.AWTException; import java.awt.Color; +import java.awt.Robot; +import java.awt.GraphicsEnvironment; import readers.Box; import readers.fonts.Font; +import requests.POSTRequest; import readers.ColorRange; import readers.PopnReader; +import readers.Reader; public class sigPlace { @@ -86,8 +91,39 @@ public class sigPlace { final static int TRANSPARENT = new Color(0,0,0,0).getRGB(); public static void main(String[] args) { + final Color SDVX_UI_COL = new Color(48,48,48); if (args.length>0&&args[0].equals("arcade")) { - System.out.println("Arcade"); + try { + Robot r = new Robot(); + while (true) { + BufferedImage screenshot = r.createScreenCapture(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()); + if (new Color(screenshot.getRGB(1550,604)).equals(SDVX_UI_COL)) { + //This is a SDVX image, so we will flip it. + BufferedImage newCanvas = new BufferedImage(screenshot.getHeight(),screenshot.getWidth(),BufferedImage.TYPE_INT_ARGB); + for (int x=0;x