EN CSharp IDE - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki

Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

C# Scripts IDE

The Monaco editor runs in the Eclipse Theia shell. Roslyn provides compilation checking, current snippet replacement hints, hover type information, jump to definition, file structure, and overload signatures.

Create, open and save

Format How to use
.csx C#-scenario of the current game session. UO, Args, Cancellation, WaitAsync and Checkpoint are available.
.cs A typical complete C# program with namespaces and classes: ICSharpScript, Main or top-level operators.
.csproj Project SDK with NuGet, ProjectReference and normal build/run.
.sln, .slnx Workspace text files: opening and saving. They are not standalone scripts to run.
.dll A managed assembly with a runnable script entry point can run as an artifact. Reference a library without an entry point through Reference/HintPath or #r. After Compile, transfer its .dll.csharp.json and dependencies too.
.cse Protected script: Run works without a password; a password is required to create protection and recover source through Decrypt.
Other text formats Create, open and save with the original extension, without being forced to rename it to .csx.
Binary formats Available viewing or associated application. Do not decode or store binary data as C#-text.

Working with the script

  • Create a file of the selected format or open an existing one.
  • Validate shows compilation errors.
  • Run runs a supported script or project in the current session.
  • Pause/Resume controls current execution; Stop requests cancellation.
  • Tooltips after UO. show game methods, after the variable - members of its C#-type. When hovering, information about the type and signature is visible; Going to the definition opens the corresponding code location.

Debugging by lines of source code

For .csx and regular .cs, stop at first executable line, current file and line, breakpoints, Pause/Continue, go to next line (Step) and cancel (Stop) are available.

Pause and Stop act at source checkpoints. A blocking call to a third-party library needs its own cancellation support. Step advances to the next instrumented source line; arbitrary StepInto/StepOut requires a managed debugger.

Variable snapshots for the selected run

Locals and C# source fields/constants show snapshots recorded by the running, instrumented source at its checkpoints. Select the actual run and source frame: its values belong only to that run, even while other scripts run concurrently. A paused snapshot stays stable; completed runs retain their last captured values.

Previews use copied data and do not invoke user getters, enumerators, ToString or arbitrary expressions. These are source frames, not a full CLR stack. Pointer, ref, ref-like and uncaptured values are marked unavailable. Watch reads only a captured identifier in the selected C# scope; expressions such as count + 1 and method calls are not evaluated.

Complete inspection.csx example: start Debug and set a breakpoint on UO.Print. Inspect count, state and limit; enter a captured name such as count in Watch.

const int limit = 3;
int count = 2;
string state = "ready";
UO.Print(state + ": " + count + "/" + limit);

Errors from the current launch attempt

A loaded script keeps its errors after completion and editing until its next launch attempt. A new attempt clears only that owning file’s previous errors and shows current-attempt errors; a successful run leaves its list empty. For a project, the launched .csproj owns diagnostics even when the error is in another source file. Unload clears that owner’s errors; other scripts’ errors remain. Late replies from an older run or validation are discarded. Documents that have never been launched retain normal live editor validation.

The editor file and autorun set are managed separately. To run the next time you start the manager profile, save the supported script in the Scripts set of this profile.

Program Structure · Manual C# · Complete Reference C# · Game Commands

In ordinary .cs or .csproj code, Main or top-level statements take precedence even when the assembly also contains ICSharpScript. Without an executable entry point, provide one public, non-abstract ICSharpScript class with a public parameterless constructor. Ordinary code accesses the game API through a supplied context or CSharpScriptContext.Current; it does not receive an undeclared global UO variable.

Client and Full_Client include C# scripts and AutoLoad and share a session with Manager. Closing and reopening the game window preserves the connection and running scripts. The embedded C# Scripts IDE is available in Full_Client. In Client, manage scripts through Manager and Macros; enable or disable C# and AutoLoad in Bad Newbie.

Info / Hide / Mount / Global

Command modes and offline IDE

In Manager, the Scripts tab beneath the character table opens debugging. The panel shows actual native UO command calls, arguments, results and errors; select a row to inspect its arguments. Observation starts when the panel opens without restarting the script. Operations handled directly by C#, including UO.Wait, may not appear in this list. Script output is available separately.

Main and the selected file

Write commands directly in a .csx file. The Main label in the run list identifies its main execution. A .cs file supports top-level statements, conventional static Main or ICSharpScript. Start, Pause and Stop target the selected file and run. Pause and Stop are disabled for a loaded file that has not started.

Valid C# takes priority over variable inspection

C# rules are checked against the user’s original source. Genuine compiler errors retain the original file, line and column; generated inspection code must not introduce errors into valid code.

A local constant enters a snapshot only after its declaration, where reading it is legal in the current scope. An unavailable value is omitted and may appear at a later checkpoint. Field constants retain ordinary C# rules.

If variable inspection is incompatible with a construct, compilation is retried without reading values. Execution-control checkpoints are retained when they can be inserted correctly. The final fallback uses original C# without generated transformations: that mode has no snapshots of C# locals/fields or source checkpoints for Pause/Step. The shared UO.SetGlobal/UO.GetGlobal store is independent of local-variable inspection.

This complete .csx example prints 5. The debugger does not read the local limit before its declaration.

int CalculateTotal()
{
    int value = 2;
    const int limit = 3;
    return value + limit;
}

UO.Print(CalculateTotal());

Large files and value inspection

.cs and .csproj remain ordinary, complete C#. When repeated variable snapshots would expand generated code excessively, only optional value capture is omitted. This lighter mode retains execution checkpoints, breakpoints and Pause/Step/Stop; it does not limit source length, syntax or execution. Locals and fields may be unavailable, and values from an earlier run are not substituted. Shared UO globals through UO.SetGlobal/UO.GetGlobal are independent and remain available.

Reading an error

Problems, editor hover and the extended message retain the genuine error code and text, file, line and column. Causes, supportable expectations and examples use the selected language. A token is shown only when a matching source snapshot is available; the current editor line may already differ from the checked source. An example illustrates an error category and is not a guaranteed automatic repair. Native failures retain their origin; mentioning CSxxxx in a message does not turn one into a compiler error.

Explicitly opened scripts

An explicitly loaded nested file retains its runnable Main entry after catalogue refresh. Workspace indexing alone does not load or execute other documents. Refreshing the catalogue is not an unload command.

Two independent procedure settings

The manager checks admission of new procedure requests. true rejects admission while another procedure is running, paused or stopping; it does not terminate existing runs.

Managed procedures from one file use a cancellable admission queue. Waiting does not block the game thread. Ordinary direct C# method calls keep their normal semantics.

The setting belongs to this script execution. A new run copies the independent engine/chat defaults once, not the graphical Profile. A script setter changes neither the GUI nor other runs already executing. Named objects, types, equipment sets, Ignore lists and globals deliberately retain their documented shared scope.

A standalone chat command changes the lasting engine context: later commands read that value and new runs copy it. Existing runs keep their own values. Chat automation has its own controller and keeps operating after the command returns; GUI automation uses separate settings.

The graphical C# IDE checkbox controls the editor, not engine execution. Explicit session-module permission in Manager is a separate control.

Replace demonstration serials or names with your own before running. Each block is a complete, separate .csx without a hidden wrapper.

UO.SingleProcedureExecution(false);
UO.SingleProcedurePerFile(true);
{
    using var healing = Callbacks.Register("Healing", async _ => { UO.Print("healing-start"); await WaitAsync(200); UO.Print("healing-end"); });
    using var weapon = Callbacks.Register("Weapon", _ => { UO.Print("weapon"); return System.Threading.Tasks.Task.CompletedTask; });
    UO.Exec("Healing");
    UO.Exec("Weapon");
    while (UO.FunRunning("Healing") != 0 || UO.FunRunning("Weapon") != 0)
        await WaitAsync(10);
}

Standalone C# language examples

The local Client and Full_Client source projects contain 22 readable standalone programs in Project_Client/tests/CSharpLanguageSemantics/Scripts and Project_Full/tests/CSharpLanguageSemantics/Scripts. Expected results are in language-cases.json. The matrix has 88 cases: source or serialized compiled form, each with observation on and off. These are concrete language examples, not a claim that every possible program or the whole .NET API has been verified.

CLR cancellation handlers

Direct calls to standard CancellationToken.Register and UnsafeRegister preserve cleanup for block and expression callbacks, method groups and delegate variables. Other ordinary script flows still obey Stop.

Indirect registration through a registrar delegate, dynamic, reflection, a third-party library or an expression tree is not rewritten automatically. Explicitly apply ClassicUO.CSharp.CSharpExecutionScope.CancellationCleanup to that callback, as in the second complete example. This is a cleanup API, not a separate language syntax.

After Stop, game UO commands remain fenced. CLR cleanup can finish releasing resources. CancelAsync does not wait for an async void callback to finish; its continuation is separate CLR work.

Direct registration; cancellation creates cleanup-direct.log beside the program.

{
    var log = System.IO.Path.Combine(System.AppContext.BaseDirectory, "cleanup-direct.log");
    using var registration = Cancellation.Register(() =>
    {
        System.IO.File.AppendAllText(log, "cleanup" + System.Environment.NewLine);
    });
    while (true)
        await WaitAsync(100);
}

An explicit wrapper for an indirect registrar call; cleanup-indirect.log is also saved beside the program.

{
    var log = System.IO.Path.Combine(System.AppContext.BaseDirectory, "cleanup-indirect.log");
    System.Action cleanup = () => System.IO.File.AppendAllText(log, "cleanup" + System.Environment.NewLine);
    System.Func<System.Action, System.Threading.CancellationTokenRegistration> register = Cancellation.Register;
    using var registration = register(
        global::ClassicUO.CSharp.CSharpExecutionScope.CancellationCleanup(cleanup)!);
    while (true)
        await WaitAsync(100);
}

Execution state and gameplay settings

The setting belongs to this script execution. A new run copies the independent engine/chat defaults once, not the graphical Profile. A script setter changes neither the GUI nor other runs already executing. Named objects, types, equipment sets, Ignore lists and globals deliberately retain their documented shared scope.

A standalone chat command changes the lasting engine context: later commands read that value and new runs copy it. Existing runs keep their own values. Chat automation has its own controller and keeps operating after the command returns; GUI automation uses separate settings.

The graphical C# IDE checkbox controls the editor, not engine execution. Explicit session-module permission in Manager is a separate control.

Execution state and gameplay settings