C # Red Alert 2 unlimited money + power load plug-in source code example
If there is reprint please indicate the source: http://www.cnblogs.com/flydoos/archive/2012/01/19/2326149.html
C # Red Alert 2 unlimited money + power load plug-in source code example
Background description:
During the past few days, I had a holiday and had nothing to do at home (but I didn't want to do it). Now, I played the game many years ago-Red Alert 2! But I don't know why. I haven't played for a few years. Now it's so unfamiliar ~~ Playing against the computer 1 vs 7 won't win, and it hurts. After building the base, seven countries attacked at the same time and suddenly killed me.
"I'm not satisfied", so I want to write an auxiliary tool. In fact, this tutorial is meaningless. Because I wrote this little tool many years ago, but it was not written in C # At the beginning. It's okay to write it in C # today. I hope you can point it out. Thank you.
Problems:
I don't know why the game was changed after I modified the power, but it still prompts "insufficient power ". The modified power is only valid for "Patriot missiles, light tower" and other buildings.
Some people say they have not found the correct base address. However, I am not familiar with Ce and have not solved it for a long time. I hope someone can explain why power cannot be changed (not load ).
Updated on
Today, it took another few hours to study the last "Power Load" problem. This time we have done it, and now we can achieve unlimited power + unlimited money. The last base address is correct, but it cannot be modified directly by writing memory. Instead, it requires NOP. You only need to add the following code on the basis of the previous one:
Helper. writememoryvalue (0x004f2d9b, processname,-1869574000 );
Helper. writememoryvalue (0x004f2d9c, processname,-1869574000 );
Helper. writememoryvalue (0x004f2d9d, processname,-1869574000 );
Helper. writememoryvalue (0x004f2d9e, processname,-1953460080 );
Helper. writememoryvalue (0x004f2da0, processname,-1743418480 );
Complete source code:
// Program. CS
Using system;
Using system. Threading;
/*** Author: between Ox a and ox C * Q: 1046559384 C #/Java technology exchange group: 96020642 * Weibo: http://weibo.com/flydoos * blog: http://www.cnblogs.com/flydoos * Date: 2012-01-19 ** money: 0x00a35db4 + 0x24c * load: 0x00a35db4 + 0x52d4 **/
Namespace redalert2
{
Class Program
{
Private const int baseaddress = 0x00a35db4;
Private const string processname = "game ";
Static void main ()
{
While (true)
{
If (helper. getpidbyprocessname (processname) = 0)
{
Console. writeline ("Sorry, you have not started the red alert II game! ");
Console. Read ();
Return;
}
VaR moneyaddress = helper. readmemoryvalue (baseaddress, processname) + 0x24c;
Helper. writememoryvalue (moneyaddress, processname, 999999999 );
Console. writeline (datetime. Now + ":" + helper. readmemoryvalue (moneyaddress, processname ));
Thread. Sleep (1000 );
}
}
}
}
// Helper. CS
Using system;
Using system. diagnostics;
Using system. runtime. interopservices;
Namespace redalert2
{
Public abstract class helper
{
# Region API
[Dllimport ("kernel32.dll")]
Public static extern bool readprocessmemory
(
Intptr hprocess,
Intptr lpbaseaddress,
Intptr lpbuffer,
Int nsize,
Intptr lpnumberofbytesread
);
[Dllimportattribute ("kernel32.dll")]
Public static extern bool writeprocessmemory
(
Intptr hprocess,
Intptr lpbaseaddress,
Int [] lpbuffer,
Int nsize,
Intptr lpnumberofbyteswritten
);
[Dllimportattribute ("kernel32.dll")]
Public static extern intptr OpenProcess
(
Int dwdesiredaccess,
Bool binherithandle,
Int dwprocessid
);
[Dllimport ("kernel32.dll")]
Private Static extern void closehandle
(
Intptr hobject
);
# Endregion
# Region Method
/// <Summary>
/// Obtain the PID based on the window title
/// </Summary>
/// <Param name = "windowtitle"> window title </param>
/// <Returns> </returns>
Public static int getpidbytitle (string windowtitle)
{
Int rs = 0;
Process [] arrayprocess = process. getprocesses ();
Foreach (PROCESS p in arrayprocess)
{
If (P. mainwindowtitle. indexof (windowtitle )! =-1)
{
Rs = P. ID;
Break;
}
}
Return Rs;
}
/// <Summary>
/// Obtain the PID based on the process name
/// </Summary>
/// <Param name = "processname"> process name </param>
/// <Returns> </returns>
Public static int getpidbyprocessname (string processname)
{
Process [] arrayprocess = process. getprocessesbyname (processname );
Foreach (PROCESS p in arrayprocess)
{
Return P. ID;
}
Return 0;
}
/// <Summary>
/// Find the window Handle Based on the window title
/// </Summary>
/// <Param name = "title"> window title </param>
/// <Returns> </returns>
Public static intptr findwindow (String title)
{
Process [] PS = process. getprocesses ();
Foreach (PROCESS p in PS)
{
If (P. mainwindowtitle. indexof (title )! =-1)
{
Return P. main1_whandle;
}
}
Return intptr. zero;
}
/// <Summary>
/// Read the value in the memory
/// </Summary>
/// <Param name = "baseaddress"> address </param>
/// <Param name = "processname"> process name </param>
/// <Returns> </returns>
Public static int readmemoryvalue (INT baseaddress, string processname)
{
Try
{
VaR buffer = new byte [4];
Intptr byteaddress = marshal. unsafeaddrofpinnedarrayelement (buffer, 0); // obtain the buffer address
Intptr hprocess = OpenProcess (0x1f0fff, false, getpidbyprocessname (processname ));
Readprocessmemory (hprocess, (intptr) baseaddress, byteaddress, 4, intptr. Zero); // read the value in the specified memory into the buffer
Closehandle (hprocess );
Return marshal. readint32 (byteaddress );
}
Catch
{
Return 0;
}
}
/// <Summary>
/// Write the value to the specified memory address
/// </Summary>
/// <Param name = "baseaddress"> address </param>
/// <Param name = "processname"> process name </param>
/// <Param name = "value"> </param>
Public static void writememoryvalue (INT baseaddress, string processname, int value)
{
Intptr hprocess = OpenProcess (0x1f0fff, false, getpidbyprocessname (processname); // 0x1f0fff maximum permission
Writeprocessmemory (hprocess, (intptr) baseaddress, new [] {value}, 4, intptr. Zero );
Closehandle (hprocess );
}
# Endregion
}
}
Running interface:
File Download:
Gu Feng Red Police 1006 download (red guard 2 standard) download: http://www.myra2.com/html/hongjingxiazai/ra2/20111015/4929.html
Download plug-in source code (vs2010 project): 1 2 backup address 3