function patchmercs(fullfilename,data)
%Patch Mechwarrior 2 Mercenaries's weapons
%
%patchmercs(fullfilename,data)
% 
%fullfilename is name of mw2.exe, including full path
%  if filename is not specified, will open a dialog to select file
%
%data is 66 x 24 array of int32, from readmercs.m. Note order should be
%   the same as original.
%

%% locate the file
if (~exist('fullfilename','var') ||isempty(fullfilename))
    fprintf('Select mw2.exe\n');
    [filename,pathname]=uigetfile('mw2.exe','Open MW2.EXE');
    fullfilename=[pathname filename];
end
%% open file, write weapons data
fid=fopen(fullfilename,'r+');
startoffset=913420;
fseek(fid,startoffset,-1);

for i=1:66
    fwrite(fid,int32(data(i,:)),'int32');%write 24 values of int32
    fseek(fid,8,0);   
end
fclose(fid);
fprintf('Done. Now data is: \n');
readmercs(fullfilename);
