Skip to content

Commit 89386c1

Browse files
committed
Initial commit
1 parent 0875c29 commit 89386c1

8 files changed

+287
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,7 @@ ASALocalRun/
328328

329329
# MFractors (Xamarin productivity tool) working folder
330330
.mfractor/
331+
332+
# Deps
333+
/GameBinaries
334+
/TorchBinaries
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
:: This script creates a symlink to the game binaries to account for different installation directories on different systems.
2+
3+
@echo off
4+
set /p path="Please enter the folder location of your SpaceEngineersDedicated.exe: "
5+
cd %~dp0
6+
mklink /J GameBinaries "%path%"
7+
if errorlevel 1 goto Error
8+
echo Done!
9+
goto End
10+
:Error
11+
echo An error occured creating the symlink.
12+
goto EndFinal
13+
:End
14+
15+
set /p path="Please enter the folder location of your Torch.Server.exe: "
16+
cd %~dp0
17+
mklink /J TorchBinaries "%path%"
18+
if errorlevel 1 goto Error
19+
echo Done! You can now open the Torch solution without issue.
20+
goto EndFinal
21+
:Error2
22+
echo An error occured creating the symlink.
23+
:EndFinal
24+
pause

StaticMarker/MarkerCommands.cs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Torch.Commands;
2+
using Torch.Commands.Permissions;
3+
using VRage.Game.ModAPI;
4+
5+
namespace StaticMarker
6+
{
7+
public class MarkerCommands : CommandModule
8+
{
9+
public MarkerPlugin Plugin => (MarkerPlugin)Context.Plugin;
10+
11+
[Command("gps", "Show static gps marker")]
12+
[Permission(MyPromoteLevel.None)]
13+
public void GPS()
14+
{
15+
if (!(Context?.Player?.SteamUserId > 0))
16+
{
17+
Context.Respond("Command can be used ingame only");
18+
return;
19+
}
20+
21+
Plugin.SendGPSEntries(Context.Player.IdentityId);
22+
}
23+
24+
[Command("gps reload", "Reload static gps marker from config file")]
25+
[Permission(MyPromoteLevel.Admin)]
26+
public void GPSReload()
27+
{
28+
if (Plugin.LoadConfig())
29+
Context.Respond("success");
30+
else
31+
Context.Respond("error");
32+
}
33+
}
34+
}

StaticMarker/MarkerEntriesConfig.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using VRage.Game;
7+
8+
namespace StaticMarker
9+
{
10+
public class MarkerEntriesConfig
11+
{
12+
public List<MyObjectBuilder_Gps.Entry> Entries = new List<MyObjectBuilder_Gps.Entry>();
13+
}
14+
}

StaticMarker/MarkerPlugin.cs

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using NLog;
2+
using Sandbox.Game.Screens.Helpers;
3+
using Sandbox.Game.World;
4+
using Sandbox.ModAPI;
5+
using System;
6+
using System.IO;
7+
using Torch;
8+
using Torch.API;
9+
using Torch.API.Managers;
10+
using Torch.API.Session;
11+
using Torch.Session;
12+
13+
namespace StaticMarker
14+
{
15+
public class MarkerPlugin : TorchPluginBase
16+
{
17+
const string ConfigMarkers = "StaticMarkerEntries.cfg";
18+
19+
private TorchSessionManager _sessionManager;
20+
private IMultiplayerManagerBase _multibase;
21+
private MarkerEntriesConfig _entriesConfig;
22+
23+
public static readonly Logger Log = LogManager.GetCurrentClassLogger();
24+
25+
/// <inheritdoc />
26+
public override void Init(ITorchBase torch)
27+
{
28+
base.Init(torch);
29+
30+
_sessionManager = Torch.Managers.GetManager<TorchSessionManager>();
31+
if (_sessionManager != null)
32+
_sessionManager.SessionStateChanged += SessionChanged;
33+
else
34+
Log.Warn("No session manager loaded!");
35+
36+
LoadConfig();
37+
}
38+
39+
private void SessionChanged(ITorchSession session, TorchSessionState state)
40+
{
41+
switch (state)
42+
{
43+
case TorchSessionState.Loaded:
44+
_multibase = Torch.CurrentSession.Managers.GetManager<IMultiplayerManagerBase>();
45+
if (_multibase != null)
46+
_multibase.PlayerJoined += _multibase_PlayerJoined;
47+
else
48+
Log.Warn("No multiplayer manager loaded!");
49+
break;
50+
case TorchSessionState.Unloading:
51+
if (_multibase != null)
52+
_multibase.PlayerJoined -= _multibase_PlayerJoined;
53+
break;
54+
}
55+
}
56+
57+
internal bool LoadConfig()
58+
{
59+
var success = false;
60+
var configFile = Path.Combine(StoragePath, ConfigMarkers);
61+
try
62+
{
63+
_entriesConfig = Persistent<MarkerEntriesConfig>.Load(configFile).Data;
64+
success = true;
65+
}
66+
catch (Exception e)
67+
{
68+
Log.Warn(e);
69+
}
70+
return success;
71+
}
72+
73+
private void _multibase_PlayerJoined(IPlayer obj)
74+
{
75+
Log.Info(obj.State.ToString());
76+
var idendity = MySession.Static.Players.TryGetIdentityId(obj.SteamId);
77+
if (idendity == 0)
78+
{
79+
Log.Info("Identity not found");
80+
return;
81+
}
82+
83+
SendGPSEntries(idendity);
84+
}
85+
86+
internal void SendGPSEntries(long identityId)
87+
{
88+
foreach (var entry in _entriesConfig.Entries)
89+
{
90+
MyAPIGateway.Session?.GPS.AddGps(identityId, new MyGps(entry));
91+
}
92+
}
93+
}
94+
}
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// Allgemeine Informationen über eine Assembly werden über die folgenden
6+
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
7+
// die einer Assembly zugeordnet sind.
8+
[assembly: AssemblyTitle("StaticMarker")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("StaticMarker")]
13+
[assembly: AssemblyCopyright("Copyright © 2018")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
18+
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
19+
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
20+
[assembly: ComVisible(false)]
21+
22+
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
23+
[assembly: Guid("83d180b6-9671-4ba3-bc2f-a1eb6595bc0c")]
24+
25+
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
26+
//
27+
// Hauptversion
28+
// Nebenversion
29+
// Buildnummer
30+
// Revision
31+
//
32+
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
33+
// indem Sie "*" wie unten gezeigt eingeben:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

StaticMarker/StaticMarker.csproj

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{83D180B6-9671-4BA3-BC2F-A1EB6595BC0C}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>StaticMarker</RootNamespace>
11+
<AssemblyName>StaticMarker</AssemblyName>
12+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="NLog">
35+
<HintPath>..\TorchBinaries\NLog.dll</HintPath>
36+
</Reference>
37+
<Reference Include="Sandbox.Common">
38+
<HintPath>..\GameBinaries\Sandbox.Common.dll</HintPath>
39+
</Reference>
40+
<Reference Include="Sandbox.Game">
41+
<HintPath>..\GameBinaries\Sandbox.Game.dll</HintPath>
42+
</Reference>
43+
<Reference Include="System" />
44+
<Reference Include="System.Core" />
45+
<Reference Include="System.Xml.Linq" />
46+
<Reference Include="System.Data.DataSetExtensions" />
47+
<Reference Include="Microsoft.CSharp" />
48+
<Reference Include="System.Data" />
49+
<Reference Include="System.Net.Http" />
50+
<Reference Include="System.Xml" />
51+
<Reference Include="Torch">
52+
<HintPath>..\TorchBinaries\Torch.dll</HintPath>
53+
</Reference>
54+
<Reference Include="Torch.API">
55+
<HintPath>..\TorchBinaries\Torch.API.dll</HintPath>
56+
</Reference>
57+
<Reference Include="Torch.Server">
58+
<HintPath>..\TorchBinaries\Torch.Server.exe</HintPath>
59+
</Reference>
60+
<Reference Include="VRage.Game">
61+
<HintPath>..\GameBinaries\VRage.Game.dll</HintPath>
62+
</Reference>
63+
<Reference Include="VRage.Math">
64+
<HintPath>..\GameBinaries\VRage.Math.dll</HintPath>
65+
</Reference>
66+
</ItemGroup>
67+
<ItemGroup>
68+
<Compile Include="MarkerCommands.cs" />
69+
<Compile Include="MarkerEntriesConfig.cs" />
70+
<Compile Include="MarkerPlugin.cs" />
71+
<Compile Include="Properties\AssemblyInfo.cs" />
72+
</ItemGroup>
73+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
74+
</Project>

StaticMarker/manifest.xml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0"?>
2+
<PluginManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3+
<Name>StaticMarker</Name>
4+
<Guid>2fa24e3f-6a17-4e95-a21b-fbd27289592e</Guid>
5+
<Repository>Fankserver/torchapi-static-marker</Repository>
6+
<Version>v1.0.0</Version>
7+
</PluginManifest>

0 commit comments

Comments
 (0)