Clean up
This commit is contained in:
@ -1,39 +1,44 @@
|
||||
using GTA;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using GTA;
|
||||
using GTA.UI;
|
||||
using SHVDN;
|
||||
using Console = GTA.Console;
|
||||
using Script = GTA.Script;
|
||||
|
||||
namespace RageCoop.Client.Loader
|
||||
{
|
||||
public class Main : GTA.Script
|
||||
public class Main : Script
|
||||
{
|
||||
private static readonly string GameDir = Directory.GetParent(typeof(SHVDN.ScriptDomain).Assembly.Location).FullName;
|
||||
private static readonly string GameDir = Directory.GetParent(typeof(ScriptDomain).Assembly.Location).FullName;
|
||||
private static readonly string ScriptsLocation = Path.Combine(GameDir, "RageCoop", "Scripts");
|
||||
private static readonly ConcurrentQueue<Action> TaskQueue = new ConcurrentQueue<Action>();
|
||||
private static int MainThreadID;
|
||||
|
||||
public Main()
|
||||
{
|
||||
if (LoaderContext.PrimaryDomain != null) { throw new InvalidOperationException("Improperly placed loader assembly, please re-install to fix this issue"); }
|
||||
if (LoaderContext.PrimaryDomain != null)
|
||||
throw new InvalidOperationException(
|
||||
"Improperly placed loader assembly, please re-install to fix this issue");
|
||||
Tick += OnTick;
|
||||
SHVDN.ScriptDomain.CurrentDomain.Tick += DomainTick;
|
||||
ScriptDomain.CurrentDomain.Tick += DomainTick;
|
||||
Aborted += (s, e) => LoaderContext.UnloadAll();
|
||||
}
|
||||
|
||||
private void OnTick(object sender, EventArgs e)
|
||||
{
|
||||
while (Game.IsLoading)
|
||||
{
|
||||
GTA.Script.Yield();
|
||||
}
|
||||
while (Game.IsLoading) Yield();
|
||||
LoaderContext.CheckForUnloadRequest();
|
||||
if (!LoaderContext.IsLoaded(ScriptsLocation))
|
||||
{
|
||||
if (!File.Exists(Path.Combine(ScriptsLocation, "RageCoop.Client.dll")))
|
||||
{
|
||||
GTA.UI.Notification.Show("~r~Main assembly is missing, please re-install the client");
|
||||
Notification.Show("~r~Main assembly is missing, please re-install the client");
|
||||
Abort();
|
||||
}
|
||||
|
||||
LoaderContext.Load(ScriptsLocation);
|
||||
}
|
||||
}
|
||||
@ -41,20 +46,15 @@ namespace RageCoop.Client.Loader
|
||||
internal static void QueueToMainThread(Action task)
|
||||
{
|
||||
if (Thread.CurrentThread.ManagedThreadId != MainThreadID)
|
||||
{
|
||||
TaskQueue.Enqueue(task);
|
||||
}
|
||||
else
|
||||
{
|
||||
task();
|
||||
}
|
||||
}
|
||||
|
||||
private static void DomainTick()
|
||||
{
|
||||
if (MainThreadID == default) { MainThreadID = Thread.CurrentThread.ManagedThreadId; }
|
||||
if (MainThreadID == default) MainThreadID = Thread.CurrentThread.ManagedThreadId;
|
||||
while (TaskQueue.TryDequeue(out var task))
|
||||
{
|
||||
try
|
||||
{
|
||||
task.Invoke();
|
||||
@ -63,7 +63,6 @@ namespace RageCoop.Client.Loader
|
||||
{
|
||||
Console.Error(ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user