Recently I dusted off my old copy of Sim City 4. Memories flooded back to me of all the time I had spent building up specially crafted money-making masterpieces in the Sim City series oh so many years ago. For a while, life was grand. I was banking a small, albeit legitimate, profit with a small city of about 20,000 people.
Then, with horrifying realization, the veil that time places over events long past lifted, and the novelty of nostalgia departed post-haste. Out of nowhere, the game hung on the balance of a precipice. Then my screen went black. Hello again, desktop old friend.
No! It can't be!
Yes, this was the exact reason I had ever stopped playing Sim City 4. And like an alzheimer's patient, I had crawled back into the false security that was offered, only to have my hopes shattered yet again.
But this time, I've decided that enough is enough! By george, if the developers won't fix it, I will!
That lasted 5 minutes.
Then I posed a query to myself, "Hey, what can I do with my mediocre programming skills to help this situation, since I've no way to solve the crashing issue?"
The answer came swiftly; "I know! I'll just write up an autosaver in python!"
Now you too can relish in the puny bandaid I've placed over this huge gash of a problem.
#!/usr/bin/env python
import time
import win32gui
from SendKeys import SendKeys
ExpectedProgramText = "SimCity 4"
SaveHotkey = "^s" # CTRL + S
InitialWaitTime = 5 # In minutes
SaveInterval = 5 # In minutes
Quitting = False
# Wait for a bit before we begin.
time.sleep(InitialWaitTime*60)
while not Quitting:
# Get the active window's title.
ForegroundWindow = win32gui.GetForegroundWindow()
WindowText = win32gui.GetWindowText(ForegroundWindow)
if WindowText == ExpectedProgramText:
# Time for a save! :)
SendKeys(SaveHotkey, pause=0.02)
# Now let's chill some more.
time.sleep(SaveInterval*60)
This was written using python 2.6 and requires PyWin32 and SendKeys and only works on Windows operating systems.
Problems:
- It seems like the autosave minimizes the UI ingame. This, as far as I can tell, is something I cannot control.
- You have to quit by sending a keyboard interrupt to the program, or manually ending the process.
Possible improvements:
- Command-line usage, complete with argument intake.
- Possibly launching SimCity 4 itself, that way there's the guarantee that it's running, and that it can end when SimCity 4 does. (Unless the crashing affects the returning of focus adversely.)
- Making a taskbar agent which can then configure the options, or shut the autosaver down.
This code is public domain. I am not liable for any results of using, executing, or having this code, except for cases wherein fun and legality are both had.
I would probably make it more user friendly if I didn't have cities to attend to.
