Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. import java.lang.reflect.Method;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4.  
  5. import net.minecraft.client.Minecraft;
  6. import net.minecraft.client.entity.EntityPlayerSP;
  7. import net.minecraft.entity.Entity;
  8. import net.minecraft.entity.EntityLivingBase;
  9. import net.minecraft.entity.player.EntityPlayer;
  10. import sun.reflect.ConstantPool;
  11.  
  12. public class PoolChecker {
  13. private static final Map<Class, Double> map = new HashMap();
  14.  
  15. static{
  16. addClass(EntityPlayerSP.class);
  17. addClass(Minecraft.class);
  18. addClass(EntityPlayer.class);
  19. addClass(EntityLivingBase.class);
  20. addClass(Entity.class);
  21. }
  22.  
  23. private static void addClass(Class cl){
  24. map.put(cl, getHash(cl));
  25. }
  26. public static boolean check(Class cl){
  27. return map.containsKey(cl) && map.get(cl)==getHash(cl);
  28. }
  29.  
  30. public static void recheck(){
  31. for(Class key : map.keySet()){
  32. if(map.get(key)!=getHash(key)){
  33. //TO-DO
  34. }
  35. }
  36. }
  37.  
  38.  
  39. private static double getHash(Class cl){
  40. Method getConstantPool;
  41. try {
  42. getConstantPool = Class.class.getDeclaredMethod("getConstantPool");
  43. getConstantPool.setAccessible(true);
  44. } catch (NoSuchMethodException e) {
  45. throw new RuntimeException(e);
  46. }
  47. double result = 0;
  48. try {
  49. ConstantPool constantPool = (ConstantPool) getConstantPool.invoke(cl);
  50. for(int i = 0; i<constantPool.getSize();i++){
  51. try {
  52. long l = constantPool.getLongAt(i);
  53. result+=l;
  54. } catch (IllegalArgumentException e) {
  55. try {
  56. double d = constantPool.getDoubleAt(i);
  57. result+=d;
  58. } catch (IllegalArgumentException ed) {
  59. try {
  60. float f = constantPool.getFloatAt(i);
  61. result+=f;
  62. } catch (IllegalArgumentException edzz) {
  63.  
  64. }
  65. }
  66. }
  67. }
  68. } catch (Exception e) {
  69. }
  70. return result;
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement