forked from iMarbot/Skylines-Traffic-Manager-Plus
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae7be3f
commit cdb0fbe
Showing
101 changed files
with
1,378 additions
and
508 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProductVersion>8.0.30703</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{7DCC08EF-DC85-47A4-BD6F-79FC52C7EF13}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>CSUtil.Redirection</RootNamespace> | ||
<AssemblyName>CSUtil.Redirection</AssemblyName> | ||
<TargetFrameworkVersion>v3.5</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> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</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> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="RedirectionHelper.cs" /> | ||
<Compile Include="Redirector.cs" /> | ||
<Compile Include="MethodInfoExt.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\CSUtil.Commons\CSUtil.Commons.csproj"> | ||
<Project>{D3ADE06E-F493-4819-865A-3BB44FEEDF01}</Project> | ||
<Name>CSUtil.Commons</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Reflection; | ||
|
||
namespace CSUtil.Redirection { | ||
public static class MethodInfoExt | ||
{ | ||
internal static Redirector.MethodRedirection RedirectTo(this MethodInfo originalMethod, MethodInfo newMethod, Assembly redirectionSource) | ||
{ | ||
return new Redirector.MethodRedirection(originalMethod, newMethod, redirectionSource); | ||
} | ||
|
||
public static bool IsCompatibleWith(this MethodInfo thisMethod, MethodInfo otherMethod) | ||
{ | ||
if (thisMethod.ReturnType != otherMethod.ReturnType) | ||
return false; | ||
|
||
ParameterInfo[] thisParameters = thisMethod.GetParameters(); | ||
ParameterInfo[] otherParameters = otherMethod.GetParameters(); | ||
|
||
if (thisParameters.Length != otherParameters.Length) | ||
return false; | ||
|
||
for (int i = 0; i < thisParameters.Length; i++) | ||
{ | ||
if (!otherParameters[i].ParameterType.IsAssignableFrom(thisParameters[i].ParameterType)) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
TLM/CSUtil.Redirection/NetworkExtensions.Framework.Unsafe.csproj.DotSettings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=_005FExtensions/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("Transit.Framework.Redirection")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("Transit.Framework.Redirection")] | ||
[assembly: AssemblyCopyright("Copyright © 2015")] | ||
[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("4250c75b-3c80-494f-a5c9-7e49c18ef1bc")] | ||
|
||
// 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")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
The MIT License (MIT) | ||
Copyright (c) 2015 Sebastian Schöner | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
using System; | ||
using System.Reflection; | ||
|
||
namespace CSUtil.Redirection { | ||
|
||
public struct RedirectCallsState | ||
{ | ||
public byte a, b, c, d, e; | ||
public ulong f; | ||
} | ||
|
||
/// <summary> | ||
/// Helper class to deal with detours. This version is for Unity 5 x64 on Windows. | ||
/// We provide three different methods of detouring. | ||
/// </summary> | ||
public static class RedirectionHelper | ||
{ | ||
/// <summary> | ||
/// Redirects all calls from method 'from' to method 'to'. | ||
/// </summary> | ||
/// <param name="from"></param> | ||
/// <param name="to"></param> | ||
public static RedirectCallsState RedirectCalls(MethodInfo from, MethodInfo to) | ||
{ | ||
// GetFunctionPointer enforces compilation of the method. | ||
var fptr1 = from.MethodHandle.GetFunctionPointer(); | ||
var fptr2 = to.MethodHandle.GetFunctionPointer(); | ||
return PatchJumpTo(fptr1, fptr2); | ||
} | ||
|
||
public static RedirectCallsState RedirectCalls(RuntimeMethodHandle from, RuntimeMethodHandle to) | ||
{ | ||
// GetFunctionPointer enforces compilation of the method. | ||
var fptr1 = from.GetFunctionPointer(); | ||
var fptr2 = to.GetFunctionPointer(); | ||
return PatchJumpTo(fptr1, fptr2); | ||
} | ||
|
||
public static void RevertRedirect(MethodInfo from, RedirectCallsState state) | ||
{ | ||
try | ||
{ | ||
var fptr1 = from.MethodHandle.GetFunctionPointer(); | ||
RevertJumpTo(fptr1, state); | ||
} | ||
catch | ||
{ | ||
// ignored | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Primitive patching. Inserts a jump to 'target' at 'site'. Works even if both methods' | ||
/// callers have already been compiled. | ||
/// </summary> | ||
/// <param name="site"></param> | ||
/// <param name="target"></param> | ||
public static RedirectCallsState PatchJumpTo(IntPtr site, IntPtr target) | ||
{ | ||
RedirectCallsState state = new RedirectCallsState(); | ||
|
||
// R11 is volatile. | ||
unsafe | ||
{ | ||
byte* sitePtr = (byte*)site.ToPointer(); | ||
state.a = *sitePtr; | ||
state.b = *(sitePtr + 1); | ||
state.c = *(sitePtr + 10); | ||
state.d = *(sitePtr + 11); | ||
state.e = *(sitePtr + 12); | ||
state.f = *((ulong*)(sitePtr + 2)); | ||
|
||
*sitePtr = 0x49; // mov r11, target | ||
*(sitePtr + 1) = 0xBB; | ||
*((ulong*)(sitePtr + 2)) = (ulong)target.ToInt64(); | ||
*(sitePtr + 10) = 0x41; // jmp r11 | ||
*(sitePtr + 11) = 0xFF; | ||
*(sitePtr + 12) = 0xE3; | ||
} | ||
|
||
return state; | ||
} | ||
|
||
public static void RevertJumpTo(IntPtr site, RedirectCallsState state) | ||
{ | ||
unsafe | ||
{ | ||
byte* sitePtr = (byte*)site.ToPointer(); | ||
*sitePtr = state.a; // mov r11, target | ||
*(sitePtr + 1) = state.b; | ||
*((ulong*)(sitePtr + 2)) = state.f; | ||
*(sitePtr + 10) = state.c; // jmp r11 | ||
*(sitePtr + 11) = state.d; | ||
*(sitePtr + 12) = state.e; | ||
} | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.