-
Notifications
You must be signed in to change notification settings - Fork 2
/
world_engine.d
174 lines (132 loc) · 5.5 KB
/
world_engine.d
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
func string oCWorld_GetWorldFilename () {
//0x0063B680 public: class zSTRING __thiscall oCWorld::GetWorldFilename(void)
const int oCWorld__GetWorldFilename_G1 = 6534784;
//0x0068DE60 public: class zSTRING __thiscall oCWorld::GetWorldFilename(void)
const int oCWorld__GetWorldFilename_G2 = 6872672;
CALL_RetValIszString ();
CALL__thiscall (_@(MEM_World), MEMINT_SwitchG1G2 (oCWorld__GetWorldFilename_G1, oCWorld__GetWorldFilename_G2));
return CALL_RetValAszstring ();
};
func void zCWorld_RemoveVob (var int vobPtr) {
//0x006D6EF0 public: virtual void __thiscall oCWorld::RemoveVob(class zCVob *)
const int oCWorld__RemoveVob_G1 = 7171824;
//0x007800C0 public: virtual void __thiscall oCWorld::RemoveVob(class zCVob *)
const int oCWorld__RemoveVob_G2 = 7864512;
if (!vobPtr) { return; };
var int worldPtr; worldPtr = _@ (MEM_World);
const int call = 0;
if (CALL_Begin(call)) {
CALL_PtrParam (_@ (vobPtr));
CALL__thiscall (_@ (worldPtr), MEMINT_SwitchG1G2 (oCWorld__RemoveVob_G1, oCWorld__RemoveVob_G2));
call = CALL_End ();
};
};
/*
* Author: Mud-freak
*/
func int oCWorld_AddVobAsChild (var int vobPtr, var int parentPtr) {
//0x006D6CA0 public: virtual class zCTree<class zCVob> * __thiscall oCWorld::AddVobAsChild(class zCVob *,class zCTree<class zCVob> *)
//const int oCWorld__AddVobAsChild_G1 = 7171232;
//0x0077FE30 public: virtual class zCTree<class zCVob> * __thiscall oCWorld::AddVobAsChild(class zCVob *,class zCTree<class zCVob> *)
//const int oCWorld__AddVobAsChild_G2 = 7863856;
if (!vobPtr) {
return 0;
};
// Adjust bits
var zCVob vob; vob = _^(vobPtr);
// vob.bitfield[0] = vob.bitfield[0] & (-67108865); //0xFBFFFFFF
// vob.bitfield[0] = vob.bitfield[0] & ~zCVob_bitfield0_collDetectionStatic & ~zCVob_bitfield0_collDetectionDynamic;
// Get parent vob tree
var int vobTreePtr;
if (parentPtr) {
var zCVob parent; parent = _^(parentPtr);
vobTreePtr = parent.globalVobTreeNode;
} else {
vobTreePtr = _@(MEM_Vobtree); // Global vob tree
};
// Insert into world
const int oCWorld__AddVobAsChild_G1 = 7171232; //0x6D6CA0
const int oCWorld__AddVobAsChild_G2 = 7863856; //0x77FE30
var int worldPtr; worldPtr = MEM_Game._zCSession_world;
const int call = 0;
if (CALL_Begin(call)) {
CALL_PutRetValTo(0);
CALL_PtrParam(_@(vobTreePtr));
CALL_PtrParam(_@(vobPtr));
CALL__thiscall(_@(worldPtr), MEMINT_SwitchG1G2(oCWorld__AddVobAsChild_G1, oCWorld__AddVobAsChild_G2));
call = CALL_End();
};
//return vobPtr;
// Set bits
//vob.bitfield[0] = vob.bitfield[0] | zCVob_bitfield0_collDetectionStatic | zCVob_bitfield0_collDetectionDynamic;
//vob.bitfield[2] = vob.bitfield[2] & ~zCVob_bitfield2_sleepingMode; // zCVob::SetSleeping(vobPtr, 1);
// Decrease reference counter... why is that necessary?
vob._zCObject_refCtr -= 1;
if (vob._zCObject_refCtr <= 0) {
const int _scalar_deleting_destructor_offset = 12; // Same for G1 and G2
CALL_IntParam(1);
CALL__thiscall(vobPtr, MEM_ReadInt(vob._vtbl+_scalar_deleting_destructor_offset));
};
return vobPtr;
};
/*
* zCWorld_TraceRayFirstHit
*/
func int zCWorld_TraceRayFirstHit (var int posPtr, var int dirPtr, var int ignoreListPtr, var int flags) {
//0x005F40C0 public: int __fastcall zCWorld::TraceRayFirstHit(class zVEC3 const &,class zVEC3 const &,class zCArray<class zCVob *> const *,int)
const int zCWorld__TraceRayFirstHit_G1 = 6242496;
//0x00621960 public: int __fastcall zCWorld::TraceRayFirstHit(class zVEC3 const &,class zVEC3 const &,class zCArray<class zCVob *> const *,int)
const int zCWorld__TraceRayFirstHit_G2 = 6429024;
var int worldPtr; worldPtr = MEM_Game._zCSession_world;
if (!posPtr) { return 0; };
if (!dirPtr) { return 0; };
if (!worldPtr) { return 0; };
var int retVal;
const int call = 0;
if (CALL_Begin(call)) {
CALL_IntParam(_@(flags));
CALL_PtrParam(_@(ignoreListPtr));
CALL_PtrParam(_@(dirPtr));
CALL_PutRetValTo (_@ (retVal));
CALL__fastcall(_@(worldPtr), _@(posPtr), MEMINT_SwitchG1G2(zCWorld__TraceRayFirstHit_G1, zCWorld__TraceRayFirstHit_G2));
call = CALL_End();
};
return + retVal;
};
//0x0051EBE0 protected: void __fastcall zCBspBase::CollectVobsInBBox3D_I(class zCArray<class zCVob *> &,struct zTBBox3D const &)const
/*
* Wld_CollectVobsInBBox3D
*/
func int Wld_CollectVobsInBBox3D (var int posPtr, var int bboxPtr) {
//0x0051E7C0 public: void __fastcall zCBspBase::CollectVobsInBBox3D(class zCArray<class zCVob *> &,struct zTBBox3D const &)const
const int zCBspBase__CollectVobsInBBox3D_G1 = 5367744;
//0x00531110 public: void __fastcall zCBspBase::CollectVobsInBBox3D(class zCArray<class zCVob *> &,struct zTBBox3D const &)const
const int zCBspBase__CollectVobsInBBox3D_G2 = 5443856;
var int bspRoot; bspRoot = MEM_World.bspTree_bspRoot;
if (!bspRoot) { return 0; };
//Create array
var int arrPtr; arrPtr = MEM_ArrayCreate ();
const int call = 0;
if (CALL_Begin (call)) {
CALL_PtrParam (_@ (bboxPtr));
CALL__fastcall (_@ (bspRoot), _@ (arrPtr), MEMINT_SwitchG1G2 (zCBspBase__CollectVobsInBBox3D_G1, zCBspBase__CollectVobsInBBox3D_G2));
call = CALL_End();
};
return + arrPtr;
};
/*
* Wld_CollectVobsInRange
*/
func int Wld_CollectVobsInRange (var int posPtr, var int rangeF) {
var int bbox[6]; //zTBBox3D
if (!posPtr) { return 0; };
MEM_CopyBytes (posPtr, _@ (bbox), 12);
MEM_CopyBytes (_@ (bbox), _@ (bbox) + 12, 12);
bbox[0] = subf (bbox[0], rangeF);
bbox[1] = subf (bbox[1], rangeF);
bbox[2] = subf (bbox[2], rangeF);
bbox[3] = addf (bbox[3], rangeF);
bbox[4] = addf (bbox[4], rangeF);
bbox[5] = addf (bbox[5], rangeF);
return + Wld_CollectVobsInBBox3D (posPtr, _@ (bbox));
};