Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.37 KB | None | 0 0
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using Addon;
  4.  
  5. namespace ReadyUP
  6. {
  7. public class Class1 : CPlugin
  8. {
  9. public int g_speed_var = 0;
  10. public float jump_height_var = 0;
  11. public int fall_damage_var = 0;
  12. public bool fall_damage_enabled = true;
  13. public int gravity_var = 0;
  14.  
  15. IntPtr j_speed = (IntPtr)0x0046F567;
  16. IntPtr j_height = (IntPtr)0x00787240;
  17. IntPtr fallmax = (IntPtr)0x00786E78;
  18. IntPtr fallmin = (IntPtr)0x0076EDFC;
  19. IntPtr gravity = (IntPtr)0x004704FC;
  20.  
  21. [DllImport("kernel32.dll")]
  22. private static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);
  23.  
  24. unsafe public override void OnServerLoad()
  25. {
  26. ServerPrint("Speed plugin loaded. Author: Pozzuh. Version 1.8");
  27.  
  28. if (GetServerCFG("SPEEDPLUGIN", "Speed", "-1") == "-1")
  29. SetServerCFG("SPEEDPLUGIN", "Speed", "190");
  30. if (GetServerCFG("SPEEDPLUGIN", "JumpHeight", "-1") == "-1")
  31. SetServerCFG("SPEEDPLUGIN", "JumpHeight", "39");
  32. if (GetServerCFG("SPEEDPLUGIN", "FallDamage", "-1") == "-1")
  33. SetServerCFG("SPEEDPLUGIN", "FallDamage", "1");
  34. if (GetServerCFG("SPEEDPLUGIN", "Gravity", "-1") == "-1")
  35. SetServerCFG("SPEEDPLUGIN", "Gravity", "800");
  36.  
  37. try
  38. {
  39. g_speed_var = Convert.ToInt32(GetServerCFG("SPEEDPLUGIN", "Speed", "220"));
  40. jump_height_var = Convert.ToInt32(GetServerCFG("SPEEDPLUGIN", "JumpHeight", "240"));
  41. fall_damage_var = Convert.ToInt32(GetServerCFG("SPEEDPLUGIN", "FallDamage", "0"));
  42. gravity_var = Convert.ToInt32(GetServerCFG("SPEEDPLUGIN", "Gravity", "800"));
  43. }
  44. catch (Exception e)
  45. {
  46. ServerPrint("invalid speed, jump height, fall damage or gravity value...");
  47. }
  48.  
  49. makeSpeedHappy();
  50. makeJumpHeightHappy();
  51. makeGravityHappy();
  52.  
  53. g_Speed(g_speed_var);
  54. jump_height(jump_height_var);
  55. g_gravity(gravity_var);
  56.  
  57. if (fall_damage_var == 0)
  58. disableFallDamage();
  59. }
  60.  
  61. public override unsafe ChatType OnSay(string Message, ServerClient Client)
  62. {
  63. string lowMsg = Message.ToLower();
  64.  
  65. if (lowMsg.StartsWith("!falldamage"))
  66. {
  67. string[] splitMsg = lowMsg.Split(' ');
  68.  
  69. if (splitMsg.Length == 1)
  70. {
  71. if (fall_damage_enabled)
  72. TellClient(Client.ClientNum, "Fall damage is currently enabled.", true);
  73. else
  74. TellClient(Client.ClientNum, "Fall damage is currently disabled.", true);
  75. }
  76. else
  77. {
  78. if (splitMsg[1] == "0")
  79. {
  80. disableFallDamage();
  81. TellClient(Client.ClientNum, "Fall damage is now disabled.", true);
  82. }
  83. else if (splitMsg[1] == "1")
  84. {
  85. enableFallDamage();
  86. TellClient(Client.ClientNum, "Fall damage is now enabled.", true);
  87. }
  88. }
  89.  
  90. return ChatType.ChatNone;
  91. }
  92.  
  93. if (lowMsg.StartsWith("!sp"))
  94. {
  95. string[] splitMsg = lowMsg.Split(' ');
  96.  
  97. if (splitMsg.Length == 1)
  98. TellClient(Client.ClientNum, "Current speed: " + *(int*)j_speed, true);
  99. else
  100. {
  101. try
  102. {
  103. int NewSpeedValue = Convert.ToInt32(splitMsg[1]);
  104. g_Speed(NewSpeedValue);
  105.  
  106. TellClient(Client.ClientNum, "Speed changed to: " + NewSpeedValue + " (default=190)", true);
  107. }
  108. catch (Exception e)
  109. {
  110. TellClient(Client.ClientNum, "^1Invalid speed value!", true);
  111. }
  112. }
  113. return ChatType.ChatNone;
  114. }
  115.  
  116. if (lowMsg.StartsWith("!jh"))
  117. {
  118. string[] splitMsg = lowMsg.Split(' ');
  119.  
  120. if (splitMsg.Length == 1)
  121. TellClient(Client.ClientNum, "^2Current jump height: " + *(float*)j_height, true);
  122. else
  123. {
  124. try
  125. {
  126. float NewJumpHeightValue = (float)Convert.ToInt32(splitMsg[1]);
  127.  
  128. jump_height(NewJumpHeightValue);
  129.  
  130. if (NewJumpHeightValue < 128)
  131. TellClient(Client.ClientNum, "Jump height changed to: " + NewJumpHeightValue, true);
  132. else
  133. {
  134. TellClient(Client.ClientNum, "Jump height changed to: " + NewJumpHeightValue + " (default=39). Fall damage disabled.", true);
  135. disableFallDamage();
  136. }
  137.  
  138. }
  139. catch (Exception e)
  140. {
  141. TellClient(Client.ClientNum, "^1Invalid jump height value!", true);
  142. }
  143. }
  144. return ChatType.ChatNone;
  145. }
  146.  
  147. if (lowMsg.StartsWith("!grav"))
  148. {
  149. string[] splitMsg = lowMsg.Split(' ');
  150.  
  151. if (splitMsg.Length == 1)
  152. TellClient(Client.ClientNum, "Current gravity: " + *(int*)gravity, true);
  153. else
  154. {
  155. try
  156. {
  157. int newGravityValue = Convert.ToInt32(splitMsg[1]);
  158.  
  159. g_gravity(newGravityValue);
  160.  
  161. TellClient(Client.ClientNum, "Gravity changed to: " + newGravityValue + " (default=800).", true);
  162. }
  163. catch (Exception e)
  164. {
  165. TellClient(Client.ClientNum, "^1Invalid gravity value!", true);
  166. }
  167. }
  168. return ChatType.ChatNone;
  169. }
  170.  
  171. return ChatType.ChatContinue;
  172. }
  173.  
  174. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  175. //Stuff needed for speed change
  176. public void makeSpeedHappy()
  177. {
  178. try
  179. {
  180. uint size = 4;
  181. uint newProtect = 0x40;
  182. uint oldProtect = 0;
  183.  
  184. VirtualProtect(j_speed, size, newProtect, out oldProtect);
  185. }
  186. catch (Exception e)
  187. {
  188. ServerLog(LogType.LogConsole, "SPEED PLUGIN ERROR: " + e.ToString());
  189. }
  190. }
  191.  
  192. unsafe public void g_Speed(int value)
  193. {
  194. try
  195. {
  196. *(int*)j_speed = value;
  197. }
  198. catch (Exception e)
  199. {
  200. ServerLog(LogType.LogConsole, "SPEED PLUGIN ERROR: " + e.ToString());
  201. }
  202. }
  203.  
  204. public unsafe void makeJumpHeightHappy()
  205. {
  206. try
  207. {
  208. uint size = 4;
  209. uint newProtect = 0x40;
  210. uint oldProtect = 0;
  211.  
  212. VirtualProtect(j_height, size, newProtect, out oldProtect);
  213. VirtualProtect(fallmin, size, newProtect, out oldProtect);
  214. VirtualProtect(fallmax, size, newProtect, out oldProtect);
  215.  
  216.  
  217. }
  218. catch (Exception e)
  219. {
  220. ServerLog(LogType.LogConsole, "SPEED PLUGIN ERROR: " + e.ToString());
  221. }
  222. }
  223.  
  224. public unsafe void disableFallDamage()
  225. {
  226. fall_damage_enabled = false;
  227. *(float*)fallmin = 999999.0f;
  228. *(float*)fallmax = 1000000.0f;
  229. }
  230.  
  231.  
  232. public unsafe void enableFallDamage()
  233. {
  234. fall_damage_enabled = true;
  235. *(float*)fallmin = 128.0f;
  236. *(float*)fallmax = 300.0f;
  237. }
  238.  
  239. unsafe public void jump_height(float value)
  240. {
  241. try
  242. {
  243. *(float*)j_height = value;
  244. }
  245. catch (Exception e)
  246. {
  247. ServerLog(LogType.LogConsole, "SPEED PLUGIN ERROR: " + e.ToString());
  248. }
  249. }
  250.  
  251. public void makeGravityHappy()
  252. {
  253. try
  254. {
  255. uint size = 4;
  256. uint newProtect = 0x40;
  257. uint oldProtect = 0;
  258.  
  259. VirtualProtect(gravity, size, newProtect, out oldProtect);
  260. }
  261. catch (Exception e)
  262. {
  263. ServerLog(LogType.LogConsole, "SPEED PLUGIN ERROR: " + e.ToString());
  264. }
  265. }
  266.  
  267. unsafe public void g_gravity(int value)
  268. {
  269. try
  270. {
  271. *(int*)gravity = value;
  272. }
  273. catch (Exception e)
  274. {
  275. ServerLog(LogType.LogConsole, "SPEED PLUGIN ERROR: " + e.ToString());
  276. }
  277. }
  278. }
  279. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement