Sunday, December 15, 2013

The Lords of Midnight: 8 bit remake returns

I have some good news regarding my old remake of The Lords of Midnight on Android.

First a reminder of the context. You may recall that Chris Wild and Mike Singleton worked together on an update of the Midnight saga with a planned release on iPhone and iPad. That was before we all learned the sad news that Mike had passed away last year.

After that, Chris finished off the game - albeit at an understandably reduced scope - and he released it on iOS and then later on other platforms.

This new game is available at http://thelordsofmidnight.com, and is a much more ambitious update than my 8-bit-style nostalgic remake. You really ought to check it out :-)

Before this all happened, I had created an unofficial remake of LOM on the Game Boy Advance and then later ported it to Android. It was pretty naïve of me, and Mike asked me nicely to remove these as they were using his copyrighted stuff, and would cause confusion for the upcoming official versions. This I did, and these ports have remained unavailable since.

Then a couple of weeks ago Chris got in touch with me. In a rather generous move, Mike's sons have given me permission to re-release the Android port. They feel it is important for as many people as possible to play the games their dad made. Because of this, "The Lords of Midnight: 8 bit" - as it is now known - is available now on the Google Play store!

If you had installed the previous incarnation you may have noticed an update. Apart from the usual Android build system updates and associated yak-shaving, the name has been changed to reflect this new deal. I also fixed some graphical hiccups that were more obvious on my 7" tablet test device, as well as adding the obligatory higher resolution icons. The other noticeable change is that there is now an extra splash screen that says that this port is released under licence (from the Singleton family) with the address of the official website at www.thelordsofmidnight.com.

I ought to state that this does not indicate a free for all on Mike Singleton's games. The copyright and trademarks are still the property of the Singleton estate. While I have been granted permission for the release of this one port, it is under licence with the understanding that the game remains free and that I "do no evil", so to speak.

What a nice and unexpected early Christmas present, eh folks?


Saturday, December 07, 2013

Blogger Themes That Break With NoScript

Blogger Themes That Break With NoScript TL;DR: here's a Blogger Feed bookmarklet to fix some blogger blogs that fail to load if you're using the Firefox add-on NoScript. Read on for the usual waffle.

I use NoScript with Firefox, and occasionally I'll find a link to a blog that just shows the NoScript icon and a handful of broken links. For example, a recent post on hacker news linked to a security blog post describing a technique to avoid using dangerous C functions with GCC. With NoScript, all I saw was the following:



This is because a new-ish Blogger theme is a big JavaScript application monstrosity that loads the text of the article via an asyncronous call, but does not gracefully degrade for those of us without scripts enabled. The owner of this particular blog has since switched from Blogger to Wordpress, so it's moot in this case.

A poster on HN wrote a bash shell script that downloads the blog, gets the corresponding feed and spits it out in HTML. This is a good idea. However I think that copying the blog link over to a terminal, running the script and then opening the resulting HTML page in the browser is a bit of a pain. Even for me.

Enter some 90s technology - the bookmarklet!

Simply drag the Blogger Feed bookmarklet onto your bookmark toolbar, or right click it and save as a bookmark. Next time you are faced with a NoBlog you just click the button or bookmark and it'll take you straight to the blog's JavaScript-free RSS feed version of the post. I imagine that this will work until Google shuts down Blogger and tries to force us all onto Google+.

In addition, if you want to have an icon for the bookmarklet, here's a tip cribbed from this superuser post:
  1. Find a regular link (without JavaScript) for the website with the favicon you want.
  2. Add that link to your bookmarks toolbar as a regular bookmark.
  3. Finally, change the properties of the bookmark you just added and change the location to be the actual JavaScript bookmarklet you want (you want the location from the bookmarklet that doesn't have the favicon).
These steps turn the bookmark from step 2 into a bookmarklet with the desired favicon and JavaScript. Here's a capture of the bookmarklet with the Blogger icon that I use:




Sadly, if the Blogger blog uses a Feedburner RSS redirect, then this trick doesn't work. However if that's the case then you're probably better off not reading their particular brand of propaganda anyway.

Sunday, September 29, 2013

Unlocking an HTC Magic: 2009 called, they want their unlocking guide updated

The HTC Magic running Android 2.2 has a locked bootloader. This means that you can't install any other operating system, only the official one.

Last year HTC had a change of heart about locking the bootloader and provide a way on their website to unlock your phone. Unfortunately, the HTC Magic ships with software that is too old to recognise the unlock command the website uses. You need to first update this software (the "HBOOT") to a version that is unlockable by HTC.

Go to HTC Dev and create an account. Select HTC Magic and click the unlock button.
HTC Dev

As shown on that screenshot, you are warned that the HBOOT will need to be updated.

This takes you to the section to download the software, called RUU, that updates the phone's HBOOT. RUU probably stands for ROM Unlocking Updater, who knows. Select the RUU corresponding to your model of Magic. I used the one marked Vodafone (AU/FR/DE/IT/NL/NZ/ES/UK/ RO/PTG/CH-GER/Mobilkom).

This RUU software is a Microsoft Windows executable file. In theory you have to use Windows to proceed. However, I don't have a Windows machine available. I got creative. You could probably use this technique on Windows if you have problems, since it sounds like the RUU requires HTC Sync, drivers and other gubbins. If you can run the RUU on Windows, run that and it should update the HBOOT. Follow the HTC Dev instructions, you're almost done. If not, here is what you could do...

According to this xda-developers post the executable unpacks a zip file as part of the process. I figured that if I ran the executable with wine it might extract the file too. The EXE didn't run to the first step though, but did show a progress bar before crashing out.

RUU under Wine on Debian "wheezy"
I paused wine just before the program crashed by hitting ctrl-z, ran find ~/.wine -name rom.zip and bingo! There was the rom.zip I neeed.

Copy this rom.zip file to an SD card. The file must be named exactly SAPPIMG.zip. The file name is case sensitive.

You have to format the SD card as fat32. Fat16 will not work. I should know, as originally I had the card as fat16. I used gparted to format a 1Gb card to fat32.

Start the phone in "HBOOT mode" - which you do by holding down the power and volume down buttons when switching it on. HBOOT mode boots very quickly. All being well, after approximately 5 seconds the blue light will go off and the screen will show some green text (checking SAPPIMG.zip, more or less).

It will ask if you want to continue, hit action (the trackball) to confirm, and then the phone reboots.
Now use the fastboot executable from the htcdev website to extract a token unique to your phone. In Debian I had to use root to do this or it just hung waiting for find devices, so that's sudo ./fastboot oem get_identifier_token

This spat out the following:
/tmp$ sudo ./fastboot oem get_identifier_token
... INFO
INFO< Please cut following message >
INFO<<<< Identifier Token Start >>>>
INFO41BF2ABF132C78CC414238FC47D43442
INFO898C7C87E0CEB4D1C5D55FCDC17647E2
...
INFOBCF34E9487BE0F794BCAEA48646A3870
INFO2946D797752D6167278226973D86BE33
INFO<<<<< Identifier Token End >>>>>
OKAY

Copy this chunk:
<<<< Identifier Token Start >>>>
41BF2ABF132C78CC414238FC47D43442
898C7C87E0CEB4D1C5D55FCDC17647E2
...
BCF34E9487BE0F794BCAEA48646A3870
2946D797752D6167278226973D86BE33
<<<<< Identifier Token End >>>>>

Be careful not to include INFO or have trailing newlines. Paste it into the form on the page on the HTC website. I have no idea of the security implications, so I've not included all of the token here - you get the idea hopefully. You need all the random numbers and letters and the << >>> lines.


HTC will email you a binary file, which you flash to the phone:

sudo ./fastboot flash unlocktoken Unlock_code.bin

The following image shows the unlock screen. It's taken with a Nintendo 3DS in low light, hence the terrible quality.



Press Volume UP to take the red pill, er, I mean unlock the bootloader... then press the power button. The phone will wipe all of your data. Oh no.

That is all. You have unlocked the phone. If you boot into HBOOT again (power, volume down) it should now display UNLOCKED against a fetching fuchsia background.



Thursday, July 25, 2013

Geocities 2.0?

After killing off Reader, I think that Google Sites is going to be the next to get the axe. I just recieved an email that pointed me to this Sunsetting Adsense help page. Rather than sunsetting Adsense, I get the feeling Google is getting itchy to get rid of Sites completely. It probably doesn't fit in with Google+ or something.

Back in 2009 or so, when Geocities closed down, I asked a question on superuser.com about alternatives for easy-to-host websites. The top answer, by the internet's Jon Skeet no less, was "Use Google Sites! It'll never shut down!". You can thank the hive mind on Stackipedia for deleting the question, and now Google Sites has its head firmly in the noose.

On the side bar to the right you might see that I host my old GBA remakes and the Chaos stuff on Google Sites. Now might be a good time for me to look for a new home for 'em.

Ah! While I'm ranting: in other related news about removing information from the web, Yahoo Groups have removed their RSS feeds. I kept track of the Gooey Blob group via the RSS feed. I realized it had gone way because the pretty good Tiny Tiny RSS warns you about dead feeds, unlike Google Reader which swallowed all the RSS errors.

Update 2013-08-17: now Google Code has removed the generic RSS feed too :-( Pages like https://code.google.com/feeds/p/android-ndk-profiler/updates/basic used to show all updates for that project. No more. For now you can still subscribe via RSS to individual Issues, Wiki and Download updates using https://code.google.com/feeds/p/android-ndk-profiler/downloads/basic for downloads,  https://code.google.com/feeds/p/android-ndk-profiler/svnchanges/basic?path=/wiki/ for the Wiki changes and https://code.google.com/feeds/p/android-ndk-profiler/issueupdates/basic for issues. It's only a matter of time until these are removed...

Friday, June 28, 2013

The inevitable bug fix release

After releasing a version with new features, it turns out it also contained 1 show-stopping bug. To fix things, 1.15 of Chaos is out.

Enabling constant saves fell foul of a memory leak in the bit of code that bridged the Android stuff and the older C code. This meant that the game crashed after about 5-10 minutes of playing. My testing obviously wasn't thorough enough.

I've resurrected the stress-test mode on the debug builds of Android now (CFLAGS=-DHAS_STRESS_TEST, configure-fans). In the last release this didn't even compile. Shows how naffly tested it was. I ran the stress test on the SDL/PC version, but not on Android. These versions share about 90% of the code, but the bug was right in the Android glue that only running the game on a device or emulator can test.

The stress mode pits 8 computer-controlled players against each other with no hold-ups, forever. Or until there's a crash at least. Things are looking a lot better now, as it has run for hours with no crashes since the fix. Previously it wouldn't get past about 6 minutes of play.

The fix was a classic memory leak. I needed to delete arrays allocated in the C code.

JNIEnv *env;
jbyteArray jb;
int size;
/* allocate a new byte array */
jb = (*env)->NewByteArray(env, size);
/* do stuff with jb ... */
(*env)->DeleteLocalRef(env, jb); /* !! this was missing */

I had misunderstood who was responsible for this allocated memory. I thought that the virtual machine's garbage collection took care of it, but the evidence indicates that it requires manual intervention.

Lessons learned: 1) automatic tests are great, 2) but not if you don't run them!

Monday, June 17, 2013

Chaos 1.14

The last time I updated Chaos was well over a year ago, so it was about due for an update.

As well as the usual bug fixes, this release has one new feature: automatic saving. Players have asked for this both by email and on the comments in the Android market for a while and it makes quite a difference.

At the end of every turn, the game is now saved. If the game is stopped then next time you start there's a "Continue" option on the first screen.


I've also updated the GBA and NDS versions to include this restore feature. Whether or not saves actually work can depend on the flash cart you use, so watch out for that.

The game saves all data in a plain text format that you can copy around. I've changed the way options are saved to also use text. Previously I just dumped out the in-memory representation for the options into a file. This should fix the problems that people have had where sound effects don't work - in fact they were disabled by default. It was due to reading a 0 first time round and this disabled the sound option.

--

Another change is that the source code for the game is now available again.

The state of Android over the last year or so has worried me. It has become a wretched hive of scum and villainy rivalled only by the dark days of the Windows 98/XP platforms.

The best way to prevent falling victim to spyware is to use software where you can audit the source code yourself. Or at least say "no" when programs require extra permissions. Chaos requires no extra permissions and now you can review the code too.

Saturday, April 27, 2013

Extracting contacts and calender data from a Nokia 2690

After resisting the inevitable march of progress, my wife upgraded to an Android phone recently. She had been using a Nokia 2690.

Image from Wikipedia

You may think "pfft, what an ancient phone!", but it has a USB connection and a microSD slot. Besides, I still use a 6100.

Attribution: Cessax / Güstrow (Cessax at de.wikipedia)

It supports infrared, which must have looked cutting edge back in 2003, but surprisingly few new laptops incorporate it in 2013. Luckily my 3 contacts won't be too difficult to copy across manually in the unlikely event I actually use one of these Orwellian tracking devices known as "smartphones".

Anyway, back to the topic on hand. After swapping the SIM card over, the Android contacts application refused to read the contacts or calender information. I think the reason was because these had been stored in the actual phone memory instead of on the SIM.

My initial searches seemed to show that Nokia's Windows-only PC suite was the common way to copy this information from the phone to some usable format. Curses.

I tried searching the internet for terms like "transfer contacts nokia phone android ubuntu". The results were long-dead forum posts copied across multiple spammy domains, blogspam about Ubuntu phones, adverts for cheap feature phones, and review after review of the latest flavour-of-the-week Android device. This is the internet we have created in 2013 - full of unanswered questions wrapped in adverts, advertorials with more adverts, spam and money grubbers.

A beacon (mmm, bacon) of hope was a post on one forum that said "I've tried wammu but it didn't work". Aha!

Wammu it turns out is a GTK front-end application that ties into the Gammu command line utility to work with dozens (hundreds?) of mobile phones. And best of all it is Free Software. Jackpot!

On Ubuntu it's easy to install
sudo apt-get install gammu

Once that was done, I connected the aging Nokia device via USB cable to my laptop and set it to "PC sync mode". That caused a new device to show up in the /dev directory - /dev/ttyACM0. Wooo!
The gammu configuration I needed was on their wiki, but the connection string did not work. After fiddling around with wammu it seems like dku2 is the correct value for the connection type, and the advertised dku2phone doesn't exist.

~$ cat .gammurc
[gammu]
port = /dev/ttyACM0
connection = dku2

Once I had the phone details showing up in the wammu GUI I was almost there. I couldn't figure out how to save from wammu to a useful format - vCard seems to be the standard here. Luckily using gammu was easier and the man page has this example that does the job:

sudo gammu backup gammu_contact_backup.vcf -yes
I had to use sudo as I wasn't allowed to open /dev/ttyACM0 otherwise, and I couldn't be bothered faffing with groups for this one-off operation. This extracts all of the contacts and stores it in the vCard format. It came as a surprise to me that gammu chooses the type of data and the output format based on the backup filename extension, so using ".vcf" is required.

To extract the calender information, I had to use the ".vcs" extension. This causes gammu to export calender information and save it in the vCalendar format.

sudo gammu backup gammu_calendar_backup.vcs -yes
Once extracted, I copied these onto a suitable sdcard for the mrs's new android phone (which is a normal person's unlocked-but-freedom-hating Samsung S3 Mini, if you were wondering. Not my choice, but doesn't seem too shabby.)

The contacts app imported the vCard file no problem. From the android app's menu (didn't Google try and get rid of menus? Maybe Samsung have more idea about what works) there's an "import from SD card" option. This goes off and finds the vCard file itself and reads all the contacts in.

For the vCalendar file it didn't work as I expected. There are no "import" options in the calender app. Instead, I used the file navigation app (included by default) - and opened the vCalendar file there. It gave me the choice of what application to open the file with, I chose the calender app, and that was that.

Unfortunately I didn't manage to get the SMS files off in a way that the Android apps could understand. I don't think there's a standard interchange format there, each phone does it their own way.

I dread to think what will happen in a few years time when I want to repeat this process to get the stuff off the Samsung phone though.

Saturday, April 20, 2013

Life After Google Reader

A few weeks ago, Google announced that they would be shutting down Google Reader on 1st July.
I used Reader for 2 things: keeping up with podcast episodes and keeping an eye on rarely-updated blogs. I didn't subscribe to anything with more than 1 post per day, as I couldn't keep up with so many new articles.

Once I recovered from the shock and disappointment of Reader itself going away, I came to the conclusion that none of the alternatives are really there yet.
  • Feedly - requires a browser plugin, and is still based on your Reader account details
  • theoldreader.com - threatening a freemium model
  • rss2email/tiny-rss - you have to run your own server - the only option that makes sense long-term - but it is a lot of hassle
  • Just about everything else shows large photos on their homepage and thinks that social media buttons are a good idea. I don't think we'd get along.
Since the spring-cleaning announcement I have gone cold turkey on Reader. My RSS-reading solution is now to imagine we're in early 2005 again and use a local client ☹

The client I'm using is newsbeuter. It's a text terminal application (this is a good thing) and has podcast queuing integration too. It can import an OPML file, which is a list of the feeds that you subscribe to. Reader has a URL to export your feed list as OPML too, so migrating is not difficult.



One nice feature newsbeuter has is the ability to export and import a list of articles that you've already read. This means that, using a git repository on bitbucket, I can synchronise read articles in a crude way between PCs. Fortunately I had mostly weened myself off Reader on portable devices, as my Google password is too annoying to type in.

The real downside is that refreshing articles is pretty slow. A couple of tweaks help here. Instead of reloading all feeds in one thread, newsbeuter supports multiple threads. 4 seems to speed things up a bit, I couldn't notice much difference using more than this.

Here's my .newsbeuter/config file:

bind-key k up
bind-key j down
reload-threads 4
reload-only-visible-feeds yes
This is far from ideal, but better than relying on free internet services that could disappear at any moment. The irony of this blog being hosted on blogger is not lost on me. I fear for its future too.

Saturday, January 26, 2013

Update to android-ndk-profiler



Android Robot
Image from Wikipedia
I've just updated my profiling library for native code on Android to version 3.2. This version is the first "final" release since I moved the code from the subversion repository on Google Code over to github. I have kept the main project hosting on Googlecode still as Github recently removed the ability to host pre-compiled downloads. Not sure what to do with issues yet, but pull requests are welcome :-)

There are no huge changes, but I have made a switch from the old ad-hoc include mechanism to use the NDK module system. This should make it a lot easier to set up the profiling code in an Android.mk file. I've updated the usage page with details of how to do this. For some reason the HTML documentation for the NDK is not online anywhere, the best you can do to view the module documentation without downloading the NDK itself is probably this page.

The switch over to github meant I could also start using Travis CI, which is a great continuous integration service for public repositories. I haven't read much about this anywhere, but it seems like a well thought out service, and it was really simple to set up.



Thursday, January 24, 2013

Command line and Gnome Desktop integration tips for Vim

Here are a couple of ideas that I find handy when working with Vim.The first tip is how to check what the last search term was in Vim from the command line. A silly idea that I've found more useful than I thought it would be.

For this to work, you need set nocompatible so that Vim writes out its state information to a viminfo file on exit. The line in the viminfo file that stores the last search looks like this:

 ~Msle0~/search_term

The m, s, l and e characters describe which magic, smartcase, line/char offset, or from the end or start flags Vim had set when you searched. For example, the third character is an 's' or an 'S' depending on whether smart case is on (S) or off (s).

Here is a script, which I call last_vim_search, that shows you what the last search term stored in the viminfo file was:

#!/bin/bash
lvs=$(awk -F/ '/^~[Mm][Ss][Ll][eE]0~\// { print $2; }' ~/.viminfo)
if test $# -eq 0 ; then
    echo $lvs
    exit
fi
grep "$lvs" "$@"

The snippet of awk searches for the matching pattern, splits on the "/" character, and spits out the last used pattern.
$ last_vim_search
\<pattern\>

As an added bonus, if I pass arguments to the script then it searches whatever arguments I passed in using grep.
$ last_vim_search *c
file.c:123: ....
file.c:456: ....

The second tip is how to integrate Vim with the "Recent Documents" feature from the Gnome Desktop. Frequently I find myself editing a text file in Vim, and then having to attach it to an email or upload it to a web form. Having the file you want to upload in the recent documents list helps a lot in these situations, as it is quicker to get to than having to navigate the file chooser to the correct location and selecting the file there. Unfortunately only "Gnome-ish" applications update the recent documents list, and terminal Vim is not one of these. This tip fixes that situation, and lets Vim update the recent list too.

For this to work, you will need the python-gtk bindings. Debian and Ubuntu at least installs python-gtk by default with Gnome. Also your version of Vim needs to have Python support compiled in. If not, you could adapt the python snippet to run in its own script.

"
" add text files that I edit to Gnome's recent file list
"

functions:RecentAddFile()
    python <<EOF
import vim
import gtk
n = vim.current.buffer.name
f = 'file://' + n
gtk.recent_manager_get_default().add_full(f,
    {'mime_type''text/plain''app_name''vim''app_exec':'vim'})
EOF
endfunc

autocmd BufReadPost *.txt call <SID>RecentAddFile()

This makes use of the "recent documents" GTK API. It's only short and doesn't really need much explanation. The python <<EOF marks the start of the embedded snippet of python code, the rest is all vimscript. The autocmd BufReadPost bit means that when Vim reads in a txt file it will call the function to add the file to the recent list.



The python code uses Vim's own API to get the current file name, which it turns into a URL by prepending "file://". The gtk call adds the URL to the recent document list. There's a simpler "add_item" method too that doesn't need the options passed in via the dictionary argument, but it doesn't seem to work in this context.

You could tweak the code to only add files in your home directory - as is it will add help pages as recent docs too. With different autocmd lines you could also add other file types to the recent history.

And now for something completely different... check out this great Super Meat Boy plushy that my better half made for eldest son. That's love :-)



PS. This weekend I'm hoping to have time to put the final touches on a new android-ndk-profiler release. The current beta-ish version seems to be working OK if you want to try it out.