Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. using ICSharpCode.SharpZipLib.Zip.Compression;
  5.  
  6. using GameMaker.ProjectCommon;
  7. using GameMaker.IO;
  8.  
  9. namespace GameMaker.ExtensionProject
  10. {
  11. public class ProjectReader : ReaderBase
  12. {
  13. Obfuscation m_obfuscation = new Obfuscation();
  14.  
  15. public ProjectReader()
  16. {
  17. }
  18.  
  19. public ProjectReader(string path)
  20. {
  21. Open(path);
  22. }
  23.  
  24. public Project ReadProject()
  25. {
  26. Project p = new Project();
  27.  
  28. ReadInt(); // version
  29. p.Hidden = ReadBool();
  30. p.Name = ReadString();
  31. p.TempDirectory = ReadString();
  32. p.Version = ReadString();
  33. p.Author = ReadString();
  34. p.DateModified = ReadString();
  35. p.License = ReadString();
  36. p.Information = ReadString();
  37. p.HelpFile = ReadString();
  38. p.Hidden = ReadBool();
  39. int count = ReadInt();
  40.  
  41. while ((count--) > 0)
  42. p.Uses.Add(ReadString());
  43.  
  44. count = ReadInt();
  45.  
  46. while ((count--) > 0)
  47. {
  48. IncludeFile file = new IncludeFile();
  49. ReadInt();
  50. file.Name = ReadString();
  51. file.Path = ReadString();
  52. file.Type = (FileType)ReadInt();
  53. file.InitializeCode = ReadString();
  54. file.FinalizeCode = ReadString();
  55. int tmpCount = ReadInt();
  56.  
  57. while ((tmpCount--) > 0)
  58. {
  59. Function function = new Function();
  60. ReadInt();
  61. function.Name = ReadString();
  62. function.ExternalName = ReadString();
  63. function.CallConvention = (CallConvention)ReadInt();
  64. function.HelpLine = ReadString();
  65. function.Hidden = ReadBool();
  66. ReadInt();
  67. int argCount = 17;
  68. while ((argCount--) > 0)
  69. function.Arguments.Add((ResultType)ReadInt());
  70.  
  71. function.ResultType = (ResultType)ReadInt();
  72.  
  73. file.Functions.Add(function);
  74. }
  75.  
  76. tmpCount = ReadInt();
  77.  
  78. while ((tmpCount--) > 0)
  79. {
  80. Constant c = new Constant();
  81. ReadInt();
  82. c.Name = ReadString();
  83. c.Value = ReadString();
  84. c.Hidden = ReadBool();
  85. file.Constants.Add(c);
  86. }
  87.  
  88. p.Files.Add(file);
  89. }
  90.  
  91. return p;
  92. }
  93.  
  94. public Project LoadInstaller()
  95. {
  96. ReadInt(); // id;
  97. ReadInt(); // version;
  98. m_obfuscation.Seed = ReadInt(); // seed
  99.  
  100. Project p = ReadProject();
  101.  
  102. if (!string.IsNullOrEmpty(p.HelpFile))
  103. {
  104. byte[] b = ReadBytes(ReadInt());
  105. Inflater inf = new Inflater();
  106. inf.SetInput(b);
  107.  
  108. using (BinaryWriter w = new BinaryWriter(new FileStream(System.IO.Path.GetFileName(p.HelpFile), FileMode.OpenOrCreate, FileAccess.ReadWrite)))
  109. {
  110. while (!inf.IsFinished)
  111. {
  112. byte[] output = new byte[1000];
  113. long size = inf.Inflate(output);
  114. w.Write(output, 0, (int)size);
  115. }
  116. }
  117.  
  118. }
  119.  
  120. foreach (IncludeFile f in p.Files)
  121. {
  122. if (!string.IsNullOrEmpty(f.Name))
  123. {
  124. byte[] b = ReadBytes(ReadInt());
  125. Inflater inf = new Inflater();
  126. inf.SetInput(b);
  127.  
  128. using (BinaryWriter w = new BinaryWriter(new FileStream(f.Name , FileMode.OpenOrCreate, FileAccess.ReadWrite)))
  129. {
  130. while (!inf.IsFinished)
  131. {
  132. byte[] output = new byte[1000];
  133. long size = inf.Inflate(output);
  134. w.Write(output, 0, (int)size);
  135. }
  136. }
  137.  
  138. }
  139. }
  140. return p;
  141. }
  142.  
  143. protected override byte ReadByte()
  144. {
  145. if (m_obfuscation.SwapTable != null)
  146. return (byte)m_obfuscation.SwapTable[1, base.ReadByte()];
  147.  
  148. return base.ReadByte();
  149. }
  150. }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement