Debian Codegraph @

Descent3/DllWrappers.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <cstdarg>
20 #include <cstdio>
21
22 #include "DllWrappers.h"
23 #include "pserror.h"
24 #include "cfile.h"
25 #include "gamefont.h"
26 #include "grdefs.h"
27 #include "descent.h"
28 #include "ddio.h"
29 #include "d3movie.h"
30 #include "program.h"
31 #include "object.h"
32 #include "objinit.h"
33 #include "player.h"
34 #include "newui.h"
35 #include "hlsoundlib.h"
36 #include "appdatabase.h"
37 #include "attach.h"
38 #include "game.h"
39 #include "demofile.h"
40 #include "pilot.h"
41 #include "audiotaunts.h"
42 #include "ship.h"
43 #include "hud.h"
44 #include "cockpit.h"
45
46 int D3W_Play3dSound(int sound_index, object *cur_obj, float volume, int flags) {
47 if (Demo_flags == DF_RECORDING) {
48 DemoWrite3DSound(sound_index, OBJNUM(cur_obj), 1, volume);
49 }
50
51 return Sound_system.Play3dSound(sound_index, cur_obj, volume, flags);
52 }
53
54 int D3W_Play2dSound(int sound_index, float volume) {
55 if (Demo_flags == DF_RECORDING) {
56 DemoWrite2DSound(sound_index, volume);
57 }
58
59 return Sound_system.Play2dSound(sound_index, volume);
60 }
61
62 void D3W_TouchSound(int sound_index) { Sound_system.CheckAndForceSoundDataAlloc(sound_index); }
63
64 // Inventory CheckItem wrapper
65 bool InvCheckItem(int playernum, int type, int id) {
66 ASSERT((playernum >= 0) && (playernum < MAX_PLAYERS));
67
68 return Players[playernum].inventory.CheckItem(type, id);
69 }
70
71 // Inventory AddItemTypeID wrapper
72 bool InvAddTypeID(int playernum, int type, int id, int aux_type, int aux_id, int flags, const char *description) {
73 ASSERT((playernum >= 0) && (playernum < MAX_PLAYERS));
74
75 return Players[playernum].inventory.Add(type, id, &Objects[Players[playernum].objnum], aux_type, aux_id, flags, description);
76 }
77
78 // Inventory Remove wrapper
79 bool InvRemove(int playernum, int type, int id) {
80 ASSERT((playernum >= 0) && (playernum < MAX_PLAYERS));
81
82 return Players[playernum].inventory.Remove(type, id);
83 }
84
85 // Inventory GetTypeIDCount wrapper
86 int InvGetTypeIDCount(int playernum, int type, int id) {
87 ASSERT((playernum >= 0) && (playernum < MAX_PLAYERS));
88
89 return Players[playernum].inventory.GetTypeIDCount(type, id);
90 }
91
92 // Inventory Reset wrapper
93 void InvReset(int playernum, bool reset_all) {
94 ASSERT((playernum >= 0) && (playernum < MAX_PLAYERS));
95
96 Players[playernum].inventory.Reset(true, (reset_all) ? INVRESET_ALL : INVRESET_DEATHSPEW);
97 }
98
99 // mprintf
100 void MonoPrintf(int n, char *format, ...) {}
101
102 // wrapper for cfopen
103 void OpenCFILE(CFILE **handle, const std::filesystem::path &filename, const char *mode) {
104 *handle = cfopen(filename, mode);
105 }
106
107 // wrapper for ObjGetUltimateParent
108 void GetUltimateParentForObject(object **parent, object *child) { *parent = ObjGetUltimateParent(child); }
109
110 void SetObjectDeadFlagDLL(object *obj, bool tell_clients_to_remove, bool tell_clients_to_play_sound) {
111 SetObjectDeadFlag(obj, tell_clients_to_remove, tell_clients_to_play_sound);
112 }
113
114 void assertdll(int x, const char *expression, const char *file, int line) {
115 #ifndef RELEASE
116 if (!(unsigned)(x)) {
117 mprintf(0, "Assertion failed (%s) in %s line %d.\n", expression, file, line);
118 if (Debug_break)
119 DEBUG_BREAK();
120 else
121 AssertionFailed(expression, file, line);
122 }
123 #endif
124 }
125
126 void RetrieveUICallback(void **fn) { *fn = (void *)GetUICallback(); }
127
128 bool dDatabaseRead1(const char *label, char *entry, int *entrylen) { return Database->read(label, entry, entrylen); }
129
130 bool dDatabaseRead2(const char *label, void *entry, int wordsize) { return Database->read(label, entry, wordsize); }
131
132 bool dDatabaseRead3(const char *label, bool *entry) { return Database->read(label, entry); }
133
134 bool dDatabaseWrite1(const char *label, const char *entry, int entrylen) {
135 return Database->write(label, entry, entrylen);
136 }
137
138 bool dDatabaseWrite2(const char *label, int entry) { return Database->write(label, entry); }
139
140 // Attaches 2 objects via attach points on each. The f_used_aligned allows for an aligned connection.
141 // NOTE: The child always moves to the parent
142 bool dAttachObject(object *parent, char parent_ap, object *child, char child_ap, bool f_use_aligned) {
143 return AttachObject(parent, parent_ap, child, child_ap, f_use_aligned);
144 }
145
146 // Attaches a child object to a parent object by a percent of the radius of the child.
147 // NOTE: The child always moves to the parent and not the reverse
148 bool dAttachObjectRadius(object *parent, char parent_ap, object *child, float percent_rad) {
149 return AttachObject(parent, parent_ap, child, percent_rad);
150 }
151
152 // Unattaches a child from an attach point
153 bool dUnattachChild(object *parent, char parent_ap) { return UnattachChild(parent, parent_ap); }
154
155 // Unattaches an object from its parent
156 bool dUnattachFromParent(object *child) { return UnattachFromParent(child); }
157
158 // Unattaches all children from a parent object
159 bool dUnattachChildren(object *parent) { return UnattachChildren(parent); }
160
161 bool dObjGet(int handle, object **obj) {
162 *obj = ObjGet(handle);
163 return (*obj) ? true : false;
164 }
165
166 // Set a vector to {0,0,0}
167 void dvm_MakeZeroVector(vector *v) { vm_MakeZero(v); }
168
169 void dvm_MakeZeroAngle(angvec *v) { vm_MakeZero(v); }
170
171 void dStartFrame(int x, int y, int x2, int y2, bool clear) { StartFrame(x, y, x2, y2, clear); }
172
173 // ObjSetPos, that automatically sets the OF_MOVED_THIS_FRAME
174 void ObjSetPosAndMarkMoved(object *obj, vector *pos, int roomnum, matrix *orient, bool f_update_attached_children) {
175 if (obj) {
176 ObjSetPos(obj, pos, roomnum, orient, f_update_attached_children);
177 if (Demo_flags == DF_RECORDING)
178 DemoWriteChangedObj(obj); // using this instead of setting the flag, since the flag
179 // has a good chance of getting cleared before it is
180 // written
181 // obj->flags |= OF_MOVED_THIS_FRAME;
182 }
183 }
184
185 // SetObjectDeadFlag that automatically writes out demo data
186 void dSetObjectDeadFlagWDemo(object *obj, bool tell_clients_to_remove, bool tell_clients_to_play_sound) {
187 if (Demo_flags == DF_RECORDING) {
188 DemoWriteSetObjDead(obj);
189 }
190
191 SetObjectDeadFlag(obj, tell_clients_to_remove, tell_clients_to_play_sound);
192 }
193
194 void dSetAudioTaunts(bool enable) {
195 // If the F6 menu can make perm changes, uncomment the next two lines (and comment the 3rd)
196 // Current_pilot.set_audiotaunts(enable);
197 // PltWriteFile(&Current_pilot,false);
198
199 // Leave this line uncommented for non-perm changes
200 taunt_Enable(enable);
201 }
202
203 // Changes the ship_index for a given player
204 void ChangePlayerShipIndex(int pnum, int ship_index) {
205 int ObjInitTypeSpecific(object * objp, bool reinitializing);
206
207 if (pnum < 0 || pnum >= MAX_PLAYERS)
208 return;
209 if (Players[pnum].start_roomnum == -1)
210 return; // this player doesn't exist
211 if (ship_index < 0 || ship_index >= MAX_SHIPS)
212 return;
213 if (!Ships[ship_index].used)
214 return;
215
216 bool isme = (pnum == Player_num) ? true : false;
217
218 if (isme) {
219 FreeCockpit();
220 CloseShipHUD();
221 }
222
223 PlayerChangeShip(pnum, ship_index);
224
225 // reset physics, model, etc.
226 ObjInitTypeSpecific(&Objects[Players[pnum].objnum], 0);
227
228 if (isme) {
229 InitShipHUD(Players[pnum].ship_index);
230 InitCockpit(Players[pnum].ship_index);
231
232 if (GetHUDMode() == HUD_COCKPIT)
233 SetHUDMode(HUD_COCKPIT);
234 else if (GetHUDMode() == HUD_FULLSCREEN)
235 SetHUDMode(HUD_FULLSCREEN);
236 }
237 }
238
239 ///////////////////////////////////////////////////////////////////
240 // adds a type/id item to the inventory (returns true on success)
241 bool dInven_Add(Inventory *inven, int type, int id, object *parent, int aux_type, int aux_id, int flags,
242 char *description) {
243 return inven->Add(type, id, parent, aux_type, aux_id, flags, description);
244 }
245
246 // adds an object to the inventory (marked by it's objhandle)
247 bool dInven_AddObject(Inventory *inven, int object_handle, int flags, char *description) {
248 return inven->AddObject(object_handle, flags, description);
249 }
250
251 // adds a special cased CounterMeasure into the inventory
252 bool dInven_AddCounterMeasure(Inventory *inven, int id, int aux_type, int aux_id, int flags, char *description) {
253 return inven->AddCounterMeasure(id, aux_type, aux_id, flags, description);
254 }
255
256 // removes an item from the inventory (reduces it's count by one...if there is no more, then it goes bye-bye)
257 // to remove an object that was added via objhandle, then pass the objhandle
258 // in the 'type' parameter, and don't pass in an id.
259 bool dInven_Remove(Inventory *inven, int type, int id) { return inven->Remove(type, id); }
260
261 // uses an item in the inventory (also reduces its count by one...if there is no more, then it goes bye-bye)
262 bool dInven_Use(Inventory *inven, int type, int id, object *parent) { return inven->Use(type, id, parent); }
263
264 // uses an item in the inventory (given it's objhandle).
265 bool dInven_UseObjHandle(Inventory *inven, int objhandle, object *parent) { return inven->Use(objhandle, parent); }
266
267 // returns how many unique type/ids are in the inventory
268 int dInven_Size(Inventory *inven) { return inven->Size(); }
269
270 // returns true if there is an item in the inventory with the given type/id (or objhandle if id is -1, pass the object
271 // handle as the type parameter)
272 bool dInven_CheckItem(Inventory *inven, int type, int id) { return inven->CheckItem(type, id); }
273
274 // Resets the inventory, cleaning it out
275 // in_game: set to true if this is being called from during gameplay
276 // reset_stage:
277 // INVRESET_ALL: Reset _EVERYTHING_
278 // INVRESET_LEVELCHANGE: Remove everything except those that last across levels
279 // INVRESET_DEATHSPEW: Remove everything except those that do not spew (Default)
280 void dInven_Reset(Inventory *inven, bool in_game, int reset_stage) { inven->Reset(in_game, reset_stage); }
281
282 // resets the position pointer in the list to the beginning
283 void dInven_ResetPos(Inventory *inven) { inven->ResetPos(); }
284
285 // moves the position pointer to the next inventory item
286 // skip : if true then skip over non-selectable items
287 void dInven_NextPos(Inventory *inven, bool skip) { inven->NextPos(skip); }
288
289 // moves the position pointer to the previous inventory item
290 // skip : if true then skip over non-selectable items
291 void dInven_PrevPos(Inventory *inven, bool skip) { inven->PrevPos(skip); }
292
293 // returns the type/id of the item at the current position
294 // return true if it is a real object (meaning it was placed in the inventory
295 // via an object handle...so id will be -1)
296 bool dInven_GetPosTypeID(Inventory *inven, int &type, int &id) { return inven->GetPosTypeID(type, id); }
297
298 // returns the aux type/id of the item
299 // return true if it is a real object (meaning it was placed in the inventory
300 // via an object handle...so id will be -1)
301 bool dInven_GetAuxPosTypeID(Inventory *inven, int &type, int &id) { return inven->GetAuxPosTypeID(type, id); }
302
303 // returns the description of the item at the current position
304 char *dInven_GetPosDescription(Inventory *inven) { return inven->GetPosDescription(); }
305
306 // returns the icon name of the item at the current position
307 char *dInven_GetPosIconName(Inventory *inven) { return inven->GetPosIconName(); }
308
309 // returns the name of the item at the current position
310 char *dInven_GetPosName(Inventory *inven) { return inven->GetPosName(); }
311
312 // return information about the current position item
313 // return true if it is a real object
314 bool dInven_GetPosInfo(Inventory *inven, uint16_t &iflags, int &flags) { return inven->GetPosInfo(iflags, flags); }
315
316 // returns the count of the item at the current position
317 int dInven_GetPosCount(Inventory *inven) { return inven->GetPosCount(); }
318
319 // returns true if the position pointer is at the begining of the inventory list
320 bool dInven_AtBeginning(Inventory *inven) { return inven->AtBeginning(); }
321
322 // returns false if the position pointer is at the end of the inventory list
323 bool dInven_AtEnd(Inventory *inven) { return inven->AtEnd(); }
324
325 // jump right to an item in the inventory
326 void dInven_GotoPos(Inventory *inven, int newpos) { inven->GotoPos(newpos); }
327
328 // jump right to an item in the inventory give it's type and id
329 // to jump to an item that was added via object handle, pass the object
330 // handle in as the type, and make id -1.
331 void dInven_GotoPosTypeID(Inventory *inven, int type, int id) { inven->GotoPos(type, id); }
332
333 // uses the currently selected item
334 bool dInven_UsePos(Inventory *inven, object *parent) { return inven->UsePos(parent); }
335
336 // returns the 'index' position of the current position
337 int dInven_GetPos(Inventory *inven) { return inven->GetPos(); }
338
339 // checks the pos, if its on a nonselectable item it will move to the next selectable (NULL if none)
340 void dInven_ValidatePos(Inventory *inven, bool forward) { inven->ValidatePos(forward); }
341
342 // returns whether an item is selectable
343 bool dInven_IsSelectable(Inventory *inven) { return inven->IsSelectable(); }
344
345 bool dInven_IsUsable(Inventory *inven) { return inven->IsUsable(); }
346
347 // returns how many of an type/id is in the inventory
348 // for object handle items, pass the object handle in as the type and leave
349 // id as -1
350 int dInven_GetTypeIDCount(Inventory *inven, int type, int id) { return inven->GetTypeIDCount(type, id); }
351
352 // searches the inventory for the specified type/id, sets the pos to it
353 // for object handle items, pass the object handle in as the type and leave
354 // id as -1
355 bool dInven_FindPos(Inventory *inven, int type, int id) { return inven->FindPos(type, id); }
356
357 // gets a detailed list of information about what is in the inventory
358 // returns the number of items filled in.
359 int dInven_GetInventoryItemList(Inventory *inven, tInvenList *list, int max_amount, int *cur_sel) {
360 return inven->GetInventoryItemList(list, max_amount, cur_sel);
361 }