June 23, 2011

RomTerraria Updated For 1.0.5

New build available.

Key Events in XNA 4.0

One of the top requested features for XNA since release was the ability to intercept key press events instead of just the key up/down events so that people could do text input easily.

Still can't do it in XNA 4.0, but here's a way of working around it by adding a message filter. Please be aware that they may break this in the future if they don't use Windows Forms for their form in XNA 5.

First, the keyboard filter class...


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace RomSteady.Xna.GameEngine.Input
{
public class KeyboardMessageFilter : IMessageFilter
{
[DllImport("user32.dll")]
static extern bool TranslateMessage(ref Message lpMsg);

const int WM_CHAR = 0x0102;
const int WM_KEYDOWN = 0x0100;

public bool PreFilterMessage(ref Message m)
{
if (m.Msg == WM_KEYDOWN)
{
TranslateMessage(ref m);
}
else if (m.Msg == WM_CHAR)
{
if (KeyPressed != null)
KeyPressed.Invoke(this,
new KeyboardMessageEventArgs()
{
Character = Convert.ToChar((int)m.WParam)
});
}
return false;
}

public event EventHandler KeyPressed;
}

public class KeyboardMessageEventArgs : EventArgs
{
public char Character;
}
}


...and now to wire it up so you can get those KeyPressed events. In your Initialize() function...


...
var keyboardFilter = new KeyboardMessageFilter();
keyboardFilter.KeyPressed +=
new EventHandler(keyboardFilter_KeyPressed);
System.Windows.Forms.Application.AddMessageFilter(keyboardFilter);
...


This code isn't flawless, but is working well enough for my purposes.

June 17, 2011

One Month of RomTerraria

So a month ago, I started working on RomTerraria, a launcher for the indie hit Terraria.

Originally, I just wanted to put in a minimap because I was getting lost regularly, but it wasn't ready yet. A regular on Shacknews made a command-line launcher to allow people to allow people to override the initial 800x600 maximum resolution, and I brought that idea in to a graphical launcher along with a rapid health recharge trainer, and over the last twenty plus updates I've added the minimap, weather effects and so much more.

The only things I won't do are expose god mode and inventory editing. I've been focused on allowing people to tweak gameplay to their level...not letting people skip playing the game.

The biggest downside of this whole thing has been that the warez monkeys out there have been bundling the early versions of my launcher with the pirated version of the game. I keep hoping that Redigit will make a change that breaks my launcher, like turn Terraria.Main.screenWidth into an auto-property. I hate the feeling that my work is being used by some people to cheat these guys out of money they rightfully deserve, especially given my history. Yes, the irony isn't lost on me.

The biggest upside is that the bad taste for game development that my departure from Ritual left in my mouth is finally gone. Now my free time is being filled with little bouncing baby prototypes. I can't wait until one is ready to share...