ref: 262fcfbaa3f5babe2e6b052752afe42e2be71f40
parent: f39e80efc3a3a0b5b8b23d806e418dc5673cca98
author: Clownacy <Clownacy@users.noreply.github.com>
date: Fri Nov 15 14:44:44 EST 2019
Clean-up Generic.cpp Also applied some windows.h constants over raw values
--- a/src/Ending.cpp
+++ b/src/Ending.cpp
@@ -193,7 +193,7 @@
sprintf(path, "%s\\%s", gDataPath, credit_script);
Credit.size = GetFileSizeLong(path);
- if (Credit.size == -1)
+ if (Credit.size == INVALID_FILE_SIZE)
return FALSE;
// Allocate buffer data
--- a/src/Ending.h
+++ b/src/Ending.h
@@ -6,7 +6,7 @@
struct CREDIT
{
- int size;
+ long size;
char *pData;
int offset;
int wait;
--- a/src/Generic.cpp
+++ b/src/Generic.cpp
@@ -54,42 +54,28 @@
dwLen = GetFileVersionInfoSizeA(path, &dwHandle);
if (dwLen == 0)
- {
-
- }
- else
- {
- lpData = malloc(dwLen);
+ goto fail;
- if (lpData == NULL)
- {
-
- }
- else
- {
- if (!GetFileVersionInfoA(path, 0, dwLen, lpData))
- {
-
- }
- else
- {
- if (!VerQueryValueA(lpData, "\\", (LPVOID*)&lpBuffer, &puLen))
- {
-
- }
- else
- {
- *v1 = (unsigned short)(lpBuffer->dwFileVersionMS >> 16);
- *v2 = (unsigned short)(lpBuffer->dwFileVersionMS & 0xFFFF);
- *v3 = (unsigned short)(lpBuffer->dwFileVersionLS >> 16);
- *v4 = (unsigned short)(lpBuffer->dwFileVersionLS & 0xFFFF);
- bResult = TRUE;
- }
- }
- }
- }
+ lpData = malloc(dwLen);
- if (lpData)
+ if (lpData == NULL)
+ goto fail;
+
+ if (!GetFileVersionInfoA(path, 0, dwLen, lpData))
+ goto fail;
+
+ if (!VerQueryValueA(lpData, "\\", (LPVOID*)&lpBuffer, &puLen))
+ goto fail;
+
+ *v1 = (unsigned short)(lpBuffer->dwFileVersionMS >> 16);
+ *v2 = (unsigned short)(lpBuffer->dwFileVersionMS & 0xFFFF);
+ *v3 = (unsigned short)(lpBuffer->dwFileVersionLS >> 16);
+ *v4 = (unsigned short)(lpBuffer->dwFileVersionLS & 0xFFFF);
+ bResult = TRUE;
+
+fail:
+
+ if (lpData != NULL)
free(lpData);
return bResult;
@@ -213,8 +199,8 @@
if (CompareFileTime(&FileTime2, &FileTime1) <= 0)
return 1; // Return if actual time is higher than system_time_high
- else
- return 0;
+
+ return 0;
}
BOOL CheckFileExists(const char *name)
@@ -241,7 +227,7 @@
hFile = CreateFileA(path, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
- return -1;
+ return INVALID_FILE_SIZE;
len = GetFileSize(hFile, NULL);
CloseHandle(hFile);
@@ -293,13 +279,13 @@
GetWindowRect(hWnd, &window_rect);
parent_hwnd = GetParent(hWnd);
- if (parent_hwnd)
+ if (parent_hwnd != NULL)
GetWindowRect(parent_hwnd, &parent_rect);
else
SystemParametersInfoA(SPI_GETWORKAREA, 0, &parent_rect, 0);
- x = parent_rect.left + (parent_rect.right - parent_rect.left - (window_rect.right - window_rect.left)) / 2;
- y = parent_rect.top + (parent_rect.bottom - parent_rect.top - (window_rect.bottom - window_rect.top)) / 2;
+ x = parent_rect.left + ((parent_rect.right - parent_rect.left) - (window_rect.right - window_rect.left)) / 2;
+ y = parent_rect.top + ((parent_rect.bottom - parent_rect.top) - (window_rect.bottom - window_rect.top)) / 2;
if (x < child_rect.left)
x = child_rect.left;
@@ -307,10 +293,10 @@
if (y < child_rect.top)
y = child_rect.top;
- if (window_rect.right - window_rect.left + x > child_rect.right)
+ if (x + (window_rect.right - window_rect.left) > child_rect.right)
x = child_rect.right - (window_rect.right - window_rect.left);
- if (window_rect.bottom - window_rect.top + y > child_rect.bottom)
+ if (y + (window_rect.bottom - window_rect.top) > child_rect.bottom)
y = child_rect.bottom - (window_rect.bottom - window_rect.top);
return SetWindowPos(hWnd, HWND_TOP, x, y, 0, 0, SWP_NOSIZE);
@@ -334,7 +320,7 @@
sprintf(path, "%s\\%s", gModulePath, filename);
fp = fopen(path, "rb");
- if (fp)
+ if (fp != NULL)
{
fread(&Rect, sizeof(RECT), 1, fp);
fread(&showCmd, sizeof(int), 1, fp);
@@ -348,13 +334,13 @@
min_window_height = GetSystemMetrics(SM_CYMIN);
if (Rect.right - Rect.left < min_window_width)
- Rect.right = min_window_width + Rect.left;
+ Rect.right = Rect.left + min_window_width;
if (Rect.bottom - Rect.top < min_window_height)
- Rect.bottom = min_window_height + Rect.top;
+ Rect.bottom = Rect.top + min_window_height;
if (Rect.right - Rect.left > max_window_width)
- Rect.right = max_window_width + Rect.left;
+ Rect.right = Rect.left + max_window_width;
if (Rect.bottom - Rect.top > max_window_height)
- Rect.bottom = max_window_width + Rect.top;
+ Rect.bottom = Rect.top + max_window_width;
if (Rect.left < pvParam.left)
{
@@ -443,7 +429,7 @@
fread(str, 1, len, fp);
fclose(fp);
- if (memcmp(str, extra_text, len) != 0)
+ if (memcmp(str, extra_text, len))
return FALSE;
else
return TRUE;
--- a/src/NpcTbl.cpp
+++ b/src/NpcTbl.cpp
@@ -19,7 +19,7 @@
size_t size;
size = GetFileSizeLong(path); // TODO - Investigate whether GetFileSizeLong actually returns an unsigned long or not
- if (size == -1)
+ if (size == INVALID_FILE_SIZE)
return FALSE;
num = (int)(size / 0x18);
--- a/src/TextScr.cpp
+++ b/src/TextScr.cpp
@@ -93,7 +93,7 @@
}
// Decrypt .tsc
-void EncryptionBinaryData2(unsigned char *pData, int size)
+void EncryptionBinaryData2(unsigned char *pData, long size)
{
int val1;
int work;
@@ -124,7 +124,7 @@
sprintf(path, "%s\\%s", gDataPath, name);
gTS.size = GetFileSizeLong(path);
- if (gTS.size == -1)
+ if (gTS.size == INVALID_FILE_SIZE)
return FALSE;
// Open file
@@ -154,7 +154,7 @@
sprintf(path, "%s\\%s", gDataPath, "Head.tsc");
long head_size = GetFileSizeLong(path);
- if (head_size == -1)
+ if (head_size == INVALID_FILE_SIZE)
return FALSE;
FILE *fp = fopen(path, "rb");
@@ -171,7 +171,7 @@
sprintf(path, "%s\\%s", gDataPath, name);
long body_size = GetFileSizeLong(path);
- if (body_size == -1)
+ if (body_size == INVALID_FILE_SIZE)
return FALSE;
fp = fopen(path, "rb");
--- a/src/TextScr.h
+++ b/src/TextScr.h
@@ -55,7 +55,7 @@
BOOL InitTextScript2(void);
void EndTextScript(void);
-void EncryptionBinaryData2(unsigned char *pData, int size);
+void EncryptionBinaryData2(unsigned char *pData, long size);
BOOL LoadTextScript2(const char *name);
BOOL LoadTextScript_Stage(const char *name);
void GetTextScriptPath(char *path);