Skip to content

Instantly share code, notes, and snippets.

@prot0man
Last active July 25, 2023 04:11
Show Gist options
  • Save prot0man/457f90d80be49829552587f61a61788c to your computer and use it in GitHub Desktop.
Save prot0man/457f90d80be49829552587f61a61788c to your computer and use it in GitHub Desktop.
Valheim vendor finder
"""
Locates the x and z coordinates of the Valheim vendor and prints them
to console.
"""
import struct
import sys
import argparse
#VENDOR_ID = b"Meteorite" # ashlands
#VENDOR_ID = b"Eikthyrnir" # first boss
#VENDOR_ID = b"GoblinKing" # plains boss
VENDOR_ID = b"Vendor_BlackForest"
VENDOR_FMT = "<fff"
def get_vendor_coordinates(db_data, index=0):
# find where the vendor is defined
offset = db_data.find(VENDOR_ID, index)
if offset == -1:
return None, None, None, None
# After vendor occurs, the 4 byte x, y, and z coordinates occur. increment
# past the vendor ID
bidx = offset + len(VENDOR_ID)
eidx = bidx + struct.calcsize(VENDOR_FMT)
x,y,z = struct.unpack(VENDOR_FMT, db_data[bidx:eidx])
return offset, int(x), int(y), int(z)
def load_db(db_path):
with open(db_path, "rb") as hfile:
data = hfile.read()
return data
def parse_args():
parser = argparse.ArgumentParser(description="Valheim Vendor finder")
parser.add_argument("db_path", help="The path to the Valheim database to find the vendor for")
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
db_data = load_db(args.db_path)
index = 0
while 1:
index, x, y, z = get_vendor_coordinates(db_data, index+1)
if index == None:
break
print("Type 'goto %d %d'" % (x, z))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment