@@ -382,67 +382,37 @@ uint32_t Mod::pauseArtAttackTimer()
382
382
return mPFN_scissor_timer_main_trampoline ();
383
383
}
384
384
385
- void clearHeapArray (const char **& heap)
385
+ void clearHeapArray (const char **heap)
386
386
{
387
- const char **tempHeapArray = heap;
388
- if (!tempHeapArray)
389
- {
390
- // The array is already cleared
391
- return ;
392
- }
393
-
394
387
uint32_t Counter = 0 ;
395
- const char *tempHeap = tempHeapArray[Counter];
396
-
397
- while (tempHeap)
388
+ while (heap[Counter])
398
389
{
399
390
delete[] heap[Counter];
391
+ heap[Counter] = nullptr ;
400
392
Counter++;
401
- tempHeap = tempHeapArray[Counter];
402
393
}
403
-
404
- delete[] heap;
405
- heap = nullptr ;
406
394
}
407
395
408
- void addTextToHeapArray (const char **& heap, char *text)
396
+ void addTextToHeapArray (const char **heap, char *text)
409
397
{
410
398
// Get the next available slot in the array
411
- uint32_t FreeSlot = 0 ;
399
+ uint32_t TotalSlots = 16 ;
400
+ int32_t FreeSlot = -1 ;
412
401
413
- if (!heap)
414
- {
415
- heap = new const char *[2 ]; // Extra slot at the end
416
- clearMemory (heap, 2 * sizeof (const char **));
417
- }
418
- else
402
+ for (uint32_t i = 0 ; i < TotalSlots; i++)
419
403
{
420
- const char **tempHeapArray = heap;
421
- const char *tempPtr;
422
-
423
- do
424
- {
425
- FreeSlot++;
426
- tempPtr = tempHeapArray[FreeSlot];
427
- }
428
- while (tempPtr);
429
-
430
- // Create a new array with a new spot for the next value
431
- uint32_t TotalSlots = FreeSlot + 1 ;
432
- const char **tempNewHeapArray = new const char *[TotalSlots + 1 ];
433
- clearMemory (tempNewHeapArray, (TotalSlots + 1 ) * sizeof (const char **));
434
-
435
- // Copy the contents of the old array to the new array
436
- for (uint32_t i = 0 ; i < FreeSlot; i++)
404
+ if (!heap[i])
437
405
{
438
- tempNewHeapArray[i] = tempHeapArray[i];
406
+ FreeSlot = i;
407
+ break ;
439
408
}
440
-
441
- // Delete the old array
442
- delete[] (heap);
443
-
444
- // Set the new array as the current array
445
- heap = tempNewHeapArray;
409
+ }
410
+
411
+ // Make sure the new text can be added
412
+ if (FreeSlot == -1 )
413
+ {
414
+ // The new text cannot be added
415
+ return ;
446
416
}
447
417
448
418
// Add the new text at the current free slot
@@ -452,30 +422,24 @@ void addTextToHeapArray(const char **&heap, char *text)
452
422
heap[FreeSlot] = NewText;
453
423
}
454
424
455
- bool checkIfTextAlreadyAdded (const char **& heap, const char *text, uint32_t bytesToCompare)
425
+ bool checkIfTextAlreadyAdded (const char **heap, const char *text, uint32_t bytesToCompare)
456
426
{
457
- const char **tempHeapArray = heap ;
458
- if (tempHeapArray )
427
+ uint32_t Counter = 0 ;
428
+ while (heap[Counter] )
459
429
{
460
- uint32_t Counter = 0 ;
461
- const char *tempHeapString = tempHeapArray[Counter];
462
-
463
- while (tempHeapString)
430
+ if (compareStringsSize (heap[Counter], text, bytesToCompare))
464
431
{
465
- if (compareStringsSize (tempHeapString, text, bytesToCompare))
466
- {
467
- return true ;
468
- }
469
-
470
- Counter++;
471
- tempHeapString = tempHeapArray[Counter];
432
+ return true ;
472
433
}
434
+ Counter++;
473
435
}
474
436
return false ;
475
437
}
476
438
477
439
void checkHeaps ()
478
440
{
441
+ const char **tempStandardHeapArray = CheckHeap.StandardHeapArray ;
442
+ const char **tempSmartHeapArray = CheckHeap.SmartHeapArray ;
479
443
char *tempDisplayBuffer = DisplayBuffer;
480
444
481
445
// Check the standard heaps
@@ -524,17 +488,17 @@ void checkHeaps()
524
488
reinterpret_cast <uint32_t >(currentChunk));
525
489
526
490
// Only add the current heap once
527
- if (!checkIfTextAlreadyAdded (CheckHeap. StandardHeapArray , tempDisplayBuffer, 16 ))
491
+ if (!checkIfTextAlreadyAdded (tempStandardHeapArray , tempDisplayBuffer, 16 ))
528
492
{
529
- addTextToHeapArray (CheckHeap. StandardHeapArray , tempDisplayBuffer);
493
+ addTextToHeapArray (tempStandardHeapArray , tempDisplayBuffer);
530
494
}
531
495
}
532
496
}
533
497
534
498
if (!ErrorsFound)
535
499
{
536
500
// No errors were found, so clear the standard heap array
537
- clearHeapArray (CheckHeap. StandardHeapArray );
501
+ clearHeapArray (tempStandardHeapArray );
538
502
}
539
503
540
504
// Check the smart heap
@@ -576,19 +540,19 @@ void checkHeaps()
576
540
reinterpret_cast <uint32_t >(currentChunk));
577
541
578
542
// Only add the current heap once
579
- if (!checkIfTextAlreadyAdded (CheckHeap. SmartHeapArray , tempDisplayBuffer, 16 ))
543
+ if (!checkIfTextAlreadyAdded (tempSmartHeapArray , tempDisplayBuffer, 16 ))
580
544
{
581
- addTextToHeapArray (CheckHeap. SmartHeapArray , tempDisplayBuffer);
545
+ addTextToHeapArray (tempSmartHeapArray , tempDisplayBuffer);
582
546
}
583
547
}
584
548
else
585
549
{
586
550
// No errors were found, so clear the smart heap array
587
- clearHeapArray (CheckHeap. SmartHeapArray );
551
+ clearHeapArray (tempSmartHeapArray );
588
552
}
589
553
590
554
// Draw any errors that occured
591
- if (CheckHeap. StandardHeapArray || CheckHeap. SmartHeapArray )
555
+ if (tempStandardHeapArray[ 0 ] || tempSmartHeapArray[ 0 ] )
592
556
{
593
557
drawFunctionOnDebugLayer (drawHeapArrayErrors);
594
558
}
0 commit comments