home *** CD-ROM | disk | FTP | other *** search
/ Action Games (2008) / akcnihry1.iso / AT-Robots 2.10 / ATRLOCK.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-04-27  |  5.3 KB  |  182 lines

  1. (*
  2. Copyright (c) 1999, Ed T. Toton III. All rights reserved.
  3.  
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7.  
  8.    Redistributions of source code must retain the above copyright notice,
  9.    this list of conditions and the following disclaimer.
  10.  
  11.    Redistributions in binary form must reproduce the above copyright notice, 
  12.    this list of conditions and the following disclaimer in the documentation
  13.    and/or other materials provided with the distribution.
  14.  
  15.    All advertising materials mentioning features or use of this software
  16.    must display the following acknowledgement:
  17.  
  18.         This product includes software developed by Ed T. Toton III &
  19.         NecroBones Enterprises.
  20.  
  21.    No modified or derivative copies or software may be distributed in the
  22.    guise of official or original releases/versions of this software. Such
  23.    works must contain acknowledgement that it is modified from the original.
  24.  
  25.    Neither the name of the author nor the name of the business or
  26.    contributers may be used to endorse or promote products derived
  27.    from this software without specific prior written permission.
  28.  
  29. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY 
  30. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
  31. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  32. DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
  33. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  34. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  35. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  36. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  37. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  38. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *)
  40.  
  41. { This program encrypts the robot programs for distribution }
  42.  
  43. {$G+}{$N+}{$E+}{$X+}{$D-}
  44. {$M 32768,0,655360}
  45. program atrlock;
  46.  
  47. uses stuff, filelib;
  48.  
  49. const
  50.  locktype = 3;
  51.  
  52. var
  53.  fn1,fn2:string;
  54.  f1,f2:text;
  55.  s,s1,s2,lock_code:string;
  56.  i,j,k,lock_pos,lock_dat,this_dat:integer;
  57.  
  58. function encode(s:string):string;
  59. var
  60.  i,j,k:integer;
  61. begin
  62.  {k:=0;}
  63.  if lock_code<>'' then
  64.   for i:=1 to length(s) do
  65.    begin
  66.     inc(lock_pos); if lock_pos>length(lock_code) then lock_pos:=1;
  67.     if ord(s[i]) in [0..31,128..255] then s[i]:=' ';
  68.     this_dat:=ord(s[i]) and 15;
  69.     s[i]:=char((ord(s[i]) xor (ord(lock_code[lock_pos]) xor lock_dat))+1);
  70.     lock_dat:=this_dat;
  71.    end;
  72.  encode:=s;
  73. end;
  74.  
  75. function prepare(s,s1:string):string;
  76. var
  77.  i,j,k,l:integer;
  78.  s2:string;
  79. begin
  80.    {--remove comments--}
  81.    if (length(s1)=0) or (s1[1]=';') then s1:=''
  82.     else
  83.      begin
  84.       k:=0;
  85.       for i:=length(s1) downto 1 do
  86.          if s1[i]=';' then k:=i;
  87.       if k>0 then s1:=lstr(s1,k-1);
  88.      end;
  89.  
  90.    {--remove excess spaces--}
  91.    s2:='';
  92.    for i:=1 to length(s1) do
  93.     if not (s1[i] in [' ',#8,#9,#10,',']) then s2:=s2+s1[i]
  94.      else begin if s2<>'' then s:=s+s2+' '; s2:=''; end;
  95.  
  96.    if s2<>'' then s:=s+s2;
  97.  
  98.    prepare:=s;
  99. end;
  100.  
  101. procedure write_line(s,s1:string);
  102. begin
  103.    s:=prepare(s,s1);
  104.  
  105.    {--write line!--}
  106.    if length(s)>0 then
  107.     begin
  108.      s:=encode(s);
  109.      writeln(f2,s);
  110.     end;
  111. end;
  112.  
  113. begin
  114.  randomize;
  115.  lock_pos:=0;
  116.  lock_dat:=0;
  117.  if (paramcount<1) or (paramcount>2) then
  118.   begin
  119.    writeln('Usage: ATRLOCK <robot[.at2]> [locked[.atl]]');
  120.    halt;
  121.   end;
  122.  fn1:=btrim(ucase(paramstr(1)));
  123.  if fn1=base_name(fn1) then fn1:=fn1+'.AT2';
  124.  if not exist(fn1) then
  125.   begin writeln('Robot "',fn1,'" not found!'); halt; end;
  126.  if paramcount=2 then
  127.     fn2:=btrim(ucase(paramstr(2))) else fn2:=base_name(fn1)+'.ATL';
  128.  if fn2=base_name(fn2) then fn2:=fn2+'.ATL';
  129.  if not valid(fn2) then
  130.   begin writeln('Output name "',fn1,'" not valid!'); halt; end;
  131.  if fn1=fn2 then
  132.   begin writeln('Filenames can not be the same!'); halt; end;
  133.  assign(f1,fn1); reset(f1);
  134.  assign(f2,fn2); rewrite(f2);
  135.  
  136.  {--copy comment header--}
  137.  writeln(f2,';------------------------------------------------------------------------------');
  138.  s:='';
  139.  while (not eof(f1)) and (s='') do
  140.   begin
  141.    readln(f1,s);
  142.    s:=btrim(s);
  143.    if s[1]=';' then begin writeln(f2,s); s:=''; end;
  144.   end;
  145.  
  146.  {--lock header--}
  147.  writeln(f2,';------------------------------------------------------------------------------');
  148.  writeln(f2,'; ',no_path(base_name(fn1)),' Locked on ',date);
  149.  writeln(f2,';------------------------------------------------------------------------------');
  150.  lock_code:='';
  151.  k:=random(21)+20;
  152.  for i:=1 to k do
  153.   lock_code:=lock_code+char(random(32)+65);
  154.  writeln(f2,'#LOCK',locktype,' ',lock_code);
  155.  
  156.  {--decode lock-code--}
  157.  for i:=1 to length(lock_code) do
  158.   lock_code[i]:=char(ord(lock_code[i])-65);
  159.  
  160.  write('Encoding "',fn1,'"...');
  161.  
  162.  {--encode robot--}
  163.  s:=btrim(s);
  164.  if length(s)>0 then
  165.   write_line('',ucase(s));
  166.  while not eof(f1) do
  167.   begin
  168.    {--read line!--}
  169.    readln(f1,s1); s:='';
  170.    s1:=btrim(ucase(s1));
  171.  
  172.    {--write line!--}
  173.    write_line(s,s1);
  174.   end;
  175.  writeln('Done. Used LOCK Format #',locktype,'.');
  176.  writeln('Only ATR2 v2.08 or later can decode.');
  177.  writeln('LOCKed robot saved as "',fn2,'"');
  178.  
  179.  close(f1); close(f2);
  180. end.
  181.  
  182.