├── .gitattributes
├── .gitignore
├── CSEGui
├── CSEGui.csproj
├── Form1.Designer.cs
├── Form1.cs
├── Form1.resx
├── Program.cs
└── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── CatSceneEditor.sln
├── CatSceneEditor
├── Algo.cs
├── CSTHelper.cs
├── CSTL.cs
├── CSTLHelper.cs
├── CatSceneEditor.csproj
├── Int.cs
├── Main.cs
├── Properties
│ └── AssemblyInfo.cs
├── StructStream.cs
├── VirtStream.cs
└── Zlib
│ ├── Adler32.cs
│ ├── Deflate.cs
│ ├── InfBlocks.cs
│ ├── InfCodes.cs
│ ├── InfTree.cs
│ ├── Inflate.cs
│ ├── StaticTree.cs
│ ├── SupportClass.cs
│ ├── Tree.cs
│ ├── ZInputStream.cs
│ ├── ZLibStream.cs
│ ├── ZOutputStream.cs
│ ├── ZStream.cs
│ ├── ZStreamException.cs
│ ├── Zlib.cs
│ ├── license.txt
│ └── readme.txt
├── CatSystemDebugger
├── CatSystemDebugger.csproj
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
├── app.manifest
└── packages.config
├── README.md
└── packages
└── AsmResolver.2.0.6262.22149
├── AsmResolver.2.0.6262.22149.nupkg
└── lib
└── net40-client
├── AsmResolver.XML
└── AsmResolver.dll
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | artifacts/
46 |
47 | *_i.c
48 | *_p.c
49 | *_i.h
50 | *.ilk
51 | *.meta
52 | *.obj
53 | *.pch
54 | *.pdb
55 | *.pgc
56 | *.pgd
57 | *.rsp
58 | *.sbr
59 | *.tlb
60 | *.tli
61 | *.tlh
62 | *.tmp
63 | *.tmp_proj
64 | *.log
65 | *.vspscc
66 | *.vssscc
67 | .builds
68 | *.pidb
69 | *.svclog
70 | *.scc
71 |
72 | # Chutzpah Test files
73 | _Chutzpah*
74 |
75 | # Visual C++ cache files
76 | ipch/
77 | *.aps
78 | *.ncb
79 | *.opendb
80 | *.opensdf
81 | *.sdf
82 | *.cachefile
83 | *.VC.db
84 | *.VC.VC.opendb
85 |
86 | # Visual Studio profiler
87 | *.psess
88 | *.vsp
89 | *.vspx
90 | *.sap
91 |
92 | # TFS 2012 Local Workspace
93 | $tf/
94 |
95 | # Guidance Automation Toolkit
96 | *.gpState
97 |
98 | # ReSharper is a .NET coding add-in
99 | _ReSharper*/
100 | *.[Rr]e[Ss]harper
101 | *.DotSettings.user
102 |
103 | # JustCode is a .NET coding add-in
104 | .JustCode
105 |
106 | # TeamCity is a build add-in
107 | _TeamCity*
108 |
109 | # DotCover is a Code Coverage Tool
110 | *.dotCover
111 |
112 | # NCrunch
113 | _NCrunch_*
114 | .*crunch*.local.xml
115 | nCrunchTemp_*
116 |
117 | # MightyMoose
118 | *.mm.*
119 | AutoTest.Net/
120 |
121 | # Web workbench (sass)
122 | .sass-cache/
123 |
124 | # Installshield output folder
125 | [Ee]xpress/
126 |
127 | # DocProject is a documentation generator add-in
128 | DocProject/buildhelp/
129 | DocProject/Help/*.HxT
130 | DocProject/Help/*.HxC
131 | DocProject/Help/*.hhc
132 | DocProject/Help/*.hhk
133 | DocProject/Help/*.hhp
134 | DocProject/Help/Html2
135 | DocProject/Help/html
136 |
137 | # Click-Once directory
138 | publish/
139 |
140 | # Publish Web Output
141 | *.[Pp]ublish.xml
142 | *.azurePubxml
143 | # TODO: Comment the next line if you want to checkin your web deploy settings
144 | # but database connection strings (with potential passwords) will be unencrypted
145 | *.pubxml
146 | *.publishproj
147 |
148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
149 | # checkin your Azure Web App publish settings, but sensitive information contained
150 | # in these scripts will be unencrypted
151 | PublishScripts/
152 |
153 | # Microsoft Azure Build Output
154 | csx/
155 | *.build.csdef
156 |
157 | # Microsoft Azure Emulator
158 | ecf/
159 | rcf/
160 |
161 | # Windows Store app package directories and files
162 | AppPackages/
163 | BundleArtifacts/
164 | Package.StoreAssociation.xml
165 | _pkginfo.txt
166 |
167 | # Visual Studio cache files
168 | # files ending in .cache can be ignored
169 | *.[Cc]ache
170 | # but keep track of directories ending in .cache
171 | !*.[Cc]ache/
172 |
173 | # Others
174 | ClientBin/
175 | ~$*
176 | *~
177 | *.dbmdl
178 | *.dbproj.schemaview
179 | *.pfx
180 | *.publishsettings
181 | node_modules/
182 | orleans.codegen.cs
183 |
184 | # Since there are multiple workflows, uncomment next line to ignore bower_components
185 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
186 | #bower_components/
187 |
188 | # RIA/Silverlight projects
189 | Generated_Code/
190 |
191 | # Backup & report files from converting an old project file
192 | # to a newer Visual Studio version. Backup files are not needed,
193 | # because we have git ;-)
194 | _UpgradeReport_Files/
195 | Backup*/
196 | UpgradeLog*.XML
197 | UpgradeLog*.htm
198 |
199 | # SQL Server files
200 | *.mdf
201 | *.ldf
202 |
203 | # Business Intelligence projects
204 | *.rdl.data
205 | *.bim.layout
206 | *.bim_*.settings
207 |
208 | # Microsoft Fakes
209 | FakesAssemblies/
210 |
211 | # GhostDoc plugin setting file
212 | *.GhostDoc.xml
213 |
214 | # Node.js Tools for Visual Studio
215 | .ntvs_analysis.dat
216 |
217 | # Visual Studio 6 build log
218 | *.plg
219 |
220 | # Visual Studio 6 workspace options file
221 | *.opt
222 |
223 | # Visual Studio LightSwitch build output
224 | **/*.HTMLClient/GeneratedArtifacts
225 | **/*.DesktopClient/GeneratedArtifacts
226 | **/*.DesktopClient/ModelManifest.xml
227 | **/*.Server/GeneratedArtifacts
228 | **/*.Server/ModelManifest.xml
229 | _Pvt_Extensions
230 |
231 | # Paket dependency manager
232 | .paket/paket.exe
233 | paket-files/
234 |
235 | # FAKE - F# Make
236 | .fake/
237 |
238 | # JetBrains Rider
239 | .idea/
240 | *.sln.iml
241 |
242 | # =========================
243 | # Operating System Files
244 | # =========================
245 |
246 | # OSX
247 | # =========================
248 |
249 | .DS_Store
250 | .AppleDouble
251 | .LSOverride
252 |
253 | # Thumbnails
254 | ._*
255 |
256 | # Files that might appear in the root of a volume
257 | .DocumentRevisions-V100
258 | .fseventsd
259 | .Spotlight-V100
260 | .TemporaryItems
261 | .Trashes
262 | .VolumeIcon.icns
263 |
264 | # Directories potentially created on remote AFP share
265 | .AppleDB
266 | .AppleDesktop
267 | Network Trash Folder
268 | Temporary Items
269 | .apdisk
270 |
271 | # Windows
272 | # =========================
273 |
274 | # Windows image file caches
275 | Thumbs.db
276 | ehthumbs.db
277 |
278 | # Folder config file
279 | Desktop.ini
280 |
281 | # Recycle Bin used on file shares
282 | $RECYCLE.BIN/
283 |
284 | # Windows Installer files
285 | *.cab
286 | *.msi
287 | *.msm
288 | *.msp
289 |
290 | # Windows shortcuts
291 | *.lnk
292 |
--------------------------------------------------------------------------------
/CSEGui/CSEGui.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {DC16B661-FC33-417C-9A09-E65E0CD9DEAE}
8 | WinExe
9 | CSEGui
10 | CSEGui
11 | v4.0
12 | 512
13 |
14 |
15 | AnyCPU
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | AnyCPU
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | Form
48 |
49 |
50 | Form1.cs
51 |
52 |
53 |
54 |
55 | Form1.cs
56 |
57 |
58 | ResXFileCodeGenerator
59 | Resources.Designer.cs
60 | Designer
61 |
62 |
63 | True
64 | Resources.resx
65 |
66 |
67 | SettingsSingleFileGenerator
68 | Settings.Designer.cs
69 |
70 |
71 | True
72 | Settings.settings
73 | True
74 |
75 |
76 |
77 |
78 | {90de8acc-4e17-4aaa-8fef-33ebced1e35d}
79 | CatSceneEditor
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/CSEGui/Form1.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace CSEGui {
2 | partial class Form1 {
3 | ///
4 | /// Variável de designer necessária.
5 | ///
6 | private System.ComponentModel.IContainer components = null;
7 |
8 | ///
9 | /// Limpar os recursos que estão sendo usados.
10 | ///
11 | /// true se for necessário descartar os recursos gerenciados; caso contrário, false.
12 | protected override void Dispose(bool disposing) {
13 | if (disposing && (components != null)) {
14 | components.Dispose();
15 | }
16 | base.Dispose(disposing);
17 | }
18 |
19 | #region Código gerado pelo Windows Form Designer
20 |
21 | ///
22 | /// Método necessário para suporte ao Designer - não modifique
23 | /// o conteúdo deste método com o editor de código.
24 | ///
25 | private void InitializeComponent() {
26 | this.components = new System.ComponentModel.Container();
27 | this.listBox1 = new System.Windows.Forms.ListBox();
28 | this.textBox1 = new System.Windows.Forms.TextBox();
29 | this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
30 | this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
31 | this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
32 | this.packgetToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
33 | this.createToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
34 | this.extractToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
35 | this.debugToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
36 | this.escapeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
37 | this.contextMenuStrip1.SuspendLayout();
38 | this.SuspendLayout();
39 | //
40 | // listBox1
41 | //
42 | this.listBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
43 | | System.Windows.Forms.AnchorStyles.Left)
44 | | System.Windows.Forms.AnchorStyles.Right)));
45 | this.listBox1.FormattingEnabled = true;
46 | this.listBox1.Location = new System.Drawing.Point(9, 10);
47 | this.listBox1.Margin = new System.Windows.Forms.Padding(2);
48 | this.listBox1.Name = "listBox1";
49 | this.listBox1.Size = new System.Drawing.Size(464, 329);
50 | this.listBox1.TabIndex = 0;
51 | this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
52 | //
53 | // textBox1
54 | //
55 | this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
56 | | System.Windows.Forms.AnchorStyles.Right)));
57 | this.textBox1.Location = new System.Drawing.Point(9, 343);
58 | this.textBox1.Margin = new System.Windows.Forms.Padding(2);
59 | this.textBox1.Name = "textBox1";
60 | this.textBox1.Size = new System.Drawing.Size(464, 20);
61 | this.textBox1.TabIndex = 1;
62 | this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
63 | //
64 | // contextMenuStrip1
65 | //
66 | this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
67 | this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
68 | this.openToolStripMenuItem,
69 | this.saveToolStripMenuItem,
70 | this.packgetToolStripMenuItem,
71 | this.debugToolStripMenuItem});
72 | this.contextMenuStrip1.Name = "contextMenuStrip1";
73 | this.contextMenuStrip1.Size = new System.Drawing.Size(181, 114);
74 | //
75 | // openToolStripMenuItem
76 | //
77 | this.openToolStripMenuItem.Name = "openToolStripMenuItem";
78 | this.openToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
79 | this.openToolStripMenuItem.Text = "Open";
80 | this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
81 | //
82 | // saveToolStripMenuItem
83 | //
84 | this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
85 | this.saveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
86 | this.saveToolStripMenuItem.Text = "Save";
87 | this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
88 | //
89 | // packgetToolStripMenuItem
90 | //
91 | this.packgetToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
92 | this.createToolStripMenuItem,
93 | this.extractToolStripMenuItem});
94 | this.packgetToolStripMenuItem.Name = "packgetToolStripMenuItem";
95 | this.packgetToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
96 | this.packgetToolStripMenuItem.Text = "Packget";
97 | //
98 | // createToolStripMenuItem
99 | //
100 | this.createToolStripMenuItem.Name = "createToolStripMenuItem";
101 | this.createToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
102 | this.createToolStripMenuItem.Text = "Create";
103 | this.createToolStripMenuItem.Click += new System.EventHandler(this.createToolStripMenuItem_Click);
104 | //
105 | // extractToolStripMenuItem
106 | //
107 | this.extractToolStripMenuItem.Name = "extractToolStripMenuItem";
108 | this.extractToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
109 | this.extractToolStripMenuItem.Text = "Extract";
110 | this.extractToolStripMenuItem.Click += new System.EventHandler(this.extractToolStripMenuItem_Click);
111 | //
112 | // debugToolStripMenuItem
113 | //
114 | this.debugToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
115 | this.escapeToolStripMenuItem});
116 | this.debugToolStripMenuItem.Name = "debugToolStripMenuItem";
117 | this.debugToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
118 | this.debugToolStripMenuItem.Text = "Debug";
119 | //
120 | // escapeToolStripMenuItem
121 | //
122 | this.escapeToolStripMenuItem.Name = "escapeToolStripMenuItem";
123 | this.escapeToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
124 | this.escapeToolStripMenuItem.Text = "Escape";
125 | this.escapeToolStripMenuItem.Click += new System.EventHandler(this.escapeToolStripMenuItem_Click);
126 | //
127 | // Form1
128 | //
129 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
130 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
131 | this.ClientSize = new System.Drawing.Size(481, 370);
132 | this.ContextMenuStrip = this.contextMenuStrip1;
133 | this.Controls.Add(this.textBox1);
134 | this.Controls.Add(this.listBox1);
135 | this.Margin = new System.Windows.Forms.Padding(2);
136 | this.Name = "Form1";
137 | this.Text = "CSEGUI";
138 | this.contextMenuStrip1.ResumeLayout(false);
139 | this.ResumeLayout(false);
140 | this.PerformLayout();
141 |
142 | }
143 |
144 | #endregion
145 |
146 | private System.Windows.Forms.ListBox listBox1;
147 | private System.Windows.Forms.TextBox textBox1;
148 | private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
149 | private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem;
150 | private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem;
151 | private System.Windows.Forms.ToolStripMenuItem packgetToolStripMenuItem;
152 | private System.Windows.Forms.ToolStripMenuItem createToolStripMenuItem;
153 | private System.Windows.Forms.ToolStripMenuItem extractToolStripMenuItem;
154 | private System.Windows.Forms.ToolStripMenuItem debugToolStripMenuItem;
155 | private System.Windows.Forms.ToolStripMenuItem escapeToolStripMenuItem;
156 | }
157 | }
158 |
159 |
--------------------------------------------------------------------------------
/CSEGui/Form1.cs:
--------------------------------------------------------------------------------
1 | using CatSceneEditor;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.ComponentModel;
5 | using System.Data;
6 | using System.Drawing;
7 | using System.IO;
8 | using System.Linq;
9 | using System.Text;
10 | using System.Windows.Forms;
11 |
12 | namespace CSEGui {
13 | public partial class Form1 : Form {
14 | public Form1() {
15 | InitializeComponent();
16 | MessageBox.Show("This is a demo DLL GUI", "CSEGUI");
17 | }
18 |
19 | private void listBox1_SelectedIndexChanged(object sender, EventArgs e) {
20 | try {
21 | textBox1.Text = listBox1.Items[listBox1.SelectedIndex].ToString();
22 | }
23 | catch { }
24 | }
25 |
26 | private void textBox1_KeyPress(object sender, KeyPressEventArgs e) {
27 | if (e.KeyChar == '\n' || e.KeyChar == '\r') {
28 | try {
29 | listBox1.Items[listBox1.SelectedIndex] = textBox1.Text;
30 | }
31 | catch {
32 |
33 | }
34 | }
35 | }
36 |
37 | CSTHelper Editor;
38 | CSTLHelper Editor2;
39 | private bool CSTMode = true;
40 |
41 | private void openToolStripMenuItem_Click(object sender, EventArgs e) {
42 | OpenFileDialog fd = new OpenFileDialog();
43 | fd.Filter = "ALL CST Files|*.cst|All CSTL Files|*.cstl";
44 | if (fd.ShowDialog() != DialogResult.OK)
45 | return;
46 |
47 | byte[] Script = System.IO.File.ReadAllBytes(fd.FileName);
48 | CSTMode = fd.FilterIndex == 1;
49 |
50 | if (CSTMode) {
51 | Editor = new CSTHelper(Script, true, true);
52 |
53 | listBox1.Items.Clear();
54 | foreach (string str in Editor.Import())
55 | listBox1.Items.Add(str);
56 | } else {
57 | Editor2 = new CSTLHelper(Script);
58 |
59 | listBox1.Items.Clear();
60 | foreach (string str in Editor2.Import())
61 | listBox1.Items.Add(str);
62 | }
63 | }
64 |
65 | private void saveToolStripMenuItem_Click(object sender, EventArgs e) {
66 | SaveFileDialog fd = new SaveFileDialog();
67 | fd.Filter = "ALL CST Files|*.cst|All CSTL Files|*.cstl";
68 | fd.FilterIndex = (CSTMode ? 0 : 1);
69 | if (fd.ShowDialog() != DialogResult.OK)
70 | return;
71 |
72 | string[] Strings = new string[listBox1.Items.Count];
73 | listBox1.Items.CopyTo(Strings, 0);
74 |
75 | System.IO.File.WriteAllBytes(fd.FileName, CSTMode ? Editor.Export(Strings) : Editor2.Export(Strings));
76 | MessageBox.Show("File Saved", "CSEGui", MessageBoxButtons.OK, MessageBoxIcon.Information);
77 | }
78 |
79 | private void createToolStripMenuItem_Click(object sender, EventArgs e) {
80 | FolderBrowserDialog fb = new FolderBrowserDialog();
81 | fb.Description = "Select folder with directories or files to repack";
82 | if (fb.ShowDialog() != DialogResult.OK)
83 | return;
84 | if (!fb.SelectedPath.EndsWith("\\"))
85 | fb.SelectedPath += '\\';
86 | bool SubDirMode = Directory.GetDirectories(fb.SelectedPath).Length > 0;
87 | if (SubDirMode) {
88 | foreach (string dir in Directory.GetDirectories(fb.SelectedPath))
89 | PackDir(dir);
90 | } else
91 | PackDir(fb.SelectedPath);
92 |
93 | MessageBox.Show("Repacked", "CSEGUI", MessageBoxButtons.OK, MessageBoxIcon.Information);
94 | }
95 |
96 | private void PackDir(string Dir) {
97 | if (!Dir.EndsWith("\\"))
98 | Dir += '\\';
99 | string OutPath = Dir.TrimEnd('\\', ' ', '~') + ".int";
100 |
101 | string[] Files = Directory.GetFiles(Dir, "*.*");
102 | FileEntry[] Entries = new FileEntry[Files.Length];
103 | for (uint i = 0; i < Files.Length; i++) {
104 | string FN = Path.GetFileName(Files[i]);
105 | Entries[i] = new FileEntry() {
106 | FileName = FN,
107 | Content = new StreamReader(Files[i]).BaseStream
108 | };
109 | }
110 |
111 | Stream Output = new StreamWriter(OutPath).BaseStream;
112 |
113 | Int.Repack(Output, Entries, true);
114 | }
115 |
116 | private void extractToolStripMenuItem_Click(object sender, EventArgs e) {
117 | OpenFileDialog fd = new OpenFileDialog();
118 | fd.Filter = "All Int Packgets|*.int";
119 | if (fd.ShowDialog() != DialogResult.OK)
120 | return;
121 |
122 | int i = 2;
123 | string OutDir = fd.FileName + "~\\";
124 | while (Directory.Exists(OutDir))
125 | OutDir = fd.FileName + string.Format("~{0}\\", i++);
126 | Directory.CreateDirectory(OutDir);
127 |
128 | Stream Reader = new StreamReader(fd.FileName).BaseStream;
129 | FileEntry[] Entries = Int.Open(Reader);
130 |
131 | foreach (FileEntry Entry in Entries) {
132 | Stream Output = new StreamWriter(OutDir + Entry.FileName).BaseStream;
133 | CopyStream(Entry.Content, Output);
134 | Entry.Content.Close();
135 | Output.Close();
136 | }
137 |
138 | Reader.Close();
139 | }
140 |
141 | private void CopyStream(Stream Input, Stream Output) {
142 | int Readed = 0;
143 | byte[] Buffer = new byte[1024];
144 | do {
145 | Readed = Input.Read(Buffer, 0, Buffer.Length);
146 | Output.Write(Buffer, 0, Readed);
147 | } while (Readed > 0);
148 | }
149 |
150 | private void escapeToolStripMenuItem_Click(object sender, EventArgs e) {
151 | OpenFileDialog fd = new OpenFileDialog();
152 | fd.Multiselect = true;
153 | if (fd.ShowDialog() != DialogResult.OK)
154 | return;
155 |
156 | foreach (string file in fd.FileNames) {
157 | byte[] Scr = File.ReadAllBytes(file);
158 | var Editor = new CSTHelper(Scr);
159 | string[] Dialogues = Editor.Import();
160 |
161 | }
162 | }
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/CSEGui/Form1.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | 17, 17
122 |
123 |
--------------------------------------------------------------------------------
/CSEGui/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Windows.Forms;
5 |
6 | namespace CSEGui {
7 | static class Program {
8 | ///
9 | /// Ponto de entrada principal para o aplicativo.
10 | ///
11 | [STAThread]
12 | static void Main() {
13 | Application.EnableVisualStyles();
14 | Application.SetCompatibleTextRenderingDefault(false);
15 | Application.Run(new Form1());
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/CSEGui/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // As informações gerais sobre um assembly são controladas por
6 | // conjunto de atributos. Altere estes valores de atributo para modificar as informações
7 | // associada a um assembly.
8 | [assembly: AssemblyTitle("CSEGui")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("CSEGui")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Definir ComVisible como false torna os tipos neste assembly invisíveis
18 | // para componentes COM. Caso precise acessar um tipo neste assembly de
19 | // COM, defina o atributo ComVisible como true nesse tipo.
20 | [assembly: ComVisible(false)]
21 |
22 | // O GUID a seguir será destinado à ID de typelib se este projeto for exposto para COM
23 | [assembly: Guid("dc16b661-fc33-417c-9a09-e65e0cd9deae")]
24 |
25 | // As informações da versão de um assembly consistem nos quatro valores a seguir:
26 | //
27 | // Versão Principal
28 | // Versão Secundária
29 | // Número da Versão
30 | // Revisão
31 | //
32 | // É possível especificar todos os valores ou usar como padrão os Números de Build e da Revisão
33 | // utilizando o "*" como mostrado abaixo:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/CSEGui/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // Este código foi gerado por uma ferramenta.
4 | // Versão de Tempo de Execução: 4.0.30319.42000
5 | //
6 | // As alterações ao arquivo poderão causar comportamento incorreto e serão perdidas se
7 | // o código for recriado
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace CSEGui.Properties {
12 |
13 |
14 | ///
15 | /// Uma classe de recurso fortemente tipados, para pesquisar cadeias de caracteres localizadas etc.
16 | ///
17 | // Esta classe foi gerada automaticamente pela StronglyTypedResourceBuilder
18 | // classe através de uma ferramenta como ResGen ou Visual Studio.
19 | // Para adicionar ou remover um associado, edite o arquivo .ResX e execute ResGen novamente
20 | // com a opção /str ou reconstrua seu projeto VS.
21 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
22 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
23 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
24 | internal class Resources {
25 |
26 | private static global::System.Resources.ResourceManager resourceMan;
27 |
28 | private static global::System.Globalization.CultureInfo resourceCulture;
29 |
30 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
31 | internal Resources() {
32 | }
33 |
34 | ///
35 | /// Retorna a instância cacheada de ResourceManager utilizada por esta classe.
36 | ///
37 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
38 | internal static global::System.Resources.ResourceManager ResourceManager {
39 | get {
40 | if ((resourceMan == null)) {
41 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CSEGui.Properties.Resources", typeof(Resources).Assembly);
42 | resourceMan = temp;
43 | }
44 | return resourceMan;
45 | }
46 | }
47 |
48 | ///
49 | /// Substitui a propriedade CurrentUICulture do thread atual para todas
50 | /// as pesquisas de recursos que usam esta classe de recursos fortemente tipados.
51 | ///
52 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
53 | internal static global::System.Globalization.CultureInfo Culture {
54 | get {
55 | return resourceCulture;
56 | }
57 | set {
58 | resourceCulture = value;
59 | }
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/CSEGui/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/CSEGui/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace CSEGui.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/CSEGui/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/CatSceneEditor.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26430.6
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CatSceneEditor", "CatSceneEditor\CatSceneEditor.csproj", "{90DE8ACC-4E17-4AAA-8FEF-33EBCED1E35D}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSEGui", "CSEGui\CSEGui.csproj", "{DC16B661-FC33-417C-9A09-E65E0CD9DEAE}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CatSystemDebugger", "CatSystemDebugger\CatSystemDebugger.csproj", "{51F0BF29-7EFD-45A1-A794-3C0CA7BF0BA4}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {90DE8ACC-4E17-4AAA-8FEF-33EBCED1E35D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {90DE8ACC-4E17-4AAA-8FEF-33EBCED1E35D}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {90DE8ACC-4E17-4AAA-8FEF-33EBCED1E35D}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {90DE8ACC-4E17-4AAA-8FEF-33EBCED1E35D}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {DC16B661-FC33-417C-9A09-E65E0CD9DEAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {DC16B661-FC33-417C-9A09-E65E0CD9DEAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {DC16B661-FC33-417C-9A09-E65E0CD9DEAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {DC16B661-FC33-417C-9A09-E65E0CD9DEAE}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {51F0BF29-7EFD-45A1-A794-3C0CA7BF0BA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {51F0BF29-7EFD-45A1-A794-3C0CA7BF0BA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {51F0BF29-7EFD-45A1-A794-3C0CA7BF0BA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {51F0BF29-7EFD-45A1-A794-3C0CA7BF0BA4}.Release|Any CPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | EndGlobal
35 |
--------------------------------------------------------------------------------
/CatSceneEditor/Algo.cs:
--------------------------------------------------------------------------------
1 | using ComponentAce;
2 | using System.IO;
3 |
4 | namespace CatSceneEditor {
5 | internal static class Algo {
6 | internal static void CompressData(byte[] inData, out byte[] outData, int CompressLevel = 9) {
7 | using (MemoryStream outMemoryStream = new MemoryStream())
8 | using (ZOutputStream outZStream = new ZOutputStream(outMemoryStream, CompressLevel))
9 | using (Stream inMemoryStream = new MemoryStream(inData)) {
10 | CopyStream(inMemoryStream, outZStream);
11 | outZStream.Finish();
12 | outData = outMemoryStream.ToArray();
13 | }
14 | }
15 | internal static void CompressData(Stream inData, Stream outData, int CompressLevel = 9) {
16 | MemoryStream tmp = new MemoryStream();
17 | ZOutputStream outZStream = new ZOutputStream(tmp, CompressLevel);
18 | CopyStream(inData, outZStream);
19 | outZStream.Finish();
20 | tmp.Position = 0;
21 | CopyStream(tmp, outData);
22 | outZStream.Close();
23 | tmp.Close();
24 | }
25 | internal static void CopyStream(Stream input, Stream output, long Length = -1) {
26 | long Readed = 0;
27 | byte[] Buffer = new byte[2000];
28 | if (Length == -1) {
29 | while ((Readed = input.Read(Buffer, 0, Buffer.Length)) > 0)
30 | output.Write(Buffer, 0, (int)Readed);
31 |
32 | } else {
33 | do {
34 | Buffer = new byte[Readed + 2000 > Length ? Length - Readed : 2000];
35 | Readed += input.Read(Buffer, 0, Buffer.Length);
36 | output.Write(Buffer, 0, Buffer.Length);
37 | } while (Readed < Length);
38 | }
39 | output.Flush();
40 | }
41 | internal static void DecompressData(byte[] inData, out byte[] outData) {
42 | try {
43 | using (Stream inMemoryStream = new MemoryStream(inData))
44 | using (ZInputStream outZStream = new ZInputStream(inMemoryStream)) {
45 | MemoryStream outMemoryStream = new MemoryStream();
46 | CopyStream(outZStream, outMemoryStream);
47 | outData = outMemoryStream.ToArray();
48 | }
49 | }
50 | catch {
51 | outData = new byte[0];
52 | }
53 | }
54 | internal static void DecompressData(Stream Input, Stream Output) {
55 | using (ZInputStream outZStream = new ZInputStream(Input)) {
56 | CopyStream(outZStream, Output);
57 | }
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/CatSceneEditor/CSTHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace CatSceneEditor {
6 | public class CSTHelper {
7 |
8 | CatScene Editor;
9 | bool Wordwrap = true;
10 | bool Decode = true;
11 |
12 | public CSTHelper(byte[] Script, bool Wordwrap, bool Decode) {
13 | Editor = new CatScene(Script);
14 | this.Wordwrap = Wordwrap;
15 | this.Decode = Decode;
16 | }
17 |
18 | public CSTHelper(byte[] Script) { Editor = new CatScene(Script); }
19 |
20 | StringEntry[] Entries;
21 |
22 | private Dictionary Prefix;
23 | private Dictionary Sufix;
24 | private Dictionary Prefix2;
25 | private Dictionary Sufix2;
26 |
27 | private const string FN = "\\fn";
28 |
29 | public string[] Import() {
30 | Prefix = new Dictionary();
31 | Sufix = new Dictionary();
32 | Prefix2 = new Dictionary();
33 | Sufix2 = new Dictionary();
34 | Entries = Editor.Import();
35 | string[] Strings = (from e in Entries where e.Type == 8193 || e.Type == 8449 select e.Content).ToArray();
36 | bool InChoice = false;
37 | foreach (var Entry in Entries) {
38 | if (Entry.Type != 12289)
39 | continue;
40 | if (Entry.Content.StartsWith("fselect")) {
41 | InChoice = true;
42 | continue;
43 | }
44 | if (!InChoice)
45 | continue;
46 |
47 | string[] Parts = SplitChoice(Entry.Content);
48 | if (Parts == null || Parts.Length != 3) {
49 | InChoice = false;
50 | continue;
51 | }
52 |
53 | if (!int.TryParse(Parts.First().Split(' ').First(), out int tmp)) {
54 | InChoice = false;
55 | continue;
56 | }
57 | Strings = Strings.Concat(new string[] { Parts[1] }).ToArray();
58 | }
59 |
60 | if (Wordwrap) {
61 | for (uint i = 0; i < Strings.LongLength; i++) {
62 | string String = Strings[i];
63 | CutString(ref String, i, false);
64 | FakeDecode(ref String, true);
65 | String = WordwrapUnescape(String);
66 | CutString(ref String, i, true);
67 | Strings[i] = String;
68 | }
69 | }
70 |
71 | return Strings;
72 | }
73 |
74 | public string[] SplitChoice(string Line) {
75 | var Parts = Line.Split(' ');
76 | if (Parts.Length < 3)
77 | return null;
78 |
79 | string Prefix = string.Join(" ", Parts.Take(2)) + " ";
80 | string Text = string.Join(" ", Parts.Skip(2));
81 | if (Text.Contains(" ") && !(Text.StartsWith("(:") && Text.EndsWith(")")))
82 | return null;
83 |
84 | var FinalText = Text.TrimStart('(', ':').TrimEnd(')');
85 | var Sufix = "";
86 |
87 | if (Text.StartsWith("(:"))
88 | Prefix += "(:";
89 |
90 | if (Text.EndsWith(")"))
91 | Sufix += ")";
92 |
93 | return new string[] { Prefix, FinalText, Sufix};
94 | }
95 |
96 | public byte[] Export(string[] Strings) {
97 | bool InChoice = false;
98 | uint x = 0;
99 | for (uint i = 0; i < Entries.LongLength; i++) {
100 | if (Entries[i].Type == 8193 || Entries[i].Type == 8449) {
101 | string String = Prefix[x] + Strings[x].Trim() + Sufix[x];
102 | if (Wordwrap && String.Contains(" ") && Entries[i].Type != 8449) {
103 | String = WordwrapEscape(String);
104 | }
105 | FakeDecode(ref String, false);
106 | Entries[i].Content = Prefix2[x] + String + Sufix2[x];
107 | x++;
108 | }
109 | }
110 | for (uint i = 0; i < Entries.LongLength; i++) {
111 | if (Entries[i].Type == 12289) {
112 | if (Entries[i].Content.StartsWith("fselect")){
113 | InChoice = true;
114 | continue;
115 | }
116 | if (!InChoice)
117 | continue;
118 | string[] Parts = SplitChoice(Entries[i].Content);
119 | if (Parts == null || Parts.Length != 3) {
120 | InChoice = false;
121 | continue;
122 | }
123 | if (!int.TryParse(Parts.First().Split(' ').First(), out int tmp)) {
124 | InChoice = false;
125 | continue;
126 | }
127 | Entries[i].Content = Parts[0] + Strings[x++] + Parts[2];
128 | }
129 | }
130 |
131 | return Editor.Export(Entries);
132 | }
133 | private string WordwrapUnescape(string String) {
134 | String = String.Replace("[", "");
135 | String = String.Replace("]", "");
136 | return String;
137 | }
138 | private string WordwrapEscape(string String) {
139 | string[] Words = String.Split(' ');
140 | String = string.Empty;
141 | for (int z = 0; z < Words.Length; z++) {
142 | string Word = Words[z];
143 | if (z == 0) {
144 | String += Word + ' ';
145 | continue;
146 | }
147 | if (Word.Contains("\\n")) {
148 | string tmp = Word.Replace("\\n", "\n");
149 | foreach (string str in tmp.Split('\n'))
150 | String += string.Format("[{0}]\\n", str);
151 | String = String.Substring(0, String.Length - 1);
152 | String += ' ';
153 | } else if (Word.Contains(":")) {
154 | string[] Split = Word.Split(':');
155 | String += string.Format("[{0}]:", Split[0]);
156 | for (int a = 1; a < Split.Length; a++) {
157 | String += Split[a] + ':';
158 | }
159 | String = String.Substring(0, String.Length - 1);
160 | String += ' ';
161 | } else
162 | String += string.Format("[{0}] ", Word);
163 | }
164 | String = String.Substring(0, String.Length - 1);
165 | return String;
166 | }
167 |
168 | //\fnThe [interval] [between] [classes,] [or] ["recess,"] [is] [fundamentally] [a] [time] [for] [lazing] [around.]\fn
169 |
170 | private void FakeDecode(ref string Line, bool Decode) {
171 | if (!Decode)
172 | return;
173 |
174 | string[] Source = new string[] { "\\'", "\\\"", "\\n", "\\_" };
175 | string[] Target = new string[] { "'", "\"", "\n", " " };
176 |
177 | for (int i = 0; i < Source.Length; i++) {
178 | Line = Line.Replace(Decode ? Source[i]: Target[i], !Decode ? Source[i] : Target[i]);
179 | }
180 | }
181 |
182 | List Prefixs = new List(new string[] { "\\n", "\\@", "\\r", "\\pc", "\\pl", "\\pr", "\\wf", "\\w", "\\fr", "\\fnl","\\fss", "\\fnn", "\\fll", "\\fn", "\\ti", "\\f", " ", "-", " " });
183 | private void CutString(ref string String, uint ID, bool Cutted) {
184 | string Prefix = string.Empty;
185 | while (GetPrefix(String) != null) {
186 | string Rst = GetPrefix(String);
187 | Prefix += String.Substring(0, Rst.Length);
188 | String = String.Substring(Rst.Length, String.Length - Rst.Length);
189 | }
190 |
191 | if (Cutted)
192 | this.Prefix[ID] = Prefix;
193 | else
194 | Prefix2[ID] = Prefix;
195 |
196 | string Sufix = string.Empty;
197 | while (GetSufix(String) != null) {
198 | string Rst = GetSufix(String);
199 | Sufix = String.Substring(String.Length - Rst.Length, Rst.Length) + Sufix;
200 | String = String.Substring(0, String.Length - Rst.Length);
201 | }
202 |
203 | if (Cutted)
204 | this.Sufix[ID] = Sufix;
205 | else
206 | Sufix2[ID] = Sufix;
207 | }
208 |
209 | private string GetPrefix(string String) {
210 | foreach (string str in Prefixs)
211 | if (String.StartsWith(str + ';'))
212 | return str + ';';
213 | else if (String.StartsWith(str))
214 | return str;
215 | return null;
216 | }
217 | private string GetSufix(string String) {
218 | foreach (string str in Prefixs)
219 | if (String.ToLower().EndsWith(str))
220 | return str;
221 | return null;
222 | }
223 |
224 | }
225 | }
226 |
--------------------------------------------------------------------------------
/CatSceneEditor/CSTL.cs:
--------------------------------------------------------------------------------
1 | using AdvancedBinary;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Text;
6 |
7 | namespace CatSceneEditor {
8 | public class CSTL {
9 | byte[] Script;
10 |
11 | public CSTL(byte[] Script) { this.Script = Script; }
12 |
13 | public string[] Langs { get; private set; }
14 |
15 | CSTLHeader Header = new CSTLHeader();
16 | public string[] Import() {
17 | StructReader Reader = new StructReader(new MemoryStream(Script), false, Encoding.UTF8);
18 | Reader.ReadStruct(ref Header);
19 | if (Header.Signature != "CSTL")
20 | throw new Exception("Invalid Format");
21 |
22 | Langs = new string[ReadNum(Reader)];
23 | for (long i = 0; i < Langs.Length; i++)
24 | Langs[i] = ReadString(Reader);
25 |
26 | long Count = (ReadNum(Reader) * 2) * Langs.Length;
27 | string[] Strings = new string[Count];
28 | for (long i = 0; i < Count; i++) {
29 | Strings[i] = ReadString(Reader);
30 | }
31 |
32 | Reader.Close();
33 | return Strings;
34 | }
35 |
36 | public byte[] Export(string[] Content) {
37 | MemoryStream Output = new MemoryStream();
38 | StructWriter Writer = new StructWriter(Output, false, Encoding.UTF8);
39 | Writer.WriteStruct(ref Header);
40 |
41 | WriteNum(Writer, Langs.Length);
42 | foreach (string Lang in Langs)
43 | WriteString(Writer, Lang);
44 |
45 | WriteNum(Writer, (Content.Length/2)/Langs.Length);
46 | foreach (string str in Content)
47 | WriteString(Writer, str);
48 |
49 | byte[] Result = Output.ToArray();
50 | Writer.Close();
51 | return Result;
52 | }
53 |
54 | private void WriteString(StructWriter Stream, string Content) {
55 | byte[] Buffer = Encoding.UTF8.GetBytes(Content);
56 | WriteNum(Stream, Buffer.LongLength);
57 |
58 | Stream.Write(Buffer, 0, Buffer.Length);
59 | }
60 |
61 | private void WriteNum(StructWriter Stream, long Value) {
62 | List Rst = new List();
63 | Rst.Add(0x00);
64 | while (Value-- > 0) {
65 | if (Rst[Rst.Count - 1] == 0xFF)
66 | Rst.Add(0x00);
67 | Rst[Rst.Count - 1]++;
68 | }
69 |
70 | if (Rst[Rst.Count - 1] == 0xFF)
71 | Rst.Add(0x00);
72 |
73 | byte[] Buffer = Rst.ToArray();
74 |
75 | Stream.Write(Buffer, 0, Buffer.Length);
76 | }
77 | private long ReadNum(StructReader Stream) {
78 | long Value = 0;
79 | while (Stream.Peek() == 0xFF)
80 | Value += Stream.ReadByte();
81 | Value += Stream.ReadByte();
82 |
83 | return Value;
84 | }
85 | private string ReadString(StructReader Stream) {
86 | byte[] Buffer = new byte[ReadNum(Stream)];
87 | Stream.Read(Buffer, 0, Buffer.Length);
88 |
89 | return Encoding.UTF8.GetString(Buffer);
90 | }
91 |
92 | struct CSTLHeader {
93 | [FString(Length = 4)]
94 | public string Signature;
95 | uint Unk;
96 | }
97 | struct StringEntry {
98 | [PString(PrefixType = Const.UINT8)]
99 | public string Content;
100 | }
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/CatSceneEditor/CSTLHelper.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace CatSceneEditor {
4 | public class CSTLHelper {
5 | CSTL Editor;
6 | string Lang = string.Empty;
7 | int LangID;
8 | public CSTLHelper(byte[] Script, string Lang) {
9 | Editor = new CSTL(Script);
10 | this.Lang = Lang;
11 | }
12 | string[] Strings;
13 | public CSTLHelper(byte[] Script) {
14 | Editor = new CSTL(Script);
15 | Lang = "en";
16 | }
17 |
18 | Dictionary StrMap = new Dictionary();
19 |
20 | public string[] Import() {
21 | StrMap = new Dictionary();
22 | Strings = Editor.Import();
23 | for (int i = 0; i < Editor.Langs.Length; i++) {
24 | if (Editor.Langs[i] == Lang) {
25 | LangID = i;
26 | break;
27 | }
28 | }
29 | List Result = new List();
30 | for (int i = 0; i < Strings.LongLength; i++) {
31 | bool IsTarget = ((i / 2) % Editor.Langs.Length) == LangID;
32 | if (IsTarget) {
33 | StrMap[Result.Count] = i;
34 | Result.Add(Strings[i]);
35 | }
36 | }
37 |
38 | return Result.ToArray();
39 | }
40 |
41 | public byte[] Export(string[] Content) {
42 | for (int i = 0; i < Content.Length; i++)
43 | Strings[StrMap[i]] = Content[i];
44 |
45 | return Editor.Export(Strings);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/CatSceneEditor/CatSceneEditor.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {90DE8ACC-4E17-4AAA-8FEF-33EBCED1E35D}
8 | Library
9 | Properties
10 | CatSceneEditor
11 | CatSceneEditor
12 | v4.0
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\
28 | TRACE
29 | prompt
30 | 4
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/CatSceneEditor/Int.cs:
--------------------------------------------------------------------------------
1 | using AdvancedBinary;
2 | using NPCSManager;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Linq;
7 | using System.Text;
8 |
9 | namespace CatSceneEditor {
10 | public static class Int {
11 |
12 | public static FileEntry[] Open(Stream Input) {
13 | StructReader Reader = new StructReader(Input, false, Encoding.GetEncoding(932));
14 | IntHeader Header = new IntHeader();
15 | Reader.ReadStruct(ref Header);
16 | if (Header.Signature != "KIF\x0")
17 | throw new Exception("Invalid Packget");
18 |
19 | FileEntry[] Entries = new FileEntry[Header.FileCount];
20 | for (uint i = 0; i < Entries.Length; i++) {
21 | FileEntry Entry = new FileEntry();
22 | Reader.ReadStruct(ref Entry);
23 | Entry.Content = new VirtStream(Input, Entry.Postion, Entry.Length);
24 | Entry.FileName = Entry.FileName.TrimEnd('\x0');
25 | if (Entry.FileName == "__key__.dat")
26 | throw new Exception("Encrypted Packget Not Supported.");
27 | Entries[i] = Entry;
28 | }
29 |
30 | return Entries;
31 | }
32 |
33 | public static void Repack(Stream Output, FileEntry[] Files, bool CloseStreams = true) {
34 | StructWriter Writer = new StructWriter(Output, false, Encoding.GetEncoding(932));
35 | IntHeader Header = new IntHeader() {
36 | Signature = "KIF\x0",
37 | FileCount = (uint)Files.LongLength
38 | };
39 |
40 | Writer.WriteStruct(ref Header);
41 |
42 | uint Len = 0;
43 | for (uint i = 0; i < Files.Length; i++) {
44 | FileEntry Entry = new FileEntry() {
45 | FileName = Files[i].FileName,
46 | Postion = (0x48 * (uint)Files.LongLength) + 0x8 + Len,
47 | Length = (uint)Files[i].Content.Length
48 | };
49 | Writer.WriteStruct(ref Entry);
50 | Len += Entry.Length;
51 | }
52 |
53 | for (uint i = 0; i < Files.Length; i++) {
54 | Tools.CopyStream(Files[i].Content, Writer.BaseStream);
55 | if (CloseStreams)
56 | Files[i].Content.Close();
57 | }
58 |
59 | if (CloseStreams)
60 | Output.Close();
61 | }
62 | }
63 |
64 | struct IntHeader {//0x8 of len
65 | [FString(Length = 0x4)]
66 | public string Signature;
67 | public uint FileCount;
68 | }
69 | public struct FileEntry {//0x48 of len
70 | [FString(Length = 0x40)]
71 | public string FileName;
72 | internal uint Postion;
73 | internal uint Length;
74 |
75 | [Ignore]
76 | public Stream Content;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/CatSceneEditor/Main.cs:
--------------------------------------------------------------------------------
1 | using AdvancedBinary;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Diagnostics;
5 | using System.IO;
6 | using System.Linq;
7 | using System.Text;
8 |
9 | namespace CatSceneEditor
10 | {
11 | public class CatScene
12 | {
13 |
14 | ScriptHeader Header;
15 | byte[] Script;
16 | bool Decompressed = false;
17 |
18 | uint EntryCount { get { return (Header.StringTable - Header.OffsetTable)/4; } }
19 | uint HeaderLen { get { return (uint)Tools.GetStructLength(new ScriptHeader()); } }
20 |
21 | public Encoding Encoding = Encoding.GetEncoding(932);
22 |
23 | public CatScene(byte[] Script) { this.Script = Script; }
24 |
25 | public StringEntry[] Import() {
26 | if (!Decompressed)
27 | Decompress();
28 |
29 | Header = new ScriptHeader();
30 | StructReader Reader = new StructReader(new MemoryStream(Script), false, Encoding);
31 |
32 | Reader.ReadStruct(ref Header);
33 |
34 | if (Header.ScriptLength + 0x10 != Script.Length)
35 | throw new Exception("Corrupted Script");
36 |
37 | List Strings = new List();
38 | for (uint i = 0; i < EntryCount; i++) {
39 | Reader.Seek(Header.OffsetTable + HeaderLen + (i*4), SeekOrigin.Begin);
40 | uint Offset = Reader.ReadUInt32() + Header.StringTable + HeaderLen;
41 |
42 | Reader.Seek(Offset, SeekOrigin.Begin);
43 | StringEntry Entry = new StringEntry();
44 | Reader.ReadStruct(ref Entry);
45 | Strings.Add(Entry);
46 | }
47 |
48 | Reader.Close();
49 | return Strings.ToArray();
50 | }
51 |
52 | public byte[] Export(StringEntry[] Strings) {
53 | ScriptHeader NewHeader = new ScriptHeader();
54 | Tools.CopyStruct(Header, ref NewHeader);
55 |
56 | MemoryStream UnkData = new MemoryStream();
57 | MemoryStream OffsetData = new MemoryStream();
58 | MemoryStream StringData = new MemoryStream();
59 |
60 | MemoryStream Reader = new MemoryStream(Script);
61 | Reader.Seek(0x10, SeekOrigin.Begin);
62 |
63 | Algo.CopyStream(Reader, UnkData, NewHeader.UnkCount * 8);
64 | Reader.Close();
65 |
66 | StructWriter OffsetWriter = new StructWriter(OffsetData, false, Encoding);
67 | StructWriter StringWriter = new StructWriter(StringData, false, Encoding);
68 |
69 |
70 | for (uint i = 0; i < EntryCount; i++) {
71 | OffsetWriter.Write((uint)StringWriter.BaseStream.Length);
72 | StringWriter.WriteStruct(ref Strings[i]);
73 | }
74 | OffsetWriter.Seek(0, SeekOrigin.Begin);
75 | StringWriter.Seek(0, SeekOrigin.Begin);
76 |
77 | NewHeader.ScriptLength = (uint)(OffsetWriter.BaseStream.Length + StringWriter.BaseStream.Length + UnkData.Length);
78 | NewHeader.OffsetTable = (uint)UnkData.Length;
79 | NewHeader.StringTable = (uint)(UnkData.Length + OffsetData.Length);
80 |
81 | byte[] Output = new byte[0x10 + UnkData.Length + OffsetData.Length + StringData.Length];
82 |
83 | Tools.BuildStruct(ref NewHeader, false, Encoding).CopyTo(Output, 0);
84 |
85 | UnkData.ToArray().CopyTo(Output, 0x10);
86 | OffsetData.ToArray().CopyTo(Output, 0x10 + UnkData.Length);
87 | StringData.ToArray().CopyTo(Output, 0x10 + UnkData.Length + OffsetData.Length);
88 |
89 | UnkData.Close();
90 | StringWriter.Close();
91 | OffsetWriter.Close();
92 |
93 | return Compress(Output);
94 | }
95 |
96 | private byte[] Compress(byte[] Input) {
97 | byte[] Compressed;
98 | Algo.CompressData(Input, out Compressed);
99 | CatHeader Header = new CatHeader() {
100 | Singnature = "CatScene",
101 | CompressedSize = (uint)Compressed.LongLength,
102 | DecompressedSize = (uint)Input.LongLength
103 | };
104 |
105 | byte[] Output = new byte[0x10 + Header.CompressedSize];
106 | Tools.BuildStruct(ref Header, false, Encoding).CopyTo(Output, 0);
107 | Compressed.CopyTo(Output, 0x10);
108 |
109 | Input = new byte[0];
110 | Compressed = new byte[0];
111 |
112 | return Output;
113 | }
114 |
115 | private void Decompress() {
116 | CatHeader CompHeader = new CatHeader();
117 | StructReader Reader = new StructReader(new MemoryStream(Script), false, Encoding);
118 |
119 | Reader.ReadStruct(ref CompHeader);
120 |
121 | if (CompHeader.Singnature != "CatScene")
122 | throw new Exception("This isn't a valid CatSystem2 Script");
123 | MemoryStream Decompressed = new MemoryStream();
124 | Algo.DecompressData(Reader.BaseStream, Decompressed);
125 |
126 | if (CompHeader.DecompressedSize != Decompressed.Length)
127 | throw new Exception("Corrupted Script");
128 |
129 | Reader.Close();
130 | Script = Decompressed.ToArray();
131 | Decompressed.Close();
132 | this.Decompressed = true;
133 | }
134 | }
135 |
136 |
137 | #pragma warning disable 649
138 | struct CatHeader {
139 | [FString(Length = 8)]
140 | internal string Singnature;
141 | internal uint CompressedSize;
142 | internal uint DecompressedSize;
143 | }
144 |
145 | struct ScriptHeader {
146 | internal uint ScriptLength;
147 |
148 | //Bytecode? String map? Anyway, is the count of the first part of the script after the header...
149 | //every single entry 2 uint... in other words 1 entry = 8 bytes
150 | internal uint UnkCount;
151 |
152 | internal uint OffsetTable;
153 | internal uint StringTable;
154 | }
155 |
156 | [DebuggerDisplay("{Type}: {Content}")]
157 | public struct StringEntry {
158 | public ushort Type;
159 |
160 | [CString]
161 | public string Content;
162 | }
163 | #pragma warning restore 649
164 | }
165 |
--------------------------------------------------------------------------------
/CatSceneEditor/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // As informações gerais sobre um assembly são controladas por
6 | // conjunto de atributos. Altere estes valores de atributo para modificar as informações
7 | // associada a um assembly.
8 | [assembly: AssemblyTitle("CatSceneEditor")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("CatSceneEditor")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Definir ComVisible como false torna os tipos neste assembly invisíveis
18 | // para componentes COM. Caso precise acessar um tipo neste assembly de
19 | // COM, defina o atributo ComVisible como true nesse tipo.
20 | [assembly: ComVisible(false)]
21 |
22 | // O GUID a seguir será destinado à ID de typelib se este projeto for exposto para COM
23 | [assembly: Guid("90de8acc-4e17-4aaa-8fef-33ebced1e35d")]
24 |
25 | // As informações da versão de um assembly consistem nos quatro valores a seguir:
26 | //
27 | // Versão Principal
28 | // Versão Secundária
29 | // Número da Versão
30 | // Revisão
31 | //
32 | // É possível especificar todos os valores ou usar como padrão os Números de Build e da Revisão
33 | // usando o '*' como mostrado abaixo:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/CatSceneEditor/VirtStream.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Text;
5 |
6 | namespace NPCSManager {
7 |
8 | public struct File {
9 | public string Path;
10 | public Stream Content;
11 | }
12 | public class VirtStream : Stream {
13 | private Stream Packget;
14 | private long FilePos = 0;
15 | private long Len;
16 |
17 | internal VirtStream(Stream Packget, long Pos, long Len) {
18 | this.Packget = Packget;
19 | FilePos = Pos;
20 | this.Len = Len;
21 | }
22 | public override bool CanRead {
23 | get {
24 | return true;
25 | }
26 | }
27 |
28 | public override bool CanSeek {
29 | get {
30 | return false;
31 | }
32 | }
33 |
34 | public override bool CanWrite {
35 | get {
36 | return false;
37 | }
38 | }
39 | public override long Length {
40 | get {
41 | return Len;
42 | }
43 | }
44 |
45 | internal long Pos = 0;
46 | public override long Position {
47 | get {
48 | return Pos;
49 | }
50 | set {
51 | Seek(value, SeekOrigin.Begin);
52 | }
53 | }
54 |
55 | public override void Flush() {
56 | throw new NotImplementedException();
57 | }
58 |
59 | public override int Read(byte[] buffer, int offset, int count) {
60 | long ReadPos = FilePos + Pos;
61 | if (ReadPos != Packget.Position)
62 | Packget.Position = ReadPos;
63 |
64 | if (Pos + count > Length)
65 | count = (int)(Length - Pos);
66 |
67 | int Readed = Packget.Read(buffer, offset, count);
68 | Pos += Readed;
69 | return Readed;
70 | }
71 |
72 | ///
73 | /// Seek the file another location
74 | ///
75 | /// Value to change the pointer location
76 | /// Change from
77 | /// New Position
78 | public override long Seek(long offset, SeekOrigin origin) {
79 | if (offset < 0 || offset > Length)
80 | throw new Exception("Invalid Position");
81 | switch (origin) {
82 | case SeekOrigin.Begin:
83 | Packget.Position = FilePos + offset;
84 | this.Pos = offset;
85 | break;
86 | case SeekOrigin.Current:
87 | if (Position + offset > Length)
88 | throw new Exception("Out of Range");
89 | Packget.Position += offset;
90 | this.Pos += offset;
91 | break;
92 | case SeekOrigin.End:
93 | long Pos = Length - offset;
94 | this.Pos = Pos;
95 | long FP = FilePos + Pos;
96 | if (Pos < 0)
97 | throw new Exception("Out of Range");
98 | Packget.Position = FP;
99 | break;
100 | }
101 | return Pos;
102 | }
103 |
104 | public override void SetLength(long value) {
105 | throw new NotImplementedException();
106 | }
107 |
108 | public override void Write(byte[] buffer, int offset, int count) {
109 | throw new NotImplementedException();
110 | }
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/CatSceneEditor/Zlib/Adler32.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2006, ComponentAce
2 | // http://www.componentace.com
3 | // All rights reserved.
4 |
5 | // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6 |
7 | // Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 | // Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 | // Neither the name of ComponentAce nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11 |
12 |
13 |
14 | /*
15 | Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
16 |
17 | Redistribution and use in source and binary forms, with or without
18 | modification, are permitted provided that the following conditions are met:
19 |
20 | 1. Redistributions of source code must retain the above copyright notice,
21 | this list of conditions and the following disclaimer.
22 |
23 | 2. Redistributions in binary form must reproduce the above copyright
24 | notice, this list of conditions and the following disclaimer in
25 | the documentation and/or other materials provided with the distribution.
26 |
27 | 3. The names of the authors may not be used to endorse or promote products
28 | derived from this software without specific prior written permission.
29 |
30 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
31 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
32 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
33 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
34 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
36 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
39 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 | */
41 | /*
42 | * This program is based on zlib-1.1.3, so all credit should go authors
43 | * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
44 | * and contributors of zlib.
45 | */
46 |
47 | using System;
48 |
49 | namespace ComponentAce
50 | {
51 |
52 | ///
53 | /// This class represents adler32 checksum algorithm
54 | ///
55 | internal class Adler32
56 | {
57 |
58 | // largest prime smaller than 65536
59 | private const int BASE = 65521;
60 | // NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
61 | private const int NMAX = 5552;
62 |
63 | ///
64 | /// This static method returns adler32 checksum of the buffer data
65 | ///
66 | internal static long GetAdler32Checksum(long adler, byte[] buf, int index, int len)
67 | {
68 | if (buf == null)
69 | {
70 | return 1L;
71 | }
72 |
73 | long s1 = adler & 0xffff;
74 | long s2 = (adler >> 16) & 0xffff;
75 | int k;
76 |
77 | while (len > 0)
78 | {
79 | k = len < NMAX?len:NMAX;
80 | len -= k;
81 | while (k >= 16)
82 | {
83 | s1 += (buf[index++] & 0xff); s2 += s1;
84 | s1 += (buf[index++] & 0xff); s2 += s1;
85 | s1 += (buf[index++] & 0xff); s2 += s1;
86 | s1 += (buf[index++] & 0xff); s2 += s1;
87 | s1 += (buf[index++] & 0xff); s2 += s1;
88 | s1 += (buf[index++] & 0xff); s2 += s1;
89 | s1 += (buf[index++] & 0xff); s2 += s1;
90 | s1 += (buf[index++] & 0xff); s2 += s1;
91 | s1 += (buf[index++] & 0xff); s2 += s1;
92 | s1 += (buf[index++] & 0xff); s2 += s1;
93 | s1 += (buf[index++] & 0xff); s2 += s1;
94 | s1 += (buf[index++] & 0xff); s2 += s1;
95 | s1 += (buf[index++] & 0xff); s2 += s1;
96 | s1 += (buf[index++] & 0xff); s2 += s1;
97 | s1 += (buf[index++] & 0xff); s2 += s1;
98 | s1 += (buf[index++] & 0xff); s2 += s1;
99 | k -= 16;
100 | }
101 | if (k != 0)
102 | {
103 | do
104 | {
105 | s1 += (buf[index++] & 0xff); s2 += s1;
106 | }
107 | while (--k != 0);
108 | }
109 | s1 %= BASE;
110 | s2 %= BASE;
111 | }
112 | return (s2 << 16) | s1;
113 | }
114 |
115 | }
116 | }
--------------------------------------------------------------------------------
/CatSceneEditor/Zlib/InfTree.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2006, ComponentAce
2 | // http://www.componentace.com
3 | // All rights reserved.
4 |
5 | // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6 |
7 | // Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 | // Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 | // Neither the name of ComponentAce nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11 |
12 | /*
13 | Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
14 |
15 | Redistribution and use in source and binary forms, with or without
16 | modification, are permitted provided that the following conditions are met:
17 |
18 | 1. Redistributions of source code must retain the above copyright notice,
19 | this list of conditions and the following disclaimer.
20 |
21 | 2. Redistributions in binary form must reproduce the above copyright
22 | notice, this list of conditions and the following disclaimer in
23 | the documentation and/or other materials provided with the distribution.
24 |
25 | 3. The names of the authors may not be used to endorse or promote products
26 | derived from this software without specific prior written permission.
27 |
28 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
29 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
30 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
31 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
32 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
34 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
37 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 | */
39 | /*
40 | * This program is based on zlib-1.1.3, so all credit should go authors
41 | * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
42 | * and contributors of zlib.
43 | */
44 | using System;
45 |
46 | namespace ComponentAce
47 | {
48 | ///
49 | /// Contains utility information for the InfTree class
50 | ///
51 | internal class InfTreeUtil
52 | {
53 | internal const int MANY = 1440;
54 |
55 | internal const int fixed_bl = 9;
56 | internal const int fixed_bd = 5;
57 |
58 |
59 | internal static readonly int[] fixed_tl = new int[]{96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9, 192, 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 160, 0, 8, 0, 0, 8, 128, 0, 8, 64, 0, 9, 224, 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 144, 83, 7, 59, 0, 8, 120, 0, 8, 56, 0, 9, 208, 81, 7, 17, 0, 8, 104, 0, 8, 40, 0, 9, 176, 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 240, 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8, 227, 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 200, 81, 7, 13, 0, 8, 100, 0, 8, 36, 0, 9, 168, 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 232, 80, 7, 8, 0, 8, 92, 0, 8, 28, 0, 9, 152, 84, 7, 83, 0, 8, 124, 0, 8, 60, 0, 9, 216, 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 184, 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9, 248, 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163, 83, 7, 35, 0, 8, 114, 0, 8, 50, 0, 9, 196, 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 164, 0, 8, 2, 0, 8, 130, 0, 8, 66, 0, 9, 228, 80, 7, 7, 0, 8, 90, 0, 8, 26, 0, 9, 148, 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 212, 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9, 180, 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 244, 80, 7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 204, 81, 7, 15, 0, 8, 102, 0, 8, 38, 0, 9, 172, 0, 8, 6, 0, 8, 134, 0, 8, 70, 0, 9, 236, 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 156, 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9, 220, 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 188, 0, 8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 252, 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 82, 7, 31, 0, 8, 113, 0, 8, 49, 0, 9, 194, 80, 7, 10, 0, 8, 97, 0, 8, 33, 0, 9, 162, 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 226, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9, 146, 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 210, 81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 178, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 242, 80, 7, 4, 0, 8, 85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0, 8, 117, 0, 8, 53, 0, 9, 202, 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 170, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9, 234, 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 154, 84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 218, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 186,
60 | 0, 8, 13, 0, 8, 141, 0, 8, 77, 0, 9, 250, 80, 7, 3, 0, 8, 83, 0, 8, 19, 85, 8, 195, 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 198, 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9, 166, 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 230, 80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 150, 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 214, 82, 7, 19, 0, 8, 107, 0, 8, 43, 0, 9, 182, 0, 8, 11, 0, 8, 139, 0, 8, 75, 0, 9, 246, 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9, 206, 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 174, 0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 238, 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 158, 84, 7, 99, 0, 8, 127, 0, 8, 63, 0, 9, 222, 82, 7, 27, 0, 8, 111, 0, 8, 47, 0, 9, 190, 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 254, 96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9, 193, 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 161, 0, 8, 0, 0, 8, 128, 0, 8, 64, 0, 9, 225, 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 145, 83, 7, 59, 0, 8, 120, 0, 8, 56, 0, 9, 209, 81, 7, 17, 0, 8, 104, 0, 8, 40, 0, 9, 177, 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 241, 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8, 227, 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 201, 81, 7, 13, 0, 8, 100, 0, 8, 36, 0, 9, 169, 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 233, 80, 7, 8, 0, 8, 92, 0, 8, 28, 0, 9, 153, 84, 7, 83, 0, 8, 124, 0, 8, 60, 0, 9, 217, 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 185, 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9, 249, 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163, 83, 7, 35, 0, 8, 114, 0, 8, 50, 0, 9, 197, 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 165, 0, 8, 2, 0, 8, 130, 0, 8, 66, 0, 9, 229, 80, 7, 7, 0, 8, 90, 0, 8, 26, 0, 9, 149, 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 213, 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9, 181, 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 245, 80, 7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 205, 81, 7, 15, 0, 8, 102, 0, 8, 38, 0, 9, 173, 0, 8, 6, 0, 8, 134, 0, 8, 70, 0, 9, 237, 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 157, 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9, 221, 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 189, 0, 8,
61 | 14, 0, 8, 142, 0, 8, 78, 0, 9, 253, 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 82, 7, 31, 0, 8, 113, 0, 8, 49, 0, 9, 195, 80, 7, 10, 0, 8, 97, 0, 8, 33, 0, 9, 163, 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 227, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9, 147, 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 211, 81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 179, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 243, 80, 7, 4, 0, 8, 85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0, 8, 117, 0, 8, 53, 0, 9, 203, 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 171, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9, 235, 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 155, 84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 219, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 187, 0, 8, 13, 0, 8, 141, 0, 8, 77, 0, 9, 251, 80, 7, 3, 0, 8, 83, 0, 8, 19, 85, 8, 195, 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 199, 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9, 167, 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 231, 80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 151, 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 215, 82, 7, 19, 0, 8, 107, 0, 8, 43, 0, 9, 183, 0, 8, 11, 0, 8, 139, 0, 8, 75, 0, 9, 247, 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9, 207, 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 175, 0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 239, 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 159, 84, 7, 99, 0, 8, 127, 0, 8, 63, 0, 9, 223, 82, 7, 27, 0, 8, 111, 0, 8, 47, 0, 9, 191, 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 255};
62 |
63 | internal static readonly int[] fixed_td = new int[] { 80, 5, 1, 87, 5, 257, 83, 5, 17, 91, 5, 4097, 81, 5, 5, 89, 5, 1025, 85, 5, 65, 93, 5, 16385, 80, 5, 3, 88, 5, 513, 84, 5, 33, 92, 5, 8193, 82, 5, 9, 90, 5, 2049, 86, 5, 129, 192, 5, 24577, 80, 5, 2, 87, 5, 385, 83, 5, 25, 91, 5, 6145, 81, 5, 7, 89, 5, 1537, 85, 5, 97, 93, 5, 24577, 80, 5, 4, 88, 5, 769, 84, 5, 49, 92, 5, 12289, 82, 5, 13, 90, 5, 3073, 86, 5, 193, 192, 5, 24577 };
64 |
65 | // Tables for deflate from PKZIP's appnote.txt.
66 | internal static readonly int[] cplens = new int[] { 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 };
67 |
68 | internal static readonly int[] cplext = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112 };
69 |
70 | internal static readonly int[] cpdist = new int[] { 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 };
71 |
72 | internal static readonly int[] cpdext = new int[] { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 };
73 |
74 | // If BMAX needs to be larger than 16, then h and x[] should be uLong.
75 | internal const int BMAX = 15; // maximum bit length of any code
76 | }
77 |
78 | internal sealed class InfTree
79 | {
80 |
81 | #region Methods
82 |
83 | ///
84 | /// Given a list of code lengths and a maximum table size, make a set of
85 | /// tables to decode that set of codes.
86 | ///
87 | /// Return (int)ZLibResultCode.Z_OK on success, (int)ZLibResultCode.Z_DATA_ERROR if the given code set is incomplete (the tables are still built in this case), (int)ZLibResultCode.Z_DATA_ERROR if the input is invalid (an over-subscribed set of lengths), or (int)ZLibResultCode.Z_DATA_ERROR if not enough memory.
88 | ///
89 | private static int huft_build(int[] b, int bindex, int n, int s, int[] d, int[] e, int[] t, int[] m, int[] hp, int[] hn, int[] v)
90 | {
91 |
92 | int a; // counter for codes of length k
93 | int[] c = new int[InfTreeUtil.BMAX + 1]; // bit length count table
94 | int f; // i repeats in table every internalFlush entries
95 | int g; // maximum code length
96 | int h; // table level
97 | int i; // counter, current code
98 | int j; // counter
99 | int k; // number of bits in current code
100 | int l; // bits per table (returned in m)
101 | int mask; // (1 << windowBits) - 1, to avoid cc -O bug on HP
102 | int p; // pointer into c[], buffer[], or v[]
103 | int q; // points to current table
104 | int[] r = new int[3]; // table entry for structure assignment
105 | int[] u = new int[InfTreeUtil.BMAX]; // table stack
106 | int w; // bits before this table == (l * h)
107 | int[] x = new int[InfTreeUtil.BMAX + 1]; // bit offsets, then code stack
108 | int xp; // pointer into x
109 | int y; // number of dummy codes added
110 | int z; // number of entries in current table
111 |
112 | // Generate counts for each bit length
113 |
114 | p = 0; i = n;
115 | do
116 | {
117 | c[b[bindex + p]]++; p++; i--; // assume all entries <= BMAX
118 | }
119 | while (i != 0);
120 |
121 | if (c[0] == n)
122 | {
123 | // null input--all zero length codes
124 | t[0] = - 1;
125 | m[0] = 0;
126 | return (int)ZLibResultCode.Z_OK;
127 | }
128 |
129 | // Find minimum and maximum length, bound *m by those
130 | l = m[0];
131 | for (j = 1; j <= InfTreeUtil.BMAX; j++)
132 | if (c[j] != 0)
133 | break;
134 | k = j; // minimum code length
135 | if (l < j)
136 | {
137 | l = j;
138 | }
139 | for (i = InfTreeUtil.BMAX; i != 0; i--)
140 | {
141 | if (c[i] != 0)
142 | break;
143 | }
144 | g = i; // maximum code length
145 | if (l > i)
146 | {
147 | l = i;
148 | }
149 | m[0] = l;
150 |
151 | // Adjust last length count to fill out codes, if needed
152 | for (y = 1 << j; j < i; j++, y <<= 1)
153 | {
154 | if ((y -= c[j]) < 0)
155 | {
156 | return (int)ZLibResultCode.Z_DATA_ERROR;
157 | }
158 | }
159 | if ((y -= c[i]) < 0)
160 | {
161 | return (int)ZLibResultCode.Z_DATA_ERROR;
162 | }
163 | c[i] += y;
164 |
165 | // Generate starting offsets into the value table for each length
166 | x[1] = j = 0;
167 | p = 1; xp = 2;
168 | while (--i != 0)
169 | {
170 | // note that i == g from above
171 | x[xp] = (j += c[p]);
172 | xp++;
173 | p++;
174 | }
175 |
176 | // Make a table of values in order of bit lengths
177 | i = 0; p = 0;
178 | do
179 | {
180 | if ((j = b[bindex + p]) != 0)
181 | {
182 | v[x[j]++] = i;
183 | }
184 | p++;
185 | }
186 | while (++i < n);
187 | n = x[g]; // set n to length of v
188 |
189 | // Generate the Huffman codes and for each, make the table entries
190 | x[0] = i = 0; // first Huffman code is zero
191 | p = 0; // grab values in bit order
192 | h = - 1; // no tables yet--level -1
193 | w = - l; // bits decoded == (l * h)
194 | u[0] = 0; // just to keep compilers happy
195 | q = 0; // ditto
196 | z = 0; // ditto
197 |
198 | // go through the bit lengths (k already is bits in shortest code)
199 | for (; k <= g; k++)
200 | {
201 | a = c[k];
202 | while (a-- != 0)
203 | {
204 | // here i is the Huffman code of length k bits for value *p
205 | // make tables up to required level
206 | while (k > w + l)
207 | {
208 | h++;
209 | w += l; // previous table always l bits
210 | // compute minimum size table less than or equal to l bits
211 | z = g - w;
212 | z = (z > l)?l:z; // table size upper limit
213 | if ((f = 1 << (j = k - w)) > a + 1)
214 | {
215 | // try a k-windowBits bit table
216 | // too few codes for k-windowBits bit table
217 | f -= (a + 1); // deduct codes from patterns left
218 | xp = k;
219 | if (j < z)
220 | {
221 | while (++j < z)
222 | {
223 | // try smaller tables up to z bits
224 | if ((f <<= 1) <= c[++xp])
225 | break; // enough codes to use up j bits
226 | f -= c[xp]; // else deduct codes from patterns
227 | }
228 | }
229 | }
230 | z = 1 << j; // table entries for j-bit table
231 |
232 | // allocate new table
233 | if (hn[0] + z > InfTreeUtil.MANY)
234 | // (note: doesn't matter for fixed)
235 | return (int)ZLibResultCode.Z_DATA_ERROR; // overflow of MANY
236 | u[h] = q = hn[0]; // DEBUG
237 | hn[0] += z;
238 |
239 | // connect to last table, if there is one
240 | if (h != 0)
241 | {
242 | x[h] = i; // save pattern for backing up
243 | r[0] = (byte) j; // bits in this table
244 | r[1] = (byte) l; // bits to dump before this table
245 | j = ZLibUtil.URShift(i, (w - l));
246 | r[2] = (int) (q - u[h - 1] - j); // offset to this table
247 | Array.Copy(r, 0, hp, (u[h - 1] + j) * 3, 3); // connect to last table
248 | }
249 | else
250 | {
251 | t[0] = q; // first table is returned result
252 | }
253 | }
254 |
255 | // set up table entry in r
256 | r[1] = (byte) (k - w);
257 | if (p >= n)
258 | {
259 | r[0] = 128 + 64; // out of values--invalid code
260 | }
261 | else if (v[p] < s)
262 | {
263 | r[0] = (byte) (v[p] < 256?0:32 + 64); // 256 is End-of-block
264 | r[2] = v[p++]; // simple code is just the value
265 | }
266 | else
267 | {
268 | r[0] = (byte) (e[v[p] - s] + 16 + 64); // non-simple--look up in lists
269 | r[2] = d[v[p++] - s];
270 | }
271 |
272 | // fill code-like entries with r
273 | f = 1 << (k - w);
274 | for (j = ZLibUtil.URShift(i, w); j < z; j += f)
275 | {
276 | Array.Copy(r, 0, hp, (q + j) * 3, 3);
277 | }
278 |
279 | // backwards increment the k-bit code i
280 | for (j = 1 << (k - 1); (i & j) != 0; j = ZLibUtil.URShift(j, 1))
281 | {
282 | i ^= j;
283 | }
284 | i ^= j;
285 |
286 | // backup over finished tables
287 | mask = (1 << w) - 1; // needed on HP, cc -O bug
288 | while ((i & mask) != x[h])
289 | {
290 | h--; // don't need to update q
291 | w -= l;
292 | mask = (1 << w) - 1;
293 | }
294 | }
295 | }
296 | // Return (int)ZLibResultCode.Z_DATA_ERROR if we were given an incomplete table
297 | return y != 0 && g != 1 ? (int)ZLibResultCode.Z_BUF_ERROR : (int)ZLibResultCode.Z_OK;
298 | }
299 |
300 | ///
301 | /// Build trees
302 | ///
303 | internal static int inflate_trees_bits(int[] c, int[] bb, int[] tb, int[] hp, ZStream z)
304 | {
305 | int r;
306 | int[] hn = new int[1]; // hufts used in space
307 | int[] v = new int[19]; // work area for huft_build
308 |
309 | r = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);
310 |
311 | if (r == (int)ZLibResultCode.Z_DATA_ERROR)
312 | {
313 | z.msg = "oversubscribed dynamic bit lengths tree";
314 | }
315 | else if (r == (int)ZLibResultCode.Z_DATA_ERROR || bb[0] == 0)
316 | {
317 | z.msg = "incomplete dynamic bit lengths tree";
318 | r = (int)ZLibResultCode.Z_DATA_ERROR;
319 | }
320 | return r;
321 | }
322 |
323 | ///
324 | /// Builds dynamic trees
325 | ///
326 | internal static int inflate_trees_dynamic(int nl, int nd, int[] c, int[] bl, int[] bd, int[] tl, int[] td, int[] hp, ZStream z)
327 | {
328 | int r;
329 | int[] hn = new int[1]; // hufts used in space
330 | int[] v = new int[288]; // work area for huft_build
331 |
332 | // build literal/length tree
333 | r = huft_build(c, 0, nl, 257, InfTreeUtil.cplens, InfTreeUtil.cplext, tl, bl, hp, hn, v);
334 | if (r != (int)ZLibResultCode.Z_OK || bl[0] == 0)
335 | {
336 | if (r == (int)ZLibResultCode.Z_DATA_ERROR)
337 | {
338 | z.msg = "oversubscribed literal/length tree";
339 | }
340 | else if (r != (int)ZLibResultCode.Z_DATA_ERROR)
341 | {
342 | z.msg = "incomplete literal/length tree";
343 | r = (int)ZLibResultCode.Z_DATA_ERROR;
344 | }
345 | return r;
346 | }
347 |
348 | // build distance tree
349 | r = huft_build(c, nl, nd, 0, InfTreeUtil.cpdist, InfTreeUtil.cpdext, td, bd, hp, hn, v);
350 |
351 | if (r != (int)ZLibResultCode.Z_OK || (bd[0] == 0 && nl > 257))
352 | {
353 | if (r == (int)ZLibResultCode.Z_DATA_ERROR)
354 | {
355 | z.msg = "oversubscribed distance tree";
356 | }
357 | else if (r == (int)ZLibResultCode.Z_DATA_ERROR)
358 | {
359 | z.msg = "incomplete distance tree";
360 | r = (int)ZLibResultCode.Z_DATA_ERROR;
361 | }
362 | else if (r != (int)ZLibResultCode.Z_DATA_ERROR)
363 | {
364 | z.msg = "empty distance tree with lengths";
365 | r = (int)ZLibResultCode.Z_DATA_ERROR;
366 | }
367 | return r;
368 | }
369 |
370 | return (int)ZLibResultCode.Z_OK;
371 | }
372 |
373 | ///
374 | /// Build fixed trees
375 | ///
376 | internal static int inflate_trees_fixed(int[] bl, int[] bd, int[][] tl, int[][] td, ZStream z)
377 | {
378 | bl[0] = InfTreeUtil.fixed_bl;
379 | bd[0] = InfTreeUtil.fixed_bd;
380 | tl[0] = InfTreeUtil.fixed_tl;
381 | td[0] = InfTreeUtil.fixed_td;
382 | return (int)ZLibResultCode.Z_OK;
383 | }
384 |
385 | #endregion
386 | }
387 | }
--------------------------------------------------------------------------------
/CatSceneEditor/Zlib/Inflate.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2006, ComponentAce
2 | // http://www.componentace.com
3 | // All rights reserved.
4 |
5 | // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6 |
7 | // Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 | // Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 | // Neither the name of ComponentAce nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11 |
12 | /*
13 | Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
14 |
15 | Redistribution and use in source and binary forms, with or without
16 | modification, are permitted provided that the following conditions are met:
17 |
18 | 1. Redistributions of source code must retain the above copyright notice,
19 | this list of conditions and the following disclaimer.
20 |
21 | 2. Redistributions in binary form must reproduce the above copyright
22 | notice, this list of conditions and the following disclaimer in
23 | the documentation and/or other materials provided with the distribution.
24 |
25 | 3. The names of the authors may not be used to endorse or promote products
26 | derived from this software without specific prior written permission.
27 |
28 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
29 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
30 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
31 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
32 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
34 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
37 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 | */
39 | /*
40 | * This program is based on zlib-1.1.3, so all credit should go authors
41 | * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
42 | * and contributors of zlib.
43 | */
44 | using System;
45 |
46 | namespace ComponentAce
47 | {
48 | ///
49 | /// This enumeration contains modes of inflate processing
50 | ///
51 | internal enum InflateMode
52 | {
53 | ///
54 | /// waiting for method byte
55 | ///
56 | METHOD = 0,
57 | ///
58 | /// waiting for flag byte
59 | ///
60 | FLAG = 1,
61 | ///
62 | /// four dictionary check bytes to go
63 | ///
64 | DICT4 = 2,
65 | ///
66 | /// three dictionary check bytes to go
67 | ///
68 | DICT3 = 3,
69 | ///
70 | /// two dictionary check bytes to go
71 | ///
72 | DICT2 = 4,
73 | ///
74 | /// one dictionary check byte to go
75 | ///
76 | DICT1 = 5,
77 | ///
78 | /// waiting for inflateSetDictionary
79 | ///
80 | DICT0 = 6,
81 | ///
82 | /// decompressing blocks
83 | ///
84 | BLOCKS = 7,
85 | ///
86 | /// four check bytes to go
87 | ///
88 | CHECK4 = 8,
89 | ///
90 | /// three check bytes to go
91 | ///
92 | CHECK3 = 9,
93 | ///
94 | /// two check bytes to go
95 | ///
96 | CHECK2 = 10,
97 | ///
98 | /// one check byte to go
99 | ///
100 | CHECK1 = 11,
101 | ///
102 | /// finished check, done
103 | ///
104 | DONE = 12,
105 | ///
106 | /// got an error--stay here
107 | ///
108 | BAD = 13
109 | }
110 |
111 | internal sealed class Inflate
112 | {
113 |
114 | #region Fields
115 |
116 | ///
117 | /// current inflate mode
118 | ///
119 | internal InflateMode mode;
120 |
121 | #region mode dependent information
122 |
123 | ///
124 | /// if FLAGS, method byte
125 | ///
126 | private int method;
127 |
128 | // if CHECK, check values to compare
129 |
130 | ///
131 | /// computed check value
132 | ///
133 | private long[] was = new long[1];
134 |
135 | ///
136 | /// stream check value
137 | ///
138 | private long need;
139 |
140 | ///
141 | /// if BAD, inflateSync's marker bytes count
142 | ///
143 | private int marker;
144 |
145 | #endregion
146 |
147 | #region mode independent information
148 | ///
149 | /// flag for no wrapper
150 | ///
151 | private int nowrap;
152 | ///
153 | /// log2(Window size) (8..15, defaults to 15)
154 | ///
155 | private int wbits;
156 |
157 | #endregion
158 |
159 | ///
160 | /// current inflate_blocks state
161 | ///
162 | private InfBlocks blocks;
163 |
164 | #endregion
165 |
166 | #region Methods
167 |
168 | ///
169 | /// Resets the Inflate algorithm
170 | ///
171 | /// A ZStream object
172 | /// A result code
173 | internal int inflateReset(ZStream z)
174 | {
175 | if (z == null || z.istate == null)
176 | return (int)ZLibResultCode.Z_STREAM_ERROR;
177 |
178 | z.total_in = z.total_out = 0;
179 | z.msg = null;
180 | z.istate.mode = z.istate.nowrap != 0? InflateMode.BLOCKS: InflateMode.METHOD;
181 | z.istate.blocks.reset(z, null);
182 | return (int)ZLibResultCode.Z_OK;
183 | }
184 |
185 | ///
186 | /// Finishes the inflate algorithm processing
187 | ///
188 | /// A ZStream object
189 | /// Operation result code
190 | internal int inflateEnd(ZStream z)
191 | {
192 | if (blocks != null)
193 | blocks.free(z);
194 | blocks = null;
195 | // ZFREE(z, z->state);
196 | return (int)ZLibResultCode.Z_OK;
197 | }
198 |
199 | ///
200 | /// Initializes the inflate algorithm
201 | ///
202 | /// A ZStream object
203 | /// Window size
204 | /// Operation result code
205 | internal int inflateInit(ZStream z, int windowBits)
206 | {
207 | z.msg = null;
208 | blocks = null;
209 |
210 | // handle undocumented nowrap option (no zlib header or check)
211 | nowrap = 0;
212 | if (windowBits < 0)
213 | {
214 | windowBits = - windowBits;
215 | nowrap = 1;
216 | }
217 |
218 | // set Window size
219 | if (windowBits < 8 || windowBits > 15)
220 | {
221 | inflateEnd(z);
222 | return (int)ZLibResultCode.Z_STREAM_ERROR;
223 | }
224 | wbits = windowBits;
225 |
226 | z.istate.blocks = new InfBlocks(z, z.istate.nowrap == 0, 1 << windowBits);
227 |
228 | // reset state
229 | inflateReset(z);
230 | return (int)ZLibResultCode.Z_OK;
231 | }
232 |
233 | ///
234 | /// Runs inflate algorithm
235 | ///
236 | /// A ZStream object
237 | /// Flush strategy
238 | /// Operation result code
239 | internal int inflate(ZStream z, FlushStrategy flush)
240 | {
241 | int r;
242 | int b;
243 |
244 | int internalFlush = (int)flush;
245 |
246 | int res_temp;
247 |
248 | if (z == null || z.istate == null || z.next_in == null)
249 | return (int)ZLibResultCode.Z_STREAM_ERROR;
250 | res_temp = internalFlush == (int)FlushStrategy.Z_FINISH ? (int)ZLibResultCode.Z_BUF_ERROR : (int)ZLibResultCode.Z_OK;
251 | r = (int)ZLibResultCode.Z_BUF_ERROR;
252 | while (true)
253 | {
254 |
255 | switch (z.istate.mode)
256 | {
257 |
258 | case InflateMode.METHOD:
259 |
260 | if (z.avail_in == 0)
261 | return r; r = res_temp;
262 |
263 | z.avail_in--; z.total_in++;
264 | if (((z.istate.method = z.next_in[z.next_in_index++]) & 0xf) != ZLibUtil.Z_DEFLATED)
265 | {
266 | z.istate.mode = InflateMode.BAD;
267 | z.msg = "unknown compression method";
268 | z.istate.marker = 5; // can't try inflateSync
269 | break;
270 | }
271 | if ((z.istate.method >> 4) + 8 > z.istate.wbits)
272 | {
273 | z.istate.mode = InflateMode.BAD;
274 | z.msg = "invalid Window size";
275 | z.istate.marker = 5; // can't try inflateSync
276 | break;
277 | }
278 | z.istate.mode = InflateMode.FLAG;
279 | goto case InflateMode.FLAG;
280 |
281 | case InflateMode.FLAG:
282 |
283 | if (z.avail_in == 0)
284 | return r; r = res_temp;
285 |
286 | z.avail_in--; z.total_in++;
287 | b = (z.next_in[z.next_in_index++]) & 0xff;
288 |
289 | if ((((z.istate.method << 8) + b) % 31) != 0)
290 | {
291 | z.istate.mode = InflateMode.BAD;
292 | z.msg = "incorrect header check";
293 | z.istate.marker = 5; // can't try inflateSync
294 | break;
295 | }
296 |
297 | if ((b & ZLibUtil.PRESET_DICT) == 0)
298 | {
299 | z.istate.mode = InflateMode.BLOCKS;
300 | break;
301 | }
302 | z.istate.mode = InflateMode.DICT4;
303 | goto case InflateMode.DICT4;
304 |
305 | case InflateMode.DICT4:
306 |
307 | if (z.avail_in == 0)
308 | return r; r = res_temp;
309 |
310 | z.avail_in--; z.total_in++;
311 | z.istate.need = ((long)(z.next_in[z.next_in_index++] & 0xff) << 24) & unchecked((int) 0xff000000L);
312 | z.istate.mode = InflateMode.DICT3;
313 | goto case InflateMode.DICT3;
314 |
315 | case InflateMode.DICT3:
316 |
317 | if (z.avail_in == 0)
318 | return r; r = res_temp;
319 |
320 | z.avail_in--; z.total_in++;
321 | z.istate.need += (((long)(z.next_in[z.next_in_index++] & 0xff) << 16) & 0xff0000L);
322 | z.istate.mode = InflateMode.DICT2;
323 | goto case InflateMode.DICT2;
324 |
325 | case InflateMode.DICT2:
326 |
327 | if (z.avail_in == 0)
328 | return r; r = res_temp;
329 |
330 | z.avail_in--; z.total_in++;
331 | z.istate.need += (((long)(z.next_in[z.next_in_index++] & 0xff) << 8) & 0xff00L);
332 | z.istate.mode = InflateMode.DICT1;
333 | goto case InflateMode.DICT1;
334 |
335 | case InflateMode.DICT1:
336 |
337 | if (z.avail_in == 0)
338 | return r; r = res_temp;
339 |
340 | z.avail_in--; z.total_in++;
341 | z.istate.need += (z.next_in[z.next_in_index++] & 0xffL);
342 | z.adler = z.istate.need;
343 | z.istate.mode = InflateMode.DICT0;
344 | return (int)ZLibResultCode.Z_NEED_DICT;
345 |
346 | case InflateMode.DICT0:
347 | z.istate.mode = InflateMode.BAD;
348 | z.msg = "need dictionary";
349 | z.istate.marker = 0; // can try inflateSync
350 | return (int)ZLibResultCode.Z_STREAM_ERROR;
351 |
352 | case InflateMode.BLOCKS:
353 |
354 | r = z.istate.blocks.proc(z, r);
355 | if (r == (int)ZLibResultCode.Z_DATA_ERROR)
356 | {
357 | z.istate.mode = InflateMode.BAD;
358 | z.istate.marker = 0; // can try inflateSync
359 | break;
360 | }
361 | if (r == (int)ZLibResultCode.Z_OK)
362 | {
363 | r = res_temp;
364 | }
365 | if (r != (int)ZLibResultCode.Z_STREAM_END)
366 | {
367 | return r;
368 | }
369 | r = res_temp;
370 | z.istate.blocks.reset(z, z.istate.was);
371 | if (z.istate.nowrap != 0)
372 | {
373 | z.istate.mode = InflateMode.DONE;
374 | break;
375 | }
376 | z.istate.mode = InflateMode.CHECK4;
377 | goto case InflateMode.CHECK4;
378 |
379 | case InflateMode.CHECK4:
380 |
381 | if (z.avail_in == 0)
382 | return r; r = res_temp;
383 |
384 | z.avail_in--; z.total_in++;
385 | z.istate.need = ((z.next_in[z.next_in_index++] & 0xff) << 24) & unchecked((int) 0xff000000L);
386 | z.istate.mode = InflateMode.CHECK3;
387 | goto case InflateMode.CHECK3;
388 |
389 | case InflateMode.CHECK3:
390 |
391 | if (z.avail_in == 0)
392 | return r; r = res_temp;
393 |
394 | z.avail_in--; z.total_in++;
395 | z.istate.need += (((z.next_in[z.next_in_index++] & 0xff) << 16) & 0xff0000L);
396 | z.istate.mode = InflateMode.CHECK2;
397 | goto case InflateMode.CHECK2;
398 |
399 | case InflateMode.CHECK2:
400 |
401 | if (z.avail_in == 0)
402 | return r; r = res_temp;
403 |
404 | z.avail_in--; z.total_in++;
405 | z.istate.need += (((z.next_in[z.next_in_index++] & 0xff) << 8) & 0xff00L);
406 | z.istate.mode = InflateMode.CHECK1;
407 | goto case InflateMode.CHECK1;
408 |
409 | case InflateMode.CHECK1:
410 |
411 | if (z.avail_in == 0)
412 | return r; r = res_temp;
413 |
414 | z.avail_in--; z.total_in++;
415 | z.istate.need += (z.next_in[z.next_in_index++] & 0xffL);
416 |
417 | if (((int) (z.istate.was[0])) != ((int) (z.istate.need)))
418 | {
419 | z.istate.mode = InflateMode.BAD;
420 | z.msg = "incorrect data check";
421 | z.istate.marker = 5; // can't try inflateSync
422 | break;
423 | }
424 |
425 | z.istate.mode = InflateMode.DONE;
426 | goto case InflateMode.DONE;
427 |
428 | case InflateMode.DONE:
429 | return (int)ZLibResultCode.Z_STREAM_END;
430 |
431 | case InflateMode.BAD:
432 | return (int)ZLibResultCode.Z_DATA_ERROR;
433 |
434 | default:
435 | return (int)ZLibResultCode.Z_STREAM_ERROR;
436 |
437 | }
438 | }
439 | }
440 |
441 | ///
442 | /// Sets dictionary for the inflate operation
443 | ///
444 | /// A ZStream object
445 | /// An array of byte - dictionary
446 | /// Dictionary length
447 | /// Operation result code
448 | internal int inflateSetDictionary(ZStream z, byte[] dictionary, int dictLength)
449 | {
450 | int index = 0;
451 | int length = dictLength;
452 | if (z == null || z.istate == null || z.istate.mode != InflateMode.DICT0)
453 | return (int)ZLibResultCode.Z_STREAM_ERROR;
454 |
455 | if (Adler32.GetAdler32Checksum(1L, dictionary, 0, dictLength) != z.adler)
456 | {
457 | return (int)ZLibResultCode.Z_DATA_ERROR;
458 | }
459 |
460 | z.adler = Adler32.GetAdler32Checksum(0, null, 0, 0);
461 |
462 | if (length >= (1 << z.istate.wbits))
463 | {
464 | length = (1 << z.istate.wbits) - 1;
465 | index = dictLength - length;
466 | }
467 | z.istate.blocks.set_dictionary(dictionary, index, length);
468 | z.istate.mode = InflateMode.BLOCKS;
469 | return (int)ZLibResultCode.Z_OK;
470 | }
471 |
472 |
473 | ///
474 | /// Inflate synchronization
475 | ///
476 | /// A ZStream object
477 | /// Operation result code
478 | internal int inflateSync(ZStream z)
479 | {
480 | int n; // number of bytes to look at
481 | int p; // pointer to bytes
482 | int m; // number of marker bytes found in a row
483 | long r, w; // temporaries to save _total_in and _total_out
484 |
485 | // set up
486 | if (z == null || z.istate == null)
487 | return (int)ZLibResultCode.Z_STREAM_ERROR;
488 | if (z.istate.mode != InflateMode.BAD)
489 | {
490 | z.istate.mode = InflateMode.BAD;
491 | z.istate.marker = 0;
492 | }
493 | if ((n = z.avail_in) == 0)
494 | return (int)ZLibResultCode.Z_BUF_ERROR;
495 | p = z.next_in_index;
496 | m = z.istate.marker;
497 |
498 | // search
499 | while (n != 0 && m < 4)
500 | {
501 | if (z.next_in[p] == ZLibUtil.mark[m])
502 | {
503 | m++;
504 | }
505 | else if (z.next_in[p] != 0)
506 | {
507 | m = 0;
508 | }
509 | else
510 | {
511 | m = 4 - m;
512 | }
513 | p++; n--;
514 | }
515 |
516 | // restore
517 | z.total_in += p - z.next_in_index;
518 | z.next_in_index = p;
519 | z.avail_in = n;
520 | z.istate.marker = m;
521 |
522 | // return no joy or set up to restart on a new block
523 | if (m != 4)
524 | {
525 | return (int)ZLibResultCode.Z_DATA_ERROR;
526 | }
527 | r = z.total_in; w = z.total_out;
528 | inflateReset(z);
529 | z.total_in = r; z.total_out = w;
530 | z.istate.mode = InflateMode.BLOCKS;
531 | return (int)ZLibResultCode.Z_OK;
532 | }
533 |
534 | ///
535 | /// Returns true if inflate is currently at the End of a block generated
536 | /// by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
537 | /// implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
538 | /// but removes the length bytes of the resulting empty stored block. When
539 | /// decompressing, PPP checks that at the End of input packet, inflate is
540 | /// waiting for these length bytes.
541 | ///
542 | internal int inflateSyncPoint(ZStream z)
543 | {
544 | if (z == null || z.istate == null || z.istate.blocks == null)
545 | return (int)ZLibResultCode.Z_STREAM_ERROR;
546 | return z.istate.blocks.sync_point();
547 | }
548 |
549 | #endregion
550 | }
551 | }
--------------------------------------------------------------------------------
/CatSceneEditor/Zlib/StaticTree.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2006, ComponentAce
2 | // http://www.componentace.com
3 | // All rights reserved.
4 |
5 | // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6 |
7 | // Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 | // Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 | // Neither the name of ComponentAce nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11 |
12 | /*
13 | Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
14 |
15 | Redistribution and use in source and binary forms, with or without
16 | modification, are permitted provided that the following conditions are met:
17 |
18 | 1. Redistributions of source code must retain the above copyright notice,
19 | this list of conditions and the following disclaimer.
20 |
21 | 2. Redistributions in binary form must reproduce the above copyright
22 | notice, this list of conditions and the following disclaimer in
23 | the documentation and/or other materials provided with the distribution.
24 |
25 | 3. The names of the authors may not be used to endorse or promote products
26 | derived from this software without specific prior written permission.
27 |
28 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
29 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
30 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
31 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
32 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
34 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
37 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 | */
39 | /*
40 | * This program is based on zlib-1.1.3, so all credit should go authors
41 | * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
42 | * and contributors of zlib.
43 | */
44 | using System;
45 |
46 |
47 | namespace ComponentAce
48 | {
49 |
50 | internal sealed class StaticTree
51 | {
52 |
53 | #region Fields
54 |
55 | private const int BL_CODES = 19;
56 | private const int D_CODES = 30;
57 | private const int LITERALS = 256;
58 | private const int LENGTH_CODES = 29;
59 | private const int L_CODES = (LITERALS + 1 + LENGTH_CODES);
60 |
61 | ///
62 | /// Bit length codes must not exceed MAX_BL_BITS bits
63 | ///
64 | internal const int MAX_BL_BITS = 7;
65 |
66 | internal static readonly short[] static_ltree = new short[]{12, 8, 140, 8, 76, 8, 204, 8, 44, 8, 172, 8, 108, 8, 236, 8, 28, 8, 156, 8, 92, 8, 220, 8, 60, 8, 188, 8, 124, 8, 252, 8, 2, 8, 130, 8, 66, 8, 194, 8, 34, 8, 162, 8, 98, 8, 226, 8, 18, 8, 146, 8, 82, 8, 210, 8, 50, 8, 178, 8, 114, 8, 242, 8, 10, 8, 138, 8, 74, 8, 202, 8, 42, 8, 170, 8, 106, 8, 234, 8, 26, 8, 154, 8, 90, 8, 218, 8, 58, 8, 186, 8, 122, 8, 250, 8, 6, 8, 134, 8, 70, 8, 198, 8, 38, 8, 166, 8, 102, 8, 230, 8, 22, 8, 150, 8, 86, 8, 214, 8, 54, 8, 182, 8, 118, 8, 246, 8, 14, 8, 142, 8, 78, 8, 206, 8, 46, 8, 174, 8, 110, 8, 238, 8, 30, 8, 158, 8, 94, 8, 222, 8, 62, 8, 190, 8, 126, 8, 254, 8, 1, 8, 129, 8, 65, 8, 193, 8, 33, 8, 161, 8, 97, 8, 225, 8, 17, 8, 145, 8, 81, 8, 209, 8, 49, 8, 177, 8, 113, 8, 241, 8, 9, 8, 137, 8, 73, 8, 201, 8, 41, 8, 169, 8, 105, 8, 233, 8, 25, 8, 153, 8, 89, 8, 217, 8, 57, 8, 185, 8, 121, 8, 249, 8, 5, 8, 133, 8, 69, 8, 197, 8, 37, 8, 165, 8, 101, 8, 229, 8, 21, 8, 149, 8, 85, 8, 213, 8, 53, 8, 181, 8, 117, 8, 245, 8, 13, 8, 141, 8, 77, 8, 205, 8, 45, 8, 173, 8, 109, 8, 237, 8, 29, 8, 157, 8, 93, 8, 221, 8, 61, 8, 189, 8, 125, 8, 253, 8, 19, 9, 275, 9, 147, 9, 403, 9, 83, 9, 339, 9, 211, 9, 467, 9, 51, 9, 307, 9, 179, 9, 435, 9, 115, 9, 371, 9, 243, 9, 499, 9, 11, 9, 267, 9, 139, 9, 395, 9, 75, 9, 331, 9, 203, 9, 459, 9, 43, 9, 299, 9, 171, 9, 427, 9, 107, 9, 363, 9, 235, 9, 491, 9, 27, 9, 283, 9, 155, 9, 411, 9, 91, 9, 347, 9, 219, 9, 475, 9, 59, 9, 315, 9, 187, 9, 443, 9, 123, 9, 379, 9, 251, 9, 507, 9, 7, 9, 263, 9, 135, 9, 391, 9, 71, 9, 327, 9, 199, 9, 455, 9, 39, 9, 295, 9, 167, 9, 423, 9, 103, 9, 359, 9, 231, 9, 487, 9, 23, 9, 279, 9, 151, 9, 407, 9, 87, 9, 343, 9, 215, 9, 471, 9, 55, 9, 311, 9, 183, 9, 439, 9, 119, 9, 375, 9, 247, 9, 503, 9, 15, 9, 271, 9, 143, 9, 399, 9, 79, 9, 335, 9, 207, 9, 463, 9, 47, 9, 303, 9, 175, 9, 431, 9, 111, 9, 367, 9, 239, 9, 495, 9, 31, 9, 287, 9, 159, 9, 415, 9, 95, 9, 351, 9, 223, 9, 479, 9, 63, 9, 319, 9, 191, 9, 447, 9, 127, 9, 383, 9, 255, 9, 511, 9, 0, 7, 64, 7
67 | , 32, 7, 96, 7, 16, 7, 80, 7, 48, 7, 112, 7, 8, 7, 72, 7, 40, 7, 104, 7, 24, 7, 88, 7, 56, 7, 120, 7, 4, 7, 68, 7, 36, 7, 100, 7, 20, 7, 84, 7, 52, 7, 116, 7, 3, 8, 131, 8, 67, 8, 195, 8, 35, 8, 163, 8, 99, 8, 227, 8};
68 |
69 | internal static readonly short[] static_dtree = new short[] { 0, 5, 16, 5, 8, 5, 24, 5, 4, 5, 20, 5, 12, 5, 28, 5, 2, 5, 18, 5, 10, 5, 26, 5, 6, 5, 22, 5, 14, 5, 30, 5, 1, 5, 17, 5, 9, 5, 25, 5, 5, 5, 21, 5, 13, 5, 29, 5, 3, 5, 19, 5, 11, 5, 27, 5, 7, 5, 23, 5 };
70 |
71 | internal static StaticTree static_l_desc;
72 |
73 | internal static StaticTree static_d_desc;
74 |
75 | internal static StaticTree static_bl_desc;
76 |
77 | internal short[] static_tree; // static tree or null
78 | internal int[] extra_bits; // extra bits for each code or null
79 | internal int extra_base; // base index for extra_bits
80 | internal int elems; // max number of elements in the tree
81 | internal int max_length; // max bit length for the codes
82 |
83 |
84 | #endregion
85 |
86 | #region Constructors
87 |
88 | internal StaticTree(short[] static_tree, int[] extra_bits, int extra_base, int elems, int max_length)
89 | {
90 | this.static_tree = static_tree;
91 | this.extra_bits = extra_bits;
92 | this.extra_base = extra_base;
93 | this.elems = elems;
94 | this.max_length = max_length;
95 | }
96 | static StaticTree()
97 | {
98 | static_l_desc = new StaticTree(static_ltree, ZLibUtil.extra_lbits, LITERALS + 1, L_CODES, ZLibUtil.MAX_WBITS);
99 | static_d_desc = new StaticTree(static_dtree, ZLibUtil.extra_dbits, 0, D_CODES, ZLibUtil.MAX_WBITS);
100 | static_bl_desc = new StaticTree(null, ZLibUtil.extra_blbits, 0, BL_CODES, MAX_BL_BITS);
101 | }
102 | #endregion
103 | }
104 | }
--------------------------------------------------------------------------------
/CatSceneEditor/Zlib/SupportClass.cs:
--------------------------------------------------------------------------------
1 |
2 | using System;
3 |
4 |
5 | namespace ComponentAce
6 | {
7 | internal class SupportClass
8 | {
9 | ///
10 | /// This method returns the literal value received
11 | ///
12 | /// The literal to return
13 | /// The received value
14 | internal static long Identity(long literal)
15 | {
16 | return literal;
17 | }
18 |
19 | ///
20 | /// This method returns the literal value received
21 | ///
22 | /// The literal to return
23 | /// The received value
24 | internal static ulong Identity(ulong literal)
25 | {
26 | return literal;
27 | }
28 |
29 | ///
30 | /// This method returns the literal value received
31 | ///
32 | /// The literal to return
33 | /// The received value
34 | internal static float Identity(float literal)
35 | {
36 | return literal;
37 | }
38 |
39 | ///
40 | /// This method returns the literal value received
41 | ///
42 | /// The literal to return
43 | /// The received value
44 | internal static double Identity(double literal)
45 | {
46 | return literal;
47 | }
48 |
49 | /*******************************/
50 | ///
51 | /// Performs an unsigned bitwise right shift with the specified number
52 | ///
53 | /// Number to operate on
54 | /// Ammount of bits to shift
55 | /// The resulting number from the shift operation
56 | internal static int URShift(int number, int bits)
57 | {
58 | if ( number >= 0)
59 | return number >> bits;
60 | else
61 | return (number >> bits) + (2 << ~bits);
62 | }
63 |
64 | ///
65 | /// Performs an unsigned bitwise right shift with the specified number
66 | ///
67 | /// Number to operate on
68 | /// Ammount of bits to shift
69 | /// The resulting number from the shift operation
70 | internal static int URShift(int number, long bits)
71 | {
72 | return URShift(number, (int)bits);
73 | }
74 |
75 | ///
76 | /// Performs an unsigned bitwise right shift with the specified number
77 | ///
78 | /// Number to operate on
79 | /// Ammount of bits to shift
80 | /// The resulting number from the shift operation
81 | internal static long URShift(long number, int bits)
82 | {
83 | if ( number >= 0)
84 | return number >> bits;
85 | else
86 | return (number >> bits) + (2L << ~bits);
87 | }
88 |
89 | ///
90 | /// Performs an unsigned bitwise right shift with the specified number
91 | ///
92 | /// Number to operate on
93 | /// Ammount of bits to shift
94 | /// The resulting number from the shift operation
95 | internal static long URShift(long number, long bits)
96 | {
97 | return URShift(number, (int)bits);
98 | }
99 |
100 | /*******************************/
101 | /// Reads a number of characters from the current source Stream and writes the data to the target array at the specified index.
102 | /// The source Stream to read from.
103 | /// Contains the array of characteres read from the source Stream.
104 | /// The starting index of the target array.
105 | /// The maximum number of characters to read from the source Stream.
106 | /// The number of characters read. The number will be less than or equal to count depending on the data available in the source Stream. Returns -1 if the end of the stream is reached.
107 | internal static System.Int32 ReadInput(System.IO.Stream sourceStream, byte[] target, int start, int count)
108 | {
109 | // Returns 0 bytes if not enough space in target
110 | if (target.Length == 0)
111 | return 0;
112 |
113 | byte[] receiver = new byte[target.Length];
114 | int bytesRead = sourceStream.Read(receiver, start, count);
115 |
116 | // Returns -1 if EOF
117 | if (bytesRead == 0)
118 | return -1;
119 |
120 | for(int i = start; i < start + bytesRead; i++)
121 | target[i] = (byte)receiver[i];
122 |
123 | return bytesRead;
124 | }
125 |
126 | /// Reads a number of characters from the current source TextReader and writes the data to the target array at the specified index.
127 | /// The source TextReader to read from
128 | /// Contains the array of characteres read from the source TextReader.
129 | /// The starting index of the target array.
130 | /// The maximum number of characters to read from the source TextReader.
131 | /// The number of characters read. The number will be less than or equal to count depending on the data available in the source TextReader. Returns -1 if the end of the stream is reached.
132 | internal static System.Int32 ReadInput(System.IO.TextReader sourceTextReader, byte[] target, int start, int count)
133 | {
134 | // Returns 0 bytes if not enough space in target
135 | if (target.Length == 0) return 0;
136 |
137 | char[] charArray = new char[target.Length];
138 | int bytesRead = sourceTextReader.Read(charArray, start, count);
139 |
140 | // Returns -1 if EOF
141 | if (bytesRead == 0) return -1;
142 |
143 | for(int index=start; index
150 | /// Converts a string to an array of bytes
151 | ///
152 | /// The string to be converted
153 | /// The new array of bytes
154 | internal static byte[] ToByteArray(System.String sourceString)
155 | {
156 | return System.Text.UTF8Encoding.UTF8.GetBytes(sourceString);
157 | }
158 |
159 | ///
160 | /// Converts an array of bytes to an array of chars
161 | ///
162 | /// The array of bytes to convert
163 | /// The new array of chars
164 | internal static char[] ToCharArray(byte[] byteArray)
165 | {
166 | return System.Text.UTF8Encoding.UTF8.GetChars(byteArray);
167 | }
168 |
169 |
170 | }
171 | }
--------------------------------------------------------------------------------
/CatSceneEditor/Zlib/Tree.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2006, ComponentAce
2 | // http://www.componentace.com
3 | // All rights reserved.
4 |
5 | // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6 |
7 | // Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 | // Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 | // Neither the name of ComponentAce nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11 |
12 | /*
13 | Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
14 |
15 | Redistribution and use in source and binary forms, with or without
16 | modification, are permitted provided that the following conditions are met:
17 |
18 | 1. Redistributions of source code must retain the above copyright notice,
19 | this list of conditions and the following disclaimer.
20 |
21 | 2. Redistributions in binary form must reproduce the above copyright
22 | notice, this list of conditions and the following disclaimer in
23 | the documentation and/or other materials provided with the distribution.
24 |
25 | 3. The names of the authors may not be used to endorse or promote products
26 | derived from this software without specific prior written permission.
27 |
28 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
29 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
30 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
31 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
32 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
34 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
37 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 | */
39 | /*
40 | * This program is based on zlib-1.1.3, so all credit should go authors
41 | * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
42 | * and contributors of zlib.
43 | */
44 | using System;
45 |
46 | namespace ComponentAce
47 | {
48 |
49 | ///
50 | /// This class represents a tree and is used in the Deflate class
51 | ///
52 | internal sealed class Tree
53 | {
54 |
55 | #region Fields
56 |
57 | ///
58 | /// The dynamic tree
59 | ///
60 | private short[] dyn_tree;
61 |
62 | ///
63 | /// Largest code with non zero frequency
64 | ///
65 | private int max_code;
66 |
67 | ///
68 | /// the corresponding static tree
69 | ///
70 | private StaticTree stat_desc;
71 |
72 | #endregion
73 |
74 | #region Properties
75 |
76 | ///
77 | /// The dynamic tree
78 | ///
79 | internal short[] DynTree
80 | {
81 | get { return dyn_tree; }
82 | set { dyn_tree = value; }
83 | }
84 |
85 | ///
86 | /// Largest code with non zero frequency
87 | ///
88 | internal int MaxCode
89 | {
90 | get { return max_code; }
91 | set { max_code = value; }
92 | }
93 | ///
94 | /// the corresponding static tree
95 | ///
96 | internal StaticTree StatDesc
97 | {
98 | get { return stat_desc; }
99 | set { stat_desc = value; }
100 | }
101 |
102 | #endregion
103 |
104 | #region Methods
105 |
106 | ///
107 | /// Mapping from a distance to a distance code. dist is the distance - 1 and
108 | /// must not have side effects. _dist_code[256] and _dist_code[257] are never
109 | /// used.
110 | ///
111 | internal static int d_code(int dist)
112 | {
113 | return ((dist) < 256 ? ZLibUtil._dist_code[dist] : ZLibUtil._dist_code[256 + (ZLibUtil.URShift((dist), 7))]);
114 | }
115 |
116 | ///
117 | /// Compute the optimal bit lengths for a tree and update the total bit length
118 | /// for the current block.
119 | /// IN assertion: the fields freq and dad are set, heap[heap_max] and
120 | /// above are the tree nodes sorted by increasing frequency.
121 | /// OUT assertions: the field count is set to the optimal bit length, the
122 | /// array bl_count contains the frequencies for each bit length.
123 | /// The length opt_len is updated; static_len is also updated if stree is
124 | /// not null.
125 | ///
126 | private void gen_bitlen(Deflate s)
127 | {
128 | short[] tree = dyn_tree;
129 | short[] stree = stat_desc.static_tree;
130 | int[] extra = stat_desc.extra_bits;
131 | int base_Renamed = stat_desc.extra_base;
132 | int max_length = stat_desc.max_length;
133 | int h; // heap index
134 | int n, m; // iterate over the tree elements
135 | int bits; // bit length
136 | int xbits; // extra bits
137 | short f; // frequency
138 | int overflow = 0; // number of elements with bit length too large
139 |
140 | for (bits = 0; bits <= ZLibUtil.MAX_WBITS; bits++)
141 | s.bl_count[bits] = 0;
142 |
143 | // In a first pass, compute the optimal bit lengths (which may
144 | // overflow in the case of the bit length tree).
145 | tree[s.heap[s.heap_max] * 2 + 1] = 0; // root of the heap
146 |
147 | for (h = s.heap_max + 1; h < ZLibUtil.HEAP_SIZE; h++)
148 | {
149 | n = s.heap[h];
150 | bits = tree[tree[n * 2 + 1] * 2 + 1] + 1;
151 | if (bits > max_length)
152 | {
153 | bits = max_length; overflow++;
154 | }
155 | tree[n * 2 + 1] = (short) bits;
156 | // We overwrite tree[n*2+1] which is no longer needed
157 |
158 | if (n > max_code)
159 | continue; // not a leaf node
160 |
161 | s.bl_count[bits]++;
162 | xbits = 0;
163 | if (n >= base_Renamed)
164 | xbits = extra[n - base_Renamed];
165 | f = tree[n * 2];
166 | s.opt_len += f * (bits + xbits);
167 | if (stree != null)
168 | s.static_len += f * (stree[n * 2 + 1] + xbits);
169 | }
170 | if (overflow == 0)
171 | return ;
172 |
173 | // This happens for example on obj2 and pic of the Calgary corpus
174 | // Find the first bit length which could increase:
175 | do
176 | {
177 | bits = max_length - 1;
178 | while (s.bl_count[bits] == 0)
179 | bits--;
180 | s.bl_count[bits]--; // move one leaf down the tree
181 | s.bl_count[bits + 1] = (short) (s.bl_count[bits + 1] + 2); // move one overflow item as its brother
182 | s.bl_count[max_length]--;
183 | // The brother of the overflow item also moves one step up,
184 | // but this does not affect bl_count[max_length]
185 | overflow -= 2;
186 | }
187 | while (overflow > 0);
188 |
189 | for (bits = max_length; bits != 0; bits--)
190 | {
191 | n = s.bl_count[bits];
192 | while (n != 0)
193 | {
194 | m = s.heap[--h];
195 | if (m > max_code)
196 | continue;
197 | if (tree[m * 2 + 1] != bits)
198 | {
199 | s.opt_len = (int) (s.opt_len + ((long) bits - (long) tree[m * 2 + 1]) * (long) tree[m * 2]);
200 | tree[m * 2 + 1] = (short) bits;
201 | }
202 | n--;
203 | }
204 | }
205 | }
206 |
207 | ///
208 | /// Construct one Huffman tree and assigns the code bit strings and lengths.
209 | /// Update the total bit length for the current block.
210 | /// IN assertion: the field freq is set for all tree elements.
211 | /// OUT assertions: the fields count and code are set to the optimal bit length
212 | /// and corresponding code. The length opt_len is updated; static_len is
213 | /// also updated if stree is not null. The field max_code is set.
214 | ///
215 | internal void build_tree(Deflate s)
216 | {
217 | short[] tree = dyn_tree;
218 | short[] stree = stat_desc.static_tree;
219 | int elems = stat_desc.elems;
220 | int n, m; // iterate over heap elements
221 | int max_code = - 1; // largest code with non zero frequency
222 | int node; // new node being created
223 |
224 | // Construct the initial heap, with least frequent element in
225 | // heap[1]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
226 | // heap[0] is not used.
227 | s.heap_len = 0;
228 | s.heap_max = ZLibUtil.HEAP_SIZE;
229 |
230 | for (n = 0; n < elems; n++)
231 | {
232 | if (tree[n * 2] != 0)
233 | {
234 | s.heap[++s.heap_len] = max_code = n;
235 | s.depth[n] = 0;
236 | }
237 | else
238 | {
239 | tree[n * 2 + 1] = 0;
240 | }
241 | }
242 |
243 | // The pkzip format requires that at least one distance code exists,
244 | // and that at least one bit should be sent even if there is only one
245 | // possible code. So to avoid special checks later on we force at least
246 | // two codes of non zero frequency.
247 | while (s.heap_len < 2)
248 | {
249 | node = s.heap[++s.heap_len] = (max_code < 2?++max_code:0);
250 | tree[node * 2] = 1;
251 | s.depth[node] = 0;
252 | s.opt_len--;
253 | if (stree != null)
254 | s.static_len -= stree[node * 2 + 1];
255 | // node is 0 or 1 so it does not have extra bits
256 | }
257 | this.max_code = max_code;
258 |
259 | // The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
260 | // establish sub-heaps of increasing lengths:
261 |
262 | for (n = s.heap_len / 2; n >= 1; n--)
263 | s.pqdownheap(tree, n);
264 |
265 | // Construct the Huffman tree by repeatedly combining the least two
266 | // frequent nodes.
267 |
268 | node = elems; // next internal node of the tree
269 | do
270 | {
271 | // n = node of least frequency
272 | n = s.heap[1];
273 | s.heap[1] = s.heap[s.heap_len--];
274 | s.pqdownheap(tree, 1);
275 | m = s.heap[1]; // m = node of next least frequency
276 |
277 | s.heap[--s.heap_max] = n; // keep the nodes sorted by frequency
278 | s.heap[--s.heap_max] = m;
279 |
280 | // Create a new node father of n and m
281 | tree[node * 2] = (short) (tree[n * 2] + tree[m * 2]);
282 | s.depth[node] = (byte) (System.Math.Max((byte) s.depth[n], (byte) s.depth[m]) + 1);
283 | tree[n * 2 + 1] = tree[m * 2 + 1] = (short) node;
284 |
285 | // and insert the new node in the heap
286 | s.heap[1] = node++;
287 | s.pqdownheap(tree, 1);
288 | }
289 | while (s.heap_len >= 2);
290 |
291 | s.heap[--s.heap_max] = s.heap[1];
292 |
293 | // At this point, the fields freq and dad are set. We can now
294 | // generate the bit lengths.
295 |
296 | gen_bitlen(s);
297 |
298 | // The field count is now set, we can generate the bit codes
299 | gen_codes(tree, max_code, s.bl_count);
300 | }
301 |
302 | ///
303 | /// Generate the codes for a given tree and bit counts (which need not be
304 | /// optimal).
305 | /// IN assertion: the array bl_count contains the bit length statistics for
306 | /// the given tree and the field count is set for all tree elements.
307 | /// OUT assertion: the field code is set for all tree elements of non
308 | /// zero code length.
309 | ///
310 | private static void gen_codes(short[] tree, int max_code, short[] bl_count)
311 | {
312 | short[] next_code = new short[ZLibUtil.MAX_WBITS + 1]; // next code value for each bit length
313 | short code = 0; // running code value
314 | int bits; // bit index
315 | int n; // code index
316 |
317 | // The distribution counts are first used to generate the code values
318 | // without bit reversal.
319 | for (bits = 1; bits <= ZLibUtil.MAX_WBITS; bits++)
320 | {
321 | next_code[bits] = code = (short) ((code + bl_count[bits - 1]) << 1);
322 | }
323 |
324 | // Check that the bit counts in bl_count are consistent. The last code
325 | // must be all ones.
326 |
327 | for (n = 0; n <= max_code; n++)
328 | {
329 | int len = tree[n * 2 + 1];
330 | if (len == 0)
331 | continue;
332 | // Now reverse the bits
333 | tree[n * 2] = (short) (bi_reverse(next_code[len]++, len));
334 | }
335 | }
336 |
337 | ///
338 | /// Reverse the first count bits of a code, using straightforward code (a faster
339 | /// method would use a table)
340 | ///
341 | private static int bi_reverse(int code, int len)
342 | {
343 | int res = 0;
344 | do
345 | {
346 | res |= code & 1;
347 | code = ZLibUtil.URShift(code, 1);
348 | res <<= 1;
349 | }
350 | while (--len > 0);
351 | return ZLibUtil.URShift(res, 1);
352 | }
353 |
354 | #endregion
355 | }
356 | }
--------------------------------------------------------------------------------
/CatSceneEditor/Zlib/ZInputStream.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2006, ComponentAce
2 | // http://www.componentace.com
3 | // All rights reserved.
4 |
5 | // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6 |
7 | // Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 | // Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 | // Neither the name of ComponentAce nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11 |
12 | /*
13 | Copyright (c) 2001 Lapo Luchini.
14 |
15 | Redistribution and use in source and binary forms, with or without
16 | modification, are permitted provided that the following conditions are met:
17 |
18 | 1. Redistributions of source code must retain the above copyright notice,
19 | this list of conditions and the following disclaimer.
20 |
21 | 2. Redistributions in binary form must reproduce the above copyright
22 | notice, this list of conditions and the following disclaimer in
23 | the documentation and/or other materials provided with the distribution.
24 |
25 | 3. The names of the authors may not be used to endorse or promote products
26 | derived from this software without specific prior written permission.
27 |
28 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
29 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
30 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS
31 | OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
32 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
34 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
37 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 | */
39 | /*
40 | * This program is based on zlib-1.1.3, so all credit should go authors
41 | * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
42 | * and contributors of zlib.
43 | */
44 | using System;
45 | using System.IO;
46 |
47 | namespace ComponentAce
48 | {
49 |
50 | ///
51 | /// The ZInputStream class is used for decompression of data. For decompression the inflate algorithm is used.
52 | /// To compress data you can use either the class or the class.
53 | ///
54 | /// The following code demonstrates how to use the ZInputStream to decompresses data
55 | ///
56 | /// [C#]
57 | /// private void decompressFile(string inFile, string outFile)
58 | /// {
59 | /// /* Create a file to store decompressed data */
60 | /// System.IO.FileStream decompressedFile = new System.IO.FileStream(@"c:\data\decompressed.dat", System.IO.FileMode.Create);
61 | /// /* Open a file containing compressed data */
62 | /// System.IO.FileStream compressedFile = new System.IO.FileStream(@"c:\data\compressed.dat", System.IO.FileMode.Open);
63 | /// /* Create ZInputStream for decompression */
64 | /// ZInputStream decompressionStream = new ZInputStream(compressedFile);
65 | ///
66 | /// try
67 | /// {
68 | /// byte[] buffer = new byte[2000];
69 | /// int len;
70 | /// /* Read and decompress data */
71 | /// while ((len = decompressionStream.Read(buffer, 0, 2000)) > 0)
72 | /// {
73 | /// /* Store decompressed data */
74 | /// decompressedFile.Write(buffer, 0, len);
75 | /// }
76 | /// }
77 | /// finally
78 | /// {
79 | /// decompressionStream.Close();
80 | /// decompressedFile.Close();
81 | /// compressedFile.Close();
82 | /// }
83 | /// }
84 | ///
85 | ///
86 | internal class ZInputStream : System.IO.Stream
87 | {
88 | #region Fields
89 |
90 | ///
91 | /// ZStream object
92 | ///
93 | private ZStream z = new ZStream();
94 |
95 | ///
96 | /// Flush strategy
97 | ///
98 | private FlushStrategy flush;
99 |
100 | ///
101 | /// Buffers
102 | ///
103 | private byte[] buf, buf1 = new byte[1];
104 |
105 | ///
106 | /// Stream to decompress data from
107 | ///
108 | private Stream _stream = null;
109 |
110 | ///
111 | /// True if no more input is available
112 | ///
113 | private bool nomoreinput = false;
114 |
115 | private bool needCopyArrays = false;
116 |
117 | #endregion
118 |
119 | #region Methods
120 |
121 | ///
122 | /// Initializes a block
123 | ///
124 | private void InitBlock()
125 | {
126 | flush = FlushStrategy.Z_NO_FLUSH;
127 | buf = new byte[ZLibUtil.zLibBufSize];
128 | }
129 |
130 | ///
131 | /// Gets/Sets the current flush strategy.
132 | ///
133 | internal FlushStrategy FlushMode
134 | {
135 | get
136 | {
137 | return flush;
138 | }
139 |
140 | set
141 | {
142 | this.flush = value;
143 | }
144 |
145 | }
146 |
147 | ///
148 | /// Constructor which takes one argument - the containing data to decompress.
149 | ///
150 | /// A stream to decompress data from.
151 | internal ZInputStream(Stream stream)
152 | {
153 | InitBlock();
154 | this._stream = stream;
155 | z.inflateInit();
156 | z.next_in = buf;
157 | z.next_in_index = 0;
158 | z.avail_in = 0;
159 | }
160 |
161 | ///
162 | /// Reads a byte of decompressed data from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.
163 | ///
164 | /// The unsigned byte cast to an Int32, or -1 if at the end of the stream.
165 | public override int ReadByte()
166 | {
167 | if (Read(buf1, 0, 1) == -1)
168 | return (-1);
169 | return (buf1[0] & 0xFF);
170 | }
171 |
172 | ///
173 | /// Reads a number of decompressed bytes into the specified byte array.
174 | ///
175 | /// The array used to store decompressed bytes.
176 | /// The location in the array to begin reading.
177 | /// The number of decompressed bytes to read.
178 | /// The number of bytes that were decompressed into the byte array.
179 | /// The following code demonstrates how to use the ZInputStream to decompresses data
180 | ///
181 | /// [C#]
182 | /// private void decompressFile(string inFile, string outFile)
183 | /// {
184 | /// /* Create a file to store decompressed data */
185 | /// System.IO.FileStream decompressedFile = new System.IO.FileStream(@"c:\data\decompressed.dat", System.IO.FileMode.Create);
186 | /// /* Open a file containing compressed data */
187 | /// System.IO.FileStream compressedFile = new System.IO.FileStream(@"c:\data\compressed.dat", System.IO.FileMode.Open);
188 | /// /* Create ZInputStream for decompression */
189 | /// ZInputStream decompressionStream = new ZInputStream(compressedFile);
190 | ///
191 | /// try
192 | /// {
193 | /// byte[] buffer = new byte[2000];
194 | /// int len;
195 | /// /* Read and decompress data */
196 | /// while ((len = decompressionStream.Read(buffer, 0, 2000)) > 0)
197 | /// {
198 | /// /* Store decompressed data */
199 | /// decompressedFile.Write(buffer, 0, len);
200 | /// }
201 | /// }
202 | /// finally
203 | /// {
204 | /// decompressionStream.Close();
205 | /// decompressedFile.Close();
206 | /// compressedFile.Close();
207 | /// }
208 | /// }
209 | ///
210 | ///
211 | public override int Read(byte[] buffer, int offset, int count)
212 | {
213 | if (count == 0)
214 | return 0;
215 |
216 | if (this.needCopyArrays && ZLibUtil.CopyLargeArrayToSmall.GetRemainingDataSize() > 0)
217 | return ZLibUtil.CopyLargeArrayToSmall.CopyData();
218 | else
219 | this.needCopyArrays = false;
220 |
221 | bool call_finish = false;
222 | int err;
223 | z.next_out = buffer;
224 | z.next_out_index = offset;
225 | z.avail_out = count;
226 | do
227 | {
228 | if ((z.avail_in == 0) && (!nomoreinput))
229 | {
230 | // if buffer is empty and more input is available, refill it
231 | z.next_in_index = 0;
232 | z.avail_in = ZLibUtil.ReadInput(_stream, buf, 0, ZLibUtil.zLibBufSize); //(ZLibUtil.zLibBufSize
260 | /// Writes a byte to the stream. Please note, that this method throws the since doesn't support writing.
261 | ///
262 | public override void Write(System.Byte[] buffer, int offset, int count)
263 | {
264 | throw new NotSupportedException("ZInputStream doesn't support writing");
265 | }
266 |
267 | ///
268 | /// Skips n decompressed bytes in the stream.
269 | ///
270 | /// The number of bytes to skip.
271 | public long Skip(long n)
272 | {
273 | int len = 512;
274 | if (n < len)
275 | len = (int)n;
276 | byte[] tmp = new byte[len];
277 | return ((long)ZLibUtil.ReadInput(this, tmp, 0, tmp.Length));
278 | }
279 |
280 | ///
281 | /// Reads the final block of decompressed data and finishes decompression.
282 | ///
283 | /// The array used to store decompressed bytes.
284 | /// The location in the array to begin reading.
285 | /// The number of decompressed bytes to read.
286 | /// The number of bytes that were decompressed into the byte array.
287 | public virtual int Finish(byte[] buffer, int offset, int count)
288 | {
289 |
290 | int err;
291 | int nWritten = 0;
292 | do
293 | {
294 | //copy to buf, emulating File.Write()
295 | z.next_out = buf;
296 | z.next_out_index = 0;
297 | z.avail_out = ZLibUtil.zLibBufSize;
298 | err = z.inflate(FlushStrategy.Z_FINISH);
299 | if (err != (int)ZLibResultCode.Z_STREAM_END && err != (int)ZLibResultCode.Z_OK)
300 | throw new ZStreamException("inflating: " + z.msg);
301 | if (ZLibUtil.zLibBufSize - z.avail_out > 0) //
302 | {
303 | this.needCopyArrays = true;
304 | ZLibUtil.CopyLargeArrayToSmall.Initialize(buf, 0, ZLibUtil.zLibBufSize - z.avail_out, buffer, offset + nWritten, count);
305 | int nWrittenNow = ZLibUtil.CopyLargeArrayToSmall.CopyData();
306 | if (ZLibUtil.CopyLargeArrayToSmall.GetRemainingDataSize() > 0)
307 | return nWrittenNow;
308 | nWritten += ZLibUtil.zLibBufSize - z.avail_out; //1
309 |
310 | }
311 | }
312 | while (z.avail_in > 0 || z.avail_out == 0);
313 | try
314 | {
315 | Flush();
316 | }
317 | catch
318 | {
319 | }
320 | return nWritten;
321 | }
322 |
323 | ///
324 | /// Frees allocated resources.
325 | ///
326 | internal virtual void End()
327 | {
328 | z.inflateEnd();
329 | z.free();
330 | z = null;
331 | }
332 |
333 | ///
334 | /// Closes the stream and the underlying stream.
335 | ///
336 | public override void Close()
337 | {
338 | End();
339 | _stream.Close();
340 | _stream = null;
341 | }
342 |
343 |
344 | ///
345 | /// Flushes the stream
346 | ///
347 | public override void Flush()
348 | {
349 | _stream.Flush();
350 | }
351 |
352 | ///
353 | /// Sets the length of the stream. Please note that the class doesn't support the SetLength operation and thus the is thrown.
354 | ///
355 | /// A new length of the stream.
356 | public override void SetLength(long value)
357 | {
358 | throw new NotSupportedException("ZInputStream doesn't support SetLength");
359 | }
360 |
361 | ///
362 | /// Gets the length of the stream in bytes. Please note that the class doesn't support the Length property and thus the is thrown.
363 | ///
364 | public override long Length
365 | {
366 | get
367 | {
368 | throw new NotSupportedException("ZLibStream doesn't support the Length property");
369 | }
370 | }
371 |
372 | ///
373 | /// Gets/Sets the current position in the stream. Please note that the class doesn't support the Position property and thus the is thrown.
374 | ///
375 | public override long Position
376 | {
377 | get
378 | {
379 | throw new NotSupportedException("ZInputStream doesn't support the Position property");
380 | }
381 | set
382 | {
383 | throw new NotSupportedException("ZInputStream doesn't support seeking");
384 | }
385 | }
386 |
387 | ///
388 | /// Seek to the offset position (from the beginning or from the current position, etc. see the available values of the parameter)in the stream. This method throws an exception since ZInpitStream doesn't support seeking operation
389 | ///
390 | public override long Seek(long offset, SeekOrigin origin)
391 | {
392 | throw new NotSupportedException("ZInputStream doesn't support seeking");
393 | }
394 |
395 | ///
396 | /// Gets a value indicating whether the stream supports reading while decompressing a file.
397 | ///
398 | ///
399 | /// Always returns true.
400 | ///
401 | public override bool CanRead
402 | {
403 | get { return true; }
404 | }
405 |
406 | ///
407 | /// Gets a value indicating whether the stream supports writing.
408 | ///
409 | /// For the always returns false.
410 | public override bool CanWrite
411 | {
412 | get { return false; }
413 | }
414 |
415 | ///
416 | /// Gets a value indicating whether the stream supports seeking.
417 | ///
418 | /// Always returns false.
419 | public override bool CanSeek
420 | {
421 | get { return false; }
422 | }
423 |
424 | #endregion
425 | }
426 | }
--------------------------------------------------------------------------------
/CatSceneEditor/Zlib/ZOutputStream.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2006, ComponentAce
2 | // http://www.componentace.com
3 | // All rights reserved.
4 |
5 | // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6 |
7 | // Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 | // Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 | // Neither the name of ComponentAce nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11 |
12 | /*
13 | Copyright (c) 2001 Lapo Luchini.
14 |
15 | Redistribution and use in source and binary forms, with or without
16 | modification, are permitted provided that the following conditions are met:
17 |
18 | 1. Redistributions of source code must retain the above copyright notice,
19 | this list of conditions and the following disclaimer.
20 |
21 | 2. Redistributions in binary form must reproduce the above copyright
22 | notice, this list of conditions and the following disclaimer in
23 | the documentation and/or other materials provided with the distribution.
24 |
25 | 3. The names of the authors may not be used to endorse or promote products
26 | derived from this software without specific prior written permission.
27 |
28 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
29 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
30 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS
31 | OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
32 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
34 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
37 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 | */
39 | /*
40 | * This program is based on zlib-1.1.3, so all credit should go authors
41 | * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
42 | * and contributors of zlib.
43 | */
44 | using System;
45 | using System.IO;
46 |
47 | namespace ComponentAce
48 | {
49 |
50 | ///
51 | /// This class uses the Deflate algorithm (an industry standard algorithm for lossless file compression and decompression) to compress data. When creating an instance of the class you passes a stream and an integer value indicating the compression level you want to use. The stream passed to the constructor is used to store compressed data.
52 | ///
53 | /// The following code demonstrates how to use the ZOutputStream to compress data
54 | ///
55 | /// [C#]
56 | /// private void compressFile(string inFile, string outFile)
57 | /// {
58 | /// /* Create a file to store compressed data */
59 | /// System.IO.FileStream compressedFile = new System.IO.FileStream(@"c:\data\compressed.dat", System.IO.FileMode.Create);
60 | /// /* Open a file containing source data */
61 | /// System.IO.FileStream sourceFile = new System.IO.FileStream(@"c:\data\source.dat", System.IO.FileMode.Open);
62 | /// /* Create ZOutputStream for compression */
63 | /// ZOutputStream compressionStream = new ZOutputStream(compressedFile);
64 | ///
65 | /// try
66 | /// {
67 | /// byte[] buffer = new byte[2000];
68 | /// int len;
69 | /// /* Read and compress data */
70 | /// while ((len = sourceFile.Read(buffer, 0, 2000)) > 0)
71 | /// {
72 | /// /* Store compressed data */
73 | /// compressionStream.Write(buffer, 0, len);
74 | /// }
75 | /// }
76 | /// finally
77 | /// {
78 | /// compressionStream.Close();
79 | /// sourceFile.Close();
80 | /// compressedFile.Close();
81 | /// }
82 | /// }
83 | ///
84 | ///
85 | internal class ZOutputStream : System.IO.Stream
86 | {
87 | #region Fields
88 |
89 | ///
90 | /// A ZStream object
91 | ///
92 | protected internal ZStream z = new ZStream();
93 |
94 | protected internal int bufsize = 4096;
95 |
96 | ///
97 | /// returns actual size of buffer, or set size of buffer between initial (4096) and maximum (2^15). Size of buffer can be only increased to prevent actual data loss
98 | ///
99 | virtual internal int BufferSize
100 | {
101 | get
102 | {
103 | return bufsize;
104 | }
105 | set
106 | {
107 | if (value >= 4096 && value <= 131072 && value > bufsize)
108 | {
109 | byte[] tmpbuf = new byte[value];
110 | Array.Copy(buf, tmpbuf, bufsize);
111 | buf = new byte[value];
112 | Array.Copy(tmpbuf, buf,bufsize);
113 | bufsize = value;
114 | }
115 | }
116 | }
117 |
118 | ///
119 | /// Current internalFlush strategy
120 | ///
121 | private FlushStrategy flush;
122 |
123 | ///
124 | /// Buffer byte arrays
125 | ///
126 | private byte[] buf, buf1 = new byte[1];
127 |
128 | ///
129 | /// Out stream
130 | ///
131 | private Stream _stream;
132 | private MemoryStream outMemoryStream;
133 |
134 | #endregion
135 |
136 | #region Methods
137 |
138 | private void InitBlock()
139 | {
140 | flush = FlushStrategy.Z_NO_FLUSH;
141 | buf = new byte[ZLibUtil.zLibBufSize];
142 | }
143 |
144 | ///
145 | /// Gets/Sets the flush strategy to use during compression.
146 | ///
147 | internal FlushStrategy FlushMode
148 | {
149 | get
150 | {
151 | return this.flush;
152 | }
153 |
154 | set
155 | {
156 | this.flush = value;
157 | }
158 |
159 | }
160 |
161 |
162 | ///
163 | /// Constructor which takes two parameters: the to store compressed data in and the desired compression level.
164 | ///
165 | /// A stream to be used to store compressed data.
166 | /// An integer value indicating the desired compression level. The compression level can take values from 0 to 9. The maximum value indicates that the maximum compression should be achieved (but this method will be the slowest one). 0 means that no compression should be used at all. If you want to use the default compression level you can pass -1. Also you can use the constants from the class.
167 | internal ZOutputStream(System.IO.Stream stream, int level)
168 | {
169 | InitBlock();
170 | this._stream = stream;
171 | z.deflateInit(level);
172 | }
173 |
174 | internal ZOutputStream(MemoryStream outMemoryStream)
175 | {
176 | this.outMemoryStream = outMemoryStream;
177 | }
178 |
179 | ///
180 | /// Writes a byte array to the stream. This block of data is compressed and stored in the stream passed as a parameter to the class constructor.
181 | ///
182 | /// A byte array to compress.
183 | /// Offset of the first byte to compress.
184 | /// The number of bytes to compress from the buffer.
185 | /// The following code demonstrates how to use the ZOutputStream to compress data
186 | ///
187 | /// [C#]
188 | /// private void compressFile(string inFile, string outFile)
189 | /// {
190 | /// /* Create a file to store compressed data */
191 | /// System.IO.FileStream compressedFile = new System.IO.FileStream(@"c:\data\compressed.dat", System.IO.FileMode.Create);
192 | /// /* Open a file containing source data */
193 | /// System.IO.FileStream sourceFile = new System.IO.FileStream(@"c:\data\source.dat", System.IO.FileMode.Open);
194 | /// /* Create ZOutputStream for compression */
195 | /// ZOutputStream compressionStream = new ZOutputStream(compressedFile);
196 | ///
197 | /// try
198 | /// {
199 | /// byte[] buffer = new byte[2000];
200 | /// int len;
201 | /// /* Read and compress data */
202 | /// while ((len = sourceFile.Read(buffer, 0, 2000)) > 0)
203 | /// {
204 | /// /* Store compressed data */
205 | /// compressionStream.Write(buffer, 0, len);
206 | /// }
207 | /// }
208 | /// finally
209 | /// {
210 | /// compressionStream.Close();
211 | /// sourceFile.Close();
212 | /// compressedFile.Close();
213 | /// }
214 | /// }
215 | ///
216 | ///
217 | public override void Write(byte[] buffer, int offset, int count)
218 | {
219 |
220 | if (count == 0)
221 | return ;
222 |
223 | if (buffer == null)
224 | throw new ArgumentNullException("buffer");
225 |
226 | int err;
227 | byte[] b = new byte[buffer.Length];
228 | System.Array.Copy(buffer, 0, b, 0, buffer.Length);
229 | z.next_in = b;
230 | z.next_in_index = offset;
231 | z.avail_in = count;
232 | do
233 | {
234 | z.next_out = buf;
235 | z.next_out_index = 0;
236 | z.avail_out = ZLibUtil.zLibBufSize;
237 | err = z.deflate(flush);
238 | if (err != (int)ZLibResultCode.Z_OK && err != (int)ZLibResultCode.Z_STREAM_END)
239 | throw new ZStreamException("deflating: " + z.msg);
240 | _stream.Write(buf, 0, ZLibUtil.zLibBufSize - z.avail_out);
241 |
242 | //fixed infinite loop where z.istate.mode == 12, but z.avail_in != 0.
243 | if (z.istate != null)
244 | if (z.istate.mode == InflateMode.DONE)
245 | if (z.avail_in > 0) { z.avail_in = 0; }
246 | }
247 | while (z.avail_in > 0 || z.avail_out == 0);
248 | }
249 |
250 | ///
251 | /// Finishes compression.
252 | ///
253 | internal void Finish()
254 | {
255 | int err;
256 | do
257 | {
258 | z.next_out = buf;
259 | z.next_out_index = 0;
260 | z.avail_out = ZLibUtil.zLibBufSize;
261 | err = z.deflate(FlushStrategy.Z_FINISH);
262 | if (err != (int)ZLibResultCode.Z_STREAM_END && err != (int)ZLibResultCode.Z_OK)
263 | throw new ZStreamException("deflating: " + z.msg);
264 | if (ZLibUtil.zLibBufSize - z.avail_out > 0)
265 | {
266 | _stream.Write(buf, 0, ZLibUtil.zLibBufSize - z.avail_out);
267 | }
268 | }
269 | while (z.avail_in > 0 || z.avail_out == 0);
270 | try
271 | {
272 | Flush();
273 | }
274 | catch
275 | {
276 | }
277 | }
278 |
279 | ///
280 | /// Frees allocated resources.
281 | ///
282 | internal void End()
283 | {
284 | z.deflateEnd();
285 | z.free();
286 | z = null;
287 | }
288 |
289 | ///
290 | /// Close the current and the underying streams.
291 | ///
292 | public override void Close()
293 | {
294 | try
295 | {
296 | try
297 | {
298 | this.Finish();
299 | }
300 | catch
301 | {
302 | }
303 | }
304 | finally
305 | {
306 | End();
307 | _stream.Close();
308 | _stream = null;
309 | }
310 | }
311 |
312 | ///
313 | /// Flushes the underlying stream.
314 | ///
315 | public override void Flush()
316 | {
317 | _stream.Flush();
318 | }
319 |
320 | ///
321 | /// Read data from the stream. Please note, that this method throws the exception since doesn't support reading.
322 | ///
323 | public override int Read(byte[] buffer, int offset, int count)
324 | {
325 | throw new NotSupportedException("ZOutputStream doesn't support reading");
326 | }
327 |
328 | ///
329 | /// Sets the length of the stream. This method throws the exception since the class doesn't support the operation.
330 | ///
331 | public override void SetLength(long value)
332 | {
333 | throw new NotSupportedException("ZOutputStream doesn't support seeking");
334 | }
335 |
336 | ///
337 | /// Sets the current position in the stream. This method throws the exception since the class doesn't support the operation.
338 | ///
339 | public override long Seek(long offset, SeekOrigin origin)
340 | {
341 | throw new NotSupportedException("ZOutputStream doesn't support seeking");
342 | }
343 |
344 | ///
345 | /// Gets a value indicating whether the stream supports reading.
346 | ///
347 | /// Always returns false since the doesn't support reading.
348 | public override bool CanRead
349 | {
350 | get { return false; }
351 | }
352 |
353 | ///
354 | /// Whether we can seek to a position in the stream.
355 | ///
356 | /// Always returns false since the doesn't support seeking.
357 | public override bool CanSeek
358 | {
359 | get { return false; }
360 | }
361 |
362 | ///
363 | /// Whether the stream supports the writing operation.
364 | ///
365 | /// This property always returns true.
366 | public override bool CanWrite
367 | {
368 | get { return true; }
369 | }
370 |
371 | ///
372 | /// Returns the length of the stream. Please note that this property always throws the exception since the stream doesn't support the property.
373 | ///
374 | public override long Length
375 | {
376 | get
377 | {
378 | throw new NotSupportedException("ZLibStream doesn't support the Length property");
379 | }
380 | }
381 |
382 | ///
383 | /// Returns the current position in the compressed stream. This property throws the exception since the stream doesn't support this property.
384 | ///
385 | public override long Position
386 | {
387 | get
388 | {
389 | throw new NotSupportedException("ZOutputStream doesn't support the Position property");
390 | }
391 | set
392 | {
393 | throw new NotSupportedException("ZOutputStream doesn't support seeking");
394 | }
395 | }
396 |
397 | #endregion
398 | }
399 | }
--------------------------------------------------------------------------------
/CatSceneEditor/Zlib/ZStreamException.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2006, ComponentAce
2 | // http://www.componentace.componentAce.com
3 | // All rights reserved.
4 |
5 | // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6 |
7 | // Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 | // Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 | // Neither the name of ComponentAce nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11 |
12 | /*
13 | Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
14 |
15 | Redistribution and use in source and binary forms, with or without
16 | modification, are permitted provided that the following conditions are met:
17 |
18 | 1. Redistributions of source code must retain the above copyright notice,
19 | this list of conditions and the following disclaimer.
20 |
21 | 2. Redistributions in binary form must reproduce the above copyright
22 | notice, this list of conditions and the following disclaimer in
23 | the documentation and/or other materials provided with the distribution.
24 |
25 | 3. The names of the authors may not be used to endorse or promote products
26 | derived from this software without specific prior written permission.
27 |
28 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
29 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
30 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
31 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
32 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
34 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
37 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 | */
39 | /*
40 | * This program is based on zlib-1.1.3, so all credit should go authors
41 | * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
42 | * and contributors of zlib.
43 | */
44 | using System;
45 | using System.IO;
46 |
47 | namespace ComponentAce
48 | {
49 |
50 | ///
51 | /// Exceptions that occur in ZStream
52 | ///
53 | internal class ZStreamException : System.IO.IOException
54 | {
55 | ///
56 | /// Default constructor.
57 | ///
58 | internal ZStreamException()
59 | :base()
60 | {
61 | }
62 |
63 | ///
64 | /// Constructor which takes one parameter - an error message
65 | ///
66 | internal ZStreamException(System.String s)
67 | :base(s)
68 | {
69 | }
70 | }
71 | }
--------------------------------------------------------------------------------
/CatSceneEditor/Zlib/license.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2006-2007, ComponentAce
2 | http://www.componentace.com
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6 |
7 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 | Neither the name of ComponentAce nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11 |
--------------------------------------------------------------------------------
/CatSceneEditor/Zlib/readme.txt:
--------------------------------------------------------------------------------
1 | ZLIB.NET: README
2 | ==================================================
3 |
4 | Contents
5 | --------
6 |
7 | Program information
8 | Company information
9 | Description
10 | Specification
11 | Other ComponentAce compression products
12 |
13 |
14 |
15 | Program information
16 | -------------------
17 |
18 | Program Name:
19 | ZLIB.NET
20 | License Type: freeware
21 |
22 | Program Version:
23 | 1.04
24 | Program Release Date:
25 | 03/28/2007
26 | Program Purpose:
27 | version of ZLIB compression library for .NET framework
28 | Target Environment:
29 | Visual Studio 2003, Visual Studio 2005, Borland Developer Studio 2005, Borland Developer Studio 2006 and other
30 |
31 |
32 | Company information
33 | -------------------
34 |
35 | Company Name:
36 | ComponentAce
37 | Contact E-mail Address:
38 | support@componentace.com
39 | Contact WWW URL:
40 | http://www.componentace.com
41 |
42 |
43 | Description
44 | -----------
45 |
46 | 100% managed version of ZLIB compression library.
47 | Based on JZlib library (c) 2000,2001,2002,2003 ymnk, JCraft,Inc.
48 |
49 | The zlib compression library was written by Jean-loup Gailly gzip@prep.ai.mit.edu and Mark Adler madler@alumni.caltech.edu.
50 |
51 | The primary site for the zlib compression library is http://www.zlib.org.
52 |
53 | Copyright and license
54 | ---------------------
55 |
56 | See "license.txt" file.
57 |
58 |
59 | Warranty and guarantee
60 | ----------------------
61 |
62 | See "license.txt" file.
63 |
64 |
65 | Other ComponentAce compression products
66 | ---------------------------------------
67 |
68 | ZipForge.NET
69 | ------------
70 |
71 | ZipForge.NET is an advanced ZIP compression library for .NET framework.
72 | ZipForge.NET features include streaming support, transaction system, ZIP encryption, repair,
73 | progress indication, Zip64 support, SFX (self-extracting) archives, unicode filenames, spanning support and much more.
74 |
75 | FlexCompress.NET
76 | ----------------
77 |
78 | FlexCompress.NET is an advanced compression and encryption .NET component designed to provide archive
79 | functionality for your applications. This solution provides flexible compression and strong encryption algorithms that
80 | allows you to integrate archiving or backup features into your programs in a fast and easy way.
81 | FlexCompres.NET uses its own file format which allows to achieve high compression rate.
82 |
83 | For more info visit
84 | http://www.componentace.com/.NET_components
--------------------------------------------------------------------------------
/CatSystemDebugger/CatSystemDebugger.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {51F0BF29-7EFD-45A1-A794-3C0CA7BF0BA4}
8 | Exe
9 | CatSystemDebugger
10 | CatSystemDebugger
11 | v4.0
12 | 512
13 |
14 |
15 | AnyCPU
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | AnyCPU
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 | app.manifest
35 |
36 |
37 |
38 | ..\packages\AsmResolver.2.0.6262.22149\lib\net40-client\AsmResolver.dll
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/CatSystemDebugger/Program.cs:
--------------------------------------------------------------------------------
1 | using AsmResolver;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Text;
7 |
8 | namespace CatSystemDebugger {
9 | class Program {
10 | static void Main(string[] args) {
11 | Console.WriteLine("CatSystem2 Debug Enabler - By Marcussacana");
12 | if (args.Length == 0) {
13 | Console.WriteLine("Drag&Drop the game executable or directory");
14 | Console.ReadKey();
15 | return;
16 | }
17 | string minified = args[0].Trim('"').ToLower().TrimEnd();
18 | string BaseDir = string.Empty;
19 | if (minified.EndsWith(".exe"))
20 | BaseDir = Path.GetDirectoryName(args[0].Trim('"'));
21 | else
22 | BaseDir = args[0].Trim('"');
23 |
24 | if (!BaseDir.EndsWith("\\"))
25 | BaseDir += "\\";
26 |
27 |
28 | string EXE = string.Empty;
29 | if (minified.EndsWith(".exe")) {
30 | EXE = args[0].Trim('"', ' ');
31 | } else {
32 | string[] Config = File.ReadAllLines(BaseDir + "boot.dfn");
33 | EXE = BaseDir + LoadConfig(Config, "boot");
34 | }
35 | string CFG = BaseDir + "config\\startup.xml";
36 | string KP = BaseDir + "cs2_debug_key.dat";
37 | DebugPatch(EXE, CFG, KP);
38 | Console.WriteLine("Press a Key to Exit");
39 | Console.ReadKey();
40 | return;
41 | }
42 |
43 | static readonly byte[] VCODE = new byte[]
44 | { 0x85, 0x83, 0xD7, 0x8A, 0x8B, 0x88, 0x04, 0xCB, 0xC3, 0x78, 0xCF, 0xD0, 0xB1, 0xA4, 0xE5, 0x9A };
45 |
46 | static readonly byte[] KEYCODE = new byte[]
47 | { 0xBA, 0xA4, 0xA3, 0xA9, 0xA0, 0xA4, 0xA1, 0xA1 };
48 |
49 | static readonly byte[] DBGKEY = new byte[]
50 | { 0xE2, 0x2A, 0xA8, 0x65, 0xC5, 0xCE, 0x04, 0x55, 0xDA, 0xE4, 0xCD, 0x9A, 0x96, 0xF2, 0x15,
51 | 0x1E, 0x1B, 0x0E, 0x13, 0xD0, 0xAB, 0x8F, 0xF8, 0x3D, 0x3F, 0xEA, 0x46, 0x73, 0x37, 0xFA,
52 | 0x8D, 0x90, 0x48, 0x4B, 0x83, 0xFF, 0x39, 0x21, 0xD0, 0x50, 0x2D, 0x12, 0x36, 0xB3, 0xF0,
53 | 0xC3, 0xD5, 0x8C, 0xD7, 0xB3, 0xDD, 0xF5, 0xF1, 0x8A, 0x77, 0xE2, 0xBD, 0x3F, 0xD2, 0x4F,
54 | 0xC9, 0x66, 0x0E, 0xFA };
55 |
56 | static readonly byte[] Validation = new byte[] { 0x75, 0x75, 0x8D, 0x4C };
57 | static readonly byte[] Validation2 = new byte[] { 0x74, 0x2D, 0x6A, 0x00, 0x68 };
58 | private static void DebugPatch(string EXE, string CFG, string KeyPath) {
59 | File.Move(EXE, EXE + ".bak");
60 | byte[] Executable = File.ReadAllBytes(EXE + ".bak");
61 | WindowsAssembly Assembly = WindowsAssembly.FromFile(EXE + ".bak");
62 | var Entries = Assembly.RootResourceDirectory.Entries;
63 | try {
64 | UpdateResourceByName(ref Executable, "V_CODE", VCODE, ref Entries);
65 | UpdateResourceByName(ref Executable, "V_CODE2", VCODE, ref Entries);
66 | UpdateResourceByName(ref Executable, "KEY_CODE", KEYCODE, ref Entries);
67 | }
68 | catch {
69 | File.Move(EXE + ".bak", EXE);
70 | Log("Failed to Patch, This is a CT2 Game?");
71 | return;
72 | }
73 | Log("All Resources Patched...");
74 | File.WriteAllBytes(KeyPath, DBGKEY);
75 | Log("Debug Key Generated...");
76 |
77 | if (!Patch(ref Executable, Validation, new byte[] { 0xEB }, "BYPASS V1")) {
78 | if (!Patch(ref Executable, Validation2, new byte[] { 0xEB }, "BYPASS V2")) {
79 | File.Move(EXE + ".bak", EXE);
80 | File.Delete(EXE + ".tmp");
81 | if (SteamStubPresent(ref Executable))
82 | Log("Failed to Patch, Steam Stub Present in the executable, Remove it before.");
83 | else
84 | Log("Failed to Patch, Unsupported Engine Version");
85 | return;
86 | }
87 | }
88 | File.WriteAllBytes(EXE, Executable);
89 |
90 | string[] XML = File.ReadAllLines(CFG, Encoding.UTF8);
91 | for (int i = 0; i < XML.Length; i++) {
92 | string Line = XML[i].Trim().ToLower();
93 | if (Line.Contains("v_code") && !Line.StartsWith("";
95 | }
96 | File.WriteAllLines(CFG, XML);
97 | Log("Successfully patched");
98 |
99 | ConsoleColor bk = Console.ForegroundColor;
100 | Console.ForegroundColor = ConsoleColor.Yellow;
101 | Console.WriteLine("Atention: To works you need decrypt all Int's Packget and delete the \"startup.xml\" into game save directory.");
102 | Console.ForegroundColor = bk;
103 | }
104 |
105 | private static bool Patch(ref byte[] Data, byte[] Ori, byte[] Patch, string Name) {
106 | Log(string.Format("Patching Resource: {0}", Name));
107 | Log(string.Format("Original Data: {0}", ByteArrToStr(Ori)));
108 | Log(string.Format("Patch Data: {0}", ByteArrToStr(Patch)));
109 |
110 | bool Patched = false;
111 | for (uint i = 0; i < Data.LongLength; i++) {
112 | if (EqualsAt(Data, Ori, i) && !Patched) {
113 | Patched = true;
114 | for (uint x = 0; x < Patch.LongLength; x++)
115 | Data[i + x] = Patch[x];
116 | break;
117 | } else if (EqualsAt(Data, Ori, i)) {
118 | Patched = false;
119 | }
120 | }
121 | return Patched;
122 | }
123 |
124 | private static bool SteamStubPresent(ref byte[] Data) {
125 | byte[] Sig = Encoding.ASCII.GetBytes(".bind");
126 | for (uint i = 0; i < Data.LongLength; i++) {
127 | if (EqualsAt(Data, Sig, i)) {
128 | return true;
129 | }
130 | }
131 | return false;
132 | }
133 |
134 | private static bool EqualsAt(byte[] Data, byte[] DataToCompare, uint Pos) {
135 | if (DataToCompare.Length + Pos > Data.Length)
136 | return false;
137 | for (uint i = 0; i < DataToCompare.Length; i++)
138 | if (DataToCompare[i] != Data[i + Pos])
139 | return false;
140 | return true;
141 | }
142 |
143 | private static void UpdateResourceByName(ref byte[] Executable, string Name, byte[] Content, ref IList Entries) {
144 | var Resource = (from e in Entries where e.Name == Name select e).Single();
145 | byte[] OriContent = Resource.SubDirectory.Entries[0].SubDirectory.Entries[0].DataEntry.Data;
146 |
147 | if (!Patch(ref Executable, OriContent, Content, Name))
148 | throw new Exception("Failed to Patch.");
149 | }
150 |
151 |
152 | private static string ByteArrToStr(byte[] Arr) {
153 | string Rst = "0x";
154 | foreach (byte b in Arr)
155 | Rst += b.ToString("X2");
156 | return Rst;
157 | }
158 | private static void Log(string Content) {
159 | Console.WriteLine("{0} at {1}: {2}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), Content);
160 | #if DEBUG
161 | System.Threading.Thread.Sleep(300);
162 | #endif
163 | }
164 | private static string LoadConfig(string[] config, string CfgName) {
165 | string Config = (from s in config where s.ToLower().TrimStart().StartsWith(CfgName.ToLower()) select s).Single();
166 | string[] Cnt = Config.Split('"');
167 | return Cnt[1].Trim();
168 | }
169 | }
170 | }
171 |
--------------------------------------------------------------------------------
/CatSystemDebugger/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // As informações gerais sobre um assembly são controladas por
6 | // conjunto de atributos. Altere estes valores de atributo para modificar as informações
7 | // associada a um assembly.
8 | [assembly: AssemblyTitle("CatSystemDebugger")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("CatSystemDebugger")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Definir ComVisible como false torna os tipos neste assembly invisíveis
18 | // para componentes COM. Caso precise acessar um tipo neste assembly de
19 | // COM, defina o atributo ComVisible como true nesse tipo.
20 | [assembly: ComVisible(false)]
21 |
22 | // O GUID a seguir será destinado à ID de typelib se este projeto for exposto para COM
23 | [assembly: Guid("51f0bf29-7efd-45a1-a794-3c0ca7bf0ba4")]
24 |
25 | // As informações da versão de um assembly consistem nos quatro valores a seguir:
26 | //
27 | // Versão Principal
28 | // Versão Secundária
29 | // Número da Versão
30 | // Revisão
31 | //
32 | // É possível especificar todos os valores ou usar como padrão os Números de Build e da Revisão
33 | // utilizando o "*" como mostrado abaixo:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/CatSystemDebugger/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
52 |
59 |
60 |
61 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/CatSystemDebugger/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ## CatSceneEditor (CSE) - v1.5
4 | [](https://ci.appveyor.com/project/marcussacana/catsceneeditor)
5 |
6 |
7 | A C# version of CatSystem2 Translation Tools
8 |
9 | Support CST, CSTL, INT
10 |
11 | Tested With: Grisaia no Kajitsu; Nekopara vol.3
12 |
13 | ## Notes:
14 | Debug Enabler Tools under testing, any bug, report it.
15 |
16 | The Tool can Extract and Repack Int's only without encryption.
17 |
18 |
19 | ### Debugger Enabler:
20 | This patch fuck the debug key validation and allow run with other game...
21 |
22 | Before apply the patch, extract all encrypted Int's and Repack without Encryption.
23 |
24 | I recommend too, delete the "startup.xml" located in the SAVE directory, the SAVE and not the CONFIG
25 |
--------------------------------------------------------------------------------
/packages/AsmResolver.2.0.6262.22149/AsmResolver.2.0.6262.22149.nupkg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcussacana/CatSceneEditor/6be7f0b754e771e1293c125232b834f2c1886f8e/packages/AsmResolver.2.0.6262.22149/AsmResolver.2.0.6262.22149.nupkg
--------------------------------------------------------------------------------
/packages/AsmResolver.2.0.6262.22149/lib/net40-client/AsmResolver.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcussacana/CatSceneEditor/6be7f0b754e771e1293c125232b834f2c1886f8e/packages/AsmResolver.2.0.6262.22149/lib/net40-client/AsmResolver.dll
--------------------------------------------------------------------------------