Skip to content

Commit

Permalink
All changes Done (Hopefully)
Browse files Browse the repository at this point in the history
  • Loading branch information
rudyrdx committed Jul 6, 2024
1 parent 06c93a0 commit 0006641
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 69 deletions.
42 changes: 0 additions & 42 deletions OpenBullet2.Web/package-lock.json

This file was deleted.

7 changes: 0 additions & 7 deletions OpenBullet2.Web/package.json

This file was deleted.

29 changes: 14 additions & 15 deletions RuriLib/Blocks/Interop/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,28 @@ public static string ShellCommand(BotData data, string executable, string argume
* These are not blocks, but they take BotData as an input. The ScriptBlockInstance will take care
* of writing C# code that calls these methods where necessary once it's transpiled.
*/

public static async Task<T> InvokeNode<T>(BotData data, (string, string) scriptOrFile, object[] parameters, bool isScript = false)
public static async Task<T> InvokeNode<T>(BotData data, string scriptOrFile, object[] parameters, bool isScript = false, string scriptHash = null)
{
data.Logger.LogHeader();
T result;

if (isScript)
if (isScript && !string.IsNullOrEmpty(scriptHash))
{
result = await InvokeFromStringOrCache<T>(data, scriptOrFile, parameters);
result = await InvokeFromStringOrCache<T>(data, scriptOrFile, parameters, scriptHash);
}
else
{

result = await InvokeFromFile<T>(data, scriptOrFile.Item2 /*hash*/, parameters);
result = await InvokeFromFile<T>(data, scriptOrFile, parameters);
}

data.Logger.Log($"Executed NodeJS script with result: {result}", LogColors.PaleChestnut);
return result;
}
private static async Task<T> InvokeFromStringOrCache<T>(BotData data, (string, string) script, object[] parameters)
{
string hash = Path.GetFileNameWithoutExtension(script.Item2).Split('/').Last();

private static async Task<T> InvokeFromStringOrCache<T>(BotData data, string script, object[] parameters, string scriptHash)
{
var (isCached, cachedResult) = await StaticNodeJSService.TryInvokeFromCacheAsync<T>(
hash,
scriptHash,
null,
parameters,
data.CancellationToken
Expand All @@ -76,22 +73,24 @@ private static async Task<T> InvokeFromStringOrCache<T>(BotData data, (string, s
}

return await StaticNodeJSService.InvokeFromStringAsync<T>(
script.Item1,
hash,
script,
scriptHash,
null,
parameters,
data.CancellationToken
).ConfigureAwait(false);
}
private static Task<T> InvokeFromFile<T>(BotData data, string filePath, object[] parameters)

private static async Task<T> InvokeFromFile<T>(BotData data, string filePath, object[] parameters)
{
return StaticNodeJSService.InvokeFromFileAsync<T>(
return await StaticNodeJSService.InvokeFromFileAsync<T>(
filePath,
null,
parameters,
data.CancellationToken
);
).ConfigureAwait(false);
}

public static Engine InvokeJint(BotData data, Engine engine, string scriptFile)
{
data.Logger.LogHeader();
Expand Down
6 changes: 1 addition & 5 deletions RuriLib/Models/Blocks/Custom/ScriptBlockInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,9 @@ public override string ToCSharp(List<string> definedVariables, ConfigSettings se

scriptHash = HexConverter.ToHexString(Crypto.MD5(Encoding.UTF8.GetBytes(nodeScript)));

scriptPath = $"Scripts/{scriptHash}.{GetScriptFileExtension(Interpreter)}";

string escapedScript = JsonConvert.ToString(nodeScript);

(string, string) scriptNHash = (escapedScript, JsonConvert.ToString(scriptPath));

writer.WriteLine($"var {resultName} = await InvokeNode<dynamic>(data, {scriptNHash}, new object[] {{ {InputVariables} }}, true);");
writer.WriteLine($"var {resultName} = await InvokeNode<dynamic>(data, {escapedScript}, new object[] {{ {InputVariables} }}, true, \"{scriptHash}\");");

foreach (var output in OutputVariables)
{
Expand Down

0 comments on commit 0006641

Please sign in to comment.