Category Archives: Programming

The Monolithic Procrastination Post

Yes, I’m aware that I’m a bastard for not posting for a whole two months despite not having any work obligations. I was honestly going to post last month following the release of the new Cursor Lock version, but got sidetracked with other projects. The story of my life really–project ADD.

news270

Cursor Lock 2.5 alpha

However, for anyone yearning for a new version of Cursor Lock, I can assure you that I will finish it soon as it’s practically complete already (as the screenshot at right will show). I’ve already completed a majority of the testing and just have a few more issues to resolve and documentation to update. I’ve also found a game that puts the new features to use: DX-Ball 2. The new window locking mode works perfectly in the game’s windowed mode to keep the paddle’s responsiveness from drifting out of the window with the mouse.

Another project that I wanted to post about alongside Cursor Lock last month is my newest Age of Empires 3 mod, Banner Army Reforms. It’s a relatively simple tweak that makes a big difference to the manageability of the Chinese civilization. It allows the player to train units individually instead of in unique groupings (Banner Armies). While a key facet of the Chinese, Banner Armies were just a strategic annoyance to me. Too bad the Chinese still suck.

Last post, I mentioned a PHP script that used PEAR’s Text_Highlighter package, but which I had some concerns about and thus wasn’t ready to go live with. Since then, I’ve been racking my brains trying to come up with a way to securely show external source code files (that have been parsed with Text_Highlighter) embedded inside a formatted page. My second implementation idea was to use my inflatable wrapper technique that places a formatting script inside the target source code file; however, that would force me to make the source code files have .php extensions. I also considered a database of IDs and associated code files, which would be secure but also a hassle and it would obfuscate the underlying source code files.

After much googling and frustration, I finally found a way to make certain file extensions be passed to a handler script. This obscure Apache manual page shows how to add an action to extension handlers. If the target of the action is a script, it will receive the originally called file as some sort of CGI parameter; in PHP, it’s placed in the ENV variable $PHP_SELF (don’t use $PATH_INFO, it can be spoofed).

Once I had all that snazzy handler business figured out and implemented in the script, I noticed a glaring oversight in the Text_Highlighter package. Since they place all the source code in a <pre> tag, no word-wrapping is done. Quite frankly, I never care enough to bother with manually line-breaking code and just let it run off as far as I need. However, on a webpage, horizontal scrolling is a cardinal sin. So, I spent more time than I’d like to admit rewriting the output module of Text_Highlighter to put the source code in a table which would allow it to wrap effectively while preserving line numbering and line indentations. I ended up actually having to put the indentation whitespace in a cell by itself. The script still needs a bit more polish, but can be seen in action on the files in this parallel program directory.

Those source code files are actually part of a column I’ve been working on lately to show off the parallel program I wrote for my final college project. Besides having beautified code, the column is also to have a web-based version of the Powerpoint slideshow I gave during my results presentation. I had originally made a simple PHP script that took a page number as a parameter and showed the appropriate slide image with all the formatting and such. I had two problems with this, however: there was no ability to copy the slide’s text and it was a bit underwhelming in this Web 2.0-hyped world. So, on a whim, I decided to have a go at making a Flash movie with all the typical play controls as well as Fullscreen and Copy Text buttons, which could load in an external SWF file with one slide per frame. Of course, it has all sorts of delicious alpha effects, too. The parallel presentation slideshow isn’t quite live yet, but you can see the new Flash in action on the lovable old Tony the Worm column. It still needs a smidgen of work yet, though, such as tooltips. I find Flash a decidedly quirky and frustrating format; finishing one button is enough for celebration.

Posted in Modding, Programming, Website | Tagged , , | Leave a comment

A Full Month of Doings

I’ve been working on so much stuff lately that it’s hard to decide what to devote each day to. Of course, practically everyone I know doesn’t give a shit about the awesome stuff I do and rather I just jump into the rat race. But anyways, here’s an overview of what I’ve been working on…

Not long after my last post, I updated my mod for the Age of Empires 3 expansion The Asian Dynasties called Gatling Guns for All!. Previously, you could only use the mod with a specific unmodified version of TAD, but I wanted the mod to be usable by all versions of both The Asian Dynasties and The Warchiefs expansions even if they’ve been previously modded. Thus, I had to create an installer (similar to the one I did for Stalker) that would modify only the aspects of the game that I changed. Originally (as I did in the Stalker mod installer), I tried to use regular expressions to find the appropriate setting to change. However, being that the game data is stored as XML, Regex had problems matching certain XML formatting quirks. So, I moved to a query language that I’d never used before called XPath, which is basically XML hierarchy-aware Regex. Though getting some of the nodes in AOE3’s settings files to match was still tricky, XPath in .Net did the job perfectly.

When I went to package the new version of the mod, I actually found out that I had incorrectly archived an essential file in the wrong path in the first versions of the mod. Thus, nobody that downloaded it would have gotten the mod to work as intended :( . And only one person called me on it, though I thought he was a noob at first. But all has been rectified now.

Next, I started working on a script for this site that would color-code programming language syntax and elements so I can attach beautified code to some columns. The script uses a PEAR PHP library called Text_Highlighter to do the color-coding on the fly. However, at the moment, my part of the script still presents certain security risks that I will have to mitigate before it goes live.

news269

Lego Indiana Jones

That project was interrupted by a visit from Kaylen that turned into non-stop gaming in the form of Lego Indiana Jones 😉 . Although the game was littered with some annoying little bugs (having just been released), we did manage to get 100% completion. As most reviews have said, it wasn’t really as fun as Lego Star Wars–how can you beat lightsabers and the force? Though bazookas and bushes you can jump into come close.

The next week, following a concern from a user, I began working on a major new feature for Cursor Lock. Though not really having anything to do with multimonitor gaming, the feature is a natural progression of the existing code. It allows the user to select whether to lock the cursor into the current screen (what it did originally), the selected window, or the selected window interior (client area). Locking the cursor into the window interior is particularly useful for playing windowed 3D games. While I was at it, I decided to completely overhaul the setup GUI to be much more intuitive, separating the selection of the different modes with pretty, graphical buttons. It’s looking rather nice already and should only take a few more days of testing and fixing bugs until public release.

Last week, I got distracted when randomly deciding to replay Deus Ex: Invisible War and then subsequently desiring to mod out some of the major flaws in the game. Only a few changes would make the game much more palatable to the PC fanbase. One of the mod ideas I had was to combine the various proximity and thrown variants of grenades (EMP, scrambler, gas, and concussion), which would return the grenades to their vanilla Deus Ex functionality and give the player a lot more inventory space. So apparently, the developer of Deus Ex, Ion Storm, only decided to release the Thief: Deadly Shadows editor and not the Invisible War one, even though the games were made concurrently on the same engine (Unreal Warfare). I tried for days to get the Thief editor to work for Invisible War, but I don’t see it ever working out easily; there are far too many hardcoded elements of the games in both the editor and the game executables. The best I could do was to get the DX2 packages to load in the Thief editor after it had loaded the core Thief packages first. Then, I could get the DX2 packages to save after some simple modifications, but that made it so there were both Thief and DX2 classes mixed together, making a good number of DX2 objects break ingame (e.g. inventory, particle emitters). In other words: Epic Fail. 😕

However, while I was poking around in Invisible War’s resources, I found the plaintext files containing the secret area’s developer quotes. I decided it’d make a good contribution to my Deus Ex column, despite not being from vanilla Deus Ex. Then, whilst I was formatting the quotes for HTML, I got the crazy notion of using the game’s font for the text. Unfortunately, the font was not in a TrueType or comparable format, but rather it was merely a texture and an accompanying text file (DX2_FONT.cel) of comma-delimited texture character widths (in pixels) that were ordered corresponding to their ASCII value. The texture character height was understood to be 23 pixels, so that a width of -1 in the text file meant to go to the next row. Using a quickly thrown together program, I turned the width values into a Paint Shop Pro script (macro) that would cut out all the characters into individual bitmaps. Finally, I manually pasted them into a font editor to complete the conversion. The font can be downloaded here, and then can be tested on the aforementioned DX2 quotes page.

Posted in Modding, Programming, Website | Tagged , , , , | Leave a comment

Snake gets nostalgic with the new Blog Archive

Over the weekend, I finally got around to coding the new blog archive. As one can see, it displays a list of the most popular tags in one table and a calendar broken down into years and months in another. This is, of course, leaps and bounds better than Coranto’s single column list of months, which was getting absurdly long.

This was the first page in a while that required me to start from mostly scratch. Although the style is similar to the rest of the site, the design is different. Before I even touched the code, though, I had to make sure my design would work. One of the key features of the design is something I’ve used before and been quite pleased with: adjustable numbers of columns for different frame widths (i.e. from different resolution monitors). It uses a bit of JavaScript to calculate the optimum number of columns and then reloads the page to pass in the number; then, the page’s script adjusts the tables accordingly. The code consisted of two major tasks: loading the data into an acceptable format and then outputting with HTML formatting. Instead of doing a lot of SQL queries, I decided it was more efficient to just parse post dates and store them in a multidimensional array of years, months, and posts. Finally, outputting merely requires array traversal with some iterative control structures, printing HTML as you go. It loads surprisingly fast for the amount of data it handles.

news258Since then, I’ve been reading back over old posts to fill out the tags–understandably, the popular tags list looks more impressive when there’s something there. One side effect, though, is that it’s making me rather nostalgic. It’s actually quite interesting seeing the number of posts …my life splayed out over time; it puts things in perspective. One may notice the two large voids in posting around summer 2000 and March 03 to May 04. Although there’s not many posts to go by, these were actually the most satisfying times in my life–they were so great, I couldn’t even be bothered with posting (that and Danky broke the news system in 2003).

news256In early 2000, Loogie and I started getting into our first online gaming experience with Team Fortress Classic. We played so much that in May we started our own clan, S&L. We spent many a night honing our skills with clanmates against our arch-nemesis, the CDD clan. And although we kept playing TFC for years, nothing quite lived up to that first summer.

In March of 2003, I started dating Beckie, my first girlfriend. Things were fast and crazy around that time (graduating high school and all) and I scored. There were so many awesome and horrible feelings and situations that it was an orgy of senses and emotions. But it got boring after a while and would never again live up to the first few months.

But what I’m trying to get at here is that our first real experience with some amazing social ventures, like dating or online gaming, may just be the most gratifying times of our lives in retrospect. I’m not even sure if timing or the persons or places (games) involved make that much difference to this fact, just that it is our first time. I also don’t believe that there’s any moral to this story; I just hope that if you took the time to read this, maybe it has attuned your sensitivity to memories of such things.

Perhaps these feelings may make us slaves to the memories of our former selves, always trying to recapture our best times. While this may be true in part for me, it’s also given me a need to sample as many things as possible (within comfortable limits, of course) to find my next great first. (Maybe I won’t even know I’ve had one until I look back.) Though, I’ve always been bitter that my first relationship got in the way of my one true love: computing. I know some of this sounds bad for my current girlfriend, but I want to assure her that she’s my number two. Hmm…no, lemme try again: You’re my favorite person in the world, Kaylen.

Sorry I got all personal on this post. I’ll try not to let it happen again. 😉

Posted in Programming, Website | Tagged | Leave a comment

Cursor Lock Optimizations

My recent major version of Multimon Cursor Lock was pretty CPU efficient, using around .15 to .3 seconds of CPU time after two minutes with a poll rate of 20ms. Still, I was noticing a large number of page faults while the program was polling–about 100 for each poll. Page faults occur when a needed “page” of memory is not currently in physical memory and thus needs to be loaded back in from the page file (swap space on a hard drive). Of course, page faults are not fatal, but they do lower performance.

Tonight, I finally decided to investigate the page faults and see if there was any fix. It was really as simple as watching Process Explorer’s process performance tab while stepping through the code. It didn’t take long until I found the culprits: CreateToolhelp32Snapshot() and Process32Next(). (I use these functions to enumerate the processes on a system. Of course, using EnumProcesses() would have been a better way, but that API function is only available on 2000/XP+ and I wanted to support as far back as 98.) Creating the snapshot requires at least 20 page faults, and looping through each process is a few more. Since I saw no memory actually being swapped, I figure the system module that contains this legacy function must be at fault (pun intended).

Seeing that my process enumeration code was causing 100 faults every time it ran (give or take, depending on how many processes are running), I came up with a simple optimization to cause it not to be needed as much. It was basically just to allow the program to remember the ID of the process it locked to last and check if its window still had focus on the next poll. Thus, while the program (typically a game) is locked, it doesn’t need to enumerate processes and creates no page faults. When I went to look at the performance for my optimized code, I actually had trouble seeing if it used any CPU at all. Apparently, the usage is so much smaller than the performance counter’s resolution, that after five minutes of locked polling, I couldn’t see any increase in CPU time usage. Because the usage is so immeasurably small, it was amusingly difficult to say how much the performance increased for the changelog.

Also, I’ve written a new column recently; it’s in the guides section, but it really doesn’t fit that category. I’d love to rearrange my column categories to include a software one, but unfortunately the URLs for columns are based on their category. Anyways, if you enjoyed this post, you’ll probably enjoy this column as well. It’s the same kind of reverse engineering goodness that gets us geeks all hot.

Posted in Programming | Tagged , | Leave a comment

Cursor Lock 2.0 and Power Supply failures

I’ve been wanting to rewrite one of my VB.Net programs over in C++ recently, just to force myself to learn the language better. Since there was no way in hell I was going to tackle any program with a graphical user interface, I chose the locking portion of my Multi-Monitor Cursor Lock to port. Looking over the code for a recent feature-request update, it seemed like most of the code involved Windows API function calls and data types, which are actually easier to implement than in VB (you just have to include windows.h).

Really, the two most difficult to learn fundamentals of C (having come from a VB/Java/PHP background) are character strings and pointers. Pointers really aren’t that bad once you learn how the operators work, but you still have to stop and think about any redirections: “& returns an address, * returns a value”. The problem with strings is that there are a million types of them and getting them to play nice requires all sorts of tricks; there’s character arrays, pointers to characters, constant version of both of those (which I still don’t really get–how can something return a constant?), string class, cstring class, wide characters, ANSI characters, Unicode characters, multi-byte characters. Since I wasn’t using MFC or ATL, I decided to stick with the string class, which could be initialized from character arrays or character pointers. And although its c_str() function returns a const char *, you can use strdup() or strcpy() to easily get a char *, which many API functions require.

After trudging through the code for parsing the command line switches in and reading default values, the code for the actual locking portion just kind of rolled out (being comprised almost completely of API calls). Doing the code was fun, but the benefits that I

news241

Testing Cursor Lock compatibility required me to install Win98 in VMWare.

saw during performance testing blew me away. I ran the VB.Net and C++ versions for two minutes at 20ms poll rate to see the CPU usage. .Net used 8.6 seconds of CPU time compared to C++’s .3 seconds: a 29 times performance increase! This test couldn’t have been more definitive as the algorithms were virtually the same; remember, I said the locking portion was mostly system calls. Then, I tested memory efficiency, which was also delightful but the difference was less dramatic: ~16,000KB to ~1,500KB (~10x less memory) or ~7,000KB to ~400KB (~17x less) using the SetProcessWorkingSetSize(hProc, -1, -1) trick–not too shabby. Also, without the .Net “Just-in-Time” compiling, the C++ version doesn’t have a two to three second start and close delay.

Happy with my results, I started working on new documentation for Cursor Lock 2.0, so I could submit to some download sites. It was about complete when I decided to turn in for the night on Saturday. As I laid in bed, nearly asleep, I heard the fans in my computer spinning down, the silence cutting through my subconscious. Peering over at the tower, I noticed the power light still on, which was even odder than the system randomly powering down. I went over and tried to restart, but it wouldn’t stay on long enough to even begin to news242POST and blue smoke smell had already permeated the room. The next morning, I smelled around the tower and found the culprit to be the power supply, as I suspected. After taking the PSU apart and dissecting it on the kitchen table, I found an interestingly charred transformer coil. When I plugged the PSU in and shorted the power-on pin, a spark leapt from aforementioned transformer to a plastic insulation divider. Upon further inspection, it appeared the divider had actually melted to the transformer.

Obviously, this power supply was dead beyond anything I could repair, so I ordered a new 500W Thermaltake PSU from Newegg. I tried to get one that I could still use whenever I finally get to upgrade my core system components; the key to this was in the 20+4-pin ATX main connector that allows you to break the newest 4 pins away from it. In retrospect, I had probably been overloading the old PSU for a while now, which was leading to some system instabilities when gaming. It was rated for 350W, but most wattage calculations I had done put my usage at slightly above that. Anyways, here’s some pics of the new power supply. I should have gotten one with it inside the case, but oh well…some other time.

Luckily, after that disaster, none of my other hardware had been fried (from an over-voltage or such), and I got to finish the documentation and polish of the new Cursor Lock. I submitted it to a few download sites, but it could be weeks before they get approved. What independent developer has $1000 for their premium services? Not to mention that there are thousand of good download sites on the web. Well, until it appears on other sites, the new version can be found right where it always was here.

Posted in Hardware, Programming | Tagged , , | Leave a comment

Links and Alarm

Links

First of all, you may notice that there is actually a link for the “Links” item in the nav. Over the past few days, I’ve been designing, coding, and adding the links themselves for this new links system. The building process was pretty similar to all the systems I’ve done so far, especially the Photo Album. I design the page in HTML first, so I can preview how tables and such will look and debug browser compatibility locally. Then I take this HTML page and convert it to server-side form, quantifying item HTML blocks with PHP loops and adding the necessary SQL queries. Somewhere in there, I create the database tables and start adding in records. This is pretty much how every system was built.

The links system is seemingly the most simple system I’ve built so far, but it’s actually a bit more complex. For one, the category (directory) hierarchy is not linked through paths like the Photo Album, but is linked by item IDs and parent category IDs (a tree). This makes sense because the category hierarchy is logical here, instead of being based on physical paths with the Photo Album. The advantage of this method is that items (links and categories alike) are not dependent on a whole chain of parent categories but merely the parent ID. This makes moving items, renaming items, and the MySQL queries easier. The disadvantage being that mapping the category paths is a recursive nightmare.

Another complex part of the links system is the feature that checks link status–whether or not the URL of the link is working. I’ve set it up so that every Friday morning (or when I run it manually), a script will request every link URL in the database. It then takes the HTTP response code from the requests and puts them into the database (this will appear as a popup tip for the link status), decrypting them into a brief OK, MOVED, or BROKEN status that appears for each link on the page. This seems to be working quite bitchin so far, except that FilePlanet always returns 403 Forbidden. I suspect that they filter out non-supported browsers through their default index this way.

Except for any bug-fixes that may pop up, the new links system is done. I’d recommend you comb through the more than fifty links already there; you may find something useful.

Snake’s Alarm

I put some more work into my alarm program before getting involved with the links business. Mainly, I’ve been working on improving the stability of the sound system. Luckily, FMOD handles all of the low-level loading, decoding, and outputting stuff for me, but I still have to implement when, what, and how it does its job. My original implementation of FMOD would crash whenever you tried to play two sounds at once. Because I didn’t want FMOD to hold onto some sound resources when alarms aren’t being played, it didn’t initialize until an alarm went off. Thus if two alarms happen to overlap, the second will indeed try to reinitialize the system, crashing it in the process.

I solved this problem by making a simple sound system stack. When the first sound is pushed onto the stack, the system initializes. When the last sound is popped, it closes. This fixes the problem with multiple sounds playing, but now I’m working on a problem when sounds end. I’ve traced this back to the fact that each sound alarm gets its own thread. My next big challenge will be bringing the different alarm threads together into one big sound system thread (with the stack). Easier said than done, but I will prevail!

I was also going to talk about my current gaming trends in this post, but I’ll save that for another time. In the meantime, here’s a rare picture of Kaylen and I out in the sun. Oh noes!

Kaylen and I catching some much-needed rays on the beach at Kiptopeke State Park.

Posted in Programming, Website | Tagged | Leave a comment