02-26-2012, 17:55
Hi,
i thought that it may be useful to switch the unlimited-ammo on and off while playing.
Since the unlimited-ammo plugin from Nukem only enables unlimited-ammo on server startup, i decided to make a dynamic version of that plugin myself.
I hope Nukem is ok with that ^^.
UnlimitedAmmoV2
Usage:
!ammo <- simple as that. Just type !ammo to enable/disable unlimited ammo
Requirements:
- @Nukem's Server Addon v1.266+
Admin Support:
If you want only Admins to use this command (which would be better ^^) you have to use the Permission plugin from Pozzuh.
I didn't implement the usage of my own AdminPlugin, since nobody wants to use it ^^
Source Code:
i thought that it may be useful to switch the unlimited-ammo on and off while playing.
Since the unlimited-ammo plugin from Nukem only enables unlimited-ammo on server startup, i decided to make a dynamic version of that plugin myself.
I hope Nukem is ok with that ^^.
UnlimitedAmmoV2
Usage:
!ammo <- simple as that. Just type !ammo to enable/disable unlimited ammo
Requirements:
- @Nukem's Server Addon v1.266+
Admin Support:
If you want only Admins to use this command (which would be better ^^) you have to use the Permission plugin from Pozzuh.
I didn't implement the usage of my own AdminPlugin, since nobody wants to use it ^^
Source Code:
Spoiler (Click to View)
CSHARP Code
- using System;
- using Addon;
- using System.Runtime.InteropServices;
-
- namespace UnlimitedAmmoV2
- {
- public class UnlimitedAmmoV2 : CPlugin
- {
- #region DLLImports
- [DllImport("kernel32.dll", SetLastError = true)]
- private static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);
- [DllImport("msvcrt.dll", EntryPoint = "memcpy", CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
- static extern IntPtr memcpy(IntPtr dest, IntPtr src, int count);
- #endregion
-
- #region Ammo Addresses
- private IntPtr weapAmmoAddr = (IntPtr)0x420E69;
- private IntPtr equipAmmoAddr = (IntPtr)0x41E749;
-
- #region Default Ammo Values
- #endregion
- #endregion
-
- private bool unlimitedAmmo = false;
-
- private string version = "v1.0";
-
- public void SetEnabled(bool enabled)
- {
- if (unlimitedAmmo != enabled)
- {
- try
- {
- if (enabled)
- {
- }
- else
- {
- }
-
- memcpy(weapAmmoAddr, Marshal.UnsafeAddrOfPinnedArrayElement(weapAmmo, 0), weapAmmo.Length);
- memcpy(equipAmmoAddr, Marshal.UnsafeAddrOfPinnedArrayElement(equipAmmo, 0), equipAmmo.Length);
-
- unlimitedAmmo = enabled;
- }
- catch (Exception ex)
- {
- ServerPrint("UnlAmmoV2 ERROR: " + ex.Message);
- }
- }
- }
-
- public override void OnServerLoad()
- {
- //Initialize Ammo Addresses
- initAmmoAddresses();
- ServerPrint(string.Format("UnlAmmoV2 {0} loaded. Author: Deviler86", version));
- }
-
- public override ChatType OnSay(string Message, ServerClient Client)
- {
- if (Message.ToLower() == "!ammo")
- {
- SetEnabled(!unlimitedAmmo);
- TellClient(Client.ClientNum, string.Format("UnlAmmoV2: Unlimited Ammo is now {0}.", (unlimitedAmmo ? "enabled" : "disabled")), true);
-
- return ChatType.ChatNone;
- }
- else
- return ChatType.ChatContinue;
- }
-
- private void initAmmoAddresses()
- {
- try
- {
- uint size = 4;
- uint newProtect = 0x40;
- uint oldProtect = 0;
-
- VirtualProtect(weapAmmoAddr, size, newProtect, out oldProtect);
- VirtualProtect(equipAmmoAddr, size, newProtect, out oldProtect);
- }
- catch (Exception ex)
- {
- ServerPrint("UnlAmmoV2 ERROR: " + ex.Message);
- }
- }
- }
- }