Ah, I see...
So ClientWeapon:get_MaxRange hack gives you option of "manual long range shooting" and Gunner:GetMaxRange hack enables "automatic long range shoting" and we need them both.
...as for dual functions with the same name: the first function
float GetMaxRange() with no arguments calls the second function
float GetMaxRange(ServerUnit target) and I suppose we should hack the just first one. Since CE natively evaluates address of the first function - I reckon we are good to go. I would know how and where to "piggyback" this function, but I am not sure how to implement player check and other required nongamebreaking checks.
In case that I am wrong and we need the second one - we can always use something like (
[Link]):
Code: Select all
{$lua}
if syntaxcheck==true then return '' end
if (LaunchMonoDataCollector() == 0) then
error("no mono")
end
function reEscape(s)
local escPatChars = [[().%+-*?[^]]
s = s:gsub('.', function(c) if escPatChars:find(c, 1, true) then return '%'..c end end)
return s
end
function findMethodAddrBySignature(classname, methodname, signature, check)
local method = findMethodBySignature(classname, methodname, signature, check)
if method ~= nil and method > 0 then
return mono_compile_method(method)
end
end
function findMethodBySignature(classname, methodname, signature, check)
assert(type(signature) == 'string', "invalid signature")
signature = "^"..reEscape(signature:gsub(";", ","))
local class = mono_findClass('', classname)
if type(class) ~= 'number' or class == 0 then return nil end
local methods = mono_class_enumMethods(class)
if type(methods) ~= 'table' or #methods < 1 then return nil end
if check then print('check:'..methodname..": <"..signature.."> vs ") end
for i = 1, #methods do
if methodname == methods[i].name then
local sign = mono_method_getSignature(methods[i].method)
if check then print(" >> <"..sign..'>') end
if sign:match(signature) then
return methods[i].method
end
end
end
end
{$asm}
...and call it withing our script with something like:
Code: Select all
{$lua}
if syntaxcheck==true then return '' end
secondGunnerGetMaxRangeFunction = findMethodAddrBySignature('Gunner', 'GetMaxRange', 'ServerUnit')
{$asm}
What do you think? (and, of course, many thanks for your work)