Skip to content

Commit 6862a02

Browse files
Mission skip improvements (#9)
* Fix mission skip bug when selecting tutorial * Various minor improvements in MissionSkipPatch
1 parent 8718189 commit 6862a02

2 files changed

Lines changed: 33 additions & 15 deletions

File tree

subtitans/missionskippatch.cpp

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,23 @@ namespace MissionSkip {
2929
if (_strupr_s(cheatActivatedMapName, sizeof(cheatActivatedMapName)) != 0)
3030
{
3131
GetLogger()->Error("Failed to convert map name to uppercase\n");
32+
GetLogger()->Informational("Orbiton has been disabled\n");
3233
return;
3334
}
3435

36+
constexpr int missionValidationStringLength = sizeof(MissionValidationString) - 1;
37+
constexpr int missionNumberStringLength = 3;
38+
39+
// Validate if the string has the expected length
40+
if(strlen(cheatActivatedMapName) < missionValidationStringLength + missionNumberStringLength)
41+
{
42+
GetLogger()->Warning("Current map has an unexpected length, are you sure this is a mission?\n");
43+
GetLogger()->Informational("Orbiton has been disabled\n");
44+
return;
45+
}
46+
3547
// Check if the current map is a mission
36-
for (unsigned int i = 0; i < sizeof(MissionValidationString) - 1; ++i)
48+
for (unsigned int i = 0; i < missionValidationStringLength; ++i)
3749
{
3850
if (MissionValidationString[i] != cheatActivatedMapName[i])
3951
{
@@ -42,17 +54,17 @@ namespace MissionSkip {
4254
return;
4355
}
4456
}
45-
46-
char missionNumberAsString[4] = { 0x00, };
47-
memcpy_s(missionNumberAsString, sizeof(missionNumberAsString), cheatActivatedMapName + strlen(MissionValidationString), 3);
57+
58+
char missionNumberAsString[missionNumberStringLength + 1] = { 0x00, };
59+
memcpy_s(missionNumberAsString, sizeof(missionNumberAsString), cheatActivatedMapName + missionValidationStringLength, missionNumberStringLength);
4860
int missionNumber = atoi(missionNumberAsString + 1); // Skip team
4961
if (missionNumber < 10)
5062
missionNumber++;
5163

52-
sprintf_s(missionNumberAsString + 1, sizeof(missionNumberAsString), "%02d", missionNumber);
53-
memcpy_s(cheatActivatedMapName + strlen(MissionValidationString), 3, missionNumberAsString, 3);
64+
sprintf_s(missionNumberAsString + 1, sizeof(missionNumberAsString) - 1, "%02d", missionNumber);
65+
memcpy_s(cheatActivatedMapName + missionValidationStringLength, missionNumberStringLength, missionNumberAsString, missionNumberStringLength);
5466

55-
memcpy_s(OrbitonMissionPathPattern + sizeof(OrbitonMissionPathPattern) - 4, 3, missionNumberAsString, 3);
67+
memcpy_s(OrbitonMissionPathPattern + (sizeof(OrbitonMissionPathPattern) - 1) - missionNumberStringLength, missionNumberStringLength, missionNumberAsString, missionNumberStringLength);
5668

5769
GetLogger()->Informational("Next mission will be forced to: %s\nExit to main menu and start a new campaign.\n", cheatActivatedMapName);
5870

@@ -106,12 +118,18 @@ namespace MissionSkip {
106118

107119
__declspec(naked) void Implementation()
108120
{
109-
__asm cmp [OrbitonActivated], 0;
121+
__asm cmp [OrbitonActivated], 0x00;
110122
__asm je fullPathOrbitonDeactivated;
111123

124+
__asm cmp ecx, 0x01;
125+
__asm je disableOrbitonForTutorial;
126+
112127
__asm push offset [OrbitonMissionPathPattern];
113128
__asm jmp [JmpBackAddress];
114129

130+
disableOrbitonForTutorial:
131+
__asm mov [OrbitonActivated], 0x00;
132+
115133
fullPathOrbitonDeactivated:
116134
__asm push offset [DefaultMissionPathPattern];
117135
__asm jmp [JmpBackAddress];
@@ -127,11 +145,11 @@ namespace MissionSkip {
127145

128146
__declspec(naked) void Implementation()
129147
{
130-
__asm cmp [OrbitonActivated], 0;
148+
__asm cmp [OrbitonActivated], 0x00;
131149
__asm je fullPathOrbitonDeactivated;
132150

133151
__asm push offset [OrbitonMissionPathPattern + 0x02];
134-
__asm mov [OrbitonActivated], 0;
152+
__asm mov [OrbitonActivated], 0x00;
135153
__asm jmp [JmpBackAddress];
136154

137155
fullPathOrbitonDeactivated:

subtitans/nativeresolutionpatch.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ namespace NativeResolution{
2424
__asm mov edx, dword ptr ds:[esi + 0x8C];
2525
__asm cmp edx, 0xF0; // Only do this for 1280x1024 resolution modification
2626
__asm jne ASM_NR_RBM_NOTNATIVERES;
27-
__asm cmp ecx, 1 // Check if last (0x0B: Left TV panel) <-- Don't add default value if match
28-
__asm jne ASM_NR_RBM_DONTOVERRIDEDEFAULT
29-
__asm mov edx, 0x00
27+
__asm cmp ecx, 0x01; // Check if last (0x0B: Left TV panel) <-- Don't add default value if match
28+
__asm jne ASM_NR_RBM_DONTOVERRIDEDEFAULT;
29+
__asm mov edx, 0x00;
3030

3131
ASM_NR_RBM_DONTOVERRIDEDEFAULT:
3232
__asm add edx, [ControlPanelMarginLeft]; // Widescreen reposition value
@@ -36,7 +36,7 @@ namespace NativeResolution{
3636
__asm mov ebx, dword ptr ds:[eax];
3737
__asm add ebx, edx;
3838
__asm mov dword ptr ds:[eax], ebx;
39-
__asm add eax, 4;
39+
__asm add eax, 0x04;
4040
__asm dec ecx;
4141
__asm jnz ASM_NR_RBM_LOOP;
4242

@@ -298,7 +298,7 @@ namespace NativeResolution{
298298
__declspec(naked) void Implementation()
299299
{
300300
__asm sub ecx, [ControlPanelMarginLeft];
301-
__asm mov dword ptr ds:[esi + 0x10c], ecx;
301+
__asm mov dword ptr ds:[esi + 0x10C], ecx;
302302
__asm jmp [JmpBackAddress];
303303
}
304304
}

0 commit comments

Comments
 (0)