Tommy

Member
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
  • 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
  1. Create a Custom Folder:
  • Place your script inside:
ServUO-57.4.1/Scripts/Custom/
  • Example structure:
ServUO-57.4.1/Scripts/Custom/MyScript.cs
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";
    }
image.png

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:
image.png

#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

}


image.png

If you make further changes to these files, always recompile using:
make -f _makedebug
mono ServUO.exe

5. Debugging Common Issues
IssueCauseSolution
Script not appearing in-gameNot compiled yetRun make -f _makedebug before starting ServUO
Compilation errorSyntax or missing referencesCheck error message, fix script
make -f _makedebug failsMissing dependenciesnuget restore ServUO.sln
Permissions issueLinux file access problemsRun 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
By following these steps, you can efficiently integrate and manage custom scripts in ServUO-57.4.1 on Linux.
 
at FileOperation.cs
do this
private static bool unbuffered = true; => private static bool unbuffered = false;
At this case you don't need to modify all thing in FileOperation.cs for installing on Ubuntu.
 
Some times I got trouble when the server saving the file, So, I update something.
at FileOperation.cs

//private static int bufferSize = 1 * MB;
private static int bufferSize = 50 * MB;

//private static int concurrency = 1;
private static int concurrency = 0;

//private static bool unbuffered = true;
private static bool unbuffered = false;
 
Permissions issueLinux file access problemsRun chmod -R 777 ServUO-57.4.1
I would advise against this. This would allow any user account on the system full access to all files for the server. Doing it just to make things work is a dangerous practice, and could leave the server open to data theft, tampering, malicious code, etc.
If there are permissions issues, they should always be corrected in the proper way.

That aside, Good stuff in this post, thank you very much!
 

Active Shards

Donations

Total amount
$0.00
Goal
$500.00
Back