public SpaceEngineersCore() { var contentPath = ToolboxUpdater.GetApplicationContentPath(); string userDataPath = SpaceEngineersConsts.BaseLocalPath.DataPath; MyFileSystem.Reset(); MyFileSystem.Init(contentPath, userDataPath); MyLog.Default = MySandboxGame.Log; MySandboxGame.Config = new MyConfig("SpaceEngineers.cfg"); // TODO: Is specific to SE, not configurable to ME. MySandboxGame.Config.Load(); MyFileSystem.InitUserSpecific(null); SpaceEngineersGame.SetupPerGameSettings(); VRageRender.MyRenderProxy.Initialize(new MyNullRender()); // We create a whole instance of MySandboxGame! // If this is causing an exception, then there is a missing dependency. MySandboxGame gameTemp = new MySandboxGame(new string[] { "-skipintro" }); // creating MySandboxGame will reset the CurrentUICulture, so I have to reapply it. Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfoByIetfLanguageTag(GlobalSettings.Default.LanguageCode); SpaceEngineersApi.LoadLocalization(); MyStorageBase.UseStorageCache = false; #region MySession creation // Replace the private constructor on MySession, so we can create it without getting involed with Havok and other depdancies. var keenStart = typeof(Sandbox.Game.World.MySession).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(MySyncLayer), typeof(bool) }, null); var ourStart = typeof(SEToolbox.Interop.MySession).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(MySyncLayer), typeof(bool) }, null); ReflectionUtil.ReplaceMethod(ourStart, keenStart); // Create an empty instance of MySession for use by low level code. Sandbox.Game.World.MySession mySession = ReflectionUtil.ConstructPrivateClass <Sandbox.Game.World.MySession>(new Type[0], new object[0]); ReflectionUtil.ConstructField(mySession, "m_sessionComponents"); // Required as the above code doesn't populate it during ctor of MySession. mySession.Settings = new MyObjectBuilder_SessionSettings { EnableVoxelDestruction = true }; VRage.MyVRage.Init(new ToolboxPlatform()); // change for the Clone() method to use XML cloning instead of Protobuf because of issues with MyObjectBuilder_CubeGrid.Clone() ReflectionUtil.SetFieldValue(typeof(VRage.ObjectBuilders.MyObjectBuilderSerializer), "ENABLE_PROTOBUFFERS_CLONING", false); // Assign the instance back to the static. Sandbox.Game.World.MySession.Static = mySession; Sandbox.Game.GameSystems.MyHeightMapLoadingSystem.Static = new MyHeightMapLoadingSystem(); Sandbox.Game.GameSystems.MyHeightMapLoadingSystem.Static.LoadData(); #endregion _stockDefinitions = new SpaceEngineersResources(); _stockDefinitions.LoadDefinitions(); _manageDeleteVoxelList = new List <string>(); }
// Reflection copy of MyTexts.AddLanguage private static void AddLanguage(MyLanguagesEnum id, string cultureName, string subcultureName = null, string displayName = null, float guiTextScale = 1f, bool isCommunityLocalized = true) { // Create an empty instance of LanguageDescription. MyTexts.MyLanguageDescription languageDescription = ReflectionUtil.ConstructPrivateClass <MyTexts.MyLanguageDescription>( new Type[] { typeof(MyLanguagesEnum), typeof(string), typeof(string), typeof(string), typeof(float), typeof(bool) }, new object[] { id, displayName, cultureName, subcultureName, guiTextScale, isCommunityLocalized }); Dictionary <MyLanguagesEnum, MyTexts.MyLanguageDescription> m_languageIdToLanguage = typeof(MyTexts).GetStaticField <Dictionary <MyLanguagesEnum, MyTexts.MyLanguageDescription> >("m_languageIdToLanguage"); Dictionary <string, MyLanguagesEnum> m_cultureToLanguageId = typeof(MyTexts).GetStaticField <Dictionary <string, MyLanguagesEnum> >("m_cultureToLanguageId"); if (!m_languageIdToLanguage.ContainsKey(id)) { m_languageIdToLanguage.Add(id, languageDescription); m_cultureToLanguageId.Add(languageDescription.FullCultureName, id); } }
public SpaceEngineersCore() { var contentPath = ToolboxUpdater.GetApplicationContentPath(); string userDataPath = SpaceEngineersConsts.BaseLocalPath.DataPath; MyFileSystem.ExePath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(FastResourceLock)).Location); MyLog.Default = MySandboxGame.Log; SpaceEngineersGame.SetupBasicGameInfo(); _startup = new MyCommonProgramStartup(new string[] { }); //var appDataPath = _startup.GetAppDataPath(); //MyInitializer.InvokeBeforeRun(AppId, MyPerGameSettings.BasicGameInfo.ApplicationName + "SEToolbox", appDataPath); //MyInitializer.InitCheckSum(); MyFileSystem.Reset(); MyFileSystem.Init(contentPath, userDataPath); // This will start the Steam Service, and Steam will think SE is running. // TODO: we don't want to be doing this all the while SEToolbox is running, // perhaps a once off during load to fetch of mods then disconnect/Dispose. _steamService = new MySteamService(MySandboxGame.IsDedicated, AppId); MyServiceManager.Instance.AddService <IMyGameService>(_steamService); MyFileSystem.InitUserSpecific(SpaceEngineersWorkshop.MySteam.UserId.ToString()); // This sets the save file/path to load games from. //MyFileSystem.InitUserSpecific(null); //SpaceEngineersWorkshop.MySteam.Dispose(); MySandboxGame.Config = new MyConfig("SpaceEngineers.cfg"); // TODO: Is specific to SE, not configurable to ME. MySandboxGame.Config.Load(); SpaceEngineersGame.SetupPerGameSettings(); VRageRender.MyRenderProxy.Initialize(new MyNullRender()); // We create a whole instance of MySandboxGame! // If this is causing an exception, then there is a missing dependency. MySandboxGame gameTemp = new MySandboxGame(new string[] { "-skipintro" }); // creating MySandboxGame will reset the CurrentUICulture, so I have to reapply it. Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfoByIetfLanguageTag(GlobalSettings.Default.LanguageCode); SpaceEngineersApi.LoadLocalization(); MyStorageBase.UseStorageCache = false; #region MySession creation // Replace the private constructor on MySession, so we can create it without getting involed with Havok and other depdancies. var keenStart = typeof(Sandbox.Game.World.MySession).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(MySyncLayer), typeof(bool) }, null); var ourStart = typeof(SEToolbox.Interop.MySession).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(MySyncLayer), typeof(bool) }, null); ReflectionUtil.ReplaceMethod(ourStart, keenStart); // Create an empty instance of MySession for use by low level code. Sandbox.Game.World.MySession mySession = ReflectionUtil.ConstructPrivateClass <Sandbox.Game.World.MySession>(new Type[0], new object[0]); ReflectionUtil.ConstructField(mySession, "m_sessionComponents"); // Required as the above code doesn't populate it during ctor of MySession. mySession.Settings = new MyObjectBuilder_SessionSettings { EnableVoxelDestruction = true }; VRage.MyVRage.Init(new ToolboxPlatform()); // change for the Clone() method to use XML cloning instead of Protobuf because of issues with MyObjectBuilder_CubeGrid.Clone() ReflectionUtil.SetFieldValue(typeof(VRage.ObjectBuilders.MyObjectBuilderSerializer), "ENABLE_PROTOBUFFERS_CLONING", false); // Assign the instance back to the static. Sandbox.Game.World.MySession.Static = mySession; Sandbox.Game.GameSystems.MyHeightMapLoadingSystem.Static = new MyHeightMapLoadingSystem(); Sandbox.Game.GameSystems.MyHeightMapLoadingSystem.Static.LoadData(); #endregion _stockDefinitions = new SpaceEngineersResources(); _stockDefinitions.LoadDefinitions(); _manageDeleteVoxelList = new List <string>(); }
public bool LoadGame(string seBinPath, string userDataPath, string savePath) { if (!Directory.Exists(seBinPath)) { return(false); } if (!Directory.Exists(savePath)) { return(false); } if (!savePath.StartsWith(userDataPath, StringComparison.OrdinalIgnoreCase)) { return(false); } string contentPath = Path.GetFullPath(Path.Combine(seBinPath, @"..\Content")); MyFileSystem.Reset(); MyFileSystem.Init(contentPath, userDataPath); MyLog.Default = MySandboxGame.Log; MySandboxGame.Config = new MyConfig("SpaceEngineers.cfg"); // TODO: Is specific to SE, not configurable to ME. MySandboxGame.Config.Load(); MyFileSystem.InitUserSpecific(null); SpaceEngineersGame.SetupPerGameSettings(); VRageRender.MyRenderProxy.Initialize(new MyNullRender()); // We create a whole instance of MySandboxGame! // If this is causing an exception, then there is a missing dependency. MySandboxGame gameTemp = new MySandboxGame(null); #region Game Localization // creating MySandboxGame will reset the CurrentUICulture, so I have to reapply it. Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfoByIetfLanguageTag(GlobalSettings.Default.LanguageCode); var culture = System.Threading.Thread.CurrentThread.CurrentUICulture; var languageTag = culture.IetfLanguageTag; var localizationPath = Path.Combine(contentPath, @"Data\Localization"); var codes = languageTag.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); var maincode = codes.Length > 0 ? codes[0] : null; var subcode = codes.Length > 1 ? codes[1] : null; MyTexts.Clear(); MyTexts.LoadTexts(localizationPath, maincode, subcode); #endregion MyStorageBase.UseStorageCache = false; #region MySession creation // Replace the private constructor on MySession, so we can create it without getting involed with Havok and other depdancies. var keenStart = typeof(Sandbox.Game.World.MySession).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(MySyncLayer), typeof(bool) }, null); var ourStart = typeof(EconomyConfigurationEditor.Interop.MySession).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(MySyncLayer), typeof(bool) }, null); ReflectionUtil.ReplaceMethod(ourStart, keenStart); // Create an empty instance of MySession for use by low level code. Sandbox.Game.World.MySession mySession = ReflectionUtil.ConstructPrivateClass <Sandbox.Game.World.MySession>(new Type[0], new object[0]); ReflectionUtil.ConstructField(mySession, "m_sessionComponents"); // Required as the above code doesn't populate it during ctor of MySession. mySession.Settings = new MyObjectBuilder_SessionSettings { EnableVoxelDestruction = true }; // Assign the instance back to the static. Sandbox.Game.World.MySession.Static = mySession; Sandbox.Game.GameSystems.MyHeightMapLoadingSystem.Static = new MyHeightMapLoadingSystem(); Sandbox.Game.GameSystems.MyHeightMapLoadingSystem.Static.LoadData(); #endregion #region Load Sandbox var filename = Path.Combine(savePath, SpaceEngineersConsts.SandBoxCheckpointFilename); MyObjectBuilder_Checkpoint checkpoint; string errorInformation; bool compressedCheckpointFormat; bool snapshot = false; bool retVal = SpaceEngineersApi.TryReadSpaceEngineersFile <MyObjectBuilder_Checkpoint>(filename, out checkpoint, out compressedCheckpointFormat, out errorInformation, snapshot); if (!retVal) { return(false); } #endregion MyDefinitionManager.Static.PrepareBaseDefinitions(); MyDefinitionManager.Static.LoadData(checkpoint.Mods); var MaterialIndex = new Dictionary <string, byte>(); return(true); }