Added conversion for OnAttacked and OnDeath handlers and added new hook character.damageLimb

This commit is contained in:
EvilFactory
2023-04-25 10:20:24 -03:00
parent 9415219141
commit 93a5065171
3 changed files with 57 additions and 63 deletions

View File

@@ -1,87 +1,77 @@
Hook.Patch(
"Barotrauma.Item", "TryInteract",
{
Hook.Patch("Barotrauma.Item", "TryInteract",
{
"Barotrauma.Character",
"System.Boolean",
"System.Boolean",
"System.Boolean"
},
function(instance, p)
},
function(instance, p)
if Hook.Call("item.interact", instance, p["user"], p["ignoreRequiredItems"], p["forceSelectKey"], p["forceUseKey"]) == true then
p.PreventExecution = true
return false
p.PreventExecution = true
return false
end
end,
Hook.HookMethodType.Before
)
end, Hook.HookMethodType.Before)
Hook.Patch(
"Barotrauma.Item", "ApplyTreatment",
{
Hook.Patch("Barotrauma.Item", "ApplyTreatment",
{
"Barotrauma.Character",
"Barotrauma.Character",
"Barotrauma.Limb"
},
function(instance, p)
},
function(instance, p)
if Hook.Call("item.applyTreatment", instance, p["user"], p["character"], p["targetLimb"]) then
p.PreventExecution = true
return false
p.PreventExecution = true
return false
end
end,
Hook.HookMethodType.Before
)
end, Hook.HookMethodType.Before)
Hook.Patch(
"Barotrauma.Item", "Combine",
{
Hook.Patch("Barotrauma.Item", "Combine",
{
"Barotrauma.Item",
"Barotrauma.Character"
},
function(instance, p)
},
function(instance, p)
if Hook.Call("item.combine", instance, p["item"], p["user"]) == true then
p.PreventExecution = true
return false
p.PreventExecution = true
return false
end
end,
Hook.HookMethodType.Before
)
end, Hook.HookMethodType.Before)
Hook.Patch(
"Barotrauma.Item", "Drop",
function(instance, p)
Hook.Patch("Barotrauma.Item", "Drop",
function(instance, p)
if Hook.Call("item.drop", instance, p["dropper"]) == true then
p.PreventExecution = true
return false
p.PreventExecution = true
return false
end
end,
Hook.HookMethodType.Before
)
end, Hook.HookMethodType.Before)
Hook.Patch(
"Barotrauma.Item", "Equip",
{
Hook.Patch("Barotrauma.Item", "Equip",
{
"Barotrauma.Character"
},
function(instance, p)
},
function(instance, p)
if Hook.Call("item.equip", instance, p["character"]) == true then
p.PreventExecution = true
return false
p.PreventExecution = true
return false
end
end,
Hook.HookMethodType.Before
)
end, Hook.HookMethodType.Before)
Hook.Patch(
"Barotrauma.Item", "Unequip",
{
Hook.Patch("Barotrauma.Item", "Unequip",
{
"Barotrauma.Character"
},
function(instance, p)
},
function(instance, p)
if Hook.Call("item.unequip", instance, p["character"]) == true then
p.PreventExecution = true
return false
p.PreventExecution = true
return false
end
end,
Hook.HookMethodType.Before
)
end, Hook.HookMethodType.Before)
Hook.Patch("Barotrauma.Character", "DamageLimb", function(instance, p)
local result = Hook.Call("character.damageLimb", instance, p["afflictions"], p["attacker"], p["hitLimb"], p["worldPosition"], p["stun"], p["attackImpulse"], p["damageMultiplier"], p["allowStacking"], p["penetration"], p["shouldImplode"], p["playSound"])
if result == true then
p.PreventExecution = true
return false
end
end, Hook.HookMethodType.Before)

View File

@@ -86,6 +86,7 @@ RegisterBarotrauma("CharacterParams+SoundParams")
RegisterBarotrauma("SteeringManager")
RegisterBarotrauma("IndoorsSteeringManager")
RegisterBarotrauma("SteeringPath")
RegisterBarotrauma("CreatureMetrics")
RegisterBarotrauma("Item")
RegisterBarotrauma("DeconstructItem")

View File

@@ -56,16 +56,19 @@ namespace Barotrauma
return default;
}));
DynValue Call(object function, params object[] arguments) => CallLuaFunction(function, arguments);
void RegisterHandler<T>(Func<Closure, T> converter) => Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Function, typeof(T), v => converter(v.Function));
RegisterHandler(f => (Character.OnDeathHandler)((a1, a2) => Call(f, a1, a2)));
RegisterHandler(f => (Character.OnAttackedHandler)((a1, a2) => Call(f, a1, a2)));
#if CLIENT
RegisterAction<Microsoft.Xna.Framework.Graphics.SpriteBatch, GUICustomComponent>();
RegisterAction<float, Microsoft.Xna.Framework.Graphics.SpriteBatch>();
RegisterAction<Microsoft.Xna.Framework.Graphics.SpriteBatch, float>();
{
DynValue Call(object function, params object[] arguments) => CallLuaFunction(function, arguments);
void RegisterHandler<T>(Func<Closure, T> converter)
=> Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Function, typeof(T), v => converter(v.Function));
RegisterHandler(f => (GUIComponent.SecondaryButtonDownHandler)(
(a1, a2) => Call(f, a1, a2)?.CastToBool() ?? default));