Skip to content

Commit

Permalink
Experimental rpc (#15)
Browse files Browse the repository at this point in the history
* + First proof of concept for calling arbitrary Omsi functions from c#

* Pain and suffering...
The calling convention is wrong because nobody in there right mind would use borland fastcall.

* + Some untested assembly and bindings for TProgMan.MakeVehicle()

* The assembly now works as expected, but I don't have the right pointer to the vehicle list which causes a crash when the function is called.
 + Rewrote most of the assembly; calling convention translation is tested working
 + Updated c# plugin to use the OmsiHookInvoker library
 * Build script changes
 * Refactoring

* Not really much closer to it working; but I now know why it's broken.
 + Added TTempRVListCreate
 + Added TProgManPlaceRandomBus
 + Pain and suffering

* It finally works
 + V2 of BorlandFastcall which accounts for Delphi trying to clean up the stack; any Delphi method can be called remotely now
 * Functional proof of concept for PlaceRandomBus

* Refactored a bunch of the RPC stuff
 + Added OmsiRemoteMethods class for RPC
 + Added AllocateString method to create Delphi AnsiStrings
 * Fixed WriteMemory() for strings
 * Plugin auto-clears it's log on startup
 * Plugin uses OmsiHook lib for RPC
 * Refactoring
 - Removed dead code from plugin
 - Removed old BorlandFastcall from OmsiHookInvoker

* * Updated README
 * Updated docs
 * Updated NuGet package license
 * Exposed more parameters to the public API for PlaceRandomBus()
 * Refactoring

* + Added link to docs in the README
 * Fixed some build issues
 * Fixed some issues with the docs

* Update dotnet.yml

* * Fixed project references

* Update dotnet.yml

Maybe this will fix it?

* Update dotnet.yml

Maybe?...

* Update dotnet.yml

who knows...

* Changed msvc version to 142

* Update dotnet.yml

Magic?

* Update OmsiHook.csproj

nuget pack couldn't find the readme when building in github actions... Screw it, don't build the nuget package then...

* Update dotnet.yml

Well I don't have unit tests anyway, so don't bother running them since dotnet won't compile it...

* + Try to patch the GH actions

Co-authored-by: Adam Mathieson <Adam@genav.ch>
  • Loading branch information
space928 and amathieson authored Apr 30, 2022
1 parent 7d132a0 commit eb37368
Show file tree
Hide file tree
Showing 29 changed files with 1,175 additions and 121 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: DocFX

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Generate docs
uses: nikeee/docfx-action@v1.0.0
with:
args: OmsiHook/docfx.json

# Publish generated site using GitHub Pages
- uses: maxheld83/ghpages@master
name: Publish Documentation on GitHub Pages
env:
BUILD_DIR: OmsiHook/_site # docfx's default output directory is _site
GH_PAT: ${{ secrets.GH_PAT }} # See https://github.com/maxheld83/ghpages
21 changes: 6 additions & 15 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,19 @@ on:
jobs:
build:

runs-on: ubuntu-latest
runs-on: windows-2019

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 5.0.x
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.1
- name: Setup Windows 10 SDK
uses: GuillaumeFalourd/setup-windows10-sdk-action@v1.4
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
- name: Generate docs
uses: nikeee/docfx-action@v1.0.0
with:
args: OmsiHook/docfx.json

# Publish generated site using GitHub Pages
- uses: maxheld83/ghpages@master
name: Publish Documentation on GitHub Pages
env:
BUILD_DIR: OmsiHook/_site # docfx's default output directory is _site
GH_PAT: ${{ secrets.GH_PAT }} # See https://github.com/maxheld83/ghpages
run: msbuild D:\a\Omsi-Extensions\Omsi-Extensions\OmsiExtensions.sln -t:rebuild -property:Configuration=Release
56 changes: 56 additions & 0 deletions OmsiExtensions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,80 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmsiExtensionsUI", "OmsiExt
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmsiExtensionsCLI", "OmsiExtensionsCLI\OmsiExtensionsCLI.csproj", "{FDA9A525-9722-46D3-B80C-8D2A76ABCA2D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OmsiHookPlugin", "OmsiHookPlugin\OmsiHookPlugin.csproj", "{D5CA6EEA-D436-456E-BCA5-34C3DFD5BFC7}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OmsiHookInvoker", "OmsiHookInvoker\OmsiHookInvoker.vcxproj", "{CBCB99EF-DD1A-4D4D-A9A8-9BF251FDCD1B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Debug|x64.ActiveCfg = Debug|Any CPU
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Debug|x64.Build.0 = Debug|Any CPU
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Debug|x86.ActiveCfg = Debug|Any CPU
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Debug|x86.Build.0 = Debug|Any CPU
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Release|Any CPU.Build.0 = Release|Any CPU
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Release|x64.ActiveCfg = Release|Any CPU
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Release|x64.Build.0 = Release|Any CPU
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Release|x86.ActiveCfg = Release|Any CPU
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Release|x86.Build.0 = Release|Any CPU
{28DA0165-EAA7-4171-A065-319409682BD1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28DA0165-EAA7-4171-A065-319409682BD1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28DA0165-EAA7-4171-A065-319409682BD1}.Debug|x64.ActiveCfg = Debug|Any CPU
{28DA0165-EAA7-4171-A065-319409682BD1}.Debug|x64.Build.0 = Debug|Any CPU
{28DA0165-EAA7-4171-A065-319409682BD1}.Debug|x86.ActiveCfg = Debug|Any CPU
{28DA0165-EAA7-4171-A065-319409682BD1}.Debug|x86.Build.0 = Debug|Any CPU
{28DA0165-EAA7-4171-A065-319409682BD1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28DA0165-EAA7-4171-A065-319409682BD1}.Release|Any CPU.Build.0 = Release|Any CPU
{28DA0165-EAA7-4171-A065-319409682BD1}.Release|x64.ActiveCfg = Release|Any CPU
{28DA0165-EAA7-4171-A065-319409682BD1}.Release|x64.Build.0 = Release|Any CPU
{28DA0165-EAA7-4171-A065-319409682BD1}.Release|x86.ActiveCfg = Release|Any CPU
{28DA0165-EAA7-4171-A065-319409682BD1}.Release|x86.Build.0 = Release|Any CPU
{FDA9A525-9722-46D3-B80C-8D2A76ABCA2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FDA9A525-9722-46D3-B80C-8D2A76ABCA2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FDA9A525-9722-46D3-B80C-8D2A76ABCA2D}.Debug|x64.ActiveCfg = Debug|Any CPU
{FDA9A525-9722-46D3-B80C-8D2A76ABCA2D}.Debug|x64.Build.0 = Debug|Any CPU
{FDA9A525-9722-46D3-B80C-8D2A76ABCA2D}.Debug|x86.ActiveCfg = Debug|Any CPU
{FDA9A525-9722-46D3-B80C-8D2A76ABCA2D}.Debug|x86.Build.0 = Debug|Any CPU
{FDA9A525-9722-46D3-B80C-8D2A76ABCA2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FDA9A525-9722-46D3-B80C-8D2A76ABCA2D}.Release|Any CPU.Build.0 = Release|Any CPU
{FDA9A525-9722-46D3-B80C-8D2A76ABCA2D}.Release|x64.ActiveCfg = Release|Any CPU
{FDA9A525-9722-46D3-B80C-8D2A76ABCA2D}.Release|x64.Build.0 = Release|Any CPU
{FDA9A525-9722-46D3-B80C-8D2A76ABCA2D}.Release|x86.ActiveCfg = Release|Any CPU
{FDA9A525-9722-46D3-B80C-8D2A76ABCA2D}.Release|x86.Build.0 = Release|Any CPU
{D5CA6EEA-D436-456E-BCA5-34C3DFD5BFC7}.Debug|Any CPU.ActiveCfg = Debug|x86
{D5CA6EEA-D436-456E-BCA5-34C3DFD5BFC7}.Debug|Any CPU.Build.0 = Debug|x86
{D5CA6EEA-D436-456E-BCA5-34C3DFD5BFC7}.Debug|x64.ActiveCfg = Debug|Any CPU
{D5CA6EEA-D436-456E-BCA5-34C3DFD5BFC7}.Debug|x64.Build.0 = Debug|Any CPU
{D5CA6EEA-D436-456E-BCA5-34C3DFD5BFC7}.Debug|x86.ActiveCfg = Debug|x86
{D5CA6EEA-D436-456E-BCA5-34C3DFD5BFC7}.Debug|x86.Build.0 = Debug|x86
{D5CA6EEA-D436-456E-BCA5-34C3DFD5BFC7}.Release|Any CPU.ActiveCfg = Release|x86
{D5CA6EEA-D436-456E-BCA5-34C3DFD5BFC7}.Release|Any CPU.Build.0 = Release|x86
{D5CA6EEA-D436-456E-BCA5-34C3DFD5BFC7}.Release|x64.ActiveCfg = Release|Any CPU
{D5CA6EEA-D436-456E-BCA5-34C3DFD5BFC7}.Release|x64.Build.0 = Release|Any CPU
{D5CA6EEA-D436-456E-BCA5-34C3DFD5BFC7}.Release|x86.ActiveCfg = Release|x86
{D5CA6EEA-D436-456E-BCA5-34C3DFD5BFC7}.Release|x86.Build.0 = Release|x86
{CBCB99EF-DD1A-4D4D-A9A8-9BF251FDCD1B}.Debug|Any CPU.ActiveCfg = Debug|Win32
{CBCB99EF-DD1A-4D4D-A9A8-9BF251FDCD1B}.Debug|Any CPU.Build.0 = Debug|Win32
{CBCB99EF-DD1A-4D4D-A9A8-9BF251FDCD1B}.Debug|x64.ActiveCfg = Debug|x64
{CBCB99EF-DD1A-4D4D-A9A8-9BF251FDCD1B}.Debug|x64.Build.0 = Debug|x64
{CBCB99EF-DD1A-4D4D-A9A8-9BF251FDCD1B}.Debug|x86.ActiveCfg = Debug|Win32
{CBCB99EF-DD1A-4D4D-A9A8-9BF251FDCD1B}.Debug|x86.Build.0 = Debug|Win32
{CBCB99EF-DD1A-4D4D-A9A8-9BF251FDCD1B}.Release|Any CPU.ActiveCfg = Release|Win32
{CBCB99EF-DD1A-4D4D-A9A8-9BF251FDCD1B}.Release|Any CPU.Build.0 = Release|Win32
{CBCB99EF-DD1A-4D4D-A9A8-9BF251FDCD1B}.Release|x64.ActiveCfg = Release|x64
{CBCB99EF-DD1A-4D4D-A9A8-9BF251FDCD1B}.Release|x64.Build.0 = Release|x64
{CBCB99EF-DD1A-4D4D-A9A8-9BF251FDCD1B}.Release|x86.ActiveCfg = Release|Win32
{CBCB99EF-DD1A-4D4D-A9A8-9BF251FDCD1B}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion OmsiExtensionsCLI/OmsiExtensionsCLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion OmsiExtensionsCLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static void Main(string[] args)

Console.WriteLine($"Read data: x:{pos.x:F3}\ty:{pos.y:F3}\tz:{pos.z:F3}\t\t" +
$"tile:{0}\trow45:{0:F3}\trow47:{0:F3}");

Console.WriteLine($"Read data: map:{map.Name}\tpath:{map.Filename}\tfriendly:{map.FriendlyName}");
Console.WriteLine($"Read data: act w name:{weather.ActWeather.name}");

Expand Down
2 changes: 1 addition & 1 deletion OmsiExtensionsUI/OmsiExtensionsUI.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
Expand Down
71 changes: 71 additions & 0 deletions OmsiHook/MemArray.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OmsiHook
{
public class MemArray<T> : OmsiObject, IEnumerable<T>, ICollection<T>, IList<T> where T : struct
{
private T[] arrayCache;

public MemArray() : base() { }

internal MemArray(Memory memory, int address) : base(memory, address) { }

/// <summary>
/// Call this method to initialise an OmsiObject if the two-parameter constructor wasn't used.
/// </summary>
/// <param name="memory"></param>
/// <param name="address"></param>
internal new void InitObject(Memory memory, int address)
{
base.InitObject(memory, address);
UpdateFromHook();
}

/// <summary>
/// Forces the cached contents of the MemArray to resynchronise with the hooked application.
/// </summary>
public void UpdateFromHook()
{
arrayCache = Memory.ReadMemoryStructArray<T>(Address);
}

public int Count => arrayCache.Length;

public bool IsReadOnly => true;

public T this[int index]
{
get => arrayCache[index];
set
{
arrayCache[index] = value;
Memory.WriteMemoryArrayItem(Address, value, index);
}
}

public void Add(T item) => throw new NotImplementedException();

public void Clear() => throw new NotImplementedException();

public bool Contains(T item) => arrayCache.Contains(item);

public void CopyTo(T[] array, int arrayIndex) => arrayCache.CopyTo(array, arrayIndex);

public IEnumerator<T> GetEnumerator() => (IEnumerator<T>)arrayCache.GetEnumerator();

public bool Remove(T item) => throw new NotImplementedException();

IEnumerator IEnumerable.GetEnumerator() => arrayCache.GetEnumerator();

public int IndexOf(T item) => Array.IndexOf(arrayCache, item);

public void Insert(int index, T item) => throw new NotImplementedException();

public void RemoveAt(int index) => throw new NotImplementedException();
}
}
Loading

0 comments on commit eb37368

Please sign in to comment.