EA , 12- |
#include
#include
#include
#include
#include
#define REPEATS 1000 //
#define ESCAPE 27 // ESCAPE
#define TEST_TIME 2 // ,
#define START_TIME 0 //
void main( )
{
time_t t;
srand( time( &t ) );
while ( true )
{
float diffs[ REPEATS ];
int frame_diffs[ REPEATS ]; //
for ( int i = 0; i < REPEATS; i++ )
{
int limit = rand( ) % TEST_TIME + 1;// - ,
// +1 0
limit *= 60; //
limit += (START_TIME * 60); //
float t = 0.0f + (START_TIME*60); //
float step = 1.0f / 60.0f; // 60
int steps = 0;
while ( t < limit )
{
steps++;
t += step;
}
//
double expectation = (double)(limit - START_TIME*60)/ ( 1.0 / 60.0 );
printf("%f\n", t );
printf("Difference = %f; steps = %d\n", t - limit, steps );
printf( "Expected steps = %f; frames dropped = %d\n",
expectation, (int)expectation - (int)steps );
diffs[i] = fabs( t - limit );
frame_diffs[ i ] = (int)expectation - (int)steps;
}
//
float sum = 0;
int frame_sum = 0;
for ( int j = 0; j < REPEATS; j++ )
{
sum += diffs[ j ];
frame_sum += frame_diffs[ j ];
}
printf( "Avg. time difference = %f, avg. frame difference = %d\n",
sum / REPEATS, frame_sum / REPEATS );
// "any key" , "ESCAPE"
printf( "Press any key to continue, press esc to quit\n" );
if ( getch() == ESCAPE )
break;
}
}
enum ProcessSizes
{
MW13 = 0x00678e4e
}
public void Refresh()
{
if(!process.IsOpen)
{
// In cases when the process is not open, but the game exists
// The process had either crashed, either was exited on purpose
if(game != null)
Console.WriteLine("Process lost (quit?)");
game = null;
return;
}
if(isUnknown) // If we couldn't determine game version, do nothing
{
return;
}
// If process is opened, but the game doesn't exist, we need to create it
if(process.IsOpen && game == null)
{
Console.WriteLine("Opened process, size = 0x{0:X}", process.ImageSize);
switch((ProcessSizes)process.ImageSize) // Guessing version
{
case ProcessSizes.MW13:
game = new MW.MW13(process);
break;
default:
Console.WriteLine("Unknown game type");
isUnknown = false;
break;
}
}
// At last, update game
game.Update();
}
public abstract class Game
{
private float lastTime;
private GameProcess game;
///
/// Synch-timer's address
///
protected int raceIgtAddress;
///
/// Timer-to-sync address
///
protected int globalIgtAddress;
private void ResetTime()
{
byte[] data = { 0, 0, 0, 0 };
game.WriteMemory(globalIgtAddress, data);
}
public void Update()
{
float tmp = game.ReadFloat(raceIgtAddress);
if (tmp < lastTime)
{
ResetTime();
Console.WriteLine("Timer reset");
}
lastTime = tmp;
}
public Game(GameProcess proc)
{
game = proc;
lastTime = -2; // Why not anyway
}
}
class Program
{
static void Run(object proc)
{
GameHolder holder = new GameHolder((string)proc);
while (true)
{
Thread.Sleep(100);
holder.Refresh();
}
}
static void Main(string[] args)
{
Thread t = new Thread(new ParameterizedThreadStart(Run));
t.Start(args[0]);
Console.WriteLine("Press any key at any time to close");
Console.ReadKey();
t.Abort();
}
}