aboutsummaryrefslogtreecommitdiff
path: root/engines/voyeur/files.h
blob: c445afdbb674de1d3689161a8f6056aab01fc11d (plain)
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#ifndef VOYEUR_FILES_H
#define VOYEUR_FILES_H

#include "common/scummsys.h"
#include "common/file.h"
#include "common/rect.h"
#include "common/str.h"
#include "voyeur/graphics.h"

namespace Voyeur {

class VoyeurEngine;
class BoltFile;
class BoltGroup;
class BoltEntry;
class RectResource;
class PictureResource;
class ViewPortResource;
class ViewPortListResource;
class FontResource;
class CMapResource;
class VInitCycleResource;
class PtrResource;
class ControlResource;
class StateResource;
class ThreadResource;

#define DECOMPRESS_SIZE 0x7000

class ResolveEntry {
public:
	uint32 _id;
	byte **_p;

	ResolveEntry(uint32 id, byte **p) { _id = id; _p = p; }
};

class BoltFilesState {
public:
	VoyeurEngine *_vm;
	BoltFile *_curLibPtr;
	BoltGroup *_curGroupPtr;
	BoltEntry *_curMemberPtr;
	int _bufferEnd;
	int _bufferBegin;
	int _bytesLeft;
	int _bufSize;
	byte *_bufStart;
	byte *_bufPos;
	byte _decompressBuf[DECOMPRESS_SIZE];
	int _historyIndex;
	byte _historyBuffer[0x200];
	int _runLength;
	bool _decompState;
	int _runType;
	int _runValue;
	int _runOffset;
	Common::File *_curFd;
	Common::Array<ResolveEntry> _resolves;

	byte *_boltPageFrame;
public:
	BoltFilesState();

	byte *decompress(byte *buf, int size, int mode);
	void nextBlock();
};

class BoltFile {
private:
	Common::Array<BoltGroup> _groups;
protected:
	BoltFilesState &_state;

	virtual void initResource(int resType) = 0;
	void initDefault();
private:
	void resolveAll();
	byte *getBoltMember(uint32 id);

public:
	Common::File _file;

	BoltFile(const Common::String &filename, BoltFilesState &state);
	virtual ~BoltFile();

	BoltGroup *getBoltGroup(uint16 id, bool process = true);
	void freeBoltGroup(uint16 id, bool freeEntries = true);
	void freeBoltMember(uint32 id);
	byte *memberAddr(uint32 id);
	byte *memberAddrOffset(uint32 id);
	void resolveIt(uint32 id, byte **p);
	void resolveFunction(uint32 id, GraphicMethodPtr *fn);

	BoltEntry &boltEntry(uint16 id); 
	BoltEntry &getBoltEntryFromLong(uint32 id);
	PictureResource *getPictureResource(uint32 id);
	CMapResource *getCMapResource(uint32 id);
};

class BVoyBoltFile: public BoltFile {
private:
	// initType method table
	void sInitRect();
	void sInitPic();
	void vInitCMap();
	void vInitCycl();
	void initViewPort();
	void initViewPortList();
	void initFontInfo();
	void initFont();
	void initSoundMap();
protected:
	virtual void initResource(int resType);
public:
	BVoyBoltFile(BoltFilesState &state);
};

class StampBoltFile: public BoltFile {
private:
	void initThread();
	void initState();
	void initPtr();
	void initControl();
protected:
	virtual void initResource(int resType);
public:
	StampBoltFile(BoltFilesState &state);
};

class BoltGroup {
private:
	Common::SeekableReadStream *_file;
public:
	bool _loaded;
	bool _processed;
	int _count;
	int _fileOffset;
	Common::Array<BoltEntry> _entries;
public:
	BoltGroup(Common::SeekableReadStream *f); 
	virtual ~BoltGroup();

	void load(uint16 groupId);
	void unload();
};


class BoltEntry {
private:
	Common::SeekableReadStream *_file;
public:
	uint16 _id;
	byte _mode;
	byte _initMethod;
	int _fileOffset;
	int _size;
	byte *_data;

	// bvoy.blt resource types
	RectResource *_rectResource;
	PictureResource *_picResource;
	ViewPortResource *_viewPortResource;
	ViewPortListResource *_viewPortListResource;
	FontResource *_fontResource;
	FontInfoResource *_fontInfoResource;
	CMapResource *_cMapResource;
	VInitCycleResource *_vInitCycleResource;

	// stampblt.blt resource types
	PtrResource *_ptrResource;
	ControlResource *_controlResource;
	StateResource *_stateResource;
	ThreadResource *_threadResource;
public:
	BoltEntry(Common::SeekableReadStream *f, uint16 id);
	virtual ~BoltEntry();

	void load();
	bool hasResource() const;
};

class FilesManager {
public:
	BoltFilesState _boltFilesState;
	BoltFile *_curLibPtr;
public:
	FilesManager();
	void setVm(VoyeurEngine *vm) { _boltFilesState._vm = vm; }

	bool openBoltLib(const Common::String &filename, BoltFile *&boltFile);
	byte *fload(const Common::String &filename, int *size = NULL);
};

class RectEntry: public Common::Rect {
public:
	int _arrIndex;
	int _count;

	RectEntry(int x1, int y1, int x2, int y2, int arrIndex, int count);
};

class RectResource: public Common::Rect {
public:
	Common::Array<RectEntry> _entries;
public:
	RectResource(const byte *src, int size, bool isExtendedRects);
	RectResource(int xp, int yp, int width, int height);
	virtual ~RectResource() {}
};

enum DisplayFlag { DISPFLAG_1 = 1, DISPFLAG_2 = 2, DISPFLAG_4 = 4, DISPFLAG_8 = 8, 
	DISPFLAG_10 = 0x10, DISPFLAG_20 = 0x20, DISPFLAG_40 = 0x40, DISPFLAG_80 = 0x80,
	DISPFLAG_100 = 0x100, DISPFLAG_200 = 0x200, DISPFLAG_400 = 0x400, 
	DISPFLAG_800 = 0x800, DISPFLAG_1000 = 0x1000, DISPFLAG_2000 = 0x2000,
	DISPFLAG_4000 = 0x4000, DISPFLAG_VIEWPORT = 0x8000, DISPFLAG_CURSOR = 0x10000 };

class DisplayResource {
private:
	VoyeurEngine *_vm;
public:
	uint32 _flags;
public:
	DisplayResource();
	DisplayResource(VoyeurEngine *vm);

	/** 
	 * Fill a box of the given size at the current _drawPtr location
	 */
	void sFillBox(int width, int height);

	/**
	 * Draw text at the current pen position
	 */
	int drawText(const Common::String &msg);

	/**
	 * Return the width of a given text in the current font
	 */
	int textWidth(const Common::String &msg);

	/**
	 * Clip the given rectangle by the currently viewable area
	 */
	bool clipRect(Common::Rect &rect);
};

/* bvoy.blt resource types */

enum PictureFlag { PICFLAG_2 = 2, PICFLAG_PIC_OFFSET = 8, PICFLAG_CLEAR_SCREEN = 0x10, 
	PICFLAG_20 = 0x20, PICFLAG_HFLIP = 0x40, PICFLAG_VFLIP = 0x80, PICFLAG_100 = 0x100,
	PICFLAG_CLEAR_SCREEN00 = 0x1000 
};

class PictureResource: public DisplayResource {
private:
	/**
	 * Flip the image data horizontally
	 */
	void flipHorizontal(const byte *data);

	/**
	 * Flip the image data vertically
	 */
	void flipVertical(const byte *data);
public:
	byte _select;
	byte _pick;
	byte _onOff;
	Common::Rect _bounds;
	uint32 _maskData;
	uint _planeSize;

	/**
	 * Image data for the picture
	 */
	byte *_imgData;

	/**
	 * Flag to indicate whether to free the image data
	 */
	DisposeAfterUse::Flag _freeImgData;
public:
	PictureResource(BoltFilesState &state, const byte *src);
	PictureResource(int flags, int select, int pick, int onOff, 
		const Common::Rect &bounds, int maskData, byte *imgData, int planeSize);
	PictureResource(Graphics::Surface *surface);
	PictureResource();
	virtual ~PictureResource();
};

typedef void (ViewPortResource::*ViewPortMethodPtr)();

class ViewPortResource: public DisplayResource {
private:
	BoltFilesState &_state;
private:
	void setupViewPort(PictureResource *page, Common::Rect *clippingRect, ViewPortSetupPtr setupFn,
		ViewPortAddPtr addFn, ViewPortRestorePtr restoreFn);
public:
	ViewPortResource *_parent;
	int _pageCount;
	int _pageIndex;
	int _lastPage;
	Common::Rect _bounds;
	PictureResource *_currentPic;
	PictureResource *_activePage;
	PictureResource *_pages[2];

	// Rect lists and counts. Note that _rectListCount values of '-1' seem to have
	// special significance, which is why I'm not making them redundant in favor 
	// of the arrays' .size() method
	Common::Array<Common::Rect> *_rectListPtr[3];
	int _rectListCount[3];

	Common::Rect _clipRect;
	GraphicMethodPtr _fn1;
	ViewPortSetupPtr _setupFn;
	ViewPortAddPtr _addFn;
	ViewPortRestorePtr _restoreFn;
	Common::Rect _fontRect;
public:
	ViewPortResource(BoltFilesState &state, const byte *src);
	virtual ~ViewPortResource();

	void setupViewPort();
	void setupViewPort(PictureResource *pic, Common::Rect *clippingRect = NULL);
	void addSaveRect(int pageIndex, const Common::Rect &r);
	void fillPic(byte onOff = 0);
	void drawIfaceTime();
	void drawPicPerm(PictureResource *pic, const Common::Point &pt);
};

class ViewPortPalEntry  {
public:
	uint16 _rEntry, _gEntry, _bEntry;
	uint16 _rChange, _gChange, _bChange;
	uint16 _palIndex;
public:
	ViewPortPalEntry(const byte *src);
};

class ViewPortListResource {
public:
	Common::Array<ViewPortPalEntry> _palette;
	Common::Array<ViewPortResource *> _entries;
	int _palIndex;

	ViewPortListResource(BoltFilesState &state, const byte *src);
	virtual ~ViewPortListResource() {}
};

class FontResource {
public:
	int _minChar, _maxChar;
	int _fontDepth;
	int _padding;
	int _fontHeight;
	int _topPadding;
	int *_charWidth;
	byte *_charOffsets;
	byte *_charImages;

	FontResource(BoltFilesState &state, byte *src);
	virtual ~FontResource();
};

enum FontJustify { ALIGN_LEFT = 0, ALIGN_CENTER = 1, ALIGN_RIGHT = 2 };

class FontInfoResource {
public:
	FontResource *_curFont;
	byte _picFlags;
	byte _picSelect;
	byte _picPick;
	byte _picOnOff;
	byte _fontFlags;
	FontJustify _justify;
	int _fontSaveBack;
	Common::Point _pos;
	int _justifyWidth;
	int _justifyHeight;
	Common::Point _shadow;
	int _foreColor;
	int _backColor;
	int _shadowColor;
public:
	FontInfoResource(BoltFilesState &state, const byte *src);
	FontInfoResource();
	FontInfoResource(byte picFlags, byte picSelect, byte picPick, byte picOnOff, byte fontFlags, 
		FontJustify justify, int fontSaveBack, const Common::Point &pos, int justifyWidth, 
		int justifyHeight, const Common::Point &shadow, int foreColor, int backColor, 
		int shadowColor);
};

class CMapResource {
private:
	VoyeurEngine *_vm;
public:
	int _steps;
	int _fadeStatus;
	int _start;
	int _end;
	byte *_entries;
public:
	CMapResource(BoltFilesState &state, const byte *src);
	virtual ~CMapResource();

	void startFade();
};

class VInitCycleResource {
private:
	BoltFilesState &_state;
public:
	int _type[4];
	byte *_ptr[4];
public:
	VInitCycleResource(BoltFilesState &state, const byte *src);
	virtual ~VInitCycleResource() {}

	void vStartCycle();
	void vStopCycle();
};

/* stampblt.blt resources */

class PtrResource {
public:
	Common::Array<BoltEntry *> _entries;

	PtrResource(BoltFilesState &state, const byte *src);
	virtual ~PtrResource() {}
};

class ControlResource {
public:
	int _memberIds[8];
	byte *_entries[8];
	int _stateId;
	StateResource *_state;

	ControlResource(BoltFilesState &state, const byte *src);
	virtual ~ControlResource() {}
};

/**
 * Stores data about the intended victim
 */
class StateResource {
public:
	int _vals[4];
	int &_victimIndex;
	int &_victimEvidenceIndex;
	int &_victimMurderIndex;

	StateResource(BoltFilesState &state, const byte *src);
	virtual ~StateResource() {}

	/**
	 * Synchronizes the game data
	 */
	void synchronize(Common::Serializer &s);
};

class ThreadResource {
public:
	static int _useCount[8];
	static void initUseCount();
	static void unloadAllStacks(VoyeurEngine *vm);

	static void init();
private:
	VoyeurEngine *_vm;
	Common::Point _aptPos;
private:
	bool getStateInfo();
	byte *getDataOffset();
	void getButtonsText();
	void getButtonsFlags();
	void performOpenCard();
	const byte *getRecordOffset(const byte *p);
	const byte *getNextRecord(const byte *p);
	const byte *getSTAMPCard(int cardId);
	int getStateFromID(uint32 id);
	uint32 getSID(int sid);
	void cardAction(const byte *p);
	void doSTAMPCardAction();
	bool goToStateID(int stackId, int id);
	const byte *cardPerform(const byte *card);
	bool cardPerform2(const byte *p, int cardCmdId);
	void savePrevious();
	void setButtonFlag(int idx, byte bits);
	void clearButtonFlag(int idx, byte bits);

	/**
	 * Frees the apartment screen data
	 */
	void freeTheApt();

	/**
	 * Does any necessary animation at the start or end of showing the apartment.
	 */
	void doAptAnim(int mode);

	/**
	 * Updates the mansion scroll position if ncessary, and returns true if it
	 * has been changed.
	 */
	bool checkMansionScroll();
public:
	int _stateId;
	int _stackId;
	int _savedStateId;
	int _savedStackId;
	int _newStateId;
	int _newStackId;
	int _stateFlags;
	int _stateCount;
	int _parseCount;
	uint32 _nextStateId;
	byte *_threadInfoPtr;
	byte _buttonFlags[64];
	byte _buttonIds[64];
	byte *_ctlPtr;
	byte *_playCommandsPtr;

	/**
	 * Loads the specified stack
	 */
	bool loadAStack(int stackId);

	/**
	 * Unloads the specified stack
	 */
	void unloadAStack(int stackId);

	/**
	 * Initializes data for the thread based on the current state
	 */
	bool doState();

public:
	ThreadResource(BoltFilesState &state, const byte *src);
	virtual ~ThreadResource() {}

	/**
	 * Initialize the thread
	 */
	void initThreadStruct(int idx, int id);

	/**
	 * Go to a new state and/or stack
	 */
	bool goToState(int stackId, int stateId);

	bool chooseSTAMPButton(int buttonId);

	/**
	 * Parses the script commands from the currently active stack
	 */
	void parsePlayCommands();

	/**
	 * Do the camera view looking at the mansion
	 */
	int doInterface();

	/**
	 * Do the display of a room that has one or more evidence hotspots
	 * available for display
	 */
	void doRoom();

	/**
	 * Shows the apartment screen
	 */
	int doApt();

	/**
	 * Loads data needed for displaying the initial apartment screen
	 */
	void loadTheApt();

	/**
	 * Synchronizes the game data
	 */
	void synchronize(Common::Serializer &s);
};

} // End of namespace Voyeur

#endif /* VOYEUR_FILES_H */