java - 删除混淆名称(Minecraft)的最有效方法是什么?

标签 java lua minecraft

我为 Minecraft 制作了一个允许 Lua 模组的模组。一切工作正常,但通常方法名称在 MC 中会被混淆。使正常函数名称重定向到混淆名称的最佳方法是什么?

例如,用户为一个 block 编写了一个脚本,右键单击时打印 hello world:

函数 onActivated(世界, x, y, z, 玩家) 玩家:addChatMessage(“ Hello World ”) 结束

addChatMessage 应调用 Java 方法 EntityPlayer.func_71035_c(String text)

最佳答案

-- translation file (translation.txt)
func_70912_b,setTameSkin,2,
func_70913_u,getTameSkin,2,
func_70915_j,getShadingWhileShaking,2,Used when calculating the amount of shading to apply while the wolf is shaking.
func_70916_h,setAngry,2,Sets whether this wolf is angry.


-- obfuscated program (script.lua)
x:func_70913_u(y, z)
x:func_70915_j(y, z)


-- your preprocessor (preprocessor.lua)
local transl = {}
for line in io.lines'translation.txt' do
   local obf, orig = line:match'^(.-),(.-),'
   transl[obf] = orig
end
local script = assert(io.open('script.lua','rb')):read'*a'
local output = assert(io.open('script2.lua','wb'))
output:write((script:gsub('[%w_]+',transl)))
output:close()


-- preprocessor output (script2.lua)
x:getTameSkin(y, z)
x:getShadingWhileShaking(y, z)
<小时/>

编辑:

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)
...

关于java - 删除混淆名称(Minecraft)的最有效方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15527100/

相关文章:

java - 在具有泛型参数的泛型方法中使用 Spring RestTemplate

c++ - 从静态函数中调用成员函数

java - Eclipse Java 版本错误

c++ - 与 Minecraft bukkit 服务器握手 - 发送服务器主机字段失败

java - 从各种未知来源检索特定对象的模式/设计方法

java - Google Guava 从起始目录开始迭代所有文件

java - JFileChooser 文件名过滤器

string - 查找两个字符串文本之间的 "difference"(Lua 示例)

c++ - Luabind: "No matching overload found, candidates:"

Java从config.yml中获取Maps的List of maps