Added conversion for OnAttacked and OnDeath handlers and added new hook character.damageLimb
This commit is contained in:
@@ -1,87 +1,77 @@
|
|||||||
|
Hook.Patch("Barotrauma.Item", "TryInteract",
|
||||||
Hook.Patch(
|
{
|
||||||
"Barotrauma.Item", "TryInteract",
|
|
||||||
{
|
|
||||||
"Barotrauma.Character",
|
"Barotrauma.Character",
|
||||||
"System.Boolean",
|
"System.Boolean",
|
||||||
"System.Boolean",
|
"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
|
if Hook.Call("item.interact", instance, p["user"], p["ignoreRequiredItems"], p["forceSelectKey"], p["forceUseKey"]) == true then
|
||||||
p.PreventExecution = true
|
p.PreventExecution = true
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end,
|
end, Hook.HookMethodType.Before)
|
||||||
Hook.HookMethodType.Before
|
|
||||||
)
|
|
||||||
|
|
||||||
Hook.Patch(
|
Hook.Patch("Barotrauma.Item", "ApplyTreatment",
|
||||||
"Barotrauma.Item", "ApplyTreatment",
|
{
|
||||||
{
|
|
||||||
"Barotrauma.Character",
|
"Barotrauma.Character",
|
||||||
"Barotrauma.Character",
|
"Barotrauma.Character",
|
||||||
"Barotrauma.Limb"
|
"Barotrauma.Limb"
|
||||||
},
|
},
|
||||||
function(instance, p)
|
function(instance, p)
|
||||||
if Hook.Call("item.applyTreatment", instance, p["user"], p["character"], p["targetLimb"]) then
|
if Hook.Call("item.applyTreatment", instance, p["user"], p["character"], p["targetLimb"]) then
|
||||||
p.PreventExecution = true
|
p.PreventExecution = true
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end,
|
end, Hook.HookMethodType.Before)
|
||||||
Hook.HookMethodType.Before
|
|
||||||
)
|
|
||||||
|
|
||||||
Hook.Patch(
|
Hook.Patch("Barotrauma.Item", "Combine",
|
||||||
"Barotrauma.Item", "Combine",
|
{
|
||||||
{
|
|
||||||
"Barotrauma.Item",
|
"Barotrauma.Item",
|
||||||
"Barotrauma.Character"
|
"Barotrauma.Character"
|
||||||
},
|
},
|
||||||
function(instance, p)
|
function(instance, p)
|
||||||
if Hook.Call("item.combine", instance, p["item"], p["user"]) == true then
|
if Hook.Call("item.combine", instance, p["item"], p["user"]) == true then
|
||||||
p.PreventExecution = true
|
p.PreventExecution = true
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end,
|
end, Hook.HookMethodType.Before)
|
||||||
Hook.HookMethodType.Before
|
|
||||||
)
|
|
||||||
|
|
||||||
Hook.Patch(
|
Hook.Patch("Barotrauma.Item", "Drop",
|
||||||
"Barotrauma.Item", "Drop",
|
function(instance, p)
|
||||||
function(instance, p)
|
|
||||||
if Hook.Call("item.drop", instance, p["dropper"]) == true then
|
if Hook.Call("item.drop", instance, p["dropper"]) == true then
|
||||||
p.PreventExecution = true
|
p.PreventExecution = true
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end,
|
end, Hook.HookMethodType.Before)
|
||||||
Hook.HookMethodType.Before
|
|
||||||
)
|
|
||||||
|
|
||||||
Hook.Patch(
|
Hook.Patch("Barotrauma.Item", "Equip",
|
||||||
"Barotrauma.Item", "Equip",
|
{
|
||||||
{
|
|
||||||
"Barotrauma.Character"
|
"Barotrauma.Character"
|
||||||
},
|
},
|
||||||
function(instance, p)
|
function(instance, p)
|
||||||
if Hook.Call("item.equip", instance, p["character"]) == true then
|
if Hook.Call("item.equip", instance, p["character"]) == true then
|
||||||
p.PreventExecution = true
|
p.PreventExecution = true
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end,
|
end, Hook.HookMethodType.Before)
|
||||||
Hook.HookMethodType.Before
|
|
||||||
)
|
|
||||||
|
|
||||||
Hook.Patch(
|
Hook.Patch("Barotrauma.Item", "Unequip",
|
||||||
"Barotrauma.Item", "Unequip",
|
{
|
||||||
{
|
|
||||||
"Barotrauma.Character"
|
"Barotrauma.Character"
|
||||||
},
|
},
|
||||||
function(instance, p)
|
function(instance, p)
|
||||||
if Hook.Call("item.unequip", instance, p["character"]) == true then
|
if Hook.Call("item.unequip", instance, p["character"]) == true then
|
||||||
p.PreventExecution = true
|
p.PreventExecution = true
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end,
|
end, Hook.HookMethodType.Before)
|
||||||
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)
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ RegisterBarotrauma("CharacterParams+SoundParams")
|
|||||||
RegisterBarotrauma("SteeringManager")
|
RegisterBarotrauma("SteeringManager")
|
||||||
RegisterBarotrauma("IndoorsSteeringManager")
|
RegisterBarotrauma("IndoorsSteeringManager")
|
||||||
RegisterBarotrauma("SteeringPath")
|
RegisterBarotrauma("SteeringPath")
|
||||||
|
RegisterBarotrauma("CreatureMetrics")
|
||||||
|
|
||||||
RegisterBarotrauma("Item")
|
RegisterBarotrauma("Item")
|
||||||
RegisterBarotrauma("DeconstructItem")
|
RegisterBarotrauma("DeconstructItem")
|
||||||
|
|||||||
@@ -56,16 +56,19 @@ namespace Barotrauma
|
|||||||
return default;
|
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
|
#if CLIENT
|
||||||
RegisterAction<Microsoft.Xna.Framework.Graphics.SpriteBatch, GUICustomComponent>();
|
RegisterAction<Microsoft.Xna.Framework.Graphics.SpriteBatch, GUICustomComponent>();
|
||||||
RegisterAction<float, Microsoft.Xna.Framework.Graphics.SpriteBatch>();
|
RegisterAction<float, Microsoft.Xna.Framework.Graphics.SpriteBatch>();
|
||||||
RegisterAction<Microsoft.Xna.Framework.Graphics.SpriteBatch, float>();
|
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)(
|
RegisterHandler(f => (GUIComponent.SecondaryButtonDownHandler)(
|
||||||
(a1, a2) => Call(f, a1, a2)?.CastToBool() ?? default));
|
(a1, a2) => Call(f, a1, a2)?.CastToBool() ?? default));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user