102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference |
GitLab repository
Toggle main menu visibility
Loading...
Searching...
No Matches
archive.c
Go to the documentation of this file.
1
/* Recovered game implementation; original addresses identify provenance. */
2
#include "
pcdogs/package/constants.h
"
3
#include "
pcdogs/package/functions.h
"
4
#include "
pcdogs/package/globals.h
"
5
#include "
pcdogs/platform/enums.h
"
6
#include "
pcdogs/runtime/functions.h
"
7
8
#include <string.h>
9
10
// Original pcdogs.exe: 0x43ec30
11
void
*
PKG_LoadEntryAlloc
(int32_t toc_index, int32_t unused_zero)
12
{
13
(void)unused_zero;
14
return
PKG_LoadEntry
(toc_index, NULL, 1);
15
}
16
17
// Original pcdogs.exe: 0x43ee00
18
void
*
PKG_LoadEntry
(int32_t toc_index,
void
*dest_buffer, int32_t unused_mode)
19
{
20
(void)unused_mode;
21
uint32_t file_size =
g_pkgTOC
[toc_index].fileSize;
22
if
((int32_t)file_size <= 0)
23
return
NULL;
24
25
/* Entries occupy whole 2048-byte sectors, including the final partial sector. */
26
uint32_t read_size = (file_size +
PKG_SECTOR_OFFSET_MASK
) & ~(uint32_t)
PKG_SECTOR_OFFSET_MASK
;
27
if
(!dest_buffer)
28
{
29
dest_buffer =
Pkg_AllocateResourceMemory
(read_size);
30
if
(!dest_buffer)
31
return
NULL;
32
}
33
34
CRT_fseek
(
g_pkgFileHandle
,
g_pkgTOC
[toc_index].fileOffset, SEEK_SET);
35
CRT_fread
(dest_buffer, 1, read_size,
g_pkgFileHandle
);
36
return
dest_buffer;
37
}
38
39
static
bool
package_exists
(
const
char
*path)
40
{
41
struct
File_Handle
*stream =
CRT_fopen
(path,
"rb"
);
42
if
(!stream)
43
return
false
;
44
45
CRT_fclose
(stream);
46
return
true
;
47
}
48
49
// Original pcdogs.exe: 0x43eea0
50
void
PKG_LocatePackagePath
(
void
)
51
{
52
GetCurrentDirectoryA(MAX_PATH,
g_pkgBasePath
);
53
char
*end =
g_pkgBasePath
;
54
while
(*end)
55
++end;
56
if
(end[-1] !=
'\\'
)
57
{
58
*end++ =
'\\'
;
59
*end =
'\0'
;
60
}
61
62
if
(
package_exists
(
"pcdogs.pkg"
))
63
return
;
64
65
/* The original search stops at the first nonexistent drive and excludes Z. */
66
for
(
char
drive =
'C'
; drive <
'Z'
; ++drive)
67
{
68
char
root[4];
69
String_FormatCRTString
(root,
"%c:\\"
, (
int
)drive);
70
DWORD type = GetDriveTypeA(root);
71
if
(type == DRIVE_UNKNOWN || type == DRIVE_NO_ROOT_DIR)
72
break
;
73
74
char
path[MAX_PATH];
75
/* "Dalmations" is the directory spelling in the shipped executable. */
76
String_FormatCRTString
(
g_pkgBasePath
,
"%sDalmations\\Setup\\102Dalms\\"
, root);
77
String_FormatCRTString
(path,
"%spcdogs.pkg"
,
g_pkgBasePath
);
78
if
(
package_exists
(path))
79
return
;
80
81
String_FormatCRTString
(
g_pkgBasePath
,
"%sSetup\\102Dalms\\"
, root);
82
String_FormatCRTString
(path,
"%spcdogs.pkg"
,
g_pkgBasePath
);
83
if
(
package_exists
(path))
84
return
;
85
}
86
87
MessageBoxA(NULL,
"Cannot find pcdogs.pkg. Aborting."
,
"Error"
,
MB_OK
);
88
}
89
90
// Original pcdogs.exe: 0x43f010
91
void
PKG_OpenAndReadTOC
(
void
)
92
{
93
char
path[MAX_PATH];
94
String_FormatCRTString
(path,
"%spcdogs.pkg"
,
g_pkgBasePath
);
95
g_pkgFileHandle
=
CRT_fopen
(path,
"rb"
);
96
if
(!
g_pkgFileHandle
)
97
return
;
98
99
struct
Pkg_Header
*header =
Pkg_AllocateResourceMemory
(
sizeof
(*header));
100
CRT_fread
(header, 1,
sizeof
(*header),
g_pkgFileHandle
);
101
memcpy(
g_pkgTOC
, header->
entries
,
sizeof
(
g_pkgTOC
));
102
Pkg_FreeResourceMemory
(header);
103
}
104
105
// Original pcdogs.exe: 0x43f090
106
void
PKG_Close
(
void
)
107
{
108
if
(
g_pkgFileHandle
)
109
{
110
CRT_fclose
(
g_pkgFileHandle
);
111
g_pkgFileHandle
= NULL;
112
}
113
}
PKG_LoadEntryAlloc
void * PKG_LoadEntryAlloc(int32_t toc_index, int32_t unused_zero)
Definition
archive.c:11
PKG_Close
void PKG_Close(void)
Definition
archive.c:106
PKG_LocatePackagePath
void PKG_LocatePackagePath(void)
Definition
archive.c:50
package_exists
static bool package_exists(const char *path)
Definition
archive.c:39
PKG_OpenAndReadTOC
void PKG_OpenAndReadTOC(void)
Definition
archive.c:91
PKG_LoadEntry
void * PKG_LoadEntry(int32_t toc_index, void *dest_buffer, int32_t unused_mode)
Definition
archive.c:18
constants.h
PKG_SECTOR_OFFSET_MASK
#define PKG_SECTOR_OFFSET_MASK
Definition
constants.h:26
functions.h
Pkg_FreeResourceMemory
void Pkg_FreeResourceMemory(void *user_ptr)
Definition
resources.c:342
Pkg_AllocateResourceMemory
void * Pkg_AllocateResourceMemory(uint32_t size)
Definition
resources.c:317
globals.h
g_pkgFileHandle
#define g_pkgFileHandle
Definition
globals.h:87
g_pkgTOC
#define g_pkgTOC
Definition
globals.h:90
g_pkgBasePath
#define g_pkgBasePath
Definition
globals.h:102
enums.h
functions.h
CRT_fclose
int32_t CRT_fclose(struct File_Handle *stream)
Definition
stdio.c:80
CRT_fseek
int32_t CRT_fseek(struct File_Handle *stream, int32_t offset, int32_t origin)
Definition
stdio.c:235
CRT_fread
uint32_t CRT_fread(void *buffer, uint32_t size, uint32_t count, struct File_Handle *stream)
Definition
stdio.c:283
CRT_fopen
struct File_Handle * CRT_fopen(char const *filename, char const *mode)
Definition
stdio.c:134
String_FormatCRTString
int32_t String_FormatCRTString(char *buffer, char const *format,...)
Definition
formatting.c:18
File_Handle
Definition
types.h:228
Pkg_Header
Definition
types.h:1195
Pkg_Header::entries
struct Pkg_TocEntry entries[0x8a]
Definition
types.h:1196
MB_OK
#define MB_OK
Definition
win32_window.h:64
src
package
archive.c
Generated by
1.17.0