| 151 | } |
| 152 | |
| 153 | void load_map_script() noexcept { |
| 154 | auto &map_header = get_map_header(); |
| 155 | auto lua_directory = get_chimera().get_path() / "lua"; |
| 156 | auto script_path = lua_directory / "scripts" / "map" / (std::string(map_header.name) + ".lua"); |
| 157 | if(fs::exists(script_path)) { |
| 158 | auto script = read_script_file(script_path); |
| 159 | if(!script.empty()) { |
| 160 | auto script_name = script_path.filename().string(); |
| 161 | load_lua_script(script_name.c_str(), script.c_str(), script.size(), false, false); |
| 162 | } |
| 163 | } |
| 164 | // Load script embbended in tag data if allowed. We do not support this on Halo Trial. |
| 165 | else if((global_fix_flags.embedded_lua || get_chimera().get_ini()->get_value_bool("memory.load_embedded_lua").value_or(false)) && game_engine() != GameEngine::GAME_ENGINE_DEMO) { |
| 166 | auto *script = reinterpret_cast<const char *>(map_header.lua_script_data); |
| 167 | auto script_size = map_header.lua_script_size; |
| 168 | if(script && script_size) { |
| 169 | // Check that the TNT is where we expect it to be. |
| 170 | auto &tag_data_header = get_tag_data_header(); |
| 171 | auto *tag_data_address = reinterpret_cast<const char *>(&tag_data_header); |
| 172 | auto *tag_data_address_end = tag_data_address + (64 * 1024 * 1024); |
| 173 | if (script >= tag_data_address && script + script_size < tag_data_address_end) { |
| 174 | // Light the fuse. |
| 175 | auto map_filename = std::string(map_header.name) + ".map"; |
| 176 | load_lua_script(map_filename.c_str(), script, script_size, true, false); |
| 177 | } |
| 178 | else { |
| 179 | console_error("Unable to load embedded Lua script: Invalid location"); |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | void load_global_scripts() noexcept { |
| 186 | auto lua_directory = get_chimera().get_path() / "lua"; |
no test coverage detected