102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference |
GitLab repository
Toggle main menu visibility
Loading...
Searching...
No Matches
progress.c
Go to the documentation of this file.
1
/* Recovered game implementation; original addresses identify provenance. */
2
#include "
pcdogs/audio/constants.h
"
3
#include "
pcdogs/audio/functions.h
"
4
#include "
pcdogs/game/globals.h
"
5
#include "
pcdogs/image/globals.h
"
6
#include "
pcdogs/level/constants.h
"
7
#include "
pcdogs/level/functions.h
"
8
#include "
pcdogs/level/globals.h
"
9
#include "
pcdogs/menu/globals.h
"
10
#include "
pcdogs/save/constants.h
"
11
#include "
pcdogs/save/functions.h
"
12
#include "
pcdogs/save/globals.h
"
13
#include "
pcdogs/save/types.h
"
14
#include "
pcdogs/settings/functions.h
"
15
#include "
pcdogs/settings/globals.h
"
16
#include <string.h>
17
18
// Original pcdogs.exe: 0x426d90
19
// Stores the supplied game-completion byte in the current save data.
20
void
Save_SetGameComplete
(uint8_t complete)
21
{
22
g_collectiblesData
.game_complete_flag = complete;
23
}
24
25
// Original pcdogs.exe: 0x426da0
26
// Returns the game-completion byte with signed extension.
27
int32_t
Save_IsGameComplete
()
28
{
29
return
(int32_t)(int8_t)
g_collectiblesData
.game_complete_flag;
30
}
31
32
// Original pcdogs.exe: 0x426f90
33
// Records current level completion, best score, bonus flags and campaign progress, with separate world-snapshot and timed-level handling.
34
void
Save_SaveGameLevelCompletion
(uint8_t completion_flag)
35
{
36
int32_t ordinal =
Level_GetCampaignProgressOrdinal
(
g_currentLevelID
);
37
int32_t slot =
Level_GetSaveArrayIndex
(
g_currentLevelID
);
38
int16_t level =
g_currentLevelID
;
39
40
if
(level ==
LEVEL_AFTER_BONUS
)
41
{
42
Save_SnapshotWorldCompletionBits
();
43
return
;
44
}
45
if
(level ==
LEVEL_BONUS_FIFTH
)
46
{
47
g_collectiblesData
.level_best_time = (uint16_t)
g_menuItems
[0];
48
return
;
49
}
50
if
(level < LEVEL_CAMPAIGN_FIRST || level >=
LEVEL_BONUS_FIRST
)
51
return
;
52
53
Save_BackupLivesToSlot
();
54
int8_t highest = (int8_t)(completion_flag ? ordinal : ordinal - 1);
55
g_saveHighestWorld
= highest;
56
if
(
g_collectiblesData
.max_world_reached < highest)
57
g_collectiblesData
.max_world_reached = highest;
58
59
if
(slot ==
LEVEL_INVALID_SAVE_INDEX
)
60
return
;
61
62
if
((int8_t)
g_currentLevelScore
> (int8_t)
g_collectiblesData
.level_best_scores[slot])
63
g_collectiblesData
.level_best_scores[slot] =
g_currentLevelScore
;
64
g_collectiblesData
.level_completion_flags[slot] |=
g_currentLevelCompletionBits
&
LEVEL_COMPLETION_ALL
;
65
for
(int32_t i = 0; i <
SAVE_BONUS_ITEM_COUNT
; ++i)
66
{
67
if
(*
Level_BonusProgressVariable
(i))
68
g_collectiblesData
.level_bonus_item_flags[slot] |= 1u << i;
69
}
70
}
71
72
// Original pcdogs.exe: 0x427150
73
// Copies the five current world-completion words into their saved snapshot fields.
74
void
Save_SnapshotWorldCompletionBits
()
75
{
76
g_savedWorld0CompletionBits
=
g_world0CompletionBits
;
77
g_savedWorld1CompletionBits
=
g_world1CompletionBits
;
78
g_savedWorld2CompletionBits
=
g_world2CompletionBits
;
79
g_savedWorld3CompletionBits
=
g_world3CompletionBits
;
80
g_savedWorld4CompletionBits
=
g_world4CompletionBits
;
81
}
82
83
// Original pcdogs.exe: 0x4271a0
84
// Sets the backup life count.
85
void
Save_SetBackupLives
(uint8_t lives)
86
{
87
g_backupLives
= lives;
88
}
89
90
// Original pcdogs.exe: 0x4275f0
91
// Initializes default game settings, full music and sound-effect volume, player and save-slot selection, and rumble suppression.
92
void
Save_InitializeNewGame
()
93
{
94
g_gameSettings
.initialized = 1;
95
Settings_SetMusicVolume
(
AUDIO_Q12_ONE
);
96
Settings_SetSfxVolume
(
AUDIO_Q12_ONE
);
97
Settings_SetSoundEnabled
(!(
Audio_GetEnabledFlag
()));
98
Settings_SetPlayerCharacter
(0);
99
Settings_SetSelectedSaveSlot
(0);
100
Settings_SetRumbleSuppressFlag
(1);
101
}
102
103
// Original pcdogs.exe: 0x427640
104
// Starts or completes loading saved settings, rejects failed or mismatched-version data and initializes defaults when needed. Returns zero while pending, one for fallback completion and two for a valid load.
105
int32_t
Save_LoadGameState
(int32_t operation_step)
106
{
107
if
(!operation_step)
108
{
109
Save_InitGameOperation
(
SAVE_OPERATION_READ
, &
g_saveRecord
,
sizeof
(
g_saveRecord
));
110
111
return
SAVE_LOAD_PENDING
;
112
}
113
114
struct
Save_OperationStatus
operation_result;
115
116
Save_ProcessGameOperation
(&operation_result);
117
118
char
operation_status = operation_result.
status_code
;
119
120
if
(operation_status && operation_status !=
SAVE_STATUS_ACCEPTED_1
&& operation_status !=
SAVE_STATUS_READ_FAILED
&& operation_status !=
SAVE_STATUS_ACCEPTED_2
&& operation_status !=
SAVE_STATUS_ACCEPTED_4
&& operation_status !=
SAVE_STATUS_ACCEPTED_7
)
121
return
SAVE_LOAD_PENDING
;
122
123
Save_InitGameOperation
(
SAVE_OPERATION_CLEANUP
, NULL, 0);
124
125
if
(!operation_result.
success
||
g_saveFileBuffer
.version_marker !=
SAVE_FILE_VERSION
)
126
{
127
if
(!
g_gameSettings
.initialized)
128
Save_InitializeNewGame
();
129
130
return
SAVE_LOAD_DEFAULTS
;
131
}
132
133
g_liveSettings
.volume =
g_saveFileBuffer
.game_state;
134
g_liveSettings
.game =
g_saveFileBuffer
.game_settings;
135
g_liveSettings
.rumble =
g_saveFileBuffer
.rumble_suppress_flag;
136
137
return
SAVE_LOAD_VALID
;
138
}
139
140
// Original pcdogs.exe: 0x4276f0
141
// Returns the saved highest-world value.
142
int32_t
Save_GetGameHighestWorld
()
143
{
144
return
(int32_t)
g_saveHighestWorld
;
145
}
146
147
// Original pcdogs.exe: 0x427700
148
// Clears current progress, initializes the life and save-state defaults, resets the highest world and clears saved world-completion snapshots.
149
void
Save_InitializeGameState
()
150
{
151
memset(&
g_collectiblesData
, 0,
SAVE_PROGRESS_BYTES
);
152
g_collectiblesData
.lives_backup =
SAVE_DEFAULT_LIVES
;
153
g_collectiblesData
.save_game_init_flag =
SAVE_INITIALIZED
;
154
g_saveHighestWorld
= 0;
155
Save_ClearGameBonusProgressData
();
156
}
157
158
// Original pcdogs.exe: 0x427730
159
// Clears the five saved world-completion words.
160
void
Save_ClearGameBonusProgressData
()
161
{
162
memset(&
g_savedWorld0CompletionBits
, 0,
SAVE_WORLD_COMPLETION_BYTES
);
163
}
constants.h
AUDIO_Q12_ONE
#define AUDIO_Q12_ONE
Definition
constants.h:24
functions.h
Audio_GetEnabledFlag
int32_t Audio_GetEnabledFlag(void)
Definition
system.c:159
globals.h
g_gameSettings
#define g_gameSettings
Definition
globals.h:32
globals.h
constants.h
LEVEL_AFTER_BONUS
@ LEVEL_AFTER_BONUS
Definition
constants.h:95
LEVEL_BONUS_FIFTH
@ LEVEL_BONUS_FIFTH
Definition
constants.h:94
LEVEL_BONUS_FIRST
@ LEVEL_BONUS_FIRST
Definition
constants.h:90
LEVEL_COMPLETION_ALL
#define LEVEL_COMPLETION_ALL
Definition
constants.h:18
LEVEL_INVALID_SAVE_INDEX
#define LEVEL_INVALID_SAVE_INDEX
Definition
constants.h:114
functions.h
globals.h
Level_BonusProgressVariable
static int32_t * Level_BonusProgressVariable(size_t bonus)
Definition
globals.h:28
g_currentLevelCompletionBits
#define g_currentLevelCompletionBits
Definition
globals.h:61
g_currentLevelScore
#define g_currentLevelScore
Definition
globals.h:64
g_currentLevelID
#define g_currentLevelID
Definition
globals.h:43
Level_GetCampaignProgressOrdinal
int32_t Level_GetCampaignProgressOrdinal(int32_t level_id)
Definition
progress.c:90
Level_GetSaveArrayIndex
int32_t Level_GetSaveArrayIndex(int32_t level_id)
Definition
progress.c:30
globals.h
g_menuItems
#define g_menuItems
Definition
globals.h:162
constants.h
SAVE_LOAD_DEFAULTS
@ SAVE_LOAD_DEFAULTS
Definition
constants.h:31
SAVE_LOAD_VALID
@ SAVE_LOAD_VALID
Definition
constants.h:32
SAVE_LOAD_PENDING
@ SAVE_LOAD_PENDING
Definition
constants.h:30
SAVE_WORLD_COMPLETION_BYTES
#define SAVE_WORLD_COMPLETION_BYTES
Definition
constants.h:38
SAVE_DEFAULT_LIVES
#define SAVE_DEFAULT_LIVES
Definition
constants.h:26
SAVE_FILE_VERSION
#define SAVE_FILE_VERSION
Definition
constants.h:25
SAVE_PROGRESS_BYTES
#define SAVE_PROGRESS_BYTES
Definition
constants.h:37
SAVE_INITIALIZED
#define SAVE_INITIALIZED
Definition
constants.h:35
SAVE_OPERATION_READ
@ SAVE_OPERATION_READ
Definition
constants.h:9
SAVE_OPERATION_CLEANUP
@ SAVE_OPERATION_CLEANUP
Definition
constants.h:11
SAVE_BONUS_ITEM_COUNT
#define SAVE_BONUS_ITEM_COUNT
Definition
constants.h:40
SAVE_STATUS_ACCEPTED_7
@ SAVE_STATUS_ACCEPTED_7
Definition
constants.h:22
SAVE_STATUS_ACCEPTED_2
@ SAVE_STATUS_ACCEPTED_2
Definition
constants.h:19
SAVE_STATUS_ACCEPTED_1
@ SAVE_STATUS_ACCEPTED_1
Definition
constants.h:18
SAVE_STATUS_ACCEPTED_4
@ SAVE_STATUS_ACCEPTED_4
Definition
constants.h:20
SAVE_STATUS_READ_FAILED
@ SAVE_STATUS_READ_FAILED
Definition
constants.h:21
functions.h
Save_GetGameHighestWorld
int32_t Save_GetGameHighestWorld(void)
Definition
progress.c:142
Save_InitGameOperation
void Save_InitGameOperation(int32_t operation, void *buffer, uint32_t size)
Definition
files.c:154
Save_BackupLivesToSlot
void Save_BackupLivesToSlot(void)
Definition
files.c:22
Save_ProcessGameOperation
void Save_ProcessGameOperation(struct Save_OperationStatus *status_out)
Definition
files.c:45
globals.h
g_saveRecord
#define g_saveRecord
Definition
globals.h:12
g_collectiblesData
#define g_collectiblesData
Definition
globals.h:21
g_saveHighestWorld
#define g_saveHighestWorld
Definition
globals.h:9
g_saveFileBuffer
#define g_saveFileBuffer
Definition
globals.h:15
Save_SetBackupLives
void Save_SetBackupLives(uint8_t lives)
Definition
progress.c:85
Save_SetGameComplete
void Save_SetGameComplete(uint8_t complete)
Definition
progress.c:20
Save_ClearGameBonusProgressData
void Save_ClearGameBonusProgressData()
Definition
progress.c:160
Save_LoadGameState
int32_t Save_LoadGameState(int32_t operation_step)
Definition
progress.c:105
Save_SaveGameLevelCompletion
void Save_SaveGameLevelCompletion(uint8_t completion_flag)
Definition
progress.c:34
Save_InitializeGameState
void Save_InitializeGameState()
Definition
progress.c:149
Save_InitializeNewGame
void Save_InitializeNewGame()
Definition
progress.c:92
Save_IsGameComplete
int32_t Save_IsGameComplete()
Definition
progress.c:27
Save_SnapshotWorldCompletionBits
void Save_SnapshotWorldCompletionBits()
Definition
progress.c:74
types.h
functions.h
Settings_SetPlayerCharacter
void Settings_SetPlayerCharacter(uint8_t character_id)
Definition
preferences.c:70
Settings_SetRumbleSuppressFlag
void Settings_SetRumbleSuppressFlag(uint8_t suppress_rumble)
Definition
preferences.c:84
Settings_SetMusicVolume
void Settings_SetMusicVolume(uint16_t volume_fp12)
Definition
preferences.c:34
Settings_SetSelectedSaveSlot
void Settings_SetSelectedSaveSlot(uint8_t slot_index)
Definition
preferences.c:63
Settings_SetSfxVolume
void Settings_SetSfxVolume(uint16_t volume_fp12)
Definition
preferences.c:20
Settings_SetSoundEnabled
void Settings_SetSoundEnabled(int32_t enabled)
Definition
preferences.c:48
globals.h
g_liveSettings
#define g_liveSettings
Definition
globals.h:27
Save_OperationStatus
Definition
types.h:52
Save_OperationStatus::status_code
uint8_t status_code
Definition
types.h:53
Save_OperationStatus::success
uint8_t success
Definition
types.h:54
g_savedWorld2CompletionBits
#define g_savedWorld2CompletionBits
Definition
values.h:417
g_savedWorld4CompletionBits
#define g_savedWorld4CompletionBits
Definition
values.h:423
g_world4CompletionBits
#define g_world4CompletionBits
Definition
values.h:852
g_world0CompletionBits
#define g_world0CompletionBits
Definition
values.h:840
g_world2CompletionBits
#define g_world2CompletionBits
Definition
values.h:846
g_backupLives
#define g_backupLives
Definition
values.h:426
g_savedWorld3CompletionBits
#define g_savedWorld3CompletionBits
Definition
values.h:420
g_world1CompletionBits
#define g_world1CompletionBits
Definition
values.h:843
g_savedWorld0CompletionBits
#define g_savedWorld0CompletionBits
Definition
values.h:411
g_world3CompletionBits
#define g_world3CompletionBits
Definition
values.h:849
g_savedWorld1CompletionBits
#define g_savedWorld1CompletionBits
Definition
values.h:414
src
save
progress.c
Generated by
1.17.0