123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|112|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> On Topic -> Code crap

Fri, 29 Nov 2013, 09:57
Afr0
What's the ugliest code you've ever written?
Unfortunately, I haven't kept a lot of my old code, but this is probably some of my ugliest code from Project Dollhouse (note: might say more about the underlying format than it does about me...)



-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Fri, 29 Nov 2013, 09:59
Afr0
I am particularly fond of this part - you could tell I was getting annoyed at this stage:



-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Fri, 29 Nov 2013, 10:18
Jayenkai
Pretty sure I didn't think this was ever going to crop up, so I never bothered to make a rule about it..

Spoilered for swears
> Reveal 🔎

-=-=-
''Load, Next List!''
Fri, 29 Nov 2013, 11:04
HoboBen
HOW DO I JAVA?



This made a recent coursework submission.

-=-=-
blog | work | code | more code
Fri, 29 Nov 2013, 17:36
dna
What does that code do Afro?
Sat, 30 Nov 2013, 00:49
Afr0
Loads Interchange File Format, which was already an archaic file format by the release of The Sims (EA designed it back in 85).
Maxis used it for The Sims to store objects and related data. At that point, it was sketchy, at best. The Sims was originally developed on Macs, meaning that the final format (if there ever was a final...) version had a a multitude of cases where it couldn't decide if fields were supposed to be big endian and little endian.

Now, by the time that The Sims Online came along, the format had developed into a monstrosity of epic proportions, as is evident from the loading code. After... five or six expansion packs, where objects clearly needed to be developed in a hurry, their already sketchy use of the format... well, let's take a look, shall we?

  • Most IFFs should contain a RSMP chunk (ReSourceMaP), indicating where the other chunks are located in the file. But all IFFs don't. I don't know why the hell they figured that scanning all headers to find the chunk you're looking for would be faster... go figure!
  • Looking up a chunk doesn't go much faster when you take into account that all chunks are uniquely identified by a name string (!), and a file may contain multiple chunks of the same type. These name strings were apparently a source of endless debate in developer meetings, so eventually it was decided to just assume that all name strings had to be 64 characters, and to zero terminate them if they happened to be shorter.
    Interestingly, this invention was added in a version after the initial one, which just referenced chunks by their ChunkID - which would have been fine.
    The Sims Online obviously uses both versions...
  • In theory, data inside chunks should be little endian, and the container itself should be big endian. But there are at least a couple of cases where the chunks can be either/or, and so this must be determined before reading.
  • Sometimes, a RSMP chunk can be empty (ooops!), meaning that if you write your reader to read the RSMP - hoping it will be faster - you'll have to back up to where you originally started off and proceed to scan all headers.
  • Sometimes, a chunk's typecode can be empty, and... well, I'm not sure my code handles this case yet, because I'm not sure there's any logical way to determine the type of the chunk, except for guesstimating by trying to read all chunks and seeing if the data makes sense.
  • Several of the chunks have at least two versions of their own, where fields may (or may not - remember, inconsistency!) exist based on the version. My favorite (though untypical) example of this is the STR# chunk, listed below. Just the fact that they decided they needed more than one way to represent an object's description string is mindboggling, let alone coming up with five of them!

  • For your viewing pleasure, here is the inconsistency that is the #STR chunk:



-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Wed, 04 Dec 2013, 05:05
Hotshot
UGLY Coding have be

Object C
COBOL

Bloody Awful !