Beispiel #1
0
func ReadRide(filename string) *Ride {
	encodedBits, err := ioutil.ReadFile(filename)
	bitsWithoutChecksum := encodedBits[:len(encodedBits)-4]

	if err != nil {
		panic(err)
	}
	z := rle.NewReader(bytes.NewReader(bitsWithoutChecksum))
	if err != nil {
		panic(err)
	}
	var bitbuffer bytes.Buffer
	bitbuffer.ReadFrom(z)
	decrypted := bitbuffer.Bytes()

	// r is a pointer
	r := new(Ride)
	Unmarshal(decrypted, r)

	if DEBUG {
		begin := 0xa2 + 2*len(r.TrackData.Elements) - 3
		for i := begin; i < begin+DEBUG_LENGTH; i++ {
			// encode the value of i as hex
			if i > len(decrypted) {
				continue
			}
			ds := hex.EncodeToString([]byte{byte(i)})
			bitValueInHex := hex.EncodeToString([]byte{decrypted[i]})
			fmt.Printf("%s: %s\n", ds, bitValueInHex)
		}
	}

	return r
}
Beispiel #2
0
Datei: td4.go Projekt: silky/rct
func readRaptor() Ride {
	encodedBits, err := ioutil.ReadFile("rides/raptor.td4")
	if err != nil {
		panic(err)
	}
	z := rle.NewReader(bytes.NewReader(encodedBits))
	if err != nil {
		panic(err)
	}
	var bitbuffer bytes.Buffer
	bitbuffer.ReadFrom(z)
	decrypted := bitbuffer.Bytes()
	for i := 0; i < 40; i++ {
		// encode the value of i as hex
		ds := hex.EncodeToString([]byte{byte(i)})
		bitValueInHex := hex.EncodeToString([]byte{decrypted[i]})
		fmt.Printf("%s: %s\n", ds, bitValueInHex)
	}

	// r is a pointer
	r := new(Ride)
	Unmarshal(decrypted, r)
	bits, err := Marshal(r)
	fmt.Println(bits)
	return *r
}
Beispiel #3
0
func main() {
	filename := flag.String("filename", "", "td6 file to decode")
	flag.Parse()
	if *filename == "" {
		log.Fatal("please enter a filename")
	}
	f, err := os.Open(*filename)
	if err != nil {
		log.Fatal(err)
	}
	reader := rle.NewReader(f)
	// xxx is there a better way to do this?
	rr := io.TeeReader(reader, os.Stdout)
	var bitbuffer bytes.Buffer
	bitbuffer.ReadFrom(rr)
}