Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/engine/N3Base/N3ShapeMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ void CN3ShapeMgr::ReleaseShapes() {
bool CN3ShapeMgr::Load(HANDLE hFile) {
DWORD dwRWC;
int nL = 0;

int TempVersion, TempIntStringLength;
ReadFile(hFile, &(TempVersion), sizeof(int), &dwRWC, NULL); // Read the map version
ReadFile(hFile, &(TempIntStringLength), sizeof(int), &dwRWC, NULL); // Read the map name char length
CHAR * TempOPDMapNamebuffer = new CHAR[TempIntStringLength / sizeof(char) + 1]{}; // Zero-initialized
ReadFile(hFile, TempOPDMapNamebuffer, TempIntStringLength, &dwRWC, NULL); // Now read it and push it back to the OPDMapName char buffer

if (false == LoadCollisionData(hFile)) {
return false;
}
Expand Down
5 changes: 5 additions & 0 deletions src/game/N3Terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,11 @@ bool CN3Terrain::Load(HANDLE hFile) {
}

DWORD dwRWC;
int TempVersion, TempIntStringLength;
ReadFile(hFile, &(TempVersion), sizeof(int), &dwRWC, NULL); // Read the map version
ReadFile(hFile, &(TempIntStringLength), sizeof(int), &dwRWC, NULL); // Read the map name char length
CHAR * TempGTDMapNamebuffer = new CHAR[TempIntStringLength / sizeof(char) + 1]{}; // Zero-initialized

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few things to point out here:

  1. Not sure why we're using Windows' CHAR here instead of just char
  2. If this is to be allocated on the heap, it might as well just use std::string like everything else (or well, that aren't the silly std::vector<char> implementations). As it is, it's just leaking memory.
  3. The naming here is a bit strange. Why TempVersion etc as opposed to MapVersion or some such, specifically: why are we referring to them as temporary vars?
    On this note, the version is being thrown away here -- when it in fact needs to be used by CN3Pond, which leads me to my next point:
  4. This is incomplete -- CN3Pond will fail to read its portion of the file correctly, as it is the only other thing updated in this version. Specifically for versions 2+ (which 1.264 does support), which is why it needs to use the version from here.

ReadFile(hFile, TempGTDMapNamebuffer, TempIntStringLength, &dwRWC, NULL); // Now read it and push it back to the GTDMapName char buffer
ReadFile(hFile, &(m_ti_MapSize), sizeof(int), &dwRWC, NULL);
m_pat_MapSize = (m_ti_MapSize - 1) / PATCH_TILE_SIZE;

Expand Down