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.ProjectCommon;
- using GameMaker.IO;
- namespace GameMaker.ExtensionProject
- {
- public class ProjectReader : ReaderBase
- {
- Obfuscation m_obfuscation = new Obfuscation();
- public ProjectReader()
- {
- }
- public ProjectReader(string path)
- {
- Open(path);
- }
- public Project ReadProject()
- {
- Project p = new Project();
- ReadInt(); // version
- p.Hidden = ReadBool();
- p.Name = ReadString();
- p.TempDirectory = ReadString();
- p.Version = ReadString();
- p.Author = ReadString();
- p.DateModified = ReadString();
- p.License = ReadString();
- p.Information = ReadString();
- p.HelpFile = ReadString();
- p.Hidden = ReadBool();
- int count = ReadInt();
- while ((count--) > 0)
- p.Uses.Add(ReadString());
- count = ReadInt();
- while ((count--) > 0)
- {
- IncludeFile file = new IncludeFile();
- ReadInt();
- file.Name = ReadString();
- file.Path = ReadString();
- file.Type = (FileType)ReadInt();
- file.InitializeCode = ReadString();
- file.FinalizeCode = ReadString();
- int tmpCount = ReadInt();
- while ((tmpCount--) > 0)
- {
- Function function = new Function();
- ReadInt();
- function.Name = ReadString();
- function.ExternalName = ReadString();
- function.CallConvention = (CallConvention)ReadInt();
- function.HelpLine = ReadString();
- function.Hidden = ReadBool();
- ReadInt();
- int argCount = 17;
- while ((argCount--) > 0)
- function.Arguments.Add((ResultType)ReadInt());
- function.ResultType = (ResultType)ReadInt();
- file.Functions.Add(function);
- }
- tmpCount = ReadInt();
- while ((tmpCount--) > 0)
- {
- Constant c = new Constant();
- ReadInt();
- c.Name = ReadString();
- c.Value = ReadString();
- c.Hidden = ReadBool();
- file.Constants.Add(c);
- }
- p.Files.Add(file);
- }
- return p;
- }
- public Project LoadInstaller()
- {
- ReadInt(); // id;
- ReadInt(); // version;
- m_obfuscation.Seed = ReadInt(); // seed
- Project p = ReadProject();
- if (!string.IsNullOrEmpty(p.HelpFile))
- {
- byte[] b = ReadBytes(ReadInt());
- Inflater inf = new Inflater();
- inf.SetInput(b);
- using (BinaryWriter w = new BinaryWriter(new FileStream(System.IO.Path.GetFileName(p.HelpFile), FileMode.OpenOrCreate, FileAccess.ReadWrite)))
- {
- while (!inf.IsFinished)
- {
- byte[] output = new byte[1000];
- long size = inf.Inflate(output);
- w.Write(output, 0, (int)size);
- }
- }
- }
- foreach (IncludeFile f in p.Files)
- {
- if (!string.IsNullOrEmpty(f.Name))
- {
- byte[] b = ReadBytes(ReadInt());
- Inflater inf = new Inflater();
- inf.SetInput(b);
- using (BinaryWriter w = new BinaryWriter(new FileStream(f.Name , FileMode.OpenOrCreate, FileAccess.ReadWrite)))
- {
- while (!inf.IsFinished)
- {
- byte[] output = new byte[1000];
- long size = inf.Inflate(output);
- w.Write(output, 0, (int)size);
- }
- }
- }
- }
- return p;
- }
- protected override byte ReadByte()
- {
- if (m_obfuscation.SwapTable != null)
- return (byte)m_obfuscation.SwapTable[1, base.ReadByte()];
- return base.ReadByte();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement