diff options
author | Nikolay Korolev <nickvnuk@gmail.com> | 2020-04-13 20:54:25 +0200 |
---|---|---|
committer | Nikolay Korolev <nickvnuk@gmail.com> | 2020-04-13 20:54:25 +0200 |
commit | 3b0cd93f89a9fea54b155fdae15ec56c6291c2cc (patch) | |
tree | e32278de01df4baf561b3966ef239bd045372e60 /src/core/FileLoader.cpp | |
parent | obviously forgot about it (diff) | |
parent | Merge pull request #412 from whampson/save-stuff (diff) | |
download | re3-3b0cd93f89a9fea54b155fdae15ec56c6291c2cc.tar re3-3b0cd93f89a9fea54b155fdae15ec56c6291c2cc.tar.gz re3-3b0cd93f89a9fea54b155fdae15ec56c6291c2cc.tar.bz2 re3-3b0cd93f89a9fea54b155fdae15ec56c6291c2cc.tar.lz re3-3b0cd93f89a9fea54b155fdae15ec56c6291c2cc.tar.xz re3-3b0cd93f89a9fea54b155fdae15ec56c6291c2cc.tar.zst re3-3b0cd93f89a9fea54b155fdae15ec56c6291c2cc.zip |
Diffstat (limited to 'src/core/FileLoader.cpp')
-rw-r--r-- | src/core/FileLoader.cpp | 165 |
1 files changed, 163 insertions, 2 deletions
diff --git a/src/core/FileLoader.cpp b/src/core/FileLoader.cpp index e0c8b01e..e0a0fafc 100644 --- a/src/core/FileLoader.cpp +++ b/src/core/FileLoader.cpp @@ -25,8 +25,6 @@ #include "CdStream.h" #include "FileLoader.h" -WRAPPER void CFileLoader::ReloadPaths(const char *filename) { EAXJMP(0x476DB0); } - char CFileLoader::ms_line[256]; const char* @@ -1198,6 +1196,165 @@ CFileLoader::LoadMapZones(const char *filename) debug("Finished loading IPL\n"); } +void +CFileLoader::ReloadPaths(const char *filename) +{ + enum { + NONE, + PATH, + }; + char *line; + int section = NONE; + int id, pathType, pathIndex = -1; + char pathTypeStr[20]; + debug("Reloading paths from %s...\n", filename); + + int fd = CFileMgr::OpenFile(filename, "r"); + for (line = CFileLoader::LoadLine(fd); line; line = CFileLoader::LoadLine(fd)) { + if (*line == '\0' || *line == '#') + continue; + + if (section == NONE) { + if (strncmp(line, "path", 4) == 0) { + section = PATH; + ThePaths.AllocatePathFindInfoMem(4500); + } + } else if (strncmp(line, "end", 3) == 0) { + section = NONE; + } else { + switch (section) { + case PATH: + if (pathIndex == -1) { + id = LoadPathHeader(line, pathTypeStr); + if (strncmp(pathTypeStr, "ped", 4) == 0) + pathType = 1; + else if (strncmp(pathTypeStr, "car", 4) == 0) + pathType = 0; + pathIndex = 0; + } else { + if (pathType == 1) + LoadPedPathNode(line, id, pathIndex); + else if (pathType == 0) + LoadCarPathNode(line, id, pathIndex); + pathIndex++; + if (pathIndex == 12) + pathIndex = -1; + } + break; + default: + break; + } + } + } + CFileMgr::CloseFile(fd); +} + +void +CFileLoader::ReloadObjectTypes(const char *filename) +{ + enum { + NONE, + OBJS, + TOBJ, + TWODFX + }; + char *line; + int section = NONE; + CModelInfo::ReInit2dEffects(); + debug("Reloading object types from %s...\n", filename); + + CFileMgr::ChangeDir("\\DATA\\MAPS\\"); + int fd = CFileMgr::OpenFile(filename, "r"); + CFileMgr::ChangeDir("\\"); + for (line = CFileLoader::LoadLine(fd); line; line = CFileLoader::LoadLine(fd)) { + if (*line == '\0' || *line == '#') + continue; + + if (section == NONE) { + if (strncmp(line, "objs", 4) == 0) section = OBJS; + else if (strncmp(line, "tobj", 4) == 0) section = TOBJ; + else if (strncmp(line, "2dfx", 4) == 0) section = TWODFX; + } else if (strncmp(line, "end", 3) == 0) { + section = NONE; + } else { + switch (section) { + case OBJS: + case TOBJ: + ReloadObject(line); + break; + case TWODFX: + Load2dEffect(line); + break; + default: + break; + } + } + } + CFileMgr::CloseFile(fd); +} + +void +CFileLoader::ReloadObject(const char *line) +{ + int id, numObjs; + char model[24], txd[24]; + float dist[3]; + uint32 flags; + CSimpleModelInfo *mi; + + if(sscanf(line, "%d %s %s %d", &id, model, txd, &numObjs) != 4) + return; + + switch(numObjs){ + case 1: + sscanf(line, "%d %s %s %d %f %d", + &id, model, txd, &numObjs, &dist[0], &flags); + break; + case 2: + sscanf(line, "%d %s %s %d %f %f %d", + &id, model, txd, &numObjs, &dist[0], &dist[1], &flags); + break; + case 3: + sscanf(line, "%d %s %s %d %f %f %f %d", + &id, model, txd, &numObjs, &dist[0], &dist[1], &dist[2], &flags); + break; + } + + mi = (CSimpleModelInfo*) CModelInfo::GetModelInfo(id); + if ( +#ifdef FIX_BUGS + mi && +#endif + mi->m_type == MITYPE_SIMPLE && !strcmp(mi->GetName(), model) && mi->m_numAtomics == numObjs) { + mi->SetLodDistances(dist); + SetModelInfoFlags(mi, flags); + } else { + printf("Can't reload %s\n", model); + } +} + +// unused mobile function - crashes +void +CFileLoader::ReLoadScene(const char *filename) +{ + char *line; + CFileMgr::ChangeDir("\\DATA\\"); + int fd = CFileMgr::OpenFile(filename, "r"); + CFileMgr::ChangeDir("\\"); + + for (line = CFileLoader::LoadLine(fd); line; line = CFileLoader::LoadLine(fd)) { + if (*line == '#') + continue; + + if (strncmp(line, "EXIT", 9) == 0) // BUG: 9? + break; + + if (strncmp(line, "IDE", 3) == 0) { + LoadObjectTypes(line + 4); + } + } + CFileMgr::CloseFile(fd); +} STARTPATCHES InjectHook(0x476290, CFileLoader::LoadLevel, PATCH_JUMP); @@ -1233,4 +1390,8 @@ STARTPATCHES InjectHook(0x478A90, CFileLoader::LoadCullZone, PATCH_JUMP); InjectHook(0x478550, CFileLoader::LoadMapZones, PATCH_JUMP); + + InjectHook(0x476DB0, CFileLoader::ReloadPaths, PATCH_JUMP); + InjectHook(0x476F30, CFileLoader::ReloadObjectTypes, PATCH_JUMP); + InjectHook(0x4772B0, CFileLoader::ReloadObject, PATCH_JUMP); ENDPATCHES |