Skip to content

Commit

Permalink
Fix some issues
Browse files Browse the repository at this point in the history
 - Soft Shadow misplaced
 - Ending video not working
 - Shaders fix after changing resolutions
 - Log Direct3D8 errors
 - Additional error checking and code fixes
  • Loading branch information
elishacloud committed Nov 2, 2022
1 parent 6ebdf23 commit 550e4a8
Show file tree
Hide file tree
Showing 14 changed files with 270 additions and 158 deletions.
2 changes: 2 additions & 0 deletions Common/AutoUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ bool NewProjectReleaseAvailable(std::string &path_str)
}

if (IsProjectUpdateAvailable)
{
return true;
}
}

return false;
Expand Down
150 changes: 85 additions & 65 deletions Common/FileSystemHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ inline bool isInString(LPCWSTR strCheck, LPCSTR, LPCWSTR strW, size_t size)
template<typename T>
inline bool isDataPath(T sh2)
{
if ((sh2[0] == 'd' || sh2[0] == 'D') &&
(sh2[1] == 'a' || sh2[1] == 'A') &&
(sh2[2] == 't' || sh2[2] == 'T') &&
(sh2[3] == 'a' || sh2[3] == 'A'))
if (sh2[0] != '\0' && (sh2[0] == 'd' || sh2[0] == 'D') &&
sh2[1] != '\0' && (sh2[1] == 'a' || sh2[1] == 'A') &&
sh2[2] != '\0' && (sh2[2] == 't' || sh2[2] == 'T') &&
sh2[3] != '\0' && (sh2[3] == 'a' || sh2[3] == 'A'))
{
return true;
}
Expand All @@ -150,34 +150,38 @@ inline bool isDataPath(T sh2)
template<typename T>
inline bool isEndVideoPath(T sh2)
{
if ((sh2[0] == 'm' || sh2[0] == 'M') &&
(sh2[1] == 'o' || sh2[1] == 'O') &&
(sh2[2] == 'v' || sh2[2] == 'V') &&
(sh2[3] == 'i' || sh2[3] == 'I') &&
(sh2[4] == 'e' || sh2[4] == 'E') &&
(sh2[6] == 'e' || sh2[6] == 'E') &&
(sh2[7] == 'n' || sh2[7] == 'N') &&
(sh2[8] == 'd' || sh2[8] == 'D') &&
(sh2[9] == 'i' || sh2[9] == 'I') &&
(sh2[10] == 'n' || sh2[10] == 'N') &&
(sh2[11] == 'g' || sh2[11] == 'G') &&
(sh2[13] == 'b' || sh2[13] == 'B') &&
(sh2[14] == 'i' || sh2[14] == 'I') &&
(sh2[15] == 'k' || sh2[15] == 'K'))
if (sh2[0] != '\0' && (sh2[0] == 'm' || sh2[0] == 'M') &&
sh2[1] != '\0' && (sh2[1] == 'o' || sh2[1] == 'O') &&
sh2[2] != '\0' && (sh2[2] == 'v' || sh2[2] == 'V') &&
sh2[3] != '\0' && (sh2[3] == 'i' || sh2[3] == 'I') &&
sh2[4] != '\0' && (sh2[4] == 'e' || sh2[4] == 'E') &&
sh2[5] != '\0' &&
sh2[6] != '\0' && (sh2[6] == 'e' || sh2[6] == 'E') &&
sh2[7] != '\0' && (sh2[7] == 'n' || sh2[7] == 'N') &&
sh2[8] != '\0' && (sh2[8] == 'd' || sh2[8] == 'D') &&
sh2[9] != '\0' && (sh2[9] == 'i' || sh2[9] == 'I') &&
sh2[10] != '\0' && (sh2[10] == 'n' || sh2[10] == 'N') &&
sh2[11] != '\0' && (sh2[11] == 'g' || sh2[11] == 'G') &&
sh2[12] != '\0' &&
sh2[13] != '\0' && (sh2[13] == 'b' || sh2[13] == 'B') &&
sh2[14] != '\0' && (sh2[14] == 'i' || sh2[14] == 'I') &&
sh2[15] != '\0' && (sh2[15] == 'k' || sh2[15] == 'K'))
{
return true;
}
if ((sh2[0] == 'm' || sh2[0] == 'M') &&
(sh2[1] == 'o' || sh2[1] == 'O') &&
(sh2[2] == 'v' || sh2[2] == 'V') &&
(sh2[3] == 'i' || sh2[3] == 'I') &&
(sh2[4] == 'e' || sh2[4] == 'E') &&
(sh2[6] == 'e' || sh2[6] == 'E') &&
(sh2[7] == 'n' || sh2[7] == 'N') &&
(sh2[8] == 'd' || sh2[8] == 'D') &&
(sh2[10] == 'b' || sh2[10] == 'B') &&
(sh2[11] == 'i' || sh2[11] == 'I') &&
(sh2[12] == 'k' || sh2[12] == 'K'))
if (sh2[0] != '\0' && (sh2[0] == 'm' || sh2[0] == 'M') &&
sh2[1] != '\0' && (sh2[1] == 'o' || sh2[1] == 'O') &&
sh2[2] != '\0' && (sh2[2] == 'v' || sh2[2] == 'V') &&
sh2[3] != '\0' && (sh2[3] == 'i' || sh2[3] == 'I') &&
sh2[4] != '\0' && (sh2[4] == 'e' || sh2[4] == 'E') &&
sh2[5] != '\0' &&
sh2[6] != '\0' && (sh2[6] == 'e' || sh2[6] == 'E') &&
sh2[7] != '\0' && (sh2[7] == 'n' || sh2[7] == 'N') &&
sh2[8] != '\0' && (sh2[8] == 'd' || sh2[8] == 'D') &&
sh2[9] != '\0' &&
sh2[10] != '\0' && (sh2[10] == 'b' || sh2[10] == 'B') &&
sh2[11] != '\0' && (sh2[11] == 'i' || sh2[11] == 'I') &&
sh2[12] != '\0' && (sh2[12] == 'k' || sh2[12] == 'K'))
{
return true;
}
Expand All @@ -187,30 +191,32 @@ inline bool isEndVideoPath(T sh2)
template<typename T>
inline DWORD getPicPath(T sh2)
{
if ((sh2[0] == 'p' || sh2[0] == 'P') &&
(sh2[1] == 'i' || sh2[1] == 'I') &&
(sh2[2] == 'c' || sh2[2] == 'C'))
if (sh2[0] != '\0' && (sh2[0] == 'p' || sh2[0] == 'P') &&
sh2[1] != '\0' && (sh2[1] == 'i' || sh2[1] == 'I') &&
sh2[2] != '\0' && (sh2[2] == 'c' || sh2[2] == 'C'))
{
return 3;
}
if ((sh2[0] == 'm' || sh2[0] == 'M') &&
(sh2[1] == 'e' || sh2[1] == 'E') &&
(sh2[2] == 'n' || sh2[2] == 'N') &&
(sh2[3] == 'u' || sh2[3] == 'U') &&
(sh2[5] == 'm' || sh2[5] == 'M') &&
(sh2[6] == 'c' || sh2[6] == 'C'))
if (sh2[0] != '\0' && (sh2[0] == 'm' || sh2[0] == 'M') &&
sh2[1] != '\0' && (sh2[1] == 'e' || sh2[1] == 'E') &&
sh2[2] != '\0' && (sh2[2] == 'n' || sh2[2] == 'N') &&
sh2[3] != '\0' && (sh2[3] == 'u' || sh2[3] == 'U') &&
sh2[4] != '\0' &&
sh2[5] != '\0' && (sh2[5] == 'm' || sh2[5] == 'M') &&
sh2[6] != '\0' && (sh2[6] == 'c' || sh2[6] == 'C'))
{
return 4;
}
if ((sh2[0] == 'e' || sh2[0] == 'E') &&
(sh2[1] == 't' || sh2[1] == 'T') &&
(sh2[2] == 'c' || sh2[2] == 'C') &&
(sh2[4] == 'e' || sh2[4] == 'E') &&
(sh2[5] == 'f' || sh2[5] == 'F') &&
(sh2[6] == 'f' || sh2[6] == 'F') &&
(sh2[7] == 'e' || sh2[7] == 'E') &&
(sh2[8] == 'c' || sh2[8] == 'C') &&
(sh2[9] == 't' || sh2[9] == 'T'))
if (sh2[0] != '\0' && (sh2[0] == 'e' || sh2[0] == 'E') &&
sh2[1] != '\0' && (sh2[1] == 't' || sh2[1] == 'T') &&
sh2[2] != '\0' && (sh2[2] == 'c' || sh2[2] == 'C') &&
sh2[3] != '\0' &&
sh2[4] != '\0' && (sh2[4] == 'e' || sh2[4] == 'E') &&
sh2[5] != '\0' && (sh2[5] == 'f' || sh2[5] == 'F') &&
sh2[6] != '\0' && (sh2[6] == 'f' || sh2[6] == 'F') &&
sh2[7] != '\0' && (sh2[7] == 'e' || sh2[7] == 'E') &&
sh2[8] != '\0' && (sh2[8] == 'c' || sh2[8] == 'C') &&
sh2[9] != '\0' && (sh2[9] == 't' || sh2[9] == 'T'))
{
return 3;
}
Expand All @@ -225,14 +231,22 @@ inline T UpdateModPath(T sh2, D str)
return sh2;
}

DWORD StrSize = strlen(sh2);
DWORD padding = 0;
bool isEnding = false;

// Check if data path is found and store location
if (isDataPath(sh2))
{
// Data path found at location '0', do nothing
}
else if (isDataPath(sh2 + modLoc))
else if (StrSize + strlen(ModPath(sh2)) + 4 > MAX_PATH)
{
// Game path is too long
LOG_ONCE(__FUNCTION__ " Error: Game path is too long: '" << sh2 << "'");
return sh2;
}
else if (StrSize > modLoc && isDataPath(sh2 + modLoc))
{
// Data path found at mod location, update padding and initialize
padding = modLoc;
Expand All @@ -254,8 +268,11 @@ inline T UpdateModPath(T sh2, D str)
strcpy_s(str + padding + PathLen, MAX_PATH - padding - PathLen, sh2 + padding + 4);

// Handle end.bik/ending.bik (favor end.bik)
if (isEndVideoPath(sh2 + padding + 5))
if ((StrSize > padding + PathLen + 1) && isEndVideoPath(sh2 + padding + PathLen + 1))
{
Logging::Log() << __FUNCTION__ " " << sh2;
isEnding = true;

// Check mod path
strcpy_s(str + padding + PathLen, MAX_PATH - padding - PathLen, GetEnding1(sh2));
if (PathFileExists(str))
Expand All @@ -267,20 +284,6 @@ inline T UpdateModPath(T sh2, D str)
{
return str;
}

// Check data path
strcpy_s(str, MAX_PATH, sh2);
strcpy_s(str + padding + 4, MAX_PATH - padding - 4, GetEnding1(sh2));
if (PathFileExists(str))
{
return str;
}
strcpy_s(str + padding + 4, MAX_PATH - padding - 4, GetEnding2(sh2));
if (PathFileExists(str))
{
return str;
}
return sh2;
}

// Handle PS2 low texture mod
Expand All @@ -302,6 +305,23 @@ inline T UpdateModPath(T sh2, D str)
}
}

// Handle end.bik/ending.bik (favor end.bik)
if (isEnding)
{
// Check data path
strcpy_s(str, MAX_PATH, sh2);
strcpy_s(str + padding + 4, MAX_PATH - padding - 4, GetEnding1(sh2));
if (PathFileExists(str))
{
return str;
}
strcpy_s(str + padding + 4, MAX_PATH - padding - 4, GetEnding2(sh2));
if (PathFileExists(str))
{
return str;
}
}

return sh2;
}

Expand Down Expand Up @@ -669,9 +689,9 @@ void InstallFileSystemHooks()
modLoc = wcslen(tmpPath) + 1;
size_t modLen = strlen(ModPathA);
picLen = strlen(ModPicPathA);
if (modLoc + modLen > MAX_PATH)
if (modLoc + modLen + 42 > MAX_PATH) // Check max length of a file in the game
{
Logging::Log() << __FUNCTION__ " Error: custom mod path length is too long! " << modLoc + modLen;
Logging::Log() << __FUNCTION__ " Error: Game path is too long: " << modLoc + modLen;
DisableFileSystemHooking();
return;
}
Expand Down
1 change: 1 addition & 0 deletions Common/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ typedef void(__stdcall* NV)(char* name, char* value, void* lpParam);
extern HMODULE m_hModule;
extern bool CustomExeStrSet;
extern bool EnableCustomShaders;
extern bool ShadersReady;
extern bool IsUpdating;
extern bool m_StopThreadFlag;
extern bool AutoScaleImages;
Expand Down
1 change: 0 additions & 1 deletion Launcher/Launcher.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
Expand Down
38 changes: 24 additions & 14 deletions Patches/FullscreenImages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ bool GetTextureRes(char *TexName, DWORD &TextureX, DWORD &TextureY);

struct ImageCache
{
void *Name;
void *Addr;
BOOL Flag;
std::string Name;
};

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

if (!TexNameAddr || !*TexNameAddr || last == *TexNameAddr ||
std::any_of(ScaleList.begin(), ScaleList.end(), [](const ImageCache & TexCache) { if (TexCache.Name == *TexNameAddr) { flag = TexCache.Flag; return true; } return false; })
|| strcmp(*TexNameAddr, "data/etc/effect/lens_flare.tbn2") == 0)
if (!TexNameAddr || !*TexNameAddr || strcmp(*TexNameAddr, "data/etc/effect/lens_flare.tbn2") == 0)
{
return FALSE;
}

if (last == *TexNameAddr ||
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; }))
{
last = (TexNameAddr) ? *TexNameAddr : nullptr;
return flag;
}

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

ScaleList.push_back({ *TexNameAddr , flag });
ScaleList.push_back({ *TexNameAddr, flag, std::string(*TexNameAddr) });
last = *TexNameAddr;

return flag;
Expand All @@ -133,17 +137,20 @@ BOOL CheckMapTexture()
static BOOL flag = FALSE;
static void *last = nullptr;

if (!TexNameAddr || !*TexNameAddr || last == *TexNameAddr ||
std::any_of(MapList.begin(), MapList.end(), [](const ImageCache & TexCache) { if (TexCache.Name == *TexNameAddr) { flag = TexCache.Flag; return true; } return false; })
|| strcmp(*TexNameAddr, "data/etc/effect/lens_flare.tbn2") == 0)
if (!TexNameAddr || !*TexNameAddr || strcmp(*TexNameAddr, "data/etc/effect/lens_flare.tbn2") == 0)
{
return FALSE;
}

if (last == *TexNameAddr ||
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; }))
{
last = (TexNameAddr) ? *TexNameAddr : nullptr;
return flag;
}

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

MapList.push_back({ *TexNameAddr , flag });
MapList.push_back({ *TexNameAddr, flag, std::string(*TexNameAddr) });
last = *TexNameAddr;

return flag;
Expand Down Expand Up @@ -194,9 +201,12 @@ void OnFileLoadTex(LPCSTR lpFileName)
// Runs each time a texture is loaded
void CheckLoadedTexture()
{
CheckingTexture = true;
GetTextureOnLoad();
CheckingTexture = false;
if (!CheckingTexture)
{
CheckingTexture = true;
GetTextureOnLoad();
CheckingTexture = false;
}
}

// ASM function to check texture on load
Expand Down
9 changes: 6 additions & 3 deletions Patches/FullscreenVideos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ void OnFileLoadVid(LPCSTR lpFileName)
// Check if loading a Game Result save
void UpdateLoadedVideo()
{
CheckingVideo = true;
GetVideoOnLoad();
CheckingVideo = false;
if (!CheckingVideo)
{
CheckingVideo = true;
GetVideoOnLoad();
CheckingVideo = false;
}
}

// ASM function to Fix Game Result Saves
Expand Down
Loading

0 comments on commit 550e4a8

Please sign in to comment.