-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEquipMass.cpp
More file actions
93 lines (71 loc) · 2.1 KB
/
EquipMass.cpp
File metadata and controls
93 lines (71 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
EquipMass.cpp - Include equipment and cargo in the ship's mass.
Jason Hood, 31 December, 2010.
When the mass of the ship is wanted, this plugin will include the mass of all
the equipment and cargo, affecting the handling of the ship (NPCs included, so
those trains with six-figure cargos are quite sluggish). Note that vanilla
gives most equipment a mass of 10, with goods having the default mass of 1.
Copy EquipMass.dll to your EXE directory and add it to the [Libraries]
sections of dacom.ini & dacomsrv.ini. Requires version 1.1 of common.dll.
v1.01, 17 September, 2012:
- fixed mass increase after a jump (in SP).
*/
#include "common.h"
#include <map>
#define NAKED __declspec( naked )
#define STDCALL __stdcall
#define ADDR_MASS ((PDWORD)(0x639c098)) // CShip::get_mass
DWORD dummy;
#define ProtectX( addr, size ) \
VirtualProtect( addr, size, PAGE_EXECUTE_READWRITE, &dummy )
#define NEWABS( from, to, prev ) \
prev = *(PDWORD)(from); \
*(PDWORD)(from) = (DWORD)to
char* cobject;
float Get_Equip_Mass()
{
CEquipManager* em = (CEquipManager*)(cobject+0xE4);
CEquipTraverser et;
CEquip* equip;
float mass = 0;
while ((equip = em->Traverse( et )) != 0)
{
if (equip->type != 0x10000)
mass += equip->archetype->mass;
}
return mass;
}
DWORD Mass_Org;
NAKED
void Mass_Hook()
{
__asm {
mov cobject, ecx
call Mass_Org
cmp dword ptr [esp], 0x54a9ed // is the call from Freelancer?
je done // yes, need to keep the original mass
cmp word ptr [esp], 0xe898 // likewise if from Server
je done
push edx // that's lucky
call Get_Equip_Mass
pop edx
fadd
fld st // update the reciprocal in the physics data
fld1 // fortunately, it looks like mass is always
fdivr // used before the reciprocal
fstp [edx+0x40]
done:
ret
}
}
void Patch()
{
ProtectX( ADDR_MASS, 4 );
NEWABS( ADDR_MASS, Mass_Hook, Mass_Org );
}
BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
{
if (fdwReason == DLL_PROCESS_ATTACH)
Patch();
return TRUE;
}