Java 什么';删除模糊名称(Minecraft)的最有效方法是什么?

Java 什么';删除模糊名称(Minecraft)的最有效方法是什么?,java,lua,minecraft,Java,Lua,Minecraft,我已经为Minecraft做了一个mod,允许Lua进行MODD。一切都很好,但通常方法的名称在MC中是模糊的。使普通函数名重定向到模糊名称的最佳方法是什么 例如,用户在右键单击时为打印hello world的块生成脚本: 功能已激活(世界、x、y、z、玩家) 播放器:addChatMessage(“你好,世界”) 结束 addChatMessage应该调用Java方法EntityPlayer.func_71035_c(字符串文本) 编辑: local obfuscations = {} fo

我已经为Minecraft做了一个mod,允许Lua进行MODD。一切都很好,但通常方法的名称在MC中是模糊的。使普通函数名重定向到模糊名称的最佳方法是什么

例如,用户在右键单击时为打印hello world的块生成脚本:

功能已激活(世界、x、y、z、玩家)
播放器:addChatMessage(“你好,世界”)
结束

addChatMessage应该调用Java方法EntityPlayer.func_71035_c(字符串文本)


编辑:

local obfuscations = {}
for line in io.lines'translation.txt' do
   local obf, orig = line:match'^(.-),(.-),'
   obfuscations[orig] = obf
end

local function get_obf_key_value(t, k, __index)
   local value = __index and __index(t, k)
   if value == nil and obfuscations[k] then
      value = t[obfuscations[k]]
   end
   return value
end

local cache = {get_obf_key_value = true}

local function __index_constructor(__index)
   if not __index then
      return get_obf_key_value
   end
   local old__index = cache[__index]
   if old__index then
      return old__index == true and __index or old__index
   else
      local function new__index(t, k)
         return get_obf_key_value(t, k, __index)
      end
      cache[__index] = new__index
      cache[new__index] = true
      return new__index
   end
end

local obf_mt = {__index = get_obf_key_value}

local function correct_metatable(object)
   local mt = getmetatable(object)
   if mt == nil then
      setmetatable(object, obf_mt)
   else
      local __index = mt.__index
      if __index == nil or type(__index) == 'function' then
          mt.__index = __index_constructor(__index)
      else
         correct_metatable(__index)
      end
   end
end

-- you should call correct_metatable(class_or_object_of_that_class)
-- at least once for every class
correct_metatable(wolf)
correct_metatable(goat)
correct_metatable(cabbage)
...

尝试使用
require'libname'
访问原始库。例如,
(需要'math').pi
以获得非模糊的
math.pi
。我说的是Minecraft方法。通常,所有方法都是模糊的(func_number_a)。因此,如果我给一个Player对象作为参数,我必须调用Player:func_34323; u c(text),而不是Player:addChatMessage()。MC编码器包将方法/字段/类名转换为逻辑名(我有用于名称的文件)。您有权访问转换算法(将
func\u 34323\u c
转换为
addChatMessage
)?这是一个秘密吗?我有包含模糊名称和逻辑名称(字段、类和方法)的文件。真正未混淆的名称是未知的,但MCP的创建者只是给func_34323; c之类的方法一个适当的名称。请给出此类文件的示例。通常MC是混淆的,所以我需要使逻辑函数名混淆,以便用户不必知道混淆的名称。问题是我不能每一次(每秒20次)混淆Lua文件。我需要以某种方式将函数重定向到模糊化的函数。@Hackingroelz-它需要更改大量的元表(对于使用的每个类)。因此,我必须更改给函数的每个对象的元表?这真的会造成很大的滞后吗?我可以添加一个全局函数来调用Java方法,但是如果没有,当然会更好。@Hackingroelz-见我的补充答案。这是一种更正类的元表的方法。
local obfuscations = {}
for line in io.lines'translation.txt' do
   local obf, orig = line:match'^(.-),(.-),'
   obfuscations[orig] = obf
end

local function get_obf_key_value(t, k, __index)
   local value = __index and __index(t, k)
   if value == nil and obfuscations[k] then
      value = t[obfuscations[k]]
   end
   return value
end

local cache = {get_obf_key_value = true}

local function __index_constructor(__index)
   if not __index then
      return get_obf_key_value
   end
   local old__index = cache[__index]
   if old__index then
      return old__index == true and __index or old__index
   else
      local function new__index(t, k)
         return get_obf_key_value(t, k, __index)
      end
      cache[__index] = new__index
      cache[new__index] = true
      return new__index
   end
end

local obf_mt = {__index = get_obf_key_value}

local function correct_metatable(object)
   local mt = getmetatable(object)
   if mt == nil then
      setmetatable(object, obf_mt)
   else
      local __index = mt.__index
      if __index == nil or type(__index) == 'function' then
          mt.__index = __index_constructor(__index)
      else
         correct_metatable(__index)
      end
   end
end

-- you should call correct_metatable(class_or_object_of_that_class)
-- at least once for every class
correct_metatable(wolf)
correct_metatable(goat)
correct_metatable(cabbage)
...