Skip to content
This repository has been archived by the owner on Nov 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #3 from brianb12321/Scripting
Browse files Browse the repository at this point in the history
Scripting
  • Loading branch information
brianb12321 authored Mar 30, 2018
2 parents 774785b + 7cc13ca commit 92259de
Show file tree
Hide file tree
Showing 76 changed files with 2,295 additions and 368 deletions.
Binary file added Libs/AutocompleteMenu.dll
Binary file not shown.
8 changes: 7 additions & 1 deletion RemotePlus.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2024
VisualStudioVersion = 15.0.27130.2027
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemotePlusServer", "src\RemotePlusServer\RemotePlusServer.csproj", "{4E41F31E-DCE5-4B9C-A2D6-20BF6ACD9C84}"
EndProject
Expand Down Expand Up @@ -39,6 +39,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServerMath", "src\ReleaseEx
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Recon", "src\Recon\Recon.csproj", "{0E62814F-F665-44D3-B97E-62DC75809741}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemotePlusLibrary.Scripting", "RemotePlusLibrary.Scripting\RemotePlusLibrary.Scripting.csproj", "{5C399F78-C133-4F9B-9758-C36A4B7FAE98}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -109,6 +111,10 @@ Global
{0E62814F-F665-44D3-B97E-62DC75809741}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E62814F-F665-44D3-B97E-62DC75809741}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E62814F-F665-44D3-B97E-62DC75809741}.Release|Any CPU.Build.0 = Release|Any CPU
{5C399F78-C133-4F9B-9758-C36A4B7FAE98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5C399F78-C133-4F9B-9758-C36A4B7FAE98}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5C399F78-C133-4F9B-9758-C36A4B7FAE98}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5C399F78-C133-4F9B-9758-C36A4B7FAE98}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
13 changes: 13 additions & 0 deletions RemotePlusLibrary.Scripting/IndexScriptObjectAttribute.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 RemotePlusLibrary.Scripting
{
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Method)]
public class IndexScriptObjectAttribute : Attribute
{
}
}
36 changes: 36 additions & 0 deletions RemotePlusLibrary.Scripting/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("RemotePlusLibrary.Scripting")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RemotePlusLibrary.Scripting")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5c399f78-c133-4f9b-9758-c36a4b7fae98")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// 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("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
95 changes: 95 additions & 0 deletions RemotePlusLibrary.Scripting/RemotePlusLibrary.Scripting.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5C399F78-C133-4F9B-9758-C36A4B7FAE98}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RemotePlusLibrary.Scripting</RootNamespace>
<AssemblyName>RemotePlusLibrary.Scripting</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Ionic.Zip, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c, processorArchitecture=MSIL">
<HintPath>..\packages\Ionic.Zip.1.9.1.8\lib\Ionic.Zip.dll</HintPath>
</Reference>
<Reference Include="IronPython, Version=2.7.8.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<HintPath>..\packages\IronPython.2.7.8.1\lib\net45\IronPython.dll</HintPath>
</Reference>
<Reference Include="IronPython.Modules, Version=2.7.8.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<HintPath>..\packages\IronPython.2.7.8.1\lib\net45\IronPython.Modules.dll</HintPath>
</Reference>
<Reference Include="IronPython.SQLite, Version=2.7.8.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<HintPath>..\packages\IronPython.2.7.8.1\lib\net45\IronPython.SQLite.dll</HintPath>
</Reference>
<Reference Include="IronPython.Wpf, Version=2.7.8.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<HintPath>..\packages\IronPython.2.7.8.1\lib\net45\IronPython.Wpf.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Dynamic, Version=1.2.0.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<HintPath>..\packages\DynamicLanguageRuntime.1.2.1\lib\net45\Microsoft.Dynamic.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Scripting, Version=1.2.0.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<HintPath>..\packages\DynamicLanguageRuntime.1.2.1\lib\net45\Microsoft.Scripting.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Scripting.Metadata, Version=1.2.0.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<HintPath>..\packages\DynamicLanguageRuntime.1.2.1\lib\net45\Microsoft.Scripting.Metadata.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.CodeCoverage.Shim, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\DynamicLanguageRuntime.1.2.1\lib\net45\Microsoft.VisualStudio.CodeCoverage.Shim.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression.FileSystem">
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="IndexScriptObjectAttribute.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScriptBuilder.cs" />
<Compile Include="ScriptGlobal.cs" />
<Compile Include="ScriptGlobalInformation.cs" />
<Compile Include="ScriptGlobalTypecs.cs" />
<Compile Include="ScriptPackageEngine\ScriptPackage.cs" />
<Compile Include="ScriptPackageEngine\ScriptPackageManifest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\RemotePlusLibrary.Configuration\RemotePlusLibrary.Configuration.csproj">
<Project>{8a8a5888-1ce7-46ed-b8de-1ac7671f3426}</Project>
<Name>RemotePlusLibrary.Configuration</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
88 changes: 88 additions & 0 deletions RemotePlusLibrary.Scripting/ScriptBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using IronPython.Hosting;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;
using RemotePlusLibrary;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace RemotePlusLibrary.Scripting
{
public class ScriptBuilder
{
private Dictionary<string, ScriptGlobal> globals = new Dictionary<string, ScriptGlobal>();
public const string SCRIPT_LOG_CONSTANT = "Script Engine";
public ScriptEngine ScriptingEngine { get; private set; }
void InitializeGlobals()
{
foreach (KeyValuePair<string, ScriptGlobal> global in globals)
{
ScriptingEngine.GetBuiltinModule().SetVariable(global.Key, global.Value.Global);
}
}
public void AddScriptObject<T>(string objectName, T scriptObject, string description, ScriptGlobalType objectType) where T : class
{
var newGlobal = new ScriptGlobal(scriptObject) { Information = new ScriptGlobalInformation() { Name = objectName, Description = description, Type = objectType } };
FillMembersRecurs(newGlobal);
globals.Add(objectName, newGlobal);
}

private void FillMembersRecurs(ScriptGlobal newGlobal)
{
FillData(newGlobal.Global.GetType(), newGlobal.Information);
}
void FillData(Type t, ScriptGlobalInformation i)
{
foreach (MethodInfo method in t.GetMethods().Where(type => type.GetCustomAttribute<IndexScriptObjectAttribute>() != null))
{
ScriptGlobalInformation info = new ScriptGlobalInformation();
var g = new ScriptGlobalInformation();
g.Name = method.Name;
g.Type = ScriptGlobalType.Function;
i.Members.Add(g);
}
foreach (var property in t.GetProperties().Where(type => type.GetCustomAttribute<IndexScriptObjectAttribute>() != null))
{
ScriptGlobalInformation info = new ScriptGlobalInformation();
info.Name = property.Name;
info.Type = ScriptGlobalType.Variable;
FillDataProperty(property.PropertyType, info);
i.Members.Add(info);
}
}
void FillDataProperty(Type t, ScriptGlobalInformation i)
{
ScriptGlobalInformation info = new ScriptGlobalInformation();
foreach (var property in t.GetProperties().Where(type => type.GetCustomAttribute<IndexScriptObjectAttribute>() != null))
{
info.Name = property.Name;
info.Type = ScriptGlobalType.Variable;
i.Members.Add(info);
FillDataProperty(property.PropertyType, info);
}
}
public bool FunctionExists(string functionName)
{
return globals.ContainsKey(functionName);
}
public List<ScriptGlobal> GetGlobals()
{
return globals.Values.ToList();
}

public void InitializeEngine()
{
ScriptingEngine = Python.CreateEngine();
InitializeGlobals();
}
public bool ExecuteString(string script)
{
var source = ScriptingEngine.CreateScriptSourceFromString(script);
return source.Execute();
}
}
}
19 changes: 19 additions & 0 deletions RemotePlusLibrary.Scripting/ScriptGlobal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using RemotePlusLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RemotePlusLibrary.Scripting
{
public class ScriptGlobal
{
public ScriptGlobalInformation Information { get; set; }
public object Global { get; set; }
public ScriptGlobal(object g)
{
Global = g;
}
}
}
22 changes: 22 additions & 0 deletions RemotePlusLibrary.Scripting/ScriptGlobalInformation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace RemotePlusLibrary.Scripting
{
[DataContract]
public class ScriptGlobalInformation
{
[DataMember]
public string Name { get; set; }
[DataMember]
public string Description { get; set; }
[DataMember]
public ScriptGlobalType Type { get; set; }
[DataMember]
public List<ScriptGlobalInformation> Members { get; set; } = new List<ScriptGlobalInformation>();
}
}
18 changes: 18 additions & 0 deletions RemotePlusLibrary.Scripting/ScriptGlobalTypecs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace RemotePlusLibrary.Scripting
{
[DataContract]
public enum ScriptGlobalType
{
[EnumMember]
Variable,
[EnumMember]
Function
}
}
44 changes: 44 additions & 0 deletions RemotePlusLibrary.Scripting/ScriptPackageEngine/ScriptPackage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ionic.Zip;
using System.IO;
using System.Runtime.Serialization;
using System.Xml;

namespace RemotePlusLibrary.Scripting.ScriptPackageEngine
{
public class ScriptPackage
{
public ZipFile PackageContents { get; private set; }
public ScriptPackageManifest PackageManifest { get; private set; }
public string PackageFileName { get; set; }
private ScriptPackage(ZipFile contents, ScriptPackageManifest manifest, string packageFileName)
{
PackageContents = contents;
PackageManifest = manifest;
PackageFileName = packageFileName;
}
public static ScriptPackage Open(string packageName)
{
if(!File.Exists(packageName))
{
throw new FileNotFoundException($"{packageName} does not exist.");
}
ZipFile package = ZipFile.Read(packageName);
var manifest = ReadPackageManifest(package[$"{Path.GetFileNameWithoutExtension(packageName)}/{Path.GetFileNameWithoutExtension(packageName)}.manifest"]);
return new ScriptPackage(package, manifest, Path.GetFileNameWithoutExtension(packageName));
}

private static ScriptPackageManifest ReadPackageManifest(ZipEntry zipArchiveEntry)
{
DataContractSerializer ser = new DataContractSerializer(typeof(ScriptPackageManifest));
XmlReader reader = XmlReader.Create(zipArchiveEntry.OpenReader());
var ss = (ScriptPackageManifest)ser.ReadObject(reader);
reader.Close();
return ss;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RemotePlusLibrary.Scripting.ScriptPackageEngine
{
public static class ScriptPackageExtensions
{
public static bool ExecuteScript(this ScriptPackage package)
{
Stream s = package.PackageContents.GetEntry(package.PackageManifest.ScriptEntryPoint).Open();

}
}
}
Loading

0 comments on commit 92259de

Please sign in to comment.