-
Notifications
You must be signed in to change notification settings - Fork 1
cm3d2.dll API
CM3D2.dll recognizes two filesystem types: Windows (0
) and Archive (1
).
Externally, a filesystem is a struct:
struct FileSystem {
int* internals_ptr; // Pointer to the internal structure
int fs_type; // Type of the filesystem (0 = windows, 1 = archive)
};
An internal file system consists of the following interfaces: InterfaceFileShare
, InterfaceFileSystemAnsi
, InterfaceFileSystemWide
, InterfaceFileSystemUtf8
, InterfaceFileSystem
.
Internally, the class of
The archives' internals contains the following values.
The location is in bytes and relative to structure's start address.
Type | Offset (QWORDS) | Notes |
---|---|---|
Address | 0 |
Pointer to vtable of FileSystemArchive
|
Address | 1 |
Pointer to something |
Address | 2 |
Pointer to vtable of InterfaceFileSystemWide
|
Address | 3 |
Pointer to something |
Address | 4 |
Pointer to vtable of InterfaceFileSystemUtf8
|
Address | 5 |
Pointer to something |
std::wstring |
6 - 10
|
Current base directory |
std::list |
11 -12
|
List of loaded ARCs? |
Value | 13 |
0x0 |
Value | 14 |
Junk? |
Address | 15 |
Pointer to vtable of InterfaceFileShare
|
- Only the 4 top bytes are used from
1
,3
and5
. Thus essentially they contain values70
,60
and50
respectively. They probably mean the size of the vtables. - There is a global counter for all initialized archives
Signature:
class FileSystemArchive: public InterfaceFileSystem;
class InterfaceFileSystem: public InterfaceFileSystemAnsi, public InterfaceFileSystemWide, public InterfaceFileSystemUtf8;
class InterfaceFileSystemAnsi: public InterfaceFileShare;
class InterfaceFileSystemWide: public InterfaceFileShare;
class InterfaceFileSystemUtf8: public InterfaceFileShare;
virtual class InterfaceFileShare;
FileSystemArchive
has the following functions:
First VFTable
Index | Function signature |
---|---|
0 | |
1 | |
2 | |
3 | |
4 | Internal function for SetBaseDirectory
|
5 | void SetBaseDirectory(*this, char* path) |
6 | Internal function for AddArchive
|
7 | |
8 | Internal for AddArchive
|
9 | void AddArchive(*this, char* path) |
10 | void AddAutoPathForAllFolder(*this) |
11 | |
12 | |
13 | void AddAutoPath(*this, char* path) |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | Pointer to _LocaleUpdate::GetLocaleT()
|
Second VFTable (implements InterfaceFileSystemWide
)
Index | Function signature |
---|---|
0 | GetFileW(this, wchar_t* path) |
1 | |
2 | CreateFileListW(this, std::vector<std::wstring>* vec, wchar_t* path, ListType list_type) |
Third VFTable
Index | Function signature |
---|---|
0 | FileMemory* GetFile(*this, char* file_str) |
1 | |
2 | std::vector<std::string*>* CreateList(*this, std::vector<std::string*>* vector, char* path, ListType list_type) |
3 | (NOTE: Is structure; likely a lambda) |
4 | |
5 | |
6 | |
7 | |
8 | BOOL IsExistentFile(*this, char* path) |
9 | |
10 |
Fourth VFTable (InterfaceFileShare
)
Index | Function signature |
---|---|
0 | bool IsValid(*this) |
1 |
A file list is a struct
struct FileListData
{
std::vector<std::string*> *file_list;
int size;
}
The pointer to the vector is a simple IntPtr
in C#.
The API provides two main file types: Win32File
(WINAPI), FileNormalWindows
(C file API), FileMemory
(memory).
Signature:
class FileMemory {
virtual ~FileMemory() = 0;
virtual bool close_file() = 0;
virtual bool seek(uint64_t dist, bool absolute) = 0;
virtual uint64_t read(void* buffer, uint64_t length) = 0;
virtual uint64_t read_from(void* buffer, uint64_t pos, uint64_t length) = 0;
virtual bool is_open() = 0;
virtual void* get_data_ptr() = 0;
virtual uint64_t tell() = 0;
virtual uint64_t length() = 0;
virtual bool set_file(void* data_ptr, uint64_t data_length, uint64_t file_offset) = 0;
virtual bool change_file_ptr2(void* data_ptr, uint64_t data_length, uint64_t file_offset) = 0;
virtual size_t move_memory(void* dest, void* src, size_t len) = 0;
}
VTable structure:
Index | Function name | Notes |
---|---|---|
0 | dispose |
Disposes of the object and file pointer |
1 | close_file |
Closes and frees raw file handler/pointer. Returns true if failed (?) |
2 | seek |
Moves the read header by the given number of bytes absolutely or relatively. Return true on success |
3 | read |
Reads at most length bytes into the given buffer. Returns the number of bytes actually read |
4 | read_from |
Reads at most length bytes into the given buffer from absolute position pos . Returns the number of bytes actually read |
5 | is_open |
Checks whether the file is open |
6 | get_data_ptr |
Returns pointer to the data this FileMemory handles. Pretty much like c_ptr(). |
7 | tell |
Current read position |
8 | length |
Total size of the current file |
9 | set_file |
Initializes this FileMemory to track the given data from the specified offset. file_offset allows to track only a slice of the file instead of the whole file |
10 | change_file_ptr2 |
Does pretty much the same thing as set_file . Don't know why there is a duplicate. |
11 | move_memory |
Moves data from one place to another. |