UnofficialCrusaderPatch / UnofficialCrusaderPatch3

Development for the dll Injection approach
GNU General Public License v3.0
11 stars 1 forks source link

[MODULES/FILES] scenario map file iteration not done correctly #50

Closed gynt closed 1 year ago

gynt commented 1 year ago

Noticed when trying to create the Christmas Calendar map See the Door01.map

gynt commented 1 year ago

The file is noticed in the folder, but it is simply not loaded properly and can't be played.

TheRedDaemon commented 1 year ago

I doubt it, but is this in any way related to #51?

I do not know how your Iteration and Map loading API functions, but could it be that the path is to long/ill-formed? I remember the Resource Load API doing some stuff. But I am unsure if it had any "length" restriction (if it is 1001, I do not consider this as a restriction.)

gynt commented 1 year ago

Good question. I need to debug this while the game is running, which is not something I am looking forward to right now. The game's maploading system is very weird, I am slowly starting to understand it. Map names are unique, you can't have more maps with the same name, so it is centered around that. At game start (and when saving maps/savs) it gets a list of all map names. And then when you load a menu, it goes through the list again to see where the map lives: in maps/ or in %user%/Documents/Stronghold Crusader/maps

I am hooking the FindFirstFileA and FindNextFileA windows functions to provide extra folders that are iterated through. So when the game browses through maps/* and thinks it arrived at the last file, I say, look here is more files.

The error described here ocurred with disable-game-maps: true amd disable-user-maps: true, so maybe that gave rise to the issue. If that is the case, it is a lua implementation problem that can be fixed without looking at the game code.

If it is something else, I think I should check whether the game's file_open actually opens the right file, or if I am intercepting that call correctly even!

@TheRedDaemon how are map files handled in the overrides part of the files module? Do you think I am unto something?

TheRedDaemon commented 1 year ago

I actually am a bit confused now looking at the override code. Almost everything would need to go through file open... but I decided to handle most stuff in loadResource (which should be renamed one day btw, since it more or less only makes a resource string "current" and appends certain parts). I think I decided to let this be the "base" and the other parts be exceptions. I think part of the reason was that a lot of files are opened via other dlls, which made the loadResource more interesting.

Anyway, Map files are currently handled via the loadResource hook. They are first processed via the normal function and then the replace check is applied. What I do not know (since the code uses a C++-String, where I failed to replicate the structure) is, what actually happens if the file is not found in the map folder. It does something else.

Maybe also important: The override uses three entries:

gynt commented 1 year ago

I will investigate.

I am tempted to delve into this and improve stuff where necessary! I did some io related stuff when looking into the plugins as zip file situation. Maybe I write part of it in C++ and use modern io handling. But then I need to understand the game, so not sure if it really helps, it does get rid of the very ugly hacks with FindFirstFileA, etc.

gynt commented 1 year ago

Solved by #53