Advertisement
ZoriaRPG

Debug Cheat Shell (v1.7, Working)

Nov 1st, 2018
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 31.96 KB | None | 0 0
  1. /////////////////////////////////
  2. /// Debug Shell for ZC Quests ///
  3. /// Alpha Version 1.7.1       ///
  4. /// 1st November, 2018        ///
  5. /// By: ZoriaRPG              ///
  6. /// Requires: ZC Necromancer  ///
  7. /////////////////////////////////
  8. //
  9. // v1.2   : Finished working code. now it all functions as I intend.
  10. // v1.2.1 : Added a code comment block with examples on how to add more instructions to match_instruction().
  11. // v1.2.1 : Added a sanity check to setting Link->Item[]. It now only works on inventory items.
  12. // v1.3.0 : Added the SAVE instruction.
  13. // v1.4.0 : Added CREATEITEM ( cri,id,x,y )
  14. // v1.4.0 : Added CREATENPC ( crn,id,x,y )
  15. // v1.4.0 : Fixed bug where buffer persists through saves.
  16. // v1.5.0 : Added LX and LY as literal args for Link's X and Y positions.
  17. // v1.6.0 : Added LX and LY tracing.
  18. // v1.6.0 : Added PALETTE as pal,n1,n2 -- POS now requires more than 'p' -- to change DMap Palette. -1 for current DMap.
  19. // v1.6.0 :       This sets Game->DmapPalette[n1] = n2
  20. // v1.6.0 : Added MONOCHROME as mon,n to set Graphics->Monochrome(n1)
  21. // v1.6.1 : Added break instructiosn to fix invalid rval and other invalid returns in switch statements.
  22. // v1.6.2 : Added clear instructions to case for NONE in switch(instr).
  23. // v1.7.0 : Added LTRIFORCE to set if Link has the triforce for a given level as 'lt,id,true|false'
  24. // v1.7.0 : Added LCOMPASS to set if Link has the compass for a given level as 'lc,id,true|false'
  25. // v1.7.0 : Added LMAP to set if Link has the map for a given level as 'lm,id,true|false'
  26. // v1.7.0 : Added LBOSSKEY to set if Link has the boss key for a given level as 'lb,id,true|false'
  27. // v1.7.0 : Added LKEYS to set the current number of LEVEL KEYS for a given level ID as 'lk,levelid,number'
  28. // v1.7.0 : Added BOMBS to set the current number of bombs as 'b,number'
  29. // v1.7.0 : Added MBOMBS to set the current number of max bombs as 'b,number'
  30. // v1.7.0 : Added ARROWS to set the current number of arrows as 'a,number'
  31. // v1.7.0 : Added MARROWS to set the current number of max arrows as 'a,number'
  32. // v1.7.0 : Added RUPEES to set the current number of rupees as 'r,number'
  33. // v1.7.0 : Added MRUPEES to set the current number of max rupees as 'r,number'
  34. // v1.7.0 : Added KEYS to set the current number of keys as 'k,number'
  35. // v1.7.0 : Added BIGHITBOX to set the if Link's hitbox is large (full tile collision), or small, as 'h,t|f'
  36. // v1.7.0 : Added LINKDIAGONAL to set the if Link may move diagonally, as 'd,t|f'
  37. // v1.7.1 : orrected a bug where RUPEES was using Game->Counter[RUPEES} insead of CR_RUPEES.
  38. // v1.7.1 : Added a NULL case for token[1] of command 'r', so that 'r' without any other legal char as the next token is RUPEES.
  39.  
  40. import "std.zh"
  41.  
  42. /*
  43. DEFINED INSTRUCTION VALUES
  44.     w WARP: return 2;   //dmap,screen
  45.     p POS: return 2;        //x,y
  46.     mx MOVEX: return 1;     //pixels (+/-)
  47.     my MOVEY: return 1;     //pixels (+/-)
  48.     rh REFILLHP: return 0;  //aNONE
  49.     rm REFILLMP: return 0;  //NONE
  50.     rc REFILLCTR: return 1; //counter
  51.     mh MAXHP: return 1; //amount
  52.     mm MAXMP: return 1; //amount
  53.     mc MAXCTR: return 2;    //counter, amount
  54.     save SAVE: return 0;   
  55.     cri CREATEITEM: return 3;   //id, x, y
  56.     crn CREATENPC: return 3;    //id, x, y
  57.    
  58.     inv INVINCIBLE: return 1;   //(BOOL) on / off
  59.     itm LINKITEM: return 2; //item, (BOOL), on / off
  60.     pal PALETTE return 2
  61.     mon MONOCHROME return 1
  62.    
  63.     h BIGHITBOX
  64.     d LINKDIAGONAL
  65.    
  66.     a ARROWS
  67.     b BOMBS
  68.     r RUPEES
  69.     mb MAXBOMBS
  70.     ma MAXARROWS
  71.     mr MAXRUPEES
  72.     k KEYS
  73.     lk LKEYS
  74.     lm LMAP
  75.     lc LCOMPASS
  76.     lt LTRIFORCE
  77.    
  78.  
  79. //COMMAND LIST
  80.     w: Warp Link to a specific dmap and screen
  81.     p: Reposition Link on the screen.
  82.     mx: Move link by +/-n pixels on the X axis.
  83.     my: Move link by +/-n pixels on the Y axis.
  84.     rh: Refill Link's HP to Max.
  85.     rm: Refill Link's HP to Max.
  86.     rc: Refill a specific counter to Max.
  87.     mh: Set Link's Max HP.
  88.     mm: Set Link's Max MP
  89.     mc: Set the maximum value of a specific counter.
  90.     inv: Set Link's Invisible state.
  91.     itm: Set the state of a specific item in Link's inventory.
  92.     save: Save the game.
  93.     cri: Create an item.
  94.     crn: Create an npc.
  95.     pal: Change a DMap palette; -1 for current dmap.
  96.     mono: Set monochrome effect.
  97.    
  98.     h: Set if Link uses a full tile hitbox. (hitbox)
  99.     d: Set if Link can move diagonally.
  100.    
  101.     a: Set the current number of Arrows
  102.     b: Set the current number of Bombs
  103.     r: Set the current number of Rupees
  104.     mb: Set the current number of Max Bombs
  105.     ma: Set the current number of Max Arrows
  106.     mr: Set the current number of Max Rupees
  107.     k: Set the current number of Keys
  108.     lk: Set the current number of Level Keys for a specific level ID.
  109.     lm: Set if the MAP item for a specific Level is in inventory.
  110.     lc: Set if the COMPASS item for a specific Level is in inventory.
  111.     lt: : Set if the TRIFORCE item for a specific Level is in inventory.
  112.     lb: : Set if the BOSS KEy item for a specific Level is in inventory.
  113. //SYNTAX
  114. //command,args
  115.     w,1,2
  116.     p,1,2
  117.     mx,1
  118.     mx,-1
  119.     my,1
  120.     my,-1
  121.     rh
  122.     rm
  123.     rc,1
  124.     mh,1
  125.     mm,1
  126.     mc,1,2
  127.     inv,true
  128.     inv,false
  129.     itm,1,true
  130.     itm,1,false
  131.     save
  132.     cri,1,2,3 //id,x,y
  133.     crn,1,2,3 //id,x,y
  134.     pal,1,2 //dmap (-1 for current), palette
  135.     mono,1 : mono,type
  136.     h,true|false
  137.     d,true|false
  138.    
  139.     a,1
  140.     b,1
  141.     r,1
  142.     mb,1
  143.     ma,1
  144.     mr,1
  145.     k,1
  146.     lk,1,2 (level id, number)
  147.     lm,1,t|f (level id, true|false)
  148.     lc,1,t|f (level id, true|false)
  149.     lt,1,t|f (level id, true|false)
  150.     lb,1,t|f (level id, true|false)
  151.        
  152.        
  153.  
  154. */
  155.  
  156. script typedef ffc namespace;
  157. typedef const int define;
  158. typedef const int CFG;
  159.  
  160.  
  161.  
  162. namespace script debugshell
  163. {
  164.     define INSTRUCTION_SIZE = 1; //The number of stack registers that any given *instruction* requires.
  165.     define MAX_INSTR_QUEUE = 1; //The number of instructions that can be enqueued.
  166.     define MAX_ARGS     = 3; //The maximum number of args that any instruction can use/require.
  167.     define STACK_SIZE   = 1 + ((INSTRUCTION_SIZE+MAX_ARGS)*MAX_INSTR_QUEUE);
  168.     define MAX_TOKEN_LENGTH = 16;
  169.     define BUFFER_LENGTH    = 42;
  170.     int stack[STACK_SIZE];
  171.     int SP;
  172.    
  173.     int debug_buffer[BUFFER_LENGTH];
  174.    
  175.     define YES = 1;
  176.     define NO = 0;
  177.    
  178.     CFG log_actions = YES;
  179.     CFG WINDOW_F_KEY = 7; //We use F7 to open the debug window.
  180.    
  181.    
  182.     define FONT = FONT_APPLE2; //Apple II
  183.     define F_COLOUR = 0x01; //font colour, white
  184.     define F_BCOLOUR = -1; //font background colour, translucent
  185.     define W_COLOUR = 0x03; //window colour (background), black
  186.     define W_S_COLOUR = 0xC5; //window colour (background), black
  187.     define CHAR_WIDTH = 6; //5 + one space
  188.     define CHAR_HEIGHT = 9; //8 + one space
  189.     define WINDOW_X = 15; //window indent over screen
  190.     define WINDOW_Y = 19; //window indent over screen
  191.     define WINDOW_H = 50;//CHAR_WIDTH * BUFFER_LENGTH;
  192.     define WINDOW_W = 180; //CHAR_HEIGHT * 3;
  193.     define WINDOW_S_X = 12; //window indent over screen
  194.     define WINDOW_S_Y = 16; //window indent over screen
  195.     define WINDOW_S_H = 50; //CHAR_WIDTH * BUFFER_LENGTH;
  196.     define WINDOW_S_W = 180; //CHAR_HEIGHT * 3;
  197.     define CHAR_X = 2; //Initial x indent
  198.     define CHAR_Y = 2; //Initial y indent
  199.     define W_OPACITY = OP_OPAQUE; //Window translucency.
  200.     define F_OPACITY = OP_OPAQUE; //Font translucency.
  201.     define W_LAYER = 6; //window draw layer
  202.     define F_LAYER = 6; //font draw layer
  203.    
  204.     CFG KEY_DELAY = 6; //frames between keystrokes
  205.    
  206.     define TYPESFX = 63;
  207.    
  208.     void process()
  209.     {
  210.         if ( Input->Key[51] ) //46+WINDOW_F_KEY] )
  211.         {
  212.             TraceS("Enabled Deb ug Shell");
  213.             if ( type() )
  214.             {
  215.                 TraceS("process() evaluated type() true");
  216.                
  217.                 int r = read(debug_buffer);
  218.                 if ( r ) execute();
  219.             }
  220.         }
  221.     }
  222.    
  223.     //if ( type() execute() )
  224.     //returns true if the user presses enter
  225.     bool type()
  226.     {
  227.         int frame = 0;
  228.         if ( !frame ) TraceS("Starting type()");
  229.         ++frame;
  230.         Game->TypingMode = true;
  231.         int key_timer; int buffer_pos = 0;
  232.         bool typing = true;
  233.         //while(!Input->ReadKey[KEY_ENTER] || Input->ReadKey[KEY_ENTER_PAD])
  234.         while(typing)
  235.         {
  236.             if ( key_timer <= 0 )
  237.             {
  238.                 if ( Input->ReadKey[KEY_BACKSPACE] ) //backspace
  239.                 {
  240.                    
  241.                     if ( buffer_pos > 0 )
  242.                     {
  243.                         debug_buffer[buffer_pos] = 0;
  244.                         --buffer_pos;
  245.                         debug_buffer[buffer_pos] = 0;
  246.                     }
  247.                     key_timer = KEY_DELAY;
  248.                     continue;
  249.                 }
  250.                 else if ( Input->ReadKey[KEY_ENTER] || Input->ReadKey[KEY_ENTER_PAD] )
  251.                 {
  252.                     Game->TypingMode = false;
  253.                     TraceNL(); TraceS("Read enter key, and buffer position is: "); Trace(buffer_pos); TraceNL();
  254.                     if ( !buffer_pos ) return false; //do not execute if there are no commands
  255.                     return true;
  256.                 }
  257.                 else if ( EscKey() )
  258.                 {
  259.                     for ( int q = 0; q < BUFFER_LENGTH; ++q ) debug_buffer[q] = 0;
  260.                    
  261.                    
  262.                     Game->TypingMode = false;
  263.                     return false; //exit and do not process.
  264.                 }
  265.                
  266.                 else
  267.                 {
  268.                     //else normal key
  269.                     int k;
  270.                     int LegalKeys[]=
  271.                     {
  272.                         KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G, KEY_H,
  273.                         KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, KEY_N, KEY_O, KEY_P,
  274.                         KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U, KEY_V, KEY_W, KEY_X,
  275.                         KEY_Y, KEY_Z, KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5,
  276.                         KEY_6, KEY_7, KEY_8, KEY_9, KEY_0_PAD, KEY_1_PAD, KEY_2_PAD,
  277.                         KEY_3_PAD, KEY_4_PAD, KEY_5_PAD,
  278.                         KEY_6_PAD, KEY_7_PAD, KEY_8_PAD, KEY_9_PAD,
  279.                         //KEY_TILDE,
  280.                         KEY_MINUS,
  281.                         //KEY_EQUALS, KEY_OPENBRACE, KEY_CLOSEBRACE,
  282.                         //KEY_COLON, KEY_QUOTE, KEY_BACKSLASH, KEY_BACKSLASH2,
  283.                         KEY_COMMA,
  284.                         //KEY_SEMICOLON, KEY_SLASH, KEY_SPACE, KEY_SLASH_PAD,
  285.                         //KEY_ASTERISK,
  286.                         KEY_MINUS_PAD
  287.                         //KEY_PLUS_PAD, KEY_CIRCUMFLEX, KEY_COLON2, KEY_EQUALS_PAD, KEY_STOP
  288.                     };
  289.  
  290.                    
  291.                     for ( int kk = SizeOfArray(LegalKeys)-1; kk >= 0; --kk )
  292.                     {
  293.                         k = LegalKeys[kk];
  294.                         if ( Input->ReadKey[k] )
  295.                         {
  296.                             TraceS("Read a key: "); Trace(k); TraceNL();
  297.                             debug_buffer[buffer_pos] = KeyToChar(k,(Input->ReadKey[KEY_LSHIFT])||(Input->ReadKey[KEY_RSHIFT])); //Warning!: Some masking may occur. :P
  298.                             TraceNL(); TraceS(debug_buffer); TraceNL();
  299.                             ++buffer_pos;
  300.                             key_timer = KEY_DELAY;
  301.                             break;
  302.                         }
  303.                     }
  304.                    
  305.                     //continue;
  306.                 }
  307.             }
  308.             else { --key_timer; }
  309.            
  310.             draw();
  311.             Waitframe();
  312.         }
  313.        
  314.     }
  315.    
  316.     void draw()
  317.     {
  318.         Screen->Rectangle(W_LAYER, WINDOW_S_X, WINDOW_S_Y, WINDOW_S_X+WINDOW_W, WINDOW_S_Y+WINDOW_H, W_S_COLOUR, 1, 0,0,0,true,W_OPACITY);
  319.         Screen->Rectangle(W_LAYER, WINDOW_X, WINDOW_Y, WINDOW_X+WINDOW_W, WINDOW_Y+WINDOW_H, W_COLOUR, 1, 0,0,0,true,W_OPACITY);
  320.         Screen->DrawString(F_LAYER,WINDOW_X+CHAR_X,WINDOW_Y+CHAR_Y,FONT,F_COLOUR,F_BCOLOUR,0,debug_buffer,F_OPACITY);
  321.     }
  322.    
  323.     void TraceErrorS(int s, int s2)
  324.     {
  325.         TraceS(s); TraceS(": "); TraceS(s2); TraceNL();
  326.     }
  327.    
  328.     void TraceError(int s, float v, float v2)
  329.     {
  330.         int buf[12]; int buf2[12];
  331.         ftoa(buf,v);
  332.         ftoa(buf2,v2);
  333.         TraceS(s); TraceS(": "); TraceS(buf); TraceS(", "); TraceS(buf2); TraceNL();
  334.     }
  335.    
  336.     void TraceErrorVS(int s, float v, int s2)
  337.     {
  338.         int buf[12];
  339.         ftoa(buf,v);
  340.         TraceS(s); TraceS(": "); TraceS(buf); TraceS(", "); TraceS(s2); TraceNL();
  341.     }
  342.    
  343.     //instruction       //variables
  344.     define NONE =   0;  //NONE
  345.     define WARP     =   1;  //dmap,screen
  346.     define POS  =   2;  //x,y
  347.     define MOVEX    =   3;  //pixels (+/-)
  348.     define MOVEY    =   4;  //pixels (+/-)
  349.     define REFILLHP =   5;  //aNONE
  350.     define REFILLMP =   6;  //NONE
  351.     define REFILLCTR =  7;  //counter
  352.     define MAXHP    =   8;  //amount
  353.     define MAXMP    =   9;  //amount
  354.     define MAXCTR   =   10; //counter, amount
  355.    
  356.     define INVINCIBLE =     11; //(BOOL) on / off
  357.     define LINKITEM =   12; //item, (BOOL), on / off
  358.     define SAVE =       13; //item, (BOOL), on / off
  359.     define CREATEITEM =     14; //item, (BOOL), on / off
  360.     define CREATENPC =  15; //item, (BOOL), on / off
  361.     define PALETTE =    16; //item, (BOOL), on / off
  362.     define MONOCHROME =     17; //item, (BOOL), on / off
  363.     define BOMBS =      18; //item, (BOOL), on / off
  364.     define MBOMBS =     19; //item, (BOOL), on / off
  365.     define ARROWS =     20; //item, (BOOL), on / off
  366.     define MARROWS =    21; //item, (BOOL), on / off
  367.     define KEYS =       22; //item, (BOOL), on / off
  368.     define LKEYS =      23; //item, (BOOL), on / off
  369.     define RUPEES =     24; //item, (BOOL), on / off
  370.     define MRUPEES =    25; //item, (BOOL), on / off
  371.     define LMAP =       26; //level map, level id, true|false
  372.     define LBOSSKEY =   27; //level map, level id, true|false
  373.     define BIGHITBOX =  28; //level map, level id, true|false
  374.     define LINKDIAGONAL =   29; //level map, level id, true|false
  375.     define LTRIFORCE =  30; //level map, level id, true|false
  376.     define LCOMPASS =   31; //level map, level id, true|false
  377.    
  378.    
  379.    
  380.    
  381.    
  382.     int num_instruction_params(int instr)
  383.     {
  384.         switch(instr)
  385.         {
  386.             //instruction       //variables
  387.             case NONE: return 0;
  388.             case WARP: return 2;    //dmap,screen
  389.             case POS: return 2;     //x,y
  390.             case MOVEX: return 1;   //pixels (+/-)
  391.             case MOVEY: return 1;   //pixels (+/-)
  392.             case REFILLHP: return 0;    //aNONE
  393.             case REFILLMP: return 0;    //NONE
  394.             case REFILLCTR: return 1;   //counter
  395.             case MAXHP: return 1;   //amount
  396.             case MAXMP: return 1;   //amount
  397.             case MAXCTR: return 2;  //counter, amount
  398.            
  399.             case INVINCIBLE: return 1;  //(BOOL) on / off
  400.             case LINKITEM: return 2;    //item, (BOOL), on / off
  401.             case SAVE: return 0;    //item, (BOOL), on / off
  402.             case CREATEITEM: return 3;  //item, (BOOL), on / off
  403.             case CREATENPC: return 3;   //item, (BOOL), on / off
  404.             case PALETTE: return 2; //item, (BOOL), on / off
  405.             case MONOCHROME: return 1;  //item, (BOOL), on / off
  406.            
  407.             case BOMBS: return 1;
  408.             case MBOMBS: return 1;
  409.             case ARROWS: return 1;
  410.             case MARROWS: return 1;
  411.             case KEYS: return 1;
  412.             case LKEYS: return 2; //level, number
  413.             case RUPEES: return 1;
  414.             case MRUPEES: return 1;
  415.             case LMAP: return 2;    //level map, level id, true|false
  416.             case LBOSSKEY: return 2;    //level bosskey, level id, true|false
  417.             case LTRIFORCE: return 2;   //level bosskey, level id, true|false
  418.             case LCOMPASS: return 2;    //level bosskey, level id, true|false
  419.             case BIGHITBOX: return 1;   //true|false
  420.             case LINKDIAGONAL: return 1;    //true|false
  421.    
  422.             default:
  423.             {
  424.                
  425.                 TraceError("Invalid instruction passed to stack",instr);
  426.                 clearbuffer();
  427.                 return 0;
  428.             }
  429.         }
  430.     }
  431.    
  432.    
  433.    
  434.     int match_instruction(int token)
  435.     {
  436.         TraceNL(); TraceS("Input token into match_instruction is: "); TraceS(token); TraceNL();
  437.        
  438.         TraceNL(); TraceErrorS("match_instruction() token is: ",token); TraceNL();
  439.         TraceNL(); TraceError("Matching string with strcmp to 'w': ", strcmp(token,"w")); TraceNL();
  440.        
  441.         /* ONE WAY TO DO THIS. I did this with individual characters, and switches, to minimise the checks down
  442.         to the absolute minimum. -Z
  443.        
  444.         You could add specific instructions this way, if you wish.
  445.        
  446.         if ( !(strcmp(token,"w") ) ) TraceErrorS("Token in match_instruction() matched to WARP. Token: ", token);
  447.         if ( !(strcmp(token,"W") ) ) TraceErrorS("Token in match_instruction() matched to WARP. Token: ", token);
  448.         if ( !(strcmp(token,"p") ) ) TraceErrorS("Token in match_instruction() matched to POS. Token: ", token);
  449.         if ( !(strcmp(token,"P") ) ) TraceErrorS("Token in match_instruction() matched to POS. Token: ", token);
  450.         if ( !(strcmp(token,"rh") ) ) TraceErrorS("Token in match_instruction() matched to REFILLHP. Token: ", token);
  451.         if ( !(strcmp(token,"RH") ) ) TraceErrorS("Token in match_instruction() matched to REFILLHP. Token: ", token);
  452.         if ( !(strcmp(token,"Rh") ) ) TraceErrorS("Token in match_instruction() matched to REFILLHP. Token: ", token);
  453.         if ( !(strcmp(token,"rH") ) ) TraceErrorS("Token in match_instruction() matched to REFILLHP. Token: ", token);
  454.         */
  455.        
  456.         switch(token[0])
  457.         {
  458.             //A
  459.             case 'a':
  460.             case 'A':
  461.                 return ARROWS;
  462.             //B
  463.             case 'b':
  464.             case 'B':
  465.             {
  466.                 return BOMBS;
  467.                 /*
  468.                 switch(token[1])
  469.                 {
  470.                     case 'i':
  471.                     case 'I':
  472.                         return BIGHITBOX;
  473.                     case 'o':
  474.                     case 'O':
  475.                         return BOMBS;
  476.                     default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); clearbuffer(); return 0;
  477.                 }
  478.                 */
  479.             }
  480.             case 'c':
  481.             case 'C':
  482.             {
  483.                 switch(token[1])
  484.                 {
  485.                     case 'r':
  486.                     case 'R':
  487.                     {
  488.                         switch(token[2])
  489.                         {
  490.                             case 'i':
  491.                             case 'I':
  492.                             {
  493.                                 TraceNL(); TraceS("instr() found token 'cri'"); TraceNL(); return CREATEITEM;
  494.                             }
  495.                            
  496.                             case 'n':
  497.                             case 'N':
  498.                             {
  499.                                 TraceNL(); TraceS("instr() found token 'cri'"); TraceNL(); return CREATENPC;
  500.                             }
  501.                
  502.                             default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); clearbuffer(); return 0;
  503.                         }
  504.                     }
  505.                     default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); clearbuffer(); return 0;
  506.                 }
  507.                 break;
  508.             }
  509.             //D
  510.             case 'd':
  511.             case 'D':
  512.                 return LINKDIAGONAL;
  513.             //E
  514.             //F
  515.             //G
  516.             //H
  517.             case 'h':
  518.             case 'H':
  519.                 return BIGHITBOX;
  520.             //I
  521.             case 'i':
  522.             case 'I':
  523.             {
  524.                 switch(token[1])
  525.                 {
  526.                     case 'n':
  527.                     case 'N':
  528.                         return INVINCIBLE;
  529.                     case 't':
  530.                     case 'T':
  531.                         return LINKITEM;
  532.                     default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); clearbuffer(); return 0;
  533.                 }
  534.                 break;
  535.             }
  536.             //J
  537.             //K
  538.             case 'k':
  539.             case 'K':
  540.                 return KEYS;
  541.             //L
  542.             case 'l':
  543.             case 'L':
  544.             {
  545.                 switch(token[1])
  546.                 {
  547.                     case 'b':
  548.                     case 'B':
  549.                         return LBOSSKEY;
  550.                     case 'c':
  551.                     case 'C':
  552.                         return LCOMPASS;
  553.                     case 'K':
  554.                     case 'k':
  555.                         return LKEYS;
  556.                     case 'M':
  557.                     case 'm':
  558.                         return LMAP;
  559.                     case 't':
  560.                     case 'T':
  561.                         return LTRIFORCE;
  562.                     default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); clearbuffer(); return 0;
  563.                 }
  564.                
  565.             }
  566.             //M
  567.             case 'm':
  568.             case 'M':
  569.             {
  570.                 switch(token[1])
  571.                 {
  572.                     case 'x':
  573.                     case 'X':
  574.                         TraceNL(); TraceS("instr() found token 'mx'"); return MOVEX;
  575.                     case 'y':
  576.                     case 'Y':
  577.                         TraceNL(); TraceS("instr() found token 'my'"); return MOVEY;
  578.                     case 'h':
  579.                     case 'H':
  580.                         return MAXHP;
  581.                     case 'm':
  582.                     case 'M':
  583.                         return MAXMP;
  584.                     case 'c':
  585.                     case 'C':
  586.                         return MAXCTR;
  587.                     case 'o':
  588.                     case 'O':
  589.                         return MONOCHROME;
  590.                     case 'b':
  591.                     case 'B':
  592.                         return MBOMBS;
  593.                    
  594.                     case 'a':
  595.                     case 'A':
  596.                         return MARROWS;
  597.                     case 'R':
  598.                     case 'r':
  599.                         return MRUPEES;
  600.                    
  601.                     default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); clearbuffer(); return 0;
  602.                 }
  603.                 break;
  604.             }
  605.            
  606.             //P
  607.             case 'p':
  608.             case 'P':
  609.             {
  610.                 switch(token[1])
  611.                 {
  612.                     case 'o':
  613.                     case 'O':
  614.                         TraceNL(); TraceS("instr() found token 'p'"); TraceNL(); return POS;
  615.                     case 'a':
  616.                     case 'A':
  617.                         TraceNL(); TraceS("instr() found token 'p'"); TraceNL(); return PALETTE;
  618.                     default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); clearbuffer(); return 0;
  619.                 }
  620.                 break;
  621.             }
  622.             //Q
  623.             //R
  624.             case 'r':
  625.             case 'R':
  626.             {
  627.                 switch(token[1])
  628.                 {
  629.                     case 'h':
  630.                     case 'H':
  631.                         return REFILLHP;
  632.                     case 'm':
  633.                     case 'M':
  634.                         return REFILLMP;
  635.                     case 'c':
  636.                     case 'C':
  637.                         return REFILLCTR;
  638.                     case 'U':
  639.                     case 'u':
  640.                     case NULL:
  641.                         return RUPEES;
  642.                     default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); clearbuffer(); return 0;
  643.                 }
  644.                 break;
  645.             }
  646.             //S
  647.             case 's':
  648.             case 'S':
  649.             {
  650.                 switch(token[1])
  651.                 {
  652.                     case 'a':
  653.                     case 'A':
  654.                     case 'V':
  655.                     case 'v':
  656.                     {
  657.                         TraceNL(); TraceS("instr() found token 'save'"); return SAVE;
  658.                     }
  659.                     default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); clearbuffer(); return 0;
  660.                 }
  661.                 break;
  662.             }
  663.             //T
  664.             //U
  665.             //V
  666.             //W
  667.             case 'w':
  668.             case 'W':
  669.                 TraceNL(); TraceS("instr() found token 'w'"); TraceNL(); return WARP;
  670.            
  671.             default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); clearbuffer(); return 0;
  672.         }
  673.        
  674.         //if ( strcmp(token,"w") == 0) { TraceNL(); TraceS("instr() found token 'w'"); return WARP; }
  675.         //else if ( strcmp(token,"p") == 0) { TraceNL(); TraceS("instr() found token 'p'"); return POS; }
  676.         //else if ( strcmp(token,"mx") == 0) { TraceNL(); TraceS("instr() found token 'mx'"); return MOVEX; }
  677.         //else if ( strcmp(token,"my") == 0) return MOVEY;
  678.         //else if ( strcmp(token,"rh") == 0) return REFILLHP;
  679.         //else if ( strcmp(token,"rm") == 0) return REFILLMP;
  680.         //else if ( strcmp(token,"rc") == 0) return REFILLCTR;
  681.         //else if ( strcmp(token,"mh") == 0) return MAXHP;
  682.         //else if ( strcmp(token,"mm") == 0) return MAXMP;
  683.         //else if ( strcmp(token,"mc") == 0) return MAXCTR;
  684.         //else if ( strcmp(token,"inv") == 0) return INVINCIBLE;
  685.         //else// if ( strcmp(token,"itm") == 0) return LINKITEM;
  686.         //else
  687.         //{
  688.         //  TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token);
  689.         //  return 0;
  690.         //}
  691.     }
  692.    
  693.     void clearbuffer()
  694.     {
  695.         for ( int q = 0; q < BUFFER_LENGTH; ++q ) debug_buffer[q] = 0;
  696.     }
  697.     int read(int str)
  698.     {
  699.         //debug
  700.         TraceNL(); TraceS("Starting read() with an initial buffer of: "); TraceS(str); TraceNL();
  701.         int token[16]; int input_string_pos;
  702.         int e; int token_pos = 0; int current_param;
  703.         for ( input_string_pos = 0; input_string_pos < MAX_TOKEN_LENGTH; ++input_string_pos )
  704.         {
  705.             if (str[input_string_pos] == ',' ) { ++input_string_pos; break; }
  706.             if (str[input_string_pos] == NULL ) break;
  707.            
  708.             token[token_pos] = str[input_string_pos];
  709.             ++token_pos;
  710.            
  711.            
  712.             //debug
  713.            
  714.             //++input_string_pos; //skip the comma now. If there are no params, we'll be on NULL.
  715.         }
  716.         //debug
  717.         TraceNL(); TraceS("read() token: "); TraceS(token); TraceNL();
  718.        
  719.         //put the instruction onto the stack.
  720.         //Right now, we are only allowing one instruction at a time.
  721.         //This allows for future expansion.
  722.         stack[SP] = match_instruction(token);
  723.         TraceNL(); TraceS("SP is: "); Trace(stack[SP]); TraceNL();
  724.         int num_params = num_instruction_params(stack[SP]);
  725.         TraceNL(); TraceS("Number of expected params "); Trace(num_params); TraceNL();
  726.        
  727.         if ( num_params )
  728.         {
  729.             if ( str[input_string_pos] == NULL )
  730.             {
  731.                 //no params.
  732.                 TraceErrorS("Input string is missing params. Token was:", token);
  733.                 return 0;
  734.             }
  735.         }
  736.        
  737.         ++SP; //get the stack ready for the next instruction.
  738.         //push the variables onto the stack.
  739.         while ( current_param < num_params )  //repeat this until we are out of params
  740.             //NOT a Do loop, because some instructions have no params!
  741.         {
  742.             for ( token_pos = MAX_TOKEN_LENGTH-1; token_pos >= 0; --token_pos ) token[token_pos] = 0; //clear the token
  743.            
  744.             //copy over new token
  745.             token_pos = 0;
  746.             TraceNL(); TraceS("read() is seeking for params."); TraceNL();
  747.             int temp_max = input_string_pos+MAX_TOKEN_LENGTH;
  748.             for ( ; input_string_pos < temp_max; ++input_string_pos )
  749.             {
  750.                 if (str[input_string_pos] == ',' ) { ++input_string_pos; break; }
  751.                 if (str[input_string_pos] == NULL ) break;
  752.                
  753.                 token[token_pos] = str[input_string_pos];
  754.                 ++token_pos;
  755.                
  756.                
  757.                 //debug
  758.                
  759.                 //++input_string_pos; //skip the comma now. If there are no params, we'll be on NULL.
  760.             }
  761.             /*
  762.             while( str[input_string_pos] != ',' || str[input_string_pos] != NULL ) //|| current_param >= num_params ) //token terminates on a comma, or the end of the string
  763.             {
  764.                 token[token_pos] = str[input_string_pos]; //store the variable into a new token
  765.                 ++token_pos;
  766.             }
  767.             */
  768.             TraceNL(); TraceS("read() is getting tval"); TraceNL();
  769.             int tval; //value of the param
  770.             //first check the boolean types:
  771.             TraceNL(); TraceS("The arg token is: "); TraceS(token); TraceNL();
  772.             if ( !isNumber(token[0]) )
  773.             {
  774.                 switch(token[0])
  775.                 {
  776.                    
  777.                     case '-': tval = atof(token); break;
  778.                    
  779.                     case 't':
  780.                     case 'T':
  781.                         tval = 1; break;
  782.                     case 'f':
  783.                     case 'F':
  784.                         tval = 0; break;
  785.                    
  786.                     case 'l':
  787.                     case 'L':
  788.                     {
  789.                         switch(token[1])
  790.                         {
  791.                             case 'x':
  792.                             case 'X':
  793.                             {
  794.                                 TraceError("tval set to Link->X: ", Link->X);
  795.                                 tval = Link->X; break;
  796.                             }
  797.                             case 'y':
  798.                             case 'Y':
  799.                             {
  800.                                 TraceError("tval set to Link->Y: ", Link->Y);
  801.                                 tval = Link->Y; break;
  802.                             }
  803.                             default: TraceErrorS("Invalid token passed as an argument for instruction: ", token); tval = 0; break;
  804.                         }
  805.                         break;
  806.                     }
  807.                    
  808.                     default: TraceErrorS("Invalid token passed as an argument for instruction: ", token); tval = 0; break;
  809.                 }
  810.                 //if ( strcmp(token,"true") ) tval = 1;
  811.                 //else if ( strcmp(token,"T") ) tval = 1;
  812.                 //else if ( strcmp(token,"false") ) tval = 0;
  813.                 //else if ( strcmp(token,"F") ) tval = 0;
  814.                
  815.             }
  816.             else //literals
  817.             {
  818.                
  819.                 tval = atof(token);
  820.                 TraceNL(); TraceS("found a literal var of: "); Trace(tval); TraceNL();
  821.                
  822.             }
  823.             //push the token value onto the stack
  824.             stack[SP] = tval;
  825.        
  826.             //now out stack looks like:
  827.            
  828.             //: PARAMn where n is the loop iteration
  829.             //: PARAMn where n is the loop iteration
  830.             //: PARAMn where n is the loop iteration
  831.             //: INSTRUCTION
  832.            
  833.             ++SP; //this is why the stack size must be +1 larger than the3 total number of instructions and
  834.             //params that it can hold.
  835.             ++current_param;
  836.            
  837.         } //repeat this until we are out of params
  838.         return 1;
  839.        
  840.     }
  841.    
  842.     //void getVarValue(int str)
  843.     //{
  844.     //  variables[VP] = atof(str);
  845.     //  ++VP;
  846.     //}
  847.    
  848.     void execute()
  849.     {
  850.        
  851.         TraceNL(); TraceS("Stack Trace");
  852.         for ( int q = SizeOfArray(stack)-1; q >= 0; --q )
  853.         {
  854.             TraceNL(); Trace(stack[q]);
  855.         }
  856.        
  857.        
  858.         TraceNL(); TraceS("Running execute()"); TraceNL();
  859.         int reg_ptr = 0; //read the stack starting here, until we reach TOP.
  860.         int args[MAX_ARGS];
  861.         //evaluate the instruction:
  862.         int instr = stack[reg_ptr];
  863.         ++reg_ptr;
  864.         int current_arg = 0;
  865.         int num_of_params = num_instruction_params(instr);
  866.         TraceNL(); TraceS("execute() expects number of args to be: "); Trace(num_of_params); TraceNL();
  867.         for ( ; num_of_params > 0; --num_of_params )
  868.         {
  869.             args[current_arg] = stack[reg_ptr];
  870.             TraceNL(); TraceS("Putting an arg on the heap. Arg value: "); Trace(args[current_arg]); TraceNL();
  871.             ++current_arg;
  872.             ++reg_ptr;
  873.            
  874.         }
  875.        
  876.         TraceNL(); TraceS("execute believes that the present instruction is: "); Trace(instr); TraceNL();
  877.         TraceNL(); TraceS("args[0] is: "); Trace(args[0]); TraceNL();
  878.         TraceNL(); TraceS("args[1] is: "); Trace(args[1]); TraceNL();
  879.        
  880.         switch(instr)
  881.         {
  882.             case NONE:
  883.                 TraceError("STACK INSTRUCTION IS INVALID: ", instr);
  884.                 Game->TypingMode = false;
  885.                 clearbuffer();
  886.                 break;
  887.             case WARP:
  888.             {
  889.                 Link->Warp(args[0],args[1]);
  890.                 if ( log_actions ) TraceError("Cheat System Warped Link to dmap,screen:",args[0],args[1]);
  891.                 break;
  892.             }
  893.             case POS:
  894.             {
  895.                 Link->X = args[0];
  896.                 Link->Y = args[1];
  897.                 if ( log_actions ) TraceError("Cheat System repositioned Link to X,Y:",args[0],args[1]);
  898.                 break;
  899.             }
  900.            
  901.             case MOVEX:
  902.             {
  903.                 Link->X += args[0];
  904.                 if ( log_actions ) TraceError("Cheat system moved Link on his X axis by: ", args[0]);
  905.                 break;
  906.             }
  907.             case MOVEY:
  908.             {
  909.                 Link->Y += args[0];
  910.                 if ( log_actions ) TraceError("Cheat system moved Link on his Y axis by", args[0]);
  911.                 break;
  912.             }
  913.             case REFILLHP:
  914.             {
  915.                 Link->HP =  Link->MaxHP;
  916.                 if ( log_actions ) TraceError("Cheat system refilled Link's HP to", Link->MaxHP);
  917.                 break;
  918.             }
  919.             case REFILLMP:
  920.             {
  921.                 Link->MP =  Link->MaxMP;
  922.                 if ( log_actions ) TraceError("Cheat system refilled Link's MP to", Link->MaxHP);
  923.                 break;
  924.             }
  925.             case REFILLCTR:
  926.             {
  927.                 Game->Counter[args[0]] =  Game->MCounter[args[0]];
  928.                 if ( log_actions ) TraceError("Cheat system refilled Counter", args[0]);
  929.                 break;
  930.             }
  931.             case MAXHP:
  932.             {
  933.                 Game->MCounter[CR_LIFE] = args[0];
  934.                 if ( log_actions ) TraceError("Cheat system set Link's Max HP to:",args[0]);
  935.                 break;
  936.             }
  937.             case MAXMP:
  938.             {
  939.                 Game->MCounter[CR_MAGIC] = args[0];
  940.                 if ( log_actions ) TraceError("Cheat system set Link's Max MP to:",args[0]);
  941.                 break;
  942.             }
  943.             case MAXCTR:
  944.             {
  945.                 Game->Counter[args[0]] = args[1];
  946.                 if ( log_actions ) TraceError("Cheat system refilled Counter (id, amount):",args[0],args[1]);
  947.                 break;
  948.             }
  949.            
  950.             case INVINCIBLE:
  951.             {
  952.                 if ( args[0] )
  953.                 {
  954.                     Link->Invisible = true;
  955.                     if ( log_actions ) TraceErrorS("Cheat system set Link's Invisibility state to ","true");
  956.                     break;
  957.                 }
  958.                 else
  959.                 {
  960.                     Link->Invisible = false;
  961.                     if ( log_actions ) TraceErrorS("Cheat system set Link's Invisibility state to ","false");
  962.                     break;
  963.                    
  964.                 }
  965.                
  966.             }
  967.             case LINKITEM:
  968.             {
  969.                 itemdata id = Game->LoadItemData(args[0]);
  970.                 if ( id->Keep )
  971.                 {
  972.                     if ( args[1] )
  973.                     {
  974.                        
  975.                         Link->Item[args[0]] = true;
  976.                         if ( log_actions ) TraceErrorS("Cheat system set Link's Inventory Item to (item, state)","true");
  977.                         break;
  978.                     }
  979.                     else
  980.                     {
  981.                         Link->Item[args[0]] = false;
  982.                         if ( log_actions ) TraceErrorS("Cheat system set Link's Inventory Item to (item, state)","false");
  983.                         break;
  984.                        
  985.                     }
  986.                 }
  987.                 else break;
  988.             }
  989.             case SAVE:
  990.             {
  991.                 TraceNL(); TraceS("Cheat system is saving the game.");
  992.                 clearbuffer();
  993.                 Game->Save();
  994.                 break;
  995.             }
  996.             case CREATEITEM:
  997.             {
  998.                 if ( log_actions ) TraceError("Cheat system is creating item ID: ", args[0]);
  999.                 if ( log_actions ) TraceError("Cheat system is creating item at X Position: ", args[1]);
  1000.                 if ( log_actions ) TraceError("Cheat system is creating item at Y Position: ", args[2]);
  1001.                 item cci = Screen->CreateItem(args[0]);
  1002.                 cci->X = args[1];
  1003.                 cci->Y = args[2];
  1004.                 break;
  1005.             }
  1006.             case CREATENPC:
  1007.             {
  1008.                 if ( log_actions ) TraceError("Cheat system is creating npc ID: ", args[0]);
  1009.                 if ( log_actions ) TraceError("Cheat system is creating npc at X Position: ", args[1]);
  1010.                 if ( log_actions ) TraceError("Cheat system is creating npc at Y Position: ", args[2]);
  1011.                 npc ccn = Screen->CreateNPC(args[0]);
  1012.                 ccn->X = args[1];
  1013.                 ccn->Y = args[2];
  1014.                 break;
  1015.             }
  1016.             case PALETTE:
  1017.             {
  1018.                 if ( args[0] < 0 )
  1019.                 {
  1020.                     Game->DMapPalette[Game->GetCurDMap()] = args[1];
  1021.                 }
  1022.                 else Game->DMapPalette[args[0]] = args[1];
  1023.                 break;
  1024.             }
  1025.             case MONOCHROME:
  1026.             {
  1027.                 Graphics->Monochrome(args[0]); break;
  1028.             }
  1029.             case MBOMBS: Game->MCounter[CR_BOMBS] = args[0]; break;
  1030.             case BOMBS: Game->Counter[CR_BOMBS] = args[0]; break;
  1031.             case MARROWS: Game->MCounter[CR_ARROWS] = args[0]; break;
  1032.             case ARROWS: Game->Counter[CR_ARROWS] = args[0]; break;
  1033.             case KEYS: Game->Counter[CR_KEYS] = args[0]; break;
  1034.             case RUPEES: Game->Counter[CR_RUPEES] = args[0]; break;
  1035.             case MRUPEES: Game->MCounter[CR_RUPEES] = args[0]; break;
  1036.            
  1037.             case LKEYS: Game->LKeys[args[0]] = args[1]; break;
  1038.             case LINKDIAGONAL: Link->Diagonal = Cond(args[0],true,false); break;
  1039.             case BIGHITBOX: Link->BigHitbox = Cond(args[0],true,false); break;
  1040.            
  1041.             case LMAP:
  1042.             {
  1043.                 if ( args[1] ) //true
  1044.                 {  
  1045.                     Game->LItems[args[0]] |= LI_MAP;
  1046.                 }
  1047.                 else Game->LItems[args[0]] &= ~LI_MAP;
  1048.             }
  1049.             case LBOSSKEY:
  1050.             {
  1051.                 if ( args[1] ) //true
  1052.                 {  
  1053.                     Game->LItems[args[0]] |= LI_BOSSKEY;
  1054.                 }
  1055.                 else Game->LItems[args[0]] &= ~LI_BOSSKEY;
  1056.             }
  1057.             case LCOMPASS:
  1058.             {
  1059.                 if ( args[1] ) //true
  1060.                 {  
  1061.                     Game->LItems[args[0]] |= LI_COMPASS;
  1062.                 }
  1063.                 else Game->LItems[args[0]] &= ~LI_COMPASS;
  1064.             }
  1065.             case LTRIFORCE:
  1066.             {
  1067.                 if ( args[1] ) //true
  1068.                 {  
  1069.                     Game->LItems[args[0]] |= LI_TRIFORCE;
  1070.                 }
  1071.                 else Game->LItems[args[0]] &= ~LI_TRIFORCE;
  1072.             }
  1073.                
  1074.             default:
  1075.             {
  1076.                
  1077.                 TraceError("Invalid instruction passed to stack",instr);
  1078.                 break;
  1079.             }
  1080.            
  1081.            
  1082.         }
  1083.         ///-----later, we'll add this: //pop everything off of the stack
  1084.         //just wipe the stack for now, as we only support one command at this time
  1085.         for ( int q = 0; q < 3; ++q ) stack[q] = 0;
  1086.         SP = 0;
  1087.        
  1088.         //clear the main buffer, too!
  1089.         for ( int cl = 0; cl < BUFFER_LENGTH; ++cl ) debug_buffer[cl] = 0;
  1090.         Game->TypingMode = false; //insurance clear
  1091.         Link->PressStart = false;
  1092.         Link->InputStart = false;
  1093.        
  1094.        
  1095.     }
  1096.        
  1097.     void run()
  1098.     {
  1099.    
  1100.        
  1101.        
  1102.     }
  1103. }
  1104.  
  1105. global script test
  1106. {
  1107.     void run()
  1108.     {
  1109.         debugshell.SP = 0;
  1110.         debugshell.clearbuffer();
  1111.         while(1)
  1112.         {
  1113.             debugshell.process();
  1114.             Waitdraw();
  1115.             Waitframe();
  1116.         }
  1117.        
  1118.     }
  1119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement