Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Moleboxing Java Programs?  (Read 1877 times)
0 Members and 1 Guest are viewing this topic.
Offline Evanstaul

Senior Newbie





« Posted 2006-06-13 07:11:39 »

Ok, right now I have a my own stripped JRE and bought Molebox. I thought it was going to be easy but I don't know the exact procedure.   

At first, I used JSmooth then Moleboxed that, I thought it was working but it actually was not using my JVM but one it searched for. 

I read a previous thread about making a simple launcher using VC.  Then I made a small program that did ShellExecute on the exact JVM, then Moleboxed that, and that didn't work either.

Can someone guide me on exactly what I can use to make one nice clean EXE for my game?  I'm trying to finish it soon.

Thanks very much!
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2006-06-13 11:26:38 »

My Molebox config file for Titan:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
box.cmdline=
box.encrypt=0
box.packdefault=1
box.pattern=*.*
box.separate=0
box.sepfile=
box.ziplevel=0
dir.addfiles=C:\Projects\Puppy Invaders Deluxe\build\molebox
exe.crc=0
exe.pack=1
exe.packedfilesvisible=1
exe.source=C:\Projects\Puppy Invaders Deluxe\build\molebox\TitanAttacks.exe
exe.target=..\TitanAttacks\TitanAttacks.exe
key.0=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
key.1=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

box.contents~
00 common.jar
00 gamecommerce.jar
00 jorbis.jar
00 lwjgl.jar
00 lwjgl_util.jar
00 spgl-lite.jar
00 TitanAttacks.jar
00 bin\dt_shmem.dll
00 bin\dt_socket.dll
00 bin\hpi.dll
00 bin\java.dll
00 bin\net.dll
00 bin\nio.dll
00 bin\rmi.dll
00 bin\verify.dll
00 bin\zip.dll
00 bin\client\jvm.dll
00 lib\ (and then the entire contents of the JRE lib folder follow basically)
~


Cas Smiley

Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #2 - Posted 2006-06-13 11:31:16 »

My launcher exe is based on some code I found years ago but basically it's just a trivial bit of JNI code to run the game from a directory that contains the bin and lib directories of the JRE. The only important bit in it looks like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
#include "launcher.h"

static JNIEnv *env;
static jobject jobj = 0;
static JavaVM *vm;

typedef jint (APIENTRY * CreateJavaVMPROC) (JavaVM **pvm, void **penv, void *args);

int WINAPI WinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow
) {


    jint res;
   jclass cls;
    jmethodID mid;
    jobjectArray args;
    JavaVMInitArgs vm_args;
    JavaVMOption options[5];

   options[0].optionString = "-Djava.class.path=patch.jar;TitanAttacks.jar;gamecommerce.jar;spgl-lite.jar;common.jar;jorbis.jar;lwjgl.jar;lwjgl_util.jar";
   options[1].optionString = "-Xmx48m";
   options[2].optionString = "-Xms24m";
   options[3].optionString = "-Xincgc";
   options[4].optionString = "-Dworkdir=.";

   HMODULE jvmdll = LoadLibrary("bin\\client\\jvm.dll");
   if (jvmdll == NULL) {
      messageBox("Failed to load Java dll.");
   }

    vm_args.version = JNI_VERSION_1_2;
    vm_args.options = options;
    vm_args.nOptions = 5;
    vm_args.ignoreUnrecognized = TRUE;

   CreateJavaVMPROC CreateJavaVM = (CreateJavaVMPROC) GetProcAddress(jvmdll, "JNI_CreateJavaVM");

    res = CreateJavaVM(&vm, (void **)&env, &vm_args);

    if (res < 0) {
        return 0;
    }

    // Get the main class
   cls = env->FindClass(MAIN_CLASS);

    if (cls == 0) {
        return 0;
    }

    // Get the method ID for the class's main(String[]) function.
   mid = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");

    if (mid == 0) {
        messageBox("Failed to find the main method.");
        return 0;
    }
        args = env->NewObjectArray(0,
                        env->FindClass("java/lang/String"), NULL);
    env->CallStaticVoidMethod(cls, mid, args);

   return 1;

}


The lwjgl.dll and OpenAL32.dlls live OUTSIDE the Molebox, and are distributed alongside the moleboxed exe.

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Evanstaul

Senior Newbie





« Reply #3 - Posted 2006-06-13 18:14:46 »

Hi Cas, thanks very much, that was extremely helpful!  I did run into two problems that I hope you can help me with.

First, I have your CPP compiling fine and it does run my game properly, but when the launcher exits it also stops the Java right away.  So I just see a window blink for a second.  If I make the launcher put up a message box and leave it there, the whole game will run fine, but with a message box of course.  There must be some way for the launcher or Java to keep the process running even after the launcher quits.  Have you encountered this problem before?

Second, can standard Molebox bundle JVM (with DLLs), or I have to buy Molebox Pro?  It seems like its only Pro, but I still can't get the game running with Molebox even with the cheap fix of putting a message box up.  Some ending debug info from Molebox Pro evaluation version:

Quote
[   275:04c8] :DLL_LOADER:call to default routine 0x6d7cd0fd
[   275:04c8] :DLL_LOADER:done with result 0x1
[   276:04c8] :BOX:CloseFile: 'JRE\BIN\CLIENT\JVM.DLL'
[   277:04c8] :WRAPPER:LoadLibrary: jre\bin\client\jvm.dll, handle is 6d6b0000
[   295:0730] :FakeMainDLL: hDLL 0x6d6b0000, reason 0x2, reserved 0x0,defEPoint 0xcaaf2e19, pzVname 0x962f50
[   295:0730] :DLL_LOADER: DLL_THREAD_ATTACH (D:\PROJECT\GAME\MAJINWAR 2\FINAL\APP-WIN\jre\bin\client\jvm.dll)
[   295:0730] :DLL_LOADER:call to default routine 0x6d7cd0fd
[   296:0730] :DLL_LOADER:done with result 0x1

Thanks very much!
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #4 - Posted 2006-06-13 19:47:25 »

The shouldn't quit at all - it just starts executing Java when it calls  env->CallStaticVoidMethod(cls, mid, args);

You are probably going to need to get Molebox Pro.

Cas Smiley

Offline Evanstaul

Senior Newbie





« Reply #5 - Posted 2006-06-13 20:27:45 »

I got it to stop closing, maybe our configs are different.  But I found a JNI function called DetachCurrentThread() that fixes my problem.  I now got it working completely, but not with Molebox yet.

I just bought MoleBox Pro and I still can't get it working it crashes with no message right on CreateJavaVM().  So it was atleast able to find jvm.dll in the EXE.  I already emailed Molebox to see if they can give me some clues. 

Thanks!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (12 views)
2014-07-30 21:08:39

Riven (21 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (29 views)
2014-07-23 21:07:15

Riven (30 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!