Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Request Permanent Message
#1
Hey.

I need an plugin for my Server which displays a permanent Message for rules like:

Noscope,Hardscope,dragscope=Kick/Bann

at the left buttom.


Ty
Reply

#2
do you mean like a message on the hud?? If so use the Server Ad Plugin: http://www.itsmods.com/forum/Thread-Rele...verAd.html
~FYANB~ Servers Website

Primary Account:
[Image: 76561198070236721.png]
Secondary Account:
[Image: 76561198096107676.png]
Third Account:
[Image: 76561198164751656.png]
Reply

#3
He wants iPrintLn, ServerAd is a bit spammish plugin.
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
Reply

#4
(01-10-2014, 04:34)SailorMoon Wrote: He wants iPrintLn, ServerAd is a bit spammish plugin.

uhm i think he wants it to stay on the screen but i guess he'll tell us
~FYANB~ Servers Website

Primary Account:
[Image: 76561198070236721.png]
Secondary Account:
[Image: 76561198096107676.png]
Third Account:
[Image: 76561198164751656.png]
Reply

#5
Wink 
Easy. it's working also on the teknomw3.

PHP Code:
using Addon;
using System;
using System.Threading;

namespace 
plugin_test
{
    public class 
plugin_test CPlugin
    
{

        public 
override void OnServerLoad()
        {
            
ServerPrint("Plugin Spam by frst_ loaded.");
            
ThreadPool.QueueUserWorkItem(new WaitCallback(this.onSpam));
        }

        private 
void onSpam(object x)
        {
            while (
true)
            {
                
base.iPrintLn("Noscope,Hardscope,dragscope=Kick/Bann"null);
                
SafeSleep(120); // seconds
            
}
        }

        public static 
void SafeSleep(int AmountSec)
        {
            
int num 0;
            while (
num != AmountSec)
            {
                
num++;
                
Thread.Sleep(0x3e8);
            }
        }
    }

Reply

#6
(01-11-2014, 14:36)frst_ Wrote: Easy. it's working also on the teknomw3.

PHP Code:
using Addon;
using System;
using System.Threading;

namespace 
plugin_test
{
    public class 
plugin_test CPlugin
    
{

        public 
override void OnServerLoad()
        {
            
ServerPrint("Plugin Spam by frst_ loaded.");
            
ThreadPool.QueueUserWorkItem(new WaitCallback(this.onSpam));
        }

        private 
void onSpam(object x)
        {
            while (
true)
            {
                
base.iPrintLn("Noscope,Hardscope,dragscope=Kick/Bann"null);
                
SafeSleep(120); // seconds
            
}
        }

        public static 
void SafeSleep(int AmountSec)
        {
            
int num 0;
            while (
num != AmountSec)
            {
                
num++;
                
Thread.Sleep(0x3e8);
            }
        }
    }


Threading tends to cause crashes on you server.

This wont cause crashes. Smile
Spam.cs
PHP Code:
using Addon;
using System;

namespace 
message
{
    public class 
message CPlugin
    
{
        public 
override void OnPlayerConnect(ServerClient client)
        {
            
// Display a message to the client every 30 seconds.
            
Timing.OnInterval(30000client, () =>
            {
            
iPrintLn("Noscope,Hardscope,dragscope = Kick/Bann"client);

            
// Let the timer know to keep going. Return false to remove/stop the timer.
            
return true;
            });
        }

    }


Timing.cs: Credit: @master131
PHP Code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
 
namespace 
Addon
{
    
// ***** Uncomment if using .NET Framework 2.0 .NET Framework 3.0, or .NET Framework 3.5 *****
    // ***** Yes, all of it, seriously. *****
    /*
    public delegate TResult Func<TResult>();
    public delegate void Action();
    public delegate void Action<T1, T2>(T1 arg1, T2 arg2);
    public delegate void Action<T1, T2, T3>(T1 arg1, T2 arg2, T3 arg3);
    public delegate void Action<T1, T2, T3, T4>(T1 arg1, T2 arg2, T3 arg3, T4 arg4);
    public delegate void Action<T1, T2, T3, T4, T5>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5);
    public delegate void Action<T1, T2, T3, T4, T5, T6>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6);
    public delegate void Action<T1, T2, T3, T4, T5, T6, T7>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7);
    public delegate void Action<T1, T2, T3, T4, T5, T6, T7, T8>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8);
    public delegate void Action<T1, T2, T3, T4, T5, T6, T7, T8, T9>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9);
    */
 
    
enum ParameterType
    
{
        
Entity 1,
        
String 2,
        
Vector 4,
        
Float 5,
        
Integer 6
    
}
 
    class 
Parameter
    
{
        private static 
readonly IntPtr EntityAddress = (IntPtr)0x01918900;
        private static 
readonly IntPtr ClientAddress = (IntPtr)0x4A0FE90;
 
        private 
readonly object _value;
        private 
readonly ParameterType _type;
 
        
internal Parameter(object valueParameterType type)
        {
            
_value value;
            
_type type;
        }
 
        public 
ParameterType Type
        
{
            
get { return _type; }
        }
 
        public 
object Value
        
{
            
get { return _value; }
        }
 
        public 
bool IsPlayer
        
{
            
get { return _type == ParameterType.Entity && (int)_value 18; }
        }
 
        public 
bool IsEntity
        
{
            
get { return _type == ParameterType.Entity && (int)_value >= 18; }
        }
 
        public 
As<T>()
        {
            if (
typeof(T) == typeof(Entity))
                return (
T)(object)GetEntity();
 
            if (
typeof(T) == typeof(ServerClient))
                return (
T)(object)GetClient();
 
            if (
typeof(T) == typeof(bool) && _type == ParameterType.Integer)
                return (
T)(object)((int)_value != 0);
 
            return (
T)Convert.ChangeType(_valuetypeof(T));
        }
 
        public static 
implicit operator Parameter(string value)
        {
            return new 
Parameter(valueParameterType.String);
        }
 
        public static 
implicit operator Parameter(int value)
        {
            return new 
Parameter(valueParameterType.Integer);
        }
 
        public static 
implicit operator Parameter(float value)
        {
            return new 
Parameter(valueParameterType.Float);
        }
 
        public static 
implicit operator Parameter(Vector value)
        {
            return new 
Parameter(valueParameterType.Vector);
        }
 
        public static 
implicit operator Parameter(ServerClient client)
        {
            return new 
Parameter(client.ClientNumParameterType.Entity);
        }
 
        public static 
implicit operator Parameter(Entity entity)
        {
            return new 
Parameter(entity.EntityNumParameterType.Entity);
        }
 
        private 
Entity GetEntity()
        {
            
// Get the constructor for the Entity class.
            
var entityConstructors typeof(Entity).GetConstructors(BindingFlags.NonPublic BindingFlags.Instance);
 
            
// Invoke the constructor with no arguments.
            
var entity = (Entity)entityConstructors[0].Invoke(null);
 
            
// Call the internal SetInformation method with a pointer to the Entity.
            
typeof(Entity).GetMethod("SetInformation"BindingFlags.NonPublic BindingFlags.Instance).Invoke(entity, new object[] { GetEntityFromNum((int)_value) });
 
            return 
entity;
        }
 
        private 
ServerClient GetClient()
        {
            
// Get the constructor for the Client class.
            
var clientConstructors typeof(ServerClient).GetConstructors(BindingFlags.NonPublic BindingFlags.Instance);
 
            
// Invoke the constructor with no arguments.
            
var client = (ServerClient)clientConstructors[0].Invoke(null);
 
            
// Call the internal SetInformation method with a pointer to the Entity.
            
typeof(ServerClient).GetMethod("SetInformation"BindingFlags.NonPublic BindingFlags.Instance).Invoke(client, new object[] { GetClientFromNum((int)_value) });
 
            return 
client;
        }
 
        private static 
IntPtr GetEntityFromNum(int entityNum)
        {
            return (
IntPtr)(EntityAddress.ToInt32() + entityNum 0x274);
        }
 
        private static 
IntPtr GetClientFromNum(int clientNum)
        {
            return (
IntPtr)(ClientAddress.ToInt32() + clientNum 0x78690);
        }
    }
 
    static class 
Timing
    
{
        class 
ServerTimer
        
{
            public 
int Interval getset; }
            public 
long Time getset; }
            public 
ServerClient Target getset; }
            public 
Delegate Function { getset; }
        }
 
        class 
ServerNotify
        
{
            public 
int TargetNum getset; }
            public 
bool HasTarget getset; }
            public 
Delegate Function { getset; }
        }
 
        [
StructLayout(LayoutKind.Sequential)]
        
struct Vec3
        
{
            public 
float X;
            public 
float Y;
            public 
float Z;
 
            public static 
implicit operator Vec3(Vector vector)
            {
                return new 
Vec3 vector.Xvector.Yvector.};
            }
 
            public static 
implicit operator Vector(Vec3 vector)
            {
                return new 
Vector(vector.Xvector.Yvector.Z);
            }
        }
 
        private static 
readonly byte[] ScrAddStringStub = new byte[]
        {
            
0x55// push ebp
            
0x8B0xEC// mov ebp, esp
            
0x51// push ecx
            
0x57// push edi
            
0xC70x450xFC0xD00x110x4F0x00// mov dword ptr [ebp-4], 4F11D0
            
0x8B0x7D0x08// mov edi, [ebp+8]
            
0xFF0x550xFC// call [ebp-4]
            
0x5F// pop edi
            
0x8B0xE5// mov esp, ebp
            
0x5D// pop ebp
            
0xC3 // retn
        
};
 
        private static 
readonly byte[] ScrAddObjectStub = new byte[]
        {
            
0x55// push ebp
            
0x8B0xEC// mov ebp, esp
            
0x51// push ecx
            
0x56// push esi
            
0xC70x450xFC0x500x110x4F0x00// mov dword ptr [ebp-4], 4F1150
            
0x8B0x750x08// mov esi, [ebp+8]
            
0xFF0x550xFC// call [ebp-4]
            
0x5E// pop esi
            
0x8B0xE5// mov esp, ebp
            
0x5D// pop ebp
            
0xC3 // retn
        
};
 
        private static 
readonly byte[] ScrAddVectorStub = new byte[]
        {
            
0x55// push ebp
            
0x8B0xEC// mov ebp, esp
            
0x51// push ecx
            
0x57// push edi
            
0xC70x450xFC0xF00x120x4F0x00// mov dword ptr [ebp-4], 4F12F0
            
0x8B0x7D0x08// mov edi, [ebp+8]
            
0xFF0x550xFC// call [ebp-4]
            
0x5F// pop edi
            
0x8B0xE5// mov esp, ebp
            
0x5D// pop ebp
            
0xC3 // retn
        
};
 
        private static 
readonly byte[] ScrNotifyNumStub = new byte[]
        {
            
0x55// push ebp
            
0x8B0xEC// mov ebp, esp
            
0x51// push ecx
            
0xC70x450xFC0x000xFD0x4E0x00// mov dword ptr [ebp-4], 4EFD00
            
0x8B0x450x0C// mov eax, [ebp+C]
            
0xFF0x750x14// push [ebp+14]
            
0xFF0x750x10// push [ebp+10]
            
0xFF0x750x08// push [ebp+8]
            
0xFF0x550xFC// call [ebp-4]
            
0x830xC40x0C// add esp, C
            
0x8B0xE5// mov esp, ebp
            
0x5D// pop ebp
            
0xC3 // retn    
        
};
 
        private static 
byte[] VmExecuteHookStub = new byte[]
        {
            
0x8B0x440x240x0C// mov eax, [esp+0Ch]
            
0x50// push eax
            
0x8B0x440x240x0C// mov eax, [esp+0Ch]
            
0x50// push eax
            
0x8B0x440x240x0C// mov eax, [esp+0Ch]
            
0x50// push eax
            
0xB80x000x000x000x00// mov eax, <handler>
            
0xFF0xD0// call eax
            
0x830xC40x0C// add esp, 0Ch
            
0x55// push ebp
            
0x8B0xEC// mov ebp, esp
            
0x830xE40xF8// and esp, 0FFFFFFF8h
            
0xB80x000x000x000x00// mov eax, <dest>
            
0xFF0xE0// jmp eax
        
};
 
        [
DllImport("kernel32.dll"SetLastError true)]
        static 
extern bool VirtualProtect(IntPtr lpAddressUIntPtr dwSizeuint flNewProtectout uint lpflOldProtect);
 
        [
DllImport("kernel32.dll"SetLastError true)]
        static 
extern IntPtr VirtualAlloc(IntPtr lpAddressUIntPtr dwSizeuint flAllocationTypeuint flProtect);
 
        [
DllImport("user32.dll"CharSet CharSet.Auto)]
        static 
extern int MessageBox(IntPtr hWndstring textstring captionuint type);
 
        private const 
uint MEM_COMMIT 0x1000;
        private const 
uint MEM_RESERVE 0x2000;
        private const 
uint PAGE_EXECUTE_READWRITE 0x40;
        private const 
uint MB_ICONERROR 0x10;
 
        [
UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private 
delegate void GameScriptNotifyHandlerDelegate(int entityuint typeIntPtr variableStack);
 
        [
UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private 
delegate int ScrAddFloatDelegate(float value);
 
        [
UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private 
delegate int ScrAddIntegerDelegate(int value);
 
        [
UnmanagedFunctionPointer(CallingConvention.CdeclCharSet CharSet.Ansi)]
        private 
delegate void ScrAddStringDelegate(string value);
 
        [
UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private 
delegate int ScrGetEntityIdDelegate(int entityNumint entityShift);
 
        [
UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private 
delegate void ScrAddObjectDelegate(int num);
 
        [
UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private 
delegate void ScrAddVectorDelegate(ref Vec3 vector);
 
        [
UnmanagedFunctionPointer(CallingConvention.CdeclCharSet CharSet.Ansi)]
        private 
delegate int ScrPrepareNotifyDelegate(string messageint zeroint messageLength);
 
        [
UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private 
delegate void ScrNotifyNumDelegate(int entNumint entShiftint prepareResultint paramCount);
 
        private static 
readonly IntPtr VirtualMachineExecuteAddress = (IntPtr)0x4EF610;
        private static 
readonly IntPtr GameScriptStringTablePointer = (IntPtr)0x1C122A4;
        private static 
readonly IntPtr GameScriptObjectTypeArray = (IntPtr)0x1D39804;
        private static 
readonly IntPtr GameScriptObjectToEntityLo = (IntPtr)0x1D39802;
 
        private static 
readonly IntPtr ScrAddFloatAddress = (IntPtr)0x4F1070;
        private static 
readonly IntPtr ScrAddIntegerAddress = (IntPtr)0x4F1020;
        private static 
readonly IntPtr ScrGetEntityIdAddress = (IntPtr)0x4EA450;
        private static 
readonly IntPtr ScrPrepareNotifyAddress = (IntPtr)0x4E7650;
 
        private static 
readonly List<ServerTimerTimers = new List<ServerTimer>();
        private static 
readonly Stopwatch Stopwatch = new Stopwatch();
        private static 
readonly Dictionary<string, List<ServerNotify>> NotifyHandlers = new Dictionary<string, List<ServerNotify>>();
 
        private static 
ScrAddFloatDelegate _scrAddFloatFunc;
        private static 
ScrAddIntegerDelegate _scrAddIntegerFunc;
        private static 
ScrAddStringDelegate _scrAddStringFunc;
        private static 
ScrGetEntityIdDelegate _scrGetEntityIdFunc;
        private static 
ScrAddObjectDelegate _scrAddObjectFunc;
        private static 
ScrAddVectorDelegate _scrAddVectorFunc;
        private static 
ScrPrepareNotifyDelegate _scrPrepareNotifyFunc;
        private static 
ScrNotifyNumDelegate _scrNotifyNumFunc;
        private static 
GCHandle _gch;
 
        private static 
IntPtr _scrNotifyStack IntPtr.Zero;
        private static 
IntPtr _scrAddStringFuncAddress IntPtr.Zero;
        private static 
IntPtr _scrAddObjectFuncAddress IntPtr.Zero;
        private static 
IntPtr _scrAddVectorFuncAddress IntPtr.Zero;
        private static 
IntPtr _scrNotifyNumFuncAddress IntPtr.Zero;
 
        static 
Timing()
        {
            
HookGameScriptNotifyHandler();
            
Stopwatch.Start();
        }
 
        private static 
void PushFloat(float value)
        {
            if (
_scrAddFloatFunc == null)
                
_scrAddFloatFunc = (ScrAddFloatDelegate)Marshal.GetDelegateForFunctionPointer(ScrAddFloatAddresstypeof(ScrAddFloatDelegate));
 
            
_scrAddFloatFunc(value);
        }
 
        private static 
void PushInteger(int value)
        {
            if (
_scrAddIntegerFunc == null)
                
_scrAddIntegerFunc = (ScrAddIntegerDelegate)Marshal.GetDelegateForFunctionPointer(ScrAddIntegerAddresstypeof(ScrAddIntegerDelegate));
 
            
_scrAddIntegerFunc(value);
        }
 
        private static 
void PushString(string value)
        {
            if (
_scrAddStringFuncAddress == IntPtr.Zero)
            {
                
_scrAddStringFuncAddress VirtualAlloc(IntPtr.Zero, (UIntPtr)ScrAddStringStub.LengthMEM_COMMIT MEM_RESERVEPAGE_EXECUTE_READWRITE);
                if (
_scrAddStringFuncAddress == IntPtr.Zero)
                    return;
                
Marshal.Copy(ScrAddStringStub0_scrAddStringFuncAddressScrAddStringStub.Length);
                
_scrAddStringFunc = (ScrAddStringDelegate)Marshal.GetDelegateForFunctionPointer(_scrAddStringFuncAddresstypeof(ScrAddStringDelegate));
            }
 
            
_scrAddStringFunc(value);
        }
 
        private static 
void PushEntity(int entityNum)
        {
            if (
_scrGetEntityIdFunc == null)
                
_scrGetEntityIdFunc = (ScrGetEntityIdDelegate)Marshal.GetDelegateForFunctionPointer(ScrGetEntityIdAddresstypeof(ScrGetEntityIdDelegate));
 
            if (
_scrAddObjectFuncAddress == IntPtr.Zero)
            {
                
_scrAddObjectFuncAddress VirtualAlloc(IntPtr.Zero, (UIntPtr)ScrAddObjectStub.LengthMEM_COMMIT MEM_RESERVEPAGE_EXECUTE_READWRITE);
                if (
_scrAddObjectFuncAddress == IntPtr.Zero)
                    return;
                
Marshal.Copy(ScrAddObjectStub0_scrAddObjectFuncAddressScrAddObjectStub.Length);
                
_scrAddObjectFunc = (ScrAddObjectDelegate)Marshal.GetDelegateForFunctionPointer(_scrAddObjectFuncAddresstypeof(ScrAddObjectDelegate));
            }
 
            
int result _scrGetEntityIdFunc(entityNumentityNum >> 16);
            
_scrAddObjectFunc(result);
        }
 
        private static 
void PushVector(Vector vector)
        {
            if (
_scrAddVectorFuncAddress == IntPtr.Zero)
            {
                
_scrAddVectorFuncAddress VirtualAlloc(IntPtr.Zero, (UIntPtr)ScrAddVectorStub.LengthMEM_COMMIT MEM_RESERVEPAGE_EXECUTE_READWRITE);
                if (
_scrAddVectorFuncAddress == IntPtr.Zero)
                    return;
                
Marshal.Copy(ScrAddVectorStub0_scrAddVectorFuncAddressScrAddVectorStub.Length);
                
_scrAddVectorFunc = (ScrAddVectorDelegate)Marshal.GetDelegateForFunctionPointer(_scrAddVectorFuncAddresstypeof(ScrAddVectorDelegate));
            }
 
            
Vec3 vec vector;
            
_scrAddVectorFunc(ref vec);
        }
 
        public static 
void Notify(Entity entitystring messageparams Parameter[] parameters)
        {
            
Notify(entity.EntityNummessageparameters);
        }
 
        public static 
void Notify(ServerClient clientstring messageparams Parameter[] parameters)
        {
            
Notify(client.ClientNummessageparameters);
        }
 
        private static 
void Notify(int entNumstring messageparams Parameter[] parameters)
        {
            if (
_scrPrepareNotifyFunc == null)
                
_scrPrepareNotifyFunc = (ScrPrepareNotifyDelegate)Marshal.GetDelegateForFunctionPointer(ScrPrepareNotifyAddresstypeof(ScrPrepareNotifyDelegate));
 
            if (
_scrNotifyNumFuncAddress == IntPtr.Zero)
            {
                
_scrNotifyNumFuncAddress VirtualAlloc(IntPtr.Zero, (UIntPtr)ScrNotifyNumStub.LengthMEM_COMMIT MEM_RESERVEPAGE_EXECUTE_READWRITE);
                if (
_scrNotifyNumFuncAddress == IntPtr.Zero)
                    return;
                
Marshal.Copy(ScrNotifyNumStub0_scrNotifyNumFuncAddressScrNotifyNumStub.Length);
                
_scrNotifyNumFunc = (ScrNotifyNumDelegate)Marshal.GetDelegateForFunctionPointer(_scrNotifyNumFuncAddresstypeof(ScrNotifyNumDelegate));
            }
 
            Array.
Reverse(parameters);
 
            foreach (var 
param in parameters)
            {
                switch (
param.Type)
                {
                    case 
ParameterType.Float:
                        
PushFloat(Convert.ToSingle(param.Value));
                        break;
                    case 
ParameterType.Integer:
                        
PushInteger(Convert.ToInt32(param.Value));
                        break;
                    case 
ParameterType.String:
                        
PushString(Convert.ToString(param.Value));
                        break;
                    case 
ParameterType.Entity:
                        
PushEntity(Convert.ToInt32(param.Value));
                        break;
                    case 
ParameterType.Vector:
                        
PushVector((Vector)param.Value);
                        break;
                }
            }
 
            
int result _scrPrepareNotifyFunc(message0message.Length 1);
            
_scrNotifyNumFunc(entNumentNum >> 16resultparameters.Length);
        }
 
        private static 
void HookGameScriptNotifyHandler()
        {
            var 
handler = new GameScriptNotifyHandlerDelegate(GameScriptNotifyHandlerHook);
            
_gch GCHandle.Alloc(handler); // Prevent GC from relocating/freeing function.
            
var handlerAddress Marshal.GetFunctionPointerForDelegate(handler);
            var 
hookStub VirtualAlloc(IntPtr.Zero, (UIntPtr)VmExecuteHookStub.LengthMEM_RESERVE MEM_COMMITPAGE_EXECUTE_READWRITE);
            
BitConverter.GetBytes(handlerAddress.ToInt32()).CopyTo(VmExecuteHookStub16);
            
BitConverter.GetBytes(VirtualMachineExecuteAddress.ToInt32() + 6).CopyTo(VmExecuteHookStub32);
            
Marshal.Copy(VmExecuteHookStub0hookStubVmExecuteHookStub.Length);
            
SetJmpHook(VirtualMachineExecuteAddresshookStub);
        }
 
        private static 
void SetJmpHook(IntPtr originalIntPtr destination)
        {
            
uint oldProtect;
            
VirtualProtect(original, (UIntPtr)5PAGE_EXECUTE_READWRITEout oldProtect);
            var 
hook = new byte[5];
            
hook[0] = 0xE9;
            
BitConverter.GetBytes((destination.ToInt32() - original.ToInt32()) - 5).CopyTo(hook1);
            
Marshal.Copy(hook0originalhook.Length);
            
VirtualProtect(original, (UIntPtr)5oldProtectout oldProtect);
        }
 
        private static 
int GetObjectType(int @object)
        {
            return 
Marshal.ReadInt32(GameScriptObjectTypeArray* @object);
        }
 
        private static 
IntPtr GetVariableStackValueFromIndex(int index)
        {
            return (
IntPtr)(_scrNotifyStack.ToInt32() + -index);
        }
 
        private static 
object[] GetParameters(int argumentCount)
        {
            var 
param = new object[argumentCount];
 
            for (
int i 0argumentCounti++)
            {
                var 
paramType = (ParameterType)Marshal.ReadInt32(GetVariableStackValueFromIndex(i), 4);
                
object value null;
 
                switch (
paramType)
                {
                    case 
ParameterType.Integer:
                        
value Marshal.ReadInt32(GetVariableStackValueFromIndex(i));
                        break;
                    case 
ParameterType.String:
                        
int stringIndex Marshal.ReadInt16(GetVariableStackValueFromIndex(i));
                        
value Marshal.PtrToStringAnsi((IntPtr)(Marshal.ReadInt32(GameScriptStringTablePointer) + 12 stringIndex 4));
                        break;
                    case 
ParameterType.Float:
                        
value Marshal.PtrToStructure(GetVariableStackValueFromIndex(i), typeof(float));
                        break;
                    case 
ParameterType.Entity:
                        
int entityObjectId Marshal.ReadInt32(GetVariableStackValueFromIndex(i));
                        
value ScriptObjectIDToEntityNum(entityObjectId);
                        break;
                    case 
ParameterType.Vector:
                        
value = (Vector)(Vec3)Marshal.PtrToStructure(Marshal.ReadIntPtr(GetVariableStackValueFromIndex(i)), typeof(Vec3));
                        break;
                }
 
                
param[i] = new Parameter(valueparamType);
            }
 
            return 
param;
        }
 
        private static 
int ScriptObjectIDToEntityNum(int scriptObjectId)
        {
            var 
loword = (uint)(Marshal.ReadInt16(GameScriptObjectToEntityLoscriptObjectId));
            var 
hiword = (uint)(Marshal.ReadInt32(GameScriptObjectTypeArrayscriptObjectId) >> 8);
            return (int)((
hiword << 16) | (loword 0xFFFF));
        }
 
        private static 
int GetNotifyArgumentCount()
        {
            
int argumentCount 0;
 
            if (
Marshal.ReadInt32(_scrNotifyStack4) != 8)
            {
                for (
int i _scrNotifyStack.ToInt32(); Marshal.ReadInt32((IntPtr)i4) != 8-= 8)
                    
argumentCount++;
            }
 
            return 
argumentCount;
        }
 
        private static 
void DispatchMessage(int targetEntityNumstring message)
        {
            foreach (var 
handler in NotifyHandlers[message])
            {
                
// Check if the handler specified a client or entity, if so, check the client num.
                
if (handler.HasTarget && handler.TargetNum != targetEntityNum)
                    continue;
 
                var 
handlerParams handler.Function.Method.GetParameters();
 
                
// Check if the handler function has parameters.
                
if (handlerParams.Length 0)
                {
                    
// Calculate the number of arguments.
                    
int argumentCount GetNotifyArgumentCount();
 
                    
// Get the parameters.
                    
object[] parameters GetParameters(argumentCount);
 
                    
// Fix the parameters if the user omitted some of them.
                    
var fixedParameters = new object[handlerParams.Length];
                    Array.
Copy(parametersfixedParametersfixedParameters.Length);
 
                    
// Dynamically invoke the function.
                    
handler.Function.DynamicInvoke(fixedParameters);
                }
                else
                {
                    
// Perform a dynamic invoke with no arguments.
                    
handler.Function.DynamicInvoke();
                }
            }
        }
 
        private static 
void HandleNotifyEvent(int entityuint type)
        {
            if (
type == 0)
                return;
 
            
// Get the current message address.
            
var messageAddress = (IntPtr)(Marshal.ReadInt32(GameScriptStringTablePointer) + 12 type 4);
 
            if (
messageAddress == IntPtr.Zero)
                return;
 
            
int targetEntityNum = -1;
 
            
// Check if the script object type is an entity/client.
            
if (GetObjectType(entity) == 21)
            {
                
// Convert the script object ID to an entity/client num.
                
targetEntityNum ScriptObjectIDToEntityNum(entity);
            }
 
            
// Get the current message.
            
string message Marshal.PtrToStringAnsi(messageAddress);
 
            
// Check the message is valid and notify the handlers.
            
if (string.IsNullOrEmpty(message) || !NotifyHandlers.ContainsKey(message))
                return;
 
            try
            {
                
DispatchMessage(targetEntityNummessage);
            }
            catch (
Exception ex)
            {
                
// Catch any errors and display it as a message box since there's no way to
                // log it without a plugin instance.
                
MessageBox(IntPtr.Zeroex.ToString(), "HandleNotifyEvent failed."MB_ICONERROR);
            }
        }
 
        private static 
void GameScriptNotifyHandlerHook(int entityuint typeIntPtr variableStack)
        {
            
_scrNotifyStack variableStack;
            
HandleNotifyEvent(entitytype);
        }
 
        public static 
void OnInterval(int intervalServerClient targetFunc<bool> function)
        {
            
Timers.Add(new ServerTimer Interval interval, Function = function, Target target });
        }
 
        public static 
void OnInterval(int intervalFunc<bool> function)
        {
            
Timers.Add(new ServerTimer Interval interval, Function = function });
        }
 
        public static 
void AfterDelay(int delayServerClient targetAction action)
        {
            
Timers.Add(new ServerTimer Interval = -1Time Stopwatch.ElapsedMilliseconds delay, Function = actionTarget target });
        }
 
        public static 
void AfterDelay(int delayAction action)
        {
            
Timers.Add(new ServerTimer Interval = -1Time Stopwatch.ElapsedMilliseconds delay, Function = action });
        }
 
        public static 
void ProcessFrame(List<ServerClientclients)
        {
            var 
currentTime Stopwatch.ElapsedMilliseconds;
 
            foreach (var 
timer in Timers.ToArray())
            {
                if (
currentTime timer.Time)
                    continue;
 
                if (
timer.Target != null && clients.FindIndex(sc => sc.XUID == timer.Target.XUID) == -1)
                {
                    
Timers.Remove(timer);
                    continue;
                }
 
                
object returnValue timer.Function.DynamicInvoke();
 
                if (
timer.Interval == -|| timer.Function.Method.ReturnType == typeof(bool) && !(bool)returnValue)
                {
                    
Timers.Remove(timer);
                }
                else
                {
                    
timer.Time currentTime timer.Interval;
                }
            }
        }
 
        private static 
void OnNotify(string typeDelegate actionbool hasTargetint targetNum)
        {
            var 
serverNotify = new ServerNotify { Function = actionHasTarget hasTargetTargetNum targetNum };
 
            if (
NotifyHandlers.ContainsKey(type))
                
NotifyHandlers[type].Add(serverNotify);
            else
                
NotifyHandlers.Add(type, new List<ServerNotify>(new[] { serverNotify }));
        }
 
        public static 
void OnNotify(string typeAction action)
        {
            
OnNotify(typeactionfalse, -1);
        }
 
        public static 
void OnNotify(string typeAction<Parameteraction)
        {
            
OnNotify(typeactionfalse, -1);
        }
 
        public static 
void OnNotify(string typeAction<ParameterParameteraction)
        {
            
OnNotify(typeactionfalse, -1);
        }
 
        public static 
void OnNotify(string typeAction<ParameterParameterParameteraction)
        {
            
OnNotify(typeactionfalse, -1);
        }
 
        public static 
void OnNotify(string typeAction<ParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactionfalse, -1);
        }
 
        public static 
void OnNotify(string typeAction<ParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactionfalse, -1);
        }
 
        public static 
void OnNotify(string typeAction<ParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactionfalse, -1);
        }
 
        public static 
void OnNotify(string typeAction<ParameterParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactionfalse, -1);
        }
 
        public static 
void OnNotify(string typeAction<ParameterParameterParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactionfalse, -1);
        }
 
        public static 
void OnNotify(string typeAction<ParameterParameterParameterParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactionfalse, -1);
        }
 
        public static 
void OnNotify(string typeServerClient clientAction action)
        {
            
OnNotify(typeactiontrueclient.ClientNum);
        }
 
        public static 
void OnNotify(string typeServerClient clientAction<Parameteraction)
        {
            
OnNotify(typeactiontrueclient.ClientNum);
        }
 
        public static 
void OnNotify(string typeServerClient clientAction<ParameterParameteraction)
        {
            
OnNotify(typeactiontrueclient.ClientNum);
        }
 
        public static 
void OnNotify(string typeServerClient clientAction<ParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueclient.ClientNum);
        }
 
        public static 
void OnNotify(string typeServerClient clientAction<ParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueclient.ClientNum);
        }
 
        public static 
void OnNotify(string typeServerClient clientAction<ParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueclient.ClientNum);
        }
 
        public static 
void OnNotify(string typeServerClient clientAction<ParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueclient.ClientNum);
        }
 
        public static 
void OnNotify(string typeServerClient clientAction<ParameterParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueclient.ClientNum);
        }
 
        public static 
void OnNotify(string typeServerClient clientAction<ParameterParameterParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueclient.ClientNum);
        }
 
        public static 
void OnNotify(string typeServerClient clientAction<ParameterParameterParameterParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueclient.ClientNum);
        }
 
        public static 
void OnNotify(string typeEntity entityAction action)
        {
            
OnNotify(typeactiontrueentity.EntityNum);
        }
 
        public static 
void OnNotify(string typeEntity entityAction<Parameteraction)
        {
            
OnNotify(typeactiontrueentity.EntityNum);
        }
 
        public static 
void OnNotify(string typeEntity entityAction<ParameterParameteraction)
        {
            
OnNotify(typeactiontrueentity.EntityNum);
        }
 
        public static 
void OnNotify(string typeEntity entityAction<ParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueentity.EntityNum);
        }
 
        public static 
void OnNotify(string typeEntity entityAction<ParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueentity.EntityNum);
        }
 
        public static 
void OnNotify(string typeEntity entityAction<ParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueentity.EntityNum);
        }
 
        public static 
void OnNotify(string typeEntity entityAction<ParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueentity.EntityNum);
        }
 
        public static 
void OnNotify(string typeEntity entityAction<ParameterParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueentity.EntityNum);
        }
 
        public static 
void OnNotify(string typeEntity entityAction<ParameterParameterParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueentity.EntityNum);
        }
 
        public static 
void OnNotify(string typeEntity entityAction<ParameterParameterParameterParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueentity.EntityNum);
        }
    }

~FYANB~ Servers Website

Primary Account:
[Image: 76561198070236721.png]
Secondary Account:
[Image: 76561198096107676.png]
Third Account:
[Image: 76561198164751656.png]
Reply

#7
(01-11-2014, 18:05)Casper Wrote:
(01-11-2014, 14:36)frst_ Wrote: Easy. it's working also on the teknomw3.

PHP Code:
using Addon;
using System;
using System.Threading;

namespace 
plugin_test
{
    public class 
plugin_test CPlugin
    
{

        public 
override void OnServerLoad()
        {
            
ServerPrint("Plugin Spam by frst_ loaded.");
            
ThreadPool.QueueUserWorkItem(new WaitCallback(this.onSpam));
        }

        private 
void onSpam(object x)
        {
            while (
true)
            {
                
base.iPrintLn("Noscope,Hardscope,dragscope=Kick/Bann"null);
                
SafeSleep(120); // seconds
            
}
        }

        public static 
void SafeSleep(int AmountSec)
        {
            
int num 0;
            while (
num != AmountSec)
            {
                
num++;
                
Thread.Sleep(0x3e8);
            }
        }
    }


Threading tends to cause crashes on you server.

This wont cause crashes. Smile
Spam.cs
PHP Code:
using Addon;
using System;

namespace 
message
{
    public class 
message CPlugin
    
{
        public 
override void OnPlayerConnect(ServerClient client)
        {
            
// Display a message to the client every 30 seconds.
            
Timing.OnInterval(30000client, () =>
            {
            
iPrintLn("Noscope,Hardscope,dragscope = Kick/Bann"client);

            
// Let the timer know to keep going. Return false to remove/stop the timer.
            
return true;
            });
        }

    }


Timing.cs: Credit: @master131
PHP Code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
 
namespace 
Addon
{
    
// ***** Uncomment if using .NET Framework 2.0 .NET Framework 3.0, or .NET Framework 3.5 *****
    // ***** Yes, all of it, seriously. *****
    /*
    public delegate TResult Func<TResult>();
    public delegate void Action();
    public delegate void Action<T1, T2>(T1 arg1, T2 arg2);
    public delegate void Action<T1, T2, T3>(T1 arg1, T2 arg2, T3 arg3);
    public delegate void Action<T1, T2, T3, T4>(T1 arg1, T2 arg2, T3 arg3, T4 arg4);
    public delegate void Action<T1, T2, T3, T4, T5>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5);
    public delegate void Action<T1, T2, T3, T4, T5, T6>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6);
    public delegate void Action<T1, T2, T3, T4, T5, T6, T7>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7);
    public delegate void Action<T1, T2, T3, T4, T5, T6, T7, T8>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8);
    public delegate void Action<T1, T2, T3, T4, T5, T6, T7, T8, T9>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9);
    */
 
    
enum ParameterType
    
{
        
Entity 1,
        
String 2,
        
Vector 4,
        
Float 5,
        
Integer 6
    
}
 
    class 
Parameter
    
{
        private static 
readonly IntPtr EntityAddress = (IntPtr)0x01918900;
        private static 
readonly IntPtr ClientAddress = (IntPtr)0x4A0FE90;
 
        private 
readonly object _value;
        private 
readonly ParameterType _type;
 
        
internal Parameter(object valueParameterType type)
        {
            
_value value;
            
_type type;
        }
 
        public 
ParameterType Type
        
{
            
get { return _type; }
        }
 
        public 
object Value
        
{
            
get { return _value; }
        }
 
        public 
bool IsPlayer
        
{
            
get { return _type == ParameterType.Entity && (int)_value 18; }
        }
 
        public 
bool IsEntity
        
{
            
get { return _type == ParameterType.Entity && (int)_value >= 18; }
        }
 
        public 
As<T>()
        {
            if (
typeof(T) == typeof(Entity))
                return (
T)(object)GetEntity();
 
            if (
typeof(T) == typeof(ServerClient))
                return (
T)(object)GetClient();
 
            if (
typeof(T) == typeof(bool) && _type == ParameterType.Integer)
                return (
T)(object)((int)_value != 0);
 
            return (
T)Convert.ChangeType(_valuetypeof(T));
        }
 
        public static 
implicit operator Parameter(string value)
        {
            return new 
Parameter(valueParameterType.String);
        }
 
        public static 
implicit operator Parameter(int value)
        {
            return new 
Parameter(valueParameterType.Integer);
        }
 
        public static 
implicit operator Parameter(float value)
        {
            return new 
Parameter(valueParameterType.Float);
        }
 
        public static 
implicit operator Parameter(Vector value)
        {
            return new 
Parameter(valueParameterType.Vector);
        }
 
        public static 
implicit operator Parameter(ServerClient client)
        {
            return new 
Parameter(client.ClientNumParameterType.Entity);
        }
 
        public static 
implicit operator Parameter(Entity entity)
        {
            return new 
Parameter(entity.EntityNumParameterType.Entity);
        }
 
        private 
Entity GetEntity()
        {
            
// Get the constructor for the Entity class.
            
var entityConstructors typeof(Entity).GetConstructors(BindingFlags.NonPublic BindingFlags.Instance);
 
            
// Invoke the constructor with no arguments.
            
var entity = (Entity)entityConstructors[0].Invoke(null);
 
            
// Call the internal SetInformation method with a pointer to the Entity.
            
typeof(Entity).GetMethod("SetInformation"BindingFlags.NonPublic BindingFlags.Instance).Invoke(entity, new object[] { GetEntityFromNum((int)_value) });
 
            return 
entity;
        }
 
        private 
ServerClient GetClient()
        {
            
// Get the constructor for the Client class.
            
var clientConstructors typeof(ServerClient).GetConstructors(BindingFlags.NonPublic BindingFlags.Instance);
 
            
// Invoke the constructor with no arguments.
            
var client = (ServerClient)clientConstructors[0].Invoke(null);
 
            
// Call the internal SetInformation method with a pointer to the Entity.
            
typeof(ServerClient).GetMethod("SetInformation"BindingFlags.NonPublic BindingFlags.Instance).Invoke(client, new object[] { GetClientFromNum((int)_value) });
 
            return 
client;
        }
 
        private static 
IntPtr GetEntityFromNum(int entityNum)
        {
            return (
IntPtr)(EntityAddress.ToInt32() + entityNum 0x274);
        }
 
        private static 
IntPtr GetClientFromNum(int clientNum)
        {
            return (
IntPtr)(ClientAddress.ToInt32() + clientNum 0x78690);
        }
    }
 
    static class 
Timing
    
{
        class 
ServerTimer
        
{
            public 
int Interval getset; }
            public 
long Time getset; }
            public 
ServerClient Target getset; }
            public 
Delegate Function { getset; }
        }
 
        class 
ServerNotify
        
{
            public 
int TargetNum getset; }
            public 
bool HasTarget getset; }
            public 
Delegate Function { getset; }
        }
 
        [
StructLayout(LayoutKind.Sequential)]
        
struct Vec3
        
{
            public 
float X;
            public 
float Y;
            public 
float Z;
 
            public static 
implicit operator Vec3(Vector vector)
            {
                return new 
Vec3 vector.Xvector.Yvector.};
            }
 
            public static 
implicit operator Vector(Vec3 vector)
            {
                return new 
Vector(vector.Xvector.Yvector.Z);
            }
        }
 
        private static 
readonly byte[] ScrAddStringStub = new byte[]
        {
            
0x55// push ebp
            
0x8B0xEC// mov ebp, esp
            
0x51// push ecx
            
0x57// push edi
            
0xC70x450xFC0xD00x110x4F0x00// mov dword ptr [ebp-4], 4F11D0
            
0x8B0x7D0x08// mov edi, [ebp+8]
            
0xFF0x550xFC// call [ebp-4]
            
0x5F// pop edi
            
0x8B0xE5// mov esp, ebp
            
0x5D// pop ebp
            
0xC3 // retn
        
};
 
        private static 
readonly byte[] ScrAddObjectStub = new byte[]
        {
            
0x55// push ebp
            
0x8B0xEC// mov ebp, esp
            
0x51// push ecx
            
0x56// push esi
            
0xC70x450xFC0x500x110x4F0x00// mov dword ptr [ebp-4], 4F1150
            
0x8B0x750x08// mov esi, [ebp+8]
            
0xFF0x550xFC// call [ebp-4]
            
0x5E// pop esi
            
0x8B0xE5// mov esp, ebp
            
0x5D// pop ebp
            
0xC3 // retn
        
};
 
        private static 
readonly byte[] ScrAddVectorStub = new byte[]
        {
            
0x55// push ebp
            
0x8B0xEC// mov ebp, esp
            
0x51// push ecx
            
0x57// push edi
            
0xC70x450xFC0xF00x120x4F0x00// mov dword ptr [ebp-4], 4F12F0
            
0x8B0x7D0x08// mov edi, [ebp+8]
            
0xFF0x550xFC// call [ebp-4]
            
0x5F// pop edi
            
0x8B0xE5// mov esp, ebp
            
0x5D// pop ebp
            
0xC3 // retn
        
};
 
        private static 
readonly byte[] ScrNotifyNumStub = new byte[]
        {
            
0x55// push ebp
            
0x8B0xEC// mov ebp, esp
            
0x51// push ecx
            
0xC70x450xFC0x000xFD0x4E0x00// mov dword ptr [ebp-4], 4EFD00
            
0x8B0x450x0C// mov eax, [ebp+C]
            
0xFF0x750x14// push [ebp+14]
            
0xFF0x750x10// push [ebp+10]
            
0xFF0x750x08// push [ebp+8]
            
0xFF0x550xFC// call [ebp-4]
            
0x830xC40x0C// add esp, C
            
0x8B0xE5// mov esp, ebp
            
0x5D// pop ebp
            
0xC3 // retn    
        
};
 
        private static 
byte[] VmExecuteHookStub = new byte[]
        {
            
0x8B0x440x240x0C// mov eax, [esp+0Ch]
            
0x50// push eax
            
0x8B0x440x240x0C// mov eax, [esp+0Ch]
            
0x50// push eax
            
0x8B0x440x240x0C// mov eax, [esp+0Ch]
            
0x50// push eax
            
0xB80x000x000x000x00// mov eax, <handler>
            
0xFF0xD0// call eax
            
0x830xC40x0C// add esp, 0Ch
            
0x55// push ebp
            
0x8B0xEC// mov ebp, esp
            
0x830xE40xF8// and esp, 0FFFFFFF8h
            
0xB80x000x000x000x00// mov eax, <dest>
            
0xFF0xE0// jmp eax
        
};
 
        [
DllImport("kernel32.dll"SetLastError true)]
        static 
extern bool VirtualProtect(IntPtr lpAddressUIntPtr dwSizeuint flNewProtectout uint lpflOldProtect);
 
        [
DllImport("kernel32.dll"SetLastError true)]
        static 
extern IntPtr VirtualAlloc(IntPtr lpAddressUIntPtr dwSizeuint flAllocationTypeuint flProtect);
 
        [
DllImport("user32.dll"CharSet CharSet.Auto)]
        static 
extern int MessageBox(IntPtr hWndstring textstring captionuint type);
 
        private const 
uint MEM_COMMIT 0x1000;
        private const 
uint MEM_RESERVE 0x2000;
        private const 
uint PAGE_EXECUTE_READWRITE 0x40;
        private const 
uint MB_ICONERROR 0x10;
 
        [
UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private 
delegate void GameScriptNotifyHandlerDelegate(int entityuint typeIntPtr variableStack);
 
        [
UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private 
delegate int ScrAddFloatDelegate(float value);
 
        [
UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private 
delegate int ScrAddIntegerDelegate(int value);
 
        [
UnmanagedFunctionPointer(CallingConvention.CdeclCharSet CharSet.Ansi)]
        private 
delegate void ScrAddStringDelegate(string value);
 
        [
UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private 
delegate int ScrGetEntityIdDelegate(int entityNumint entityShift);
 
        [
UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private 
delegate void ScrAddObjectDelegate(int num);
 
        [
UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private 
delegate void ScrAddVectorDelegate(ref Vec3 vector);
 
        [
UnmanagedFunctionPointer(CallingConvention.CdeclCharSet CharSet.Ansi)]
        private 
delegate int ScrPrepareNotifyDelegate(string messageint zeroint messageLength);
 
        [
UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private 
delegate void ScrNotifyNumDelegate(int entNumint entShiftint prepareResultint paramCount);
 
        private static 
readonly IntPtr VirtualMachineExecuteAddress = (IntPtr)0x4EF610;
        private static 
readonly IntPtr GameScriptStringTablePointer = (IntPtr)0x1C122A4;
        private static 
readonly IntPtr GameScriptObjectTypeArray = (IntPtr)0x1D39804;
        private static 
readonly IntPtr GameScriptObjectToEntityLo = (IntPtr)0x1D39802;
 
        private static 
readonly IntPtr ScrAddFloatAddress = (IntPtr)0x4F1070;
        private static 
readonly IntPtr ScrAddIntegerAddress = (IntPtr)0x4F1020;
        private static 
readonly IntPtr ScrGetEntityIdAddress = (IntPtr)0x4EA450;
        private static 
readonly IntPtr ScrPrepareNotifyAddress = (IntPtr)0x4E7650;
 
        private static 
readonly List<ServerTimerTimers = new List<ServerTimer>();
        private static 
readonly Stopwatch Stopwatch = new Stopwatch();
        private static 
readonly Dictionary<string, List<ServerNotify>> NotifyHandlers = new Dictionary<string, List<ServerNotify>>();
 
        private static 
ScrAddFloatDelegate _scrAddFloatFunc;
        private static 
ScrAddIntegerDelegate _scrAddIntegerFunc;
        private static 
ScrAddStringDelegate _scrAddStringFunc;
        private static 
ScrGetEntityIdDelegate _scrGetEntityIdFunc;
        private static 
ScrAddObjectDelegate _scrAddObjectFunc;
        private static 
ScrAddVectorDelegate _scrAddVectorFunc;
        private static 
ScrPrepareNotifyDelegate _scrPrepareNotifyFunc;
        private static 
ScrNotifyNumDelegate _scrNotifyNumFunc;
        private static 
GCHandle _gch;
 
        private static 
IntPtr _scrNotifyStack IntPtr.Zero;
        private static 
IntPtr _scrAddStringFuncAddress IntPtr.Zero;
        private static 
IntPtr _scrAddObjectFuncAddress IntPtr.Zero;
        private static 
IntPtr _scrAddVectorFuncAddress IntPtr.Zero;
        private static 
IntPtr _scrNotifyNumFuncAddress IntPtr.Zero;
 
        static 
Timing()
        {
            
HookGameScriptNotifyHandler();
            
Stopwatch.Start();
        }
 
        private static 
void PushFloat(float value)
        {
            if (
_scrAddFloatFunc == null)
                
_scrAddFloatFunc = (ScrAddFloatDelegate)Marshal.GetDelegateForFunctionPointer(ScrAddFloatAddresstypeof(ScrAddFloatDelegate));
 
            
_scrAddFloatFunc(value);
        }
 
        private static 
void PushInteger(int value)
        {
            if (
_scrAddIntegerFunc == null)
                
_scrAddIntegerFunc = (ScrAddIntegerDelegate)Marshal.GetDelegateForFunctionPointer(ScrAddIntegerAddresstypeof(ScrAddIntegerDelegate));
 
            
_scrAddIntegerFunc(value);
        }
 
        private static 
void PushString(string value)
        {
            if (
_scrAddStringFuncAddress == IntPtr.Zero)
            {
                
_scrAddStringFuncAddress VirtualAlloc(IntPtr.Zero, (UIntPtr)ScrAddStringStub.LengthMEM_COMMIT MEM_RESERVEPAGE_EXECUTE_READWRITE);
                if (
_scrAddStringFuncAddress == IntPtr.Zero)
                    return;
                
Marshal.Copy(ScrAddStringStub0_scrAddStringFuncAddressScrAddStringStub.Length);
                
_scrAddStringFunc = (ScrAddStringDelegate)Marshal.GetDelegateForFunctionPointer(_scrAddStringFuncAddresstypeof(ScrAddStringDelegate));
            }
 
            
_scrAddStringFunc(value);
        }
 
        private static 
void PushEntity(int entityNum)
        {
            if (
_scrGetEntityIdFunc == null)
                
_scrGetEntityIdFunc = (ScrGetEntityIdDelegate)Marshal.GetDelegateForFunctionPointer(ScrGetEntityIdAddresstypeof(ScrGetEntityIdDelegate));
 
            if (
_scrAddObjectFuncAddress == IntPtr.Zero)
            {
                
_scrAddObjectFuncAddress VirtualAlloc(IntPtr.Zero, (UIntPtr)ScrAddObjectStub.LengthMEM_COMMIT MEM_RESERVEPAGE_EXECUTE_READWRITE);
                if (
_scrAddObjectFuncAddress == IntPtr.Zero)
                    return;
                
Marshal.Copy(ScrAddObjectStub0_scrAddObjectFuncAddressScrAddObjectStub.Length);
                
_scrAddObjectFunc = (ScrAddObjectDelegate)Marshal.GetDelegateForFunctionPointer(_scrAddObjectFuncAddresstypeof(ScrAddObjectDelegate));
            }
 
            
int result _scrGetEntityIdFunc(entityNumentityNum >> 16);
            
_scrAddObjectFunc(result);
        }
 
        private static 
void PushVector(Vector vector)
        {
            if (
_scrAddVectorFuncAddress == IntPtr.Zero)
            {
                
_scrAddVectorFuncAddress VirtualAlloc(IntPtr.Zero, (UIntPtr)ScrAddVectorStub.LengthMEM_COMMIT MEM_RESERVEPAGE_EXECUTE_READWRITE);
                if (
_scrAddVectorFuncAddress == IntPtr.Zero)
                    return;
                
Marshal.Copy(ScrAddVectorStub0_scrAddVectorFuncAddressScrAddVectorStub.Length);
                
_scrAddVectorFunc = (ScrAddVectorDelegate)Marshal.GetDelegateForFunctionPointer(_scrAddVectorFuncAddresstypeof(ScrAddVectorDelegate));
            }
 
            
Vec3 vec vector;
            
_scrAddVectorFunc(ref vec);
        }
 
        public static 
void Notify(Entity entitystring messageparams Parameter[] parameters)
        {
            
Notify(entity.EntityNummessageparameters);
        }
 
        public static 
void Notify(ServerClient clientstring messageparams Parameter[] parameters)
        {
            
Notify(client.ClientNummessageparameters);
        }
 
        private static 
void Notify(int entNumstring messageparams Parameter[] parameters)
        {
            if (
_scrPrepareNotifyFunc == null)
                
_scrPrepareNotifyFunc = (ScrPrepareNotifyDelegate)Marshal.GetDelegateForFunctionPointer(ScrPrepareNotifyAddresstypeof(ScrPrepareNotifyDelegate));
 
            if (
_scrNotifyNumFuncAddress == IntPtr.Zero)
            {
                
_scrNotifyNumFuncAddress VirtualAlloc(IntPtr.Zero, (UIntPtr)ScrNotifyNumStub.LengthMEM_COMMIT MEM_RESERVEPAGE_EXECUTE_READWRITE);
                if (
_scrNotifyNumFuncAddress == IntPtr.Zero)
                    return;
                
Marshal.Copy(ScrNotifyNumStub0_scrNotifyNumFuncAddressScrNotifyNumStub.Length);
                
_scrNotifyNumFunc = (ScrNotifyNumDelegate)Marshal.GetDelegateForFunctionPointer(_scrNotifyNumFuncAddresstypeof(ScrNotifyNumDelegate));
            }
 
            Array.
Reverse(parameters);
 
            foreach (var 
param in parameters)
            {
                switch (
param.Type)
                {
                    case 
ParameterType.Float:
                        
PushFloat(Convert.ToSingle(param.Value));
                        break;
                    case 
ParameterType.Integer:
                        
PushInteger(Convert.ToInt32(param.Value));
                        break;
                    case 
ParameterType.String:
                        
PushString(Convert.ToString(param.Value));
                        break;
                    case 
ParameterType.Entity:
                        
PushEntity(Convert.ToInt32(param.Value));
                        break;
                    case 
ParameterType.Vector:
                        
PushVector((Vector)param.Value);
                        break;
                }
            }
 
            
int result _scrPrepareNotifyFunc(message0message.Length 1);
            
_scrNotifyNumFunc(entNumentNum >> 16resultparameters.Length);
        }
 
        private static 
void HookGameScriptNotifyHandler()
        {
            var 
handler = new GameScriptNotifyHandlerDelegate(GameScriptNotifyHandlerHook);
            
_gch GCHandle.Alloc(handler); // Prevent GC from relocating/freeing function.
            
var handlerAddress Marshal.GetFunctionPointerForDelegate(handler);
            var 
hookStub VirtualAlloc(IntPtr.Zero, (UIntPtr)VmExecuteHookStub.LengthMEM_RESERVE MEM_COMMITPAGE_EXECUTE_READWRITE);
            
BitConverter.GetBytes(handlerAddress.ToInt32()).CopyTo(VmExecuteHookStub16);
            
BitConverter.GetBytes(VirtualMachineExecuteAddress.ToInt32() + 6).CopyTo(VmExecuteHookStub32);
            
Marshal.Copy(VmExecuteHookStub0hookStubVmExecuteHookStub.Length);
            
SetJmpHook(VirtualMachineExecuteAddresshookStub);
        }
 
        private static 
void SetJmpHook(IntPtr originalIntPtr destination)
        {
            
uint oldProtect;
            
VirtualProtect(original, (UIntPtr)5PAGE_EXECUTE_READWRITEout oldProtect);
            var 
hook = new byte[5];
            
hook[0] = 0xE9;
            
BitConverter.GetBytes((destination.ToInt32() - original.ToInt32()) - 5).CopyTo(hook1);
            
Marshal.Copy(hook0originalhook.Length);
            
VirtualProtect(original, (UIntPtr)5oldProtectout oldProtect);
        }
 
        private static 
int GetObjectType(int @object)
        {
            return 
Marshal.ReadInt32(GameScriptObjectTypeArray* @object);
        }
 
        private static 
IntPtr GetVariableStackValueFromIndex(int index)
        {
            return (
IntPtr)(_scrNotifyStack.ToInt32() + -index);
        }
 
        private static 
object[] GetParameters(int argumentCount)
        {
            var 
param = new object[argumentCount];
 
            for (
int i 0argumentCounti++)
            {
                var 
paramType = (ParameterType)Marshal.ReadInt32(GetVariableStackValueFromIndex(i), 4);
                
object value null;
 
                switch (
paramType)
                {
                    case 
ParameterType.Integer:
                        
value Marshal.ReadInt32(GetVariableStackValueFromIndex(i));
                        break;
                    case 
ParameterType.String:
                        
int stringIndex Marshal.ReadInt16(GetVariableStackValueFromIndex(i));
                        
value Marshal.PtrToStringAnsi((IntPtr)(Marshal.ReadInt32(GameScriptStringTablePointer) + 12 stringIndex 4));
                        break;
                    case 
ParameterType.Float:
                        
value Marshal.PtrToStructure(GetVariableStackValueFromIndex(i), typeof(float));
                        break;
                    case 
ParameterType.Entity:
                        
int entityObjectId Marshal.ReadInt32(GetVariableStackValueFromIndex(i));
                        
value ScriptObjectIDToEntityNum(entityObjectId);
                        break;
                    case 
ParameterType.Vector:
                        
value = (Vector)(Vec3)Marshal.PtrToStructure(Marshal.ReadIntPtr(GetVariableStackValueFromIndex(i)), typeof(Vec3));
                        break;
                }
 
                
param[i] = new Parameter(valueparamType);
            }
 
            return 
param;
        }
 
        private static 
int ScriptObjectIDToEntityNum(int scriptObjectId)
        {
            var 
loword = (uint)(Marshal.ReadInt16(GameScriptObjectToEntityLoscriptObjectId));
            var 
hiword = (uint)(Marshal.ReadInt32(GameScriptObjectTypeArrayscriptObjectId) >> 8);
            return (int)((
hiword << 16) | (loword 0xFFFF));
        }
 
        private static 
int GetNotifyArgumentCount()
        {
            
int argumentCount 0;
 
            if (
Marshal.ReadInt32(_scrNotifyStack4) != 8)
            {
                for (
int i _scrNotifyStack.ToInt32(); Marshal.ReadInt32((IntPtr)i4) != 8-= 8)
                    
argumentCount++;
            }
 
            return 
argumentCount;
        }
 
        private static 
void DispatchMessage(int targetEntityNumstring message)
        {
            foreach (var 
handler in NotifyHandlers[message])
            {
                
// Check if the handler specified a client or entity, if so, check the client num.
                
if (handler.HasTarget && handler.TargetNum != targetEntityNum)
                    continue;
 
                var 
handlerParams handler.Function.Method.GetParameters();
 
                
// Check if the handler function has parameters.
                
if (handlerParams.Length 0)
                {
                    
// Calculate the number of arguments.
                    
int argumentCount GetNotifyArgumentCount();
 
                    
// Get the parameters.
                    
object[] parameters GetParameters(argumentCount);
 
                    
// Fix the parameters if the user omitted some of them.
                    
var fixedParameters = new object[handlerParams.Length];
                    Array.
Copy(parametersfixedParametersfixedParameters.Length);
 
                    
// Dynamically invoke the function.
                    
handler.Function.DynamicInvoke(fixedParameters);
                }
                else
                {
                    
// Perform a dynamic invoke with no arguments.
                    
handler.Function.DynamicInvoke();
                }
            }
        }
 
        private static 
void HandleNotifyEvent(int entityuint type)
        {
            if (
type == 0)
                return;
 
            
// Get the current message address.
            
var messageAddress = (IntPtr)(Marshal.ReadInt32(GameScriptStringTablePointer) + 12 type 4);
 
            if (
messageAddress == IntPtr.Zero)
                return;
 
            
int targetEntityNum = -1;
 
            
// Check if the script object type is an entity/client.
            
if (GetObjectType(entity) == 21)
            {
                
// Convert the script object ID to an entity/client num.
                
targetEntityNum ScriptObjectIDToEntityNum(entity);
            }
 
            
// Get the current message.
            
string message Marshal.PtrToStringAnsi(messageAddress);
 
            
// Check the message is valid and notify the handlers.
            
if (string.IsNullOrEmpty(message) || !NotifyHandlers.ContainsKey(message))
                return;
 
            try
            {
                
DispatchMessage(targetEntityNummessage);
            }
            catch (
Exception ex)
            {
                
// Catch any errors and display it as a message box since there's no way to
                // log it without a plugin instance.
                
MessageBox(IntPtr.Zeroex.ToString(), "HandleNotifyEvent failed."MB_ICONERROR);
            }
        }
 
        private static 
void GameScriptNotifyHandlerHook(int entityuint typeIntPtr variableStack)
        {
            
_scrNotifyStack variableStack;
            
HandleNotifyEvent(entitytype);
        }
 
        public static 
void OnInterval(int intervalServerClient targetFunc<bool> function)
        {
            
Timers.Add(new ServerTimer Interval interval, Function = function, Target target });
        }
 
        public static 
void OnInterval(int intervalFunc<bool> function)
        {
            
Timers.Add(new ServerTimer Interval interval, Function = function });
        }
 
        public static 
void AfterDelay(int delayServerClient targetAction action)
        {
            
Timers.Add(new ServerTimer Interval = -1Time Stopwatch.ElapsedMilliseconds delay, Function = actionTarget target });
        }
 
        public static 
void AfterDelay(int delayAction action)
        {
            
Timers.Add(new ServerTimer Interval = -1Time Stopwatch.ElapsedMilliseconds delay, Function = action });
        }
 
        public static 
void ProcessFrame(List<ServerClientclients)
        {
            var 
currentTime Stopwatch.ElapsedMilliseconds;
 
            foreach (var 
timer in Timers.ToArray())
            {
                if (
currentTime timer.Time)
                    continue;
 
                if (
timer.Target != null && clients.FindIndex(sc => sc.XUID == timer.Target.XUID) == -1)
                {
                    
Timers.Remove(timer);
                    continue;
                }
 
                
object returnValue timer.Function.DynamicInvoke();
 
                if (
timer.Interval == -|| timer.Function.Method.ReturnType == typeof(bool) && !(bool)returnValue)
                {
                    
Timers.Remove(timer);
                }
                else
                {
                    
timer.Time currentTime timer.Interval;
                }
            }
        }
 
        private static 
void OnNotify(string typeDelegate actionbool hasTargetint targetNum)
        {
            var 
serverNotify = new ServerNotify { Function = actionHasTarget hasTargetTargetNum targetNum };
 
            if (
NotifyHandlers.ContainsKey(type))
                
NotifyHandlers[type].Add(serverNotify);
            else
                
NotifyHandlers.Add(type, new List<ServerNotify>(new[] { serverNotify }));
        }
 
        public static 
void OnNotify(string typeAction action)
        {
            
OnNotify(typeactionfalse, -1);
        }
 
        public static 
void OnNotify(string typeAction<Parameteraction)
        {
            
OnNotify(typeactionfalse, -1);
        }
 
        public static 
void OnNotify(string typeAction<ParameterParameteraction)
        {
            
OnNotify(typeactionfalse, -1);
        }
 
        public static 
void OnNotify(string typeAction<ParameterParameterParameteraction)
        {
            
OnNotify(typeactionfalse, -1);
        }
 
        public static 
void OnNotify(string typeAction<ParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactionfalse, -1);
        }
 
        public static 
void OnNotify(string typeAction<ParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactionfalse, -1);
        }
 
        public static 
void OnNotify(string typeAction<ParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactionfalse, -1);
        }
 
        public static 
void OnNotify(string typeAction<ParameterParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactionfalse, -1);
        }
 
        public static 
void OnNotify(string typeAction<ParameterParameterParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactionfalse, -1);
        }
 
        public static 
void OnNotify(string typeAction<ParameterParameterParameterParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactionfalse, -1);
        }
 
        public static 
void OnNotify(string typeServerClient clientAction action)
        {
            
OnNotify(typeactiontrueclient.ClientNum);
        }
 
        public static 
void OnNotify(string typeServerClient clientAction<Parameteraction)
        {
            
OnNotify(typeactiontrueclient.ClientNum);
        }
 
        public static 
void OnNotify(string typeServerClient clientAction<ParameterParameteraction)
        {
            
OnNotify(typeactiontrueclient.ClientNum);
        }
 
        public static 
void OnNotify(string typeServerClient clientAction<ParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueclient.ClientNum);
        }
 
        public static 
void OnNotify(string typeServerClient clientAction<ParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueclient.ClientNum);
        }
 
        public static 
void OnNotify(string typeServerClient clientAction<ParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueclient.ClientNum);
        }
 
        public static 
void OnNotify(string typeServerClient clientAction<ParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueclient.ClientNum);
        }
 
        public static 
void OnNotify(string typeServerClient clientAction<ParameterParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueclient.ClientNum);
        }
 
        public static 
void OnNotify(string typeServerClient clientAction<ParameterParameterParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueclient.ClientNum);
        }
 
        public static 
void OnNotify(string typeServerClient clientAction<ParameterParameterParameterParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueclient.ClientNum);
        }
 
        public static 
void OnNotify(string typeEntity entityAction action)
        {
            
OnNotify(typeactiontrueentity.EntityNum);
        }
 
        public static 
void OnNotify(string typeEntity entityAction<Parameteraction)
        {
            
OnNotify(typeactiontrueentity.EntityNum);
        }
 
        public static 
void OnNotify(string typeEntity entityAction<ParameterParameteraction)
        {
            
OnNotify(typeactiontrueentity.EntityNum);
        }
 
        public static 
void OnNotify(string typeEntity entityAction<ParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueentity.EntityNum);
        }
 
        public static 
void OnNotify(string typeEntity entityAction<ParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueentity.EntityNum);
        }
 
        public static 
void OnNotify(string typeEntity entityAction<ParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueentity.EntityNum);
        }
 
        public static 
void OnNotify(string typeEntity entityAction<ParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueentity.EntityNum);
        }
 
        public static 
void OnNotify(string typeEntity entityAction<ParameterParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueentity.EntityNum);
        }
 
        public static 
void OnNotify(string typeEntity entityAction<ParameterParameterParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueentity.EntityNum);
        }
 
        public static 
void OnNotify(string typeEntity entityAction<ParameterParameterParameterParameterParameterParameterParameterParameterParameteraction)
        {
            
OnNotify(typeactiontrueentity.EntityNum);
        }
    }


No need to lie, the code works stably
Reply

#8
Threading crashes the servers. Its no lie its the truth.
~FYANB~ Servers Website

Primary Account:
[Image: 76561198070236721.png]
Secondary Account:
[Image: 76561198096107676.png]
Third Account:
[Image: 76561198164751656.png]
Reply

#9
Also tekno and Retail MW3 are different in terms of addon support and modding capabilities. Threading causes problems on Retail. Tekno isnt supported here anyways so...
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  [Request] User welcome message abdul samad 10 6,011 02-17-2014, 12:24
Last Post: Nekochan
  Help Headshot Message Plugin Slimpy 4 3,484 01-23-2014, 10:18
Last Post: Slimpy

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.