Skip to content
This repository has been archived by the owner on Dec 22, 2024. It is now read-only.

Commit

Permalink
release 0.3.2 BETA
Browse files Browse the repository at this point in the history
  • Loading branch information
Pursuit committed Dec 15, 2018
1 parent 2ed6e6a commit 4396166
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 52 deletions.
1 change: 0 additions & 1 deletion AsiSupport/ASI/AsiInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ private static IntPtr NativeCall()
argumentsIndex = 0;

*(NativeRetVal*)returnedValue = (NativeRetVal)NativeFunction.Call(nativeHash, typeof(NativeRetVal), args);

return returnedValue;
}

Expand Down
101 changes: 53 additions & 48 deletions AsiSupport/ASI/AsiLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@ public class AsiLoader

public string WorkingDir { get; private set; }
public bool Loading { get; private set; }
public List<AsiPlugin> LoadedPlugins { get; private set; }
private readonly ManifestFile exceptions;
public List<AsiPlugin> LoadedPlugins { get; } = new List<AsiPlugin>();
private readonly IntegrityMap integrityMap;

public AsiLoader(string workingDir)
{
Log.Info("Initializing AsiLoader...");
this.WorkingDir = Path.GetFullPath(workingDir);
this.Loading = false;
this.LoadedPlugins = new List<AsiPlugin>();
this.exceptions = new ManifestFile(Path.Combine(Support.Instance.DataDirectory, "Exceptions"));
this.integrityMap = new IntegrityMap(Path.Combine(Support.Instance.DataDirectory, "Conversions"));
this.integrityMap.Cleanup(this.WorkingDir);

Expand Down Expand Up @@ -99,69 +96,77 @@ public void LoadPlugin(string name)

public void LoadPlugin(AsiPlugin plugin)
{
if(this.exceptions.Entries.Contains(plugin.Name.ToLower()))
{
Log.Info("Skipping \"" + plugin.Name + "\".");
return;
}

this.Loading = true;
Log.Info("Loading \"" + plugin.Name + '"');

//In case ScriptHookV is present and has already loaded the ASI
Game.TerminateAllScriptsWithName(plugin.Name.ToLower() + ".asi");

if(plugin.Type == AsiType.NonUniversal)
try
{
Log.Info("Non universal ASI detected. Converting it...");
plugin.ConvertAsi();
this.integrityMap.UpdateConversionHash(plugin.Name, IOUtil.GetFileChecksum(plugin.Name + ".asi"), IOUtil.GetFileChecksum(plugin.UASIPath));
Log.Info("Plugin converted successfully.");
GameFiber.Yield();
}
else if(plugin.Type == AsiType.UniversalConverted)
{
bool outdated = false;

if(this.integrityMap.HasConversionHash(plugin.Name))
outdated = IOUtil.GetFileChecksum(plugin.Name + ".asi") != this.integrityMap.GetAsiHash(plugin.Name) || IOUtil.GetFileChecksum(plugin.UASIPath) != this.integrityMap.GetUnivHash(plugin.Name);
else outdated = true;
//In case ScriptHookV is present and has already loaded the ASI
Game.TerminateAllScriptsWithName(plugin.Name.ToLower() + ".asi");

if(outdated)
if(plugin.Type == AsiType.NonUniversal)
{
Log.Info("Outdated ASI detected. Converting it again...");
Log.Info("Non universal ASI detected. Converting it...");
plugin.ConvertAsi();
this.integrityMap.UpdateConversionHash(plugin.Name, IOUtil.GetFileChecksum(plugin.Name + ".asi"), IOUtil.GetFileChecksum(plugin.UASIPath));
Log.Info("Plugin converted successfully.");
GameFiber.Yield();
}
else if(plugin.Type == AsiType.UniversalConverted)
{
bool outdated = false;

GameFiber.Yield();
}
if(this.integrityMap.HasConversionHash(plugin.Name))
outdated = IOUtil.GetFileChecksum(plugin.Name + ".asi") != this.integrityMap.GetAsiHash(plugin.Name) || IOUtil.GetFileChecksum(plugin.UASIPath) != this.integrityMap.GetUnivHash(plugin.Name);
else outdated = true;

this.LoadedPlugins.Add(plugin);
IntPtr module = LoadLibraryA(plugin.UASIPath);
if(outdated)
{
Log.Info("Outdated ASI detected. Converting it again...");
plugin.ConvertAsi();
this.integrityMap.UpdateConversionHash(plugin.Name, IOUtil.GetFileChecksum(plugin.Name + ".asi"), IOUtil.GetFileChecksum(plugin.UASIPath));
Log.Info("Plugin converted successfully.");
}

if(module != IntPtr.Zero)
{
if(plugin.ScriptThreads.Count > 0)
{
Log.Info("Plugin \"" + plugin.Name + "\" loaded successfully.");
GameFiber.Yield();
}

this.LoadedPlugins.Add(plugin);
IntPtr module = LoadLibraryA(plugin.UASIPath);

foreach(AsiThread thread in plugin.ScriptThreads)
thread.Start();
if(module != IntPtr.Zero)
{
if(plugin.ScriptThreads.Count > 0)
{
Log.Info("Plugin \"" + plugin.Name + "\" loaded successfully.");

foreach(AsiThread thread in plugin.ScriptThreads)
thread.Start();
}
else Log.Warn("Plugin \"" + plugin.Name + "\" has been loaded successfully, but didn't register any thread. Try rebooting your game to fix this issue.");
}
else
{
this.LoadedPlugins.Remove(plugin);
Log.Error("Unable to load \"" + plugin.Name + "\", try rebooting your game: " + new Win32Exception(Marshal.GetLastWin32Error()));
}
else Log.Warn("Plugin \"" + plugin.Name + "\" has been loaded successfully, but didn't register any thread. Try rebooting your game to fix this issue.");

this.Loading = false;

if(this.integrityMap.Dirty)
this.integrityMap.SaveMap();
}
else
catch(NotScriptException)
{
this.LoadedPlugins.Remove(plugin);
Log.Error("Unable to load \"" + plugin.Name + "\", try rebooting your game: " + new Win32Exception(Marshal.GetLastWin32Error()));
Log.Info("Skipping \"" + plugin.Name + "\" as it is not a ScriptHookV script.");
}
catch(Exception e)
{
if(this.LoadedPlugins.Contains(plugin))
this.LoadedPlugins.Remove(plugin);

this.Loading = false;

if(this.integrityMap.Dirty)
this.integrityMap.SaveMap();
Log.Error("Unable to load \"" + plugin.Name + "\": " + e);
}
}

public AsiPlugin GetPlugin(string name)
Expand Down
3 changes: 3 additions & 0 deletions AsiSupport/ASI/AsiPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public void ConvertAsi()
fStream.Position = pos;
this.JumpToRVA(fStream, reader, relocationPos, reader.ReadUInt32()); //Jump to the dll's Name

if(fStream.Position > fStream.Length) //If we jumped out of the file
throw new NotScriptException();

for(int i = 0; i < dllName.Length; i++)
dllName[i] = (char)reader.ReadByte();

Expand Down
13 changes: 13 additions & 0 deletions AsiSupport/ASI/NotScriptException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AsiSupport.ASI
{
public class NotScriptException : Exception
{
public NotScriptException() : base("The specified ASI file is not an ASI script") {}
}
}
1 change: 1 addition & 0 deletions AsiSupport/AsiSupport.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<Compile Include="ASI\AsiType.cs" />
<Compile Include="ASI\IntegrityMap.cs" />
<Compile Include="ASI\AsiThread.cs" />
<Compile Include="ASI\NotScriptException.cs" />
<Compile Include="Config.cs" />
<Compile Include="ConsoleCommands.cs" />
<Compile Include="EntryPoint.cs" />
Expand Down
4 changes: 2 additions & 2 deletions AsiSupport/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.3.1")]
[assembly: AssemblyFileVersion("0.3.1")]
[assembly: AssemblyVersion("0.3.2")]
[assembly: AssemblyFileVersion("0.3.2")]
1 change: 0 additions & 1 deletion AsiSupport/resources.manifest
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#AsiSupport resource manifest

resource:Exceptions.manifest
resource:Versions.manifest
4 changes: 4 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
__0.3.2__
* The plugin should no longer crash if it failed to load or convert an ASI file
* The plugin now detects non ScriptHookV scripts instead of trying to convert them

__0.3.1__
* Improved performance

Expand Down

0 comments on commit 4396166

Please sign in to comment.