func td6Handler(directory string, templateDirectory string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { iterPath := strings.Replace(r.URL.Path, "/td6", "", 1) m, err := loadMember(directory, iterPath) if err != nil { w.WriteHeader(http.StatusBadRequest) w.Write([]byte(err.Error())) return } query := r.URL.Query() completeParam := query.Get("complete") complete := completeParam == "true" // For whatever reason RCT2 needs the extension to be in uppercase shortName := fmt.Sprintf("%s.TD6", truncate(17, m.Id)) w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", shortName)) w.Header().Set("Content-Type", "text/td6") ride := td6.CreateMineTrainRide(m.Track, complete) for i := 0; i < len(ride.TrackData.Elements); i++ { fmt.Println(tracks.ElementNames[ride.TrackData.Elements[i].Segment.Type]) } bits, err := td6.Marshal(ride) paddedBits := td6.Pad(bits) rleWriter := rle.NewWriter(w) if err != nil { w.WriteHeader(http.StatusBadRequest) w.Write([]byte(err.Error())) return } w.WriteHeader(http.StatusOK) rleWriter.Write(paddedBits) } }
func main() { ride := td6.ReadRide("rides/mine-train-gold-rush.td6") bits, err := td6.Marshal(ride) if err != nil { log.Fatal(err) } writer := rle.NewWriter(os.Stdout) writer.Write(bits) }
func main() { usage := "Invalid arguments. Usage: encode_td6 filename" flag.Parse() args := flag.Args() if len(args) != 1 { log.Fatal(usage) } filename := args[0] bits, err := ioutil.ReadFile(filename) if err != nil { log.Fatal(err) } writer := rle.NewWriter(os.Stdout) writer.Write(bits) }
func main() { r := td6.ReadRide("rides/mischief.td6") fmt.Println(r.Excitement) fmt.Println(r.Intensity) fmt.Println(r.Nausea) fmt.Println(r.MaxSpeed) fmt.Println(r.AverageSpeed) fmt.Printf("Track length: %d\n", len(r.TrackData.Elements)) bits, err := td6.Marshal(r) if err != nil { panic(err) } //for i := range bits { //if bits[i] != decrypted[i] { //fmt.Printf("%d: ", i) //fmt.Printf("byte %x differs, in my mischief it is %d, in orig it is %d\n", i, bits[i], decrypted[i]) //} //} if td6.DEBUG { begin := 0xa2 + 2*len(r.TrackData.Elements) - 3 for i := begin; i < begin+td6.DEBUG_LENGTH; i++ { // encode the value of i as hex ds := hex.EncodeToString([]byte{byte(i)}) bitValueInHex := hex.EncodeToString([]byte{bits[i]}) fmt.Printf("%s: %s\n", ds, bitValueInHex) } } paddedBits := td6.Pad(bits) //fmt.Println(paddedBits) //fmt.Println(decrypted) var buf bytes.Buffer w := rle.NewWriter(&buf) w.Write(paddedBits) ioutil.WriteFile("/Users/kevin/Applications/Wineskin/rct2.app/Contents/Resources/drive_c/GOG Games/RollerCoaster Tycoon 2 Triple Thrill Pack/Tracks/mymischief.TD6", buf.Bytes(), 0644) fmt.Println("Wrote rides/mischief.td6.out.") }