Wing Commander II
Reconstructed Win32 source (1996)
Toggle main menu visibility
Loading...
Searching...
No Matches
packet.c
Go to the documentation of this file.
1
/*
2
* Packet sections and data file handles.
3
*
4
* Retail object 0x44F010-0x44F1EF (link order; see docs/ORDER.md).
5
*/
6
#include "
game.h
"
7
8
short
OpenDataFileOrDie
(
const
char
*path);
9
int
ReadDataFileAtOffset
(
unsigned
short
fd,
int
offset,
unsigned
int
length,
10
void
*data);
11
int
SeekDataFile
(
unsigned
short
fd,
int
offset,
unsigned
int
origin);
12
13
/* Function start: 0x44F010 */
14
short
OpenPacketSection
(
const
char
*filename,
short
section,
15
PacketSectionHandle
*out)
16
{
17
unsigned
int
start;
18
unsigned
int
length;
19
unsigned
int
next;
20
int
offset;
21
unsigned
int
directorySize;
22
short
method;
23
short
entryCount;
24
short
handle;
25
26
handle =
OpenDataFileOrDie
(filename);
27
if
(handle != -1) {
28
for
(;;) {
29
if
(
ReadDataFileAtOffset
(handle, 0, 4, &length) == 0)
30
goto
failed;
31
if
(
ReadDataFileAtOffset
(handle, 4, 4, &directorySize) == 0)
32
goto
failed;
33
entryCount = (short)((directorySize >> 2) - 1);
34
if
(section >= entryCount) {
35
g_nPacketError
= 3;
36
goto
failed;
37
}
38
offset = (section + 1) * 4;
39
if
(
ReadDataFileAtOffset
(handle, offset, 4, &start) == 0)
40
goto
failed;
41
method = (short)(start >> 24);
42
start &= 0x00ffffff;
43
out->
finalSection
= 0;
44
if
(entryCount - 1 == section) {
45
next = length;
46
out->
finalSection
= 1;
47
}
else
{
48
offset += 4;
49
if
(
ReadDataFileAtOffset
(handle, offset, 4, &next) == 0)
50
goto
failed;
51
/* The top byte holds the next section's method flag. */
52
((
unsigned
char
*)&next)[3] = 0;
53
}
54
length = next - start;
55
if
(
SeekDataFile
(handle, start, 0) == 0)
56
goto
failed;
57
out->
file
= handle;
58
out->
sectionCount
= entryCount;
59
out->
compression
= method;
60
out->
dataOffset
= start;
61
out->
position
= 0;
62
out->
dataSize
= length;
63
return
1;
64
}
65
}
66
failed:
67
CloseDataFile
((
unsigned
short
)handle);
68
return
0;
69
}
70
71
/* Function start: 0x44F1C7 */
72
void
CloseDataFileByHandle
(
unsigned
short
*handle)
73
{
74
CloseDataFile
(*handle);
75
}
SeekDataFile
int SeekDataFile(unsigned short fd, int offset, unsigned int origin)
Definition
datafile.c:78
ReadDataFileAtOffset
int ReadDataFileAtOffset(unsigned short fd, int offset, unsigned int length, void *data)
Definition
datafile.c:60
OpenPacketSection
short OpenPacketSection(const char *filename, short section, PacketSectionHandle *handle)
Definition
packet.c:14
CloseDataFileByHandle
void CloseDataFileByHandle(unsigned short *handle)
Definition
packet.c:72
OpenDataFileOrDie
short OpenDataFileOrDie(const char *path)
Definition
datafile.c:13
CloseDataFile
void CloseDataFile(unsigned short fd)
Definition
datafile.c:22
game.h
Shared Win32 declarations, types and library interfaces.
g_nPacketError
short g_nPacketError
Definition
datafile.c:10
PacketSectionHandle
Definition
game_data.h:1172
PacketSectionHandle::dataOffset
unsigned int dataOffset
Definition
game_data.h:1177
PacketSectionHandle::compression
short compression
Definition
game_data.h:1176
PacketSectionHandle::file
short file
Definition
game_data.h:1173
PacketSectionHandle::sectionCount
short sectionCount
Definition
game_data.h:1175
PacketSectionHandle::dataSize
unsigned int dataSize
Definition
game_data.h:1179
PacketSectionHandle::finalSection
short finalSection
Definition
game_data.h:1174
PacketSectionHandle::position
unsigned int position
Definition
game_data.h:1178
src
packet.c
Generated by
1.18.0