Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon

5. June 2011

 

When I was starting out, I was just dying to earn my “real programmer badge™”.  At the time “real programmers” used assembly and I was taking the lazy easy way out using C.  So, in my quest to earn my real programmer badge I taught myself assembly.  Now it took me 10 times as long to write my code and it sure was more difficult; no doubt my badge would be in the mail!  Sadly… no, it didn’t arrive.

 

 

The years went by and assembly became more and more niche.  In the meanwhile, higher level languages came to the fore.  There were even languages that hacks and simpletons could rapidly create programs in, like Delphi ( pascal ) and Visual Basic.  Of course real programmers looked down upon these amateurs, everybody knew that this wasn’t real programming.  Hell even C++ was looked down upon, it was way too high level and slow for real programmers to use, so being a real programmer I kept using C.  Things sure were slow and painful, lots and lots of work, no doubt my real programmer badge was on it’s way! 

 

 

Another generation of languages came along, new pretenders like Java and C# rose in popularity and the lazy and weak flocked to them like mad.  Real programmers of course knew that C++ was the one true language.  Sure, those class libraries and the freedom from memory management sure looked tempting, but I am a real programmer damn it, so I continued working in C++.  My god was it difficult so I truly must be getting close to getting my real programmer badge.  When it didn’t arrive I decide their surely must be a mistake at the post office!

 

 

Then the current generation of languages came to the forefront.  Scripting languages had risen in popularity, to the point that it seemed more people were “scripting” than programming these days!  Scripting?  What real programmer in their right mind would ever work in a lowly scripting language?  I am a real programmer, I will leave scripting for the hacks and newbies, thank you very much!  Real programmers work in C++!  Oddly enough, I still haven’t received my badge…?

 

 

Recently a funny thing happened… I took to a project under a tight deadline, it absolutely had to ship on a given date.  There was no way I could possibly succeed in time using a real programming language, so I took to using the plebian tools.  Working in C#, the wonderful class libraries sure did make development fast.  At times I actually slunk to the lowest of the low and used scripting languages!  It felt so dirty but I have to admit the rapid turn around and interactive tools sure did things quick.  In the end, it was a challenge and I had to prostitute my pride, but I shipped on time!  The following day, a FedEx truck pulled up to my front door and delivered my prized Real Programmers Badge™!

 

 

 

Official-Seal-of-Awesome

 

( Image totally stolen from a middle aged drama queen. )

Of course, this story is completely full of crap but the moral is completely true.  When I was starting out C was truly looked down upon as being a tool of “fake” programmers. Through the years the language has changed but there has always been an “IT” language that new programmers to the field think they have to work in to be a real programmer.  It sadly often takes years of experience to realize how stupid this mindset actually is.  Can you imagine a carpenter that wouldn’t use a drill because “real carpenters” use screw drivers, would you hire this person?

 

 

A real programmer uses the right tool for the job.  For those of you just starting out, “the job” very much includes “learning to program”.  In the end a real programmer makes the best product they can, as efficiently as they can, using whatever tool works best.  Sometimes, that tool might even be C++!

Programming ,

3. May 2011

In a recent forum conversation, it was brought to my attention a previous work of mine was now unavailable online.  You see, when XNA was a new technology I started writing a free book on the subject, working with the release candidate.  In the end I wrote 4 chapters, then Microsoft released XNA 1 and there were some major changes that would more or less have meant a complete rewrite, which didn’t seem all to exciting a proposition.  That told, all the chapters combined were downloaded well over a 1/4 million time, so it did have an audience.

 

xnaAnyways, the website that hosted these documents is now gone, as is the old mirror I hosted to.  By request, I managed to find the files, dust them off and I am posting those files here.  Keep in mind, these were written in 2006 and target a pre-release version of XNA, so the use is pretty extremely limited.

 

 

 

 

If for some reason you are still interested, here they are:

Chapter One

Chapter Two

Chapter Three

Chapter Four

 

Also, of some possible interest, I was in the middle of authoring a complete very simple 2D game for Chapter 5.  The texts are gone, but I have the unfinished source code and assets right here.  It’s not complete, polished and nor does it compile anymore.  It did back in the day, I remember that much, before the final release of XNA 1 this code was 100% working.  I don’t know if it will be of use to anyone, but here it is!

 

Chapter 5 Game Source Code [ 18 MB download ]

 

Enjoy this trip down memory lane.

Programming

26. April 2011

So today, after 6 days of downtime I get word from Sony that apparently mine and 75 million other accounts have been compromised, including pretty much all of my personal information. Worst of all, this information included my password and possibly my credit card information.

 

This is an unforgiveable sin on many levels, but more than anything I have to say this… if you are storing sensitive information in your game, encrypt the hell out of it!  Really, it’s not that hard.  Actually here is how you do it…  this is code I have used in another project, but sadly I forget exactly where I got it from for proper crediting.  So, if you are the author, let me know and I will give proper accreditation.

using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace ConfigurationLibrary
{
    public sealed class CryptoString
    {
        private CryptoString() { }
        private static byte[] savedKey = ASCIIEncoding.UTF8.GetBytes("YOURVALHERE");
        private static byte[] savedIV = ASCIIEncoding.UTF8.GetBytes("YOURVALHEREASWELL");
        public static byte[] Key
        {
            get { return savedKey; }
            set { savedKey = value; }
        }
        public static byte[] IV
        {
            get { return savedIV; }
            set { savedIV = value; }
        }
        private static void RdGenerateSecretKey(RijndaelManaged rdProvider)
        {
            if(savedKey == null)
            {
                rdProvider.KeySize = 256;
                rdProvider.GenerateKey();
                savedKey = rdProvider.Key;
            }
        }
        private static void RdGenerateSecretInitVector(RijndaelManaged rdProvider)
        {
            if(savedIV == null)
            {
                rdProvider.GenerateIV();
                savedIV = rdProvider.IV;
            }
        }
        public static string Encrypt(string originalStr)
        {
            // Encode data string to be stored in memory.
            byte[] originalStrAsBytes = Encoding.ASCII.GetBytes(originalStr);
            byte[] originalBytes = { };
            // Create MemoryStream to contain output.
            using(MemoryStream memStream = new
                     MemoryStream(originalStrAsBytes.Length))
            {
                using(RijndaelManaged rijndael = new RijndaelManaged())
                {
                    // Generate and save secret key and init vector.
                    RdGenerateSecretKey(rijndael);
                    RdGenerateSecretInitVector(rijndael);
                    if(savedKey == null || savedIV == null)
                    {
                        throw (new NullReferenceException(
                                "savedKey and savedIV must be non-null."));
                    }
                    // Create encryptor and stream objects.
                    using(ICryptoTransform rdTransform =
                           rijndael.CreateEncryptor((byte[])savedKey.
                           Clone(), (byte[])savedIV.Clone()))
                    {
                        using(CryptoStream cryptoStream = new CryptoStream(memStream,
                              rdTransform, CryptoStreamMode.Write))
                        {
                            // Write encrypted data to the MemoryStream.
                            cryptoStream.Write(originalStrAsBytes, 0,
                                       originalStrAsBytes.Length);
                            cryptoStream.FlushFinalBlock();
                            originalBytes = memStream.ToArray();
                        }
                    }
                }
            }
            // Convert encrypted string.
            string encryptedStr = Convert.ToBase64String(originalBytes);
            return (encryptedStr);
        }
        public static string Decrypt(string encryptedStr)
        {
            // Unconvert encrypted string.
            byte[] encryptedStrAsBytes = Convert.FromBase64String(encryptedStr);
            byte[] initialText = new Byte[encryptedStrAsBytes.Length];
            using(RijndaelManaged rijndael = new RijndaelManaged())
            {
                using(MemoryStream memStream = new MemoryStream(encryptedStrAsBytes))
                {
                    if(savedKey == null || savedIV == null)
                    {
                        throw (new NullReferenceException(
                                "savedKey and savedIV must be non-null."));
                    }
                    // Create decryptor and stream objects.
                    using(ICryptoTransform rdTransform =
                         rijndael.CreateDecryptor((byte[])savedKey.
                         Clone(), (byte[])savedIV.Clone()))
                    {
                        using(CryptoStream cryptoStream = new CryptoStream(memStream,
                         rdTransform, CryptoStreamMode.Read))
                        {
                            // Read in decrypted string as a byte[].
                            cryptoStream.Read(initialText, 0, initialText.Length);
                        }
                    }
                }
            }
            // Convert byte[] to string.
            string decryptedStr = Encoding.ASCII.GetString(initialText);
            return (decryptedStr);
        }
    }
}

Now its as simple as calling ConfigurationLibrary.CryptoString.Encrypt(somestring);  and ConfigurationLibrary.CryptoString.Decrypt(somestring).

 

It is this easy to encrypt your info, compromising your users security is never justified!  Just be sure to protect your encryption keys as much as possible.

 

For the record, I don’t know if Sony encrypted this information or not, but they haven’t communicated that they did, which leads me to believe that they didn’t.  If they did, Sony has done a horrible job at PR.  If they didn’t, Sony made a mistake a first year CS student never should have!  Either way, Sony just screwed up really badly.

Programming, Totally Off Topic , ,

Month List

Popular Comments