|
641 | 641 | #include <cstdlib> |
642 | 642 | #include <filesystem> |
643 | 643 |
|
| 644 | +#include "args.h" |
| 645 | +#include "ddio.h" |
| 646 | +#include "crossplat.h" |
644 | 647 | #include "Mission.h" |
645 | 648 | #include "3d.h" |
646 | 649 | #include "LoadLevel.h" |
@@ -701,12 +704,12 @@ bool mn3_GetInfo(const std::filesystem::path &mn3file, tMissionInfo *msn); |
701 | 704 |
|
702 | 705 | static inline bool IS_MN3_FILE(const std::filesystem::path &fname) { |
703 | 706 | std::filesystem::path ext = fname.extension(); |
704 | | - return (stricmp((const char*)ext.u8string().c_str(), ".mn3") == 0); |
| 707 | + return (stricmp((const char *)ext.u8string().c_str(), ".mn3") == 0); |
705 | 708 | } |
706 | 709 |
|
707 | 710 | static inline std::filesystem::path MN3_TO_MSN_NAME(const std::filesystem::path &mn3name) { |
708 | 711 | std::filesystem::path fname = std::filesystem::path(mn3name).stem(); |
709 | | - if (stricmp((const char*)fname.u8string().c_str(), "d3_2") == 0) { |
| 712 | + if (stricmp((const char *)fname.u8string().c_str(), "d3_2") == 0) { |
710 | 713 | fname = "d3"; |
711 | 714 | } |
712 | 715 | fname.replace_extension(".msn"); |
@@ -742,6 +745,26 @@ void InitMission() { |
742 | 745 | } |
743 | 746 | atexit(ResetMission); |
744 | 747 | } |
| 748 | + |
| 749 | +void InitDefaultMissionFromCLI() { |
| 750 | + // Load mission on startup |
| 751 | + int mission_arg = FindArg("-mission"); |
| 752 | + if (mission_arg > 0) { |
| 753 | + std::filesystem::path filename = std::filesystem::path(GameArgs[mission_arg + 1]).filename().replace_extension(".mn3"); |
| 754 | + LoadMission((const char*)filename.u8string().c_str()); |
| 755 | + |
| 756 | + int level_arg = FindArg("-loadlevel"); |
| 757 | + if (level_arg > 0) { |
| 758 | + int level{std::atoi(GameArgs[level_arg + 1])}; |
| 759 | + if (level <= 0 || level > Current_mission.num_levels) { |
| 760 | + LOG_WARNING << "Invalid level selection, resetting to 1"; |
| 761 | + level = 1; |
| 762 | + } |
| 763 | + Current_mission.cur_level = level; |
| 764 | + } |
| 765 | + } |
| 766 | +} |
| 767 | + |
745 | 768 | // reset all states for a mission |
746 | 769 | void ResetMission() { |
747 | 770 | LOG_INFO << "In ResetMission()"; |
@@ -1166,9 +1189,9 @@ bool LoadMission(const char *mssn) { |
1166 | 1189 | // set up current mission (movies are already set above) |
1167 | 1190 | msn->cur_level = 1; |
1168 | 1191 | msn->num_levels = numlevels; |
1169 | | - msn->filename = mem_strdup((const char*)mission.u8string().c_str()); |
| 1192 | + msn->filename = mem_strdup((const char *)mission.u8string().c_str()); |
1170 | 1193 | msn->game_state_flags = 0; |
1171 | | - strcpy(Net_msn_URLs.msnname, (const char*)mission.u8string().c_str()); |
| 1194 | + strcpy(Net_msn_URLs.msnname, (const char *)mission.u8string().c_str()); |
1172 | 1195 | res = true; // everything is ok. |
1173 | 1196 |
|
1174 | 1197 | // if error, print it out, else end. |
@@ -1238,7 +1261,7 @@ void LoadLevelText(const std::filesystem::path &level_filename) { |
1238 | 1261 | pathname.replace_extension(".str"); |
1239 | 1262 |
|
1240 | 1263 | char **goal_strings; |
1241 | | - if (CreateStringTable((const char*)pathname.u8string().c_str(), &goal_strings, &n_strings)) { |
| 1264 | + if (CreateStringTable((const char *)pathname.u8string().c_str(), &goal_strings, &n_strings)) { |
1242 | 1265 | int n_goals = Level_goals.GetNumGoals(); |
1243 | 1266 | ASSERT(n_strings == (n_goals * 3)); |
1244 | 1267 | for (int i = 0; i < n_goals; i++) { |
@@ -1784,24 +1807,26 @@ bool mn3_Open(const std::filesystem::path &mn3file) { |
1784 | 1807 | /* Disabled loading scripts from .mn3 files on purpose: |
1785 | 1808 | all 64-bit first-party level scripts have already been loaded from `PRIMARY_HOG`. |
1786 | 1809 | Mission files contain only Win32 scripts by default, which cannot not be loaded on 64-bit builds. |
1787 | | - Reactivate this when we have a proper sandbox system to safely run third-party scripts contained in user-made levels. */ |
1788 | | - // Osiris_ExtractScriptsFromHog(mn3_handle, true); |
| 1810 | + Reactivate this when we have a proper sandbox system to safely run third-party scripts contained in user-made |
| 1811 | + levels. */ |
| 1812 | + // Osiris_ExtractScriptsFromHog(mn3_handle, true); |
1789 | 1813 | } |
1790 | 1814 | // do table file stuff. |
1791 | 1815 | std::filesystem::path filename = mn3file.stem(); |
1792 | 1816 |
|
1793 | 1817 | std::filesystem::path voice_hog; |
1794 | | - if ((stricmp((const char*)filename.u8string().c_str(), "d3") == 0) || (stricmp((const char*)filename.u8string().c_str(), "training") == 0)) { |
| 1818 | + if ((stricmp((const char *)filename.u8string().c_str(), "d3") == 0) || |
| 1819 | + (stricmp((const char *)filename.u8string().c_str(), "training") == 0)) { |
1795 | 1820 | // Open audio hog file |
1796 | 1821 | voice_hog = std::filesystem::path("missions") / "d3voice1.hog"; // Audio for levels 1-4 |
1797 | 1822 | Mission_voice_hog_handle = cf_OpenLibrary(voice_hog); |
1798 | | - } else if (stricmp((const char*)filename.u8string().c_str(), "d3_2") == 0) { |
| 1823 | + } else if (stricmp((const char *)filename.u8string().c_str(), "d3_2") == 0) { |
1799 | 1824 | // Open audio hog file |
1800 | 1825 | voice_hog = std::filesystem::path("missions") / "d3voice2.hog"; // Audio for levels 5-17 |
1801 | 1826 | Mission_voice_hog_handle = cf_OpenLibrary(voice_hog); |
1802 | 1827 | } |
1803 | 1828 | filename.replace_extension(".gam"); |
1804 | | - mng_SetAddonTable((const char*)filename.u8string().c_str()); |
| 1829 | + mng_SetAddonTable((const char *)filename.u8string().c_str()); |
1805 | 1830 | Current_mission.mn3_handle = mn3_handle; |
1806 | 1831 | return true; |
1807 | 1832 | } |
|
0 commit comments