Skip to content

Commit 80fdaaa

Browse files
UOS Fix
- fix uos docs for ClassicUO - better 'stop' error handling
1 parent 8f42121 commit 80fdaaa

File tree

4 files changed

+49
-41
lines changed

4 files changed

+49
-41
lines changed

Razor/Client/ClassicUO.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ private void OnPlayerPositionChanged(int x, int y, int z)
266266

267267
internal static void RunTheUI()
268268
{
269+
AutoDocIO.UpdateDocs();
269270
Engine.MainWnd = new MainForm();
270271
if (!IsOSI)
271272
{

Razor/RazorEnhanced/AutoDoc.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public static bool JsonDocExists(string path = null)
148148
public static bool UpdateDocs(bool update = false)
149149
{
150150
//TODO: Remove manual override
151+
XMLCommentReader.LoadXmlDocumentation(typeof(AutoDoc).Assembly);
151152
update = true;
152153

153154
if (!JsonDocExists())
@@ -1298,14 +1299,15 @@ public static void LoadXmlDocumentation(string xmlDocumentation)
12981299
}
12991300
}
13001301

1301-
internal static void LoadXmlDocumentation(Assembly assembly)
1302+
public static void LoadXmlDocumentation(Assembly assembly)
13021303
{
13031304
if (loadedAssemblies.Contains(assembly))
13041305
{
13051306
return; // Already loaded
13061307
}
13071308
string directoryPath = GetPath(assembly);
13081309
string xmlFilePath = Path.Combine(directoryPath, assembly.GetName().Name + ".xml");
1310+
13091311
if (File.Exists(xmlFilePath))
13101312
{
13111313
LoadXmlDocumentation(File.ReadAllText(xmlFilePath));

Razor/RazorEnhanced/EnhancedScript.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ private TracebackDelegate TracebackPython(TraceBackFrame frame, string result, o
908908
return TracebackPython;
909909
}
910910

911-
private bool TracebackUOS(UOS.Script script, UOS.ASTNode node, UOS.Scope scope)
911+
private bool TracebackUOS(UOS.UOSCompiledScript script, UOS.ASTNode node, UOS.Scope scope)
912912
{
913913
if (m_uosTraceback != null)
914914
{
@@ -1079,7 +1079,10 @@ public bool HandleException(Exception ex)
10791079

10801080
// GRACEFUL/SILENT EXIT
10811081
if (exceptionType == typeof(ThreadAbortException)) { return true; } // thread stopped: All good
1082-
if (exceptionType == typeof(SystemExitException)) { // sys.exit() or end of script
1082+
if (exceptionType == typeof(SystemExitException) ||
1083+
exceptionType == typeof(UOSStopError)
1084+
) { // sys.exit() or end of script
1085+
m_Script.Stop();
10831086
return true;
10841087
}
10851088

Razor/RazorEnhanced/UOSteamEngine.cs

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
namespace RazorEnhanced.UOS
2121
{
22-
//
23-
24-
2522
public class UOSScriptError : Exception
2623
{
2724
public ASTNode Node;
@@ -84,11 +81,21 @@ public UOSArgumentError(ASTNode node, string error) : base(node, error) { }
8481
public UOSArgumentError(string line, int lineNumber, ASTNode node, string error) : base(line, lineNumber, node, error) { }
8582
}
8683

84+
public class UOSStopError : UOSScriptError
85+
{
86+
public UOSStopError(ASTNode node, string error) : base(node, error) { }
87+
public UOSStopError(string line, int lineNumber, ASTNode node, string error) : base(line, lineNumber, node, error) { }
88+
}
89+
8790

8891

8992

9093

9194

95+
/// <summary>
96+
/// This class contains all the methods available for the UOS scripts (.uos)
97+
/// The following classes and commands ARE NOT available in python.
98+
/// </summary>
9299
public class UOSteamEngine
93100
{
94101
static bool DEFAULT_ISOLATION = false;
@@ -104,13 +111,13 @@ public class UOSteamEngine
104111
private bool m_UseIsolation = DEFAULT_ISOLATION;
105112
private Namespace m_Namespace;
106113
private Interpreter m_Interpreter;
107-
private Script m_Script;
114+
private UOSCompiledScript m_Compiled;
108115

109116
private Action<string> m_OutputWriter;
110117
private Action<string> m_ErrorWriter;
111118

112119
public void SetTrace(UOSTracebackDelegate traceDelegate) {
113-
m_Script.OnTraceback += traceDelegate;
120+
m_Compiled.OnTraceback += traceDelegate;
114121
}
115122

116123
public void SetStdout(Action<string> stdoutWriter)
@@ -123,7 +130,7 @@ public void SetStderr(Action<string> stderrWriter)
123130
m_ErrorWriter = stderrWriter;
124131
}
125132

126-
public Script Script { get { return m_Script; } }
133+
public UOSCompiledScript Compiled { get { return m_Compiled; } }
127134
public Interpreter Interpreter { get { return m_Interpreter; } }
128135
public Namespace Namespace {
129136
get { return m_Namespace; }
@@ -144,10 +151,7 @@ public bool UseIsolation {
144151
}
145152
}
146153

147-
public class StopException : Exception
148-
{
149-
public StopException() : base("Stop encountered") { }
150-
}
154+
151155

152156
// useOnceIgnoreList
153157
private readonly List<int> m_serialUseOnceIgnoreList;
@@ -210,10 +214,11 @@ internal List<string> AllKeywords()
210214
}
211215

212216

217+
213218

214219
public UOSteamEngine()
215220
{
216-
m_mutex = new Mutex();
221+
//m_mutex = new Mutex();
217222
m_serialUseOnceIgnoreList = new List<int>();
218223

219224
m_Loaded = false;
@@ -335,16 +340,16 @@ public bool Load(string content, string filename = "")
335340

336341
public bool Load(ASTNode root, string filename = "")
337342
{
338-
m_mutex.WaitOne();
343+
//m_mutex.WaitOne();
339344

340345
m_Loaded = false;
341-
m_Script = null;
346+
m_Compiled = null;
342347
try
343348
{
344349
InitInterpreter(true);
345350

346-
m_Script = new Script(root, this);
347-
m_Script.Filename = filename;
351+
m_Compiled = new UOSCompiledScript(root, this);
352+
m_Compiled.Filename = filename;
348353

349354

350355
UpdateNamespace();
@@ -354,44 +359,41 @@ public bool Load(ASTNode root, string filename = "")
354359
SendError($"UOSEngine: fail to load script:\n{e.Message}");
355360
}
356361

357-
m_mutex.ReleaseMutex();
362+
//m_mutex.ReleaseMutex();
358363
return m_Loaded;
359364
}
360365

361366
public bool Execute(bool editorMode = false)
362367
{
363368
if (!m_Loaded) { return false; }
364-
365-
m_mutex.WaitOne();
369+
Execute();
370+
/*m_mutex.WaitOne();
366371
try
367372
{
368373
Execute();
369374
}
370-
catch (UOSteamEngine.StopException)
375+
catch (UOSStopError e)
371376
{
372-
if (!editorMode && m_Script.Filename != "") {
373-
Misc.ScriptStop(m_Script.Filename);
374-
}
377+
EnhancedScript.Service.CurrentScript().Stop();
375378
}
376379
catch (Exception e)
377380
{
378-
if (!editorMode && m_Script.Filename != "") {
379-
Misc.ScriptStop(m_Script.Filename);
380-
}
381-
throw;
381+
EnhancedScript.Service.CurrentScript().Stop();
382+
throw e;
382383
}
383384
finally
384385
{
385-
m_mutex.ReleaseMutex();
386-
}
386+
//m_mutex.ReleaseMutex();
387+
}
388+
*/
387389
return true;
388390
}
389391

390392
private void UpdateNamespace(){
391393
var ns = Namespace.GlobalNamespace;
392394
if (m_UseIsolation && m_Namespace == Namespace.GlobalNamespace)
393395
{
394-
ns = Namespace.Get(Path.GetFileNameWithoutExtension(Script.Filename));
396+
ns = Namespace.Get(Path.GetFileNameWithoutExtension(Compiled.Filename));
395397
}
396398
if (ns != m_Namespace) {
397399
m_Namespace = ns;
@@ -5185,12 +5187,12 @@ internal ASTNode Node
51855187
get; set;
51865188
}
51875189

5188-
internal Script _script
5190+
internal UOSCompiledScript _script
51895191
{
51905192
get; set;
51915193
}
51925194

5193-
public Argument(Script script, ASTNode node)
5195+
public Argument(UOSCompiledScript script, ASTNode node)
51945196
{
51955197
Node = node;
51965198
_script = script;
@@ -5381,8 +5383,8 @@ public override int GetHashCode()
53815383
return base.GetHashCode();
53825384
}
53835385
}
5384-
public delegate bool UOSTracebackDelegate(Script script, ASTNode node, Scope scope);
5385-
public class Script
5386+
public delegate bool UOSTracebackDelegate(UOSCompiledScript script, ASTNode node, Scope scope);
5387+
public class UOSCompiledScript
53865388
{
53875389
bool Debug { get; set; }
53885390
public string Filename;
@@ -5396,7 +5398,7 @@ public class Script
53965398

53975399
private Scope _scope;
53985400

5399-
public Script()
5401+
public UOSCompiledScript()
54005402
{
54015403
Debug = false;
54025404
}
@@ -5472,7 +5474,7 @@ private Argument[] ConstructArguments(ref ASTNode node)
54725474
// scripts to a bytecode. That would allow more errors
54735475
// to be caught with better error messages, as well as
54745476
// make the scripts execute more quickly.
5475-
public Script(ASTNode root, UOSteamEngine engine)
5477+
public UOSCompiledScript(ASTNode root, UOSteamEngine engine)
54765478
{
54775479
// Set current to the first statement
54785480
_root = root;
@@ -6062,7 +6064,7 @@ public bool ExecuteNext()
60626064
case ASTNodeType.STOP:
60636065
Engine.Interpreter.StopScript();
60646066
_statement = null;
6065-
throw(new UOSteamEngine.StopException());
6067+
throw new UOSStopError(node,"Found stop keyword.");
60666068
break;
60676069
case ASTNodeType.REPLAY:
60686070
_statement = _statement.Parent.FirstChild();
@@ -6573,7 +6575,7 @@ public class Interpreter
65736575

65746576
// Lists
65756577
private UOSteamEngine m_Engine;
6576-
private Script m_Script = null;
6578+
private UOSCompiledScript m_Script = null;
65776579

65786580
private bool m_Suspended = false;
65796581
private ManualResetEvent m_SuspendedMutex;
@@ -6870,7 +6872,7 @@ public bool StartScript()
68706872
if (m_Script != null)
68716873
return false;
68726874

6873-
m_Script = m_Engine.Script;
6875+
m_Script = m_Engine.Compiled;
68746876
_executionState = ExecutionState.RUNNING;
68756877
Suspended = false;
68766878
m_Script.Init();

0 commit comments

Comments
 (0)