Tommy
Initiate
ServUO Custom Script Integration & Debugging Guide
1. Understanding ServUO Compilation & Script Loading
When working with ServUO-57.4.1, adding new scripts requires proper compilation and script loading. Here’s how to ensure your custom scripts are recognized in-game.
2. Why New Scripts Don’t Load Immediately
3. How to Add Custom Scripts Correctly
2. Recompile and Run ServUO:
make -f _makedebug
mono ServUO.exe
4. Modified Core Files
In addition to adding new scripts, we also modified core files for compatibility with Linux:
Main.cs Modifications
FileOperations.cs Modifications
#if WINDOWS
[DllImport("Kernel32", CharSet = CharSet.Auto, SetLastError = true)]
private static extern SafeFileHandle CreateFile(
string lpFileName,
int dwDesiredAccess,
FileShare dwShareMode,
IntPtr securityAttrs,
FileMode dwCreationDisposition,
int dwFlagsAndAttributes,
IntPtr hTemplateFile
);
#endif
..............
public static FileStream OpenSequentialStream(string path, FileMode mode, FileAccess access, FileShare share)
{
FileOptions options = FileOptions.SequentialScan;
if (concurrency > 0)
{
options |= FileOptions.Asynchronous;
}
if (unbuffered)
{
options |= NoBuffering;
}
else
{
return new FileStream(path, mode, access, share, bufferSize, options);
}
#if WINDOWS
SafeFileHandle fileHandle = CreateFile(path, (int)access, share, IntPtr.Zero, mode, (int)options, IntPtr.Zero);
if (fileHandle.IsInvalid)
{
throw new IOException();
}
return new UnbufferedFileStream(fileHandle, access, bufferSize, (concurrency > 0));
#else
return new FileStream(path, mode, access, share, bufferSize, options);
#endif
}
If you make further changes to these files, always recompile using:
make -f _makedebug
mono ServUO.exe
5. Debugging Common Issues
6. Best Practices
7. Summary
1. Understanding ServUO Compilation & Script Loading
When working with ServUO-57.4.1, adding new scripts requires proper compilation and script loading. Here’s how to ensure your custom scripts are recognized in-game.
2. Why New Scripts Don’t Load Immediately
- When you run mono ServUO.exe, ServUO only loads precompiled scripts.
- If you add a new script, it will not appear until it is compiled.
- Running make -f _makedebug forces a full rebuild, which ensures your script is compiled and loaded.
3. How to Add Custom Scripts Correctly
- Create a Custom Folder:
- Place your script inside:
- Example structure:
2. Recompile and Run ServUO:
make -f _makedebug
mono ServUO.exe
- This ensures the new script is compiled and recognized properly.
4. Modified Core Files
In addition to adding new scripts, we also modified core files for compatibility with Linux:
Main.cs Modifications
- ServUO attempted to set process priority, which is Windows-only.
- We modified the code to only apply on Windows:
- Thread = Thread.CurrentThread;
Process = Process.GetCurrentProcess();
Assembly = Assembly.GetEntryAssembly();
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
Process.PriorityClass = ProcessPriorityClass.High;
}
if (Thread != null)
{
Thread.Name = "Core Thread";
}

FileOperations.cs Modifications
- ServUO used CreateFile from Kernel32.dll, which does not exist on Linux.
- We replaced it with a Linux-compatible file handling method:

#if WINDOWS
[DllImport("Kernel32", CharSet = CharSet.Auto, SetLastError = true)]
private static extern SafeFileHandle CreateFile(
string lpFileName,
int dwDesiredAccess,
FileShare dwShareMode,
IntPtr securityAttrs,
FileMode dwCreationDisposition,
int dwFlagsAndAttributes,
IntPtr hTemplateFile
);
#endif
..............
public static FileStream OpenSequentialStream(string path, FileMode mode, FileAccess access, FileShare share)
{
FileOptions options = FileOptions.SequentialScan;
if (concurrency > 0)
{
options |= FileOptions.Asynchronous;
}
if (unbuffered)
{
options |= NoBuffering;
}
else
{
return new FileStream(path, mode, access, share, bufferSize, options);
}
#if WINDOWS
SafeFileHandle fileHandle = CreateFile(path, (int)access, share, IntPtr.Zero, mode, (int)options, IntPtr.Zero);
if (fileHandle.IsInvalid)
{
throw new IOException();
}
return new UnbufferedFileStream(fileHandle, access, bufferSize, (concurrency > 0));
#else
return new FileStream(path, mode, access, share, bufferSize, options);
#endif
}

If you make further changes to these files, always recompile using:
make -f _makedebug
mono ServUO.exe
5. Debugging Common Issues
Issue | Cause | Solution |
Script not appearing in-game | Not compiled yet | Run make -f _makedebug before starting ServUO |
Compilation error | Syntax or missing references | Check error message, fix script |
make -f _makedebug fails | Missing dependencies | nuget restore ServUO.sln |
Permissions issue | Linux file access problems | Run chmod -R 777 ServUO-57.4.1 |
6. Best Practices
- Always use make -f _makedebug to ensure scripts are compiled.
- Organize custom scripts inside Scripts/Custom/.
- Recompile after modifying core files (Main.cs, FileOperations.cs).
- Check logs for errors and fix issues before restarting the server.
7. Summary
- For new scripts and core modifications → Use make -f _makedebug
- For debugging → Check logs and permissions