Beamdog has been untangling old computer code for more than seven years now. It released three Enhanced Editions of classic role-playing games with Baldur’s Gate, its Shadows of Amn sequel, and Icewind Dale. You’d think the Edmonton, Canada-based studio would’ve figured out every conceivable hurdle to taking the old Infinity Engine code and making it work.

Of course not. Planescape: Torment threw a new problem at Beamdog: the spells. Seems that Brian Fargo’s Black Isle Studio started working with the Infinity Engine — the game tool behind the beloved RPG — before it was finished (Baldur’s Gate came out first, but Black Isle began work on Planescape before the engine was finished), and Beamdog discovered a heap of issues when taking the old code and updating it for the Enhanced Edition.

“… Baldur’s Gate and Icewind Dale are kind of like cousins — they share a lot of similarities — whereas [with] Planescape, the [Black Isle] team actually forked from a version of the Infinity Engine before Baldur’s Gate shipped,” Beamdog cofounder Trent Oster said over a video call. “They took something that was about two-thirds of the way built and started making Torment with it. One thing that wasn’t finished was the spell system. So they said, OK, we’ve got some free programmer time and some free designer time, [so] let’s make the spells.”

Some of these spells, Oster learned, were “data-driven, made by designers,” and others were hard-coded, with custom code. And, of course, puzzling this out became even harder because some of that went missing. “So we had to reverse-engineer some of it,” Oster said.

“[Beamdog’s Enhanced Editions] are essentially in a version of the Throne of Bhaal code base [that was the expansion for Shadows of Amn]. What we realistically did was we took Planescape and ported it into that code base. It’s actually Planescape running in a highly modified version of the Throne of Bhaal code,” Oster said. “We had to go in and hard-code all the Planescape spells. It was — from the moment we discovered how insidious the problem was until the time it was fixed, that was probably four months of work.”

All for the spell system.

“Some of them, okay, it plays a custom cinematic, and then another one, and then another one. If you grab a modded version of the game, especially one that’s a widescreen mod, you can see the spell render in exactly the 640-by-480 [pixel] window that was normally the full screen. It cuts off on the edges. OK, we have to go through and come up with a way to fix that so we can render it across a 4K display and have it look good. Naturally, we went through and redid the whole thing and rebuilt a rendering system just around the spells,” Oster said.

Beamdog always encounters something that tangles up the code. With past versions, it’s been things like pathfinding (how characters find their ways across a map screen). Oster and team expected something — we’re talking about games that first ran on Windows 95, a Frankenstein’s monster of an OS in the first place.

“We knew something was going to hose us. We just didn’t know exactly what it was. You’re always waiting for the other boot to drop when you’re dealing with code from Windows 95. It was an era where everybody idolized the crazy coder who sat up all night and wrote a bunch of stuff. Some of that isn’t the most obvious in terms of how it’s structured. When you try to read through it 15 years later, it doesn’t necessarily make a lot of sense,” he said.

“When you don’t have the code at all, you’re trying to interpret, from the functionality you’re viewing, how it would be done in the game engine. In the end, we deployed some pretty high-level talent.”

That high-level talent was a few former BioWare engineers, and when it was time, Oster told them, “OK, spells — here’s the first one in the game and the last one in the game. Start at A. We just went through every last one.”

This is Beamdog’s fifth go at enhancing Infinity Engine game code. Each time, the studio’s designers learn something new. But they also achieve a new understanding of the game design process each time. Including the most important — find an easier way to do it next time.

“I’d say the first—at first, we had this whole, we’ll ninja in and make some subtle changes and ninja out. Nobody will know we were ever there. Over time that turned into, we’re going to machete in and hack out huge chunks of code and replace them. At the last level we’re at, it’s really—we’re going to just rebuild it all, and we’re going to use the same assets.

“If I were to start over and do it from scratch, I wouldn’t actually use the original code. I’d probably just build an interpreter that looked at the old engine and used the old assets, and I’d re-engineer the same kind of gameplay.”

VentureBeat's PC Gaming channel is presented by the Intel® Game Dev program. Stay informed about the latest game dev tools and tips. Get the news you can use.