Roy Triesscheijn’s Weblog

My programming world

Archive for November, 2010

Site hacks

Posted by Roy Triesscheijn on 29th November 2010

www.roy-t.nl has been offline for short periods the last 2 weeks. Sorry for the inconvenience, but it turned out some (automated?) hack caused a lot of the wordpress file to be infected with hazardous javascript, so I took the website offline (only hours after the infection because of Google’s excellent warning system)

All of the damage has been repaired. I don’t know how the hack exploited my server though. I guess this website is way too small time to deserve the attention of an actual hacker, so I guess they used a wordpress exploit. However this website is as-up-to-date as can be now, so I hope I don’t have to worry about that anymore, just to be sure all ftp and database passwords have been changed.

One other file was changed (the paypal page), but since it was a .html file, the php code inserted was never executed. So didn’t cause further harm then people not being able to donate for the last two weeks.

Anyway, all of this should be over now. If you see any problems, please let me know asap!

Tags: , ,
Posted in Blog | 2 Comments »

Code snippet: EventLog wrapper

Posted by Roy Triesscheijn on 21st November 2010

This is a small code snippet that allows your application to write log message to the event log. It will also allow you to capture events of these log messages so that your GUI can show pop-ups or other information messages.

(Added a small update a few hours after this was posted for Vista/W7 when not running the application as admin)

Anyway here’s the code:

     public class Logger
    {
        private static Logger instance;
        public static Logger Instance
        {
            get { if (instance == null) { instance = new Logger(); } return instance; }
        }

        private Logger(){}

        private string eventSource = "MyApplicationName";   //TODO: change this into the name of your application

        public delegate void logMessage(string message);
        public event logMessage Logged = delegate(string message) { };
        public event logMessage LoggedCritical = delegate(string message) { };
        public event logMessage LoggedWarning = delegate(string message) { };
        public event logMessage LoggedInfo = delegate(string message) { };

        public void Log(string message, EventLogEntryType severity)
        {
            try
            {
                if (!EventLog.SourceExists(eventSource))
                {
                    EventLog.CreateEventSource(eventSource, "Application");
                }
                EventLog.WriteEntry(eventSource, message, severity);
            }
            catch (SecurityException noRightsException)
            {
                //User has no rights to write logs.
            }
            Logged(message);

            switch (severity)
            {
                case EventLogEntryType.Error:
                    LoggedCritical(message);
                    break;
                case EventLogEntryType.Information:
                    LoggedInfo(message);
                    break;
                case EventLogEntryType.Warning:
                    LoggedWarning(message);
                    break;
            }
        }
    }

Tags: , , ,
Posted in Blog, General Coding | No Comments »

How to drown a keyboard

Posted by Roy Triesscheijn on 13th November 2010

Maybe it’s best to start of this post with a small picture:
OH NO!

That’s my hand, and what I’m holding is my nice Microsoft Natural 4000 ergonomic keyboard (which is supposed to look like this) , or well, it’s the innards of the keyboard, the part that you shouldn’t normally see. Oh and there’s a towel.

Unfortunately 4 days ago I tried to explain something in a very expressive way while sitting at my desk with a cup of tea. As you might’ve guessed the hot tea and the keyboard kinda came in contact with each other (well… I poored almost all of the tea over it by accident).

After a small inspection, I found out that my 3 and “enter” key weren’t working at all, and that pressing some others keys had some awkward side-effects. So I removed all the keys and let the keyboard dry for 3 days. Unfortunately this didn’t remedy any of the problems. So I opened the keyboard (a lot of screws at the back, 2 hidden under the space key and 4 hidden under the arm rests, for those interested). I didn’t find much water, but the innards did look quite fancy.

Of course, this didn’t help me at all.

Another bad case is that I’m hooked to this type of keyboard and the local shops haven’t got it anymore…. Also the cool €35,- combo package (MS 4000 keyboard + (crappy) MS 3000 mouse) isn’t available anywhere anymore, and the keyboard alone costs about 50… Oh well.

(Did I remind you guys that there is a donate button on the right hand side of this blog?).

I should probably stop mocking now… This crappy el-cheapo BenQ keyboard isnt that bad at all. Can’t wait to order a 4000 again though, ah at least I can still type.

Tags: , , , ,
Posted in Blog, Personal | No Comments »

XBLIGs back in the games section

Posted by Roy Triesscheijn on 9th November 2010

As some of you might’ve heard already:

XBLIG is back in the games section on the new dashboard. I would sincerely like to thank Microsoft for realizing it’s mistake. I really didn’t think they would change it back. This offers us a lot of new and good opportunities. Because now the new changes are actually making XBLIG better instead of worse (as seen from the ‘old’ dashboard).

Anyway, try to find it and look for some cool games!

(As always a game by my making will be released ‘soon’).

Tags: , ,
Posted in Blog, XNA | No Comments »

Codesnippet: handy input manager

Posted by Roy Triesscheijn on 5th November 2010

Today I was working on a small prototype, however I got carried away a bit with the input management. In the end I spend nearly an hour working on “the mother of all InputManagers”. To spare you from this, I’ve decided to put the snippet online.

Features:
-Registers input from keyboard or gamepad.
-Left, Right, Up, Down mapped to gamepad Dpad and gamepad left thumbstick at the same time.
-Settable deadzones for the gamepad thumbsticks
-Provides, button up, button down and button pressed methods.

The code: (be sure to see the test code as well, at the bottom of this post)

public class InputManager
    {
        public InputManager(InputType type, PlayerIndex player)
        {
            this.inputType = type;
            this.playerIndex = player;

            //Fill dictionaries, TODO: bring this out into an xml file
            inputToKeys = new Dictionary<Inputs, Keys>(10);
            inputToKeys.Add(Inputs.A, Keys.A);
            inputToKeys.Add(Inputs.B, Keys.S);
            inputToKeys.Add(Inputs.Back, Keys.Escape);
            inputToKeys.Add(Inputs.Down, Keys.Down);
            inputToKeys.Add(Inputs.Left, Keys.Left);
            inputToKeys.Add(Inputs.Right, Keys.Right);
            inputToKeys.Add(Inputs.Start, Keys.Space);
            inputToKeys.Add(Inputs.Up, Keys.Up);
            inputToKeys.Add(Inputs.X, Keys.Z);
            inputToKeys.Add(Inputs.Y, Keys.X);

            inputToButtons = new Dictionary<Inputs, Buttons>(10);
            inputToButtons.Add(Inputs.A, Buttons.A);
            inputToButtons.Add(Inputs.B, Buttons.B);
            inputToButtons.Add(Inputs.Back, Buttons.Back);
            inputToButtons.Add(Inputs.Down, Buttons.DPadDown);
            inputToButtons.Add(Inputs.Left, Buttons.DPadLeft);
            inputToButtons.Add(Inputs.Right, Buttons.DPadRight);
            inputToButtons.Add(Inputs.Start, Buttons.Start);
            inputToButtons.Add(Inputs.Up, Buttons.DPadUp);
            inputToButtons.Add(Inputs.X, Buttons.X);
            inputToButtons.Add(Inputs.Y, Buttons.Y);
            //note that left, right, down and up are also mapped
            //to the left thumbstick
        }

        public bool IsInputPressed(Inputs input)
        {
            if (inputType == InputType.Keyboard)
            {
                return (curState.IsKeyDown(inputToKeys[input])
                    && !prevState.IsKeyDown(inputToKeys[input]));
            }
            else //inputType == InputType.Controller
            {
                //Check both left thumbstick dpad and buttons
                return (StickDirectionDown(curPadState, input)
                    && !StickDirectionDown(prevPadState, input))

                    || (curPadState.IsButtonDown(inputToButtons[input])
                    && !prevPadState.IsButtonDown(inputToButtons[input]));
            }
        }

        public bool IsInputDown(Inputs input)
        {
            if (inputType == InputType.Keyboard)
            {
                return curState.IsKeyDown(inputToKeys[input]);
            }
            else //inputType == InputType.Controller
            {
                return (StickDirectionDown(curPadState, input)

                || curPadState.IsButtonDown(inputToButtons[input]));
            }
        }

        public bool IsInputUp(Inputs input)
        {
            if (inputType == InputType.Keyboard)
            {
                return prevState.IsKeyUp(inputToKeys[input]);
            }
            else //inputType == InputType.Controller
            {
                return (!StickDirectionDown(curPadState, input)

                    && prevPadState.IsButtonUp(inputToButtons[input]));
            }
        }

        public bool StickDirectionDown(GamePadState gamePadState, Inputs input)
        {
            if (input == Inputs.Left)
            {
                return (gamePadState.ThumbSticks.Left.X < -thumbStickDeadzone);
            }
            else if (input == Inputs.Right)
            {
                return (gamePadState.ThumbSticks.Left.X > thumbStickDeadzone);
            }
            else if (input == Inputs.Up)
            {
                return (gamePadState.ThumbSticks.Left.Y > thumbStickDeadzone);
            }
            else if (input == Inputs.Down)
            {
                return (gamePadState.ThumbSticks.Left.Y < -thumbStickDeadzone);
            }

            return false;
        }

        public bool InputIsDirection(Inputs input)
        {
            return (input == Inputs.Left || input == Inputs.Right ||
                input == Inputs.Up || input == Inputs.Down);
        }

        public void Update()
        {
            if (inputType == InputType.Keyboard)
            {
                prevState = curState;
                curState = Keyboard.GetState();
            }
            else if (inputType == InputType.Controller)
            {
                prevPadState = curPadState;
                curPadState = GamePad.GetState(playerIndex);
            }

        }        

        #region FieldsAndProperties
        public float thumbStickDeadzone = 0.5f;

        private Dictionary<Inputs, Keys> inputToKeys;
        private Dictionary<Inputs, Buttons> inputToButtons;

        private KeyboardState curState, prevState;
        private GamePadState curPadState, prevPadState;
        private InputType inputType;
        private PlayerIndex playerIndex;
        #endregion
    }

    public enum Inputs
    {
        A, B, X, Y, Left, Right, Up, Down, Start, Back
    }

    public enum InputType
    {
        Keyboard, Controller
    }

Testcode:


InputManager input = new InputManager(InputType.Keyboard, PlayerIndex.One);
public void Update(GameTime gameTime){
            input.Update();

            foreach (object value in Enum.GetValues(typeof(Inputs)))
            {
                if (((Inputs)value) == Inputs.Left)
                {

                }
                bool pressed = input.IsInputPressed((Inputs)value);
                bool down = input.IsInputDown((Inputs)value);
                bool notUp = !input.IsInputUp((Inputs)value);

                if (pressed || down)
                {
                    string message = "Input{3} was: Pressed({0}), Down({1}), NotUp({2})";
                    message = String.Format(message, pressed, down, notUp, Enum.GetName(typeof(Inputs), value));
                    Console.Out.WriteLine(message);
                }
            }
}

Tags: , , , , , ,
Posted in Blog, General Coding, General Gamedesign, XNA | 2 Comments »

Educational games and the powerpoint dilemma

Posted by Roy Triesscheijn on 4th November 2010

I didn’t have the time to finish up my upcoming reflection tutorial (it’s still coming!). But here is a small article about a real-world problem I faced on my work.

As a student I work part-time at the university’s science center (Science LinX, Dutch). One of my activities there is to help develop new exhibits, mostly as a programmer. But my input is always valued by my boss. We’ve been talking a lot about some recent projects (not developed by us) turning out to be more like powerpoint slides than real games. It seems very hard to keep educational games fun. In the design documents of some exhibits I haven’t even found any stakes regarding the fun-ness.

Well I would do things differently! And recently I’ve been given the chance:

On a project regarding the Herschel satellite there was a set of information that we wanted the public to learn (in our case 14~18 year olds). A colleague categorized the information and came with the idea to present pictures with different details of the satellite and then embed the information in them: you would have a close up few detailing one one of the components, or a far-away view detailing the launch of the satellite, etc…

Now I liked this idea, but it was way too powerpointish, and not fun. Some thought had already been put into this and things that where thought of was displaying al the data on MS surface table, and being able to zoom in with multi-touch gestures. However this would be hard to communicate to the users, and would it be more fun if you could pinch zoom?

So I came with my own idea for demonstrating the data: create a 3D simulation of our solar system, including the satellite. Add an Xbox controller for moving the camera. And present different textual fields depending on how close you’ve zoomed in onto the satellite. Seemed like a cool idea, didn’t? My colleague agreed and would search for any existing models of the satellite and would be working on the texts etc… I looked up my old space ace code and started salvaging code so that I could create a quick prototype.

After working for a full day on the prototype my boss (who had been ill) came into the office, and I quickly explained the idea to here. Unfortunately there wasn’t anyway to play the game yet, but I was sure she would understand the novelty and fun factor.

She immediately soon asked for our design documents (which we hadn’t updated at all yet) and came with some very provoking questions, the first (for me unexpected) question was: “How is this more fun than a powerpoint presentation”?

I was baffled and shocked, and I would immediately explain it to her, however… I couldn’t think of a reason why, other than that you could control the camera and that things moved (not a strong argument).

So I walked into the same trap as other exhibit developers on my first try, although I thought I was guarding actively against that trap!  I had a nice long talk with my boss, and she had some very good ideas to get stuff on the road again. Monday there will be a fancy meeting and we’ll ask the most important question again: will it be fun.

Tags: , , ,
Posted in Blog, Personal | No Comments »