C#, Code, Unreal Engine 4

Unreal Engine 4 , blueprints or C++?

Unreal Engine 4 is probably one of the most powerful and widespread engines in the industry right now.

For artists it’s easy to see why , it has some very good rendering capabilities, has great functionality with substance painter and is very easy to create new shaders in with its very robust node-based approach.

Programmers new to UE4 however are not always sure how they should feel about UE4. Sure , the blueprint system seems like a nice idea , but can I really do everything I want in it?

Most programmers have a certain fear of the blueprint system at first because they feel like it limits them to what they can do. It also isn’t exactly very freeform at first. Sure , it’s easy to grasp , but very hard to actually implement complex systems in. Atleast , that’s what they think.

As a programmer myself however , i understand all these questions and had them myself at first. Coming from unity , this gives you the idea that you can write everything you want very easily, as it’s totally code-based. Blueprints however are also very powerful , and not should not be underestimated. It’s actually very easy and possible to create a fully working FPS with an inventory etc. without even touching a single line of code in UE4. And all that , thanks to the power of blueprints.

An added benefit of blueprints , is that they can be made extremely readable and it’s a lot easier for the artists on your project to try and code ( or at least understand ) something themselves. This , because it is  essentially the same node-based system as the way in which they create their shaders in UE4.

And when you are a small team , it can be very helpful if an artist ca roughly code one of his ideas and then just let you refine and actually implement this feature.

Therefore , I highly recommend leaving the C++ code on the side and at least trying some code in UE4 blueprints. You’ll be amazed at what it can do.

I’ll be making another blogpost containing some actual examples of me using this system to great effect in the near future.

Stay tuned!



C#, Code, Diablo 2

Understanding the diablo 2 save file format / Part 3

Now , for the third and final part , let’s look into the checksum a bit , i’ll try to keep my code simple and short this time , so you don’t get a headache while trying to read this post 😉

On a sidenote , this contains a lot of bitshifting etc. which is not ideal to write in c#, but verything should still be straightforward enough to translate into another language. 🙂

The checksum is actually pretty simple , first of all , you set the checksum bits to 0. ( they are bytes 12-15 )

character.BinaryStream[12] = 0x00;
character.BinaryStream[13] = 0x00;
character.BinaryStream[14] = 0x00;
character.BinaryStream[15] = 0x00;

Now for the checksum algorithm. This one is also fairly simple. All you have to do is add up all the bytes one by one and everytime you add a byte , you bitshift the sum 1 spot to the left. You do however have to make sure to carry over the highest bit( most bitshifting operators do not do this , so we have to do it manually ) , as we do not want this value to get lost , so we actually just rotate our sum around 1 bit everytime we add another value.

uint checksum = 0;            

for (int i = 0; i < character.BinaryStream.Count(); i++)
 byte thisByte = character.BinaryStream[i];

 uint carry = 0;
 if ((checksum & (1 << 31)) != 0)
    carry = 1;

checksum = unchecked (unchecked(checksum << 1) + character.BinaryStream[i]) + unchecked(carry) ;

And now , we just have to get the checksum back in the 4 bytes!

 byte[] intbytearray = BitConverter.GetBytes(checksum);
character.BinaryStream[12] = intbytearray[0];
character.BinaryStream[13] = intbytearray[1];
character.BinaryStream[14] = intbytearray[2];
character.BinaryStream[15] = intbytearray[3];

If all went well , you should now be able to read in files ,save them out , and still be able to play them !