//
// 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 PlayerManager? _playerManager;
private SceneManager? _sceneManager;
///
/// Initializes a new instance of the class.
///
/// The process to browse.
/// The options for obtaining player manager.
/// The scene manager options.
public ExternalNosBrowser
(
Process process,
PlayerManagerOptions playerManagerOptions,
SceneManagerOptions sceneManagerOptions
)
{
_playerManagerOptions = playerManagerOptions;
_sceneManagerOptions = sceneManagerOptions;
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;
}
}