An Automatic SC2 Game Start Switcher - Page 2
| Forum Index > SC2 General |
|
Vallz
41 Posts
| ||
|
tehemperorer
United States2183 Posts
I do have a few questions though, if you don't mind!1. Why the multiple s = reader.readLine();? You have 3, which means I think that only the last readLine() is actually stored. Wasn't sure if you were trying to do a StringBuilder.append kinda thing or not 2. You spawn a lot of threads, not sure if it's necessary... Main is a thread, then you invoke an anonymous Runnable (another thread), which then spawns a new thread every time Runtime.getRuntime().exec(command) is read. Check back over those! 3. There are other ways of course to do things. One of which could be taking a few command line arg into main and using those as the values that drive the program. Here is the refactored code! + Show Spoiler + /* Created by Zamiel on Feb. 26, 2013 */ import javax.swing.*; import java.io.*; public class SC2GameStartSwitcher { private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("StarCraft II Automatic Game Start Switcher"); JLabel label = new JLabel("Detecting SC2 game starts. Feel free to minimize this window."); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(label); frame.setSize(500,100); frame.setVisible(true); } public static int getStartModule() { // returns 0 if not in a game, 1 if in a game String s = getValue("reg query HKCU\\Software\\Razer\\Starcraft2 /v StartModule"); if (s.contains("0x1")){ return 1; } else if (s.contains("0x0")){ return 0; } else { return -1; } } public static int getAPMValue() { String[] splits = getValue("reg query HKCU\\Software\\Razer\\Starcraft2 /v APMValue").split(" "); return Integer.parseInt(splits[12]); } public static Process execute(String command){ try { return Runtime.getRuntime().exec(command); } catch (IOException e) { e.printStackTrace(); return null; } } public static String getValue(String regValue){ try { Process p = execute(regValue); p.waitFor(); java.io.InputStream is = p.getInputStream(); java.io.BufferedReader reader = new java.io.BufferedReader(new InputStreamReader(is)); String s = null; s = reader.readLine(); s = reader.readLine(); s = reader.readLine(); is.close(); return s; } catch (Exception e){ return null; } } public static void main(String[] args) { int gameState = 0; //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); while (true) { // run forever try { Thread.sleep(10); // pause for 10 milliseconds } catch (InterruptedException E) { Thread.currentThread().interrupt(); } switch (gameState){ case 0: // not in a game if (getStartModule() == 1) { // we are now loading the game gameState = 1; } if (getAPMValue() != 1000) { // set the current APM to an arbitrary value so that we can detect a change once the game starts execute("reg add HKCU\\Software\\Razer\\Starcraft2 /v APMValue /d 1000 /f"); } case 1: if (getAPMValue() != 1000) { // the APM has changed which means that loading is done execute("wscript activateSC2.vbs"); gameState = 2; } case 2: // we are playing a game if (getStartModule() == 0) { // we have left the game gameState = 0; } } } } } EDIT: aww, all formatting was lost! | ||
|
ACrow
Germany6583 Posts
Is this just to shave off the approx. 10secs of loading screen? Anyhow, if this helps people, props to you, nice that you're trying to help out! | ||
|
Dingodile
4139 Posts
| ||
|
ECA.BruTATroN
United States282 Posts
| ||
|
skeldark
Germany2223 Posts
The TOS dont talk about Ram or registry. It says you are not allowed to collect information about the game. So it makes no diffrence if you read the ram, read the registry, open the sc2 folder, install the game or play the game. Its all against the TOS. TLDR: Blizzard TOS is not worth the bytes it is saved in. btw you dont have to watch for a change in the apm entry (if you really do that) there is an "ingame" entry in the reg folder. | ||
|
Godwrath
Spain10135 Posts
| ||
|
Zamiel
United States211 Posts
All of the other posts contain criticisms or questions that are already addressed earlier in the thread. | ||
|
tehemperorer
United States2183 Posts
On February 28 2013 04:07 Zamiel wrote: tehemperorer, I appreciate the suggestions, but as you can see from a few posts back, I've already completely rewritten the program in C#, which has subsequently made it a lot cleaner. (I haven't updated the OP yet. I guess I'll do that now. All of the other posts contain criticisms or questions that are already addressed earlier in the thread. Cool man! | ||
|
Zamiel
United States211 Posts
I didn't bother to make a GUI for it, since its not really necessary, and well, I don't know how. =p Enjoy! | ||
|
Snoodles
401 Posts
| ||
| ||
I do have a few questions though, if you don't mind!