Skip to content

Commit

Permalink
Added Debug CLM
Browse files Browse the repository at this point in the history
- Debug Commandline mode added (Switch Branch to DEBUG)
- Release Mode Compiles with extern functions for Arma 3
  • Loading branch information
Slep-wt committed Dec 26, 2019
1 parent a65c72a commit f4b79ee
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 17 deletions.
93 changes: 85 additions & 8 deletions src/aex/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
using System.Runtime.InteropServices;
using RGiesecke.DllExport;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;


/*
* File: Entry.cs
Expand All @@ -13,6 +16,70 @@
* Do not remvoe these comment blocks!
*/

#if !A3COMPAT
using System.Text.RegularExpressions;
class main
{
static Regex cr = new Regex(@"(\[.*?\])|(\"".*?\"")|(\d)");
static bool Loaded = false;
static string sid;
static void Main()
{
bool exit = false;
StringBuilder output = new StringBuilder();
if (!Loaded)
{
aex.EntryPoint.RvExtension(ref output, 1024, "load");
sid = output.ToString();
output.Clear();
Loaded = true;
}

while (!exit)
{
try
{
string cmd = Console.ReadLine();
MatchCollection cm = cr.Matches(cmd);
List<string> parameters = new List<string>();
string command = "";

parameters.Add(sid);

foreach (Match x in cm)
{
string y = x.ToString();
Console.WriteLine(y);
if (y.StartsWith("[")) {
command = y.Trim(new char[] { '[', ']' });
Console.WriteLine(command);
} else if (y.StartsWith("\""))
parameters.Add(y.Trim(new char[] { '"', '"' }));
else
parameters.Add(y);
}
if (command != "" && parameters.Count > 1)
{
int res = aex.EntryPoint.RvExtensionArgs(ref output, 1024, command, parameters.ToArray(), parameters.Count);
}
else if (command == "version")
aex.EntryPoint.RvExtensionVersion(ref output, 1024);
else
aex.EntryPoint.RvExtension(ref output, 1024, command);

Console.Write(output.ToString());
output.Clear();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
}
#endif


namespace aex
{
public class EntryPoint
Expand All @@ -21,23 +88,29 @@ public class EntryPoint
internal static string sessionid = Utility.Session.CreateID();
internal static string[] modules = { "Discord Disabled", "MySql Disabled" };
internal static readonly string version = "1.0.00";
#if A3COMPAT
#if is64
[DllExport("RVExtensionVersion", CallingConvention = CallingConvention.Winapi)]
#else
[DllExport("_RVExtensionVersion@8", CallingConvention = CallingConvention.Winapi)]
#endif
public static void RvExtensionVersion(StringBuilder output, int outputSize)
#endif
public static void RvExtensionVersion(ref StringBuilder output, int outputSize)
{
outputSize--;
output.Append(version);
}

#if A3COMPAT
#if is64
[DllExport("RVExtension", CallingConvention = CallingConvention.Winapi)]
#else
[DllExport("_RVExtension@12", CallingConvention = CallingConvention.Winapi)]
#endif

public static void RvExtension(StringBuilder output, int outputSize, [MarshalAs(UnmanagedType.LPStr)] string function)
#else
public static void RvExtension(ref StringBuilder output, int outputSize, string function)
#endif
{
outputSize--;
if (function == "load")
Expand All @@ -52,16 +125,13 @@ public static void RvExtension(StringBuilder output, int outputSize, [MarshalAs(
Mysql.ModuleInit();
string ActiveModules = "[AEX::INIT::MODULES] " + modules[0] + " | " + modules[1];
Utility.Session.LogThis(ActiveModules);
output.Append(sessionid);
init = true;
}
catch (Exception e)
{
Utility.Session.LogThis("[AEX::EXCEPTION] " + e.ToString());
}
if (!init)
{
output.Append(sessionid);
}
}
else
{
Expand All @@ -71,6 +141,7 @@ public static void RvExtension(StringBuilder output, int outputSize, [MarshalAs(
}
}

#if A3COMPAT
#if is64
[DllExport("RVExtensionArgs", CallingConvention = CallingConvention.Winapi)]
#else
Expand All @@ -79,6 +150,9 @@ public static void RvExtension(StringBuilder output, int outputSize, [MarshalAs(
public static int RvExtensionArgs(StringBuilder output, int outputSize,
[MarshalAs(UnmanagedType.LPStr)] string function,
[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr, SizeParamIndex = 4)] string[] args, int argCount)
#else
public static int RvExtensionArgs(ref StringBuilder output, int outputSize, string function, string[] args, int argCount)
#endif
{
outputSize--;
try
Expand Down Expand Up @@ -135,7 +209,7 @@ public static int RvExtensionArgs(StringBuilder output, int outputSize,
case "mysql:async":
if (args.Length == 3)
{
Task<string> SQLAsync = Mysql.ExecuteAsync(args[1], Convert.ToBoolean(args[2]));
Task<string> SQLAsync = Mysql.ExecuteAsync(args[1], Convert.ToBoolean(Convert.ToInt32(args[2])));
SQLAsync.Wait();
output.Append(SQLAsync.Result);
} else
Expand Down Expand Up @@ -167,9 +241,12 @@ public static int RvExtensionArgs(StringBuilder output, int outputSize,
}
catch (Exception e)
{
#if !A3COMPAT
output.Append(e.ToString());
#endif
Utility.Session.LogThis("[AEX::EXCEPTION] " + e.ToString());
return 1;
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/aex/Mysql.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public class Mysql
private static readonly string DefaultDatabase = (string)Utility.JSON.readJSON("mysql", "database");
internal static readonly string cstr = "Server= " + DatabaseAddress + ";Port= " + PortNumber + ";Database=" + DefaultDatabase + ";Uid=" + DatabaseUsername + ";Pwd=" + DatabasePassword + ";Pooling=false;";
internal static MySqlConnection conn = new MySqlConnection(cstr);
internal static readonly int MaxReturnSize = 8192;
internal static readonly int MaxReturnSize = (int)Utility.JSON.readJSON("misc", "datamaxreturn");

internal static string[][] SQLResultBuffer = new string[256][];
internal static string[][] SQLResultBuffer = new string[(int)Utility.JSON.readJSON("mysql", "buffer")][];

internal static void ModuleInit()
{
Expand Down
22 changes: 20 additions & 2 deletions src/aex/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ internal class JSONFormat
[JsonProperty("MysqlDatabase")]
public string MysqlDatabase;

[JsonProperty("MysqlBufferSize")]
public int MysqlBufferSize;

[JsonProperty("DataMaxReturnSize")]
public int DataMaxReturnSize;

[JsonProperty("EnableDebug")]
public bool EnableDebug;
}
Expand Down Expand Up @@ -300,9 +306,10 @@ public static object[] readJSONArray(string module, string attrib)
{
case "apid":
return ds.DiscordApid;

case "apikey":
return ds.DiscordApikey;
case "channels":
return ds.DiscordChannels;

default:
return new string[1]{ "ERR_INVALID_ATTRIB" };
Expand Down Expand Up @@ -391,14 +398,25 @@ public static object readJSON(string module, string attrib)

case "database":
return ds.MysqlDatabase;

case "buffer":
return ds.MysqlBufferSize;
case "enable":
return ds.EnableMysql;

default:
return "ERR_INVALID_ATTRIB";
}
}
else if (module == "misc")
{
switch (attrib)
{
case "datamaxreturn":
return ds.DataMaxReturnSize;
case "enabledebug":
return ds.EnableDebug;
}
}
return "ERR_INVALID_PARAMS";
}
}
Expand Down
16 changes: 11 additions & 5 deletions src/aex/aex.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9192B246-99F7-4115-B289-2352495FD5F3}</ProjectGuid>
<OutputType>Library</OutputType>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>aex</RootNamespace>
<AssemblyName>aex</AssemblyName>
Expand All @@ -21,18 +21,20 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;is64</DefineConstants>
<DefineConstants>TRACE;DEBUG;is64;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<DefineConstants>TRACE;is64;A3COMPAT</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -78,6 +80,9 @@
<PropertyGroup>
<DelaySign>false</DelaySign>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="BouncyCastle.Crypto, Version=1.8.3.0, Culture=neutral, PublicKeyToken=0e99375e54769942">
<HintPath>..\packages\BouncyCastle.1.8.3.1\lib\BouncyCastle.Crypto.dll</HintPath>
Expand All @@ -92,9 +97,8 @@
<Reference Include="MySql.Data">
<HintPath>..\packages\MySql.Data.8.0.18\lib\net452\MySql.Data.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Renci.SshNet, Version=2016.1.0.0, Culture=neutral, PublicKeyToken=1cee9f8bde3db106, processorArchitecture=MSIL">
<HintPath>..\packages\SSH.NET.2016.1.0\lib\net40\Renci.SshNet.dll</HintPath>
Expand All @@ -115,6 +119,8 @@
<Reference Include="System.Core">
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Core.dll</HintPath>
</Reference>
<Reference Include="System.Data.Entity" />
<Reference Include="System.Data.Entity.Design" />
<Reference Include="System.Data.Linq">
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Data.Linq.dll</HintPath>
</Reference>
Expand Down
6 changes: 6 additions & 0 deletions src/aex/aex.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ReferencePath>I:\aexsrc\packages\</ReferencePath>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions src/aex/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<package id="Fody" version="3.2.0" targetFramework="net452" developmentDependency="true" />
<package id="Google.Protobuf" version="3.6.1" targetFramework="net452" />
<package id="MySql.Data" version="8.0.18" targetFramework="net452" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net452" />
<package id="SSH.NET" version="2016.1.0" targetFramework="net452" />
<package id="System.Buffers" version="4.4.0" targetFramework="net452" />
<package id="System.Memory" version="4.5.0" targetFramework="net452" />
Expand Down

0 comments on commit f4b79ee

Please sign in to comment.