From 7607ed36a26f968b8d79749ed826ab8911cac50d Mon Sep 17 00:00:00 2001 From: Brant Martin Date: Sat, 28 Jan 2017 14:29:01 -0500 Subject: [PATCH] Update for SE v172. Fix drill speed thing --- EssentialsPlugin/AssemblyFileVersion.cs | 6 +-- EssentialsPlugin/Essentials.cs | 59 ++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/EssentialsPlugin/AssemblyFileVersion.cs b/EssentialsPlugin/AssemblyFileVersion.cs index 2954713..135107a 100644 --- a/EssentialsPlugin/AssemblyFileVersion.cs +++ b/EssentialsPlugin/AssemblyFileVersion.cs @@ -1,4 +1,4 @@ -//410 +//415 // // This code was generated by a tool. Any changes made manually will be lost // the next time this code is regenerated. @@ -6,5 +6,5 @@ using System.Reflection; -[assembly: AssemblyFileVersion("1.13.7.410")] -[assembly: AssemblyVersion("1.13.7.410")] +[assembly: AssemblyFileVersion("1.13.7.415")] +[assembly: AssemblyVersion("1.13.7.415")] diff --git a/EssentialsPlugin/Essentials.cs b/EssentialsPlugin/Essentials.cs index b271fbc..5d67718 100644 --- a/EssentialsPlugin/Essentials.cs +++ b/EssentialsPlugin/Essentials.cs @@ -28,7 +28,6 @@ using SEModAPI.API.Utility; using SEModAPI.API; using SEModAPIExtensions.API; - using SEModAPIExtensions.API.Plugin; using SEModAPIExtensions.API.Plugin.Events; using SEModAPIInternal.API.Common; using SEModAPIInternal.API.Entity.Sector.SectorObject; @@ -49,8 +48,10 @@ using VRage.Game.Entity; using VRage.Library.Collections; using VRage.Network; + using VRage.Plugins; using VRage.Serialization; using VRageMath; + using IPlugin = SEModAPIExtensions.API.Plugin.IPlugin; public class Essentials : IPlugin, IChatEventHandler, IPlayerEventHandler, ICubeGridHandler, ICubeBlockEventHandler, ISectorEventHandler { @@ -1316,9 +1317,11 @@ private void DoInit( string path ) MyAPIGateway.Multiplayer.RegisterMessageHandler(9005, Communication.ReceiveMessageParts); MyAPIGateway.Multiplayer.RegisterMessageHandler( 9007, Communication.HandleAddConcealExempt ); BlacklistManager.Instance.UpdateBlacklist(); - //_drillUpdateVal= (int)typeof(MyDrillConstants).GetField("DRILL_UPDATE_INTERVAL_IN_FRAMES").GetValue(null); - //m_entitiesForUpdate10 = (CachingList)typeof(MyEntities).GetField("m_entitiesForUpdate10", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null); - //_countdownField = typeof(MyShipDrill).GetField("m_drillFrameCountdown", BindingFlags.NonPublic | BindingFlags.Instance); + _drillUpdateVal= (int)typeof(MyDrillConstants).GetField("DRILL_UPDATE_INTERVAL_IN_FRAMES").GetValue(null); + m_entitiesForUpdate10 = ((MyDistributedUpdater, MyEntity>)typeof(MyEntities).GetField("m_entitiesForUpdate10", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null)).List; + _countdownField = typeof(MyShipDrill).GetField("m_drillFrameCountdown", BindingFlags.NonPublic | BindingFlags.Instance); + var pluginslist = (List)typeof(MyPlugins).GetField("m_plugins", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null); + pluginslist.Add( new FakeVRagePlugin( ) ); Log.Info( "Plugin '{0}' initialized. (Version: {1} ID: {2})", Name, Version, Id ); } @@ -1452,9 +1455,9 @@ public void Shutdown( ) } //private int _updateCounter; - //private int _drillUpdateVal; - //static CachingList m_entitiesForUpdate10; - //private FieldInfo _countdownField; + private int _drillUpdateVal; + static CachingList m_entitiesForUpdate10; + private FieldInfo _countdownField; public void Update( ) { @@ -1483,6 +1486,31 @@ public void Update( ) #endregion + public void GameUpdate() + { + if (MyAPIGateway.Session == null) + return; + + //if (++_updateCounter % 10 != 0) + // return; + + + //Wrapper.BeginGameAction(() => + //{ + //foreach (var entity in m_entitiesForUpdate10) + for (int i = 0; i < m_entitiesForUpdate10.Count; i++) + { + var entity = m_entitiesForUpdate10[i]; + if (!(entity is MyShipDrill)) + continue; + //Log.Debug( "Update " + entity.DisplayName ); + int val = (int)_countdownField.GetValue(entity); + val -= PluginSettings.Instance.DrillSpeed / 10; + _countdownField.SetValue(entity, val); + } + //}, null, null); + } + #region IChatEventHandler Members public void OnMessageReceived( ) @@ -1731,5 +1759,22 @@ public Version Version } #endregion + } + + class FakeVRagePlugin : VRage.Plugins.IPlugin + { + public void Dispose( ) + { + } + + public void Init( object gameInstance ) + { + } + + public void Update( ) + { + Essentials.Instance.GameUpdate( ); + } + } }