mirror of
https://github.com/kwsch/NHSE.git
synced 2026-03-24 10:44:15 -05:00
Updates the Field Item Editor to render layers based on the entire map, and the per-patch positioning of each layer. Import/export will gracefully handle upgrade/downgrade, and viewport import/export will gracefully update tiles rather than a per-acre basis. Performance has also been slightly improved; no allocation is done anymore when updating the image.
101 lines
2.6 KiB
C#
101 lines
2.6 KiB
C#
using System;
|
|
using System.Windows.Forms;
|
|
using NHSE.Injection;
|
|
using NHSE.WinForms.Properties;
|
|
|
|
namespace NHSE.WinForms;
|
|
|
|
public sealed class SysBotController(InjectionType type)
|
|
{
|
|
public readonly SysBot Bot = new();
|
|
private readonly Settings _settings = Settings.Default;
|
|
|
|
public string IP => _settings.SysBotIP;
|
|
public string Port => _settings.SysBotPort.ToString();
|
|
|
|
public bool Connect(string ip, string port)
|
|
{
|
|
if (!int.TryParse(port, out var p))
|
|
p = 6000;
|
|
|
|
try
|
|
{
|
|
Bot.Connect(ip, p);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
WinFormsUtil.Error(ex.Message);
|
|
return false;
|
|
}
|
|
|
|
_settings.SysBotIP = ip;
|
|
_settings.SysBotPort = p;
|
|
_settings.Save();
|
|
|
|
return true;
|
|
}
|
|
|
|
public uint GetDefaultOffset() => type switch
|
|
{
|
|
InjectionType.Generic => _settings.SysBotGenericOffset,
|
|
InjectionType.Pouch => _settings.SysBotPouchOffset,
|
|
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null),
|
|
};
|
|
|
|
public void SetOffset(uint value)
|
|
{
|
|
switch (type)
|
|
{
|
|
case InjectionType.Generic: _settings.SysBotGenericOffset = value; break;
|
|
case InjectionType.Pouch: _settings.SysBotPouchOffset = value; break;
|
|
default: return;
|
|
}
|
|
_settings.Save();
|
|
}
|
|
|
|
public void HexEdit(uint offset, int length)
|
|
{
|
|
var read = ReadBytes(offset, length);
|
|
using var ram = new SimpleHexEditor(read);
|
|
if (ram.ShowDialog() != DialogResult.OK)
|
|
return;
|
|
|
|
var write = ram.Bytes;
|
|
if (read.Length != write.Length)
|
|
{
|
|
var prompt = WinFormsUtil.Prompt(MessageBoxButtons.OKCancel,
|
|
string.Format(MessageStrings.MsgDataSizeMismatchRAM, read.Length, write.Length),
|
|
MessageStrings.MsgAskWriteAnyway);
|
|
|
|
if (prompt != DialogResult.OK)
|
|
return;
|
|
}
|
|
|
|
WriteBytes(ram.Bytes, offset);
|
|
SetOffset(offset);
|
|
System.Media.SystemSounds.Asterisk.Play();
|
|
}
|
|
|
|
public void PopPrompt()
|
|
{
|
|
if (_settings.SysBotPrompted)
|
|
return;
|
|
|
|
WinFormsUtil.Alert(MessageStrings.MsgSysBotInfo, MessageStrings.MsgSysBotRequired);
|
|
_settings.SysBotPrompted = true;
|
|
_settings.Save();
|
|
}
|
|
|
|
public void WriteBytes(byte[] data, uint offset)
|
|
{
|
|
Bot.WriteBytes(data, offset);
|
|
SetOffset(offset);
|
|
}
|
|
|
|
public byte[] ReadBytes(uint offset, int length)
|
|
{
|
|
var result = Bot.ReadBytes(offset, length);
|
|
SetOffset(offset);
|
|
return result;
|
|
}
|
|
} |