Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. using ICSharpCode.SharpZipLib.Zip.Compression;
  5.  
  6. using GameMaker.IO;
  7. using GameMaker.ProjectCommon;
  8.  
  9. namespace GameMaker.ExtensionProject
  10. {
  11. public class ProjectWriter : WriterBase
  12. {
  13.  
  14. Obfuscation m_obfuscation = new Obfuscation();
  15.  
  16. internal Obfuscation Obfuscation
  17. {
  18. get { return m_obfuscation; }
  19. }
  20.  
  21. public int[,] SwapTable
  22. {
  23. get { return m_obfuscation.SwapTable; }
  24. }
  25.  
  26. public int Seed
  27. {
  28. get { return m_obfuscation.Seed; }
  29. set { m_obfuscation.Seed = value; }
  30. }
  31.  
  32. public ProjectWriter()
  33. {
  34. }
  35.  
  36. public ProjectWriter(string path)
  37. {
  38. Open(path);
  39. }
  40.  
  41. public void WriteProject(Project proj)
  42. {
  43. WriteInt(700);
  44. WriteBool(proj.Editable);
  45. WriteString(proj.Name);
  46. WriteString(proj.TempDirectory);
  47. WriteString(proj.Version);
  48. WriteString(proj.Author);
  49. WriteString(proj.DateModified);
  50. WriteString(proj.License);
  51. WriteString(proj.Information);
  52. WriteString(proj.HelpFile);
  53. WriteBool(proj.Hidden);
  54. WriteInt(proj.Uses.Count);
  55. foreach (string s in proj.Uses)
  56. WriteString(s);
  57.  
  58. WriteInt(proj.Files.Count);
  59. foreach (IncludeFile f in proj.Files)
  60. {
  61. WriteInt(700);
  62. WriteString(f.Name);
  63. WriteString(f.Path);
  64. WriteInt((int)f.Type);
  65. WriteString(f.InitializeCode);
  66. WriteString(f.FinalizeCode);
  67. WriteInt(f.Functions.Count);
  68. foreach (Function func in f.Functions)
  69. {
  70. WriteInt(700);
  71. WriteString(func.Name);
  72. WriteString(func.ExternalName);
  73. WriteInt((int)func.CallConvention);
  74. WriteString(func.HelpLine);
  75. WriteBool(func.Hidden);
  76. WriteInt(func.Arguments.Count);
  77. foreach (ResultType t in func.Arguments)
  78. WriteInt((int)t);
  79.  
  80. WriteInt((int)func.ResultType);
  81. }
  82.  
  83. WriteInt(f.Constants.Count);
  84. foreach (Constant c in f.Constants)
  85. {
  86. WriteInt(700);
  87. WriteString(c.Name);
  88. WriteString(c.Value);
  89. WriteBool(c.Hidden);
  90. }
  91. }
  92. }
  93.  
  94. public void CreateInstaller(Project proj)
  95. {
  96. WriteInt(1234321);
  97. WriteInt(701);
  98. Random random = new Random();
  99. int seed = (random.Next() % 25600) + 3000;
  100. WriteInt(248);
  101. Seed = 248;
  102.  
  103. WriteProject(proj);
  104.  
  105. // Is there a help file?
  106. if (!string.IsNullOrEmpty(proj.HelpFile))
  107. {
  108. MemoryStream stm = new MemoryStream();
  109.  
  110. // Open it.
  111. using (BinaryReader r = new BinaryReader(new FileStream(proj.HelpFile, FileMode.Open, FileAccess.ReadWrite)))
  112. {
  113. byte[] data = r.ReadBytes((int)r.BaseStream.Length);
  114. Deflater def = new Deflater();
  115. def.SetInput(data);
  116. def.Finish();
  117.  
  118. // Compress it.
  119. while (!def.IsFinished)
  120. {
  121. byte[] buf = new byte[1000];
  122. int size = def.Deflate(buf);
  123. stm.Write(buf, 0, size);
  124. }
  125. }
  126.  
  127. // Write it to the installer
  128. WriteInt((int)stm.Length);
  129. WriteBytes(stm.ToArray());
  130. stm.Close();
  131. }
  132.  
  133. foreach (IncludeFile f in proj.Files)
  134. {
  135. MemoryStream stm = new MemoryStream();
  136.  
  137. using (BinaryReader r = new BinaryReader(new FileStream(f.Path, FileMode.Open, FileAccess.ReadWrite)))
  138. {
  139. byte[] data = r.ReadBytes((int)r.BaseStream.Length);
  140. Deflater def = new Deflater();
  141. def.SetInput(data);
  142. def.Finish();
  143. while (!def.IsFinished)
  144. {
  145. byte[] buf = new byte[1000];
  146. int size = def.Deflate(buf);
  147. stm.Write(buf, 0, size);
  148. }
  149. }
  150.  
  151. WriteInt((int)stm.Length);
  152. WriteBytes(stm.ToArray());
  153. stm.Close();
  154. }
  155. }
  156.  
  157. protected override void WriteByte(byte b)
  158. {
  159. if (m_obfuscation.SwapTable != null)
  160. base.WriteByte((byte)m_obfuscation.SwapTable[0, b]);
  161. else
  162. base.WriteByte(b);
  163. }
  164. }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement