Initial commit

A modern .NET 9 NativeAOT framework for Asheron's Call client modding.
Self-contained injection system that hooks D3D9 EndScene to render an
ImGui overlay inside the AC client process.
This commit is contained in:
tombohar 2026-04-10 18:38:07 -04:00
commit 80b71d295d
179 changed files with 52858 additions and 0 deletions

View file

@ -0,0 +1,115 @@
using System;
using System.Text.RegularExpressions;
using Decal.Adapter.Wrappers;
namespace NexSuite.Plugins.RynthAi
{
public class LuaBridge
{
private readonly PluginCore _core;
// Returns the actual North/South coordinate (e.g. 42.5)
public double GetPlayerNS()
{
return Decal.Adapter.CoreManager.Current.WorldFilter[Decal.Adapter.CoreManager.Current.CharacterFilter.Id].Coordinates().NorthSouth;
}
// Returns the actual East/West coordinate (e.g. -33.7)
public double GetPlayerEW()
{
return Decal.Adapter.CoreManager.Current.WorldFilter[Decal.Adapter.CoreManager.Current.CharacterFilter.Id].Coordinates().EastWest;
}
// Returns the altitude in meters
public double GetPlayerZ()
{
return Decal.Adapter.CoreManager.Current.Actions.LocationZ;
}
public LuaBridge(PluginCore core)
{
_core = core;
}
// --- MOVEMENT ---
public void GoTo(string ns, string ew)
{
double dNS = ParseCoord(ns);
double dEW = ParseCoord(ew);
_core.UI.Settings.CurrentRoute.Points.Clear();
_core.UI.Settings.CurrentRoute.Points.Add(new NavPoint { NS = dNS, EW = dEW, Type = NavPointType.Point });
_core.UI.Settings.CurrentRoute.RouteType = NavRouteType.Once;
_core.UI.Settings.ActiveNavIndex = 0;
_core.UI.Settings.IsMacroRunning = true;
_core.UI.Settings.EnableNavigation = true;
if (_core.UI?.RouteTab != null) _core.UI.RouteTab.NeedsRouteGraphicsRefresh = true;
_core.PluginHost.Actions.AddChatText($"[RynthLua] Navigating to: {ns}, {ew}", 1);
}
public void Stop()
{
_core.UI.Settings.IsMacroRunning = false;
_core.UI.Settings.EnableNavigation = false;
_core.PluginHost.Actions.AddChatText("[RynthLua] Macro Stopped.", 1);
}
// --- INTERACTION ---
public void UsePortal(string portalName)
{
foreach (WorldObject wo in _core.PluginCoreManager.WorldFilter.GetLandscape())
{
if (wo.Name.IndexOf(portalName, StringComparison.OrdinalIgnoreCase) >= 0)
{
if (wo.ObjectClass == ObjectClass.Portal || wo.ObjectClass == ObjectClass.Npc)
{
// The correct Decal API call: UseItem(GUID, ContainerID)
// We use 0 for the container because portals are in the world.
_core.PluginHost.Actions.UseItem(wo.Id, 0);
return;
}
}
}
}
// --- UTILS ---
private double ParseCoord(string val)
{
if (string.IsNullOrEmpty(val)) return 0;
string clean = Regex.Replace(val, "[^0-9.-]", "");
if (!double.TryParse(clean, out double result)) return 0;
return (val.ToUpper().Contains("S") || val.ToUpper().Contains("W")) ? -result : result;
}
public bool IsPathClear(double startNS, double startEW, double startZ, double endNS, double endEW, double endZ)
{
try
{
// Use '_core' instead of '_plugin'
if (_core.Raycast == null || !_core.Raycast.IsInitialized)
return true;
// Convert EW/NS to Global Meters
float startX = (float)((startEW * 10.0 + 1019.5) * 24.0);
float startY = (float)((startNS * 10.0 + 1019.5) * 24.0);
var origin = new RynthAi.Raycasting.Vector3(startX, startY, (float)startZ + 1.0f);
float endX = (float)((endEW * 10.0 + 1019.5) * 24.0);
float endY = (float)((endNS * 10.0 + 1019.5) * 24.0);
var destination = new RynthAi.Raycasting.Vector3(endX, endY, (float)endZ + 1.0f);
// Access Landcell safely via CoreManager
uint landcell = (uint)Decal.Adapter.CoreManager.Current.Actions.Landcell;
var geometry = _core.Raycast.GeometryLoader.GetLandblockGeometry(landcell);
// Test the line
return !RynthAi.Raycasting.RaycastEngine.IsLinearPathBlocked(origin, destination, geometry);
}
catch
{
return true; // Default to assuming clear if it fails, to prevent the bot from freezing
}
}
}
}

View file

@ -0,0 +1,154 @@
using System;
using System.Text;
using NLua;
using Decal.Adapter;
using Decal.Adapter.Wrappers;
using System.IO;
namespace NexSuite.Plugins.RynthAi
{
public class LuaManager : IDisposable
{
private Lua _lua;
private readonly PluginCore _core;
private bool _isDisposed;
public void Execute(string script) => ExecuteString(script);
public LuaManager(PluginCore core)
{
_core = core;
Init();
}
public void Init()
{
try
{
// 1. Clean up old state if re-initializing to prevent memory leaks
_lua?.Dispose();
// 2. Initialize the fresh NLua state
_lua = new Lua();
_lua.LoadCLRPackage();
// 3. Instantiate the Bridge
// This class acts as the middle-man, housing GoTo, Stop, and UsePortal logic
var bridge = new LuaBridge(_core);
// --- THE API BRIDGE: Expose the Bridge as "RynthAi" ---
// Usage in Lua: RynthAi:GoTo("33.5N", "44.8E")
_lua["RynthAi"] = bridge;
// --- SHORTCUTS: Direct manager access for advanced scripting ---
if (_core.UI != null)
{
_lua["Combat"] = _core.UI.CombatManager;
_lua["Settings"] = _core.UI.Settings;
_lua["Nav"] = _core.UI.Settings.CurrentRoute;
}
// Expose the raw Decal CoreManager (e.g., Core.WorldFilter)
_lua["Core"] = _core.PluginCoreManager;
// --- REDIRECT PRINT ---
// Replaces Lua's default print() with our custom C# method
// which sends text to both AC Chat and the UI Console.
_lua.RegisterFunction("print", this, typeof(LuaManager).GetMethod("LuaPrint"));
LuaPrint("Lua Engine Initialized.");
}
catch (Exception ex)
{
LogError("Init Error: " + ex.Message);
}
}
public void ExecuteString(string script)
{
try
{
if (string.IsNullOrEmpty(script) || _lua == null) return;
_lua.DoString(script);
}
catch (NLua.Exceptions.LuaException ex)
{
// This will now show you the EXACT line number and error in AC chat
LogError("Lua Script Error: " + ex.Message);
}
catch (Exception ex)
{
LogError("Engine Error: " + ex.Message);
}
}
public void LuaPrint(object msg)
{
// 1. Format the basic string and timestamp
string text = msg?.ToString() ?? "nil";
string timestamp = DateTime.Now.ToString("HH:mm:ss");
string formattedMsg = $"[{timestamp}] {text}";
// 2. Always output to Asheron's Call Chat (Green text)
// This is safe even if the UI window isn't open yet
_core.PluginHost.Actions.AddChatText($"[RynthLua] {text}", 5);
// 3. Safely update the ImGui Console Tab
// We wrap everything in this check so the plugin doesn't crash
// if you try to print something before the UI is fully loaded.
if (_core.UI?.Settings != null)
{
// Append the new line to the console
_core.UI.Settings.LuaConsoleOutput += $"\n{formattedMsg}";
// Limit console size to roughly 10k characters to prevent memory bloat
if (_core.UI.Settings.LuaConsoleOutput.Length > 10000)
{
// Trims the oldest 5,000 characters
_core.UI.Settings.LuaConsoleOutput = _core.UI.Settings.LuaConsoleOutput.Substring(5000);
}
}
}
public void LoadMainScript()
{
try
{
string scriptDir = Path.Combine(_core.AssemblyDirectory, "Scripts");
if (!Directory.Exists(scriptDir)) Directory.CreateDirectory(scriptDir);
string path = Path.Combine(scriptDir, "main.lua");
if (File.Exists(path))
{
string code = File.ReadAllText(path);
ExecuteString(code);
LuaPrint("Main script loaded from: " + path);
}
else
{
// Create a dummy file so the user has a template
File.WriteAllText(path, "-- RynthAi Main Lua Script\nfunction OnBotTick()\nend");
LuaPrint("Created template main.lua at: " + path);
}
}
catch (Exception ex)
{
LogError("LoadMainScript Error: " + ex.Message);
}
}
private void LogError(string msg)
{
_core.PluginHost.Actions.AddChatText($"[RynthLua Error] {msg}", 2);
_core.UI.Settings.LuaConsoleOutput += $"\n[ERROR] {msg}";
}
public void Dispose()
{
if (!_isDisposed)
{
_lua?.Dispose();
_isDisposed = true;
}
}
}
}