Skip to content

Commit

Permalink
Rudimentary support for Source SDK 2013 MP Staticprops
Browse files Browse the repository at this point in the history
  • Loading branch information
Galaco committed May 28, 2023
1 parent 0df6c0f commit d8a9f6f
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 11 deletions.
37 changes: 29 additions & 8 deletions lumps/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,35 @@ func (lump *Game) GetStaticPropLump() *primitives.StaticPropLump {
props[idx] = primitives.IStaticPropDataLump(&vprops[idx])
}
case 10:
propLumpSize = 76 * int(numProps)
vprops := make([]primitives.StaticPropV10, numProps)
err = binary.Read(bytes.NewBuffer(sprpLump.Data[offset:offset+propLumpSize]), binary.LittleEndian, &vprops)
if err != nil {
return nil
}
for idx := range vprops {
props[idx] = primitives.IStaticPropDataLump(&vprops[idx])
// This switch is a major hackjob to avoid the need to know what game the bsp is for.
// Because Valve in all their wisdom have multiple DIFFERENT v10 formats (a true v10,
// and the MP2013 updated v6 which is REPORTED as v10 as well) we can attempt to infer
// which format it actually is.
switch {
case offset+(int(unsafe.Sizeof(primitives.StaticPropV10{}))*int(numProps)) <= len(sprpLump.Data):
// Real v10 format
propLumpSize = int(unsafe.Sizeof(primitives.StaticPropV10{})) * int(numProps)
vprops := make([]primitives.StaticPropV10, numProps)
err = binary.Read(bytes.NewBuffer(sprpLump.Data[offset:offset+propLumpSize]), binary.LittleEndian, &vprops)
if err != nil {
return nil
}
for idx := range vprops {
props[idx] = primitives.IStaticPropDataLump(&vprops[idx])
}
case offset+(int(unsafe.Sizeof(primitives.StaticPropV10MP2013{}))*int(numProps)) <= len(sprpLump.Data):
// Fake v7* 2013MP format.
propLumpSize = int(unsafe.Sizeof(primitives.StaticPropV10MP2013{})) * int(numProps)
vprops := make([]primitives.StaticPropV10MP2013, numProps)
err = binary.Read(bytes.NewBuffer(sprpLump.Data[offset:offset+propLumpSize]), binary.LittleEndian, &vprops)
if err != nil {
return nil
}
for idx := range vprops {
props[idx] = primitives.IStaticPropDataLump(&vprops[idx])
}
default:
panic("staticpropdata doesn't correspond to a known v10 format")
}
case 11:
vprops := make([]primitives.StaticPropV11, numProps)
Expand Down
6 changes: 3 additions & 3 deletions primitives/game/staticpropv10.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ type StaticPropV10 struct {
DiffuseModulation float32
DisableXBox360 bool
ExtraFlags int32
_ byte
_ byte
_ byte
_ byte
_ byte
_ byte
}

// GetOrigin Origin of object in world
Expand Down
147 changes: 147 additions & 0 deletions primitives/game/staticpropv10MP2013.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package game

import (
"github.com/go-gl/mathgl/mgl32"
)

// StaticPropV10MP2013 v6 type
type StaticPropV10MP2013 struct {
Origin mgl32.Vec3
Angles mgl32.Vec3
PropType uint16
FirstLeaf uint16
LeafCount uint16
Solid uint8
_ byte
Skin int32
FadeMinDist float32
FadeMaxDist float32
LightingOrigin mgl32.Vec3
ForcedFadeScale float32
MinDXLevel uint16
MaxDXLevel uint16
Flags uint8
_ byte
LightmapResX uint16 // lightmap image width
LightmapResY uint16 // lightmap image height
_ [2]byte
}

// GetOrigin origin of object in world
func (l *StaticPropV10MP2013) GetOrigin() mgl32.Vec3 {
return l.Origin
}

// GetAngles rotation of object in world
func (l *StaticPropV10MP2013) GetAngles() mgl32.Vec3 {
return l.Angles
}

// GetUniformScale is always 1 (i.e. 1x scale multiplier)
// Not defined in v6
func (l *StaticPropV10MP2013) GetUniformScale() float32 {
return 1
}

// GetPropType prop type
func (l *StaticPropV10MP2013) GetPropType() uint16 {
return l.PropType
}

// GetFirstLeaf index into StaticPropLeafLump
func (l *StaticPropV10MP2013) GetFirstLeaf() uint16 {
return l.FirstLeaf
}

// GetLeafCount number of leafs this prop is in
func (l *StaticPropV10MP2013) GetLeafCount() uint16 {
return l.LeafCount
}

// GetSolid is solid
func (l *StaticPropV10MP2013) GetSolid() uint8 {
return l.Solid
}

// GetFlags prop flags
func (l *StaticPropV10MP2013) GetFlags() uint8 {
return 0
}

// GetSkin skin index of this prop (default 0)
func (l *StaticPropV10MP2013) GetSkin() int32 {
return l.Skin
}

// GetFadeMinDist distance from prop that it starts to fade
func (l *StaticPropV10MP2013) GetFadeMinDist() float32 {
return l.FadeMinDist
}

// GetFadeMaxDist distance from prop that it is fully invisible/not rendered
func (l *StaticPropV10MP2013) GetFadeMaxDist() float32 {
return l.FadeMaxDist
}

// GetLightingOrigin world position to sample light from.
// This may differ from prop origin
func (l *StaticPropV10MP2013) GetLightingOrigin() mgl32.Vec3 {
return l.LightingOrigin
}

// GetForcedFadeScale
func (l *StaticPropV10MP2013) GetForcedFadeScale() float32 {
return l.ForcedFadeScale
}

// GetMinDXLevel Minimum directx level to render this prop
func (l *StaticPropV10MP2013) GetMinDXLevel() uint16 {
return l.MinDXLevel
}

// GetMaxDXLevel Maximum directx level to render this prop
func (l *StaticPropV10MP2013) GetMaxDXLevel() uint16 {
return l.MaxDXLevel
}

// GetMinCPULevel Minimum CPU type to render this prop
// Not defined in v6
func (l *StaticPropV10MP2013) GetMinCPULevel() uint8 {
return 0
}

// GetMaxCPULevel maximum cpu to render
// Not defined in v6
func (l *StaticPropV10MP2013) GetMaxCPULevel() uint8 {
return 0
}

// GetMinGPULevel minimum GPU to render
// Not defined in v6
func (l *StaticPropV10MP2013) GetMinGPULevel() uint8 {
return 0
}

// GetMaxGPULevel Maximum GPU to render
// Not defined in v6
func (l *StaticPropV10MP2013) GetMaxGPULevel() uint8 {
return 0
}

// GetDiffuseModulation
// Not defined in v6
func (l *StaticPropV10MP2013) GetDiffuseModulation() float32 {
return 0
}

// GetUnknown
// Not defined in v6
func (l *StaticPropV10MP2013) GetUnknown() float32 {
return 0
}

// GetDisableXBox360 should disable on XBox 360
// Not defined in v6
func (l *StaticPropV10MP2013) GetDisableXBox360() bool {
return false
}

0 comments on commit d8a9f6f

Please sign in to comment.