Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
Wand customisation, --level arg, probe reports level
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorrow446 authored Feb 15, 2023
1 parent edc6deb commit 40bd4dd
Show file tree
Hide file tree
Showing 5 changed files with 610 additions and 62 deletions.
182 changes: 150 additions & 32 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,17 @@ var rawDbImageStr = []byte{
'\x6D', '\x61', '\x67', '\x65',
}

var queries = map[string]string{
"galleons": `UPDATE "InventoryDynamic" SET "Count" = %d WHERE "CharacterID" = "Player0" AND "ItemID" = "Knuts"`,
"xp": `UPDATE "MiscDataDynamic" SET "DataValue" = %d WHERE "DataName" = "ExperiencePoints"`,
"first_name": `UPDATE "MiscDataDynamic" SET "DataValue" = "%s" WHERE "DataName" = "PlayerFirstName"`,
"surname": `UPDATE "MiscDataDynamic" SET "DataValue" = "%s" WHERE "DataName" = "PlayerLastName"`,
"inventory_size": `UPDATE "MiscDataDynamic" SET "DataValue" = %d WHERE "DataName" = "BaseInventoryCapacity"`,
"inventory_quant": `UPDATE "InventoryDynamic" SET "Count" = %d WHERE "CharacterID" = "Player0" AND "HolderID" = "ResourceInventory" AND LOWER(ItemId) = "%s"`,
"talent_points": `UPDATE "MiscDataDynamic" SET "DataValue" = %d WHERE "DataOwner" = "Player0" AND "DataName" = "PerkPoints"`,
"unstuck": `UPDATE "MiscDataDynamic" SET "DataValue" = %f WHERE "DataOwner" = "Player" AND "DataName" = "%s"`,
"world": `UPDATE "MiscDataDynamic" SET "DataValue" = "Overland" WHERE "DataOwner" = "Player" AND "DataName" = "World"`,
"house": `UPDATE "MiscDataDynamic" SET "DataValue" = "%s" WHERE "DataOwner" = "Player" AND "DataName" = "HouseID"`,
var xps = []int{
0, 500, 1030, 1595, 2195,
2835, 3515, 4240, 5015, 5840,
6715, 7650, 8650, 9700, 10825,
12025, 13300, 14660, 16110, 17650,
19290, 21035, 22885, 24865, 26965,
29205, 31590, 34130, 36830, 39710,
42750, 46000, 49500, 53000, 56500,
60000, 63500, 67000, 70500, 74000,
}

var unstuckMap = map[string]float64{
"LocX": 367983.1875,
"LocY": -452051.0625,
"LocZ": -81909.851562,
"Pitch": 0.0,
"Yaw": 79.999962,
"Roll": 0.0,
}

var resolveHouse = map[string]string{
"gryffindor": "Gryffindor",
"ravenclaw": "Ravenclaw",
"hufflepuff": "Hufflepuff",
"slytherin": "Slytherin",
}

func containsItemId(parsed []*ItemPairs, itemId string) bool {
for _, pair := range parsed {
if pair.ItemID == itemId {
Expand Down Expand Up @@ -100,6 +82,70 @@ func parseInvPairs(pairs []string) ([]*ItemPairs, error) {
return parsed, nil
}


func parseWand(args *Args) (*Wand, error) {
var wand Wand
errTemp := "invalid wand %s"

if args.WandBase != "" {
base, ok := resolveWandParts["bases"][strings.ToLower(args.WandBase)]
if !ok {
return nil, fmt.Errorf(errTemp, "base")
}
wand.Base = base
}

if args.WandWood != "" {
wood, ok := resolveWandParts["wood"][strings.ToLower(args.WandWood)]
if !ok {
return nil, fmt.Errorf(errTemp, "wood")
}
wand.Wood = wood
}

if args.WandCore != "" {
core, ok := resolveWandParts["cores"][strings.ToLower(args.WandCore)]
if !ok {
return nil, fmt.Errorf(errTemp, "core")
}
wand.Core = core
}

if args.WandLength != "" {
length, ok := resolveWandParts["lengths"][strings.ToLower(args.WandLength)]
if !ok {
return nil, fmt.Errorf(errTemp, "length")
}
wand.Length = length
}

// if args.WandStyle != "" {
// invalidStyle := fmt.Errorf(errTemp, "style")
// fullStyle := strings.ToLower(args.WandStyle)
// split := strings.SplitN(fullStyle, "_", 4)
// splitLen := len(split)
// if splitLen != 2 && splitLen != 4 {
// return nil, invalidStyle
// }
// base := strings.Join(split[:2], "_")
// baseRes, ok := resolveWandParts["bases"][base]
// if !ok {
// return nil, invalidStyle
// }
// if splitLen == 4 {
// style := strings.Join(split[2:], "_")
// styleRes, ok := resolveWandParts["styles"][style]
// if !ok {
// return nil, invalidStyle
// }
// wand.Style = baseRes + "_" + styleRes
// } else {
// wand.Style = baseRes
// }
// }
return &wand, nil
}

func parseArgs() (*Args, error) {
var args Args
arg.MustParse(&args)
Expand All @@ -113,6 +159,9 @@ func parseArgs() (*Args, error) {
if args.XP < 0 {
return nil, errors.New("xp can't be negative")
}
if args.XP > 99999999 {
return nil, errors.New("xp can't be more than 99999999")
}
if args.Galleons < 0 {
return nil, errors.New("galleons can't be negative")
}
Expand All @@ -121,13 +170,30 @@ func parseArgs() (*Args, error) {
return nil, errors.New("inventory size can't be less than 20")
}

if args.XP > 0 && args.Level > 0 {
return nil, errors.New("xp and level args can't both be provided")
}

if args.Level > 0 {
if !(args.Level >= 1 && args.Level <= 40) {
return nil, errors.New("level must be between 1 and 40")
} else {
args.XP = xps[args.Level-1]
}
}

noArgs := !args.Probe && !args.Unstuck && !args.DumpDB &&
!args.InjectDB && !args.ResetTalentPoints && args.XP == 0 &&
args.Galleons == 0 && args.InventorySize == 0 &&
args.TalentPoints == 0 && len(args.ItemQuantities) < 1 &&
args.House == "" && args.FirstName == "" &&
args.Level == 0 && args.House == "" && args.FirstName == "" &&
args.Surname == ""
if noArgs {

noWandArgs := args.WandBase == "" && args.WandWood == "" &&
args.WandCore == "" && args.WandLength == "" &&
args.WandFlex == ""

if noArgs && noWandArgs {
return nil, errors.New("no write arguments were provided")
}

Expand All @@ -152,11 +218,16 @@ func parseArgs() (*Args, error) {
}
inPath := args.InPath
outPath := args.OutPath

args.InPath = outPath
args.OutPath = inPath
}

wand, err := parseWand(&args)
if err != nil {
return nil, err
}
args.Wand = wand

if args.OutPath == "" {
args.OutPath = args.InPath
}
Expand Down Expand Up @@ -265,7 +336,8 @@ func writeSave(updatedDbBytes, saveData []byte, imageStrStart, dbEndOffset int,

func writeToDb(db *sql.DB, args *Args) error {
defer db.Close()
if args.XP > 0 {

if args.XP > 0 || args.Level > 0 {
err := updateRow(db, fmt.Sprintf(queries["xp"], args.XP))
if err != nil {
return err
Expand Down Expand Up @@ -307,7 +379,6 @@ func writeToDb(db *sql.DB, args *Args) error {
}
}


if len(args.ItemQuantities) > 0 {
for _, pair := range args.ParsedItemQuants {
err := updateRow(db, fmt.Sprintf(queries["inventory_quant"], pair.Quantity, pair.ItemID))
Expand Down Expand Up @@ -336,6 +407,53 @@ func writeToDb(db *sql.DB, args *Args) error {
return err
}
}

wand := args.Wand

if wand.Base != "" {
for _, dataName := range [2]string{"WandBase", "WandStyle"} {
err := updateRow(db, fmt.Sprintf(queries["wand"], wand.Base, dataName))
if err != nil {
return err
}
}
}

if wand.Wood != "" {
err := updateRow(db, fmt.Sprintf(queries["wand"], wand.Wood, "WandWood"))
if err != nil {
return err
}
}

if wand.Core != "" {
err := updateRow(db, fmt.Sprintf(queries["wand"], wand.Core, "WandCore"))
if err != nil {
return err
}
}

if wand.Length != "" {
err := updateRow(db, fmt.Sprintf(queries["wand"], wand.Length, "WandLength"))
if err != nil {
return err
}
}

if wand.Flex != "" {
err := updateRow(db, fmt.Sprintf(queries["wand"], wand.Flex, "WandFlex"))
if err != nil {
return err
}
}

// if wand.Style != "" {
// err := updateRow(db, fmt.Sprintf(queries["wand"], wand.Style, "WandStyle"))
// if err != nil {
// return err
// }
// }

return nil
}

Expand Down
Loading

0 comments on commit 40bd4dd

Please sign in to comment.