An unofficial collection of APIs used in FreeJam games and mods
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
4.0KB

  1. use std::io::Read;
  2. use crate::techblox::{Parsable, SerializedEntityDescriptor};
  3. use crate::techblox::blocks::*;
  4. const HASHNAMES: &[&str] = &[
  5. // Block group info entities
  6. "BlockGroupEntityDescriptorV0",
  7. // Block entities
  8. "StandardBlockEntityDescriptorV4",
  9. "BatteryEntityDescriptorV4",
  10. "MotorEntityDescriptorV7",
  11. "LeverEntityDescriptorV7",
  12. "ButtonEntityDescriptorV6",
  13. "JointBlockEntityDescriptorV3",
  14. "ServoEntityDescriptorV7",
  15. "PistonEntityDescriptorV6",
  16. "DampedSpringEntityDescriptorV5",
  17. "DampedAngularSpringEntityDescriptorV4",
  18. "SpawnPointEntityDescriptorV6",
  19. "BuildingSpawnPointEntityDescriptorV4",
  20. "TriggerEntityDescriptorV6",
  21. "PilotSeatEntityDescriptorV4",
  22. "PilotSeatEntityDescriptorV3",
  23. "TextBlockEntityDescriptorV4",
  24. "PassengerSeatEntityDescriptorV4",
  25. "PassengerSeatEntityDescriptorV3",
  26. "LogicBlockEntityDescriptorV1",
  27. "TyreEntityDescriptorV1",
  28. "ObjectIDEntityDescriptorV1",
  29. "MoverEntityDescriptorV1",
  30. "RotatorEntityDescriptorV1",
  31. "DamperEntityDescriptorV1",
  32. "AdvancedDamperEntityDescriptorV1",
  33. "CoMEntityDescriptor",
  34. "FilterBlockEntityDescriptorV1",
  35. "ConstrainerEntityDescriptorV1",
  36. "NumberToTextBlockEntityDescriptorV1",
  37. "CentreHudBlockEntityDescriptorV1",
  38. "ObjectiveHudBlockEntityDescriptorV1",
  39. "GameStatsHudBlockEntityDescriptorV1",
  40. "GameOverHudBlockEntityDescriptorV1",
  41. "TimerBlockEntityDescriptorV1",
  42. "BitBlockEntityDescriptorV2",
  43. "ConstantBlockEntityDescriptor",
  44. "CounterBlockEntityDescriptorV1",
  45. "SimpleSfxEntityDescriptorV1",
  46. "LoopedSfxEntityDescriptorV1",
  47. "MusicBlockEntityDescriptorV1",
  48. "ProjectileBlockEntityDescriptorV1",
  49. "DamagingSurfaceEntityDescriptorV1",
  50. "DestructionManagerEntityDescriptorV1",
  51. "ChunkDestructionBlockEntityDescriptorV1",
  52. "ClusterDestructionBlockEntityDescriptorV1",
  53. "PickupBlockEntityDescriptorV1",
  54. "PointLightEntityDescriptorV1",
  55. "SpotLightEntityDescriptorV1",
  56. "SunLightEntityDescriptorV1",
  57. "AmbientLightEntityDescriptorV1",
  58. "FogEntityDescriptorV1",
  59. "SkyEntityDescriptorV1",
  60. "SynchronizedWireBlockEntityDescriptor",
  61. "WheelRigEntityDescriptor",
  62. "WheelRigSteerableEntityDescriptor",
  63. "EngineBlockEntityDescriptor",
  64. // Other Non-block entities (stored after blocks in game saves)
  65. "WireEntityDescriptorMock",
  66. "GlobalWireSettingsEntityDescriptor",
  67. "FlyCamEntityDescriptorV0",
  68. "CharacterCameraEntityDescriptorV1",
  69. ];
  70. pub fn lookup_hashname(hash: u32, data: &mut dyn Read) -> std::io::Result<Box<dyn SerializedEntityDescriptor>> {
  71. Ok(match hash {
  72. 1357220432 /*StandardBlockEntityDescriptorV4*/ => Box::new(BlockEntity::parse(data)?),
  73. 2281299333 /*PilotSeatEntityDescriptorV4*/ => Box::new(PilotSeatEntity::parse(data)?),
  74. 1360086092 /*PassengerSeatEntityDescriptorV4*/ => Box::new(PassengerSeatEntity::parse(data)?),
  75. 1757314505 /*EngineBlockEntityDescriptor*/ => Box::new(EngineBlockEntity::parse(data)?),
  76. 3586818581 /*JointBlockEntityDescriptorV3*/ => Box::new(JointBlockEntity::parse(data)?),
  77. 3789998433 /*DampedAngularSpringEntityDescriptorV4*/ => Box::new(DampedAngularSpringEntity::parse(data)?),
  78. 2892049599 /*DampedSpringEntityDescriptorV5*/ => Box::new(DampedSpringEntity::parse(data)?),
  79. 1156723746 /*WheelRigEntityDescriptor*/ => Box::new(WheelRigEntity::parse(data)?),
  80. 1864425618 /*WheelRigSteerableEntityDescriptor*/ => Box::new(WheelRigSteerableEntity::parse(data)?),
  81. 1517625162 /*TyreEntityDescriptorV1*/ => Box::new(TyreEntity::parse(data)?),
  82. _ => {
  83. #[cfg(debug_assertions)]
  84. println!("Unknown hash ID {} (missing entry for {})", hash, lookup_name_by_hash(hash).unwrap_or("<Unknown>"));
  85. return Err(std::io::Error::new(std::io::ErrorKind::Other, format!("Unrecognised hash {}", hash)))
  86. }
  87. })
  88. }
  89. pub fn lookup_name_by_hash(hash: u32) -> Option<&'static str> {
  90. for name in HASHNAMES {
  91. if crate::techblox::hashname(name) == hash {
  92. return Some(name);
  93. }
  94. }
  95. None
  96. }