Files
RAGECOOP-V/Client/Loader/Main.cs

51 lines
1.6 KiB
C#
Raw Normal View History

2022-10-23 19:02:39 +08:00
using System;
using System.IO;
2022-10-23 19:02:39 +08:00
using GTA;
using GTA.UI;
using SHVDN;
using Script = GTA.Script;
namespace RageCoop.Client.Loader
{
[ScriptAttributes(Author = "RageCoop", NoScriptThread = true,
SupportURL = "https://github.com/RAGECOOP/RAGECOOP-V")]
2022-10-23 19:02:39 +08:00
public class Main : Script
{
2022-10-23 19:02:39 +08:00
private static readonly string GameDir = Directory.GetParent(typeof(ScriptDomain).Assembly.Location).FullName;
2022-10-15 17:06:19 +08:00
private static readonly string ScriptsLocation = Path.Combine(GameDir, "RageCoop", "Scripts");
private bool _loaded;
2022-10-23 19:02:39 +08:00
public Main()
{
if (LoaderContext.PrimaryDomain != null) return;
Tick += OnTick;
KeyDown += (s, e) => LoaderContext.KeyEventAll(e.KeyCode, true);
KeyUp += (s, e) => LoaderContext.KeyEventAll(e.KeyCode, false);
2022-10-15 13:52:49 +08:00
Aborted += (s, e) => LoaderContext.UnloadAll();
}
private void OnTick(object sender, EventArgs e)
{
2022-11-30 20:17:06 +08:00
if (!_loaded)
{
_loaded = !Game.IsLoading;
return;
}
2022-10-15 13:52:49 +08:00
LoaderContext.CheckForUnloadRequest();
if (!LoaderContext.IsLoaded(ScriptsLocation))
{
if (!File.Exists(Path.Combine(ScriptsLocation, "RageCoop.Client.dll")))
{
2022-10-23 19:02:39 +08:00
Notification.Show("~r~Main assembly is missing, please re-install the client");
Abort();
return;
}
2022-11-30 20:17:06 +08:00
2022-10-15 13:52:49 +08:00
LoaderContext.Load(ScriptsLocation);
}
2022-11-30 20:17:06 +08:00
LoaderContext.TickAll();
}
}
2022-10-23 19:02:39 +08:00
}