Skip to content

Commit

Permalink
Fixed some minor issues raised by Adam & Improved builld system:
Browse files Browse the repository at this point in the history
 - Relaxed target framework requirement
 - Fixed spelling
 - Added version number to docs (can't manage to get the automatic version number trtacking to work though...)
 - Updated copyright and version number
 - Restricted OmsiHook to x86
 - Added dependency on OmsiHookRPCPlugin to OmsiHook
 - Refactored OmsiHookRPCMethods.cs
 - Other small build system changes
  • Loading branch information
space928 committed Oct 25, 2023
1 parent 453b41e commit 55bcfad
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 45 deletions.
23 changes: 11 additions & 12 deletions OmsiExtensions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@ Global
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
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Debug|Any CPU.ActiveCfg = Debug|x86
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Debug|Any CPU.Build.0 = Debug|x86
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Debug|x64.ActiveCfg = Debug|x86
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Debug|x64.Build.0 = Debug|x86
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Debug|x86.ActiveCfg = Debug|x86
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Debug|x86.Build.0 = Debug|x86
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Release|Any CPU.ActiveCfg = Release|x86
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Release|Any CPU.Build.0 = Release|x86
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Release|x64.ActiveCfg = Release|x86
{2E750CBE-F868-4AB7-96C2-27560F53E06B}.Release|x86.ActiveCfg = Release|x86
{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
Expand Down Expand Up @@ -90,6 +88,7 @@ Global
{CDB17143-5653-48BE-AAC8-8419D5B4FD2C}.Debug|x86.ActiveCfg = Debug|x86
{CDB17143-5653-48BE-AAC8-8419D5B4FD2C}.Debug|x86.Build.0 = Debug|x86
{CDB17143-5653-48BE-AAC8-8419D5B4FD2C}.Release|Any CPU.ActiveCfg = Release|x86
{CDB17143-5653-48BE-AAC8-8419D5B4FD2C}.Release|Any CPU.Build.0 = Release|x86
{CDB17143-5653-48BE-AAC8-8419D5B4FD2C}.Release|x64.ActiveCfg = Release|x86
{CDB17143-5653-48BE-AAC8-8419D5B4FD2C}.Release|x86.ActiveCfg = Release|x86
{CDB17143-5653-48BE-AAC8-8419D5B4FD2C}.Release|x86.Build.0 = Release|x86
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>net6.0-windows10.0.17763.0</TargetFramework>
<TargetFramework>net6.0-windows</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
35 changes: 28 additions & 7 deletions OmsiHook/OmsiHook.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Authors>Thomas Mathieson et al</Authors>
<Copyright>Copyright Thomas Mathieson 2022 all rights reserved</Copyright>
<Copyright>Copyright Thomas Mathieson 2023 all rights reserved</Copyright>
<PackageProjectUrl>https://github.com/space928/Omsi-Extensions</PackageProjectUrl>
<RepositoryUrl>https://github.com/space928/Omsi-Extensions</RepositoryUrl>
<PackageLicenseFile></PackageLicenseFile>
<Description>OmsiHook is a simple library for hooking into Omsi's memory for modding.</Description>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<AssemblyVersion>2.1.0.1</AssemblyVersion>
<FileVersion>2.1.0.1</FileVersion>
<Version>2.1.0</Version>
<AssemblyVersion>2.2.0.1</AssemblyVersion>
<FileVersion>2.2.0.1</FileVersion>
<Version>2.2.0</Version>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<SignAssembly>False</SignAssembly>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>Logo.png</PackageIcon>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Nullable>disable</Nullable>
<Platforms>x86</Platforms>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'" />

<ItemGroup>
<None Include="..\.editorconfig" Link=".editorconfig" />
Expand All @@ -34,14 +35,33 @@
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Include="..\Release\OmsiHookInvoker.dll" Link="OmsiHookInvoker.dll">
<None Include="..\$(Configuration)\OmsiHookInvoker.dll" Link="OmsiHookInvoker.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>True</Pack>
<PackagePath>\lib\net5.0</PackagePath>
<PackagePath>\lib\net6.0</PackagePath>
</None>
<None Include="..\OmsiHookRPCPlugin\bin\x86\$(Configuration)\$(TargetFramework)\OmsiHookRPCPlugin.dll" Link="OmsiHookRPCPlugin.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>True</Pack>
<PackagePath>\lib\net6.0</PackagePath>
</None>
<None Include="..\OmsiHookRPCPlugin\bin\x86\$(Configuration)\$(TargetFramework)\OmsiHookRPCPluginNE.dll" Link="OmsiHookRPCPluginNE.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>True</Pack>
<PackagePath>\lib\net6.0</PackagePath>
</None>
<None Include="..\OmsiHookRPCPlugin\bin\x86\$(Configuration)\$(TargetFramework)\OmsiHookRPCPlugin.opl" Link="OmsiHookRPCPlugin.opl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>True</Pack>
<PackagePath>\lib\net6.0</PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<!-- <PackageReference Include="DhyMik.DocFx.UpdateDocFxVersionAttributeTask" Version="1.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>-->
<PackageReference Include="docfx.console" Condition="'$(Configuration)'!='Debug'" Version="2.59.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -53,6 +73,7 @@
<ProjectReference Include="..\OmsiHookInvoker\OmsiHookInvoker.vcxproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\OmsiHookRPCPlugin\OmsiHookRPCPlugin.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
13 changes: 11 additions & 2 deletions OmsiHook/OmsiHookRPCMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,27 @@

namespace OmsiHookRPCPlugin
{
public static class OmsiHookRPCMethods
internal static class OmsiHookRPCMethods
{
public const string PIPE_NAME = @"OmsiHookRPCPipe";

[SuppressMessage("ReSharper", "InconsistentNaming")]
public enum RemoteMethod : int
internal enum RemoteMethod : int
{
TProgManMakeVehicle,
TTempRVListCreate,
TProgManPlaceRandomBus,
GetMem,
FreeMem
}

internal static readonly ReadOnlyDictionary<RemoteMethod, int> RemoteMethodsArgsSizes = new(new Dictionary<RemoteMethod, int>()
{
{ RemoteMethod.TProgManMakeVehicle, 61 },
{ RemoteMethod.TTempRVListCreate, 8 },
{ RemoteMethod.TProgManPlaceRandomBus, 35 },
{ RemoteMethod.GetMem, 4 },
{ RemoteMethod.FreeMem, 4 },
});
}
}
15 changes: 9 additions & 6 deletions OmsiHook/OmsiRemoteMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ public static int PlaceRandomBus(int aiType = 0, int group = 1, int type = -1, b
return TProgManPlaceRandomBus(memory.ReadMemory<int>(0x00862f28), aiType, group, 0, false, true, type, scheduled, 0, tour, line);
#else
int argPos = 0;
Span<byte> writeBuffer = stackalloc byte[39];
var method = OmsiHookRPCMethods.RemoteMethod.TProgManPlaceRandomBus;
Span<byte> writeBuffer = stackalloc byte[OmsiHookRPCMethods.RemoteMethodsArgsSizes[method]+4];
Span<byte> readBuffer = stackalloc byte[4];
BitConverter.TryWriteBytes(writeBuffer[(argPos)..], (int)OmsiHookRPCMethods.RemoteMethod.TProgManPlaceRandomBus);
BitConverter.TryWriteBytes(writeBuffer[(argPos)..], (int)method);
BitConverter.TryWriteBytes(writeBuffer[(argPos += 4)..], aiType);
BitConverter.TryWriteBytes(writeBuffer[(argPos += 4)..], group);
BitConverter.TryWriteBytes(writeBuffer[(argPos += 4)..], 0);
Expand Down Expand Up @@ -104,9 +105,10 @@ public static int OmsiGetMem(int length)
return GetMem(length);
#else
int argPos = 0;
Span<byte> writeBuffer = stackalloc byte[8];
var method = OmsiHookRPCMethods.RemoteMethod.GetMem;
Span<byte> writeBuffer = stackalloc byte[OmsiHookRPCMethods.RemoteMethodsArgsSizes[method]+4];
Span<byte> readBuffer = stackalloc byte[4];
BitConverter.TryWriteBytes(writeBuffer[(argPos)..], (int)OmsiHookRPCMethods.RemoteMethod.GetMem);
BitConverter.TryWriteBytes(writeBuffer[(argPos)..], (int)method);
BitConverter.TryWriteBytes(writeBuffer[(argPos += 4)..], length);
pipe.Write(writeBuffer);
pipe.Read(readBuffer);
Expand All @@ -125,9 +127,10 @@ public static void OmsiFreeMem(int addr)
FreeMem(addr);
#else
int argPos = 0;
Span<byte> writeBuffer = stackalloc byte[8];
var method = OmsiHookRPCMethods.RemoteMethod.FreeMem;
Span<byte> writeBuffer = stackalloc byte[OmsiHookRPCMethods.RemoteMethodsArgsSizes[method] + 4];
Span<byte> readBuffer = stackalloc byte[4];
BitConverter.TryWriteBytes(writeBuffer[(argPos)..], (int)OmsiHookRPCMethods.RemoteMethod.FreeMem);
BitConverter.TryWriteBytes(writeBuffer[(argPos)..], (int)method);
BitConverter.TryWriteBytes(writeBuffer[(argPos += 4)..], addr);
pipe.Write(writeBuffer);
pipe.Read(readBuffer);
Expand Down
2 changes: 1 addition & 1 deletion OmsiHook/articles/performance-tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ cached or not.
OmsiHook allows you to call remote methods in Omsi, this is a fairly complicated process and as such
isn't always very fast. For native Omsi plugins using OmsiHook you don't need to worry much about the
performance of remote calls, but for external applications using OmsiHook, these calls are especially
expensive. This is because in this case OmsiHook needs to relty on OmsiHookRPCPlugin, a native Omsi
expensive. This is because in this case OmsiHook needs to rely on OmsiHookRPCPlugin, a native Omsi
plugin shipped with OmsiHook which executes remote calls on the behalf of OmsiHook in batches, once
per frame. As such, for external applications, remote calls will *always* take at least 1 frame to
complete.
Expand Down
9 changes: 6 additions & 3 deletions OmsiHook/docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
],
"dest": "api",
"disableGitFeatures": true,
"disableDefaultFilter": false
"disableDefaultFilter": false,
"memberLayout": "samePage",
"enumSortOrder": "declaringOrder"
}
],
"build": {
Expand All @@ -21,12 +23,13 @@
"_appFaviconPath": "images/favicon.ico",
"_appLogoPath": "images/logo.svg",
"_appFooter": "<strong>DocFX + OmsiHook = ♥</strong>",
"_copyrightFooter": "© Thomas/Adam Mathieson. All rights reserved.",
"_copyrightFooter": "© Thomas/Adam Mathieson 2023. All rights reserved.",
"_enableSearch": true,
"_disableSideFilter": false,
"_enableNewTab": true,
"_disableContribution": true,
"_disableBreadcrumb": false
"_disableBreadcrumb": false,
"_DocumentationVersion": "2.2.0"
},
"content": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

{{#_enableSearch}}
<div class="sidesearch">
<a class="version versionHeader" href="">Version {{{_DocumentationVersion}}}</a>
<form id="search" role="search" class="search">
<i class="bi bi-search search-icon"></i>
<input type="text" id="search-query" placeholder="{{__global.search}}" autocomplete="off">
Expand Down
5 changes: 5 additions & 0 deletions OmsiHook/templates/singulinkfx/styles/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.version .versionHeader {
display: inline-block;
line-height: 20px;
padding: 15px 30px 15px 30px;
}
9 changes: 0 additions & 9 deletions OmsiHookRPCPlugin/OmsiHookRPCPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ public MethodData(RemoteMethod method, byte[] args, int threadId)
}
}

private static readonly ReadOnlyDictionary<RemoteMethod, int> RemoteMethodsArgsSizes = new(new Dictionary<RemoteMethod, int>()
{
{ RemoteMethod.TProgManMakeVehicle, 61 },
{ RemoteMethod.TTempRVListCreate, 8 },
{ RemoteMethod.TProgManPlaceRandomBus, 35 },
{ RemoteMethod.GetMem, 4 },
{ RemoteMethod.FreeMem, 4 },
});

private static void Log(object msg)
{
lock (logLock)
Expand Down
18 changes: 14 additions & 4 deletions OmsiHookRPCPlugin/OmsiHookRPCPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>
<PropertyGroup>
<Authors>Thomas Mathieson</Authors>
<Version>1.1.0</Version>
<Version>1.2.0</Version>
<Copyright>Thomas Mathieson</Copyright>
</PropertyGroup>
<PropertyGroup>
Expand All @@ -15,10 +15,16 @@
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DNNE" Version="1.0.30" />
<Compile Include="..\OmsiHook\OmsiHookRPCMethods.cs" Link="OmsiHookRPCMethods.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OmsiHook\OmsiHook.csproj" />
<None Include="..\Logo.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="DNNE" Version="1.0.30" />
</ItemGroup>
<ItemGroup>
<None Update="OmsiHookRPCPlugin.opl">
Expand Down Expand Up @@ -95,8 +101,12 @@
valid self-contained install environment. -->
<DnneSelfContained_Experimental>false</DnneSelfContained_Experimental>
<BaseOutputPath></BaseOutputPath>
<Title>OmsiHook RPC Plugin</Title>
<PackageIcon>Logo.png</PackageIcon>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<SignAssembly>False</SignAssembly>
</PropertyGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy &quot;$(SolutionDir)Debug\*.dll&quot; &quot;$(OutDir)&quot; /y&#xD;&#xA;xcopy &quot;$(SolutionDir)Release\*.dll&quot; &quot;$(OutDir)&quot; /y&#xD;&#xA;xcopy &quot;$(OutDir)*.dll&quot; &quot;D:\Program Files\OMSI 2\plugins\&quot; /y&#xD;&#xA;xcopy &quot;$(OutDir)*.opl&quot; &quot;D:\Program Files\OMSI 2\plugins\&quot; /y&#xD;&#xA;xcopy &quot;$(OutDir)*.runtimeconfig.json&quot; &quot;D:\Program Files\OMSI 2\plugins\&quot; /y" />
<Exec Command="xcopy &quot;$(SolutionDir)$(Configuration)\*.dll&quot; &quot;$(OutDir)&quot; /y&#xD;&#xA;xcopy &quot;$(OutDir)*.dll&quot; &quot;D:\Program Files\OMSI 2\plugins\&quot; /y /c&#xD;&#xA;xcopy &quot;$(OutDir)*.opl&quot; &quot;D:\Program Files\OMSI 2\plugins\&quot; /y /c &#xD;&#xA;xcopy &quot;$(OutDir)*.runtimeconfig.json&quot; &quot;D:\Program Files\OMSI 2\plugins\&quot; /y /c" />
</Target>
</Project>

0 comments on commit 55bcfad

Please sign in to comment.