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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
|
package de.torui.coflsky.gui.tfm;
import de.torui.coflsky.CoflSky;
import de.torui.coflsky.WSCommandHandler;
import de.torui.coflsky.gui.GUIType;
import de.torui.coflsky.handlers.EventHandler;
import de.torui.coflsky.handlers.EventRegistry;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.gui.inventory.GuiChest;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.inventory.ContainerChest;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
import org.lwjgl.input.Mouse;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static net.minecraft.client.gui.Gui.drawRect;
public class ButtonRemapper {
private static ButtonRemapper instance;
private final static int BUY_BUTTON_SLOT = 31;
private final static int ITEM_SLOT = 13;
private final static int CONFIRM_BUTTON_SLOT = 11;
private final static int CANCEL_CONFIRM_SLOT = 15;
private final static int BACK_BUTTON_SLOT = 49;
private final static double SCALE_VALUE = 2.0d;
private final static Pattern BED_TIME_PATTERN = Pattern.compile("Can buy in: (.*)");
private final Method drawItemMethod;
private final Method renderToolTipMethod;
private ButtonRemapper() {
// drawItemStack obfuscated
String[] methodNames = new String[]{"drawItemStack", "func_146982_a"};
drawItemMethod = ReflectionHelper.findMethod(GuiContainer.class, null, methodNames, ItemStack.class, int.class, int.class, String.class);
drawItemMethod.setAccessible(true);
// obfuscated renderToolTip method
methodNames = new String[]{"renderToolTip", "func_146285_a"};
renderToolTipMethod = ReflectionHelper.findMethod(GuiScreen.class, null, methodNames, ItemStack.class, int.class, int.class);
}
public static ButtonRemapper getInstance() {
if (instance == null) {
instance = new ButtonRemapper();
}
return instance;
}
public ItemStack getItem(int slotNum, GuiChest currentScreen) {
ContainerChest container = (ContainerChest) currentScreen.inventorySlots;
return container.getSlot(slotNum).getStack();
}
public boolean waitingForBed(GuiChest currentScreen) {
ItemStack bedStack = getItem(BUY_BUTTON_SLOT, currentScreen);
if (bedStack == null || !bedStack.getItem().equals(Item.getByNameOrId("minecraft:bed"))) {
return false;
}
ItemStack itemStack = getItem(ITEM_SLOT, currentScreen);
if (itemStack == null) {
return false;
}
List<String> itemTooltip = itemStack.getTooltip(Minecraft.getMinecraft().thePlayer, false);
for (String data : itemTooltip) {
Matcher matcher = BED_TIME_PATTERN.matcher(EnumChatFormatting.getTextWithoutFormattingCodes(data));
if (!matcher.find()) {
continue;
}
String timeData = matcher.group(1);
if (!timeData.equals("Soon!")) {
return true;
}
}
return false;
}
private int[] getBuyBoxDimensions() {
int centerX = getGuiCenterX();
int centerY = getGuiCenterY();
double multiplier = 0.1;
return new int[]{(int) (centerX - (centerX * multiplier)), (int) (centerY + (centerY * multiplier)),
(int) (centerX + (centerX * multiplier)), (int) (centerY - (centerY * multiplier))};
}
private int[] getCancelBoxDimensions() {
int centerX = getGuiCenterX();
int centerY = (int) (getGuiCenterY() * 1.25);
double multiplier = 0.05;
return new int[]{(int) (centerX - (centerX * multiplier)), (int) (centerY + (centerY * multiplier)),
(int) (centerX + (centerX * multiplier)), (int) (centerY - (centerY * multiplier))};
}
@SuppressWarnings("SameParameterValue")
private void drawBoxWithShadow(int leftX, int topY, int rightX, int bottomY, int colour, int shadowSize, int shadowColour) {
drawRect(leftX - shadowSize, topY + shadowSize, rightX + shadowSize, bottomY - shadowSize, shadowColour);
drawRect(leftX, topY, rightX, bottomY, colour);
}
private void drawTfmBox(boolean isConfirm) {
String titleText;
if (isConfirm) {
titleText = "Cofl - Confirm Purchase";
} else {
titleText = "Cofl - Auction View";
}
int outerBox = 0xff4f4f4f; // gray colour
// draw the outer tfm box
drawBoxWithShadow((int) (getGuiCenterX() * 0.5), (int) (getGuiCenterY() * 1.6), (int) (getGuiCenterX() * 1.5), (int) (getGuiCenterY() * 0.4), outerBox, 1, 0xff000000);
Minecraft.getMinecraft().fontRendererObj.drawStringWithShadow(titleText, (int) (getGuiCenterX() * 0.55), (int) (getGuiCenterY() * 0.45), 0xFFFFFFFF);
}
private void renderTooltip(GuiChest chest, ItemStack item) {
ToolTipHelper toolTipData = new ToolTipHelper(item);
int toolTipY = getGuiCenterY() - (toolTipData.determineHeight() / 2);
int toolTipX = (int) (getGuiCenterX() * 1.25) - (toolTipData.determineWidth() / 2);
if (toolTipX < getGuiCenterX()) {
toolTipX = getGuiCenterX() + 10;
}
try {
renderToolTipMethod.invoke(chest, item, toolTipX, toolTipY);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
private void renderItem(GuiChest chest, ItemStack item) {
GlStateManager.pushMatrix();
GlStateManager.scale(SCALE_VALUE, SCALE_VALUE, 0);
int itemX = (int) ((getGuiCenterX() - 16) / SCALE_VALUE);
int itemY = (int) ((getGuiCenterY() - 16) / SCALE_VALUE);
try {
drawItemMethod.invoke(chest, item, itemX, itemY, null);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
GlStateManager.popMatrix();
}
private void drawBuyBox(boolean shouldBeRed) {
int colour = shouldBeRed ? 255 << 16 : 255 << 8;
colour += 128 << 24;
int[] dim = getBuyBoxDimensions();
drawBoxWithShadow(dim[0], dim[1], dim[2], dim[3], colour, 1, 0xff000000);
}
private void drawCancelBox() {
int colour = 0x7FFF0000;
int[] dim = getCancelBoxDimensions();
drawBoxWithShadow(dim[0], dim[1], dim[2], dim[3], colour, 1, 0xff000000);
}
public void drawProfitInfo() {
FontRenderer font = Minecraft.getMinecraft().fontRendererObj;
String text = WSCommandHandler.flipHandler.lastClickedFlipMessage;
|