mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
chore: use ConcurrentDictionary in SigScanner
This commit is contained in:
parent
7760457dc5
commit
cf13e4f69d
1 changed files with 7 additions and 12 deletions
|
|
@ -1,11 +1,12 @@
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Dalamud.IoC;
|
||||
using Dalamud.IoC.Internal;
|
||||
using Dalamud.Utility.Timing;
|
||||
|
|
@ -27,7 +28,7 @@ namespace Dalamud.Game
|
|||
private IntPtr moduleCopyPtr;
|
||||
private long moduleCopyOffset;
|
||||
|
||||
private Dictionary<string, long>? textCache;
|
||||
private ConcurrentDictionary<string, long>? textCache;
|
||||
|
||||
[ServiceManager.ServiceConstructor]
|
||||
private SigScanner(DalamudStartInfo startInfo)
|
||||
|
|
@ -341,15 +342,12 @@ namespace Dalamud.Game
|
|||
public IntPtr ScanText(string signature)
|
||||
{
|
||||
if (this.textCache != null)
|
||||
{
|
||||
lock (this.textCache)
|
||||
{
|
||||
if (this.textCache.TryGetValue(signature, out var address))
|
||||
{
|
||||
return new IntPtr(address + this.Module.BaseAddress.ToInt64());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var mBase = this.IsCopy ? this.moduleCopyPtr : this.TextSectionBase;
|
||||
var scanRet = Scan(mBase, this.TextSectionSize, signature);
|
||||
|
|
@ -363,12 +361,9 @@ namespace Dalamud.Game
|
|||
scanRet = ReadJmpCallSig(scanRet);
|
||||
|
||||
if (this.textCache != null)
|
||||
{
|
||||
lock (this.textCache)
|
||||
{
|
||||
this.textCache[signature] = scanRet.ToInt64() - this.Module.BaseAddress.ToInt64();
|
||||
}
|
||||
}
|
||||
|
||||
return scanRet;
|
||||
}
|
||||
|
|
@ -563,7 +558,7 @@ namespace Dalamud.Game
|
|||
return;
|
||||
}
|
||||
|
||||
this.textCache = JsonConvert.DeserializeObject<Dictionary<string, long>>(File.ReadAllText(this.cacheFile.FullName)) ?? new Dictionary<string, long>();
|
||||
this.textCache = JsonConvert.DeserializeObject<ConcurrentDictionary<string, long>>(File.ReadAllText(this.cacheFile.FullName)) ?? new ConcurrentDictionary<string, long>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue