Monday, May 21, 2012

Java-ZeroMQ for Android

Those last weeks at work, I have been busy on a project that had several subtopics.

Among them, was to use ZeroMQ sockets with an Android phone.

That should have been simple, since ZeroMQ has published a page that explains how to realize this.

Unfortunately, those instructions are not as effective as they promise. And I am not the onliest to have met issues.

I'm not sure if there is a chance that the libraries can actually cross-compile properly with the method exposed on the official Wiki, but it looked unlikely to.

Furthermore, the page only explains how to generate the single libzmq.so and not its JNI port (and high-level improvements) : jzmq.

The goal then was to generate a self-contained binary that embedded the JNI port functions, the ZeroMQ library itself and its libuuid dependency.

And finally, since Android APKs only accept native libraries that end up with .so (no version numbers) it was also mandatory to get the Makefiles to generate a version-free binary (avoid soname definition)

After a few hunches (well, in fact, a lot) I came up with an almost-proper solution : a collection of scripts to ./configure the three interdependent packages  (e2fsprogs, zeromq and jzmq) without modification and have them together generate the native library and the associated jar easily, with the help of a top-level Makefile.

It also downloads the stable packages from their www location.

I said "almost" proper, because the real clean solution would be to intervene to modify the Wiki, propose patches, etc... But you know, it came up like this, and maybe that will be integrated to ZeroMQ in a nicer way in the future if that's the way to go.

Issues mostly came from Jzmq though, since it has not been very actively maintained since almost a year now, and has a few incompatibilities with the new autotools suite.

The final solution is usable as a one-liner : export [...] && make.

It generates a zmq.jar file that is directly usable in your Android app, which automatically loads the libjzmq.so that you have also generated and wisely copied in the libs/armeabi folder of the same application.

See the code on github, and enjoy !

Please report issues and further improvements if you care.

References

Thanks to Mikael Le Goff for the first tests and support with this.
Thanks to Dave for his post that helped me fix a few last issues a lot quicker !

Wednesday, May 2, 2012

Diablo 3 with wine under Linux x86_64

Hello everybody. 

Holiday in Japan: fiancée flew back to France a few days ago, and low on money.
3 days like a gremlin in its cave, my back really makes me suffer.
I switch chairs; geek again until late night. 

A noble goal. 
Have that long-awaited Diablo III run under my freshly-installed Precise Pangolin, 64-bit. 
Here are the steps. 

1. Precise Pangolin 

Unity now works great. 
It pleases power users too: no more clicks. Almost never.
Better than Mint, which had awful bugs from time to time.

2.  Diablo III - Beta

 

a) Get Wine to work
$ sudo apt-get build-dep wine1.4
$ tar xjvf wine-1.5.3.tar.bz2 
$ cd ~/wine-1.5.3
$ patch -p1 < 0001-AcceptEX-patch.patch
$ patch -p1 < reset.patch
$ ./configure
$ make
  • Compress the wine-1.5.3 folder, copy it to your x64 machine.
  • Download winetricks. 
  • Install Visual Studio runtime.
$ env WINE=$HOME/wine-1.5.3/wine sh $HOME/wine-1.5.3/winetricks vcrun2010

b. Get Diablo 3
$ ~/wine-1.5.3/wine Diablo-III-Beta-enUS-Setup.exe


If that does not work, install it in a Windows virtual machine and copy its whole installation folder back to your Linux box.

If you have a Battle.Net account at that point, or an open beta key, you're good to go.

$ ~/wine-1.5.3/wine ~/d3beta/Diablo\ III.exe -launch

If you want to play the beta without a key, or if you want to enjoy the game by yourself in offline mode, follow the rest.


 c. Get Mooege & Patcher  

Mooege is a Battle.Net emulator for Diablo 3.
It does suffer a few bugs, but works already quite well.
There are different ways to install it.
You can pick a precompiled version here, or compile it yourself.
Since it's C#, you can compile it for Mono or .NET4.
All the steps for this are detailed there.
From what I tried, the bugs are the same with both compilation modes...
It does crash randomly because of garbage collection issues under Wine.

The best choice is still to make Mooege run in a VirtualBox.
  • Install Windows in a virtual machine.
  • Add a bridge network adapter.
Bridge adapter attached to the Wifi interface
  • You'll see the network address of it when running the virtual machine.
Here is the IP of this machine on my LAN.
  • Mooege: there is an Assets\MPQ folder in your Mooege root folder (or the one you built with VS2010 or Mono). Copy all the files and folders from your C:\Program Files\Diablo III Beta\Data_D3\PC\MPQs folder into Assets\MPQ.
  • Run Mooege afterwards.
Mooege in background.
  • Now run Diablo with that command line:
$ ~/wine-1.5.3/wine ~/d3beta/Diablo\ III.exe -launch -auroraaddress 192.168.11.112:1345


When you get to the login screen, stop. You can go to video settings in D3 to make it windowed.
Login screen on my computer.

There is an issue in the latest versions of the Beta that force us to patch the Battle.net library in order to continue.
That may be fixed in the future versions of Mooege though, but nothing for sure.

There's an in-memory patcher (Egris BNet Patcher) that does that job.
Unfortunately it has been designed for people under Windows.
I have had some feedback that said it may work under Linux, once compiled against .NET2.0 .
Didn't work out for me though.

So there's a C code that does the same job under Linux.
Not well refined, you have to use sudo under Ubuntu to make it work (new policies...) and it does not detect by itself Diablo 3 process.

If that topic becomes hot, I'll maybe improve the stuff.

Last lines then:
  • Compile and run the patcher, login screen still on. 
$ git clone git@github.com:vperron/linux_bnet_patcher.git
$ cd linux_bnet_patcher
$ make linux_bnet_patcher
$ ps aux              [get the Diablo3 process ID]
$ sudo ./linux_bnet_patcher <Diablo3_PID>
  • Once the job's done, enter the Mooege credentials.
Login: test@
Password: what you want.

Click play. Choose a character. Enjoy.

Final setup.

References

Thread on WineHQ
Thread on OwnedCore
...information from too many places to be listed.