Skip to content
This repository has been archived by the owner on Jan 23, 2019. It is now read-only.

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Koncord committed Dec 22, 2018
0 parents commit 4fcacbd
Show file tree
Hide file tree
Showing 10 changed files with 425 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NetLibGen
---------
This is an experimental tes3mp C# bindings generator
13 changes: 13 additions & 0 deletions csharp/Functions/Public.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Runtime.CompilerServices;

namespace TES3MPSharp
{
public static partial class TES3MP
{
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void MakePublic(object callback, string name);

[MethodImpl(MethodImplOptions.InternalCall)]
public static extern object CallPublic(string name, params object[] args);
}
}
34 changes: 34 additions & 0 deletions csharp/Functions/Timer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;


namespace TES3MPSharp
{
public static partial class TES3MP
{
public static int CreateTimer(object callback, int msec)
{
return CreateTimerEx(callback, msec, "");
}

[MethodImpl(MethodImplOptions.InternalCall)]
public static extern int CreateTimerEx(object callback, int msec, string types, params object[] args);


[DllImport("__Internal", CharSet = CharSet.Ansi)]
public static extern void StartTimer(int timerId);

[DllImport("__Internal", CharSet = CharSet.Ansi)]
public static extern void StopTimer(int timerId);

[DllImport("__Internal", CharSet = CharSet.Ansi)]
public static extern void RestartTimer(int timerId, int msec);

[DllImport("__Internal", CharSet = CharSet.Ansi)]
public static extern void FreeTimer(int timerId);

[DllImport("__Internal", CharSet = CharSet.Ansi)]
public static extern bool IsTimerElapsed(int timerId);
}
}
183 changes: 183 additions & 0 deletions csharp/Instance.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
using System;

namespace TES3MPSharp
{
public class Instance
{
public virtual void OnServerInit()
{
}
public virtual void OnServerPostInit()
{
}
public virtual void OnServerExit(int code)
{
}
public virtual void OnPlayerConnect(ushort pid)
{
}
public virtual void OnPlayerDisconnect(ushort pid)
{
}
public virtual void OnPlayerDeath(ushort pid)
{
}
public virtual void OnPlayerResurrect(ushort pid)
{
}
public virtual void OnPlayerCellChange(ushort pid)
{
}
public virtual void OnPlayerAttribute(ushort pid)
{
}
public virtual void OnPlayerSkill(ushort pid)
{
}
public virtual void OnPlayerLevel(ushort pid)
{
}
public virtual void OnPlayerBounty(ushort pid)
{
}
public virtual void OnPlayerReputation(ushort pid)
{
}
public virtual void OnPlayerEquipment(ushort pid)
{
}
public virtual void OnPlayerInventory(ushort pid)
{
}
public virtual void OnPlayerJournal(ushort pid)
{
}
public virtual void OnPlayerFaction(ushort pid)
{
}
public virtual void OnPlayerShapeshift(ushort pid)
{
}
public virtual void OnPlayerSpellbook(ushort pid)
{
}
public virtual void OnPlayerQuickKeys(ushort pid)
{
}
public virtual void OnPlayerTopic(ushort pid)
{
}
public virtual void OnPlayerDisposition(ushort pid)
{
}
public virtual void OnPlayerBook(ushort pid)
{
}
public virtual void OnPlayerItemUse(ushort pid)
{
}
public virtual void OnPlayerMiscellaneous(ushort pid)
{
}
public virtual void OnPlayerInput(ushort pid)
{
}
public virtual void OnPlayerRest(ushort pid)
{
}
public virtual void OnPlayerSendMessage(ushort pid, string message)
{
}
public virtual void OnPlayerEndCharGen(ushort pid)
{
}

public virtual void OnGUIAction(ushort pid, int idGui, string data)
{
}

public virtual void OnRecordDynamic(ushort pid)
{
}

public virtual void OnCellLoad(ushort pid, string cellDescription)
{
}
public virtual void OnCellUnload(ushort pid, string cellDescription)
{
}
public virtual void OnCellDeletion(string cellDescription)
{
}

public virtual void OnContainer(ushort pid, string cellDescription)
{
}
public virtual void OnDoorState(ushort pid, string cellDescription)
{
}
public virtual void OnObjectActivate(ushort pid, string cellDescription)
{
}
public virtual void OnObjectPlace(ushort pid, string cellDescription)
{
}
public virtual void OnObjectState(ushort pid, string cellDescription)
{
}
public virtual void OnObjectSpawn(ushort pid, string cellDescription)
{
}
public virtual void OnObjectDelete(ushort pid, string cellDescription)
{
}
public virtual void OnObjectLock(ushort pid, string cellDescription)
{
}
public virtual void OnObjectScale(ushort pid, string cellDescription)
{
}
public virtual void OnObjectTrap(ushort pid, string cellDescription)
{
}
public virtual void OnVideoPlay(ushort pid, string cellDescription)
{
}

public virtual void OnActorList(ushort pid, string cellDescription)
{
}
public virtual void OnActorEquipment(ushort pid, string cellDescription)
{
}
public virtual void OnActorAI(ushort pid, string cellDescription)
{
}
public virtual void OnActorDeath(ushort pid, string cellDescription)
{
}
public virtual void OnActorCellChange(ushort pid, string cellDescription)
{
}
public virtual void OnActorTest(ushort pid, string cellDescription)
{
}

public virtual void OnWorldKillCount(ushort pid)
{
}
public virtual void OnWorldMap(ushort pid)
{
}
public virtual void OnWorldWeather(ushort pid)
{
}

public virtual void OnMpNumIncrement(int mpNum)
{
}
public virtual void OnRequestPluginList()
{
}
}
}
11 changes: 11 additions & 0 deletions csharp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
files := Instance.cs Properties/AssemblyInfo.cs $(wildcard ./Functions/*.cs) $(wildcard ./Functions.Generated/*.cs)

all: TES3MPSharp.dll

TES3MPSharp.dll: $(files)
@mcs -out:TES3MPSharp.dll -target:library $(files)

clean:
@rm -f TES3MPSharp.dll

.PHONY: all clean run
35 changes: 35 additions & 0 deletions csharp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Reflection;
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("TES3MPSharp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TES3MPSharp")]
[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("86F11AE4-07E5-468B-A8B1-50504791F14E")]

// 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")]
61 changes: 61 additions & 0 deletions genFnClass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import os
import sys
from helper import *

Config.set_library_path('/usr/lib/llvm-6.0/lib')


def createCsharpFile(csharpNamespace: str, cppFilename: str, csharpFilename: str):
index = Index.create()
tu = index.parse(cppFilename)
funcs, classes, namespaces = find_decls(tu)

csharpFile = open(csharpFilename, "w")

csharpFile.write('using System.Runtime.InteropServices;\n\n')
csharpFile.write('namespace {0}\n{{\n'.format(csharpNamespace))

# csharpFile.write(' public static class {0}\n {{\n'.format(u.spelling))
csharpFile.write(' public static partial class {0}\n {{\n'.format('TES3MP'))

for c in funcs:

if c.kind == CursorKind.FUNCTION_DECL:
funcName = c.spelling
funcType = convertType(c.result_type.kind)
#csharpFile.write(' [MethodImpl(MethodImplOptions.InternalCall)]\n')
csharpFile.write(' [DllImport("__Internal", CharSet = CharSet.Ansi)]\n')
csharpFile.write(' public static extern {0} {1}('.format(funcType, funcName))

args = ''
for par in get_params(c):
isPtr = False
typ = par[0]
argName = par[-1]
if typ == TypeKind.POINTER:
isPtr = True
typ = par[1]
argType = convertType(typ, isPtr)
args += '{0} {1}, '.format(argType, argName)

csharpFile.write(args[:-2] + ');\n\n')

csharpFile.write(' }\n')
csharpFile.write('}')
csharpFile.close()


if __name__ == '__main__':
if len(sys.argv) < 3:
print(sys.argv[0], "csharp-namespace cpp-file [csharp-file]")
sys.exit()

namespace = sys.argv[1]
cppfile = sys.argv[2]
csharpfile = ''
if len(sys.argv) == 3:
csharpfile = cppfile.split(os.sep)[-1].split('.')[0] + '.cs'
else:
csharpfile = sys.argv[3]

createCsharpFile(namespace, cppfile, csharpfile)
19 changes: 19 additions & 0 deletions genFnClasses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from genFnClass import createCsharpFile
import sys
from os import listdir, makedirs, path
from os.path import isfile, join
from progressbar import *

# python ./genFnClasses.py $TES3MP_PATH/apps/openmw-mp/Script/Functions $OUT/lib
if __name__ == '__main__':
cppfilesDir = sys.argv[1]
outdir = sys.argv[2]
hppfiles = [f for f in listdir(cppfilesDir) if isfile(join(cppfilesDir, f)) and f.endswith('.hpp')]
if not path.exists(outdir):
makedirs(outdir)
for i in progressbar(range(len(hppfiles))):
cppfile = join(cppfilesDir, hppfiles[i])
outfile = join(outdir, hppfiles[i].split('.')[0] + '.cs')
if hppfiles[i] == "Timer.hpp" or hppfiles[i] == "Public.hpp":
continue
createCsharpFile("TES3MPSharp", cppfile, outfile)
Loading

0 comments on commit 4fcacbd

Please sign in to comment.