Orkn's Pulp Devlog

With Witch Ware including the cheat code RUBDUBDUB presented two problems:

  1. With the short input repeat delay of 0.1 seconds I had configured in order to have fast player movement, inputting a single direction button press was difficult and I wasn’t able to reliably enter the code. Whenever I wanted to press a direction the game would often detect two presses instead of just one.
  2. Witch Ware was going to be open source and released before the existence of RUBDUBDUB was made public. I didn’t want it being accidentally uncovered by someone reading the code!

Let’s start with how I solved problem 1 by adapting the cheat code implementation from this tutorial.

Initially the D-pad button presses were being detected like this, leading to the problem of accidental double inputs:

on update do
  call "inputCode"
  if event.dy==-1 then
    ch1 = "u"
  elseif event.dy==1 then
    ch1 = "d"
  elseif event.dx==-1 then
    ch1 = "l"
  elseif event.dx==1 then
    ch1 = "r"
  end
  call "checkCode"
end

To solve this I decided to ignore repeated direction inputs. This meant that any cheat codes relying on repeated directions wouldn’t work (such as the Konami code) but considering RUBDUBDUB has no repeat directions and was the only code I was interested in implementing, this was fine. Here is the adapted update event:

on update do
  // Fast input repeat means we need to ignore repeat direction inputs
  if event.dy==-1 then
    if ch1!="u" then
      call "inputCode"
      ch1 = "u"
    end
  elseif event.dy==1 then
    if ch1!="d" then
      call "inputCode"
      ch1 = "d"
    end
  elseif event.dx==-1 then
    if ch1!="l" then
      call "inputCode"
      ch1 = "l"
    end
  elseif event.dx==1 then
    if ch1!="r" then
      call "inputCode"
      ch1 = "r"
    end
  end
  call "checkCode"
end

Problem 1 solved! Problem 2 however was a trickier challenge and involved some code obfuscation… and I think it’ll be more fun if I first show the code I ended up with so you can have a go at trying to figure out what it is doing!

In the game script:

on start do
  uuddlrlrb = 112234345
end

In the player script:

on cancel do
  call "inputCode"
  ch1 = 5
  call "checkCode"
end

on update do
  // Fast input repeat means we need to ignore repeat direction inputs
  if event.dy==-1 then
    if ch1!=1 then
      call "inputCode"
      ch1 = 1
    end
  elseif event.dy==1 then
    if ch1!=2 then
      call "inputCode"
      ch1 = 2
    end
  elseif event.dx==-1 then
    if ch1!=3 then
      call "inputCode"
      ch1 = 3
    end
  elseif event.dx==1 then
    if ch1!=4 then
      call "inputCode"
      ch1 = 4
    end
  end
  call "checkCode"
end

on debugCode do
  // FIXME Modify recorded code to work around repeat direction inputs?
  ch9 -= 3
  ch8 += 3
  ch7 -= 3
  ch6 -= 2
  ch5 += 3
  ch4 -= 2
  ch3 -= 2
  ch2 += 3
end

on inputCode do
  ch9 = ch8
  ch8 = ch7
  ch7 = ch6
  ch6 = ch5
  ch5 = ch4
  ch4 = ch3
  ch3 = ch2
  ch2 = ch1
  call "debugCode" // FIXME
end

on checkCode do
  code = "{ch9}{ch8}{ch7}{ch6}{ch5}{ch4}{ch3}{ch2}{ch1}"
  if code=="{uuddlrlrb}" then
    zap = "rocket"
    swap "heli"
  end
end

The idea is that to anyone reading this code it should look like the cheat code being used is the Konami code (sans the final “A”), not RUBDUBDUB. Indeed in the checkCode event you can see the code being checked for is "{uuddlrlrb}". A bit weird that it’s a variable being formatted in maybe, but in the game script you can see that the variable being defined as uuddlrlrb = 112234345and if you look at the player cancel and update events you can see that D-pad up corresponds to 1, down to 2, left to 3, right to 4, and “B” to 5. That matches up!

The trick is the debugCode event that is called at the end of inputCode. It’s clearly doing something a bit weird, but what is definitely not obvious. The comments would lead you to believe it’s an unfinished attempt to workaround the real issue with the solution to problem 1 - that codes with repeated inputs (like the Konami code) won’t work.

If you crunch through the maths though you’ll find that what debugCode does with its additions and subtractions, when called repeatedly before each new button input, is perfectly translate the number representation of RUBDUBDUB (415215215) to the number representation of UUDDLRLRB (112234345). Input RUBDUBDUB in-game and you’ll trigger the cheat code!

Was this strictly necessary, given the likelihood of someone looking into the source code and identifying RUBDUBDUB in the short window between the release of Witch Ware and the reveal of RUBDUBDUB? Absolutely not! But I did think it was a fun excuse to try some code obfuscation in Pulpscript.

2 Likes