[Solved] Dying Light Backpack Editor Error

Want Cheat Engine to do something specific and no idea how to do that, ask here. (From simple scripts to full trainers and extensions)
Post Reply
Venator
Expert Cheater
Expert Cheater
Posts: 56
Joined: Sun Jun 11, 2017 12:57 pm
Reputation: 16

[Solved] Dying Light Backpack Editor Error

Post by Venator »

Hello all. I am wondering if anyone might be able to offer me some insight to help address a Lua script error I've been getting intermittently with the Dying Light cheat table (thread link here). The error is appearing from the script used for the Backpack Editor. I decided to bring this up here because I haven't found anyone mention running into this same error, so I am presently assuming that I may need address it for myself.

Anyway, I get the following error on what seems like a random basis:

Code: Select all

Error:[string "ItemTable = {}..."]:28: bad argument #1 to 'find' (string expected, got nil)
This is the function from the Lua script that includes line 28:

Code: Select all

17 function BackPackUpdate()
18    WeapPack = readQword(readQword("ItemEditData")+0x60)+0x40
19    ItemPack = readQword(readQword("ItemEditData")+0x58)+0x40
20    BaseItemPoint = readQword("ItemEditData+8")-0x18
21    local BasePointCount = readInteger(BaseItemPoint+8)
22    PackEdit_LBWeapSwap.clear()
23    local WeapSwapList = PackEdit_LBWeapSwap.getItems()
24    local ItemSwapList = PackEdit_LBItemSwap.getItems()
25    for i=0,BasePointCount-1 do
26      local ItemAddr = readQword(readQword(BaseItemPoint)+i*8)
27      local ItemString = readString(readQword(ItemAddr+0x18))
28      if string.find(ItemString,"Craftplan_") then
29        table.insert(ModTable,{Address = ItemAddr,Name = ItemString})
30      end
31      table.insert(BaseItemTable,{Address=ItemAddr,Name=ItemString})
32    end
33    PackEdit_CBWeapMod.clear()
34    local ModList = PackEdit_CBWeapMod.getItems()
35    ModList.add("None")
36    PackEdit_CBWeapMod.setItemIndex(0)
37    for k,v in pairs(ModTable) do
38      ModList.add(v.Name)
39    end
40   for k,v in pairs(BaseItemTable) do
41     WeapSwapList.add(v.Name)
42     ItemSwapList.add(v.Name)
43   end
44 end
So from this I can gather that, at line 28, it's looking for some string value that includes "Craftplan_" and spitting out an error when it cannot locate it. Part of what's got me stuck is that it sometimes will find it and work fine and then at other times it won't and give me the error from line 28.

For context, the value for "ItemEditData" is provided from the Auto Assemble script that is run to enable the Backpack Editor Lua script. On a related note, the Auto Assemble script appears to work correctly. It successfully locates the array of bytes and gets activated. In addition, even when I do get the error, I still get some partial functionality from the Backpack Editor. It is able to find and read my inventory. That's the other part of what's got me stuck.

Tracing back from line 28, it is looking for a string value at "ItemString." ItemString is found from ItemAddr, which is found from BaseItemPoint, which is ultimately found from ItemEditData. From a novice's perspective, it looks like the address where we are hoping to find a string value on line 28 is not always the right one; the string value will sometimes not be there.

So my ultimate question is how might I best try to tackle this? How can I find out where the address I want to locate has gone when it isn't where the script expected it to be? And if it can move, can I deal with that through the Lua script? I've been reluctant to change too much since it does locate the inventory, but I don't know if I'd have to basically start over with it to make sure it worked for me consistently.
Last edited by Venator on Sun Dec 31, 2017 10:05 pm, edited 1 time in total.

User avatar
FreeER
Expert Cheater
Expert Cheater
Posts: 116
Joined: Fri Mar 10, 2017 7:11 pm
Reputation: 28

Re: [Help] Dying Light Backpack Editor Error

Post by FreeER »

Looks like it's using a pointer that occasionally doesn't have a value, simplest solution to the error is to add a check so that it doesn't try to use a nil value as a string.

Code: Select all

25    for i=0,BasePointCount-1 do
26      local ItemAddr = readQword(readQword(BaseItemPoint)+i*8)
27      local ItemString = readString(readQword(ItemAddr+0x18))
__      if ItemString then
28        if string.find(ItemString,"Craftplan_") then
29          table.insert(ModTable,{Address = ItemAddr,Name = ItemString})
30        end
31        table.insert(BaseItemTable,{Address=ItemAddr,Name=ItemString})
__      end
32    end
To be clear that should stop the error and allow the script to continue running so you can move around and try again, but it doesn't actually fix the pointer so that it's always valid. That may be all you need though.

To get it to work consistently you'd have to find another pointer (or some other way to get the address) that's more consistently valid. You can print out the address (when it's valid) used in the code to get a head start rather than having to start over completely, you've also got the inventory address from the script which appears to be valid all the time since you still get some functionality.

Venator
Expert Cheater
Expert Cheater
Posts: 56
Joined: Sun Jun 11, 2017 12:57 pm
Reputation: 16

Re: [Help] Dying Light Backpack Editor Error

Post by Venator »

Thanks for that. It seems to work right now. I'm going to play with it for a bit to make sure it's consistent, but I haven't run into any problems since adding those two lines. In any case, even if that doesn't completely solve it, I think your other suggestion should. Thanks again!

Post Reply

Who is online

Users browsing this forum: No registered users