@@ -45,9 +45,6 @@ internal unsafe class AddonVirtualTable : IDisposable
4545
4646 private readonly AtkUnitBase * atkUnitBase ;
4747
48- private readonly AtkUnitBase . AtkUnitBaseVirtualTable * originalVirtualTable ;
49- private readonly AtkUnitBase . AtkUnitBaseVirtualTable * modifiedVirtualTable ;
50-
5148 // Pinned Function Delegates, as these functions get assigned to an unmanaged virtual table,
5249 // the CLR needs to know they are in use, or it will invalidate them causing random crashing.
5350 private readonly AtkUnitBase . Delegates . Dtor destructorFunction ;
@@ -78,16 +75,16 @@ internal AddonVirtualTable(AtkUnitBase* addon, AddonLifecycle lifecycleService)
7875 this . lifecycleService = lifecycleService ;
7976
8077 // Save original virtual table
81- this . originalVirtualTable = addon ->VirtualTable ;
78+ this . OriginalVirtualTable = addon ->VirtualTable ;
8279
8380 // Create copy of original table
8481 // Note this will copy any derived/overriden functions that this specific addon has.
8582 // Note: currently there are 73 virtual functions, but there's no harm in copying more for when they add new virtual functions to the game
86- this . modifiedVirtualTable = ( AtkUnitBase . AtkUnitBaseVirtualTable * ) IMemorySpace . GetUISpace ( ) ->Malloc ( 0x8 * VirtualTableEntryCount , 8 ) ;
87- NativeMemory . Copy ( addon ->VirtualTable , this . modifiedVirtualTable , 0x8 * VirtualTableEntryCount ) ;
83+ this . ModifiedVirtualTable = ( AtkUnitBase . AtkUnitBaseVirtualTable * ) IMemorySpace . GetUISpace ( ) ->Malloc ( 0x8 * VirtualTableEntryCount , 8 ) ;
84+ NativeMemory . Copy ( addon ->VirtualTable , this . ModifiedVirtualTable , 0x8 * VirtualTableEntryCount ) ;
8885
8986 // Overwrite the addons existing virtual table with our own
90- addon ->VirtualTable = this . modifiedVirtualTable ;
87+ addon ->VirtualTable = this . ModifiedVirtualTable ;
9188
9289 // Pin each of our listener functions
9390 this . destructorFunction = this . OnAddonDestructor ;
@@ -108,30 +105,40 @@ internal AddonVirtualTable(AtkUnitBase* addon, AddonLifecycle lifecycleService)
108105 this . focusFunction = this . OnAddonFocus ;
109106
110107 // Overwrite specific virtual table entries
111- this . modifiedVirtualTable ->Dtor = ( delegate * unmanaged< AtkUnitBase * , byte , AtkEventListener * > ) Marshal . GetFunctionPointerForDelegate ( this . destructorFunction ) ;
112- this . modifiedVirtualTable ->OnSetup = ( delegate * unmanaged< AtkUnitBase * , uint , AtkValue * , void > ) Marshal . GetFunctionPointerForDelegate ( this . onSetupFunction ) ;
113- this . modifiedVirtualTable ->Finalizer = ( delegate * unmanaged< AtkUnitBase * , void > ) Marshal . GetFunctionPointerForDelegate ( this . finalizerFunction ) ;
114- this . modifiedVirtualTable ->Draw = ( delegate * unmanaged< AtkUnitBase * , void > ) Marshal . GetFunctionPointerForDelegate ( this . drawFunction ) ;
115- this . modifiedVirtualTable ->Update = ( delegate * unmanaged< AtkUnitBase * , float , void > ) Marshal . GetFunctionPointerForDelegate ( this . updateFunction ) ;
116- this . modifiedVirtualTable ->OnRefresh = ( delegate * unmanaged< AtkUnitBase * , uint , AtkValue * , bool > ) Marshal . GetFunctionPointerForDelegate ( this . onRefreshFunction ) ;
117- this . modifiedVirtualTable ->OnRequestedUpdate = ( delegate * unmanaged< AtkUnitBase * , NumberArrayData * * , StringArrayData * * , void > ) Marshal . GetFunctionPointerForDelegate ( this . onRequestedUpdateFunction ) ;
118- this . modifiedVirtualTable ->ReceiveEvent = ( delegate * unmanaged< AtkUnitBase * , AtkEventType , int , AtkEvent * , AtkEventData * , void > ) Marshal . GetFunctionPointerForDelegate ( this . onReceiveEventFunction ) ;
119- this . modifiedVirtualTable ->Open = ( delegate * unmanaged< AtkUnitBase * , uint , bool > ) Marshal . GetFunctionPointerForDelegate ( this . openFunction ) ;
120- this . modifiedVirtualTable ->Close = ( delegate * unmanaged< AtkUnitBase * , bool , bool > ) Marshal . GetFunctionPointerForDelegate ( this . closeFunction ) ;
121- this . modifiedVirtualTable ->Show = ( delegate * unmanaged< AtkUnitBase * , bool , uint , void > ) Marshal . GetFunctionPointerForDelegate ( this . showFunction ) ;
122- this . modifiedVirtualTable ->Hide = ( delegate * unmanaged< AtkUnitBase * , bool , bool , uint , void > ) Marshal . GetFunctionPointerForDelegate ( this . hideFunction ) ;
123- this . modifiedVirtualTable ->OnMove = ( delegate * unmanaged< AtkUnitBase * , void > ) Marshal . GetFunctionPointerForDelegate ( this . onMoveFunction ) ;
124- this . modifiedVirtualTable ->OnMouseOver = ( delegate * unmanaged< AtkUnitBase * , void > ) Marshal . GetFunctionPointerForDelegate ( this . onMouseOverFunction ) ;
125- this . modifiedVirtualTable ->OnMouseOut = ( delegate * unmanaged< AtkUnitBase * , void > ) Marshal . GetFunctionPointerForDelegate ( this . onMouseOutFunction ) ;
126- this . modifiedVirtualTable ->Focus = ( delegate * unmanaged< AtkUnitBase * , void > ) Marshal . GetFunctionPointerForDelegate ( this . focusFunction ) ;
108+ this . ModifiedVirtualTable ->Dtor = ( delegate * unmanaged< AtkUnitBase * , byte , AtkEventListener * > ) Marshal . GetFunctionPointerForDelegate ( this . destructorFunction ) ;
109+ this . ModifiedVirtualTable ->OnSetup = ( delegate * unmanaged< AtkUnitBase * , uint , AtkValue * , void > ) Marshal . GetFunctionPointerForDelegate ( this . onSetupFunction ) ;
110+ this . ModifiedVirtualTable ->Finalizer = ( delegate * unmanaged< AtkUnitBase * , void > ) Marshal . GetFunctionPointerForDelegate ( this . finalizerFunction ) ;
111+ this . ModifiedVirtualTable ->Draw = ( delegate * unmanaged< AtkUnitBase * , void > ) Marshal . GetFunctionPointerForDelegate ( this . drawFunction ) ;
112+ this . ModifiedVirtualTable ->Update = ( delegate * unmanaged< AtkUnitBase * , float , void > ) Marshal . GetFunctionPointerForDelegate ( this . updateFunction ) ;
113+ this . ModifiedVirtualTable ->OnRefresh = ( delegate * unmanaged< AtkUnitBase * , uint , AtkValue * , bool > ) Marshal . GetFunctionPointerForDelegate ( this . onRefreshFunction ) ;
114+ this . ModifiedVirtualTable ->OnRequestedUpdate = ( delegate * unmanaged< AtkUnitBase * , NumberArrayData * * , StringArrayData * * , void > ) Marshal . GetFunctionPointerForDelegate ( this . onRequestedUpdateFunction ) ;
115+ this . ModifiedVirtualTable ->ReceiveEvent = ( delegate * unmanaged< AtkUnitBase * , AtkEventType , int , AtkEvent * , AtkEventData * , void > ) Marshal . GetFunctionPointerForDelegate ( this . onReceiveEventFunction ) ;
116+ this . ModifiedVirtualTable ->Open = ( delegate * unmanaged< AtkUnitBase * , uint , bool > ) Marshal . GetFunctionPointerForDelegate ( this . openFunction ) ;
117+ this . ModifiedVirtualTable ->Close = ( delegate * unmanaged< AtkUnitBase * , bool , bool > ) Marshal . GetFunctionPointerForDelegate ( this . closeFunction ) ;
118+ this . ModifiedVirtualTable ->Show = ( delegate * unmanaged< AtkUnitBase * , bool , uint , void > ) Marshal . GetFunctionPointerForDelegate ( this . showFunction ) ;
119+ this . ModifiedVirtualTable ->Hide = ( delegate * unmanaged< AtkUnitBase * , bool , bool , uint , void > ) Marshal . GetFunctionPointerForDelegate ( this . hideFunction ) ;
120+ this . ModifiedVirtualTable ->OnMove = ( delegate * unmanaged< AtkUnitBase * , void > ) Marshal . GetFunctionPointerForDelegate ( this . onMoveFunction ) ;
121+ this . ModifiedVirtualTable ->OnMouseOver = ( delegate * unmanaged< AtkUnitBase * , void > ) Marshal . GetFunctionPointerForDelegate ( this . onMouseOverFunction ) ;
122+ this . ModifiedVirtualTable ->OnMouseOut = ( delegate * unmanaged< AtkUnitBase * , void > ) Marshal . GetFunctionPointerForDelegate ( this . onMouseOutFunction ) ;
123+ this . ModifiedVirtualTable ->Focus = ( delegate * unmanaged< AtkUnitBase * , void > ) Marshal . GetFunctionPointerForDelegate ( this . focusFunction ) ;
127124 }
128125
126+ /// <summary>
127+ /// Gets the original virtual table address for this addon.
128+ /// </summary>
129+ internal AtkUnitBase . AtkUnitBaseVirtualTable * OriginalVirtualTable { get ; private set ; }
130+
131+ /// <summary>
132+ /// Gets the modified virtual address for this addon.
133+ /// </summary>
134+ internal AtkUnitBase . AtkUnitBaseVirtualTable * ModifiedVirtualTable { get ; private set ; }
135+
129136 /// <inheritdoc/>
130137 public void Dispose ( )
131138 {
132139 // Ensure restoration is done atomically.
133- Interlocked . Exchange ( ref * ( nint * ) & this . atkUnitBase ->VirtualTable , ( nint ) this . originalVirtualTable ) ;
134- IMemorySpace. Free ( this . modifiedVirtualTable , 0x8 * VirtualTableEntryCount ) ;
140+ Interlocked . Exchange ( ref * ( nint * ) & this . atkUnitBase ->VirtualTable , ( nint ) this . OriginalVirtualTable ) ;
141+ IMemorySpace. Free ( this . ModifiedVirtualTable , 0x8 * VirtualTableEntryCount ) ;
135142 }
136143
137144 private AtkEventListener * OnAddonDestructor ( AtkUnitBase * thisPtr , byte freeFlags )
@@ -144,7 +151,7 @@ public void Dispose()
144151
145152 try
146153 {
147- result = this . originalVirtualTable ->Dtor ( thisPtr , freeFlags ) ;
154+ result = this . OriginalVirtualTable ->Dtor ( thisPtr , freeFlags ) ;
148155 }
149156 catch ( Exception e )
150157 {
@@ -153,7 +160,7 @@ public void Dispose()
153160
154161 if ( ( freeFlags & 1 ) == 1 )
155162 {
156- IMemorySpace . Free ( this . modifiedVirtualTable , 0x8 * VirtualTableEntryCount ) ;
163+ IMemorySpace . Free ( this . ModifiedVirtualTable , 0x8 * VirtualTableEntryCount ) ;
157164 AddonLifecycle . AllocatedTables . Remove ( this ) ;
158165 }
159166 }
@@ -182,7 +189,7 @@ private void OnAddonSetup(AtkUnitBase* addon, uint valueCount, AtkValue* values)
182189
183190 try
184191 {
185- this . originalVirtualTable ->OnSetup ( addon , valueCount , values ) ;
192+ this . OriginalVirtualTable ->OnSetup ( addon , valueCount , values ) ;
186193 }
187194 catch ( Exception e )
188195 {
@@ -209,7 +216,7 @@ private void OnAddonFinalize(AtkUnitBase* thisPtr)
209216
210217 try
211218 {
212- this . originalVirtualTable ->Finalizer ( thisPtr ) ;
219+ this . OriginalVirtualTable ->Finalizer ( thisPtr ) ;
213220 }
214221 catch ( Exception e )
215222 {
@@ -234,7 +241,7 @@ private void OnAddonDraw(AtkUnitBase* addon)
234241
235242 try
236243 {
237- this . originalVirtualTable ->Draw ( addon ) ;
244+ this . OriginalVirtualTable ->Draw ( addon ) ;
238245 }
239246 catch ( Exception e )
240247 {
@@ -265,7 +272,7 @@ private void OnAddonUpdate(AtkUnitBase* addon, float delta)
265272
266273 try
267274 {
268- this . originalVirtualTable ->Update ( addon , delta ) ;
275+ this . OriginalVirtualTable ->Update ( addon , delta ) ;
269276 }
270277 catch ( Exception e )
271278 {
@@ -299,7 +306,7 @@ private bool OnAddonRefresh(AtkUnitBase* addon, uint valueCount, AtkValue* value
299306
300307 try
301308 {
302- result = this . originalVirtualTable ->OnRefresh ( addon , valueCount , values ) ;
309+ result = this . OriginalVirtualTable ->OnRefresh ( addon , valueCount , values ) ;
303310 }
304311 catch ( Exception e )
305312 {
@@ -333,7 +340,7 @@ private void OnRequestedUpdate(AtkUnitBase* addon, NumberArrayData** numberArray
333340
334341 try
335342 {
336- this . originalVirtualTable ->OnRequestedUpdate ( addon , numberArrayData , stringArrayData ) ;
343+ this . OriginalVirtualTable ->OnRequestedUpdate ( addon , numberArrayData , stringArrayData ) ;
337344 }
338345 catch ( Exception e )
339346 {
@@ -369,7 +376,7 @@ private void OnAddonReceiveEvent(AtkUnitBase* addon, AtkEventType eventType, int
369376
370377 try
371378 {
372- this . originalVirtualTable ->ReceiveEvent ( addon , eventType , eventParam , atkEvent , atkEventData ) ;
379+ this . OriginalVirtualTable ->ReceiveEvent ( addon , eventType , eventParam , atkEvent , atkEventData ) ;
373380 }
374381 catch ( Exception e )
375382 {
@@ -398,7 +405,7 @@ private bool OnAddonOpen(AtkUnitBase* thisPtr, uint depthLayer)
398405
399406 try
400407 {
401- result = this . originalVirtualTable ->Open ( thisPtr , depthLayer ) ;
408+ result = this . OriginalVirtualTable ->Open ( thisPtr , depthLayer ) ;
402409 }
403410 catch ( Exception e )
404411 {
@@ -432,7 +439,7 @@ private bool OnAddonClose(AtkUnitBase* thisPtr, bool fireCallback)
432439
433440 try
434441 {
435- result = this . originalVirtualTable ->Close ( thisPtr , fireCallback ) ;
442+ result = this . OriginalVirtualTable ->Close ( thisPtr , fireCallback ) ;
436443 }
437444 catch ( Exception e )
438445 {
@@ -466,7 +473,7 @@ private void OnAddonShow(AtkUnitBase* thisPtr, bool silenceOpenSoundEffect, uint
466473
467474 try
468475 {
469- this . originalVirtualTable ->Show ( thisPtr , silenceOpenSoundEffect , unsetShowHideFlags ) ;
476+ this . OriginalVirtualTable ->Show ( thisPtr , silenceOpenSoundEffect , unsetShowHideFlags ) ;
470477 }
471478 catch ( Exception e )
472479 {
@@ -500,7 +507,7 @@ private void OnAddonHide(AtkUnitBase* thisPtr, bool unkBool, bool callHideCallba
500507
501508 try
502509 {
503- this . originalVirtualTable ->Hide ( thisPtr , unkBool , callHideCallback , setShowHideFlags ) ;
510+ this . OriginalVirtualTable ->Hide ( thisPtr , unkBool , callHideCallback , setShowHideFlags ) ;
504511 }
505512 catch ( Exception e )
506513 {
@@ -527,7 +534,7 @@ private void OnAddonMove(AtkUnitBase* thisPtr)
527534
528535 try
529536 {
530- this . originalVirtualTable ->OnMove ( thisPtr ) ;
537+ this . OriginalVirtualTable ->OnMove ( thisPtr ) ;
531538 }
532539 catch ( Exception e )
533540 {
@@ -554,7 +561,7 @@ private void OnAddonMouseOver(AtkUnitBase* thisPtr)
554561
555562 try
556563 {
557- this . originalVirtualTable ->OnMouseOver ( thisPtr ) ;
564+ this . OriginalVirtualTable ->OnMouseOver ( thisPtr ) ;
558565 }
559566 catch ( Exception e )
560567 {
@@ -581,7 +588,7 @@ private void OnAddonMouseOut(AtkUnitBase* thisPtr)
581588
582589 try
583590 {
584- this . originalVirtualTable ->OnMouseOut ( thisPtr ) ;
591+ this . OriginalVirtualTable ->OnMouseOut ( thisPtr ) ;
585592 }
586593 catch ( Exception e )
587594 {
@@ -608,7 +615,7 @@ private void OnAddonFocus(AtkUnitBase* thisPtr)
608615
609616 try
610617 {
611- this . originalVirtualTable ->Focus ( thisPtr ) ;
618+ this . OriginalVirtualTable ->Focus ( thisPtr ) ;
612619 }
613620 catch ( Exception e )
614621 {
0 commit comments