Skip to content

Commit e194a46

Browse files
committed
UUH 2.1.0.0
Recoded quite a bit, and added arguments.
1 parent e0bbf20 commit e194a46

26 files changed

Lines changed: 518 additions & 546 deletions
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
62

7-
namespace HookAttribute
3+
namespace UniversalUnityHooks
84
{
9-
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
5+
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
106
public sealed class AddMethodAttribute : Attribute
117
{
12-
string FullName { get; set; }
13-
string MethodName { get; set; }
14-
public AddMethodAttribute(string fullName, string methodName)
8+
private string FullName { get; }
9+
10+
private string MethodName { get; }
11+
12+
public AddMethodAttribute(string fullName, string methodName)
1513
{
1614
FullName = fullName;
1715
MethodName = methodName;
1816
}
19-
public string GetName() => FullName;
20-
public string GetMethodName() => MethodName;
2117
}
2218
}

HookAttribute/HookAttribute.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
62

7-
namespace HookAttribute
3+
namespace UniversalUnityHooks
84
{
95
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
106
public sealed class HookAttribute : Attribute
117
{
12-
bool AddToEnd { get; set; }
13-
string FullName { get; set; }
8+
private bool AddToEnd { get; }
9+
10+
private string FullName { get; }
11+
1412
public HookAttribute(string fullName, bool addToEnd = false)
1513
{
1614
FullName = fullName;
1715
AddToEnd = addToEnd;
1816
}
19-
public string GetName() => FullName;
20-
public bool PlaceAtEnd() => AddToEnd;
2117
}
2218
}
Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,16 @@
11
using System.Reflection;
2-
using System.Runtime.CompilerServices;
32
using System.Runtime.InteropServices;
43

5-
// General Information about an assembly is controlled through the following
6-
// set of attributes. Change these attribute values to modify the information
7-
// associated with an assembly.
84
[assembly: AssemblyTitle("HookAttribute")]
9-
[assembly: AssemblyDescription("")]
5+
[assembly: AssemblyDescription("This dll is required for your attributes. reference and add 'using UniversalUnityHooks;'.")]
106
[assembly: AssemblyConfiguration("")]
117
[assembly: AssemblyCompany("")]
12-
[assembly: AssemblyProduct("HookAttribute")]
13-
[assembly: AssemblyCopyright("Copyright © 2018")]
8+
[assembly: AssemblyProduct("UniversalUnityHooks")]
9+
[assembly: AssemblyCopyright("Copyright © UserR00T 2019")]
1410
[assembly: AssemblyTrademark("")]
1511
[assembly: AssemblyCulture("")]
16-
17-
// Setting ComVisible to false makes the types in this assembly not visible
18-
// to COM components. If you need to access a type in this assembly from
19-
// COM, set the ComVisible attribute to true on that type.
2012
[assembly: ComVisible(false)]
21-
22-
// The following GUID is for the ID of the typelib if this project is exposed to COM
2313
[assembly: Guid("1c514f24-0478-4e3f-a5ea-e52e0314b9b0")]
14+
[assembly: AssemblyVersion("0.0.0.0")]
15+
[assembly: AssemblyFileVersion("0.0.0.0")]
2416

25-
// Version information for an assembly consists of the following four values:
26-
//
27-
// Major Version
28-
// Minor Version
29-
// Build Number
30-
// Revision
31-
//
32-
// You can specify all the values or you can default the Build and Revision Numbers
33-
// by using the '*' as shown below:
34-
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("1.0.0.0")]

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ It'd compile it like this:
6666
}
6767
```
6868

69+
## Arguments
70+
The following arguments are allowed:
71+
``UniversalUnityHooks.exe --help``
72+
```
73+
-t, --target Set the target assembly file to be injected.
74+
75+
-i, --input Set the input assemblies to be injected.
76+
77+
-o, --output Set the output directory for assemblies to be copied to. NOTE: This will also be the search
78+
directory. Recommended to keep default.
79+
80+
-w, --wait Waits for input before continuing.
81+
82+
--help Display this help screen.
83+
84+
--version Display version information.
85+
```
86+
6987
## License
7088

7189
This code is licenced under the MIT Licence, [Information can be found here.](https://github.com/UserR00T/UniversalUnityHooks/blob/master/LICENSE)
@@ -79,4 +97,11 @@ Unfortunately there are some limitations;
7997

8098
Ardivaba: https://github.com/Ardivaba
8199

82-
DeathByKorea: https://github.com/DeathByKorea
100+
DeathByKorea: https://github.com/DeathByKorea
101+
102+
### Dependencies:
103+
[commandline](https://github.com/commandlineparser/commandline)
104+
105+
[NetChalker](https://github.com/UserR00T/NetChalker)
106+
107+
[Fody.Costura](https://github.com/Fody/Costura)

TestProject/Core.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
1-
using HookAttribute;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading;
7-
using System.Threading.Tasks;
1+
using System;
2+
using UniversalUnityHooks;
83

94
namespace TestProject
105
{
11-
public class Core
12-
{
13-
[HookAttribute.Hook("Injected.Method3")]
14-
public static bool InjectedMethod_M(Injected instance)
15-
{
6+
#pragma warning disable RCS1163, IDE0060, RCS1102
7+
public class Core
8+
{
9+
[Hook("Injected.Method3")]
10+
public static bool InjectedMethod_M(Injected instance)
11+
{
1612
return true;
1713
}
18-
[HookAttribute.Hook("Injected.Method2")]
14+
15+
[Hook("Injected.Method2")]
1916
public static void InjectedMethod2_M(Injected instance)
2017
{
2118
Console.WriteLine("InjectedMethod2_M called");
2219
}
2320

24-
2521
[AddMethod(nameof(Injected), "TestMethod")]
26-
public static void OnTestMethod(Injected instance)
27-
{
22+
public static void OnTestMethod(Injected instance)
23+
{
2824
Console.WriteLine("OnTestMethod Called");
2925
}
26+
3027
[AddMethod(nameof(StaticInjected), "StaticTestMethod")]
3128
public static void OnStaticTestMethod()
3229
{
3330
Console.WriteLine("OnStaticTestMethod Called");
3431
}
35-
}
32+
}
33+
#pragma warning restore RCS1102, IDE0060, RCS1163
3634
}

TestProject/Injected.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
62

73
namespace TestProject
84
{
9-
public class Injected
5+
public class Injected
106
{
117
public void Method1()
128
{
139
Console.WriteLine("Magic v1");
1410
}
11+
1512
public void Method2()
1613
{
1714
Console.WriteLine("Magic v2");
1815
}
16+
1917
public bool Method3()
2018
{
2119
Console.WriteLine("Magic v3");
2220
return true;
2321
}
22+
2423
public bool Method4()
2524
{
2625
Console.WriteLine("Magic v4");
@@ -31,23 +30,26 @@ public static void StaticMethod1()
3130
{
3231
Console.WriteLine("Magic v1");
3332
}
33+
3434
public static void StaticMethod2()
3535
{
3636
Console.WriteLine("Magic v2");
3737
}
38+
3839
public static bool StaticMethod3()
3940
{
4041
Console.WriteLine("Magic v3");
4142
return true;
4243
}
44+
4345
public static bool StaticMethod4()
4446
{
4547
Console.WriteLine("Magic v4");
4648
return false;
4749
}
4850
}
51+
4952
public static class StaticInjected
5053
{
51-
5254
}
5355
}

UniversalUnityHooks/Assemblies.cs

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using Mono.Cecil;
2+
using System;
3+
using System.IO;
4+
using System.Linq;
5+
6+
namespace UniversalUnityHooks
7+
{
8+
public class AssemblyHelper
9+
{
10+
public string AssemblyDirectory { get; }
11+
12+
public AssemblyHelper(string directory)
13+
{
14+
AssemblyDirectory = directory;
15+
}
16+
17+
public void FetchAndLoadAll()
18+
{
19+
try
20+
{
21+
foreach (var file in Directory.GetFiles(AssemblyDirectory, "*.dll"))
22+
{
23+
Program.Chalker.WriteWait($"Loading in assembly {Path.GetFileName(file)}..");
24+
var timer = new OperationTimer();
25+
try
26+
{
27+
var assembly = AssemblyDefinition.ReadAssembly(Path.GetFullPath(file));
28+
var allAttributes = Program.AttributesHelper.FindInAssembly(assembly);
29+
var filteredAttributes = Program.AttributesHelper.InstantiateAndInvoke(allAttributes, timer);
30+
foreach (var keyValuePair in filteredAttributes)
31+
Program.Attributes.Add(keyValuePair.Key, keyValuePair.Value);
32+
timer.Stop();
33+
Program.Chalker.WriteSuccess($"Loaded in assembly and {filteredAttributes.Sum(x=>x.Value.Count)} attribute(s) in {timer.GetElapsedMs}ms\r\n");
34+
}
35+
catch (Exception ex)
36+
{
37+
Program.Chalker.WriteError(ex.InnerException.StackTrace);
38+
timer.Stop();
39+
Program.Chalker.WriteError($"Could not load in assembly after {timer.GetElapsedMs}ms.");
40+
Program.Chalker.WriteError($"Message: {ex.Message}");
41+
Program.Chalker.WriteError(ex.StackTrace);
42+
}
43+
}
44+
}
45+
catch (Exception ex)
46+
{
47+
Program.Chalker.WriteError($"{ex.Message}\r\nStackTrace:{ex.StackTrace}");
48+
}
49+
}
50+
}
51+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Mono.Cecil;
2+
3+
namespace UniversalUnityHooks
4+
{
5+
public class AttributeData
6+
{
7+
public AttributeData(TypeDefinition type, MethodDefinition method, CustomAttribute attribute, AssemblyDefinition assembly)
8+
{
9+
Type = type;
10+
Method = method;
11+
Attribute = attribute;
12+
Assembly = assembly;
13+
}
14+
15+
public Cecil.ReturnData TargetData { get; set; }
16+
17+
public AssemblyDefinition Assembly { get; set; }
18+
19+
public TypeDefinition Type { get; set; }
20+
21+
public MethodDefinition Method { get; set; }
22+
23+
public CustomAttribute Attribute { get; set; }
24+
}
25+
}

0 commit comments

Comments
 (0)