Skip to content

Commit 550e4a8

Browse files
committed
Fix some issues
- Soft Shadow misplaced - Ending video not working - Shaders fix after changing resolutions - Log Direct3D8 errors - Additional error checking and code fixes
1 parent 6ebdf23 commit 550e4a8

File tree

14 files changed

+270
-158
lines changed

14 files changed

+270
-158
lines changed

Common/AutoUpdate.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ bool NewProjectReleaseAvailable(std::string &path_str)
295295
}
296296

297297
if (IsProjectUpdateAvailable)
298+
{
298299
return true;
300+
}
299301
}
300302

301303
return false;

Common/FileSystemHooks.cpp

Lines changed: 85 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ inline bool isInString(LPCWSTR strCheck, LPCSTR, LPCWSTR strW, size_t size)
137137
template<typename T>
138138
inline bool isDataPath(T sh2)
139139
{
140-
if ((sh2[0] == 'd' || sh2[0] == 'D') &&
141-
(sh2[1] == 'a' || sh2[1] == 'A') &&
142-
(sh2[2] == 't' || sh2[2] == 'T') &&
143-
(sh2[3] == 'a' || sh2[3] == 'A'))
140+
if (sh2[0] != '\0' && (sh2[0] == 'd' || sh2[0] == 'D') &&
141+
sh2[1] != '\0' && (sh2[1] == 'a' || sh2[1] == 'A') &&
142+
sh2[2] != '\0' && (sh2[2] == 't' || sh2[2] == 'T') &&
143+
sh2[3] != '\0' && (sh2[3] == 'a' || sh2[3] == 'A'))
144144
{
145145
return true;
146146
}
@@ -150,34 +150,38 @@ inline bool isDataPath(T sh2)
150150
template<typename T>
151151
inline bool isEndVideoPath(T sh2)
152152
{
153-
if ((sh2[0] == 'm' || sh2[0] == 'M') &&
154-
(sh2[1] == 'o' || sh2[1] == 'O') &&
155-
(sh2[2] == 'v' || sh2[2] == 'V') &&
156-
(sh2[3] == 'i' || sh2[3] == 'I') &&
157-
(sh2[4] == 'e' || sh2[4] == 'E') &&
158-
(sh2[6] == 'e' || sh2[6] == 'E') &&
159-
(sh2[7] == 'n' || sh2[7] == 'N') &&
160-
(sh2[8] == 'd' || sh2[8] == 'D') &&
161-
(sh2[9] == 'i' || sh2[9] == 'I') &&
162-
(sh2[10] == 'n' || sh2[10] == 'N') &&
163-
(sh2[11] == 'g' || sh2[11] == 'G') &&
164-
(sh2[13] == 'b' || sh2[13] == 'B') &&
165-
(sh2[14] == 'i' || sh2[14] == 'I') &&
166-
(sh2[15] == 'k' || sh2[15] == 'K'))
153+
if (sh2[0] != '\0' && (sh2[0] == 'm' || sh2[0] == 'M') &&
154+
sh2[1] != '\0' && (sh2[1] == 'o' || sh2[1] == 'O') &&
155+
sh2[2] != '\0' && (sh2[2] == 'v' || sh2[2] == 'V') &&
156+
sh2[3] != '\0' && (sh2[3] == 'i' || sh2[3] == 'I') &&
157+
sh2[4] != '\0' && (sh2[4] == 'e' || sh2[4] == 'E') &&
158+
sh2[5] != '\0' &&
159+
sh2[6] != '\0' && (sh2[6] == 'e' || sh2[6] == 'E') &&
160+
sh2[7] != '\0' && (sh2[7] == 'n' || sh2[7] == 'N') &&
161+
sh2[8] != '\0' && (sh2[8] == 'd' || sh2[8] == 'D') &&
162+
sh2[9] != '\0' && (sh2[9] == 'i' || sh2[9] == 'I') &&
163+
sh2[10] != '\0' && (sh2[10] == 'n' || sh2[10] == 'N') &&
164+
sh2[11] != '\0' && (sh2[11] == 'g' || sh2[11] == 'G') &&
165+
sh2[12] != '\0' &&
166+
sh2[13] != '\0' && (sh2[13] == 'b' || sh2[13] == 'B') &&
167+
sh2[14] != '\0' && (sh2[14] == 'i' || sh2[14] == 'I') &&
168+
sh2[15] != '\0' && (sh2[15] == 'k' || sh2[15] == 'K'))
167169
{
168170
return true;
169171
}
170-
if ((sh2[0] == 'm' || sh2[0] == 'M') &&
171-
(sh2[1] == 'o' || sh2[1] == 'O') &&
172-
(sh2[2] == 'v' || sh2[2] == 'V') &&
173-
(sh2[3] == 'i' || sh2[3] == 'I') &&
174-
(sh2[4] == 'e' || sh2[4] == 'E') &&
175-
(sh2[6] == 'e' || sh2[6] == 'E') &&
176-
(sh2[7] == 'n' || sh2[7] == 'N') &&
177-
(sh2[8] == 'd' || sh2[8] == 'D') &&
178-
(sh2[10] == 'b' || sh2[10] == 'B') &&
179-
(sh2[11] == 'i' || sh2[11] == 'I') &&
180-
(sh2[12] == 'k' || sh2[12] == 'K'))
172+
if (sh2[0] != '\0' && (sh2[0] == 'm' || sh2[0] == 'M') &&
173+
sh2[1] != '\0' && (sh2[1] == 'o' || sh2[1] == 'O') &&
174+
sh2[2] != '\0' && (sh2[2] == 'v' || sh2[2] == 'V') &&
175+
sh2[3] != '\0' && (sh2[3] == 'i' || sh2[3] == 'I') &&
176+
sh2[4] != '\0' && (sh2[4] == 'e' || sh2[4] == 'E') &&
177+
sh2[5] != '\0' &&
178+
sh2[6] != '\0' && (sh2[6] == 'e' || sh2[6] == 'E') &&
179+
sh2[7] != '\0' && (sh2[7] == 'n' || sh2[7] == 'N') &&
180+
sh2[8] != '\0' && (sh2[8] == 'd' || sh2[8] == 'D') &&
181+
sh2[9] != '\0' &&
182+
sh2[10] != '\0' && (sh2[10] == 'b' || sh2[10] == 'B') &&
183+
sh2[11] != '\0' && (sh2[11] == 'i' || sh2[11] == 'I') &&
184+
sh2[12] != '\0' && (sh2[12] == 'k' || sh2[12] == 'K'))
181185
{
182186
return true;
183187
}
@@ -187,30 +191,32 @@ inline bool isEndVideoPath(T sh2)
187191
template<typename T>
188192
inline DWORD getPicPath(T sh2)
189193
{
190-
if ((sh2[0] == 'p' || sh2[0] == 'P') &&
191-
(sh2[1] == 'i' || sh2[1] == 'I') &&
192-
(sh2[2] == 'c' || sh2[2] == 'C'))
194+
if (sh2[0] != '\0' && (sh2[0] == 'p' || sh2[0] == 'P') &&
195+
sh2[1] != '\0' && (sh2[1] == 'i' || sh2[1] == 'I') &&
196+
sh2[2] != '\0' && (sh2[2] == 'c' || sh2[2] == 'C'))
193197
{
194198
return 3;
195199
}
196-
if ((sh2[0] == 'm' || sh2[0] == 'M') &&
197-
(sh2[1] == 'e' || sh2[1] == 'E') &&
198-
(sh2[2] == 'n' || sh2[2] == 'N') &&
199-
(sh2[3] == 'u' || sh2[3] == 'U') &&
200-
(sh2[5] == 'm' || sh2[5] == 'M') &&
201-
(sh2[6] == 'c' || sh2[6] == 'C'))
200+
if (sh2[0] != '\0' && (sh2[0] == 'm' || sh2[0] == 'M') &&
201+
sh2[1] != '\0' && (sh2[1] == 'e' || sh2[1] == 'E') &&
202+
sh2[2] != '\0' && (sh2[2] == 'n' || sh2[2] == 'N') &&
203+
sh2[3] != '\0' && (sh2[3] == 'u' || sh2[3] == 'U') &&
204+
sh2[4] != '\0' &&
205+
sh2[5] != '\0' && (sh2[5] == 'm' || sh2[5] == 'M') &&
206+
sh2[6] != '\0' && (sh2[6] == 'c' || sh2[6] == 'C'))
202207
{
203208
return 4;
204209
}
205-
if ((sh2[0] == 'e' || sh2[0] == 'E') &&
206-
(sh2[1] == 't' || sh2[1] == 'T') &&
207-
(sh2[2] == 'c' || sh2[2] == 'C') &&
208-
(sh2[4] == 'e' || sh2[4] == 'E') &&
209-
(sh2[5] == 'f' || sh2[5] == 'F') &&
210-
(sh2[6] == 'f' || sh2[6] == 'F') &&
211-
(sh2[7] == 'e' || sh2[7] == 'E') &&
212-
(sh2[8] == 'c' || sh2[8] == 'C') &&
213-
(sh2[9] == 't' || sh2[9] == 'T'))
210+
if (sh2[0] != '\0' && (sh2[0] == 'e' || sh2[0] == 'E') &&
211+
sh2[1] != '\0' && (sh2[1] == 't' || sh2[1] == 'T') &&
212+
sh2[2] != '\0' && (sh2[2] == 'c' || sh2[2] == 'C') &&
213+
sh2[3] != '\0' &&
214+
sh2[4] != '\0' && (sh2[4] == 'e' || sh2[4] == 'E') &&
215+
sh2[5] != '\0' && (sh2[5] == 'f' || sh2[5] == 'F') &&
216+
sh2[6] != '\0' && (sh2[6] == 'f' || sh2[6] == 'F') &&
217+
sh2[7] != '\0' && (sh2[7] == 'e' || sh2[7] == 'E') &&
218+
sh2[8] != '\0' && (sh2[8] == 'c' || sh2[8] == 'C') &&
219+
sh2[9] != '\0' && (sh2[9] == 't' || sh2[9] == 'T'))
214220
{
215221
return 3;
216222
}
@@ -225,14 +231,22 @@ inline T UpdateModPath(T sh2, D str)
225231
return sh2;
226232
}
227233

234+
DWORD StrSize = strlen(sh2);
228235
DWORD padding = 0;
236+
bool isEnding = false;
229237

230238
// Check if data path is found and store location
231239
if (isDataPath(sh2))
232240
{
233241
// Data path found at location '0', do nothing
234242
}
235-
else if (isDataPath(sh2 + modLoc))
243+
else if (StrSize + strlen(ModPath(sh2)) + 4 > MAX_PATH)
244+
{
245+
// Game path is too long
246+
LOG_ONCE(__FUNCTION__ " Error: Game path is too long: '" << sh2 << "'");
247+
return sh2;
248+
}
249+
else if (StrSize > modLoc && isDataPath(sh2 + modLoc))
236250
{
237251
// Data path found at mod location, update padding and initialize
238252
padding = modLoc;
@@ -254,8 +268,11 @@ inline T UpdateModPath(T sh2, D str)
254268
strcpy_s(str + padding + PathLen, MAX_PATH - padding - PathLen, sh2 + padding + 4);
255269

256270
// Handle end.bik/ending.bik (favor end.bik)
257-
if (isEndVideoPath(sh2 + padding + 5))
271+
if ((StrSize > padding + PathLen + 1) && isEndVideoPath(sh2 + padding + PathLen + 1))
258272
{
273+
Logging::Log() << __FUNCTION__ " " << sh2;
274+
isEnding = true;
275+
259276
// Check mod path
260277
strcpy_s(str + padding + PathLen, MAX_PATH - padding - PathLen, GetEnding1(sh2));
261278
if (PathFileExists(str))
@@ -267,20 +284,6 @@ inline T UpdateModPath(T sh2, D str)
267284
{
268285
return str;
269286
}
270-
271-
// Check data path
272-
strcpy_s(str, MAX_PATH, sh2);
273-
strcpy_s(str + padding + 4, MAX_PATH - padding - 4, GetEnding1(sh2));
274-
if (PathFileExists(str))
275-
{
276-
return str;
277-
}
278-
strcpy_s(str + padding + 4, MAX_PATH - padding - 4, GetEnding2(sh2));
279-
if (PathFileExists(str))
280-
{
281-
return str;
282-
}
283-
return sh2;
284287
}
285288

286289
// Handle PS2 low texture mod
@@ -302,6 +305,23 @@ inline T UpdateModPath(T sh2, D str)
302305
}
303306
}
304307

308+
// Handle end.bik/ending.bik (favor end.bik)
309+
if (isEnding)
310+
{
311+
// Check data path
312+
strcpy_s(str, MAX_PATH, sh2);
313+
strcpy_s(str + padding + 4, MAX_PATH - padding - 4, GetEnding1(sh2));
314+
if (PathFileExists(str))
315+
{
316+
return str;
317+
}
318+
strcpy_s(str + padding + 4, MAX_PATH - padding - 4, GetEnding2(sh2));
319+
if (PathFileExists(str))
320+
{
321+
return str;
322+
}
323+
}
324+
305325
return sh2;
306326
}
307327

@@ -669,9 +689,9 @@ void InstallFileSystemHooks()
669689
modLoc = wcslen(tmpPath) + 1;
670690
size_t modLen = strlen(ModPathA);
671691
picLen = strlen(ModPicPathA);
672-
if (modLoc + modLen > MAX_PATH)
692+
if (modLoc + modLen + 42 > MAX_PATH) // Check max length of a file in the game
673693
{
674-
Logging::Log() << __FUNCTION__ " Error: custom mod path length is too long! " << modLoc + modLen;
694+
Logging::Log() << __FUNCTION__ " Error: Game path is too long: " << modLoc + modLen;
675695
DisableFileSystemHooking();
676696
return;
677697
}

Common/Settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ typedef void(__stdcall* NV)(char* name, char* value, void* lpParam);
261261
extern HMODULE m_hModule;
262262
extern bool CustomExeStrSet;
263263
extern bool EnableCustomShaders;
264+
extern bool ShadersReady;
264265
extern bool IsUpdating;
265266
extern bool m_StopThreadFlag;
266267
extern bool AutoScaleImages;

Launcher/Launcher.vcxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
<ConfigurationType>Application</ConfigurationType>
2828
<UseDebugLibraries>false</UseDebugLibraries>
2929
<PlatformToolset>v141_xp</PlatformToolset>
30-
<WholeProgramOptimization>true</WholeProgramOptimization>
3130
<CharacterSet>Unicode</CharacterSet>
3231
</PropertyGroup>
3332
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />

Patches/FullscreenImages.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ bool GetTextureRes(char *TexName, DWORD &TextureX, DWORD &TextureY);
101101

102102
struct ImageCache
103103
{
104-
void *Name;
104+
void *Addr;
105105
BOOL Flag;
106+
std::string Name;
106107
};
107108

108109
std::vector<ImageCache> ScaleList, MapList;
@@ -112,17 +113,20 @@ BOOL CheckTexture()
112113
static BOOL flag = FALSE;
113114
static void *last = nullptr;
114115

115-
if (!TexNameAddr || !*TexNameAddr || last == *TexNameAddr ||
116-
std::any_of(ScaleList.begin(), ScaleList.end(), [](const ImageCache & TexCache) { if (TexCache.Name == *TexNameAddr) { flag = TexCache.Flag; return true; } return false; })
117-
|| strcmp(*TexNameAddr, "data/etc/effect/lens_flare.tbn2") == 0)
116+
if (!TexNameAddr || !*TexNameAddr || strcmp(*TexNameAddr, "data/etc/effect/lens_flare.tbn2") == 0)
117+
{
118+
return FALSE;
119+
}
120+
121+
if (last == *TexNameAddr ||
122+
std::any_of(ScaleList.begin(), ScaleList.end(), [](const ImageCache& TexCache) { if (TexCache.Addr == *TexNameAddr && strcmp(*TexNameAddr, TexCache.Name.c_str()) == 0) { flag = TexCache.Flag; return true; } return false; }))
118123
{
119-
last = (TexNameAddr) ? *TexNameAddr : nullptr;
120124
return flag;
121125
}
122126

123127
flag = (std::any_of(std::begin(DefaultTextureList), std::end(DefaultTextureList), [](const TexSize & TexItem) { return TexItem.IsScaled && strcmp(TexItem.Name, *TexNameAddr) == 0; }));
124128

125-
ScaleList.push_back({ *TexNameAddr , flag });
129+
ScaleList.push_back({ *TexNameAddr, flag, std::string(*TexNameAddr) });
126130
last = *TexNameAddr;
127131

128132
return flag;
@@ -133,17 +137,20 @@ BOOL CheckMapTexture()
133137
static BOOL flag = FALSE;
134138
static void *last = nullptr;
135139

136-
if (!TexNameAddr || !*TexNameAddr || last == *TexNameAddr ||
137-
std::any_of(MapList.begin(), MapList.end(), [](const ImageCache & TexCache) { if (TexCache.Name == *TexNameAddr) { flag = TexCache.Flag; return true; } return false; })
138-
|| strcmp(*TexNameAddr, "data/etc/effect/lens_flare.tbn2") == 0)
140+
if (!TexNameAddr || !*TexNameAddr || strcmp(*TexNameAddr, "data/etc/effect/lens_flare.tbn2") == 0)
141+
{
142+
return FALSE;
143+
}
144+
145+
if (last == *TexNameAddr ||
146+
std::any_of(MapList.begin(), MapList.end(), [](const ImageCache& TexCache) { if (TexCache.Addr == *TexNameAddr && strcmp(*TexNameAddr, TexCache.Name.c_str()) == 0) { flag = TexCache.Flag; return true; } return false; }))
139147
{
140-
last = (TexNameAddr) ? *TexNameAddr : nullptr;
141148
return flag;
142149
}
143150

144151
flag = (std::any_of(std::begin(DefaultTextureList), std::end(DefaultTextureList), [](const TexSize & TexItem) { return TexItem.IsMap && strcmp(TexItem.Name, *TexNameAddr) == 0; }));
145152

146-
MapList.push_back({ *TexNameAddr , flag });
153+
MapList.push_back({ *TexNameAddr, flag, std::string(*TexNameAddr) });
147154
last = *TexNameAddr;
148155

149156
return flag;
@@ -194,9 +201,12 @@ void OnFileLoadTex(LPCSTR lpFileName)
194201
// Runs each time a texture is loaded
195202
void CheckLoadedTexture()
196203
{
197-
CheckingTexture = true;
198-
GetTextureOnLoad();
199-
CheckingTexture = false;
204+
if (!CheckingTexture)
205+
{
206+
CheckingTexture = true;
207+
GetTextureOnLoad();
208+
CheckingTexture = false;
209+
}
200210
}
201211

202212
// ASM function to check texture on load

Patches/FullscreenVideos.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,12 @@ void OnFileLoadVid(LPCSTR lpFileName)
8181
// Check if loading a Game Result save
8282
void UpdateLoadedVideo()
8383
{
84-
CheckingVideo = true;
85-
GetVideoOnLoad();
86-
CheckingVideo = false;
84+
if (!CheckingVideo)
85+
{
86+
CheckingVideo = true;
87+
GetVideoOnLoad();
88+
CheckingVideo = false;
89+
}
8790
}
8891

8992
// ASM function to Fix Game Result Saves

0 commit comments

Comments
 (0)