Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using ICSharpCode.SharpZipLib.Zip.Compression;
- using GameMaker.IO;
- using GameMaker.ProjectCommon;
- namespace GameMaker.ExtensionProject
- {
- public class ProjectWriter : WriterBase
- {
- Obfuscation m_obfuscation = new Obfuscation();
- internal Obfuscation Obfuscation
- {
- get { return m_obfuscation; }
- }
- public int[,] SwapTable
- {
- get { return m_obfuscation.SwapTable; }
- }
- public int Seed
- {
- get { return m_obfuscation.Seed; }
- set { m_obfuscation.Seed = value; }
- }
- public ProjectWriter()
- {
- }
- public ProjectWriter(string path)
- {
- Open(path);
- }
- public void WriteProject(Project proj)
- {
- WriteInt(700);
- WriteBool(proj.Editable);
- WriteString(proj.Name);
- WriteString(proj.TempDirectory);
- WriteString(proj.Version);
- WriteString(proj.Author);
- WriteString(proj.DateModified);
- WriteString(proj.License);
- WriteString(proj.Information);
- WriteString(proj.HelpFile);
- WriteBool(proj.Hidden);
- WriteInt(proj.Uses.Count);
- foreach (string s in proj.Uses)
- WriteString(s);
- WriteInt(proj.Files.Count);
- foreach (IncludeFile f in proj.Files)
- {
- WriteInt(700);
- WriteString(f.Name);
- WriteString(f.Path);
- WriteInt((int)f.Type);
- WriteString(f.InitializeCode);
- WriteString(f.FinalizeCode);
- WriteInt(f.Functions.Count);
- foreach (Function func in f.Functions)
- {
- WriteInt(700);
- WriteString(func.Name);
- WriteString(func.ExternalName);
- WriteInt((int)func.CallConvention);
- WriteString(func.HelpLine);
- WriteBool(func.Hidden);
- WriteInt(func.Arguments.Count);
- foreach (ResultType t in func.Arguments)
- WriteInt((int)t);
- WriteInt((int)func.ResultType);
- }
- WriteInt(f.Constants.Count);
- foreach (Constant c in f.Constants)
- {
- WriteInt(700);
- WriteString(c.Name);
- WriteString(c.Value);
- WriteBool(c.Hidden);
- }
- }
- }
- public void CreateInstaller(Project proj)
- {
- WriteInt(1234321);
- WriteInt(701);
- Random random = new Random();
- int seed = (random.Next() % 25600) + 3000;
- WriteInt(248);
- Seed = 248;
- WriteProject(proj);
- // Is there a help file?
- if (!string.IsNullOrEmpty(proj.HelpFile))
- {
- MemoryStream stm = new MemoryStream();
- // Open it.
- using (BinaryReader r = new BinaryReader(new FileStream(proj.HelpFile, FileMode.Open, FileAccess.ReadWrite)))
- {
- byte[] data = r.ReadBytes((int)r.BaseStream.Length);
- Deflater def = new Deflater();
- def.SetInput(data);
- def.Finish();
- // Compress it.
- while (!def.IsFinished)
- {
- byte[] buf = new byte[1000];
- int size = def.Deflate(buf);
- stm.Write(buf, 0, size);
- }
- }
- // Write it to the installer
- WriteInt((int)stm.Length);
- WriteBytes(stm.ToArray());
- stm.Close();
- }
- foreach (IncludeFile f in proj.Files)
- {
- MemoryStream stm = new MemoryStream();
- using (BinaryReader r = new BinaryReader(new FileStream(f.Path, FileMode.Open, FileAccess.ReadWrite)))
- {
- byte[] data = r.ReadBytes((int)r.BaseStream.Length);
- Deflater def = new Deflater();
- def.SetInput(data);
- def.Finish();
- while (!def.IsFinished)
- {
- byte[] buf = new byte[1000];
- int size = def.Deflate(buf);
- stm.Write(buf, 0, size);
- }
- }
- WriteInt((int)stm.Length);
- WriteBytes(stm.ToArray());
- stm.Close();
- }
- }
- protected override void WriteByte(byte b)
- {
- if (m_obfuscation.SwapTable != null)
- base.WriteByte((byte)m_obfuscation.SwapTable[0, b]);
- else
- base.WriteByte(b);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement