// // ExternalNosBrowser.cs // // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Diagnostics; using Microsoft.Extensions.Options; using NosSmooth.LocalBinding.Options; using NosSmooth.LocalBinding.Structs; using Reloaded.Memory.Sigscan; using Reloaded.Memory.Sources; using Remora.Results; namespace NosSmooth.LocalBinding; /// /// Used for browsing a nostale process data. /// public class ExternalNosBrowser { private readonly PlayerManagerOptions _playerManagerOptions; private readonly SceneManagerOptions _sceneManagerOptions; private readonly PetManagerOptions _petManagerOptions; private PlayerManager? _playerManager; private SceneManager? _sceneManager; private PetManagerList? _petManagerList; /// /// Initializes a new instance of the class. /// /// The process to browse. /// The options for obtaining player manager. /// The scene manager options. /// The pet manager options. public ExternalNosBrowser ( Process process, PlayerManagerOptions playerManagerOptions, SceneManagerOptions sceneManagerOptions, PetManagerOptions petManagerOptions ) { _playerManagerOptions = playerManagerOptions; _sceneManagerOptions = sceneManagerOptions; _petManagerOptions = petManagerOptions; Process = process; Memory = new ExternalMemory(process); Scanner = new Scanner(process, process.MainModule); } /// /// The NosTale process. /// public Process Process { get; } /// /// Gets the memory scanner. /// internal Scanner Scanner { get; } /// /// Gets the current process memory. /// internal IMemory Memory { get; } /// /// Get the player manager. /// /// The player manager or an error. public Result GetPlayerManager() { if (_playerManager is null) { var playerManagerResult = PlayerManager.Create(this, _playerManagerOptions); if (!playerManagerResult.IsSuccess) { return playerManagerResult; } _playerManager = playerManagerResult.Entity; } return _playerManager; } /// /// Get the player manager. /// /// The player manager or an error. public Result GetSceneManager() { if (_sceneManager is null) { var sceneManagerResult = SceneManager.Create(this, _sceneManagerOptions); if (!sceneManagerResult.IsSuccess) { return sceneManagerResult; } _sceneManager = sceneManagerResult.Entity; } return _sceneManager; } /// /// Get the pet manager list. /// /// The player manager or an error. public Result GetPetManagerList() { if (_petManagerList is null) { var petManagerResult = PetManagerList.Create(this, _petManagerOptions); if (!petManagerResult.IsSuccess) { return petManagerResult; } _petManagerList = petManagerResult.Entity; } return _petManagerList; } }