├── README.md
├── Fire Emblem Save Tool.sln
├── Fire Emblem Save Tool
├── Properties
│ └── AssemblyInfo.cs
├── Fire Emblem Save Tool.csproj
├── Program.cs
└── Huffman8.cs
├── .gitignore
└── LICENSE
/README.md:
--------------------------------------------------------------------------------
1 | # FEST
2 | Save compressor / decompressor for Fire Emblem: Awakening and Fire Emblem: Fates. This is the simplified version of [FEAST](https://github.com/SciresM/FEAST), with single file support.
3 |
4 | # Download
5 | https://github.com/RainThunder/FEST/releases
6 |
7 | # Instructions
8 | * Decompress: Drag and drop a compressed save file (e.g: "Chapter0", "Global") to the .exe file.
9 | * Compress: Drag and drop a decompressed save file to the .exe file.
10 |
11 | # Credits
12 | * SciresM and CUE for FEAST.
13 |
--------------------------------------------------------------------------------
/Fire Emblem Save Tool.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fire Emblem Save Tool", "Fire Emblem Save Tool\Fire Emblem Save Tool.csproj", "{7AF5F43A-9901-42D9-A2AB-8D155A6B0D1B}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|x86 = Debug|x86
9 | Release|x86 = Release|x86
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {7AF5F43A-9901-42D9-A2AB-8D155A6B0D1B}.Debug|x86.ActiveCfg = Debug|x86
13 | {7AF5F43A-9901-42D9-A2AB-8D155A6B0D1B}.Debug|x86.Build.0 = Debug|x86
14 | {7AF5F43A-9901-42D9-A2AB-8D155A6B0D1B}.Release|x86.ActiveCfg = Release|x86
15 | {7AF5F43A-9901-42D9-A2AB-8D155A6B0D1B}.Release|x86.Build.0 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/Fire Emblem Save Tool/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Fire Emblem Save Tool")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Fire Emblem Save Tool")]
13 | [assembly: AssemblyCopyright("Copyright © SciresM 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("c3a7088c-c3f4-4cc4-9ba8-38ea5b125d88")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #################
2 | ## Eclipse
3 | #################
4 |
5 | *.pydevproject
6 | .project
7 | .metadata
8 | bin/
9 | tmp/
10 | *.tmp
11 | *.bak
12 | *.swp
13 | *~.nib
14 | local.properties
15 | .classpath
16 | .settings/
17 | .loadpath
18 |
19 | # External tool builders
20 | .externalToolBuilders/
21 |
22 | # Locally stored "Eclipse launch configurations"
23 | *.launch
24 |
25 | # CDT-specific
26 | .cproject
27 |
28 | # PDT-specific
29 | .buildpath
30 |
31 |
32 | #################
33 | ## Visual Studio
34 | #################
35 |
36 | ## Ignore Visual Studio temporary files, build results, and
37 | ## files generated by popular Visual Studio add-ons.
38 |
39 | # User-specific files
40 | *.suo
41 | *.user
42 | *.sln.docstates
43 |
44 | # Build results
45 |
46 | [Dd]ebug/
47 | [Rr]elease/
48 | x64/
49 | build/
50 | [Bb]in/
51 | [Oo]bj/
52 |
53 | # MSTest test Results
54 | [Tt]est[Rr]esult*/
55 | [Bb]uild[Ll]og.*
56 |
57 | *_i.c
58 | *_p.c
59 | *.ilk
60 | *.meta
61 | *.obj
62 | *.pch
63 | *.pdb
64 | *.pgc
65 | *.pgd
66 | *.rsp
67 | *.sbr
68 | *.tlb
69 | *.tli
70 | *.tlh
71 | *.tmp
72 | *.tmp_proj
73 | *.log
74 | *.vspscc
75 | *.vssscc
76 | .builds
77 | *.pidb
78 | *.log
79 | *.scc
80 |
81 | # Visual C++ cache files
82 | ipch/
83 | *.aps
84 | *.ncb
85 | *.opensdf
86 | *.sdf
87 | *.cachefile
88 |
89 | # Visual Studio profiler
90 | *.psess
91 | *.vsp
92 | *.vspx
93 |
94 | # Guidance Automation Toolkit
95 | *.gpState
96 |
97 | # ReSharper is a .NET coding add-in
98 | _ReSharper*/
99 | *.[Rr]e[Ss]harper
100 |
101 | # TeamCity is a build add-in
102 | _TeamCity*
103 |
104 | # DotCover is a Code Coverage Tool
105 | *.dotCover
106 |
107 | # NCrunch
108 | *.ncrunch*
109 | .*crunch*.local.xml
110 |
111 | # Installshield output folder
112 | [Ee]xpress/
113 |
114 | # DocProject is a documentation generator add-in
115 | DocProject/buildhelp/
116 | DocProject/Help/*.HxT
117 | DocProject/Help/*.HxC
118 | DocProject/Help/*.hhc
119 | DocProject/Help/*.hhk
120 | DocProject/Help/*.hhp
121 | DocProject/Help/Html2
122 | DocProject/Help/html
123 |
124 | # Click-Once directory
125 | publish/
126 |
127 | # Publish Web Output
128 | *.Publish.xml
129 | *.pubxml
130 | *.publishproj
131 |
132 | # NuGet Packages Directory
133 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
134 | #packages/
135 |
136 | # Windows Azure Build Output
137 | csx
138 | *.build.csdef
139 |
140 | # Windows Store app package directory
141 | AppPackages/
142 |
143 | # Others
144 | sql/
145 | *.Cache
146 | ClientBin/
147 | [Ss]tyle[Cc]op.*
148 | ~$*
149 | *~
150 | *.dbmdl
151 | *.[Pp]ublish.xml
152 | *.pfx
153 | *.publishsettings
154 |
155 | # RIA/Silverlight projects
156 | Generated_Code/
157 |
158 | # Backup & report files from converting an old project file to a newer
159 | # Visual Studio version. Backup files are not needed, because we have git ;-)
160 | _UpgradeReport_Files/
161 | Backup*/
162 | UpgradeLog*.XML
163 | UpgradeLog*.htm
164 |
165 | # SQL Server files
166 | App_Data/*.mdf
167 | App_Data/*.ldf
168 |
169 | #############
170 | ## Windows detritus
171 | #############
172 |
173 | # Windows image file caches
174 | Thumbs.db
175 | ehthumbs.db
176 |
177 | # Folder config file
178 | Desktop.ini
179 |
180 | # Recycle Bin used on file shares
181 | $RECYCLE.BIN/
182 |
183 | # Mac crap
184 | .DS_Store
185 |
186 |
187 | #############
188 | ## Python
189 | #############
190 |
191 | *.py[cod]
192 |
193 | # Packages
194 | *.egg
195 | *.egg-info
196 | dist/
197 | build/
198 | eggs/
199 | parts/
200 | var/
201 | sdist/
202 | develop-eggs/
203 | .installed.cfg
204 |
205 | # Installer logs
206 | pip-log.txt
207 |
208 | # Unit test / coverage reports
209 | .coverage
210 | .tox
211 |
212 | #Translations
213 | *.mo
214 |
215 | #Mr Developer
216 | .mr.developer.cfg
217 |
--------------------------------------------------------------------------------
/Fire Emblem Save Tool/Fire Emblem Save Tool.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | x86
6 | 8.0.30703
7 | 2.0
8 | {7AF5F43A-9901-42D9-A2AB-8D155A6B0D1B}
9 | Exe
10 | Properties
11 | Fire_Emblem_Save_Tool
12 | Fire Emblem Save Tool
13 | v4.0
14 | Client
15 | 512
16 | publish\
17 | true
18 | Disk
19 | false
20 | Foreground
21 | 7
22 | Days
23 | false
24 | false
25 | true
26 | 0
27 | 1.0.0.%2a
28 | false
29 | false
30 | true
31 |
32 |
33 | x86
34 | true
35 | full
36 | false
37 | bin\Debug\
38 | DEBUG;TRACE
39 | prompt
40 | 4
41 | true
42 |
43 |
44 | x86
45 | pdbonly
46 | true
47 | bin\Release\
48 | TRACE
49 | prompt
50 | 4
51 | true
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | False
76 | Microsoft .NET Framework 4 Client Profile %28x86 and x64%29
77 | true
78 |
79 |
80 | False
81 | .NET Framework 3.5 SP1 Client Profile
82 | false
83 |
84 |
85 | False
86 | .NET Framework 3.5 SP1
87 | false
88 |
89 |
90 | False
91 | Windows Installer 4.5
92 | true
93 |
94 |
95 |
96 |
103 |
--------------------------------------------------------------------------------
/Fire Emblem Save Tool/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 | using System.IO;
4 |
5 | namespace Fire_Emblem_Save_Tool
6 | {
7 | static class Program
8 | {
9 | private const int CompMagic = 0x434F4D50;
10 | private const int IndeMagic = 0x494E4445;
11 |
12 | static void Main(string[] args)
13 | {
14 | Console.WriteLine("FEST - A Fire Emblem Save Compressor and Decompressor\n" +
15 | "This is the simplified version of SciresM's FEAST\n");
16 |
17 | // Argument check
18 | if (args.Length == 0)
19 | {
20 | Console.WriteLine("Usage: FEST [filenames...]");
21 | }
22 |
23 | // Loop through all files
24 | for (int i = 0; i < args.Length; i++)
25 | {
26 | if (!File.Exists(args[i])) continue;
27 |
28 | byte[] header;
29 | byte[] raw;
30 | string outFilename;
31 | bool IsCompressed = false;
32 |
33 | // Check file
34 | using (FileStream fs = new FileStream(args[i], FileMode.Open, FileAccess.Read))
35 | using (BinaryReader br = new BinaryReader(fs))
36 | {
37 | byte[] check = new byte[0xD0];
38 | br.Read(check, 0, 0xD0);
39 | int magic = BitConverter.ToInt32(check, 0);
40 |
41 | // Compresed Global, Rating, Exchange files.
42 | if (BitConverter.ToInt32(check, 0x0) == CompMagic)
43 | {
44 | header = new byte[0];
45 | raw = new byte[(int)fs.Length - 0x10];
46 | Array.Copy(check, 0x10, raw, 0x0, 0xC0);
47 | br.Read(raw, 0xC0, (int)fs.Length - 0xD0);
48 | IsCompressed = true;
49 | }
50 | // Decompressed Global, Rating, Exchange files.
51 | else if (BitConverter.ToInt32(check, 0x0) == IndeMagic)
52 | {
53 | header = new byte[0];
54 | raw = new byte[(int)fs.Length];
55 | Array.Copy(check, 0x0, raw, 0x0, 0xD0);
56 | br.Read(raw, 0xD0, (int)fs.Length - 0xD0);
57 | IsCompressed = false;
58 | }
59 | // Compressed Chapter and Map files
60 | else if (BitConverter.ToInt32(check, 0xC0) == CompMagic)
61 | {
62 | header = new byte[0xC0];
63 | Array.Copy(check, 0x0, header, 0x0, 0xC0);
64 | raw = new byte[(int)fs.Length - 0xD0];
65 | br.Read(raw, 0x0, (int)fs.Length - 0xD0);
66 | IsCompressed = true;
67 | }
68 | // Decompressed Chapter and Map files
69 | else if (BitConverter.ToInt32(check, 0xC0) == IndeMagic)
70 | {
71 | header = new byte[0xC0];
72 | Array.Copy(check, 0x0, header, 0x0, 0xC0);
73 | raw = new byte[(int)fs.Length - 0xC0];
74 | Array.Copy(check, 0xC0, raw, 0x0, 0x10);
75 | br.Read(raw, 0x10, (int)fs.Length - 0xD0);
76 | }
77 | else
78 | {
79 | Console.WriteLine("Unsupported file.");
80 | continue;
81 | }
82 | }
83 |
84 | // Determine filenames
85 | if (IsCompressed)
86 | {
87 | outFilename = args[i] + "_dec";
88 | }
89 | else
90 | {
91 | if (args[i].EndsWith("_dec"))
92 | outFilename = args[i].Remove(args[i].Length - 4);
93 | else
94 | outFilename = args[i] + "_com";
95 | }
96 |
97 | // Write
98 | using (FileStream fs = new FileStream(outFilename, FileMode.Create, FileAccess.Write))
99 | using (BinaryWriter bw = new BinaryWriter(fs))
100 | {
101 | if (IsCompressed)
102 | {
103 | byte[] decompressed = new Huffman8().Decompress(raw);
104 | bw.Write(header, 0x0, header.Length);
105 | bw.Write(decompressed, 0x0, decompressed.Length);
106 | }
107 | else
108 | {
109 | bw.Write(header, 0, header.Length);
110 |
111 | // File info
112 | bw.Write(CompMagic); // "COMP"
113 | bw.Write(0x00000002); // Huffman-8 compression
114 | bw.Write(raw.Length);
115 | bw.Write(GetChecksum(GetChecksum(0, header), raw));
116 |
117 | byte[] compressed = new Huffman8().Compress(raw);
118 | bw.Write(compressed);
119 | }
120 | }
121 | }
122 | }
123 |
124 | static uint GetChecksum(uint oldChecksum, byte[] data) // It's just CRC32.
125 | {
126 | uint checksum = ~oldChecksum;
127 | uint length = (uint)data.Length;
128 | uint[] table = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d };
129 | if (length > 0)
130 | {
131 | int ofs = -1;
132 | if (length % 2 == 1)
133 | {
134 | ofs++;
135 | checksum = table[(byte)(data[ofs] ^ (checksum & 0xFF))] ^ (checksum >> 8);
136 | }
137 | uint v12;
138 | for (uint i = length >> 1; i > 0; checksum = table[(byte)(data[ofs] ^ (v12 & 0xFF))] ^ (v12 >> 8))
139 | {
140 | i--;
141 | int v10 = (byte)(data[ofs + 1] ^ (checksum & 0xFF));
142 | ofs += 2;
143 | v12 = table[v10] ^ (checksum >> 8);
144 | }
145 | }
146 | return ~checksum;
147 | }
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/Fire Emblem Save Tool/Huffman8.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Mostly taken from huffman.c: http://www.romhacking.net/utilities/826/
3 | */
4 | using System;
5 | using System.Linq;
6 |
7 | namespace Fire_Emblem_Save_Tool
8 | {
9 | public class Huffman8
10 | {
11 | const byte CMD_CODE = 0x28; // 8-bit Huffman magic number
12 | const uint HUF_LNODE = 0;
13 | const uint HUF_RNODE = 1;
14 |
15 | const int HUF_SHIFT = 1;
16 | const uint HUF_MASK = 0x80;
17 | const uint HUF_MASK4 = 0x80000000;
18 |
19 | const uint HUF_LCHAR = 0x80;
20 | const uint HUF_RCHAR = 0x40;
21 | const uint HUF_NEXT = 0x3F;
22 |
23 | // const uint RAW_MINIM = 0x0;
24 | // const uint RAW_MAXIM = 0xFFFFFF;
25 |
26 | // const uint HUF_MINIM = 0x4;
27 | const uint HUF_MAXIM = 0x1400000;
28 |
29 | class HuffmanNode
30 | {
31 | public uint symbol;
32 | public uint weight;
33 | public uint leafs;
34 |
35 | public HuffmanNode dad;
36 | public HuffmanNode lson;
37 | public HuffmanNode rson;
38 | }
39 | class HuffmanCode
40 | {
41 | public uint nbits;
42 | public byte[] codework;
43 | }
44 |
45 | HuffmanNode[] tree;
46 | byte[] codetree, codemask;
47 | HuffmanCode[] codes;
48 | const uint max_symbols = 0x100;
49 | uint num_leafs, num_nodes;
50 | uint[] freqs;
51 | int num_bits;
52 |
53 | public byte[] Decompress(byte[] data)
54 | {
55 | uint header = BitConverter.ToUInt32(data, 0);
56 | num_bits = (int)header & 0xF;
57 | uint UncompressedLength = header >> 8;
58 | byte[] Uncompressed = new byte[UncompressedLength];
59 | uint pak_pos = 4;
60 | pak_pos += (uint)(data[pak_pos] + 1) << 1;
61 | uint raw_pos = 0;
62 | const uint tree_ofs = 4;
63 | int nbits = 0;
64 | uint pos = data[tree_ofs + 1];
65 | uint next = 0, mask4 = 0;
66 | uint code = BitConverter.ToUInt32(data, (int)pak_pos);
67 |
68 | while (raw_pos < Uncompressed.Length)
69 | {
70 | if ((mask4 >>= HUF_SHIFT) == 0)
71 | {
72 | if (pak_pos + 3 >= data.Length) break;
73 | code = BitConverter.ToUInt32(data, (int)pak_pos);
74 | pak_pos += 4;
75 | mask4 = HUF_MASK4;
76 | }
77 |
78 | next += ((pos & HUF_NEXT) + 1) << 1;
79 |
80 | uint ch;
81 | if ((code & mask4) == 0)
82 | {
83 | ch = pos & HUF_LCHAR;
84 | pos = data[tree_ofs + next];
85 | }
86 | else
87 | {
88 | ch = pos & HUF_RCHAR;
89 | pos = data[tree_ofs + next + 1];
90 | }
91 |
92 | if (ch != 0)
93 | {
94 | Uncompressed[raw_pos] |= (byte)(pos << nbits);
95 | //// *raw = (*raw << num_bits) | pos;
96 | nbits = (nbits + num_bits) & 7;
97 | if (nbits == 0) raw_pos++;
98 |
99 | pos = data[tree_ofs+1];
100 | next = 0;
101 | }
102 | }
103 |
104 | return Uncompressed;
105 | }
106 |
107 | public byte[] Compress(byte[] data)
108 | {
109 | uint pk4_pos = 0;
110 | num_bits = 8;
111 | uint raw_len = (uint)data.Length;
112 |
113 | byte[] pbuf = new byte[HUF_MAXIM + 1];
114 | Array.Copy(BitConverter.GetBytes((CMD_CODE) | (raw_len << 8)), pbuf, 4);
115 | uint pak_pos = 4;
116 | uint raw_pos = 0;
117 | HUF_InitFreqs();
118 | HUF_CreateFreqs(data, data.Length);
119 |
120 | HUF_InitTree();
121 | HUF_CreateTree();
122 |
123 | HUF_InitCodeTree();
124 | HUF_CreateCodeTree();
125 |
126 | HUF_InitCodeWorks();
127 | HUF_CreateCodeWorks();
128 |
129 | uint cod_pos = 0;
130 |
131 | uint len = (uint)((codetree[cod_pos] + 1) << 1);
132 | while (len-- != 0) pbuf[pak_pos++] = codetree[cod_pos++];
133 | uint mask4 = 0;
134 | while (raw_pos < data.Length)
135 | {
136 | uint ch = data[raw_pos++];
137 |
138 |
139 | int nbits;
140 | for (nbits = 8; nbits != 0; nbits -= num_bits)
141 | {
142 | HuffmanCode code = codes[ch & ((1 << num_bits) - 1)];
143 | //// code = codes[ch >> (8 - num_bits)];
144 |
145 | len = code.nbits;
146 | int cwork = 0;
147 |
148 | byte mask = (byte)HUF_MASK;
149 | while (len-- != 0)
150 | {
151 | if ((mask4 >>= HUF_SHIFT) == 0)
152 | {
153 | mask4 = HUF_MASK4;
154 | pk4_pos = pak_pos;
155 | Array.Copy(BitConverter.GetBytes(0), 0, pbuf, pk4_pos, 4);
156 | pak_pos += 4;
157 | }
158 | if ((code.codework[cwork] & mask) != 0) Array.Copy(BitConverter.GetBytes(BitConverter.ToUInt32(pbuf, (int)pk4_pos) | mask4), 0, pbuf, pk4_pos, 4);
159 | if ((mask >>= HUF_SHIFT) == 0)
160 | {
161 | mask = (byte)HUF_MASK;
162 | cwork++;
163 | }
164 | }
165 |
166 | ch >>= num_bits;
167 | //// ch = (ch << num_bits) & 0xFF;
168 | }
169 | }
170 | uint pak_len = pak_pos;
171 | return pbuf.Take((int)pak_len).ToArray();
172 | }
173 |
174 | private void HUF_InitFreqs()
175 | {
176 | uint i;
177 |
178 | freqs = new uint[max_symbols];
179 |
180 | for (i = 0; i < max_symbols; i++) freqs[i] = 0;
181 | }
182 | private void HUF_CreateFreqs(byte[] raw_buffer, int raw_len)
183 | {
184 | uint i;
185 |
186 | for (i = 0; i < raw_len; i++)
187 | {
188 | uint ch = raw_buffer[i];
189 | int nbits;
190 | for (nbits = 8; nbits != 0; nbits -= num_bits)
191 | {
192 | freqs[ch >> (8 - num_bits)]++;
193 | ch = (ch << num_bits) & 0xFF;
194 | }
195 | }
196 |
197 | num_leafs = 0;
198 | for (i = 0; i < max_symbols; i++) if (freqs[i] != 0) num_leafs++;
199 | if (num_leafs < 2)
200 | {
201 | if (num_leafs == 1)
202 | {
203 | for (i = 0; i < max_symbols; i++)
204 | {
205 | if (freqs[i] != 0)
206 | {
207 | freqs[i] = 1;
208 | break;
209 | }
210 | }
211 | }
212 | while (num_leafs++ < 2)
213 | {
214 | for (i = 0; i < max_symbols; i++)
215 | {
216 | if (freqs[i] == 0)
217 | {
218 | freqs[i] = 2;
219 | break;
220 | }
221 | }
222 | }
223 | }
224 | num_nodes = (num_leafs << 1) - 1;
225 | }
226 | private void HUF_InitTree()
227 | {
228 | tree = new HuffmanNode[num_nodes];
229 | uint i;
230 | for (i = 0; i < num_nodes; i++) tree[i] = null;
231 | }
232 | private void HUF_CreateTree()
233 | {
234 | uint i;
235 |
236 | uint num_node = 0;
237 | for (i = 0; i < max_symbols; i++)
238 | {
239 | if (freqs[i] != 0)
240 | {
241 | HuffmanNode node = new HuffmanNode();
242 | tree[num_node++] = node;
243 |
244 | node.symbol = i;
245 | node.weight = freqs[i];
246 | node.leafs = 1;
247 | node.dad = null;
248 | node.lson = null;
249 | node.rson = null;
250 | }
251 | }
252 |
253 |
254 | while (num_node < num_nodes)
255 | {
256 | HuffmanNode rnode;
257 | HuffmanNode lnode = rnode = null;
258 | uint rweight;
259 | uint lweight = rweight = 0;
260 |
261 | for (i = 0; i < num_node; i++)
262 | {
263 | if (tree[i].dad == null)
264 | {
265 | if (lweight == 0 || (tree[i].weight < lweight))
266 | {
267 | rweight = lweight;
268 | rnode = lnode;
269 | lweight = tree[i].weight;
270 | lnode = tree[i];
271 | }
272 | else if (rweight == 0 || (tree[i].weight < rweight))
273 | {
274 | rweight = tree[i].weight;
275 | rnode = tree[i];
276 | }
277 | }
278 | }
279 |
280 | HuffmanNode node = new HuffmanNode();
281 | tree[num_node++] = node;
282 |
283 | node.symbol = num_node - num_leafs + max_symbols;
284 | node.weight = lnode.weight + rnode.weight;
285 | node.leafs = lnode.leafs + rnode.leafs;
286 | node.dad = null;
287 | node.lson = lnode;
288 | node.rson = rnode;
289 |
290 | lnode.dad = rnode.dad = node;
291 | }
292 | }
293 | private void HUF_InitCodeTree()
294 | {
295 | uint i;
296 |
297 | uint max_nodes = (((num_leafs - 1) | 1) + 1) << 1;
298 |
299 | codetree = new byte[max_nodes];
300 | codemask = new byte[max_nodes];
301 |
302 | for (i = 0; i < max_nodes; i++)
303 | {
304 | codetree[i] = 0;
305 | codemask[i] = 0;
306 | }
307 | }
308 | private void HUF_CreateCodeTree()
309 | {
310 | uint i = 0;
311 |
312 | codetree[i] = (byte)((num_leafs - 1) | 1);
313 | codemask[i] = 0;
314 |
315 | HUF_CreateCodeBranch(tree[num_nodes - 1], i + 1, i + 2);
316 | HUF_UpdateCodeTree();
317 |
318 | i = (uint)((codetree[0] + 1) << 1);
319 | while (--i != 0) if (codemask[i] != 0xFF) codetree[i] |= codemask[i];
320 | }
321 | private uint HUF_CreateCodeBranch(HuffmanNode root, uint p, uint q)
322 | {
323 | HuffmanNode[] stack = new HuffmanNode[2 * root.leafs];
324 | uint mask;
325 |
326 | if (root.leafs <= HUF_NEXT + 1)
327 | {
328 | uint r;
329 | uint s = r = 0;
330 | stack[r++] = root;
331 |
332 | while (s < r)
333 | {
334 | HuffmanNode node;
335 | if ((node = stack[s++]).leafs == 1)
336 | {
337 | if (s == 1) { codetree[p] = (byte)node.symbol; codemask[p] = 0xFF; }
338 | else { codetree[q] = (byte)node.symbol; codemask[q++] = 0xFF; }
339 | }
340 | else
341 | {
342 | mask = 0;
343 | if (node.lson.leafs == 1) mask |= HUF_LCHAR;
344 | if (node.rson.leafs == 1) mask |= HUF_RCHAR;
345 |
346 | if (s == 1) { codetree[p] = (byte)((r - s) >> 1); codemask[p] = (byte)mask; }
347 | else { codetree[q] = (byte)((r - s) >> 1); codemask[q++] = (byte)mask; }
348 |
349 | stack[r++] = node.lson;
350 | stack[r++] = node.rson;
351 | }
352 | }
353 | }
354 | else
355 | {
356 | mask = 0;
357 | if (root.lson.leafs == 1) mask |= HUF_LCHAR;
358 | if (root.rson.leafs == 1) mask |= HUF_RCHAR;
359 |
360 | codetree[p] = 0; codemask[p] = (byte)mask;
361 |
362 | if (root.lson.leafs <= root.rson.leafs)
363 | {
364 | uint l_leafs = HUF_CreateCodeBranch(root.lson, q, q + 2);
365 | uint r_leafs = HUF_CreateCodeBranch(root.rson, q + 1, q + (l_leafs << 1));
366 | codetree[q + 1] = (byte)(l_leafs - 1);
367 | }
368 | else
369 | {
370 | uint r_leafs = HUF_CreateCodeBranch(root.rson, q + 1, q + 2);
371 | uint l_leafs = HUF_CreateCodeBranch(root.lson, q, q + (r_leafs << 1));
372 | codetree[q] = (byte)(r_leafs - 1);
373 | }
374 | }
375 |
376 | return (root.leafs);
377 | }
378 | private void HUF_UpdateCodeTree()
379 | {
380 | uint i;
381 | uint max = (uint)((codetree[0] + 1) << 1);
382 | for (i = 1; i < max; i++)
383 | {
384 | if ((codemask[i] != 0xFF) && (codetree[i] > HUF_NEXT))
385 | {
386 | uint inc;
387 | if ((i & 1) != 0 && (codetree[i - 1] == HUF_NEXT))
388 | {
389 | i--;
390 | inc = 1;
391 | }
392 | else if ((i & 1) == 0 && (codetree[i + 1] == HUF_NEXT))
393 | {
394 | i++;
395 | inc = 1;
396 | }
397 | else
398 | {
399 | inc = codetree[i] - HUF_NEXT;
400 | }
401 |
402 | uint n1 = (i >> 1) + 1 + codetree[i];
403 | uint n0 = n1 - inc;
404 |
405 | uint l1 = n1 << 1;
406 | uint l0 = n0 << 1;
407 |
408 | uint tmp0 = BitConverter.ToUInt16(codetree, (int)l1);
409 | uint tmp1 = BitConverter.ToUInt16(codemask, (int)l1);
410 | uint j;
411 | for (j = l1; j > l0; j -= 2)
412 | {
413 | codetree[j] = codetree[j - 2];
414 | codetree[j + 1] = codetree[j - 1];
415 | codemask[j] = codemask[j - 2];
416 | codemask[j + 1] = codemask[j - 1];
417 | }
418 | Array.Copy(BitConverter.GetBytes(tmp0), 0, codetree, l0, 2);
419 | Array.Copy(BitConverter.GetBytes(tmp1), 0, codemask, l0, 2);
420 |
421 | codetree[i] -= (byte)inc;
422 |
423 | uint k;
424 | for (j = i + 1; j < l0; j++)
425 | {
426 | if (codemask[j] != 0xFF)
427 | {
428 | k = (j >> 1) + 1 + codetree[j];
429 | if ((k >= n0) && (k < n1)) codetree[j]++;
430 | }
431 | }
432 |
433 | if (codemask[l0 + 0] != 0xFF) codetree[l0 + 0] += (byte)inc;
434 | if (codemask[l0 + 1] != 0xFF) codetree[l0 + 1] += (byte)inc;
435 |
436 | for (j = l0 + 2; j < l1 + 2; j++)
437 | {
438 | if (codemask[j] != 0xFF)
439 | {
440 | k = (j >> 1) + 1 + codetree[j];
441 | if (k > n1) codetree[j]--;
442 | }
443 | }
444 |
445 | i = (i | 1) - 2;
446 | }
447 | }
448 | }
449 | private void HUF_InitCodeWorks()
450 | {
451 | uint i;
452 | codes = new HuffmanCode[max_symbols];
453 | for (i = 0; i < max_symbols; i++) codes[i] = null;
454 | }
455 | private void HUF_CreateCodeWorks()
456 | {
457 | byte[] scode = new byte[100];
458 | uint i;
459 |
460 | for (i = 0; i < num_leafs; i++)
461 | {
462 | HuffmanNode node = tree[i];
463 | uint symbol = node.symbol;
464 |
465 | uint nbits = 0;
466 | while (node.dad != null)
467 | {
468 | scode[nbits++] = node.dad.lson == node ? (byte)HUF_LNODE : (byte)HUF_RNODE;
469 | node = node.dad;
470 | }
471 | uint maxbytes = (nbits + 7) >> 3;
472 |
473 | HuffmanCode code = new HuffmanCode();
474 |
475 | codes[symbol] = code;
476 | code.nbits = nbits;
477 | code.codework = new byte[maxbytes];
478 |
479 | uint j;
480 | for (j = 0; j < maxbytes; j++) code.codework[j] = 0;
481 |
482 | byte mask = (byte)HUF_MASK;
483 | j = 0;
484 | uint nbit;
485 | for (nbit = nbits; nbit != 0; nbit--)
486 | {
487 | if (scode[nbit - 1] != 0) code.codework[j] |= mask;
488 | if ((mask >>= HUF_SHIFT) == 0)
489 | {
490 | mask = (byte)HUF_MASK;
491 | j++;
492 | }
493 | }
494 | }
495 | }
496 | }
497 | }
498 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
341 |
--------------------------------------------------------------------------------