|
28 | 28 | using SEModAPI.API.Utility; |
29 | 29 | using SEModAPI.API; |
30 | 30 | using SEModAPIExtensions.API; |
31 | | - using SEModAPIExtensions.API.Plugin; |
32 | 31 | using SEModAPIExtensions.API.Plugin.Events; |
33 | 32 | using SEModAPIInternal.API.Common; |
34 | 33 | using SEModAPIInternal.API.Entity.Sector.SectorObject; |
|
49 | 48 | using VRage.Game.Entity; |
50 | 49 | using VRage.Library.Collections; |
51 | 50 | using VRage.Network; |
| 51 | + using VRage.Plugins; |
52 | 52 | using VRage.Serialization; |
53 | 53 | using VRageMath; |
| 54 | + using IPlugin = SEModAPIExtensions.API.Plugin.IPlugin; |
54 | 55 |
|
55 | 56 | public class Essentials : IPlugin, IChatEventHandler, IPlayerEventHandler, ICubeGridHandler, ICubeBlockEventHandler, ISectorEventHandler |
56 | 57 | { |
@@ -1316,9 +1317,11 @@ private void DoInit( string path ) |
1316 | 1317 | MyAPIGateway.Multiplayer.RegisterMessageHandler(9005, Communication.ReceiveMessageParts); |
1317 | 1318 | MyAPIGateway.Multiplayer.RegisterMessageHandler( 9007, Communication.HandleAddConcealExempt ); |
1318 | 1319 | BlacklistManager.Instance.UpdateBlacklist(); |
1319 | | - //_drillUpdateVal= (int)typeof(MyDrillConstants).GetField("DRILL_UPDATE_INTERVAL_IN_FRAMES").GetValue(null); |
1320 | | - //m_entitiesForUpdate10 = (CachingList<MyEntity>)typeof(MyEntities).GetField("m_entitiesForUpdate10", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null); |
1321 | | - //_countdownField = typeof(MyShipDrill).GetField("m_drillFrameCountdown", BindingFlags.NonPublic | BindingFlags.Instance); |
| 1320 | + _drillUpdateVal= (int)typeof(MyDrillConstants).GetField("DRILL_UPDATE_INTERVAL_IN_FRAMES").GetValue(null); |
| 1321 | + m_entitiesForUpdate10 = ((MyDistributedUpdater<CachingList<MyEntity>, MyEntity>)typeof(MyEntities).GetField("m_entitiesForUpdate10", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null)).List; |
| 1322 | + _countdownField = typeof(MyShipDrill).GetField("m_drillFrameCountdown", BindingFlags.NonPublic | BindingFlags.Instance); |
| 1323 | + var pluginslist = (List<VRage.Plugins.IPlugin>)typeof(MyPlugins).GetField("m_plugins", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null); |
| 1324 | + pluginslist.Add( new FakeVRagePlugin( ) ); |
1322 | 1325 | Log.Info( "Plugin '{0}' initialized. (Version: {1} ID: {2})", Name, Version, Id ); |
1323 | 1326 | } |
1324 | 1327 |
|
@@ -1452,9 +1455,9 @@ public void Shutdown( ) |
1452 | 1455 | } |
1453 | 1456 |
|
1454 | 1457 | //private int _updateCounter; |
1455 | | - //private int _drillUpdateVal; |
1456 | | - //static CachingList<MyEntity> m_entitiesForUpdate10; |
1457 | | - //private FieldInfo _countdownField; |
| 1458 | + private int _drillUpdateVal; |
| 1459 | + static CachingList<MyEntity> m_entitiesForUpdate10; |
| 1460 | + private FieldInfo _countdownField; |
1458 | 1461 |
|
1459 | 1462 | public void Update( ) |
1460 | 1463 | { |
@@ -1483,6 +1486,31 @@ public void Update( ) |
1483 | 1486 |
|
1484 | 1487 | #endregion |
1485 | 1488 |
|
| 1489 | + public void GameUpdate() |
| 1490 | + { |
| 1491 | + if (MyAPIGateway.Session == null) |
| 1492 | + return; |
| 1493 | + |
| 1494 | + //if (++_updateCounter % 10 != 0) |
| 1495 | + // return; |
| 1496 | + |
| 1497 | + |
| 1498 | + //Wrapper.BeginGameAction(() => |
| 1499 | + //{ |
| 1500 | + //foreach (var entity in m_entitiesForUpdate10) |
| 1501 | + for (int i = 0; i < m_entitiesForUpdate10.Count; i++) |
| 1502 | + { |
| 1503 | + var entity = m_entitiesForUpdate10[i]; |
| 1504 | + if (!(entity is MyShipDrill)) |
| 1505 | + continue; |
| 1506 | + //Log.Debug( "Update " + entity.DisplayName ); |
| 1507 | + int val = (int)_countdownField.GetValue(entity); |
| 1508 | + val -= PluginSettings.Instance.DrillSpeed / 10; |
| 1509 | + _countdownField.SetValue(entity, val); |
| 1510 | + } |
| 1511 | + //}, null, null); |
| 1512 | + } |
| 1513 | + |
1486 | 1514 | #region IChatEventHandler Members |
1487 | 1515 |
|
1488 | 1516 | public void OnMessageReceived( ) |
@@ -1731,5 +1759,22 @@ public Version Version |
1731 | 1759 | } |
1732 | 1760 |
|
1733 | 1761 | #endregion |
| 1762 | + |
1734 | 1763 | } |
| 1764 | + |
| 1765 | + class FakeVRagePlugin : VRage.Plugins.IPlugin |
| 1766 | + { |
| 1767 | + public void Dispose( ) |
| 1768 | + { |
| 1769 | + } |
| 1770 | + |
| 1771 | + public void Init( object gameInstance ) |
| 1772 | + { |
| 1773 | + } |
| 1774 | + |
| 1775 | + public void Update( ) |
| 1776 | + { |
| 1777 | + Essentials.Instance.GameUpdate( ); |
| 1778 | + } |
| 1779 | + } |
1735 | 1780 | } |
0 commit comments