Mir wurde in dieser Nacht langweilig, also kam ich auf diese Idee.
Ich weiß, dass es hier viele C# Programmierer gibt, also könnte das ganze vielleicht sogar einen Sinn gehabt haben:
Code
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- using System.Diagnostics;
- using System.IO;
- namespace External_CoD4_Radar
- {
- public partial class frmMain : Form
- {
- int m_ClientNum = 0;
- float[ ]m_ViewOrigin = new float[ 3 ];
- float[ ]m_ViewAngles = new float[ 3 ];
- float[ , ] m_PlayerOrigins = new float[ 64, 3 ];
- int[ ] m_PlayerAlives = new int[ 64 ];
- int[ ] m_PlayerTeams = new int[ 64 ];
- [DllImport( "kernel32.dll" )]
- public static extern IntPtr OpenProcess( UInt32 dwDesiredAccess, Int32 bInheritHandle, UInt32 dwProcessId );
- [DllImport( "kernel32.dll" )]
- public static extern Int32 CloseHandle( IntPtr hObject );
- [DllImport( "kernel32.dll" )]
- public static extern Int32 ReadProcessMemory( IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[ ] buffer, UInt32 size, out IntPtr lpNumberOfBytesRead );
- public enum ProcessAccessType
- {
- PROCESS_TERMINATE = ( 0x0001 ),
- PROCESS_CREATE_THREAD = ( 0x0002 ),
- PROCESS_SET_SESSIONID = ( 0x0004 ),
- PROCESS_VM_OPERATION = ( 0x0008 ),
- PROCESS_VM_READ = ( 0x0010 ),
- PROCESS_VM_WRITE = ( 0x0020 ),
- PROCESS_DUP_HANDLE = ( 0x0040 ),
- PROCESS_CREATE_PROCESS = ( 0x0080 ),
- PROCESS_SET_QUOTA = ( 0x0100 ),
- PROCESS_SET_INFORMATION = ( 0x0200 ),
- PROCESS_QUERY_INFORMATION = ( 0x0400 )
- }
- private Process m_GameProcess;
- private IntPtr m_ProcessHandle;
- private byte[ ] ReadMemoryAtAdress( IntPtr MemoryAddress, uint bytesToRead )
- {
- byte[ ] buffer = new byte[ bytesToRead ];
- IntPtr ptrBytesRead;
- ReadProcessMemory( m_ProcessHandle, MemoryAddress, buffer, bytesToRead, out ptrBytesRead );
- return buffer;
- }
- private int ReadInt( IntPtr addr )
- {
- byte[ ] rawData = ReadMemoryAtAdress( addr, 4 );
- MemoryStream memoryStream = new MemoryStream( rawData );
- BinaryReader binaryReader = new BinaryReader( memoryStream );
- int i = binaryReader.ReadInt32( );
- binaryReader.Close( );
- memoryStream.Close( );
- return i;
- }
- private float[ ] ReadVec3( IntPtr addr )
- {
- byte[ ] rawData = ReadMemoryAtAdress( addr, 12 );
- MemoryStream memoryStream = new MemoryStream( rawData );
- BinaryReader binaryReader = new BinaryReader( memoryStream );
- float[ ] vec3 = new float[ 3 ];
- vec3[ 0 ] = binaryReader.ReadSingle( );
- vec3[ 1 ] = binaryReader.ReadSingle( );
- vec3[ 2 ] = binaryReader.ReadSingle( );
- binaryReader.Close( );
- memoryStream.Close( );
- return vec3;
- }
- public frmMain( )
- {
- InitializeComponent( );
- }
- private void txtRange_TextChanged( object sender, EventArgs e )
- {
- int iValue = Convert.ToInt32( txtRange.Text );
- if ( iValue > 500 )
- iValue = 500;
- else if ( iValue < 0 )
- iValue = 0;
- trackbarRange.Value = iValue;
- txtRange.Text = Convert.ToString( iValue );
- }
- private void trackbarRange_Scroll( object sender, EventArgs e )
- {
- txtRange.Text = Convert.ToString( trackbarRange.Value );
- }
- private void txtRange_KeyPress( object sender, KeyPressEventArgs e )
- {
- if ( !System.Text.RegularExpressions.Regex.IsMatch( e.KeyChar.ToString( ), "\\d+" ) )
- e.Handled = true;
- }
- private void frmMain_Load( object sender, EventArgs e )
- {
- m_GameProcess = new Process( );
- m_ProcessHandle = IntPtr.Zero;
- tmrRefreshProcess.Enabled = true;
- }
- private void tmrRefreshProcess_Tick( object sender, EventArgs e )
- {
- Process[ ] gameProcesses = Process.GetProcessesByName( "iw3mp" );
- if ( gameProcesses.Length > 0 )
- {
- if ( m_ProcessHandle.ToInt32( ) == 0 )
- {
- m_GameProcess = gameProcesses[ 0 ];
- txtProcessInfo_Name.Text = m_GameProcess.ProcessName;
- ProcessAccessType accessType = ProcessAccessType.PROCESS_VM_READ | ProcessAccessType.PROCESS_VM_WRITE | ProcessAccessType.PROCESS_VM_OPERATION;
- m_ProcessHandle = OpenProcess( ( uint )accessType, 1, ( uint )m_GameProcess.Id );
- if ( m_ProcessHandle.ToInt32( ) != 0 )
- tmrRefreshRadar.Enabled = true;
- }
- }
- else
- {
- txtProcessInfo_Name.Text = "CoD4 not started";
- tmrRefreshRadar.Enabled = false;
- m_ProcessHandle = IntPtr.Zero;
- }
- }
- bool IsFriend( int clientNum )
- {
- if ( m_PlayerTeams[ m_ClientNum ] > 0 )
- return ( m_PlayerTeams[ m_ClientNum ] == m_PlayerTeams[ clientNum ] );
- else
- return false;
- }
- Point CalcRadarPoint( int clientNum )
- {
- // .Net doesn't provide cool math. :-(
- // We've to do it all ourselves.
- float[ ] clientPos = new float[ 3 ];
- clientPos[ 0 ] = m_PlayerOrigins[ clientNum, 0 ];
- clientPos[ 1 ] = m_PlayerOrigins[ clientNum, 1 ];
- clientPos[ 2 ] = m_PlayerOrigins[ clientNum, 2 ];
- float[ ] delta = new float[ 3 ];
- delta[ 0 ] = clientPos[ 0 ] - m_ViewOrigin[ 0 ];
- delta[ 1 ] = clientPos[ 1 ] - m_ViewOrigin[ 1 ];
- delta[ 2 ] = clientPos[ 2 ] - m_ViewOrigin[ 2 ];
- float distance = ( float )Math.Sqrt( delta[ 0 ] * delta[ 0 ] + delta[ 1 ] * delta[ 1 ] + delta[ 2 ] * delta[ 2 ] );
- float angle = ( float )( Math.Atan2( delta[ 1 ], delta[ 0 ] ) * 180.0f / Math.PI );
- angle = angle - m_ViewAngles[ 1 ] - 90;
- float range = Convert.ToSingle( txtRange.Text ) * 10.0f;
- Point result = new Point( );
- result.X = ( int )( picRadar.Width / 2 + ( Math.Cos( ( 90 + ( 90 - angle ) ) * Math.PI / 180.0f ) * ( distance / range * picRadar.Width / 2 ) ) );
- result.Y = ( int )( picRadar.Height / 2 + ( Math.Sin( angle * Math.PI / 180.0f ) * ( distance / range * picRadar.Height / 2 ) ) );
- return result;
- }
- private void tmrRefreshRadar_Tick( object sender, EventArgs e )
- {
- Bitmap bmp = new Bitmap( picRadar.Width, picRadar.Height );
- for ( int x = 0; x < bmp.Width; x++ )
- {
- for ( int y = 0; y < bmp.Height; y++ )
- {
- if ( x == bmp.Width / 2 || y == bmp.Height / 2 )
- bmp.SetPixel( x, y, Color.White );
- else
- bmp.SetPixel( x, y, Color.Gray );
- }
- }
- m_ClientNum = ReadInt( new IntPtr( 0x0074E338 ) );
- m_ViewOrigin = ReadVec3( new IntPtr( 0x00797618 ) );
- m_ViewAngles = ReadVec3( new IntPtr( 0x0079B698 ) );
- Graphics graphic = Graphics.FromImage( bmp );
- for ( int i = 0; i < 64; i++ )
- {
- float[ ] origin = ReadVec3( new IntPtr( 0x0084F2D8 + i * 476 + 28 ) );
- m_PlayerOrigins[ i, 0 ] = origin[ 0 ];
- m_PlayerOrigins[ i, 1 ] = origin[ 1 ];
- m_PlayerOrigins[ i, 2 ] = origin[ 2 ];
- m_PlayerAlives[ i ] = ReadInt( new IntPtr( 0x0084F2D8 + i * 476 + 448 ) );
- m_PlayerTeams[ i ] = ReadInt( new IntPtr( 0x00839270 + i * 1228 + 28 ) );
- // Draw the radar in the same loop, the infos are gathered.
- if ( m_ClientNum == i )
- continue;
- if ( m_PlayerAlives[ i ] == 0 )
- continue;
- Point radarPoint = CalcRadarPoint( i );
- if ( radarPoint.X <= 0 || radarPoint.Y <= 0 || radarPoint.X >= picRadar.Width || radarPoint.Y >= picRadar.Height )
- continue;
- Color color = ( IsFriend( i ) ) ? Color.Blue : Color.Red;
- // graphic.FillRectangle( new SolidBrush( color ), new Rectangle( radarPoint.X - 2, radarPoint.Y - 2, 4, 4 ) );
- graphic.DrawRectangle( new Pen( new SolidBrush( color ) ), new Rectangle( radarPoint.X - 3, radarPoint.Y - 3, 6, 6 ) );
- }
- picRadar.Image = bmp;
- }
- }
- }
Ich weiß das ganze ist unperformant und mit sicherheit grottig geschrieben, aber ich bin auch mit dem .Net Framework nicht so dicke.
MfG