Skip to content

Instantly share code, notes, and snippets.

@acvanzant

acvanzant/get_vendor.py

Forked from prot0man/get_vendor.py
Last active Feb 25, 2021
Embed
What would you like to do?
Valheim vendor finder
"""
Locates the x and z coordinates of bosses and the troll vendor
"""
import struct
import sys
import argparse
TROLLVENDOR = b"Vendor_BlackForest"
GOBLINKING = b"GoblinKing"
DRAGONQUEEN = b"Dragonqueen"
BONEMASS = b"Bonemass"
ELDER = b"GDKing"
EIKTHYRNIR = b"Eikthyrnir"
VENDOR_FMT = "<fff"
def get_vendor_coordinates(db_data, id):
print("getting locations for %s" % id)
# find where the vendor is defined
offset = db_data.find(id)
if offset == -1:
raise Exception("Invalid database provided")
dist = 9999
xx,yy,zz = 9999,9999,9999
while offset != -1:
# After vendor occurs, the 4 byte x, y, and z coordinates occur. increment
# past the vendor ID
bidx = offset + len(id)
eidx = bidx + struct.calcsize(VENDOR_FMT)
x,y,z = struct.unpack(VENDOR_FMT, db_data[bidx:eidx])
diff = (abs(x)+abs(z))/2
if diff < dist:
dist = diff
xx,yy,zz = x,y,z
offset = db_data.find(id, bidx)
return xx,yy,zz,dist
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 location within")
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
db_data = load_db(args.db_path)
ex,ey,ez,edist = get_vendor_coordinates(db_data, EIKTHYRNIR)
print("Type 'goto %d %d', (%d)" % (ex, ez, edist))
elx,ely,elz,eldist = get_vendor_coordinates(db_data, ELDER)
print("Type 'goto %d %d', (%d)" % (elx, elz, eldist))
bx,by,bz,bdist = get_vendor_coordinates(db_data, BONEMASS)
print("Type 'goto %d %d', (%d)" % (bx, bz, bdist))
gx,gy,gz,gdist = get_vendor_coordinates(db_data, GOBLINKING)
print("Type 'goto %d %d', (%d)" % (gx, gz, gdist))
dx,dy,dz,ddist = get_vendor_coordinates(db_data, DRAGONQUEEN)
print("Type 'goto %d %d', (%d)" % (dx, dz, ddist))
tx,ty,tz,tdist = get_vendor_coordinates(db_data, TROLLVENDOR)
print("Type 'goto %d %d', (%d)" % (tx, tz, tdist))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment