forked from Phobos-developers/YRpp
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLocomotionClass.h
More file actions
221 lines (193 loc) · 7.75 KB
/
LocomotionClass.h
File metadata and controls
221 lines (193 loc) · 7.75 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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#pragma once
#include <Interfaces.h>
#include <FootClass.h>
#include <Unsorted.h>
#include <YRCom.h>
#include <Drawing.h>
#include <Helpers/ComPtr.h>
#include <Helpers/CompileTime.h>
class LocomotionClass : public IPersistStream, public ILocomotion
{
public:
class CLSIDs
{
public:
static constexpr reference<CLSID const, 0x7E9A30u> const Drive {};
static constexpr reference<CLSID const, 0x7E9A40u> const Hover {};
static constexpr reference<CLSID const, 0x7E9A50u> const Tunnel {};
static constexpr reference<CLSID const, 0x7E9A60u> const Walk {};
static constexpr reference<CLSID const, 0x7E9A70u> const Droppod {};
static constexpr reference<CLSID const, 0x7E9A80u> const Fly {};
static constexpr reference<CLSID const, 0x7E9A90u> const Teleport {};
static constexpr reference<CLSID const, 0x7E9AA0u> const Mech {};
static constexpr reference<CLSID const, 0x7E9AB0u> const Ship {};
static constexpr reference<CLSID const, 0x7E9AC0u> const Jumpjet {};
static constexpr reference<CLSID const, 0x7E9AD0u> const Rocket {};
};
//IUnknown
virtual HRESULT __stdcall QueryInterface(REFIID iid, void** ppvObject) R0;
virtual ULONG __stdcall AddRef() R0;
virtual ULONG __stdcall Release() R0;
//IPersist
virtual HRESULT __stdcall GetClassID(CLSID* pClassID) R0;
//IPersistStream
virtual HRESULT __stdcall IsDirty() R0;
virtual HRESULT __stdcall Load(IStream* pStm) R0;
virtual HRESULT __stdcall Save(IStream* pStm, BOOL fClearDirty) R0;
virtual HRESULT __stdcall GetSizeMax(ULARGE_INTEGER* pcbSize) R0;
virtual ~LocomotionClass() RX; // should be SDDTOR in fact
virtual int Size() R0;
// ILocomotion
// virtual HRESULT __stdcall QueryInterface(REFIID iid, void** ppvObject) R0;
// virtual ULONG __stdcall AddRef() R0;
// virtual ULONG __stdcall Release() R0;
virtual HRESULT __stdcall Link_To_Object(void* pointer) R0;
virtual bool __stdcall Is_Moving() R0;
virtual CoordStruct* __stdcall Destination(CoordStruct* pcoord) R0;
virtual CoordStruct* __stdcall Head_To_Coord(CoordStruct* pcoord) R0;
virtual Move __stdcall Can_Enter_Cell(CellStruct cell) RT(Move);
virtual bool __stdcall Is_To_Have_Shadow() R0;
virtual Matrix3D __stdcall Draw_Matrix(VoxelIndexKey* pIndex) RT(Matrix3D);
virtual Matrix3D __stdcall Shadow_Matrix(VoxelIndexKey* pIndex) RT(Matrix3D);
virtual Point2D* __stdcall Draw_Point(Point2D* pPoint) R0;
virtual Point2D* __stdcall Shadow_Point(Point2D* pPoint) R0;
virtual VisualType __stdcall Visual_Character(VARIANT_BOOL unused) RT(VisualType);
virtual int __stdcall Z_Adjust() R0;
virtual ZGradient __stdcall Z_Gradient() RT(ZGradient);
virtual bool __stdcall Process() R0;
virtual void __stdcall Move_To(CoordStruct to) RX;
virtual void __stdcall Stop_Moving() RX;
virtual void __stdcall Do_Turn(DirStruct coord) RX;
virtual void __stdcall Unlimbo() RX;
virtual void __stdcall Tilt_Pitch_AI() RX;
virtual bool __stdcall Power_On() R0;
virtual bool __stdcall Power_Off() R0;
virtual bool __stdcall Is_Powered() R0;
virtual bool __stdcall Is_Ion_Sensitive() R0;
virtual bool __stdcall Push(DirStruct dir) R0;
virtual bool __stdcall Shove(DirStruct dir) R0;
virtual void __stdcall Force_Track(int track, CoordStruct coord) RX;
virtual Layer __stdcall In_Which_Layer() RT(Layer);
virtual void __stdcall Force_Immediate_Destination(CoordStruct coord) RX;
virtual void __stdcall Force_New_Slope(int ramp) RX;
virtual bool __stdcall Is_Moving_Now() R0;
virtual int __stdcall Apparent_Speed() R0;
virtual int __stdcall Drawing_Code() R0;
virtual FireError __stdcall Can_Fire() RT(FireError);
virtual int __stdcall Get_Status() R0;
virtual void __stdcall Acquire_Hunter_Seeker_Target() RX;
virtual bool __stdcall Is_Surfacing() R0;
virtual void __stdcall Mark_All_Occupation_Bits(int mark) RX;
virtual bool __stdcall Is_Moving_Here(CoordStruct to) R0;
virtual bool __stdcall Will_Jump_Tracks() R0;
virtual bool __stdcall Is_Really_Moving_Now() R0;
virtual void __stdcall Stop_Movement_Animation() RX;
virtual void __stdcall Clear_Coords() RX;
virtual void __stdcall Lock() RX;
virtual void __stdcall Unlock() RX;
virtual int __stdcall Get_Track_Number() R0;
virtual int __stdcall Get_Track_Index() R0;
virtual int __stdcall Get_Speed_Accum() R0;
// Non virtuals
static HRESULT TryPiggyback(IPiggyback** Piggy, ILocomotion** Loco)
{ PUSH_VAR32(Loco); SET_REG32(ECX, Piggy); CALL(0x45AF20); }
static HRESULT CreateInstance(ILocomotion** ppv, const CLSID* rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext)
{ PUSH_VAR32(dwClsContext); PUSH_VAR32(pUnkOuter); PUSH_VAR32(rclsid); SET_REG32(ECX, ppv); CALL(0x41C250); }
// these two are identical, why do they both exist...
static void AddRef1(LocomotionClass** Loco)
{ SET_REG32(ECX, Loco); CALL(0x45A170); }
static void AddRef2(LocomotionClass** Loco)
{ SET_REG32(ECX, Loco); CALL(0x6CE270); }
static void ChangeLocomotorTo(FootClass* Object, const CLSID& clsid)
{
// remember the current one
YRComPtr<ILocomotion> Original(Object->Locomotor);
// create a new locomotor and link it
auto NewLoco = CreateInstance(clsid);
NewLoco->Link_To_Object(Object);
// get piggy interface and piggy original
YRComPtr<IPiggyback> Piggy(NewLoco);
Piggy->Begin_Piggyback(Original.get());
// replace the current locomotor
Object->Locomotor = std::move(NewLoco);
}
// creates a new instance by class ID. returns a pointer to ILocomotion
static YRComPtr<ILocomotion> CreateInstance(const CLSID& rclsid)
{
return YRComPtr<ILocomotion>(rclsid, nullptr,
CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER);
}
// finds out whether a locomotor is currently piggybacking and restores
// the original locomotor. this function ignores Is_Ok_To_End().
static bool End_Piggyback(YRComPtr<ILocomotion>& pLoco)
{
if (!pLoco)
{
Game::RaiseError(E_POINTER);
}
if (YRComPtr<IPiggyback> pPiggy = pLoco)
{
if (pPiggy->Is_Piggybacking())
{
// this frees the current locomotor
pLoco.reset(nullptr);
// this restores the old one
auto res = pPiggy->End_Piggyback(pLoco.pointer_to());
if (FAILED(res))
{
Game::RaiseError(res);
}
return (res == S_OK);
}
}
return false;
}
//Constructors
LocomotionClass(LocomotionClass& another) { JMP_THIS(0x55A6C0); }
protected:
explicit __forceinline LocomotionClass(noinit_t) noexcept
{
}
//Properties
public:
FootClass* Owner;
FootClass* LinkedTo;
bool Powered;
bool Dirty;
int RefCount;
};
template<typename T>
concept LocoHasILocoVtbl = std::is_base_of_v<LocomotionClass, std::remove_cvref_t<T>> && requires
{
{ T::ILocoVTable }->std::convertible_to<uintptr_t>;
};
template<typename T>
concept LocoHasClassGUID = std::is_base_of_v<LocomotionClass, std::remove_cvref_t<T>> &&
std::is_same_v<std::remove_reference_t<decltype(T::ClassGUID.get())>, CLSID const>;
template <typename T>
__forceinline T locomotion_cast(ILocomotion* iLoco)
{
using Base = std::remove_cvref_t<std::remove_const_t<std::remove_pointer_t<T>>>;
static_assert(std::is_base_of_v<LocomotionClass, Base> && !std::is_same_v<LocomotionClass, Base>,
"T needs to point to a class derived from LocomotionClass");
if constexpr (LocoHasILocoVtbl<Base>)
{
return VTable::Get(iLoco) == Base::ILocoVTable ? static_cast<T>(iLoco) : nullptr;
}
else if constexpr (LocoHasClassGUID<Base>)
{
CLSID locoCLSID;
return (SUCCEEDED(static_cast<LocomotionClass*>(iLoco)->GetClassID(&locoCLSID)) && locoCLSID == Base::ClassGUID()) ?
static_cast<T>(iLoco) : nullptr;
}
else
static_assert(false, "Cannot Use locomotion_cast here yet");
}
template<typename T>
__forceinline T locomotion_cast(YRComPtr<ILocomotion>& comLoco)
{
using Base = std::remove_const_t<std::remove_pointer_t<T>>;
static_assert(std::is_base_of<LocomotionClass, Base>::value,
"locomotion_cast: T is required to be a sub-class of LocomotionClass.");
return locomotion_cast<T>(comLoco.get());
}