Note that there are some explanatory texts on larger screens.

plurals
  1. POEmbedding a jar file into C#
    text
    copied!<p>i have a jar file that loads a game, and i want to embed it into a C# application. Is there any way i can do this, i thought you could do it by using IKVM but i can seem to find out how to. Thanks.</p> <p>If you want to see my java code:(It will take a while to load if you try it out)</p> <pre><code>import java.applet.*; import java.awt.Dimension; import java.io.*; import java.net.*; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.*; public class OSRSLoader implements AppletStub { static JMenuBar menubar; static JFrame i; public static void main(String args[]) throws Exception { new OSRSLoader(); } public OSRSLoader() throws Exception, FileNotFoundException { JFrame i = new JFrame("RS Oldschool Client Beta V1:00"); i.setSize(new Dimension(763, 514)); i.setPreferredSize(new Dimension(763, 514)); JLabel label = new JLabel(); ImageIcon icon = new ImageIcon(new URL("http://www.runescape.com/image/rsp777/oldschool_ani.gif")); icon.setImageObserver(null); label.setIcon(icon); i.add(label); i.pack(); i.setVisible(true); String str = getPageSource(new URL("http://oldschool38.runescape.com")); Pattern pattern = Pattern.compile("gamep\\w+"); Matcher match = pattern.matcher(str); if(match.find()) { OSRSLoader stub = new OSRSLoader(Pattern.compile("&lt;param name=\"([^\\s]+)\"\\s+value=\"([^&gt;]*)\"&gt;"), str); Download("http://oldschool38.runescape.com/", (new StringBuilder(String.valueOf(match.group(0)))).append(".jar").toString()); stub.setCodeBase(new URL((new StringBuilder("http://oldschool38.runescape.com/")).append(match.group(0)).append(".jar").toString())); stub.setDocumentBase(new URL((new StringBuilder("http://oldschool38.runescape.com/")).append(match.group(0)).append(".jar").toString())); stub.getParameter((String)parameters.get("java_arguments")); URLClassLoader classLoader = new URLClassLoader(new URL[] { new URL("file:gamepack.jar") }); Applet applet = (Applet)classLoader.loadClass("client").newInstance(); applet.setStub(stub); applet.setSize(new Dimension(763, 504)); applet.init(); applet.start(); i.add(applet); i.pack(); i.setDefaultCloseOperation(3); label.setVisible(false); } } private void createMenuBar() { } public OSRSLoader(Pattern parameterPattern, String frameSource) { String key; String value; for(Matcher param = parameterPattern.matcher(frameSource); param.find(); System.out.println((new StringBuilder("Parameter Loaded. Key = ")).append(key).append(", value =").append(value).toString())) { key = param.group(1); value = param.group(2); parameters.put(key, value); } } private String getPageSource(URL url) throws IOException, InterruptedException { URLConnection cn = url.openConnection(); cn.addRequestProperty("Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"); cn.addRequestProperty("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); cn.addRequestProperty("Accept-Encoding", "gzip,deflate"); cn.addRequestProperty("Accept-Language", "en-gb,en;q=0.5"); cn.addRequestProperty("Connection", "keep-alive"); cn.addRequestProperty("Host", "www.runescape.com"); cn.addRequestProperty("Keep-Alive", "300"); cn.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:9.0.1) Gecko/20100101 Firefox/9.01"); DataInputStream di = new DataInputStream(cn.getInputStream()); byte tmp[] = new byte[cn.getContentLength()]; di.readFully(tmp); di.close(); Thread.sleep(250 + (int)Math.random() * 500); return new String(tmp); } public void appletResize(int i, int j) { } public void setCodeBase(URL codeBase) { this.codeBase = codeBase; } public void setDocumentBase(URL documentBase) { this.documentBase = documentBase; } public AppletContext getAppletContext() { return null; } public URL getCodeBase() { return codeBase; } public URL getDocumentBase() { return documentBase; } public String getParameter(String name) { return (String)parameters.get(name); } public boolean isActive() { return false; } public static void Download(String world, String archive) throws Exception { URLConnection jarConnection = (new URL((new StringBuilder(String.valueOf(world))).append(archive).toString())).openConnection(); FileOutputStream out = new FileOutputStream("./gamepack.jar"); InputStream input = jarConnection.getInputStream(); byte info[] = new byte[1024]; int ln; while((ln = input.read(info)) != -1) out.write(info, 0, ln); } private static Map parameters = new HashMap(); private URL codeBase; private URL documentBase; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload