You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: ds1.go
    path of file: ./repos/OpenDiablo2/d2common/d2fileformats/d2ds1
    
    the code of the file until where you have to start completion: package d2ds1

import (
	"fmt"

	"github.com/OpenDiablo2/OpenDiablo2/d2common/d2datautils"
	"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
	"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
	"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector"
	"github.com/OpenDiablo2/OpenDiablo
    
func (ds1 *DS1) loadSubstitutions(br *d2datautils.StreamReader) error {
	var err error

	hasSubstitutions := ds1.version.hasSubstitutions() &&
		(ds1.SubstitutionType == subType1 || ds1.SubstitutionType == subType2)

	if !hasSubstitutions {
		ds1.SubstitutionGroups = make([]SubstitutionGroup, 0)
		return nil
	}

	if ds1.version.hasUnknown2Bytes() {
		ds1.unknown2, err = br.ReadUInt32()
		if err != nil {
			return fmt.Errorf("reading unknown 2: %w", err)
		}
	}

	numberOfSubGroups, err := br.ReadInt32()
	if err != nil {
		return fmt.Errorf("reading number of sub groups: %w", err)
	}

	ds1.SubstitutionGroups = make([]SubstitutionGroup, numberOfSubGroups)

	for subIdx := 0; subIdx < int(numberOfSubGroups); subIdx++ {
		newSub := SubstitutionGroup{}

		newSub.TileX, err = br.ReadInt32()
		if err != nil {
			return fmt.Errorf("reading substitution's %d X: %v", subIdx, err)
		}

		newSub.TileY, err = br.ReadInt32()
		if err != nil {
			return fmt.Errorf("reading substitution's %d Y: %v", subIdx, err)
		}

		newSub.WidthInTiles, err = br.ReadInt32()
		if err != nil {
			return fmt.Errorf("reading substitution's %d W: %v", subIdx, err)
		}

		newSub.HeightInTiles, err = br.ReadInt32()
		if err != nil {
			return fmt.Errorf("reading substitution's %d H: %v", subIdx, err)
		}

		newSub.Unknown, err = br.ReadInt32()
		if err != nil {
			return fmt.Errorf("reading substitution's %d unknown: %v", subIdx, err)
		}

		ds1.SubstitutionGroups[subIdx] = newSub
	}

	return err
}