cmd

package
v1.0.31 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2021 License: MIT Imports: 25 Imported by: 1

Documentation

Overview

Copyright © 2020 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2020 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2020 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2020 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var ConvertCmd = &cobra.Command{
	Use:   "convert",
	Short: "Convert an item from gibbed to digital_marine or vice versa",
	Args:  cobra.MaximumNArgs(2),
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) > 0 {
			if len(args) > 1 {
				literals = append(literals, args[0]+" "+args[1])
			} else {
				literals = append(literals, args[0])
			}
		}

		queue := make(chan string)
		done := sync.WaitGroup{}

		done.Add(1)
		go func() {
			for literal := range queue {
				c, err := convert(literal)
				if err != nil {
					cmd.PrintErr(err)
					return
				}
				cmd.Println(c)
			}
			done.Done()
		}()

		for _, literal := range literals {
			queue <- literal
		}

		for _, file := range files {
			var reader io.Reader
			var err error
			if file != "-" {
				reader, err = os.Open(file)
				if err != nil {
					cmd.PrintErr(err)
					return
				}
			} else {
				reader = os.Stdin
			}
			scanner := bufio.NewScanner(reader)
			for scanner.Scan() {
				queue <- scanner.Text()
			}
			if err := scanner.Err(); err != nil {
				cmd.PrintErr(err)
				return
			}
			if f, ok := reader.(*os.File); ok {
				err = f.Close()
				if err != nil {
					cmd.PrintErr(err)
					return
				}
			}
		}
		close(queue)
		done.Wait()
	},
}

deserializeCmd represents the deserialize command

View Source
var DecryptCommand = &cobra.Command{
	Use:   "decrypt",
	Short: "decrypt a file",
	Args:  cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		f, err := os.Open(args[0])
		if err != nil {
			panic(err)
		}
		defer f.Close()
		var d []byte
		if fileType == "character" {
			_, d = character.Decrypt(f, "pc")
		} else if fileType == "profile" {
			_, d = profile.Decrypt(f, "pc")
		} else {
			log.Fatalln("invalid file type")
		}
		_, err = os.Stdout.Write(d)
	},
}
View Source
var DeserializeCmd = &cobra.Command{
	Use:   "deserialize",
	Short: "Deserialize a .sav file.",
	Long: `Deserialize a .sav file.

Tries to best-guess the sav file format (profile or character) based on the files name.
Override with --format <profile|character>
`,
	Args: cobra.ExactArgs(1),
	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
		if format != "" {
			if format == "profile" {
				isProfile = true
			} else if format == "character" {
				isProfile = false
			} else {
				return errors.New("unknown format option")
			}
		} else {
			isProfile = shared.GuessIsProfileSav(args[0])
		}
		return nil
	},
	Run: func(cmd *cobra.Command, args []string) {
		f, err := os.Open(args[0])
		if err != nil {
			panic(err)
		}

		if isProfile {
			s, p, err := profile.Deserialize(f, "pc")
			if err != nil {
				panic(err)
			}
			r := struct {
				Sav     shared.SavFile
				Profile pb.Profile
			}{s, p}
			bs, err := yaml.Marshal(r)
			if err != nil {
				panic(err)
			}
			fmt.Print(string(bs))
		} else {
			s, c, err := character.Deserialize(f, "pc")
			if err != nil {
				panic(err)
			}
			r := struct {
				Sav       shared.SavFile
				Character pb.Character
			}{s, c}
			bs, err := yaml.Marshal(r)
			if err != nil {
				panic(err)
			}
			fmt.Print(string(bs))
		}

	},
}

deserializeCmd represents the deserialize command

View Source
var ItemsCommand = &cobra.Command{
	Use:  "items",
	Args: cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {

		f, err := os.Open(args[0])
		if err != nil {
			cmd.PrintErrf("couldn't open character: %v\n", err)
		}
		s, c, err := character.Deserialize(f, "pc")
		if err != nil {
			cmd.PrintErr(err)
			return
		}
		err = f.Close()
		if err != nil {
			cmd.PrintErr(err)
			return
		}

		for _, file := range files {
			var reader io.Reader
			var err error
			if file != "-" {
				reader, err = os.Open(file)
				if err != nil {
					cmd.PrintErr(err)
					return
				}
			} else {
				reader = os.Stdin
			}
			scanner := bufio.NewScanner(reader)
			for scanner.Scan() {
				items = append(items, scanner.Text())
			}
			if err := scanner.Err(); err != nil {
				cmd.PrintErr(err)
				return
			}
			if f, ok := reader.(*os.File); ok {
				err = f.Close()
				if err != nil {
					cmd.PrintErr(err)
					return
				}
			}
		}

		for i := range items {
			var anoints = make([]string, 0)
			if parts := strings.Split(items[i], " "); len(parts) > 1 {
				var anointments Anointments
				bs, err := base64.StdEncoding.DecodeString(parts[1])
				if err != nil {
					cmd.PrintErr(err)
					return
				}
				err = json.Unmarshal(bs, &anointments)
				if anointments.CopyType != "anointment" {
					cmd.PrintErrln("not a valid anointment code")
					return
				}
				for _, i := range anointments.Components {
					anoints = append(anoints, item.DmKeyToInvKey(anointments.ComponentNames[i],
						assets.GetDB().GetData("InventoryGenericPartData").Assets))
				}
				items[i] = parts[0]
			}
			if strings.HasPrefix(items[i], "bl3(") || strings.HasPrefix(items[i], "BL3(") {

			} else {

				bs, err := base64.StdEncoding.DecodeString(items[i])
				if err != nil {
					cmd.PrintErr(err)
					return
				}
				var dmi item.DigitalMarineItem
				err = json.Unmarshal(bs, &dmi)
				if err == nil {
					gi := item.DmToGibbed(dmi)
					bs, err = item.Serialize(gi, 0)
					if err != nil {
						cmd.PrintErr(err)
						return
					}
					items[i] = hex.EncodeToString(bs)
				}

			}

			items[i] = strings.TrimPrefix(items[i], "bl3(")
			items[i] = strings.TrimPrefix(items[i], "BL3(")
			items[i] = strings.TrimSuffix(items[i], ")")

			bs, err := base64.StdEncoding.DecodeString(items[i])
			if err != nil {
				cmd.PrintErr(err)
				return
			}

			bsc := make([]byte, len(bs))
			copy(bsc, bs)
			current, err := item.Deserialize(bsc)
			if err != nil {
				cmd.PrintErr(err)
				return
			}
			current.Generics = append(current.Generics, anoints...)
			bs, err = item.Serialize(current, 0)
			if err != nil {
				cmd.PrintErr(err)
				return
			}
			c.InventoryItems = append(c.InventoryItems, &pb.OakInventoryItemSaveGameData{
				ItemSerialNumber:    bs,
				PickupOrderIndex:    200,
				Flags:               1,
				WeaponSkinPath:      "",
				DevelopmentSaveData: nil,
			})
		}

		f, err = os.Create(args[0])
		if err != nil {
			cmd.PrintErrf("couldn't create character: %v\n", err)
		}
		character.Serialize(f, s, c, "pc")
		err = f.Close()
		if err != nil {
			cmd.PrintErr(err)
			return
		}

	},
}

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func StringToAsciiBytes added in v1.0.15

func StringToAsciiBytes(s string) []byte

Types

type Anointments added in v1.0.11

type Anointments struct {
	CopyType       string   `json:"copyType"`
	ComponentNames []string `json:"componentNames"`
	Components     []int    `json:"components"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL