Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method to determine if module is loaded #69

Closed
DanRStevens opened this issue Apr 16, 2019 · 5 comments

Comments

Projects
None yet
2 participants
@DanRStevens
Copy link
Member

commented Apr 16, 2019

Some levels may be dependent on a module being loaded, such as an alternate rule set for the game. Perhaps these levels could be given a method to determine if a given module is loaded, or to retrieve a list of loaded modules.

This is something Crow was recently looking for. Such functionality seems most related to op2ext, as it controls which modules get loaded.

@Brett208

This comment has been minimized.

Copy link
Member

commented Apr 17, 2019

This would be helpful for multitek2 as well. I guess the user would have to include op2ext in their mission project (or at least the public header) My first stab would be:

// Returns the number of loaded modules (.ini and console combined)
OP2EXT_API size_t GetLoadedModuleCount();


// Retrieves the module name at the specified index. Use function GetLoadedModuleCount to determine how many module names to check. 
// A console module's name is the name of the directory the console module is stored in.
// An ini module name is the module's [section name] within the ini file
// Returns 0 on success. Returns the required minimum size of the buffer on failure.
// If an index beyond the loaded module count is passed, returns 0 and clears the buffer.
OP2EXT_API size_t GetLoadedModuleName(size_t moduleIndex, char* buffer, size_t bufferSize);
@DanRStevens

This comment has been minimized.

Copy link
Member Author

commented Apr 17, 2019

That looks like it could work.

Should be generic enough to implement whatever methods are needed. Not sure if we want to go there, but we could potentially also have a method to query if a specific module is loaded. That may be what people really want, though the above implementation is more generic with a greater number of use cases.

@Brett208

This comment has been minimized.

Copy link
Member

commented Apr 17, 2019

In addition to the 2 functions above, we could add:

 #include <stdbool.h>

// Performs a case insensitive search of loaded module names, returning true if found.
// A console module's name is the name of the directory the console module is stored in.
// An ini module name is the module's [section name] within the ini file.
OP2EXT_API bool IsModuleLoaded(char* moduleName);
@DanRStevens

This comment has been minimized.

Copy link
Member Author

commented Apr 18, 2019

What happens if an ini section name matches a console module's directory name? I don't believe we keep any kind of tracking information around about what is loaded, or how it was loaded.

From a caller perspective, do we need to differentiate between the module types? They are rather incompatible, so maybe we should. That might apply to both sets of methods.

@Brett208

This comment has been minimized.

Copy link
Member

commented Apr 18, 2019

The console module loader and .ini module loader do not talk. So you could load a .ini and console module with the exact same name. Practically speaking I would discourage this behaviour. Not sure it is worth preventing/fixing as it never occurred to me to try in practice, nor have I heard anyone attempting. We could add a check to see if the module is already loaded internal to op2ext to prevent. Although that would maybe be best as a separate issue from this.

Perhaps we could have 3 functions to check if loaded:

#include<stdbool.h>

// Performs a case insensitive search of loaded module names, returning true if found.
// A console module's name is the name of the directory the console module is stored in.
// An ini module name is the module's [section name] within the ini file.
OP2EXT_API bool IsModuleLoaded(const char* moduleName);

// Performs a case insensitive comparison of the loaded console module name.
// A console module's name is the name of the directory the console module is stored in.
OP2EXT_API bool IsConsoleModuleLoaded(const char* moduleName);

// Performs a case insensitive search of loaded ini module names, returning true if found.
// An ini module name is the module's [section name] within the ini file.
OP2EXT_API bool IsIniModuleLoaded(const char* moduleName);

// Returns the number of loaded modules (.ini and console combined)
OP2EXT_API size_t GetLoadedModuleCount();

// Retrieves the module name at the specified index. Use function GetLoadedModuleCount to determine how many module names to check. 
// A console module's name is the name of the directory the console module is stored in.
// An ini module name is the module's [section name] within the ini file
// Returns 0 on success. Returns the required minimum size of the buffer on failure.
// If an index beyond the loaded module count is passed, returns 0 and clears the buffer.
OP2EXT_API size_t GetLoadedModuleName(size_t moduleIndex, const char* buffer, size_t bufferSize);

If you don't care, just call IsModuleLoaded, if you need to know which way it was loaded, use one of the other two functions.

-Brett

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.