Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Runtime.InteropServices;
- using Addon;
- namespace ReadyUP
- {
- public class Class1 : CPlugin
- {
- public int g_speed_var = 0;
- public float jump_height_var = 0;
- public int fall_damage_var = 0;
- public bool fall_damage_enabled = true;
- public int gravity_var = 0;
- IntPtr j_speed = (IntPtr)0x0046F567;
- IntPtr j_height = (IntPtr)0x00787240;
- IntPtr fallmax = (IntPtr)0x00786E78;
- IntPtr fallmin = (IntPtr)0x0076EDFC;
- IntPtr gravity = (IntPtr)0x004704FC;
- [DllImport("kernel32.dll")]
- private static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);
- unsafe public override void OnServerLoad()
- {
- ServerPrint("Speed plugin loaded. Author: Pozzuh. Version 1.8");
- if (GetServerCFG("SPEEDPLUGIN", "Speed", "-1") == "-1")
- SetServerCFG("SPEEDPLUGIN", "Speed", "190");
- if (GetServerCFG("SPEEDPLUGIN", "JumpHeight", "-1") == "-1")
- SetServerCFG("SPEEDPLUGIN", "JumpHeight", "39");
- if (GetServerCFG("SPEEDPLUGIN", "FallDamage", "-1") == "-1")
- SetServerCFG("SPEEDPLUGIN", "FallDamage", "1");
- if (GetServerCFG("SPEEDPLUGIN", "Gravity", "-1") == "-1")
- SetServerCFG("SPEEDPLUGIN", "Gravity", "800");
- try
- {
- g_speed_var = Convert.ToInt32(GetServerCFG("SPEEDPLUGIN", "Speed", "220"));
- jump_height_var = Convert.ToInt32(GetServerCFG("SPEEDPLUGIN", "JumpHeight", "240"));
- fall_damage_var = Convert.ToInt32(GetServerCFG("SPEEDPLUGIN", "FallDamage", "0"));
- gravity_var = Convert.ToInt32(GetServerCFG("SPEEDPLUGIN", "Gravity", "800"));
- }
- catch (Exception e)
- {
- ServerPrint("invalid speed, jump height, fall damage or gravity value...");
- }
- makeSpeedHappy();
- makeJumpHeightHappy();
- makeGravityHappy();
- g_Speed(g_speed_var);
- jump_height(jump_height_var);
- g_gravity(gravity_var);
- if (fall_damage_var == 0)
- disableFallDamage();
- }
- public override unsafe ChatType OnSay(string Message, ServerClient Client)
- {
- string lowMsg = Message.ToLower();
- if (lowMsg.StartsWith("!falldamage"))
- {
- string[] splitMsg = lowMsg.Split(' ');
- if (splitMsg.Length == 1)
- {
- if (fall_damage_enabled)
- TellClient(Client.ClientNum, "Fall damage is currently enabled.", true);
- else
- TellClient(Client.ClientNum, "Fall damage is currently disabled.", true);
- }
- else
- {
- if (splitMsg[1] == "0")
- {
- disableFallDamage();
- TellClient(Client.ClientNum, "Fall damage is now disabled.", true);
- }
- else if (splitMsg[1] == "1")
- {
- enableFallDamage();
- TellClient(Client.ClientNum, "Fall damage is now enabled.", true);
- }
- }
- return ChatType.ChatNone;
- }
- if (lowMsg.StartsWith("!sp"))
- {
- string[] splitMsg = lowMsg.Split(' ');
- if (splitMsg.Length == 1)
- TellClient(Client.ClientNum, "Current speed: " + *(int*)j_speed, true);
- else
- {
- try
- {
- int NewSpeedValue = Convert.ToInt32(splitMsg[1]);
- g_Speed(NewSpeedValue);
- TellClient(Client.ClientNum, "Speed changed to: " + NewSpeedValue + " (default=190)", true);
- }
- catch (Exception e)
- {
- TellClient(Client.ClientNum, "^1Invalid speed value!", true);
- }
- }
- return ChatType.ChatNone;
- }
- if (lowMsg.StartsWith("!jh"))
- {
- string[] splitMsg = lowMsg.Split(' ');
- if (splitMsg.Length == 1)
- TellClient(Client.ClientNum, "^2Current jump height: " + *(float*)j_height, true);
- else
- {
- try
- {
- float NewJumpHeightValue = (float)Convert.ToInt32(splitMsg[1]);
- jump_height(NewJumpHeightValue);
- if (NewJumpHeightValue < 128)
- TellClient(Client.ClientNum, "Jump height changed to: " + NewJumpHeightValue, true);
- else
- {
- TellClient(Client.ClientNum, "Jump height changed to: " + NewJumpHeightValue + " (default=39). Fall damage disabled.", true);
- disableFallDamage();
- }
- }
- catch (Exception e)
- {
- TellClient(Client.ClientNum, "^1Invalid jump height value!", true);
- }
- }
- return ChatType.ChatNone;
- }
- if (lowMsg.StartsWith("!grav"))
- {
- string[] splitMsg = lowMsg.Split(' ');
- if (splitMsg.Length == 1)
- TellClient(Client.ClientNum, "Current gravity: " + *(int*)gravity, true);
- else
- {
- try
- {
- int newGravityValue = Convert.ToInt32(splitMsg[1]);
- g_gravity(newGravityValue);
- TellClient(Client.ClientNum, "Gravity changed to: " + newGravityValue + " (default=800).", true);
- }
- catch (Exception e)
- {
- TellClient(Client.ClientNum, "^1Invalid gravity value!", true);
- }
- }
- return ChatType.ChatNone;
- }
- return ChatType.ChatContinue;
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- //Stuff needed for speed change
- public void makeSpeedHappy()
- {
- try
- {
- uint size = 4;
- uint newProtect = 0x40;
- uint oldProtect = 0;
- VirtualProtect(j_speed, size, newProtect, out oldProtect);
- }
- catch (Exception e)
- {
- ServerLog(LogType.LogConsole, "SPEED PLUGIN ERROR: " + e.ToString());
- }
- }
- unsafe public void g_Speed(int value)
- {
- try
- {
- *(int*)j_speed = value;
- }
- catch (Exception e)
- {
- ServerLog(LogType.LogConsole, "SPEED PLUGIN ERROR: " + e.ToString());
- }
- }
- public unsafe void makeJumpHeightHappy()
- {
- try
- {
- uint size = 4;
- uint newProtect = 0x40;
- uint oldProtect = 0;
- VirtualProtect(j_height, size, newProtect, out oldProtect);
- VirtualProtect(fallmin, size, newProtect, out oldProtect);
- VirtualProtect(fallmax, size, newProtect, out oldProtect);
- }
- catch (Exception e)
- {
- ServerLog(LogType.LogConsole, "SPEED PLUGIN ERROR: " + e.ToString());
- }
- }
- public unsafe void disableFallDamage()
- {
- fall_damage_enabled = false;
- *(float*)fallmin = 999999.0f;
- *(float*)fallmax = 1000000.0f;
- }
- public unsafe void enableFallDamage()
- {
- fall_damage_enabled = true;
- *(float*)fallmin = 128.0f;
- *(float*)fallmax = 300.0f;
- }
- unsafe public void jump_height(float value)
- {
- try
- {
- *(float*)j_height = value;
- }
- catch (Exception e)
- {
- ServerLog(LogType.LogConsole, "SPEED PLUGIN ERROR: " + e.ToString());
- }
- }
- public void makeGravityHappy()
- {
- try
- {
- uint size = 4;
- uint newProtect = 0x40;
- uint oldProtect = 0;
- VirtualProtect(gravity, size, newProtect, out oldProtect);
- }
- catch (Exception e)
- {
- ServerLog(LogType.LogConsole, "SPEED PLUGIN ERROR: " + e.ToString());
- }
- }
- unsafe public void g_gravity(int value)
- {
- try
- {
- *(int*)gravity = value;
- }
- catch (Exception e)
- {
- ServerLog(LogType.LogConsole, "SPEED PLUGIN ERROR: " + e.ToString());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement