| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/lib/module.h $ |
| 21 | * $Revision: 12 $ |
| 22 | * $Date: 7/14/99 6:43p $ |
| 23 | * $Author: Jeff $ |
| 24 | * |
| 25 | * Header for Dynamic Loadable Modules |
| 26 | * |
| 27 | * $Log: /DescentIII/Main/lib/module.h $ |
| 28 | * |
| 29 | * 12 7/14/99 6:43p Jeff |
| 30 | * don't load modules globally by default |
| 31 | * |
| 32 | * 11 7/13/99 5:40p Jeff |
| 33 | * fixes for Linux compile |
| 34 | * |
| 35 | * 10 6/25/99 4:58p Jeff |
| 36 | * default module load as global |
| 37 | * |
| 38 | * 9 5/10/99 10:53p Ardussi |
| 39 | * changes to compile on Mac |
| 40 | * |
| 41 | * 8 4/19/99 3:57a Jeff |
| 42 | * changed define for Linux in order for multiplayer games to compile |
| 43 | * |
| 44 | * 7 4/15/99 2:57a Jeff |
| 45 | * added missing defines for linux |
| 46 | * |
| 47 | * 6 1/11/99 12:53p Jeff |
| 48 | * added a function that given a module name it will make sure it has an |
| 49 | * extension. Made Osiris friendly with modules with no extension |
| 50 | * |
| 51 | * 5 1/04/99 12:24p Jeff |
| 52 | * updated...added compiler friendly define for dll functions that return |
| 53 | * a pointer |
| 54 | * |
| 55 | * 4 11/13/98 6:36p Jeff |
| 56 | * created dmfc_dll (a DLL version of DMFC) and converted current mods to |
| 57 | * use it |
| 58 | * |
| 59 | * 3 7/06/98 10:45a Jeff |
| 60 | * Made Linux friendly |
| 61 | * |
| 62 | * 2 6/05/98 2:15p Jeff |
| 63 | * Initial creation |
| 64 | * |
| 65 | * 1 6/05/98 2:14p Jeff |
| 66 | * |
| 67 | * $NoKeywords: $ |
| 68 | */ |
| 69 | |
| 70 | #ifndef __DLMODULE_H_ |
| 71 | #define __DLMODULE_H_cxx . . $ `lib/module.h:71:9`! |
| 72 | |
| 73 | #include <cstdint> |
| 74 | |
| 75 | #ifdef __cpluspluscxx . . $ `<built-in>:467:9`! |
| 76 | #define CPPEXTERNcxx . . $ `lib/module.h:76:9`! extern "C" |
| 77 | #else |
| 78 | #define CPPEXTERN extern |
| 79 | #endif |
| 80 | |
| 81 | #ifdef _MSC_VER // MSVC Build |
| 82 | # define STDCALL __stdcall |
| 83 | # define STDCALLPTR *STDCALL |
| 84 | #else // Non-MS compilers |
| 85 | # if defined(__i386__) || defined(_X86_) || defined(__THW_INTEL__) |
| 86 | # define STDCALL __attribute__((stdcall)) |
| 87 | # else |
| 88 | # define STDCALLcxx . . $ `lib/module.h:88:11`! |
| 89 | # endif |
| 90 | # define STDCALLPTRcxx . . $ `lib/module.h:90:10`! STDCALL * |
| 91 | #endif |
| 92 | |
| 93 | # define DLLFUNCCALLcxx . . $ `lib/module.h:93:10`! STDCALL |
| 94 | # define DLLFUNCCALLPTRcxx . . $ `lib/module.h:94:10`! STDCALLPTR |
| 95 | |
| 96 | #ifdef WIN32 |
| 97 | //=========================Windows Definition============================ |
| 98 | #include "windows.h" |
| 99 | |
| 100 | #define MODPROCADDRESS FARPROC |
| 101 | #define DLLFUNCEXPORT __declspec(dllexport) |
| 102 | #define DLLFUNCIMPORT __declspec(dllimport) |
| 103 | #define DLLEXPORT CPPEXTERN DLLFUNCEXPORT |
| 104 | struct module { |
| 105 | HINSTANCE handle; // handle to the DLL |
| 106 | }; |
| 107 | //======================================================================= |
| 108 | #elif defined(POSIXcxx . . $ `<built-in>:478:9`!) |
| 109 | //==========================Linux Definitions============================ |
| 110 | |
| 111 | #define MODPROCADDRESScxx . . $ `lib/module.h:111:9`! void * |
| 112 | #define DLLFUNCEXPORTcxx . . $ `lib/module.h:112:9`! __attribute__((visibility("default"))) |
| 113 | #define DLLFUNCIMPORTcxx . . $ `lib/module.h:113:9`! |
| 114 | #define DLLEXPORTcxx . . $ `lib/module.h:114:9`! CPPEXTERN DLLFUNCEXPORT |
| 115 | |
| 116 | struct modulecxx . . $ module# { |
| 117 | void *handlecxx . . $ module#handle.; // handle to the DLL |
| 118 | }; |
| 119 | //======================================================================= |
| 120 | #endif |
| 121 | |
| 122 | // Mod error codes |
| 123 | #define MODERR_NOERRORcxx . . $ `lib/module.h:123:9`! 0 // There was no error |
| 124 | #define MODERR_INVALIDMODcxx . . $ `lib/module.h:124:9`! 1 // This is not a valid module |
| 125 | #define MODERR_MODNOTFOUNDcxx . . $ `lib/module.h:125:9`! 2 // The module couldn't be found |
| 126 | #define MODERR_MODINITFAILcxx . . $ `lib/module.h:126:9`! 3 // The module initialization routine failed |
| 127 | #define MODERR_NOMODcxx . . $ `lib/module.h:127:9`! 4 // The value you past in for the module isn't a module, or nothing has been loaded |
| 128 | #define MODERR_INVALIDHANDLEcxx . . $ `lib/module.h:128:9`! 5 // The module handle passed in is NULL |
| 129 | #define MODERR_OTHERcxx . . $ `lib/module.h:129:9`! 255 // Some other error occured |
| 130 | |
| 131 | // Flags |
| 132 | #define MODF_LAZYcxx . . $ `lib/module.h:132:9`! 0x001 // Symbol resolution on demand |
| 133 | #define MODF_NOWcxx . . $ `lib/module.h:133:9`! 0x002 // Resolve all symbols before returning |
| 134 | #define MODF_GLOBALcxx . . $ `lib/module.h:134:9`! 0x200 // |
| 135 | |
| 136 | // Returns the real name of the module. If a given file has an extension, it will |
| 137 | // just return that filename. If the given file has no given extension, the |
| 138 | // system specific extension is concatted and returned. |
| 139 | void mod_GetRealModuleNamecxx . . $ mod_GetRealModuleName(611124a97efc52dd).(const char *modfilename, char *realmodfilename); |
| 140 | |
| 141 | // Loads a dynamic module into memory for use. If no extension is given, the default |
| 142 | // system specific extension is used. |
| 143 | // Returns true on success, false otherwise |
| 144 | bool mod_LoadModulecxx . . $ mod_LoadModule(2b2b4995973ac6b0).(modulecxx . . $ module# *handle, const char *modfilename, int flags = MODF_LAZYcxx . . $ `lib/module.h:132:9`!); |
| 145 | |
| 146 | // Frees a previously loaded module from memory, it can no longer be used |
| 147 | // Returns true on success, false otherwise |
| 148 | bool mod_FreeModulecxx . . $ mod_FreeModule(f63d3fb9c9f41dd6).(modulecxx . . $ module# *handle); |
| 149 | |
| 150 | // Returns a pointer to a function within a loaded module. If it returns NULL there was an error. Check |
| 151 | // mod_GetLastError to see if there was an error symstr is the name of the function you want to get the symbol for (Do |
| 152 | // NOT give any pre/suffix to this name) parmbytes is the size (in bytes) of the parameter list the function should have |
| 153 | MODPROCADDRESScxx . . $ `lib/module.h:111:9`! mod_GetSymbolcxx . . $ mod_GetSymbol(434bf6e9929b4f62).(modulecxx . . $ module# *handle, const char *symstr, uint8_tcxx . . $ uint8_t# parmbytes); |
| 154 | |
| 155 | // Returns an error code to what the last error was. When this function is called the last error is cleared, so by |
| 156 | // calling this function it not only returns the last error, but it removes it, so if you were to call this function |
| 157 | // again, it would return no error |
| 158 | int mod_GetLastErrorcxx . . $ mod_GetLastError(b126dc7c1de90089).(void); |
| 159 | |
| 160 | #endif |