diff options
| author | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
| commit | c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch) | |
| tree | df9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/console/Gamma.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/console/Gamma.java')
| -rw-r--r-- | NET/worlds/console/Gamma.java | 555 |
1 files changed, 555 insertions, 0 deletions
diff --git a/NET/worlds/console/Gamma.java b/NET/worlds/console/Gamma.java new file mode 100644 index 0000000..422a88b --- /dev/null +++ b/NET/worlds/console/Gamma.java @@ -0,0 +1,555 @@ +package NET.worlds.console; + +import NET.worlds.core.IniFile; +import NET.worlds.core.Std; +import NET.worlds.network.NetUpdate; +import NET.worlds.scape.MusicManager; +import NET.worlds.scape.Pilot; +import NET.worlds.scape.TeleportAction; +import NET.worlds.scape.TeleportStatus; +import NET.worlds.scape.World; +import java.awt.Button; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.text.MessageFormat; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.NoSuchElementException; +import java.util.Properties; +import java.util.StringTokenizer; + +public class Gamma implements Runnable, MainCallback, TeleportStatus { + private static SplashScreen splash = null; + public static ProgressBar loadProgress; + static final int LOAD_PROGRESS_STEPS = 12; + static final float failVersion = 1.13F; + private static String _home = "file:"; + private static String _dllPath = "home:"; + private static Hashtable<String, String> _params = new Hashtable<String, String>(); + private static boolean _autoplay = false; + static Shaper shaper; + private String startingURL; + private String loadErr; + + static boolean checkVersion(String ver) { + StringTokenizer tok = new StringTokenizer(ver, "._"); + float version = 0.0F; + + try { + Integer i = new Integer(tok.nextToken()); + version = i.intValue(); + i = new Integer(tok.nextToken()); + float min = i.floatValue() / 10.0F; + if (!(min < 1.0F)) { + return true; + } + + version += min; + i = new Integer(tok.nextToken()); + min = i.floatValue() / 100.0F; + version += min; + } catch (NoSuchElementException var9) { + } + + if (version <= 1.13F) { + BlockingDialog d = new BlockingDialog(new Frame(), "Worlds.com: Error", true); + GridBagLayout gbl = new GridBagLayout(); + d.setLayout(gbl); + d.setSize(200, 150); + MultiLineLabel mll = new MultiLineLabel("Your system's Java Virtual Machine\nis out of date. Please download our\nfull installer and try again."); + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = 0; + gbl.setConstraints(mll, c); + d.add(mll); + Button b = new Button("OK"); + b.addActionListener(d); + GridBagConstraints c2 = new GridBagConstraints(); + c2.gridx = 0; + c2.gridy = 1; + gbl.setConstraints(b, c2); + d.add(b); + d.validate(); + d.show(); + d.waitForResponse(); + return false; + } else { + return true; + } + } + + public static void main(String[] args) { + String worldURL = parseCommandLine(args); + String s = System.getProperty("java.version"); + if (!checkVersion(s)) { + System.exit(0); + } + + String vendor = System.getProperty("java.vendor"); + System.out.println("User running java version " + s + " from vendor " + System.getProperty("java.vendor")); + String awtDll = "winawt"; + String netDll = "net"; + boolean msvm = false; + if (vendor.indexOf("Microsoft") != -1) { + awtDll = "MSAWT"; + netDll = "MSNET32"; + msvm = true; + } + + System.out.println("Loading: " + earlyURLUnalias(_dllPath + "gamma.dll")); + System.load(earlyURLUnalias(_dllPath + "gamma.dll")); + if (msvm) { + Window.doMicrosoftVMHacks(); + } + + if (IniFile.gamma().getIniInt("MULTIRUN", 0) == 0 && !Startup.synchronizeStartup(worldURL, _autoplay)) { + System.exit(0); + } + + if (s.charAt(2) <= '1' && !msvm) { + try { + System.loadLibrary(awtDll); + } catch (UnsatisfiedLinkError var35) { + } + + try { + System.loadLibrary(netDll); + } catch (UnsatisfiedLinkError var34) { + } + } else { + if (!msvm) { + awtDll = "awt"; + } + + new Color(0, 0, 0); + + try { + URL stupid = new URL("http://127.0.0.1/"); + URLConnection uc = stupid.openConnection(); + uc.connect(); + } catch (MalformedURLException var36) { + } catch (IOException var37) { + } + } + + if (!msvm) { + Window.hookWinAPIs(awtDll); + } + + String inihome = earlyURLUnalias("home:worlds.ini"); + Std.initProductName(); + IniFile install = IniFile.override(); + String splashgif = install.getIniString("splashgif", Console.message("Opnscrnc.gif")); + splash = new SplashScreen(GammaFrame.getDefaultTitle(), splashgif); + splash.show(); + splash.toFront(); + String proxyIP = IniFile.gamma().getIniString("Proxy Server IP", ""); + String proxyPort = IniFile.gamma().getIniString("Proxy Server Port", ""); + if (proxyIP.length() > 7) { + Properties p = System.getProperties(); + System.out.println("Using Proxy Server: " + proxyIP + ":" + proxyPort); + p.remove("socksProxyHost"); + p.remove("socksProxyPort"); + p.put("socksProxyHost", proxyIP); + p.put("socksProxyPort", proxyPort); + System.setProperties(p); + } + + loadProgress = new ProgressBar("Loading Worldsplayer...", 12); + Dimension sd = splash.getSize(); + Dimension d = loadProgress.getSize(); + int px = splash.getLocationOnScreen().x + (sd.width >> 1) - (d.width >> 1); + int py = splash.getLocationOnScreen().y + sd.height; + loadProgress.setLocation(px, py); + loadProgress.show(); + java.awt.Cursor c = java.awt.Cursor.getPredefinedCursor(3); + loadProgress.setCursor(c); + splash.setCursor(c); + if (inihome.length() > 1 && inihome.charAt(1) == ':') { + Startup.computeVolumeInfo(inihome.charAt(0) + ":\\"); + } else { + Startup.computeVolumeInfo(null); + } + + try { + LogFile.open(); + Gamma g = new Gamma(worldURL); + Main.register(g); + if (loadProgress != null) { + loadProgress.setMessage("Starting main thread..."); + loadProgress.advance(); + } + + Thread mainThread = new Thread(g, "Gamma Main"); + mainThread.setDaemon(true); + mainThread.start(); + new Gamma.PriorityAdjuster(mainThread); + if (loadProgress != null) { + loadProgress.setMessage("Initializing ActiveX..."); + loadProgress.advance(); + } + + new Netscape(); + + try { + mainThread.join(); + } catch (InterruptedException var30) { + throw new Error(var30.toString()); + } + + GammaFrame frame = Console.getFrame(); + if (frame != null) { + frame.setVisible(false); + } + } catch (OutOfMemoryError var31) { + System.out.println("ERROR: Ran out of memory!!"); + System.out.println("Details: " + var31); + } catch (Throwable var32) { + System.out.println("Uncaught throwable: " + var32); + } finally { + LogFile.close(); + } + + System.exit(0); + } + + public static void hideSplash() { + if (splash != null) { + splash.hide(); + splash.dispose(); + splash = null; + if (loadProgress != null) { + loadProgress.hide(); + loadProgress.dispose(); + loadProgress = null; + } + } + } + + public static String earlyURLUnalias(String url) { + if (url.startsWith("home:")) { + url = _home + url.substring(5); + } + + if (url.startsWith("file:")) { + url = url.substring(5); + } + + url = url.replace('\\', '/'); + if (url.length() < 2 || url.charAt(1) != ':' && !url.startsWith("//")) { + String curDir = System.getProperty("user.dir").replace('\\', '/'); + if (!curDir.endsWith("/")) { + curDir = curDir + "/"; + } + + url = curDir + url; + } + + return url; + } + + public static String getParam(String name) { + return _params.get(name); + } + + private static String parseCommandLine(String[] args) { + String world = null; + + for (int i = 0; i < args.length; i++) { + if (args[i].length() > 0 && args[i].charAt(0) == '-') { + if (args[i].equalsIgnoreCase("-help")) { + usage("Help message"); + } else if (args[i].equalsIgnoreCase("-home")) { + if (++i == args.length) { + usage("-home must be followed by a path:"); + } + + _home = "file:" + args[i]; + System.out.println("Home: " + args[i]); + } else if (args[i].equalsIgnoreCase("-dllpath")) { + if (++i == args.length) { + usage("-dllpath must be followed by a path:"); + } + + _dllPath = args[i]; + } else if (args[i].equalsIgnoreCase("-set")) { + label51: { + if (++i != args.length) { + if (++i != args.length) { + break label51; + } + } + + usage("-set must be followed by a name of a parameter to set and its value"); + } + + _params.put(args[i - 1], args[i]); + } else if (args[i].equalsIgnoreCase("-autoplay")) { + _autoplay = true; + } else if (!args[i].equalsIgnoreCase("-embedding") + && !args[i].equalsIgnoreCase("/embedding") + && !args[i].equalsIgnoreCase("-automation") + && !args[i].equalsIgnoreCase("/automation")) { + usage("Unrecognized command line option: " + args[i]); + } + } else { + if (world != null) { + usage("There may be only one command-line world URL"); + } + + world = args[i]; + } + } + + _home = makeEndWithSlash(_home); + _dllPath = makeEndWithSlash(_dllPath); + return world; + } + + private static String makeEndWithSlash(String url) { + if (!url.endsWith("\\") && !url.endsWith("/") && !url.endsWith(":")) { + url = url + "\\"; + } + + return url; + } + + public static void usage(String msg) { + System.out + .println( + "Usage: javaw {-java_options} NET.worlds.console.Gamma {-options} WorldURL\nWorldURL is optional, the default world is the first WorldsMark.\nYes, it's gross, but the 'NET.worlds.console.Gamma' is required\nSome useful -java_options:\n -classpath Path Class search path [default is CLASSPATH env var]\n-options:\n -help Print this message (still runs Gamma)\n -home HomeDir Gamma home directory [defaults to current dir]\n -dllpath DLLPath Path to the native code DLL [current directory]\n -set Name Value Set the named parameter to the specified value" + ); + throw new Error(msg); + } + + public static String getHome() { + return _home; + } + + public static String getExePath() { + return getHome() + "bin\\"; + } + + public static void dllLoad(String dll) { + System.load(NET.worlds.network.URL.make(_dllPath + dll).unalias()); + } + + public static Shaper getShaper() { + return shaper; + } + + public static boolean shaperEnabled() { + return IniFile.gamma().getIniInt("DISABLESHAPER", 1) == 0 || IniFile.override().getIniInt("DISABLESHAPER", 1) == 0; + } + + private Gamma(String url) { + this.startingURL = url; + } + + private void die(Throwable e) { + e.printStackTrace(System.out); + if (getShaper() != null) { + Console.println(Console.message("Saving-modified")); + Enumeration<World> worlds = World.getWorlds(); + + while (worlds.hasMoreElements()) { + World w = worlds.nextElement(); + if (w.getEdited()) { + String base = w.getSourceURL().unalias(); + if (base.toLowerCase().endsWith(".wor")) { + base = base.substring(0, base.length() - 4); + } + + if (base.toLowerCase().endsWith(".world")) { + base = base.substring(0, base.length() - 6); + } + + int dash = base.lastIndexOf("-"); + if (dash != -1) { + for (int i = dash + 1; i < base.length(); i++) { + if (!Character.isDigit(base.charAt(i))) { + dash = -1; + break; + } + } + } + + if (dash != -1) { + base = base.substring(0, dash); + } + + String name = base + ".world"; + + for (int number = 1; new File(name).exists(); number++) { + name = base + "-" + number + ".world"; + } + + Object[] arguments = new Object[]{new String(w.getName()), new String("" + w.getSourceURL()), new String(name)}; + Console.println(MessageFormat.format(Console.message("Saving-name"), arguments)); + + try { + Shaper.doSave(name, w, false); + } catch (Exception var10) { + Console.println(Console.message("Ignoring") + var10); + } catch (Error var11) { + Console.println(Console.message("Ignoring") + var11); + } + } + } + } + } + + @Override + public void run() { + Main.register(new Gamma.RecordPosition()); + + try { + Main.mainLoop(); + } catch (Throwable var2) { + this.die(var2); + } + } + + @Override + public void mainCallback() { + Main.unregister(this); + if (NetUpdate.doUpdate(false)) { + Main.end(); + } else { + File bin = new File(earlyURLUnalias("home:bin")); + File prg = new File(bin, "gdkup.prg"); + File exe = new File(bin, "gdkup.exe"); + if (prg.exists() && (!exe.exists() || prg.lastModified() > exe.lastModified())) { + if (exe.exists()) { + exe.delete(); + } + + try { + FileInputStream i = new FileInputStream(prg); + FileOutputStream o = new FileOutputStream(exe); + byte[] buf = new byte[8192]; + + int len; + while ((len = i.read(buf)) > 0) { + o.write(buf, 0, len); + } + + i.close(); + o.close(); + } catch (Exception var10) { + var10.printStackTrace(System.out); + throw new Error("Can't copy gdkup.prg"); + } + } + + if (shaperEnabled()) { + shaper = new Shaper(); + } + + IniFile install = IniFile.override(); + String splashOver = install.getIniString("splashover", Console.message("Pwc.gif")); + int splashXOver = install.getIniInt("splashxover", 141); + int splashYOver = install.getIniInt("splashyover", 140); + if (splashXOver >= 0) { + splash.addOverlay(splashOver, splashXOver, splashYOver); + } + + if (loadProgress != null) { + loadProgress.setMessage("Teleporting to start location..."); + loadProgress.advance(); + } + + try { + TeleportAction.teleport(this.startingURL, this, false); + } catch (Exception var9) { + this.loadErr = "Couldn't teleport to " + this.startingURL + ": " + var9; + } + + if (this.loadErr != null) { + System.out.println(this.loadErr); + this.loadErr = null; + TeleportAction.teleport("world:", this, false); + if (this.loadErr != null) { + this.loadErr = null; + TeleportAction.teleport("home:NewWorld.world", this, false); + if (this.loadErr != null) { + Main.end(); + return; + } + } + + Main.register(new Gamma.StartupTeleport()); + } + + new MusicManager(); + } + } + + @Override + public void teleportStatus(String err, String url) { + if (err == null) { + this.loadErr = null; + } else { + this.loadErr = err; + } + } + + static class PriorityAdjuster implements MainCallback { + private Thread mainThread; + boolean wasActivated = true; + + PriorityAdjuster(Thread t) { + this.mainThread = t; + this.mainThread.setPriority(5); + Main.register(this); + } + + @Override + public void mainCallback() { + if (Window.isActivated() != this.wasActivated) { + this.wasActivated = !this.wasActivated; + this.mainThread.setPriority(this.wasActivated ? 5 : 1); + } + } + } + + public class RecordPosition implements MainCallback, MainTerminalCallback { + @Override + public void mainCallback() { + } + + @Override + public void terminalCallback() { + Pilot pilot = Pilot.getActive(); + if (pilot != null) { + IniFile.gamma().setIniString("RestartAt", pilot.getURL()); + } + + Main.unregister(this); + } + } + + class StartupTeleport implements MainCallback { + @Override + public void mainCallback() { + if (Console.getFrame() != null && Console.getFrame().isShowing()) { + Main.unregister(this); + + try { + TeleportAction.teleport(Gamma.this.startingURL, Gamma.this, true); + } catch (Exception var2) { + } + } + } + } +} |