Y_Less

y_scripting

Jan 12th, 2011
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 19.15 KB | None | 0 0
  1. /*----------------------------------------------------------------------------*-
  2.                     ===============================
  3.                      y_scripting - Access amx data
  4.                     ===============================
  5. Description:
  6.     Allows a script access to information about itself, such as function names.
  7.     This can be used for a range of things, including automatic callback hooking
  8.     and testing.
  9. Legal:
  10.     Version: MPL 1.1
  11.    
  12.     The contents of this file are subject to the Mozilla Public License Version
  13.     1.1 (the "License"); you may not use this file except in compliance with
  14.     the License. You may obtain a copy of the License at
  15.     http://www.mozilla.org/MPL/
  16.    
  17.     Software distributed under the License is distributed on an "AS IS" basis,
  18.     WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  19.     for the specific language governing rights and limitations under the
  20.     License.
  21.    
  22.     The Original Code is the SA:MP script information include.
  23.    
  24.     The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  25.     Portions created by the Initial Developer are Copyright (C) 2008
  26.     the Initial Developer. All Rights Reserved.
  27.    
  28.     Contributors:
  29.         ZeeX, koolk
  30.    
  31.     Thanks:
  32.         Peter, Cam - Support.
  33.         ZeeX - Very productive conversations.
  34.         koolk - IsPlayerinAreaEx code.
  35.         TheAlpha - Danish translation.
  36.         breadfish - German translation.
  37.         Fireburn - Dutch translation.
  38.         yom - French translation.
  39.         50p - Polish translation.
  40.         Zamaroht - Spanish translation.
  41.         Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  42.             for me to strive to better.
  43.         Pixels^ - Running XScripters where the idea was born.
  44.         Matite - Pestering me to release it and using it.
  45.    
  46.     Very special thanks to:
  47.         Thiadmer - PAWN.
  48.         Kye/Kalcor - SA:MP.
  49.         SA:MP Team past, present and future - SA:MP.
  50. Version:
  51.     1.0
  52. Changelog:
  53.     06/08/10:
  54.         First version
  55. -*----------------------------------------------------------------------------*/
  56.  
  57. #include <YSI\internal\y_version>
  58.  
  59. #include <YSI\internal\y_funcinc>
  60.  
  61. #define Scripting_FastString(%1,%2,%3,%4) \
  62.     (((%1) << 0) | ((%2) << 8) | ((%3) << 16) | ((%4) << 24))
  63.  
  64. static stock Scripting_GetBase()
  65. {
  66.     static
  67.         s_addr;
  68.     if (!s_addr)
  69.     {
  70.         // Get the data offset.
  71.         #emit LCTRL                     1
  72.         #emit STOR.pri                  s_addr
  73.         // Invert to get the prefix offset relative to the data.
  74.         s_addr = -s_addr;
  75.     }
  76.     return s_addr;
  77. }
  78.  
  79. static stock Scripting_GetPublics()
  80. {
  81.     static
  82.         s_addr;
  83.     if (!s_addr)
  84.     {
  85.         new
  86.             addr;// = Scripting_GetBase();
  87.         // Get the data offset.
  88.         #emit LCTRL                     1
  89.         #emit STOR.S.pri                addr
  90.         // Invert to get the prefix offset relative to the data.
  91.         addr = -addr;
  92.         // Get the pointer to the publics.
  93.         addr += 32;
  94.         #emit LREF.S.pri                addr
  95.         #emit STOR.pri                  s_addr
  96.         // Adjust to get the relative offset.
  97.         s_addr = s_addr + addr - 32;
  98.     }
  99.     return s_addr;
  100. }
  101.  
  102. static stock Scripting_GetNatives()
  103. {
  104.     static
  105.         s_addr;
  106.     if (!s_addr)
  107.     {
  108.         new
  109.             addr;// = Scripting_GetBase();
  110.         // Get the data offset.
  111.         #emit LCTRL                     1
  112.         #emit STOR.S.pri                addr
  113.         // Invert to get the prefix offset relative to the data.
  114.         addr = -addr;
  115.         // Get the pointer to the publics.
  116.         addr += 36;
  117.         #emit LREF.S.pri                addr
  118.         #emit STOR.pri                  s_addr
  119.         // Adjust to get the relative offset.
  120.         s_addr = s_addr + addr - 36;
  121.     }
  122.     return s_addr;
  123. }
  124.  
  125. static stock Scripting_GetLibraries()
  126. {
  127.     static
  128.         s_addr;
  129.     if (!s_addr)
  130.     {
  131.         new
  132.             addr;// = Scripting_GetBase();
  133.         // Get the data offset.
  134.         #emit LCTRL                     1
  135.         #emit STOR.S.pri                addr
  136.         // Invert to get the prefix offset relative to the data.
  137.         addr = -addr;
  138.         // Get the pointer to the publics.
  139.         addr += 40;
  140.         #emit LREF.S.pri                addr
  141.         #emit STOR.pri                  s_addr
  142.         // Adjust to get the relative offset.
  143.         s_addr = s_addr + addr - 40;
  144.     }
  145.     return s_addr;
  146. }
  147.  
  148. static stock Scripting_GetPubvars()
  149. {
  150.     static
  151.         s_addr;
  152.     if (!s_addr)
  153.     {
  154.         new
  155.             addr;// = Scripting_GetBase();
  156.         // Get the data offset.
  157.         #emit LCTRL                     1
  158.         #emit STOR.S.pri                addr
  159.         // Invert to get the prefix offset relative to the data.
  160.         addr = -addr;
  161.         // Get the pointer to the publics.
  162.         addr += 44;
  163.         #emit LREF.S.pri                addr
  164.         #emit STOR.pri                  s_addr
  165.         // Adjust to get the relative offset.
  166.         s_addr = s_addr + addr - 44;
  167.     }
  168.     return s_addr;
  169. }
  170.  
  171. static stock Scripting_GetTags()
  172. {
  173.     static
  174.         s_addr;
  175.     if (!s_addr)
  176.     {
  177.         new
  178.             addr;// = Scripting_GetBase();
  179.         // Get the data offset.
  180.         #emit LCTRL                     1
  181.         #emit STOR.S.pri                addr
  182.         // Invert to get the prefix offset relative to the data.
  183.         addr = -addr;
  184.         // Get the pointer to the publics.
  185.         addr += 48;
  186.         #emit LREF.S.pri                addr
  187.         #emit STOR.pri                  s_addr
  188.         // Adjust to get the relative offset.
  189.         s_addr = s_addr + addr - 48;
  190.     }
  191.     return s_addr;
  192. }
  193.  
  194. stock Scripting_GetPubvarsCount()
  195. {
  196.     static
  197.         s_count;
  198.     if (!s_count)
  199.     {
  200.         // Get the difference in pointers.
  201.         s_count = (Scripting_GetTags() - Scripting_GetPubvars()) / 8;
  202.     }
  203.     return s_count;
  204. }
  205.  
  206. static stock Scripting_GetString(addr)
  207. {
  208.     new
  209.         str[32],
  210.         buffer,
  211.         ch,
  212.         idx;
  213.     do
  214.     {
  215.         // Read 4 bytes.
  216.         #emit LREF.S.pri                addr
  217.         #emit STOR.S.pri                buffer
  218.         // Write a character to the buffer.
  219.         ch = buffer & 0xFF;
  220.         str[idx++] = ch;
  221.         // Check for the end of the string.
  222.         if (!ch) break;
  223.         // Write a character to the buffer.
  224.         ch = buffer >> 8 & 0xFF;
  225.         str[idx++] = ch;
  226.         // Check for the end of the string.
  227.         if (!ch) break;
  228.         // Write a character to the buffer.
  229.         ch = buffer >> 16 & 0xFF;
  230.         str[idx++] = ch;
  231.         // Check for the end of the string.
  232.         if (!ch) break;
  233.         // Write a character to the buffer.
  234.         ch = buffer >>> 24;
  235.         str[idx++] = ch;
  236.         // Check for the end of the string.
  237.         if (!ch) break;
  238.         // Get the next address.
  239.         addr += 4;
  240.     }
  241.     while (idx < 32);
  242.     return str;
  243. }
  244.  
  245. static stock Scripting_GetStringFast(addr, buffer)
  246. {
  247.     new
  248.         str[32],
  249.         ch,
  250.         idx;
  251.     do
  252.     {
  253.         // Write a character to the buffer.
  254.         ch = buffer & 0xFF;
  255.         str[idx++] = ch;
  256.         // Check for the end of the string.
  257.         if (!ch) break;
  258.         // Write a character to the buffer.
  259.         ch = buffer >> 8 & 0xFF;
  260.         str[idx++] = ch;
  261.         // Check for the end of the string.
  262.         if (!ch) break;
  263.         // Write a character to the buffer.
  264.         ch = buffer >> 16 & 0xFF;
  265.         str[idx++] = ch;
  266.         // Check for the end of the string.
  267.         if (!ch) break;
  268.         // Write a character to the buffer.
  269.         ch = buffer >>> 24;
  270.         str[idx++] = ch;
  271.         // Check for the end of the string.
  272.         if (!ch) break;
  273.         // Get the next address.
  274.         addr += 4;
  275.         // Read 4 bytes.
  276.         #emit LREF.S.pri                addr
  277.         #emit STOR.S.pri                buffer
  278.     }
  279.     while (idx < 32);
  280.     return str;
  281. }
  282.  
  283. /*----------------------------------------------------------------------------*-
  284. Function:
  285.     Scripting_GetPublicsCount
  286. Params:
  287.     -
  288. Return:
  289.     Number of public functions in a script.
  290. Notes:
  291.     -
  292.  
  293. native Scripting_GetPublicsCount();
  294.  
  295. -*----------------------------------------------------------------------------*/
  296.  
  297. stock Scripting_GetPublicsCount()
  298. {
  299.     static
  300.         s_count;
  301.     if (!s_count)
  302.     {
  303.         // Get the difference in pointers.
  304.         s_count = (Scripting_GetNatives() - Scripting_GetPublics()) / 8;
  305.     }
  306.     return s_count;
  307. }
  308.  
  309. /*----------------------------------------------------------------------------*-
  310. Function:
  311.     Scripting_GetNativesCount
  312. Params:
  313.     -
  314. Return:
  315.     Number of native functions in a script.
  316. Notes:
  317.     -
  318.  
  319. native Scripting_GetNativesCount();
  320.  
  321. -*----------------------------------------------------------------------------*/
  322.  
  323. stock Scripting_GetNativesCount()
  324. {
  325.     static
  326.         s_count;
  327.     if (!s_count)
  328.     {
  329.         // Get the difference in pointers.
  330.         s_count = (Scripting_GetLibraries() - Scripting_GetNatives()) / 8;
  331.     }
  332.     return s_count;
  333. }
  334.  
  335. /*----------------------------------------------------------------------------*-
  336. Function:
  337.     Scripting_GetPublicFast
  338. Params:
  339.     idx - Index of the public to start at.
  340.     buffer[32] - Buffer to store the name in.
  341.     search - Pattern matching parameter.
  342. Return:
  343.     Index of next public.
  344. Notes:
  345.     Gets a string starting with a known 4 character sequence.
  346.  
  347. native Scripting_GetPublicFast(idx, buffer[32], search);
  348.  
  349. -*----------------------------------------------------------------------------*/
  350.  
  351. stock Scripting_GetPublicFast(idx, buffer[32], search)
  352. {
  353.     new
  354.         count = Scripting_GetPublicsCount(),
  355.         base = Scripting_GetBase(),
  356.         pos = idx * 8 + 4 + Scripting_GetPublics(),
  357.         addr;
  358.     while (idx < count)
  359.     {
  360.         // Get the offset in the public records.
  361.         // Get the pointer to the string.
  362.         //pos += publics;
  363.         // Get the address of the string.
  364.         #emit LREF.S.pri                pos
  365.         #emit STOR.S.pri                addr
  366.         //printf("%s", Scripting_GetString(Scripting_GetBase() + pos));
  367.         //new
  368.         //  str[32] = Scripting_GetString(base + pos));
  369.         ++idx;
  370.         addr += base;
  371.         new
  372.             chars;
  373.         #emit LREF.S.pri                addr
  374.         #emit STOR.S.pri                chars
  375.         if (chars == search)
  376.         {
  377.             buffer = Scripting_GetStringFast(addr, chars);
  378.             return idx;
  379.         }
  380.         pos += 8;
  381.     }
  382.     buffer[0] = '\0';
  383.     return 0;
  384. }
  385.  
  386. /*----------------------------------------------------------------------------*-
  387. Function:
  388.     Scripting_GetPublicSuffix
  389. Params:
  390.     idx - Index of the public to start at.
  391.     buffer[32] - Buffer to store the name in.
  392.     search - Pattern matching parameter.
  393. Return:
  394.     Index of next public.
  395. Notes:
  396.     Gets a string ending with a known 4 character sequence.
  397.  
  398. native Scripting_GetPublicFast(idx, buffer[32], search);
  399.  
  400. -*----------------------------------------------------------------------------*/
  401.  
  402. stock Scripting_GetPublicSuffix(idx, buffer[32], search)
  403. {
  404.     new
  405.         count = Scripting_GetPublicsCount(),
  406.         base = Scripting_GetBase(),
  407.         // Add 12 to get the pointer to the next string.
  408.         pos = idx * 8 + 12 + Scripting_GetPublics(),
  409.         addr;
  410.     // This code will actually spill in to the natives record, but that's fine.
  411.     while (idx < count)
  412.     {
  413.         // Get the address of the string.
  414.         #emit LREF.S.pri                pos
  415.         #emit STOR.S.pri                addr
  416.         ++idx;
  417.         addr = addr + base - 5;
  418.         //addr
  419.         #emit LREF.S.pri                addr
  420.         #emit STOR.S.pri                addr
  421.         if (addr == search)
  422.         {
  423.             pos -= 8;
  424.             #emit LREF.S.pri            pos
  425.             #emit STOR.S.pri            addr
  426.             addr += base;
  427.             buffer = Scripting_GetString(addr);
  428.             return idx;
  429.         }
  430.         pos += 8;
  431.     }
  432.     buffer[0] = '\0';
  433.     return 0;
  434. }
  435.  
  436. /*----------------------------------------------------------------------------*-
  437. Function:
  438.     Scripting_GetNativeFast
  439. Params:
  440.     idx - Index of the native to get.
  441.     buffer[32] - Buffer to store the name in.
  442.     search - Pattern matching parameter.
  443. Return:
  444.     Index of next native.
  445. Notes:
  446.     -
  447.  
  448. native Scripting_GetNativeFast(idx, buffer[32], search);
  449.  
  450. -*----------------------------------------------------------------------------*/
  451.  
  452. stock Scripting_GetNativeFast(idx, buffer[32], search)
  453. {
  454.     new
  455.         count = Scripting_GetNativesCount(),
  456.         base = Scripting_GetBase(),
  457.         pos = idx * 8 + 4 + Scripting_GetNatives()
  458.         addr;
  459.     while (idx < count)
  460.     {
  461.         // Get the offset in the public records.
  462.         new
  463.         // Get the pointer to the string.
  464.         //pos += publics;
  465.         // Get the address of the string.
  466.         #emit LREF.S.pri                pos
  467.         #emit STOR.S.pri                addr
  468.         //printf("%s", Scripting_GetString(Scripting_GetBase() + pos));
  469.         //new
  470.         //  str[32] = Scripting_GetString(base + pos));
  471.         ++idx;
  472.         addr += base;
  473.         new
  474.             chars;
  475.         #emit LREF.S.pri                addr
  476.         #emit STOR.S.pri                chars
  477.         if (chars == search)
  478.         {
  479.             buffer = Scripting_GetStringFast(addr, chars);
  480.             return idx;
  481.         }
  482.         pos += 8;
  483.     }
  484.     buffer[0] = '\0';
  485.     return 0;
  486. }
  487.  
  488. /*----------------------------------------------------------------------------*-
  489. Function:
  490.     Scripting_GetPublic
  491. Params:
  492.     idx - Index of the public to get.
  493.     buffer[32] - Buffer to store the name in.
  494.     search[] - Optional pattern matching parameter.
  495. Return:
  496.     Index of next public.
  497. Notes:
  498.     -
  499.  
  500. native Scripting_GetPublic(idx, buffer[32], search[] = "");
  501.  
  502. -*----------------------------------------------------------------------------*/
  503.  
  504. stock Scripting_GetPublic(idx, buffer[32], search[] = "")
  505. {
  506.     new
  507.         count = Scripting_GetPublicsCount(),
  508.         base = Scripting_GetBase(),
  509.         pos = idx * 8 + 4 + Scripting_GetPublics(),
  510.         addr;
  511.     while (idx < count)
  512.     {
  513.         // Get the offset in the public records.
  514.         // Get the pointer to the string.
  515.         //pos += publics;
  516.         // Get the address of the string.
  517.         #emit LREF.S.pri                pos
  518.         #emit STOR.S.pri                addr
  519.         //printf("%s", Scripting_GetString(Scripting_GetBase() + pos));
  520.         //new
  521.         //  str[32] = Scripting_GetString(base + pos));
  522.         ++idx;
  523.         buffer = Scripting_GetString(base + addr);
  524.         if (search[0] == '\0' || strfind(buffer, search) != -1)
  525.         {
  526.             return idx;
  527.         }
  528.         pos += 8;
  529.     }
  530.     buffer[0] = '\0';
  531.     return 0;
  532. }
  533.  
  534. /*----------------------------------------------------------------------------*-
  535. Function:
  536.     Scripting_GetNative
  537. Params:
  538.     idx - Index of the native to get.
  539.     buffer[32] - Buffer to store the name in.
  540.     search[] - Optional pattern matching parameter.
  541. Return:
  542.     Index of next native.
  543. Notes:
  544.     -
  545.  
  546. native Scripting_GetNative(idx, buffer[32], search[] = "");
  547.  
  548. -*----------------------------------------------------------------------------*/
  549.  
  550. stock Scripting_GetNative(idx, buffer[32], search[] = "")
  551. {
  552.     new
  553.         count = Scripting_GetNativesCount(),
  554.         base = Scripting_GetBase(),
  555.         pos = idx * 8 + 4 + Scripting_GetNatives(),
  556.         addr;
  557.     while (idx < count)
  558.     {
  559.         // Get the offset in the public records.
  560.         // Get the pointer to the string.
  561.         //pos += publics;
  562.         // Get the address of the string.
  563.         #emit LREF.S.pri                pos
  564.         #emit STOR.S.pri                addr
  565.         //printf("%s", Scripting_GetString(Scripting_GetBase() + pos));
  566.         //new
  567.         //  str[32] = Scripting_GetString(base + pos));
  568.         ++idx;
  569.         buffer = Scripting_GetString(base + addr);
  570.         if (search[0] == '\0' || strfind(buffer, search) != -1)
  571.         {
  572.             return idx;
  573.         }
  574.         pos += 8;
  575.     }
  576.     buffer[0] = '\0';
  577.     return 0;
  578. }
  579.  
  580. static stock Scripting_CompareString(str[], addr)
  581. {
  582.     new
  583.         buffer,
  584.         ch,
  585.         idx;
  586.     do
  587.     {
  588.         // Read 4 bytes.
  589.         #emit LREF.S.pri                addr
  590.         #emit STOR.S.pri                buffer
  591.         ch = buffer & 0xFF;
  592.         if (ch != str[idx++]) return false;
  593.         if (!ch) break;
  594.         ch = buffer >> 8 & 0xFF;
  595.         if (ch != str[idx++]) return false;
  596.         if (!ch) break;
  597.         ch = buffer >> 16 & 0xFF;
  598.         if (ch != str[idx++]) return false;
  599.         if (!ch) break;
  600.         ch = buffer >>> 24;
  601.         if (ch != str[idx++]) return false;
  602.         if (!ch) break;
  603.         addr += 4;
  604.     }
  605.     while (idx < 32);
  606.     return true;
  607. }
  608.  
  609. /*----------------------------------------------------------------------------*-
  610. Function:
  611.     Scripting_GetPublicPointer
  612. Params:
  613.     name[] - Name of the function to get the pointer for.
  614. Return:
  615.     Pointer or -1.
  616. Notes:
  617.     -
  618.  
  619. native Scripting_GetPublicPointer(name[]);
  620.  
  621. -*----------------------------------------------------------------------------*/
  622.  
  623. stock Scripting_GetPublicPointer(name[])
  624. {
  625.     new
  626.         count = Scripting_GetPublicsCount(),
  627.         base = Scripting_GetBase(),
  628.         pos = 4 + Scripting_GetPublics(),
  629.         addr;
  630.     while (count--)
  631.     {
  632.         // Get the offset in the public records.
  633.         // Get the pointer to the string.
  634.         //pos += publics;
  635.         // Get the address of the string.
  636.         #emit LREF.S.pri                pos
  637.         #emit STOR.S.pri                addr
  638.         //printf("%s", Scripting_GetString(Scripting_GetBase() + pos));
  639.         //new
  640.         //  str[32] = Scripting_GetString(base + pos));
  641.         if (Scripting_CompareString(name, base + addr))
  642.         {
  643.             //pos = idx * 8 + publics;
  644.             pos -= 4;
  645.             // Get the pointer to the string.
  646.             //pos += publics;
  647.             // Get the address of the string.
  648.             #emit LREF.S.pri            pos
  649.             #emit STOR.S.pri            addr
  650.             // It doesn't really matter what this is relative to, as long as the
  651.             // usage in code is consistent.
  652.             return addr;
  653.         }
  654.         pos += 8;
  655.     }
  656.     return -1;
  657. }
  658.  
  659. /*----------------------------------------------------------------------------*-
  660. Function:
  661.     Scripting_RedirectPublic
  662. Params:
  663.     name[] - Name of the function to move.
  664.     pointer - Where to move it to.
  665. Return:
  666.     -
  667. Notes:
  668.     -
  669.  
  670. native Scripting_RedirectPublic(name[], pointer);
  671.  
  672. -*----------------------------------------------------------------------------*/
  673.  
  674. stock Scripting_RedirectPublic(name[], pointer)
  675. {
  676.     new
  677.         count = Scripting_GetPublicsCount(),
  678.         base = Scripting_GetBase(),
  679.         pos = 4 + Scripting_GetPublics(),
  680.         addr;
  681.     while (count--)
  682.     {
  683.         // Get the offset in the public records.
  684.         // Get the pointer to the string.
  685.         //pos += publics;
  686.         // Get the address of the string.
  687.         #emit LREF.S.pri                pos
  688.         #emit STOR.S.pri                addr
  689.         //printf("%s", Scripting_GetString(Scripting_GetBase() + pos));
  690.         //new
  691.         //  str[32] = Scripting_GetString(base + pos));
  692.         if (Scripting_CompareString(name, base + addr))
  693.         {
  694.             //pos = idx * 8 + publics;
  695.             pos -= 4;
  696.             // Get the pointer to the string.
  697.             //pos += publics;
  698.             // Get the address of the string.
  699.             #emit LOAD.S.pri            pointer
  700.             #emit SREF.S.pri            pos
  701.             // It doesn't really matter what this is relative to, as long as the
  702.             // usage in code is consistent.
  703.             return;
  704.         }
  705.         pos += 8;
  706.     }
  707. }
  708.  
  709. /*----------------------------------------------------------------------------*-
  710. Function:
  711.     Scripting_GetPublicVariable
  712. Params:
  713.     name[] - Name of the variable to get.
  714. Return:
  715.     -
  716. Notes:
  717.     -
  718.  
  719. native Scripting_GetPublicVariable(name[]);
  720.  
  721. -*----------------------------------------------------------------------------*/
  722.  
  723. stock Scripting_GetPublicVariable(name[])
  724. {
  725.     new
  726.         count = Scripting_GetPubvarsCount(),
  727.         base = Scripting_GetBase(),
  728.         pos = 4 + Scripting_GetPubvars(),
  729.         addr;
  730.     while (count--)
  731.     {
  732.         #emit LREF.S.pri                pos
  733.         #emit STOR.S.pri                addr
  734.         if (Scripting_CompareString(name, base + addr))
  735.         {
  736.             pos -= 4;
  737.             // Get the address.
  738.             #emit LREF.S.pri            pos
  739.             #emit STOR.S.pri            addr
  740.             // Get the value.
  741.             #emit LREF.S.pri            addr
  742.             #emit STOR.S.pri            pos
  743.             return pos;
  744.         }
  745.         pos += 8;
  746.     }
  747.     return -1;
  748. }
  749.  
  750. /*----------------------------------------------------------------------------*-
  751. Function:
  752.     Scripting_SetPublicVariable
  753. Params:
  754.     name[] - Name of the variable to set.
  755.     value - Value to set it to.
  756. Return:
  757.     -
  758. Notes:
  759.     -
  760.  
  761. native Scripting_SetPublicVariable(name[], value);
  762.  
  763. -*----------------------------------------------------------------------------*/
  764.  
  765. stock Scripting_SetPublicVariable(name[], value)
  766. {
  767.     new
  768.         count = Scripting_GetPubvarsCount(),
  769.         base = Scripting_GetBase(),
  770.         pos = 4 + Scripting_GetPubvars(),
  771.         addr;
  772.     while (count--)
  773.     {
  774.         #emit LREF.S.pri                pos
  775.         #emit STOR.S.pri                addr
  776.         if (Scripting_CompareString(name, base + addr))
  777.         {
  778.             pos -= 4;
  779.             // Get the address.
  780.             #emit LREF.S.pri            pos
  781.             #emit STOR.S.pri            addr
  782.             // Get the value.
  783.             #emit LOAD.S.pri            value
  784.             #emit SREF.S.pri            addr
  785.             return pos;
  786.         }
  787.         pos += 8;
  788.     }
  789.     return -1;
  790. }
Advertisement
Add Comment
Please, Sign In to add comment