Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
secsome committed Oct 16, 2021
2 parents e7b13ca + 9512e71 commit 521f13d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 50 deletions.
2 changes: 1 addition & 1 deletion FA2pp
Submodule FA2pp updated 2 files
+4 −4 FAMemory.h
+19 −13 FunctionInit.cpp
8 changes: 4 additions & 4 deletions FA2sp/FA2sp.Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

constexpr int PRODUCT_MAJOR = 1;
constexpr int PRODUCT_MINOR = 1;
constexpr int PRODUCT_REVISION = 1;
constexpr char* PRODUCT_STR = "1.1.1";
constexpr int PRODUCT_REVISION = 2;
constexpr char* PRODUCT_STR = "1.1.2";
constexpr char* DISPLAY_STR = PRODUCT_STR;
constexpr char* VERSION_STRVER = "FA2sp 1.1.1";
constexpr char* VERSION_STRVER = "FA2sp 1.1.2";

constexpr char* PRODUCT_NAME = "FA2sp";
constexpr char* APPLY_INFO = "Found Final Alert 2 version 1.02. Applying FA2sp 1.1.1.";
constexpr char* APPLY_INFO = "Found Final Alert 2 version 1.02. Applying FA2sp 1.1.2.";
// constexpr char* APPLY_INFO = "Found Final Alert 2 version 1.02. Applying FA2sp - " __DATE__ " - " __TIME__;

constexpr char* MUTEX_HASH_VAL = "b8097bca8590a4f46c975ebb43503aab2243ce7f1c87f12f7984dbe1";
Expand Down
60 changes: 32 additions & 28 deletions FA2sp/Miscs/Hooks.SaveMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "../FA2sp.Constants.h"

#include <map>
#include <sstream>
#include <fstream>

// FA2 SaveMap is almost O(N^4), who wrote that?
DEFINE_HOOK(428D97, CFinalSunDlg_SaveMap, 7)
Expand Down Expand Up @@ -54,31 +54,35 @@ DEFINE_HOOK(428D97, CFinalSunDlg_SaveMap, 7)

Logger::Debug("Trying to save map to %s\n", filepath);

CloseHandle(
CreateFile(filepath, GENERIC_WRITE, NULL, nullptr, TRUNCATE_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN | FILE_ATTRIBUTE_NORMAL, NULL)
);
auto hFile = CreateFile(filepath, GENERIC_WRITE, NULL, nullptr, CREATE_ALWAYS, FILE_FLAG_SEQUENTIAL_SCAN | FILE_ATTRIBUTE_NORMAL, NULL);

std::stringstream ss;
ss <<
"; Map created with FinalAlert 2(tm) Mission Editor\n"
"; Get it at http://www.westwood.com\n"
"; note that all comments were truncated\n"
"\n"
"; This FA2 uses FA2sp created by secsome\n"
"; Get the lastest dll at https://github.com/secsome/FA2sp\n"
"; Current version : " << PRODUCT_STR << "\n\n";

for (auto& section : pINI->Dict)
std::ofstream fout;
fout.open(filepath, std::ios::out | std::ios::trunc);

if (fout.is_open())
{
ss << "[" << section.first << "]\n";
for (auto& pair : section.second.EntitiesDictionary)
ss << pair.first << "=" << pair.second << "\n";
ss << "\n";
}
fout <<
"; Map created with FinalAlert 2(tm) Mission Editor\n"
"; Get it at http://www.westwood.com\n"
"; note that all comments were truncated\n"
"\n"
"; This FA2 uses FA2sp created by secsome\n"
"; Get the lastest dll at https://github.com/secsome/FA2sp\n"
"; Current version : " << PRODUCT_STR << "\n\n";

for (auto& section : pINI->Dict)
{
fout << "[" << section.first << "]\n";
for (auto& pair : section.second.EntitiesDictionary)
fout << pair.first << "=" << pair.second << "\n";
fout << "\n";
}

WriteFile(hFile, ss.str().c_str(), ss.str().length(), nullptr, nullptr);
CloseHandle(hFile);
fout.close();
}
else
{
FA2sp::Buffer.Format("Failed to create file %s.\n", filepath);
::MessageBox(NULL, FA2sp::Buffer, "Error", MB_OK | MB_ICONERROR);
}

return 0x42A859;
}
Expand All @@ -103,11 +107,11 @@ DEFINE_HOOK(42A8F5, CFinalSunDlg_SaveMap_ReplaceCopyFile, 7)

REF_STACK(ppmfc::CString, filepath, STACK_OFFS(0x3F4, -0x4));

HANDLE hFile =
CreateFile(filepath, GENERIC_READ, NULL, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE)
std::ifstream fin;
fin.open(filepath, std::ios::in | std::ios::binary);
if (fin.is_open())
{
CloseHandle(hFile);
fin.close();
return 0x42A92D;
}
return 0x42A911;
Expand Down
38 changes: 21 additions & 17 deletions FA2sp/Miscs/Hooks.Stringtables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../FA2sp.h"

#include <map>
#include <fstream>

class StringtableLoader
{
Expand Down Expand Up @@ -185,17 +186,17 @@ void StringtableLoader::WriteCSFFile()
char tmpCsfFile[0x400];
strcpy_s(tmpCsfFile, CFinalSunApp::ExePath());
strcat_s(tmpCsfFile, "\\RA2Tmp.csf");
HANDLE hFile = CreateFile(tmpCsfFile, GENERIC_WRITE, FILE_SHARE_WRITE, nullptr,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (hFile == INVALID_HANDLE_VALUE)
std::ofstream fout;
fout.open(tmpCsfFile, std::ios::out | std::ios::trunc | std::ios::binary);
if (!fout.is_open())
return;

auto write_to_stream = [&hFile](const void* buffer, size_t size = 4) {
WriteFile(hFile, buffer, size, nullptr, nullptr);
auto write_to_stream = [&fout](const void* buffer, size_t size = 4) {
fout.write((char*)buffer, size);
};

auto write_int = [&hFile](int n) {
WriteFile(hFile, &n, 4, nullptr, nullptr);
auto write_int = [&fout](int n) {
fout.write((char*)&n, 4);
};

// CSF header
Expand Down Expand Up @@ -229,27 +230,30 @@ void StringtableLoader::WriteCSFFile()
write_to_stream(buffer, valueBufferSize << 1);
delete[] value;
}
CloseHandle(hFile);
fout.close();
}

bool StringtableLoader::LoadToBuffer()
{
HANDLE hFile = INVALID_HANDLE_VALUE;
char directoryBuffer[0x400];
strcpy_s(directoryBuffer, CFinalSunApp::ExePath());
strcat_s(directoryBuffer, "\\");
strcat_s(directoryBuffer, "RA2Tmp.csf");
hFile = CreateFile(directoryBuffer, GENERIC_READ, FILE_SHARE_READ, nullptr,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
if (hFile != INVALID_HANDLE_VALUE)
std::ifstream fin;
fin.open(directoryBuffer, std::ios::in | std::ios::binary);
if (fin.is_open())
{
DWORD dwFileSize = GetFileSize(hFile, nullptr);
StringtableLoader::pEDIBuffer = GameCreateArray<char>(dwFileSize);
fin.seekg(0, std::ios::end);
const int size = static_cast<int>(fin.tellg());
if (size == 0)
return false;
fin.seekg(0, std::ios::beg);
StringtableLoader::pEDIBuffer = GameCreateArray<char>(size);
bool result = false;
if (StringtableLoader::pEDIBuffer)
result = ReadFile(hFile, StringtableLoader::pEDIBuffer, dwFileSize, nullptr, nullptr);
CloseHandle(hFile);
return result;
fin.read(StringtableLoader::pEDIBuffer, size);
fin.close();
return true;
}
return false;
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Compile Using C++ Standard Now: C++14
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~////////// FINALALERT2 - SP CHANGELOG //////////~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\\\\\//////////////////////////////////////\\\\\~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

======================= Changes (2021-10-16 RELEASE 1.1.2) ==============================================================================================
*) Fixed the bug that FA2sp crashes while trying to read/write file on some systems

======================= Changes (2021-10-12 RELEASE 1.1.1) ==============================================================================================
*) Minor bugfixes
*) Now FA2sp will apply Visual Style depending on your system instead of keeping them look like Windows95 style
Expand Down

0 comments on commit 521f13d

Please sign in to comment.