### Initialize and Use UOFileManager for Asset Loading Source: https://context7.com/soulless-1/classicuo/llms.txt Demonstrates the initialization and usage of the UOFileManager class for loading Ultima Online game assets. It covers loading various asset types (art, animations, maps, clilocs) from MUL and UOP formats, with support for versioning and localization. Requires specifying client version and UO installation path. ```csharp using ClassicUO.Assets; using ClassicUO.Utility; // Initialize the file manager with client version and UO installation path var clientVersion = ClientVersion.CV_7000; var uoPath = "/path/to/UltimaOnline"; var fileManager = new UOFileManager(clientVersion, uoPath); // Load all game assets with verdata patching and English language fileManager.Load(useVerdata: true, lang: "ENU", mapsLayouts: ""); // Access specific asset loaders var artLoader = fileManager.Arts; var animLoader = fileManager.Animations; var mapLoader = fileManager.Maps; // Get art data for a specific tile or item uint artIndex = 0x0001; ArtInfo artInfo = artLoader.GetArt(artIndex); Console.WriteLine($"Art dimensions: {artInfo.Width}x{artInfo.Height}"); Console.WriteLine($"Pixel data length: {artInfo.Pixels.Length}"); // Load cliloc strings for localization var clilocLoader = fileManager.Clilocs; // Cliloc 1000001 typically contains game messages // Dispose when done to release file handles fileManager.Dispose(); ``` -------------------------------- ### C# Plugin Initialization and Callback Registration for ClassicUO Source: https://context7.com/soulless-1/classicuo/llms.txt This C# code demonstrates the initialization of a ClassicUO plugin by implementing the Assistant.Engine.Install method. It registers callback delegates for packet reception, packet sending, and hotkey presses, allowing bidirectional communication with the client. Dependencies include the CUO_API namespace and System.Runtime.InteropServices. ```csharp using System; using System.Runtime.InteropServices; using CUO_API; namespace Assistant { public static class Engine { private static PluginHeader _pluginHeader; // Called by ClassicUO to initialize the plugin public static unsafe void Install(IntPtr headerPtr) { _pluginHeader = Marshal.PtrToStructure(headerPtr); // Register plugin callbacks _pluginHeader.OnRecv = Marshal.GetFunctionPointerForDelegate( new OnPacketSendRecv(OnPacketReceive) ); _pluginHeader.OnSend = Marshal.GetFunctionPointerForDelegate( new OnPacketSendRecv(OnPacketSend) ); _pluginHeader.OnHotkeyPressed = Marshal.GetFunctionPointerForDelegate( new OnHotkey(OnHotkey) ); Marshal.StructureToPtr(_pluginHeader, headerPtr, false); Console.WriteLine($"Plugin loaded - Client Version: {_pluginHeader.ClientVersion}"); } private static bool OnPacketReceive(ref byte[] data, ref int length) { byte packetId = data[0]; Console.WriteLine($"Received packet: 0x{packetId:X2}, Length: {length}"); // Return false to block packet, true to allow return true; } private static bool OnPacketSend(ref byte[] data, ref int length) { byte packetId = data[0]; Console.WriteLine($"Sending packet: 0x{packetId:X2}, Length: {length}"); return true; } private static bool OnHotkey(int key, int mod, bool pressed) { Console.WriteLine($"Hotkey: Key={key}, Mod={mod}, Pressed={pressed}"); // Example: Cast spell on Ctrl+1 if (pressed && key == 49 && mod == 2) // '1' key with Ctrl { CastSpell(1); // Magic Arrow } return true; } private static void CastSpell(int spellIndex) { var castSpellDelegate = Marshal.GetDelegateForFunctionPointer( _pluginHeader.CastSpell ); castSpellDelegate(spellIndex); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void CastSpellDelegate(int index); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate bool OnPacketSendRecv(ref byte[] data, ref int length); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate bool OnHotkey(int key, int mod, bool pressed); } } ``` -------------------------------- ### Manual .NET Publish for ClassicUO Source: https://context7.com/soulless-1/classicuo/llms.txt Manually publishes the ClassicUO Bootstrap and Client projects using 'dotnet publish'. This command-line operation allows for specific configuration of the build process, including target platform and output directory. It's useful for custom build environments or when the automated script is not used. ```bash # Manual build for specific platform dotnet publish ./src/ClassicUO.Bootstrap/src/ClassicUO.Bootstrap.csproj -c Release -o ./bin/dist dotnet publish ./src/ClassicUO.Client -c Release -p:NativeLib=Shared -p:OutputType=Library -r linux-x64 -o ./bin/dist ``` -------------------------------- ### Build ClassicUO with Native AOT Compilation Source: https://context7.com/soulless-1/classicuo/llms.txt Builds the ClassicUO client and bootstrap projects using native AOT compilation. This script automatically detects the operating system (Linux, macOS, Windows) and places the output binaries in the 'bin/dist' directory. It produces a native shared library and a bootstrap executable. ```bash git clone --recursive https://github.com/ClassicUO/ClassicUO.git cd ClassicUO/scripts bash build-naot.sh ``` -------------------------------- ### Configure Client Settings with Settings Class Source: https://context7.com/soulless-1/classicuo/llms.txt The Settings class allows for comprehensive configuration of the ClassicUO client, including server connection details, UI preferences, and plugin management. Settings are loaded from and saved to a 'settings.json' file, persisting user preferences across sessions. Various parameters can be adjusted, such as IP address, port, client version, display resolution, and enabled plugins. ```csharp using ClassicUO.Configuration; using System.IO; using System.Text.Json; // Access global settings singleton var settings = Settings.GlobalSettings; // Configure server connection settings.IP = "play.uoserver.com"; settings.Port = 2593; settings.Username = "myusername"; settings.Password = "mypassword"; settings.SaveAccount = true; settings.AutoLogin = true; // Set client directories settings.UltimaOnlineDirectory = "/path/to/UO"; settings.ProfilesPath = "./profiles"; settings.ClientVersion = "7.0.84.2"; // Configure display settings settings.FPS = 60; settings.IsWindowMaximized = false; settings.WindowSize = new Microsoft.Xna.Framework.Point(1920, 1080); // Enable plugins settings.Plugins = new[] { "./Assistant/Razor.dll", "./Assistant/ClassicAssist.dll" }; // Network options settings.IgnoreRelayIp = true; // Connect directly to configured IP settings.Reconnect = true; settings.ReconnectTime = 5; // Save settings to disk var settingsPath = Settings.GetSettingsFilepath(); var json = JsonSerializer.Serialize(settings, SettingsJsonContext.RealDefault.Settings); File.WriteAllText(settingsPath, json); // Load settings from disk if (File.Exists(settingsPath)) { var jsonData = File.ReadAllText(settingsPath); settings = JsonSerializer.Deserialize(jsonData, SettingsJsonContext.RealDefault.Settings); } ``` -------------------------------- ### Load Graphics Assets with ArtLoader Source: https://context7.com/soulless-1/classicuo/llms.txt Shows how to use the ArtLoader class within ClassicUO to load visual game assets, such as land tiles and static items. It details accessing art data from MUL files and converting 16-bit color to 32-bit RGBA format. This is essential for rendering game graphics. ```csharp using ClassicUO.Assets; var fileManager = new UOFileManager(ClientVersion.CV_7000, "/path/to/UO"); fileManager.Load(true, "ENU"); var artLoader = fileManager.Arts; // Load a land tile (grass terrain) uint landTileIndex = 0x0003; ArtInfo landArt = artLoader.GetArt(landTileIndex); Console.WriteLine($"Land tile: {landArt.Width}x{landArt.Height}"); // Load a static item (tree) uint staticItemIndex = 0x4000 + 0x0CE3; ArtInfo staticArt = artLoader.GetArt(staticItemIndex); Console.WriteLine($"Static item: {staticArt.Width}x{staticArt.Height}"); // Access raw pixel data for rendering Span pixels = staticArt.Pixels; for (int y = 0; y < staticArt.Height; y++) { for (int x = 0; x < staticArt.Width; x++) { uint pixel = pixels[y * staticArt.Width + x]; byte alpha = (byte)((pixel >> 24) & 0xFF); byte red = (byte)((pixel >> 16) & 0xFF); byte green = (byte)((pixel >> 8) & 0xFF); byte blue = (byte)(pixel & 0xFF); } } ``` -------------------------------- ### Manage TCP and WebSocket Network Connections with NetClient Source: https://context7.com/soulless-1/classicuo/llms.txt The NetClient class facilitates network communication with Ultima Online servers using TCP or WebSocket. It handles connection establishment, event handling for connection status, and provides statistics on data transfer. Ensure the correct server address and port are provided for successful connection. Packet encryption and compression can be enabled after successful login. ```csharp using ClassicUO.Network; using System.Net.Sockets; // Initialize the network client singleton var netClient = NetClient.Socket; // Load encryption based on client version var clientVersion = ClientVersion.CV_7000; var encryption = netClient.Load(clientVersion, EncryptionType.None); Console.WriteLine($"Encryption type: {encryption}"); // Setup event handlers netClient.Connected += (sender, args) => { Console.WriteLine("Connected to server"); }; netClient.Disconnected += (sender, error) => { Console.WriteLine($"Disconnected: {error}"); }; // Connect to game server (TCP) string serverIP = "127.0.0.1"; ushort serverPort = 2593; netClient.Connect(serverIP, serverPort); // Connect via WebSocket // netClient.Connect("wss://game.server.com", 2593); // Check connection status if (netClient.IsConnected) { Console.WriteLine($"Local IP: {netClient.LocalIP:X8}"); Console.WriteLine($"Bytes sent: {netClient.Statistics.TotalBytesSent}"); Console.WriteLine($"Bytes received: {netClient.Statistics.TotalBytesReceived}"); } // Enable packet compression (used after login) netClient.EnableCompression(); // Disconnect from server netClient.Disconnect(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.