protected override void OnHook() { base.OnHook(); if (Instance == null) { return; } var batch = InventoryReplicableUpdate.GetNextBatch(); itemsGroup = new ItemsStateGroup(Instance, this, batch); propsGroup = new PropsStateGroup(this, Instance.SyncType, batch); Instance.BeforeRemovedFromContainer += OnRemovedFromContainer; if (Instance.Owner is MyCubeBlock block) { block.SlimBlock.CubeGridChanged += OnBlockCubeGridChanged; m_parent = FindByObject(block.CubeGrid); if (block is MyTerminalBlock tb && Plugin.StaticConfig.InventoryPreventSharing) { tb.OwnershipChanged += OnOwnershipChanged; } } else { m_parent = FindByObject(Instance.Owner); } }
void InventoryChanged(MyInventoryBase obj) { var counter = MySandboxGame.Static.SimulationFrameCounter; if (_lastFrame + (uint)InventoryReplicableUpdate.ReplicableInterval > counter) { InventoryReplicableUpdate.Schedule(this); } else { InventoryReplicableUpdate.Reset(this); MarkDirty(); } }
void Notify(SyncBase sync) { m_propertyTimestamps[sync.Id] = _server.GetSimulationUpdateTime(); var counter = MySandboxGame.Static.SimulationFrameCounter; var isStatic = (Owner as InventoryReplicable).Instance?.Entity is MyCubeBlock block && block.CubeGrid.IsStatic; if (isStatic && _lastFrame + (uint)InventoryReplicableUpdate.ReplicableInterval > counter) { InventoryReplicableUpdate.Schedule(this); } else { InventoryReplicableUpdate.Reset(this); MarkDirty(); } }
void OnRemovedFromContainer(MyEntityComponentBase obj) { InventoryReplicableUpdate.Reset(itemsGroup); InventoryReplicableUpdate.Reset(propsGroup); if (Instance?.Owner is MyCubeBlock block) { block.SlimBlock.CubeGridChanged -= OnBlockCubeGridChanged; if (block is MyTerminalBlock tb) { tb.OwnershipChanged -= OnOwnershipChanged; InventoryReplicableUpdate.ResetChangedOwnership(itemsGroup); InventoryReplicableUpdate.ResetChangedOwnership(propsGroup); } } RaiseDestroyed(); }
public bool Inject(Harmony harmony) { if (!Plugin.StaticConfig.InventoryEnabled) { return(false); } var source = AccessTools.Method(typeof(MyReplicableFactory), "FindTypeFor"); var patch = AccessTools.Method(typeof(InventoryReplicablePatch), "FindTypeForPrefix"); harmony.Patch(source, new HarmonyMethod(patch)); source = AccessTools.Method(typeof(MyTypeTable), "Register"); patch = AccessTools.Method(typeof(InventoryReplicablePatch), "RegisterPostfix"); harmony.Patch(source, null, new HarmonyMethod(patch)); InventoryReplicableUpdate.Init(); return(true); }
void OnOwnershipChanged(MyTerminalBlock block) { InventoryReplicableUpdate.OnChangedOwnership(itemsGroup); InventoryReplicableUpdate.OnChangedOwnership(propsGroup); }
public override void OnDestroyClient() { InventoryReplicableUpdate.Reset(itemsGroup); InventoryReplicableUpdate.Reset(propsGroup); }