.:: SimCity 4 Money Cheat Generator using C# (CSharp) ::.
Table of Contents:
Downloads:
Stand alone program (just executable file to generate money)
Full source code written in C# (Visual Studio 2003, FCL v1.1)
Situation:
Every now and then you as the Mayor of your fine SimCity town may fall short of money and need extra cash, fast. Fortunately, the folks as Maxis have provided a cheat to solve this issue. However, they only allow your funds to be increased by 1000 per a series of keystrokes.
SimCity 4 Rush Hour provides a cheat code to increase funds by 1000. To activate this code you are required to press CTRL-X, then type “weaknesspays” in the provided cheat box. If you are trying to acquire a larger amount of funds then this practice is unpractical. Such an issue prompted me to develop an application to help with the repetitive task of typing weakness pays over and over.
I’ve called the application SC4weaknesspays.
(Return To Top ^)
Using SC4weaknesspays:
I have provided the full source code for developers to enhance or research the application with or just the .exe file for those who just want to run the program and get paid.
The program is relatively simple to use. Normally using the weaknesspays cheat SC4 requires you to press Ctrl-X then type weaknesspays then press enter. My SC4weaknesspays program basically does the dirty work for you over and over.
To activate the program, simply press the “Start” link and you will then get a status message of “Listening for keystroke” as detailed below.
Once the program is “Listening for keystroke” you can perform actions by pressing the following keys:
Home: Start the weaknesspays cheat code sequence
Esc: Temporarily stop entering the weaknesspays cheat code sequence
End: Permanently stop listening for keystroke (Same result as pressing the “Stop” link)
BEFORE pressing the “Home” key, you need to launch SimCity4 and load your city. Once the city is loaded, go into Mayor mode then make sure that your cursor is a circle by pressing the Esc key several times. Once you are in the proper mode, press the Home key to start the weaknesspays generator. You may press Esc or End to stop the cheat code sequence as detailed above.
(Return To Top ^)
Development Goals:
- Create a program that repeatedly activates the SimCity 4 money cheat code a user specified amount of times
- Develop an application that doesn’t cause SimCity 4 to react in undesirable ways (application locking up, all the keystroke sequences not going through)
(Return To Top ^)
Underlying Technology
Since the S4weaknesspays needs to generate the keystrokes outside of it’s own scope, the application needs to listen for a specified keystroke, which I have specified has the Home key. Microsoft provides a GetAsyncKeyState function in user32.dll that will detect which key was recently pressed. I found an implementation of this function in C# from Alexander Kent’s article at CodeProject.com. To actually emulate the keystrokes I implemented the .net method System.Windows.Forms.SendKeys().
To keep the application moving smoothly I’ve used implementations of the .net framework classes of System.Timers.Timer and System.Threading.Thread.
(Return To Top ^)
The Code:
First, we’ll cover the code that powers the form as displayed and described above. To keep the code clean I created an class object called WeaknessGenerator that facilitates the listens for the keystrokes to launch a specified action.
To listen to the keystrokes, a reference to the GetAsyncKeyState function needs to be established. This is used through a series of DllImports.
WeaknessGenerator Class Code:
[DllImport("User32.dll")]
private static extern short GetAsyncKeyState(
System.Windows.Forms.Keys vKey); // Keys enumeration
[DllImport("User32.dll")]
private static extern short GetAsyncKeyState(System.Int32 vKey);
Listening for the keystrokes requires a timer method to continuously monitor keystrokes.
this.timerKeyListen = new System.Timers.Timer();
this.timerKeyListen.Elapsed +=
new System.Timers.ElapsedEventHandler(timerKeyListen_Elapsed);
this.timerKeyListen.Interval = 10;
An ElapsedEventHandler needs to listen for keystrokes to launch the appropriate methods. Home to start entering the money cheat, Escape to stop money cheat code entry, and End to completely stop listening for keystrokes.
private void timerKeyListen_Elapsed(
object sender, System.Timers.ElapsedEventArgs e)
{
foreach(System.Int32 i in Enum.GetValues(typeof(Keys)))
{
if(GetAsyncKeyState(i) == -32767)
{
if (i == 27) // Esc
this.stopEntriesThread();
if (i == 36) // Home
this.startEntriesThread();
if (i == 35) // End
this.Stop();
}
}
}
Once the Home key is pressed, a thread is launched, causing the method startEntries() from the Thread.Start() method.
if (!entryThread.IsAlive)
entryThread.Start();
Next comes the magic, using the SendKeys() method to emulate the keystrokes of Ctrl-X : weaknesspays : Enter .. SimCity4 starts acting a little strange if the series of keystrokes are entered without a little pause between each one. The Thread.Sleep() method easily provides a way for the application to wait before pressing a keystroke.
for (int i = 1; i <= this.numberOfEntries; i++)
{
OnStatusChanged(new GeneratorEventArgs(
this.numberOfEntries, i, GeneratorCommandType.Start,
"Entering Weakness Pays"));
SendKeys.SendWait("^x");
Thread.Sleep(50);
SendKeys.SendWait("weaknesspays");
Thread.Sleep(50);
SendKeys.SendWait("{ENTER}");
Thread.Sleep(50);
}
To facilitate the change of events and status from the class to the calling WinForm I have created an event.
public delegate void GeneratorStatusChanged(
object sender, GeneratorEventArgs args);
I have also created a class of EventArgs that allows for information such as the number of cheat keycodes request, the current ordinal position, status of the generator, and any sort of text status message. An example of using this event is:
OnStatusChanged(new GeneratorEventArgs(
this.numberOfEntries, i, GeneratorCommandType.Start,
"Entering weaknesspays"));
WinForm Code:
Most of the WinForm code is pretty lightweight by putting the majority of the processing on the WeaknessGenerator class. A few code segments worth mentioning are the events for the Sart and Stop buttons:
private void startListen_LinkClicked(
object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
startThread();
}
private void stopListen_LinkClicked(
object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
if (this.generator != null)
generator.Stop();
}
Attaching the Event Handler and running the necessary code.
private void generator_StatusChanged(
object sender, GeneratorEventArgs args)
{
this.statusLabel.Text = args.StatusText;
this.progressBar.Maximum = args.NumberOfEntries;
.....
}
(Return To Top ^)
References:
(Return To Top ^)