bool InitializeGameDataReaders() { foreach (var desc in this.processDescriptions) { try { reader = ProcessMemoryReader.Create(desc.ProcessName, desc.ModuleName); memory = CreateGameMemoryTableForReader(reader); } catch (ProcessNotFoundException) { CleanUpDataReaders(); } catch (ModuleNotLoadedException) { CleanUpDataReaders(); } if (reader != null) { break; } } if (reader == null) { return(false); } Logger.Info($"Diablo II process found:"); Logger.Info(reader.ProcessInfo); OnProcessFound(new ProcessFoundEventArgs(reader.ProcessInfo)); try { CreateReaders(); return(true); } catch (ModuleNotLoadedException e) { Logger.Error($"Try launching a game. Module not loaded: {e.ModuleName}", e); CleanUpDataReaders(); return(false); } catch (GameVersionUnsupportedException e) { Logger.Error($"Version not supported: {e.GameVersion}", e); CleanUpDataReaders(); return(false); } catch (ProcessMemoryReadException e) { Logger.Error($"Failed to read memory: {e.Message}", e); CleanUpDataReaders(); return(false); } }
void CleanUpDataReaders() { reader?.Dispose(); reader = null; memory = null; inventoryReader = null; unitReader = null; skillReader = null; }
// foreach (var item in unitReader.inventoryReader.EnumerateInventoryBackward(player, FilterSlots)) bool InitializeGameDataReaders() { foreach (var desc in this.processDescriptions) { try { reader = new ProcessMemoryReader(desc.ProcessName, desc.ModuleName, desc.SubModules); } catch (ProcessNotFoundException) { CleanUpDataReaders(); } if (reader != null) { break; } } if (reader == null) { return(false); } try { memory = CreateGameMemoryTableForReader(reader); CreateUnitReader(); Logger.Info($"Found the Diablo II process (version {reader.FileVersion})."); return(true); } catch (ModuleNotLoadedException e) { Logger.Error($"Diablo II Process was found, but the module {e.ModuleName} was not yet loaded. Try launching a game."); CleanUpDataReaders(); return(false); } catch (GameVersionUnsupportedException e) { Logger.Error($"Diablo II Process was found, but the version {e.GameVersion} is not supported."); CleanUpDataReaders(); return(false); } catch (ProcessMemoryReadException) { Logger.Error("Diablo II Process was found but failed to read memory."); CleanUpDataReaders(); return(false); } void CleanUpDataReaders() { reader?.Dispose(); reader = null; memory = null; unitReader = null; } }