Crayon Syntax Highlighter broken on WordPress on PHP 7.3

When I came to post the previous post on my blog, I found that my host’s recent upgrade to PHP 7.3 broke what seemed like everything. Turns out it’s just one plugin – Crayon Syntax Highlighter, which is really useful for styling code in posts.

Unfortunately, the developer hasn’t updated his plugin in three years or so, and it seems to be changes to how regex is used that has broken it. You may get the same error I did: “PHP Warning: preg_replace(): Compilation failed: invalid range in character class”.

The quick fix is bin the plugin, but obviously I’d still like to use it. Thankfully, some other people have taken it upon themselves to release a fixed version, which you can get from here: https://github.com/Crunchify/crayon-syntax-highlighter/releases

Deactivate the current Crayon plugin (don’t delete it as you’ll have to configure everything again!), install this one (manually – upload the zip from that link to your site), and enable it. Once confirmed working, you can delete the old version of the plugin.

Resizing a Linux partition running under Hyper-V

We’ve all been there. Setting up a new machine and giving it a 20GB hard drive because it’ll literally only need 4GB ever and then, two years later, it’s somehow full and won’t boot. Unlike Windows based guests on Hyper-V, which can have their drives resized easily by the Hyper-V tools, Linux guests are a little different.

You can certainly resize the disk image in the same way (turn the VM off, choose Edit Disk, and then Expand), but Linux doesn’t see the extra space. To make things worse, if – like me – you set the VM up originally as a Generation 2 machine (with all the UEFI bells and whistles) then some Linux tools and rescue images like gparted and fdisk don’t work properly (with boot errors like ” efi: EFI_MEMMAP is not enabled”). Plus my machine wouldn’t boot to install or run them because, as I said, it was full.

Anyway, here’s how I resized it. This all relates to a Debian 9 guest on Hyper-V on a Windows Server 2016 machine, but the process should be the same for most Linux variants.

Firstly, after turning the VM off, I resized the image in the Hyper-V Manager as above – using Edit Disk.

Then, I made a copy of the disk just in case. Turned out this wasn’t necessary, but better to be safe.

So, since I couldn’t use the current VM to fix my drive (Gen 2, tools don’t work, won’t boot), I set up a new temporary VM in Hyper-V, making sure I chose Gen 1 this time. I added the hard drive image from the real VM as the drive, and then set it to boot from an ISO of gparted. This allowed me to access the drive and resize the partitions. Before I did that, however, gparted had detected a change in drive size and asked if I wanted to fix it – I said yes.

Since I had three partitions (/dev/sda1 to sda3) but it was the second (sda2) that needed expanding, I had to move sda3 to the end of the drive first. It’s all pretty straightforward in gparted – just remember to actually apply your changes when you’re done as otherwise nothing happens!

This temporary VM was then turned off, the drive image was reattached to the original VM and… it didn’t work.

Hyper-V threw immediately threw up a permissions error, as it couldn’t access the disk image any more. ” An error occurred while attempting to start the selected virtual machine(s)”, and this:

Hyper-V Virtual Machine Management service Account does not have sufficient privilege to open attachment 'D:\PathToImage\DriveName.vhdx'. Error: 'General access denied error' (0x80070005). (Virtual machine ID xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).

Luckily, this is fixable. Make a note of the Virtual Machine ID in the error, and then run this command in an admin console substituting the ID for all the Xs and the actual full path to the image:

icacls "D:\PathToImage\DriveName.vhdx" /grant "NT VIRTUAL MACHINE\xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx":(F) 

With this done, I could finally boot my original virtual machine successfully. In my case, it did a quick disk check itself automatically, and then everything was working normally only I’ve a lot more disk space to play with!

Veeam VeeamZip “Failed to process [isFileExists]” error when backing up Hyper-V

When backing up to a Synology NAS using VeeamZIP via PowerShell, the job was failing with an “isFileExists” error. Here’s the solution.

I have a Windows Server 2016 server with a number of Hyper-V virtual machines running on it, and Windows Server Backup wasn’t backing them up for reasons known only to Microsoft. Various forums and reports on Microsoft’s Technet suggest there’s a fix needed for Server 2016 which, two years after first complaints, still hasn’t been forthcoming. Everywhere seemed to suggest using something like Veeam Backup & Replication instead, so I installed that.

I only need a simple “backup the VM periodically” function, and Veeam B&R has this option in the free version in the form of VeeamZIP. This is all well and good, but it’s ad-hoc backup only – no scheduling unless you fork out for the paid versions. Luckily, Veeam themselves have a PowerShell script that you can schedule, which makes use of the Start-VBRZip command.

Sadly, it wouldn’t work for me, and it turns out it’s because I’m backing up to a Synology NAS.

If you look at the script, you’ll see this:

If I set $Directory to a location local to the server (e.g. “d:\”) then it works. Set it to the NAS (e.g. “\\synonas\share\backups”) and I get the error “Failed to process [isFileExists]”.

Looking on the NAS, the logs say the server connected – with working credentials – but no files are created. After the usual head-scratching and log searching, I realised something: The script is running with the correct credentials, but the Start-VBRZip command in it is not.

On the PowerShell command line itself, you can specify which credentials Start-VBRZip can use with the -NetworkCredentials parameter. You can read more about that here.  However, there are two steps needed to get that working:

  1. Create a set of stored credentials in the Veeam Backup & Replication GUI, using the “Manage Credentials” option.
  2. Retrieve that in the form of an array in PowerShell and pass it to Start-VBRZip.

The second step is necessary because the parameter expects an array not a string. If you have a set of credentials for (e.g.) “DOMAIN\Admin” stored in Veeam B&R, you can’t just pass -NetworkCredentials “DOMAIN\Admin”.

What you can do, however, is extract the array necessary with this command:

and then pass $cred to Start-VBRZip’s -NetworkCredentials parameter.

Only there’s another snag: the provided PowerShell script doesn’t do anything with credentials as the parameter is missing. We can fix that by adding it ourselves.

In the script, there’s a line that says “DO NOT MODIFY PAST THIS LINE”. To hell with that! Immediately after the “Ansp VeeamPSSnapin” line, add

then rewrite these lines:

to include the missing parameter:

Save the file, add it to Task Scheduler as per the Veeam instructions, and it should now work!

How to make a PICO-8 game: Part 10

The last animation

It’s time to put the final touches to our game, namely animating the player sprite. Previously I’ve shown you how to do this for the enemies, and also how to create the enemies as objects, so we’re combining those for this task.

Part 10: Player Animation

As before, we need to draw some frames of animation to use. I’ve created some additional frames in sprite slots 2, 3 and 4 to carry on from 1.

Again, it’s pretty simple but is just for illustration.

Now, we need to create the player as an object. We could have a function to house this, make_player() like we have make_enemy(), but we only need to create one player so that’s overkill. Instead, we’ll create it in one go in the _init() function, replacing the x and y we had there before:

You’ll notice I’ve put a player.draw function in there, which works just like the enemy draw function from last time.

Continue reading “How to make a PICO-8 game: Part 10”

How to make a PICO-8 game: Part 9

Animated

Sprites are all well and good, but if they animate they look so much better. Let’s head towards the end of this project by polishing it a bit.

Part 9: Animation

First up, we need to have some frames of animation for the enemy sprites. To make it a bit more logical on the sprite screen, I’ve moved the first frame from “slot” 2 to “slot” 17, then edited it and created three more frames of animation:

It’s nothing fancy, but you can change that if you like.

Now, when we create the enemy, we need to pass an extra parameter to the make_enemy() function – the total number of animation frames for the sprite. Of course we could hard code this into the enemy object, but lets assume we might want to reuse this function at another time for a range of objects each with a varying number of animation frames.

Currently, the function starts with this:

We’ll add “eframemax” to this:

and then set:

in the function itself. You’ll see why we had en.frame = 0 in there now!

Next, we need to add some code to change which sprite to use, changing it every so many ticks so it animates like a flickbook. We already have variables for ticks and ticksmax to help with this.

Continue reading “How to make a PICO-8 game: Part 9”

How to make a PICO-8 game: Part 8

Enemy objects

Last time, we got halfway through butchering our previously working game, leaving it in a state where it refused to even run. This time, we’ll fix that.

Part 8: Enemy Objects

Now that there are multiple enemies, and they’re all objects, we can no longer use any code that refers to the old variables of ex and ey, or any other “single enemy” legacy code. Currently, that also means that collisions no longer work.

Luckily, the function checkcol() only needs to be sent two lots of x and y values, so still works fine providing we send it the right variables, so we can leave that alone. However, we need to replace the code that calls it.

At the moment, it says this in _update():

which doesn’t work – note the ex and ey. Instead, lets call this function for each enemy, and pass that enemy’s x and y to the function. Like this:

Be extra careful with the brackets here – the foreach encloses the code in them!

Hopefully by now what this code does is clear, as it’s similar to the enemy  draw routine: It runs through each enemy in enemies{} and triggers checkcol for each.

That’s collisions sorted. Our code won’t run yet, because we still have to fix the enemy move and enemy speed increase routines.

Continue reading “How to make a PICO-8 game: Part 8”

How to make a PICO-8 game: Part 7

Outnumbered

If you remember (it was before Christmas, so I realise you might not), the last thing we did on our game was make it harder. This was done by making the enemy speed up, but there’s another way – why not spawn more enemies?

Part 7: Spawning

Up until now, we’ve referred to the enemy’s position variables as ex and ey, and used the variables d and dinc to determine their speed and how much they speed up by. If we decide to add a second enemy, we can use more varables – ex2, ey2, d2 and dinc2 perhaps. And for a third enemy, ex3 and ey3 and so on. Simple, yes?

Well yes, but terribly inefficient. Not least because we need the associated code to alter them too. What if, instead, we can just say “make an enemy with these attributes” as many times as we like, and then say “just update all the enemies and draw them on the screen please and thanks”? That’d be like magic, right?

Magic in the form of an enemy object. In PICO-8, objects take the form of specially constructed tables, with keys and values. For example, we can create an “empty” enemy called “en” like this:

and then give it some attributes as key/value pairs:

and so on.

Then, we can be clever and create lots of these and put them all in another table, called “enemies”. We can then perform tasks on all the enemies in the enemies table in one go!

Let’s start with a function to make enemies and add them to the enemies table.

Continue reading “How to make a PICO-8 game: Part 7”

How to make a PICO-8 game: Part 6

Die Hard

We have a complete, if dull and far too easy, game. Now we’ve the basics set up, let’s make it harder – and hopefully a bit more playable as a result!

Part 6: Die Hard

There are a number of ways we can make the game harder, but the simplest one is just to make the enemy faster. We can do this just by changing the value of d from 0.05 to a bigger number. Instead of that, though, why not slowly increment d so that the enemy gets faster and faster the more time the player has spent alive?

We can do this with a counter that increments every loop of the game logic. When it hits a certain threshold, increment d and reset the counter. Let’s call this series of counting “ticks”, and after 200 ticks (so 200 loops of the game logic – essentially 200 frames) d increases. We’ll also choose that d will increase by 0.05 each time.

For this, we need three new variables: ticks (the tick counter), tickstrigger (the number at which ticks triggers a speed increase), and dinc (how much d increased by each time).

We’ll put these in _init():

Now we need a simple routine to increment ticks, check if ticks has spilled over the tickstrigger, and if so, increment d by dinc. We can put that in _update(), after the rest of the game logic:

Now, you’ll notice that ticks increases by one each loop, as does score, so you can watch the score counter on the screen increase and at 200, 400, 600 and every other multiple of 200, the enemy will speed up.

That’s made the game somewhat harder. Of course, eventually the enemy will be faster than the player and there’ll be no way to continue playing, but we can deal with that another time.

Our code so far, then:

Next time, we’ll make the game harder in a different way by creating multiple enemies, and to do that we need to delete and rewrite half our code. It’ll be worth it!