Interface IMyUtilities
ModAPI interface giving access to utility functions
Namespace: VRage.Game.ModAPI
Assembly: VRage.Game.dll
Syntax
public interface IMyUtilities
Properties
ConfigDedicated
Gets config of dedicated server
Declaration
IMyConfigDedicated ConfigDedicated { get; }
Property Value
| Type | Description |
|---|---|
| IMyConfigDedicated |
GamePaths
Gets ModAPI interface that, giving you information about most important game paths
Declaration
IMyGamePaths GamePaths { get; }
Property Value
| Type | Description |
|---|---|
| IMyGamePaths |
IsDedicated
Gets if this game instance is dedicated server
Declaration
bool IsDedicated { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Methods
add_MessageEntered(MessageEnteredDel)
Declaration
void add_MessageEntered(MessageEnteredDel value)
Parameters
| Type | Name | Description |
|---|---|---|
| MessageEnteredDel | value |
add_MessageEnteredSender(MessageEnteredSenderDel)
Declaration
void add_MessageEnteredSender(MessageEnteredSenderDel value)
Parameters
| Type | Name | Description |
|---|---|---|
| MessageEnteredSenderDel | value |
CreateNotification(String, Int32, String)
Create a notification object. The object needs to have Show() called on it to be shown. On top of that you can dynamically change the text, font and adjust the time to live.
Declaration
IMyHudNotification CreateNotification(string message, int disappearTimeMs = 2000, string font = "White")
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | message | Message text |
| System.Int32 | disappearTimeMs | How long notification would stay (in milliseconds) |
| System.String | font | Font (color). |
Returns
| Type | Description |
|---|---|
| IMyHudNotification | The notification object. |
See Also
DeleteFileInGlobalStorage(String)
Deletes file in global storage %APPDATA%/Roaming/SpaceEngineers/Storage
Declaration
void DeleteFileInGlobalStorage(string file)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative path |
DeleteFileInLocalStorage(String, Type)
Deletes file in local storage %APPDATA%/Roaming/SpaceEngineers/Storage/{Assembly Scope} Where {Assembly Scope} - callingType.Assembly.ManifestModule.ScopeName
Declaration
void DeleteFileInLocalStorage(string file, Type callingType)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative file path |
| System.Type | callingType | Use any of your mod classes |
DeleteFileInWorldStorage(String, Type)
Deletes file in world storage %APPDATA%/Roaming/SpaceEngineers/Save/{SteamId}/{WorldName}/Storage/{Assembly Scope} Where {Assembly Scope} - callingType.Assembly.ManifestModule.ScopeName
Declaration
void DeleteFileInWorldStorage(string file, Type callingType)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative file path |
| System.Type | callingType | Use any of your mod classes |
FileExistsInGameContent(String)
Checks if file exists in game content folder. (Folder where SE is installed)
Declaration
bool FileExistsInGameContent(string file)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative file path |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if file exists |
FileExistsInGlobalStorage(String)
Checks if file exists in %APPDATA%/Roaming/SpaceEngineers/Storage folder. (Folder where SE is installed)
Declaration
bool FileExistsInGlobalStorage(string file)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative file path |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if file exists |
FileExistsInLocalStorage(String, Type)
Checks if file exists in %APPDATA%/Roaming/SpaceEngineers/Storage/{Assembly Scope} Where {Assembly Scope} - callingType.Assembly.ManifestModule.ScopeName
Declaration
bool FileExistsInLocalStorage(string file, Type callingType)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative file path |
| System.Type | callingType | Use any of your mod classes |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if file exists |
FileExistsInModLocation(String, MyObjectBuilder_Checkpoint.ModItem)
Checks if file exists in other mod folder
Declaration
bool FileExistsInModLocation(string file, MyObjectBuilder_Checkpoint.ModItem modItem)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative path to file |
| MyObjectBuilder_Checkpoint.ModItem | modItem | Mod to test |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if file exists |
FileExistsInWorldStorage(String, Type)
Checks if file exists in world save %APPDATA%/Roaming/SpaceEngineers/Save/{SteamId}/{WorldName}/Storage/{Assembly Scope} Where {Assembly Scope} - callingType.Assembly.ManifestModule.ScopeName
Declaration
bool FileExistsInWorldStorage(string file, Type callingType)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative file path |
| System.Type | callingType | Use any of your mod classes |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if file exists |
GetObjectiveLine()
Gets objectives interface
Declaration
IMyHudObjectiveLine GetObjectiveLine()
Returns
| Type | Description |
|---|---|
| IMyHudObjectiveLine | Interface to work with objectives |
GetTypeName(Type)
Gets name of type
Declaration
string GetTypeName(Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Type | type | Type |
Returns
| Type | Description |
|---|---|
| System.String | Name |
See Also
GetVariable<T>(String, out T)
Gets registered variable.
Declaration
bool GetVariable<T>(string name, out T value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | Name of variable |
| T | value | Returned value |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if variable exists |
Type Parameters
| Name | Description |
|---|---|
| T | Type of variable |
See Also
InvokeOnGameThread(Action, String, Int32, Int32)
Invokes action on simulation thread
Declaration
void InvokeOnGameThread(Action action, string invokerName = "ModAPI", int StartAt = -1, int RepeatTimes = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Action | action | Method to call |
| System.String | invokerName | Description of caller |
| System.Int32 | StartAt | Target frame when this action should be called (GameplayFrameCounter) |
| System.Int32 | RepeatTimes | How many times this action should be invoked |
ReadBinaryFileInGameContent(String)
Reads text file from game content folder. (Folder where SE is installed)
Declaration
BinaryReader ReadBinaryFileInGameContent(string file)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative file path |
Returns
| Type | Description |
|---|---|
| System.IO.BinaryReader | Text reader |
ReadBinaryFileInGlobalStorage(String)
Reads text file from global storage %APPDATA%/Roaming/SpaceEngineers/Storage
Declaration
BinaryReader ReadBinaryFileInGlobalStorage(string file)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative file path |
Returns
| Type | Description |
|---|---|
| System.IO.BinaryReader | Text reader |
ReadBinaryFileInLocalStorage(String, Type)
Reads binary file from local storage %APPDATA%/Roaming/SpaceEngineers/Storage/{Assembly Scope}
Declaration
BinaryReader ReadBinaryFileInLocalStorage(string file, Type callingType)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative file path |
| System.Type | callingType | Use any of your mod classes |
Returns
| Type | Description |
|---|---|
| System.IO.BinaryReader | Text reader |
ReadBinaryFileInModLocation(String, MyObjectBuilder_Checkpoint.ModItem)
Reads text file from the specified mod's directory.
Declaration
BinaryReader ReadBinaryFileInModLocation(string file, MyObjectBuilder_Checkpoint.ModItem modItem)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative file path |
| MyObjectBuilder_Checkpoint.ModItem | modItem | The mod to read from. This can be acquired from IMySession or ModItem. |
Returns
| Type | Description |
|---|---|
| System.IO.BinaryReader | Text reader |
ReadBinaryFileInWorldStorage(String, Type)
Read binary file from world storage %APPDATA%/Roaming/SpaceEngineers/Save/{SteamId}/{WorldName}/Storage/{Assembly Scope}
Declaration
BinaryReader ReadBinaryFileInWorldStorage(string file, Type callingType)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative file path |
| System.Type | callingType | Use any of your mod classes |
Returns
| Type | Description |
|---|---|
| System.IO.BinaryReader | Text reader |
ReadFileInGameContent(String)
Reads text file from game content folder. (Folder where SE is installed)
Declaration
TextReader ReadFileInGameContent(string file)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative file path |
Returns
| Type | Description |
|---|---|
| System.IO.TextReader | Text reader |
ReadFileInGlobalStorage(String)
Reads text file from global storage %APPDATA%/Roaming/SpaceEngineers/Storage
Declaration
TextReader ReadFileInGlobalStorage(string file)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative file path |
Returns
| Type | Description |
|---|---|
| System.IO.TextReader | Text reader |
ReadFileInLocalStorage(String, Type)
Reads text file from local storage %APPDATA%/Roaming/SpaceEngineers/Storage/{Assembly Scope}
Declaration
TextReader ReadFileInLocalStorage(string file, Type callingType)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative file path |
| System.Type | callingType | Use any of your mod classes |
Returns
| Type | Description |
|---|---|
| System.IO.TextReader | Text reader |
ReadFileInModLocation(String, MyObjectBuilder_Checkpoint.ModItem)
Reads text file from the specified mod's directory.
Declaration
TextReader ReadFileInModLocation(string file, MyObjectBuilder_Checkpoint.ModItem modItem)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative file path |
| MyObjectBuilder_Checkpoint.ModItem | modItem | The mod to read from. This can be acquired from IMySession or ModItem. |
Returns
| Type | Description |
|---|---|
| System.IO.TextReader | Text reader |
ReadFileInWorldStorage(String, Type)
Read text file from world storage %APPDATA%/Roaming/SpaceEngineers/Save/{SteamId}/{WorldName}/Storage/{Assembly Scope}
Declaration
TextReader ReadFileInWorldStorage(string file, Type callingType)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative file path |
| System.Type | callingType | Use any of your mod classes |
Returns
| Type | Description |
|---|---|
| System.IO.TextReader | Text reader |
RegisterMessageHandler(Int64, Action<Object>)
Adds a handler to the mod message system.
Declaration
void RegisterMessageHandler(long id, Action<object> messageHandler)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int64 | id | Id of handler |
| System.Action<System.Object> | messageHandler | Function that would be called |
See Also
remove_MessageEntered(MessageEnteredDel)
Declaration
void remove_MessageEntered(MessageEnteredDel value)
Parameters
| Type | Name | Description |
|---|---|---|
| MessageEnteredDel | value |
remove_MessageEnteredSender(MessageEnteredSenderDel)
Declaration
void remove_MessageEnteredSender(MessageEnteredSenderDel value)
Parameters
| Type | Name | Description |
|---|---|---|
| MessageEnteredSenderDel | value |
RemoveVariable(String)
Unregisters variable
Declaration
bool RemoveVariable(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | Name of variable |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if it existed before this call |
See Also
SendMessage(String)
Send message to other players
Declaration
void SendMessage(string messageText)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | messageText | Text of message |
SendModMessage(Int64, Object)
Allows passing data between mods on the same client.
Declaration
void SendModMessage(long id, object payload)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int64 | id | Id of handler |
| System.Object | payload | Message that would be sent. Can be any type |
See Also
SerializeFromBinary<T>(Byte[])
Uses ProtoBuf to deserialize an object from a byte array.
Declaration
T SerializeFromBinary<T>(byte[] data)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte[] | data | Object serialized as bytes |
Returns
| Type | Description |
|---|---|
| T | Deserialized object |
Type Parameters
| Name | Description |
|---|---|
| T |
SerializeFromXML<T>(String)
Deserializing object to xml. See https://docs.microsoft.com/en-us/dotnet/standard/serialization/controlling-xml-serialization-using-attributes
Declaration
T SerializeFromXML<T>(string buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | buffer | Xml |
Returns
| Type | Description |
|---|---|
| T | Object of desired T |
Type Parameters
| Name | Description |
|---|---|
| T | Type of object you have been serializing to |
Remarks
Deserialization is slow. You should prefer SerializeFromBinary<T>(Byte[]) Use VRage.Serialization.SerializableDictionary instead of System.Collections.Generic.Dictionary<, >
SerializeToBinary<T>(T)
Uses ProtoBuf to serialize an object into a byte array. You need mark class with [ProtoContract] and each member that you wish to serialize with [ProtoMember(uniqId)]
Declaration
byte[] SerializeToBinary<T>(T obj)
Parameters
| Type | Name | Description |
|---|---|---|
| T | obj | Object to serialize |
Returns
| Type | Description |
|---|---|
| System.Byte[] | Object serialized as bytes |
Type Parameters
| Name | Description |
|---|---|
| T |
SerializeToXML<T>(T)
Serializing object to xml. See https://docs.microsoft.com/en-us/dotnet/standard/serialization/controlling-xml-serialization-using-attributes
Declaration
string SerializeToXML<T>(T objToSerialize)
Parameters
| Type | Name | Description |
|---|---|---|
| T | objToSerialize | Object to save |
Returns
| Type | Description |
|---|---|
| System.String | Xml |
Type Parameters
| Name | Description |
|---|---|
| T | Type of object to save |
Remarks
Serialization is slow. You should prefer SerializeToBinary<T>(T)
SetVariable<T>(String, T)
Registers variable in game. It would be saved and loaded through game restarts
Declaration
void SetVariable<T>(string name, T value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | Name of variable |
| T | value | Value of variable |
Type Parameters
| Name | Description |
|---|---|
| T | Type of variable |
ShowMessage(String, String)
Shows message for local player without sending it to other players
Declaration
void ShowMessage(string sender, string messageText)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | sender | Who is sender. Example: Good.bot |
| System.String | messageText | Text of message |
ShowMissionScreen(String, String, String, String, Action<ResultEnum>, String)
Shows mission screen
Declaration
void ShowMissionScreen(string screenTitle = null, string currentObjectivePrefix = null, string currentObjective = null, string screenDescription = null, Action<ResultEnum> callback = null, string okButtonCaption = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | screenTitle | Screen title |
| System.String | currentObjectivePrefix | Subtitle prefix |
| System.String | currentObjective | Subtitle |
| System.String | screenDescription | Description |
| System.Action<ResultEnum> | callback | Called when player press ok button or close window |
| System.String | okButtonCaption | Ok button text |
ShowNotification(String, Int32, String)
Shows notification
Declaration
void ShowNotification(string message, int disappearTimeMs = 2000, string font = "White")
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | message | Message text |
| System.Int32 | disappearTimeMs | How long notification would stay (in milliseconds) |
| System.String | font | Font (color). |
See Also
UnregisterMessageHandler(Int64, Action<Object>)
Removes a handler from the mod message system.
Declaration
void UnregisterMessageHandler(long id, Action<object> messageHandler)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int64 | id | Id of handler |
| System.Action<System.Object> | messageHandler | Function was used as messageHandler |
See Also
WriteBinaryFileInGlobalStorage(String)
Write bytes to file from local storage %APPDATA%/Roaming/SpaceEngineers/Storage/{Assembly Scope}
Declaration
BinaryWriter WriteBinaryFileInGlobalStorage(string file)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative file path |
Returns
| Type | Description |
|---|---|
| System.IO.BinaryWriter | Text writer |
WriteBinaryFileInLocalStorage(String, Type)
Write bytes to file from local storage %APPDATA%/Roaming/SpaceEngineers/Storage/{Assembly Scope}
Declaration
BinaryWriter WriteBinaryFileInLocalStorage(string file, Type callingType)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative file path |
| System.Type | callingType | Use any of your mod classes |
Returns
| Type | Description |
|---|---|
| System.IO.BinaryWriter | Text writer |
WriteBinaryFileInWorldStorage(String, Type)
Write file to the current world's Storage directory.
Declaration
BinaryWriter WriteBinaryFileInWorldStorage(string file, Type callingType)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | |
| System.Type | callingType |
Returns
| Type | Description |
|---|---|
| System.IO.BinaryWriter |
WriteFileInGlobalStorage(String)
Write text to file from local storage %APPDATA%/Roaming/SpaceEngineers/Storage/{Assembly Scope}
Declaration
TextWriter WriteFileInGlobalStorage(string file)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative file path |
Returns
| Type | Description |
|---|---|
| System.IO.TextWriter | Text writer |
WriteFileInLocalStorage(String, Type)
Write text to file from local storage %APPDATA%/Roaming/SpaceEngineers/Storage/{Assembly Scope}
Declaration
TextWriter WriteFileInLocalStorage(string file, Type callingType)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative file path |
| System.Type | callingType | Use any of your mod classes |
Returns
| Type | Description |
|---|---|
| System.IO.TextWriter | Text writer |
WriteFileInWorldStorage(String, Type)
Write text to file from current world's storage directory. %APPDATA%/Roaming/SpaceEngineers/Save/{SteamId}/{WorldName}/Storage/{Assembly Scope}
Declaration
TextWriter WriteFileInWorldStorage(string file, Type callingType)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | Relative file path |
| System.Type | callingType | Use any of your mod classes |
Returns
| Type | Description |
|---|---|
| System.IO.TextWriter | Text writer |
Events
MessageEntered
Old handler. Use MessageEnteredSender instead
Declaration
event MessageEnteredDel MessageEntered
Event Type
| Type | Description |
|---|---|
| MessageEnteredDel |
MessageEnteredSender
Called when player sending message. If you change SendMessageToOthers to false, message won't be sent to other players and server It may be used to handle local commands like /wave
Declaration
event MessageEnteredSenderDel MessageEnteredSender
Event Type
| Type | Description |
|---|---|
| MessageEnteredSenderDel |
MessageRecieved
Called when message arrived from server (other player). Arguments - Player SteamId and message text.
Declaration
event Action<ulong, string> MessageRecieved
Event Type
| Type | Description |
|---|---|
| System.Action<System.UInt64, System.String> |