class_fakeplayer.lua 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. -- The purpose of this class is to have something that can be passed into callbacks that
  2. -- demand a "Player" object as a parameter and hopefully prevent the mods that have
  3. -- registered with those callbacks from crashing on a nil dereference or bad function
  4. -- call. This is not supposed to be a remotely functional thing, it's just supposed
  5. -- to provide dummy methods and return values of the correct data type for anything that
  6. -- might ignore the false "is_player()" return and go ahead and try to use this thing
  7. -- anyway.
  8. -- I'm trying to patch holes in bad mod programming, essentially. If a mod is so badly
  9. -- programmed that it crashes anyway there's not a lot else I can do on my end of things.
  10. local FakePlayer = {}
  11. FakePlayer.__index = FakePlayer
  12. local function return_value(x)
  13. return (function() return x end)
  14. end
  15. local function return_nil()
  16. return nil
  17. end
  18. local function return_empty_string()
  19. return ""
  20. end
  21. local function return_zero()
  22. return 0
  23. end
  24. local function return_empty_table()
  25. return {}
  26. end
  27. function FakePlayer.update(self, pos, player_name)
  28. self.is_fake_player = player_name
  29. self.get_pos = return_value(pos)
  30. end
  31. function FakePlayer.create(pos, player_name)
  32. local self = {}
  33. setmetatable(self, FakePlayer)
  34. self.is_fake_player = player_name
  35. -- ObjectRef
  36. self.get_pos = return_value(pos)
  37. self.set_pos = return_nil
  38. self.move_to = return_nil
  39. self.punch = return_nil
  40. self.right_click = return_nil
  41. self.get_hp = return_value(10)
  42. self.set_hp = return_nil
  43. self.get_inventory = return_nil -- returns an `InvRef`
  44. self.get_wield_list = return_empty_string
  45. self.get_wield_index = return_value(1)
  46. self.get_wielded_item = return_value(ItemStack(nil))
  47. self.set_wielded_item = return_value(false)
  48. self.set_armor_groups = return_nil
  49. self.get_armor_groups = return_empty_table
  50. self.set_animation = return_nil
  51. self.get_animation = return_nil -- a set of values, maybe important?
  52. self.set_attach = return_nil
  53. self.get_attach = return_nil
  54. self.set_detach = return_nil
  55. self.set_bone_position = return_nil
  56. self.get_bone_position = return_nil
  57. self.set_properties = return_nil
  58. self.get_properties = return_empty_table
  59. self.is_player = return_value(false)
  60. self.get_nametag_attributes = return_empty_table
  61. self.set_nametag_attributes = return_nil
  62. --LuaEntitySAO
  63. self.set_velocity = return_nil
  64. self.get_velocity = return_value({x=0,y=0,z=0})
  65. self.set_acceleration = return_nil
  66. self.get_acceleration = return_value({x=0,y=0,z=0})
  67. self.set_yaw = return_nil
  68. self.get_yaw = return_zero
  69. self.set_texture_mod = return_nil
  70. self.get_texture_mod = return_nil -- maybe important?
  71. self.set_sprite = return_nil
  72. --self.get_entity_name` (**Deprecated**: Will be removed in a future version)
  73. self.get_luaentity = return_nil
  74. -- Player object
  75. self.get_player_name = return_empty_string
  76. self.get_player_velocity = return_nil
  77. self.get_look_dir = return_value({x=0,y=1,z=0})
  78. self.get_look_horizontal = return_zero
  79. self.set_look_horizontal = return_nil
  80. self.get_look_vertical = return_zero
  81. self.set_look_vertical = return_nil
  82. --self.get_look_pitch`: pitch in radians - Deprecated as broken. Use `get_look_vertical`
  83. --self.get_look_yaw`: yaw in radians - Deprecated as broken. Use `get_look_horizontal`
  84. --self.set_look_pitch(radians)`: sets look pitch - Deprecated. Use `set_look_vertical`.
  85. --self.set_look_yaw(radians)`: sets look yaw - Deprecated. Use `set_look_horizontal`.
  86. self.get_breath = return_value(10)
  87. self.set_breath = return_nil
  88. self.get_attribute = return_nil
  89. self.set_attribute = return_nil
  90. self.set_inventory_formspec = return_nil
  91. self.get_inventory_formspec = return_empty_string
  92. self.get_player_control = return_value({jump=false, right=false, left=false, LMB=false, RMB=false, sneak=false, aux1=false, down=false, up=false} )
  93. self.get_player_control_bits = return_zero
  94. self.set_physics_override = return_nil
  95. self.get_physics_override = return_value({speed = 1, jump = 1, gravity = 1, sneak = true, sneak_glitch = false, new_move = true,})
  96. self.hud_add = return_nil
  97. self.hud_remove = return_nil
  98. self.hud_change = return_nil
  99. self.hud_get = return_nil -- possibly important return value?
  100. self.hud_set_flags = return_nil
  101. self.hud_get_flags = return_value({ hotbar=true, healthbar=true, crosshair=true, wielditem=true, breathbar=true, minimap=true })
  102. self.hud_set_hotbar_itemcount = return_nil
  103. self.hud_get_hotbar_itemcount = return_zero
  104. self.hud_set_hotbar_image = return_nil
  105. self.hud_get_hotbar_image = return_empty_string
  106. self.hud_set_hotbar_selected_image = return_nil
  107. self.hud_get_hotbar_selected_image = return_empty_string
  108. self.set_sky = return_nil
  109. self.get_sky = return_empty_table -- may need members on this table
  110. self.set_clouds = return_nil
  111. self.get_clouds = return_value({density = 0, color = "#fff0f0e5", ambient = "#000000", height = 120, thickness = 16, speed = {x=0, y=-2}})
  112. self.override_day_night_ratio = return_nil
  113. self.get_day_night_ratio = return_nil
  114. self.set_local_animation = return_nil
  115. self.get_local_animation = return_empty_table
  116. self.set_eye_offset = return_nil
  117. self.get_eye_offset = return_value({x=0,y=0,z=0},{x=0,y=0,z=0})
  118. return self
  119. end
  120. return FakePlayer