• 9 Vote(s) - 4.56 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Release MW3 Server Addon Extensions
Standing on a solid carepackage with angles set makes the camera shake
  Reply
@archit Orly

(12-10-2012, 12:04)master131 Wrote: Known bugs:
- Standing on a hidden care package with collision will cause the player's camera to shake.
  Reply
It isn't hidden after pasting timing.cs I got many errors but to fix them I just had to rewrite many of the things exactly the same(weird) and now as soon as I join the server crashes help please
  Reply
ive tried to do the timing.cs just tons of errors
[Image: b_560_95_1.png]


[Image: b_560_95_1.png]

  Reply
I pasted the code in notepad++ and saw ? marks in between many places so I replaced them and got this
CSHARP Code
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Reflection;
  5. using System.Runtime.InteropServices;
  6.  
  7. namespace Addon
  8. {
  9. // ***** Uncomment if using .NET Framework 2.0 or .NET Framework 3.0 *****
  10. // ***** Yes, all of it, seriously. *****
  11. public delegate TResult Func<TResult>();
  12. public delegate void Action();
  13. public delegate void Action<T1, T2>(T1 arg1, T2 arg2);
  14. public delegate void Action<T1, T2, T3>(T1 arg1, T2 arg2, T3 arg3);
  15. public delegate void Action<T1, T2, T3, T4>(T1 arg1, T2 arg2, T3 arg3, T4 arg4);
  16. public delegate void Action<T1, T2, T3, T4, T5>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5);
  17. public delegate void Action<T1, T2, T3, T4, T5, T6>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6);
  18. 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);
  19. 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);
  20. 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);
  21.  
  22. enum ParameterType
  23. {
  24. Entity = 1,
  25. String = 2,
  26. Vector = 4,
  27. Float = 5,
  28. Integer = 6
  29. }
  30.  
  31. class Parameter
  32. {
  33. private static readonly IntPtr EntityAddress = (IntPtr)0x01918900;
  34. private static readonly IntPtr ClientAddress = (IntPtr)0x4A0FE90;
  35.  
  36. private readonly object _value;
  37. private readonly ParameterType _type;
  38.  
  39. internal Parameter(object value, ParameterType type)
  40. {
  41. _value = value;
  42. _type = type;
  43. }
  44.  
  45. public ParameterType Type
  46. {
  47. get { return _type; }
  48. }
  49.  
  50. public object Value
  51. {
  52. get { return _value; }
  53. }
  54.  
  55. public bool IsPlayer
  56. {
  57. get { return _type == ParameterType.Entity && (int)_value < 18; }
  58. }
  59.  
  60. public bool IsEntity
  61. {
  62. get { return _type == ParameterType.Entity && (int)_value >= 18; }
  63. }
  64.  
  65. public T As<T>()
  66. {
  67. if (typeof(T) == typeof(Entity))
  68. return (T)(object)GetEntity();
  69.  
  70. if (typeof(T) == typeof(ServerClient))
  71. return (T)(object)GetClient();
  72.  
  73. return (T)Convert.ChangeType(_value, typeof(T));
  74. }
  75.  
  76. public static implicit operator Parameter(string value)
  77. {
  78. return new Parameter(value, ParameterType.String);
  79. }
  80.  
  81. public static implicit operator Parameter(int value)
  82. {
  83. return new Parameter(value, ParameterType.Integer);
  84. }
  85.  
  86. public static implicit operator Parameter(float value)
  87. {
  88. return new Parameter(value, ParameterType.Float);
  89. }
  90.  
  91. public static implicit operator Parameter(Vector value)
  92. {
  93. return new Parameter(value, ParameterType.Vector);
  94. }
  95.  
  96. public static implicit operator Parameter(ServerClient client)
  97. {
  98. return new Parameter(client.ClientNum, ParameterType.Entity);
  99. }
  100.  
  101. public static implicit operator Parameter(Entity entity)
  102. {
  103. return new Parameter(entity.EntityNum, ParameterType.Entity);
  104. }
  105.  
  106. private Entity GetEntity()
  107. {
  108. // Get the constructor for the Entity class.
  109. var entityConstructors = typeof(Entity).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance);
  110.  
  111. // Invoke the constructor with no arguments.
  112. var entity = (Entity)entityConstructors[0].Invoke(null);
  113.  
  114. // Call the internal SetInformation method with a pointer to the Entity.
  115. typeof(Entity).GetMethod("SetInformation", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(entity, new object[] { GetEntityFromNum((int)_value) });
  116.  
  117. return entity;
  118. }
  119.  
  120. private ServerClient GetClient()
  121. {
  122. // Get the constructor for the Client class.
  123. var clientConstructors = typeof(ServerClient).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance);
  124.  
  125. // Invoke the constructor with no arguments.
  126. var client = (ServerClient)clientConstructors[0].Invoke(null);
  127.  
  128. // Call the internal SetInformation method with a pointer to the Entity.
  129. typeof(ServerClient).GetMethod("SetInformation", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(client, new object[] { GetClientFromNum((int)_value) });
  130.  
  131. return client;
  132. }
  133.  
  134. private static IntPtr GetEntityFromNum(int entityNum)
  135. {
  136. return (IntPtr)(EntityAddress.ToInt32() + entityNum * 0x274);
  137. }
  138.  
  139. private static IntPtr GetClientFromNum(int clientNum)
  140. {
  141. return (IntPtr)(ClientAddress.ToInt32() + clientNum * 0x78690);
  142. }
  143. }
  144.  
  145. static class Timing
  146. {
  147. class ServerTimer
  148. {
  149. public int Interval { get; set; }
  150. public long Time { get; set; }
  151. public ServerClient Target { get; set; }
  152. public Delegate Function { get; set; }
  153. }
  154.  
  155. class ServerNotify
  156. {
  157. public int TargetNum { get; set; }
  158. public bool HasTarget { get; set; }
  159. public Delegate Function { get; set; }
  160. }
  161.  
  162. [StructLayout(LayoutKind.Sequential)]
  163. struct Vec3
  164. {
  165. public float X;
  166. public float Y;
  167. public float Z;
  168.  
  169. public static implicit operator Vec3(Vector vector)
  170. {
  171. return new Vec3 { X = vector.X, Y = vector.Y, Z = vector.Z };
  172. }
  173.  
  174. public static implicit operator Vector(Vec3 vector)
  175. {
  176. return new Vector(vector.X, vector.Y, vector.Z);
  177. }
  178. }
  179.  
  180. private static readonly byte[] ScrAddStringStub = new byte[]
  181. {
  182. 0x55, // push ebp
  183. 0x8B, 0xEC, // mov ebp, esp
  184. 0x51, // push ecx
  185. 0x57, // push edi
  186. 0xC7, 0x45, 0xFC, 0xD0, 0x11, 0x4F, 0x00, // mov dword ptr [ebp-4], 4F11D0
  187. 0x8B, 0x7D, 0x08, // mov edi, [ebp+8]
  188. 0xFF, 0x55, 0xFC, // call [ebp-4]
  189. 0x5F, // pop edi
  190. 0x8B, 0xE5, // mov esp, ebp
  191. 0x5D, // pop ebp
  192. 0xC3 // retn
  193. };
  194.  
  195. private static readonly byte[] ScrAddObjectStub = new byte[]
  196. {
  197. 0x55, // push ebp
  198. 0x8B, 0xEC, // mov ebp, esp
  199. 0x51, // push ecx
  200. 0x56, // push esi
  201. 0xC7, 0x45, 0xFC, 0x50, 0x11, 0x4F, 0x00, // mov dword ptr [ebp-4], 4F1150
  202. 0x8B, 0x75, 0x08, // mov esi, [ebp+8]
  203. 0xFF, 0x55, 0xFC, // call [ebp-4]
  204. 0x5E, // pop esi
  205. 0x8B, 0xE5, // mov esp, ebp
  206. 0x5D, // pop ebp
  207. 0xC3 // retn
  208. };
  209.  
  210. private static readonly byte[] ScrAddVectorStub = new byte[]
  211. {
  212. 0x55, // push ebp
  213. 0x8B, 0xEC, // mov ebp, esp
  214. 0x51, // push ecx
  215. 0x57, // push edi
  216. 0xC7, 0x45, 0xFC, 0xF0, 0x12, 0x4F, 0x00, // mov dword ptr [ebp-4], 4F12F0
  217. 0x8B, 0x7D, 0x08, // mov edi, [ebp+8]
  218. 0xFF, 0x55, 0xFC, // call [ebp-4]
  219. 0x5F, // pop edi
  220. 0x8B, 0xE5, // mov esp, ebp
  221. 0x5D, // pop ebp
  222. 0xC3 // retn
  223. };
  224.  
  225. private static readonly byte[] ScrNotifyNumStub = new byte[]
  226. {
  227. 0x55, // push ebp
  228. 0x8B, 0xEC, // mov ebp, esp
  229. 0x51, // push ecx
  230. 0xC7, 0x45, 0xFC, 0x00, 0xFD, 0x4E, 0x00, // mov dword ptr [ebp-4], 4EFD00
  231. 0x8B, 0x45, 0x0C, // mov eax, [ebp+C]
  232. 0xFF, 0x75, 0x14, // push [ebp+14]
  233. 0xFF, 0x75, 0x10, // push [ebp+10]
  234. 0xFF, 0x75, 0x08, // push [ebp+8]
  235. 0xFF, 0x55, 0xFC, // call [ebp-4]
  236. 0x83, 0xC4, 0x0C, // add esp, C
  237. 0x8B, 0xE5, // mov esp, ebp
  238. 0x5D, // pop ebp
  239. 0xC3 // retn
  240. };
  241.  
  242. [DllImport("kernel32.dll", SetLastError = true)]
  243. static extern bool VirtualProtect(IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);
  244.  
  245. [DllImport("kernel32.dll", SetLastError = true)]
  246. static extern IntPtr VirtualAlloc(IntPtr lpAddress, UIntPtr dwSize, uint flAllocationType, uint flProtect);
  247.  
  248. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  249. static extern int MessageBox(IntPtr hWnd, string text, string caption, uint type);
  250.  
  251. private const uint MEM_COMMIT = 0x1000;
  252. private const uint MEM_RESERVE = 0x2000;
  253. private const uint PAGE_EXECUTE_READWRITE = 0x40;
  254. private const uint MB_ICONERROR = 0x10;
  255.  
  256. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  257. private delegate int GameScriptNotifyHandlerDelegate(int scriptObjectId, int messageIndex, IntPtr argumentInfoPtr);
  258.  
  259. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  260. private delegate int ScrAddFloatDelegate(float value);
  261.  
  262. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  263. private delegate int ScrAddIntegerDelegate(int value);
  264.  
  265. [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
  266. private delegate void ScrAddStringDelegate(string value);
  267.  
  268. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  269. private delegate int ScrGetEntityIdDelegate(int entityNum, int entityShift);
  270.  
  271. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  272. private delegate void ScrAddObjectDelegate(int num);
  273.  
  274. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  275. private delegate void ScrAddVectorDelegate(ref Vec3 vector);
  276.  
  277. [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
  278. private delegate int ScrPrepareNotifyDelegate(string message, int zero, int messageLength);
  279.  
  280. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  281. private delegate void ScrNotifyNumDelegate(int entNum, int entShift, int prepareResult, int paramCount);
  282.  
  283. private static readonly IntPtr GameScriptNotifyHandler = (IntPtr)0x4EF610;
  284. private static readonly IntPtr GameScriptStringTablePointer = (IntPtr)0x1C122A4;
  285. private static readonly IntPtr GameScriptObjectTypeArray = (IntPtr)0x1D39804;
  286. private static readonly IntPtr GameScriptObjectToEntityLo = (IntPtr)0x1D39802;
  287.  
  288. private static readonly IntPtr ScrAddFloatAddress = (IntPtr)0x4F1070;
  289. private static readonly IntPtr ScrAddIntegerAddress = (IntPtr)0x4F1020;
  290. private static readonly IntPtr ScrGetEntityIdAddress = (IntPtr)0x4EA450;
  291. private static readonly IntPtr ScrPrepareNotifyAddress = (IntPtr)0x4E7650;
  292.  
  293. private static readonly List<ServerTimer> Timers = new List<ServerTimer>();
  294. private static readonly Stopwatch Stopwatch = new Stopwatch();
  295. private static readonly Dictionary<string, List<ServerNotify>> NotifyHandlers = new Dictionary<string, List<ServerNotify>>();
  296.  
  297. private static GameScriptNotifyHandlerDelegate _gameScriptNotifyHandlerOriginal;
  298. private static ScrAddFloatDelegate _scrAddFloatFunc;
  299. private static ScrAddIntegerDelegate _scrAddIntegerFunc;
  300. private static ScrAddStringDelegate _scrAddStringFunc;
  301. private static ScrGetEntityIdDelegate _scrGetEntityIdFunc;
  302. private static ScrAddObjectDelegate _scrAddObjectFunc;
  303. private static ScrAddVectorDelegate _scrAddVectorFunc;
  304. private static ScrPrepareNotifyDelegate _scrPrepareNotifyFunc;
  305. private static ScrNotifyNumDelegate _scrNotifyNumFunc;
  306. private static IntPtr _lastGameScriptArgumentInfoPtr = IntPtr.Zero;
  307. private static IntPtr _scrAddStringFuncAddress = IntPtr.Zero;
  308. private static IntPtr _scrAddObjectFuncAddress = IntPtr.Zero;
  309. private static IntPtr _scrAddVectorFuncAddress = IntPtr.Zero;
  310. private static IntPtr _scrNotifyNumFuncAddress = IntPtr.Zero;
  311.  
  312. static Timing()
  313. {
  314. HookGameScriptNotifyHandler();
  315. Stopwatch.Start();
  316. }
  317.  
  318. private static void PushFloat(float value)
  319. {
  320. if (_scrAddFloatFunc == null)
  321. _scrAddFloatFunc = (ScrAddFloatDelegate)Marshal.GetDelegateForFunctionPointer(ScrAddFloatAddress, typeof(ScrAddFloatDelegate));
  322.  
  323. _scrAddFloatFunc(value);
  324. }
  325.  
  326. private static void PushInteger(int value)
  327. {
  328. if (_scrAddIntegerFunc == null)
  329. _scrAddIntegerFunc = (ScrAddIntegerDelegate)Marshal.GetDelegateForFunctionPointer(ScrAddIntegerAddress, typeof(ScrAddIntegerDelegate));
  330.  
  331. _scrAddIntegerFunc(value);
  332. }
  333.  
  334. private static void PushString(string value)
  335. {
  336. if (_scrAddStringFuncAddress == IntPtr.Zero)
  337. {
  338. _scrAddStringFuncAddress = VirtualAlloc(IntPtr.Zero, (UIntPtr)ScrAddStringStub.Length, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
  339. if (_scrAddStringFuncAddress == IntPtr.Zero)
  340. return;
  341. Marshal.Copy(ScrAddStringStub, 0, _scrAddStringFuncAddress, ScrAddStringStub.Length);
  342. _scrAddStringFunc = (ScrAddStringDelegate)Marshal.GetDelegateForFunctionPointer(_scrAddStringFuncAddress, typeof(ScrAddStringDelegate));
  343. }
  344.  
  345. _scrAddStringFunc(value);
  346. }
  347.  
  348. private static void PushEntity(int entityNum)
  349. {
  350. if (_scrGetEntityIdFunc == null)
  351. _scrGetEntityIdFunc = (ScrGetEntityIdDelegate)Marshal.GetDelegateForFunctionPointer(ScrGetEntityIdAddress, typeof(ScrGetEntityIdDelegate));
  352.  
  353. if (_scrAddObjectFuncAddress == IntPtr.Zero)
  354. {
  355. _scrAddObjectFuncAddress = VirtualAlloc(IntPtr.Zero, (UIntPtr)ScrAddObjectStub.Length, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
  356. if (_scrAddObjectFuncAddress == IntPtr.Zero)
  357. return;
  358. Marshal.Copy(ScrAddObjectStub, 0, _scrAddObjectFuncAddress, ScrAddObjectStub.Length);
  359. _scrAddObjectFunc = (ScrAddObjectDelegate)Marshal.GetDelegateForFunctionPointer(_scrAddObjectFuncAddress, typeof(ScrAddObjectDelegate));
  360. }
  361.  
  362. int result = _scrGetEntityIdFunc(entityNum, entityNum >> 16);
  363. _scrAddObjectFunc(result);
  364. }
  365.  
  366. private static void PushVector(Vector vector)
  367. {
  368. if (_scrAddVectorFuncAddress == IntPtr.Zero)
  369. {
  370. _scrAddVectorFuncAddress = VirtualAlloc(IntPtr.Zero, (UIntPtr)ScrAddVectorStub.Length, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
  371. if (_scrAddVectorFuncAddress == IntPtr.Zero)
  372. return;
  373. Marshal.Copy(ScrAddVectorStub, 0, _scrAddVectorFuncAddress, ScrAddVectorStub.Length);
  374. _scrAddVectorFunc = (ScrAddVectorDelegate)Marshal.GetDelegateForFunctionPointer(_scrAddVectorFuncAddress, typeof(ScrAddVectorDelegate));
  375. }
  376.  
  377. Vec3 vec = vector;
  378. _scrAddVectorFunc(ref vec);
  379. }
  380.  
  381. public static void Notify(Entity entity, string message, params Parameter[] parameters)
  382. {
  383. Notify(entity.EntityNum, message, parameters);
  384. }
  385.  
  386. public static void Notify(ServerClient client, string message, params Parameter[] parameters)
  387. {
  388. Notify(client.ClientNum, message, parameters);
  389. }
  390.  
  391. private static void Notify(int entNum, string message, params Parameter[] parameters)
  392. {
  393. if (_scrPrepareNotifyFunc == null)
  394. _scrPrepareNotifyFunc = (ScrPrepareNotifyDelegate)Marshal.GetDelegateForFunctionPointer(ScrPrepareNotifyAddress, typeof(ScrPrepareNotifyDelegate));
  395.  
  396. if (_scrNotifyNumFuncAddress == IntPtr.Zero)
  397. {
  398. _scrNotifyNumFuncAddress = VirtualAlloc(IntPtr.Zero, (UIntPtr)ScrNotifyNumStub.Length, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
  399. if (_scrNotifyNumFuncAddress == IntPtr.Zero)
  400. return;
  401. Marshal.Copy(ScrNotifyNumStub, 0, _scrNotifyNumFuncAddress, ScrNotifyNumStub.Length);
  402. _scrNotifyNumFunc = (ScrNotifyNumDelegate)Marshal.GetDelegateForFunctionPointer(_scrNotifyNumFuncAddress, typeof(ScrNotifyNumDelegate));
  403. }
  404.  
  405. Array.Reverse(parameters);
  406.  
  407. foreach (var param in parameters)
  408. {
  409. switch (param.Type)
  410. {
  411. case ParameterType.Float:
  412. PushFloat(Convert.ToSingle(param.Value));
  413. break;
  414. case ParameterType.Integer:
  415. PushInteger(Convert.ToInt32(param.Value));
  416. break;
  417. case ParameterType.String:
  418. PushString(Convert.ToString(param.Value));
  419. break;
  420. case ParameterType.Entity:
  421. PushEntity(Convert.ToInt32(param.Value));
  422. break;
  423. case ParameterType.Vector:
  424. PushVector((Vector)param.Value);
  425. break;
  426. }
  427. }
  428.  
  429. int result = _scrPrepareNotifyFunc(message, 0, message.Length + 1);
  430. _scrNotifyNumFunc(entNum, entNum >> 16, result, parameters.Length);
  431. }
  432.  
  433. private static void HookGameScriptNotifyHandler()
  434. {
  435. IntPtr hookDestination = Marshal.GetFunctionPointerForDelegate(new GameScriptNotifyHandlerDelegate(GameScriptNotifyHandlerHook));
  436. IntPtr originalFunction = DetourFunction(GameScriptNotifyHandler, hookDestination, 6);
  437. _gameScriptNotifyHandlerOriginal = (GameScriptNotifyHandlerDelegate)Marshal.GetDelegateForFunctionPointer(originalFunction, typeof(GameScriptNotifyHandlerDelegate));
  438. }
  439.  
  440. private static int GetObjectType(int scriptObjectId)
  441. {
  442. return Marshal.ReadInt32(GameScriptObjectTypeArray, 8 * scriptObjectId);
  443. }
  444.  
  445. private static IntPtr GetParameterValueAddressFromIndex(int index)
  446. {
  447. return (IntPtr)(_lastGameScriptArgumentInfoPtr.ToInt32() + -8 * index);
  448. }
  449.  
  450. private static object[] GetParameters(int argumentCount)
  451. {
  452. var param = new object[argumentCount];
  453.  
  454. for (int i = 0; i < argumentCount; i++)
  455. {
  456. var paramType = (ParameterType)Marshal.ReadInt32(GetParameterValueAddressFromIndex(i), 4);
  457. object value = null;
  458.  
  459. switch (paramType)
  460. {
  461. case ParameterType.Integer:
  462. value = Marshal.ReadInt32(GetParameterValueAddressFromIndex(i));
  463. break;
  464. case ParameterType.String:
  465. int stringIndex = Marshal.ReadInt16(GetParameterValueAddressFromIndex(i));
  466. value = Marshal.PtrToStringAnsi((IntPtr)(Marshal.ReadInt32(GameScriptStringTablePointer) + 12 * stringIndex + 4));
  467. break;
  468. case ParameterType.Float:
  469. value = Marshal.PtrToStructure(GetParameterValueAddressFromIndex(i), typeof(float));
  470. break;
  471. case ParameterType.Entity:
  472. int entityObjectId = Marshal.ReadInt32(GetParameterValueAddressFromIndex(i));
  473. value = ScriptObjectIDToEntityNum(entityObjectId);
  474. break;
  475. case ParameterType.Vector:
  476. value = (Vector)(Vec3)Marshal.PtrToStructure(Marshal.ReadIntPtr(GetParameterValueAddressFromIndex(i)), typeof(Vec3));
  477. break;
  478. }
  479.  
  480. param[i] = new Parameter(value, paramType);
  481. }
  482.  
  483. return param;
  484. }
  485.  
  486. private static int ScriptObjectIDToEntityNum(int scriptObjectId)
  487. {
  488. var loword = (uint)(Marshal.ReadInt16(GameScriptObjectToEntityLo, 8 * scriptObjectId));
  489. var hiword = (uint)(Marshal.ReadInt32(GameScriptObjectTypeArray, 8 * scriptObjectId) >> 8);
  490. return (int)((hiword << 16) | (loword & 0xFFFF));
  491. }
  492.  
  493. private static int GetNotifyArgumentCount()
  494. {
  495. int argumentCount = 0;
  496.  
  497. if (Marshal.ReadInt32(_lastGameScriptArgumentInfoPtr, 4) != 8)
  498. {
  499. for (int i = _lastGameScriptArgumentInfoPtr.ToInt32(); Marshal.ReadInt32((IntPtr)i, 4) != 8; i -= 8)
  500. argumentCount++;
  501. }
  502.  
  503. return argumentCount;
  504. }
  505.  
  506. private static void DispatchMessage(int targetEntityNum, string message)
  507. {
  508. foreach (var handler in NotifyHandlers[message])
  509. {
  510. // Check if the handler specified a client or entity, if so, check the client num.
  511. if (handler.HasTarget && handler.TargetNum != targetEntityNum)
  512. continue;
  513.  
  514. var handlerParams = handler.Function.Method.GetParameters();
  515.  
  516. // Check if the handler function has parameters.
  517. if (handlerParams.Length > 0)
  518. {
  519. // Calculate the number of arguments.
  520. int argumentCount = GetNotifyArgumentCount();
  521.  
  522. // Get the parameters.
  523. object[] parameters = GetParameters(argumentCount);
  524.  
  525. // Fix the parameters if the user omitted some of them.
  526. var fixedParameters = new object[handlerParams.Length];
  527. Array.Copy(parameters, fixedParameters, fixedParameters.Length);
  528.  
  529. // Dynamically invoke the function.
  530. handler.Function.DynamicInvoke(fixedParameters);
  531. }
  532. else
  533. {
  534. // Perform a dynamic invoke with no arguments.
  535. handler.Function.DynamicInvoke();
  536. }
  537. }
  538. }
  539.  
  540. private static void HandleNotifyEvent(int scriptObjectId, int messageIndex)
  541. {
  542. if (messageIndex == 0) return;
  543.  
  544. // Get the current message address.
  545. var messageAddress = (IntPtr)(Marshal.ReadInt32(GameScriptStringTablePointer) + 12 * messageIndex + 4);
  546.  
  547. if (messageAddress == IntPtr.Zero)
  548. return;
  549.  
  550. int targetEntityNum = -1;
  551.  
  552. // Check if the script object type is an entity/client.
  553. if (GetObjectType(scriptObjectId) == 21)
  554. {
  555. // Convert the script object ID to an entity/client num.
  556. targetEntityNum = ScriptObjectIDToEntityNum(scriptObjectId);
  557. }
  558.  
  559. // Get the current message.
  560. string message = Marshal.PtrToStringAnsi(messageAddress);
  561.  
  562. // Check the message is valid and notify the handlers.
  563. if (string.IsNullOrEmpty(message) || !NotifyHandlers.ContainsKey(message))
  564. return;
  565.  
  566. try
  567. {
  568. DispatchMessage(targetEntityNum, message);
  569. }
  570. catch (Exception ex)
  571. {
  572. // Catch any errors and display it as a message box since there's no way to
  573. // log it without a plugin instance.
  574. MessageBox(IntPtr.Zero, ex.ToString(), "HandleNotifyEvent failed.", MB_ICONERROR);
  575. }
  576. }
  577.  
  578. private static int GameScriptNotifyHandlerHook(int scriptObjectId, int messageIndex, IntPtr argumentInfoPtr)
  579. {
  580. _lastGameScriptArgumentInfoPtr = argumentInfoPtr;
  581. HandleNotifyEvent(scriptObjectId, messageIndex);
  582. return _gameScriptNotifyHandlerOriginal(scriptObjectId, messageIndex, argumentInfoPtr);
  583. }
  584.  
  585. private static IntPtr DetourFunction(IntPtr originalFunction, IntPtr hookFunction, int length)
  586. {
  587. IntPtr jmp = VirtualAlloc(IntPtr.Zero, (UIntPtr)(length + 5), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
  588.  
  589. uint oldProtect;
  590. VirtualProtect(originalFunction, (UIntPtr)length, PAGE_EXECUTE_READWRITE, out oldProtect);
  591.  
  592. var buffer = new byte[length];
  593. Marshal.Copy(originalFunction, buffer, 0, length);
  594. Marshal.Copy(buffer, 0, jmp, length);
  595.  
  596. jmp = (IntPtr)(jmp.ToInt32() + length);
  597.  
  598. Marshal.WriteByte(jmp, 0xE9);
  599. Marshal.Copy(BitConverter.GetBytes((originalFunction.ToInt32() + length - jmp.ToInt32()) - 5), 0, (IntPtr)(jmp.ToInt32() + 1), 4);
  600.  
  601. Marshal.WriteByte(originalFunction, 0xE9);
  602. Marshal.Copy(BitConverter.GetBytes((hookFunction.ToInt32() - originalFunction.ToInt32()) - 5), 0, (IntPtr)(originalFunction.ToInt32() + 1), 4);
  603.  
  604. VirtualProtect(originalFunction, (UIntPtr)length, oldProtect, out oldProtect);
  605.  
  606. return (IntPtr)(jmp.ToInt32() - length);
  607. }
  608.  
  609. public static void OnInterval(int interval, ServerClient target, Func<bool> function)
  610. {
  611. Timers.Add(new ServerTimer { Interval = interval, Function = function, Target = target });
  612. }
  613.  
  614. public static void OnInterval(int interval, Func<bool> function)
  615. {
  616. Timers.Add(new ServerTimer { Interval = interval, Function = function });
  617. }
  618.  
  619. public static void AfterDelay(int delay, ServerClient target, Action action)
  620. {
  621. Timers.Add(new ServerTimer { Interval = -1, Time = Stopwatch.ElapsedMilliseconds + delay, Function = action, Target = target });
  622. }
  623.  
  624. public static void AfterDelay(int delay, Action action)
  625. {
  626. Timers.Add(new ServerTimer { Interval = -1, Time = Stopwatch.ElapsedMilliseconds + delay, Function = action });
  627. }
  628.  
  629. public static void ProcessFrame(List<ServerClient> clients)
  630. {
  631. var currentTime = Stopwatch.ElapsedMilliseconds;
  632.  
  633. foreach (var timer in Timers.ToArray())
  634. {
  635. if (currentTime < timer.Time)
  636. continue;
  637.  
  638. if (timer.Target != null && clients.FindIndex(sc => sc.XUID == timer.Target.XUID) == -1)
  639. {
  640. Timers.Remove(timer);
  641. continue;
  642. }
  643.  
  644. object returnValue = timer.Function.DynamicInvoke();
  645.  
  646. if (timer.Interval == -1 || timer.Function.Method.ReturnType == typeof(bool) && !(bool)returnValue)
  647. {
  648. Timers.Remove(timer);
  649. }
  650. else
  651. {
  652. timer.Time = currentTime + timer.Interval;
  653. }
  654. }
  655. }
  656.  
  657. private static void OnNotify(string type, Delegate action, bool hasTarget, int targetNum)
  658. {
  659. var serverNotify = new ServerNotify { Function = action, HasTarget = hasTarget, TargetNum = targetNum };
  660.  
  661. if (NotifyHandlers.ContainsKey(type))
  662. NotifyHandlers[type].Add(serverNotify);
  663. else
  664. NotifyHandlers.Add(type, new List<ServerNotify>(new[] { serverNotify }));
  665. }
  666.  
  667. public static void OnNotify(string type, Action action)
  668. {
  669. OnNotify(type, action, false, -1);
  670. }
  671.  
  672. public static void OnNotify(string type, Action<Parameter> action)
  673. {
  674. OnNotify(type, action, false, -1);
  675. }
  676.  
  677. public static void OnNotify(string type, Action<Parameter, Parameter> action)
  678. {
  679. OnNotify(type, action, false, -1);
  680. }
  681.  
  682. public static void OnNotify(string type, Action<Parameter, Parameter, Parameter> action)
  683. {
  684. OnNotify(type, action, false, -1);
  685. }
  686.  
  687. public static void OnNotify(string type, Action<Parameter, Parameter, Parameter, Parameter> action)
  688. {
  689. OnNotify(type, action, false, -1);
  690. }
  691.  
  692. public static void OnNotify(string type, Action<Parameter, Parameter, Parameter, Parameter, Parameter> action)
  693. {
  694. OnNotify(type, action, false, -1);
  695. }
  696.  
  697. public static void OnNotify(string type, Action<Parameter, Parameter, Parameter, Parameter, Parameter, Parameter> action)
  698. {
  699. OnNotify(type, action, false, -1);
  700. }
  701.  
  702. public static void OnNotify(string type, Action<Parameter, Parameter, Parameter, Parameter, Parameter, Parameter, Parameter> action)
  703. {
  704. OnNotify(type, action, false, -1);
  705. }
  706.  
  707. public static void OnNotify(string type, Action<Parameter, Parameter, Parameter, Parameter, Parameter, Parameter, Parameter, Parameter> action)
  708. {
  709. OnNotify(type, action, false, -1);
  710. }
  711.  
  712. public static void OnNotify(string type, Action<Parameter, Parameter, Parameter, Parameter, Parameter, Parameter, Parameter, Parameter, Parameter> action)
  713. {
  714. OnNotify(type, action, false, -1);
  715. }
  716.  
  717. public static void OnNotify(string type, ServerClient client, Action action)
  718. {
  719. OnNotify(type, action, true, client.ClientNum);
  720. }
  721.  
  722. public static void OnNotify(string type, ServerClient client, Action<Parameter> action)
  723. {
  724. OnNotify(type, action, true, client.ClientNum);
  725. }
  726.  
  727. public static void OnNotify(string type, ServerClient client, Action<Parameter, Parameter> action)
  728. {
  729. OnNotify(type, action, true, client.ClientNum);
  730. }
  731.  
  732. public static void OnNotify(string type, ServerClient client, Action<Parameter, Parameter, Parameter> action)
  733. {
  734. OnNotify(type, action, true, client.ClientNum);
  735. }
  736.  
  737. public static void OnNotify(string type, ServerClient client, Action<Parameter, Parameter, Parameter, Parameter> action)
  738. {
  739. OnNotify(type, action, true, client.ClientNum);
  740. }
  741.  
  742. public static void OnNotify(string type, ServerClient client, Action<Parameter, Parameter, Parameter, Parameter, Parameter> action)
  743. {
  744. OnNotify(type, action, true, client.ClientNum);
  745. }
  746.  
  747. public static void OnNotify(string type, ServerClient client, Action<Parameter, Parameter, Parameter, Parameter, Parameter, Parameter> action)
  748. {
  749. OnNotify(type, action, true, client.ClientNum);
  750. }
  751.  
  752. public static void OnNotify(string type, ServerClient client, Action<Parameter, Parameter, Parameter, Parameter, Parameter, Parameter, Parameter> action)
  753. {
  754. OnNotify(type, action, true, client.ClientNum);
  755. }
  756.  
  757. public static void OnNotify(string type, ServerClient client, Action<Parameter, Parameter, Parameter, Parameter, Parameter, Parameter, Parameter, Parameter> action)
  758. {
  759. OnNotify(type, action, true, client.ClientNum);
  760. }
  761.  
  762. public static void OnNotify(string type, ServerClient client, Action<Parameter, Parameter, Parameter, Parameter, Parameter, Parameter, Parameter, Parameter, Parameter> action)
  763. {
  764. OnNotify(type, action, true, client.ClientNum);
  765. }
  766.  
  767. public static void OnNotify(string type, Entity entity, Action action)
  768. {
  769. OnNotify(type, action, true, entity.EntityNum);
  770. }
  771.  
  772. public static void OnNotify(string type, Entity entity, Action<Parameter> action)
  773. {
  774. OnNotify(type, action, true, entity.EntityNum);
  775. }
  776.  
  777. public static void OnNotify(string type, Entity entity, Action<Parameter, Parameter> action)
  778. {
  779. OnNotify(type, action, true, entity.EntityNum);
  780. }
  781.  
  782. public static void OnNotify(string type, Entity entity, Action<Parameter, Parameter, Parameter> action)
  783. {
  784. OnNotify(type, action, true, entity.EntityNum);
  785. }
  786.  
  787. public static void OnNotify(string type, Entity entity, Action<Parameter, Parameter, Parameter, Parameter> action)
  788. {
  789. OnNotify(type, action, true, entity.EntityNum);
  790. }
  791.  
  792. public static void OnNotify(string type, Entity entity, Action<Parameter, Parameter, Parameter, Parameter, Parameter> action)
  793. {
  794. OnNotify(type, action, true, entity.EntityNum);
  795. }
  796.  
  797. public static void OnNotify(string type, Entity entity, Action<Parameter, Parameter, Parameter, Parameter, Parameter, Parameter> action)
  798. {
  799. OnNotify(type, action, true, entity.EntityNum);
  800. }
  801.  
  802. public static void OnNotify(string type, Entity entity, Action<Parameter, Parameter, Parameter, Parameter, Parameter, Parameter, Parameter> action)
  803. {
  804. OnNotify(type, action, true, entity.EntityNum);
  805. }
  806.  
  807. public static void OnNotify(string type, Entity entity, Action<Parameter, Parameter, Parameter, Parameter, Parameter, Parameter, Parameter, Parameter> action)
  808. {
  809. OnNotify(type, action, true, entity.EntityNum);
  810. }
  811.  
  812. public static void OnNotify(string type, Entity entity, Action<Parameter, Parameter, Parameter, Parameter, Parameter, Parameter, Parameter, Parameter, Parameter> action)
  813. {
  814. OnNotify(type, action, true, entity.EntityNum);
  815. }
  816. }
  817. }

But as soon as a player joins it crashes
  Reply
Uhmm, I was just playing in my server, and I wanted to place sentry gun on carepackage bunker, but not possible.(I took the sentry gun from an carepackage)
I know normally it's not possible, but is there a way to make it place able on carepackages?
That should be really awesome, but I don't think it's possible, because in the normal mw3 it's neither possible.
Oh and second:
Possible, to make it if I let an carepackage drop on the carepackagebunker, that it won't fall through it.

Anyway again thanks for the release lol, it made a lot of things awesome Smile
Keep up the goodwork!Big Grin
[Image: b_560_95_1.png]
[Image: hax0r3ez.gif]
  Reply
(01-15-2013, 18:58)99IRock Wrote: Uhmm, I was just playing in my server, and I wanted to place sentry gun on carepackage bunker, but not possible.(I took the sentry gun from an carepackage)
I know normally it's not possible, but is there a way to make it place able on carepackages?
That should be really awesome, but I don't think it's possible, because in the normal mw3 it's neither possible.
Oh and second:
Possible, to make it if I let an carepackage drop on the carepackagebunker, that it won't fall through it.

Anyway again thanks for the release lol, it made a lot of things awesome Smile
Keep up the goodwork!Big Grin

It isn't possible to place sentry on packages, because it's in gsc ( i mean checking )
C++/Obj-C developer. Neko engine wip
Steam: Click
  Reply
(01-15-2013, 18:58)99IRock Wrote: Uhmm, I was just playing in my server, and I wanted to place sentry gun on carepackage bunker, but not possible.(I took the sentry gun from an carepackage)
I know normally it's not possible, but is there a way to make it place able on carepackages?
That should be really awesome, but I don't think it's possible, because in the normal mw3 it's neither possible.
Oh and second:
Possible, to make it if I let an carepackage drop on the carepackagebunker, that it won't fall through it.

Anyway again thanks for the release lol, it made a lot of things awesome Smile
Keep up the goodwork!Big Grin

Ye, I already noticed that too, you can also shoot through the carepackages and the bombs from stealthbomb FX fall through them too.

Quote:Doesn't Extensions.CloneBrushmodelToScriptmodel do that?

EDIT - I see what you mean. Bullets work if you shoot the top, if you shoot the shit the bullet holes don't appear. I don't know, it could be to do with the collision ID.

I didn't mean the holes, I meant you can shoot through the carepackages and kill someone behind it, also grenades, throwing knives etc. fly through.
  Reply
anyone managed to add this Timing.cs yet without tons of errors?
[Image: b_560_95_1.png]


[Image: b_560_95_1.png]

  Reply
Me but crashes as soon as a player joins please fix timing,cs
  Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Add a point shop to my server h1dexyz 1 438 03-04-2018, 22:36
Last Post: h1dexyz
Lightbulb Preview Weapon Classe For Infected Clasic Server groochu1982 0 596 02-19-2017, 08:35
Last Post: groochu1982
Exclamation Help HOW CAN I TURN OFF THE "CROSSHAIR" IN MY SERVER? Eliichong0 0 701 06-16-2016, 16:01
Last Post: Eliichong0
Bug Upload files to FTP server S3VDIT0 4 1,462 01-28-2016, 17:17
Last Post: S3VDIT0

Forum Jump:


Users browsing this thread: 1 Guest(s)