Wing Commander II
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
iffindex.c
Go to the documentation of this file.
1/*
2 * Scene chunk decoding.
3 *
4 * Retail object 0x458A90-0x458E0F (link order; see docs/ORDER.md).
5 */
6#include "game.h"
7
8/* Function start: 0x458A90 */
9signed char DecodeSceneStructChunk(unsigned char **cursor,
10 SceneResourceTable **resource)
11{
12 short ptrSize;
13 unsigned int chunkSize;
14 unsigned char *record;
15 void **slots;
16 short index;
17 unsigned short step;
18 unsigned short recordCount;
19
20 record = *cursor;
21 record += 4;
22 chunkSize = *(unsigned int *)record;
23 record += 4;
24 SwapSceneChunkSizeEndian((int *)&chunkSize);
25 step = *(unsigned short *)record;
26 record += 2;
27 recordCount = (unsigned short)((chunkSize - 2) / step);
28 (*resource)->type = 0;
29 (*resource)->count = recordCount;
30 ptrSize = HOST_POINTER_SIZE;
32 recordCount, ptrSize, 0, "Cannot Allocate STRC stuff");
33 (*resource)->data = slots;
34 for (index = 1; index <= recordCount; index++) {
35 *slots = IdentityHandle(record);
36 slots++;
37 record += step;
38 }
39 *cursor += ((chunkSize + 1) & ~1) + 8;
40 return 1;
41}
42
43/* Function start: 0x458B8C */
44signed char DecodeSceneOffsetChunk(unsigned char **cursor,
45 SceneResourceTable **resource)
46{
47 void *pointer;
48 unsigned int size;
49 void **dest;
50 short entryIndex;
51 unsigned char *data;
52 unsigned short count;
53 int offset;
54
55 data = *cursor;
56 data += 4;
57 size = *(unsigned int *)data;
58 data += 4;
59 SwapSceneChunkSizeEndian((int *)&size);
60 count = *(unsigned short *)data;
61 data += 2;
62 (*resource)->type = 1;
63 (*resource)->count = count;
65 count, HOST_POINTER_SIZE, 0, "Cannot Alloc OFST stuff");
66 (*resource)->data = dest;
67 for (entryIndex = 1; entryIndex <= count; entryIndex++) {
68 offset = *(int *)data;
69 if (offset != -1)
70 pointer = data + offset;
71 else
72 pointer = 0;
73 data += 4;
74 *dest = pointer;
75 dest++;
76 }
77 *cursor += ((size + 1) & ~1) + 8;
78 return 1;
79}
80
81/* Function start: 0x458C81 */
82signed char DecodeSceneSymbolChunk(unsigned char **cursor,
83 SceneResourceTable **resource)
84{
85 unsigned int size;
86 short ptrSize;
87 unsigned char *string;
88 unsigned char *data;
89 void **table;
90 unsigned char *begin;
91 short remaining;
92 short entryCount;
93
94 data = *cursor;
95 begin = data;
96 data += 4;
97 size = *(unsigned int *)data;
98 data += 4;
99 SwapSceneChunkSizeEndian((int *)&size);
100 begin = data;
101 entryCount = 0;
102 ptrSize = HOST_POINTER_SIZE;
103 do {
104 string = (unsigned char *)DosStrchr((char *)data, 0) + 1;
105 entryCount++;
106 data = string;
107 } while (string - begin < (int)size);
108 data = begin;
109 (*resource)->type = 2;
110 (*resource)->count = entryCount;
112 entryCount, ptrSize, 0, "Cannot Alloc SYMB stuff");
113 (*resource)->data = table;
114 string = begin;
115 remaining = entryCount;
116 do {
117 *table = IdentityHandle(string);
118 table++;
119 string = (unsigned char *)DosStrchr((char *)string, 0) + 1;
120 remaining--;
121 } while (remaining != 0);
122 *cursor += ((size + 1) & ~1) + 8;
123 return 1;
124}
125
126/* Function start: 0x458D94 */
127signed char DecodeSceneFileChunk(unsigned char **cursor,
128 SceneResourceTable **resource)
129{
130 unsigned int size;
131 unsigned char *data;
132
133 data = *cursor;
134 data += 4;
135 size = *(unsigned int *)data;
136 data += 4;
137 SwapSceneChunkSizeEndian((int *)&size);
138 (*resource)->count = *(unsigned short *)data;
139 data += 2;
140 (*resource)->data = data;
141 (*resource)->type = 3;
142 *cursor += ((size + 1) & ~1) + 8;
143 return 1;
144}
signed char DecodeSceneOffsetChunk(unsigned char **cursor, SceneResourceTable **resource)
Definition iffindex.c:44
signed char DecodeSceneSymbolChunk(unsigned char **cursor, SceneResourceTable **resource)
Definition iffindex.c:82
void * AllocateScenePointerTable(int count, short elementSize, unsigned short flags, const char *errorMessage)
Definition iffload.c:131
signed char DecodeSceneFileChunk(unsigned char **cursor, SceneResourceTable **resource)
Definition iffindex.c:127
void * IdentityHandle(void *v)
Definition eventmgr.c:196
char * DosStrchr(const char *s, short c)
Definition eventmgr.c:459
signed char DecodeSceneStructChunk(unsigned char **cursor, SceneResourceTable **resource)
Definition iffindex.c:9
void SwapSceneChunkSizeEndian(int *value)
Definition iffload.c:32
Shared Win32 declarations, types and library interfaces.
#define HOST_POINTER_SIZE
Definition game.h:103