├── .gitattributes
├── .gitignore
├── COPYING
├── LEConfigs
├── cn-le.config
├── jp-le.config
└── template-le.config
├── LELauncher.sln
├── LELauncher
├── Amemiya.Extensions.ArrayExtensions.cs
├── AssociationReader.cs
├── GlobalHelper.cs
├── LEConfig.cs
├── LELauncher.csproj
├── LEProfile.cs
├── LERegistryRedirector.cs
├── LoaderWrapper.cs
├── Program.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── RegistryEntriesLoader.cs
├── RegistryEntry.cs
├── SystemHelper.cs
├── app.config
├── app.manifest
└── key.snk
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | Thumbs.db
2 | *.obj
3 | *.pdb
4 | *.user
5 | *.aps
6 | *.pch
7 | *.vspscc
8 | *_i.c
9 | *_p.c
10 | *.ncb
11 | *.suo
12 | *.sln.docstates
13 | *.tlb
14 | *.tlh
15 | *.bak
16 | *.cache
17 | *.ilk
18 | *.log
19 | [Bb]in
20 | [Dd]ebug*/
21 | *.lib
22 | *.sbr
23 | obj/
24 | [Rr]elease*/
25 | _ReSharper*/
26 | [Tt]est[Rr]esult*
27 | *.vssscc
28 | $tf*/
29 | .vs/
30 |
--------------------------------------------------------------------------------
/COPYING:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/LEConfigs/cn-le.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Game.exe
7 | zh-CN
8 | China Standard Time
9 | false
10 | true
11 | true
12 | false
13 |
14 |
15 |
--------------------------------------------------------------------------------
/LEConfigs/jp-le.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Game.exe
7 | ja-JP
8 | Tokyo Standard Time
9 | false
10 | true
11 | true
12 | false
13 |
14 |
15 |
--------------------------------------------------------------------------------
/LEConfigs/template-le.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Replace with relative path to target exe (e.g. Game.exe or SomeFolder\start.exe). This can include JP/CN characters
7 | Replace with appropriate localization code (e.g. ja-JP or zh-CN)
8 | Replace with appropriate timezone (e.g. Tokyo Standard Time or China Standard Time)
9 | false
10 | true
11 | true
12 | false
13 |
14 |
15 |
--------------------------------------------------------------------------------
/LELauncher.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.10.35027.167
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LELauncher", "LELauncher\LELauncher.csproj", "{A2CF5369-4665-49F6-B948-B44296002C3D}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {A2CF5369-4665-49F6-B948-B44296002C3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {A2CF5369-4665-49F6-B948-B44296002C3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {A2CF5369-4665-49F6-B948-B44296002C3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {A2CF5369-4665-49F6-B948-B44296002C3D}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {BB83E844-41DB-4478-A6EC-E98C28AC06E9}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/LELauncher/Amemiya.Extensions.ArrayExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Runtime.InteropServices;
5 |
6 | namespace Amemiya.Extensions
7 | {
8 | public static class ArrayExtensions
9 | {
10 | ///
11 | /// Convert a struct into a binary array.
12 | ///
13 | /// The binary array
14 | public static byte[] StructToBytes(object structObj)
15 | {
16 | var size = Marshal.SizeOf(structObj);
17 | var buffer = Marshal.AllocHGlobal(size);
18 | try
19 | {
20 | Marshal.StructureToPtr(structObj, buffer, true);
21 | var bytes = new byte[size];
22 | Marshal.Copy(buffer, bytes, 0, size);
23 | return bytes;
24 | }
25 | finally
26 | {
27 | Marshal.FreeHGlobal(buffer);
28 | }
29 | }
30 |
31 | ///
32 | /// Combine two arrays into one
33 | ///
34 | /// The new array
35 | public static T[] CombineWith(this T[] source, T[] with)
36 | {
37 | if (source == null || source.Length == 0)
38 | return with;
39 |
40 | var newBytes = new T[source.Length + with.Length];
41 |
42 | SetRange(newBytes, source, 0);
43 | SetRange(newBytes, with, source.Length);
44 |
45 | return newBytes;
46 | }
47 |
48 | ///
49 | /// Compare the two arrays
50 | ///
51 | /// True if they are equal
52 | public static bool EqualWith(this T[] source, T[] compareWith)
53 | {
54 | if (source.Length != compareWith.Length)
55 | return false;
56 |
57 | if (source.Where((t, i) => !EqualityComparer.Default.Equals(t, compareWith[i])).Any())
58 | return false;
59 |
60 | return true;
61 | }
62 |
63 | ///
64 | /// Expand current array to a lager one
65 | ///
66 | /// The new array
67 | public static byte[] ExpandTo(this byte[] source, int newLength)
68 | {
69 | if (source.Length > newLength)
70 | return source;
71 |
72 | var b = new byte[newLength];
73 | FillWith(b, (byte)0);
74 |
75 | SetRange(b, source, 0);
76 |
77 | return b;
78 | }
79 |
80 | ///
81 | /// Fill every item of current array with "with"
82 | ///
83 | public static void FillWith(this T[] source, T with)
84 | {
85 | for (var i = 0; i < source.Length; i++)
86 | source[i] = with;
87 | }
88 |
89 | ///
90 | /// Locate an array index in current array
91 | ///
92 | /// -1 if not-found
93 | public static int IndexOf(this T[] source, T[] arrayToFind, int startAt, bool isBackward)
94 | {
95 | if (isBackward)
96 | {
97 | for (var index = startAt - arrayToFind.Length; index >= 0; --index)
98 | {
99 | if (EqualWith(Slice(source, index, arrayToFind.Length + index), arrayToFind))
100 | return index;
101 | }
102 | return -1;
103 | }
104 |
105 | for (var index = startAt; index <= source.Length - arrayToFind.Length; ++index)
106 | {
107 | if (EqualWith(Slice(source, index, arrayToFind.Length + index), arrayToFind))
108 | return index;
109 | }
110 | return -1;
111 | }
112 |
113 | ///
114 | /// Set current array to bytesValue, starting from startFrom
115 | ///
116 | public static void SetRange(this T[] source, T[] bytesValue, int startFrom)
117 | {
118 | if (source.Length < bytesValue.Length + startFrom)
119 | throw new Exception("dest too small");
120 |
121 | Array.Copy(bytesValue, 0, source, startFrom, bytesValue.Length);
122 | }
123 |
124 | public static T[] Slice(this T[] source, int start, int end)
125 | {
126 | if (end < 0)
127 | {
128 | end = source.Length + end;
129 | }
130 | var len = end - start;
131 |
132 | var res = new T[len];
133 | for (var i = 0; i < len; i++)
134 | {
135 | res[i] = source[i + start];
136 | }
137 | return res;
138 | }
139 | }
140 | }
--------------------------------------------------------------------------------
/LELauncher/AssociationReader.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.Win32;
3 |
4 | namespace LELauncher
5 | {
6 | public class AssociationReader
7 | {
8 | public static bool HaveAssociatedProgram(string ext)
9 | {
10 | if (GetAssociatedProgram(ext) == null)
11 | return false;
12 |
13 | return true;
14 | }
15 |
16 | public static string[] GetAssociatedProgram(string ext)
17 | {
18 | var prog = GetAssociatedProgramFromRegistry(ext);
19 |
20 | if (prog == null)
21 | return null;
22 |
23 | var jb = SplitExecutableAndArgument(prog);
24 |
25 | return jb;
26 | }
27 |
28 | public static string GetAssociatedIcon(string ext)
29 | {
30 | var prog = GetAssociatedIconFromRegistry(ext);
31 |
32 | if (prog == null)
33 | return null;
34 |
35 | return prog;
36 | }
37 |
38 | private static string GetAssociatedIconFromRegistry(string ext)
39 | {
40 | var d = (string)Registry.GetValue($"HKEY_CLASSES_ROOT\\{ext}", null, null);
41 |
42 | if (string.IsNullOrEmpty(d))
43 | return null;
44 |
45 | var prog =
46 | (string)Registry.GetValue($"HKEY_CLASSES_ROOT\\{d}\\DefaultIcon", null, null);
47 |
48 | return prog;
49 | }
50 |
51 | private static string[] SplitExecutableAndArgument(string line)
52 | {
53 | var ret = line.StartsWith("\"")
54 | ? line.Split(new[] {"\" "}, 2, StringSplitOptions.None)
55 | : line.Split(new[] {' '}, 2, StringSplitOptions.None);
56 |
57 | if (ret.Length == 2)
58 | {
59 | ret[0] = ret[0].StartsWith("\"") ? ret[0].Substring(1) : ret[0];
60 | return ret;
61 | }
62 | return null;
63 | }
64 |
65 | private static string GetAssociatedProgramFromRegistry(string ext)
66 | {
67 | var d = (string)Registry.GetValue($"HKEY_CLASSES_ROOT\\{ext}", null, null);
68 |
69 | if (string.IsNullOrEmpty(d))
70 | return null;
71 |
72 | var prog =
73 | (string)Registry.GetValue($"HKEY_CLASSES_ROOT\\{d}\\Shell\\Open\\Command", null, null);
74 |
75 | return prog;
76 | }
77 | }
78 | }
--------------------------------------------------------------------------------
/LELauncher/GlobalHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Reflection;
6 | using System.Text;
7 | using System.Windows.Forms;
8 | using System.Xml.Linq;
9 |
10 | namespace LELauncher
11 | {
12 | public static class GlobalHelper
13 | {
14 | public static string Version = "0.0.4";
15 |
16 | public static void ShowErrorDebugMessageBox(string commandLine, uint errorCode)
17 | {
18 | MessageBox.Show(
19 | $"Error Number: {Convert.ToString(errorCode, 16).ToUpper()}\r\n"
20 | + $"Commands: {commandLine}\r\n" + "\r\n"
21 | + $"{string.Format($"{Environment.OSVersion} {(SystemHelper.Is64BitOS() ? "x64" : "x86")}", Environment.OSVersion, SystemHelper.Is64BitOS() ? "x64" : "x86")}\r\n"
22 | + $"{GenerateSystemDllVersionList()}\r\n"
23 | + "If you have any antivirus software running, please turn it off and try again.\r\n"
24 | + "If this window still shows, try go to Safe Mode and run this program again.\r\n"
25 | + "If you have tried all above but none of them works, feel free to submit an issue at\r\n"
26 | + "https://github.com/DTM9025/LE-Launcher/issues.\r\n" + "\r\n" + "\r\n"
27 | + "You can press CTRL+C to copy this message to your clipboard.\r\n",
28 | "Locale Emulator Launcher Version " + Version);
29 | }
30 |
31 | private static string GenerateSystemDllVersionList()
32 | {
33 | string[] dlls = {"NTDLL.DLL", "KERNELBASE.DLL", "KERNEL32.DLL", "USER32.DLL", "GDI32.DLL"};
34 |
35 | var result = new StringBuilder();
36 |
37 | foreach (var dll in dlls)
38 | {
39 | var version = FileVersionInfo.GetVersionInfo(
40 | Path.Combine(
41 | Path.GetPathRoot(Environment.SystemDirectory),
42 | SystemHelper.Is64BitOS()
43 | ? @"Windows\SysWOW64\"
44 | : @"Windows\System32\",
45 | dll));
46 |
47 | result.Append(dll);
48 | result.Append(": ");
49 | result.Append(
50 | $"{version.FileMajorPart}.{version.FileMinorPart}.{version.FileBuildPart}.{version.FilePrivatePart}");
51 | result.Append("\r\n");
52 | }
53 |
54 | return result.ToString();
55 | }
56 |
57 | public static bool CheckCoreDLLs()
58 | {
59 | string[] dlls = {"LoaderDll.dll", "LocaleEmulator.dll"};
60 |
61 | return
62 | dlls.Select(dll => Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), dll))
63 | .All(File.Exists);
64 | }
65 | }
66 | }
--------------------------------------------------------------------------------
/LELauncher/LEConfig.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Linq;
4 | using System.Reflection;
5 | using System.Xml.Linq;
6 |
7 | namespace LELauncher
8 | {
9 | public static class LEConfig
10 | {
11 | public static string GlobalConfigPath =
12 | Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
13 | "LEConfig.xml");
14 |
15 | public static LEProfile GetProfile(string name)
16 | {
17 | try
18 | {
19 | return GetProfiles(GlobalConfigPath).Where(p => p.Name == name).ToArray()[0];
20 | }
21 | catch
22 | {
23 | return new LEProfile();
24 | }
25 | }
26 |
27 | public static LEProfile[] GetProfiles()
28 | {
29 | return GetProfiles(GlobalConfigPath);
30 | }
31 |
32 | public static LEProfile[] GetProfiles(string configPath)
33 | {
34 | try
35 | {
36 | var dict = XDocument.Load(configPath);
37 |
38 | var pros = from i in dict.Descendants("LEConfig").Elements("Profiles").Elements()
39 | select i;
40 |
41 | var profiles =
42 | pros.Select(p => new LEProfile(p.Attribute("Name").Value,
43 | p.Attribute("Guid").Value,
44 | bool.Parse(p.Attribute("MainMenu").Value),
45 | p.Element("Parameter").Value,
46 | p.Element("Location").Value,
47 | p.Element("Timezone").Value,
48 | bool.Parse(p.TryGetValue("RunAsAdmin", "false")),
49 | bool.Parse(p.TryGetValue("RedirectRegistry", "true")),
50 | bool.Parse(p.TryGetValue("IsAdvancedRedirection", "false")),
51 | bool.Parse(p.TryGetValue("RunWithSuspend", "false"))
52 | )
53 | ).ToArray();
54 |
55 | return profiles;
56 | }
57 | catch
58 | {
59 | return new LEProfile[0];
60 | }
61 | }
62 |
63 | public static bool CheckGlobalConfigFile(bool buildNewConfig)
64 | {
65 | if (buildNewConfig && !File.Exists(GlobalConfigPath))
66 | BuildGlobalConfigFile();
67 |
68 | return File.Exists(GlobalConfigPath);
69 | }
70 |
71 | public static void SaveGlobalConfigFile(params LEProfile[] profiles)
72 | {
73 | WriteConfig(GlobalConfigPath, profiles);
74 | }
75 |
76 | public static void SaveApplicationConfigFile(string path, LEProfile profile)
77 | {
78 | WriteConfig(path, profile);
79 | }
80 |
81 | private static void BuildGlobalConfigFile()
82 | {
83 | var defaultProfiles = new[]
84 | {
85 | new LEProfile("Run in Japanese",
86 | Guid.NewGuid().ToString(),
87 | false,
88 | string.Empty,
89 | "ja-JP",
90 | "Tokyo Standard Time",
91 | false,
92 | true,
93 | false,
94 | false
95 | ),
96 | new LEProfile("Run in Japanese (Admin)",
97 | Guid.NewGuid().ToString(),
98 | false,
99 | string.Empty,
100 | "ja-JP",
101 | "Tokyo Standard Time",
102 | true,
103 | true,
104 | false,
105 | false
106 | )
107 | };
108 |
109 | WriteConfig(GlobalConfigPath, defaultProfiles);
110 | }
111 |
112 | private static string TryGetValue(this XElement element, string name, string defaultValue = null)
113 | {
114 | var found = element.Element(name);
115 | if (found != null)
116 | {
117 | return found.Value;
118 | }
119 | return defaultValue;
120 | }
121 |
122 | private static void WriteConfig(string writeTo, params LEProfile[] profiles)
123 | {
124 | var baseNode = new XElement("Profiles");
125 |
126 | foreach (var pro in profiles)
127 | {
128 | baseNode.Add(new XElement("Profile",
129 | new XAttribute("Name", pro.Name),
130 | new XAttribute("Guid", pro.Guid),
131 | new XAttribute("MainMenu", pro.ShowInMainMenu),
132 | new XElement("Parameter", pro.Parameter),
133 | new XElement("Location", pro.Location),
134 | new XElement("Timezone", pro.Timezone),
135 | new XElement("RunAsAdmin", pro.RunAsAdmin),
136 | new XElement("RedirectRegistry", pro.RedirectRegistry),
137 | new XElement("IsAdvancedRedirection", pro.IsAdvancedRedirection),
138 | new XElement("RunWithSuspend", pro.RunWithSuspend)
139 | )
140 | );
141 | }
142 |
143 | var tree = new XElement("LEConfig", baseNode);
144 |
145 | try
146 | {
147 | tree.Save(writeTo);
148 | }
149 | catch
150 | {
151 | }
152 | }
153 | }
154 | }
--------------------------------------------------------------------------------
/LELauncher/LELauncher.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {A2CF5369-4665-49F6-B948-B44296002C3D}
8 | WinExe
9 | Properties
10 | LELauncher
11 | LELauncher
12 | v4.0
13 | 512
14 |
15 |
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 | ..\Build\Debug\
38 | DEBUG;TRACE
39 | prompt
40 | 4
41 | true
42 | false
43 |
44 |
45 | x86
46 | pdbonly
47 | true
48 | ..\Build\Release\
49 | TRACE
50 | prompt
51 | 4
52 | false
53 |
54 |
55 |
56 | true
57 |
58 |
59 | key.snk
60 |
61 |
62 | app.manifest
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 | ResXFileCodeGenerator
90 | Resources.Designer.cs
91 | Designer
92 |
93 |
94 | True
95 | Resources.resx
96 | True
97 |
98 |
99 |
100 |
101 |
102 | SettingsSingleFileGenerator
103 | Settings.Designer.cs
104 |
105 |
106 | True
107 | Settings.settings
108 | True
109 |
110 |
111 |
112 |
113 | False
114 | Microsoft .NET Framework 4.5.1 %28x86 and x64%29
115 | true
116 |
117 |
118 | False
119 | .NET Framework 3.5 SP1 Client Profile
120 | false
121 |
122 |
123 | False
124 | .NET Framework 3.5 SP1
125 | false
126 |
127 |
128 |
129 |
130 |
137 |
--------------------------------------------------------------------------------
/LELauncher/LEProfile.cs:
--------------------------------------------------------------------------------
1 | namespace LELauncher
2 | {
3 | public struct LEProfile
4 | {
5 | public string Guid;
6 | public bool IsAdvancedRedirection;
7 | public string Location;
8 | public string Name;
9 | public string Parameter;
10 | public bool RedirectRegistry;
11 | public bool RunAsAdmin;
12 | public bool RunWithSuspend;
13 | public bool ShowInMainMenu;
14 | public string Timezone;
15 |
16 | ///
17 | /// Create a new LEProfile object using default(ja-JP) settings.
18 | ///
19 | /// A placeholder, not used at all.
20 | public LEProfile(bool isDefault)
21 | : this(
22 | "ja-JP",
23 | System.Guid.NewGuid().ToString(),
24 | false,
25 | string.Empty,
26 | "ja-JP",
27 | "Tokyo Standard Time",
28 | false,
29 | true,
30 | false,
31 | false)
32 | {
33 | }
34 |
35 | ///
36 | /// Create a new LEProfile using arguments.
37 | ///
38 | public LEProfile(string name,
39 | string guid,
40 | bool showInMainMenu,
41 | string parameter,
42 | string location,
43 | string timezone,
44 | bool runAsAdmin,
45 | bool redirectRegistry,
46 | bool isAdvancedRedirection,
47 | bool runWithSuspend)
48 | {
49 | Name = name;
50 | Guid = guid;
51 | ShowInMainMenu = showInMainMenu;
52 | Parameter = parameter;
53 | Location = location;
54 | Timezone = timezone;
55 | RunAsAdmin = runAsAdmin;
56 | RedirectRegistry = redirectRegistry;
57 | IsAdvancedRedirection = isAdvancedRedirection;
58 | RunWithSuspend = runWithSuspend;
59 | }
60 | }
61 | }
--------------------------------------------------------------------------------
/LELauncher/LERegistryRedirector.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * This is a *dirty* implementation due to the lack of support of StructureToPtr(struct-has-non-fix-lengthed-array).
3 | * Maybe I will try another methods in the future.
4 | */
5 |
6 | using System;
7 | using System.Collections.Generic;
8 | using System.Runtime.InteropServices;
9 | using System.Text;
10 | using System.Windows.Forms;
11 | using Amemiya.Extensions;
12 |
13 | namespace LELauncher
14 | {
15 | internal class LERegistryRedirector
16 | {
17 | ///
18 | /// Registry Root flags
19 | ///
20 | private static readonly Dictionary _regKeyFlags =
21 | new Dictionary
22 | {
23 | {"HKEY_CLASSES_ROOT", 0x80000000},
24 | {"HKEY_CURRENT_USER", 0x80000001},
25 | {"HKEY_LOCAL_MACHINE", 0x80000002},
26 | {"HKEY_USERS", 0x80000003},
27 | {"HKEY_CURRENT_CONFIG", 0x80000005}
28 | };
29 |
30 | ///
31 | /// Registry data types
32 | ///
33 | private static readonly Dictionary _regTypeFlags =
34 | new Dictionary
35 | {
36 | {"REG_SZ", 1},
37 | {"REG_EXPAND_SZ", 2},
38 | {"REG_BINARY", 3},
39 | {"REG_DWORD", 4},
40 | {"REG_MULTI_SZ", 7},
41 | {"REG_QWORD", 11}
42 | };
43 |
44 | private readonly List _objectData = new List();
45 | private readonly List _registryReplacement;
46 |
47 | ///
48 | /// Initialize
49 | ///
50 | /// Sum of registry entries
51 | internal LERegistryRedirector(int count)
52 | {
53 | NumberOfRegistryRedirectionEntries = count;
54 |
55 | _registryReplacement = new List(count);
56 | }
57 |
58 | ///
59 | /// Number of registry redirection entries.
60 | ///
61 | internal int NumberOfRegistryRedirectionEntries { get; set; }
62 |
63 | ///
64 | /// Get data in binary array format
65 | ///
66 | internal byte[] GetBinaryData()
67 | {
68 | // Write amount of REGISTRY_REDIRECTION_ENTRY64s
69 | var result = BitConverter.GetBytes((ulong)NumberOfRegistryRedirectionEntries);
70 |
71 | // Write REGISTRY_REDIRECTION_ENTRY64s
72 | var entrys =
73 | new byte[NumberOfRegistryRedirectionEntries * Marshal.SizeOf(new REGISTRY_REDIRECTION_ENTRY64())];
74 | entrys.FillWith((byte)0x00);
75 |
76 | for (var i = 0; i < _registryReplacement.Count; i++)
77 | {
78 | entrys.SetRange(ArrayExtensions.StructToBytes(_registryReplacement[i]),
79 | i * Marshal.SizeOf(_registryReplacement[i]));
80 | }
81 | result = result.CombineWith(entrys);
82 |
83 | // Write data objects
84 | result = result.CombineWith(_objectData.ToArray());
85 |
86 | return result;
87 | }
88 |
89 | ///
90 | /// Add a fake registry item to runtime.
91 | ///
92 | internal bool AddRegistryEntry(
93 | string root,
94 | string subkey,
95 | string valueName,
96 | string dataType,
97 | string data)
98 | {
99 | try
100 | {
101 | var original = new REGISTRY_ENTRY64
102 | {
103 | Root = _regKeyFlags[root],
104 | SubKey = new UNICODE_STRING64(),
105 | ValueName = new UNICODE_STRING64(),
106 | DataType = _regTypeFlags[dataType],
107 | Data = 0,
108 | DataSize = 0
109 | };
110 |
111 | AddStringData(subkey,
112 | out original.SubKey.Buffer,
113 | out original.SubKey.Length,
114 | out original.SubKey.MaximumLength);
115 |
116 | AddStringData(valueName,
117 | out original.ValueName.Buffer,
118 | out original.ValueName.Length,
119 | out original.ValueName.MaximumLength);
120 |
121 | AddObjectData(dataType, data, out original.Data, out original.DataSize);
122 |
123 | var entry = new REGISTRY_REDIRECTION_ENTRY64 {Original = original, Redirected = original};
124 |
125 | _registryReplacement.Add(entry);
126 |
127 | return true;
128 | }
129 | catch (Exception e)
130 | {
131 | MessageBox.Show(e.Message);
132 |
133 | return false;
134 | }
135 | }
136 |
137 | ///
138 | /// Append a string to the end of leb block
139 | ///
140 | private void AddStringData(string value, out long offset, out ushort length, out ushort maxLength)
141 | {
142 | ulong temp;
143 | AddObjectData("REG_SZ", value, out offset, out temp);
144 |
145 | length = (ushort)temp;
146 | maxLength = (ushort)temp;
147 | }
148 |
149 | ///
150 | /// Append a object to the end of leb block
151 | ///
152 | private void AddObjectData(string type, string value, out long offset, out ulong length)
153 | {
154 | offset = Marshal.SizeOf(new LoaderWrapper.LEB())
155 | + NumberOfRegistryRedirectionEntries * Marshal.SizeOf(new REGISTRY_REDIRECTION_ENTRY64())
156 | + _objectData.Count
157 | + sizeof (ulong) /*Size of NumberOfRegistryRedirectionEntries*/;
158 |
159 | switch (type)
160 | {
161 | case "REG_SZ":
162 | case "REG_EXPAND_SZ":
163 | case "REG_MULTI_SZ":
164 | length = (ulong)Encoding.Unicode.GetBytes(value).Length;
165 | _objectData.AddRange(Encoding.Unicode.GetBytes(value));
166 | break;
167 |
168 | case "REG_DWORD":
169 | length = sizeof (uint);
170 | _objectData.AddRange(BitConverter.GetBytes(uint.Parse(value)));
171 | break;
172 |
173 | case "REG_QWORD":
174 | length = sizeof (ulong);
175 | _objectData.AddRange(BitConverter.GetBytes(ulong.Parse(value)));
176 | break;
177 |
178 | case "REG_BINARY":
179 | default:
180 | throw new Exception("Data type " + type + " not supported yet.");
181 | }
182 |
183 | _objectData.AddRange(new byte[] {0x00, 0x00});
184 | }
185 |
186 | [StructLayout(LayoutKind.Sequential)]
187 | internal struct REGISTRY_ENTRY64
188 | {
189 | internal ulong Root;
190 | internal UNICODE_STRING64 SubKey;
191 | internal UNICODE_STRING64 ValueName;
192 | internal uint DataType;
193 | internal long Data;
194 | internal ulong DataSize;
195 | }
196 |
197 | [StructLayout(LayoutKind.Sequential)]
198 | internal struct REGISTRY_REDIRECTION_ENTRY64
199 | {
200 | internal REGISTRY_ENTRY64 Original;
201 | internal REGISTRY_ENTRY64 Redirected;
202 | }
203 |
204 | [StructLayout(LayoutKind.Sequential)]
205 | internal struct UNICODE_STRING64
206 | {
207 | internal ushort Length;
208 | internal ushort MaximumLength;
209 | internal long Buffer;
210 | }
211 | }
212 | }
--------------------------------------------------------------------------------
/LELauncher/LoaderWrapper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Runtime.InteropServices;
5 | using System.Text;
6 | using Amemiya.Extensions;
7 | using Microsoft.Win32;
8 |
9 | namespace LELauncher
10 | {
11 | internal class LoaderWrapper
12 | {
13 | private const uint CREATE_NORMAL = 0x00000000;
14 | private const uint CREATE_SUSPENDED = 0x00000004;
15 | private byte[] _defaultFaceName = new byte[64];
16 | private LEB _leb;
17 | private LERegistryRedirector _registry = new LERegistryRedirector(0);
18 |
19 | internal LoaderWrapper()
20 | : this(null, null, null)
21 | {
22 | }
23 |
24 | internal LoaderWrapper(string applicationName)
25 | : this(applicationName, null, null)
26 | {
27 | }
28 |
29 | internal LoaderWrapper(string applicationName, string commandLine, string currentDirectory)
30 | {
31 | ApplicationName = applicationName;
32 | CommandLine = commandLine;
33 | CurrentDirectory = currentDirectory;
34 |
35 | _leb = new LEB
36 | {
37 | AnsiCodePage = 932,
38 | OemCodePage = 932,
39 | LocaleID = 0x411,
40 | DefaultCharset = 128,
41 | HookUILanguageAPI = 0,
42 | // As we have abandoned the "default font" parameter,
43 | // we decide to put here some empty bytes.
44 | DefaultFaceName = new byte[64]
45 | };
46 | Timezone = "Tokyo Standard Time";
47 | }
48 |
49 | ///
50 | /// Application that will be run.
51 | ///
52 | internal string ApplicationName { get; set; }
53 |
54 | ///
55 | /// Command arguments.
56 | ///
57 | internal string CommandLine { get; set; }
58 |
59 | ///
60 | /// Working directory.
61 | ///
62 | internal string CurrentDirectory { get; set; }
63 |
64 | ///
65 | /// Whether the process should be created with CREATE_SUSPENDED. Useful when debugging with OllyDbg.
66 | ///
67 | internal bool DebugMode { get; set; }
68 |
69 | ///
70 | /// New AnsiCodePage. Default value is 932.
71 | ///
72 | internal uint AnsiCodePage
73 | {
74 | get { return _leb.AnsiCodePage; }
75 | set { _leb.AnsiCodePage = value; }
76 | }
77 |
78 | ///
79 | /// New OemCodePage. Default value is 932.
80 | ///
81 | internal uint OemCodePage
82 | {
83 | get { return _leb.OemCodePage; }
84 | set { _leb.OemCodePage = value; }
85 | }
86 |
87 | ///
88 | /// New LocaleID. Default value is 0x411(1041).
89 | ///
90 | internal uint LocaleID
91 | {
92 | get { return _leb.LocaleID; }
93 | set { _leb.LocaleID = value; }
94 | }
95 |
96 | ///
97 | /// New DefaultCharset. Default value is 128(Shift-JIS).
98 | ///
99 | internal uint DefaultCharset
100 | {
101 | get { return _leb.DefaultCharset; }
102 | set { _leb.DefaultCharset = value; }
103 | }
104 |
105 | ///
106 | /// Should we hook UI-related API? Default value is 0.
107 | ///
108 | internal uint HookUILanguageAPI
109 | {
110 | get { return _leb.HookUILanguageAPI; }
111 | set { _leb.HookUILanguageAPI = value; }
112 | }
113 |
114 | ///
115 | /// String that represents a Timezone.
116 | /// This can be found in HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones.
117 | ///
118 | internal string Timezone
119 | {
120 | get { return _leb.Timezone.GetStandardName(); }
121 | set
122 | {
123 | if (value.Length > 32)
124 | throw new Exception("String too long.");
125 |
126 | if (false == Enumerable.Any(TimeZoneInfo.GetSystemTimeZones(), item => item.Id == value))
127 | throw new Exception($"Timezone \"{value}\" not found in your system.");
128 |
129 | var tzi = TimeZoneInfo.FindSystemTimeZoneById(value);
130 | _leb.Timezone.SetStandardName(tzi.StandardName);
131 | _leb.Timezone.SetDaylightName(tzi.StandardName);
132 |
133 | var tzi2 = ReadTZIFromRegistry(value);
134 | _leb.Timezone.Bias = tzi2.Bias;
135 | _leb.Timezone.StandardBias = tzi2.StandardBias;
136 | _leb.Timezone.DaylightBias = 0; //tzi2.DaylightBias;
137 |
138 | //SYSTEMTIME is not the same with TIME_FIELDS (from RTL)
139 | //_leb.Timezone.StandardDate = SYSTEMTIME_To_TIME_FIELDS(tzi2.StandardDate);
140 | //_leb.Timezone.DaylightDate = SYSTEMTIME_To_TIME_FIELDS(tzi2.DaylightDate);
141 | }
142 | }
143 |
144 | ///
145 | /// Get or set the number of registry redirection entries.
146 | ///
147 | internal int NumberOfRegistryRedirectionEntries
148 | {
149 | get { return _registry.NumberOfRegistryRedirectionEntries; }
150 | set { _registry = new LERegistryRedirector(value); }
151 | }
152 |
153 | internal bool AddRegistryRedirectEntry(
154 | string root,
155 | string subkey,
156 | string valueName,
157 | string dataType,
158 | string data)
159 | {
160 | return _registry.AddRegistryEntry(root,
161 | subkey,
162 | valueName,
163 | dataType,
164 | data);
165 | }
166 |
167 | ///
168 | /// Create process.
169 | ///
170 | /// Error number
171 | internal uint Start()
172 | {
173 | if (string.IsNullOrEmpty(ApplicationName))
174 | throw new Exception("ApplicationName cannot null.");
175 |
176 | var newLEB = ArrayExtensions.StructToBytes(_leb);
177 | newLEB = newLEB.CombineWith(_registry.GetBinaryData());
178 |
179 | var locLEB = Marshal.AllocHGlobal(newLEB.Length);
180 | Marshal.Copy(newLEB, 0, locLEB, newLEB.Length);
181 |
182 | AttachConsole(ATTACH_PARENT_PROCESS);
183 |
184 | var startupInfo = new STARTUPINFO();
185 | var processInformation = new PROCESS_INFORMATION();
186 |
187 | var ret = LeCreateProcess(locLEB,
188 | ApplicationName,
189 | CommandLine,
190 | CurrentDirectory,
191 | DebugMode ? CREATE_SUSPENDED : CREATE_NORMAL,
192 | ref startupInfo,
193 | out processInformation,
194 | IntPtr.Zero,
195 | IntPtr.Zero,
196 | IntPtr.Zero,
197 | IntPtr.Zero);
198 |
199 | Marshal.FreeHGlobal(locLEB);
200 |
201 | if (ret == 0)
202 | {
203 | WaitForSingleObject(processInformation.hProcess, INFINITE);
204 | CloseHandle(processInformation.hProcess);
205 | CloseHandle(processInformation.hThread);
206 | }
207 |
208 | return ret;
209 | }
210 |
211 | private static byte[] SetBytes(byte[] bytesInput, IEnumerable bytesValue)
212 | {
213 | var i = 0;
214 | foreach (var byteChar in bytesValue)
215 | {
216 | bytesInput[i] = byteChar;
217 | i++;
218 | }
219 | return bytesInput;
220 | }
221 |
222 | public static T BytesToStruct(byte[] bytes)
223 | {
224 | var size = Marshal.SizeOf(typeof (T));
225 | var buffer = Marshal.AllocHGlobal(size);
226 | try
227 | {
228 | Marshal.Copy(bytes, 0, buffer, size);
229 | return (T)Marshal.PtrToStructure(buffer, typeof (T));
230 | }
231 | finally
232 | {
233 | Marshal.FreeHGlobal(buffer);
234 | }
235 | }
236 |
237 | private TIME_FIELDS SYSTEMTIME_To_TIME_FIELDS(_SYSTEMTIME st)
238 | {
239 | return new TIME_FIELDS
240 | {
241 | Year = st.wYear,
242 | Month = st.wMonth,
243 | Day = st.wDay,
244 | Hour = st.wHour,
245 | Minute = st.wMinute,
246 | Second = st.wSecond,
247 | Milliseconds = st.wMilliseconds,
248 | Weekday = st.wDayOfWeek
249 | };
250 | }
251 |
252 | private _REG_TZI_FORMAT ReadTZIFromRegistry(string id)
253 | {
254 | var tzi =
255 | (byte[])
256 | Registry.GetValue(
257 | $"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\{id}",
258 | "TZI",
259 | null);
260 |
261 | return BytesToStruct<_REG_TZI_FORMAT>(tzi);
262 | }
263 |
264 | [StructLayout(LayoutKind.Sequential)]
265 | public struct PROCESS_INFORMATION
266 | {
267 | public IntPtr hProcess;
268 | public IntPtr hThread;
269 | public uint dwProcessId;
270 | public uint dwThreadId;
271 | }
272 |
273 | [StructLayout(LayoutKind.Sequential)]
274 | public struct STARTUPINFO
275 | {
276 | public int cb;
277 | public String lpReserved;
278 | public String lpDesktop;
279 | public String lpTitle;
280 | public uint dwX;
281 | public uint dwY;
282 | public uint dwXSize;
283 | public uint dwYSize;
284 | public uint dwXCountChars;
285 | public uint dwYCountChars;
286 | public uint dwFillAttribute;
287 | public uint dwFlags;
288 | public short wShowWindow;
289 | public short cbReserved2;
290 | public IntPtr lpReserved2;
291 | public IntPtr hStdInput;
292 | public IntPtr hStdOutput;
293 | public IntPtr hStdError;
294 | }
295 |
296 | [DllImport("LoaderDll.dll", CharSet = CharSet.Unicode)]
297 | public static extern uint LeCreateProcess(IntPtr leb,
298 | [MarshalAs(UnmanagedType.LPWStr), In] string applicationName,
299 | [MarshalAs(UnmanagedType.LPWStr), In] string commandLine,
300 | [MarshalAs(UnmanagedType.LPWStr), In] string currentDirectory,
301 | uint creationFlags,
302 | ref STARTUPINFO startupInfo,
303 | out PROCESS_INFORMATION processInformation,
304 | IntPtr processAttributes,
305 | IntPtr threadAttributes,
306 | IntPtr environment,
307 | IntPtr token);
308 |
309 | [DllImport("kernel32.dll", SetLastError = true)]
310 | static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);
311 |
312 | [DllImport("kernel32.dll", SetLastError = true)]
313 | static extern bool CloseHandle(IntPtr hHandle);
314 |
315 | const uint INFINITE = 0xFFFFFFFF;
316 |
317 | [DllImport("kernel32.dll", SetLastError = true)]
318 | static extern bool AttachConsole(uint dwProcessId);
319 |
320 | const uint ATTACH_PARENT_PROCESS = 0x0ffffffff;
321 |
322 | [StructLayout(LayoutKind.Sequential)]
323 | internal struct LEB
324 | {
325 | internal uint AnsiCodePage;
326 | internal uint OemCodePage;
327 | internal uint LocaleID;
328 | internal uint DefaultCharset;
329 | internal uint HookUILanguageAPI;
330 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] internal byte[] DefaultFaceName;
331 | internal RTL_TIME_ZONE_INFORMATION Timezone;
332 | }
333 |
334 | [StructLayout(LayoutKind.Sequential)]
335 | internal struct PML_PROCESS_INFORMATION
336 | {
337 | internal IntPtr hProcess;
338 | internal IntPtr hThread;
339 | internal uint dwProcessId;
340 | internal uint dwThreadId;
341 | internal IntPtr FirstCallLdrLoadDll;
342 | }
343 |
344 | [StructLayout(LayoutKind.Sequential)]
345 | internal struct RTL_TIME_ZONE_INFORMATION
346 | {
347 | internal int Bias;
348 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] internal byte[] StandardName;
349 | internal TIME_FIELDS StandardDate;
350 | internal int StandardBias;
351 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] internal byte[] DaylightName;
352 | internal TIME_FIELDS DaylightDate;
353 | internal int DaylightBias;
354 |
355 | public override string ToString()
356 | {
357 | return
358 | $"StandardName={Encoding.Unicode.GetString(StandardName)}";
359 | }
360 |
361 | public string GetStandardName()
362 | {
363 | return Encoding.Unicode.GetString(StandardName).Replace("\x00", "");
364 | }
365 |
366 | public void SetStandardName(string name)
367 | {
368 | StandardName = SetBytes(new byte[64], Encoding.Unicode.GetBytes(name));
369 | }
370 |
371 | public string GetDaylightName()
372 | {
373 | return Encoding.Unicode.GetString(DaylightName).Replace("\x00", "");
374 | }
375 |
376 | public void SetDaylightName(string name)
377 | {
378 | DaylightName = SetBytes(new byte[64], Encoding.Unicode.GetBytes(name));
379 | }
380 | }
381 |
382 | private struct _REG_TZI_FORMAT
383 | {
384 | internal int Bias;
385 | internal int StandardBias;
386 | internal int DaylightBias;
387 | internal _SYSTEMTIME StandardDate;
388 | internal _SYSTEMTIME DaylightDate;
389 | }
390 |
391 | [StructLayout(LayoutKind.Sequential)]
392 | internal struct _SYSTEMTIME
393 | {
394 | internal ushort wYear;
395 | internal ushort wMonth;
396 | internal ushort wDayOfWeek;
397 | internal ushort wDay;
398 | internal ushort wHour;
399 | internal ushort wMinute;
400 | internal ushort wSecond;
401 | internal ushort wMilliseconds;
402 | }
403 |
404 | [StructLayout(LayoutKind.Sequential)]
405 | internal struct TIME_FIELDS
406 | {
407 | internal ushort Year; // range [1601...]
408 | internal ushort Month; // range [1..12]
409 | internal ushort Day; // range [1..31]
410 | internal ushort Hour; // range [0..23]
411 | internal ushort Minute; // range [0..59]
412 | internal ushort Second; // range [0..59]
413 | internal ushort Milliseconds; // range [0..999]
414 | internal ushort Weekday; // range [0..6] == [Sunday..Saturday]
415 | }
416 | }
417 | }
418 |
--------------------------------------------------------------------------------
/LELauncher/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using System.Globalization;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Reflection;
7 | using System.Windows.Forms;
8 |
9 |
10 | namespace LELauncher
11 | {
12 | internal static class Program
13 | {
14 | internal static string[] Args;
15 |
16 | ///
17 | /// The main entry point for the application.
18 | ///
19 | [STAThread]
20 | private static void Main(string[] args)
21 | {
22 | SystemHelper.DisableDPIScale();
23 |
24 | if (!GlobalHelper.CheckCoreDLLs())
25 | {
26 | MessageBox.Show(
27 | "Some of the core Dlls are missing.\r\n" +
28 | "Please whitelist these Dlls in your antivirus software, then download and re-install.\r\n"
29 | +
30 | "\r\n" +
31 | "These Dlls are:\r\n" +
32 | "LoaderDll.dll\r\n" +
33 | "LocaleEmulator.dll",
34 | "Locale Emulator DLL Error",
35 | MessageBoxButtons.OK,
36 | MessageBoxIcon.Error);
37 |
38 | return;
39 | }
40 |
41 | RunWithIndependentProfile();
42 |
43 | }
44 |
45 | private static void RunWithIndependentProfile()
46 | {
47 | var dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
48 |
49 | var conf = Path.Combine(dirName, "le.config");
50 |
51 | if (!File.Exists(conf))
52 | {
53 | MessageBox.Show(
54 | "No config file found.\r\n" +
55 | "Please ensure an appropriate le.config file is present.\r\n",
56 | "Locale Emulator Config Error",
57 | MessageBoxButtons.OK,
58 | MessageBoxIcon.Error);
59 |
60 | return;
61 | }
62 |
63 | var profile = LEConfig.GetProfiles(conf)[0];
64 |
65 | string exePath = Path.Combine(dirName, profile.Parameter);
66 | if (!File.Exists(exePath))
67 | {
68 | MessageBox.Show(
69 | "Cannot find target executable: " + profile.Parameter + "\r\n" +
70 | "Please ensure the Parameter value in le.config is a correct relative path to the target exe.\r\n",
71 | "Locale Emulator Config Error",
72 | MessageBoxButtons.OK,
73 | MessageBoxIcon.Error);
74 |
75 | return;
76 | }
77 |
78 | DoRunWithLEProfile(exePath, profile);
79 |
80 | }
81 |
82 | private static void DoRunWithLEProfile(string absPath, LEProfile profile)
83 | {
84 | try
85 | {
86 | if (profile.RunAsAdmin && !SystemHelper.IsAdministrator())
87 | {
88 | ElevateProcess();
89 |
90 | return;
91 | }
92 |
93 | if (profile.RunWithSuspend)
94 | {
95 | if (DialogResult.No ==
96 | MessageBox.Show(
97 | "You are running a exectuable with CREATE_SUSPENDED flag.\r\n" +
98 | "\r\n" +
99 | "The exectuable will be executed after you click the \"Yes\" button, " +
100 | "but as a background process which has no notifications at all." +
101 | "You can attach it by using OllyDbg, or stop it with Task Manager.\r\n",
102 | "Locale Emulator Debug Mode Warning",
103 | MessageBoxButtons.YesNo,
104 | MessageBoxIcon.Information
105 | ))
106 | return;
107 | }
108 |
109 | var applicationName = string.Empty;
110 | var commandLine = string.Empty;
111 |
112 | if (Path.GetExtension(absPath).ToLower() == ".exe" || Path.GetExtension(absPath).ToLower() == ".com")
113 | {
114 | applicationName = absPath;
115 |
116 | commandLine = absPath.StartsWith("\"")
117 | ? $"{absPath} "
118 | : $"\"{absPath}\" ";
119 | }
120 | else
121 | {
122 | var jb = AssociationReader.GetAssociatedProgram(Path.GetExtension(absPath));
123 |
124 | if (jb == null)
125 | return;
126 |
127 | applicationName = jb[0];
128 |
129 | commandLine = jb[0].StartsWith("\"")
130 | ? $"{jb[0]} "
131 | : $"\"{jb[0]}\" ";
132 | commandLine += jb[1].Replace("%1", absPath).Replace("%L", absPath).Replace("%*", "");
133 | }
134 |
135 | var currentDirectory = Path.GetDirectoryName(absPath);
136 | var ansiCodePage = (uint) CultureInfo.GetCultureInfo(profile.Location).TextInfo.ANSICodePage;
137 | var oemCodePage = (uint) CultureInfo.GetCultureInfo(profile.Location).TextInfo.OEMCodePage;
138 | var localeID = (uint) CultureInfo.GetCultureInfo(profile.Location).TextInfo.LCID;
139 | var defaultCharset = (uint)
140 | GetCharsetFromANSICodepage(CultureInfo.GetCultureInfo(profile.Location)
141 | .TextInfo.ANSICodePage);
142 |
143 | var registries = profile.RedirectRegistry
144 | ? RegistryEntriesLoader.GetRegistryEntries(profile.IsAdvancedRedirection)
145 | : null;
146 |
147 | var l = new LoaderWrapper
148 | {
149 | ApplicationName = applicationName,
150 | CommandLine = commandLine,
151 | CurrentDirectory = currentDirectory,
152 | AnsiCodePage = ansiCodePage,
153 | OemCodePage = oemCodePage,
154 | LocaleID = localeID,
155 | DefaultCharset = defaultCharset,
156 | HookUILanguageAPI = profile.IsAdvancedRedirection ? (uint) 1 : 0,
157 | Timezone = profile.Timezone,
158 | NumberOfRegistryRedirectionEntries = registries?.Length ?? 0,
159 | DebugMode = profile.RunWithSuspend
160 | };
161 |
162 | registries?.ToList()
163 | .ForEach(
164 | item =>
165 | l.AddRegistryRedirectEntry(item.Root,
166 | item.Key,
167 | item.Name,
168 | item.Type,
169 | item.GetValue(CultureInfo.GetCultureInfo(profile.Location))));
170 |
171 | uint ret;
172 | if ((ret = l.Start()) != 0)
173 | {
174 | if (SystemHelper.IsAdministrator())
175 | {
176 | GlobalHelper.ShowErrorDebugMessageBox(commandLine, ret);
177 | }
178 | else
179 | {
180 | ElevateProcess();
181 | }
182 | }
183 | }
184 | catch (Exception e)
185 | {
186 | MessageBox.Show(e.ToString());
187 | }
188 | }
189 |
190 | private static void ElevateProcess()
191 | {
192 | try
193 | {
194 | SystemHelper.RunWithElevatedProcess(
195 | Assembly.GetExecutingAssembly().Location,
196 | Args);
197 | }
198 | catch (Exception)
199 | {
200 | }
201 | }
202 |
203 | private static int GetCharsetFromANSICodepage(int ansicp)
204 | {
205 | const int ANSI_CHARSET = 0;
206 | const int DEFAULT_CHARSET = 1;
207 | const int SYMBOL_CHARSET = 2;
208 | const int SHIFTJIS_CHARSET = 128;
209 | const int HANGEUL_CHARSET = 129;
210 | const int HANGUL_CHARSET = 129;
211 | const int GB2312_CHARSET = 134;
212 | const int CHINESEBIG5_CHARSET = 136;
213 | const int OEM_CHARSET = 255;
214 | const int JOHAB_CHARSET = 130;
215 | const int HEBREW_CHARSET = 177;
216 | const int ARABIC_CHARSET = 178;
217 | const int GREEK_CHARSET = 161;
218 | const int TURKISH_CHARSET = 162;
219 | const int VIETNAMESE_CHARSET = 163;
220 | const int THAI_CHARSET = 222;
221 | const int EASTEUROPE_CHARSET = 238;
222 | const int RUSSIAN_CHARSET = 204;
223 | const int MAC_CHARSET = 77;
224 | const int BALTIC_CHARSET = 186;
225 |
226 | var charset = ANSI_CHARSET;
227 |
228 | switch (ansicp)
229 | {
230 | case 932: // Japanese
231 | charset = SHIFTJIS_CHARSET;
232 | break;
233 | case 936: // Simplified Chinese
234 | charset = GB2312_CHARSET;
235 | break;
236 | case 949: // Korean
237 | charset = HANGEUL_CHARSET;
238 | break;
239 | case 950: // Traditional Chinese
240 | charset = CHINESEBIG5_CHARSET;
241 | break;
242 | case 1250: // Eastern Europe
243 | charset = EASTEUROPE_CHARSET;
244 | break;
245 | case 1251: // Russian
246 | charset = RUSSIAN_CHARSET;
247 | break;
248 | case 1252: // Western European Languages
249 | charset = ANSI_CHARSET;
250 | break;
251 | case 1253: // Greek
252 | charset = GREEK_CHARSET;
253 | break;
254 | case 1254: // Turkish
255 | charset = TURKISH_CHARSET;
256 | break;
257 | case 1255: // Hebrew
258 | charset = HEBREW_CHARSET;
259 | break;
260 | case 1256: // Arabic
261 | charset = ARABIC_CHARSET;
262 | break;
263 | case 1257: // Baltic
264 | charset = BALTIC_CHARSET;
265 | break;
266 | }
267 |
268 | return charset;
269 | }
270 | }
271 | }
272 |
--------------------------------------------------------------------------------
/LELauncher/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 |
8 | [assembly: AssemblyTitle("LELauncher")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("DTM9025")]
12 | [assembly: AssemblyProduct("LELauncher")]
13 | [assembly: AssemblyCopyright("Copyright © DTM9025 2024")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 | [assembly: AssemblyVersion("0.0.4.0")]
17 |
18 | // Setting ComVisible to false makes the types in this assembly not visible
19 | // to COM components. If you need to access a type in this assembly from
20 | // COM, set the ComVisible attribute to true on that type.
21 |
22 | [assembly: ComVisible(false)]
23 |
24 | // The following GUID is for the ID of the typelib if this project is exposed to COM
25 |
26 | [assembly: Guid("2087a15c-bf38-4bac-a5cd-c0b2e5d4abde")]
--------------------------------------------------------------------------------
/LELauncher/Properties/Resources.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 LELauncher.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("LELauncher.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/LELauncher/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 |
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 |
--------------------------------------------------------------------------------
/LELauncher/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 LELauncher.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.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 |
--------------------------------------------------------------------------------
/LELauncher/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/LELauncher/RegistryEntriesLoader.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using System.Globalization;
6 |
7 | namespace LELauncher
8 | {
9 | public static class RegistryEntriesLoader
10 | {
11 | private static readonly RegistryEntry[] entries;
12 | private static readonly RegistryEntry[] entriesIncludingAdvanced;
13 |
14 | static RegistryEntriesLoader()
15 | {
16 | entries = new[]
17 | {
18 | new RegistryEntry("HKEY_LOCAL_MACHINE", @"System\CurrentControlSet\Control\Nls\CodePage", "InstallLanguage", "REG_SZ", culture => culture.TextInfo.LCID.ToString()),
19 | new RegistryEntry("HKEY_LOCAL_MACHINE", @"System\CurrentControlSet\Control\Nls\CodePage", "Default", "REG_SZ", culture => culture.TextInfo.LCID.ToString()),
20 | new RegistryEntry("HKEY_LOCAL_MACHINE", @"System\CurrentControlSet\Control\Nls\CodePage", "OEMCP", "REG_SZ", culture => culture.TextInfo.OEMCodePage.ToString()),
21 | new RegistryEntry("HKEY_LOCAL_MACHINE", @"System\CurrentControlSet\Control\Nls\CodePage", "ACP", "REG_SZ", culture => culture.TextInfo.ANSICodePage.ToString())
22 |
23 | };
24 |
25 | var advancedEntries = new[]
26 | {
27 | new RegistryEntry("HKEY_CURRENT_USER", @"Control Panel\International", "Locale", "REG_SZ", culture => culture.TextInfo.LCID.ToString("X8")),
28 | new RegistryEntry("HKEY_CURRENT_USER", @"Control Panel\International", "LocaleName", "REG_SZ", culture => $"{culture.TextInfo.CultureName}\x00"),
29 | new RegistryEntry("HKEY_CURRENT_USER", @"Control Panel\Desktop", "PreferredUILanguages", "REG_MULTI_SZ", culture => $"{culture.TextInfo.CultureName}\x00"),
30 | new RegistryEntry("HKEY_CURRENT_USER", @"Control Panel\Desktop\MuiCached", "MachinePreferredUILanguages", "REG_MULTI_SZ", culture => $"{culture.TextInfo.CultureName}\x00")
31 | };
32 |
33 | entriesIncludingAdvanced = entries.Concat(advancedEntries).ToArray();
34 | }
35 |
36 | public static RegistryEntry[] GetRegistryEntries(bool isAdvanced)
37 | {
38 | return isAdvanced ? entriesIncludingAdvanced : entries;
39 | }
40 |
41 |
42 | }
43 | }
--------------------------------------------------------------------------------
/LELauncher/RegistryEntry.cs:
--------------------------------------------------------------------------------
1 | using System.Globalization;
2 |
3 | namespace LELauncher
4 | {
5 | public class RegistryEntry
6 | {
7 |
8 | public delegate string ValueReceiver(CultureInfo culture);
9 |
10 | ///
11 | /// e.g. HKEY_LOCAL_MACHINE
12 | ///
13 | public string Root { get; private set; }
14 |
15 | ///
16 | /// e.g. System\CurrentControlSet\Control\Nls\CodePage
17 | ///
18 | public string Key { get; private set; }
19 |
20 | ///
21 | /// e.g. ACP
22 | ///
23 | public string Name { get; private set; }
24 |
25 | ///
26 | /// e.g. REG_SZ
27 | ///
28 | public string Type { get; private set; }
29 |
30 | ///
31 | /// e.g. culture => culture.TextInfo.ANSICodePage.ToString()
32 | /// In the example above, if the culture corresponds to ja-jp, the result is "932".
33 | ///
34 | public ValueReceiver GetValue { get; private set; }
35 |
36 | public RegistryEntry(string root, string key, string name, string type, ValueReceiver getValue)
37 | {
38 | Root = root;
39 | Key = key;
40 | Name = name;
41 | Type = type;
42 | GetValue = getValue;
43 | }
44 | }
45 | }
--------------------------------------------------------------------------------
/LELauncher/SystemHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Drawing;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Runtime.InteropServices;
6 | using System.Security.Principal;
7 |
8 | namespace LELauncher
9 | {
10 | public static class SystemHelper
11 | {
12 | public static bool Is64BitOS()
13 | {
14 | //The code below is from http://1code.codeplex.com/SourceControl/changeset/view/39074#842775
15 | //which is under the Microsoft Public License: http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
16 |
17 | if (IntPtr.Size == 8) // 64-bit programs run only on Win64
18 | {
19 | return true;
20 | }
21 | // Detect whether the current process is a 32-bit process
22 | // running on a 64-bit system.
23 | bool flag;
24 | return DoesWin32MethodExist("kernel32.dll", "IsWow64Process") &&
25 | IsWow64Process(GetCurrentProcess(), out flag) && flag;
26 | }
27 |
28 | private static bool DoesWin32MethodExist(string moduleName, string methodName)
29 | {
30 | var moduleHandle = GetModuleHandle(moduleName);
31 | if (moduleHandle == IntPtr.Zero)
32 | {
33 | return false;
34 | }
35 | return GetProcAddress(moduleHandle, methodName) != IntPtr.Zero;
36 | }
37 |
38 | public static string RedirectToWow64(string path)
39 | {
40 | var system = Environment.ExpandEnvironmentVariables("%SystemRoot%\\System32\\").ToLower();
41 | var systemWow64 = Environment.ExpandEnvironmentVariables("%SystemRoot%\\SysWOW64\\").ToLower();
42 |
43 | path = Environment.ExpandEnvironmentVariables(path).ToLower();
44 |
45 | return path.Replace(system, systemWow64);
46 | }
47 |
48 | public static string EnsureAbsolutePath(string path)
49 | {
50 | return Path.IsPathRooted(path) ? path : Path.GetFullPath(path);
51 | }
52 |
53 | public static bool Is4KDisplay()
54 | {
55 | Graphics g = Graphics.FromHwnd(IntPtr.Zero);
56 | IntPtr desktop = g.GetHdc();
57 |
58 | // 10 = VERTRES
59 | // 90 = LOGPIXELSY
60 | // 117 = DESKTOPVERTRES
61 | int logicDpi = GetDeviceCaps(desktop, 10);
62 | int logY = GetDeviceCaps(desktop, 90);
63 | int realDpi = GetDeviceCaps(desktop, 117);
64 |
65 | g.ReleaseHdc();
66 |
67 | return (realDpi/logicDpi == 2) || (logY/96 == 2);
68 | }
69 |
70 | public static void DisableDPIScale()
71 | {
72 | SetProcessDPIAware();
73 | }
74 |
75 | [DllImport("gdi32.dll")]
76 | public static extern int GetDeviceCaps(IntPtr hDC, int nIndex);
77 |
78 | [DllImport("user32.dll")]
79 | private static extern bool SetProcessDPIAware();
80 |
81 | [DllImport("kernel32.dll")]
82 | private static extern IntPtr GetCurrentProcess();
83 |
84 | [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
85 | private static extern IntPtr GetModuleHandle(string moduleName);
86 |
87 | [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
88 | private static extern IntPtr GetProcAddress(IntPtr hModule, [MarshalAs(UnmanagedType.LPStr)] string procName);
89 |
90 | [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
91 | [return: MarshalAs(UnmanagedType.Bool)]
92 | private static extern bool IsWow64Process(IntPtr hProcess, out bool wow64Process);
93 |
94 | public static bool CheckPermission(string path)
95 | {
96 | try
97 | {
98 | var tempGuid = Guid.NewGuid().ToString();
99 |
100 | File.Create(Path.Combine(path, tempGuid)).Close();
101 | File.Delete(Path.Combine(path, tempGuid));
102 |
103 | return true;
104 | }
105 | catch
106 | {
107 | return false;
108 | }
109 | }
110 |
111 | public static bool IsAdministrator()
112 | {
113 | var wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());
114 |
115 | return wp.IsInRole(WindowsBuiltInRole.Administrator);
116 | }
117 |
118 | ///
119 | /// RunWithElevatedProcess
120 | ///
121 | /// Run error.
122 | ///
123 | ///
124 | public static void RunWithElevatedProcess(string executable, string[] args)
125 | {
126 | var arg = string.Empty;
127 | arg = args == null
128 | ? string.Empty
129 | : args.Aggregate(arg, (current, s) => current + $" \"{s}\"");
130 |
131 | var shExecInfo = new SHELLEXECUTEINFO();
132 |
133 | shExecInfo.cbSize = Marshal.SizeOf(shExecInfo);
134 |
135 | shExecInfo.fMask = 0;
136 | shExecInfo.hwnd = IntPtr.Zero;
137 | shExecInfo.lpVerb = "runas";
138 | shExecInfo.lpFile = executable;
139 | shExecInfo.lpParameters = arg;
140 | shExecInfo.lpDirectory = Path.GetDirectoryName(executable);
141 |
142 | ;
143 |
144 | if (ShellExecuteEx(ref shExecInfo) == false)
145 | {
146 | throw new Exception("Error when run with elevated LE.\r\n" + $"Executable: {executable}\r\n"
147 | + $"Arguments: {arg}");
148 | }
149 | }
150 |
151 | [DllImport("shell32.dll", CharSet = CharSet.Auto)]
152 | private static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);
153 |
154 | [StructLayout(LayoutKind.Sequential)]
155 | public struct SHELLEXECUTEINFO
156 | {
157 | public int cbSize;
158 | public uint fMask;
159 | public IntPtr hwnd;
160 | [MarshalAs(UnmanagedType.LPTStr)] public string lpVerb;
161 | [MarshalAs(UnmanagedType.LPTStr)] public string lpFile;
162 | [MarshalAs(UnmanagedType.LPTStr)] public string lpParameters;
163 | [MarshalAs(UnmanagedType.LPTStr)] public string lpDirectory;
164 | public int nShow;
165 | public IntPtr hInstApp;
166 | public IntPtr lpIDList;
167 | [MarshalAs(UnmanagedType.LPTStr)] public string lpClass;
168 | public IntPtr hkeyClass;
169 | public uint dwHotKey;
170 | public IntPtr hIcon;
171 | public IntPtr hProcess;
172 | }
173 | }
174 | }
--------------------------------------------------------------------------------
/LELauncher/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/LELauncher/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/LELauncher/key.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DTM9025/LELauncher/2af2117f3c4a627fcd6d854d7fe2ac84a9c2355e/LELauncher/key.snk
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Locale Emulator Launcher
2 | ========================
3 |
4 | Launcher for Locale Emulator that is distributable and can be included in game packages.
5 |
6 | By simply including `LELauncher.exe`, the configuration `le.config`, and the dlls `LoaderDll.dll` and `LocaleEmulator.dll`,
7 | you can run any executable with the appropriate locale settings just like as you would with Locale Emulator. However,
8 | this format makes it so you can package it with your game distributions or patches without needing to tell users to
9 | install Locale Emulator (or manually switch locales). By simply editing `le.config` with a text editor with the appropriate
10 | values, you can include those files and have the user just run it without needing to install Locale Emulator!
11 |
12 | **NOTE:** The release binaries currently only work for 32-bit applications.
13 |
14 | ## Download
15 |
16 | Download available at .
17 |
18 | ## Configuration
19 |
20 | This launcher requires those four files to be located in the same directory. In addition, it requires `le.config` to
21 | be properly configured to run the desired executable with the appropriate locale settings. You can edit `le.config` with
22 | any text editor. The fields that you can edit are in the `le.config` Profile and are as follows:
23 |
24 | * `Parameter`: The relative path from the directory of `LELauncher.exe` to the target executable you want to run.
25 | * `Location`: The locale you want to simulate. These are the same as the ones used in Locale Emulator. Common values include `ja-JP` and `zh-CN`. Available location codes can be found [here](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/a9eac961-e77d-41a6-90a5-ce1a8b0cdb9c).
26 | * `Timezone`: The timezone you want to simulate. These are the same as the ones in Locale Emulator. Examples are `Tokyo Standard Time` and `China Standard Time`.
27 | * `RunAsAdmin`: Whether to run the target executable as Admin or not. Can be set `true` or `false`.
28 | * `RedirectRegistry`: Whether to fake language-related keys in Registry. Can be set `true` or `false`. **Recommended to be true**.
29 | * `IsAdvancedRedirection`: Whether to fake system UI language. Can be set `true` or `false`.
30 | * `RunWithSuspend`: Whether to run the target executable with a suspended process. Can be set `true` or `false`. **Recommended to be false**.
31 |
32 | Example configs for common profiles can be found in the [`LEConfigs`](https://github.com/DTM9025/LELauncher/tree/master/LEConfigs) folder.
33 |
34 | ## Requirements
35 |
36 | This program requires the `.NET Framework 4.0 Runtime` or higher to be installed. This should be included by default in Windows 11/10/8 and
37 | should be installed in most Windows 7 instances. If this is not the case, then you can download the runtime (or tell users to download the runtime) from [here](https://dotnet.microsoft.com/en-us/download/dotnet-framework/net48).
38 |
39 | Due to this, this program only works for Windows 7 and up. In addition, the release binaries only work for 32bit executables.
40 |
41 | ## Example Usage
42 |
43 | Let's say you have a 32-bit game that you are translating. However, for some weird reason it doesn't work unless you are in
44 | a Japanese locale, even after editing all file names, etc. (maybe text doesn't showup or it just refuses to run). You
45 | can include this launcher in your patch and tell users to run `LELauncher.exe` to run the translated patched game, allowing
46 | you to run the game with the Japanese locale.
47 |
48 | For starters, let's say the directory structure of the patched game zip will be this:
49 |
50 | ```
51 |
52 | ├── resources
53 | │ ├── blah
54 | │ └── blah
55 | |── assets
56 | | └── blah
57 | | └── blah.png
58 | └── game.exe
59 | ```
60 |
61 | Before you zip this up, you add `LELauncher.exe`, `le.config`, `LoaderDll.dll`, and `LocaleEmulator.dll` into the root folder
62 | alongside `game.exe`.
63 |
64 | To ensure it runs in the Japanese locale, you edit `le.config` with a text editor and make the `Location` value to be `ja-JP` and
65 | make the `Timezone` value to be `Tokyo Standard Time`. To ensure `LELauncher.exe` launches the game you also make the `Parameter`
66 | value to be `game.exe`, as that is the relative path to that executable from `LELauncher.exe`'s directory. You set the other
67 | parameters as appropriate.
68 |
69 | If you want, you can also rename `LELauncher.exe` to whatever is best for you (like `game-en.exe` or something) to make it
70 | more clear to users that they should run that executable to run the translated game. In addition, you could also change
71 | the icon with external tools like Resource Hacker (instructions can be found [here](https://stackoverflow.com/questions/64545983/how-do-i-add-an-icon-to-an-iconless-exe-file)).
72 |
73 | Now you can just zip the folder up with those four files as your patch distribution, and tell users to run `LELauncher.exe`
74 | (or whatever you renamed it to) to run the translated patched game and it will run in the Japanese locale! All without
75 | needing to tell the user to install Locale Emulator or switch locales in Windows!
76 |
77 | ## Build
78 |
79 | 1. Clone the repo using Git.
80 | 2. Install Microsoft Visual Studio 2015 / 2017. Make sure you have `.NET desktop development` checked.
81 | 3. Open `LELauncher.sln`.
82 | 4. Perform Build action.
83 | 5. Clone and build the core libraries: https://github.com/xupefei/Locale-Emulator-Core
84 | 6. Copy LoaderDll.dll and LocaleEmulator.dll from Locale-Emulator-Core to LELauncher build folder.
85 | 7. Create a `le.config` file as appropriate and place into the build folder. (See [`LEConfigs`](https://github.com/DTM9025/LELauncher/tree/master/LEConfigs) folder for examples).
86 |
87 | ## License
88 |
89 | 
90 |
91 | This program is free software: you can redistribute it and/or modify
92 | it under the terms of the GNU General Public License as published by
93 | the Free Software Foundation, either version 3 of the License, or
94 | (at your option) any later version.
95 |
96 | This program is distributed in the hope that it will be useful,
97 | but WITHOUT ANY WARRANTY; without even the implied warranty of
98 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
99 | GNU General Public License for more details.
100 |
101 | You should have received a copy of the GNU General Public License
102 | along with this program. If not, see .
103 |
104 | ## Credit
105 |
106 | This project is forked from [Locale Emulator](https://github.com/xupefei/Locale-Emulator) by [xupefei](https://github.com/xupefei/).
107 |
--------------------------------------------------------------------------------