Palm-Studios / sh3redux

SILENT HILL 3 Engine Remake in OpenGL and C++
GNU General Public License v3.0
164 stars 15 forks source link

types.cpp inaccurately loading file #68

Closed Quaker762 closed 7 years ago

Quaker762 commented 7 years ago

For some reason, this section of code

` for(sh3_arc_section& candidate : c_sections) {

    auto files = candidate.fileList.equal_range(filename);
    if(files.first == end(candidate.fileList))
    {
        continue; // No filename found in this section, continue over
    }
    else // We've found it
    {
        section = &candidate;
        // files.first is the std::map iterator
        // files.first->second is the value of the entry the iterator is pointing at
        index = files.first->second;
        if(next(files.first) != files.second)
        {
            Log(LogLevel::WARN, "Multiple files with name %s exist.", filename.c_str());
        }
        break;
    }
}`

on line 97 in 'types.cpp' incorrectly detects what section the file is in. I've verified that the names and indexes are being mapped correctly (at least I think so), but for some reason this loop detects that a LOT of files are in the tex section when they are definitely not. It also seems it grabs the same index when it does this.

Quaker762 commented 7 years ago

I think this might have something to do with weird string null-terminators. I'm being told I can't open a handle to a section due to this..

Quaker762 commented 7 years ago

So it would seem that loading everything from arc.arc is accurate (as seen in attached log.txt). Therefore this MUST have something to do with actually finding the file in the map, but I can't see anything wrong with the code for it..??

Also note that it complains of multiple files of the same name. log.txt

Quaker762 commented 7 years ago

More strange behaviour, attempting to print out keys and indexes results in this each step. I'm surprised it loads anything when I put a different file name in, this is super weird.

EDIT: Okay, I've done a bit more probing, and it seems like there's an error with c_sections. Stepping through after a call to section.Load() returns a map with the keys all the same.

EDIT EDIT: Okay, there is a serious problem here. The map seems to fuck itself right after the for loop where we map the file name to it's index (section.cpp, line 66-77). When I try to search for the file in the map right after it is inserted, it can't find it. This couldn't possibly be a bug in the c++ runtime, could it??

z33ky commented 7 years ago

More strange behaviour, attempting to print out keys and indexes results in this each step. I'm surprised it loads anything when I put a different file name in, this is super weird.

You're not iterating over the map here, since you don't increment it. Try

for(auto i : candidate.fileList)
{
    std::printf("Path: %s, index: %d\n", i.first.c_str(), i.second);
}

While I'm also getting warnings about duplicates, at least the file "data/eff_tex/fire00_tr.pic" is correctly detected to be in section "tex" and "data/tmp/us11.map" to be in section "bgus". Which file are you trying to load that is mapped to the wrong section? I'm looking further into the duplicate warnings ATM.

Quaker762 commented 7 years ago

You're not iterating over the map here, since you don't increment it.

Lol, I just realised that when I opened the project again after a few drinks.. Alcohol goes in and code comes out I guess..

Which file are you trying to load that is mapped to the wrong section?

Most files. They end up dumping _CATALOG.VIX for some reason, I'm not sure. That or they fail to open at all and just silently fail (returning ARC_FILE_NOT_FOUND).

It would seem that LoadFile() isn't detecting files in the map correctly. I'm not too up to date with STL stuff like iterators, so I'm not too sure if there are any issues.

z33ky commented 7 years ago

69 with the following patch does the right thing for me, i.e. first opens "tex.arc" and then "bgus.arc":

diff --git a/source/main.cpp b/source/main.cpp
index 9be0896..e23c033 100644
--- a/source/main.cpp
+++ b/source/main.cpp
@@ -71,11 +71,12 @@ int main(int argc, char** argv)
     std::printf("%f\n", static_cast<double>(ret.y));

 //    sh3_config config;
-//    sh3_arc arc;
+    sh3_arc arc;
 //
 //    arc.Load();
-//    std::vector<uint8_t> data;
-//    arc.LoadFile("data/eff_tex/fire00_tr.pic", data);
+    std::vector<uint8_t> data;
+    arc.LoadFile("data/eff_tex/fire00_tr.pic", data);
+    arc.LoadFile("data/tmp/us11.map", data);
 //
 //    sh3_window* window = new sh3_window(640, 480, "SILENT HILL 3");
Quaker762 commented 7 years ago

Those two files seem to work. Try opening data/bg/hu/hu22.kg2 and check the output. It loads _CATALOG.VIX for some reason.