gir489 Grandmaster Cheater Reputation: 14
Joined: 03 Jan 2012 Posts: 835 Location: Maryland, United States
|
Posted: Tue May 23, 2023 9:13 am Post subject: Lua error in script dotnetpatch Not all addresses found. |
|
|
I'm trying to use the .NET patcher against Valheim so I can reimplement the auto pickup function to exclude certain items that overfill my inventory that I do not want.
Below is the script I'm trying to use. The only thing I changed was the newAutoPickup function, so I'm not sure why it's complaining that it can't find the addresses. Player.AutoPickup resolves to 1C6F89D68A0 in memory.
Code: | [enable]
{$lua}
if syntaxcheck then return end
LaunchMonoDataCollector()
if dotnetdetours==nil then
dotnetdetours={}
else
local di=dotnetdetours['Player.AutoPickup']
if di and di.processid==getOpenedProcessID() then
--already detoured. Undo first
local r,err=autoAssemble(di.disablescript, di.disableinfo)
if not r then
error(err)
else
dotnetdetours['Player.AutoPickup']=nil
end
end
end
local detourinfo={}
local csharpscript=[[
using System.Runtime.CompilerServices; //for NoInlining
using UnityEngine;
//feel free to add more
public class patchedPlayer : Player
{
public void newAutoPickup(float dt)
{
//you have access to public fields. Use reflection if you wish to access private fields
//oldAutoPickup(dt);
if (IsTeleporting())
{
// return;
}
Vector3 vector = base.transform.position + Vector3.up;
Collider[] array = Physics.OverlapSphere(vector, m_autoPickupRange, LayerMask.GetMask("item"));
foreach (Collider collider in array)
{
if (!collider.attachedRigidbody)
{
continue;
}
ItemDrop component = collider.attachedRigidbody.GetComponent<ItemDrop>();
if (component == null || !component.m_autoPickup || HaveUniqueKey(component.m_itemData.m_shared.m_name) || !component.GetComponent<ZNetView>().IsValid())
{
continue;
}
if (!component.CanPickup())
{
component.RequestOwn();
}
else
{
if (component.InTar())
{
continue;
}
component.Load();
if (!m_inventory.CanAddItem(component.m_itemData) || component.m_itemData.GetWeight() + m_inventory.GetTotalWeight() > GetMaxCarryWeight())
{
continue;
}
float num = Vector3.Distance(component.transform.position, vector);
if (!(num > m_autoPickupRange))
{
if (num < 0.3f)
{
Pickup(component.gameObject);
continue;
}
Vector3 vector2 = Vector3.Normalize(vector - component.transform.position);
float num2 = 15f;
component.transform.position = component.transform.position + vector2 * num2 * dt;
}
}
}
return;
}
[MethodImpl(MethodImplOptions.NoInlining)]
public void oldAutoPickup(float dt)
{
//don't bother putting code in here. It will get replaced (just some stuff to make sure there's space)
return ;
}
}
]]
local references, sysfile=dotnetpatch_getAllReferences() --you're free to build your own list
local csfile,msg=compileCS(csharpscript, references, sysfile)
if csfile==nil then
--sometimes having the sysfile causes an issue. Try without
csfile,msg=compileCS(csharpscript, references)
if csfile==nil then
if msg==nil then msg=' (?Unknown error?)' end
messageDialog('Compilation error:'..msg, mtError, mbOK) --show compile error in a dialog instead of a lua error only
error(msg)
end
end
--still here, c# dll created, now inject and hook
local result, disableinfo, disablescript=InjectDotNetDetour(csfile, "Player::AutoPickup","patchedPlayer::newAutoPickup","patchedPlayer::oldAutoPickup")
if result then
detourinfo.disableinfo=di
detourinfo.disablescript=disablescript
detourinfo.processid=getOpenedProcessID()
dotnetdetours['Player.AutoPickup']=detourinfo
else
if disableinfo==nil then disableinfo='no reason' end
error('InjectDotNetDetour failed : '..disableinfo) --prevents checking
end
{$asm}
[disable]
{$lua}
if syntaxcheck then return end
if dotnetdetours['Player.AutoPickup'] then
autoAssemble(dotnetdetours['Player.AutoPickup'].disablescript, dotnetdetours['Player.AutoPickup'].disableinfo)
end
{$asm} |
The full error is:
Code: | Lua error in the script at line 2:autorun\dotnetpatch.lua:186: not all addresses found |
EDIT: If I redirect Player:FixedUpdate to call patchedPlayer::newAutoPickup, it calls my new function. If I want to restore it, I can just reload Player:AutoPickup into the MOV instruction that then CALLs it. I'm not sure if this is a bug in the auto detour code, but I can just basically run compileCS, then manually do the detour by hand.
|
|