• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubybathyscaphegamephpguicwindows翻訳pythonomegattwitterframeworkbtronarduinovb.net計画中(planning stage)directxpreviewertestゲームエンジンdom

VS plugin mod for Basic Armour


Commit MetaInfo

Revision0f6600dd68a2dc4ff1d0bf23065fb40efca436b5 (tree)
Zeit2019-05-24 11:50:30
Autormelchior <melchior@user...>
Commitermelchior

Log Message

* ArmourModHookin.cs: Changes to delay events, attempt to prevent

duplicate event calls...

* EntityArmourPlayer.cs: Changed attach timing for client replacement

entity

Ändern Zusammenfassung

Diff

--- a/ArmourMod/Armour/ArmourModHookin.cs
+++ b/ArmourMod/Armour/ArmourModHookin.cs
@@ -75,9 +75,7 @@ namespace ArmourMod
7575 //Both Server parts and Client part(s)
7676 base.Start(api);
7777 this.CoreAPI = api;
78- var entityPlayerClassName = api.ClassRegistry.GetEntityClassName( typeof(EntityPlayer) );
79- api.RegisterEntity( entityPlayerClassName, typeof(EntityArmourPlayer) );// class swap 'EntityPlayer'
80- Mod.Logger.Notification("Replaced EntityPlayer with Armour version");
78+
8179 }
8280
8381 public override void StartServerSide(ICoreServerAPI api)
@@ -87,28 +85,27 @@ namespace ArmourMod
8785 this.ServerAPI = api;
8886
8987 PrepareServersideConfig( );
88+ AttachPlayerEntity( );
9089 }
9190
9291 public override void StartClientSide(ICoreClientAPI ClientApi)
9392 {
9493 this.ClientAPI = ClientApi;
95- ClientApi.Event.BlockTexturesLoaded += () => {
96- #if DEBUG
97- Mod.Logger.VerboseDebug( "Armour Mod Populate Armoury, Attach Renderers " );
98- #endif
9994
100- var armorData = PopulateArmoury( ClientApi );
101- ArmourMeshRenderer theOne = new ArmourMeshRenderer(ClientApi, armorData );
95+ ListenForServerConfigMessage( );
10296
103- //#if RENDER
104- Mod.Logger.VerboseDebug( "Registering Renderers for Armour");
105- ClientApi.Event.RegisterRenderer(theOne, EnumRenderStage.Opaque,this.Mod.Info.Name);
106- ClientApi.Event.RegisterRenderer(theOne, EnumRenderStage.ShadowFar,this.Mod.Info.Name);
107- ClientApi.Event.RegisterRenderer(theOne, EnumRenderStage.ShadowNear,this.Mod.Info.Name);
108- //#endif
109- };
97+ ClientApi.Event.BlockTexturesLoaded += ( ) => {
11098
111- ListenForServerConfigMessage( );
99+ if (ClientAPI.Network.DidReceiveChannelId(_domain)) {//Possible race condtion still?
100+ Mod.Logger.Debug("Message channel WAS ack'd by server: {0}, wiring up client", _domain);
101+ AttachPlayerEntity( );
102+ AttachRenderers( );
103+ } else {
104+ Mod.Logger.Error("Message channel NOT ack'd by server: {0}", _domain);
105+ //Unload rest of mod?
106+
107+ }
108+ };
112109 }
113110
114111 #region Configuration Synch-up
@@ -258,6 +255,28 @@ namespace ArmourMod
258255
259256 return Armoury;
260257 }
258+
259+ private void AttachRenderers( )
260+ {
261+ #if DEBUG
262+ Mod.Logger.VerboseDebug("Armour Mod Populate Armoury, Attach Renderers ");
263+ #endif
264+ var armorData = PopulateArmoury(this.ClientAPI);
265+ ArmourMeshRenderer theOne = new ArmourMeshRenderer(ClientAPI, armorData);
266+
267+
268+ Mod.Logger.VerboseDebug("Registering Renderers for Armour");
269+ ClientAPI.Event.RegisterRenderer(theOne, EnumRenderStage.Opaque, this.Mod.Info.Name);
270+ ClientAPI.Event.RegisterRenderer(theOne, EnumRenderStage.ShadowFar, this.Mod.Info.Name);
271+ ClientAPI.Event.RegisterRenderer(theOne, EnumRenderStage.ShadowNear, this.Mod.Info.Name);
272+ }
273+
274+ private void AttachPlayerEntity( )
275+ {
276+ var entityPlayerClassName = CoreAPI.ClassRegistry.GetEntityClassName(typeof(EntityPlayer));
277+ CoreAPI.RegisterEntity(entityPlayerClassName, typeof(EntityArmourPlayer));// class swap 'EntityPlayer'
278+ Mod.Logger.Notification("Replaced EntityPlayer with Armour version");
279+ }
261280 }
262281 }
263282
--- a/ArmourMod/Armour/EntityArmourPlayer.cs
+++ b/ArmourMod/Armour/EntityArmourPlayer.cs
@@ -24,6 +24,8 @@ namespace ArmourMod
2424 private DamageFilter finalFilter;
2525
2626 private long recurringClientDelayHookId;
27+ private long oneShotDelayId;
28+ private bool slotEventAttached;
2729
2830
2931 internal ArmourModConfig CachedConfiguration
@@ -69,18 +71,18 @@ namespace ArmourMod
6971 #if DEBUG
7072 Logger.VerboseDebug( "OnEntityLoaded - EntityArmourPlayer" );
7173
72- Logger.VerboseDebug( "Side:{0}, gearInv == null?{1}", CoreAPI.Side.ToString( ), base.GearInventory == null );
74+ Logger.VerboseDebug( "Side:{0}, gearInv == null?{1}", CoreAPI.Side.ToString( ), this.GearInventory == null );
7375 #endif
7476
7577 if ( CoreAPI.Side.IsClient() ) {
7678
7779 //Attach to Inventory events
7880 #if DEBUG
79- Logger.VerboseDebug( "Side:{0}, gearInv == null?{1}", CoreAPI.Side.ToString( ), base.GearInventory == null );
81+ Logger.VerboseDebug( "Side:{0}, gearInv == null?{1}", CoreAPI.Side.ToString( ), this.GearInventory == null );
8082 #endif
8183
8284
83- ClientAPI.Event.PlayerJoin += ClientDelayHook;
85+ this.oneShotDelayId = ClientAPI.Event.RegisterGameTickListener(ClientDelayHook, 250);
8486 }
8587 }
8688
@@ -95,10 +97,10 @@ namespace ArmourMod
9597 if ( CoreAPI.Side.IsServer() ) {
9698 //Attach to Inventory events
9799 #if DEBUG
98- Logger.VerboseDebug( "Side:{0}, gearInv == null?{1}", CoreAPI.Side.ToString( ), base.GearInventory == null );
100+ Logger.VerboseDebug( "Side:{0}, gearInv == null?{1}", CoreAPI.Side.ToString( ), this.GearInventory == null );
99101 #endif
100102
101- base.GearInventory.SlotModified += ServerWatchSlotModified;
103+ this.GearInventory.SlotModified += ServerWatchSlotModified;
102104 //this.LeftHandItemSlot.//Check also for shields
103105
104106 //base.GearInventory.SlotNotified += WatchSlotNotified;
@@ -254,21 +256,27 @@ namespace ArmourMod
254256 }
255257
256258
257- protected void ClientDelayHook(IClientPlayer byPlayer)
258- {
259- if (base.GearInventory == null) {
259+ protected void ClientDelayHook(float delay)
260+ {
261+ ClientAPI.Event.UnregisterGameTickListener(oneShotDelayId);
262+
263+ if (this.GearInventory == null) {
260264 Logger.Error("ClientDelayHook: base.GearInventory IS NULL! ");
261265 recurringClientDelayHookId = ClientAPI.Event.RegisterCallback(RecurringClientDelayHook, 100);
262266 return;
263267 }
264268
265- base.GearInventory.SlotModified += ClientWatchSlotModified;
269+ if (slotEventAttached == false) {
270+ slotEventAttached = true;
271+ this.GearInventory.SlotModified += ClientWatchSlotModified;
272+ }
273+
266274 PopulateWornArmourModels( );
267275 }
268276
269277 protected void RecurringClientDelayHook(float delayed)
270278 {
271- if (base.GearInventory == null) {
279+ if (this.GearInventory == null) {
272280 Logger.Error("RecurringClientDelayHook: base.GearInventory IS NULL! ");
273281
274282 return;
@@ -277,7 +285,10 @@ namespace ArmourMod
277285
278286 ClientAPI.Event.UnregisterCallback(recurringClientDelayHookId);
279287
280- base.GearInventory.SlotModified += ClientWatchSlotModified;
288+ if (slotEventAttached == false) {
289+ slotEventAttached = true;
290+ this.GearInventory.SlotModified += ClientWatchSlotModified;
291+ }
281292 PopulateWornArmourModels( );
282293 }
283294 }
@@ -286,7 +297,7 @@ namespace ArmourMod
286297
287298 private void ServerWatchSlotModified (int slotId)
288299 {
289- var watchedSlot = base.GearInventory[slotId];
300+ var watchedSlot = this.GearInventory[slotId];
290301 #if DEBUG
291302 Logger.VerboseDebug( "WatchSlotModified:{0}", slotId );
292303 #endif
@@ -323,7 +334,7 @@ namespace ArmourMod
323334 #if DEBUG
324335 Logger.VerboseDebug( "(Client) WatchSlotModified:{0}", slotId );
325336 #endif
326- var watchedSlot = base.GearInventory[slotId];
337+ var watchedSlot = this.GearInventory[slotId];
327338
328339 if ( !watchedSlot.Empty ) {
329340