| 152 | static bool sSourceModInitialized = false; |
| 153 | |
| 154 | bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late) |
| 155 | { |
| 156 | const char *gamepath = g_SMAPI->GetBaseDir(); |
| 157 | |
| 158 | /* Store full path to game */ |
| 159 | g_BaseDir.assign(gamepath); |
| 160 | |
| 161 | /* Store name of game directory by itself */ |
| 162 | size_t len = strlen(gamepath); |
| 163 | for (size_t i = len - 1; i < len; i--) |
| 164 | { |
| 165 | if (gamepath[i] == PLATFORM_SEP_CHAR) |
| 166 | { |
| 167 | ke::SafeStrcpy(m_ModDir, sizeof(m_ModDir), &gamepath[++i]); |
| 168 | break; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | const char *basepath = icvar->GetCommandLineValue("sm_basepath"); |
| 173 | /* Set a custom base path if there is one. */ |
| 174 | if (basepath != NULL && basepath[0] != '\0') |
| 175 | { |
| 176 | m_GotBasePath = true; |
| 177 | } |
| 178 | /* Otherwise, use a default and keep the m_GotBasePath unlocked. */ |
| 179 | else |
| 180 | { |
| 181 | basepath = sm_basepath.GetDefault(); |
| 182 | } |
| 183 | |
| 184 | ke::path::Format(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/%s", g_BaseDir.c_str(), basepath); |
| 185 | ke::path::Format(m_SMRelDir, sizeof(m_SMRelDir), "%s", basepath); |
| 186 | |
| 187 | if (!sCoreProviderImpl.LoadBridge(error, maxlength)) |
| 188 | { |
| 189 | return false; |
| 190 | } |
| 191 | |
| 192 | sCoreProviderImpl.InitializeBridge(); |
| 193 | |
| 194 | /* There will always be a path by this point, since it was force-set above. */ |
| 195 | m_GotBasePath = true; |
| 196 | |
| 197 | sSourceModInitialized = true; |
| 198 | |
| 199 | /* Hook this now so we can detect startup without calling StartSourceMod() */ |
| 200 | SH_ADD_HOOK(IServerGameDLL, LevelInit, gamedll, SH_MEMBER(this, &SourceModBase::LevelInit), false); |
| 201 | SH_ADD_HOOK(IVEngineServer, GetMapEntitiesString, engine, SH_MEMBER(this, &SourceModBase::GetMapEntitiesString), false); |
| 202 | |
| 203 | /* Only load if we're not late */ |
| 204 | if (!late) |
| 205 | { |
| 206 | StartSourceMod(false); |
| 207 | } |
| 208 | |
| 209 | return true; |
| 210 | } |
| 211 |
no test coverage detected