EventInjectionTransformer.java
3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* This file is part of LiteLoader.
* Copyright (C) 2012-16 Adam Mummery-Smith
* All Rights Reserved.
*/
package com.mumfrey.liteloader.transformers.event;
import org.spongepowered.asm.mixin.injection.InjectionPoint;
import com.mumfrey.liteloader.transformers.ObfProvider;
import net.minecraft.launchwrapper.IClassTransformer;
public abstract class EventInjectionTransformer implements IClassTransformer
{
public EventInjectionTransformer()
{
try
{
this.addEvents();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
/* (non-Javadoc)
* @see net.minecraft.launchwrapper.IClassTransformer
* #transform(java.lang.String, java.lang.String, byte[])
*/
@Override
public byte[] transform(String name, String transformedName, byte[] basicClass)
{
return basicClass;
}
/**
* Subclasses should register events here
*/
protected abstract void addEvents();
/**
* Register a new event to be injected, the event instance will be created
* if it does not already exist.
*
* @param eventName Name of the event to use/create. Beware that
* IllegalArgumentException if the event was already defined with
* incompatible parameters
* @param targetMethod Method descriptor to identify the method to inject
* into
* @param injectionPoint Delegate which finds the location(s) in the target
* method to inject into
*
* @return the event - for fluent interface
*/
protected final Event addEvent(String eventName, MethodInfo targetMethod, InjectionPoint injectionPoint)
{
return this.addEvent(Event.getOrCreate(eventName), targetMethod, injectionPoint);
}
/**
* Register an event to be injected
*
* @param event Event to inject
* @param targetMethod Method descriptor to identify the method to inject
* into
* @param injectionPoint Delegate which finds the location(s) in the target
* method to inject into
*
* @return the event - for fluent interface
*/
protected final Event addEvent(Event event, MethodInfo targetMethod, InjectionPoint injectionPoint)
{
if (event == null)
{
throw new IllegalArgumentException("Event cannot be null!");
}
if (injectionPoint == null)
{
throw new IllegalArgumentException("Injection point cannot be null for event " + event.getName());
}
if ("true".equals(System.getProperty("mcpenv")))
{
EventTransformer.addEvent(event, targetMethod.owner, targetMethod.sig, injectionPoint);
}
else
{
EventTransformer.addEvent(event, targetMethod.owner, targetMethod.sigSrg, injectionPoint);
EventTransformer.addEvent(event, targetMethod.ownerObf, targetMethod.sigObf, injectionPoint);
}
event.addPendingInjection(targetMethod);
return event;
}
/**
* Register an access injection interface
*
* @param interfaceName
*/
protected final void addAccessor(String interfaceName)
{
EventTransformer.addAccessor(interfaceName);
}
/**
* Register an access injection interface and provide a contextual
* obfuscation provider.
*
* @param interfaceName
* @param obfProvider
*/
protected final void addAccessor(String interfaceName, ObfProvider obfProvider)
{
EventTransformer.addAccessor(interfaceName, obfProvider);
}
}