Change package format to iso9660

This commit is contained in:
sardelka9515
2022-10-15 17:06:19 +08:00
parent d7c0abdfc2
commit 8d27c072ca
19 changed files with 101 additions and 116 deletions

View File

@ -1,14 +1,11 @@
using System;
using SHVDN;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Console = GTA.Console;
using SHVDN;
using System.Windows.Forms;
using Console = GTA.Console;
namespace RageCoop.Client.Loader
{
@ -17,7 +14,8 @@ namespace RageCoop.Client.Loader
{
#region PRIMARY-LOADING-LOGIC
public static ConcurrentDictionary<string, LoaderContext> LoadedDomains => new ConcurrentDictionary<string, LoaderContext>(_loadedDomains);
static readonly ConcurrentDictionary<string, LoaderContext> _loadedDomains = new ConcurrentDictionary<string, LoaderContext>();
private static readonly ConcurrentDictionary<string, LoaderContext> _loadedDomains = new ConcurrentDictionary<string, LoaderContext>();
public bool UnloadRequested;
public string BaseDirectory => AppDomain.CurrentDomain.BaseDirectory;
@ -129,7 +127,8 @@ namespace RageCoop.Client.Loader
domain.Dispose();
ScriptDomain.Unload(domain.CurrentDomain);
}
catch (Exception e) {
catch (Exception e)
{
ex = e;
GTA.UI.Notification.Show(ex.ToString());
}

View File

@ -1,20 +1,17 @@
using System;
using GTA;
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using GTA;
using SHVDN;
using Console = GTA.Console;
namespace RageCoop.Client.Loader
{
public class Main : GTA.Script
{
static readonly string GameDir = Directory.GetParent(typeof(SHVDN.ScriptDomain).Assembly.Location).FullName;
static readonly string ScriptsLocation = Path.Combine(GameDir, "RageCoop", "Scripts");
private static readonly string GameDir = Directory.GetParent(typeof(SHVDN.ScriptDomain).Assembly.Location).FullName;
private static readonly string ScriptsLocation = Path.Combine(GameDir, "RageCoop", "Scripts");
private static readonly ConcurrentQueue<Action> TaskQueue = new ConcurrentQueue<Action>();
static int MainThreadID;
private static int MainThreadID;
public Main()
{
if (LoaderContext.PrimaryDomain != null) { throw new InvalidOperationException("Improperly placed loader assembly, please re-install to fix this issue"); }
@ -55,7 +52,7 @@ namespace RageCoop.Client.Loader
private static void DomainTick(object sender, EventArgs e)
{
if (MainThreadID == default) { MainThreadID=Thread.CurrentThread.ManagedThreadId;}
if (MainThreadID == default) { MainThreadID = Thread.CurrentThread.ManagedThreadId; }
while (TaskQueue.TryDequeue(out var task))
{
try

View File

@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following

View File

@ -1,6 +1,5 @@
using GTA;
using GTA.Math;
using RageCoop.Client.Scripting;
using System;
using System.Drawing;
using System.Threading;

View File

@ -5,17 +5,15 @@ using RageCoop.Client.Menus;
using RageCoop.Client.Scripting;
using RageCoop.Core;
using SHVDN;
using Script = GTA.Script;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Console = GTA.Console;
using Script = GTA.Script;
namespace RageCoop.Client
{
@ -33,7 +31,6 @@ namespace RageCoop.Client
internal static RelationshipGroup SyncedPedsGroup;
internal static new Settings Settings = null;
internal static BaseScript BaseScript = new BaseScript();
#if !NON_INTERACTIVE
#endif

View File

@ -1,9 +1,7 @@
using GTA;
using LemonUI.Menus;
using RageCoop.Client.Scripting;
using System;
using System.Drawing;
using System.IO;
namespace RageCoop.Client
{
@ -19,7 +17,7 @@ namespace RageCoop.Client
UseMouse = false,
Alignment = Main.Settings.FlipMenu ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left
};
public static NativeItem ReloadItem = new NativeItem("Reload","Reload RAGECOOP and associated scripts");
public static NativeItem ReloadItem = new NativeItem("Reload", "Reload RAGECOOP and associated scripts");
public static NativeItem SimulatedLatencyItem = new NativeItem("Simulated network latency", "Simulated network latency in ms (one way)", "0");
public static NativeCheckboxItem ShowOwnerItem = new NativeCheckboxItem("Show entity owner", "Show the owner name of the entity you're aiming at", false);
private static readonly NativeCheckboxItem ShowNetworkInfoItem = new NativeCheckboxItem("Show Network Info", Networking.ShowNetworkInfo);

View File

@ -2,8 +2,8 @@
using GTA.Math;
using GTA.Native;
using Lidgren.Network;
using RageCoop.Core;
using RageCoop.Client.Scripting;
using RageCoop.Core;
using System;
using System.Collections.Generic;

View File

@ -16,7 +16,7 @@ using System.Resources;
// Version informationr(
[assembly: AssemblyVersion("1.5.4.334")]
[assembly: AssemblyFileVersion("1.5.4.334")]
[assembly: AssemblyVersion("1.5.4.341")]
[assembly: AssemblyFileVersion("1.5.4.341")]
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]

View File

@ -6,7 +6,6 @@ using RageCoop.Core.Scripting;
using SHVDN;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows.Forms;

View File

@ -9,11 +9,10 @@ using System.Threading.Tasks;
namespace RageCoop.Client.Scripting
{
[ScriptAttributes(Author = "RageCoop", NoDefaultInstance = true, SupportURL = "https://github.com/RAGECOOP/RAGECOOP-V")]
internal class BaseScript : ClientScript
internal static class BaseScript
{
private bool _isHost = false;
public override void OnStart()
private static bool _isHost = false;
public static void OnStart()
{
API.Events.OnPedDeleted += (s, p) => { API.SendCustomEvent(CustomEvents.OnPedDeleted, p.ID); };
API.Events.OnVehicleDeleted += (s, p) => { API.SendCustomEvent(CustomEvents.OnVehicleDeleted, p.ID); };
@ -58,19 +57,19 @@ namespace RageCoop.Client.Scripting
});
}
private void WeatherTimeSync(CustomEventReceivedArgs e)
private static void WeatherTimeSync(CustomEventReceivedArgs e)
{
World.CurrentTimeOfDay = new TimeSpan((int)e.Args[0], (int)e.Args[1], (int)e.Args[2]);
Function.Call(Hash._SET_WEATHER_TYPE_TRANSITION, (int)e.Args[3], (int)e.Args[4], (float)e.Args[5]);
}
private void SetDisplayNameTag(CustomEventReceivedArgs e)
private static void SetDisplayNameTag(CustomEventReceivedArgs e)
{
var p = PlayerList.GetPlayer((int)e.Args[0]);
if (p != null) { p.DisplayNameTag = (bool)e.Args[1]; }
}
private void UpdatePedBlip(CustomEventReceivedArgs e)
private static void UpdatePedBlip(CustomEventReceivedArgs e)
{
var p = Entity.FromHandle((int)e.Args[0]);
if (p == null) { return; }
@ -90,7 +89,7 @@ namespace RageCoop.Client.Scripting
}
}
private void CreateVehicle(CustomEventReceivedArgs e)
private static void CreateVehicle(CustomEventReceivedArgs e)
{
var vehicleModel = (Model)e.Args[1];
vehicleModel.Request(1000);
@ -109,7 +108,7 @@ namespace RageCoop.Client.Scripting
EntityPool.Add(v);
}
private void DeleteServerBlip(CustomEventReceivedArgs e)
private static void DeleteServerBlip(CustomEventReceivedArgs e)
{
if (EntityPool.ServerBlips.TryGetValue((int)e.Args[0], out var blip))
{
@ -118,7 +117,7 @@ namespace RageCoop.Client.Scripting
}
}
private void ServerBlipSync(CustomEventReceivedArgs obj)
private static void ServerBlipSync(CustomEventReceivedArgs obj)
{
int id = (int)obj.Args[0];
var sprite = (BlipSprite)(ushort)obj.Args[1];
@ -140,15 +139,12 @@ namespace RageCoop.Client.Scripting
}
private void DeleteEntity(CustomEventReceivedArgs e)
private static void DeleteEntity(CustomEventReceivedArgs e)
{
Entity.FromHandle((int)e.Args[0])?.Delete();
}
public override void OnStop()
{
}
private void SetNameTag(CustomEventReceivedArgs e)
private static void SetNameTag(CustomEventReceivedArgs e)
{
var p = PlayerList.GetPlayer((int)e.Args[0]);
if (p != null)
@ -156,11 +152,11 @@ namespace RageCoop.Client.Scripting
p.DisplayNameTag = (bool)e.Args[1];
}
}
private void SetAutoRespawn(CustomEventReceivedArgs args)
private static void SetAutoRespawn(CustomEventReceivedArgs args)
{
API.Config.EnableAutoRespawn = (bool)args.Args[0];
}
private void DeleteServerProp(CustomEventReceivedArgs e)
private static void DeleteServerProp(CustomEventReceivedArgs e)
{
var id = (int)e.Args[0];
if (EntityPool.ServerProps.TryGetValue(id, out var prop))
@ -170,7 +166,7 @@ namespace RageCoop.Client.Scripting
}
}
private void ServerObjectSync(CustomEventReceivedArgs e)
private static void ServerObjectSync(CustomEventReceivedArgs e)
{
SyncedProp prop;
var id = (int)e.Args[0];
@ -188,7 +184,7 @@ namespace RageCoop.Client.Scripting
prop.Model.Request(1000);
prop.Update();
}
private void NativeCall(CustomEventReceivedArgs e)
private static void NativeCall(CustomEventReceivedArgs e)
{
List<InputArgument> arguments = new List<InputArgument>();
int i;
@ -272,7 +268,7 @@ namespace RageCoop.Client.Scripting
}
}
private InputArgument GetInputArgument(object obj)
private static InputArgument GetInputArgument(object obj)
{
// Implicit conversion
switch (obj)

View File

@ -1,5 +1,4 @@
using RageCoop.Core.Scripting;
using System;
namespace RageCoop.Client.Scripting
{

View File

@ -8,7 +8,6 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
namespace RageCoop.Client.Scripting
{
@ -135,7 +134,7 @@ namespace RageCoop.Client.Scripting
LoadedResources.TryAdd(r.Name, r);
}
void SetupScripts()
private void SetupScripts()
{
foreach (var s in GetClientScripts())
{
@ -165,7 +164,8 @@ namespace RageCoop.Client.Scripting
API.Logger.Debug("Started script: " + s.GetType().FullName);
}
}
void StopScripts()
private void StopScripts()
{
foreach (var s in GetClientScripts())
{

View File

@ -1,20 +1,13 @@
using GTA;
using Console = GTA.Console;
using GTA.Math;
using GTA.Native;
using Newtonsoft.Json;
using RageCoop.Core;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Xml.Serialization;
using Newtonsoft.Json;
using SHVDN;
using System.Runtime.InteropServices.ComTypes;
[assembly: InternalsVisibleTo("RageCoop.Client.Installer")]
namespace RageCoop.Client

View File

@ -1,11 +1,9 @@
using GTA;
using GTA.Native;
using RageCoop.Client.Scripting;
using RageCoop.Core;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Threading;
using System.Threading.Tasks;
namespace RageCoop.Client
{
@ -23,7 +21,7 @@ namespace RageCoop.Client
public WorldThread()
{
Util.StartUpCheck();
Instance = this;
Instance = this;
Tick += OnTick;
Aborted += (sender, e) =>
{

View File

@ -37,7 +37,7 @@ namespace RageCoop.Core
public static Version GetLatestVersion(string branch = "dev-nightly")
{
var url = $"https://raw.githubusercontent.com/RAGECOOP/RAGECOOP-V/{branch}/RageCoop.Server/Properties/AssemblyInfo.cs";
var versionLine = HttpHelper.DownloadString(url).Split(new char[] {'\n'}, StringSplitOptions.RemoveEmptyEntries).Where(x => x.Contains("[assembly: AssemblyVersion(")).First();
var versionLine = HttpHelper.DownloadString(url).Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).Where(x => x.Contains("[assembly: AssemblyVersion(")).First();
var start = versionLine.IndexOf('\"') + 1;
var end = versionLine.LastIndexOf('\"');
return Version.Parse(versionLine.Substring(start, end - start));
@ -427,7 +427,7 @@ namespace RageCoop.Core
return output;
}
public static bool IsScript(this Type type,Type scriptType)
public static bool IsScript(this Type type, Type scriptType)
{
return !type.IsAbstract && type.IsSubclassOf(scriptType);
}

View File

@ -1,10 +1,8 @@
using GTA.NaturalMotion;
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;
namespace RageCoop.Core
@ -142,7 +140,8 @@ namespace RageCoop.Core
Flush();
}
}
string Format(LogLine line)
private string Format(LogLine line)
{
return string.Format("[{0}][{2}] [{3}] {1}", line.TimeStamp.ToString(DateTimeFormat), line.Message, Name, line.LogLevel.ToString());
}

View File

@ -15,7 +15,7 @@ using System.Resources;
[assembly: AssemblyCulture("")]
// Version information
[assembly: AssemblyVersion("1.5.4.106")]
[assembly: AssemblyFileVersion("1.5.4.106")]
[assembly: AssemblyVersion("1.5.4.118")]
[assembly: AssemblyFileVersion("1.5.4.118")]
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]

View File

@ -55,6 +55,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="DiscUtils.Iso9660" Version="0.16.13" />
<PackageReference Include="Fody" Version="6.6.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@ -1,8 +1,10 @@
using ICSharpCode.SharpZipLib.Zip;
using DiscUtils.Iso9660;
using ICSharpCode.SharpZipLib.Zip;
using RageCoop.Core;
using System;
using System.IO;
using System.Threading.Tasks;
namespace RageCoop.Server.Scripting
{
internal class Resources
@ -16,6 +18,7 @@ namespace RageCoop.Server.Scripting
Server = server;
Logger = server.Logger;
}
private readonly Dictionary<CDReader, Stream> Packages = new();
private readonly Dictionary<string, Stream> ClientResources = new();
private readonly Dictionary<string, Stream> ResourceStreams = new();
public void LoadAll()
@ -26,25 +29,37 @@ namespace RageCoop.Server.Scripting
Directory.CreateDirectory(path);
foreach (var pkg in Directory.GetFiles(path, "*.respkg", SearchOption.AllDirectories))
{
Logger?.Debug($"Adding resources from package \"{Path.GetFileNameWithoutExtension(pkg)}\"");
var pkgZip = new ZipFile(pkg);
foreach (ZipEntry e in pkgZip)
try
{
if (!e.IsFile) { continue; }
if (e.Name.StartsWith("Client") && e.Name.EndsWith(".res"))
Logger?.Debug($"Adding resources from package \"{Path.GetFileNameWithoutExtension(pkg)}\"");
var pkgStream = File.Open(pkg, FileMode.Open, FileAccess.Read, FileShare.Read);
var reader = new CDReader(pkgStream, true);
foreach (var e in reader.Root.GetDirectories("Client")[0].GetFiles())
{
var stream = pkgZip.GetInputStream(e).ToMemStream();
ClientResources.Add(Path.GetFileNameWithoutExtension(e.Name), stream);
Logger?.Debug("Resource added: " + Path.GetFileNameWithoutExtension(e.Name));
var name = Path.GetFileNameWithoutExtension(e.Name);
if (!ClientResources.TryAdd(name, e.Open(FileMode.Open)))
{
Logger?.Warning($"Resource \"{name}\" already added, ignoring");
continue;
}
Logger?.Debug("Resource added: " + name);
}
else if (e.Name.StartsWith("Server") && e.Name.EndsWith(".res"))
foreach (var e in reader.Root.GetDirectories("Server")[0].GetFiles())
{
var stream = pkgZip.GetInputStream(e).ToMemStream();
ResourceStreams.Add(Path.GetFileNameWithoutExtension(e.Name), stream);
Logger?.Debug("Resource added: " + Path.GetFileNameWithoutExtension(e.Name));
var name = Path.GetFileNameWithoutExtension(e.Name);
if (!ResourceStreams.TryAdd(name, e.Open(FileMode.Open)))
{
Logger?.Warning($"Resource \"{name}\" already loaded, ignoring");
continue;
}
Logger?.Debug("Resource added: " + name);
}
Packages.Add(reader, pkgStream);
}
catch (Exception ex)
{
Logger?.Error("Failed to read resources from package: " + pkg, ex);
}
pkgZip.Close();
}
}
@ -64,9 +79,16 @@ namespace RageCoop.Server.Scripting
{
foreach (var resourceFolder in resourceFolders)
{
var zipPath = Path.Combine(tmpDir, Path.GetFileName(resourceFolder)) + ".res";
var name = Path.GetFileNameWithoutExtension(zipPath);
if (ClientResources.ContainsKey(name))
{
Logger?.Warning($"Client resource \"{name}\" already loaded, ignoring");
continue;
}
// Pack client side resource as a zip file
Logger?.Info("Packing client-side resource: " + resourceFolder);
var zipPath = Path.Combine(tmpDir, Path.GetFileName(resourceFolder)) + ".res";
try
{
using ZipFile zip = ZipFile.Create(zipPath);
@ -82,7 +104,7 @@ namespace RageCoop.Server.Scripting
}
zip.CommitUpdate();
zip.Close();
ClientResources.Add(Path.GetFileNameWithoutExtension(zipPath), File.OpenRead(zipPath));
ClientResources.Add(name, File.OpenRead(zipPath));
}
catch (Exception ex)
{
@ -91,14 +113,6 @@ namespace RageCoop.Server.Scripting
}
}
}
var packed = Directory.GetFiles(path, "*.res", SearchOption.TopDirectoryOnly);
if (packed.Length > 0)
{
foreach (var file in packed)
{
ClientResources.Add(Path.GetFileNameWithoutExtension(file), File.OpenRead(file));
}
}
}
// Server
@ -127,14 +141,6 @@ namespace RageCoop.Server.Scripting
Logger?.Error(ex);
}
}
foreach (var res in Directory.GetFiles(path, "*.res", SearchOption.TopDirectoryOnly))
{
if (!ResourceStreams.TryAdd(Path.GetFileNameWithoutExtension(res), File.OpenRead(res)))
{
Logger?.Warning($"Resource \"{res}\" cannot be loaded, ignoring...");
continue;
}
}
foreach (var res in ResourceStreams)
{
try
@ -206,6 +212,18 @@ namespace RageCoop.Server.Scripting
}
LoadedResources.Clear();
}
foreach (var s in ClientResources.Values)
{
try
{
s.Close();
s.Dispose();
}
catch (Exception ex)
{
Logger?.Error("[Resources.CloseStream]", ex);
}
}
foreach (var s in ResourceStreams.Values)
{
try
@ -218,17 +236,10 @@ namespace RageCoop.Server.Scripting
Logger?.Error("[Resources.CloseStream]", ex);
}
}
foreach (var s in ClientResources.Values)
foreach (var r in Packages)
{
try
{
s.Close();
s.Dispose();
}
catch (Exception ex)
{
Logger?.Error("[Resources.CloseStream]", ex);
}
r.Key.Dispose();
r.Value.Dispose();
}
}
public void SendTo(Client client)