-
Notifications
You must be signed in to change notification settings - Fork 5
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
Showing
17 changed files
with
188 additions
and
53 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
Binary file not shown.
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<Defs> | ||
<ReclaimFabric.Bootstrap> | ||
<defName>ReclaimFabric</defName> | ||
</ReclaimFabric.Bootstrap> | ||
</Defs> |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
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,29 @@ | ||
using System; | ||
using System.Reflection; | ||
using Verse; | ||
using RimWorld; | ||
|
||
namespace ReclaimFabric | ||
{ | ||
class Bootstrap : Def | ||
{ | ||
private const BindingFlags UniversalBindingFlags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; | ||
|
||
static Bootstrap() | ||
{ | ||
{ | ||
MethodInfo method3 = typeof(Thing).GetMethod("SmeltProducts", BindingFlags.Instance | BindingFlags.Public); | ||
MethodInfo method4 = typeof(_Thing_ReclaimFabric).GetMethod("_SmeltProducts", BindingFlags.Static | BindingFlags.NonPublic); | ||
Log.Message("Attempting detour from " + method3 + "to " + method4); | ||
if (!Detours.TryDetourFromTo(method3, method4)) | ||
{ | ||
Log.Error("Reclaim Fabric Detour failed"); | ||
return; | ||
} | ||
Log.Message("Reclaim Fabric Detour Successful"); | ||
} | ||
|
||
Assembly Assembly_CSharp = Assembly.Load("Assembly-CSharp.dll"); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,118 @@ | ||
/* | ||
This is free and unencumbered software released into the public domain. | ||
Anyone is free to copy, modify, publish, use, compile, sell, or | ||
distribute this software, either in source code form or as a compiled | ||
binary, for any purpose, commercial or non-commercial, and by any | ||
means. | ||
In jurisdictions that recognize copyright laws, the author or authors | ||
of this software dedicate any and all copyright interest in the | ||
software to the public domain.We make this dedication for the benefit | ||
of the public at large and to the detriment of our heirs and | ||
successors.We intend this dedication to be an overt act of | ||
relinquishment in perpetuity of all present and future rights to this | ||
software under copyright law. | ||
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 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. | ||
For more information, please refer to<http://unlicense.org/> | ||
*/ | ||
|
||
using UnityEngine; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
|
||
namespace ReclaimFabric | ||
{ | ||
public static class Detours | ||
{ | ||
|
||
private static List<string> detoured = new List<string>(); | ||
private static List<string> destinations = new List<string>(); | ||
|
||
/** | ||
This is a basic first implementation of the IL method 'hooks' (detours) made possible by RawCode's work; | ||
https://ludeon.com/forums/index.php?topic=17143.0 | ||
Performs detours, spits out basic logs and warns if a method is detoured multiple times. | ||
**/ | ||
public static unsafe bool TryDetourFromTo(MethodInfo source, MethodInfo destination) | ||
{ | ||
// error out on null arguments | ||
if (source == null) | ||
{ | ||
Debug.LogError("Detours - Source MethodInfo is null"); | ||
return false; | ||
} | ||
|
||
if (destination == null) | ||
{ | ||
Debug.LogError("Detours - Destination MethodInfo is null"); | ||
return false; | ||
} | ||
|
||
// keep track of detours and spit out some messaging | ||
string sourceString = source.DeclaringType.FullName + "." + source.Name + " @ 0x" + source.MethodHandle.GetFunctionPointer().ToString("X" + (IntPtr.Size * 2).ToString()); | ||
string destinationString = destination.DeclaringType.FullName + "." + destination.Name + " @ 0x" + destination.MethodHandle.GetFunctionPointer().ToString("X" + (IntPtr.Size * 2).ToString()); | ||
|
||
detoured.Add(sourceString); | ||
destinations.Add(destinationString); | ||
|
||
if (IntPtr.Size == sizeof(Int64)) | ||
{ | ||
// 64-bit systems use 64-bit absolute address and jumps | ||
// 12 byte destructive | ||
|
||
// Get function pointers | ||
long Source_Base = source.MethodHandle.GetFunctionPointer().ToInt64(); | ||
long Destination_Base = destination.MethodHandle.GetFunctionPointer().ToInt64(); | ||
|
||
// Native source address | ||
byte* Pointer_Raw_Source = (byte*)Source_Base; | ||
|
||
// Pointer to insert jump address into native code | ||
long* Pointer_Raw_Address = (long*)(Pointer_Raw_Source + 0x02); | ||
|
||
// Insert 64-bit absolute jump into native code (address in rax) | ||
// mov rax, immediate64 | ||
// jmp [rax] | ||
*(Pointer_Raw_Source + 0x00) = 0x48; | ||
*(Pointer_Raw_Source + 0x01) = 0xB8; | ||
*Pointer_Raw_Address = Destination_Base; // ( Pointer_Raw_Source + 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 ) | ||
*(Pointer_Raw_Source + 0x0A) = 0xFF; | ||
*(Pointer_Raw_Source + 0x0B) = 0xE0; | ||
|
||
} | ||
else | ||
{ | ||
// 32-bit systems use 32-bit relative offset and jump | ||
// 5 byte destructive | ||
|
||
// Get function pointers | ||
int Source_Base = source.MethodHandle.GetFunctionPointer().ToInt32(); | ||
int Destination_Base = destination.MethodHandle.GetFunctionPointer().ToInt32(); | ||
|
||
// Native source address | ||
byte* Pointer_Raw_Source = (byte*)Source_Base; | ||
|
||
// Pointer to insert jump address into native code | ||
int* Pointer_Raw_Address = (int*)(Pointer_Raw_Source + 1); | ||
|
||
// Jump offset (less instruction size) | ||
int offset = (Destination_Base - Source_Base) - 5; | ||
|
||
// Insert 32-bit relative jump into native code | ||
*Pointer_Raw_Source = 0xE9; | ||
*Pointer_Raw_Address = offset; | ||
} | ||
|
||
// done! | ||
return true; | ||
} | ||
|
||
} | ||
|
||
} |
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
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
-165 Bytes
(98%)
Source/ReclaimFabric/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
Binary file not shown.
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
Binary file modified
BIN
+32.3 KB
(140%)
Source/ReclaimFabric/obj/Debug/ReclaimFabric.csprojResolveAssemblyReference.cache
Binary file not shown.
Binary file not shown.
Binary file not shown.