Probably easiest just to post the whole thing. This is part of my upcoming patch, hence the name (JFLP = Jason’s Freelancer Patch).
/*
jflp.c - Patch Freelancer to remove some FLSpew warnings.
Jason Hood, 31 May, 2009.
This patch removes the following spew warnings:
* couldnt find material 163618903
Generated when a waypoint is selected. I was unable to fix it, so now I
just remove the warning.
* get_zone(N) failed
Generated when a job sector has no name, which is quite frequently.
* Disconnecting equipment with FATE_UNKNOWN, using FATE_DISAPPEAR
Generated when a wreck drops its weapons. This is a bug in Freelancer.exe,
since it doesn't detect the "fate_loot" type.
* Used Hostile Pick Assistance
Not sure exactly when this is generated (or even why), but it's something
to do with targetting enemy fighters.
2 June, 2009:
* replace the line number of the "Deform::start_aim" notice with the
timestamp of the event (in milliseconds; it also replaces the string with
"(null)", in order to fit the new code).
Build (VC 6):
rc jflp.rc
cl /nologo /Fepath\to\freelancer\exe\jflp.dll jflp.c /link /dll /subsystem:windows /machine:ix86 jflp.res
*/
#define WIN32_LEAN_AND_MEAN
#include <windows.h>void Patch_Common( void )
{
#define ADDR_VERS10 (0x62c1485 - 0x6260000 + common)
#define ADDR_FATE10 (0x6293727 - 0x6260000 + common)
#define ADDR_ZONE10 (0x633c26c - 0x6260000 + common)
#define ADDR_VERS11 (0x62c14e5 - 0x6260000 + common)
#define ADDR_FATE11 (0x6293487 - 0x6260000 + common)
#define ADDR_ZONE11 (0x633c34c - 0x6260000 + common)
DWORD dummy;
PBYTE addr_fate, addr_zone;
PBYTE common = (PBYTE)GetModuleHandle( "common.dll" );
if (*(DWORD*)ADDR_VERS11 == 0x639F3CC)
{
addr_fate = ADDR_FATE11;
addr_zone = ADDR_ZONE11;
}
else if (*(DWORD*)ADDR_VERS10 == 0x639F39C)
{
addr_fate = ADDR_FATE10;
addr_zone = ADDR_ZONE10;
}
else
return;
// Change the fate test to below 3 is bad, below/equal 5 is good.
VirtualProtect( addr_fate, 6, PAGE_EXECUTE_READWRITE, &dummy );
memcpy( addr_fate, "\x72\x05\x83\xf8\x05\x76", 6 );
// Skip the zone message altogether.
VirtualProtect( addr_zone, 1, PAGE_EXECUTE_READWRITE, &dummy );
*addr_zone = 0x28;
}
__declspec(naked)
void RendComp_Patch( void )
{
__asm mov edx, [ebp]
__asm cmp edx, 163618903
__asm lea eax, [esp+28]
__asm ret
}
void Patch_RendComp( void )
{
#define ADDR_MATERIAL (0x6c318be - 0x6c20000 + rendcomp)
DWORD dummy;
PBYTE rendcomp = (PBYTE)GetModuleHandle( "rendcomp.dll" );
if (*ADDR_MATERIAL == 0x8b)
{
// Add in a test for the ignored material.
static BYTE code[] =
{
0xE8,0x00,0x00,0x00,0x00, // call RendComp_Patch
0x74,0x2D, // jz skip_log
0x52
};
*(DWORD*)(code+1) = (PBYTE)RendComp_Patch - ADDR_MATERIAL - 5;
VirtualProtect( ADDR_MATERIAL, sizeof(code), PAGE_EXECUTE_READWRITE, &dummy );
memcpy( ADDR_MATERIAL, code, sizeof(code) );
}
}
void Patch( void )
{
#define ADDR_ASSIST (PBYTE)0x4ede00
#define ADDR_DEFORM (PBYTE)0x452648
DWORD dummy;
if (*ADDR_ASSIST == 0x68)
{
// Skip the "Used Hostile Pick Assistance" message.
VirtualProtect( ADDR_ASSIST, 2, PAGE_EXECUTE_READWRITE, &dummy );
(ADDR_ASSIST)[0] = 0xeb;
(ADDR_ASSIST)[1] = 0x26;
VirtualProtect( ADDR_DEFORM, 10, PAGE_EXECUTE_READWRITE, &dummy );
memcpy( ADDR_DEFORM, "\x6a\x00" // push 0 ;"(null)"
"\x8b\x76\x04" // mov esi, [esi+4]
"\xff\x76\x08" // push dword[esi+8]
"\x90\x90", 10 ); // nop/nop
}
Patch_Common();
Patch_RendComp();
}
BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
{
if (fdwReason == DLL_PROCESS_ATTACH)
Patch();
return TRUE;
}</windows.h>